Linux block layer
 help / color / mirror / Atom feed
* [PATCH blktests] src/miniublk: fix logical block size setting
@ 2023-11-04 12:17 Akinobu Mita
  2023-11-06  0:33 ` Ming Lei
  2023-11-07  2:24 ` Shinichiro Kawasaki
  0 siblings, 2 replies; 3+ messages in thread
From: Akinobu Mita @ 2023-11-04 12:17 UTC (permalink / raw)
  To: linux-block; +Cc: akinobu.mita, shinichiro.kawasaki, ming.lei

The miniublk always sets the logical block size to 512 bytes when setting
a regular file-backed loop target.
A test fails if the regular file is on a filesystem built on a block
device with a logical block size of 4KB.

$ cd blktests
$ modprobe -r scsi_debug
$ modprobe scsi_debug sector_size=4096 dev_size_mb=2048
$ mkfs.ext4 /dev/sdX
$ mount /dev/sdX results/
$ ./check ublk/003

The logical block size of the ublk block device is set to 512 bytes,
so a request that is not 4KB aligned may occur, and the miniublk will
attempt to process it with direct IO and fail.

The original ublk program already fixed this problem by determining
the logical block size to set based on the block device to which the
target regular file belongs.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 src/miniublk.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/miniublk.c b/src/miniublk.c
index 1c97668..565aa60 100644
--- a/src/miniublk.c
+++ b/src/miniublk.c
@@ -1440,6 +1440,8 @@ static int ublk_loop_tgt_init(struct ublk_dev *dev)
 		p.basic.physical_bs_shift = ilog2(pbs);
 	} else if (S_ISREG(st.st_mode)) {
 		bytes = st.st_size;
+		p.basic.logical_bs_shift = ilog2(st.st_blksize);
+		p.basic.physical_bs_shift = ilog2(st.st_blksize);
 	} else {
 		bytes = 0;
 	}
@@ -1512,6 +1514,8 @@ static int ublk_loop_tgt_recover(struct ublk_dev *dev)
 			return -1;
 	} else if (S_ISREG(st.st_mode)) {
 		bytes = st.st_size;
+		bs = st.st_blksize;
+		pbs = st.st_blksize;
 	} else {
 		bytes = 0;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH blktests] src/miniublk: fix logical block size setting
  2023-11-04 12:17 [PATCH blktests] src/miniublk: fix logical block size setting Akinobu Mita
@ 2023-11-06  0:33 ` Ming Lei
  2023-11-07  2:24 ` Shinichiro Kawasaki
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2023-11-06  0:33 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-block, shinichiro.kawasaki

On Sat, Nov 04, 2023 at 09:17:42PM +0900, Akinobu Mita wrote:
> The miniublk always sets the logical block size to 512 bytes when setting
> a regular file-backed loop target.
> A test fails if the regular file is on a filesystem built on a block
> device with a logical block size of 4KB.
> 
> $ cd blktests
> $ modprobe -r scsi_debug
> $ modprobe scsi_debug sector_size=4096 dev_size_mb=2048
> $ mkfs.ext4 /dev/sdX
> $ mount /dev/sdX results/
> $ ./check ublk/003
> 
> The logical block size of the ublk block device is set to 512 bytes,
> so a request that is not 4KB aligned may occur, and the miniublk will
> attempt to process it with direct IO and fail.
> 
> The original ublk program already fixed this problem by determining
> the logical block size to set based on the block device to which the
> target regular file belongs.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
>  src/miniublk.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/miniublk.c b/src/miniublk.c
> index 1c97668..565aa60 100644
> --- a/src/miniublk.c
> +++ b/src/miniublk.c
> @@ -1440,6 +1440,8 @@ static int ublk_loop_tgt_init(struct ublk_dev *dev)
>  		p.basic.physical_bs_shift = ilog2(pbs);
>  	} else if (S_ISREG(st.st_mode)) {
>  		bytes = st.st_size;
> +		p.basic.logical_bs_shift = ilog2(st.st_blksize);
> +		p.basic.physical_bs_shift = ilog2(st.st_blksize);
>  	} else {
>  		bytes = 0;
>  	}
> @@ -1512,6 +1514,8 @@ static int ublk_loop_tgt_recover(struct ublk_dev *dev)
>  			return -1;
>  	} else if (S_ISREG(st.st_mode)) {
>  		bytes = st.st_size;
> +		bs = st.st_blksize;
> +		pbs = st.st_blksize;
>  	} else {
>  		bytes = 0;

Looks fine,

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH blktests] src/miniublk: fix logical block size setting
  2023-11-04 12:17 [PATCH blktests] src/miniublk: fix logical block size setting Akinobu Mita
  2023-11-06  0:33 ` Ming Lei
@ 2023-11-07  2:24 ` Shinichiro Kawasaki
  1 sibling, 0 replies; 3+ messages in thread
From: Shinichiro Kawasaki @ 2023-11-07  2:24 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-block@vger.kernel.org, ming.lei@redhat.com

On Nov 04, 2023 / 21:17, Akinobu Mita wrote:
> The miniublk always sets the logical block size to 512 bytes when setting
> a regular file-backed loop target.
> A test fails if the regular file is on a filesystem built on a block
> device with a logical block size of 4KB.
> 
> $ cd blktests
> $ modprobe -r scsi_debug
> $ modprobe scsi_debug sector_size=4096 dev_size_mb=2048
> $ mkfs.ext4 /dev/sdX
> $ mount /dev/sdX results/
> $ ./check ublk/003
> 
> The logical block size of the ublk block device is set to 512 bytes,
> so a request that is not 4KB aligned may occur, and the miniublk will
> attempt to process it with direct IO and fail.
> 
> The original ublk program already fixed this problem by determining
> the logical block size to set based on the block device to which the
> target regular file belongs.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

I've applied it. Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-07  2:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-04 12:17 [PATCH blktests] src/miniublk: fix logical block size setting Akinobu Mita
2023-11-06  0:33 ` Ming Lei
2023-11-07  2:24 ` Shinichiro Kawasaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox