pNFS: Add flag to track if we've called nfs4_ff_layout_stat_io_start_read/write
authorTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 22 Dec 2015 17:30:24 +0000 (12:30 -0500)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Mon, 28 Dec 2015 19:32:41 +0000 (14:32 -0500)
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/flexfilelayout/flexfilelayout.c
include/linux/nfs_xdr.h

index 14109a82ce84a7fb7a9f125cad27354ef14c4443..9257679a15badfefa4b6161a56c1994a4f6d15db 100644 (file)
@@ -1279,14 +1279,31 @@ ff_layout_reset_to_mds(struct pnfs_layout_segment *lseg, int idx)
        return ff_layout_test_devid_unavailable(node);
 }
 
-static int ff_layout_read_prepare_common(struct rpc_task *task,
-                                        struct nfs_pgio_header *hdr)
+static void ff_layout_read_record_layoutstats_start(struct rpc_task *task,
+               struct nfs_pgio_header *hdr)
 {
+       if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
+               return;
        nfs4_ff_layout_stat_io_start_read(hdr->inode,
                        FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
                        hdr->args.count,
                        task->tk_start);
+}
+
+static void ff_layout_read_record_layoutstats_done(struct rpc_task *task,
+               struct nfs_pgio_header *hdr)
+{
+       if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
+               return;
+       nfs4_ff_layout_stat_io_end_read(task,
+                       FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
+                       hdr->args.count,
+                       hdr->res.count);
+}
 
+static int ff_layout_read_prepare_common(struct rpc_task *task,
+                                        struct nfs_pgio_header *hdr)
+{
        if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
                rpc_exit(task, -EIO);
                return -EIO;
@@ -1302,6 +1319,7 @@ static int ff_layout_read_prepare_common(struct rpc_task *task,
        }
        hdr->pgio_done_cb = ff_layout_read_done_cb;
 
+       ff_layout_read_record_layoutstats_start(task, hdr);
        return 0;
 }
 
@@ -1360,10 +1378,6 @@ static void ff_layout_read_call_done(struct rpc_task *task, void *data)
 
        dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
 
-       nfs4_ff_layout_stat_io_end_read(task,
-                       FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
-                       hdr->args.count, hdr->res.count);
-
        if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
            task->tk_status == 0) {
                nfs4_sequence_done(task, &hdr->res.seq_res);
@@ -1378,6 +1392,7 @@ static void ff_layout_read_count_stats(struct rpc_task *task, void *data)
 {
        struct nfs_pgio_header *hdr = data;
 
+       ff_layout_read_record_layoutstats_done(task, hdr);
        rpc_count_iostats_metrics(task,
            &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]);
 }
@@ -1453,14 +1468,31 @@ static int ff_layout_commit_done_cb(struct rpc_task *task,
        return 0;
 }
 
-static int ff_layout_write_prepare_common(struct rpc_task *task,
-                                         struct nfs_pgio_header *hdr)
+static void ff_layout_write_record_layoutstats_start(struct rpc_task *task,
+               struct nfs_pgio_header *hdr)
 {
+       if (test_and_set_bit(NFS_IOHDR_STAT, &hdr->flags))
+               return;
        nfs4_ff_layout_stat_io_start_write(hdr->inode,
                        FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
                        hdr->args.count,
                        task->tk_start);
+}
+
+static void ff_layout_write_record_layoutstats_done(struct rpc_task *task,
+               struct nfs_pgio_header *hdr)
+{
+       if (!test_and_clear_bit(NFS_IOHDR_STAT, &hdr->flags))
+               return;
+       nfs4_ff_layout_stat_io_end_write(task,
+                       FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
+                       hdr->args.count, hdr->res.count,
+                       hdr->res.verf->committed);
+}
 
+static int ff_layout_write_prepare_common(struct rpc_task *task,
+                                         struct nfs_pgio_header *hdr)
+{
        if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
                rpc_exit(task, -EIO);
                return -EIO;
@@ -1477,6 +1509,7 @@ static int ff_layout_write_prepare_common(struct rpc_task *task,
                return -EAGAIN;
        }
 
+       ff_layout_write_record_layoutstats_start(task, hdr);
        return 0;
 }
 
@@ -1526,23 +1559,45 @@ static void ff_layout_write_count_stats(struct rpc_task *task, void *data)
 {
        struct nfs_pgio_header *hdr = data;
 
-       nfs4_ff_layout_stat_io_end_write(task,
-                       FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx),
-                       hdr->args.count, hdr->res.count,
-                       hdr->res.verf->committed);
-
+       ff_layout_write_record_layoutstats_done(task, hdr);
        rpc_count_iostats_metrics(task,
            &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]);
 }
 
-static void ff_layout_commit_prepare_common(struct rpc_task *task,
+static void ff_layout_commit_record_layoutstats_start(struct rpc_task *task,
                struct nfs_commit_data *cdata)
 {
+       if (test_and_set_bit(NFS_IOHDR_STAT, &cdata->flags))
+               return;
        nfs4_ff_layout_stat_io_start_write(cdata->inode,
                        FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
                        0, task->tk_start);
 }
 
+static void ff_layout_commit_record_layoutstats_done(struct rpc_task *task,
+               struct nfs_commit_data *cdata)
+{
+       struct nfs_page *req;
+       __u64 count = 0;
+
+       if (!test_and_clear_bit(NFS_IOHDR_STAT, &cdata->flags))
+               return;
+
+       if (task->tk_status == 0) {
+               list_for_each_entry(req, &cdata->pages, wb_list)
+                       count += req->wb_bytes;
+       }
+       nfs4_ff_layout_stat_io_end_write(task,
+                       FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
+                       count, count, NFS_FILE_SYNC);
+}
+
+static void ff_layout_commit_prepare_common(struct rpc_task *task,
+               struct nfs_commit_data *cdata)
+{
+       ff_layout_commit_record_layoutstats_start(task, cdata);
+}
+
 static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data)
 {
        ff_layout_commit_prepare_common(task, data);
@@ -1569,18 +1624,8 @@ static void ff_layout_commit_done(struct rpc_task *task, void *data)
 static void ff_layout_commit_count_stats(struct rpc_task *task, void *data)
 {
        struct nfs_commit_data *cdata = data;
-       struct nfs_page *req;
-       __u64 count = 0;
-
-       if (task->tk_status == 0) {
-               list_for_each_entry(req, &cdata->pages, wb_list)
-                       count += req->wb_bytes;
-       }
-
-       nfs4_ff_layout_stat_io_end_write(task,
-                       FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index),
-                       count, count, NFS_FILE_SYNC);
 
+       ff_layout_commit_record_layoutstats_done(task, cdata);
        rpc_count_iostats_metrics(task,
            &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]);
 }
index 11bbae44f4cbf91dd3ed62aa9d2e1849b14a8839..7b30ac0c7def8708a4c593a533c3d00d71c7c46b 100644 (file)
@@ -1375,6 +1375,7 @@ enum {
        NFS_IOHDR_ERROR = 0,
        NFS_IOHDR_EOF,
        NFS_IOHDR_REDO,
+       NFS_IOHDR_STAT,
 };
 
 struct nfs_pgio_header {
@@ -1454,6 +1455,7 @@ struct nfs_commit_data {
        const struct rpc_call_ops *mds_ops;
        const struct nfs_commit_completion_ops *completion_ops;
        int (*commit_done_cb) (struct rpc_task *task, struct nfs_commit_data *data);
+       unsigned long           flags;
 };
 
 struct nfs_pgio_completion_ops {