Whamcloud - gitweb
LU-15216 lmv: improve MDT QOS space balance
[fs/lustre-release.git] / lustre / llite / namei.c
index e5540d3..80b8460 100644 (file)
@@ -49,7 +49,7 @@
 static int ll_create_it(struct inode *dir, struct dentry *dentry,
                        struct lookup_intent *it,
                        void *secctx, __u32 secctxlen, bool encrypt,
-                       void *encctx, __u32 encctxlen);
+                       void *encctx, __u32 encctxlen, unsigned int open_flags);
 
 /* called from iget5_locked->find_inode() under inode_lock spinlock */
 static int ll_test_inode(struct inode *inode, void *opaque)
@@ -257,7 +257,7 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
        }
 
        if (bits & MDS_INODELOCK_XATTR) {
-               ll_xattr_cache_destroy(inode);
+               ll_xattr_cache_empty(inode);
                bits &= ~MDS_INODELOCK_XATTR;
        }
 
@@ -908,37 +908,20 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
                        *secctxlen = 0;
        }
        if (it->it_op & IT_CREAT && encrypt) {
-               /* Volatile file name may look like:
-                * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
-                * where fd is opened descriptor of reference file.
-                */
                if (unlikely(filename_is_volatile(dentry->d_name.name,
                                                  dentry->d_name.len, NULL))) {
+                       /* get encryption context from reference file */
                        int ctx_size = LLCRYPT_ENC_CTX_SIZE;
                        struct lustre_sb_info *lsi;
                        struct file *ref_file;
                        struct inode *ref_inode;
-                       char *p, *q, *fd_str;
                        void *ctx;
-                       int fd;
-
-                       p = strnstr(dentry->d_name.name, ":fd=",
-                                   dentry->d_name.len);
-                       if (!p || strlen(p + 4) == 0)
-                               GOTO(out, retval = ERR_PTR(-EINVAL));
 
-                       q = strchrnul(p + 4, ':');
-                       fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
-                       if (!fd_str)
-                               GOTO(out, retval = ERR_PTR(-ENOMEM));
-                       rc = kstrtouint(fd_str, 10, &fd);
-                       kfree(fd_str);
+                       rc = volatile_ref_file(dentry->d_name.name,
+                                              dentry->d_name.len,
+                                              &ref_file);
                        if (rc)
-                               GOTO(inherit, rc = -EINVAL);
-
-                       ref_file = fget(fd);
-                       if (!ref_file)
-                               GOTO(inherit, rc = -EINVAL);
+                               GOTO(out, retval = ERR_PTR(rc));
 
                        ref_inode = file_inode(ref_file);
                        if (!ref_inode) {
@@ -984,7 +967,6 @@ getctx:
                                       op_data->op_file_encctx_size);
                                OBD_FREE(ctx, ctx_size);
                        }
-
                } else {
 inherit:
                        rc = llcrypt_inherit_context(parent, NULL, op_data,
@@ -1252,7 +1234,14 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
                if (rc)
                        GOTO(out_release, rc);
                if (open_flags & O_CREAT) {
-                       if (!llcrypt_has_encryption_key(dir))
+                       /* For migration or mirroring without enc key, we still
+                        * need to be able to create a volatile file.
+                        */
+                       if (!llcrypt_has_encryption_key(dir) &&
+                           (!filename_is_volatile(dentry->d_name.name,
+                                                  dentry->d_name.len, NULL) ||
+                           (open_flags & O_FILE_ENC) != O_FILE_ENC ||
+                           !(open_flags & O_DIRECT)))
                                GOTO(out_release, rc = -ENOKEY);
                        encrypt = true;
                }
@@ -1283,7 +1272,8 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
                if (it_disposition(it, DISP_OPEN_CREATE)) {
                        /* Dentry instantiated in ll_create_it. */
                        rc = ll_create_it(dir, dentry, it, secctx, secctxlen,
-                                         encrypt, encctx, encctxlen);
+                                         encrypt, encctx, encctxlen,
+                                         open_flags);
                        ll_security_release_secctx(secctx, secctxlen);
                        llcrypt_free_ctx(encctx, encctxlen);
                        if (rc) {
@@ -1409,7 +1399,7 @@ static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
 static int ll_create_it(struct inode *dir, struct dentry *dentry,
                        struct lookup_intent *it,
                        void *secctx, __u32 secctxlen, bool encrypt,
-                       void *encctx, __u32 encctxlen)
+                       void *encctx, __u32 encctxlen, unsigned int open_flags)
 {
        struct inode *inode;
        __u64 bits = 0;
@@ -1444,7 +1434,18 @@ static int ll_create_it(struct inode *dir, struct dentry *dentry,
        d_instantiate(dentry, inode);
 
        if (encrypt) {
-               rc = ll_set_encflags(inode, encctx, encctxlen, true);
+               bool preload = true;
+
+               /* For migration or mirroring without enc key, we
+                * create a volatile file without enc context.
+                */
+               if (!llcrypt_has_encryption_key(dir) &&
+                   filename_is_volatile(dentry->d_name.name,
+                                        dentry->d_name.len, NULL) &&
+                   (open_flags & O_FILE_ENC) == O_FILE_ENC &&
+                   open_flags & O_DIRECT)
+                       preload = false;
+               rc = ll_set_encflags(inode, encctx, encctxlen, preload);
                if (rc)
                        RETURN(rc);
        }
@@ -1494,7 +1495,7 @@ static void ll_qos_mkdir_prep(struct md_op_data *op_data, struct inode *dir)
        struct ll_inode_info *lli = ll_i2info(dir);
        struct lmv_stripe_md *lsm;
 
-       op_data->op_dir_depth = lli->lli_depth;
+       op_data->op_dir_depth = lli->lli_dir_depth;
 
        /* parent directory is striped */
        if (unlikely(lli->lli_lsm_md))
@@ -1523,11 +1524,11 @@ static void ll_qos_mkdir_prep(struct md_op_data *op_data, struct inode *dir)
 
        if (lsm->lsm_md_max_inherit != LMV_INHERIT_NONE &&
            (lsm->lsm_md_max_inherit == LMV_INHERIT_UNLIMITED ||
-            lsm->lsm_md_max_inherit >= lli->lli_depth)) {
+            lsm->lsm_md_max_inherit >= lli->lli_dir_depth)) {
                op_data->op_flags |= MF_QOS_MKDIR;
                if (lsm->lsm_md_max_inherit_rr != LMV_INHERIT_RR_NONE &&
                    (lsm->lsm_md_max_inherit_rr == LMV_INHERIT_RR_UNLIMITED ||
-                    lsm->lsm_md_max_inherit_rr >= lli->lli_depth))
+                    lsm->lsm_md_max_inherit_rr >= lli->lli_dir_depth))
                        op_data->op_flags |= MF_RR_MKDIR;
                CDEBUG(D_INODE, DFID" requests qos mkdir %#x\n",
                       PFID(&lli->lli_fid), op_data->op_flags);
@@ -1967,8 +1968,11 @@ static int ll_rmdir(struct inode *dir, struct dentry *dchild)
                 * immediately.
                 */
                body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
-               if (body->mbo_valid & OBD_MD_FLNLINK)
+               if (body->mbo_valid & OBD_MD_FLNLINK) {
+                       spin_lock(&dchild->d_inode->i_lock);
                        set_nlink(dchild->d_inode, body->mbo_nlink);
+                       spin_unlock(&dchild->d_inode->i_lock);
+               }
        }
 
        ptlrpc_req_finished(request);
@@ -2055,8 +2059,11 @@ static int ll_unlink(struct inode *dir, struct dentry *dchild)
         * the link count so the inode can be freed immediately.
         */
        body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
-       if (body->mbo_valid & OBD_MD_FLNLINK)
+       if (body->mbo_valid & OBD_MD_FLNLINK) {
+               spin_lock(&dchild->d_inode->i_lock);
                set_nlink(dchild->d_inode, body->mbo_nlink);
+               spin_unlock(&dchild->d_inode->i_lock);
+       }
 
        ll_update_times(request, dir);