do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
Subsystems (2)
PATCH 1/1 do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned
The code currently uses sdio->blkbits to compute the number of blocks to be cleaned. However sdio->blkbits is derived from the logical block size of the underlying block device (Refer to the definition of do_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.
This commit fixes the bug by using inode->i_blkbits to compute the number of blocks to be cleaned.
--- fs/direct-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/direct-io.c +2 -1
@@ -905,6 +905,7 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,static int do_direct_IO (struct dio *dio,struct dio_submit *sdio,struct buffer_head *map_bh) { +const unsigned i_blkbits = dio->inode->i_blkbits;const unsigned blkbits = sdio->blkbits;int ret =0 ;
@@ -949,7 +950,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,clean_bdev_aliases ( map_bh->b_bdev, map_bh->b_blocknr, - map_bh->b_size >> blkbits); + map_bh->b_size >> i_blkbits); }if (!sdio->blkfactor)
Signature · 1 line
2.5.5
Quoted 10 lines · Chandan Rajendra
The code currently uses
sdio->blkbitsto compute the number of blocks to be cleaned. Howeversdio->blkbitsis derived from the logical block size of the underlying block device (Refer to the definition ofdo_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.This commit fixes the bug by using
inode->i_blkbitsto compute the number of blocks to be cleaned.
Looks fine,
Jens Axboe
maintainerQuoted 10 lines · Chandan Rajendra
The code currently uses
sdio->blkbitsto compute the number of blocks to be cleaned. Howeversdio->blkbitsis derived from the logical block size of the underlying block device (Refer to the definition ofdo_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.This commit fixes the bug by using
inode->i_blkbitsto compute the number of blocks to be cleaned.
Thanks, added for 4.10.
Signature · 1 line
Jens Axboe
Quoted 21 lines · Chandan Rajendra
The code currently uses
sdio->blkbitsto compute the number of blocks to be cleaned. Howeversdio->blkbitsis derived from the logical block size of the underlying block device (Refer to the definition ofdo_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.This commit fixes the bug by using
inode->i_blkbitsto compute the number of blocks to be cleaned.Signed-off-by Chandan Rajendra <[email protected]>--- fs/direct-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/direct-io.c +0
-0
fs/direct-io.c static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio, · line 908
Quoted 4 lines
fs/direct-io.c +1
-0@@ -905,6 +905,7 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,static int do_direct_IO (struct dio *dio,struct dio_submit *sdio,struct buffer_head *map_bh) { +const unsigned i_blkbits = dio->inode->i_blkbits;
NAK. Please see commit ab73857e354 ("direct-io: don't read inode->i_blkbits multiple times").
I think you want:
const unsigned i_blkbits = sdio->blkbits + sdio->blkfactor;
as is used elsewhere in the code.
Cheers,
Jeff
Quoted 10 lines · Chandan Rajendra
The code currently uses
sdio->blkbitsto compute the number of blocks to be cleaned. Howeversdio->blkbitsis derived from the logical block size of the underlying block device (Refer to the definition ofdo_blockdev_direct_IO()). Due to this, generic/299 test would rarely fail when executed on an ext4 filesystem with 64k as the block size and when using a virtio based disk (having 512 byte as the logical block size) inside a kvm guest.This commit fixes the bug by using
inode->i_blkbitsto compute the number of blocks to be cleaned.
Ah, good catch. You can add:
Honza
Quoted 29 lines
Signed-off-by Chandan Rajendra <[email protected]>--- fs/direct-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/direct-io.c +2
-1@@ -905,6 +905,7 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,static int do_direct_IO (struct dio *dio,struct dio_submit *sdio,struct buffer_head *map_bh) { +const unsigned i_blkbits = dio->inode->i_blkbits;const unsigned blkbits = sdio->blkbits;int ret =0 ;@@ -949,7 +950,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio,clean_bdev_aliases ( map_bh->b_bdev, map_bh->b_blocknr, - map_bh->b_size >> blkbits); + map_bh->b_size >> i_blkbits); }if (!sdio->blkfactor)Signature · 1 line
2.5.5
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 1/1 direct-io: don't introduce another read of inode->i_blkbits
In reply to Chandan RajendraCommit 20ce44d545844 ("do_direct_IO: Use inode->i_blkbits to compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commit ab73857e354ab ("direct-io:
don't read inode->i_blkbits multiple times") for the reasoning, and commit b87570f5d3496 ("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.
---
Chandan, can you please test this to ensure this still fixes your problem?
fs/direct-io.c +1 -1
@@ -905,8 +905,8 @@ static inline void dio_zero_block(struct dio *dio, struct dio_submit *sdio,static int do_direct_IO (struct dio *dio,struct dio_submit *sdio,struct buffer_head *map_bh) { -const unsigned i_blkbits = dio->inode->i_blkbits;const unsigned blkbits = sdio->blkbits; +const unsigned i_blkbits = blkbits + sdio->blkfactor;int ret =0 ;while (sdio->block_in_file < sdio->final_block_in_request) {
Jens Axboe
maintainerRe: [PATCH] direct-io: don't introduce another read of inode->i_blkbits
Quoted 9 lines · Jeff Moyer
Commit
20ce44d545844("do_direct_IO: Useinode->i_blkbitsto compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commitab73857e354ab("direct-io:
don't readinode->i_blkbitsmultiple times") for the reasoning, and commitb87570f5d3496("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.
Quoted 5 lines
Fixes 20ce44d545844Signed-off-by Jeff Moyer <[email protected]>---
Chandan, can you please test this to ensure this still fixes your problem?
Please, that would be great. And if so, then let's fold the two.
Signature · 1 line
Jens Axboe
Re: [PATCH] direct-io: don't introduce another read of inode->i_blkbits
In reply to Jeff MoyerQuoted 9 lines · Jeff Moyer
Commit
20ce44d545844("do_direct_IO: Useinode->i_blkbitsto compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commitab73857e354ab("direct-io:
don't readinode->i_blkbitsmultiple times") for the reasoning, and commitb87570f5d3496("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.
Quoted 5 lines
Fixes 20ce44d545844Signed-off-by Jeff Moyer <[email protected]>---
Chandan, can you please test this to ensure this still fixes your problem?
This patch fixes the failure,
Signature · 1 line
chandan
Jens Axboe
maintainerRe: [PATCH] direct-io: don't introduce another read of inode->i_blkbits
Quoted 13 lines · Chandan Rajendra
Quoted 12 lines · Jeff Moyer
Commit
20ce44d545844("do_direct_IO: Useinode->i_blkbitsto compute block count to be cleaned") introduced a regression: if the block size of the block device is changed while a direct I/O request is being setup, it can result in a panic. See commitab73857e354ab("direct-io:
don't readinode->i_blkbitsmultiple times") for the reasoning, and commitb87570f5d3496("Fix a crash when block device is read and block size is changed at the same time") for a more detailed problem description and reproducer.Fixes 20ce44d545844Signed-off-by Jeff Moyer <[email protected]>
Quoted 7 lines
Quoted 2 lines
---
Chandan, can you please test this to ensure this still fixes your problem?This patch fixes the failure,
Tested-by Chandan Rajendra <[email protected]>
I've updated the patch, thanks guys.
Signature · 1 line
Jens Axboe