* [PATCH v3 2/3] ext4: Wait for writeback to complete while making pages writable
[not found] ` <20110422000226.GA22189@tux1.beaverton.ibm.com>
@ 2011-05-04 17:41 ` Darrick J. Wong
2011-05-04 17:42 ` [PATCH v3 3/3] mm: Wait for writeback when grabbing pages to begin a write Darrick J. Wong
1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2011-05-04 17:41 UTC (permalink / raw)
To: Theodore Ts'o
Cc: Christoph Hellwig, Chris Mason, Jeff Layton, Jan Kara,
Dave Chinner, Joel Becker, Martin K. Petersen, Jens Axboe,
linux-kernel, linux-fsdevel, Mingming Cao, linux-scsi,
Dave Hansen, linux-mm, linux-ext4
In order to stabilize pages during disk writes, ext4_page_mkwrite must wait for
writeback operations to complete before making a page writable. Furthermore,
the function must return locked pages, and recheck the writeback status if the
page lock is ever dropped.
Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---
fs/ext4/inode.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 3db34b2..1d162a2 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5809,15 +5809,19 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
goto out_unlock;
}
ret = 0;
- if (PageMappedToDisk(page))
- goto out_unlock;
+
+ lock_page(page);
+ wait_on_page_writeback(page);
+ if (PageMappedToDisk(page)) {
+ up_read(&inode->i_alloc_sem);
+ return VM_FAULT_LOCKED;
+ }
if (page->index == size >> PAGE_CACHE_SHIFT)
len = size & ~PAGE_CACHE_MASK;
else
len = PAGE_CACHE_SIZE;
- lock_page(page);
/*
* return if we have all the buffers mapped. This avoid
* the need to call write_begin/write_end which does a
@@ -5827,8 +5831,8 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
if (page_has_buffers(page)) {
if (!walk_page_buffers(NULL, page_buffers(page), 0, len, NULL,
ext4_bh_unmapped)) {
- unlock_page(page);
- goto out_unlock;
+ up_read(&inode->i_alloc_sem);
+ return VM_FAULT_LOCKED;
}
}
unlock_page(page);
@@ -5848,6 +5852,16 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
if (ret < 0)
goto out_unlock;
ret = 0;
+
+ /*
+ * write_begin/end might have created a dirty page and someone
+ * could wander in and start the IO. Make sure that hasn't
+ * happened.
+ */
+ lock_page(page);
+ wait_on_page_writeback(page);
+ up_read(&inode->i_alloc_sem);
+ return VM_FAULT_LOCKED;
out_unlock:
if (ret)
ret = VM_FAULT_SIGBUS;
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v3 3/3] mm: Wait for writeback when grabbing pages to begin a write
[not found] ` <20110422000226.GA22189@tux1.beaverton.ibm.com>
2011-05-04 17:41 ` [PATCH v3 2/3] ext4: Wait for writeback to complete while making pages writable Darrick J. Wong
@ 2011-05-04 17:42 ` Darrick J. Wong
2011-05-04 18:48 ` Christoph Hellwig
1 sibling, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2011-05-04 17:42 UTC (permalink / raw)
To: Theodore Ts'o
Cc: Christoph Hellwig, Chris Mason, Jeff Layton, Jan Kara,
Dave Chinner, Joel Becker, Martin K. Petersen, Jens Axboe,
linux-kernel, linux-fsdevel, Mingming Cao, linux-scsi,
Dave Hansen, linux-mm, linux-ext4
When grabbing a page for a buffered IO write, the mm should wait for writeback
on the page to complete so that the page does not become writable during the IO
operation.
Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---
mm/filemap.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index c641edf..c22675f 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2287,8 +2287,10 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping,
gfp_notmask = __GFP_FS;
repeat:
page = find_lock_page(mapping, index);
- if (page)
+ if (page) {
+ wait_on_page_writeback(page);
return page;
+ }
page = __page_cache_alloc(mapping_gfp_mask(mapping) & ~gfp_notmask);
if (!page)
@@ -2301,6 +2303,7 @@ repeat:
goto repeat;
return NULL;
}
+ wait_on_page_writeback(page);
return page;
}
EXPORT_SYMBOL(grab_cache_page_write_begin);
^ permalink raw reply related [flat|nested] 3+ messages in thread