From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr82T-0006sZ-MK for qemu-devel@nongnu.org; Wed, 19 Nov 2014 11:23:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xr82K-0008JT-M3 for qemu-devel@nongnu.org; Wed, 19 Nov 2014 11:23:29 -0500 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:44487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr82K-0008JK-Eg for qemu-devel@nongnu.org; Wed, 19 Nov 2014 11:23:20 -0500 Received: by mail-wg0-f52.google.com with SMTP id a1so1223019wgh.11 for ; Wed, 19 Nov 2014 08:23:19 -0800 (PST) Date: Wed, 19 Nov 2014 16:23:16 +0000 From: Stefan Hajnoczi Message-ID: <20141119162316.GA15177@stefanha-thinkpad.redhat.com> References: <1415156231-6319-1-git-send-email-famz@redhat.com> <1415156231-6319-2-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline In-Reply-To: <1415156231-6319-2-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 1/3] qmp: Add command 'blockdev-backup' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , mreitz@redhat.com, qemu-devel@nongnu.org, Stefan Hajnoczi , Markus Armbruster --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Nov 05, 2014 at 10:57:09AM +0800, Fam Zheng wrote: > +void qmp_blockdev_backup(const char *device, const char *target, > + enum MirrorSyncMode sync, > + bool has_speed, int64_t speed, > + bool has_on_source_error, > + BlockdevOnError on_source_error, > + bool has_on_target_error, > + BlockdevOnError on_target_error, > + Error **errp) > +{ > + BlockDriverState *bs; > + BlockDriverState *target_bs; > + Error *local_err = NULL; > + > + if (!has_speed) { > + speed = 0; > + } > + if (!has_on_source_error) { > + on_source_error = BLOCKDEV_ON_ERROR_REPORT; > + } > + if (!has_on_target_error) { > + on_target_error = BLOCKDEV_ON_ERROR_REPORT; > + } > + > + bs = bdrv_find(device); > + if (!bs) { > + error_set(errp, QERR_DEVICE_NOT_FOUND, device); > + return; > + } > + > + target_bs = bdrv_find(target); > + if (!target_bs) { > + error_set(errp, QERR_DEVICE_NOT_FOUND, target); > + return; > + } > + > + bdrv_ref(target_bs); > + backup_start(bs, target_bs, speed, sync, on_source_error, on_target_error, > + block_job_cb, bs, &local_err); > + if (local_err != NULL) { > + bdrv_unref(target_bs); > + error_propagate(errp, local_err); > + } > +} Please make sure to acquire AioContext so that this is safe with dataplane. Here the tricky thing is that bs and target_bs must have the same AioContext. The easiest thing is to refuse if their AioContexts are not identical, but that puts the onus on the user to put the BlockDriverStates into the same AioContext. --8t9RHnE3ZwKMSgU+ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUbMP0AAoJEJykq7OBq3PIsRAH/3BZcpgicTZDpwvA88PhHbYv zoH4qg94LAecVC5P8m0EqaLvXI8EpMNwE2zHkgIqarBp22q2CMpNQygoc8Z3SQ4y zSp/HziByDEiU1sgzkzfJx0Jo/JM8tN9noz4d0TznLwLfg6q2gtASrAD6/Mr5ebP 3sZOCWw56f3LzcWDuz+5OLGbwbFr6e+MYN4LCEVVZb6Cdah400wdoLaD5nFpyT53 G27bCbv5aieXLltpUu0WWi1H4yT7XTNr/9+NJUy/xQ9fmlkKMj9X1NZyw1FUd1a+ /130oF6UGP+TAxpM8wTKSq+FlKCJU09OBKdLvFZky4zlFMhSO47Vx81BKwjWMBs= =rar+ -----END PGP SIGNATURE----- --8t9RHnE3ZwKMSgU+--