vmm: config: Expose disk lock granularity option by vieux · Pull Request #7763 · cloud-hypervisor/cloud-hypervisor · GitHub
Skip to content

vmm: config: Expose disk lock granularity option#7763

Merged
rbradford merged 2 commits intocloud-hypervisor:mainfrom
vieux:disk-lock-granularity-config
Mar 8, 2026
Merged

vmm: config: Expose disk lock granularity option#7763
rbradford merged 2 commits intocloud-hypervisor:mainfrom
vieux:disk-lock-granularity-config

Conversation

@vieux
Copy link
Copy Markdown
Contributor

@vieux vieux commented Feb 26, 2026

Add a per-disk lock_granularity parameter that lets users choose between byte-range OFD locks and whole-file OFD locks:

--disk path=/foo.img,lock_granularity=byte-range
--disk path=/bar.img,lock_granularity=full

Byte-range is the default and matches QEMU behavior, working best with storage backends like NetApp where whole-file OFD locks are treated as mandatory. The full option restores the original whole-file locking for environments that depend on it.

This plumbs the LockGranularity enum introduced in PR #7494 through the config layer (CLI, OpenAPI, DiskConfig) down to virtio-devices.

Closes: #7553

@vieux vieux requested a review from a team as a code owner February 26, 2026 23:00
@phip1611 phip1611 self-requested a review February 27, 2026 07:21
Copy link
Copy Markdown
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Left some remarks

Comment thread vmm/src/api/openapi/cloud-hypervisor.yaml Outdated
Comment thread vmm/src/config.rs Outdated
Comment thread vmm/src/vm_config.rs Outdated
Comment thread vmm/src/vm_config.rs Outdated
Comment thread vmm/src/vm_config.rs Outdated
Comment thread vmm/src/vm_config.rs Outdated
Comment thread vmm/src/vm_config.rs Outdated
@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Feb 27, 2026

Copy link
Copy Markdown
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.

What's OFD? And I don't see any documentation updates?

Comment thread vmm/src/api/openapi/cloud-hypervisor.yaml Outdated
Comment thread vmm/src/config.rs Outdated
@phip1611
Copy link
Copy Markdown
Member

phip1611 commented Mar 2, 2026

What's OFD?

The locking mechanism I introduced in #6974 is based on Open File-Description locks. UNIX and POSIX file locks are fundamentally broken; OFD is the modern API of Linux

@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Mar 2, 2026

@rbradford For documentation, would an update to docs/device_model.md in the virtio-block section be sufficient, or would you also like a release-notes entry?

@rbradford
Copy link
Copy Markdown
Member

@rbradford For documentation, would an update to docs/device_model.md in the virtio-block section be sufficient, or would you also like a release-notes entry?

My mistake - I though there was a document for the --disk option seems I was mistaken.

Copy link
Copy Markdown
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.

Maybe add a docs/disk_locking.md to provide details. I don't think the OpenAPI yaml file is the correct place for such documentation.

And is there no way we can detect this and just do the right thing rather than have to have it be an option?

@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Mar 2, 2026

Will add docs/disk_locking.md

Regarding auto-detection, the default (byte-range) already does the right thing in most cases. The issue is that some NFS server implementations (e.g. NetApp) treat whole-file OFD locks as mandatory, but there's no reliable way to detect this from the client side I believe.

Comment thread vmm/src/api/openapi/cloud-hypervisor.yaml Outdated
@vieux vieux force-pushed the disk-lock-granularity-config branch from 6f75bd2 to 75ef46f Compare March 2, 2026 20:46
Comment thread docs/disk_locking.md Outdated
Comment thread docs/disk_locking.md
@vieux vieux force-pushed the disk-lock-granularity-config branch from 75ef46f to d164f8d Compare March 2, 2026 21:40
@vieux vieux requested review from phip1611 and rbradford March 3, 2026 03:48
Comment thread docs/disk_locking.md Outdated
Comment thread docs/disk_locking.md
@phip1611
Copy link
Copy Markdown
Member

phip1611 commented Mar 3, 2026

Almost there! Thanks for working on that

@vieux vieux force-pushed the disk-lock-granularity-config branch from d164f8d to a2669ad Compare March 3, 2026 10:02
@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Mar 3, 2026

@phip1611 Sounds good, used your exact suggestions :)

@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Mar 3, 2026

(I don't think I can re-trigger CI on my side, seems like a temporary failure)

Copy link
Copy Markdown
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

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

awesome, let's ship it!

Comment thread vmm/src/device_manager.rs Outdated
Comment thread vmm/src/config.rs
@vieux vieux force-pushed the disk-lock-granularity-config branch 2 times, most recently from 159a947 to 00f62dd Compare March 4, 2026 18:52
@phip1611
Copy link
Copy Markdown
Member

phip1611 commented Mar 5, 2026

Please fix CI! You can also locally run git rebase -i HEAD~3 --exec "cargo clippy" to address the issues

@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Mar 5, 2026

@phip1611 as I mentioned in the thread I'm waiting in @rbradford to see if they're happy with the new approach, I kept it as a separate commit for ease of review. If it's 👍 I'll squash to be mergeable. Does that work for you?

Add a per-disk lock_granularity parameter that lets users choose
between byte-range OFD locks and whole-file OFD locks:

  --disk path=/foo.img,lock_granularity=byte-range
  --disk path=/bar.img,lock_granularity=full

Byte-range is the default and matches QEMU behavior, working
best with storage backends where whole-file OFD locks are treated
as mandatory. The full option restores the original whole-file
locking for environments that depend on it.

The LockGranularityChoice enum and its FromStr impl live in the
block crate alongside the existing LockGranularity type. The
Block device converts the user-facing choice to the internal
LockGranularity at lock time, keeping device_manager.rs simple.

Closes: cloud-hypervisor#7553

Signed-off-by: Victor Vieux <vieux@repl.it>
Add docs/disk_locking.md explaining advisory OFD locking, the
lock_granularity parameter, byte-range vs whole-file semantics,
and fallback behavior.

Signed-off-by: Victor Vieux <vieux@repl.it>
@vieux vieux force-pushed the disk-lock-granularity-config branch from 00f62dd to d1ad2e2 Compare March 6, 2026 20:10
@vieux
Copy link
Copy Markdown
Contributor Author

vieux commented Mar 6, 2026

@rbradford rbradford added this pull request to the merge queue Mar 8, 2026
Merged via the queue into cloud-hypervisor:main with commit 01e4053 Mar 8, 2026
37 checks passed
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.

Expose disk lock granularity as a user-configurable option

3 participants