From patchwork Thu Jun 20 17:46:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 253050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 81E452C007B for ; Fri, 21 Jun 2013 04:03:12 +1000 (EST) Received: from localhost ([::1]:56109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjCQ-00032C-JU for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 14:03:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upj50-0005S7-S5 for qemu-devel@nongnu.org; Thu, 20 Jun 2013 13:55:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upj4z-0005DA-TF for qemu-devel@nongnu.org; Thu, 20 Jun 2013 13:55:30 -0400 Received: from mail-wg0-x22a.google.com ([2a00:1450:400c:c00::22a]:34033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upiwh-0002J7-TF for qemu-devel@nongnu.org; Thu, 20 Jun 2013 13:46:56 -0400 Received: by mail-wg0-f42.google.com with SMTP id z11so411090wgg.3 for ; Thu, 20 Jun 2013 10:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=n+QuLB1crDdTWKK5BIh/14wowKvoTyP4ezmwGckhpbU=; b=QjtRIWv86Rqwnjs4HGAI55CbSSDI16kBLx0zWskOFUDBStXSvZHl00mDGDLtpDIhXs xowaFql5pJdB0XFwXUX+lw45QbWPrJ9vVrSqUDjjIb8FGBIWepPrJz9nVmwwAwNi63A7 FQ6hwCpgNzQjel2Rrcz55FFBCnpzwPX4t8up5q4viR5cJF3/vLYiAQLIgMJNiysQpih3 AYCbM/JIFzixFCNVGNVukdcGrbOviwh6ejcrZC1vw+3bnPbJpiba6YUsBvVW92odyQil 3gDdcTB8DQf1dgqd+xXSIvSJxXo0God84Gn0jrMMOfa1zBg2CiWxQiwv9EJtCgrj0C7K Fiyg== X-Received: by 10.194.122.103 with SMTP id lr7mr6523550wjb.15.1371750415178; Thu, 20 Jun 2013 10:46:55 -0700 (PDT) Received: from localhost (158.red-80-26-177.adsl.dynamic.ccgg.telefonica.net. [80.26.177.158]) by mx.google.com with ESMTPSA id cw8sm17681582wib.7.2013.06.20.10.46.53 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 20 Jun 2013 10:46:54 -0700 (PDT) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 19:46:08 +0200 Message-Id: <1371750371-18491-10-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 1.8.3.rc1.49.g8d97506 In-Reply-To: <1371750371-18491-1-git-send-email-marcandre.lureau@redhat.com> References: <1371750371-18491-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::22a Cc: spice-devel@lists.freedesktop.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH 09/12] block: add "snapshot.size" option to avoid extra bdrv_open() 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: Marc-André Lureau --- block.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 5db8fa1..b421083 100644 --- a/block.c +++ b/block.c @@ -1046,20 +1046,25 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, BlockDriverState *bs1; int64_t total_size; + total_size = qdict_get_try_int(options, "snapshot.size", -1); + qdict_del(options, "snapshot.size"); + if (qdict_size(options) != 0) { error_report("Can't use snapshot=on with driver-specific options"); ret = -EINVAL; goto fail; } - bs1 = bdrv_new_int("", NULL); - ret = bdrv_open(bs1, filename, NULL, 0, drv); - if (ret < 0) { + if (total_size == -1) { + bs1 = bdrv_new_int("", NULL); + ret = bdrv_open(bs1, filename, NULL, 0, drv); + if (ret < 0) { + bdrv_delete(bs1); + goto fail; + } + total_size = bdrv_getlength(bs1); bdrv_delete(bs1); - goto fail; } - total_size = bdrv_getlength(bs1); - bdrv_delete(bs1); ret = make_snapshot(bs, total_size, &filename, &drv); if (ret < 0) {