Whamcloud - gitweb
LU-15910 llite: use max default EA size to get default LMV
[fs/lustre-release.git] / lustre / llite / dir.c
index fedc5bb..1892c65 100644 (file)
@@ -49,7 +49,6 @@
 #include <obd_support.h>
 #include <obd_class.h>
 #include <uapi/linux/lustre/lustre_ioctl.h>
-#include <uapi/linux/llcrypt.h>
 #include <lustre_lib.h>
 #include <lustre_dlm.h>
 #include <lustre_fid.h>
@@ -167,7 +166,8 @@ void ll_release_page(struct inode *inode, struct page *page,
 
        /* Always remove the page for striped dir, because the page is
         * built from temporarily in LMV layer */
-       if (inode && ll_dir_striped(inode)) {
+       if (inode && S_ISDIR(inode->i_mode) &&
+           lmv_dir_striped(ll_i2info(inode)->lli_lsm_md)) {
                __free_page(page);
                return;
        }
@@ -469,9 +469,10 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
 
        if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
                CDEBUG(D_VFSTRACE,
-                      "VFS Op:inode="DFID"(%p) name %s stripe_offset %d, stripe_count: %u\n",
+                      "VFS Op:inode="DFID"(%p) name=%s stripe_offset=%d stripe_count=%u, hash_type=%x\n",
                       PFID(ll_inode2fid(parent)), parent, dirname,
-                      (int)lump->lum_stripe_offset, lump->lum_stripe_count);
+                      (int)lump->lum_stripe_offset, lump->lum_stripe_count,
+                      lump->lum_hash_type);
        } else {
                struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lump;
 
@@ -492,7 +493,9 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
        /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle
         * unknown hash if client doesn't set a valid one. switch to fnv_1a_64.
         */
-       if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
+       if (CFS_FAIL_CHECK(OBD_FAIL_LMV_UNKNOWN_STRIPE)) {
+               lump->lum_hash_type = cfs_fail_val;
+       } else if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
                enum lmv_hash_type type = lump->lum_hash_type &
                                          LMV_HASH_TYPE_MASK;
 
@@ -522,7 +525,7 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
 
        if (ll_sbi_has_encrypt(sbi) &&
            (IS_ENCRYPTED(parent) ||
-           unlikely(llcrypt_dummy_context_enabled(parent)))) {
+            unlikely(ll_sb_has_test_dummy_encryption(parent->i_sb)))) {
                err = llcrypt_get_encryption_info(parent);
                if (err)
                        GOTO(out_op_data, err);
@@ -687,27 +690,23 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
        RETURN(rc);
 }
 
-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)
+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;
        struct lov_mds_md *lmm = NULL;
        struct ptlrpc_request *req = NULL;
-       int rc, lmm_size;
+       int lmm_size = OBD_MAX_DEFAULT_EA_SIZE;
        struct md_op_data *op_data;
        struct lu_fid fid;
-       ENTRY;
+       int rc;
 
-       rc = ll_get_default_mdsize(sbi, &lmm_size);
-       if (rc)
-               RETURN(rc);
+       ENTRY;
 
-       op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
-                                    0, lmm_size, LUSTRE_OPC_ANY,
-                                    NULL);
+       op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, lmm_size,
+                                    LUSTRE_OPC_ANY, NULL);
        if (IS_ERR(op_data))
                RETURN(PTR_ERR(op_data));
 
@@ -1237,34 +1236,33 @@ int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
                else
                        RETURN(-EINVAL);
 
-                switch (valid) {
-                case QC_MDTIDX:
-                        rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
-                                           sizeof(*qctl), qctl, NULL);
-                        break;
-                case QC_OSTIDX:
-                        rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
-                                           sizeof(*qctl), qctl, NULL);
-                        break;
-                case QC_UUID:
-                        rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
-                                           sizeof(*qctl), qctl, NULL);
-                        if (rc == -EAGAIN)
-                                rc = obd_iocontrol(OBD_IOC_QUOTACTL,
-                                                   sbi->ll_dt_exp,
-                                                   sizeof(*qctl), qctl, NULL);
-                        break;
-                default:
-                        rc = -EINVAL;
-                        break;
-                }
-
-                if (rc)
-                        RETURN(rc);
+               switch (valid) {
+               case QC_MDTIDX:
+                       rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
+                                          sizeof(*qctl), qctl, NULL);
+                       break;
+               case QC_OSTIDX:
+                       rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
+                                          sizeof(*qctl), qctl, NULL);
+                       break;
+               case QC_UUID:
+                       rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
+                                          sizeof(*qctl), qctl, NULL);
+                       if (rc == -EAGAIN)
+                               rc = obd_iocontrol(OBD_IOC_QUOTACTL,
+                                                  sbi->ll_dt_exp,
+                                                  sizeof(*qctl), qctl, NULL);
+                       break;
+               default:
+                       rc = -EINVAL;
+                       break;
+               }
 
-                qctl->qc_cmd = cmd;
-        } else {
-                struct obd_quotactl *oqctl;
+               qctl->qc_cmd = cmd;
+               if (rc)
+                       RETURN(rc);
+       } else {
+               struct obd_quotactl *oqctl;
                int oqctl_len = sizeof(*oqctl);
 
                if (LUSTRE_Q_CMD_IS_POOL(cmd))
@@ -1651,33 +1649,51 @@ out:
 
                                lum = (struct lmv_user_md *)lmm;
                                lli = ll_i2info(inode);
-                               if (lum->lum_max_inherit == LMV_INHERIT_NONE ||
-                                   (lum->lum_max_inherit > 0 &&
-                                    lum->lum_max_inherit < lli->lli_dir_depth))
-                                       GOTO(finish_req, rc = -ENODATA);
-
-                               if (lum->lum_max_inherit ==
-                                   lli->lli_dir_depth) {
-                                       lum->lum_max_inherit = LMV_INHERIT_NONE;
-                                       lum->lum_max_inherit_rr =
-                                               LMV_INHERIT_RR_NONE;
-                                       goto out_copy;
-                               }
-                               if (lum->lum_max_inherit > lli->lli_dir_depth &&
-                                   lum->lum_max_inherit <= LMV_INHERIT_MAX)
+                               if (lum->lum_max_inherit !=
+                                   LMV_INHERIT_UNLIMITED) {
+                                       if (lum->lum_max_inherit ==
+                                               LMV_INHERIT_NONE ||
+                                           lum->lum_max_inherit <
+                                               LMV_INHERIT_END ||
+                                           lum->lum_max_inherit >
+                                               LMV_INHERIT_MAX ||
+                                           lum->lum_max_inherit <
+                                               lli->lli_dir_depth)
+                                               GOTO(finish_req, rc = -ENODATA);
+
+                                       if (lum->lum_max_inherit ==
+                                           lli->lli_dir_depth) {
+                                               lum->lum_max_inherit =
+                                                       LMV_INHERIT_NONE;
+                                               lum->lum_max_inherit_rr =
+                                                       LMV_INHERIT_RR_NONE;
+                                               goto out_copy;
+                                       }
+
                                        lum->lum_max_inherit -=
                                                lli->lli_dir_depth;
+                               }
 
-                               if (lum->lum_max_inherit_rr >
-                                       lli->lli_dir_depth &&
-                                   lum->lum_max_inherit_rr <=
-                                       LMV_INHERIT_RR_MAX)
-                                       lum->lum_max_inherit_rr -=
-                                               lli->lli_dir_depth;
-                               else if (lum->lum_max_inherit_rr ==
+                               if (lum->lum_max_inherit_rr !=
+                                       LMV_INHERIT_RR_UNLIMITED) {
+                                       if (lum->lum_max_inherit_rr ==
+                                               LMV_INHERIT_NONE ||
+                                           lum->lum_max_inherit_rr <
+                                               LMV_INHERIT_RR_END ||
+                                           lum->lum_max_inherit_rr >
+                                               LMV_INHERIT_RR_MAX ||
+                                           lum->lum_max_inherit_rr <=
+                                               lli->lli_dir_depth) {
+                                               lum->lum_max_inherit_rr =
+                                                       LMV_INHERIT_RR_NONE;
+                                               goto out_copy;
+                                       }
+
+                                       if (lum->lum_max_inherit_rr >
                                                lli->lli_dir_depth)
-                                       lum->lum_max_inherit_rr =
-                                               LMV_INHERIT_RR_NONE;
+                                               lum->lum_max_inherit_rr -=
+                                                       lli->lli_dir_depth;
+                               }
                        }
 out_copy:
                        if (copy_to_user(ulmv, lmm, lmmsize))
@@ -2013,7 +2029,7 @@ out_req:
                }
 
                rc = quotactl_ioctl(inode->i_sb, qctl);
-               if (rc == 0 &&
+               if ((rc == 0 || rc == -ENODATA) &&
                    copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
                         rc = -EFAULT;