From nobody Fri Dec 27 11:53:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1732634233600650.6609925611604; Tue, 26 Nov 2024 07:17:13 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 94AB81C0C; Tue, 26 Nov 2024 10:17:12 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9433618BC; Tue, 26 Nov 2024 10:16:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 123DC181C; Tue, 26 Nov 2024 10:16:48 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 8153D1397 for ; Tue, 26 Nov 2024 10:16:47 -0500 (EST) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-m-W5FiU-P3adU5ho-raHEA-1; Tue, 26 Nov 2024 10:16:45 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 27F491833851 for ; Tue, 26 Nov 2024 15:16:27 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0485919772CF for ; Tue, 26 Nov 2024 15:16:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732634207; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=f+EoNKOZXMTkirp/bIomlX81DUySFXp3n5Mb2Z2sLRY=; b=V8IEJ5N6pyLHUhj+zvzqoXgHHgPdu++WJRtXtLvR0Lb9uWKcfmVOOSC4n8T4xnSMJyFHBo B2Dr+UCc+mPxr2VhDNIrTtF3aviqD0KxX8fVEesJ334AS9q1mqitrCJveEDtEDpwbvCTSs Rf0EYTaW9/rPuWGzRc+oTmPEsbSgxXA= X-MC-Unique: m-W5FiU-P3adU5ho-raHEA-1 X-Mimecast-MFC-AGG-ID: m-W5FiU-P3adU5ho-raHEA From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/8] qemuBlockReopenAccess: Fix update of 'readonly' state Date: Tue, 26 Nov 2024 16:16:13 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MBoVyt_dLVnZ4Xh-31_0JmjcqskFaT8xkvtOzwIFQC0_1732634204 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZLIGEWE7FH3OFFJ3JJAJPZW7CACRET5V X-Message-ID-Hash: ZLIGEWE7FH3OFFJ3JJAJPZW7CACRET5V X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1732634235977019100 Content-Type: text/plain; charset="utf-8" Refactors done in 24b667eeed78d2df (and also 9ec0e28e876b17df9) broke the expected handling of the update of 'readonly' flag of a virStorage. The source is actually set to the proper state but rolled back to the previous state as the 'cleanup' label should have been 'error' and thus not reached on success. Additionally some of the code paths violate the statement in the comment after updating 'readonly' that only 'goto error' must be used. Fixes: 24b667eeed78d2df0376a38a592ed9d8c2744bdc Signed-off-by: Peter Krempa --- src/qemu/qemu_block.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 088c128424..a7c8be8d8b 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3172,7 +3172,6 @@ qemuBlockReopenAccess(virDomainObj *vm, g_autoptr(virJSONValue) reopenoptions =3D virJSONValueNewArray(); g_autoptr(virJSONValue) srcprops =3D NULL; int rc; - int ret =3D -1; VIR_DEBUG("nodename:'%s' current-ro:'%d requested-ro=3D'%d'", qemuBlockStorageSourceGetEffectiveNodename(src), @@ -3190,39 +3189,39 @@ qemuBlockReopenAccess(virDomainObj *vm, } src->readonly =3D readonly; - /* from now on all error paths must use 'goto cleanup' */ + /* from now on all error paths must use 'goto error' which restores th= e original state */ /* based on which is the current 'effecitve' layer we must reopen the * appropriate blockdev */ if (qemuBlockStorageSourceGetFormatNodename(src)) { if (!(srcprops =3D qemuBlockStorageSourceGetFormatProps(src, src->= backingStore))) - return -1; + goto error; } else if (qemuBlockStorageSourceGetSliceNodename(src)) { if (!(srcprops =3D qemuBlockStorageSourceGetBlockdevStorageSlicePr= ops(src, true, false))) - return -1; + goto error; } else { if (!(srcprops =3D qemuBlockStorageSourceGetBackendProps(src, QEMU_BLOCK_= STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE))) - return -1; + goto error; } if (virJSONValueArrayAppend(reopenoptions, &srcprops) < 0) - return -1; + goto error; if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) - goto cleanup; + goto error; rc =3D qemuMonitorBlockdevReopen(qemuDomainGetMonitor(vm), &reopenopti= ons); qemuDomainObjExitMonitor(vm); if (rc < 0) - goto cleanup; + goto error; - ret =3D 0; + return 0; - cleanup: + error: src->readonly =3D !readonly; - return ret; + return -1; } --=20 2.47.0