From nobody Mon Feb 9 17:06:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671005760; cv=none; d=zohomail.com; s=zohoarc; b=YPHXCRGJpC1diQui+pTXR2+0uYpf2jg26px90eff1yyeknw2aFCedXDzMViJJUn+5XoTW+b1IdEXZS7kqGl8vaFbs2GFifW+tkd97zgR2XkXxv+xKrOyBrNh2ak84Pj/1FyTfTpWLRVN6casJM+rDCwgv1PDPq1c2pu4AJfbfac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671005760; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eVHvMEwuxUvl9djAZ1mBOtP/TaLImV8ASuD/2djkqc0=; b=Y4gACHd1NpicsTH1AlyMpPU46XNEWnGlhyd/bZ/P5864wcZqQ8KHcFn6eVEcYijRYa/MNpJPdCF1KNrIjjhIh8EnsBzsFSkBXSu4QhM99uLwIC9aHoWZmFJUA3FMlzRHID1inchIlCpflSu8kDBRBm8HWHsfQI2q1KLcv/wVp6c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167100576054163.75759977289226; Wed, 14 Dec 2022 00:16:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5MUW-0003Zs-Of; Wed, 14 Dec 2022 02:47:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5MUJ-0003QL-1p for qemu-devel@nongnu.org; Wed, 14 Dec 2022 02:47:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5MUG-0003e2-D1 for qemu-devel@nongnu.org; Wed, 14 Dec 2022 02:47:34 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-ODZKYc5wMiK0k3kCO3F2nQ-1; Wed, 14 Dec 2022 02:47:28 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A3A93C02529; Wed, 14 Dec 2022 07:47:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.195.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03F4A40C2064; Wed, 14 Dec 2022 07:47:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 631DE21E6498; Wed, 14 Dec 2022 08:47:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671004051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eVHvMEwuxUvl9djAZ1mBOtP/TaLImV8ASuD/2djkqc0=; b=RadnhPScwKV47MirH/uHqgkmBslauDA0WwtTu4jzbHhOHPi3V0g/4iPqhlbAWlY4pXd7dc gMWSIgyhF9nz9iuJXexCQMmUhdnv/1rcSR0h67vZjBw4zVdGb/tanOLcnFZqA9J+xtNiQq wd8y2rBWSxDrFBeY+A9O2C6U0UR2siQ= X-MC-Unique: ODZKYc5wMiK0k3kCO3F2nQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org, Eric Blake Subject: [PULL 08/30] blockdev: Clean up abuse of DriveBackup member format Date: Wed, 14 Dec 2022 08:46:59 +0100 Message-Id: <20221214074721.731441-11-armbru@redhat.com> In-Reply-To: <20221214074721.731441-1-armbru@redhat.com> References: <20221214074721.731441-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671005761318100003 Content-Type: text/plain; charset="utf-8" drive-backup argument @format defaults to the format of the source unless @mode is "existing". drive_backup_prepare() implements this by copying the source's @format_name to DriveBackup member @format. It leaves @has_format false, violating the "has_format =3D=3D !!format" invariant. Unclean. Falls apart when we elide @has_format (commit after next): then QAPI passes @format, which is a string constant, to g_free(). iotest 056 duly explodes. Clean it up. Since the value stored in member @format is not actually used outside this function, use a local variable instead of modifying the QAPI object. Signed-off-by: Markus Armbruster Cc: Kevin Wolf Cc: Hanna Reitz Cc: qemu-block@nongnu.org Message-Id: <20221104160712.3005652-9-armbru@redhat.com> Reviewed-by: Eric Blake --- blockdev.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 3f1dec6242..d6550e0dc8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1686,6 +1686,7 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) BlockDriverState *source =3D NULL; AioContext *aio_context; AioContext *old_context; + const char *format; QDict *options; Error *local_err =3D NULL; int flags; @@ -1717,9 +1718,9 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) /* Paired with .clean() */ bdrv_drained_begin(bs); =20 - if (!backup->has_format) { - backup->format =3D backup->mode =3D=3D NEW_IMAGE_MODE_EXISTING ? - NULL : (char *) bs->drv->format_name; + format =3D backup->format; + if (!format && backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { + format =3D bs->drv->format_name; } =20 /* Early check to avoid creating target */ @@ -1758,19 +1759,19 @@ static void drive_backup_prepare(BlkActionState *co= mmon, Error **errp) } =20 if (backup->mode !=3D NEW_IMAGE_MODE_EXISTING) { - assert(backup->format); + assert(format); if (source) { /* Implicit filters should not appear in the filename */ BlockDriverState *explicit_backing =3D bdrv_skip_implicit_filters(source); =20 bdrv_refresh_filename(explicit_backing); - bdrv_img_create(backup->target, backup->format, + bdrv_img_create(backup->target, format, explicit_backing->filename, explicit_backing->drv->format_name, NULL, size, flags, false, &local_err); } else { - bdrv_img_create(backup->target, backup->format, NULL, NULL, NU= LL, + bdrv_img_create(backup->target, format, NULL, NULL, NULL, size, flags, false, &local_err); } } @@ -1783,8 +1784,8 @@ static void drive_backup_prepare(BlkActionState *comm= on, Error **errp) options =3D qdict_new(); qdict_put_str(options, "discard", "unmap"); qdict_put_str(options, "detect-zeroes", "unmap"); - if (backup->format) { - qdict_put_str(options, "driver", backup->format); + if (format) { + qdict_put_str(options, "driver", format); } =20 target_bs =3D bdrv_open(backup->target, NULL, options, flags, errp); --=20 2.37.3