qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v4 21/29] util: use fcntl() for qemu_write_pidfi


From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH v4 21/29] util: use fcntl() for qemu_write_pidfile() locking
Date: Wed, 29 Aug 2018 01:41:14 +0200

Hi

On Tue, Aug 28, 2018 at 6:01 PM Daniel P. Berrangé <address@hidden> wrote:
>
> On Fri, Jul 13, 2018 at 03:09:08PM +0200, Marc-André Lureau wrote:
> > According to Daniel Berrange, fcntl() locks have better portable
> > semantics than lockf().
>
> Specifically I was referring to this from 'man lockf':
>
>    On Linux, lockf() is just an interface  on  top  of  fcntl(2)  locking.
>    Many other systems implement lockf() in this way, but note that POSIX.1
>    leaves the relationship between lockf() and fcntl(2) locks unspecified.
>    A  portable  application  should  probably  avoid mixing calls to these
>    interfaces.
>
> IOW, if its just a shim around fcntl() on many systems, it is clearer
> if we just use fcntl() directly, as we then know how fcntl() locks will
> behave if they're on a network filesystem like NFS.
>
> > Use an exclusive lock on the first byte with fcntl().
> >
> > Signed-off-by: Marc-André Lureau <address@hidden>
> > ---
> >  util/oslib-posix.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> > index da1d4a3201..26b11490b9 100644
> > --- a/util/oslib-posix.c
> > +++ b/util/oslib-posix.c
> > @@ -92,6 +92,11 @@ bool qemu_write_pidfile(const char *pidfile, Error 
> > **errp)
> >  {
> >      int pidfd;
> >      char pidstr[32];
> > +    struct flock lock = {
> > +        .l_type = F_WRLCK,
> > +        .l_whence = SEEK_SET,
> > +        .l_len = 1,
> > +    };
>
> For the same semantics as lockf we should use  len == 0 (ie infinity)

I went to look at how libvirt implements it. Interestingly, it uses
start=0, len=1, and you added it in:

https://libvirt.org/git/?p=libvirt.git;a=blobdiff;f=src/util/virpidfile.c;h=38cc7e28c619defa81d55a47f596eeb6f9832cfd;hp=c0b12867db09d138f0382d76db098c78722be7c4;hb=e1da464d88cd39794809ec0d82dcdfbede744ad6;hpb=b7e5ca48f8c753a85ae77be3430fef83629d2178



reply via email to

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