From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 150670415818130.14765753214374; Fri, 29 Sep 2017 09:55:58 -0700 (PDT) Received: from localhost ([::1]:36173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZn-0001gu-UI for importer@patchew.org; Fri, 29 Sep 2017 12:55:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyY6-0000NK-Nu for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyY5-0002dI-SA for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60044) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyY3-0002bq-9F; Fri, 29 Sep 2017 12:53:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41AE678EA3; Fri, 29 Sep 2017 16:53:58 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3074B17C2A; Fri, 29 Sep 2017 16:53:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 41AE678EA3 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:23 +0200 Message-Id: <20170929165347.29658-2-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 29 Sep 2017 16:53:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 01/25] block/mirror: Small absolute-paths simplification X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When invoking drive-mirror in absolute-paths mode, the target's backing BDS is assigned to it in mirror_exit(). The current logic only does so if the target does not have that backing BDS already; but it actually cannot have a backing BDS at all (the BDS is opened with O_NO_BACKING in qmp_drive_mirror()), so just assert that and assign the new backing BDS unconditionally. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block/mirror.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 351b80ca2c..25e9354b4d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -533,12 +533,12 @@ static void mirror_exit(BlockJob *job, void *opaque) &error_abort); if (s->backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN) { BlockDriverState *backing =3D s->is_none_mode ? src : s->base; - if (backing_bs(target_bs) !=3D backing) { - bdrv_set_backing_hd(target_bs, backing, &local_err); - if (local_err) { - error_report_err(local_err); - data->ret =3D -EPERM; - } + + assert(!target_bs->backing); + bdrv_set_backing_hd(target_bs, backing, &local_err); + if (local_err) { + error_report_err(local_err); + data->ret =3D -EPERM; } } =20 --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704175466124.55570024957751; Fri, 29 Sep 2017 09:56:15 -0700 (PDT) Received: from localhost ([::1]:36174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZu-0001na-L1 for importer@patchew.org; Fri, 29 Sep 2017 12:55:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYH-0000bj-DG for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYG-0002iO-5i for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51364) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYA-0002f9-Mt; Fri, 29 Sep 2017 12:54:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74F5D7EA90; Fri, 29 Sep 2017 16:54:05 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 444D818961; Fri, 29 Sep 2017 16:54:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 74F5D7EA90 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:24 +0200 Message-Id: <20170929165347.29658-3-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 29 Sep 2017 16:54:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 02/25] block: Use children list in bdrv_refresh_filename X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_refresh_filename() should invoke itself recursively on all children, not just on file. With that change, we can remove the manual invocations in blkverify, quorum, commit, and mirror. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 9 +++++---- block/blkverify.c | 3 --- block/commit.c | 1 - block/mirror.c | 1 - block/quorum.c | 1 - 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 5c65fac672..5721168d1d 100644 --- a/block.c +++ b/block.c @@ -4877,16 +4877,17 @@ static bool append_open_options(QDict *d, BlockDriv= erState *bs) void bdrv_refresh_filename(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; + BdrvChild *child; QDict *opts; =20 if (!drv) { return; } =20 - /* This BDS's file name will most probably depend on its file's name, = so - * refresh that first */ - if (bs->file) { - bdrv_refresh_filename(bs->file->bs); + /* This BDS's file name may depend on any of its children's file names= , so + * refresh those first */ + QLIST_FOREACH(child, &bs->children, next) { + bdrv_refresh_filename(child->bs); } =20 if (drv->bdrv_refresh_filename) { diff --git a/block/blkverify.c b/block/blkverify.c index 06369f9eac..b2ed8cd70d 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -281,9 +281,6 @@ static void blkverify_refresh_filename(BlockDriverState= *bs, QDict *options) { BDRVBlkverifyState *s =3D bs->opaque; =20 - /* bs->file->bs has already been refreshed */ - bdrv_refresh_filename(s->test_file->bs); - if (bs->file->bs->full_open_options && s->test_file->bs->full_open_options) { diff --git a/block/commit.c b/block/commit.c index 8f0e83578a..1df8db5428 100644 --- a/block/commit.c +++ b/block/commit.c @@ -246,7 +246,6 @@ static int coroutine_fn bdrv_commit_top_preadv(BlockDri= verState *bs, =20 static void bdrv_commit_top_refresh_filename(BlockDriverState *bs, QDict *= opts) { - bdrv_refresh_filename(bs->backing->bs); pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->backing->bs->filename); } diff --git a/block/mirror.c b/block/mirror.c index 25e9354b4d..7aa873d86f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1078,7 +1078,6 @@ static void bdrv_mirror_top_refresh_filename(BlockDri= verState *bs, QDict *opts) * bdrv_set_backing_hd */ return; } - bdrv_refresh_filename(bs->backing->bs); pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->backing->bs->filename); } diff --git a/block/quorum.c b/block/quorum.c index 272f9a5b77..2f1a628449 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1074,7 +1074,6 @@ static void quorum_refresh_filename(BlockDriverState = *bs, QDict *options) int i; =20 for (i =3D 0; i < s->num_children; i++) { - bdrv_refresh_filename(s->children[i]->bs); if (!s->children[i]->bs->full_open_options) { return; } --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150670432946437.49081894737424; Fri, 29 Sep 2017 09:58:49 -0700 (PDT) Received: from localhost ([::1]:36191 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxycM-000457-LP for importer@patchew.org; Fri, 29 Sep 2017 12:58:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYH-0000bw-G3 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYG-0002iV-Dp for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYD-0002gh-I5; Fri, 29 Sep 2017 12:54:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85317155B9; Fri, 29 Sep 2017 16:54:08 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62AF360610; Fri, 29 Sep 2017 16:54:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 85317155B9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:25 +0200 Message-Id: <20170929165347.29658-4-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 29 Sep 2017 16:54:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 03/25] block: Add BDS.backing_overridden X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the backing file is overridden, this most probably does change the guest-visible data of a BDS. Therefore, we will need to consider this in bdrv_refresh_filename(). Adding a new field to the BDS is not nice, but it is very simple and exactly keeps track of whether the backing file has been overridden. This commit adds a FIXME which will be remedied by a follow-up commit. Until then, the respective piece of code will not result in any behavior that is worse than what we currently have. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- include/block/block_int.h | 1 + block.c | 13 +++++++++++++ block/mirror.c | 4 ++++ blockdev.c | 16 ++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 99abe2ce74..2b816ec601 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -603,6 +603,7 @@ struct BlockDriverState { char backing_file[PATH_MAX]; /* if non zero, the image is a diff of this file image */ char backing_format[16]; /* if non-zero and backing_file exists */ + bool backing_overridden; /* backing file has been specified by the use= r */ =20 QDict *full_open_options; char exact_filename[PATH_MAX]; diff --git a/block.c b/block.c index 5721168d1d..95258316ec 100644 --- a/block.c +++ b/block.c @@ -2196,6 +2196,11 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, reference =3D qdict_get_try_str(parent_options, bdref_key); if (reference || qdict_haskey(options, "file.filename")) { backing_filename[0] =3D '\0'; + + /* FIXME: Should also be set to true if @options contains other ru= ntime + * options which control the data that is read from the bac= king + * BDS */ + bs->backing_overridden =3D true; } else if (bs->backing_file[0] =3D=3D '\0' && qdict_size(options) =3D= =3D 0) { QDECREF(options); goto free_exit; @@ -2396,6 +2401,9 @@ static BlockDriverState *bdrv_append_temp_snapshot(Bl= ockDriverState *bs, goto out; } =20 + bs_snapshot->backing_overridden =3D true; + bdrv_refresh_filename(bs_snapshot); + out: QDECREF(snapshot_options); g_free(tmp_filename); @@ -2526,6 +2534,7 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, backing =3D qdict_get_try_str(options, "backing"); if (backing && *backing =3D=3D '\0') { flags |=3D BDRV_O_NO_BACKING; + bs->backing_overridden =3D true; qdict_del(options, "backing"); } =20 @@ -4888,6 +4897,10 @@ void bdrv_refresh_filename(BlockDriverState *bs) * refresh those first */ QLIST_FOREACH(child, &bs->children, next) { bdrv_refresh_filename(child->bs); + + if (child->role =3D=3D &child_backing && child->bs->backing_overri= dden) { + bs->backing_overridden =3D true; + } } =20 if (drv->bdrv_refresh_filename) { diff --git a/block/mirror.c b/block/mirror.c index 7aa873d86f..cac7490e04 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -540,6 +540,10 @@ static void mirror_exit(BlockJob *job, void *opaque) error_report_err(local_err); data->ret =3D -EPERM; } + + /* The target image's file already has been created with the backi= ng + * file we just set, so there is no need to set backing_overridden= or + * call bdrv_refresh_filename(). */ } =20 if (s->to_replace) { diff --git a/blockdev.c b/blockdev.c index 56a6b24a0b..b0393e1786 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1781,6 +1781,8 @@ static void external_snapshot_commit(BlkActionState *= common) { ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); + TransactionAction *action =3D common->action; + bool image_was_existing =3D false; =20 /* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we @@ -1789,6 +1791,20 @@ static void external_snapshot_commit(BlkActionState = *common) bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDW= R, NULL); } + + if (action->type =3D=3D TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC= ) { + BlockdevSnapshotSync *s =3D action->u.blockdev_snapshot_sync.data; + if (s->has_mode && s->mode =3D=3D NEW_IMAGE_MODE_EXISTING) { + image_was_existing =3D true; + } + } else { + image_was_existing =3D true; + } + + if (image_was_existing) { + state->new_bs->backing_overridden =3D true; + bdrv_refresh_filename(state->new_bs); + } } =20 static void external_snapshot_abort(BlkActionState *common) --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704468114592.5456491803751; Fri, 29 Sep 2017 10:01:08 -0700 (PDT) Received: from localhost ([::1]:36206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyer-0006Jq-8a for importer@patchew.org; Fri, 29 Sep 2017 13:01:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYL-0000fB-99 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYJ-0002k2-TM for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYG-0002iE-D3; Fri, 29 Sep 2017 12:54:12 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48456461C1; Fri, 29 Sep 2017 16:54:11 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FA1418961; Fri, 29 Sep 2017 16:54:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 48456461C1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:26 +0200 Message-Id: <20170929165347.29658-5-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 29 Sep 2017 16:54:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 04/25] block: Respect backing bs in bdrv_refresh_filename X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Basically, bdrv_refresh_filename() should respect all children of a BlockDriverState. However, generally those children are driver-specific, so this function cannot handle the general case. On the other hand, there are only few drivers which use other children than @file and @backing (that being vmdk, quorum, and blkverify). Most block drivers only use @file and/or @backing (if they use any children at all). Both can be implemented directly in bdrv_refresh_filename. The user overriding the file's filename is already handled, however, the user overriding the backing file is not. If this is done, opening the BDS with the plain filename of its file will not be correct, so we may not set bs->exact_filename in that case. iotest 051 contains test cases for overwriting the backing file, and so its output changes with this patch applied (which I consider a good thing). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 12 +++++++++++- tests/qemu-iotests/051.out | 8 ++++---- tests/qemu-iotests/051.pc.out | 8 ++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 95258316ec..ba24845960 100644 --- a/block.c +++ b/block.c @@ -4928,6 +4928,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) =20 opts =3D qdict_new(); has_open_options =3D append_open_options(opts, bs); + has_open_options |=3D bs->backing_overridden; =20 /* If no specific options have been given for this BDS, the filena= me of * the underlying file should suffice for this one as well */ @@ -4939,11 +4940,20 @@ void bdrv_refresh_filename(BlockDriverState *bs) * file BDS. The full options QDict of that file BDS should somehow * contain a representation of the filename, therefore the followi= ng * suffices without querying the (exact_)filename of this BDS. */ - if (bs->file->bs->full_open_options) { + if (bs->file->bs->full_open_options && + (!bs->backing || bs->backing->bs->full_open_options)) + { qdict_put_str(opts, "driver", drv->format_name); QINCREF(bs->file->bs->full_open_options); qdict_put(opts, "file", bs->file->bs->full_open_options); =20 + if (bs->backing) { + QINCREF(bs->backing->bs->full_open_options); + qdict_put(opts, "backing", bs->backing->bs->full_open_opti= ons); + } else if (bs->backing_overridden && !bs->backing) { + qdict_put(opts, "backing", qstring_new()); + } + bs->full_open_options =3D opts; } else { QDECREF(opts); diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index e3c6eaba57..50d5cd07c8 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -59,7 +59,7 @@ QEMU X.Y.Z monitor - type 'help' for more information Testing: -drive file=3DTEST_DIR/t.qcow2,driver=3Dqcow2,backing.file.filena= me=3DTEST_DIR/t.qcow2.orig,if=3Dnone,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.orig"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writeback Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1) @@ -148,7 +148,7 @@ QEMU_PROG: -drive driver=3Dnull-co,cache=3Dinvalid_valu= e: invalid cache option Testing: -drive file=3DTEST_DIR/t.qcow2,cache=3Dwriteback,backing.file.fil= ename=3DTEST_DIR/t.qcow2.base,backing.cache.no-flush=3Don,backing.node-name= =3Dbacking,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,if= =3Dnone,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.base"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writeback Backing file: TEST_DIR/t.qcow2.base (chain depth: 1) @@ -168,7 +168,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Testing: -drive file=3DTEST_DIR/t.qcow2,cache=3Dwritethrough,backing.file.= filename=3DTEST_DIR/t.qcow2.base,backing.cache.no-flush=3Don,backing.node-n= ame=3Dbacking,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,i= f=3Dnone,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.base"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writethrough Backing file: TEST_DIR/t.qcow2.base (chain depth: 1) @@ -188,7 +188,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Testing: -drive file=3DTEST_DIR/t.qcow2,cache=3Dunsafe,backing.file.filena= me=3DTEST_DIR/t.qcow2.base,backing.cache.no-flush=3Don,backing.node-name=3D= backing,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,if=3Dno= ne,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.base"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writeback, ignore flushes Backing file: TEST_DIR/t.qcow2.base (chain depth: 1) diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out index f2c5622cee..406f83780b 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -59,7 +59,7 @@ QEMU X.Y.Z monitor - type 'help' for more information Testing: -drive file=3DTEST_DIR/t.qcow2,driver=3Dqcow2,backing.file.filena= me=3DTEST_DIR/t.qcow2.orig,if=3Dnone,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.orig"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writeback Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1) @@ -240,7 +240,7 @@ QEMU_PROG: -drive driver=3Dnull-co,cache=3Dinvalid_valu= e: invalid cache option Testing: -drive file=3DTEST_DIR/t.qcow2,cache=3Dwriteback,backing.file.fil= ename=3DTEST_DIR/t.qcow2.base,backing.cache.no-flush=3Don,backing.node-name= =3Dbacking,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,if= =3Dnone,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.base"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writeback Backing file: TEST_DIR/t.qcow2.base (chain depth: 1) @@ -260,7 +260,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Testing: -drive file=3DTEST_DIR/t.qcow2,cache=3Dwritethrough,backing.file.= filename=3DTEST_DIR/t.qcow2.base,backing.cache.no-flush=3Don,backing.node-n= ame=3Dbacking,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,i= f=3Dnone,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.base"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writethrough Backing file: TEST_DIR/t.qcow2.base (chain depth: 1) @@ -280,7 +280,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Testing: -drive file=3DTEST_DIR/t.qcow2,cache=3Dunsafe,backing.file.filena= me=3DTEST_DIR/t.qcow2.base,backing.cache.no-flush=3Don,backing.node-name=3D= backing,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,if=3Dno= ne,id=3Ddrive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) info block -drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) +drive0 (NODE_NAME): json:{"backing": {"driver": "qcow2", "file": {"driver"= : "file", "filename": "TEST_DIR/t.qcow2.base"}}, "driver": "qcow2", "file":= {"driver": "file", "filename": "TEST_DIR/t.qcow2"}} (qcow2) Removable device: not locked, tray closed Cache mode: writeback, ignore flushes Backing file: TEST_DIR/t.qcow2.base (chain depth: 1) --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704309367282.3098363480499; Fri, 29 Sep 2017 09:58:29 -0700 (PDT) Received: from localhost ([::1]:36188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxycC-0003wP-HT for importer@patchew.org; Fri, 29 Sep 2017 12:58:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYR-0000l9-RX for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYQ-0002nM-Nc for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYM-0002l0-NL; Fri, 29 Sep 2017 12:54:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A02AB2576C; Fri, 29 Sep 2017 16:54:17 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EC5B7F47C; Fri, 29 Sep 2017 16:54:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A02AB2576C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:27 +0200 Message-Id: <20170929165347.29658-6-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 29 Sep 2017 16:54:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 05/25] block: Make path_combine() return the path X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Besides being safe for arbitrary path lengths, after some follow-up patches all callers will want a freshly allocated buffer anyway. In the meantime, path_combine_deprecated() is added which has the same interface as path_combine() had before this patch. All callers to that function will be converted in follow-up patches. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block.h | 4 +-- block.c | 85 ++++++++++++++++++++++++++++-------------------= ---- block/vmdk.c | 3 +- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 3c3af462e4..a6ab70fb5e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -491,9 +491,7 @@ void bdrv_get_full_backing_filename_from_filename(const= char *backed, =20 int path_has_protocol(const char *path); int path_is_absolute(const char *path); -void path_combine(char *dest, int dest_size, - const char *base_path, - const char *filename); +char *path_combine(const char *base_path, const char *filename); =20 int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os); int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos); diff --git a/block.c b/block.c index ba24845960..32e8437107 100644 --- a/block.c +++ b/block.c @@ -147,53 +147,62 @@ int path_is_absolute(const char *path) #endif } =20 -/* if filename is absolute, just copy it to dest. Otherwise, build a +/* if filename is absolute, just return its duplicate. Otherwise, build a path to it by considering it is relative to base_path. URL are supported. */ -void path_combine(char *dest, int dest_size, - const char *base_path, - const char *filename) +char *path_combine(const char *base_path, const char *filename) { + const char *protocol_stripped =3D NULL; const char *p, *p1; + char *result; int len; =20 - if (dest_size <=3D 0) - return; if (path_is_absolute(filename)) { - pstrcpy(dest, dest_size, filename); - } else { - const char *protocol_stripped =3D NULL; + return g_strdup(filename); + } =20 - if (path_has_protocol(base_path)) { - protocol_stripped =3D strchr(base_path, ':'); - if (protocol_stripped) { - protocol_stripped++; - } + if (path_has_protocol(base_path)) { + protocol_stripped =3D strchr(base_path, ':'); + if (protocol_stripped) { + protocol_stripped++; } - p =3D protocol_stripped ?: base_path; + } + p =3D protocol_stripped ?: base_path; =20 - p1 =3D strrchr(base_path, '/'); + p1 =3D strrchr(base_path, '/'); #ifdef _WIN32 - { - const char *p2; - p2 =3D strrchr(base_path, '\\'); - if (!p1 || p2 > p1) - p1 =3D p2; + { + const char *p2; + p2 =3D strrchr(base_path, '\\'); + if (!p1 || p2 > p1) { + p1 =3D p2; } + } #endif - if (p1) - p1++; - else - p1 =3D base_path; - if (p1 > p) - p =3D p1; - len =3D p - base_path; - if (len > dest_size - 1) - len =3D dest_size - 1; - memcpy(dest, base_path, len); - dest[len] =3D '\0'; - pstrcat(dest, dest_size, filename); + if (p1) { + p1++; + } else { + p1 =3D base_path; + } + if (p1 > p) { + p =3D p1; } + len =3D p - base_path; + + result =3D g_malloc(len + strlen(filename) + 1); + memcpy(result, base_path, len); + strcpy(result + len, filename); + + return result; +} + +static void path_combine_deprecated(char *dest, int dest_size, + const char *base_path, + const char *filename) +{ + char *combined =3D path_combine(base_path, filename); + pstrcpy(dest, dest_size, combined); + g_free(combined); } =20 /* @@ -287,7 +296,7 @@ void bdrv_get_full_backing_filename_from_filename(const= char *backed, error_setg(errp, "Cannot use relative backing file names for '%s'", backed); } else { - path_combine(dest, sz, backed, backing); + path_combine_deprecated(dest, sz, backed, backing); } } =20 @@ -4070,8 +4079,8 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, } else { /* If not an absolute filename path, make it relative to the c= urrent * image's filename path */ - path_combine(filename_tmp, PATH_MAX, curr_bs->filename, - backing_file); + path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filen= ame, + backing_file); =20 /* We are going to compare absolute pathnames */ if (!realpath(filename_tmp, filename_full)) { @@ -4080,8 +4089,8 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, =20 /* We need to make sure the backing filename we are comparing = against * is relative to the current image filename (or absolute) */ - path_combine(filename_tmp, PATH_MAX, curr_bs->filename, - curr_bs->backing_file); + path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filen= ame, + curr_bs->backing_file); =20 if (!realpath(filename_tmp, backing_file_full)) { continue; diff --git a/block/vmdk.c b/block/vmdk.c index c665bcc977..5397a4345e 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -857,8 +857,7 @@ static int vmdk_parse_extents(const char *desc, BlockDr= iverState *bs, return -EINVAL; } =20 - extent_path =3D g_malloc0(PATH_MAX); - path_combine(extent_path, PATH_MAX, desc_file_path, fname); + extent_path =3D path_combine(desc_file_path, fname); =20 ret =3D snprintf(extent_opt_prefix, 32, "extents.%d", s->num_exten= ts); assert(ret < 32); --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150670435074849.524911789352245; Fri, 29 Sep 2017 09:59:10 -0700 (PDT) Received: from localhost ([::1]:36193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyct-0004Ww-TB for importer@patchew.org; Fri, 29 Sep 2017 12:59:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYe-0000uf-3D for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYc-0002tR-OK for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50964) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYX-0002qZ-AV; Fri, 29 Sep 2017 12:54:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4ACA42C96FC; Fri, 29 Sep 2017 16:54:28 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F6049817F; Fri, 29 Sep 2017 16:54:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4ACA42C96FC Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:28 +0200 Message-Id: <20170929165347.29658-7-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 29 Sep 2017 16:54:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 06/25] block: bdrv_get_full_backing_filename_from_...'s ret. val. X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make bdrv_get_full_backing_filename_from_filename() return an allocated string instead of placing the result in a caller-provided buffer. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block.h | 7 +++---- block.c | 51 +++++++++++++++++++++++++++++++++++------------= ---- block/vmdk.c | 9 ++++----- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index a6ab70fb5e..3002236967 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -484,10 +484,9 @@ void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size); void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz, Error **errp); -void bdrv_get_full_backing_filename_from_filename(const char *backed, - const char *backing, - char *dest, size_t sz, - Error **errp); +char *bdrv_get_full_backing_filename_from_filename(const char *backed, + const char *backing, + Error **errp); =20 int path_has_protocol(const char *path); int path_is_absolute(const char *path); diff --git a/block.c b/block.c index 32e8437107..4ca56983bb 100644 --- a/block.c +++ b/block.c @@ -283,20 +283,28 @@ int bdrv_set_read_only(BlockDriverState *bs, bool rea= d_only, Error **errp) return 0; } =20 -void bdrv_get_full_backing_filename_from_filename(const char *backed, - const char *backing, - char *dest, size_t sz, - Error **errp) +/* If @backing is empty, this function returns NULL without setting + * @errp. In all other cases, NULL will only be returned with @errp + * set. + * + * Therefore, a return value of NULL without @errp set means that + * there is no backing file; if @errp is set, there is one but its + * absolute filename cannot be generated. + */ +char *bdrv_get_full_backing_filename_from_filename(const char *backed, + const char *backing, + Error **errp) { - if (backing[0] =3D=3D '\0' || path_has_protocol(backing) || - path_is_absolute(backing)) - { - pstrcpy(dest, sz, backing); + if (backing[0] =3D=3D '\0') { + return NULL; + } else if (path_has_protocol(backing) || path_is_absolute(backing)) { + return g_strdup(backing); } else if (backed[0] =3D=3D '\0' || strstart(backed, "json:", NULL)) { error_setg(errp, "Cannot use relative backing file names for '%s'", backed); + return NULL; } else { - path_combine_deprecated(dest, sz, backed, backing); + return path_combine(backed, backing); } } =20 @@ -304,9 +312,20 @@ void bdrv_get_full_backing_filename(BlockDriverState *= bs, char *dest, size_t sz, Error **errp) { char *backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->file= name; + char *full_name; + Error *local_error =3D NULL; =20 - bdrv_get_full_backing_filename_from_filename(backed, bs->backing_file, - dest, sz, errp); + full_name =3D bdrv_get_full_backing_filename_from_filename(backed, + bs->backing_f= ile, + &local_error); + if (full_name) { + pstrcpy(dest, sz, full_name); + g_free(full_name); + } else if (local_error) { + error_propagate(errp, local_error); + } else if (sz > 0) { + *dest =3D '\0'; + } } =20 void bdrv_register(BlockDriver *bdrv) @@ -4509,17 +4528,17 @@ void bdrv_img_create(const char *filename, const ch= ar *fmt, size =3D qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); if (backing_file && !(flags & BDRV_O_NO_BACKING)) { BlockDriverState *bs; - char *full_backing =3D g_new0(char, PATH_MAX); + char *full_backing; int back_flags; QDict *backing_options =3D NULL; =20 - bdrv_get_full_backing_filename_from_filename(filename, backing_fil= e, - full_backing, PATH_MA= X, - &local_err); + full_backing =3D + bdrv_get_full_backing_filename_from_filename(filename, backing= _file, + &local_err); if (local_err) { - g_free(full_backing); goto out; } + assert(full_backing); =20 /* backing files always opened read-only */ back_flags =3D flags; diff --git a/block/vmdk.c b/block/vmdk.c index 5397a4345e..c1dbcfe133 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2001,16 +2001,15 @@ static int vmdk_create(const char *filename, QemuOp= ts *opts, Error **errp) } if (backing_file) { BlockBackend *blk; - char *full_backing =3D g_new0(char, PATH_MAX); - bdrv_get_full_backing_filename_from_filename(filename, backing_fil= e, - full_backing, PATH_MA= X, - &local_err); + char *full_backing =3D + bdrv_get_full_backing_filename_from_filename(filename, backing= _file, + &local_err); if (local_err) { - g_free(full_backing); error_propagate(errp, local_err); ret =3D -ENOENT; goto exit; } + assert(full_backing); =20 blk =3D blk_new_open(full_backing, NULL, NULL, BDRV_O_NO_BACKING, errp); --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704451472416.1427724148475; Fri, 29 Sep 2017 10:00:51 -0700 (PDT) Received: from localhost ([::1]:36205 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyeg-0006C0-Ek for importer@patchew.org; Fri, 29 Sep 2017 13:00:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYh-0000xR-5N for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYg-0002uW-15 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYc-0002t2-Dr; Fri, 29 Sep 2017 12:54:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 679A04DD7C; Fri, 29 Sep 2017 16:54:33 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 80FBA84CE5; Fri, 29 Sep 2017 16:54:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 679A04DD7C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:29 +0200 Message-Id: <20170929165347.29658-8-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 29 Sep 2017 16:54:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 07/25] block: bdrv_get_full_backing_filename's ret. val. X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make bdrv_get_full_backing_filename() return an allocated string instead of placing the result in a caller-provided buffer. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block.h | 3 +-- block.c | 47 +++++++++++++++++------------------------------ block/qapi.c | 12 ++---------- 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 3002236967..65b15ecd18 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -482,8 +482,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs, const char *bdrv_get_encrypted_filename(BlockDriverState *bs); void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size); -void bdrv_get_full_backing_filename(BlockDriverState *bs, - char *dest, size_t sz, Error **errp); +char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp); char *bdrv_get_full_backing_filename_from_filename(const char *backed, const char *backing, Error **errp); diff --git a/block.c b/block.c index 4ca56983bb..488abfbfc4 100644 --- a/block.c +++ b/block.c @@ -308,24 +308,13 @@ char *bdrv_get_full_backing_filename_from_filename(co= nst char *backed, } } =20 -void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size= _t sz, - Error **errp) +char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp) { char *backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->file= name; - char *full_name; - Error *local_error =3D NULL; =20 - full_name =3D bdrv_get_full_backing_filename_from_filename(backed, - bs->backing_f= ile, - &local_error); - if (full_name) { - pstrcpy(dest, sz, full_name); - g_free(full_name); - } else if (local_error) { - error_propagate(errp, local_error); - } else if (sz > 0) { - *dest =3D '\0'; - } + return bdrv_get_full_backing_filename_from_filename(backed, + bs->backing_file, + errp); } =20 void bdrv_register(BlockDriver *bdrv) @@ -2189,7 +2178,7 @@ out: int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, const char *bdref_key, Error **errp) { - char *backing_filename =3D g_malloc0(PATH_MAX); + char *backing_filename =3D NULL; char *bdref_key_dot; const char *reference =3D NULL; int ret =3D 0; @@ -2223,7 +2212,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, */ reference =3D qdict_get_try_str(parent_options, bdref_key); if (reference || qdict_haskey(options, "file.filename")) { - backing_filename[0] =3D '\0'; + /* keep backing_filename NULL */ =20 /* FIXME: Should also be set to true if @options contains other ru= ntime * options which control the data that is read from the bac= king @@ -2233,8 +2222,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, QDECREF(options); goto free_exit; } else { - bdrv_get_full_backing_filename(bs, backing_filename, PATH_MAX, - &local_err); + backing_filename =3D bdrv_get_full_backing_filename(bs, &local_err= ); if (local_err) { ret =3D -EINVAL; error_propagate(errp, local_err); @@ -2254,9 +2242,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, qdict_put_str(options, "driver", bs->backing_format); } =20 - backing_hd =3D bdrv_open_inherit(*backing_filename ? backing_filename = : NULL, - reference, options, 0, bs, &child_backi= ng, - errp); + backing_hd =3D bdrv_open_inherit(backing_filename, reference, options,= 0, bs, + &child_backing, errp); if (!backing_hd) { bs->open_flags |=3D BDRV_O_NO_BACKING; error_prepend(errp, "Could not open backing file: "); @@ -4062,7 +4049,6 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, int is_protocol =3D 0; BlockDriverState *curr_bs =3D NULL; BlockDriverState *retval =3D NULL; - Error *local_error =3D NULL; =20 if (!bs || !bs->drv || !backing_file) { return NULL; @@ -4079,21 +4065,22 @@ BlockDriverState *bdrv_find_backing_image(BlockDriv= erState *bs, /* If either of the filename paths is actually a protocol, then * compare unmodified paths; otherwise make paths relative */ if (is_protocol || path_has_protocol(curr_bs->backing_file)) { + char *backing_file_full_ret; + if (strcmp(backing_file, curr_bs->backing_file) =3D=3D 0) { retval =3D curr_bs->backing->bs; break; } /* Also check against the full backing filename for the image = */ - bdrv_get_full_backing_filename(curr_bs, backing_file_full, PAT= H_MAX, - &local_error); - if (local_error =3D=3D NULL) { - if (strcmp(backing_file, backing_file_full) =3D=3D 0) { + backing_file_full_ret =3D bdrv_get_full_backing_filename(curr_= bs, + NULL); + if (backing_file_full_ret) { + bool equal =3D strcmp(backing_file, backing_file_full_ret)= =3D=3D 0; + g_free(backing_file_full_ret); + if (equal) { retval =3D curr_bs->backing->bs; break; } - } else { - error_free(local_error); - local_error =3D NULL; } } else { /* If not an absolute filename path, make it relative to the c= urrent diff --git a/block/qapi.c b/block/qapi.c index 7fa2437923..949b4b0b90 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -276,18 +276,10 @@ void bdrv_query_image_info(BlockDriverState *bs, =20 backing_filename =3D bs->backing_file; if (backing_filename[0] !=3D '\0') { - char *backing_filename2 =3D g_malloc0(PATH_MAX); + char *backing_filename2; info->backing_filename =3D g_strdup(backing_filename); info->has_backing_filename =3D true; - bdrv_get_full_backing_filename(bs, backing_filename2, PATH_MAX, &e= rr); - if (err) { - /* Can't reconstruct the full backing filename, so we must omit - * this field and apply a Best Effort to this query. */ - g_free(backing_filename2); - backing_filename2 =3D NULL; - error_free(err); - err =3D NULL; - } + backing_filename2 =3D bdrv_get_full_backing_filename(bs, NULL); =20 /* Always report the full_backing_filename if present, even if it'= s the * same as backing_filename. That they are same is useful info. */ --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150670451948450.660866882053824; Fri, 29 Sep 2017 10:01:59 -0700 (PDT) Received: from localhost ([::1]:36212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyfX-0006x0-Ou for importer@patchew.org; Fri, 29 Sep 2017 13:01:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYn-00013D-Pg for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYn-00033V-2B for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58661) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYk-0002yS-TB; Fri, 29 Sep 2017 12:54:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCC61820E4; Fri, 29 Sep 2017 16:54:41 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9C1886E85; Fri, 29 Sep 2017 16:54:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CCC61820E4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:30 +0200 Message-Id: <20170929165347.29658-9-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Sep 2017 16:54:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 08/25] block: Add bdrv_make_absolute_filename() X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is a general function for making a filename that is relative to a certain BDS absolute. It calls bdrv_get_full_backing_filename_from_filename() for now, but that will be changed in a follow-up patch. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 488abfbfc4..2da242c1e9 100644 --- a/block.c +++ b/block.c @@ -308,13 +308,24 @@ char *bdrv_get_full_backing_filename_from_filename(co= nst char *backed, } } =20 -char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp) +/* If @filename is empty or NULL, this function returns NULL without + * setting @errp. In all other cases, NULL will only be returned with + * @errp set. + */ +static char *bdrv_make_absolute_filename(BlockDriverState *relative_to, + const char *filename, Error **err= p) { - char *backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->file= name; + char *bs_filename =3D relative_to->exact_filename[0] + ? relative_to->exact_filename + : relative_to->filename; + + return bdrv_get_full_backing_filename_from_filename(bs_filename, + filename ?: "", er= rp); +} =20 - return bdrv_get_full_backing_filename_from_filename(backed, - bs->backing_file, - errp); +char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp) +{ + return bdrv_make_absolute_filename(bs, bs->backing_file, errp); } =20 void bdrv_register(BlockDriver *bdrv) --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704225365488.7654650473777; Fri, 29 Sep 2017 09:57:05 -0700 (PDT) Received: from localhost ([::1]:36175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyai-0002X3-Dp for importer@patchew.org; Fri, 29 Sep 2017 12:56:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyYz-0001H2-5A for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyYy-0003Ij-8p for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:54:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40690) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYs-0003Aa-QO; Fri, 29 Sep 2017 12:54:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1A7D6146E; Fri, 29 Sep 2017 16:54:49 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD48C18A44; Fri, 29 Sep 2017 16:54:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1A7D6146E Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:31 +0200 Message-Id: <20170929165347.29658-10-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 29 Sep 2017 16:54:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 09/25] block: Fix bdrv_find_backing_image() X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_find_backing_image() should use bdrv_get_full_backing_filename() or bdrv_make_absolute_filename() instead of trying to do what those functions do by itself. path_combine_deprecated() can now be dropped, so let's do that. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 2da242c1e9..17579125de 100644 --- a/block.c +++ b/block.c @@ -196,15 +196,6 @@ char *path_combine(const char *base_path, const char *= filename) return result; } =20 -static void path_combine_deprecated(char *dest, int dest_size, - const char *base_path, - const char *filename) -{ - char *combined =3D path_combine(base_path, filename); - pstrcpy(dest, dest_size, combined); - g_free(combined); -} - /* * Helper function for bdrv_parse_filename() implementations to remove opt= ional * protocol prefixes (especially "file:") from a filename and for putting = the @@ -4067,7 +4058,6 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, =20 filename_full =3D g_malloc(PATH_MAX); backing_file_full =3D g_malloc(PATH_MAX); - filename_tmp =3D g_malloc(PATH_MAX); =20 is_protocol =3D path_has_protocol(backing_file); =20 @@ -4096,22 +4086,31 @@ BlockDriverState *bdrv_find_backing_image(BlockDriv= erState *bs, } else { /* If not an absolute filename path, make it relative to the c= urrent * image's filename path */ - path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filen= ame, - backing_file); + filename_tmp =3D bdrv_make_absolute_filename(curr_bs, backing_= file, + NULL); + if (!filename_tmp) { + continue; + } =20 /* We are going to compare absolute pathnames */ if (!realpath(filename_tmp, filename_full)) { + g_free(filename_tmp); continue; } + g_free(filename_tmp); =20 /* We need to make sure the backing filename we are comparing = against * is relative to the current image filename (or absolute) */ - path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filen= ame, - curr_bs->backing_file); + filename_tmp =3D bdrv_get_full_backing_filename(curr_bs, NULL); + if (!filename_tmp) { + continue; + } =20 if (!realpath(filename_tmp, backing_file_full)) { + g_free(filename_tmp); continue; } + g_free(filename_tmp); =20 if (strcmp(backing_file_full, filename_full) =3D=3D 0) { retval =3D curr_bs->backing->bs; @@ -4122,7 +4121,6 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, =20 g_free(filename_full); g_free(backing_file_full); - g_free(filename_tmp); return retval; } =20 --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704644449387.82872088782085; Fri, 29 Sep 2017 10:04:04 -0700 (PDT) Received: from localhost ([::1]:36223 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyhi-0000Hl-LG for importer@patchew.org; Fri, 29 Sep 2017 13:03:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZ3-0001Ks-9D for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyZ2-0003OV-E7 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50482) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyYz-0003Ju-M9; Fri, 29 Sep 2017 12:54:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D69A820E6; Fri, 29 Sep 2017 16:54:56 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA13484CF4; Fri, 29 Sep 2017 16:54:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9D69A820E6 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:32 +0200 Message-Id: <20170929165347.29658-11-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Sep 2017 16:54:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 10/25] block: Add bdrv_dirname() X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This function may be implemented by block drivers to derive a directory name from a BDS. Concatenating this g_free()-able string with a relative filename must result in a valid (not necessarily existing) filename, so this is a function that should generally be not implemented by format drivers, because this is protocol-specific. If a BDS's driver does not implement this function, bdrv_dirname() will fall through to the BDS's file if it exists. If it does not, the exact_filename field will be used to generate a directory name. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block.h | 1 + include/block/block_int.h | 7 +++++++ block.c | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index 65b15ecd18..34422e87e7 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -486,6 +486,7 @@ char *bdrv_get_full_backing_filename(BlockDriverState *= bs, Error **errp); char *bdrv_get_full_backing_filename_from_filename(const char *backed, const char *backing, Error **errp); +char *bdrv_dirname(BlockDriverState *bs, Error **errp); =20 int path_has_protocol(const char *path); int path_is_absolute(const char *path); diff --git a/include/block/block_int.h b/include/block/block_int.h index 2b816ec601..3a71be3734 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -135,6 +135,13 @@ struct BlockDriver { =20 void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); =20 + /* + * Returns an allocated string which is the directory name of this BDS= : It + * will be used to make relative filenames absolute by prepending this + * function's return value to them. + */ + char *(*bdrv_dirname)(BlockDriverState *bs, Error **errp); + /* aio */ BlockAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, diff --git a/block.c b/block.c index 17579125de..d2ef7cbecb 100644 --- a/block.c +++ b/block.c @@ -5018,6 +5018,32 @@ void bdrv_refresh_filename(BlockDriverState *bs) } } =20 +char *bdrv_dirname(BlockDriverState *bs, Error **errp) +{ + BlockDriver *drv =3D bs->drv; + + if (!drv) { + error_setg(errp, "Node '%s' is ejected", bs->node_name); + return NULL; + } + + if (drv->bdrv_dirname) { + return drv->bdrv_dirname(bs, errp); + } + + if (bs->file) { + return bdrv_dirname(bs->file->bs, errp); + } + + if (bs->exact_filename[0] !=3D '\0') { + return path_combine(bs->exact_filename, ""); + } + + error_setg(errp, "Cannot generate a base directory for %s nodes", + drv->format_name); + return NULL; +} + /* * Hot add/remove a BDS's child. So the user can take a child offline when * it is broken and take a new child online --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704637929407.19615001605837; Fri, 29 Sep 2017 10:03:57 -0700 (PDT) Received: from localhost ([::1]:36222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyhT-000082-4n for importer@patchew.org; Fri, 29 Sep 2017 13:03:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZC-0001V0-62 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyZB-0003by-Ex for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyZ9-0003WE-8b; Fri, 29 Sep 2017 12:55:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3269DC059B60; Fri, 29 Sep 2017 16:55:06 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D50498E788; Fri, 29 Sep 2017 16:54:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3269DC059B60 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:33 +0200 Message-Id: <20170929165347.29658-12-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 29 Sep 2017 16:55:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 11/25] blkverify: Make bdrv_dirname() return NULL X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" blkverify's BDSs have a file BDS, but we do not want this to be preferred over the raw node. There is no way to decide between the two (and not really a reason to, either), so just return NULL in blkverify's implementation of bdrv_dirname(). Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block/blkverify.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/blkverify.c b/block/blkverify.c index b2ed8cd70d..d5233eeaf9 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -309,6 +309,15 @@ static void blkverify_refresh_filename(BlockDriverStat= e *bs, QDict *options) } } =20 +static char *blkverify_dirname(BlockDriverState *bs, Error **errp) +{ + /* In general, there are two BDSs with different dirnames below this o= ne; + * so there is no unique dirname we could return (unless both are equa= l by + * chance). Therefore, to be consistent, just always return NULL. */ + error_setg(errp, "Cannot generate a base directory for blkverify nodes= "); + return NULL; +} + static BlockDriver bdrv_blkverify =3D { .format_name =3D "blkverify", .protocol_name =3D "blkverify", @@ -320,6 +329,7 @@ static BlockDriver bdrv_blkverify =3D { .bdrv_child_perm =3D bdrv_filter_default_perms, .bdrv_getlength =3D blkverify_getlength, .bdrv_refresh_filename =3D blkverify_refresh_filename, + .bdrv_dirname =3D blkverify_dirname, =20 .bdrv_co_preadv =3D blkverify_co_preadv, .bdrv_co_pwritev =3D blkverify_co_pwritev, --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150670480772039.885443238218954; Fri, 29 Sep 2017 10:06:47 -0700 (PDT) Received: from localhost ([::1]:36239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxykA-0002Sa-LF for importer@patchew.org; Fri, 29 Sep 2017 13:06:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZI-0001do-Ml for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyZH-0003n9-Qc for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyZC-0003cQ-6l; Fri, 29 Sep 2017 12:55:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A9C57F3E3; Fri, 29 Sep 2017 16:55:09 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6799086E97; Fri, 29 Sep 2017 16:55:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3A9C57F3E3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:34 +0200 Message-Id: <20170929165347.29658-13-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 29 Sep 2017 16:55:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 12/25] quorum: Make bdrv_dirname() return NULL X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" While the common implementation for bdrv_dirname() should return NULL for quorum BDSs already (because they do not have a file node and their exact_filename field should be empty), there is no reason not to make that explicit. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block/quorum.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block/quorum.c b/block/quorum.c index 2f1a628449..e5a844335e 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1095,6 +1095,16 @@ static void quorum_refresh_filename(BlockDriverState= *bs, QDict *options) bs->full_open_options =3D opts; } =20 +static char *quorum_dirname(BlockDriverState *bs, Error **errp) +{ + /* In general, there are multiple BDSs with different dirnames below t= his + * one; so there is no unique dirname we could return (unless all are = equal + * by chance, or there is only one). Therefore, to be consistent, just + * always return NULL. */ + error_setg(errp, "Cannot generate a base directory for quorum nodes"); + return NULL; +} + static BlockDriver bdrv_quorum =3D { .format_name =3D "quorum", .protocol_name =3D "quorum", @@ -1104,6 +1114,7 @@ static BlockDriver bdrv_quorum =3D { .bdrv_file_open =3D quorum_open, .bdrv_close =3D quorum_close, .bdrv_refresh_filename =3D quorum_refresh_filename, + .bdrv_dirname =3D quorum_dirname, =20 .bdrv_co_flush_to_disk =3D quorum_co_flush, =20 --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704962536772.2777105498458; Fri, 29 Sep 2017 10:09:22 -0700 (PDT) Received: from localhost ([::1]:36251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxymt-0004gf-Oi for importer@patchew.org; Fri, 29 Sep 2017 13:09:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZk-00021m-PP for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyZk-00040y-16 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyZh-0003yq-10; Fri, 29 Sep 2017 12:55:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0D4225797; Fri, 29 Sep 2017 16:55:39 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 68D5384D11; Fri, 29 Sep 2017 16:55:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F0D4225797 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:35 +0200 Message-Id: <20170929165347.29658-14-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 29 Sep 2017 16:55:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 13/25] block/nbd: Make bdrv_dirname() return NULL X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The generic bdrv_dirname() implementation would be able to generate some form of directory name for many NBD nodes, but it would be always wrong. Therefore, we have to explicitly make it an error (until NBD has some form of specification for export paths, if it ever will). Signed-off-by: Max Reitz --- block/nbd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index a50d24b50a..ed921fa333 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -565,6 +565,16 @@ static void nbd_refresh_filename(BlockDriverState *bs,= QDict *options) bs->full_open_options =3D opts; } =20 +static char *nbd_dirname(BlockDriverState *bs, Error **errp) +{ + /* The generic bdrv_dirname() implementation is able to work out some + * directory name for NBD nodes, but that would be wrong. So far there= is no + * specification for how "export paths" would work, so NBD does not ha= ve + * directory names. */ + error_setg(errp, "Cannot generate a base directory for NBD nodes"); + return NULL; +} + static BlockDriver bdrv_nbd =3D { .format_name =3D "nbd", .protocol_name =3D "nbd", @@ -582,6 +592,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_dirname =3D nbd_dirname, }; =20 static BlockDriver bdrv_nbd_tcp =3D { @@ -601,6 +612,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_dirname =3D nbd_dirname, }; =20 static BlockDriver bdrv_nbd_unix =3D { @@ -620,6 +632,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_dirname =3D nbd_dirname, }; =20 static void bdrv_nbd_init(void) --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150670483041462.386440614978596; Fri, 29 Sep 2017 10:07:10 -0700 (PDT) Received: from localhost ([::1]:36240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxykX-0002n6-Gh for importer@patchew.org; Fri, 29 Sep 2017 13:06:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZr-00029X-K3 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyZq-00045Z-OF for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36398) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyZo-00042x-Mw; Fri, 29 Sep 2017 12:55:48 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A799881DEC; Fri, 29 Sep 2017 16:55:47 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 141E317C2A; Fri, 29 Sep 2017 16:55:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A799881DEC Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:36 +0200 Message-Id: <20170929165347.29658-15-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 29 Sep 2017 16:55:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 14/25] block/nfs: Implement bdrv_dirname() X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" While the basic idea is obvious and could be handled by the default bdrv_dirname() implementation, we cannot generate a directory name if the gid or uid are set, so we have to explicitly return NULL in those cases. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block/nfs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/nfs.c b/block/nfs.c index 337fcd9c84..0152a9bd32 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -875,6 +875,19 @@ static void nfs_refresh_filename(BlockDriverState *bs,= QDict *options) bs->full_open_options =3D opts; } =20 +static char *nfs_dirname(BlockDriverState *bs, Error **errp) +{ + NFSClient *client =3D bs->opaque; + + if (client->uid || client->gid) { + error_setg(errp, "Cannot generate a base directory for NBD node '%= s'", + bs->filename); + return NULL; + } + + return g_strdup_printf("nfs://%s%s/", client->server->host, client->pa= th); +} + #ifdef LIBNFS_FEATURE_PAGECACHE static void nfs_invalidate_cache(BlockDriverState *bs, Error **errp) @@ -908,6 +921,7 @@ static BlockDriver bdrv_nfs =3D { .bdrv_detach_aio_context =3D nfs_detach_aio_context, .bdrv_attach_aio_context =3D nfs_attach_aio_context, .bdrv_refresh_filename =3D nfs_refresh_filename, + .bdrv_dirname =3D nfs_dirname, =20 #ifdef LIBNFS_FEATURE_PAGECACHE .bdrv_invalidate_cache =3D nfs_invalidate_cache, --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506705144077825.2991105918728; Fri, 29 Sep 2017 10:12:24 -0700 (PDT) Received: from localhost ([::1]:36269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxypa-0006wx-VC for importer@patchew.org; Fri, 29 Sep 2017 13:12:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyZz-0002HQ-Gj for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyZy-00048u-C7 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:55:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60902) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyZs-00046H-Im; Fri, 29 Sep 2017 12:55:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87897C0587C6; Fri, 29 Sep 2017 16:55:51 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16D5884CE5; Fri, 29 Sep 2017 16:55:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 87897C0587C6 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:37 +0200 Message-Id: <20170929165347.29658-16-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 29 Sep 2017 16:55:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 15/25] block: Use bdrv_dirname() for relative filenames X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_get_full_backing_filename_from_filename() breaks down when it comes to JSON filenames. Using bdrv_dirname() as the basis is better because since we have BDS, we can descend through the BDS tree to the protocol layer, which gives us a greater probability of finding a non-JSON name; also, bdrv_dirname() is more correct as it allows block drivers to override the generation of that directory name in a protocol-specific way. We still need to keep bdrv_get_full_backing_filename_from_filename(), though, because it has valid callers which need it during image creation when no BDS is available yet. This makes a test case in qemu-iotest 110, which was supposed to fail, work. That is actually good, but we need to change the reference output (and the comment in 110) accordingly. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 20 +++++++++++++++----- tests/qemu-iotests/110 | 3 ++- tests/qemu-iotests/110.out | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index d2ef7cbecb..fd67b667b7 100644 --- a/block.c +++ b/block.c @@ -306,12 +306,22 @@ char *bdrv_get_full_backing_filename_from_filename(co= nst char *backed, static char *bdrv_make_absolute_filename(BlockDriverState *relative_to, const char *filename, Error **err= p) { - char *bs_filename =3D relative_to->exact_filename[0] - ? relative_to->exact_filename - : relative_to->filename; + char *dir, *full_name; =20 - return bdrv_get_full_backing_filename_from_filename(bs_filename, - filename ?: "", er= rp); + if (!filename || filename[0] =3D=3D '\0') { + return NULL; + } else if (path_has_protocol(filename) || path_is_absolute(filename)) { + return g_strdup(filename); + } + + dir =3D bdrv_dirname(relative_to, errp); + if (!dir) { + return NULL; + } + + full_name =3D g_strconcat(dir, filename, NULL); + g_free(dir); + return full_name; } =20 char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp) diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110 index 9de7369f3a..ba1b3c6c7d 100755 --- a/tests/qemu-iotests/110 +++ b/tests/qemu-iotests/110 @@ -61,7 +61,8 @@ echo '=3D=3D=3D Non-reconstructable filename =3D=3D=3D' echo =20 # Across blkdebug without a config file, you cannot reconstruct filenames,= so -# qemu is incapable of knowing the directory of the top image +# qemu is incapable of knowing the directory of the top image from the fil= ename +# alone. However, using bdrv_dirname(), it should still work. TEST_IMG=3D"json:{ 'driver': '$IMGFMT', 'file': { diff --git a/tests/qemu-iotests/110.out b/tests/qemu-iotests/110.out index b3584ff87f..5370bc1d26 100644 --- a/tests/qemu-iotests/110.out +++ b/tests/qemu-iotests/110.out @@ -14,7 +14,7 @@ backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGF= MT.base) image: json:{"driver": "IMGFMT", "file": {"set-state.0.event": "read_aio",= "image": {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}, "driver": "b= lkdebug", "set-state.0.new_state": 42}} file format: IMGFMT virtual size: 64M (67108864 bytes) -backing file: t.IMGFMT.base (cannot determine actual path) +backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGFMT.base) =20 =3D=3D=3D Backing name is always relative to the backed image =3D=3D=3D =20 --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704988755210.33035308212266; Fri, 29 Sep 2017 10:09:48 -0700 (PDT) Received: from localhost ([::1]:36256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxynI-000518-19 for importer@patchew.org; Fri, 29 Sep 2017 13:09:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxya2-0002KZ-KZ for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxya1-0004Ag-Qr for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyZz-000495-3U; Fri, 29 Sep 2017 12:55:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 192E5C0587E0; Fri, 29 Sep 2017 16:55:58 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FBB5989B5; Fri, 29 Sep 2017 16:55:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 192E5C0587E0 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:38 +0200 Message-Id: <20170929165347.29658-17-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 29 Sep 2017 16:55:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 16/25] block: Add 'base-directory' BDS option X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Using this option, one can directly override what bdrv_dirname() will return. This is useful if one uses e.g. qcow2 on top of quorum (with only protocol BDSs under the quorum BDS) and wants to be able to use relative backing filenames. Signed-off-by: Max Reitz --- qapi/block-core.json | 9 +++++++++ include/block/block_int.h | 2 ++ block.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 750bb0c77c..c57741f4c6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3137,6 +3137,14 @@ # (default: off) # @force-share: force share all permission on added nodes. # Requires read-only=3Dtrue. (Since 2.10) +# @base-directory May be specified for any node. Normally, whenever a file= name +# is specified which is supposed to be relative to this no= de +# (such as relative backing filenames), the base directory= to be +# used is the directory the image file of this node is in,= which +# is simply prepended to the relative filename. Using this +# option, the string which is prepended (i.e. the base +# directory) can be overridden. +# (Since 2.10) # # Remaining options are determined by the block driver. # @@ -3145,6 +3153,7 @@ { 'union': 'BlockdevOptions', 'base': { 'driver': 'BlockdevDriver', '*node-name': 'str', + '*base-directory': 'str', '*discard': 'BlockdevDiscardOptions', '*cache': 'BlockdevCacheOptions', '*read-only': 'bool', diff --git a/include/block/block_int.h b/include/block/block_int.h index 3a71be3734..3c53a373e1 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -615,6 +615,8 @@ struct BlockDriverState { QDict *full_open_options; char exact_filename[PATH_MAX]; =20 + char *dirname; + BdrvChild *backing; BdrvChild *file; =20 diff --git a/block.c b/block.c index fd67b667b7..c055bcce5a 100644 --- a/block.c +++ b/block.c @@ -1250,6 +1250,12 @@ QemuOptsList bdrv_runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "always accept other writers (default: off)", }, + { + .name =3D "base-directory", + .type =3D QEMU_OPT_STRING, + .help =3D "String to prepend to filenames relative to this BDS= for " + "making them absolute", + }, { /* end of list */ } }, }; @@ -1322,6 +1328,8 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, trace_bdrv_open_common(bs, filename ?: "", bs->open_flags, drv->format_name); =20 + bs->dirname =3D g_strdup(qemu_opt_get(opts, "base-directory")); + bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); =20 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { @@ -3383,6 +3391,8 @@ static void bdrv_delete(BlockDriverState *bs) =20 bdrv_close(bs); =20 + g_free(bs->dirname); + /* remove from list, if necessary */ if (bs->node_name[0] !=3D '\0') { QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list); @@ -5032,6 +5042,10 @@ char *bdrv_dirname(BlockDriverState *bs, Error **err= p) { BlockDriver *drv =3D bs->drv; =20 + if (bs->dirname) { + return g_strdup(bs->dirname); + } + if (!drv) { error_setg(errp, "Node '%s' is ejected", bs->node_name); return NULL; --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704717852719.7369835566227; Fri, 29 Sep 2017 10:05:17 -0700 (PDT) Received: from localhost ([::1]:36226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyih-00015l-M1 for importer@patchew.org; Fri, 29 Sep 2017 13:04:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxya8-0002Pw-6x for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxya4-0004CW-Jd for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxya2-0004AK-1a; Fri, 29 Sep 2017 12:56:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1CA47EA98; Fri, 29 Sep 2017 16:56:00 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1861E98166; Fri, 29 Sep 2017 16:55:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1CA47EA98 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:39 +0200 Message-Id: <20170929165347.29658-18-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 29 Sep 2017 16:56:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 17/25] iotests: Add quorum case to test 110 X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test 110 tests relative backing filenames for complex BDS trees. Add quorum as an example that can never work automatically (without special-casing if all child nodes have the same base directory), and an example on how to make it work manually (using the base-directory option). Signed-off-by: Max Reitz --- tests/qemu-iotests/110 | 48 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/110.out | 12 ++++++++++++ 2 files changed, 60 insertions(+) diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110 index ba1b3c6c7d..d96b656b6b 100755 --- a/tests/qemu-iotests/110 +++ b/tests/qemu-iotests/110 @@ -30,6 +30,7 @@ status=3D1 # failure is the default! _cleanup() { _cleanup_test_img + rm -f "$TEST_IMG.copy" } trap "_cleanup; exit \$status" 0 1 2 3 15 =20 @@ -87,6 +88,53 @@ echo # omit the image size; it should work anyway _make_test_img -b "$TEST_IMG_REL.base" =20 +echo +echo '=3D=3D=3D Nodes without a common directory =3D=3D=3D' +echo + +cp "$TEST_IMG" "$TEST_IMG.copy" + +# Should inform us that the actual path of the backing file cannot be dete= rmined +TEST_IMG=3D"json:{ + 'driver': '$IMGFMT', + 'file': { + 'driver': 'quorum', + 'vote-threshold': 1, + 'children': [ + { + 'driver': 'file', + 'filename': '$TEST_IMG' + }, + { + 'driver': 'file', + 'filename': '$TEST_IMG.copy' + } + ] + } +}" _img_info | _filter_img_info + +echo + +# Should work fine +TEST_IMG=3D"json:{ + 'driver': '$IMGFMT', + 'file': { + 'driver': 'quorum', + 'base-directory': '$TEST_DIR/', + 'vote-threshold': 1, + 'children': [ + { + 'driver': 'file', + 'filename': '$TEST_IMG' + }, + { + 'driver': 'file', + 'filename': '$TEST_IMG.copy' + } + ] + } +}" _img_info | _filter_img_info + =20 # success, all done echo '*** done' diff --git a/tests/qemu-iotests/110.out b/tests/qemu-iotests/110.out index 5370bc1d26..e1845d8026 100644 --- a/tests/qemu-iotests/110.out +++ b/tests/qemu-iotests/110.out @@ -19,4 +19,16 @@ backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMG= FMT.base) =3D=3D=3D Backing name is always relative to the backed image =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3Dt.IMGFMT.base + +=3D=3D=3D Nodes without a common directory =3D=3D=3D + +image: json:{"driver": "IMGFMT", "file": {"children": [{"driver": "file", = "filename": "TEST_DIR/t.IMGFMT"}, {"driver": "file", "filename": "TEST_DIR/= t.IMGFMT.copy"}], "driver": "quorum", "blkverify": false, "rewrite-corrupte= d": false, "vote-threshold": 1}} +file format: IMGFMT +virtual size: 64M (67108864 bytes) +backing file: t.IMGFMT.base (cannot determine actual path) + +image: json:{"driver": "IMGFMT", "file": {"children": [{"driver": "file", = "filename": "TEST_DIR/t.IMGFMT"}, {"driver": "file", "filename": "TEST_DIR/= t.IMGFMT.copy"}], "driver": "quorum", "blkverify": false, "rewrite-corrupte= d": false, "vote-threshold": 1}} +file format: IMGFMT +virtual size: 64M (67108864 bytes) +backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGFMT.base) *** done --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704410684262.75041291902505; Fri, 29 Sep 2017 10:00:10 -0700 (PDT) Received: from localhost ([::1]:36196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxydl-0005KY-Lv for importer@patchew.org; Fri, 29 Sep 2017 12:59:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaD-0002V4-VS for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyaC-0004Gj-4H for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58048) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxya7-0004D9-C6; Fri, 29 Sep 2017 12:56:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 437F17D0DC; Fri, 29 Sep 2017 16:56:06 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C53A52FD7; Fri, 29 Sep 2017 16:56:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 437F17D0DC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:40 +0200 Message-Id: <20170929165347.29658-19-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Sep 2017 16:56:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 18/25] block: Add sgfnt_runtime_opts to BlockDriver X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This new field can be set by block drivers to list the runtime options they accept that may influence the contents of the respective BDS. As of a follow-up patch, this list will be used by the common bdrv_refresh_filename() implementation to decide which options to put into BDS.full_open_options (and consequently whether a JSON filename has to be created), thus freeing the drivers of having to implement that logic themselves. Additionally, this patch adds the field to all of the block drivers that need it and sets it accordingly. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block_int.h | 7 +++++++ block/blkdebug.c | 6 ++++++ block/crypto.c | 5 +++++ block/curl.c | 21 +++++++++++++++++++++ block/gluster.c | 19 +++++++++++++++++++ block/iscsi.c | 18 ++++++++++++++++++ block/nbd.c | 14 ++++++++++++++ block/nfs.c | 4 ++++ block/null.c | 9 +++++++++ block/quorum.c | 8 ++++++++ block/rbd.c | 5 +++++ block/replication.c | 5 +++++ block/sheepdog.c | 12 ++++++++++++ block/ssh.c | 5 +++++ block/throttle.c | 4 ++++ block/vpc.c | 4 ++++ block/vvfat.c | 4 ++++ block/vxhs.c | 8 ++++++++ 18 files changed, 158 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 3c53a373e1..19d8d6801a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -444,6 +444,13 @@ struct BlockDriver { Error **errp); =20 QLIST_ENTRY(BlockDriver) list; + + /* Pointer to a NULL-terminated array of names of significant options = that + * can be specified for bdrv_open(). A significant option is one that + * changes the data of a BDS. + * If this pointer is NULL, the array is considered empty. + * "filename" and "driver" are always considered significant. */ + const char *const *sgfnt_runtime_opts; }; =20 typedef struct BlockLimits { diff --git a/block/blkdebug.c b/block/blkdebug.c index 46e53f2f09..976dc43f17 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -905,6 +905,12 @@ static BlockDriver bdrv_blkdebug =3D { =3D blkdebug_debug_remove_breakpoint, .bdrv_debug_resume =3D blkdebug_debug_resume, .bdrv_debug_is_suspended =3D blkdebug_debug_is_suspended, + + .sgfnt_runtime_opts =3D (const char *const[]) { "config", + "inject-error.", + "set-state.", + "suspend.", + NULL }, }; =20 static void bdrv_blkdebug_init(void) diff --git a/block/crypto.c b/block/crypto.c index 60ddf8623e..7c3681ff04 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -626,6 +626,11 @@ BlockDriver bdrv_crypto_luks =3D { .bdrv_getlength =3D block_crypto_getlength, .bdrv_get_info =3D block_crypto_get_info_luks, .bdrv_get_specific_info =3D block_crypto_get_specific_info_luks, + + .sgfnt_runtime_opts =3D (const char *const[]) { + BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, + NULL + }, }; =20 static void block_crypto_init(void) diff --git a/block/curl.c b/block/curl.c index 2a244e2439..11318a9a29 100644 --- a/block/curl.c +++ b/block/curl.c @@ -957,6 +957,19 @@ static int64_t curl_getlength(BlockDriverState *bs) return s->len; } =20 +static const char *const curl_sgfnt_runtime_opts[] =3D { + CURL_BLOCK_OPT_URL, + CURL_BLOCK_OPT_SSLVERIFY, + CURL_BLOCK_OPT_COOKIE, + CURL_BLOCK_OPT_COOKIE_SECRET, + CURL_BLOCK_OPT_USERNAME, + CURL_BLOCK_OPT_PASSWORD_SECRET, + CURL_BLOCK_OPT_PROXY_USERNAME, + CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET, + + NULL +}; + static BlockDriver bdrv_http =3D { .format_name =3D "http", .protocol_name =3D "http", @@ -971,6 +984,8 @@ static BlockDriver bdrv_http =3D { =20 .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, + + .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_https =3D { @@ -987,6 +1002,8 @@ static BlockDriver bdrv_https =3D { =20 .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, + + .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_ftp =3D { @@ -1003,6 +1020,8 @@ static BlockDriver bdrv_ftp =3D { =20 .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, + + .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_ftps =3D { @@ -1019,6 +1038,8 @@ static BlockDriver bdrv_ftps =3D { =20 .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, + + .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 static void curl_block_init(void) diff --git a/block/gluster.c b/block/gluster.c index 0f4265a3a4..e47bda97df 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1414,6 +1414,21 @@ static int64_t coroutine_fn qemu_gluster_co_get_bloc= k_status( } =20 =20 +static const char *const gluster_sgfnt_open_opts[] =3D { + GLUSTER_OPT_VOLUME, + GLUSTER_OPT_PATH, + GLUSTER_OPT_TYPE, + GLUSTER_OPT_SERVER_PATTERN, + GLUSTER_OPT_HOST, + GLUSTER_OPT_PORT, + GLUSTER_OPT_TO, + GLUSTER_OPT_IPV4, + GLUSTER_OPT_IPV6, + GLUSTER_OPT_SOCKET, + + NULL +}; + static BlockDriver bdrv_gluster =3D { .format_name =3D "gluster", .protocol_name =3D "gluster", @@ -1440,6 +1455,7 @@ static BlockDriver bdrv_gluster =3D { #endif .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, .create_opts =3D &qemu_gluster_create_opts, + .sgfnt_runtime_opts =3D gluster_sgfnt_open_opts, }; =20 static BlockDriver bdrv_gluster_tcp =3D { @@ -1468,6 +1484,7 @@ static BlockDriver bdrv_gluster_tcp =3D { #endif .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, .create_opts =3D &qemu_gluster_create_opts, + .sgfnt_runtime_opts =3D gluster_sgfnt_open_opts, }; =20 static BlockDriver bdrv_gluster_unix =3D { @@ -1496,6 +1513,7 @@ static BlockDriver bdrv_gluster_unix =3D { #endif .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, .create_opts =3D &qemu_gluster_create_opts, + .sgfnt_runtime_opts =3D gluster_sgfnt_open_opts, }; =20 /* rdma is deprecated (actually never supported for volfile fetch). @@ -1530,6 +1548,7 @@ static BlockDriver bdrv_gluster_rdma =3D { #endif .bdrv_co_get_block_status =3D qemu_gluster_co_get_block_status, .create_opts =3D &qemu_gluster_create_opts, + .sgfnt_runtime_opts =3D gluster_sgfnt_open_opts, }; =20 static void bdrv_gluster_init(void) diff --git a/block/iscsi.c b/block/iscsi.c index 4683f3b244..5da74e3ccb 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2161,6 +2161,20 @@ static QemuOptsList iscsi_create_opts =3D { } }; =20 +static const char *const iscsi_sgfnt_runtime_opts[] =3D { + "transport", + "portal", + "target", + "user", + "password", + "password-secret", + "lun", + "initiator-name", + "header-digest", + + NULL +}; + static BlockDriver bdrv_iscsi =3D { .format_name =3D "iscsi", .protocol_name =3D "iscsi", @@ -2193,6 +2207,8 @@ static BlockDriver bdrv_iscsi =3D { =20 .bdrv_detach_aio_context =3D iscsi_detach_aio_context, .bdrv_attach_aio_context =3D iscsi_attach_aio_context, + + .sgfnt_runtime_opts =3D iscsi_sgfnt_runtime_opts, }; =20 #if LIBISCSI_API_VERSION >=3D (20160603) @@ -2228,6 +2244,8 @@ static BlockDriver bdrv_iser =3D { =20 .bdrv_detach_aio_context =3D iscsi_detach_aio_context, .bdrv_attach_aio_context =3D iscsi_attach_aio_context, + + .sgfnt_runtime_opts =3D iscsi_sgfnt_runtime_opts, }; #endif =20 diff --git a/block/nbd.c b/block/nbd.c index ed921fa333..0a36394b73 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -575,6 +575,17 @@ static char *nbd_dirname(BlockDriverState *bs, Error *= *errp) return NULL; } =20 +static const char *const nbd_sgfnt_runtime_opts[] =3D { + "path", + "host", + "port", + "export", + "tls-creds", + "server.", + + NULL +}; + static BlockDriver bdrv_nbd =3D { .format_name =3D "nbd", .protocol_name =3D "nbd", @@ -593,6 +604,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_dirname =3D nbd_dirname, + .sgfnt_runtime_opts =3D nbd_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_nbd_tcp =3D { @@ -613,6 +625,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_dirname =3D nbd_dirname, + .sgfnt_runtime_opts =3D nbd_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_nbd_unix =3D { @@ -633,6 +646,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_dirname =3D nbd_dirname, + .sgfnt_runtime_opts =3D nbd_sgfnt_runtime_opts, }; =20 static void bdrv_nbd_init(void) diff --git a/block/nfs.c b/block/nfs.c index 0152a9bd32..e8cff25fd3 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -923,6 +923,10 @@ static BlockDriver bdrv_nfs =3D { .bdrv_refresh_filename =3D nfs_refresh_filename, .bdrv_dirname =3D nfs_dirname, =20 + .sgfnt_runtime_opts =3D (const char *const[]) { "path", "u= id", + "gid", "serv= er.", + NULL }, + #ifdef LIBNFS_FEATURE_PAGECACHE .bdrv_invalidate_cache =3D nfs_invalidate_cache, #endif diff --git a/block/null.c b/block/null.c index dd9c13f9ba..59673d2449 100644 --- a/block/null.c +++ b/block/null.c @@ -255,6 +255,13 @@ static void null_refresh_filename(BlockDriverState *bs= , QDict *opts) bs->full_open_options =3D opts; } =20 +static const char *const null_sgfnt_runtime_opts[] =3D { + BLOCK_OPT_SIZE, + NULL_OPT_ZEROES, + + NULL +}; + static BlockDriver bdrv_null_co =3D { .format_name =3D "null-co", .protocol_name =3D "null-co", @@ -273,6 +280,7 @@ static BlockDriver bdrv_null_co =3D { .bdrv_co_get_block_status =3D null_co_get_block_status, =20 .bdrv_refresh_filename =3D null_refresh_filename, + .sgfnt_runtime_opts =3D null_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_null_aio =3D { @@ -293,6 +301,7 @@ static BlockDriver bdrv_null_aio =3D { .bdrv_co_get_block_status =3D null_co_get_block_status, =20 .bdrv_refresh_filename =3D null_refresh_filename, + .sgfnt_runtime_opts =3D null_sgfnt_runtime_opts, }; =20 static void bdrv_null_init(void) diff --git a/block/quorum.c b/block/quorum.c index e5a844335e..fa7b0f6da6 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1130,6 +1130,14 @@ static BlockDriver bdrv_quorum =3D { =20 .is_filter =3D true, .bdrv_recurse_is_first_non_filter =3D quorum_recurse_is_first_non_fi= lter, + + .sgfnt_runtime_opts =3D (const char *const[]) { + QUORUM_OPT_VOTE_THRESHOLD, + QUORUM_OPT_BLKVERIFY, + QUORUM_OPT_REWRITE, + QUORUM_OPT_READ_PATTERN, + NULL + }, }; =20 static void bdrv_quorum_init(void) diff --git a/block/rbd.c b/block/rbd.c index 144f350e1f..79db69e767 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1151,6 +1151,11 @@ static BlockDriver bdrv_rbd =3D { #ifdef LIBRBD_SUPPORTS_INVALIDATE .bdrv_invalidate_cache =3D qemu_rbd_invalidate_cache, #endif + + .sgfnt_runtime_opts =3D (const char *const[]) { "pool", "image", "= conf", + "snapshot", "user", + "server.", + "password-secret", N= ULL }, }; =20 static void bdrv_rbd_init(void) diff --git a/block/replication.c b/block/replication.c index 3a4e6822e4..68795221fd 100644 --- a/block/replication.c +++ b/block/replication.c @@ -694,6 +694,11 @@ BlockDriver bdrv_replication =3D { .bdrv_recurse_is_first_non_filter =3D replication_recurse_is_first_non= _filter, =20 .has_variable_length =3D true, + .sgfnt_runtime_opts =3D (const char *const[]) { + REPLICATION_MODE, + REPLICATION_TOP_ID, + NULL + }, }; =20 static void bdrv_replication_init(void) diff --git a/block/sheepdog.c b/block/sheepdog.c index 696a71442a..1b788534b6 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -3077,6 +3077,15 @@ static QemuOptsList sd_create_opts =3D { } }; =20 +static const char *const sd_sgfnt_runtime_opts[] =3D { + "vdi", + "snap-id", + "tag", + "server.", + + NULL +}; + static BlockDriver bdrv_sheepdog =3D { .format_name =3D "sheepdog", .protocol_name =3D "sheepdog", @@ -3111,6 +3120,7 @@ static BlockDriver bdrv_sheepdog =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .sgfnt_runtime_opts =3D sd_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_sheepdog_tcp =3D { @@ -3147,6 +3157,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .sgfnt_runtime_opts =3D sd_sgfnt_runtime_opts, }; =20 static BlockDriver bdrv_sheepdog_unix =3D { @@ -3183,6 +3194,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .sgfnt_runtime_opts =3D sd_sgfnt_runtime_opts, }; =20 static void bdrv_sheepdog_init(void) diff --git a/block/ssh.c b/block/ssh.c index b049a16eb9..35387cf20d 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1209,6 +1209,11 @@ static BlockDriver bdrv_ssh =3D { .bdrv_getlength =3D ssh_getlength, .bdrv_co_flush_to_disk =3D ssh_co_flush, .create_opts =3D &ssh_create_opts, + .sgfnt_runtime_opts =3D (const char *const[]) { + "host", "port", "path", "user", + "host_key_check", "server.", + NULL + }, }; =20 static void bdrv_ssh_init(void) diff --git a/block/throttle.c b/block/throttle.c index 5bca76300f..93341f8151 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -227,6 +227,10 @@ static BlockDriver bdrv_throttle =3D { .bdrv_co_get_block_status =3D bdrv_co_get_block_status_fro= m_file, =20 .is_filter =3D true, + .sgfnt_runtime_opts =3D (const char *const[]) { + QEMU_OPT_THROTTLE_GROUP_NA= ME, + NULL + }, }; =20 static void bdrv_throttle_init(void) diff --git a/block/vpc.c b/block/vpc.c index 1576d7b595..f351a652b3 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1103,6 +1103,10 @@ static BlockDriver bdrv_vpc =3D { =20 .create_opts =3D &vpc_create_opts, .bdrv_has_zero_init =3D vpc_has_zero_init, + .sgfnt_runtime_opts =3D (const char *const[]) { + VPC_OPT_SIZE_CALC, + NULL + }, }; =20 static void bdrv_vpc_init(void) diff --git a/block/vvfat.c b/block/vvfat.c index a0f2335894..c667f03a14 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3252,6 +3252,10 @@ static BlockDriver bdrv_vvfat =3D { .bdrv_co_preadv =3D vvfat_co_preadv, .bdrv_co_pwritev =3D vvfat_co_pwritev, .bdrv_co_get_block_status =3D vvfat_co_get_block_status, + + .sgfnt_runtime_opts =3D (const char *const[]) { "dir", "fat-type", + "floppy", "label", "= rw", + NULL }, }; =20 static void bdrv_vvfat_init(void) diff --git a/block/vxhs.c b/block/vxhs.c index 75cc6c8672..08cdc3b525 100644 --- a/block/vxhs.c +++ b/block/vxhs.c @@ -565,6 +565,14 @@ static BlockDriver bdrv_vxhs =3D { .bdrv_getlength =3D vxhs_getlength, .bdrv_aio_readv =3D vxhs_aio_readv, .bdrv_aio_writev =3D vxhs_aio_writev, + .sgfnt_runtime_opts =3D (const char *const[]) { + VXHS_OPT_VDISK_ID, + "tls-creds", + VXHS_OPT_HOST, + VXHS_OPT_PORT, + VXHS_OPT_SERVER".", + NULL + }, }; =20 static void bdrv_vxhs_init(void) --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506705169102561.7765619015189; Fri, 29 Sep 2017 10:12:49 -0700 (PDT) Received: from localhost ([::1]:36274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyq6-0007Og-4c for importer@patchew.org; Fri, 29 Sep 2017 13:12:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaI-0002Ye-40 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyaE-0004Hp-NF for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyaB-0004GP-W7; Fri, 29 Sep 2017 12:56:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2165C0587D1; Fri, 29 Sep 2017 16:56:10 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 663057F464; Fri, 29 Sep 2017 16:56:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E2165C0587D1 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:41 +0200 Message-Id: <20170929165347.29658-20-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 29 Sep 2017 16:56:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 19/25] block: Add BlockDriver.bdrv_gather_child_options X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Some follow-up patches will rework the way bs->full_open_options is refreshed in bdrv_refresh_filename(). The new implementation will remove the need for the block drivers' bdrv_refresh_filename() implementations to set bs->full_open_options; instead, it will be generic and use static information from each block driver. However, by implementing bdrv_gather_child_options(), block drivers will still be able to override the way the full_open_options of their children are incorporated into their own. We need to implement this function for VMDK because we have to prevent the generic implementation from gathering the options of all children: It is not possible to specify options for the extents through the runtime options. For quorum, the child names that would be used by the generic implementation and the ones that we actually want to use differ. See quorum_gather_child_options() for more information. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block_int.h | 13 +++++++++++++ block/quorum.c | 30 ++++++++++++++++++++++++++++++ block/vmdk.c | 13 +++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 19d8d6801a..65e6500313 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -136,6 +136,19 @@ struct BlockDriver { void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); =20 /* + * Gathers the open options for all children into @target. A simple fo= rmat + * driver (without backing file support) might implement this function= like + * this: + * + * QINCREF(bs->file->bs->full_open_options); + * qdict_put(target, "file", bs->file->bs->full_open_options); + * + * If not specified, the generic implementation will simply put all + * children's options under their respective name. + */ + void (*bdrv_gather_child_options)(BlockDriverState *bs, QDict *target); + + /* * Returns an allocated string which is the directory name of this BDS= : It * will be used to make relative filenames absolute by prepending this * function's return value to them. diff --git a/block/quorum.c b/block/quorum.c index fa7b0f6da6..2daf8635f3 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1095,6 +1095,35 @@ static void quorum_refresh_filename(BlockDriverState= *bs, QDict *options) bs->full_open_options =3D opts; } =20 +static void quorum_gather_child_options(BlockDriverState *bs, QDict *targe= t) +{ + BDRVQuorumState *s =3D bs->opaque; + QList *children_list; + int i; + + /* The generic implementation for gathering child options in + * bdrv_refresh_filename() would use the names of the children as spec= ified + * for bdrv_open_child() or bdrv_attach_child(), which is "children.%u= " with + * %u being a value (s->next_child_index) that is incremented each tim= e a + * new child is added (and never decremented). Since children can be d= eleted + * at runtime, there may be gaps in that enumeration. When creating a = new + * quorum BDS and specifying the children for it through runtime optio= ns, + * the enumeration used there may not have any gaps, though. + * + * Therefore, we have to create a new gap-less enumeration here (which= we + * can achieve by simply putting all of the children's full_open_optio= ns + * into a QList). + */ + + children_list =3D qlist_new(); + qdict_put(target, "children", children_list); + + for (i =3D 0; i < s->num_children; i++) { + QINCREF(s->children[i]->bs->full_open_options); + qlist_append(children_list, s->children[i]->bs->full_open_options); + } +} + static char *quorum_dirname(BlockDriverState *bs, Error **errp) { /* In general, there are multiple BDSs with different dirnames below t= his @@ -1114,6 +1143,7 @@ static BlockDriver bdrv_quorum =3D { .bdrv_file_open =3D quorum_open, .bdrv_close =3D quorum_close, .bdrv_refresh_filename =3D quorum_refresh_filename, + .bdrv_gather_child_options =3D quorum_gather_child_options, .bdrv_dirname =3D quorum_dirname, =20 .bdrv_co_flush_to_disk =3D quorum_co_flush, diff --git a/block/vmdk.c b/block/vmdk.c index c1dbcfe133..46f2fc80e5 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2327,6 +2327,18 @@ static int vmdk_get_info(BlockDriverState *bs, Block= DriverInfo *bdi) return 0; } =20 +static void vmdk_gather_child_options(BlockDriverState *bs, QDict *target) +{ + /* No children but file and backing can be explicitly specified */ + QINCREF(bs->file->bs->full_open_options); + qdict_put(target, "file", bs->file->bs->full_open_options); + + if (bs->backing && bs->backing_overridden) { + QINCREF(bs->backing->bs->full_open_options); + qdict_put(target, "backing", bs->backing->bs->full_open_options); + } +} + static QemuOptsList vmdk_create_opts =3D { .name =3D "vmdk-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.head), @@ -2397,6 +2409,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_get_specific_info =3D vmdk_get_specific_info, .bdrv_refresh_limits =3D vmdk_refresh_limits, .bdrv_get_info =3D vmdk_get_info, + .bdrv_gather_child_options =3D vmdk_gather_child_options, =20 .supports_backing =3D true, .create_opts =3D &vmdk_create_opts, --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506705273008874.5572789984233; Fri, 29 Sep 2017 10:14:33 -0700 (PDT) Received: from localhost ([::1]:36284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyrt-0000TR-72 for importer@patchew.org; Fri, 29 Sep 2017 13:14:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaM-0002cZ-75 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyaL-0004Lk-1h for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyaH-0004J9-IQ; Fri, 29 Sep 2017 12:56:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84C8C356D0; Fri, 29 Sep 2017 16:56:16 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 534B99816B; Fri, 29 Sep 2017 16:56:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 84C8C356D0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:42 +0200 Message-Id: <20170929165347.29658-21-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 29 Sep 2017 16:56:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 20/25] block: Generically refresh runtime options X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of having every block driver which implements bdrv_refresh_filename() copy all of the significant runtime options over to bs->full_open_options, implement this process generically in bdrv_refresh_filename(). This patch only adds this new generic implementation, it does not remove the old functionality. This is done in a follow-up patch. With this patch, some superfluous information (that should never have been there) may be removed from some JSON filenames, as can be seen in the change to iotest 110's reference output. Signed-off-by: Max Reitz --- block.c | 116 +++++++++++++++++++++++++++++++++++++++++= +++- tests/qemu-iotests/110.out | 4 +- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index c055bcce5a..55c16ae99c 100644 --- a/block.c +++ b/block.c @@ -4874,6 +4874,92 @@ out: return to_replace_bs; } =20 +/** + * Iterates through the list of runtime option keys that are said to be + * "significant" for a BDS. An option is called "significant" if it change= s a + * BDS's data. For example, the null block driver's "size" and "read-zeroe= s" + * options are significant, but its "latency-ns" option is not. + * + * If a key returned by this function ends with a dot, all options startin= g with + * that prefix are significant. + */ +static const char *const *significant_options(BlockDriverState *bs, + const char *const *curopt) +{ + static const char *const global_options[] =3D { + "driver", "filename", "base-directory", NULL + }; + + if (!curopt) { + return &global_options[0]; + } + + curopt++; + if (curopt =3D=3D &global_options[ARRAY_SIZE(global_options) - 1] && b= s->drv) { + curopt =3D bs->drv->sgfnt_runtime_opts; + } + + return (curopt && *curopt) ? curopt : NULL; +} + +/** + * Copies all significant runtime options from bs->options to the given QD= ict. + * The set of significant option keys is determined by invoking + * significant_options(). + * + * Returns true iff any significant option was present in bs->options (and= thus + * copied to the target QDict) with the exception of "filename" and "drive= r". + * The caller is expected to use this value to decide whether the existenc= e of + * significant options prevents the generation of a plain filename. + */ +static bool append_significant_runtime_options(QDict *d, BlockDriverState = *bs) +{ + bool found_any =3D false; + const char *const *option_name =3D NULL; + + if (!bs->drv) { + return false; + } + + while ((option_name =3D significant_options(bs, option_name))) { + bool option_given =3D false; + + assert(strlen(*option_name) > 0); + if ((*option_name)[strlen(*option_name) - 1] !=3D '.') { + QObject *entry =3D qdict_get(bs->options, *option_name); + if (!entry) { + continue; + } + + qobject_incref(entry); + qdict_put_obj(d, *option_name, entry); + option_given =3D true; + } else { + const QDictEntry *entry; + for (entry =3D qdict_first(bs->options); entry; + entry =3D qdict_next(bs->options, entry)) + { + if (strstart(qdict_entry_key(entry), *option_name, NULL)) { + qobject_incref(qdict_entry_value(entry)); + qdict_put_obj(d, qdict_entry_key(entry), + qdict_entry_value(entry)); + option_given =3D true; + } + } + } + + /* While "driver" and "filename" need to be included in a JSON fil= ename, + * their existence does not prohibit generation of a plain filenam= e. */ + if (!found_any && option_given && + strcmp(*option_name, "driver") && strcmp(*option_name, "filena= me")) + { + found_any =3D true; + } + } + + return found_any; +} + static bool append_open_options(QDict *d, BlockDriverState *bs) { const QDictEntry *entry; @@ -5028,9 +5114,37 @@ void bdrv_refresh_filename(BlockDriverState *bs) bs->full_open_options =3D opts; } =20 + /* Gather the options QDict */ + opts =3D qdict_new(); + append_significant_runtime_options(opts, bs); + + if (drv->bdrv_gather_child_options) { + /* Some block drivers may not want to present all of their childre= n's + * options, or name them differently from BdrvChild.name */ + drv->bdrv_gather_child_options(bs, opts); + } else { + QLIST_FOREACH(child, &bs->children, next) { + if (child->role =3D=3D &child_backing && !bs->backing_overridd= en) { + /* We can skip the backing BDS if it has not been overridd= en */ + continue; + } + + QINCREF(child->bs->full_open_options); + qdict_put(opts, child->name, child->bs->full_open_options); + } + + if (bs->backing_overridden && !bs->backing) { + /* Force no backing file */ + qdict_put(opts, "backing", qstring_new()); + } + } + + QDECREF(bs->full_open_options); + bs->full_open_options =3D opts; + if (bs->exact_filename[0]) { pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename); - } else if (bs->full_open_options) { + } else { QString *json =3D qobject_to_json(QOBJECT(bs->full_open_options)); snprintf(bs->filename, sizeof(bs->filename), "json:%s", qstring_get_str(json)); diff --git a/tests/qemu-iotests/110.out b/tests/qemu-iotests/110.out index e1845d8026..7eb199dd5c 100644 --- a/tests/qemu-iotests/110.out +++ b/tests/qemu-iotests/110.out @@ -22,12 +22,12 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 backing_file=3Dt.IMGFMT.b =20 =3D=3D=3D Nodes without a common directory =3D=3D=3D =20 -image: json:{"driver": "IMGFMT", "file": {"children": [{"driver": "file", = "filename": "TEST_DIR/t.IMGFMT"}, {"driver": "file", "filename": "TEST_DIR/= t.IMGFMT.copy"}], "driver": "quorum", "blkverify": false, "rewrite-corrupte= d": false, "vote-threshold": 1}} +image: json:{"driver": "IMGFMT", "file": {"children": [{"driver": "file", = "filename": "TEST_DIR/t.IMGFMT"}, {"driver": "file", "filename": "TEST_DIR/= t.IMGFMT.copy"}], "driver": "quorum", "vote-threshold": 1}} file format: IMGFMT virtual size: 64M (67108864 bytes) backing file: t.IMGFMT.base (cannot determine actual path) =20 -image: json:{"driver": "IMGFMT", "file": {"children": [{"driver": "file", = "filename": "TEST_DIR/t.IMGFMT"}, {"driver": "file", "filename": "TEST_DIR/= t.IMGFMT.copy"}], "driver": "quorum", "blkverify": false, "rewrite-corrupte= d": false, "vote-threshold": 1}} +image: json:{"driver": "IMGFMT", "file": {"children": [{"driver": "file", = "filename": "TEST_DIR/t.IMGFMT"}, {"driver": "file", "filename": "TEST_DIR/= t.IMGFMT.copy"}], "driver": "quorum", "base-directory": "TEST_DIR/", "vote-= threshold": 1}} file format: IMGFMT virtual size: 64M (67108864 bytes) backing file: t.IMGFMT.base (actual path: TEST_DIR/t.IMGFMT.base) --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506705298070449.8341645845005; Fri, 29 Sep 2017 10:14:58 -0700 (PDT) Received: from localhost ([::1]:36286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxysF-0000oP-Pm for importer@patchew.org; Fri, 29 Sep 2017 13:14:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaW-0002lW-9h for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyaU-0004Qc-65 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60848) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyaN-0004ND-38; Fri, 29 Sep 2017 12:56:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1611C461F9; Fri, 29 Sep 2017 16:56:22 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 111AB6060C; Fri, 29 Sep 2017 16:56:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1611C461F9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:43 +0200 Message-Id: <20170929165347.29658-22-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 29 Sep 2017 16:56:22 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 21/25] block: Purify .bdrv_refresh_filename() X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, BlockDriver.bdrv_refresh_filename() is supposed to both refresh the filename (BDS.exact_filename) and set BDS.full_open_options. Now that we have generic code in the central bdrv_refresh_filename() for creating BDS.full_open_options, we can drop the latter part from all BlockDriver.bdrv_refresh_filename() implementations. This also means that we can drop all of the existing default code for this from the global bdrv_refresh_filename() itself. Furthermore, we now have to call BlockDriver.bdrv_refresh_filename() after having set BDS.full_open_options, because the block driver's implementation should now be allowed to depend on BDS.full_open_options being set correctly. Finally, with this patch we can drop the @options parameter from BlockDriver.bdrv_refresh_filename(); also, add a comment on this function's purpose in block/block_int.h while touching its interface. Signed-off-by: Max Reitz --- include/block/block_int.h | 6 +- block.c | 145 +++++++-----------------------------------= ---- block/blkdebug.c | 52 ++++++----------- block/blkverify.c | 16 +---- block/commit.c | 2 +- block/mirror.c | 2 +- block/nbd.c | 23 +------- block/nfs.c | 36 +----------- block/null.c | 23 +++++--- block/quorum.c | 30 ---------- 10 files changed, 63 insertions(+), 272 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 65e6500313..464af1b101 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -133,7 +133,11 @@ struct BlockDriver { int (*bdrv_create)(const char *filename, QemuOpts *opts, Error **errp); int (*bdrv_make_empty)(BlockDriverState *bs); =20 - void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); + /* + * Refreshes the bs->exact_filename field. If that is impossible, + * bs->exact_filename has to be left empty. + */ + void (*bdrv_refresh_filename)(BlockDriverState *bs); =20 /* * Gathers the open options for all children into @target. A simple fo= rmat diff --git a/block.c b/block.c index 55c16ae99c..415f9c49f0 100644 --- a/block.c +++ b/block.c @@ -4960,47 +4960,6 @@ static bool append_significant_runtime_options(QDict= *d, BlockDriverState *bs) return found_any; } =20 -static bool append_open_options(QDict *d, BlockDriverState *bs) -{ - const QDictEntry *entry; - QemuOptDesc *desc; - BdrvChild *child; - bool found_any =3D false; - const char *p; - - for (entry =3D qdict_first(bs->options); entry; - entry =3D qdict_next(bs->options, entry)) - { - /* Exclude options for children */ - QLIST_FOREACH(child, &bs->children, next) { - if (strstart(qdict_entry_key(entry), child->name, &p) - && (!*p || *p =3D=3D '.')) - { - break; - } - } - if (child) { - continue; - } - - /* And exclude all non-driver-specific options */ - for (desc =3D bdrv_runtime_opts.desc; desc->name; desc++) { - if (!strcmp(qdict_entry_key(entry), desc->name)) { - break; - } - } - if (desc->name) { - continue; - } - - qobject_incref(qdict_entry_value(entry)); - qdict_put_obj(d, qdict_entry_key(entry), qdict_entry_value(entry)); - found_any =3D true; - } - - return found_any; -} - /* Updates the following BDS fields: * - exact_filename: A filename which may be used for opening a block dev= ice * which (mostly) equals the given BDS (even without any @@ -5018,6 +4977,8 @@ void bdrv_refresh_filename(BlockDriverState *bs) BlockDriver *drv =3D bs->drv; BdrvChild *child; QDict *opts; + bool generate_json_filename; /* Whether our default implementation sho= uld + fill exact_filename (false) or not (tr= ue) */ =20 if (!drv) { return; @@ -5033,90 +4994,10 @@ void bdrv_refresh_filename(BlockDriverState *bs) } } =20 - if (drv->bdrv_refresh_filename) { - /* Obsolete information is of no use here, so drop the old file na= me - * information before refreshing it */ - bs->exact_filename[0] =3D '\0'; - if (bs->full_open_options) { - QDECREF(bs->full_open_options); - bs->full_open_options =3D NULL; - } - - opts =3D qdict_new(); - append_open_options(opts, bs); - drv->bdrv_refresh_filename(bs, opts); - QDECREF(opts); - } else if (bs->file) { - /* Try to reconstruct valid information from the underlying file */ - bool has_open_options; - - bs->exact_filename[0] =3D '\0'; - if (bs->full_open_options) { - QDECREF(bs->full_open_options); - bs->full_open_options =3D NULL; - } - - opts =3D qdict_new(); - has_open_options =3D append_open_options(opts, bs); - has_open_options |=3D bs->backing_overridden; - - /* If no specific options have been given for this BDS, the filena= me 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 underlyi= ng - * file BDS. The full options QDict of that file BDS should somehow - * contain a representation of the filename, therefore the followi= ng - * 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_str(opts, "driver", drv->format_name); - QINCREF(bs->file->bs->full_open_options); - qdict_put(opts, "file", bs->file->bs->full_open_options); - - if (bs->backing) { - QINCREF(bs->backing->bs->full_open_options); - qdict_put(opts, "backing", bs->backing->bs->full_open_opti= ons); - } else if (bs->backing_overridden && !bs->backing) { - qdict_put(opts, "backing", qstring_new()); - } - - bs->full_open_options =3D opts; - } else { - QDECREF(opts); - } - } else if (!bs->full_open_options && qdict_size(bs->options)) { - /* There is no underlying file BDS (at least referenced by BDS.fil= e), - * so the full options QDict should be equal to the options given - * specifically for this block device when it was opened (plus the - * driver specification). - * Because those options don't change, there is no need to update - * full_open_options when it's already set. */ - - opts =3D qdict_new(); - append_open_options(opts, bs); - qdict_put_str(opts, "driver", drv->format_name); - - if (bs->exact_filename[0]) { - /* This may not work for all block protocol drivers (some may - * require this filename to be parsed), but we have to find so= me - * default solution here, so just include it. If some block dr= iver - * does not support pure options without any filename at all or - * needs some special format of the options QDict, it needs to - * implement the driver-specific bdrv_refresh_filename() funct= ion. - */ - qdict_put_str(opts, "filename", bs->exact_filename); - } - - bs->full_open_options =3D opts; - } - /* Gather the options QDict */ opts =3D qdict_new(); - append_significant_runtime_options(opts, bs); + generate_json_filename =3D append_significant_runtime_options(opts, bs= ); + generate_json_filename |=3D bs->backing_overridden; =20 if (drv->bdrv_gather_child_options) { /* Some block drivers may not want to present all of their childre= n's @@ -5142,6 +5023,24 @@ void bdrv_refresh_filename(BlockDriverState *bs) QDECREF(bs->full_open_options); bs->full_open_options =3D opts; =20 + if (drv->bdrv_refresh_filename) { + /* Obsolete information is of no use here, so drop the old file na= me + * information before refreshing it */ + bs->exact_filename[0] =3D '\0'; + + drv->bdrv_refresh_filename(bs); + } else if (bs->file) { + /* Try to reconstruct valid information from the underlying file */ + + bs->exact_filename[0] =3D '\0'; + + /* If no specific options have been given for this BDS, the filena= me of + * the underlying file should suffice for this one as well */ + if (bs->file->bs->exact_filename[0] && !generate_json_filename) { + strcpy(bs->exact_filename, bs->file->bs->exact_filename); + } + } + if (bs->exact_filename[0]) { pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename); } else { diff --git a/block/blkdebug.c b/block/blkdebug.c index 976dc43f17..e0d108f1a7 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -798,52 +798,34 @@ static int64_t blkdebug_getlength(BlockDriverState *b= s) return bdrv_getlength(bs->file->bs); } =20 -static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) +static void blkdebug_refresh_filename(BlockDriverState *bs) { BDRVBlkdebugState *s =3D bs->opaque; - QDict *opts; const QDictEntry *e; - bool force_json =3D false; - - for (e =3D qdict_first(options); e; e =3D qdict_next(options, e)) { - if (strcmp(qdict_entry_key(e), "config") && - strcmp(qdict_entry_key(e), "x-image")) - { - force_json =3D true; - break; - } - } + int ret; =20 - if (force_json && !bs->file->bs->full_open_options) { - /* The config file cannot be recreated, so creating a plain filena= me - * is impossible */ + if (!bs->file->bs->exact_filename[0]) { return; } =20 - if (!force_json && bs->file->bs->exact_filename[0]) { - int ret =3D snprintf(bs->exact_filename, sizeof(bs->exact_filename= ), - "blkdebug:%s:%s", s->config_file ?: "", - bs->file->bs->exact_filename); - if (ret >=3D sizeof(bs->exact_filename)) { - /* An overflow makes the filename unusable, so do not report a= ny */ - bs->exact_filename[0] =3D 0; + for (e =3D qdict_first(bs->full_open_options); e; + e =3D qdict_next(bs->full_open_options, e)) + { + if (strcmp(qdict_entry_key(e), "config") && + strcmp(qdict_entry_key(e), "image") && + strcmp(qdict_entry_key(e), "driver")) + { + return; } } =20 - opts =3D qdict_new(); - qdict_put_str(opts, "driver", "blkdebug"); - - QINCREF(bs->file->bs->full_open_options); - qdict_put(opts, "image", bs->file->bs->full_open_options); - - for (e =3D qdict_first(options); e; e =3D qdict_next(options, e)) { - if (strcmp(qdict_entry_key(e), "x-image")) { - qobject_incref(qdict_entry_value(e)); - qdict_put_obj(opts, qdict_entry_key(e), qdict_entry_value(e)); - } + ret =3D snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "blkdebug:%s:%s", + s->config_file ?: "", bs->file->bs->exact_filename); + if (ret >=3D sizeof(bs->exact_filename)) { + /* An overflow makes the filename unusable, so do not report any */ + bs->exact_filename[0] =3D 0; } - - bs->full_open_options =3D opts; } =20 static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp) diff --git a/block/blkverify.c b/block/blkverify.c index d5233eeaf9..7da2e08a06 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -277,24 +277,10 @@ static bool blkverify_recurse_is_first_non_filter(Blo= ckDriverState *bs, return bdrv_recurse_is_first_non_filter(s->test_file->bs, candidate); } =20 -static void blkverify_refresh_filename(BlockDriverState *bs, QDict *option= s) +static void blkverify_refresh_filename(BlockDriverState *bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 - if (bs->file->bs->full_open_options - && s->test_file->bs->full_open_options) - { - QDict *opts =3D qdict_new(); - qdict_put_str(opts, "driver", "blkverify"); - - QINCREF(bs->file->bs->full_open_options); - qdict_put(opts, "raw", bs->file->bs->full_open_options); - QINCREF(s->test_file->bs->full_open_options); - qdict_put(opts, "test", s->test_file->bs->full_open_options); - - bs->full_open_options =3D opts; - } - if (bs->file->bs->exact_filename[0] && s->test_file->bs->exact_filename[0]) { diff --git a/block/commit.c b/block/commit.c index 1df8db5428..e2c617e79d 100644 --- a/block/commit.c +++ b/block/commit.c @@ -244,7 +244,7 @@ static int coroutine_fn bdrv_commit_top_preadv(BlockDri= verState *bs, return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } =20 -static void bdrv_commit_top_refresh_filename(BlockDriverState *bs, QDict *= opts) +static void bdrv_commit_top_refresh_filename(BlockDriverState *bs) { pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), bs->backing->bs->filename); diff --git a/block/mirror.c b/block/mirror.c index cac7490e04..5b4688acdd 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1075,7 +1075,7 @@ static int coroutine_fn bdrv_mirror_top_pdiscard(Bloc= kDriverState *bs, return bdrv_co_pdiscard(bs->backing->bs, offset, bytes); } =20 -static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs, QDict *= opts) +static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs) { if (bs->backing =3D=3D NULL) { /* we can be here after failed bdrv_attach_child in diff --git a/block/nbd.c b/block/nbd.c index 0a36394b73..9ce9fad7ea 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -514,12 +514,9 @@ static void nbd_attach_aio_context(BlockDriverState *b= s, nbd_client_attach_aio_context(bs, new_context); } =20 -static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) +static void nbd_refresh_filename(BlockDriverState *bs) { BDRVNBDState *s =3D bs->opaque; - QDict *opts =3D qdict_new(); - QObject *saddr_qdict; - Visitor *ov; const char *host =3D NULL, *port =3D NULL, *path =3D NULL; =20 if (s->saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET) { @@ -532,8 +529,6 @@ static void nbd_refresh_filename(BlockDriverState *bs, = QDict *options) path =3D s->saddr->u.q_unix.path; } /* else can't represent as pseudo-filename */ =20 - qdict_put_str(opts, "driver", "nbd"); - if (path && s->export) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nbd+unix:///%s?socket=3D%s", s->export, path); @@ -547,22 +542,6 @@ static void nbd_refresh_filename(BlockDriverState *bs,= QDict *options) snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nbd://%s:%s", host, port); } - - ov =3D qobject_output_visitor_new(&saddr_qdict); - visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort); - visit_complete(ov, &saddr_qdict); - visit_free(ov); - qdict_put_obj(opts, "server", saddr_qdict); - - if (s->export) { - qdict_put_str(opts, "export", s->export); - } - if (s->tlscredsid) { - qdict_put_str(opts, "tls-creds", s->tlscredsid); - } - - qdict_flatten(opts); - bs->full_open_options =3D opts; } =20 static char *nbd_dirname(BlockDriverState *bs, Error **errp) diff --git a/block/nfs.c b/block/nfs.c index e8cff25fd3..83b62519f2 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -819,14 +819,9 @@ static int nfs_reopen_prepare(BDRVReopenState *state, return 0; } =20 -static void nfs_refresh_filename(BlockDriverState *bs, QDict *options) +static void nfs_refresh_filename(BlockDriverState *bs) { NFSClient *client =3D bs->opaque; - QDict *opts =3D qdict_new(); - QObject *server_qdict; - Visitor *ov; - - qdict_put_str(opts, "driver", "nfs"); =20 if (client->uid && !client->gid) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), @@ -844,35 +839,6 @@ static void nfs_refresh_filename(BlockDriverState *bs,= QDict *options) snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nfs://%s%s", client->server->host, client->path); } - - ov =3D qobject_output_visitor_new(&server_qdict); - visit_type_NFSServer(ov, NULL, &client->server, &error_abort); - visit_complete(ov, &server_qdict); - qdict_put_obj(opts, "server", server_qdict); - qdict_put_str(opts, "path", client->path); - - if (client->uid) { - qdict_put_int(opts, "user", client->uid); - } - if (client->gid) { - qdict_put_int(opts, "group", client->gid); - } - if (client->tcp_syncnt) { - qdict_put_int(opts, "tcp-syn-cnt", client->tcp_syncnt); - } - if (client->readahead) { - qdict_put_int(opts, "readahead-size", client->readahead); - } - if (client->pagecache) { - qdict_put_int(opts, "page-cache-size", client->pagecache); - } - if (client->debug) { - qdict_put_int(opts, "debug", client->debug); - } - - visit_free(ov); - qdict_flatten(opts); - bs->full_open_options =3D opts; } =20 static char *nfs_dirname(BlockDriverState *bs, Error **errp) diff --git a/block/null.c b/block/null.c index 59673d2449..65f5d681c0 100644 --- a/block/null.c +++ b/block/null.c @@ -241,18 +241,23 @@ static int64_t coroutine_fn null_co_get_block_status(= BlockDriverState *bs, } } =20 -static void null_refresh_filename(BlockDriverState *bs, QDict *opts) +static void null_refresh_filename(BlockDriverState *bs) { - QINCREF(opts); - qdict_del(opts, "filename"); - - if (!qdict_size(opts)) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", - bs->drv->format_name); + const QDictEntry *e; + + for (e =3D qdict_first(bs->full_open_options); e; + e =3D qdict_next(bs->full_open_options, e)) + { + /* These options can be ignored */ + if (strcmp(qdict_entry_key(e), "filename") && + strcmp(qdict_entry_key(e), "driver")) + { + return; + } } =20 - qdict_put_str(opts, "driver", bs->drv->format_name); - bs->full_open_options =3D opts; + snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", + bs->drv->format_name); } =20 static const char *const null_sgfnt_runtime_opts[] =3D { diff --git a/block/quorum.c b/block/quorum.c index 2daf8635f3..1b364188cc 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1066,35 +1066,6 @@ static void quorum_del_child(BlockDriverState *bs, B= drvChild *child, bdrv_drained_end(bs); } =20 -static void quorum_refresh_filename(BlockDriverState *bs, QDict *options) -{ - BDRVQuorumState *s =3D bs->opaque; - QDict *opts; - QList *children; - int i; - - for (i =3D 0; i < s->num_children; i++) { - if (!s->children[i]->bs->full_open_options) { - return; - } - } - - children =3D qlist_new(); - for (i =3D 0; i < s->num_children; i++) { - QINCREF(s->children[i]->bs->full_open_options); - qlist_append(children, s->children[i]->bs->full_open_options); - } - - opts =3D qdict_new(); - qdict_put_str(opts, "driver", "quorum"); - qdict_put_int(opts, QUORUM_OPT_VOTE_THRESHOLD, s->threshold); - qdict_put_bool(opts, QUORUM_OPT_BLKVERIFY, s->is_blkverify); - qdict_put_bool(opts, QUORUM_OPT_REWRITE, s->rewrite_corrupted); - qdict_put(opts, "children", children); - - bs->full_open_options =3D opts; -} - static void quorum_gather_child_options(BlockDriverState *bs, QDict *targe= t) { BDRVQuorumState *s =3D bs->opaque; @@ -1142,7 +1113,6 @@ static BlockDriver bdrv_quorum =3D { =20 .bdrv_file_open =3D quorum_open, .bdrv_close =3D quorum_close, - .bdrv_refresh_filename =3D quorum_refresh_filename, .bdrv_gather_child_options =3D quorum_gather_child_options, .bdrv_dirname =3D quorum_dirname, =20 --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704877005758.087471415939; Fri, 29 Sep 2017 10:07:57 -0700 (PDT) Received: from localhost ([::1]:36245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxylO-0003VY-8l for importer@patchew.org; Fri, 29 Sep 2017 13:07:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaV-0002lA-TV for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyaV-0004RF-34 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyaQ-0004Od-Cy; Fri, 29 Sep 2017 12:56:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 537FC7F3E2; Fri, 29 Sep 2017 16:56:25 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16C4017C5C; Fri, 29 Sep 2017 16:56:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 537FC7F3E2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:44 +0200 Message-Id: <20170929165347.29658-23-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 29 Sep 2017 16:56:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 22/25] block: Do not copy exact_filename from format file X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the a format BDS's file BDS is in turn a format BDS, we cannot simply use the same filename, because when opening a BDS tree based on a filename alone, qemu will create only one format node on top of one protocol node (disregarding a potential backing file). Signed-off-by: Max Reitz --- block.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 415f9c49f0..cfcbd3a09f 100644 --- a/block.c +++ b/block.c @@ -5034,9 +5034,20 @@ void bdrv_refresh_filename(BlockDriverState *bs) =20 bs->exact_filename[0] =3D '\0'; =20 - /* If no specific options have been given for this BDS, the filena= me of - * the underlying file should suffice for this one as well */ - if (bs->file->bs->exact_filename[0] && !generate_json_filename) { + /* We can use the underlying file's filename if: + * - it has a filename, + * - the file is a protocol BDS, and + * - opening that file (as this BDS's format) will automatically c= reate + * the BDS tree we have right now, that is: + * - the user did not significantly change this BDS's behavior w= ith + * some explicit options + * - no non-file child of this BDS has been overridden by the us= er + * Both of these conditions are represented by generate_json_fil= ename. + */ + if (bs->file->bs->exact_filename[0] && + bs->file->bs->drv->bdrv_file_open && + !generate_json_filename) + { strcpy(bs->exact_filename, bs->file->bs->exact_filename); } } --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704581979407.40971050570704; Fri, 29 Sep 2017 10:03:01 -0700 (PDT) Received: from localhost ([::1]:36217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxygY-0007pG-5U for importer@patchew.org; Fri, 29 Sep 2017 13:02:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaY-0002me-IY for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyaX-0004SG-Ce for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33034) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyaU-0004QN-CQ; Fri, 29 Sep 2017 12:56:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57AE7806C2; Fri, 29 Sep 2017 16:56:29 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A45E886E77; Fri, 29 Sep 2017 16:56:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57AE7806C2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:45 +0200 Message-Id: <20170929165347.29658-24-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Sep 2017 16:56:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 23/25] block: Fix FIXME from "Add BDS.backing_overridden" X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Said commit introduced a FIXME stating that bdrv_open_backing_file() should set bs->backing_overridden to true not only if the file.filename option was set, but if the "options" QDict contained any option that is significant for any node in the BDS tree emerging from the backing BDS. This behavior is implemented by this patch. Signed-off-by: Max Reitz --- block.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index cfcbd3a09f..83da207268 100644 --- a/block.c +++ b/block.c @@ -73,6 +73,9 @@ static BlockDriverState *bdrv_open_inherit(const char *fi= lename, const BdrvChildRole *child_role, Error **errp); =20 +static bool has_significant_runtime_options(BlockDriverState *bs, + const QDict *d); + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; =20 @@ -2185,6 +2188,42 @@ out: bdrv_refresh_limits(bs, NULL); } =20 +/** + * Checks whether @options contains any significant option for any of the = nodes + * in the BDS tree emerging from @bs. + */ +static bool is_significant_option_tree(BlockDriverState *bs, QDict *option= s) +{ + BdrvChild *child; + + if (!qdict_size(options)) { + /* No need to recurse */ + return false; + } + + if (has_significant_runtime_options(bs, options)) { + return true; + } + + QLIST_FOREACH(child, &bs->children, next) { + QDict *child_options; + char *option_prefix; + + option_prefix =3D g_strdup_printf("%s.", child->name); + qdict_extract_subqdict(options, &child_options, option_prefix); + g_free(option_prefix); + + if (is_significant_option_tree(child->bs, child_options)) { + QDECREF(child_options); + return true; + } + + QDECREF(child_options); + } + + return false; +} + /* * Opens the backing file for a BlockDriverState if not yet open * @@ -2203,7 +2242,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, const char *reference =3D NULL; int ret =3D 0; BlockDriverState *backing_hd; - QDict *options; + QDict *options, *cloned_options =3D NULL; QDict *tmp_parent_options =3D NULL; Error *local_err =3D NULL; =20 @@ -2233,11 +2272,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, reference =3D qdict_get_try_str(parent_options, bdref_key); if (reference || qdict_haskey(options, "file.filename")) { /* keep backing_filename NULL */ - - /* FIXME: Should also be set to true if @options contains other ru= ntime - * options which control the data that is read from the bac= king - * BDS */ - bs->backing_overridden =3D true; } else if (bs->backing_file[0] =3D=3D '\0' && qdict_size(options) =3D= =3D 0) { QDECREF(options); goto free_exit; @@ -2258,6 +2292,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, goto free_exit; } =20 + cloned_options =3D qdict_clone_shallow(options); + if (bs->backing_format[0] !=3D '\0' && !qdict_haskey(options, "driver"= )) { qdict_put_str(options, "driver", bs->backing_format); } @@ -2272,6 +2308,10 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, } bdrv_set_aio_context(backing_hd, bdrv_get_aio_context(bs)); =20 + if (reference || is_significant_option_tree(backing_hd, cloned_options= )) { + bs->backing_overridden =3D true; + } + /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ bdrv_set_backing_hd(bs, backing_hd, &local_err); @@ -2287,6 +2327,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, free_exit: g_free(backing_filename); QDECREF(tmp_parent_options); + QDECREF(cloned_options); return ret; } =20 @@ -4903,6 +4944,34 @@ static const char *const *significant_options(BlockD= riverState *bs, } =20 /** + * Returns true if @d contains any options the block driver of @bs conside= rs to + * be significant runtime options. + */ +static bool has_significant_runtime_options(BlockDriverState *bs, + const QDict *d) +{ + const char *const *option_name =3D NULL; + + while ((option_name =3D significant_options(bs, option_name))) { + assert(strlen(*option_name) > 0); + if ((*option_name)[strlen(*option_name) - 1] !=3D '.') { + if (qdict_haskey(d, *option_name)) { + return true; + } + } else { + const QDictEntry *entry; + for (entry =3D qdict_first(d); entry; entry =3D qdict_next(d, = entry)) { + if (strstart(qdict_entry_key(entry), *option_name, NULL)) { + return true; + } + } + } + } + + return false; +} + +/** * Copies all significant runtime options from bs->options to the given QD= ict. * The set of significant option keys is determined by invoking * significant_options(). --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506704766006809.7799608895651; Fri, 29 Sep 2017 10:06:06 -0700 (PDT) Received: from localhost ([::1]:36236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyjP-0001kl-7N for importer@patchew.org; Fri, 29 Sep 2017 13:05:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyae-0002sd-Iy for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyad-0004VR-R6 for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyaY-0004SV-Jz; Fri, 29 Sep 2017 12:56:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8832DC04AC58; Fri, 29 Sep 2017 16:56:33 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8AF7B7F464; Fri, 29 Sep 2017 16:56:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8832DC04AC58 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:46 +0200 Message-Id: <20170929165347.29658-25-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 29 Sep 2017 16:56:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 24/25] block/curl: Implement bdrv_refresh_filename() X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- block/curl.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/curl.c b/block/curl.c index 11318a9a29..fe57223fda 100644 --- a/block/curl.c +++ b/block/curl.c @@ -957,6 +957,20 @@ static int64_t curl_getlength(BlockDriverState *bs) return s->len; } =20 +static void curl_refresh_filename(BlockDriverState *bs) +{ + BDRVCURLState *s =3D bs->opaque; + + if (!s->sslverify || s->cookie || + s->username || s->password || s->proxyusername || s->proxypassword) + { + return; + } + + pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), s->url); +} + + static const char *const curl_sgfnt_runtime_opts[] =3D { CURL_BLOCK_OPT_URL, CURL_BLOCK_OPT_SSLVERIFY, @@ -985,6 +999,7 @@ static BlockDriver bdrv_http =3D { .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, =20 + .bdrv_refresh_filename =3D curl_refresh_filename, .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 @@ -1003,6 +1018,7 @@ static BlockDriver bdrv_https =3D { .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, =20 + .bdrv_refresh_filename =3D curl_refresh_filename, .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 @@ -1021,6 +1037,7 @@ static BlockDriver bdrv_ftp =3D { .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, =20 + .bdrv_refresh_filename =3D curl_refresh_filename, .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 @@ -1039,6 +1056,7 @@ static BlockDriver bdrv_ftps =3D { .bdrv_detach_aio_context =3D curl_detach_aio_context, .bdrv_attach_aio_context =3D curl_attach_aio_context, =20 + .bdrv_refresh_filename =3D curl_refresh_filename, .sgfnt_runtime_opts =3D curl_sgfnt_runtime_opts, }; =20 --=20 2.13.6 From nobody Thu May 2 11:58:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506705388454405.5579219802489; Fri, 29 Sep 2017 10:16:28 -0700 (PDT) Received: from localhost ([::1]:36301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxytl-0001xa-Sg for importer@patchew.org; Fri, 29 Sep 2017 13:16:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxyaf-0002tb-Ef for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxyae-0004Vv-Qz for qemu-devel@nongnu.org; Fri, 29 Sep 2017 12:56:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5405) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxyac-0004UT-LC; Fri, 29 Sep 2017 12:56:38 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FF5F80B56; Fri, 29 Sep 2017 16:56:37 +0000 (UTC) Received: from localhost (ovpn-204-59.brq.redhat.com [10.40.204.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B726B84CF6; Fri, 29 Sep 2017 16:56:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6FF5F80B56 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 29 Sep 2017 18:53:47 +0200 Message-Id: <20170929165347.29658-26-mreitz@redhat.com> In-Reply-To: <20170929165347.29658-1-mreitz@redhat.com> References: <20170929165347.29658-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 29 Sep 2017 16:56:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 25/25] block/null: Generate filename even with latency-ns X-BeenThere: qemu-devel@gnu.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 , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" While we cannot represent the latency-ns option in a filename, it is not a significant option so not being able to should not stop us from generating a filename nonetheless. Signed-off-by: Max Reitz --- block/null.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/null.c b/block/null.c index 65f5d681c0..ca0aa3d528 100644 --- a/block/null.c +++ b/block/null.c @@ -250,7 +250,8 @@ static void null_refresh_filename(BlockDriverState *bs) { /* These options can be ignored */ if (strcmp(qdict_entry_key(e), "filename") && - strcmp(qdict_entry_key(e), "driver")) + strcmp(qdict_entry_key(e), "driver") && + strcmp(qdict_entry_key(e), NULL_OPT_LATENCY)) { return; } --=20 2.13.6