From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCbkH-0002Oq-HX for qemu-devel@nongnu.org; Thu, 01 Dec 2016 19:30:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCbkG-0007u3-E4 for qemu-devel@nongnu.org; Thu, 01 Dec 2016 19:30:33 -0500 References: <1477928314-11184-1-git-send-email-famz@redhat.com> <1477928314-11184-2-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: <29e8c31e-a05f-79b0-df81-ec84317496b9@redhat.com> Date: Fri, 2 Dec 2016 01:30:24 +0100 MIME-Version: 1.0 In-Reply-To: <1477928314-11184-2-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Ve75Du4lXREfHIfLincV3uqWcp8RdOsBd" Subject: Re: [Qemu-devel] [PATCH 01/14] 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: "Daniel P. Berrange" , Kevin Wolf , qemu-block@nongnu.org, rjones@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Ve75Du4lXREfHIfLincV3uqWcp8RdOsBd From: Max Reitz To: Fam Zheng , qemu-devel@nongnu.org Cc: "Daniel P. Berrange" , Kevin Wolf , qemu-block@nongnu.org, rjones@redhat.com Message-ID: <29e8c31e-a05f-79b0-df81-ec84317496b9@redhat.com> Subject: Re: [PATCH 01/14] osdep: Add qemu_lock_fd and qemu_unlock_fd References: <1477928314-11184-1-git-send-email-famz@redhat.com> <1477928314-11184-2-git-send-email-famz@redhat.com> In-Reply-To: <1477928314-11184-2-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 31.10.2016 16:38, 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 0e3c330..f15e122 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -294,6 +294,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); As I've asked in the last version: Can EINTR happen at all? My man page tells me it's possible only 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 --Ve75Du4lXREfHIfLincV3uqWcp8RdOsBd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQFGBAEBCAAwFiEEkb62CjDbPohX0Rgp9AfbAGHVz0AFAlhAwKASHG1yZWl0ekBy ZWRoYXQuY29tAAoJEPQH2wBh1c9AYJ8IAIblQuNJ8bUnpM/Hu1o3UJtOnd09Bcfo e42NiqJh6JT7kpWSw/tyN6xHKUqVjJcXBG/AYVCGjD1rjvEVA+Yyj2L7x6V5HJDQ azyPYNbFt8BKR2bmec3HRQJRQK/xo4BIaZkBNG01gIn2RMpgUq9KubgBedeQyvhZ hVb8Jh6lXoqLWzoooMcnGwaUlJ9P3mU3/F8tYxdwxMEU2dVjOxTtJGt93IK1APeU 7nyVjrh4ToBzLFjHJK/QdIxjR4x2g5ZoEAab12aVAU5WmLUOGP/pmE+wU9Kmciso CoydR5cNunMSCUXiNXPmdhQOcZcPkocbpalakLXqps2bw1XuCR2h1CU= =05j+ -----END PGP SIGNATURE----- --Ve75Du4lXREfHIfLincV3uqWcp8RdOsBd--