Received: from eggs.gnu.org ([2001:4830:134:3::10]:34915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5FQG-0002H6-Uf for qemu-devel@nongnu.org; Tue, 24 May 2016 12:43:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5FQF-0007kO-QS for qemu-devel@nongnu.org; Tue, 24 May 2016 12:43:12 -0400 References: <1463470536-8981-1-git-send-email-famz@redhat.com> <1463470536-8981-9-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: Date: Tue, 24 May 2016 18:42:55 +0200 MIME-Version: 1.0 In-Reply-To: <1463470536-8981-9-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="itX2IPH7I5dhRTXXsDkkwLEApQFt6warS" Subject: Re: [Qemu-devel] [PATCH v5 08/27] 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: Kevin Wolf , Jeff Cody , Markus Armbruster , Eric Blake , John Snow , qemu-block@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, den@openvz.org, stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --itX2IPH7I5dhRTXXsDkkwLEApQFt6warS From: Max Reitz To: Fam Zheng , qemu-devel@nongnu.org Cc: Kevin Wolf , Jeff Cody , Markus Armbruster , Eric Blake , John Snow , qemu-block@nongnu.org, berrange@redhat.com, pbonzini@redhat.com, den@openvz.org, stefanha@redhat.com Message-ID: Subject: Re: [PATCH v5 08/27] osdep: Add qemu_lock_fd and qemu_unlock_fd References: <1463470536-8981-1-git-send-email-famz@redhat.com> <1463470536-8981-9-git-send-email-famz@redhat.com> In-Reply-To: <1463470536-8981-9-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 17.05.2016 09:35, 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 | 31 +++++++++++++++++++++++++++++++ > 2 files changed, 33 insertions(+) >=20 > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index 1e3221c..81913a7 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -265,6 +265,8 @@ int qemu_madvise(void *addr, size_t len, int advice= ); > =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 d56d071..9e5d7fa 100644 > --- a/util/osdep.c > +++ b/util/osdep.c > @@ -236,6 +236,37 @@ int qemu_close(int fd) > return close(fd); > } > =20 > +static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_= type) > +{ > +#ifdef F_OFD_SETLK > + struct flock fl =3D (struct flock) { The (struct flock) can be omitted here (since this is an initialization), but that's up to you. > + .l_whence =3D SEEK_SET, One space too many? > + /* Locking byte 1 avoids interfereing with virtlockd. */ *interfering or *interference But apart from that: This comment seems completely misplaced here. I guess it's supposed to be in raw-posix.c instead (or just wherever you're calling qemu_{un,}lock_fd()). > + .l_start =3D start, > + .l_len =3D len, > + .l_type =3D fl_type, > + }; > + if (fcntl(fd, F_OFD_SETLK, &fl) =3D=3D -1) { > + return -errno; > + } else { > + return 0; > + } > +#else > + return -ENOTSUP; > +#endif > +} > + > +int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive) > +{ > + Superfluous empty line. Max > + 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); > +} > + > /* > * A variant of write(2) which handles partial write. > * >=20 --itX2IPH7I5dhRTXXsDkkwLEApQFt6warS Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJXRISPAAoJEDuxQgLoOKyta9AH/177ccjX3mdTLOOMo9s6RGmC va+Bq9VXQ79jRPnJex4KpCx+zj32kao3VG135RdlDS9Bb8sx+LFYaAC+vtPzKgIu fWfRepA/lCXOKQKmJqpJSBYoDZqxmYcjdxIbANBb5V/OeZ2L1ZCtyTNK1YsJms8v hY20fG3etWfEi5EPDSpLAcRzEBgWWi3TV14GsAmDw72xIotXjg5ti0cqtiBNj5Fw fK/vh4+9UgOfhZMW9CUn2dAVp+A17hQxhevK21dwPy5MnczutY0cKRDbpvsf4RGW TJdwoG/ZV/8U1e4xs5aur5necLIIWNF46c5iAapLXpspd+Vqg+hMRnCptNU5D7w= =+J5t -----END PGP SIGNATURE----- --itX2IPH7I5dhRTXXsDkkwLEApQFt6warS--