Whamcloud - gitweb
LU-6179 llite: remove LOCKAHEAD_OLD compatibility
[fs/lustre-release.git] / lustre / llite / dir.c
index 7946691..4f54260 100644 (file)
@@ -40,9 +40,7 @@
 #include <linux/version.h>
 #include <linux/security.h>
 #include <linux/user_namespace.h>
-#ifdef HAVE_UIDGID_HEADER
-# include <linux/uidgid.h>
-#endif
+#include <linux/uidgid.h>
 #include <linux/uaccess.h>
 #include <linux/buffer_head.h>   // for wait_on_buffer
 #include <linux/pagevec.h>
@@ -314,15 +312,16 @@ static int ll_iterate(struct file *filp, struct dir_context *ctx)
 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
 #endif
 {
-       struct inode            *inode  = file_inode(filp);
-       struct ll_file_data     *lfd    = LUSTRE_FPRIVATE(filp);
-       struct ll_sb_info       *sbi    = ll_i2sbi(inode);
-       int                     hash64  = sbi->ll_flags & LL_SBI_64BIT_HASH;
-       int                     api32   = ll_need_32bit_api(sbi);
-       struct md_op_data       *op_data;
-       struct lu_fid           pfid = { 0 };
-       __u64                   pos;
-       int                     rc;
+       struct inode *inode = file_inode(filp);
+       struct ll_file_data *lfd = filp->private_data;
+       struct ll_sb_info *sbi = ll_i2sbi(inode);
+       int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
+       int api32 = ll_need_32bit_api(sbi);
+       struct md_op_data *op_data;
+       struct lu_fid pfid = { 0 };
+       ktime_t kstart = ktime_get();
+       __u64 pos;
+       int rc;
        ENTRY;
 
        if (lfd != NULL)
@@ -330,8 +329,9 @@ static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
        else
                pos = 0;
 
-       CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
-              "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
+       CDEBUG(D_VFSTRACE,
+              "VFS Op:inode="DFID"(%p) pos/size%lu/%llu 32bit_api %d\n",
+              PFID(ll_inode2fid(inode)),
               inode, (unsigned long)pos, i_size_read(inode), api32);
 
        if (pos == MDS_DIR_END_OFF)
@@ -406,32 +406,12 @@ static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
 
 out:
        if (!rc)
-               ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
+               ll_stats_ops_tally(sbi, LPROC_LL_READDIR,
+                                  ktime_us_delta(ktime_get(), kstart));
 
        RETURN(rc);
 }
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
-static int ll_send_mgc_param(struct obd_export *mgc, char *string)
-{
-        struct mgs_send_param *msp;
-        int rc = 0;
-
-        OBD_ALLOC_PTR(msp);
-        if (!msp)
-                return -ENOMEM;
-
-       strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param));
-        rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
-                                sizeof(struct mgs_send_param), msp, NULL);
-        if (rc)
-                CERROR("Failed to set parameter: %d\n", rc);
-        OBD_FREE_PTR(msp);
-
-        return rc;
-}
-#endif
-
 /**
  * Create striped directory with specified stripe(@lump)
  *
@@ -463,7 +443,7 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
        int err;
        ENTRY;
 
-       if (unlikely(!lmv_magic_supported(lump->lum_magic)))
+       if (unlikely(!lmv_user_magic_supported(lump->lum_magic)))
                RETURN(-EINVAL);
 
        if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
@@ -488,7 +468,26 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
            !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD))
                RETURN(-ENOENT);
 
-       if (unlikely(!lmv_magic_supported(cpu_to_le32(lump->lum_magic))))
+       if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
+               if ((lump->lum_hash_type & LMV_HASH_TYPE_MASK) ==
+                    LMV_HASH_TYPE_CRUSH) {
+                       /* if server doesn't support 'crush' hash type,
+                        * switch to fnv_1a_64.
+                        */
+                       lump->lum_hash_type &= ~LMV_HASH_TYPE_MASK;
+                       lump->lum_hash_type |= LMV_HASH_TYPE_FNV_1A_64;
+               } else if ((lump->lum_hash_type & LMV_HASH_TYPE_MASK) ==
+                    LMV_HASH_TYPE_UNKNOWN) {
+                       /* from 2.14 MDT will choose default hash type if client
+                        * doesn't set a valid one, while old server doesn't
+                        * handle it.
+                        */
+                       lump->lum_hash_type &= ~LMV_HASH_TYPE_MASK;
+                       lump->lum_hash_type |= LMV_HASH_TYPE_DEFAULT;
+               }
+       }
+
+       if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
                lustre_swab_lmv_user_md(lump);
 
        if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
