Skip to content

Conversation

@lisongqian
Copy link
Contributor

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]

}

fn read_only(&self) -> bool {
(self.features() & (1u64 << VIRTIO_BLK_F_RO)) != 0
Copy link
Member

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?

Copy link
Contributor Author

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.


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 };
Copy link
Member

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lisongqian lisongqian force-pushed the read-only branch 2 times, most recently from f284a34 to d7d97ff Compare August 25, 2025 13:38
Copy link
Member

@rbradford rbradford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR - thanks!

@rbradford rbradford enabled auto-merge August 25, 2025 16:04
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.")]
Copy link
Member

@phip1611 phip1611 Aug 26, 2025

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:

Suggested change
#[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")]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted - thanks @phip1611

Copy link
Contributor Author

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]>
auto-merge was automatically disabled August 26, 2025 08:56

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
(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

Copy link
Contributor Author

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. :)

Copy link
Member

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!

@rbradford rbradford added this pull request to the merge queue Aug 26, 2025
Merged via the queue into cloud-hypervisor:main with commit 92370e8 Aug 26, 2025
39 of 40 checks passed
@lisongqian lisongqian deleted the read-only branch August 27, 2025 02:27
cbrewster added a commit to cbrewster/cloud-hypervisor that referenced this pull request Dec 6, 2025
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.
cbrewster added a commit to cbrewster/cloud-hypervisor that referenced this pull request Dec 6, 2025
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.
cbrewster added a commit to cbrewster/cloud-hypervisor that referenced this pull request Dec 6, 2025
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.
cbrewster added a commit to cbrewster/cloud-hypervisor that referenced this pull request Dec 8, 2025
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]>
github-merge-queue bot pushed a commit that referenced this pull request Dec 9, 2025
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants