Skip to content

block: advisory locks: use byte-range locks to match QEMU behavior#26

Merged
tpressure merged 1 commit intocyberus-technology:gardenlinuxfrom
phip1611:poc-disk-locking-granularity
Oct 21, 2025
Merged

block: advisory locks: use byte-range locks to match QEMU behavior#26
tpressure merged 1 commit intocyberus-technology:gardenlinuxfrom
phip1611:poc-disk-locking-granularity

Conversation

@phip1611
Copy link
Member

@phip1611 phip1611 commented Oct 21, 2025

See commit message for context.

Ticket: https://github.com/cobaltcore-dev/cobaltcore/issues/289

@phip1611 phip1611 self-assigned this Oct 21, 2025
@phip1611 phip1611 force-pushed the poc-disk-locking-granularity branch from 97538ee to 6a32e1c Compare October 21, 2025 08:12
@hertrste
Copy link
Collaborator

Is it possible to have a test for this one? Checking that read access to the disk image is possible while a CHV VM is using it?

@phip1611 phip1611 force-pushed the poc-disk-locking-granularity branch from 6a32e1c to fb7d521 Compare October 21, 2025 08:19
@phip1611
Copy link
Member Author

Is it possible to have a test for this one? Checking that read access to the disk image is possible while a CHV VM is using it?

Not really. I just tried a few things to test this but even in a NFS environment, whole-file locks are just advisory locks. It must be some management policy of OpenStack cinder to treat whole-file advisory locks as mandatory lock.

@phip1611 phip1611 force-pushed the poc-disk-locking-granularity branch from fb7d521 to e5420d2 Compare October 21, 2025 08:21
.disk_image
.size()
.map(|size| LockGranularity::ByteRange(0, size))
.unwrap_or(LockGranularity::WholeFile);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just so I understand everything correctly:

This will basically always result in a byte sized lock?

Even if we do not make it configurable for the user right now, would it make sense to pass the lock granularity more explicitly?

Copy link
Member Author

@phip1611 phip1611 Oct 21, 2025

Choose a reason for hiding this comment

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

This will basically always result in a byte sized lock?

exactly except for if .size() returns Err which I think should almost never happen. From the commit message:

Whole-file locks remain a valid use case and could be supported later.
This patch only provides the necessary groundwork; making it configurable
is out of scope for now.

@hertrste
Copy link
Collaborator

Looks good! Hope that fixes our current problems!

The granularity has significant implications in typical cloud
deployments with network storage. The Linux kernel will sync advisory
locks to network file systems, but these backends may have different
policies and handle locks differently. For example, Netapp speaks a NFS
API but will treat advisory OFD locks for the whole file as mandatory
locks, whereas byte-range locks for the whole file will remain
advisory [0].

As it is a valid use case to prevent multiple CHV instances from
accessing the same disk but disk management software (e.g., Cinder in
OpenStack) should be able to snapshot disks while VMs are running, we
need special control over the lock granularity. Therefore, it is a valid
use case to lock the whole byte range of a disk image without technically
locking the whole file - to get the best of both worlds.

This also brings CHVs behavior in line with QEMU [1].

Whole-file locks remain a valid use case and could be supported later.
This patch only provides the necessary groundwork; making it configurable
is out of scope for now.

[0] https://kb.netapp.com/on-prem/ontap/da/NAS/NAS-KBs/How_is_Mandatory_Locking_supported_for_NFSv4_on_ONTAP_9
[1] <qemu>/util/osdep.c::qemu_lock_fcntl()

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
@phip1611 phip1611 force-pushed the poc-disk-locking-granularity branch from e5420d2 to ddc56ed Compare October 21, 2025 10:45
@tpressure
Copy link

@phip1611 thanks for the quick fix. looks good.

@tpressure tpressure merged commit 7163bfe into cyberus-technology:gardenlinux Oct 21, 2025
20 of 22 checks passed
@phip1611 phip1611 deleted the poc-disk-locking-granularity branch October 21, 2025 15:26
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