-
Notifications
You must be signed in to change notification settings - Fork 565
block: Using feature bits to check the read-only flag #7294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
virtio-devices/src/block.rs
Outdated
| } | ||
|
|
||
| fn read_only(&self) -> bool { | ||
| (self.features() & (1u64 << VIRTIO_BLK_F_RO)) != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code above uses has_feature() but this does it manually - any reason for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing. I just feel a little bit strange to include a function declaration in this file of these structs' definitions.
virtio-devices/src/block.rs
Outdated
|
|
||
| impl BlockEpollHandler { | ||
| fn check_request(features: u64, request_type: RequestType) -> result::Result<(), ExecuteError> { | ||
| let has_feature = |feature_pos: u64| -> bool { (features & (1u64 << feature_pos)) != 0 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract this to a common piece of code and and then use this for read_only ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
f284a34 to
d7d97ff
Compare
rbradford
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR - thanks!
block/src/lib.rs
Outdated
| Read(#[source] GuestMemoryError), | ||
| #[error("Failed to read_exact")] | ||
| ReadExact(#[source] io::Error), | ||
| #[error("Can't execute an operation other than `read` on a read-only device.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to align style with other error messages:
| #[error("Can't execute an operation other than `read` on a read-only device.")] | |
| #[error("Can't execute an operation other than `read` on a read-only device")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted - thanks @phip1611
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
This patch changes the read-only check using acked features bit, which will help to check more features. Signed-off-by: Songqian Li <[email protected]>
Head branch was pushed to by a user without write access
| } | ||
|
|
||
| fn has_feature(features: u64, feature_flag: u64) -> bool { | ||
| (features & (1u64 << feature_flag)) != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| (features & (1u64 << feature_flag)) != 0 | |
| (features & (1 << feature_flag)) != 0 |
You can leave it as it, but this makes things harder to read than necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review. Align style with others, so remains unchanged.
BTW, you can make multiple comments at once instead of making one at a time, which will save a lot of time. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, you can make multiple comments at once instead of making one at a time, which will save a lot of time. :)
Thanks! I'm used to the one-comment-at-a-time approach. I will try to put more focus on the review feature to submit all my comments in a batch in the future!
92370e8
cloud-hypervisor#7294 adjusted the checks for read-only requests made to virtio-blk devices and started rejecting VIRTIO_BLK_T_GET_ID requests. These requests do not perform any writes and are needed in order to access device serials from within the guest.
cloud-hypervisor#7294 adjusted the checks for read-only requests made to virtio-blk devices and started rejecting VIRTIO_BLK_T_GET_ID requests. These requests do not perform any writes and are needed in order to access device serials from within the guest.
cloud-hypervisor#7294 adjusted the checks for read-only requests made to virtio-blk devices and started rejecting VIRTIO_BLK_T_GET_ID requests. These requests do not perform any writes and are needed in order to access device serials from within the guest.
cloud-hypervisor#7294 adjusted the checks for read-only requests made to virtio-blk devices and started rejecting VIRTIO_BLK_T_GET_ID requests. These requests do not perform any writes and are needed in order to access device serials from within the guest. Signed-off-by: Connor Brewster <[email protected]>
#7294 adjusted the checks for read-only requests made to virtio-blk devices and started rejecting VIRTIO_BLK_T_GET_ID requests. These requests do not perform any writes and are needed in order to access device serials from within the guest. Signed-off-by: Connor Brewster <[email protected]>
block: Using feature bits to check the read-only flag
This patch changes the read-only check using acked features bit, which will help to check more features.
Signed-off-by: Songqian Li [email protected]