Received: from eggs.gnu.org ([2001:4830:134:3::10]:59748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5FCl-0002o7-NA for qemu-devel@nongnu.org; Tue, 24 May 2016 12:29:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5FCj-0003zJ-Jm for qemu-devel@nongnu.org; Tue, 24 May 2016 12:29:14 -0400 References: <1463470536-8981-1-git-send-email-famz@redhat.com> <1463470536-8981-8-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: Date: Tue, 24 May 2016 18:28:55 +0200 MIME-Version: 1.0 In-Reply-To: <1463470536-8981-8-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="whjx4U82W8TfM4M8qXNkMQr8PGkr943oG" Subject: Re: [Qemu-devel] [PATCH v5 07/27] block: Handle image locking during reopen 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) --whjx4U82W8TfM4M8qXNkMQr8PGkr943oG 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 07/27] block: Handle image locking during reopen References: <1463470536-8981-1-git-send-email-famz@redhat.com> <1463470536-8981-8-git-send-email-famz@redhat.com> In-Reply-To: <1463470536-8981-8-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: > Stash the locking state into BDRVReopenState. If it was locked, unlock > in prepare, and lock it again when commit or abort. >=20 > Signed-off-by: Fam Zheng > --- > block.c | 11 +++++++++++ > include/block/block.h | 1 + > 2 files changed, 12 insertions(+) >=20 > diff --git a/block.c b/block.c > index ad3663c..2be42bb 100644 > --- a/block.c > +++ b/block.c > @@ -2112,6 +2112,11 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_= state, BlockReopenQueue *queue, > } while ((entry =3D qdict_next(reopen_state->options, entry)))= ; > } > =20 > + reopen_state->was_locked =3D reopen_state->bs->image_locked; > + if (reopen_state->was_locked) { > + bdrv_unlock_image(reopen_state->bs); > + } > + > ret =3D 0; > =20 > error: > @@ -2136,6 +2141,9 @@ static void bdrv_reopen_commit(BDRVReopenState *r= eopen_state) > if (drv->bdrv_reopen_commit) { > drv->bdrv_reopen_commit(reopen_state); > } > + if (reopen_state->was_locked) { > + bdrv_lock_image(reopen_state->bs); > + } > =20 > /* set BDS specific flags now */ > QDECREF(reopen_state->bs->explicit_options); > @@ -2162,6 +2170,9 @@ static void bdrv_reopen_abort(BDRVReopenState *re= open_state) > if (drv->bdrv_reopen_abort) { > drv->bdrv_reopen_abort(reopen_state); > } > + if (reopen_state->was_locked) { > + bdrv_lock_image(reopen_state->bs); I'm not sure I'm quite happy with this, because this may fail; therefore, it may happen that the operation done in _prepare() cannot be undone. Of course, the same applies to _commit(): bdrv_lock_image() can just fail. It's probably even worse there. I don't see a good reason why just relocking the image in _abort() should fail; but it's very much conceivable that locking the reopened image in _commit() fails. I think the correct way would be to rely on the drivers which implement locking to handle reopening correctly, that is, try lock the reopened image in _prepare() and unlock the old one before discarding it in _commit(). However, I'm not sure myself whether it's worth the effort. It's very simple to do it like you did here -- but then again, it doesn't seem quite correct. Also: Should bdrv_reopen_prepare() check that the locking flags are not changed? Max > + } > =20 > QDECREF(reopen_state->explicit_options); > } > diff --git a/include/block/block.h b/include/block/block.h > index 7740d3f..28b8ae9 100644 > --- a/include/block/block.h > +++ b/include/block/block.h > @@ -158,6 +158,7 @@ typedef struct BDRVReopenState { > QDict *options; > QDict *explicit_options; > void *opaque; > + bool was_locked; > } BDRVReopenState; > =20 > /* >=20 --whjx4U82W8TfM4M8qXNkMQr8PGkr943oG 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 iQEcBAEBCAAGBQJXRIFHAAoJEDuxQgLoOKyt+sgIAJiBRIWTXiSy72O4D09lkZ3o GJWRYpVlx86BAiDuqXhu8M+tMM8O1OSaHzAxvm6EJY02/NraNzMXM3QgYf45xbL+ F/NkXVUa6OA18oxmHFPnnTHopII7nvNTmeZ/9EXDhRD8IvkED9Lde92uB3w1DmGC tMIMKHXNviffKtEkSLHP7PlmIhXQFxrcH3Oy5eif+Z6qxDtIwhYFFGJ366diD0by gSg7lT2c7exa6TcR1VI3VNC1Z7Jqk7iIxNVW2GPH4pWSKPo279nw8K0dophsrLQt wRhoRQs/V7EgvmPjjQFG8/FPcixtqoKcVnHhdzE0kiRvPWVBrdiL5XYs8EwQXJU= =amVl -----END PGP SIGNATURE----- --whjx4U82W8TfM4M8qXNkMQr8PGkr943oG--