From nobody Sat May 18 09:23:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673269773; cv=none; d=zohomail.com; s=zohoarc; b=eB7bMVGQjsxQMn2BnUsuulI1rmtpkgIlFAIEYDSP5CO2S69PRJAhENp7CYwnECCzSap00lJALKvO4WyhvQdSbuzQHrm+Gi9FTAne7L3M1TsHmZMyODxe8Jl/W6+LrBX1BevAsJgNIAkQs3tL3L9GZqvMYPaoFkQfgtSHoQ3JftQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673269773; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=HBHONTR9s9kXYzn4j6fGsPnOwEfCV9VeOVWrrYUkOlo=; b=PAlcmzfJjcfPHddLJYaZW5fbpGPO8i+iLgX7p3G9fXmQk7/2K4lP1fS2tDxljKKEbZVSQmmcWghjP4ka8RHL+OZbOKE4keqhR8SQq/PGONDSRAWlHFPsir4t1wmCJZZPIa/PE7lZPskank8FPPb+YbTIV8LM1xW+bqbSBTHDM7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1673269773142665.2138843164014; Mon, 9 Jan 2023 05:09:33 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-32-s5jm57-LOmWyfM0H-77vTQ-1; Mon, 09 Jan 2023 08:09:29 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9362C183B3C1; Mon, 9 Jan 2023 13:09:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E529C16027; Mon, 9 Jan 2023 13:09:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5DABD1947BA1; Mon, 9 Jan 2023 13:09:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 71BB71947B94 for ; Mon, 9 Jan 2023 13:09:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5CFC61121318; Mon, 9 Jan 2023 13:09:26 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8DD51121314 for ; Mon, 9 Jan 2023 13:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673269771; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HBHONTR9s9kXYzn4j6fGsPnOwEfCV9VeOVWrrYUkOlo=; b=ZV56nvxpLBLXf/6NdRgAOCWXjiUmZ0BZSJCg1kYzE2CGXfW+EBI5kIQnIVnyTRd0ETCGpo 9P4rURUtDMmvUwALkGerKNuDZTvHoOZujysfU+N1MNsDUJK3KTJCoC/uh48v5500VNEsom oXsoMDbI3gSuOICCxe9gg4M2Sj1lFRs= X-MC-Unique: s5jm57-LOmWyfM0H-77vTQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] qemu: snapshot: Restructure control flow to detect errors sooner and work around compiler Date: Mon, 9 Jan 2023 14:09:24 +0100 Message-Id: <8cd2b50df211925cde5d6dbfd528046cc4a97675.1673269582.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673269775262100001 Content-Type: text/plain; charset="utf-8" Some compilers aren't happy when an automatically freed variable is used just to free something (thus it's only assigned in the code): When compiling qemuSnapshotDelete after recent commits they complain: ../src/qemu/qemu_snapshot.c:3153:61: error: variable 'delData' set but not = used [-Werror,-Wunused-but-set-variable] g_autoslist(qemuSnapshotDeleteExternalData) delData =3D NUL= L; ^ To work around the issue we can restructure the code which also has the following semantic implications: - since qemuSnapshotDeleteExternalPrepare does validation we error out sooner than attempting to start the VM - we read the temporary variable at least in one code path Fixes: 4a4d89a9252 Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 32f7011cbe..b8416808b3 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3146,12 +3146,13 @@ qemuSnapshotDelete(virDomainObj *vm, if (virDomainSnapshotIsExternal(snap) && !(flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))) { + g_autoslist(qemuSnapshotDeleteExternalData) tmpData =3D NULL; - externalData =3D qemuSnapshotDeleteExternalPrepare(vm, snap); + /* this also serves as validation whether the snapshot can be = deleted */ + if (!(tmpData =3D qemuSnapshotDeleteExternalPrepare(vm, snap))) + goto endjob; if (!virDomainObjIsActive(vm)) { - g_autoslist(qemuSnapshotDeleteExternalData) delData =3D NU= LL; - if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB= _SNAPSHOT, NULL, -1, NULL, NULL, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, @@ -3163,20 +3164,19 @@ qemuSnapshotDelete(virDomainObj *vm, /* Call the prepare again as some data require that the VM= is * running to get everything we need. */ - delData =3D g_steal_pointer(&externalData); - externalData =3D qemuSnapshotDeleteExternalPrepare(vm, sna= p); + if (!(externalData =3D qemuSnapshotDeleteExternalPrepare(v= m, snap))) + goto endjob; } else { qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; + externalData =3D g_steal_pointer(&tmpData); + /* If the VM is running we need to indicate that the async= snapshot * job is snapshot delete job. */ jobPriv->snapshotDelete =3D true; qemuDomainSaveStatus(vm); } - - if (!externalData) - goto endjob; } } --=20 2.38.1