Received: from eggs.gnu.org ([2001:4830:134:3::10]:49654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpHr9-00078U-Ow for qemu-devel@nongnu.org; Wed, 28 Sep 2016 12:37:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpHr7-0001Ip-Kf for qemu-devel@nongnu.org; Wed, 28 Sep 2016 12:37:14 -0400 References: <1474958276-7715-1-git-send-email-famz@redhat.com> <1474958276-7715-2-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: <6d56ac2d-aa76-f323-085b-54f0dd4e519c@redhat.com> Date: Wed, 28 Sep 2016 18:37:01 +0200 MIME-Version: 1.0 In-Reply-To: <1474958276-7715-2-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tECqUGc1WaAJxI1xwdUKNXWqhGxg9Kh6C" Subject: Re: [Qemu-devel] [PATCH v2 1/5] blockdev-mirror: Sanity check before moving target_bs AioContext List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , qemu-stable@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --tECqUGc1WaAJxI1xwdUKNXWqhGxg9Kh6C From: Max Reitz To: Fam Zheng , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , qemu-stable@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com Message-ID: <6d56ac2d-aa76-f323-085b-54f0dd4e519c@redhat.com> Subject: Re: [PATCH v2 1/5] blockdev-mirror: Sanity check before moving target_bs AioContext References: <1474958276-7715-1-git-send-email-famz@redhat.com> <1474958276-7715-2-git-send-email-famz@redhat.com> In-Reply-To: <1474958276-7715-2-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 27.09.2016 08:37, Fam Zheng wrote: > Similar to blockdev-backup, if the target was already moved to a > different AioContext, bad things can happen. This happens when the > target belongs to a data plane device. It's a very unlikely case, but > let's check it anyway. You didn't implement it for blockdev-mirror, though, but for drive-mirror (which I don't think needs this check). Max >=20 > Signed-off-by: Fam Zheng > --- > blockdev.c | 35 ++++++++++++++++++++++++----------- > 1 file changed, 24 insertions(+), 11 deletions(-) >=20 > diff --git a/blockdev.c b/blockdev.c > index 29c6561..a4960b9 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -3281,6 +3281,21 @@ BlockDeviceInfoList *qmp_query_named_block_nodes= (Error **errp) > return bdrv_named_nodes_list(errp); > } > =20 > +static void blockdev_set_aio_context(BlockDriverState *bs, AioContext = *ctx, > + Error **errp) > +{ > + if (bdrv_get_aio_context(bs) !=3D ctx) { > + if (!bdrv_has_blk(bs)) { > + /* The target BDS is not attached, we can safely move it t= o another > + * AioContext. */ > + bdrv_set_aio_context(bs, ctx); > + } else { > + error_setg(errp, "Target is attached to a different thread= from " > + "source."); > + } > + } > +} > + > void do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, Erro= r **errp) > { > BlockDriverState *bs; > @@ -3317,16 +3332,10 @@ void do_blockdev_backup(BlockdevBackup *backup,= BlockJobTxn *txn, Error **errp) > goto out; > } > =20 > - if (bdrv_get_aio_context(target_bs) !=3D aio_context) { > - if (!bdrv_has_blk(target_bs)) { > - /* The target BDS is not attached, we can safely move it t= o another > - * AioContext. */ > - bdrv_set_aio_context(target_bs, aio_context); > - } else { > - error_setg(errp, "Target is attached to a different thread= from " > - "source."); > - goto out; > - } > + blockdev_set_aio_context(target_bs, aio_context, &local_err); > + if (local_err) { > + error_propagate(errp, local_err); > + goto out; > } > backup_start(backup->job_id, bs, target_bs, backup->speed, backup-= >sync, > NULL, backup->compress, backup->on_source_error, > @@ -3538,7 +3547,11 @@ void qmp_drive_mirror(DriveMirror *arg, Error **= errp) > goto out; > } > =20 > - bdrv_set_aio_context(target_bs, aio_context); > + blockdev_set_aio_context(target_bs, aio_context, &local_err); > + if (local_err) { > + error_propagate(errp, local_err); > + goto out; > + } > =20 > blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, t= arget_bs, > arg->has_replaces, arg->replaces, arg->sync= , >=20 --tECqUGc1WaAJxI1xwdUKNXWqhGxg9Kh6C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEvBAEBCAAZBQJX6/GtEhxtcmVpdHpAcmVkaGF0LmNvbQAKCRD0B9sAYdXPQFxz B/4/oiHoXQ/13jn3XxZicK+Ka87J6xtjdgAAjZLjQ/2yC/wPgL7+6VG6yZagwqWe wv+TBFIHUtnr0QsLW48VcfhfNDNRbyef3ZsOTzWHgOBhBhFSSqJtvMl2iu0614pI oI5AXZI79xv7ffQrm0sMr8HeopqGXB45NslraiFtQQZVpd34Os/6XMmJDTLUiha/ G4L/VQ+IEujAK/cWk5GTFA1nLvEFJdo0evPDx45D0g2U5xXqCt3EBh8aliclenbQ qO4blRf6SpnjLRsjCSK+R7luC7kKKIIOEVVW1cRk2jlpwijWSx6lZngvoZcr33BT bRTjCnhim2Iiso/0IHoCovmk =MBY7 -----END PGP SIGNATURE----- --tECqUGc1WaAJxI1xwdUKNXWqhGxg9Kh6C--