NFS: Ensure that we free the rpc_task after read and write cleanups are done
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 4 Jan 2013 17:47:04 +0000 (12:47 -0500)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 4 Jan 2013 17:59:10 +0000 (12:59 -0500)
This patch ensures that we free the rpc_task after the cleanup callbacks
are done in order to avoid a deadlock problem that can be triggered if
the callback needs to wait for another workqueue item to complete.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: Weston Andros Adamson <dros@netapp.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Bruce Fields <bfields@fieldses.org>
Cc: stable@vger.kernel.org [>= 3.5]
fs/nfs/read.c
fs/nfs/write.c

index b6bdb18e892c8ea5bf04869e296b1cdafca4d4a7..a5e5d9899d56fa622c1156609b406ee953527d6c 100644 (file)
@@ -91,12 +91,16 @@ void nfs_readdata_release(struct nfs_read_data *rdata)
        put_nfs_open_context(rdata->args.context);
        if (rdata->pages.pagevec != rdata->pages.page_array)
                kfree(rdata->pages.pagevec);
-       if (rdata != &read_header->rpc_data)
-               kfree(rdata);
-       else
+       if (rdata == &read_header->rpc_data) {
                rdata->header = NULL;
+               rdata = NULL;
+       }
        if (atomic_dec_and_test(&hdr->refcnt))
                hdr->completion_ops->completion(hdr);
+       /* Note: we only free the rpc_task after callbacks are done.
+        * See the comment in rpc_free_task() for why
+        */
+       kfree(rdata);
 }
 EXPORT_SYMBOL_GPL(nfs_readdata_release);
 
index b673be31590e496605a82f3b8b0e01c4d701f0b3..c483cc50b82ee5aa77f80f0d057550526469f466 100644 (file)
@@ -126,12 +126,16 @@ void nfs_writedata_release(struct nfs_write_data *wdata)
        put_nfs_open_context(wdata->args.context);
        if (wdata->pages.pagevec != wdata->pages.page_array)
                kfree(wdata->pages.pagevec);
-       if (wdata != &write_header->rpc_data)
-               kfree(wdata);
-       else
+       if (wdata == &write_header->rpc_data) {
                wdata->header = NULL;
+               wdata = NULL;
+       }
        if (atomic_dec_and_test(&hdr->refcnt))
                hdr->completion_ops->completion(hdr);
+       /* Note: we only free the rpc_task after callbacks are done.
+        * See the comment in rpc_free_task() for why
+        */
+       kfree(wdata);
 }
 EXPORT_SYMBOL_GPL(nfs_writedata_release);