aboutsummaryrefslogtreecommitdiffstats
path: root/fs/direct-io.c
diff options
context:
space:
mode:
authorTao Ma <boyu.mt@taobao.com>2012-01-12 20:20:33 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-12 23:13:12 -0500
commitae55e1aaa7e2e57e538cb98cf617f511c5dc4f73 (patch)
tree3f3981dd7617c656e7a6ba2f3a83a14637c63221 /fs/direct-io.c
parent45dac90f0ca7d9efeda8f3d416c808c71207bf20 (diff)
fs/direct-io.c: calculate fs_count correctly in get_more_blocks()
In get_more_blocks(), we use dio_count to calcuate fs_count and do some tricky things to increase fs_count if dio_count isn't aligned. But actually it still has some corner cases that can't be coverd. See the following example: dio_write foo -s 1024 -w 4096 (direct write 4096 bytes at offset 1024). The same goes if the offset isn't aligned to fs_blocksize. In this case, the old calculation counts fs_count to be 1, but actually we will write into 2 different blocks (if fs_blocksize=4096). The old code just works, since it will call get_block twice (and may have to allocate and create extents twice for filesystems like ext4). So we'd better call get_block just once with the proper fs_count. Signed-off-by: Tao Ma <boyu.mt@taobao.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Christoph Hellwig <hch@lst.de> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/direct-io.c')
-rw-r--r--fs/direct-io.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/fs/direct-io.c b/fs/direct-io.c
index d740ab67ff6e..389863f59cda 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -580,9 +580,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
580{ 580{
581 int ret; 581 int ret;
582 sector_t fs_startblk; /* Into file, in filesystem-sized blocks */ 582 sector_t fs_startblk; /* Into file, in filesystem-sized blocks */
583 sector_t fs_endblk; /* Into file, in filesystem-sized blocks */
583 unsigned long fs_count; /* Number of filesystem-sized blocks */ 584 unsigned long fs_count; /* Number of filesystem-sized blocks */
584 unsigned long dio_count;/* Number of dio_block-sized blocks */
585 unsigned long blkmask;
586 int create; 585 int create;
587 586
588 /* 587 /*
@@ -593,11 +592,9 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
593 if (ret == 0) { 592 if (ret == 0) {
594 BUG_ON(sdio->block_in_file >= sdio->final_block_in_request); 593 BUG_ON(sdio->block_in_file >= sdio->final_block_in_request);
595 fs_startblk = sdio->block_in_file >> sdio->blkfactor; 594 fs_startblk = sdio->block_in_file >> sdio->blkfactor;
596 dio_count = sdio->final_block_in_request - sdio->block_in_file; 595 fs_endblk = (sdio->final_block_in_request - 1) >>
597 fs_count = dio_count >> sdio->blkfactor; 596 sdio->blkfactor;
598 blkmask = (1 << sdio->blkfactor) - 1; 597 fs_count = fs_endblk - fs_startblk + 1;
599 if (dio_count & blkmask)
600 fs_count++;
601 598
602 map_bh->b_state = 0; 599 map_bh->b_state = 0;
603 map_bh->b_size = fs_count << dio->inode->i_blkbits; 600 map_bh->b_size = fs_count << dio->inode->i_blkbits;