From patchwork Thu Oct 17 05:36:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 284094 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 07A6C2C00C8 for ; Thu, 17 Oct 2013 16:37:33 +1100 (EST) Received: from localhost ([::1]:50398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWgH5-000227-5G for incoming@patchwork.ozlabs.org; Thu, 17 Oct 2013 01:37:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWgGf-0001xz-Az for qemu-devel@nongnu.org; Thu, 17 Oct 2013 01:37:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWgGZ-0003cW-7c for qemu-devel@nongnu.org; Thu, 17 Oct 2013 01:37:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45002) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWgGY-0003cO-VO for qemu-devel@nongnu.org; Thu, 17 Oct 2013 01:36:59 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9H5awoc007580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 17 Oct 2013 01:36:58 -0400 Received: from T430s.nay.redhat.com ([10.66.6.118]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r9H5aiha025495; Thu, 17 Oct 2013 01:36:52 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 17 Oct 2013 13:36:42 +0800 Message-Id: <1381988203-28576-2-git-send-email-famz@redhat.com> In-Reply-To: <1381988203-28576-1-git-send-email-famz@redhat.com> References: <1381988203-28576-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, hbrock@redhat.com, rjones@redhat.com, imain@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [RFC PATCH v3 1/2] 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 Signed-off-by: Fam Zheng --- block.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index fd05a80..38b3e80 100644 --- a/block.c +++ b/block.c @@ -1158,11 +1158,28 @@ 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; - - qdict_extract_subqdict(options, &backing_options, "backing."); - ret = bdrv_open_backing_file(bs, backing_options, &local_err); - if (ret < 0) { - goto close_and_fail; + const char *backing_bs; + + backing_bs = qdict_get_try_str(options, "backing"); + if (backing_bs) { + bs->backing_hd = bdrv_find(backing_bs); + bdrv_ref(bs->backing_hd); + qdict_del(options, "backing"); + if (bs->backing_hd) { + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->backing_hd->filename); + pstrcpy(bs->backing_format, sizeof(bs->backing_format), + bs->backing_hd->drv->format_name); + } else { + error_setg(errp, "Backing device not found: %s", backing_bs); + goto close_and_fail; + } + } else { + qdict_extract_subqdict(options, &backing_options, "backing."); + ret = bdrv_open_backing_file(bs, backing_options, &local_err); + if (ret < 0) { + goto close_and_fail; + } } }