From patchwork Tue Jul 31 16:51:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 174287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7F3E92C009F for ; Wed, 1 Aug 2012 02:52:52 +1000 (EST) Received: from localhost ([::1]:60741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwFgg-0001pV-Aq for incoming@patchwork.ozlabs.org; Tue, 31 Jul 2012 12:52:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwFgQ-0001gq-9X for qemu-devel@nongnu.org; Tue, 31 Jul 2012 12:52:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SwFgO-0004Lp-Tv for qemu-devel@nongnu.org; Tue, 31 Jul 2012 12:52:34 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:39301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwFgO-0004Jc-PD for qemu-devel@nongnu.org; Tue, 31 Jul 2012 12:52:32 -0400 Received: by mail-yw0-f45.google.com with SMTP id p34so6071606yhp.4 for ; Tue, 31 Jul 2012 09:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=h8e1T02UGzhEWPZb/WKO73l2mQRWy9wAnvoJ3AC2bBw=; b=bZNU43ElL8suHkf2nQsYCNdfNRZnRIQ8Zrm0OXqRxJ7CFdfGZw5GWnZKHsTtrh4Fhc I/Lh1e8parR6WbF5XR6EAELM1+1fPmhZXXvAtm4Nq1p07+x/vsQktFVG3cTDUalRhg2R 5kv6LFDXfrsR9lGX/unvMWLNcIHA4+hCq6ybDYh4NiQweZ0KDu/lEzidVl+AkWNPuon8 vz3XjC8IX2+NrnofHdAepxMyEhfP+0FusDvDzYGKXlN0xiqVYHCYyTnxqdJCPDE/x4Ws GWn3kbqh4gKoAkXVkdWAHnthjQ8P9FPXqa2MbMhUTKf/BVCDb8ViSuIsyGo66aMlBpDd BTFw== Received: by 10.50.85.230 with SMTP id k6mr1253413igz.49.1343753552099; Tue, 31 Jul 2012 09:52:32 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id uq6sm3025753igb.14.2012.07.31.09.52.29 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jul 2012 09:52:31 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Wed, 1 Aug 2012 00:51:48 +0800 Message-Id: <1343753510-24661-4-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1343753510-24661-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1343753510-24661-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.45 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH 4/6 v11] add-cow: support snapshot_blkde 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 add-cow will let raw file support snapshot_blkdev indirectly. Signed-off-by: Dong Xu Wang --- blockdev.c | 45 +++++++++++++++++++++++++++++++++++++-------- docs/live-block-ops.txt | 11 ++++++++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3d75015..a1e9268 100644 --- a/blockdev.c +++ b/blockdev.c @@ -19,7 +19,7 @@ #include "qmp-commands.h" #include "trace.h" #include "arch_init.h" - +#include "block/add-cow.h" static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); static const char *const if_name[IF_COUNT] = { @@ -665,6 +665,8 @@ static void blockdev_do_action(int kind, void *data, Error **errp) void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, bool has_format, const char *format, bool has_mode, enum NewImageMode mode, + bool has_image_file, const char *image_filename, + bool has_image_format, const char *image_format, Error **errp) { BlockdevSnapshot snapshot = { @@ -674,6 +676,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, .format = (char *) format, .has_mode = has_mode, .mode = mode, + .has_image_file = has_image_file, + .image_file = (char *) image_filename, + .has_image_format = has_image_format, + .image_format = (char *) image_format, }; blockdev_do_action(BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC, &snapshot, errp); @@ -776,15 +782,30 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) /* create new image w/backing file */ if (mode != NEW_IMAGE_MODE_EXISTING) { - ret = bdrv_img_create(new_image_file, format, - states->old_bs->filename, - states->old_bs->drv->format_name, - NULL, -1, flags); - if (ret) { - error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file); - goto delete_and_fail; + char option[1024]; + uint64_t size; + + bdrv_get_geometry(states->old_bs, &size); + size *= BDRV_SECTOR_SIZE; + if (dev_info->blockdev_snapshot_sync->image_file) { + sprintf(option, "image_file=%s,image_format=%s", + dev_info->blockdev_snapshot_sync->image_file, + dev_info->blockdev_snapshot_sync->has_image_format ? dev_info->blockdev_snapshot_sync->image_format : "raw"); + ret = bdrv_img_create(new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + option, -1, flags); + } else { + ret = bdrv_img_create(new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + NULL, -1, flags); } } + if (ret) { + error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file); + goto delete_and_fail; + } /* We will manually add the backing_hd field to the bs later */ states->new_bs = bdrv_new(""); @@ -1083,6 +1104,14 @@ static void block_stream_cb(void *opaque, int ret) } qobject_decref(obj); + if (strcmp(bs->drv->format_name, "add-cow") == 0) { + BDRVAddCowState *s = bs->opaque; + char *format = s->image_file_format; + BlockDriver *drv = bdrv_find_format(format); + assert(drv); + bdrv_drain_all(); + bdrv_swap(s->image_hd, bs); + } drive_put_ref_bh_schedule(drive_get_by_blockdev(bs)); } diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt index a257087..a53bab3 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 =================== @@ -56,3 +57,11 @@ 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 source.img raw + +source.img is a raw file, and should be pre-created. disk.img will be created +using soure.img as image file. After block_stream process finished, it will +reassociate the drive with source.img automatically.