From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Fq3-0006br-O4 for qemu-devel@nongnu.org; Tue, 24 May 2016 13:09:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5Fpz-0005X2-Um for qemu-devel@nongnu.org; Tue, 24 May 2016 13:09:50 -0400 References: <1463470536-8981-1-git-send-email-famz@redhat.com> <1463470536-8981-12-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: <6bc4980e-f6e1-1d10-9be5-07836b0be566@redhat.com> Date: Tue, 24 May 2016 19:09:34 +0200 MIME-Version: 1.0 In-Reply-To: <1463470536-8981-12-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jBIrnUQMgiTHTIt1U9dIN7srL6uBUjiEj" Subject: Re: [Qemu-devel] [PATCH v5 11/27] raw-posix: Implement .bdrv_lockf 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) --jBIrnUQMgiTHTIt1U9dIN7srL6uBUjiEj 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: <6bc4980e-f6e1-1d10-9be5-07836b0be566@redhat.com> Subject: Re: [PATCH v5 11/27] raw-posix: Implement .bdrv_lockf References: <1463470536-8981-1-git-send-email-famz@redhat.com> <1463470536-8981-12-git-send-email-famz@redhat.com> In-Reply-To: <1463470536-8981-12-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: > virtlockd in libvirt locks the first byte, we lock byte 1 to avoid > the intervene. >=20 > Both file and host device protocols are covered. Is there a reason you didn't cover host_cdrom other than it generally being read-only and thus probably not really needing a lock? > Suggested-by: "Daniel P. Berrange" I think the quotation marks are superfluous. > Signed-off-by: Fam Zheng > --- > block/raw-posix.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) >=20 > diff --git a/block/raw-posix.c b/block/raw-posix.c > index bb8669f..acd3be2 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -35,6 +35,7 @@ > #include "raw-aio.h" > #include "qapi/util.h" > #include "qapi/qmp/qstring.h" > +#include "glib.h" What for? > =20 > #if defined(__APPLE__) && (__MACH__) > #include > @@ -397,6 +398,23 @@ static void raw_attach_aio_context(BlockDriverStat= e *bs, > #endif > } > =20 > +static int raw_lockf(BlockDriverState *bs, BdrvLockfCmd cmd) > +{ > + > + BDRVRawState *s =3D bs->opaque; > + > + switch (cmd) { > + case BDRV_LOCKF_EXCLUSIVE: > + return qemu_lock_fd(s->fd, 1, 1, true); > + case BDRV_LOCKF_SHARED: > + return qemu_lock_fd(s->fd, 1, 1, false); > + case BDRV_LOCKF_UNLOCK: > + return qemu_unlock_fd(s->fd, 1, 1); > + default: > + abort(); > + } I figure the comment from patch 8 about why byte 1 is locked should be here somewhere. Max > +} > + > #ifdef CONFIG_LINUX_AIO > static int raw_set_aio(LinuxAioState **aio_ctx, int *use_aio, int bdrv= _flags) > { > @@ -1942,6 +1960,8 @@ BlockDriver bdrv_file =3D { > .bdrv_detach_aio_context =3D raw_detach_aio_context, > .bdrv_attach_aio_context =3D raw_attach_aio_context, > =20 > + .bdrv_lockf =3D raw_lockf, > + > .create_opts =3D &raw_create_opts, > }; > =20 > @@ -2396,6 +2416,8 @@ static BlockDriver bdrv_host_device =3D { > #ifdef __linux__ > .bdrv_aio_ioctl =3D hdev_aio_ioctl, > #endif > + > + .bdrv_lockf =3D raw_lockf, > }; > =20 > #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_ke= rnel__) >=20 --jBIrnUQMgiTHTIt1U9dIN7srL6uBUjiEj 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 iQEcBAEBCAAGBQJXRIrPAAoJEDuxQgLoOKytL5EH/1tDbFB0QpEsqRV7pKZoLLTh odxh0zlQ2C3I2yi/6myYjjVKlgdroA6p+hmzyBTeh4NOBxppFRc0SFqa/S+JpAtS c1dkgEKJHGbq+rVjQe6UVmBbH3RTYVOYOkFw8DC9lsRd7tx3kR04HbQLSeV9QYes 0S1mNelVZ1MZjescjXMTuw55iY0O82qsf+C435KSuPrgW/rBCXAR2K6ysSGKCkjy ktyvuQWm9gJGKWdoUKy1XI3GZl6d6I0JD68FvwyQ7v6Ah3EaEMmYyL5gABv0tGc8 GgK7Jjdi2YT2qjkzSvf6AOve3eOTGr8w+0temNuSr9GAFbc4aEBG6MZ+6Jc9sQI= =Xeq7 -----END PGP SIGNATURE----- --jBIrnUQMgiTHTIt1U9dIN7srL6uBUjiEj--