Received: from eggs.gnu.org ([2001:4830:134:3::10]:48782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V07hK-0000zy-1e for qemu-devel@nongnu.org; Fri, 19 Jul 2013 06:14:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V07hI-0000RJ-IY for qemu-devel@nongnu.org; Fri, 19 Jul 2013 06:14:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16288) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V07hI-0000RC-Ad for qemu-devel@nongnu.org; Fri, 19 Jul 2013 06:14:00 -0400 Date: Fri, 19 Jul 2013 12:13:54 +0200 From: Kevin Wolf Message-ID: <20130719101354.GG2992@dhcp-200-207.str.redhat.com> References: <1373521624-4380-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1373521624-4380-4-git-send-email-xiawenc@linux.vnet.ibm.com> <20130718122226.GJ3582@dhcp-200-207.str.redhat.com> <51E904B2.8060702@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <51E904B2.8060702@linux.vnet.ibm.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V5 3/8] qmp: add internal snapshot support in qmp_transaction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: phrdina@redhat.com, famz@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com Am 19.07.2013 um 11:19 hat Wenchao Xia geschrieben: > =E4=BA=8E 2013-7-18 20:22, Kevin Wolf =E5=86=99=E9=81=93: > >Am 11.07.2013 um 07:46 hat Wenchao Xia geschrieben: > >>Unlike savevm, the qmp_transaction interface will not generate > >>snapshot name automatically, saving trouble to return information > >>of the new created snapshot. > >> > >>Although qcow2 support storing multiple snapshots with same name > >>but different ID, here it will fail when an snapshot with that name > >>already exist before the operation. Format such as rbd do not support > >>ID at all, and in most case, it means trouble to user when he faces > >>multiple snapshots with same name, so ban that case. Request with > >>empty name will be rejected. > >> > >>Snapshot ID can't be specified in this interface. > >> > >>Signed-off-by: Wenchao Xia > >>--- > >> blockdev.c | 117 +++++++++++++++++++++++++++++++++++++++++++= +++++++++++ > >> qapi-schema.json | 18 ++++++++- > >> qmp-commands.hx | 34 ++++++++++++---- > >> 3 files changed, 160 insertions(+), 9 deletions(-) > >> > >>diff --git a/blockdev.c b/blockdev.c > >>index b3a57e0..6554768 100644 > >>--- a/blockdev.c > >>+++ b/blockdev.c > >>@@ -808,6 +808,118 @@ struct BlkTransactionState { > >> QSIMPLEQ_ENTRY(BlkTransactionState) entry; > >> }; > >> > >>+/* internal snapshot private data */ > >>+typedef struct InternalSnapshotState { > >>+ BlkTransactionState common; > >>+ BlockDriverState *bs; > >>+ QEMUSnapshotInfo sn; > >>+} InternalSnapshotState; > >>+ > >>+static void internal_snapshot_prepare(BlkTransactionState *common, > >>+ Error **errp) > >>+{ > >>+ const char *device; > >>+ const char *name; > >>+ BlockDriverState *bs; > >>+ QEMUSnapshotInfo sn, *sn1; > >>+ bool ret; > >>+ qemu_timeval tv; > >>+ BlockdevSnapshotInternal *internal; > >>+ InternalSnapshotState *state; > >>+ int ret1; > >>+ > >>+ g_assert(common->action->kind =3D=3D > >>+ TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC= ); > >>+ internal =3D common->action->blockdev_snapshot_internal_sync; > >>+ state =3D DO_UPCAST(InternalSnapshotState, common, common); > >>+ > >>+ /* 1. parse input */ > >>+ device =3D internal->device; > >>+ name =3D internal->name; > >>+ > >>+ /* 2. check for validation */ > >>+ bs =3D bdrv_find(device); > >>+ if (!bs) { > >>+ error_set(errp, QERR_DEVICE_NOT_FOUND, device); > >>+ return; > >>+ } > >>+ > >>+ if (!bdrv_is_inserted(bs)) { > >>+ error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); > >>+ return; > >>+ } > >>+ > >>+ if (bdrv_is_read_only(bs)) { > >>+ error_set(errp, QERR_DEVICE_IS_READ_ONLY, device); > >>+ return; > >>+ } > >>+ > >>+ if (!bdrv_can_snapshot(bs)) { > >>+ error_set(errp, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, > >>+ bs->drv->format_name, device, "internal snapshot")= ; > >>+ return; > >>+ } > >>+ > >>+ if (!strlen(name)) { > >>+ error_setg(errp, "Name is empty on device '%s'", device); > > > >Name is empty. This has nothing to do with the device. > > > OK. >=20 > >>+ return; > >>+ } > >>+ > >>+ /* check whether a snapshot with name exist */ > >>+ ret =3D bdrv_snapshot_find_by_id_and_name(bs, NULL, name, &sn, e= rrp); > >>+ if (error_is_set(errp)) { > >>+ return; > >>+ } > >>+ if (ret) { > > > >Save one line with '} else if {' ? > > > will change, thanks. >=20 > >>+ error_setg(errp, > >>+ "Snapshot with name '%s' already exists on device= '%s'", > >>+ name, device); > >>+ return; > >>+ } > >>+ > >>+ /* 3. take the snapshot */ > >>+ sn1 =3D &state->sn; > > > >do_savevm() has a memset() to clear all of sn1 before it starts fillin= g > >it in. Should we do the same here? For example sn1.vm_state_size looks > >undefined. > > > I think state->sn is set to zero by > qmp_transaction(): > state =3D g_malloc0(ops->instance_size); Oh, yes. I was confused by the fact that there is a local sn, which isn't related to sn1 at all. Perhaps some renaming to make things clearer? Kevin