@@ -558,10 +557,6 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
        struct md_op_data *op_data;
        struct ptlrpc_request *req = NULL;
        int rc = 0;
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
-       struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
-       struct obd_device *mgc = lsi->lsi_mgc;
-#endif
        int lum_size;
        ENTRY;
 
@@ -623,70 +618,13 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
        if (rc)
                RETURN(rc);
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 13, 53, 0)
-       /*
-        * 2.9 server has stored filesystem default stripe in ROOT xattr,
-        * and it's stored into system config for backward compatibility.
-        *
-        * In the following we use the fact that LOV_USER_MAGIC_V1 and
-        * LOV_USER_MAGIC_V3 have the same initial fields so we do not
-        * need the make the distiction between the 2 versions
-        */
-       if (set_default && mgc->u.cli.cl_mgc_mgsexp &&
-           (lump == NULL ||
-            le32_to_cpu(lump->lmm_magic) == LOV_USER_MAGIC_V1 ||
-            le32_to_cpu(lump->lmm_magic) == LOV_USER_MAGIC_V3)) {
-               char *param = NULL;
-               char *buf;
-
-               OBD_ALLOC(param, MGS_PARAM_MAXLEN);
-               if (param == NULL)
-                       GOTO(end, rc = -ENOMEM);
-
-               buf = param;
-               /* Get fsname and assume devname to be -MDT0000. */
-               snprintf(buf, MGS_PARAM_MAXLEN, "%s-MDT0000.lov",
-                        sbi->ll_fsname);
-               buf += strlen(buf);
-
-               /* Set root stripesize */
-               snprintf(buf, MGS_PARAM_MAXLEN, ".stripesize=%u",
-                        lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
-               rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
-               if (rc)
-                       GOTO(end, rc);
-
-               /* Set root stripecount */
-               snprintf(buf, MGS_PARAM_MAXLEN, ".stripecount=%hd",
-                        lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
-               rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
-               if (rc)
-                       GOTO(end, rc);
-
-               /* Set root stripeoffset */
-               snprintf(buf, MGS_PARAM_MAXLEN, ".stripeoffset=%hd",
-                        lump ? le16_to_cpu(lump->lmm_stripe_offset) :
-                               (typeof(lump->lmm_stripe_offset))(-1));
-               rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
-
-end:
-               if (param != NULL)
-                       OBD_FREE(param, MGS_PARAM_MAXLEN);
-       }
-#endif
        RETURN(rc);
 }
 
-/**
- * This function will be used to get default LOV/LMV/Default LMV
- * @valid will be used to indicate which stripe it will retrieve
- *     OBD_MD_MEA              LMV stripe EA
- *     OBD_MD_DEFAULT_MEA      Default LMV stripe EA
- *     otherwise               Default LOV EA.
- * Each time, it can only retrieve 1 stripe EA
- **/
-int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
-                    struct ptlrpc_request **request, u64 valid)
+static int ll_dir_get_default_layout(struct inode *inode, void **plmm,
+                                    int *plmm_size,
+                                    struct ptlrpc_request **request, u64 valid,
+                                    enum get_default_layout_type type)
 {
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        struct mdt_body   *body;
@@ -694,6 +632,7 @@ int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
        struct ptlrpc_request *req = NULL;
        int rc, lmm_size;
        struct md_op_data *op_data;
+       struct lu_fid fid;
        ENTRY;
 
        rc = ll_get_default_mdsize(sbi, &lmm_size);
@@ -707,11 +646,19 @@ int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
                RETURN(PTR_ERR(op_data));
 
        op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
+
+       if (type == GET_DEFAULT_LAYOUT_ROOT) {
+               lu_root_fid(&op_data->op_fid1);
+               fid = op_data->op_fid1;
+       } else {
+               fid = *ll_inode2fid(inode);
+       }
+
        rc = md_getattr(sbi->ll_md_exp, op_data, &req);
        ll_finish_md_op_data(op_data);
        if (rc < 0) {
-               CDEBUG(D_INFO, "md_getattr failed on inode "
-                      DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
+               CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
+                      PFID(&fid), rc);
                GOTO(out, rc);
        }
 
@@ -773,6 +720,72 @@ out:
        return rc;
 }
 
