Whamcloud - gitweb
LU-15971 llite: implicit default LMV inherit
[fs/lustre-release.git] / lustre / llite / namei.c
index 15f6cea..bfa031b 100644 (file)
@@ -750,10 +750,13 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
 
        if (!it_disposition(it, DISP_LOOKUP_NEG)) {
                /* We have the "lookup" lock, so unhide dentry */
-               if (bits & MDS_INODELOCK_LOOKUP) {
+               if (bits & MDS_INODELOCK_LOOKUP)
                        d_lustre_revalidate(*de);
-                       ll_update_dir_depth(parent, (*de)->d_inode);
-               }
+               /* open may not fetch LOOKUP lock, update dir depth/dmv anyway
+                * in case it's used uninitialized.
+                */
+               if (S_ISDIR(inode->i_mode))
+                       ll_update_dir_depth_dmv(parent, *de);
 
                if (encrypt) {
                        rc = llcrypt_prepare_readdir(inode);
@@ -1449,7 +1452,8 @@ static int ll_create_it(struct inode *dir, struct dentry *dentry,
        ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, inode, it, &bits);
        if (bits & MDS_INODELOCK_LOOKUP) {
                d_lustre_revalidate(dentry);
-               ll_update_dir_depth(dir, inode);
+               if (S_ISDIR(inode->i_mode))
+                       ll_update_dir_depth_dmv(dir, dentry);
        }
 
        RETURN(0);
@@ -1543,6 +1547,9 @@ static int ll_new_node(struct inode *dir, struct dentry *dchild,
        struct ll_sb_info *sbi = ll_i2sbi(dir);
        struct llcrypt_str *disk_link = NULL;
        bool encrypt = false;
+       struct lmv_user_md *lum = NULL;
+       const void *data = NULL;
+       size_t datalen = 0;
        int err;
 
        ENTRY;
@@ -1551,6 +1558,8 @@ static int ll_new_node(struct inode *dir, struct dentry *dchild,
                rdev = 0;
                if (!disk_link)
                        RETURN(-EINVAL);
+               data = disk_link->name;
+               datalen = disk_link->len;
        }
 
 again:
@@ -1559,8 +1568,36 @@ again:
        if (IS_ERR(op_data))
                GOTO(err_exit, err = PTR_ERR(op_data));
 
-       if (S_ISDIR(mode))
+       if (S_ISDIR(mode)) {
                ll_qos_mkdir_prep(op_data, dir);
+               if ((exp_connect_flags2(ll_i2mdexp(dir)) &
+                    OBD_CONNECT2_DMV_IMP_INHERIT) &&
+                   op_data->op_default_mea1 && !lum) {
+                       const struct lmv_stripe_md *lsm;
+
+                       /* once DMV_IMP_INHERIT is set, pack default LMV in
+                        * create request.
+                        */
+                       OBD_ALLOC_PTR(lum);
+                       if (!lum)
+                               GOTO(err_exit, err = -ENOMEM);
+
+                       lsm = op_data->op_default_mea1;
+                       lum->lum_magic = cpu_to_le32(lsm->lsm_md_magic);
+                       lum->lum_stripe_count =
+                               cpu_to_le32(lsm->lsm_md_stripe_count);
+                       lum->lum_stripe_offset =
+                               cpu_to_le32(lsm->lsm_md_master_mdt_index);
+                       lum->lum_hash_type =
+                               cpu_to_le32(lsm->lsm_md_hash_type);
+                       lum->lum_max_inherit = lsm->lsm_md_max_inherit;
+                       lum->lum_max_inherit_rr = lsm->lsm_md_max_inherit_rr;
+                       lum->lum_pool_name[0] = 0;
+                       op_data->op_bias |= MDS_CREATE_DEFAULT_LMV;
+                       data = lum;
+                       datalen = sizeof(*lum);
+               }
+       }
 
        if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
                err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
@@ -1621,11 +1658,13 @@ again:
                        dchild->d_sb->s_op->destroy_inode(fakeinode);
                        if (err)
                                GOTO(err_exit, err);
+
+                       data = disk_link->name;
+                       datalen = disk_link->len;
                }
        }
 
-       err = md_create(sbi->ll_md_exp, op_data, tgt ? disk_link->name : NULL,
-                       tgt ? disk_link->len : 0, mode,
+       err = md_create(sbi->ll_md_exp, op_data, data, datalen, mode,
                        from_kuid(&init_user_ns, current_fsuid()),
                        from_kgid(&init_user_ns, current_fsgid()),
                        current_cap(), rdev, &request);
@@ -1750,9 +1789,10 @@ again:
 err_exit:
        if (request != NULL)
                ptlrpc_req_finished(request);
-
        if (!IS_ERR_OR_NULL(op_data))
                ll_finish_md_op_data(op_data);
+       if (lum)
+               OBD_FREE_PTR(lum);
 
        RETURN(err);
 }