Received: from eggs.gnu.org ([2001:4830:134:3::10]:59895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFcg8-0005bK-8m for qemu-devel@nongnu.org; Wed, 22 Jun 2016 03:34:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFcg7-0000RY-4G for qemu-devel@nongnu.org; Wed, 22 Jun 2016 03:34:28 -0400 Date: Wed, 22 Jun 2016 15:34:13 +0800 From: Fam Zheng Message-ID: <20160622073413.GE22636@ad.usersys.redhat.com> References: <1464943756-14143-1-git-send-email-famz@redhat.com> <1464943756-14143-6-git-send-email-famz@redhat.com> <20160617121213.GG5431@noname.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20160617121213.GG5431@noname.redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v6 05/22] osdep: Add qemu_lock_fd and qemu_unlock_fd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org, Max Reitz , Jeff Cody , Markus Armbruster , Eric Blake , qemu-block@nongnu.org, rjones@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, John Snow , berrange@redhat.com, den@openvz.org On Fri, 06/17 14:12, Kevin Wolf wrote: > Am 03.06.2016 um 10:48 hat Fam Zheng geschrieben: > > They are wrappers of POSIX fcntl "file private locking". > >=20 > > Signed-off-by: Fam Zheng > > --- > > include/qemu/osdep.h | 2 ++ > > util/osdep.c | 29 +++++++++++++++++++++++++++++ > > 2 files changed, 31 insertions(+) > >=20 > > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > > index 6937694..749214a 100644 > > --- a/include/qemu/osdep.h > > +++ b/include/qemu/osdep.h > > @@ -280,6 +280,8 @@ int qemu_madvise(void *addr, size_t len, int advi= ce); > > =20 > > int qemu_open(const char *name, int flags, ...); > > int qemu_close(int fd); > > +int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)= ; > > +int qemu_unlock_fd(int fd, int64_t start, int64_t len); > > =20 > > #if defined(__HAIKU__) && defined(__i386__) > > #define FMT_pid "%ld" > > diff --git a/util/osdep.c b/util/osdep.c > > index 9a7a439..085ed52 100644 > > --- a/util/osdep.c > > +++ b/util/osdep.c > > @@ -137,6 +137,35 @@ static int qemu_parse_fdset(const char *param) > > { > > return qemu_parse_fd(param); > > } > > + > > +static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int f= l_type) > > +{ > > +#ifdef F_OFD_SETLK > > + int ret; > > + struct flock fl =3D { > > + .l_whence =3D SEEK_SET, > > + .l_start =3D start, > > + .l_len =3D len, > > + .l_type =3D fl_type, > > + }; > > + do { > > + ret =3D fcntl(fd, F_OFD_SETLK, &fl); > > + } while (ret =3D=3D -1 && errno =3D=3D EINTR); > > + return ret =3D=3D -1 ? -errno : 0; > > +#else > > + return -ENOTSUP; > > +#endif > > +} >=20 > This will return -ENOTSUP in the case that the function wasn't availabl= e > at build time, but -EINVAL if it was available at build time but the > kernel doesn't support it at runtime. Should we unify this? I'm not sure we can reliably distinguish "fcntl cmd not supported" and "f= cntl cmd supported but parameters have invalid value" out of -EINVAL. Quoting the manual: > https://www.gnu.org/software/libc/manual/html_node/Open-File-Descriptio= n-Locks.html >=20 > Macro: int F_OFD_SETL >=20 > EINVAL >=20 > Either the lockp argument doesn=E2=80=99t specify valid lock inform= ation, the > operating system kernel doesn=E2=80=99t support open file descripti= on locks, or the > file associated with filedes doesn=E2=80=99t support locks. >=20 I'd expect the user to know what he's doing if he is using a kernel that = is much older than the one built QEMU, since this is relatively a very uncom= mon thing to do. Fam