From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: virtio-fs@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Virtio-fs] [Qemu-devel] [PATCH v2] virtiofsd: fix compile error if 'F_OFD_GETLK' not defined
Date: Fri, 2 Aug 2019 12:10:34 +0100 [thread overview]
Message-ID: <20190802111034.GC30115@redhat.com> (raw)
In-Reply-To: <20190802105352.GF2899@work-vm>
On Fri, Aug 02, 2019 at 11:53:52AM +0100, Dr. David Alan Gilbert wrote:
> * piaojun (piaojun@huawei.com) wrote:
> > Use F_GETLK for fcntl when F_OFD_GETLK not defined, such as kernel 3.10.
> >
> > Signed-off-by: Jun Piao <piaojun@huawei.com>
>
>
> > ---
> > v2:
> > - Use F_OFD_SETLK to replace F_OFD_GETLK in #ifdef.
> >
> > ---
> > contrib/virtiofsd/passthrough_ll.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthrough_ll.c
> > index a81c01d..c69f2f3 100644
> > --- a/contrib/virtiofsd/passthrough_ll.c
> > +++ b/contrib/virtiofsd/passthrough_ll.c
> > @@ -1780,7 +1780,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
> > goto out;
> > }
> >
> > +#ifdef F_OFD_GETLK
> > ret = fcntl(plock->fd, F_OFD_GETLK, lock);
> > +#else
> > + ret = fcntl(plock->fd, F_GETLK, lock);
> > +#endif
> > if (ret == -1)
> > saverr = errno;
> >
> > @@ -1831,7 +1835,11 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino,
> >
> > /* TODO: Is it alright to modify flock? */
> > lock->l_pid = 0;
> > +#ifdef F_OFD_SETLK
> > ret = fcntl(plock->fd, F_OFD_SETLK, lock);
> > +#else
> > + ret = fcntl(plock->fd, F_GETLK, lock);
> ^^^^^^^
>
> Typo! You've got GETLK rather than SETLK.
>
> But, a bigger question - does this actually work!
> The manpage says:
> 'If a process closes any file descriptor referring to a file, then
> all of the process's locks on that file are released, regardless of the
> file descriptor(s) on which the locks were obtained.'
>
> the fd we're using here came from lookup_create_plock_ctx which did
> a new openat to get this fd; so we've already got multiple fd's
> referring to this file; and thus I worry we're going to close
> one of them and lose all our locks on it.
Yeah, this is what makes F_GETLK/F_SETLK such an awful thing to
use. It is just about managable if an app is single threaded
and the developer can examine all code paths to make sure there
are no other open FDs referring to the same underling file.
If code has multiple FDs open, and/or is a multithreaded app,
F_SETLK is really fragile / error prone.
In QEMU proper, we used the fallback to F_GETLK/F_SETLK because
we were adding locking to existing features. If we didn't have
the fallback then we would either be breaking existing usage by
mandating OFD locks, or leaving those users with no locking at
all by disabling locking entirely.
For a program like virtiofsd that is brand new functionality
we don't have to worry about breaking existing users. Thus I
would strongly recommend we just mandate OFD locks, and entirely
disable the build of virtiofsd if OFD is missing on the host.
RHEL-7's 3.10 kernel *does* have OFD locking as it was backported
and QEMU in RHEL-7 already uses this. Users just need to make
sure they have updates applied to their RHEL-7 hosts to get this.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
WARNING: multiple messages have this Message-ID (diff)
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: piaojun <piaojun@huawei.com>,
virtio-fs@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] virtiofsd: fix compile error if 'F_OFD_GETLK' not defined
Date: Fri, 2 Aug 2019 12:10:34 +0100 [thread overview]
Message-ID: <20190802111034.GC30115@redhat.com> (raw)
In-Reply-To: <20190802105352.GF2899@work-vm>
On Fri, Aug 02, 2019 at 11:53:52AM +0100, Dr. David Alan Gilbert wrote:
> * piaojun (piaojun@huawei.com) wrote:
> > Use F_GETLK for fcntl when F_OFD_GETLK not defined, such as kernel 3.10.
> >
> > Signed-off-by: Jun Piao <piaojun@huawei.com>
>
>
> > ---
> > v2:
> > - Use F_OFD_SETLK to replace F_OFD_GETLK in #ifdef.
> >
> > ---
> > contrib/virtiofsd/passthrough_ll.c | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthrough_ll.c
> > index a81c01d..c69f2f3 100644
> > --- a/contrib/virtiofsd/passthrough_ll.c
> > +++ b/contrib/virtiofsd/passthrough_ll.c
> > @@ -1780,7 +1780,11 @@ static void lo_getlk(fuse_req_t req, fuse_ino_t ino,
> > goto out;
> > }
> >
> > +#ifdef F_OFD_GETLK
> > ret = fcntl(plock->fd, F_OFD_GETLK, lock);
> > +#else
> > + ret = fcntl(plock->fd, F_GETLK, lock);
> > +#endif
> > if (ret == -1)
> > saverr = errno;
> >
> > @@ -1831,7 +1835,11 @@ static void lo_setlk(fuse_req_t req, fuse_ino_t ino,
> >
> > /* TODO: Is it alright to modify flock? */
> > lock->l_pid = 0;
> > +#ifdef F_OFD_SETLK
> > ret = fcntl(plock->fd, F_OFD_SETLK, lock);
> > +#else
> > + ret = fcntl(plock->fd, F_GETLK, lock);
> ^^^^^^^
>
> Typo! You've got GETLK rather than SETLK.
>
> But, a bigger question - does this actually work!
> The manpage says:
> 'If a process closes any file descriptor referring to a file, then
> all of the process's locks on that file are released, regardless of the
> file descriptor(s) on which the locks were obtained.'
>
> the fd we're using here came from lookup_create_plock_ctx which did
> a new openat to get this fd; so we've already got multiple fd's
> referring to this file; and thus I worry we're going to close
> one of them and lose all our locks on it.
Yeah, this is what makes F_GETLK/F_SETLK such an awful thing to
use. It is just about managable if an app is single threaded
and the developer can examine all code paths to make sure there
are no other open FDs referring to the same underling file.
If code has multiple FDs open, and/or is a multithreaded app,
F_SETLK is really fragile / error prone.
In QEMU proper, we used the fallback to F_GETLK/F_SETLK because
we were adding locking to existing features. If we didn't have
the fallback then we would either be breaking existing usage by
mandating OFD locks, or leaving those users with no locking at
all by disabling locking entirely.
For a program like virtiofsd that is brand new functionality
we don't have to worry about breaking existing users. Thus I
would strongly recommend we just mandate OFD locks, and entirely
disable the build of virtiofsd if OFD is missing on the host.
RHEL-7's 3.10 kernel *does* have OFD locking as it was backported
and QEMU in RHEL-7 already uses this. Users just need to make
sure they have updates applied to their RHEL-7 hosts to get this.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2019-08-02 11:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-02 8:38 [Virtio-fs] [PATCH v2] virtiofsd: fix compile error if 'F_OFD_GETLK' not defined piaojun
2019-08-02 8:38 ` [Qemu-devel] " piaojun
2019-08-02 10:53 ` [Virtio-fs] " Dr. David Alan Gilbert
2019-08-02 10:53 ` [Qemu-devel] " Dr. David Alan Gilbert
2019-08-02 11:10 ` Daniel P. Berrangé [this message]
2019-08-02 11:10 ` Daniel P. Berrangé
2019-08-04 8:18 ` [Virtio-fs] " piaojun
2019-08-04 8:18 ` piaojun
2019-08-06 13:27 ` [Virtio-fs] " Vivek Goyal
2019-08-06 13:27 ` [Qemu-devel] " Vivek Goyal
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=20190802111034.GC30115@redhat.com \
--to=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=virtio-fs@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.