From patchwork Tue Apr 26 21:32:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 8945781 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4ED009F441 for ; Tue, 26 Apr 2016 21:32:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9262220166 for ; Tue, 26 Apr 2016 21:32:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A37B32014A for ; Tue, 26 Apr 2016 21:32:56 +0000 (UTC) Received: from localhost ([::1]:39688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAbH-0006n7-Pf for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Apr 2016 17:32:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAay-0006fm-Jc for qemu-devel@nongnu.org; Tue, 26 Apr 2016 17:32:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avAax-0003uY-If for qemu-devel@nongnu.org; Tue, 26 Apr 2016 17:32:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAat-0003sg-17; Tue, 26 Apr 2016 17:32:31 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8DC6C057FA6; Tue, 26 Apr 2016 21:32:30 +0000 (UTC) Received: from localhost (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3QLWTc8013554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 26 Apr 2016 17:32:30 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 26 Apr 2016 23:32:03 +0200 Message-Id: <1461706338-20219-5-git-send-email-mreitz@redhat.com> In-Reply-To: <1461706338-20219-1-git-send-email-mreitz@redhat.com> References: <1461706338-20219-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/19] block: Add bdrv_default_refresh_format_filename X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Split off the default code for format BDS from bdrv_refresh_filename() into an own function, first because it is nicer this way, and second because this will allow block drivers to reuse this function in their own specific implementation of bdrv_refresh_filename(). Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 95 +++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/block.c b/block.c index aff9ea3..447468c 100644 --- a/block.c +++ b/block.c @@ -3872,6 +3872,56 @@ static bool append_open_options(QDict *d, BlockDriverState *bs) return found_any; } +static void bdrv_default_refresh_format_filename(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + QDict *opts; + bool has_open_options; + + bs->exact_filename[0] = '\0'; + if (bs->full_open_options) { + QDECREF(bs->full_open_options); + bs->full_open_options = NULL; + } + + opts = qdict_new(); + has_open_options = append_open_options(opts, bs); + has_open_options |= bs->backing_overridden; + + /* If no specific options have been given for this BDS, the filename of + * the underlying file should suffice for this one as well */ + if (bs->file->bs->exact_filename[0] && !has_open_options) { + strcpy(bs->exact_filename, bs->file->bs->exact_filename); + } + /* Reconstructing the full options QDict is simple for most format block + * drivers, as long as the full options are known for the underlying + * file BDS. The full options QDict of that file BDS should somehow + * contain a representation of the filename, therefore the following + * suffices without querying the (exact_)filename of this BDS. */ + if (bs->file->bs->full_open_options && + (!bs->backing || bs->backing->bs->full_open_options)) + { + qdict_put_obj(opts, "driver", + QOBJECT(qstring_from_str(drv->format_name))); + + QINCREF(bs->file->bs->full_open_options); + qdict_put_obj(opts, "file", + QOBJECT(bs->file->bs->full_open_options)); + + if (bs->backing) { + QINCREF(bs->backing->bs->full_open_options); + qdict_put_obj(opts, "backing", + QOBJECT(bs->backing->bs->full_open_options)); + } else if (bs->backing_overridden && !bs->backing) { + qdict_put_obj(opts, "backing", QOBJECT(qstring_new())); + } + + bs->full_open_options = opts; + } else { + QDECREF(opts); + } +} + /* Updates the following BDS fields: * - exact_filename: A filename which may be used for opening a block device * which (mostly) equals the given BDS (even without any @@ -3915,50 +3965,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) QDECREF(opts); } else if (bs->file) { /* Try to reconstruct valid information from the underlying file */ - bool has_open_options; - - bs->exact_filename[0] = '\0'; - if (bs->full_open_options) { - QDECREF(bs->full_open_options); - bs->full_open_options = NULL; - } - - opts = qdict_new(); - has_open_options = append_open_options(opts, bs); - has_open_options |= bs->backing_overridden; - - /* If no specific options have been given for this BDS, the filename of - * the underlying file should suffice for this one as well */ - if (bs->file->bs->exact_filename[0] && !has_open_options) { - strcpy(bs->exact_filename, bs->file->bs->exact_filename); - } - /* Reconstructing the full options QDict is simple for most format block - * drivers, as long as the full options are known for the underlying - * file BDS. The full options QDict of that file BDS should somehow - * contain a representation of the filename, therefore the following - * suffices without querying the (exact_)filename of this BDS. */ - if (bs->file->bs->full_open_options && - (!bs->backing || bs->backing->bs->full_open_options)) - { - qdict_put_obj(opts, "driver", - QOBJECT(qstring_from_str(drv->format_name))); - - QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "file", - QOBJECT(bs->file->bs->full_open_options)); - - if (bs->backing) { - QINCREF(bs->backing->bs->full_open_options); - qdict_put_obj(opts, "backing", - QOBJECT(bs->backing->bs->full_open_options)); - } else if (bs->backing_overridden && !bs->backing) { - qdict_put_obj(opts, "backing", QOBJECT(qstring_new())); - } - - bs->full_open_options = opts; - } else { - QDECREF(opts); - } + bdrv_default_refresh_format_filename(bs); } else if (!bs->full_open_options && qdict_size(bs->options)) { /* There is no underlying file BDS (at least referenced by BDS.file), * so the full options QDict should be equal to the options given