diff options
| author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-05-09 14:30:35 -0400 |
|---|---|---|
| committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-05-09 15:16:07 -0400 |
| commit | 3aff4ebb95b20ad8db2c1447e8c52097d89af5a7 (patch) | |
| tree | ad56aceafbcbd0650e71e029ffa138eedffd33ba | |
| parent | dc327ed4cd320be689596365372a3683208c3ba0 (diff) | |
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 <Trond.Myklebust@netapp.com>
Cc: Fred Isaman <iisaman@netapp.com>
| -rw-r--r-- | fs/nfs/pagelist.c | 12 | ||||
| -rw-r--r-- | fs/nfs/write.c | 6 | ||||
| -rw-r--r-- | include/linux/nfs_page.h | 1 |
3 files changed, 15 insertions, 4 deletions
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index 33a21ca9b84b..69146f386989 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, | |||
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | /** | 130 | /** |
| 131 | * nfs_unlock_request - Unlock request and wake up sleepers. | 131 | * nfs_unlock_request_dont_release - Unlock request and wake up sleepers. |
| 132 | * @req: | 132 | * @req: |
| 133 | */ | 133 | */ |
| 134 | void nfs_unlock_request(struct nfs_page *req) | 134 | void nfs_unlock_request_dont_release(struct nfs_page *req) |
| 135 | { | 135 | { |
| 136 | if (!NFS_WBACK_BUSY(req)) { | 136 | if (!NFS_WBACK_BUSY(req)) { |
| 137 | printk(KERN_ERR "NFS: Invalid unlock attempted\n"); | 137 | printk(KERN_ERR "NFS: Invalid unlock attempted\n"); |
| @@ -141,6 +141,14 @@ void nfs_unlock_request(struct nfs_page *req) | |||
| 141 | clear_bit(PG_BUSY, &req->wb_flags); | 141 | clear_bit(PG_BUSY, &req->wb_flags); |
| 142 | smp_mb__after_clear_bit(); | 142 | smp_mb__after_clear_bit(); |
| 143 | wake_up_bit(&req->wb_flags, PG_BUSY); | 143 | wake_up_bit(&req->wb_flags, PG_BUSY); |
| 144 | } | ||
| 145 | |||
| 146 | /** | ||
| 147 | * nfs_unlock_request - Unlock request and release the nfs_page | ||
| 148 | */ | ||
| 149 | void nfs_unlock_request(struct nfs_page *req) | ||
| 150 | { | ||
| 151 | nfs_unlock_request_dont_release(req); | ||
| 144 | nfs_release_request(req); | 152 | nfs_release_request(req); |
| 145 | } | 153 | } |
| 146 | 154 | ||
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 6f263daac748..fd36b31ee72e 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
| @@ -628,8 +628,9 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr) | |||
| 628 | remove_req: | 628 | remove_req: |
| 629 | nfs_inode_remove_request(req); | 629 | nfs_inode_remove_request(req); |
| 630 | next: | 630 | next: |
| 631 | nfs_unlock_request(req); | 631 | nfs_unlock_request_dont_release(req); |
| 632 | nfs_end_page_writeback(page); | 632 | nfs_end_page_writeback(page); |
| 633 | nfs_release_request(req); | ||
| 633 | } | 634 | } |
| 634 | out: | 635 | out: |
| 635 | hdr->release(hdr); | 636 | hdr->release(hdr); |
| @@ -1042,8 +1043,9 @@ static void nfs_redirty_request(struct nfs_page *req) | |||
| 1042 | struct page *page = req->wb_page; | 1043 | struct page *page = req->wb_page; |
| 1043 | 1044 | ||
| 1044 | nfs_mark_request_dirty(req); | 1045 | nfs_mark_request_dirty(req); |
| 1045 | nfs_unlock_request(req); | 1046 | nfs_unlock_request_dont_release(req); |
| 1046 | nfs_end_page_writeback(page); | 1047 | nfs_end_page_writeback(page); |
| 1048 | nfs_release_request(req); | ||
| 1047 | } | 1049 | } |
| 1048 | 1050 | ||
| 1049 | static void nfs_async_write_error(struct list_head *head) | 1051 | static void nfs_async_write_error(struct list_head *head) |
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h index f9ee9eba7f88..ef7504215446 100644 --- a/include/linux/nfs_page.h +++ b/include/linux/nfs_page.h | |||
| @@ -96,6 +96,7 @@ extern bool nfs_generic_pg_test(struct nfs_pageio_descriptor *desc, | |||
| 96 | struct nfs_page *req); | 96 | struct nfs_page *req); |
| 97 | extern int nfs_wait_on_request(struct nfs_page *); | 97 | extern int nfs_wait_on_request(struct nfs_page *); |
| 98 | extern void nfs_unlock_request(struct nfs_page *req); | 98 | extern void nfs_unlock_request(struct nfs_page *req); |
| 99 | extern void nfs_unlock_request_dont_release(struct nfs_page *req); | ||
| 99 | 100 | ||
| 100 | /* | 101 | /* |
| 101 | * Lock the page of an asynchronous request without getting a new reference | 102 | * Lock the page of an asynchronous request without getting a new reference |
