Whamcloud - gitweb
b=18233 fix read+truncate livelock
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index e7c62b8..73170fc 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -42,7 +42,6 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
-#include <linux/random.h>
 #include <linux/version.h>
 #include <linux/mm.h>
 
@@ -116,7 +115,7 @@ static struct ll_sb_info *ll_init_sbi(void)
         cfs_list_add_tail(&sbi->ll_list, &ll_super_blocks);
         cfs_spin_unlock(&ll_sb_lock);
 
-#ifdef ENABLE_LLITE_CHECKSUM
+#ifdef ENABLE_CHECKSUM
         sbi->ll_flags |= LL_SBI_CHECKSUM;
 #endif
 
@@ -254,7 +253,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
                 GOTO(out_md, err);
         }
 
-        err = obd_statfs(obd, &osfs, cfs_time_current_64() - CFS_HZ, 0);
+        err = obd_statfs(obd, &osfs,
+                         cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 0);
         if (err)
                 GOTO(out_md_fid, err);
 
@@ -413,7 +413,9 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
         CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
 
         sb->s_op = &lustre_super_operations;
+#if THREAD_SIZE >= 8192
         sb->s_export_op = &lustre_export_operations;
+#endif
 
         /* make root inode
          * XXX: move this to after cbd setup? */
@@ -711,17 +713,25 @@ static int ll_options(char *options, int *flags)
                         *flags &= ~tmp;
                         goto next;
                 }
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2,5,50,0)
                 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
                 if (tmp) {
                         /* Ignore deprecated mount option.  The client will
                          * always try to mount with ACL support, whether this
                          * is used depends on whether server supports it. */
+                        LCONSOLE_ERROR_MSG(0x152, "Ignoring deprecated "
+                                                  "mount option 'acl'.\n");
                         goto next;
                 }
                 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
                 if (tmp) {
+                        LCONSOLE_ERROR_MSG(0x152, "Ignoring deprecated "
+                                                  "mount option 'noacl'.\n");
                         goto next;
                 }
+#else
+#warning "{no}acl options have been deprecated since 1.8, please remove them"
+#endif
                 tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT);
                 if (tmp) {
                         *flags |= tmp;
@@ -763,6 +773,11 @@ static int ll_options(char *options, int *flags)
                         *flags |= tmp;
                         goto next;
                 }
+                tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
+                if (tmp) {
+                        *flags |= tmp;
+                        goto next;
+                }
 
                 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
                                    s1);
@@ -783,7 +798,7 @@ void ll_lli_init(struct ll_inode_info *lli)
         lli->lli_inode_magic = LLI_INODE_MAGIC;
         cfs_sema_init(&lli->lli_size_sem, 1);
         cfs_sema_init(&lli->lli_write_sem, 1);
-        cfs_sema_init(&lli->lli_trunc_sem, 1);
+        cfs_init_rwsem(&lli->lli_trunc_sem);
         lli->lli_flags = 0;
         lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
         cfs_spin_lock_init(&lli->lli_lock);
@@ -800,9 +815,12 @@ void ll_lli_init(struct ll_inode_info *lli)
         cfs_sema_init(&lli->lli_rmtperm_sem, 1);
         CFS_INIT_LIST_HEAD(&lli->lli_oss_capas);
         cfs_spin_lock_init(&lli->lli_sa_lock);
-        CFS_INIT_LIST_HEAD(&lli->lli_sa_dentry);
 }
 
+#ifdef HAVE_NEW_BACKING_DEV_INFO
+static atomic_t ll_bdi_num = ATOMIC_INIT(0);
+#endif
+
 int ll_fill_super(struct super_block *sb)
 {
         struct lustre_profile *lprof;
@@ -830,6 +848,18 @@ int ll_fill_super(struct super_block *sb)
         if (err)
                 GOTO(out_free, err);
 
+        err = ll_bdi_init(&lsi->bdi);
+        if (err)
+                GOTO(out_free, err);
+
+#ifdef HAVE_NEW_BACKING_DEV_INFO
+        lsi->bdi.name = "lustre";
+        lsi->bdi.capabilities = BDI_CAP_MAP_COPY;
+        err = bdi_register(&lsi->bdi, NULL, "lustre-%d",
+                           atomic_inc_return(&ll_bdi_num));
+        sb->s_bdi = &lsi->bdi;
+#endif
+
         /* Generate a string unique to this super, in case some joker tries
            to mount the same fs at two mount points.
            Use the address of the super itself.*/
@@ -934,6 +964,9 @@ void ll_put_super(struct super_block *sb)
         if (profilenm)
                 class_del_profile(profilenm);
 
+        if (ll_bdi_wb_cnt(lsi->bdi) > 0)
+                ll_bdi_destroy(&lsi->bdi);
+
         ll_free_sbi(sb);
         lsi->lsi_llsbi = NULL;
 
@@ -959,11 +992,10 @@ struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
                         inode = igrab(lock->l_ast_data);
                 } else {
                         inode = lock->l_ast_data;
-                        ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
-                                                D_INFO : D_WARNING,
-                                        lock, __FILE__, __func__, __LINE__,
-                                        "l_ast_data %p is bogus: magic %08x",
-                                        lock->l_ast_data, lli->lli_inode_magic);
+                        LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ?  D_INFO :
+                                         D_WARNING, lock, "l_ast_data %p is "
+                                         "bogus: magic %08x", lock->l_ast_data,
+                                         lli->lli_inode_magic);
                         inode = NULL;
                 }
         }
