Commit a7662236 authored by Jan Kara's avatar Jan Kara Committed by Linus Torvalds

[PATCH] Make ll_rw_block() wait for buffer lock

Introduce new ll_rw_block() operation SWRITE meaning that block layer should
wait for the buffer lock and write-out afterwards.  Hence data in buffers at
the time of call are guaranteed to be submitted to the disk.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e6c9f5c1
...@@ -917,8 +917,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list) ...@@ -917,8 +917,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
* contents - it is a noop if I/O is still in * contents - it is a noop if I/O is still in
* flight on potentially older contents. * flight on potentially older contents.
*/ */
wait_on_buffer(bh); ll_rw_block(SWRITE, 1, &bh);
ll_rw_block(WRITE, 1, &bh);
brelse(bh); brelse(bh);
spin_lock(lock); spin_lock(lock);
} }
...@@ -2793,21 +2792,22 @@ int submit_bh(int rw, struct buffer_head * bh) ...@@ -2793,21 +2792,22 @@ int submit_bh(int rw, struct buffer_head * bh)
/** /**
* ll_rw_block: low-level access to block devices (DEPRECATED) * ll_rw_block: low-level access to block devices (DEPRECATED)
* @rw: whether to %READ or %WRITE or maybe %READA (readahead) * @rw: whether to %READ or %WRITE or %SWRITE or maybe %READA (readahead)
* @nr: number of &struct buffer_heads in the array * @nr: number of &struct buffer_heads in the array
* @bhs: array of pointers to &struct buffer_head * @bhs: array of pointers to &struct buffer_head
* *
* ll_rw_block() takes an array of pointers to &struct buffer_heads, * ll_rw_block() takes an array of pointers to &struct buffer_heads, and
* and requests an I/O operation on them, either a %READ or a %WRITE. * requests an I/O operation on them, either a %READ or a %WRITE. The third
* The third %READA option is described in the documentation for * %SWRITE is like %WRITE only we make sure that the *current* data in buffers
* generic_make_request() which ll_rw_block() calls. * are sent to disk. The fourth %READA option is described in the documentation
* for generic_make_request() which ll_rw_block() calls.
* *
* This function drops any buffer that it cannot get a lock on (with the * This function drops any buffer that it cannot get a lock on (with the
* BH_Lock state bit), any buffer that appears to be clean when doing a * BH_Lock state bit) unless SWRITE is required, any buffer that appears to be
* write request, and any buffer that appears to be up-to-date when doing * clean when doing a write request, and any buffer that appears to be
* read request. Further it marks as clean buffers that are processed for * up-to-date when doing read request. Further it marks as clean buffers that
* writing (the buffer cache won't assume that they are actually clean until * are processed for writing (the buffer cache won't assume that they are
* the buffer gets unlocked). * actually clean until the buffer gets unlocked).
* *
* ll_rw_block sets b_end_io to simple completion handler that marks * ll_rw_block sets b_end_io to simple completion handler that marks
* the buffer up-to-date (if approriate), unlocks the buffer and wakes * the buffer up-to-date (if approriate), unlocks the buffer and wakes
...@@ -2823,11 +2823,13 @@ void ll_rw_block(int rw, int nr, struct buffer_head *bhs[]) ...@@ -2823,11 +2823,13 @@ void ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct buffer_head *bh = bhs[i]; struct buffer_head *bh = bhs[i];
if (test_set_buffer_locked(bh)) if (rw == SWRITE)
lock_buffer(bh);
else if (test_set_buffer_locked(bh))
continue; continue;
get_bh(bh); get_bh(bh);
if (rw == WRITE) { if (rw == WRITE || rw == SWRITE) {
if (test_clear_buffer_dirty(bh)) { if (test_clear_buffer_dirty(bh)) {
bh->b_end_io = end_buffer_write_sync; bh->b_end_io = end_buffer_write_sync;
submit_bh(WRITE, bh); submit_bh(WRITE, bh);
......
...@@ -69,6 +69,7 @@ extern int dir_notify_enable; ...@@ -69,6 +69,7 @@ extern int dir_notify_enable;
#define READ 0 #define READ 0
#define WRITE 1 #define WRITE 1
#define READA 2 /* read-ahead - don't block if no resources */ #define READA 2 /* read-ahead - don't block if no resources */
#define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */
#define SPECIAL 4 /* For non-blockdevice requests in request queue */ #define SPECIAL 4 /* For non-blockdevice requests in request queue */
#define READ_SYNC (READ | (1 << BIO_RW_SYNC)) #define READ_SYNC (READ | (1 << BIO_RW_SYNC))
#define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC)) #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC))
......
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