Whamcloud - gitweb
LU-11114 llite: Update mdc and lite stats on open|creat
[fs/lustre-release.git] / lustre / llite / namei.c
index d097614..31c8d28 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,25 +719,28 @@ 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;
 }
 
-struct pcc_create_attach {
-       struct pcc_dataset *pca_dataset;
-       struct dentry *pca_dentry;
-};
-
 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
                                   struct lookup_intent *it,
                                   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;
@@ -866,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));
@@ -965,8 +987,7 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
        void *secctx = NULL;
        __u32 secctxlen = 0;
        struct ll_sb_info *sbi;
-       struct pcc_create_attach pca = {NULL, NULL};
-       struct pcc_dataset *dataset = NULL;
+       struct pcc_create_attach pca = { NULL, NULL };
        int rc = 0;
        ENTRY;
 
@@ -1007,6 +1028,7 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
                if (!filename_is_volatile(dentry->d_name.name,
                                          dentry->d_name.len, NULL)) {
                        struct pcc_matcher item;
+                       struct pcc_dataset *dataset;
 
                        item.pm_uid = from_kuid(&init_user_ns, current_uid());
                        item.pm_gid = from_kgid(&init_user_ns, current_gid());
@@ -1041,17 +1063,30 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
                                        dput(de);
                                goto out_release;
                        }
-                       if (dataset != NULL && dentry->d_inode) {
-                               rc = pcc_inode_create_fini(dataset,
-                                                          dentry->d_inode,
-                                                          pca.pca_dentry);
-                               if (rc) {
-                                       if (de != NULL)
-                                               dput(de);
-                                       GOTO(out_release, rc);
-                               }
+
+                       rc = pcc_inode_create_fini(dentry->d_inode, &pca);
+                       if (rc) {
+                               if (de != NULL)
+                                       dput(de);
+                               GOTO(out_release, rc);
                        }
+
                        ll_set_created(opened, file);
+               } else {
+                       /* Open the file with O_CREAT, but the file already
+                        * existed on MDT. This may happend in the case that
+                        * the LOOKUP ibits lock is revoked and the
+                        * corresponding dentry cache is deleted.
+                        * i.e. In the current Lustre, the truncate operation
+                        * will revoke the LOOKUP ibits lock, and the file
+                        * dentry cache will be invalidated. The following open
+                        * with O_CREAT flag will call into ->atomic_open, the
+                        * file was wrongly though as newly created file and
+                        * try to auto cache the file. So after client knows it
+                        * is not a DISP_OPEN_CREATE, it should cleanup the
+                        * already created PCC copy.
+                        */
+                       pcc_create_attach_cleanup(dir->i_sb, &pca);
                }
 
                if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN)) {
@@ -1073,11 +1108,11 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
                } else {
                        rc = finish_no_open(file, de);
                }
+       } else {
+               pcc_create_attach_cleanup(dir->i_sb, &pca);
        }
 
 out_release:
-       if (dataset != NULL)
-               pcc_dataset_put(dataset);
        ll_intent_release(it);
        OBD_FREE(it, sizeof(*it));
 
@@ -1447,6 +1482,7 @@ static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
                    dev_t rdev)
 {
        struct qstr *name = &dchild->d_name;
+       ktime_t kstart = ktime_get();
        int err;
        ENTRY;
 
@@ -1477,7 +1513,8 @@ static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
        }
 
        if (!err)
-               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD,
+                                  ktime_us_delta(ktime_get(), kstart));
 
        RETURN(err);
 }
@@ -1489,6 +1526,7 @@ static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
                        umode_t mode, bool want_excl)
 {
+       ktime_t kstart = ktime_get();
        int rc;
 
        CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
@@ -1502,11 +1540,13 @@ static int ll_create_nd(struct inode *dir, struct dentry *dentry,
         * volatile file name, so we use ll_mknod() here. */
        rc = ll_mknod(dir, dentry, mode, 0);
 
-       ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
-
        CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, unhashed %d\n",
               dentry->d_name.len, dentry->d_name.name, d_unhashed(dentry));
 
+       if (!rc)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE,
+                                  ktime_us_delta(ktime_get(), kstart));
+
        return rc;
 }
 #else /* !HAVE_IOP_ATOMIC_OPEN */
