Enable virtio-blk to access hostOS /dev/ block devices #572
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The user may not always have a disk image but might have a /dev/x block device, such as a USB drive that they want to share with the guest OS. So, allowing this type of virtio-blk source is intuitive. To support this, ioctl is used to retrieve the actual size of the /dev/x block device. This implementation supports both Apple and Linux platforms.
Testing
macOS:
Linux
Might see:
macOS
Linux
Known Issue:
On macOS/arm64, OS v15.3.1, the /dev/ block device cannot be
mmap
with error log:ERROR src/devices/virtio-blk.c:475: Could not map disk <block-device>
.After some debugging, the errno is set to
EINVAL
. Then, reading the man page ofmmap
in the system:The page size in my system is 16KiB, which the block device size aligned of (128MiB % 16KiB == 0). The rest of the requirements appear to be met, so this seems a bit strange to me. If anyone has a macOS/arm64 machine, maybe can give it a try.
Summary by Bito
This pull request enhances the virtio-blk driver to enable access to hostOS /dev/ block devices, including USB drives, for guest OS sharing. It introduces ioctl calls for device size retrieval and improves error handling and disk size logic for better reliability across platforms.Unit tests added: True
Estimated effort to review (1-5, lower is better): 2