Whamcloud - gitweb
LU-12631 llite: report latency for filesystem ops
[fs/lustre-release.git] / lustre / llite / namei.c
index 30d5198..7e46d5f 100644 (file)
@@ -283,9 +283,6 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
                        CDEBUG(D_INODE, "cannot flush DoM data "
                               DFID": rc = %d\n",
                               PFID(ll_inode2fid(inode)), rc);
-               lock_res_and_lock(lock);
-               ldlm_set_kms_ignore(lock);
-               unlock_res_and_lock(lock);
        }
 
        if (bits & MDS_INODELOCK_LAYOUT) {
@@ -362,6 +359,9 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
            inode != inode->i_sb->s_root->d_inode)
                ll_invalidate_aliases(inode);
 
+       if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
+               forget_all_cached_acls(inode);
+
        iput(inode);
        RETURN_EXIT;
 }
@@ -395,11 +395,13 @@ int ll_md_need_convert(struct ldlm_lock *lock)
        switch (lock->l_req_mode) {
        case LCK_PR:
                mode = LCK_PR;
+               /* fallthrough */
        case LCK_PW:
                mode |= LCK_CR;
                break;
        case LCK_CW:
                mode = LCK_CW;
+               /* fallthrough */
        case LCK_CR:
                mode |= LCK_CR;
                break;
@@ -708,11 +710,6 @@ out:
        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,
@@ -963,8 +960,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;
 
@@ -1005,6 +1001,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());
@@ -1039,17 +1036,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)) {
@@ -1071,11 +1081,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));
 
@@ -1445,38 +1455,41 @@ 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;
+       ENTRY;
 
        CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p) mode %o dev %x\n",
               name->len, name->name, PFID(ll_inode2fid(dir)), dir,
-               mode, rdev);
+              mode, rdev);
 
        if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
                mode &= ~current_umask();
 
-        switch (mode & S_IFMT) {
-        case 0:
-                mode |= S_IFREG; /* for mode = 0 case, fallthrough */
-        case S_IFREG:
-        case S_IFCHR:
-        case S_IFBLK:
-        case S_IFIFO:
-        case S_IFSOCK:
+       switch (mode & S_IFMT) {
+       case 0:
+               mode |= S_IFREG;
+               /* fallthrough */
+       case S_IFREG:
+       case S_IFCHR:
+       case S_IFBLK:
+       case S_IFIFO:
+       case S_IFSOCK:
                err = ll_new_node(dir, dchild, NULL, mode, old_encode_dev(rdev),
                                  LUSTRE_OPC_MKNOD);
-                break;
-        case S_IFDIR:
-                err = -EPERM;
-                break;
-        default:
-                err = -EINVAL;
-        }
+               break;
+       case S_IFDIR:
+               err = -EPERM;
+               break;
+       default:
+               err = -EINVAL;
+       }
 
-        if (!err)
-                ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
+       if (!err)
+               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD,
+                                  ktime_us_delta(ktime_get(), kstart));
 
-        RETURN(err);
+       RETURN(err);
 }
 
 #ifdef HAVE_IOP_ATOMIC_OPEN
@@ -1486,6 +1499,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);
@@ -1499,11 +1513,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 */
@@ -1512,6 +1528,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);
@@ -1545,16 +1562,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 */
 
@@ -1562,6 +1580,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;
 
@@ -1572,10 +1591,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,
@@ -1586,6 +1606,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;
@@ -1593,29 +1614,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);
@@ -1627,7 +1650,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);
 }
@@ -1635,10 +1659,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);
@@ -1655,15 +1681,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);
 }
 
 /**
@@ -1673,6 +1700,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;
 
@@ -1686,12 +1714,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);
 }
 
@@ -1701,8 +1730,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);
 
@@ -1735,10 +1767,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);
 }
 
@@ -1754,6 +1788,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;
 
@@ -1782,20 +1817,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);
 }