Received: from eggs.gnu.org ([2001:4830:134:3::10]:51150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxhAH-0007e7-Nj for qemu-devel@nongnu.org; Fri, 21 Oct 2016 17:15:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxhAE-00053I-7j for qemu-devel@nongnu.org; Fri, 21 Oct 2016 17:15:45 -0400 References: <1475237406-26917-1-git-send-email-famz@redhat.com> <1475237406-26917-5-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: Date: Fri, 21 Oct 2016 23:15:30 +0200 MIME-Version: 1.0 In-Reply-To: <1475237406-26917-5-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="SVgQJRRvpPsJqoUIIDc9noahbr5Xl5Fd4" Subject: Re: [Qemu-devel] [PATCH v8 04/36] osdep: Add qemu_lock_fd and qemu_unlock_fd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: berrange@redhat.com, John Snow , qemu-block@nongnu.org, Kevin Wolf , rjones@redhat.com, Jeff Cody , Markus Armbruster , stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com, eblake@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --SVgQJRRvpPsJqoUIIDc9noahbr5Xl5Fd4 From: Max Reitz To: Fam Zheng , qemu-devel@nongnu.org Cc: berrange@redhat.com, John Snow , qemu-block@nongnu.org, Kevin Wolf , rjones@redhat.com, Jeff Cody , Markus Armbruster , stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com, eblake@redhat.com Message-ID: Subject: Re: [PATCH v8 04/36] osdep: Add qemu_lock_fd and qemu_unlock_fd References: <1475237406-26917-1-git-send-email-famz@redhat.com> <1475237406-26917-5-git-send-email-famz@redhat.com> In-Reply-To: <1475237406-26917-5-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 30.09.2016 14:09, Fam Zheng wrote: > 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 9e9fa61..f773f49 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -286,6 +286,8 @@ int qemu_close(int fd); > #ifndef _WIN32 > int qemu_dup(int fd); > #endif > +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 06fb1cf..b85a490 100644 > --- a/util/osdep.c > +++ b/util/osdep.c > @@ -140,6 +140,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 fl_= 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); Can EINTR happen? My fcntl() man page claims it's only possible with F(_OFD)_SETLKW. Max > + return ret =3D=3D -1 ? -errno : 0; > +#else > + return -ENOTSUP; > +#endif > +} > + > +int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive) > +{ > + return qemu_lock_fcntl(fd, start, len, exclusive ? F_WRLCK : F_RDL= CK); > +} > + > +int qemu_unlock_fd(int fd, int64_t start, int64_t len) > +{ > + return qemu_lock_fcntl(fd, start, len, F_UNLCK); > +} > #endif > =20 > /* >=20 --SVgQJRRvpPsJqoUIIDc9noahbr5Xl5Fd4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEvBAEBCAAZBQJYCoVyEhxtcmVpdHpAcmVkaGF0LmNvbQAKCRD0B9sAYdXPQDEl B/9wJavTx41YR1d21u8E19fGt8hYXjt4Lf8EgX3cWO7cxrV8TyzUOZ/7WQt5C9mS OvGYaQr9caFhH0PNjMK9uim7eRWFkF1FOSHQbK35jCoYB42uSe0bIO8NGKjIHiWA R6jnLdkIY2HleQzVrBYvPXQMfG79rK7axebBfuacDWwl2CGO4d3yfqjIP0wZ1bLf rnMoH8OEdYfW3ATGfnOD0Z/tkzx0o160WyNdWJ/e31SN2CYTtiJzd8ir/pyzzrxs rOtf0WwWrbq3QDkXCC2jPY/G5963mg6sgMtAngJmbf2/J7VaihJh5jXv6t4YjvRl Z2KT0p4fbr+6eQELzWzkG2Oh =YH08 -----END PGP SIGNATURE----- --SVgQJRRvpPsJqoUIIDc9noahbr5Xl5Fd4--