diff options
author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2007-05-20 10:18:27 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2007-05-24 10:44:20 -0400 |
commit | 7fe7f8487ae742239dd8c66596e2311c30d057d1 (patch) | |
tree | c506bd7dcacc9d5b25b3295bd1f327e534532c54 /fs | |
parent | 585a2858b970cb6e2e5ca4877eefd18b4dba8ed4 (diff) |
NFS: Avoid a deadlock situation on write
When processes are allowed to attempt to lock a non-contiguous range of nfs
write requests, it is possible for generic_writepages to 'wrap round' the
address space, and call writepage() on a request that is already locked by
the same process.
We avoid the deadlock by checking if the page index is contiguous with the
list of nfs write requests that is already held in our
nfs_pageio_descriptor prior to attempting to lock a new request.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/nfs/pagelist.c | 20 | ||||
-rw-r--r-- | fs/nfs/write.c | 6 |
2 files changed, 24 insertions, 2 deletions
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index cbdd1c6aaa94..c5bb51a29e80 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c | |||
@@ -355,6 +355,26 @@ void nfs_pageio_complete(struct nfs_pageio_descriptor *desc) | |||
355 | nfs_pageio_doio(desc); | 355 | nfs_pageio_doio(desc); |
356 | } | 356 | } |
357 | 357 | ||
358 | /** | ||
359 | * nfs_pageio_cond_complete - Conditional I/O completion | ||
360 | * @desc: pointer to io descriptor | ||
361 | * @index: page index | ||
362 | * | ||
363 | * It is important to ensure that processes don't try to take locks | ||
364 | * on non-contiguous ranges of pages as that might deadlock. This | ||
365 | * function should be called before attempting to wait on a locked | ||
366 | * nfs_page. It will complete the I/O if the page index 'index' | ||
367 | * is not contiguous with the existing list of pages in 'desc'. | ||
368 | */ | ||
369 | void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index) | ||
370 | { | ||
371 | if (!list_empty(&desc->pg_list)) { | ||
372 | struct nfs_page *prev = nfs_list_entry(desc->pg_list.prev); | ||
373 | if (index != prev->wb_index + 1) | ||
374 | nfs_pageio_doio(desc); | ||
375 | } | ||
376 | } | ||
377 | |||
358 | #define NFS_SCAN_MAXENTRIES 16 | 378 | #define NFS_SCAN_MAXENTRIES 16 |
359 | /** | 379 | /** |
360 | * nfs_scan_list - Scan a list for matching requests | 380 | * nfs_scan_list - Scan a list for matching requests |
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index b084c03ce493..af344a158e01 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -273,8 +273,6 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio, | |||
273 | * request as dirty (in which case we don't care). | 273 | * request as dirty (in which case we don't care). |
274 | */ | 274 | */ |
275 | spin_unlock(req_lock); | 275 | spin_unlock(req_lock); |
276 | /* Prevent deadlock! */ | ||
277 | nfs_pageio_complete(pgio); | ||
278 | ret = nfs_wait_on_request(req); | 276 | ret = nfs_wait_on_request(req); |
279 | nfs_release_request(req); | 277 | nfs_release_request(req); |
280 | if (ret != 0) | 278 | if (ret != 0) |
@@ -321,6 +319,8 @@ static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc | |||
321 | pgio = &mypgio; | 319 | pgio = &mypgio; |
322 | } | 320 | } |
323 | 321 | ||
322 | nfs_pageio_cond_complete(pgio, page->index); | ||
323 | |||
324 | err = nfs_page_async_flush(pgio, page); | 324 | err = nfs_page_async_flush(pgio, page); |
325 | if (err <= 0) | 325 | if (err <= 0) |
326 | goto out; | 326 | goto out; |
@@ -329,6 +329,8 @@ static int nfs_writepage_locked(struct page *page, struct writeback_control *wbc | |||
329 | if (!offset) | 329 | if (!offset) |
330 | goto out; | 330 | goto out; |
331 | 331 | ||
332 | nfs_pageio_cond_complete(pgio, page->index); | ||
333 | |||
332 | ctx = nfs_find_open_context(inode, NULL, FMODE_WRITE); | 334 | ctx = nfs_find_open_context(inode, NULL, FMODE_WRITE); |
333 | if (ctx == NULL) { | 335 | if (ctx == NULL) { |
334 | err = -EBADF; | 336 | err = -EBADF; |