Whamcloud - gitweb
LU-7623 lov: Get rid of an ugly statfs hack in lov_iocontrol
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index 90176b5..cf17367 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -63,9 +63,6 @@
 
 struct kmem_cache *ll_file_data_slab;
 
-static struct list_head ll_super_blocks = LIST_HEAD_INIT(ll_super_blocks);
-static DEFINE_SPINLOCK(ll_sb_lock);
-
 #ifndef log2
 #define log2(n) ffz(~(n))
 #endif
@@ -113,10 +110,6 @@ static struct ll_sb_info *ll_init_sbi(void)
         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
         CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
 
-       spin_lock(&ll_sb_lock);
-       list_add_tail(&sbi->ll_list, &ll_super_blocks);
-       spin_unlock(&ll_sb_lock);
-
         sbi->ll_flags |= LL_SBI_VERBOSE;
 #ifdef ENABLE_CHECKSUM
         sbi->ll_flags |= LL_SBI_CHECKSUM;
@@ -156,9 +149,6 @@ static void ll_free_sbi(struct super_block *sb)
        ENTRY;
 
        if (sbi != NULL) {
-               spin_lock(&ll_sb_lock);
-               list_del(&sbi->ll_list);
-               spin_unlock(&ll_sb_lock);
                if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
                        cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
                if (sbi->ll_cache != NULL) {
@@ -218,7 +208,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
                                  OBD_CONNECT_FLOCK_DEAD |
                                  OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
                                  OBD_CONNECT_OPEN_BY_FID |
-                                 OBD_CONNECT_DIR_STRIPE;
+                                 OBD_CONNECT_DIR_STRIPE |
+                                 OBD_CONNECT_BULK_MBITS;
 
 #ifdef HAVE_LRU_RESIZE_SUPPORT
         if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
@@ -405,7 +396,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
                                  OBD_CONNECT_EINPROGRESS |
                                  OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
                                  OBD_CONNECT_LAYOUTLOCK |
-                                 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK;
+                                 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
+                                 OBD_CONNECT_BULK_MBITS;
 
         if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
                 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
@@ -836,6 +828,18 @@ static int ll_options(char *options, int *flags)
                         *flags &= ~tmp;
                         goto next;
                 }
+               tmp = ll_set_opt("context", s1, 1);
+               if (tmp)
+                       goto next;
+               tmp = ll_set_opt("fscontext", s1, 1);
+               if (tmp)
+                       goto next;
+               tmp = ll_set_opt("defcontext", s1, 1);
+               if (tmp)
+                       goto next;
+               tmp = ll_set_opt("rootcontext", s1, 1);
+               if (tmp)
+                       goto next;
                tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT);
                if (tmp) {
                        *flags |= tmp;
@@ -1007,7 +1011,11 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
        if (err)
                GOTO(out_free, err);
        lsi->lsi_flags |= LSI_BDI_INITIALIZED;
+#ifdef HAVE_BDI_CAP_MAP_COPY
        lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
+#else
+       lsi->lsi_bdi.capabilities = 0;
+#endif
        err = ll_bdi_register(&lsi->lsi_bdi);
        if (err)
                GOTO(out_free, err);
@@ -1058,17 +1066,19 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
        sbi->ll_client_common_fill_super_succeeded = 1;
 
 out_free:
-        if (md)
-                OBD_FREE(md, strlen(lprof->lp_md) + instlen + 2);
-        if (dt)
-                OBD_FREE(dt, strlen(lprof->lp_dt) + instlen + 2);
-        if (err)
-                ll_put_super(sb);
-        else if (sbi->ll_flags & LL_SBI_VERBOSE)
-                LCONSOLE_WARN("Mounted %s\n", profilenm);
+       if (md)
+               OBD_FREE(md, strlen(lprof->lp_md) + instlen + 2);
+       if (dt)
+               OBD_FREE(dt, strlen(lprof->lp_dt) + instlen + 2);
+       if (lprof != NULL)
+               class_put_profile(lprof);
+       if (err)
+               ll_put_super(sb);
+       else if (sbi->ll_flags & LL_SBI_VERBOSE)
+               LCONSOLE_WARN("Mounted %s\n", profilenm);
 
-        OBD_FREE_PTR(cfg);
-        RETURN(err);
+       OBD_FREE_PTR(cfg);
+       RETURN(err);
 } /* ll_fill_super */
 
 void ll_put_super(struct super_block *sb)
@@ -1177,7 +1187,7 @@ struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
        return inode;
 }
 
-static void ll_dir_clear_lsm_md(struct inode *inode)
+void ll_dir_clear_lsm_md(struct inode *inode)
 {
        struct ll_inode_info *lli = ll_i2info(inode);
 
@@ -1221,9 +1231,11 @@ static struct inode *ll_iget_anon_dir(struct super_block *sb,
                LTIME_S(inode->i_ctime) = 0;
                inode->i_rdev = 0;
 
+#ifdef HAVE_BACKING_DEV_INFO
                /* initializing backing dev info. */
                inode->i_mapping->backing_dev_info =
                                                &s2lsi(inode->i_sb)->lsi_bdi;
+#endif
                inode->i_op = &ll_dir_inode_operations;
                inode->i_fop = &ll_dir_operations;
                lli->lli_fid = *fid;
@@ -1323,15 +1335,42 @@ static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
 
        /* set the directory layout */
        if (lli->lli_lsm_md == NULL) {
+               struct cl_attr  *attr;
 
                rc = ll_init_lsm_md(inode, md);
                if (rc != 0)
                        RETURN(rc);
 
-               lli->lli_lsm_md = lsm;
-               /* set lsm_md to NULL, so the following free lustre_md
+               /* set md->lmv to NULL, so the following free lustre_md
                 * will not free this lsm */
                md->lmv = NULL;
+               lli->lli_lsm_md = lsm;
+
+               OBD_ALLOC_PTR(attr);
+               if (attr == NULL)
+                       RETURN(-ENOMEM);
+
+               /* validate the lsm */
+               rc = md_merge_attr(ll_i2mdexp(inode), lsm, attr,
+                                  ll_md_blocking_ast);
+               if (rc != 0) {
+                       OBD_FREE_PTR(attr);
+                       RETURN(rc);
+               }
+
+               if (md->body->mbo_valid & OBD_MD_FLNLINK)
+                       md->body->mbo_nlink = attr->cat_nlink;
+               if (md->body->mbo_valid & OBD_MD_FLSIZE)
+                       md->body->mbo_size = attr->cat_size;
+               if (md->body->mbo_valid & OBD_MD_FLATIME)
+                       md->body->mbo_atime = attr->cat_atime;
+               if (md->body->mbo_valid & OBD_MD_FLCTIME)
+                       md->body->mbo_ctime = attr->cat_ctime;
+               if (md->body->mbo_valid & OBD_MD_FLMTIME)
+                       md->body->mbo_mtime = attr->cat_mtime;
+
+               OBD_FREE_PTR(attr);
+
                CDEBUG(D_INODE, "Set lsm %p magic %x to "DFID"\n", lsm,
                       lsm->lsm_md_magic, PFID(ll_inode2fid(inode)));
                RETURN(0);
@@ -1558,7 +1597,8 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
        }
 
         /* We mark all of the fields "set" so MDS/OST does not re-set them */
-        if (attr->ia_valid & ATTR_CTIME) {
+       if (!(attr->ia_valid & ATTR_CTIME_SET) &&
+           (attr->ia_valid & ATTR_CTIME)) {
                 attr->ia_ctime = CFS_CURRENT_TIME;
                 attr->ia_valid |= ATTR_CTIME_SET;
         }
@@ -1591,15 +1631,16 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
        if (op_data == NULL)
                GOTO(out, rc = -ENOMEM);
 
-       op_data->op_attr = *attr;
-
        if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
                /* If we are changing file size, file content is
                 * modified, flag it. */
                attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
                op_data->op_bias |= MDS_DATA_MODIFIED;
+               ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
        }
 
+       op_data->op_attr = *attr;
+
        rc = ll_md_setattr(dentry, op_data);
        if (rc)
                GOTO(out, rc);
@@ -1609,7 +1650,8 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
 
        if (attr->ia_valid & (ATTR_SIZE |
                              ATTR_ATIME | ATTR_ATIME_SET |
-                             ATTR_MTIME | ATTR_MTIME_SET)) {
+                             ATTR_MTIME | ATTR_MTIME_SET |
+                             ATTR_CTIME | ATTR_CTIME_SET)) {
                /* For truncate and utimes sending attributes to OSTs, setting
                 * mtime/atime to the past will be performed under PW [0:EOF]
                 * extent lock (new_size:EOF for truncate).  It may seem
@@ -1640,8 +1682,13 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
                int rc2;
 
                rc2 = ll_hsm_state_set(inode, &hss);
+               /* truncate and write can happen at the same time, so that
+                * the file can be set modified even though the file is not
+                * restored from released state, and ll_hsm_state_set() is
+                * not applicable for the file, and rc2 < 0 is normal in this
+                * case. */
                if (rc2 < 0)
-                       CERROR(DFID "HSM set dirty failed: rc2 = %d\n",
+                       CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
                               PFID(ll_inode2fid(inode)), rc2);
        }
 
@@ -1909,8 +1956,14 @@ int ll_update_inode(struct inode *inode, struct lustre_md *md)
        }
 
        if (body->mbo_valid & OBD_MD_TSTATE) {
+               /* Set LLIF_FILE_RESTORING if restore ongoing and
+                * clear it when done to ensure to start again
+                * glimpsing updated attrs
+                */
                if (body->mbo_t_state & MS_RESTORE)
                        ll_file_set_flag(lli, LLIF_FILE_RESTORING);
+               else
+                       ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
        }
 
        return 0;
@@ -1940,10 +1993,10 @@ int ll_read_inode2(struct inode *inode, void *opaque)
 
         /* OIDEBUG(inode); */
 
-        /* initializing backing dev info. */
-        inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
-
-
+#ifdef HAVE_BACKING_DEV_INFO
+       /* initializing backing dev info. */
+       inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
+#endif
         if (S_ISREG(inode->i_mode)) {
                 struct ll_sb_info *sbi = ll_i2sbi(inode);
                 inode->i_op = &ll_file_inode_operations;
@@ -2305,7 +2358,6 @@ int ll_obd_statfs(struct inode *inode, void __user *arg)
         char *buf = NULL;
         struct obd_ioctl_data *data = NULL;
         __u32 type;
-       __u32 __user flags;     /* not user, but obd_iocontrol is abused */
         int len = 0, rc;
 
         if (!inode || !(sbi = ll_i2sbi(inode)))
@@ -2334,8 +2386,7 @@ int ll_obd_statfs(struct inode *inode, void __user *arg)
         else
                 GOTO(out_statfs, rc = -ENODEV);
 
-       flags = (type & LL_STATFS_NODELAY) ? OBD_STATFS_NODELAY : 0;
-       rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, &flags);
+       rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
         if (rc)
                 GOTO(out_statfs, rc);
 out_statfs: