qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] docs: document file-posix locking protocol


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH v2] docs: document file-posix locking protocol
Date: Thu, 15 Jul 2021 20:13:40 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

03.07.2021 17:50, Nir Soffer wrote:
On Sat, Jul 3, 2021 at 4:51 PM Vladimir Sementsov-Ogievskiy
<vsementsov@virtuozzo.com> wrote:

[..]

+
+Important notice: Qemu may fallback to POSIX file locks only if OFD locks
+unavailable. Other programs should behave similarly: use POSIX file locks
+only if OFD locks unavailable and if you are OK with drawbacks of POSIX
+file locks (for example, they are lost on close() of any file descriptor
+for that file).

Worth an example.

Hmm.. Copying here the whole #ifdef and probing logic around these locks from 
Qemu is too much..

I can't imagine what small and short could be added here.

Actually I think, OFD is old enough so we shouldn't care too much about older 
kernels without it. Let's just rewrite paragraph to something like this:

Don't use POSIX locks, they are known to be unsafe. Qemu uses OFD, so to be 
compatible, use OFD locks. Qemu may use POSIX locks when OFD is not available 
in the system. Other programs are not recommended to open images on such old 
systems if there is a risk of parallel access to the same image.


Related question, are POSIX locks somehow compatible with OFD locks? If one 
program use OFD and the other use POSIX locks on the same file.. Will it work 
or not?


+
+Image locking examples
+~~~~~~~~~~~~~~~~~~~~~~
+
+Read-only, allow others to write
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[..]

+RW, allow others to read only
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+We want to read and write, and don't want others to modify the image.
+So, let's lock bytes 100, 101, 201. Operation is as follows:
+
+1. rd-lock bytes 100 (read), 101 (write), 201 (don't allow others to write)
+
+.. highlight:: c
+
+    for byte in (100, 101, 201) {

Using python syntax here is a little bit confusing.

Agree, as everything other is C..

Will change to something like

int offsets[] = {100, 101, 201}, *off, *end = offsets + 3;

for (off = offsets; off < end; off++) {



+        struct flock fl = {
+            .l_whence = SEEK_SET,
+            .l_start  = byte,
+            .l_len    = 1,
+            .l_type   = F_RDLCK,
+        };
+        ret = fcntl(fd, F_OFD_SETLK, &fl);
+        if (ret == -1) {
+            /* Error */
+        }
+    }
+

[..]


Having this is great even if the locking protocol is not made public.


Thanks!


--
Best regards,
Vladimir



reply via email to

[Prev in Thread] Current Thread [Next in Thread]