Whamcloud - gitweb
LU-12321 mdc: allow ELC for DOM file unlink
[fs/lustre-release.git] / lustre / llite / namei.c
index 7e46d5f..edcaade 100644 (file)
@@ -38,9 +38,7 @@
 #include <linux/pagemap.h>
 #include <linux/security.h>
 #include <linux/user_namespace.h>
-#ifdef HAVE_UIDGID_HEADER
-# include <linux/uidgid.h>
-#endif
+#include <linux/uidgid.h>
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
@@ -205,6 +203,12 @@ static int ll_dom_lock_cancel(struct inode *inode, struct ldlm_lock *lock)
 
        /* reach MDC layer to flush data under  the DoM ldlm lock */
        rc = cl_object_flush(env, lli->lli_clob, lock);
+       if (rc == -ENODATA) {
+               CDEBUG(D_INODE, "inode "DFID" layout has no DoM stripe\n",
+                      PFID(ll_inode2fid(inode)));
+               /* most likely result of layout change, do nothing */
+               rc = 0;
+       }
 
        cl_env_put(env, &refcheck);
        RETURN(rc);
@@ -301,7 +305,7 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
        lli = ll_i2info(inode);
 
        if (bits & MDS_INODELOCK_UPDATE)
-               lli->lli_update_atime = 1;
+               ll_file_set_flag(lli, LLIF_UPDATE_ATIME);
 
        if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
                CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, "
@@ -426,11 +430,10 @@ int ll_md_need_convert(struct ldlm_lock *lock)
        return !!(bits);
 }
 
-int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
+int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *ld,
                       void *data, int flag)
 {
        struct lustre_handle lockh;
-       __u64 bits = lock->l_policy_data.l_inodebits.bits;
        int rc;
 
        ENTRY;
@@ -440,17 +443,21 @@ int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
        {
                __u64 cancel_flags = LCF_ASYNC;
 
-               if (ll_md_need_convert(lock)) {
-                       cancel_flags |= LCF_CONVERT;
-                       /* For lock convert some cancel actions may require
-                        * this lock with non-dropped canceled bits, e.g. page
-                        * flush for DOM lock. So call ll_lock_cancel_bits()
-                        * here while canceled bits are still set.
-                        */
-                       bits = lock->l_policy_data.l_inodebits.cancel_bits;
-                       if (bits & MDS_INODELOCK_DOM)
-                               ll_lock_cancel_bits(lock, MDS_INODELOCK_DOM);
+               /* if lock convert is not needed then still have to
+                * pass lock via ldlm_cli_convert() to keep all states
+                * correct, set cancel_bits to full lock bits to cause
+                * full cancel to happen.
+                */
+               if (!ll_md_need_convert(lock)) {
+                       lock_res_and_lock(lock);
+                       lock->l_policy_data.l_inodebits.cancel_bits =
+                                       lock->l_policy_data.l_inodebits.bits;
+                       unlock_res_and_lock(lock);
                }
+               rc = ldlm_cli_convert(lock, cancel_flags);
+               if (!rc)
+                       RETURN(0);
+               /* continue with cancel otherwise */
                ldlm_lock2handle(lock, &lockh);
                rc = ldlm_cli_cancel(&lockh, cancel_flags);
                if (rc < 0) {
@@ -460,24 +467,34 @@ int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                break;
        }
        case LDLM_CB_CANCELING:
+       {
+               __u64 to_cancel = lock->l_policy_data.l_inodebits.bits;
+
                /* Nothing to do for non-granted locks */
                if (!ldlm_is_granted(lock))
                        break;
 
-               if (ldlm_is_converting(lock)) {
-                       /* this is called on already converted lock, so
-                        * ibits has remained bits only and cancel_bits
-                        * are bits that were dropped.
-                        * Note that DOM lock is handled prior lock convert
-                        * and is excluded here.
+               /* If 'ld' is supplied then bits to be cancelled are passed
+                * implicitly by lock converting and cancel_bits from 'ld'
+                * should be used. Otherwise full cancel is being performed
+                * and lock inodebits are used.
+                *
+                * Note: we cannot rely on cancel_bits in lock itself at this
+                * moment because they can be changed by concurrent thread,
+                * so ldlm_cli_inodebits_convert() pass cancel bits implicitly
+                * in 'ld' parameter.
+                */
+               if (ld) {
+                       /* partial bits cancel allowed only during convert */
+                       LASSERT(ldlm_is_converting(lock));
+                       /* mask cancel bits by lock bits so only no any unused
+                        * bits are passed to ll_lock_cancel_bits()
                         */
-                       bits = lock->l_policy_data.l_inodebits.cancel_bits &
-                               ~MDS_INODELOCK_DOM;
-               } else {
-                       LASSERT(ldlm_is_canceling(lock));
+                       to_cancel &= ld->l_policy_data.l_inodebits.cancel_bits;
                }
-               ll_lock_cancel_bits(lock, bits);
+               ll_lock_cancel_bits(lock, to_cancel);
                break;
+       }
        default:
                LBUG();
        }
@@ -596,7 +613,8 @@ struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
 static int ll_lookup_it_finish(struct ptlrpc_request *request,
                               struct lookup_intent *it,
                               struct inode *parent, struct dentry **de,
-                              void *secctx, __u32 secctxlen)
+                              void *secctx, __u32 secctxlen,
+                              ktime_t kstart)
 {
        struct inode             *inode = NULL;
        __u64                     bits = 0;
@@ -701,11 +719,18 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
                }
        }
 
+       if (it_disposition(it, DISP_OPEN_CREATE)) {
+               ll_stats_ops_tally(ll_i2sbi(parent), LPROC_LL_MKNOD,
+                                  ktime_us_delta(ktime_get(), kstart));
+       }
+
        GOTO(out, rc = 0);
 
 out:
-       if (rc != 0 && it->it_op & IT_OPEN)
+       if (rc != 0 && it->it_op & IT_OPEN) {
+               ll_intent_drop_lock(it);
                ll_open_cleanup((*de)->d_sb, request);
+       }
 
        return rc;
 }
@@ -715,6 +740,7 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
                                   void **secctx, __u32 *secctxlen,
                                   struct pcc_create_attach *pca)
 {
+       ktime_t kstart = ktime_get();
        struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
        struct dentry *save = dentry, *retval;
        struct ptlrpc_request *req = NULL;
@@ -861,7 +887,8 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
        ll_unlock_md_op_lsm(op_data);
        rc = ll_lookup_it_finish(req, it, parent, &dentry,
                                 secctx != NULL ? *secctx : NULL,
-                                secctxlen != NULL ? *secctxlen : 0);
+                                secctxlen != NULL ? *secctxlen : 0,
+                               kstart);
         if (rc != 0) {
                 ll_intent_release(it);
                 GOTO(out, retval = ERR_PTR(rc));
@@ -1751,7 +1778,11 @@ static int ll_unlink(struct inode *dir, struct dentry *dchild)
                RETURN(PTR_ERR(op_data));
 
        op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
-
+       /* notify lower layer if inode has dirty pages */
+       if (S_ISREG(dchild->d_inode->i_mode) &&
+           ll_i2info(dchild->d_inode)->lli_clob &&
+           dirty_cnt(dchild->d_inode))
+               op_data->op_cli_flags |= CLI_DIRTY_DATA;
        op_data->op_fid2 = op_data->op_fid3;
        rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
        ll_finish_md_op_data(op_data);