From nobody Tue Nov 4 15:00:49 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530145392804787.8539768493265; Wed, 27 Jun 2018 17:23:12 -0700 (PDT) Received: from localhost ([::1]:33850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYKiN-0007yF-W8 for importer@patchew.org; Wed, 27 Jun 2018 20:23:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYKTw-0004eB-Kt for qemu-devel@nongnu.org; Wed, 27 Jun 2018 20:08:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYKTv-000472-95 for qemu-devel@nongnu.org; Wed, 27 Jun 2018 20:08:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55552 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYKTq-000405-Hf; Wed, 27 Jun 2018 20:08:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 394EB4078B9E; Thu, 28 Jun 2018 00:08:10 +0000 (UTC) Received: from localhost (unknown [10.40.205.153]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 846B211166EE; Thu, 28 Jun 2018 00:08:08 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 28 Jun 2018 02:07:25 +0200 Message-Id: <20180628000745.4477-12-mreitz@redhat.com> In-Reply-To: <20180628000745.4477-1-mreitz@redhat.com> References: <20180628000745.4477-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 28 Jun 2018 00:08:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 28 Jun 2018 00:08:10 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v9 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make bdrv_get_full_backing_filename() return an allocated string instead of placing the result in a caller-provided buffer. Signed-off-by: Max Reitz Reviewed-by: Alberto Garcia --- include/block/block.h | 3 +-- block.c | 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 5f9c32b0f6..7c4ff51f8a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -457,8 +457,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 fbec6680c8..400cc0d071 100644 --- a/block.c +++ b/block.c @@ -319,28 +319,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) @@ -2305,7 +2293,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; @@ -2340,7 +2328,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; @@ -2355,8 +2343,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); @@ -2377,9 +2364,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: "); @@ -4295,7 +4281,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; @@ -4315,21 +4300,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 1c59febfef..b573a60609 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.17.1