Closed ddiss closed 2 years ago
t'd be nice if ublk tgt_loop obtained the I/O alignment requirements from the underlying >loopback device and advertised the same values, or alternatively supported a blocksize >parameter with ublk add.
Yeah, it should be easy to figure out these underlying parameters via ioctl(blk device), and just copy the kernel loop's logic.
Feel free to cook a patch!
Fixed by cfc561a ("tgt_loop: set correct block size if backing file is block device")
Thanks for the fix! This covers the tgt_loop(zram) case, but there's still an issue with file-backed direct-io for tgt_loop(zram->XFS->file). It could be similarly handled with something like:
--- a/tgt_loop.cpp
+++ b/tgt_loop.cpp
@@ -110,6 +110,8 @@ static int loop_init_tgt(struct ublksrv_dev *dev, int type, int argc, char
can_discard = backing_supports_discard(file);
} 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);
can_discard = true;
} else {
bytes = 0;
Looking at kernel loopback, it appears to disable directio for cases like this.
Yeah, you are right.
I think buffered io option should be provided as one command line too for ublk-loop.
And if the underlying file/device can't support dio, buffered io needs to be switched to.
However, it is much easier to do this kind of thing in userspace than kernel.
I will submit one patch after related details are figured out.
Thanks,
Now the issue has been addressed by:
bf54b6b tgt_loop: improve for handling loop direct io
Now the issue has been addressed by:
bf54b6b tgt_loop: improve for handling loop direct io
Works for me - thanks. FWIW, one helpful statx change which may be relevant in the future is: https://lore.kernel.org/lkml/20220827065851.135710-6-ebiggers@kernel.org/T/
Linux zram devices advertise a 4k logical block size by default:
When using the
tgt_loop
backend to expose a 4k zram device via ublk, the logical block size is advertised as 512 bytes:This results in 512 aligned I/O attempts from the block layer, instead of the 4k aligned request required by zram, causing I/O failures:
Changing the hardcoded
struct ublk_params.basic.logical_bs_shift
values to advertise 4k alignment avoids this error, e.g.:It'd be nice if ublk tgt_loop obtained the I/O alignment requirements from the underlying loopback device and advertised the same values, or alternatively supported a blocksize parameter with
ublk add
.BTW, thanks for working on ublk - it's an impressive feature :-)