10 #include <linux/time.h>
15 #include <linux/string.h>
21 #include <linux/uio.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
32 static struct kmem_cache *io_page_cachep, *io_end_cachep;
37 if (io_page_cachep ==
NULL)
40 if (io_end_cachep ==
NULL) {
80 put_io_page(io->
pages[i]);
95 ext4_debug(
"ext4_end_io_nolock: io 0x%p from inode %lu,list->next 0x%p,"
102 "failed to convert unwritten extents to written "
103 "extents -- potential data loss! "
104 "(inode %lu, offset %llu, size %zd, error %d)",
105 inode->
i_ino, offset, size, ret);
118 static void dump_completed_IO(
struct inode *inode)
125 if (list_empty(&
EXT4_I(inode)->i_completed_io_list)) {
126 ext4_debug(
"inode %lu completed_io list is empty\n",
139 ext4_debug(
"io 0x%p from inode %lu,prev 0x%p,next 0x%p\n",
140 io, inode->
i_ino, io0, io1);
164 static int ext4_do_flush_completed_IO(
struct inode *inode,
174 INIT_LIST_HEAD(&to_free);
177 dump_completed_IO(inode);
181 while (!list_empty(&unwritten)) {
184 list_del_init(&io->
list);
186 err = ext4_end_io(io);
199 list_del_init(&io->
list);
201 list_move(&io->
list, &to_free);
212 while (!list_empty(&to_free)) {
214 list_del_init(&io->
list);
226 ext4_do_flush_completed_IO(io->
inode, io);
234 ret = ext4_do_flush_completed_IO(inode,
NULL);
246 INIT_LIST_HEAD(&io->
list);
258 static void buffer_io_error(
struct buffer_head *bh)
261 printk(
KERN_ERR "Buffer I/O error on device %s, logical block %llu\n",
263 (
unsigned long long)bh->b_blocknr);
266 static void ext4_end_bio(
struct bio *bio,
int error)
271 sector_t bi_sector = bio->bi_sector;
274 bio->bi_private =
NULL;
275 bio->bi_end_io =
NULL;
276 if (
test_bit(BIO_UPTODATE, &bio->bi_flags))
282 struct buffer_head *bh, *
head;
284 loff_t io_end_offset;
289 head = page_buffers(page);
292 io_end_offset = io_end->
offset + io_end->
size;
298 (offset+bh->b_size <= io_end_offset))
301 offset += bh->b_size;
302 bh = bh->b_this_page;
303 }
while (bh != head);
306 put_io_page(io_end->
pages[i]);
309 inode = io_end->
inode;
313 ext4_warning(inode->
i_sb,
"I/O error writing to inode %lu "
314 "(offset %llu size %ld starting block %llu)",
316 (
unsigned long long) io_end->
offset,
332 struct bio *bio = io->
io_bio;
348 struct buffer_head *bh)
351 struct page *page = bh->b_page;
358 bio = bio_alloc(
GFP_NOIO,
min(nvecs, BIO_MAX_PAGES));
359 bio->bi_sector = bh->b_blocknr * (bh->b_size >> 9);
360 bio->bi_bdev = bh->b_bdev;
361 bio->bi_private = io->
io_end = io_end;
362 bio->bi_end_io = ext4_end_bio;
376 struct buffer_head *bh)
381 if (buffer_new(bh)) {
382 clear_buffer_new(bh);
386 if (!buffer_mapped(bh) || buffer_delay(bh)) {
387 if (!buffer_mapped(bh))
388 clear_buffer_dirty(bh);
399 ret = io_submit_init(io, inode, wbc, bh);
406 goto submit_and_retry;
407 if (buffer_uninit(bh))
408 ext4_set_io_unwritten_flag(inode, io_end);
412 if (ret != bh->b_size)
413 goto submit_and_retry;
427 struct inode *inode = page->
mapping->host;
428 unsigned block_start, block_end, blocksize;
430 struct buffer_head *bh, *
head;
435 BUG_ON(!PageLocked(page));
436 BUG_ON(PageWriteback(page));
447 set_page_writeback(page);
448 ClearPageError(page);
450 for (bh = head = page_buffers(page), block_start = 0;
451 bh != head || !block_start;
452 block_start = block_end, bh = bh->b_this_page) {
454 block_end = block_start + blocksize;
455 if (block_start >= len) {
467 zero_user_segment(page, block_start, block_end);
468 clear_buffer_dirty(bh);
469 set_buffer_uptodate(bh);
472 clear_buffer_dirty(bh);
473 ret = io_submit_add_bh(io, io_page, inode, wbc, bh);
493 put_io_page(io_page);