From patchwork Wed Jan 8 02:52:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 307978 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BF14C2C00BD for ; Wed, 8 Jan 2014 14:17:34 +1100 (EST) Received: from localhost ([::1]:44554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0jIk-0006rR-Ha for incoming@patchwork.ozlabs.org; Tue, 07 Jan 2014 21:55:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0jGv-00040b-52 for qemu-devel@nongnu.org; Tue, 07 Jan 2014 21:53:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0jGp-0005JE-3Q for qemu-devel@nongnu.org; Tue, 07 Jan 2014 21:53:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1686) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0jGo-0005J9-RL for qemu-devel@nongnu.org; Tue, 07 Jan 2014 21:53:27 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s082rP7R012871 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 Jan 2014 21:53:26 -0500 Received: from ad.nay.redhat.com ([10.66.6.190]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s082qYID013710; Tue, 7 Jan 2014 21:53:20 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 8 Jan 2014 10:52:17 +0800 Message-Id: <1389149541-9829-8-git-send-email-famz@redhat.com> In-Reply-To: <1389149541-9829-1-git-send-email-famz@redhat.com> References: <1389149541-9829-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, rjones@redhat.com, armbru@redhat.com, imain@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v9 07/11] block: Parse "backing" option to reference existing BDS 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 Now it's safe to allow reference for backing_hd in the interface. Signed-off-by: Fam Zheng --- block.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 907c483..618b8c3 100644 --- a/block.c +++ b/block.c @@ -1199,12 +1199,34 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, /* If there is a backing file, use it */ if ((flags & BDRV_O_NO_BACKING) == 0) { QDict *backing_options; + const char *backing_name; + BlockDriverState *backing_hd; + backing_name = qdict_get_try_str(options, "backing"); qdict_extract_subqdict(options, &backing_options, "backing."); - ret = bdrv_open_backing_file(bs, backing_options, &local_err); - if (ret < 0) { + + if (backing_name && qdict_size(backing_options)) { + error_setg(&local_err, + "Option \"backing\" and \"backing.*\" cannot be " + "used together"); + ret = -EINVAL; goto close_and_fail; } + if (backing_name) { + backing_hd = bdrv_find(backing_name); + if (!backing_hd) { + error_set(&local_err, QERR_DEVICE_NOT_FOUND, backing_name); + ret = -ENOENT; + goto close_and_fail; + } + qdict_del(options, "backing"); + bdrv_set_backing_hd(bs, backing_hd); + } else { + ret = bdrv_open_backing_file(bs, backing_options, &local_err); + if (ret < 0) { + goto close_and_fail; + } + } } /* Check if any unknown options were used */