Commit 46c709c0 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] handle concurrent block_write_full_page and set_page_dirty

set_page_dirty() runs without the page lock.  So
__block_write_full_page() needs to be able to cope with the page's
buffers being dirtied concurrently, on another CPU.

Do this with careful ordering and a test-and-set.
parent d028eab5
...@@ -1288,6 +1288,16 @@ static int __block_write_full_page(struct inode *inode, ...@@ -1288,6 +1288,16 @@ static int __block_write_full_page(struct inode *inode,
(1 << BH_Dirty)|(1 << BH_Uptodate)); (1 << BH_Dirty)|(1 << BH_Uptodate));
} }
/*
* Be very careful. We have no exclusion from __set_page_dirty_buffers
* here, and the (potentially unmapped) buffers may become dirty at
* any time. If a buffer becomes dirty here after we've inspected it
* then we just miss that fact, and the page stays dirty.
*
* Buffers outside i_size may be dirtied by __set_page_dirty_buffers;
* handle that here by just cleaning them.
*/
block = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); block = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
head = page_buffers(page); head = page_buffers(page);
bh = head; bh = head;
...@@ -1298,15 +1308,11 @@ static int __block_write_full_page(struct inode *inode, ...@@ -1298,15 +1308,11 @@ static int __block_write_full_page(struct inode *inode,
*/ */
do { do {
if (block > last_block) { if (block > last_block) {
if (buffer_dirty(bh)) clear_buffer_dirty(bh);
buffer_error();
if (buffer_mapped(bh)) if (buffer_mapped(bh))
buffer_error(); buffer_error();
/* /*
* NOTE: this buffer can only be marked uptodate * The buffer was zeroed by block_write_full_page()
* because we know that block_write_full_page has
* zeroed it out. That seems unnecessary and may go
* away.
*/ */
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
} else if (!buffer_mapped(bh) && buffer_dirty(bh)) { } else if (!buffer_mapped(bh) && buffer_dirty(bh)) {
...@@ -1327,11 +1333,9 @@ static int __block_write_full_page(struct inode *inode, ...@@ -1327,11 +1333,9 @@ static int __block_write_full_page(struct inode *inode,
do { do {
get_bh(bh); get_bh(bh);
if (buffer_dirty(bh)) { if (buffer_mapped(bh) && buffer_dirty(bh)) {
lock_buffer(bh); lock_buffer(bh);
if (buffer_dirty(bh)) { if (test_clear_buffer_dirty(bh)) {
if (!buffer_mapped(bh))
buffer_error();
if (!buffer_uptodate(bh)) if (!buffer_uptodate(bh))
buffer_error(); buffer_error();
set_buffer_async_io(bh); set_buffer_async_io(bh);
...@@ -1353,7 +1357,6 @@ static int __block_write_full_page(struct inode *inode, ...@@ -1353,7 +1357,6 @@ static int __block_write_full_page(struct inode *inode,
do { do {
struct buffer_head *next = bh->b_this_page; struct buffer_head *next = bh->b_this_page;
if (buffer_async(bh)) { if (buffer_async(bh)) {
clear_buffer_dirty(bh);
submit_bh(WRITE, bh); submit_bh(WRITE, bh);
nr_underway++; nr_underway++;
} }
......
...@@ -480,6 +480,8 @@ int __set_page_dirty_buffers(struct page *page) ...@@ -480,6 +480,8 @@ int __set_page_dirty_buffers(struct page *page)
do { do {
if (buffer_uptodate(bh)) if (buffer_uptodate(bh))
set_buffer_dirty(bh); set_buffer_dirty(bh);
else
buffer_error();
bh = bh->b_this_page; bh = bh->b_this_page;
} while (bh != head); } while (bh != head);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment