From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.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@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049571575661.7734716565585; Fri, 1 Feb 2019 11:32:51 -0800 (PST) Received: from localhost ([127.0.0.1]:60477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeYJ-0007QR-PA for importer@patchew.org; Fri, 01 Feb 2019 14:32:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVr-0005ld-6C for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVm-0002Oy-U2 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVc-00025V-6E; Fri, 01 Feb 2019 14:29:54 -0500 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 C10C288E5A; Fri, 1 Feb 2019 19:29:40 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5B1D60C55; Fri, 1 Feb 2019 19:29:39 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:05 +0100 Message-Id: <20190201192935.18394-2-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:29:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 01/31] block: Use bdrv_refresh_filename() to pull X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Before this patch, bdrv_refresh_filename() is used in a pushing manner: Whenever the BDS graph is modified, the parents of the modified edges are supposed to be updated (recursively upwards). However, that is nonviable, considering that we want child changes not to concern parents. Also, in the long run we want a pull model anyway: Here, we would have a bdrv_filename() function which returns a BDS's filename, freshly constructed. This patch is an intermediate step. It adds bdrv_refresh_filename() calls before every place a BDS.filename value is used. The only exceptions are protocol drivers that use their own filename, which clearly would not profit from refreshing that filename before. Also, bdrv_get_encrypted_filename() is removed along the way (as a user of BDS.filename), since it is completely unused. In turn, all of the calls to bdrv_refresh_filename() before this patch are removed, because we no longer have to call this function on graph changes. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- include/block/block.h | 1 - block.c | 31 +++++++++++++++---------------- block/qapi.c | 4 ++++ block/raw-format.c | 1 + block/replication.c | 2 -- block/vhdx-log.c | 1 + block/vmdk.c | 6 ++++++ blockdev.c | 8 ++++++++ qemu-img.c | 11 +++++++++-- 9 files changed, 44 insertions(+), 21 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 57233cf2c0..2eecff73fe 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -484,7 +484,6 @@ void bdrv_round_to_clusters(BlockDriverState *bs, int64_t *cluster_offset, int64_t *cluster_bytes); =20 -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, diff --git a/block.c b/block.c index b67d9b7b65..e93334d9fc 100644 --- a/block.c +++ b/block.c @@ -323,8 +323,11 @@ void bdrv_get_full_backing_filename_from_filename(cons= t char *backed, 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 *backed; =20 + bdrv_refresh_filename(bs); + + backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->filename; bdrv_get_full_backing_filename_from_filename(backed, bs->backing_file, dest, sz, errp); } @@ -1004,6 +1007,8 @@ static void bdrv_backing_attach(BdrvChild *c) "node is used as backing hd of '%s'", bdrv_get_device_or_node_name(parent)); =20 + bdrv_refresh_filename(backing_hd); + parent->open_flags &=3D ~BDRV_O_NO_BACKING; pstrcpy(parent->backing_file, sizeof(parent->backing_file), backing_hd->filename); @@ -1413,6 +1418,7 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, } =20 if (file !=3D NULL) { + bdrv_refresh_filename(blk_bs(file)); filename =3D blk_bs(file)->filename; } else { /* @@ -2309,8 +2315,6 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd, bdrv_unref(backing_hd); } =20 - bdrv_refresh_filename(bs); - out: bdrv_refresh_limits(bs, NULL); } @@ -2839,8 +2843,6 @@ static BlockDriverState *bdrv_open_inherit(const char= *filename, g_free(child_key_dot); } =20 - bdrv_refresh_filename(bs); - /* Check if any unknown options were used */ if (qdict_size(options) !=3D 0) { const QDictEntry *entry =3D qdict_first(options); @@ -3285,6 +3287,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, if (local_err !=3D NULL) { error_propagate(errp, local_err); } else { + bdrv_refresh_filename(reopen_state->bs); error_setg(errp, "failed while preparing to reopen image '= %s'", reopen_state->bs->filename); } @@ -3881,7 +3884,10 @@ int bdrv_drop_intermediate(BlockDriverState *top, Bl= ockDriverState *base, /* success - we can delete the intermediate states, and link top->base= */ /* TODO Check graph modification op blockers (BLK_PERM_GRAPH_MOD) once * we've figured out how they should work. */ - backing_file_str =3D backing_file_str ? backing_file_str : base->filen= ame; + if (!backing_file_str) { + bdrv_refresh_filename(base); + backing_file_str =3D base->filename; + } =20 QLIST_FOREACH_SAFE(c, &top->parents, next_parent, next) { /* Check whether we are allowed to switch c from top to base */ @@ -4429,16 +4435,6 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverSta= te *bs) return bs->supported_zero_flags & BDRV_REQ_MAY_UNMAP; } =20 -const char *bdrv_get_encrypted_filename(BlockDriverState *bs) -{ - if (bs->backing && bs->backing->bs->encrypted) - return bs->backing_file; - else if (bs->encrypted) - return bs->filename; - else - return NULL; -} - void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size) { @@ -4558,6 +4554,9 @@ BlockDriverState *bdrv_find_backing_image(BlockDriver= State *bs, =20 is_protocol =3D path_has_protocol(backing_file); =20 + /* This will recursively refresh everything in the backing chain */ + bdrv_refresh_filename(bs); + for (curr_bs =3D bs; curr_bs->backing; curr_bs =3D curr_bs->backing->b= s) { =20 /* If either of the filename paths is actually a protocol, then diff --git a/block/qapi.c b/block/qapi.c index c66f949db8..743136b84e 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -51,6 +51,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, return NULL; } =20 + bdrv_refresh_filename(bs); + info =3D g_malloc0(sizeof(*info)); info->file =3D g_strdup(bs->filename); info->ro =3D bs->read_only; @@ -264,6 +266,8 @@ void bdrv_query_image_info(BlockDriverState *bs, goto out; } =20 + bdrv_refresh_filename(bs); + info =3D g_new0(ImageInfo, 1); info->filename =3D g_strdup(bs->filename); info->format =3D g_strdup(bdrv_get_format_name(bs)); diff --git a/block/raw-format.c b/block/raw-format.c index 6f6dc99b2c..d07bcdae62 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -436,6 +436,7 @@ static int raw_open(BlockDriverState *bs, QDict *option= s, int flags, bs->file->bs->supported_zero_flags); =20 if (bs->probed && !bdrv_is_read_only(bs)) { + bdrv_refresh_filename(bs->file->bs); fprintf(stderr, "WARNING: Image format was not specified for '%s' and prob= ing " "guessed raw.\n" diff --git a/block/replication.c b/block/replication.c index e70dd95001..9b332002ee 100644 --- a/block/replication.c +++ b/block/replication.c @@ -616,8 +616,6 @@ static void replication_done(void *opaque, int ret) if (ret =3D=3D 0) { s->stage =3D BLOCK_REPLICATION_DONE; =20 - /* refresh top bs's filename */ - bdrv_refresh_filename(bs); s->active_disk =3D NULL; s->secondary_disk =3D NULL; s->hidden_disk =3D NULL; diff --git a/block/vhdx-log.c b/block/vhdx-log.c index ecd64266c5..3149ff08d8 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -803,6 +803,7 @@ int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState = *s, bool *flushed, =20 if (logs.valid) { if (bs->read_only) { + bdrv_refresh_filename(bs); ret =3D -EPERM; error_setg(errp, "VHDX image file '%s' opened read-only, but " diff --git a/block/vmdk.c b/block/vmdk.c index 682ad93aa1..db8bf996c4 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -479,6 +479,7 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkE= xtent *extent, extent->l1_table, l1_size); if (ret < 0) { + bdrv_refresh_filename(extent->file->bs); error_setg_errno(errp, -ret, "Could not read l1 table from extent '%s'", extent->file->bs->filename); @@ -499,6 +500,7 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkE= xtent *extent, extent->l1_backup_table, l1_size); if (ret < 0) { + bdrv_refresh_filename(extent->file->bs); error_setg_errno(errp, -ret, "Could not read l1 backup table from extent '= %s'", extent->file->bs->filename); @@ -530,6 +532,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, =20 ret =3D bdrv_pread(file, sizeof(magic), &header, sizeof(header)); if (ret < 0) { + bdrv_refresh_filename(file->bs); error_setg_errno(errp, -ret, "Could not read header from file '%s'", file->bs->filename); @@ -607,6 +610,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, =20 ret =3D bdrv_pread(file, sizeof(magic), &header, sizeof(header)); if (ret < 0) { + bdrv_refresh_filename(file->bs); error_setg_errno(errp, -ret, "Could not read header from file '%s'", file->bs->filename); @@ -861,6 +865,7 @@ static int vmdk_parse_extents(const char *desc, BlockDr= iverState *bs, if (!path_is_absolute(fname) && !path_has_protocol(fname) && !desc_file_path[0]) { + bdrv_refresh_filename(bs->file->bs); error_setg(errp, "Cannot use relative extent paths with VMDK " "descriptor file '%s'", bs->file->bs->filename); return -EINVAL; @@ -2470,6 +2475,7 @@ static ImageInfo *vmdk_get_extent_info(VmdkExtent *ex= tent) { ImageInfo *info =3D g_new0(ImageInfo, 1); =20 + bdrv_refresh_filename(extent->file->bs); *info =3D (ImageInfo){ .filename =3D g_strdup(extent->file->bs->filename), .format =3D g_strdup(extent->type), diff --git a/blockdev.c b/blockdev.c index fb18e9c975..3bab7e4f5a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1627,6 +1627,7 @@ static void external_snapshot_prepare(BlkActionState = *common, error_setg_errno(errp, -size, "bdrv_getlength failed"); goto out; } + bdrv_refresh_filename(state->old_bs); bdrv_img_create(new_image_file, format, state->old_bs->filename, state->old_bs->drv->format_name, @@ -3216,6 +3217,7 @@ void qmp_block_stream(bool has_job_id, const char *jo= b_id, const char *device, goto out; } assert(bdrv_get_aio_context(base_bs) =3D=3D aio_context); + bdrv_refresh_filename(base_bs); base_name =3D base_bs->filename; } =20 @@ -3335,6 +3337,10 @@ void qmp_block_commit(bool has_job_id, const char *j= ob_id, const char *device, goto out; } } else if (has_top && top) { + /* This strcmp() is just a shortcut, there is no need to + * refresh @bs's filename. If it mismatches, + * bdrv_find_backing_image() will do the refresh and may still + * return @bs. */ if (strcmp(bs->filename, top) !=3D 0) { top_bs =3D bdrv_find_backing_image(bs, top); } @@ -3495,6 +3501,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= JobTxn *txn, if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { assert(backup->format); if (source) { + bdrv_refresh_filename(source); bdrv_img_create(backup->target, backup->format, source->filena= me, source->drv->format_name, NULL, size, flags, false, &local_err); @@ -3875,6 +3882,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) break; case NEW_IMAGE_MODE_ABSOLUTE_PATHS: /* create new image with backing file */ + bdrv_refresh_filename(source); bdrv_img_create(arg->target, format, source->filename, source->drv->format_name, diff --git a/qemu-img.c b/qemu-img.c index 25288c4d18..c077ea1c92 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2790,6 +2790,7 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, BlockDriverState *file; bool has_offset; int64_t map; + char *filename =3D NULL; =20 /* As an optimization, we could cache the current range of unallocated * clusters in each file of the chain, and avoid querying the same @@ -2817,6 +2818,11 @@ static int get_block_status(BlockDriverState *bs, in= t64_t offset, =20 has_offset =3D !!(ret & BDRV_BLOCK_OFFSET_VALID); =20 + if (file && has_offset) { + bdrv_refresh_filename(file); + filename =3D file->filename; + } + *e =3D (MapEntry) { .start =3D offset, .length =3D bytes, @@ -2825,8 +2831,8 @@ static int get_block_status(BlockDriverState *bs, int= 64_t offset, .offset =3D map, .has_offset =3D has_offset, .depth =3D depth, - .has_filename =3D file && has_offset, - .filename =3D file && has_offset ? file->filename : NULL, + .has_filename =3D filename, + .filename =3D filename, }; =20 return 0; @@ -3327,6 +3333,7 @@ static int img_rebase(int argc, char **argv) qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true); } =20 + bdrv_refresh_filename(bs); overlay_filename =3D bs->exact_filename[0] ? bs->exact_filename : bs->filename; out_real_path =3D g_malloc(PATH_MAX); --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049762908166.76834829056065; Fri, 1 Feb 2019 11:36:02 -0800 (PST) Received: from localhost ([127.0.0.1]:60545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpebT-0001sO-Mi for importer@patchew.org; Fri, 01 Feb 2019 14:35:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVs-0005mh-0y for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVj-0002Jt-Tn for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVe-000267-DZ; Fri, 01 Feb 2019 14:29:54 -0500 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 14FB42CD7F4; Fri, 1 Feb 2019 19:29:43 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97D035C226; Fri, 1 Feb 2019 19:29:42 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:06 +0100 Message-Id: <20190201192935.18394-3-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:29:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 02/31] block: Use children list in bdrv_refresh_filename X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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, mirror, and blklogwrites. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block.c | 9 +++++---- block/blklogwrites.c | 3 --- block/blkverify.c | 3 --- block/commit.c | 1 - block/mirror.c | 1 - block/quorum.c | 1 - 6 files changed, 5 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index e93334d9fc..0e3d29d378 100644 --- a/block.c +++ b/block.c @@ -5475,16 +5475,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/blklogwrites.c b/block/blklogwrites.c index d2e01bdb1d..36e3d0f822 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -285,9 +285,6 @@ static void blk_log_writes_refresh_filename(BlockDriver= State *bs, { BDRVBlkLogWritesState *s =3D bs->opaque; =20 - /* bs->file->bs has already been refreshed */ - bdrv_refresh_filename(s->log_file->bs); - if (bs->file->bs->full_open_options && s->log_file->bs->full_open_options) { diff --git a/block/blkverify.c b/block/blkverify.c index 89bf4386e3..035d77b64a 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -285,9 +285,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 53148e610b..093b1505de 100644 --- a/block/commit.c +++ b/block/commit.c @@ -232,7 +232,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 b67b0120f8..031c1aeaeb 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1438,7 +1438,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 16b3c8067c..cf9d7c16c2 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1073,7 +1073,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049643882476.8651745139631; Fri, 1 Feb 2019 11:34:03 -0800 (PST) Received: from localhost ([127.0.0.1]:60484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeZZ-00009O-Oo for importer@patchew.org; Fri, 01 Feb 2019 14:33:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVl-0005gm-1o for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVi-0002Hg-Ny for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVe-00027h-Uc; Fri, 01 Feb 2019 14:29:55 -0500 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 68F312CD7F0; Fri, 1 Feb 2019 19:29:45 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ECDA05D6AA; Fri, 1 Feb 2019 19:29:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:07 +0100 Message-Id: <20190201192935.18394-4-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.29]); Fri, 01 Feb 2019 19:29:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 03/31] block: Skip implicit nodes for filename info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_refresh_filename() should simply skip all implicit nodes. They are supposed to be invisible to the user, so they should not appear in filename information. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block.c b/block.c index 0e3d29d378..96fed5d7e6 100644 --- a/block.c +++ b/block.c @@ -5488,6 +5488,20 @@ void bdrv_refresh_filename(BlockDriverState *bs) bdrv_refresh_filename(child->bs); } =20 + if (bs->implicit) { + /* For implicit nodes, just copy everything from the single child = */ + child =3D QLIST_FIRST(&bs->children); + assert(QLIST_NEXT(child, next) =3D=3D NULL); + + pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), + child->bs->exact_filename); + pstrcpy(bs->filename, sizeof(bs->filename), child->bs->filename); + + bs->full_open_options =3D qobject_ref(child->bs->full_open_options= ); + + return; + } + if (drv->bdrv_refresh_filename) { /* Obsolete information is of no use here, so drop the old file na= me * information before refreshing it */ --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049956738856.6542178625884; Fri, 1 Feb 2019 11:39:16 -0800 (PST) Received: from localhost ([127.0.0.1]:60579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeec-0004Jz-LU for importer@patchew.org; Fri, 01 Feb 2019 14:39:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVs-0005nN-Jq for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVo-0002Qr-GY for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43064) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVe-00028c-V7; Fri, 01 Feb 2019 14:29:55 -0500 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 F29FC81F10; Fri, 1 Feb 2019 19:29:47 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5124060C55; Fri, 1 Feb 2019 19:29:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:08 +0100 Message-Id: <20190201192935.18394-5-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:29:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 04/31] block: Add BDS.auto_backing_file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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(). To see whether it has been overridden, we might want to compare bs->backing_file and bs->backing->bs->filename. However, bs->backing_file is changed by bdrv_set_backing_hd() (which is just used to change the backing child at runtime, without modifying the image header), so bs->backing_file most of the time simply contains a copy of bs->backing->bs->filename anyway, so it is useless for such a comparison. This patch adds an auto_backing_file BDS field which contains the backing file path as indicated by the image header, which is not changed by bdrv_set_backing_hd(). Because of bdrv_refresh_filename() magic, however, a BDS's filename may differ from what has been specified during bdrv_open(). Then, the comparison between bs->auto_backing_file and bs->backing->bs->filename may fail even though bs->backing was opened from bs->auto_backing_file. To mitigate this, we can copy the real BDS's filename (after the whole bdrv_open() and bdrv_refresh_filename() process) into bs->auto_backing_file, if we know the former has been opened based on the latter. This is only possible if no options modifying the backing file's behavior have been specified, though. To simplify things, this patch only copies the filename from the backing file if no options have been specified for it at all. Furthermore, there are cases where an overlay is created by qemu which already contains a BDS's filename (e.g. in blockdev-snapshot-sync). We do not need to worry about updating the overlay's bs->auto_backing_file there, because we actually wrote a post-bdrv_refresh_filename() filename into the image header. So all in all, there will be false negatives where (as of a future patch) bdrv_refresh_filename() will assume that the backing file differs from what was specified in the image header, even though it really does not. However, these cases should be limited to where (1) the user actually did override something in the backing chain (e.g. by specifying options for the backing file), or (2) the user executed a QMP command to change some node's backing file (e.g. change-backing-file or block-commit with @backing-file given) where the given filename does not happen to coincide with qemu's idea of the backing BDS's filename. Then again, (1) really is limited to -drive. With -blockdev or blockdev-add, you have to adhere to the schema, so a user cannot give partial "unimportant" options (e.g. by just setting backing.node-name and leaving the rest to the image header). Therefore, trying to fix this would mean trying to fix something for -drive only. To improve on (2), we would need a full infrastructure to "canonicalize" an arbitrary filename (+ options), so it can be compared against another. That seems a bit over the top, considering that filenames nowadays are there mostly for the user's entertainment. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- include/block/block_int.h | 4 ++++ block.c | 19 +++++++++++++++++++ block/qcow.c | 7 +++++-- block/qcow2.c | 10 +++++++--- block/qed.c | 7 +++++-- block/vmdk.c | 6 ++++-- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index f605622216..93cd669a35 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -696,6 +696,10 @@ struct BlockDriverState { char filename[PATH_MAX]; char backing_file[PATH_MAX]; /* if non zero, the image is a diff of this file image */ + /* The backing filename indicated by the image header; if we ever + * open this file, then this is replaced by the resulting BDS's + * filename (i.e. after a bdrv_refresh_filename() run). */ + char auto_backing_file[PATH_MAX]; char backing_format[16]; /* if non-zero and backing_file exists */ =20 QDict *full_open_options; diff --git a/block.c b/block.c index 96fed5d7e6..c2fab44265 100644 --- a/block.c +++ b/block.c @@ -2336,6 +2336,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, char *bdref_key_dot; const char *reference =3D NULL; int ret =3D 0; + bool implicit_backing =3D false; BlockDriverState *backing_hd; QDict *options; QDict *tmp_parent_options =3D NULL; @@ -2371,6 +2372,16 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, qobject_unref(options); goto free_exit; } else { + if (qdict_size(options) =3D=3D 0) { + /* If the user specifies options that do not modify the + * backing file's behavior, we might still consider it the + * implicit backing file. But it's easier this way, and + * just specifying some of the backing BDS's options is + * only possible with -drive anyway (otherwise the QAPI + * schema forces the user to specify everything). */ + implicit_backing =3D !strcmp(bs->auto_backing_file, bs->backin= g_file); + } + bdrv_get_full_backing_filename(bs, backing_filename, PATH_MAX, &local_err); if (local_err) { @@ -2404,6 +2415,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDi= ct *parent_options, } bdrv_set_aio_context(backing_hd, bdrv_get_aio_context(bs)); =20 + if (implicit_backing) { + bdrv_refresh_filename(backing_hd); + pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), + backing_hd->filename); + } + /* 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); @@ -3792,6 +3809,8 @@ int bdrv_change_backing_file(BlockDriverState *bs, if (ret =3D=3D 0) { pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?= : ""); pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fm= t ?: ""); + pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), + backing_file ?: ""); } return ret; } diff --git a/block/qcow.c b/block/qcow.c index 0a235bf393..d47515d3df 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -31,6 +31,7 @@ #include "qemu/module.h" #include "qemu/option.h" #include "qemu/bswap.h" +#include "qemu/cutils.h" #include #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" @@ -295,11 +296,13 @@ static int qcow_open(BlockDriverState *bs, QDict *opt= ions, int flags, goto fail; } ret =3D bdrv_pread(bs->file, header.backing_file_offset, - bs->backing_file, len); + bs->auto_backing_file, len); if (ret < 0) { goto fail; } - bs->backing_file[len] =3D '\0'; + bs->auto_backing_file[len] =3D '\0'; + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->auto_backing_file); } =20 /* Disable migration when qcow images are used */ diff --git a/block/qcow2.c b/block/qcow2.c index 8c91b92865..662737275a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1474,13 +1474,15 @@ static int coroutine_fn qcow2_do_open(BlockDriverSt= ate *bs, QDict *options, goto fail; } ret =3D bdrv_pread(bs->file, header.backing_file_offset, - bs->backing_file, len); + bs->auto_backing_file, len); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read backing file name= "); goto fail; } - bs->backing_file[len] =3D '\0'; - s->image_backing_file =3D g_strdup(bs->backing_file); + bs->auto_backing_file[len] =3D '\0'; + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->auto_backing_file); + s->image_backing_file =3D g_strdup(bs->auto_backing_file); } =20 /* Internal snapshots */ @@ -2518,6 +2520,8 @@ static int qcow2_change_backing_file(BlockDriverState= *bs, return -EINVAL; } =20 + pstrcpy(bs->auto_backing_file, sizeof(bs->auto_backing_file), + backing_file ?: ""); pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_file ?: ""= ); pstrcpy(bs->backing_format, sizeof(bs->backing_format), backing_fmt ?:= ""); =20 diff --git a/block/qed.c b/block/qed.c index 1280870024..81a1bedd41 100644 --- a/block/qed.c +++ b/block/qed.c @@ -454,11 +454,14 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverS= tate *bs, QDict *options, } =20 ret =3D qed_read_string(bs->file, s->header.backing_filename_offse= t, - s->header.backing_filename_size, bs->backing= _file, - sizeof(bs->backing_file)); + s->header.backing_filename_size, + bs->auto_backing_file, + sizeof(bs->auto_backing_file)); if (ret < 0) { return ret; } + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->auto_backing_file); =20 if (s->header.features & QED_F_BACKING_FORMAT_NO_PROBE) { pstrcpy(bs->backing_format, sizeof(bs->backing_format), "raw"); diff --git a/block/vmdk.c b/block/vmdk.c index db8bf996c4..d21f6a9f2c 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -386,12 +386,14 @@ static int vmdk_parent_open(BlockDriverState *bs) ret =3D -EINVAL; goto out; } - if ((end_name - p_name) > sizeof(bs->backing_file) - 1) { + if ((end_name - p_name) > sizeof(bs->auto_backing_file) - 1) { ret =3D -EINVAL; goto out; } =20 - pstrcpy(bs->backing_file, end_name - p_name + 1, p_name); + pstrcpy(bs->auto_backing_file, end_name - p_name + 1, p_name); + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->auto_backing_file); } =20 out: --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049770041336.53157010295; Fri, 1 Feb 2019 11:36:10 -0800 (PST) Received: from localhost ([127.0.0.1]:60547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpebc-0001yX-0H for importer@patchew.org; Fri, 01 Feb 2019 14:36:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVx-0005te-Tf for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVs-0002VK-52 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVc-00029G-2c; Fri, 01 Feb 2019 14:29:54 -0500 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 7FB8885363; Fri, 1 Feb 2019 19:29:50 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4FCC60C55; Fri, 1 Feb 2019 19:29:49 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:09 +0100 Message-Id: <20190201192935.18394-6-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:29:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 05/31] block: Respect backing bs in bdrv_refresh_filename X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 overriding the backing file, and so its output changes with this patch applied. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 38 ++++++++++++++++++++++++++++++++++- tests/qemu-iotests/051.out | 8 ++++---- tests/qemu-iotests/051.pc.out | 8 ++++---- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index c2fab44265..223b9b19cb 100644 --- a/block.c +++ b/block.c @@ -5479,6 +5479,21 @@ static bool append_open_options(QDict *d, BlockDrive= rState *bs) return found_any; } =20 +/* Note: This function may return false positives; it may return true + * even if opening the backing file specified by bs's image header + * would result in exactly bs->backing. */ +static bool bdrv_backing_overridden(BlockDriverState *bs) +{ + if (bs->backing) { + return strcmp(bs->auto_backing_file, + bs->backing->bs->filename); + } else { + /* No backing BDS, so if the image header reports any backing + * file, it must have been suppressed */ + return bs->auto_backing_file[0] !=3D '\0'; + } +} + /* 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 @@ -5496,6 +5511,7 @@ void bdrv_refresh_filename(BlockDriverState *bs) BlockDriver *drv =3D bs->drv; BdrvChild *child; QDict *opts; + bool backing_overridden; =20 if (!drv) { return; @@ -5521,6 +5537,16 @@ void bdrv_refresh_filename(BlockDriverState *bs) return; } =20 + backing_overridden =3D bdrv_backing_overridden(bs); + + if (bs->open_flags & BDRV_O_NO_IO) { + /* Without I/O, the backing file does not change anything. + * Therefore, in such a case (primarily qemu-img), we can + * pretend the backing file has not been overridden even if + * it technically has been. */ + backing_overridden =3D false; + } + if (drv->bdrv_refresh_filename) { /* Obsolete information is of no use here, so drop the old file na= me * information before refreshing it */ @@ -5546,6 +5572,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 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 */ @@ -5557,11 +5584,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); qdict_put(opts, "file", qobject_ref(bs->file->bs->full_open_options)); =20 + if (bs->backing) { + qdict_put(opts, "backing", + qobject_ref(bs->backing->bs->full_open_options)); + } else if (backing_overridden) { + qdict_put_null(opts, "backing"); + } + bs->full_open_options =3D opts; } else { qobject_unref(opts); diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 793af2ab96..b900935fbc 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -82,7 +82,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) @@ -172,7 +172,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) @@ -192,7 +192,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) @@ -212,7 +212,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 ca64edae6a..8c5c735dfd 100644 --- a/tests/qemu-iotests/051.pc.out +++ b/tests/qemu-iotests/051.pc.out @@ -82,7 +82,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) @@ -244,7 +244,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) @@ -264,7 +264,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) @@ -284,7 +284,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.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@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049571310598.9543682442248; Fri, 1 Feb 2019 11:32:51 -0800 (PST) Received: from localhost ([127.0.0.1]:60479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeYK-0007RE-1Z for importer@patchew.org; Fri, 01 Feb 2019 14:32:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVl-0005gl-1V for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVi-0002IL-Tp for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43104) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVe-0002AI-UR; Fri, 01 Feb 2019 14:29:55 -0500 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 D49A1796EA; Fri, 1 Feb 2019 19:29:52 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 680A5608C6; Fri, 1 Feb 2019 19:29:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:10 +0100 Message-Id: <20190201192935.18394-7-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.25]); Fri, 01 Feb 2019 19:29:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 06/31] iotests.py: Add filter_imgfmt() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/iotests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index c323c62d20..8c5dd40f83 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -312,6 +312,16 @@ def filter_img_info(output, filename): lines.append(line) return '\n'.join(lines) =20 +def filter_imgfmt(msg): + return msg.replace(imgfmt, 'IMGFMT') + +def filter_qmp_imgfmt(qmsg): + def _filter(key, value): + if is_str(value): + return filter_imgfmt(value) + return value + return filter_qmp(qmsg, _filter) + def log(msg, filters=3D[], indent=3DNone): '''Logs either a string message or a JSON serializable message (like Q= MP). If indent is provided, JSON serializable messages are pretty-printed.'= '' --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049750167792.8733019738045; Fri, 1 Feb 2019 11:35:50 -0800 (PST) Received: from localhost ([127.0.0.1]:60523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpebK-0001jU-Pc for importer@patchew.org; Fri, 01 Feb 2019 14:35:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVm-0005iu-Vp for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVl-0002La-04 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51498) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVg-0002CY-6w; Fri, 01 Feb 2019 14:29:56 -0500 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 38621C0B2015; Fri, 1 Feb 2019 19:29:55 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC4B05D9D1; Fri, 1 Feb 2019 19:29:54 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:11 +0100 Message-Id: <20190201192935.18394-8-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.31]); Fri, 01 Feb 2019 19:29:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 07/31] iotests.py: Add node_info() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This function queries a node; since we cannot do that right now, it executes query-named-block-nodes and returns the matching node's object. Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- tests/qemu-iotests/iotests.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 8c5dd40f83..719df561a3 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -551,6 +551,13 @@ class VM(qtest.QEMUQtestMachine): else: iotests.log(ev) =20 + def node_info(self, node_name): + nodes =3D self.qmp('query-named-block-nodes') + for x in nodes['return']: + if x['node-name'] =3D=3D node_name: + return x + return None + =20 index_re =3D re.compile(r'([^\[]+)\[([^\]]+)\]') =20 --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049867250836.2695359457922; Fri, 1 Feb 2019 11:37:47 -0800 (PST) Received: from localhost ([127.0.0.1]:60565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gped9-00039w-47 for importer@patchew.org; Fri, 01 Feb 2019 14:37:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeW2-0005zP-Oa for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVv-0002Zr-L3 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43138) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVi-0002Gl-Ru; Fri, 01 Feb 2019 14:29:59 -0500 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 C720A81F10; Fri, 1 Feb 2019 19:29:57 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2440360C55; Fri, 1 Feb 2019 19:29:56 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:12 +0100 Message-Id: <20190201192935.18394-9-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:29:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 08/31] iotests: Add test for backing file overrides X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- tests/qemu-iotests/228 | 242 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/228.out | 84 +++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 327 insertions(+) create mode 100755 tests/qemu-iotests/228 create mode 100644 tests/qemu-iotests/228.out diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 new file mode 100755 index 0000000000..2930f8442c --- /dev/null +++ b/tests/qemu-iotests/228 @@ -0,0 +1,242 @@ +#!/usr/bin/env python +# +# Test for when a backing file is considered overridden (thus, a +# json:{} filename is generated for the overlay) and when it is not +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Max Reitz + +import iotests +from iotests import log, qemu_img, filter_testfiles, filter_imgfmt, \ + filter_qmp_testfiles, filter_qmp_imgfmt + +# Need backing file and change-backing-file support +iotests.verify_image_format(supported_fmts=3D['qcow2', 'qed']) +iotests.verify_platform(['linux']) + + +def log_node_info(node): + log('') + + log('bs->filename: ' + node['image']['filename'], + filters=3D[filter_testfiles, filter_imgfmt]) + log('bs->backing_file: ' + node['backing_file'], + filters=3D[filter_testfiles, filter_imgfmt]) + + if 'backing-image' in node['image']: + log('bs->backing->bs->filename: ' + + node['image']['backing-image']['filename'], + filters=3D[filter_testfiles, filter_imgfmt]) + else: + log('bs->backing: (none)') + + log('') + + +with iotests.FilePath('base.img') as base_img_path, \ + iotests.FilePath('top.img') as top_img_path, \ + iotests.VM() as vm: + + assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + # Choose a funny way to describe the backing filename + assert qemu_img('create', '-f', iotests.imgfmt, '-b', + 'file:' + base_img_path, top_img_path) =3D=3D 0 + + vm.launch() + + log('--- Implicit backing file ---') + log('') + + vm.qmp_log('blockdev-add', + node_name=3D'node0', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': top_img_path + }, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + # Filename should be plain, and the backing filename should not + # contain the "file:" prefix + log_node_info(vm.node_info('node0')) + + vm.qmp_log('blockdev-del', node_name=3D'node0') + + log('') + log('--- change-backing-file ---') + log('') + + vm.qmp_log('blockdev-add', + node_name=3D'node0', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': top_img_path + }, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + # Changing the backing file to a qemu-reported filename should + # result in qemu accepting the corresponding BDS as the implicit + # backing BDS (and thus not generate a json:{} filename). + # So, first, query the backing filename. + + backing_filename =3D \ + vm.node_info('node0')['image']['backing-image']['filename'] + + # Next, change the backing file to something different + + vm.qmp_log('change-backing-file', + image_node_name=3D'node0', + device=3D'node0', + backing_file=3D'null-co://', + filters=3D[filter_qmp_testfiles]) + + # Now, verify that we get a json:{} filename + # (Image header says "null-co://", actual backing file still is + # base_img_path) + + log_node_info(vm.node_info('node0')) + + # Change it back + # (To get header and backing file in sync) + + vm.qmp_log('change-backing-file', + image_node_name=3D'node0', + device=3D'node0', + backing_file=3Dbacking_filename, + filters=3D[filter_qmp_testfiles]) + + # And verify that we get our original results + + log_node_info(vm.node_info('node0')) + + # Finally, try a "file:" prefix. While this is actually what we + # originally had in the image header, qemu will not reopen the + # backing file here, so it cannot verify that this filename + # "resolves" to the actual backing BDS's filename and will thus + # consider both to be different. + # (This may be fixed in the future.) + + vm.qmp_log('change-backing-file', + image_node_name=3D'node0', + device=3D'node0', + backing_file=3D('file:' + backing_filename), + filters=3D[filter_qmp_testfiles]) + + # So now we should get a json:{} filename + + log_node_info(vm.node_info('node0')) + + # Remove and re-attach so we can see that (as in our first try), + # opening the image anew helps qemu resolve the header backing + # filename. + + vm.qmp_log('blockdev-del', node_name=3D'node0') + + vm.qmp_log('blockdev-add', + node_name=3D'node0', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': top_img_path + }, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + log_node_info(vm.node_info('node0')) + + vm.qmp_log('blockdev-del', node_name=3D'node0') + + log('') + log('--- Override backing file ---') + log('') + + # For this test, we need the plain filename in the image header + # (because qemu cannot "canonicalize"/"resolve" the backing + # filename unless the backing file is opened implicitly with the + # overlay) + assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + top_img_path) =3D=3D 0 + + # You can only reliably override backing options by using a node + # reference (or by specifying file.filename, but, well...) + vm.qmp_log('blockdev-add', node_name=3D'null', driver=3D'null-co') + + vm.qmp_log('blockdev-add', + node_name=3D'node0', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': top_img_path + }, + backing=3D'null', + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + # Should get a json:{} filename (and bs->backing_file is + # null-co://, because that field actually has not much to do + # with the header backing filename (except that it is changed by + # change-backing-file)) + + log_node_info(vm.node_info('node0')) + + # Detach the backing file by reopening the whole thing + + vm.qmp_log('blockdev-del', node_name=3D'node0') + vm.qmp_log('blockdev-del', node_name=3D'null') + + vm.qmp_log('blockdev-add', + node_name=3D'node0', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': top_img_path + }, + backing=3DNone, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + # Should get a json:{} filename (because we overrode the backing + # file to not be there) + + log_node_info(vm.node_info('node0')) + + # Open the original backing file + + vm.qmp_log('blockdev-add', + node_name=3D'original-backing', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': base_img_path + }, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + # Attach the original backing file to its overlay + + vm.qmp_log('blockdev-snapshot', + node=3D'original-backing', + overlay=3D'node0') + + # This should give us the original plain result + # FIXME: Currently, the block layer considers the runtime backing + # file to be different from the image header, which is + # wrong. This is fixed by a future patch. + + log_node_info(vm.node_info('node0')) + + vm.qmp_log('blockdev-del', node_name=3D'node0') + vm.qmp_log('blockdev-del', node_name=3D'original-backing') + + vm.shutdown() diff --git a/tests/qemu-iotests/228.out b/tests/qemu-iotests/228.out new file mode 100644 index 0000000000..57fe97d4bc --- /dev/null +++ b/tests/qemu-iotests/228.out @@ -0,0 +1,84 @@ +--- Implicit backing file --- + +{"execute": "blockdev-add", "arguments": {"driver": "IMGFMT", "file": {"dr= iver": "file", "filename": "TEST_DIR/PID-top.img"}, "node-name": "node0"}} +{"return": {}} + +bs->filename: TEST_DIR/PID-top.img +bs->backing_file: TEST_DIR/PID-base.img +bs->backing->bs->filename: TEST_DIR/PID-base.img + +{"execute": "blockdev-del", "arguments": {"node-name": "node0"}} +{"return": {}} + +--- change-backing-file --- + +{"execute": "blockdev-add", "arguments": {"driver": "IMGFMT", "file": {"dr= iver": "file", "filename": "TEST_DIR/PID-top.img"}, "node-name": "node0"}} +{"return": {}} +{"execute": "change-backing-file", "arguments": {"backing-file": "null-co:= //", "device": "node0", "image-node-name": "node0"}} +{"return": {}} + +bs->filename: json:{"backing": {"driver": "IMGFMT", "file": {"driver": "fi= le", "filename": "TEST_DIR/PID-base.img"}}, "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/PID-top.img"}} +bs->backing_file: null-co:// +bs->backing->bs->filename: TEST_DIR/PID-base.img + +{"execute": "change-backing-file", "arguments": {"backing-file": "TEST_DIR= /PID-base.img", "device": "node0", "image-node-name": "node0"}} +{"return": {}} + +bs->filename: TEST_DIR/PID-top.img +bs->backing_file: TEST_DIR/PID-base.img +bs->backing->bs->filename: TEST_DIR/PID-base.img + +{"execute": "change-backing-file", "arguments": {"backing-file": "file:TES= T_DIR/PID-base.img", "device": "node0", "image-node-name": "node0"}} +{"return": {}} + +bs->filename: json:{"backing": {"driver": "IMGFMT", "file": {"driver": "fi= le", "filename": "TEST_DIR/PID-base.img"}}, "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/PID-top.img"}} +bs->backing_file: file:TEST_DIR/PID-base.img +bs->backing->bs->filename: TEST_DIR/PID-base.img + +{"execute": "blockdev-del", "arguments": {"node-name": "node0"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"driver": "IMGFMT", "file": {"dr= iver": "file", "filename": "TEST_DIR/PID-top.img"}, "node-name": "node0"}} +{"return": {}} + +bs->filename: TEST_DIR/PID-top.img +bs->backing_file: TEST_DIR/PID-base.img +bs->backing->bs->filename: TEST_DIR/PID-base.img + +{"execute": "blockdev-del", "arguments": {"node-name": "node0"}} +{"return": {}} + +--- Override backing file --- + +{"execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name"= : "null"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"backing": "null", "driver": "IM= GFMT", "file": {"driver": "file", "filename": "TEST_DIR/PID-top.img"}, "nod= e-name": "node0"}} +{"return": {}} + +bs->filename: json:{"backing": {"driver": "null-co"}, "driver": "IMGFMT", = "file": {"driver": "file", "filename": "TEST_DIR/PID-top.img"}} +bs->backing_file: null-co:// +bs->backing->bs->filename: null-co:// + +{"execute": "blockdev-del", "arguments": {"node-name": "node0"}} +{"return": {}} +{"execute": "blockdev-del", "arguments": {"node-name": "null"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"backing": null, "driver": "IMGF= MT", "file": {"driver": "file", "filename": "TEST_DIR/PID-top.img"}, "node-= name": "node0"}} +{"return": {}} + +bs->filename: json:{"backing": null, "driver": "IMGFMT", "file": {"driver"= : "file", "filename": "TEST_DIR/PID-top.img"}} +bs->backing_file: TEST_DIR/PID-base.img +bs->backing: (none) + +{"execute": "blockdev-add", "arguments": {"driver": "IMGFMT", "file": {"dr= iver": "file", "filename": "TEST_DIR/PID-base.img"}, "node-name": "original= -backing"}} +{"return": {}} +{"execute": "blockdev-snapshot", "arguments": {"node": "original-backing",= "overlay": "node0"}} +{"return": {}} + +bs->filename: json:{"backing": {"driver": "IMGFMT", "file": {"driver": "fi= le", "filename": "TEST_DIR/PID-base.img"}}, "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/PID-top.img"}} +bs->backing_file: TEST_DIR/PID-base.img +bs->backing->bs->filename: TEST_DIR/PID-base.img + +{"execute": "blockdev-del", "arguments": {"node-name": "node0"}} +{"return": {}} +{"execute": "blockdev-del", "arguments": {"node-name": "original-backing"}} +{"return": {}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 959ffe85fc..88a20fd17a 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -227,6 +227,7 @@ 225 rw auto quick 226 auto quick 227 auto quick +228 rw auto quick 229 auto quick 231 auto quick 232 auto quick --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549049937612120.65047697942668; Fri, 1 Feb 2019 11:38:57 -0800 (PST) Received: from localhost ([127.0.0.1]:60571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeeH-00043K-Ft for importer@patchew.org; Fri, 01 Feb 2019 14:38:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVv-0005r9-Rk for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVs-0002Vz-LG for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVl-0002Kn-2Q; Fri, 01 Feb 2019 14:30:02 -0500 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 28212A4046; Fri, 1 Feb 2019 19:30:00 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACCA1608C6; Fri, 1 Feb 2019 19:29:59 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:13 +0100 Message-Id: <20190201192935.18394-10-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.38]); Fri, 01 Feb 2019 19:30:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 09/31] block: Make path_combine() return the path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Kevin Wolf --- 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 2eecff73fe..67a6264c44 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -495,9 +495,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 223b9b19cb..dbb11693f0 100644 --- a/block.c +++ b/block.c @@ -152,53 +152,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 /* @@ -316,7 +325,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 @@ -4600,8 +4609,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)) { @@ -4610,8 +4619,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 d21f6a9f2c..144e24685d 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -873,8 +873,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050114689632.1651894370991; Fri, 1 Feb 2019 11:41:54 -0800 (PST) Received: from localhost ([127.0.0.1]:60637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpehA-0006rO-Fk for importer@patchew.org; Fri, 01 Feb 2019 14:41:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeVy-0005ts-2B for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVu-0002Ym-R3 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59792) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVn-0002PG-TL; Fri, 01 Feb 2019 14:30:04 -0500 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 C0DAE4947D; Fri, 1 Feb 2019 19:30:02 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 135AD5C63E; Fri, 1 Feb 2019 19:30:01 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:14 +0100 Message-Id: <20190201192935.18394-11-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 10/31] block: bdrv_get_full_backing_filename_from_...'s ret. val. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 --- include/block/block.h | 7 +++--- block.c | 53 ++++++++++++++++++++++++++++++------------- block/vmdk.c | 10 ++++---- qemu-img.c | 12 ++++------ 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 67a6264c44..4c9ec67ed6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -488,10 +488,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 dbb11693f0..5289b466be 100644 --- a/block.c +++ b/block.c @@ -312,20 +312,29 @@ fail: return -EACCES; } =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 @@ -333,12 +342,24 @@ void bdrv_get_full_backing_filename(BlockDriverState = *bs, char *dest, size_t sz, Error **errp) { char *backed; + char *full_name; + Error *local_error =3D NULL; =20 bdrv_refresh_filename(bs); =20 backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->filename; - 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) @@ -5122,17 +5143,17 @@ void bdrv_img_create(const char *filename, const ch= ar *fmt, size =3D qemu_opt_get_size(opts, BLOCK_OPT_SIZE, img_size); 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 144e24685d..b2421c7726 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2078,16 +2078,16 @@ static int coroutine_fn vmdk_co_do_create(int64_t s= ize, =20 if (backing_file) { BlockBackend *backing; - char *full_backing =3D g_new0(char, PATH_MAX); - bdrv_get_full_backing_filename_from_filename(blk_bs(blk)->filename= , backing_file, - full_backing, PATH_MA= X, - &local_err); + char *full_backing =3D + bdrv_get_full_backing_filename_from_filename(blk_bs(blk)->file= name, + 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 backing =3D blk_new_open(full_backing, NULL, NULL, BDRV_O_NO_BACKING, errp); diff --git a/qemu-img.c b/qemu-img.c index c077ea1c92..8ee8dad771 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3336,18 +3336,14 @@ static int img_rebase(int argc, char **argv) bdrv_refresh_filename(bs); overlay_filename =3D bs->exact_filename[0] ? bs->exact_filename : bs->filename; - out_real_path =3D g_malloc(PATH_MAX); - - bdrv_get_full_backing_filename_from_filename(overlay_filename, - out_baseimg, - out_real_path, - PATH_MAX, - &local_err); + out_real_path =3D + bdrv_get_full_backing_filename_from_filename(overlay_filen= ame, + out_baseimg, + &local_err); if (local_err) { error_reportf_err(local_err, "Could not resolve backing filename: "); ret =3D -1; - g_free(out_real_path); goto out; } =20 --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050285041259.8392744281314; Fri, 1 Feb 2019 11:44:45 -0800 (PST) Received: from localhost ([127.0.0.1]:60669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeju-0000vB-1X for importer@patchew.org; Fri, 01 Feb 2019 14:44:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeW4-00061Q-E5 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVy-0002dH-Fn for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVq-0002Sh-Mc; Fri, 01 Feb 2019 14:30:07 -0500 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 9756241A53; Fri, 1 Feb 2019 19:30:05 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B275600D7; Fri, 1 Feb 2019 19:30:04 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:15 +0100 Message-Id: <20190201192935.18394-12-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.30]); Fri, 01 Feb 2019 19:30:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 11/31] block: bdrv_get_full_backing_filename's ret. val. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 | 48 +++++++++++++++---------------------------- block/qapi.c | 12 ++--------- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 4c9ec67ed6..9222cce3c3 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -486,8 +486,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs, =20 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 5289b466be..ad78344e07 100644 --- a/block.c +++ b/block.c @@ -338,28 +338,16 @@ 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; - char *full_name; - Error *local_error =3D NULL; =20 bdrv_refresh_filename(bs); =20 backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->filename; - - 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) @@ -2362,7 +2350,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; @@ -2397,7 +2385,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 */ } else if (bs->backing_file[0] =3D=3D '\0' && qdict_size(options) =3D= =3D 0) { qobject_unref(options); goto free_exit; @@ -2412,8 +2400,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, implicit_backing =3D !strcmp(bs->auto_backing_file, bs->backin= g_file); } =20 - 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); @@ -2434,9 +2421,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: "); @@ -4591,7 +4577,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; @@ -4611,21 +4596,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 743136b84e..287e38e9de 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -291,18 +291,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050043880213.10599586011017; Fri, 1 Feb 2019 11:40:43 -0800 (PST) Received: from localhost ([127.0.0.1]:60592 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeg1-0005gm-KT for importer@patchew.org; Fri, 01 Feb 2019 14:40:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeW2-0005zY-Ip for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeVy-0002dl-Ve for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48786) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVt-0002Vd-0h; Fri, 01 Feb 2019 14:30:10 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9C3CC0601ED; Fri, 1 Feb 2019 19:30:07 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D52F10027CE; Fri, 1 Feb 2019 19:30:07 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:16 +0100 Message-Id: <20190201192935.18394-13-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 01 Feb 2019 19:30:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 12/31] block: Add bdrv_make_absolute_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index ad78344e07..21100ac7fd 100644 --- a/block.c +++ b/block.c @@ -338,16 +338,29 @@ 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; + char *bs_filename; =20 - bdrv_refresh_filename(bs); + bdrv_refresh_filename(relative_to); + + bs_filename =3D relative_to->exact_filename[0] + ? relative_to->exact_filename + : relative_to->filename; =20 - backed =3D bs->exact_filename[0] ? bs->exact_filename : bs->filename; - return bdrv_get_full_backing_filename_from_filename(backed, - bs->backing_file, - errp); + return bdrv_get_full_backing_filename_from_filename(bs_filename, + filename ?: "", er= rp); +} + +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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050463037835.1541075723878; Fri, 1 Feb 2019 11:47:43 -0800 (PST) Received: from localhost ([127.0.0.1]:60731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpemn-0003PF-0s for importer@patchew.org; Fri, 01 Feb 2019 14:47:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeW6-00063M-D7 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeW2-0002fx-Jp for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52640) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeVv-0002Ya-J6; Fri, 01 Feb 2019 14:30:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E755D7E3D; Fri, 1 Feb 2019 19:30:10 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D633C101963E; Fri, 1 Feb 2019 19:30:09 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:17 +0100 Message-Id: <20190201192935.18394-14-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 01 Feb 2019 19:30:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 13/31] block: Fix bdrv_find_backing_image() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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: Alberto Garcia --- block.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/block.c b/block.c index 21100ac7fd..d30389ff35 100644 --- a/block.c +++ b/block.c @@ -201,15 +201,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 @@ -4597,13 +4588,9 @@ BlockDriverState *bdrv_find_backing_image(BlockDrive= rState *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 - /* This will recursively refresh everything in the backing chain */ - bdrv_refresh_filename(bs); - for (curr_bs =3D bs; curr_bs->backing; curr_bs =3D curr_bs->backing->b= s) { =20 /* If either of the filename paths is actually a protocol, then @@ -4629,22 +4616,23 @@ 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); - - /* We are going to compare absolute pathnames */ - if (!realpath(filename_tmp, filename_full)) { + filename_tmp =3D bdrv_make_absolute_filename(curr_bs, backing_= file, + NULL); + /* We are going to compare canonicalized absolute pathnames */ + if (!filename_tmp || !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); - - if (!realpath(filename_tmp, backing_file_full)) { + filename_tmp =3D bdrv_get_full_backing_filename(curr_bs, NULL); + if (!filename_tmp || !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; @@ -4655,7 +4643,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050043185195.27331256866637; Fri, 1 Feb 2019 11:40:43 -0800 (PST) Received: from localhost ([127.0.0.1]:60601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeg4-0005mj-6v for importer@patchew.org; Fri, 01 Feb 2019 14:40:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWL-0006Kt-T0 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWJ-0002qL-J8 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39822) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeW6-0002gL-ET; Fri, 01 Feb 2019 14:30:24 -0500 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 DB2FE31A109; Fri, 1 Feb 2019 19:30:18 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C34B608C6; Fri, 1 Feb 2019 19:30:12 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:18 +0100 Message-Id: <20190201192935.18394-15-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 14/31] block: Add bdrv_dirname() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index 9222cce3c3..5334ba1261 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -490,6 +490,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 93cd669a35..d65f80a013 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -141,6 +141,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_preadv)(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags, diff --git a/block.c b/block.c index d30389ff35..dba05ee349 100644 --- a/block.c +++ b/block.c @@ -5654,6 +5654,33 @@ 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); + } + + bdrv_refresh_filename(bs); + 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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050829807371.07459705930796; Fri, 1 Feb 2019 11:53:49 -0800 (PST) Received: from localhost ([127.0.0.1]:60828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpesi-0008BO-R7 for importer@patchew.org; Fri, 01 Feb 2019 14:53:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWO-0006MV-2w for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWL-0002rt-PQ for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWA-0002gu-Bh; Fri, 01 Feb 2019 14:30:27 -0500 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 645DBC0C9A7B; Fri, 1 Feb 2019 19:30:21 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC56A60C64; Fri, 1 Feb 2019 19:30:20 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:19 +0100 Message-Id: <20190201192935.18394-16-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 15/31] blkverify: Make bdrv_dirname() return NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 035d77b64a..3c7d4c8729 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -313,6 +313,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", @@ -324,6 +333,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050667723973.7869678270944; Fri, 1 Feb 2019 11:51:07 -0800 (PST) Received: from localhost ([127.0.0.1]:60788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeq5-00060Q-M2 for importer@patchew.org; Fri, 01 Feb 2019 14:51:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWO-0006MY-3O for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWL-0002rm-P9 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62114) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWB-0002hw-Ny; Fri, 01 Feb 2019 14:30:27 -0500 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 8E4AE13AC01; Fri, 1 Feb 2019 19:30:23 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11AFA60C62; Fri, 1 Feb 2019 19:30:22 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:20 +0100 Message-Id: <20190201192935.18394-17-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.38]); Fri, 01 Feb 2019 19:30:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 16/31] quorum: Make bdrv_dirname() return NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 cf9d7c16c2..a890f21e85 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1094,6 +1094,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", =20 @@ -1102,6 +1112,7 @@ static BlockDriver bdrv_quorum =3D { .bdrv_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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050964550713.712260397616; Fri, 1 Feb 2019 11:56:04 -0800 (PST) Received: from localhost ([127.0.0.1]:60895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeuu-0001Ql-Fi for importer@patchew.org; Fri, 01 Feb 2019 14:56:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWX-0006XW-GQ for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWS-0002x1-3s for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWJ-0002ns-O2; Fri, 01 Feb 2019 14:30:37 -0500 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 51FD97E420; Fri, 1 Feb 2019 19:30:29 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F832600D7; Fri, 1 Feb 2019 19:30:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:21 +0100 Message-Id: <20190201192935.18394-18-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 17/31] block/nbd: Make bdrv_dirname() return NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- block/nbd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index e87699fb73..bca127c8f5 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -564,6 +564,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_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, + .bdrv_dirname =3D nbd_dirname, }; =20 static BlockDriver bdrv_nbd_tcp =3D { @@ -602,6 +613,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, + .bdrv_dirname =3D nbd_dirname, }; =20 static BlockDriver bdrv_nbd_unix =3D { @@ -622,6 +634,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, + .bdrv_dirname =3D nbd_dirname, }; =20 static void bdrv_nbd_init(void) --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050227050565.2349250936745; Fri, 1 Feb 2019 11:43:47 -0800 (PST) Received: from localhost ([127.0.0.1]:60659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpej2-0008Qs-3k for importer@patchew.org; Fri, 01 Feb 2019 14:43:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWS-0006S5-57 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWO-0002tb-1A for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:42 -0500 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 1gpeWJ-0002oP-KJ; Fri, 01 Feb 2019 14:30:35 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA0D041A53; Fri, 1 Feb 2019 19:30:31 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ECED101963F; Fri, 1 Feb 2019 19:30:31 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:22 +0100 Message-Id: <20190201192935.18394-19-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 01 Feb 2019 19:30:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 18/31] block/nfs: Implement bdrv_dirname() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/block/nfs.c b/block/nfs.c index eab1a2c408..19ee07c321 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -855,6 +855,20 @@ 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) { + bdrv_refresh_filename(bs); + error_setg(errp, "Cannot generate a base directory for NFS 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 coroutine_fn nfs_co_invalidate_cache(BlockDriverState *bs, Error **errp) @@ -889,6 +903,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_co_invalidate_cache =3D nfs_co_invalidate_cache, --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050182581595.501912400527; Fri, 1 Feb 2019 11:43:02 -0800 (PST) Received: from localhost ([127.0.0.1]:60653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeiJ-0007o9-Ek for importer@patchew.org; Fri, 01 Feb 2019 14:42:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWX-0006XU-Fx for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWS-0002x7-4Q for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWJ-0002pe-Lz; Fri, 01 Feb 2019 14:30:37 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 129578E3EC; Fri, 1 Feb 2019 19:30:34 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B34F1019635; Fri, 1 Feb 2019 19:30:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:23 +0100 Message-Id: <20190201192935.18394-20-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 01 Feb 2019 19:30:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 19/31] block: Use bdrv_dirname() for relative filenames X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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, 16 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index dba05ee349..05135152d5 100644 --- a/block.c +++ b/block.c @@ -337,16 +337,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; + char *dir, *full_name; =20 - bdrv_refresh_filename(relative_to); + if (!filename || filename[0] =3D=3D '\0') { + return NULL; + } else if (path_has_protocol(filename) || path_is_absolute(filename)) { + return g_strdup(filename); + } =20 - bs_filename =3D relative_to->exact_filename[0] - ? relative_to->exact_filename - : relative_to->filename; + dir =3D bdrv_dirname(relative_to, errp); + if (!dir) { + return NULL; + } =20 - return bdrv_get_full_backing_filename_from_filename(bs_filename, - filename ?: "", er= rp); + 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 b64b3b215a..3e9d72d302 100755 --- a/tests/qemu-iotests/110 +++ b/tests/qemu-iotests/110 @@ -60,7 +60,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050232558693.9340854315398; Fri, 1 Feb 2019 11:43:52 -0800 (PST) Received: from localhost ([127.0.0.1]:60661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpej3-0008SJ-IT for importer@patchew.org; Fri, 01 Feb 2019 14:43:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWX-0006XV-G1 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWS-0002x6-4I for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:30:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWL-0002rS-SY; Fri, 01 Feb 2019 14:30:38 -0500 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 6E7598E3E6; Fri, 1 Feb 2019 19:30:36 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8996608E1; Fri, 1 Feb 2019 19:30:35 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:24 +0100 Message-Id: <20190201192935.18394-21-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.25]); Fri, 01 Feb 2019 19:30:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 20/31] iotests: Add quorum case to test 110 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Test 110 tests relative backing filenames for complex BDS trees. Now that the originally supposedly failing test passes, let us add a new failing test: Quorum can never work automatically (without detecting whether all child nodes have the same base directory, but that would be rather inconsistent behavior). Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- tests/qemu-iotests/110 | 26 ++++++++++++++++++++++++++ tests/qemu-iotests/110.out | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/tests/qemu-iotests/110 b/tests/qemu-iotests/110 index 3e9d72d302..185ad5437e 100755 --- a/tests/qemu-iotests/110 +++ b/tests/qemu-iotests/110 @@ -29,6 +29,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 @@ -86,6 +87,31 @@ 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 + =20 # success, all done echo '*** done' diff --git a/tests/qemu-iotests/110.out b/tests/qemu-iotests/110.out index 5370bc1d26..1d0b2475cc 100644 --- a/tests/qemu-iotests/110.out +++ b/tests/qemu-iotests/110.out @@ -19,4 +19,11 @@ 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) *** done --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050596245572.4734277694481; Fri, 1 Feb 2019 11:49:56 -0800 (PST) Received: from localhost ([127.0.0.1]:60756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeow-00051J-2Y for importer@patchew.org; Fri, 01 Feb 2019 14:49:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWu-0006o9-E2 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWq-00034G-2T for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWQ-0002uv-87; Fri, 01 Feb 2019 14:30:44 -0500 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 E0C77124D18; Fri, 1 Feb 2019 19:30:40 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55FCB5C6DC; Fri, 1 Feb 2019 19:30:38 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:25 +0100 Message-Id: <20190201192935.18394-22-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.39]); Fri, 01 Feb 2019 19:30:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 21/31] block: Add strong_runtime_opts to BlockDriver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 | 16 ++++++++++++++++ block/blklogwrites.c | 8 ++++++++ block/crypto.c | 8 ++++++++ block/curl.c | 21 +++++++++++++++++++++ block/gluster.c | 19 +++++++++++++++++++ block/iscsi.c | 18 ++++++++++++++++++ block/nbd.c | 14 ++++++++++++++ block/nfs.c | 11 +++++++++++ block/null.c | 9 +++++++++ block/nvme.c | 8 ++++++++ block/qcow.c | 7 +++++++ block/qcow2.c | 7 +++++++ block/quorum.c | 11 +++++++++++ block/raw-format.c | 10 +++++++++- block/rbd.c | 14 ++++++++++++++ block/replication.c | 8 ++++++++ block/sheepdog.c | 12 ++++++++++++ block/ssh.c | 12 ++++++++++++ block/throttle.c | 7 +++++++ block/vpc.c | 7 +++++++ block/vvfat.c | 12 ++++++++++++ block/vxhs.c | 11 +++++++++++ 23 files changed, 256 insertions(+), 1 deletion(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index d65f80a013..40f00aa44e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -516,6 +516,13 @@ struct BlockDriver { void (*bdrv_register_buf)(BlockDriverState *bs, void *host, size_t siz= e); void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host); QLIST_ENTRY(BlockDriver) list; + + /* Pointer to a NULL-terminated array of names of strong options + * that can be specified for bdrv_open(). A strong 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 strong. */ + const char *const *strong_runtime_opts; }; =20 typedef struct BlockLimits { diff --git a/block/blkdebug.c b/block/blkdebug.c index 0759452925..71b4275b98 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -888,6 +888,20 @@ static int blkdebug_reopen_prepare(BDRVReopenState *re= open_state, return 0; } =20 +static const char *const blkdebug_strong_runtime_opts[] =3D { + "config", + "inject-error.", + "set-state.", + "align", + "max-transfer", + "opt-write-zero", + "max-write-zero", + "opt-discard", + "max-discard", + + NULL +}; + static BlockDriver bdrv_blkdebug =3D { .format_name =3D "blkdebug", .protocol_name =3D "blkdebug", @@ -917,6 +931,8 @@ 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, + + .strong_runtime_opts =3D blkdebug_strong_runtime_opts, }; =20 static void bdrv_blkdebug_init(void) diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 36e3d0f822..5da5df112d 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -517,6 +517,13 @@ blk_log_writes_co_pdiscard(BlockDriverState *bs, int64= _t offset, int count) LOG_DISCARD_FLAG, false); } =20 +static const char *const blk_log_writes_strong_runtime_opts[] =3D { + "log-append", + "log-sector-size", + + NULL +}; + static BlockDriver bdrv_blk_log_writes =3D { .format_name =3D "blklogwrites", .instance_size =3D sizeof(BDRVBlkLogWritesState), @@ -536,6 +543,7 @@ static BlockDriver bdrv_blk_log_writes =3D { .bdrv_co_block_status =3D bdrv_co_block_status_from_file, =20 .is_filter =3D true, + .strong_runtime_opts =3D blk_log_writes_strong_runtime_opts, }; =20 static void bdrv_blk_log_writes_init(void) diff --git a/block/crypto.c b/block/crypto.c index f0a5f6b987..d9bfd1084a 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -622,6 +622,12 @@ block_crypto_get_specific_info_luks(BlockDriverState *= bs) return spec_info; } =20 +static const char *const block_crypto_strong_runtime_opts[] =3D { + BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, + + NULL +}; + BlockDriver bdrv_crypto_luks =3D { .format_name =3D "luks", .instance_size =3D sizeof(BlockCrypto), @@ -643,6 +649,8 @@ 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, + + .strong_runtime_opts =3D block_crypto_strong_runtime_opts, }; =20 static void block_crypto_init(void) diff --git a/block/curl.c b/block/curl.c index b7ac265d3a..1c9e4f6a64 100644 --- a/block/curl.c +++ b/block/curl.c @@ -947,6 +947,19 @@ static int64_t curl_getlength(BlockDriverState *bs) return s->len; } =20 +static const char *const curl_strong_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", @@ -961,6 +974,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, + + .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 static BlockDriver bdrv_https =3D { @@ -977,6 +992,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, + + .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 static BlockDriver bdrv_ftp =3D { @@ -993,6 +1010,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, + + .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 static BlockDriver bdrv_ftps =3D { @@ -1009,6 +1028,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, + + .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 static void curl_block_init(void) diff --git a/block/gluster.c b/block/gluster.c index 72891060e3..af64330211 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1495,6 +1495,21 @@ static int coroutine_fn qemu_gluster_co_block_status= (BlockDriverState *bs, } =20 =20 +static const char *const gluster_strong_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", @@ -1522,6 +1537,7 @@ static BlockDriver bdrv_gluster =3D { #endif .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, + .strong_runtime_opts =3D gluster_strong_open_opts, }; =20 static BlockDriver bdrv_gluster_tcp =3D { @@ -1551,6 +1567,7 @@ static BlockDriver bdrv_gluster_tcp =3D { #endif .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, + .strong_runtime_opts =3D gluster_strong_open_opts, }; =20 static BlockDriver bdrv_gluster_unix =3D { @@ -1580,6 +1597,7 @@ static BlockDriver bdrv_gluster_unix =3D { #endif .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, + .strong_runtime_opts =3D gluster_strong_open_opts, }; =20 /* rdma is deprecated (actually never supported for volfile fetch). @@ -1615,6 +1633,7 @@ static BlockDriver bdrv_gluster_rdma =3D { #endif .bdrv_co_block_status =3D qemu_gluster_co_block_status, .create_opts =3D &qemu_gluster_create_opts, + .strong_runtime_opts =3D gluster_strong_open_opts, }; =20 static void bdrv_gluster_init(void) diff --git a/block/iscsi.c b/block/iscsi.c index ff473206e6..a0c0084837 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2448,6 +2448,20 @@ static QemuOptsList iscsi_create_opts =3D { } }; =20 +static const char *const iscsi_strong_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", @@ -2482,6 +2496,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, + + .strong_runtime_opts =3D iscsi_strong_runtime_opts, }; =20 #if LIBISCSI_API_VERSION >=3D (20160603) @@ -2519,6 +2535,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, + + .strong_runtime_opts =3D iscsi_strong_runtime_opts, }; #endif =20 diff --git a/block/nbd.c b/block/nbd.c index bca127c8f5..5b4e4cf1db 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -574,6 +574,17 @@ static char *nbd_dirname(BlockDriverState *bs, Error *= *errp) return NULL; } =20 +static const char *const nbd_strong_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_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, + .strong_runtime_opts =3D nbd_strong_runtime_opts, }; =20 static BlockDriver bdrv_nbd_tcp =3D { @@ -614,6 +626,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, + .strong_runtime_opts =3D nbd_strong_runtime_opts, }; =20 static BlockDriver bdrv_nbd_unix =3D { @@ -635,6 +648,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, + .strong_runtime_opts =3D nbd_strong_runtime_opts, }; =20 static void bdrv_nbd_init(void) diff --git a/block/nfs.c b/block/nfs.c index 19ee07c321..6985a44b89 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -878,6 +878,15 @@ static void coroutine_fn nfs_co_invalidate_cache(Block= DriverState *bs, } #endif =20 +static const char *nfs_strong_runtime_opts[] =3D { + "path", + "user", + "group", + "server.", + + NULL +}; + static BlockDriver bdrv_nfs =3D { .format_name =3D "nfs", .protocol_name =3D "nfs", @@ -905,6 +914,8 @@ static BlockDriver bdrv_nfs =3D { .bdrv_refresh_filename =3D nfs_refresh_filename, .bdrv_dirname =3D nfs_dirname, =20 + .strong_runtime_opts =3D nfs_strong_runtime_opts, + #ifdef LIBNFS_FEATURE_PAGECACHE .bdrv_co_invalidate_cache =3D nfs_co_invalidate_cache, #endif diff --git a/block/null.c b/block/null.c index d442d3e901..858892f0c4 100644 --- a/block/null.c +++ b/block/null.c @@ -252,6 +252,13 @@ static void null_refresh_filename(BlockDriverState *bs= , QDict *opts) bs->full_open_options =3D qobject_ref(opts); } =20 +static const char *const null_strong_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", @@ -269,6 +276,7 @@ static BlockDriver bdrv_null_co =3D { .bdrv_co_block_status =3D null_co_block_status, =20 .bdrv_refresh_filename =3D null_refresh_filename, + .strong_runtime_opts =3D null_strong_runtime_opts, }; =20 static BlockDriver bdrv_null_aio =3D { @@ -288,6 +296,7 @@ static BlockDriver bdrv_null_aio =3D { .bdrv_co_block_status =3D null_co_block_status, =20 .bdrv_refresh_filename =3D null_refresh_filename, + .strong_runtime_opts =3D null_strong_runtime_opts, }; =20 static void bdrv_null_init(void) diff --git a/block/nvme.c b/block/nvme.c index b5952c9b08..2d5acfdccf 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1136,6 +1136,13 @@ static void nvme_unregister_buf(BlockDriverState *bs= , void *host) qemu_vfio_dma_unmap(s->vfio, host); } =20 +static const char *const nvme_strong_runtime_opts[] =3D { + NVME_BLOCK_OPT_DEVICE, + NVME_BLOCK_OPT_NAMESPACE, + + NULL +}; + static BlockDriver bdrv_nvme =3D { .format_name =3D "nvme", .protocol_name =3D "nvme", @@ -1153,6 +1160,7 @@ static BlockDriver bdrv_nvme =3D { =20 .bdrv_refresh_filename =3D nvme_refresh_filename, .bdrv_refresh_limits =3D nvme_refresh_limits, + .strong_runtime_opts =3D nvme_strong_runtime_opts, =20 .bdrv_detach_aio_context =3D nvme_detach_aio_context, .bdrv_attach_aio_context =3D nvme_attach_aio_context, diff --git a/block/qcow.c b/block/qcow.c index d47515d3df..25d2025fd0 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -1186,6 +1186,12 @@ static QemuOptsList qcow_create_opts =3D { } }; =20 +static const char *const qcow_strong_runtime_opts[] =3D { + "encrypt." BLOCK_CRYPTO_OPT_QCOW_KEY_SECRET, + + NULL +}; + static BlockDriver bdrv_qcow =3D { .format_name =3D "qcow", .instance_size =3D sizeof(BDRVQcowState), @@ -1209,6 +1215,7 @@ static BlockDriver bdrv_qcow =3D { .bdrv_get_info =3D qcow_get_info, =20 .create_opts =3D &qcow_create_opts, + .strong_runtime_opts =3D qcow_strong_runtime_opts, }; =20 static void bdrv_qcow_init(void) diff --git a/block/qcow2.c b/block/qcow2.c index 662737275a..c21452bc2f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4921,6 +4921,12 @@ static QemuOptsList qcow2_create_opts =3D { } }; =20 +static const char *const qcow2_strong_runtime_opts[] =3D { + "encrypt." BLOCK_CRYPTO_OPT_QCOW_KEY_SECRET, + + NULL +}; + BlockDriver bdrv_qcow2 =3D { .format_name =3D "qcow2", .instance_size =3D sizeof(BDRVQcow2State), @@ -4969,6 +4975,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_inactivate =3D qcow2_inactivate, =20 .create_opts =3D &qcow2_create_opts, + .strong_runtime_opts =3D qcow2_strong_runtime_opts, .bdrv_co_check =3D qcow2_co_check, .bdrv_amend_options =3D qcow2_amend_options, =20 diff --git a/block/quorum.c b/block/quorum.c index a890f21e85..1af6458dc4 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1104,6 +1104,15 @@ static char *quorum_dirname(BlockDriverState *bs, Er= ror **errp) return NULL; } =20 +static const char *const quorum_strong_runtime_opts[] =3D { + QUORUM_OPT_VOTE_THRESHOLD, + QUORUM_OPT_BLKVERIFY, + QUORUM_OPT_REWRITE, + QUORUM_OPT_READ_PATTERN, + + NULL +}; + static BlockDriver bdrv_quorum =3D { .format_name =3D "quorum", =20 @@ -1128,6 +1137,8 @@ static BlockDriver bdrv_quorum =3D { =20 .is_filter =3D true, .bdrv_recurse_is_first_non_filter =3D quorum_recurse_is_first_non_fi= lter, + + .strong_runtime_opts =3D quorum_strong_runtime_opts, }; =20 static void bdrv_quorum_init(void) diff --git a/block/raw-format.c b/block/raw-format.c index d07bcdae62..e3e5ba2c8a 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -532,6 +532,13 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriv= erState *bs, read_flags, write_flags); } =20 +static const char *const raw_strong_runtime_opts[] =3D { + "offset", + "size", + + NULL +}; + BlockDriver bdrv_raw =3D { .format_name =3D "raw", .instance_size =3D sizeof(BDRVRawState), @@ -561,7 +568,8 @@ BlockDriver bdrv_raw =3D { .bdrv_lock_medium =3D &raw_lock_medium, .bdrv_co_ioctl =3D &raw_co_ioctl, .create_opts =3D &raw_create_opts, - .bdrv_has_zero_init =3D &raw_has_zero_init + .bdrv_has_zero_init =3D &raw_has_zero_init, + .strong_runtime_opts =3D raw_strong_runtime_opts, }; =20 static void bdrv_raw_init(void) diff --git a/block/rbd.c b/block/rbd.c index 8a1a9f4b6e..0c549c9935 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1228,6 +1228,18 @@ static QemuOptsList qemu_rbd_create_opts =3D { } }; =20 +static const char *const qemu_rbd_strong_runtime_opts[] =3D { + "pool", + "image", + "conf", + "snapshot", + "user", + "server.", + "password-secret", + + NULL +}; + static BlockDriver bdrv_rbd =3D { .format_name =3D "rbd", .instance_size =3D sizeof(BDRVRBDState), @@ -1265,6 +1277,8 @@ static BlockDriver bdrv_rbd =3D { #ifdef LIBRBD_SUPPORTS_INVALIDATE .bdrv_co_invalidate_cache =3D qemu_rbd_co_invalidate_cache, #endif + + .strong_runtime_opts =3D qemu_rbd_strong_runtime_opts, }; =20 static void bdrv_rbd_init(void) diff --git a/block/replication.c b/block/replication.c index 9b332002ee..4c80b54daf 100644 --- a/block/replication.c +++ b/block/replication.c @@ -676,6 +676,13 @@ static void replication_stop(ReplicationState *rs, boo= l failover, Error **errp) aio_context_release(aio_context); } =20 +static const char *const replication_strong_runtime_opts[] =3D { + REPLICATION_MODE, + REPLICATION_TOP_ID, + + NULL +}; + BlockDriver bdrv_replication =3D { .format_name =3D "replication", .instance_size =3D sizeof(BDRVReplicationState), @@ -692,6 +699,7 @@ BlockDriver bdrv_replication =3D { .bdrv_recurse_is_first_non_filter =3D replication_recurse_is_first_non= _filter, =20 .has_variable_length =3D true, + .strong_runtime_opts =3D replication_strong_runtime_opts, }; =20 static void bdrv_replication_init(void) diff --git a/block/sheepdog.c b/block/sheepdog.c index b916ba07bf..cbdfe9ab6e 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -3203,6 +3203,15 @@ static QemuOptsList sd_create_opts =3D { } }; =20 +static const char *const sd_strong_runtime_opts[] =3D { + "vdi", + "snap-id", + "tag", + "server.", + + NULL +}; + static BlockDriver bdrv_sheepdog =3D { .format_name =3D "sheepdog", .protocol_name =3D "sheepdog", @@ -3238,6 +3247,7 @@ static BlockDriver bdrv_sheepdog =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .strong_runtime_opts =3D sd_strong_runtime_opts, }; =20 static BlockDriver bdrv_sheepdog_tcp =3D { @@ -3275,6 +3285,7 @@ static BlockDriver bdrv_sheepdog_tcp =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .strong_runtime_opts =3D sd_strong_runtime_opts, }; =20 static BlockDriver bdrv_sheepdog_unix =3D { @@ -3312,6 +3323,7 @@ static BlockDriver bdrv_sheepdog_unix =3D { .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 .create_opts =3D &sd_create_opts, + .strong_runtime_opts =3D sd_strong_runtime_opts, }; =20 static void bdrv_sheepdog_init(void) diff --git a/block/ssh.c b/block/ssh.c index bbc513e095..190ef95300 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1254,6 +1254,17 @@ static int coroutine_fn ssh_co_truncate(BlockDriverS= tate *bs, int64_t offset, return ssh_grow_file(s, offset, errp); } =20 +static const char *const ssh_strong_runtime_opts[] =3D { + "host", + "port", + "path", + "user", + "host_key_check", + "server.", + + NULL +}; + static BlockDriver bdrv_ssh =3D { .format_name =3D "ssh", .protocol_name =3D "ssh", @@ -1270,6 +1281,7 @@ static BlockDriver bdrv_ssh =3D { .bdrv_co_truncate =3D ssh_co_truncate, .bdrv_co_flush_to_disk =3D ssh_co_flush, .create_opts =3D &ssh_create_opts, + .strong_runtime_opts =3D ssh_strong_runtime_opts, }; =20 static void bdrv_ssh_init(void) diff --git a/block/throttle.c b/block/throttle.c index 636c9764aa..f64dcc27b9 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -227,6 +227,12 @@ static void coroutine_fn throttle_co_drain_end(BlockDr= iverState *bs) atomic_dec(&tgm->io_limits_disabled); } =20 +static const char *const throttle_strong_runtime_opts[] =3D { + QEMU_OPT_THROTTLE_GROUP_NAME, + + NULL +}; + static BlockDriver bdrv_throttle =3D { .format_name =3D "throttle", .instance_size =3D sizeof(ThrottleGroupMember), @@ -259,6 +265,7 @@ static BlockDriver bdrv_throttle =3D { .bdrv_co_drain_end =3D throttle_co_drain_end, =20 .is_filter =3D true, + .strong_runtime_opts =3D throttle_strong_runtime_opts, }; =20 static void bdrv_throttle_init(void) diff --git a/block/vpc.c b/block/vpc.c index 52ab717642..a902a4c54d 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1218,6 +1218,12 @@ static QemuOptsList vpc_create_opts =3D { } }; =20 +static const char *const vpc_strong_runtime_opts[] =3D { + VPC_OPT_SIZE_CALC, + + NULL +}; + static BlockDriver bdrv_vpc =3D { .format_name =3D "vpc", .instance_size =3D sizeof(BDRVVPCState), @@ -1238,6 +1244,7 @@ static BlockDriver bdrv_vpc =3D { =20 .create_opts =3D &vpc_create_opts, .bdrv_has_zero_init =3D vpc_has_zero_init, + .strong_runtime_opts =3D vpc_strong_runtime_opts, }; =20 static void bdrv_vpc_init(void) diff --git a/block/vvfat.c b/block/vvfat.c index b7b61ea8b7..5f66787890 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3253,6 +3253,16 @@ static void vvfat_close(BlockDriverState *bs) } } =20 +static const char *const vvfat_strong_runtime_opts[] =3D { + "dir", + "fat-type", + "floppy", + "label", + "rw", + + NULL +}; + static BlockDriver bdrv_vvfat =3D { .format_name =3D "vvfat", .protocol_name =3D "fat", @@ -3267,6 +3277,8 @@ static BlockDriver bdrv_vvfat =3D { .bdrv_co_preadv =3D vvfat_co_preadv, .bdrv_co_pwritev =3D vvfat_co_pwritev, .bdrv_co_block_status =3D vvfat_co_block_status, + + .strong_runtime_opts =3D vvfat_strong_runtime_opts, }; =20 static void bdrv_vvfat_init(void) diff --git a/block/vxhs.c b/block/vxhs.c index 0cb0a007e9..2e18229ba4 100644 --- a/block/vxhs.c +++ b/block/vxhs.c @@ -556,6 +556,16 @@ static int64_t vxhs_getlength(BlockDriverState *bs) return vdisk_size; } =20 +static const char *const vxhs_strong_runtime_opts[] =3D { + VXHS_OPT_VDISK_ID, + "tls-creds", + VXHS_OPT_HOST, + VXHS_OPT_PORT, + VXHS_OPT_SERVER".", + + NULL +}; + static BlockDriver bdrv_vxhs =3D { .format_name =3D "vxhs", .protocol_name =3D "vxhs", @@ -567,6 +577,7 @@ static BlockDriver bdrv_vxhs =3D { .bdrv_getlength =3D vxhs_getlength, .bdrv_aio_preadv =3D vxhs_aio_preadv, .bdrv_aio_pwritev =3D vxhs_aio_pwritev, + .strong_runtime_opts =3D vxhs_strong_runtime_opts, }; =20 static void bdrv_vxhs_init(void) --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050402636830.4199719982619; Fri, 1 Feb 2019 11:46:42 -0800 (PST) Received: from localhost ([127.0.0.1]:60723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpelo-0002dH-Ia for importer@patchew.org; Fri, 01 Feb 2019 14:46:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeWt-0006nz-KW for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeWq-000349-1X for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWX-0002wW-5Q; Fri, 01 Feb 2019 14:30:49 -0500 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 7126973A70; Fri, 1 Feb 2019 19:30:43 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1C285D6B3; Fri, 1 Feb 2019 19:30:42 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:26 +0100 Message-Id: <20190201192935.18394-23-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 22/31] block: Add BlockDriver.bdrv_gather_child_options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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 (currently) want to use differ. See quorum_gather_child_options() for more information. Note that both of these are cases which are not ideal: In case of VMDK it would probably be nice to be able to specify options for all extents. In case of quorum, the current runtime option structure is simply broken and needs to be fixed (but that is left for another patch). Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block_int.h | 24 +++++++++++++++++++++++ block/quorum.c | 40 +++++++++++++++++++++++++++++++++++++++ block/vmdk.c | 19 +++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index 40f00aa44e..8df23ab79c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -141,6 +141,30 @@ struct BlockDriver { =20 void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); =20 + /* + * Gathers the open options for all children into @target. + * A simple format 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. + * + * @backing_overridden is true when bs->backing seems not to be + * the child that would result from opening bs->backing_file. + * Therefore, if it is true, the backing child's options should be + * gathered; otherwise, there is no need since the backing child + * is the one implied by the image header. + * + * Note that ideally this function would not be needed. Every + * block driver which implements it is probably doing something + * shady regarding its runtime option structure. + */ + void (*bdrv_gather_child_options)(BlockDriverState *bs, QDict *target, + bool backing_overridden); + /* * Returns an allocated string which is the directory name of this BDS= : It * will be used to make relative filenames absolute by prepending this diff --git a/block/quorum.c b/block/quorum.c index 1af6458dc4..3984f0aa4f 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1094,6 +1094,45 @@ 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, + bool backing_overridden) +{ + 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 specified 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 time a new child + * is added (and never decremented). Since children can be + * deleted at runtime, there may be gaps in that enumeration. + * When creating a new quorum BDS and specifying the children for + * it through runtime options, 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_options into a QList). + * + * XXX: Note that there are issues with the current child option + * structure quorum uses (such as the fact that children do + * not really have unique permanent names). Therefore, this + * is going to have to change in the future and ideally we + * want quorum to be covered by the generic implementation. + */ + + children_list =3D qlist_new(); + qdict_put(target, "children", children_list); + + for (i =3D 0; i < s->num_children; i++) { + qlist_append(children_list, + qobject_ref(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 @@ -1121,6 +1160,7 @@ static BlockDriver bdrv_quorum =3D { .bdrv_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 b2421c7726..1d58324508 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -27,6 +27,7 @@ #include "qapi/error.h" #include "block/block_int.h" #include "sysemu/block-backend.h" +#include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" #include "qemu/module.h" @@ -2607,6 +2608,23 @@ static int vmdk_get_info(BlockDriverState *bs, Block= DriverInfo *bdi) return 0; } =20 +static void vmdk_gather_child_options(BlockDriverState *bs, QDict *target, + bool backing_overridden) +{ + /* No children but file and backing can be explicitly specified (TODO)= */ + qdict_put(target, "file", + qobject_ref(bs->file->bs->full_open_options)); + + if (backing_overridden) { + if (bs->backing) { + qdict_put(target, "backing", + qobject_ref(bs->backing->bs->full_open_options)); + } else { + qdict_put_null(target, "backing"); + } + } +} + static QemuOptsList vmdk_create_opts =3D { .name =3D "vmdk-create-opts", .head =3D QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.head), @@ -2678,6 +2696,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549051165791437.63585312177986; Fri, 1 Feb 2019 11:59:25 -0800 (PST) Received: from localhost ([127.0.0.1]:60920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpey7-0003c1-Js for importer@patchew.org; Fri, 01 Feb 2019 14:59:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXZ-0007Hi-Bc for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXW-0003MY-9r for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXN-0002xn-OH; Fri, 01 Feb 2019 14:31:43 -0500 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 004802CD7F4; Fri, 1 Feb 2019 19:30:45 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 577D8608C6; Fri, 1 Feb 2019 19:30:45 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:27 +0100 Message-Id: <20190201192935.18394-24-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 23/31] block: Generically refresh runtime options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of having every block driver which implements bdrv_refresh_filename() copy all of the strong 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 iotests 110's and 228's reference outputs. Signed-off-by: Max Reitz --- block.c | 116 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/110.out | 2 +- tests/qemu-iotests/228 | 7 ++- tests/qemu-iotests/228.out | 2 +- 4 files changed, 121 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 05135152d5..f7a0c78697 100644 --- a/block.c +++ b/block.c @@ -5474,6 +5474,92 @@ out: return to_replace_bs; } =20 +/** + * Iterates through the list of runtime option keys that are said to + * be "strong" for a BDS. An option is called "strong" if it changes + * a BDS's data. For example, the null block driver's "size" and + * "read-zeroes" options are strong, but its "latency-ns" option is + * not. + * + * If a key returned by this function ends with a dot, all options + * starting with that prefix are strong. + */ +static const char *const *strong_options(BlockDriverState *bs, + const char *const *curopt) +{ + static const char *const global_options[] =3D { + "driver", "filename", 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->strong_runtime_opts; + } + + return (curopt && *curopt) ? curopt : NULL; +} + +/** + * Copies all strong runtime options from bs->options to the given + * QDict. The set of strong option keys is determined by invoking + * strong_options(). + * + * Returns true iff any strong option was present in bs->options (and + * thus copied to the target QDict) with the exception of "filename" + * and "driver". The caller is expected to use this value to decide + * whether the existence of strong options prevents the generation of + * a plain filename. + */ +static bool append_strong_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 strong_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; + } + + qdict_put_obj(d, *option_name, qobject_ref(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)) { + qdict_put_obj(d, qdict_entry_key(entry), + qobject_ref(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; @@ -5650,9 +5736,37 @@ void bdrv_refresh_filename(BlockDriverState *bs) bs->full_open_options =3D opts; } =20 + /* Gather the options QDict */ + opts =3D qdict_new(); + append_strong_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, backing_overridden); + } else { + QLIST_FOREACH(child, &bs->children, next) { + if (child->role =3D=3D &child_backing && !backing_overridden) { + /* We can skip the backing BDS if it has not been overridd= en */ + continue; + } + + qdict_put(opts, child->name, + qobject_ref(child->bs->full_open_options)); + } + + if (backing_overridden && !bs->backing) { + /* Force no backing file */ + qdict_put_null(opts, "backing"); + } + } + + qobject_unref(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 1d0b2475cc..46e6a60510 100644 --- a/tests/qemu-iotests/110.out +++ b/tests/qemu-iotests/110.out @@ -22,7 +22,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108= 864 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) diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 index 2930f8442c..7a57c41e29 100755 --- a/tests/qemu-iotests/228 +++ b/tests/qemu-iotests/228 @@ -230,9 +230,10 @@ with iotests.FilePath('base.img') as base_img_path, \ overlay=3D'node0') =20 # This should give us the original plain result - # FIXME: Currently, the block layer considers the runtime backing - # file to be different from the image header, which is - # wrong. This is fixed by a future patch. + # FIXME: Currently, it yields a json:{} filename even though it + # only contains a @driver and a @file entry, so a plain + # filename would obviously suffice. This is fixed by a + # future patch. =20 log_node_info(vm.node_info('node0')) =20 diff --git a/tests/qemu-iotests/228.out b/tests/qemu-iotests/228.out index 57fe97d4bc..393ab09164 100644 --- a/tests/qemu-iotests/228.out +++ b/tests/qemu-iotests/228.out @@ -74,7 +74,7 @@ bs->backing: (none) {"execute": "blockdev-snapshot", "arguments": {"node": "original-backing",= "overlay": "node0"}} {"return": {}} =20 -bs->filename: json:{"backing": {"driver": "IMGFMT", "file": {"driver": "fi= le", "filename": "TEST_DIR/PID-base.img"}}, "driver": "IMGFMT", "file": {"d= river": "file", "filename": "TEST_DIR/PID-top.img"}} +bs->filename: json:{"driver": "IMGFMT", "file": {"driver": "file", "filena= me": "TEST_DIR/PID-top.img"}} bs->backing_file: TEST_DIR/PID-base.img bs->backing->bs->filename: TEST_DIR/PID-base.img =20 --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050842169594.2086264332229; Fri, 1 Feb 2019 11:54:02 -0800 (PST) Received: from localhost ([127.0.0.1]:60830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpesu-0008JV-0a for importer@patchew.org; Fri, 01 Feb 2019 14:53:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXi-0007QW-6s for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:32:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXc-0003Tm-P5 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:32:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXN-0002yS-Pa; Fri, 01 Feb 2019 14:31:43 -0500 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 E946EDC8EE; Fri, 1 Feb 2019 19:30:48 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB1725D9D1; Fri, 1 Feb 2019 19:30:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:28 +0100 Message-Id: <20190201192935.18394-25-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 24/31] block: Purify .bdrv_refresh_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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. This completely obsoletes blklogwrite's implementation of .bdrv_refresh_filename(). Signed-off-by: Max Reitz --- include/block/block_int.h | 6 +- block.c | 131 +++++++------------------------------ block/blkdebug.c | 54 ++++++--------- block/blklogwrites.c | 22 ------- block/blkverify.c | 16 +---- block/commit.c | 2 +- block/mirror.c | 2 +- block/nbd.c | 23 +------ block/nfs.c | 36 +--------- block/null.c | 22 ++++--- block/nvme.c | 22 ++++--- block/quorum.c | 30 --------- tests/qemu-iotests/228 | 4 -- tests/qemu-iotests/228.out | 2 +- 14 files changed, 81 insertions(+), 291 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 8df23ab79c..620581d236 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -139,7 +139,11 @@ struct BlockDriver { 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. diff --git a/block.c b/block.c index f7a0c78697..7ddf8e3685 100644 --- a/block.c +++ b/block.c @@ -5560,33 +5560,6 @@ static bool append_strong_runtime_options(QDict *d, = BlockDriverState *bs) return found_any; } =20 -static bool append_open_options(QDict *d, BlockDriverState *bs) -{ - const QDictEntry *entry; - QemuOptDesc *desc; - bool found_any =3D false; - - for (entry =3D qdict_first(bs->options); entry; - entry =3D qdict_next(bs->options, entry)) - { - /* 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; - } - - qdict_put_obj(d, qdict_entry_key(entry), - qobject_ref(qdict_entry_value(entry))); - found_any =3D true; - } - - return found_any; -} - /* Note: This function may return false positives; it may return true * even if opening the backing file specified by bs's image header * would result in exactly bs->backing. */ @@ -5620,6 +5593,8 @@ void bdrv_refresh_filename(BlockDriverState *bs) BdrvChild *child; QDict *opts; bool backing_overridden; + bool generate_json_filename; /* Whether our default implementation sho= uld + fill exact_filename (false) or not (tr= ue) */ =20 if (!drv) { return; @@ -5655,90 +5630,10 @@ void bdrv_refresh_filename(BlockDriverState *bs) backing_overridden =3D false; } =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) { - qobject_unref(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); - qobject_unref(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) { - qobject_unref(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 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); - qdict_put(opts, "file", - qobject_ref(bs->file->bs->full_open_options)); - - if (bs->backing) { - qdict_put(opts, "backing", - qobject_ref(bs->backing->bs->full_open_options)); - } else if (backing_overridden) { - qdict_put_null(opts, "backing"); - } - - bs->full_open_options =3D opts; - } else { - qobject_unref(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_strong_runtime_options(opts, bs); + generate_json_filename =3D append_strong_runtime_options(opts, bs); + generate_json_filename |=3D backing_overridden; =20 if (drv->bdrv_gather_child_options) { /* Some block drivers may not want to present all of their childre= n's @@ -5764,6 +5659,24 @@ void bdrv_refresh_filename(BlockDriverState *bs) qobject_unref(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 71b4275b98..1ea835c2b9 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -811,51 +811,37 @@ 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)) + { + /* Real child options are under "image", but "x-image" may + * contain a filename */ + if (strcmp(qdict_entry_key(e), "config") && + strcmp(qdict_entry_key(e), "image") && + strcmp(qdict_entry_key(e), "x-image") && + strcmp(qdict_entry_key(e), "driver")) + { + return; } } =20 - opts =3D qdict_new(); - qdict_put_str(opts, "driver", "blkdebug"); - - qdict_put(opts, "image", qobject_ref(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")) { - qdict_put_obj(opts, qdict_entry_key(e), - qobject_ref(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/blklogwrites.c b/block/blklogwrites.c index 5da5df112d..eb2b4901a5 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -280,27 +280,6 @@ static int64_t blk_log_writes_getlength(BlockDriverSta= te *bs) return bdrv_getlength(bs->file->bs); } =20 -static void blk_log_writes_refresh_filename(BlockDriverState *bs, - QDict *options) -{ - BDRVBlkLogWritesState *s =3D bs->opaque; - - if (bs->file->bs->full_open_options - && s->log_file->bs->full_open_options) - { - QDict *opts =3D qdict_new(); - qdict_put_str(opts, "driver", "blklogwrites"); - - qobject_ref(bs->file->bs->full_open_options); - qdict_put(opts, "file", bs->file->bs->full_open_options); - qobject_ref(s->log_file->bs->full_open_options); - qdict_put(opts, "log", s->log_file->bs->full_open_options); - qdict_put_int(opts, "log-sector-size", s->sectorsize); - - bs->full_open_options =3D opts; - } -} - static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, const BdrvChildRole *role, BlockReopenQueue *ro_q, @@ -531,7 +510,6 @@ static BlockDriver bdrv_blk_log_writes =3D { .bdrv_open =3D blk_log_writes_open, .bdrv_close =3D blk_log_writes_close, .bdrv_getlength =3D blk_log_writes_getlength, - .bdrv_refresh_filename =3D blk_log_writes_refresh_filename, .bdrv_child_perm =3D blk_log_writes_child_perm, .bdrv_refresh_limits =3D blk_log_writes_refresh_limits, =20 diff --git a/block/blkverify.c b/block/blkverify.c index 3c7d4c8729..3ff77ff49a 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -281,24 +281,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"); - - qdict_put(opts, "raw", - qobject_ref(bs->file->bs->full_open_options)); - qdict_put(opts, "test", - qobject_ref(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 093b1505de..2b876bf6e9 100644 --- a/block/commit.c +++ b/block/commit.c @@ -230,7 +230,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 031c1aeaeb..726d3c27fb 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1431,7 +1431,7 @@ static int coroutine_fn bdrv_mirror_top_pdiscard(Bloc= kDriverState *bs, NULL, 0); } =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 5b4e4cf1db..fcc9e897e5 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -513,12 +513,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) { @@ -531,8 +528,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); @@ -546,22 +541,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 6985a44b89..531903610b 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -799,14 +799,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), @@ -824,35 +819,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 858892f0c4..1c56a0ef01 100644 --- a/block/null.c +++ b/block/null.c @@ -239,17 +239,23 @@ static int coroutine_fn null_co_block_status(BlockDri= verState *bs, return ret; } =20 -static void null_refresh_filename(BlockDriverState *bs, QDict *opts) +static void null_refresh_filename(BlockDriverState *bs) { - 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 qobject_ref(opts); + snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", + bs->drv->format_name); } =20 static const char *const null_strong_runtime_opts[] =3D { diff --git a/block/nvme.c b/block/nvme.c index 2d5acfdccf..88c24399ab 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1053,17 +1053,23 @@ static int nvme_reopen_prepare(BDRVReopenState *reo= pen_state, return 0; } =20 -static void nvme_refresh_filename(BlockDriverState *bs, QDict *opts) +static void nvme_refresh_filename(BlockDriverState *bs) { - 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 qobject_ref(opts); + snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", + bs->drv->format_name); } =20 static void nvme_refresh_limits(BlockDriverState *bs, Error **errp) diff --git a/block/quorum.c b/block/quorum.c index 3984f0aa4f..352f729136 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1065,35 +1065,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++) { - qlist_append(children, - qobject_ref(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, bool backing_overridden) { @@ -1159,7 +1130,6 @@ static BlockDriver bdrv_quorum =3D { =20 .bdrv_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 diff --git a/tests/qemu-iotests/228 b/tests/qemu-iotests/228 index 7a57c41e29..9a50afd205 100755 --- a/tests/qemu-iotests/228 +++ b/tests/qemu-iotests/228 @@ -230,10 +230,6 @@ with iotests.FilePath('base.img') as base_img_path, \ overlay=3D'node0') =20 # This should give us the original plain result - # FIXME: Currently, it yields a json:{} filename even though it - # only contains a @driver and a @file entry, so a plain - # filename would obviously suffice. This is fixed by a - # future patch. =20 log_node_info(vm.node_info('node0')) =20 diff --git a/tests/qemu-iotests/228.out b/tests/qemu-iotests/228.out index 393ab09164..4217df24fe 100644 --- a/tests/qemu-iotests/228.out +++ b/tests/qemu-iotests/228.out @@ -74,7 +74,7 @@ bs->backing: (none) {"execute": "blockdev-snapshot", "arguments": {"node": "original-backing",= "overlay": "node0"}} {"return": {}} =20 -bs->filename: json:{"driver": "IMGFMT", "file": {"driver": "file", "filena= me": "TEST_DIR/PID-top.img"}} +bs->filename: TEST_DIR/PID-top.img bs->backing_file: TEST_DIR/PID-base.img bs->backing->bs->filename: TEST_DIR/PID-base.img =20 --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050621469200.39427218460685; Fri, 1 Feb 2019 11:50:21 -0800 (PST) Received: from localhost ([127.0.0.1]:60758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpepL-0005J5-Dg for importer@patchew.org; Fri, 01 Feb 2019 14:50:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXT-0007Ed-6p for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXR-0003Et-8E for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXK-0002zh-PY; Fri, 01 Feb 2019 14:31:38 -0500 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 3E10D85363; Fri, 1 Feb 2019 19:30:51 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3C745DD63; Fri, 1 Feb 2019 19:30:50 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:29 +0100 Message-Id: <20190201192935.18394-26-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.25]); Fri, 01 Feb 2019 19:30:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 25/31] block: Do not copy exact_filename from format file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If 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 Reviewed-by: Alberto Garcia --- block.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 7ddf8e3685..c9a6cf0440 100644 --- a/block.c +++ b/block.c @@ -5670,9 +5670,21 @@ 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 (strong) 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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050426597338.3703826849254; Fri, 1 Feb 2019 11:47:06 -0800 (PST) Received: from localhost ([127.0.0.1]:60725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpemC-0002w7-GQ for importer@patchew.org; Fri, 01 Feb 2019 14:47:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXR-0007EY-7e for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXN-0003CP-Dj for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40670) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXE-00030T-Fn; Fri, 01 Feb 2019 14:31:35 -0500 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 9215A2E606E; Fri, 1 Feb 2019 19:30:53 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24C535D6AA; Fri, 1 Feb 2019 19:30:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:30 +0100 Message-Id: <20190201192935.18394-27-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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.29]); Fri, 01 Feb 2019 19:30:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 26/31] block/nvme: Fix bdrv_refresh_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, nvme's bdrv_refresh_filename() is an exact copy of null's implementation. However, for null, "null-co://" and "null-aio://" are indeed valid filenames -- for nvme, they are not, as a device address is still required. The correct implementation should generate a filename of the form "nvme://[PCI address]/[namespace]" (as the comment above nvme_parse_filename() describes). Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block/nvme.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 88c24399ab..7f0a2abd22 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -111,6 +111,9 @@ typedef struct { =20 /* Total size of mapped qiov, accessed under dma_map_lock */ int dma_map_count; + + /* PCI address (required for nvme_refresh_filename()) */ + char *device; } BDRVNVMeState; =20 #define NVME_BLOCK_OPT_DEVICE "device" @@ -557,6 +560,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, =20 qemu_co_mutex_init(&s->dma_map_lock); qemu_co_queue_init(&s->dma_flush_queue); + s->device =3D g_strdup(device); s->nsid =3D namespace; s->aio_context =3D bdrv_get_aio_context(bs); ret =3D event_notifier_init(&s->irq_notifier, 0); @@ -729,6 +733,8 @@ static void nvme_close(BlockDriverState *bs) event_notifier_cleanup(&s->irq_notifier); qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE); qemu_vfio_close(s->vfio); + + g_free(s->device); } =20 static int nvme_file_open(BlockDriverState *bs, QDict *options, int flags, @@ -1055,21 +1061,10 @@ static int nvme_reopen_prepare(BDRVReopenState *reo= pen_state, =20 static void nvme_refresh_filename(BlockDriverState *bs) { - 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; - } - } + BDRVNVMeState *s =3D bs->opaque; =20 - snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", - bs->drv->format_name); + snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nvme://%s/%i= ", + s->device, s->nsid); } =20 static void nvme_refresh_limits(BlockDriverState *bs, Error **errp) --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154905123758377.17873959459519; Fri, 1 Feb 2019 12:00:37 -0800 (PST) Received: from localhost ([127.0.0.1]:60956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpezM-0004VU-HH for importer@patchew.org; Fri, 01 Feb 2019 15:00:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXc-0007Ke-3b for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXa-0003RE-92 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXU-000310-1e; Fri, 01 Feb 2019 14:31:48 -0500 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 EEF62C0C6C07; Fri, 1 Feb 2019 19:30:55 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7811D5D6AA; Fri, 1 Feb 2019 19:30:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:31 +0100 Message-Id: <20190201192935.18394-28-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 27/31] block/curl: Harmonize option defaults X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Both of the defaults we currently have in the curl driver are named based on a slightly different schema, let's unify that and call both CURL_BLOCK_OPT_${NAME}_DEFAULT. While at it, we can add a macro for the third option for which a default exists, namely "sslverify". Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block/curl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/block/curl.c b/block/curl.c index 1c9e4f6a64..2c07a694d8 100644 --- a/block/curl.c +++ b/block/curl.c @@ -61,8 +61,6 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_= handle, =20 #define CURL_NUM_STATES 8 #define CURL_NUM_ACB 8 -#define READ_AHEAD_DEFAULT (256 * 1024) -#define CURL_TIMEOUT_DEFAULT 5 #define CURL_TIMEOUT_MAX 10000 =20 #define CURL_BLOCK_OPT_URL "url" @@ -76,6 +74,10 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi= _handle, #define CURL_BLOCK_OPT_PROXY_USERNAME "proxy-username" #define CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET "proxy-password-secret" =20 +#define CURL_BLOCK_OPT_READAHEAD_DEFAULT (256 * 1024) +#define CURL_BLOCK_OPT_SSLVERIFY_DEFAULT true +#define CURL_BLOCK_OPT_TIMEOUT_DEFAULT 5 + struct BDRVCURLState; =20 static bool libcurl_initialized; @@ -696,7 +698,7 @@ static int curl_open(BlockDriverState *bs, QDict *optio= ns, int flags, } =20 s->readahead_size =3D qemu_opt_get_size(opts, CURL_BLOCK_OPT_READAHEAD, - READ_AHEAD_DEFAULT); + CURL_BLOCK_OPT_READAHEAD_DEFAULT= ); if ((s->readahead_size & 0x1ff) !=3D 0) { error_setg(errp, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512= ", s->readahead_size); @@ -704,13 +706,14 @@ static int curl_open(BlockDriverState *bs, QDict *opt= ions, int flags, } =20 s->timeout =3D qemu_opt_get_number(opts, CURL_BLOCK_OPT_TIMEOUT, - CURL_TIMEOUT_DEFAULT); + CURL_BLOCK_OPT_TIMEOUT_DEFAULT); if (s->timeout > CURL_TIMEOUT_MAX) { error_setg(errp, "timeout parameter is too large or negative"); goto out_noclean; } =20 - s->sslverify =3D qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, tru= e); + s->sslverify =3D qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, + CURL_BLOCK_OPT_SSLVERIFY_DEFAULT); =20 cookie =3D qemu_opt_get(opts, CURL_BLOCK_OPT_COOKIE); cookie_secret =3D qemu_opt_get(opts, CURL_BLOCK_OPT_COOKIE_SECRET); --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549051090969777.5691961931288; Fri, 1 Feb 2019 11:58:10 -0800 (PST) Received: from localhost ([127.0.0.1]:60914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpewt-0002yw-2F for importer@patchew.org; Fri, 01 Feb 2019 14:58:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXJ-00076c-Se for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXH-0003A0-7S for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWs-00031P-F2; Fri, 01 Feb 2019 14:31:11 -0500 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 44E57C058CA6; Fri, 1 Feb 2019 19:30:58 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEF385D9D1; Fri, 1 Feb 2019 19:30:57 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:32 +0100 Message-Id: <20190201192935.18394-29-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:30:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 28/31] block/curl: Implement bdrv_refresh_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block/curl.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/curl.c b/block/curl.c index 2c07a694d8..606709fea4 100644 --- a/block/curl.c +++ b/block/curl.c @@ -950,6 +950,23 @@ static int64_t curl_getlength(BlockDriverState *bs) return s->len; } =20 +static void curl_refresh_filename(BlockDriverState *bs) +{ + BDRVCURLState *s =3D bs->opaque; + + /* "readahead" and "timeout" do not change the guest-visible data, + * so ignore them */ + if (s->sslverify !=3D CURL_BLOCK_OPT_SSLVERIFY_DEFAULT || + 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_strong_runtime_opts[] =3D { CURL_BLOCK_OPT_URL, CURL_BLOCK_OPT_SSLVERIFY, @@ -978,6 +995,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, .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 @@ -996,6 +1014,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, .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 @@ -1014,6 +1033,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, .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 @@ -1032,6 +1052,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, .strong_runtime_opts =3D curl_strong_runtime_opts, }; =20 --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050362925827.3331566103574; Fri, 1 Feb 2019 11:46:02 -0800 (PST) Received: from localhost ([127.0.0.1]:60717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpelD-00027P-SN for importer@patchew.org; Fri, 01 Feb 2019 14:45:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXK-00077f-UY for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXJ-0003B8-Sb for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40762) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeWv-00031z-Jx; Fri, 01 Feb 2019 14:31:13 -0500 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 9FCB1A7EF; Fri, 1 Feb 2019 19:31:00 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E169608C7; Fri, 1 Feb 2019 19:30:59 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:33 +0100 Message-Id: <20190201192935.18394-30-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:31:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 29/31] block/null: Generate filename even with latency-ns X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" While we cannot represent the latency-ns option in a filename, it is not a strong option so not being able to should not stop us from generating a filename nonetheless. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block/null.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/null.c b/block/null.c index 1c56a0ef01..a322929478 100644 --- a/block/null.c +++ b/block/null.c @@ -248,7 +248,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.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154905080059790.14509822400953; Fri, 1 Feb 2019 11:53:20 -0800 (PST) Received: from localhost ([127.0.0.1]:60826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpesB-0007rB-Ey for importer@patchew.org; Fri, 01 Feb 2019 14:53:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXY-0007Hg-5r for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXW-0003Mh-Ds for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33340) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXR-00032z-Gd; Fri, 01 Feb 2019 14:31:46 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33BD38E5A1; Fri, 1 Feb 2019 19:31:03 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A79219744; Fri, 1 Feb 2019 19:31:02 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:34 +0100 Message-Id: <20190201192935.18394-31-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 01 Feb 2019 19:31:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 30/31] block: BDS options may lack the "driver" option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When BDSs are created by qemu itself (e.g. as filters in block jobs), they may not have a "driver" option in their options QDict. When generating a json:{} filename, however, it must always be present. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- block.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block.c b/block.c index c9a6cf0440..d496debda4 100644 --- a/block.c +++ b/block.c @@ -5557,6 +5557,12 @@ static bool append_strong_runtime_options(QDict *d, = BlockDriverState *bs) } } =20 + if (!qdict_haskey(d, "driver")) { + /* Drivers created with bdrv_new_open_driver() may not have a + * @driver option. Add it here. */ + qdict_put_str(d, "driver", bs->drv->format_name); + } + return found_any; } =20 --=20 2.20.1 From nobody Tue May 7 07:34:35 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.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@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549050590148972.1544145852686; Fri, 1 Feb 2019 11:49:50 -0800 (PST) Received: from localhost ([127.0.0.1]:60754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeok-0004r4-SW for importer@patchew.org; Fri, 01 Feb 2019 14:49:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpeXZ-0007Hh-91 for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpeXV-0003Kg-7c for qemu-devel@nongnu.org; Fri, 01 Feb 2019 14:31:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52498) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gpeXK-00033W-WC; Fri, 01 Feb 2019 14:31:39 -0500 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 9436CC0C0F9B; Fri, 1 Feb 2019 19:31:05 +0000 (UTC) Received: from localhost (ovpn-204-111.brq.redhat.com [10.40.204.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E28995D6AA; Fri, 1 Feb 2019 19:31:04 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 1 Feb 2019 20:29:35 +0100 Message-Id: <20190201192935.18394-32-mreitz@redhat.com> In-Reply-To: <20190201192935.18394-1-mreitz@redhat.com> References: <20190201192935.18394-1-mreitz@redhat.com> MIME-Version: 1.0 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, 01 Feb 2019 19:31:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 31/31] iotests: Test json:{} filenames of internal BDSs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- tests/qemu-iotests/224 | 139 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/224.out | 18 +++++ tests/qemu-iotests/group | 1 + 3 files changed, 158 insertions(+) create mode 100755 tests/qemu-iotests/224 create mode 100644 tests/qemu-iotests/224.out diff --git a/tests/qemu-iotests/224 b/tests/qemu-iotests/224 new file mode 100755 index 0000000000..b4dfaa639f --- /dev/null +++ b/tests/qemu-iotests/224 @@ -0,0 +1,139 @@ +#!/usr/bin/env python +# +# Test json:{} filenames with qemu-internal BDSs +# (the one of commit, to be precise) +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Max Reitz + +import iotests +from iotests import log, qemu_img, qemu_io_silent, filter_qmp_testfiles, \ + filter_qmp_imgfmt +import json + +# Need backing file support (for arbitrary backing formats) +iotests.verify_image_format(supported_fmts=3D['qcow2', 'qcow', 'qed']) +iotests.verify_platform(['linux']) + + +# There are two variations of this test: +# (1) We do not set filter_node_name. In that case, the commit_top +# driver should not appear anywhere. +# (2) We do set filter_node_name. In that case, it should appear. +# +# This for loop executes both. +for filter_node_name in False, True: + log('') + log('--- filter_node_name: %s ---' % filter_node_name) + log('') + + with iotests.FilePath('base.img') as base_img_path, \ + iotests.FilePath('mid.img') as mid_img_path, \ + iotests.FilePath('top.img') as top_img_path, \ + iotests.VM() as vm: + + assert qemu_img('create', '-f', iotests.imgfmt, + base_img_path, '64M') =3D=3D 0 + assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_pat= h, + mid_img_path) =3D=3D 0 + assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, + top_img_path) =3D=3D 0 + + # Something to commit + assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') =3D= =3D 0 + + vm.launch() + + # Change the bottom-most image's backing file (to null-co://) + # to enforce json:{} filenames + vm.qmp_log('blockdev-add', + node_name=3D'top', + driver=3Diotests.imgfmt, + file=3D{ + 'driver': 'file', + 'filename': top_img_path + }, + backing=3D{ + 'node-name': 'mid', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': mid_img_path + }, + 'backing': { + 'node-name': 'base', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': base_img_path + }, + 'backing': { + 'driver': 'null-co' + } + } + }, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt]) + + # As long as block-commit does not accept node names, we have to + # get our mid/base filenames here + mid_name =3D vm.node_info('mid')['image']['filename'] + base_name =3D vm.node_info('base')['image']['filename'] + + assert mid_name[:5] =3D=3D 'json:' + assert base_name[:5] =3D=3D 'json:' + + # Start the block job + if filter_node_name: + vm.qmp_log('block-commit', + job_id=3D'commit', + device=3D'top', + filter_node_name=3D'filter_node', + top=3Dmid_name, + base=3Dbase_name, + speed=3D1, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt= ]) + else: + vm.qmp_log('block-commit', + job_id=3D'commit', + device=3D'top', + top=3Dmid_name, + base=3Dbase_name, + speed=3D1, + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt= ]) + + vm.qmp_log('job-pause', id=3D'commit') + + # Get and parse top's json:{} filename + top_name =3D vm.node_info('top')['image']['filename'] + + vm.shutdown() + + assert top_name[:5] =3D=3D 'json:' + top_options =3D json.loads(top_name[5:]) + + if filter_node_name: + # This should be present and set + assert top_options['backing']['driver'] =3D=3D 'commit_top' + # And the mid image is commit_top's backing image + mid_options =3D top_options['backing']['backing'] + else: + # The mid image should appear as the immediate backing BDS + # of top + mid_options =3D top_options['backing'] + + assert mid_options['driver'] =3D=3D iotests.imgfmt + assert mid_options['file']['filename'] =3D=3D mid_img_path diff --git a/tests/qemu-iotests/224.out b/tests/qemu-iotests/224.out new file mode 100644 index 0000000000..23374a1d29 --- /dev/null +++ b/tests/qemu-iotests/224.out @@ -0,0 +1,18 @@ + +--- filter_node_name: False --- + +{"execute": "blockdev-add", "arguments": {"backing": {"backing": {"backing= ": {"driver": "null-co"}, "driver": "IMGFMT", "file": {"driver": "file", "f= ilename": "TEST_DIR/PID-base.img"}, "node-name": "base"}, "driver": "IMGFMT= ", "file": {"driver": "file", "filename": "TEST_DIR/PID-mid.img"}, "node-na= me": "mid"}, "driver": "IMGFMT", "file": {"driver": "file", "filename": "TE= ST_DIR/PID-top.img"}, "node-name": "top"}} +{"return": {}} +{"execute": "block-commit", "arguments": {"base": "json:{\"backing\": {\"d= river\": \"null-co\"}, \"driver\": \"IMGFMT\", \"file\": {\"driver\": \"fil= e\", \"filename\": \"TEST_DIR/PID-base.img\"}}", "device": "top", "job-id":= "commit", "speed": 1, "top": "json:{\"backing\": {\"backing\": {\"driver\"= : \"null-co\"}, \"driver\": \"IMGFMT\", \"file\": {\"driver\": \"file\", \"= filename\": \"TEST_DIR/PID-base.img\"}}, \"driver\": \"IMGFMT\", \"file\": = {\"driver\": \"file\", \"filename\": \"TEST_DIR/PID-mid.img\"}}"}} +{"return": {}} +{"execute": "job-pause", "arguments": {"id": "commit"}} +{"return": {}} + +--- filter_node_name: True --- + +{"execute": "blockdev-add", "arguments": {"backing": {"backing": {"backing= ": {"driver": "null-co"}, "driver": "IMGFMT", "file": {"driver": "file", "f= ilename": "TEST_DIR/PID-base.img"}, "node-name": "base"}, "driver": "IMGFMT= ", "file": {"driver": "file", "filename": "TEST_DIR/PID-mid.img"}, "node-na= me": "mid"}, "driver": "IMGFMT", "file": {"driver": "file", "filename": "TE= ST_DIR/PID-top.img"}, "node-name": "top"}} +{"return": {}} +{"execute": "block-commit", "arguments": {"base": "json:{\"backing\": {\"d= river\": \"null-co\"}, \"driver\": \"IMGFMT\", \"file\": {\"driver\": \"fil= e\", \"filename\": \"TEST_DIR/PID-base.img\"}}", "device": "top", "filter-n= ode-name": "filter_node", "job-id": "commit", "speed": 1, "top": "json:{\"b= acking\": {\"backing\": {\"driver\": \"null-co\"}, \"driver\": \"IMGFMT\", = \"file\": {\"driver\": \"file\", \"filename\": \"TEST_DIR/PID-base.img\"}},= \"driver\": \"IMGFMT\", \"file\": {\"driver\": \"file\", \"filename\": \"T= EST_DIR/PID-mid.img\"}}"}} +{"return": {}} +{"execute": "job-pause", "arguments": {"id": "commit"}} +{"return": {}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 88a20fd17a..c4257152c5 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -224,6 +224,7 @@ 221 rw auto quick 222 rw auto quick 223 rw auto quick +224 rw auto quick 225 rw auto quick 226 auto quick 227 auto quick --=20 2.20.1