nfs: modify pg_test interface to return size_t
authorWeston Andros Adamson <dros@primarydata.com>
Thu, 15 May 2014 15:56:43 +0000 (11:56 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Thu, 29 May 2014 15:11:43 +0000 (11:11 -0400)
This is a step toward allowing pg_test to inform the the
coalescing code to reduce the size of requests so they may fit in
whatever scheme the pg_test callback wants to define.

For now, just return the size of the request if there is space, or 0
if there is not.  This shouldn't change any behavior as it acts
the same as when the pg_test functions returned bool.

Signed-off-by: Weston Andros Adamson <dros@primarydata.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/blocklayout/blocklayout.c
fs/nfs/nfs4filelayout.c
fs/nfs/objlayout/objio_osd.c
fs/nfs/pagelist.c
fs/nfs/pnfs.c
fs/nfs/pnfs.h
include/linux/nfs_page.h

index 206cc68c9694d9103f3a1999a6fd9b512bf45786..9b431f44fad9d19a31d6c61ca3986453b137f4d4 100644 (file)
@@ -1189,13 +1189,17 @@ bl_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
                pnfs_generic_pg_init_read(pgio, req);
 }
 
-static bool
+/*
+ * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
+ * of bytes (maximum @req->wb_bytes) that can be coalesced.
+ */
+static size_t
 bl_pg_test_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
                struct nfs_page *req)
 {
        if (pgio->pg_dreq != NULL &&
            !is_aligned_req(req, SECTOR_SIZE))
-               return false;
+               return 0;
 
        return pnfs_generic_pg_test(pgio, prev, req);
 }
@@ -1241,13 +1245,17 @@ bl_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
        }
 }
 
-static bool
+/*
+ * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
+ * of bytes (maximum @req->wb_bytes) that can be coalesced.
+ */
+static size_t
 bl_pg_test_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
                 struct nfs_page *req)
 {
        if (pgio->pg_dreq != NULL &&
            !is_aligned_req(req, PAGE_CACHE_SIZE))
-               return false;
+               return 0;
 
        return pnfs_generic_pg_test(pgio, prev, req);
 }
index 9fd7cebbff04580d6f1780e230cfadce9f46d213..ba9a9aadf6c8056803f2e9c4106e1c339a695c1c 100644 (file)
@@ -915,10 +915,10 @@ filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
 /*
  * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
  *
- * return true  : coalesce page
- * return false : don't coalesce page
+ * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
+ * of bytes (maximum @req->wb_bytes) that can be coalesced.
  */
-static bool
+static size_t
 filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
                   struct nfs_page *req)
 {
@@ -927,7 +927,7 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
 
        if (!pnfs_generic_pg_test(pgio, prev, req) ||
            !nfs_generic_pg_test(pgio, prev, req))
-               return false;
+               return 0;
 
        p_stripe = (u64)req_offset(prev);
        r_stripe = (u64)req_offset(req);
@@ -936,7 +936,9 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
        do_div(p_stripe, stripe_unit);
        do_div(r_stripe, stripe_unit);
 
-       return (p_stripe == r_stripe);
+       if (p_stripe == r_stripe)
+               return req->wb_bytes;
+       return 0;
 }
 
 static void
index 426b366b0b3369bc8ec3f0e56753046cad1273c6..71b9c69dbe9cd057fb4226994ad6e42158f83cec 100644 (file)
@@ -564,14 +564,19 @@ int objio_write_pagelist(struct nfs_pgio_data *wdata, int how)
        return 0;
 }
 
-static bool objio_pg_test(struct nfs_pageio_descriptor *pgio,
+/*
+ * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
+ * of bytes (maximum @req->wb_bytes) that can be coalesced.
+ */
+static size_t objio_pg_test(struct nfs_pageio_descriptor *pgio,
                          struct nfs_page *prev, struct nfs_page *req)
 {
-       if (!pnfs_generic_pg_test(pgio, prev, req))
-               return false;
+       if (!pnfs_generic_pg_test(pgio, prev, req) ||
+           pgio->pg_count + req->wb_bytes >
+           (unsigned long)pgio->pg_layout_private)
+               return 0;
 
-       return pgio->pg_count + req->wb_bytes <=
-                       (unsigned long)pgio->pg_layout_private;
+       return req->wb_bytes;
 }
 
 static void objio_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
index 4b4b212ec6b2185448a9f4dd48c27563e399cca1..82233431880dc25a5794c7b8cdb561f2cb715b1b 100644 (file)
@@ -280,7 +280,17 @@ nfs_wait_on_request(struct nfs_page *req)
                        TASK_UNINTERRUPTIBLE);
 }
 