@@ -1515,6 +1555,7 @@ static int ll_create_nd(struct inode *dir, struct dentry *dentry,
 {
        struct ll_dentry_data *lld = ll_d2d(dentry);
        struct lookup_intent *it = NULL;
+       ktime_t kstart = ktime_get();
        int rc;
 
        CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
@@ -1548,16 +1589,17 @@ static int ll_create_nd(struct inode *dir, struct dentry *dentry,
                filp = lookup_instantiate_filp(nd, dentry, NULL);
                if (IS_ERR(filp))
                        rc = PTR_ERR(filp);
-        }
+       }
 
 out:
-        ll_intent_release(it);
-        OBD_FREE(it, sizeof(*it));
+       ll_intent_release(it);
+       OBD_FREE(it, sizeof(*it));
 
-        if (!rc)
-                ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
+       if (!rc)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE,
+                                  ktime_us_delta(ktime_get(), kstart));
 
-        return rc;
+       return rc;
 }
 #endif /* HAVE_IOP_ATOMIC_OPEN */
 
@@ -1565,6 +1607,7 @@ static int ll_symlink(struct inode *dir, struct dentry *dchild,
                      const char *oldpath)
 {
        struct qstr *name = &dchild->d_name;
+       ktime_t kstart = ktime_get();
        int err;
        ENTRY;
 
@@ -1575,10 +1618,11 @@ static int ll_symlink(struct inode *dir, struct dentry *dchild,
        err = ll_new_node(dir, dchild, oldpath, S_IFLNK | S_IRWXUGO, 0,
                          LUSTRE_OPC_SYMLINK);
 
-        if (!err)
-                ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
+       if (!err)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK,
+                                  ktime_us_delta(ktime_get(), kstart));
 
-        RETURN(err);
+       RETURN(err);
 }
 
 static int ll_link(struct dentry *old_dentry, struct inode *dir,
@@ -1589,6 +1633,7 @@ static int ll_link(struct dentry *old_dentry, struct inode *dir,
        struct ll_sb_info *sbi = ll_i2sbi(dir);
        struct ptlrpc_request *request = NULL;
        struct md_op_data *op_data;
+       ktime_t kstart = ktime_get();
        int err;
 
        ENTRY;
@@ -1596,29 +1641,31 @@ static int ll_link(struct dentry *old_dentry, struct inode *dir,
               "target=%.*s\n", PFID(ll_inode2fid(src)), src,
               PFID(ll_inode2fid(dir)), dir, name->len, name->name);
 
-        op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len,
-                                     0, LUSTRE_OPC_ANY, NULL);
-        if (IS_ERR(op_data))
-                RETURN(PTR_ERR(op_data));
+       op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len,
+                                    0, LUSTRE_OPC_ANY, NULL);
+       if (IS_ERR(op_data))
+               RETURN(PTR_ERR(op_data));
 
-        err = md_link(sbi->ll_md_exp, op_data, &request);
-        ll_finish_md_op_data(op_data);
-        if (err)
-                GOTO(out, err);
+       err = md_link(sbi->ll_md_exp, op_data, &request);
+       ll_finish_md_op_data(op_data);
+       if (err)
+               GOTO(out, err);
 
-        ll_update_times(request, dir);
-        ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
-        EXIT;
+       ll_update_times(request, dir);
+       ll_stats_ops_tally(sbi, LPROC_LL_LINK,
+                          ktime_us_delta(ktime_get(), kstart));
+       EXIT;
 out:
-        ptlrpc_req_finished(request);
-        RETURN(err);
+       ptlrpc_req_finished(request);
+       RETURN(err);
 }
 
 static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
 {
        struct qstr *name = &dchild->d_name;
-        int err;
-        ENTRY;
+       ktime_t kstart = ktime_get();
+       int err;
+       ENTRY;
 
        CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
               name->len, name->name, PFID(ll_inode2fid(dir)), dir);
@@ -1630,7 +1677,8 @@ static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
 
        err = ll_new_node(dir, dchild, NULL, mode, 0, LUSTRE_OPC_MKDIR);
        if (err == 0)
-               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR,
+                                  ktime_us_delta(ktime_get(), kstart));
 
        RETURN(err);
 }
