From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2w5e-0005qA-MO for qemu-devel@nongnu.org; Wed, 29 Feb 2012 21:50:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S2w5c-0006Dx-Ot for qemu-devel@nongnu.org; Wed, 29 Feb 2012 21:49:58 -0500 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:43791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2w5c-0006BQ-3d for qemu-devel@nongnu.org; Wed, 29 Feb 2012 21:49:56 -0500 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 1 Mar 2012 08:19:48 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q212nj9N3383330 for ; Thu, 1 Mar 2012 08:19:45 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q212njGx019436 for ; Thu, 1 Mar 2012 13:49:45 +1100 From: Dong Xu Wang Date: Thu, 1 Mar 2012 10:49:28 +0800 Message-Id: <1330570168-8226-2-git-send-email-wdongxu@linux.vnet.ibm.com> In-Reply-To: <1330570168-8226-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1330570168-8226-1-git-send-email-wdongxu@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/2] block: add-cow support snapshot_blkdev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Marcelo Tosatti , Dong Xu Wang , Stefan Hajnoczi From: Dong Xu Wang We can not use raw to support snapshot_file, but add-cow can do this. CC: Marcelo Tosatti CC: Kevin Wolf CC: Stefan Hajnoczi Signed-off-by: Dong Xu Wang --- blockdev.c | 53 ++++++++++++++++++++++++++++++++++++++++++---- docs/live-block-ops.txt | 8 ++++++- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index d78aa51..c820fcb 100644 --- a/blockdev.c +++ b/blockdev.c @@ -687,12 +687,55 @@ 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 (strcmp(format, "add-cow")) { + 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; + } + } else { + char image_file[1024]; + char option[1024]; + + uint64_t size; + BlockDriver *backing_drv = NULL; + BlockDriverState *backing_bs = NULL; + + backing_bs = bdrv_new(""); + backing_drv = bdrv_find_format(bs->drv->format_name); + if (!backing_drv) { + error_report("Unknown backing file format '%s'", + bs->drv->format_name); + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + ret = bdrv_open(backing_bs, bs->filename, flags, backing_drv); + if (ret < 0) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + bdrv_get_geometry(backing_bs, &size); + size *= 512; + bdrv_delete(backing_bs); + + sprintf(image_file, "%s.raw", snapshot_file); + + ret = bdrv_img_create(image_file, "raw", NULL, + NULL, NULL, size, flags); + if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } + sprintf(option, "image_file=%s.raw", snapshot_file); + ret = bdrv_img_create(snapshot_file, format, bs->filename, + bs->drv->format_name, option, -1, flags); + if (ret) { + error_set(errp, QERR_UNDEFINED_ERROR); + return; + } } + bs->backing_format[0] = '\0'; bdrv_drain_all(); bdrv_flush(bs); diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt index a257087..7edbf91 100644 --- a/docs/live-block-ops.txt +++ b/docs/live-block-ops.txt @@ -2,7 +2,8 @@ LIVE BLOCK OPERATIONS ===================== High level description of live block operations. Note these are not -supported for use with the raw format at the moment. +supported for use with the raw format at the moment, but we can use +add-cow as metadata to suport raw format. Snapshot live merge =================== @@ -55,4 +56,9 @@ into that image. Example: (qemu) block_stream ide0-hd0 +Raw is not supported, but we can use add-cow in the 1st step: +(qemu) snapshot_blkdev ide0-hd0 /new-path/disk.img add-cow + +It will create a raw file named disk.img.raw, with the same virtual size of +ide0-hd0 first, and then create disk.img. -- 1.7.5.4