-bool nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, struct nfs_page *prev, struct nfs_page *req)
+/*
+ * nfs_generic_pg_test - determine if requests can be coalesced
+ * @desc: pointer to descriptor
+ * @prev: previous request in desc, or NULL
+ * @req: this request
+ *
+ * Returns zero if @req can be coalesced into @desc, otherwise it returns
+ * the size of the request.
+ */
+size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc,
+                          struct nfs_page *prev, struct nfs_page *req)
 {
        /*
         * FIXME: ideally we should be able to coalesce all requests
@@ -292,7 +302,9 @@ bool nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, struct nfs_page *pr
        if (desc->pg_bsize < PAGE_SIZE)
                return 0;
 
-       return desc->pg_count + req->wb_bytes <= desc->pg_bsize;
+       if (desc->pg_count + req->wb_bytes <= desc->pg_bsize)
+               return req->wb_bytes;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(nfs_generic_pg_test);
 
@@ -747,6 +759,8 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev,
                                      struct nfs_page *req,
                                      struct nfs_pageio_descriptor *pgio)
 {
+       size_t size;
+
        if (!nfs_match_open_context(req->wb_context, prev->wb_context))
                return false;
        if (req->wb_context->dentry->d_inode->i_flock != NULL &&
@@ -758,7 +772,9 @@ static bool nfs_can_coalesce_requests(struct nfs_page *prev,
                return false;
        if (req_offset(req) != req_offset(prev) + prev->wb_bytes)
                return false;
-       return pgio->pg_ops->pg_test(pgio, prev, req);
+       size = pgio->pg_ops->pg_test(pgio, prev, req);
+       WARN_ON_ONCE(size && size != req->wb_bytes);
+       return size > 0;
 }
 
 /**
index 0fe670189fd18a18d9d131e9cf1a1f90413bb53d..de6eb16f94d19aa6b8fc686443f183ab38f4fda1 100644 (file)
@@ -1434,7 +1434,11 @@ pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio,
 }
 EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write);
 
-bool
+/*
+ * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
+ * of bytes (maximum @req->wb_bytes) that can be coalesced.
+ */
+size_t
 pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
                     struct nfs_page *req)
 {
@@ -1455,8 +1459,10 @@ pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
         * first byte that lies outside the pnfs_layout_range. FIXME?
         *
         */
-       return req_offset(req) < end_offset(pgio->pg_lseg->pls_range.offset,
-                                        pgio->pg_lseg->pls_range.length);
+       if (req_offset(req) < end_offset(pgio->pg_lseg->pls_range.offset,
+                                        pgio->pg_lseg->pls_range.length))
+               return req->wb_bytes;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(pnfs_generic_pg_test);
 
index 0031267d749289496c1fd7071a51b818731dc75c..dccf182ec4d8451c2869d8c03a845971c9464974 100644 (file)
@@ -187,7 +187,8 @@ int pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc);
 void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio,
                                struct nfs_page *req, u64 wb_size);
 int pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc);
-bool pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, struct nfs_page *req);
+size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio,
+                           struct nfs_page *prev, struct nfs_page *req);
 void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg);
 struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp);
 void pnfs_free_lseg_list(struct list_head *tmp_list);
index be0b0981e7a0c6c6920873cc2c278394ee171b53..13d59af561f624a99a2a5e4b1df6805b16b9e1fe 100644 (file)
@@ -46,7 +46,8 @@ struct nfs_page {
 struct nfs_pageio_descriptor;
 struct nfs_pageio_ops {
        void    (*pg_init)(struct nfs_pageio_descriptor *, struct nfs_page *);
-       bool    (*pg_test)(struct nfs_pageio_descriptor *, struct nfs_page *, struct nfs_page *);
+       size_t  (*pg_test)(struct nfs_pageio_descriptor *, struct nfs_page *,
+                          struct nfs_page *);
        int     (*pg_doio)(struct nfs_pageio_descriptor *);
 };
 
@@ -102,7 +103,7 @@ extern      int nfs_pageio_add_request(struct nfs_pageio_descriptor *,
                                   struct nfs_page *);
 extern void nfs_pageio_complete(struct nfs_pageio_descriptor *desc);
 extern void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *, pgoff_t);
-extern bool nfs_generic_pg_test(struct nfs_pageio_descriptor *desc,
+extern size_t nfs_generic_pg_test(struct nfs_pageio_descriptor *desc,
                                struct nfs_page *prev,
                                struct nfs_page *req);
 extern  int nfs_wait_on_request(struct nfs_page *);