From patchwork Mon May 7 17:34:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 157362 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 B9A3EB6FA5 for ; Tue, 8 May 2012 03:35:36 +1000 (EST) Received: from localhost ([::1]:35469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRRqQ-0001go-Jq for incoming@patchwork.ozlabs.org; Mon, 07 May 2012 13:35:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRRq8-0001YN-Pf for qemu-devel@nongnu.org; Mon, 07 May 2012 13:35:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRRq3-000177-JD for qemu-devel@nongnu.org; Mon, 07 May 2012 13:35:16 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:52055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRRq3-0000QL-B3 for qemu-devel@nongnu.org; Mon, 07 May 2012 13:35:11 -0400 Received: by mail-pz0-f45.google.com with SMTP id v2so1242703dad.4 for ; Mon, 07 May 2012 10:35:10 -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=UAmaE6u7oehNgnluYzO+KAaazdzwXZW7royiC8FvYik=; b=I2pVktb7zzD9KY5l3KRIHZ3rblUgTwYOd+eZ8+Qt8y068b2Q2fexfko2Ef3/rVI4Dj gHi2lBEIK0NR6A/s4tfUrdVDrFONYc+x+cSH54bseQgZpvTECwjPM2626zlx8/Ad3oTY 2BALP4kPjqp/ohIy2yPq9qeSh55UrNzuaBvJehqh09HnlRP++iAUco2XYL+rh9gKQAFj G/yQd/8uQRKBgTYL9cjjhfExl40NxTgSIKCl/yr6R4Mxy23nXd8hADMlvzXgzO6ZjMg4 peyA1zTmtoEypnn0hS4StmsO5WXfU1x0/PyiazOoIWVUPd6FsqRYmWmoMa7I5wyRVrJX P84Q== Received: by 10.68.233.165 with SMTP id tx5mr2398244pbc.163.1336412110417; Mon, 07 May 2012 10:35:10 -0700 (PDT) Received: from localhost.localdomain ([124.207.163.4]) by mx.google.com with ESMTPS id pn10sm18904952pbb.22.2012.05.07.10.35.05 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 07 May 2012 10:35:09 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Tue, 8 May 2012 01:34:18 +0800 Message-Id: <1336412058-13751-3-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1336412058-13751-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1336412058-13751-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.210.45 Cc: Kevin Wolf , Marcelo Tosatti , Dong Xu Wang , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 3/3 v9] add-cow: support 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 Raw does not support snapshot_blkdev, we will use add-cow as metadata. CC: Marcelo Tosatti CC: Kevin Wolf CC: Stefan Hajnoczi Signed-off-by: Dong Xu Wang --- blockdev.c | 31 +++++++++++++++++++++++++++---- docs/live-block-ops.txt | 10 +++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index d25ffea..b9939d3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -780,15 +780,38 @@ 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, + if (strcmp(format, "add-cow")) { + 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; + } else { + char image_file[1024]; + char option[1024]; + uint64_t size; + + bdrv_get_geometry(states->old_bs, &size); + size *= BDRV_SECTOR_SIZE; + + sprintf(image_file, "%s.raw", new_image_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", new_image_file); + ret = bdrv_img_create(new_image_file, format, + states->old_bs->filename, + states->old_bs->drv->format_name, + option, -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(""); diff --git a/docs/live-block-ops.txt b/docs/live-block-ops.txt index a257087..c97344b 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,10 @@ 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.