From 3aff4ebb95b20ad8db2c1447e8c52097d89af5a7 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Wed, 9 May 2012 14:30:35 -0400 Subject: NFS: Prevent a deadlock in the new writeback code We have to unlock the nfs_page before we call nfs_end_page_writeback to avoid races with functions that expect the page to be unlocked when PG_locked and PG_writeback are not set. The problem is that nfs_unlock_request also releases the nfs_page, causing a deadlock if the release of the nfs_open_context triggers an iput() while the PG_writeback flag is still set... The solution is to separate the unlocking and release of the nfs_page, so that we can do the former before nfs_end_page_writeback and the latter after. Signed-off-by: Trond Myklebust Cc: Fred Isaman --- fs/nfs/pagelist.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'fs/nfs/pagelist.c') diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index 33a21ca9b84..69146f38698 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c @@ -128,10 +128,10 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode, } /** - * nfs_unlock_request - Unlock request and wake up sleepers. + * nfs_unlock_request_dont_release - Unlock request and wake up sleepers. * @req: */ -void nfs_unlock_request(struct nfs_page *req) +void nfs_unlock_request_dont_release(struct nfs_page *req) { if (!NFS_WBACK_BUSY(req)) { printk(KERN_ERR "NFS: Invalid unlock attempted\n"); @@ -141,6 +141,14 @@ void nfs_unlock_request(struct nfs_page *req) clear_bit(PG_BUSY, &req->wb_flags); smp_mb__after_clear_bit(); wake_up_bit(&req->wb_flags, PG_BUSY); +} + +/** + * nfs_unlock_request - Unlock request and release the nfs_page + */ +void nfs_unlock_request(struct nfs_page *req) +{ + nfs_unlock_request_dont_release(req); nfs_release_request(req); } -- cgit v1.2.3-70-g09d2