block: Query actual DIO alignment for file-backed images - #7767
Conversation
49b12d3 to
e1d22e9
Compare
|
@weltling I think there are some cargo formatting issues kicking it out of merge queue |
Thanks for the review, @rbradford! Yeah. Must have started failing today of all days :) I filed #7770 to fix the nightly issue, will rebase this one then. Thanks |
|
I've been reflecting on this PR a bit over the weekend. I'm not sure we should use both methods for detection. What does the new method do that the old one doesn't? And the old one will continue to work. I think it's fine to depend on Linux 6.1 for this functionality and just stick with the new one if there is some reason why it's better. |
| @@ -1161,8 +1161,83 @@ impl DiskTopology { | |||
| Ok(block_size) | |||
| } | |||
|
|
|||
| /// Query the O_DIRECT alignment requirement for a regular file. | |||
There was a problem hiding this comment.
Your commit message and comment should give a rationale why statx(STATX_DIOALIGN) is better and preferred over the fstatvfs approach
There was a problem hiding this comment.
Done, updated the commit message and the comment. Thanks
e1d22e9 to
1dbc56a
Compare
Agreed, dropped the Keeping the Thanks |
| } | ||
| } | ||
|
|
||
| debug!("DIO alignment query failed, falling back to default {SECTOR_SIZE}"); |
DiskTopology::probe() returned a hardcoded 512 for regular files, causing O_DIRECT failures on volumes with larger block sizes (e.g. 4K). Use statx(STATX_DIOALIGN) (Linux >= 6.1) to query the real per file DIO memory and offset alignment. Unlike fstatvfs().f_bsize, which only returns the filesystem preferred I/O block size, STATX_DIOALIGN reports the true DIO constraints accounting for the filesystem, underlying block device, and any stacking (loop, dm, etc.). Signed-off-by: Anatol Belski <[email protected]>
Test valid power of two alignment, layout compatibility, direct helper coverage, and O_DIRECT write/read roundtrip. Signed-off-by: Anatol Belski <[email protected]>
Move LOOP_CTL_GET_FREE + open + LOOP_CONFIGURE into the retry loop so each attempt requests a fresh free device number. Previously, a parallel test could claim the same device between GET_FREE and CONFIGURE, and retrying the same stale number would always fail with EBUSY. Signed-off-by: Anatol Belski <[email protected]>
Verify that DiskTopology::probe() returns the correct DIO alignment for a regular file on a 4k sector filesystem. The test creates a loop device with --sector-size 4096, formats ext4, places a raw disk image on it, and boots a VM with direct=on. Asserts that the guest sees a 4096 byte logical sector and that a DIO write/read roundtrip succeeds. Signed-off-by: Anatol Belski <[email protected]>
Boot a VM with a 4k sector loop device passed with direct=on and image_type=raw. Assert that the guest sees a 4096 byte logical sector and that a DIO write/read roundtrip at 4096 byte alignment succeeds. Signed-off-by: Anatol Belski <[email protected]>
1dbc56a to
faa1803
Compare
Follow-up to #7735.
DiskTopology::probe()returned a hardcoded 512 for regular files, causing O_DIRECT failures on volumes with larger block sizes (e.g. 4K).This PR queries the real alignment via
statx(STATX_DIOALIGN)(Linux >= 6.1) and automatically detects whether the file was opened withO_DIRECTviafcntl(F_GETFL).An integration test boots a VM with a file backed disk on a 4K sector filesystem (loop device + ext4) and verifies the guest sees the correct logical sector size and that DIO I/O succeeds.
There is also a small refactoring of
create_loop_device()in the integration test helpers to fix a race where parallel tests could claim the same loop device.Additionally, this PR contains an integration test for the block device alignment path from #7735.