+/**
+ * This function will be used to get default LOV/LMV/Default LMV
+ * @valid will be used to indicate which stripe it will retrieve.
+ * If the directory does not have its own default layout, then the
+ * function will request the default layout from root FID.
+ *     OBD_MD_MEA              LMV stripe EA
+ *     OBD_MD_DEFAULT_MEA      Default LMV stripe EA
+ *     otherwise               Default LOV EA.
+ * Each time, it can only retrieve 1 stripe EA
+ **/
+int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
+                            struct ptlrpc_request **request,
+                            struct ptlrpc_request **root_request,
+                            u64 valid)
+{
+       struct ptlrpc_request *req = NULL;
+       struct ptlrpc_request *root_req = NULL;
+       struct lov_mds_md *lmm = NULL;
+       int lmm_size = 0;
+       int rc = 0;
+       ENTRY;
+
+       rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
+                                      &req, valid, 0);
+       if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
+           !(valid & (OBD_MD_MEA|OBD_MD_DEFAULT_MEA)) && root_request != NULL)
+               rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
+                                              &root_req, valid,
+                                              GET_DEFAULT_LAYOUT_ROOT);
+
+       *plmm = lmm;
+       *plmm_size = lmm_size;
+       *request = req;
+       if (root_request != NULL)
+               *root_request = root_req;
+
+       RETURN(rc);
+}
+
+/**
+ * This function will be used to get default LOV/LMV/Default LMV
+ * @valid will be used to indicate which stripe it will retrieve
+ *     OBD_MD_MEA              LMV stripe EA
+ *     OBD_MD_DEFAULT_MEA      Default LMV stripe EA
+ *     otherwise               Default LOV EA.
+ * Each time, it can only retrieve 1 stripe EA
+ **/
+int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
+                    struct ptlrpc_request **request, u64 valid)
+{
+       struct ptlrpc_request *req = NULL;
+       struct lov_mds_md *lmm = NULL;
+       int lmm_size = 0;
+       int rc = 0;
+       ENTRY;
+
+       rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
+                                      &req, valid, 0);
+
+       *plmm = lmm;
+       *plmm_size = lmm_size;
+       *request = req;
+
+       RETURN(rc);
+}
+
 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
 {
        struct md_op_data       *op_data;
@@ -1403,7 +1416,7 @@ out_free:
                lum = (struct lmv_user_md *)data->ioc_inlbuf2;
                lumlen = data->ioc_inllen2;
 
-               if (!lmv_magic_supported(lum->lum_magic)) {
+               if (!lmv_user_magic_supported(lum->lum_magic)) {
                        CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
                               lum->lum_magic, -EINVAL);
                        GOTO(lmv_out_free, rc = -EINVAL);
@@ -1424,11 +1437,7 @@ out_free:
                        GOTO(lmv_out_free, rc = -EINVAL);
                }
 
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 50, 0)
-               mode = data->ioc_type != 0 ? data->ioc_type : S_IRWXUGO;
-#else
                mode = data->ioc_type;
-#endif
                rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode);
 lmv_out_free:
                OBD_FREE_LARGE(buf, len);
@@ -1464,9 +1473,9 @@ lmv_out_free:
 
                int set_default = 0;
 
-               CLASSERT(sizeof(struct lov_user_md_v3) >
-                        sizeof(struct lov_comp_md_v1));
-               CLASSERT(sizeof(*lumv3) == sizeof(*lumv3p));
+               BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
+                            sizeof(struct lov_comp_md_v1));
+               BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
                /* first try with v1 which is smaller than v3 */
                if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
                        RETURN(-EFAULT);
@@ -1505,6 +1514,7 @@ out:
                                        (struct lmv_user_md __user *)arg;
                struct lmv_user_md      lum;
                struct ptlrpc_request   *request = NULL;
+               struct ptlrpc_request   *root_request = NULL;
                union lmv_mds_md        *lmm = NULL;
                int                     lmmsize;
                u64                     valid = 0;
