From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Nir Soffer <nsoffer@redhat.com>
Cc: qemu-block <qemu-block@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
Eric Blake <eblake@redhat.com>,
den@openvz.org, Daniel Berrange <berrange@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH v2] docs: document file-posix locking protocol
Date: Thu, 15 Jul 2021 20:13:40 +0300 [thread overview]
Message-ID: <a18fd577-7f23-2e4f-0833-1ac13310313d@virtuozzo.com> (raw)
In-Reply-To: <CAMRbyysqP+by8PrF7WQD4D2R7GXLwya4L1GMm8V8oHPS3AyJjw@mail.gmail.com>
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
next prev parent reply other threads:[~2021-07-15 17:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-03 13:50 [PATCH v2] docs: document file-posix locking protocol Vladimir Sementsov-Ogievskiy
2021-07-03 14:50 ` Nir Soffer
2021-07-05 7:55 ` Vladimir Sementsov-Ogievskiy
2021-07-05 8:26 ` Denis V. Lunev
2021-07-15 17:13 ` Vladimir Sementsov-Ogievskiy [this message]
2021-07-15 17:19 ` Daniel P. Berrangé
2021-07-15 20:00 ` Vladimir Sementsov-Ogievskiy
2021-07-16 16:21 ` Vladimir Sementsov-Ogievskiy
2021-07-16 18:47 ` Vladimir Sementsov-Ogievskiy
2021-07-16 20:35 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a18fd577-7f23-2e4f-0833-1ac13310313d@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).