block: fix short read and short write in AsyncAdaptor#6884
Merged
rbradford merged 1 commit intocloud-hypervisor:mainfrom Dec 21, 2024
Merged
block: fix short read and short write in AsyncAdaptor#6884rbradford merged 1 commit intocloud-hypervisor:mainfrom
rbradford merged 1 commit intocloud-hypervisor:mainfrom
Conversation
The original code relied on the default `read_vectored` or `write_vectored` implementations from the standard library. The default implementation of those functions only uses the first non-empty buffer. That's not correct when there are more than one buffers. Fixes: cloud-hypervisor#6876 Signed-off-by: Wei Liu <liuwe@microsoft.com>
russell-islam
approved these changes
Dec 21, 2024
rbradford
approved these changes
Dec 21, 2024
| .map_err(AsyncIoError::ReadVectored)? | ||
| let mut r = 0; | ||
| for b in slices.iter_mut() { | ||
| r += file.read(b).map_err(AsyncIoError::ReadVectored)?; |
Member
There was a problem hiding this comment.
Would be nice to think about using libc::readv to minimise the syscalls.
Member
Author
There was a problem hiding this comment.
That cannot be done easily. VHDX and QCOW2 disks are not regular files. Their read and write implementation does a bunch of calculation before reading and writing the actual file on disk.
Member
|
@liuw Thank you for fixing the issue. Please add a label |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 original code relied on the default
read_vectoredorwrite_vectoredimplementations from the standard library.The default implementation of those functions only uses the first non-empty buffer. That's not correct when there are more than one buffers.
Fixes: #6876
This should be backported.