@@ -1530,8 +1540,8 @@ out:
                else
                        RETURN(-EINVAL);
 
-               rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
-                                     valid);
+               rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
+                                             &request, &root_request, valid);
                if (rc != 0)
                        GOTO(finish_req, rc);
 
@@ -1621,6 +1631,7 @@ out_tmp:
                OBD_FREE(tmp, lum_size);
 finish_req:
                ptlrpc_req_finished(request);
+               ptlrpc_req_finished(root_request);
                return rc;
        }
 
@@ -1665,6 +1676,7 @@ out_rmdir:
        case IOC_MDC_GETFILEINFO_OLD:
        case IOC_MDC_GETFILESTRIPE: {
                struct ptlrpc_request *request = NULL;
+               struct ptlrpc_request *root_request = NULL;
                struct lov_user_md __user *lump;
                struct lov_mds_md *lmm = NULL;
                struct mdt_body *body;
@@ -1686,8 +1698,9 @@ out_rmdir:
                        rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
                                                      &lmmsize, &request);
                } else {
-                       rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize,
-                                             &request, 0);
+                       rc = ll_dir_getstripe_default(inode, (void **)&lmm,
+                                                     &lmmsize, &request,
+                                                     &root_request, 0);
                }
 
                if (request) {
@@ -1826,6 +1839,7 @@ out_rmdir:
                EXIT;
 out_req:
                ptlrpc_req_finished(request);
+               ptlrpc_req_finished(root_request);
                if (filename)
                        ll_putname(filename);
                return rc;
@@ -2122,53 +2136,53 @@ out_detach:
 
 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
 {
-        struct inode *inode = file->f_mapping->host;
-        struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
-        struct ll_sb_info *sbi = ll_i2sbi(inode);
-        int api32 = ll_need_32bit_api(sbi);
-        loff_t ret = -EINVAL;
-        ENTRY;
+       struct inode *inode = file->f_mapping->host;
+       struct ll_file_data *fd = file->private_data;
+       struct ll_sb_info *sbi = ll_i2sbi(inode);
+       int api32 = ll_need_32bit_api(sbi);
+       loff_t ret = -EINVAL;
+       ENTRY;
 
        inode_lock(inode);
-        switch (origin) {
-                case SEEK_SET:
-                        break;
-                case SEEK_CUR:
-                        offset += file->f_pos;
-                        break;
-                case SEEK_END:
-                        if (offset > 0)
-                                GOTO(out, ret);
-                        if (api32)
-                                offset += LL_DIR_END_OFF_32BIT;
-                        else
-                                offset += LL_DIR_END_OFF;
-                        break;
-                default:
-                        GOTO(out, ret);
-        }
+       switch (origin) {
+       case SEEK_SET:
+               break;
+       case SEEK_CUR:
+               offset += file->f_pos;
+               break;
+       case SEEK_END:
+               if (offset > 0)
+                       GOTO(out, ret);
+               if (api32)
+                       offset += LL_DIR_END_OFF_32BIT;
+               else
+                       offset += LL_DIR_END_OFF;
+               break;
+       default:
+               GOTO(out, ret);
+       }
 
-        if (offset >= 0 &&
-            ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
-             (!api32 && offset <= LL_DIR_END_OFF))) {
-                if (offset != file->f_pos) {
-                        if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
-                            (!api32 && offset == LL_DIR_END_OFF))
+       if (offset >= 0 &&
+           ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
+            (!api32 && offset <= LL_DIR_END_OFF))) {
+               if (offset != file->f_pos) {
+                       if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
+                           (!api32 && offset == LL_DIR_END_OFF))
                                fd->lfd_pos = MDS_DIR_END_OFF;
-                        else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
+                       else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
                                fd->lfd_pos = offset << 32;
-                        else
+                       else
                                fd->lfd_pos = offset;
-                        file->f_pos = offset;
-                        file->f_version = 0;
-                }
-                ret = offset;
-        }
-        GOTO(out, ret);
+                       file->f_pos = offset;
+                       file->f_version = 0;
+               }
+               ret = offset;
+       }
+       GOTO(out, ret);
 
 out:
        inode_unlock(inode);
-        return ret;
+       return ret;
 }
 
 static int ll_dir_open(struct inode *inode, struct file *file)