@@ -1638,10 +1686,12 @@ static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
 static int ll_rmdir(struct inode *dir, struct dentry *dchild)
 {
        struct qstr *name = &dchild->d_name;
-        struct ptlrpc_request *request = NULL;
-        struct md_op_data *op_data;
-        int rc;
-        ENTRY;
+       struct ptlrpc_request *request = NULL;
+       struct md_op_data *op_data;
+       ktime_t kstart = ktime_get();
+       int rc;
+
+       ENTRY;
 
        CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
               name->len, name->name, PFID(ll_inode2fid(dir)), dir);
@@ -1658,15 +1708,16 @@ static int ll_rmdir(struct inode *dir, struct dentry *dchild)
                op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
 
        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);
-        if (rc == 0) {
-                ll_update_times(request, dir);
-                ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
-        }
+       rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
+       ll_finish_md_op_data(op_data);
+       if (!rc)
+               ll_update_times(request, dir);
 
-        ptlrpc_req_finished(request);
-        RETURN(rc);
+       ptlrpc_req_finished(request);
+       if (!rc)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR,
+                                  ktime_us_delta(ktime_get(), kstart));
+       RETURN(rc);
 }
 
 /**
@@ -1676,6 +1727,7 @@ int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
 {
        struct ptlrpc_request *request = NULL;
        struct md_op_data *op_data;
+       ktime_t kstart = ktime_get();
        int rc;
        ENTRY;
 
@@ -1689,12 +1741,13 @@ int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
        op_data->op_cli_flags |= CLI_RM_ENTRY;
        rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
        ll_finish_md_op_data(op_data);
-       if (rc == 0) {
+       if (!rc)
                ll_update_times(request, dir);
-               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
-       }
 
        ptlrpc_req_finished(request);
+       if (!rc)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR,
+                                  ktime_us_delta(ktime_get(), kstart));
        RETURN(rc);
 }
 
@@ -1704,8 +1757,11 @@ static int ll_unlink(struct inode *dir, struct dentry *dchild)
        struct ptlrpc_request *request = NULL;
        struct md_op_data *op_data;
        struct mdt_body *body;
+       ktime_t kstart = ktime_get();
        int rc;
+
        ENTRY;
+
        CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
               name->len, name->name, PFID(ll_inode2fid(dir)), dir);
 
@@ -1738,10 +1794,12 @@ static int ll_unlink(struct inode *dir, struct dentry *dchild)
                set_nlink(dchild->d_inode, body->mbo_nlink);
 
        ll_update_times(request, dir);
-       ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
 
 out:
        ptlrpc_req_finished(request);
+       if (!rc)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK,
+                                  ktime_us_delta(ktime_get(), kstart));
        RETURN(rc);
 }
 
@@ -1757,6 +1815,7 @@ static int ll_rename(struct inode *src, struct dentry *src_dchild,
        struct ptlrpc_request *request = NULL;
        struct ll_sb_info *sbi = ll_i2sbi(src);
        struct md_op_data *op_data;
+       ktime_t kstart = ktime_get();
        int err;
        ENTRY;
 
@@ -1785,20 +1844,22 @@ static int ll_rename(struct inode *src, struct dentry *src_dchild,
        if (tgt_dchild->d_inode != NULL)
                op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
 
-        err = md_rename(sbi->ll_md_exp, op_data,
-                        src_name->name, src_name->len,
-                        tgt_name->name, tgt_name->len, &request);
-        ll_finish_md_op_data(op_data);
-        if (!err) {
-                ll_update_times(request, src);
-                ll_update_times(request, tgt);
-                ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
-        }
+       err = md_rename(sbi->ll_md_exp, op_data,
+                       src_name->name, src_name->len,
+                       tgt_name->name, tgt_name->len, &request);
+       ll_finish_md_op_data(op_data);
+       if (!err) {
+               ll_update_times(request, src);
+               ll_update_times(request, tgt);
+       }
 
-        ptlrpc_req_finished(request);
+       ptlrpc_req_finished(request);
 
-       if (err == 0)
+       if (!err) {
                d_move(src_dchild, tgt_dchild);
+               ll_stats_ops_tally(sbi, LPROC_LL_RENAME,
+                                  ktime_us_delta(ktime_get(), kstart));
+       }
 
        RETURN(err);
 }