From patchwork Wed Feb 22 17:13:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Federico Simoncelli X-Patchwork-Id: 142508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 81C1AB6FA5 for ; Thu, 23 Feb 2012 04:14:37 +1100 (EST) Received: from localhost ([::1]:54844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0Flz-0004Bh-Fa for incoming@patchwork.ozlabs.org; Wed, 22 Feb 2012 12:14:35 -0500 Received: from eggs.gnu.org ([140.186.70.92]:48634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0Flh-0003if-Ne for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:14:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0Flg-0008Ov-5p for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:14:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41665) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0Flf-0008Oq-VH for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:14:16 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q1MHEFI9004918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Feb 2012 12:14:15 -0500 Received: from vm-rhdev1.telemaco.homelinux.net (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q1MHDwJV005471; Wed, 22 Feb 2012 12:14:14 -0500 From: Federico Simoncelli To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2012 17:13:35 +0000 Message-Id: <1329930815-7995-4-git-send-email-fsimonce@redhat.com> In-Reply-To: <1329930815-7995-1-git-send-email-fsimonce@redhat.com> References: <1329930815-7995-1-git-send-email-fsimonce@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, Federico Simoncelli , mtosatti@redhat.com Subject: [Qemu-devel] [PATCH 3/3] Add nocreate option to snapshot_blkdev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Federico Simoncelli --- blockdev.c | 14 ++++++++------ hmp-commands.hx | 16 ++++++++++------ hmp.c | 4 +++- qapi-schema.json | 8 +++++++- qmp-commands.hx | 2 +- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/blockdev.c b/blockdev.c index 7a6613a..2c3e10a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -647,7 +647,7 @@ void do_commit(Monitor *mon, const QDict *qdict) void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, bool has_format, const char *format, - Error **errp) + bool has_nocreate, bool nocreate, Error **errp) { BlockDriverState *bs; BlockDriver *drv, *old_drv, *proto_drv; @@ -686,11 +686,13 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, return; } - ret = bdrv_img_create(snapshot_file, format, bs->filename, - bs->drv->format_name, NULL, -1, flags); - if (ret) { - error_set(errp, QERR_UNDEFINED_ERROR); - return; + if (!(has_nocreate && nocreate)) { + ret = bdrv_img_create(snapshot_file, format, bs->filename, + bs->drv->format_name, NULL, -1, flags); + if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } } bdrv_drain_all(); diff --git a/hmp-commands.hx b/hmp-commands.hx index 573b823..ff49412 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -868,14 +868,18 @@ ETEXI { .name = "snapshot_blkdev", - .args_type = "device:B,snapshot-file:s?,format:s?", - .params = "device [new-image-file] [format]", + .args_type = "nocreate:-n,device:B,snapshot-file:s?,format:s?", + .params = "[-n] device [new-image-file] [format]", .help = "initiates a live snapshot\n\t\t\t" "of device. If a new image file is specified, the\n\t\t\t" - "new image file will become the new root image.\n\t\t\t" - "If format is specified, the snapshot file will\n\t\t\t" - "be created in that format. Otherwise the\n\t\t\t" - "snapshot will be internal! (currently unsupported)", + "new image file will be created (unless -n is\n\t\t\t" + "specified) and will become the new root image.\n\t\t\t" + "The -n (nocreate) option is potentially dangerous\n\t\t\t" + "if the image wasn't prepared in the correct way\n\t\t\t" + "by an external manager. If format is specified,\n\t\t\t" + "the snapshot file will be created in that format.\n\t\t\t" + "Otherwise the snapshot will be internal!\n\t\t\t" + "(currently unsupported)", .mhandler.cmd = hmp_snapshot_blkdev, }, diff --git a/hmp.c b/hmp.c index 8ff8c94..44868c7 100644 --- a/hmp.c +++ b/hmp.c @@ -684,6 +684,7 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict) void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) { + int nocreate = qdict_get_try_bool(qdict, "nocreate", 0); const char *device = qdict_get_str(qdict, "device"); const char *filename = qdict_get_try_str(qdict, "snapshot-file"); const char *format = qdict_get_try_str(qdict, "format"); @@ -697,7 +698,8 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) return; } - qmp_blockdev_snapshot_sync(device, filename, !!format, format, &errp); + qmp_blockdev_snapshot_sync(device, filename, + !!format, format, true, nocreate, &errp); hmp_handle_error(mon, &errp); } diff --git a/qapi-schema.json b/qapi-schema.json index d02ee86..ac652c2 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1116,9 +1116,14 @@ # @snapshot-file: the target of the new image. If the file exists, or if it # is a device, the snapshot will be created in the existing # file/device. If does not exist, a new file will be created. +# This behavior can be overridden using the nocreate option. # # @format: #optional the format of the snapshot image, default is 'qcow2'. # +# @nocreate: #optional use the target image avoiding the creation. This is +# a potentially dangerous option if the image wasn't prepared +# in the correct way by an external manager. +# # Returns: nothing on success # If @device is not a valid block device, DeviceNotFound # If @snapshot-file can't be opened, OpenFileFailed @@ -1133,7 +1138,8 @@ # Since 0.14.0 ## { 'command': 'blockdev-snapshot-sync', - 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } } + 'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str', + '*nocreate': 'bool' } } ## # @human-monitor-command: diff --git a/qmp-commands.hx b/qmp-commands.hx index b5e2ab8..e717826 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -668,7 +668,7 @@ EQMP { .name = "blockdev-snapshot-sync", - .args_type = "device:B,snapshot-file:s,format:s?", + .args_type = "nocreate:-n,device:B,snapshot-file:s,format:s?", .mhandler.cmd_new = qmp_marshal_input_blockdev_snapshot_sync, },