From nobody Tue Dec 16 18:34:34 2025 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1743166430; cv=none; d=zohomail.com; s=zohoarc; b=epSAbgjsM2Hb9fLzsVhC9yc16k5TGkc6K2ueGWydtb8GIQLMstIYNj6umSwLdRgaphJSHaRrw2l2JEhM44XwGSYKec6BOPs/NRSMrzxZ1afKEqVEedF8abPrPgJ6i7S8J1UhzZoU3R4EN2c8Ifzf8IA3Ev3SlVDZ0rDuGbb6e0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743166430; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=c+Z7zBgRK5iVdW4J89SNygMuOOzKihvN/lYpirzrlfA=; b=fRk4abmBHFC/0PqpODW7EEWBwzO3HMLbZ+jtvRSb5rroMNZLfcnLkx6XMays5Boqs6VdwlAz4l1pDLpVCTr2NxkitgA80LwSVq1DzW7FrJQDPFCxyj4sOEpE91t5cwO0RNqlft2mhnpkOMeAPIJt+KdsAeayZno18wSWZTliQIM= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1743166430639913.7235888390888; Fri, 28 Mar 2025 05:53:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1120A132E; Fri, 28 Mar 2025 08:53:50 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2A91E1283; Fri, 28 Mar 2025 08:52:50 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 875651254; Fri, 28 Mar 2025 08:52:45 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 06C9911F8 for ; Fri, 28 Mar 2025 08:52:45 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-458-qbBCH3nyPyC7hqyaf1p3Hg-1; Fri, 28 Mar 2025 08:52:42 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52EC71800A3B for ; Fri, 28 Mar 2025 12:52:41 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.8]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 50A38180174E; Fri, 28 Mar 2025 12:52:40 +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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,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=1743166364; 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=7WY5ILqaheKPlcRH8wgetwVoyWZr9DW/PRL3fari/OQ=; b=XJsO1D808tgIBeMQGPc+dOW/dXM5bRHctbMsuJslnf/NyFlxMfRktS/eZMhEBa4UsZe5jW 3saN1XFwt1ukGzGJeKU9G94tdUWSMKnzeTRo3RyVxRH8rBg962OC+i0VCz/wDTNDuBvTVk JlHEKfyUkPn98IygyfLEf6LqToedKQE= X-MC-Unique: qbBCH3nyPyC7hqyaf1p3Hg-1 X-Mimecast-MFC-AGG-ID: qbBCH3nyPyC7hqyaf1p3Hg_1743166361 To: devel@lists.libvirt.org Subject: [PATCH 2/8] virDomainStorageNetworkParseHost: Refactor cleanup Date: Fri, 28 Mar 2025 13:52:28 +0100 Message-ID: <73619c087f12d4a1a8ba73fe31c93b76527eb46e.1743166287.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PyZ7J5YSCfc3G87QaroC2uchycRc5Ow3puCQGiYok7g_1743166361 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LL6J3IYIBOVA5WD2R7F4X3IAIUJ3PQRW X-Message-ID-Hash: LL6J3IYIBOVA5WD2R7F4X3IAIUJ3PQRW 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 CC: Peter Krempa 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743166431676019000 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Use a 'switch' statement instead of a bunch of if statements to do validation and selection what to parse. Remove the pre-clearing of the struct as we always alocate cleared memory for it and we can reorder assignments to avoid the need for cleanup. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 68 ++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 53ab502306..1680da3ea6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6016,55 +6016,59 @@ int virDomainStorageNetworkParseHost(xmlNodePtr hostnode, virStorageNetHostDef *host) { - int ret =3D -1; - g_autofree char *port =3D NULL; - - memset(host, 0, sizeof(*host)); + g_autofree char *socket =3D NULL; if (virXMLPropEnumDefault(hostnode, "transport", virStorageNetHostTransportTypeFromString, VIR_XML_PROP_NONE, &host->transport, - VIR_STORAGE_NET_HOST_TRANS_TCP) < 0) { - goto cleanup; - } + VIR_STORAGE_NET_HOST_TRANS_TCP) < 0) + return -1; - host->socket =3D virXMLPropString(hostnode, "socket"); + socket =3D virXMLPropString(hostnode, "socket"); - if (host->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host->socket =3D=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing socket for unix transport")); - goto cleanup; - } + switch (host->transport) { + case VIR_STORAGE_NET_HOST_TRANS_UNIX: + if (!socket) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing socket for unix transport")); + return -1; + } - if (host->transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host->socket !=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, - _("transport '%1$s' does not support socket attribu= te"), - virStorageNetHostTransportTypeToString(host->transp= ort)); - goto cleanup; - } + host->socket =3D g_steal_pointer(&socket); + break; + + case VIR_STORAGE_NET_HOST_TRANS_TCP: + case VIR_STORAGE_NET_HOST_TRANS_RDMA: { + g_autofree char *portstr =3D NULL; + unsigned int port =3D 0; + + if (socket) { + virReportError(VIR_ERR_XML_ERROR, + _("transport '%1$s' does not support socket att= ribute"), + virStorageNetHostTransportTypeToString(host->tr= ansport)); + return -1; + } + + if ((portstr =3D virXMLPropString(hostnode, "port")) && + virStringParsePort(portstr, &port) < 0) + return -1; - if (host->transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { if (!(host->name =3D virXMLPropString(hostnode, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for host")); - goto cleanup; + return -1; } - if ((port =3D virXMLPropString(hostnode, "port"))) { - if (virStringParsePort(port, &host->port) < 0) - goto cleanup; - } + host->port =3D port; } + break; - ret =3D 0; + case VIR_STORAGE_NET_HOST_TRANS_LAST: + break; + } - cleanup: - if (ret < 0) - virStorageNetHostDefClear(host); - return ret; + return 0; } --=20 2.49.0