@@ -1238,7 +1270,7 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
         UNLOCK_INODE_MUTEX(inode);
         if (ia_valid & ATTR_SIZE)
                 UP_WRITE_I_ALLOC_SEM(inode);
-        cfs_down(&lli->lli_trunc_sem);
+        cfs_down_write(&lli->lli_trunc_sem);
         LOCK_INODE_MUTEX(inode);
         if (ia_valid & ATTR_SIZE)
                 DOWN_WRITE_I_ALLOC_SEM(inode);
@@ -1262,13 +1294,15 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
 
         if (ia_valid & ATTR_SIZE)
                 attr->ia_valid |= ATTR_SIZE;
-        if ((ia_valid & ATTR_SIZE) | 
-            ((ia_valid | ATTR_ATIME | ATTR_ATIME_SET) &&
-             LTIME_S(attr->ia_atime) < LTIME_S(attr->ia_ctime)) ||
-            ((ia_valid | ATTR_MTIME | ATTR_MTIME_SET) &&
-             LTIME_S(attr->ia_mtime) < LTIME_S(attr->ia_ctime)))
-                /* perform truncate and setting mtime/atime to past under PW
-                 * 0:EOF extent lock (new_size:EOF for truncate) */
+        if (ia_valid & (ATTR_SIZE |
+                        ATTR_ATIME | ATTR_ATIME_SET |
+                        ATTR_MTIME | ATTR_MTIME_SET))
+                /* on truncate and utimes send attributes to osts, setting
+                 * mtime/atime to past will be performed under PW 0:EOF extent
+                 * lock (new_size:EOF for truncate)
+                 * it may seem excessive to send mtime/atime updates to osts
+                 * when not setting times to past, but it is necessary due to
+                 * possible time de-synchronization */
                 rc = ll_setattr_ost(inode, attr);
         EXIT;
 out:
@@ -1277,7 +1311,7 @@ out:
                         rc1 = ll_setattr_done_writing(inode, op_data, mod);
                 ll_finish_md_op_data(op_data);
         }
-        cfs_up(&lli->lli_trunc_sem);
+        cfs_up_write(&lli->lli_trunc_sem);
         return rc ? rc : rc1;
 }
 
@@ -1364,10 +1398,10 @@ int ll_statfs(struct dentry *de, struct kstatfs *sfs)
         CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
         ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
 
-        /* For now we will always get up-to-date statfs values, but in the
-         * future we may allow some amount of caching on the client (e.g.
-         * from QOS or lprocfs updates). */
-        rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1, 0);
+        /* Some amount of caching on the client is allowed */
+        rc = ll_statfs_internal(sb, &osfs,
+                                cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
+                                0);
         if (rc)
                 return rc;
 
@@ -1579,6 +1613,9 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
                         /* Use old size assignment to avoid
                          * deadlock bz14138 & bz14326 */
                         inode->i_size = body->size;
+
+                        CDEBUG(D_VFSTRACE, "inode=%lu, updating i_size %llu\n",
+                               inode->i_ino, (unsigned long long)body->size);
                 }
 
                 if (body->valid & OBD_MD_FLBLOCKS)
@@ -1595,15 +1632,6 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
         }
 }
 
-static struct backing_dev_info ll_backing_dev_info = {
-        .ra_pages       = 0,    /* No readahead */
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
-        .capabilities   = 0,    /* Does contribute to dirty memory */
-#else
-        .memory_backed  = 0,    /* Does contribute to dirty memory */
-#endif
-};
-
 void ll_read_inode2(struct inode *inode, void *opaque)
 {
         struct lustre_md *md = opaque;
@@ -1629,6 +1657,10 @@ void ll_read_inode2(struct inode *inode, void *opaque)
 
         /* OIDEBUG(inode); */
 
+        /* initializing backing dev info. */
+        inode->i_mapping->backing_dev_info = &(s2lsi(inode->i_sb)->bdi);
+
+
         if (S_ISREG(inode->i_mode)) {
                 struct ll_sb_info *sbi = ll_i2sbi(inode);
                 inode->i_op = &ll_file_inode_operations;
@@ -1649,9 +1681,6 @@ void ll_read_inode2(struct inode *inode, void *opaque)
                 init_special_inode(inode, inode->i_mode,
                                    kdev_t_to_nr(inode->i_rdev));
 
-                /* initializing backing dev info. */
-                inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
-
                 EXIT;
         }
 }
@@ -2082,9 +2111,6 @@ int ll_show_options(struct seq_file *seq, struct vfsmount *vfs)
         if (sbi->ll_flags & LL_SBI_USER_XATTR)
                 seq_puts(seq, ",user_xattr");
 
-        if (sbi->ll_flags & LL_SBI_ACL)
-                seq_puts(seq, ",acl");
-
         if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
                 seq_puts(seq, ",lazystatfs");