From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575453352; cv=none; d=zohomail.com; s=zohoarc; b=iyXFdsxOUjcY/YFB1GLL2bft6fWdiERRc0t3GKjabObuT20dMHvn8ioy+ZRgcJH1hTXky8+97JFMUWOxnuc0if7Ecm+8CiNB2OPYdUgrd0HsswS1obMaD441EJSm9AoIvUTvIkPtNxaLCpv+EUheyQnJgSANQLcu8nTQFyd9yG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453352; h=Content-Type:Content-Transfer-Encoding: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=DCCuULFkTho0WNGF3kF8mOpIumGLjmoU+y47Z+X87H8=; b=JsBhzhYNWK8quQxGXPWotEt0+rExYphJfQwhpT4Wgu7KTmUxOJHSxbO758UwKYWVmcduCl7UbMDTwssY1JRxZ/oojhFABMyd1WkbMrrliQCnvNnpVHz+QkM04Z5IhfvanF5R5F5I93SxVmA6p83EL8yOgqSoHRT53idm4KGfLg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1575453352182414.0931710493909; Wed, 4 Dec 2019 01:55:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-366-lyZDo1-9MXKznRq9GZ8FGA-1; Wed, 04 Dec 2019 04:55:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F910188BFD1; Wed, 4 Dec 2019 09:55:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DAAF5C883; Wed, 4 Dec 2019 09:55:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C8CF918089C8; Wed, 4 Dec 2019 09:55:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tdEm023712 for ; Wed, 4 Dec 2019 04:55:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id C5B7B5DA7D; Wed, 4 Dec 2019 09:55:39 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D3805DA32 for ; Wed, 4 Dec 2019 09:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453351; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=DCCuULFkTho0WNGF3kF8mOpIumGLjmoU+y47Z+X87H8=; b=ISLIjmEyyDpTp4u0pdsn9RlO2FCSYtTj9XKM8G4WkJh3Zyyohg/fN9ggaxnB8PM7Y8m9HX NrPIqdgC6AENB/zyQEiC4yXV0q0G+CInpG8/HOCqxBhURgL1NRJJiLncldfXrZ61eUFk8L 0ji9vBvFdKlaNqp9l7pGDMl3x2Xexb8= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:26 +0100 Message-Id: <38d11289c735ad3ccd8af54e4966cc343f16e9d3.1575453027.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/9] qemu_driver: Push qemuDomainInterfaceAddresses() a few lines down X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: lyZDo1-9MXKznRq9GZ8FGA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" If we place qemuDomainInterfaceAddresses() a few lines below the two functions its using then we can drop forward declarations of those functions. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_driver.c | 125 ++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 65 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1911073f3e..1b9d6d16a1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -151,13 +151,6 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t fa= llback_gid, const char *path, int oflags, bool *needUnlink); =20 -static int qemuGetDHCPInterfaces(virDomainPtr dom, - virDomainObjPtr vm, - virDomainInterfacePtr **ifaces); - -static int qemuARPGetInterfaces(virDomainObjPtr vm, - virDomainInterfacePtr **ifaces); - static virQEMUDriverPtr qemu_driver; =20 /* Looks up the domain object from snapshot and unlocks the @@ -21554,64 +21547,6 @@ qemuDomainGetFSInfo(virDomainPtr dom, return ret; } =20 -static int -qemuDomainInterfaceAddresses(virDomainPtr dom, - virDomainInterfacePtr **ifaces, - unsigned int source, - unsigned int flags) -{ - virQEMUDriverPtr driver =3D dom->conn->privateData; - virDomainObjPtr vm =3D NULL; - qemuAgentPtr agent; - int ret =3D -1; - - virCheckFlags(0, -1); - - if (!(vm =3D qemuDomainObjFromDomain(dom))) - goto cleanup; - - if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0) - goto cleanup; - - if (virDomainObjCheckActive(vm) < 0) - goto cleanup; - - switch (source) { - case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE: - ret =3D qemuGetDHCPInterfaces(dom, vm, ifaces); - break; - - case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT: - if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) <= 0) - goto cleanup; - - if (!qemuDomainAgentAvailable(vm, true)) - goto endjob; - - agent =3D qemuDomainObjEnterAgent(vm); - ret =3D qemuAgentGetInterfaces(agent, ifaces); - qemuDomainObjExitAgent(vm, agent); - - endjob: - qemuDomainObjEndAgentJob(vm); - - break; - - case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP: - ret =3D qemuARPGetInterfaces(vm, ifaces); - break; - - default: - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, - _("Unknown IP address data source %d"), - source); - break; - } - - cleanup: - virDomainObjEndAPI(&vm); - return ret; -} =20 static int qemuGetDHCPInterfaces(virDomainPtr dom, @@ -21764,6 +21699,66 @@ qemuARPGetInterfaces(virDomainObjPtr vm, } =20 =20 +static int +qemuDomainInterfaceAddresses(virDomainPtr dom, + virDomainInterfacePtr **ifaces, + unsigned int source, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D dom->conn->privateData; + virDomainObjPtr vm =3D NULL; + qemuAgentPtr agent; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + goto cleanup; + + if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + switch (source) { + case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE: + ret =3D qemuGetDHCPInterfaces(dom, vm, ifaces); + break; + + case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT: + if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) <= 0) + goto cleanup; + + if (!qemuDomainAgentAvailable(vm, true)) + goto endjob; + + agent =3D qemuDomainObjEnterAgent(vm); + ret =3D qemuAgentGetInterfaces(agent, ifaces); + qemuDomainObjExitAgent(vm, agent); + + endjob: + qemuDomainObjEndAgentJob(vm); + + break; + + case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP: + ret =3D qemuARPGetInterfaces(vm, ifaces); + break; + + default: + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, + _("Unknown IP address data source %d"), + source); + break; + } + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int qemuDomainSetUserPassword(virDomainPtr dom, const char *user, --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575453423; cv=none; d=zohomail.com; s=zohoarc; b=dbMJ7euzAlw5UH7krUTJdWmTPfr4dXq2csKwzPtMfbNQguv9prZx+x1iYktsTCW/q8+rAQOujboe/F+/o65tGWzH0MPpTjXXLg0/RFp6fZQozLThwbZWRlNMftrQIEDm56I4t8IpCE+9hXkC9BeFoUxludjsJcudXj2noAgVQ1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453423; h=Content-Type:Content-Transfer-Encoding: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=YspEvakT1IZDKGwejbIOX72ubxbq4WMmYa6MzwPIT5Q=; b=a5EjK7MP8UkYlHxXiYlaDKjSVrl9b7jr+glWEGR5lHHm92ykISqV2Zmhw4FAO1bGEAIjeWIGQ2PgQd+qBqMJjcTOkIhfzX8cZLKgWgJL0Am6Qv2MV1HwyRa1qfP3NlnWPmI+Iwfe1PBv9rRyYGDMS/VXwOZ7ODoRxE2/nXit62c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575453423536117.90060305505551; Wed, 4 Dec 2019 01:57:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-VQC2b9r0NnuurwLitSTjLA-1; Wed, 04 Dec 2019 04:55:57 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EC3D8BFCFF; Wed, 4 Dec 2019 09:55:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65D004AF; Wed, 4 Dec 2019 09:55:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 27CB418089CF; Wed, 4 Dec 2019 09:55:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tgJQ023731 for ; Wed, 4 Dec 2019 04:55:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id E24A75DA7E; Wed, 4 Dec 2019 09:55:42 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A2575DA7D for ; Wed, 4 Dec 2019 09:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453422; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YspEvakT1IZDKGwejbIOX72ubxbq4WMmYa6MzwPIT5Q=; b=GNJ3XbsmvF3mNBbUY6Zo3J/kV/qBE2TOzuBK8eyolgfcFNA7g0JEtDm598qNaawzIciDpx ooaVSWLabFSfESOUH6Ta1+UiXZCsj3MFq6TgfJ9FNNKe1/iRADFya/NuACanEKXDS013/r S9T8hi/H24ocPlAG9bZc5vwEjvc2y+U= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:27 +0100 Message-Id: <8b433f971a7aee2fa11e76a4e8d1afd0e7060001.1575453027.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/9] qemu: Don't use dom->conn to lookup virNetwork X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: VQC2b9r0NnuurwLitSTjLA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When using the monolithic daemon, then dom->conn has all driver tables filled in properly and thus it's safe to call an API other than virDomain*(). However, when using split daemons then dom->conn has only hypervisor driver table set (dom->conn->driver) and the rest is NULL. Therefore, if we want to call a non-domain API (virNetworkLookupByName() in this case), we have obtain the cached connection object accessible via virGetConnectNetwork(). Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_driver.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1b9d6d16a1..e5be74c461 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21549,10 +21549,10 @@ qemuDomainGetFSInfo(virDomainPtr dom, =20 =20 static int -qemuGetDHCPInterfaces(virDomainPtr dom, - virDomainObjPtr vm, +qemuGetDHCPInterfaces(virDomainObjPtr vm, virDomainInterfacePtr **ifaces) { + g_autoptr(virConnect) conn =3D NULL; int rv =3D -1; int n_leases =3D 0; size_t i, j; @@ -21563,21 +21563,20 @@ qemuGetDHCPInterfaces(virDomainPtr dom, virNetworkDHCPLeasePtr *leases =3D NULL; virDomainInterfacePtr *ifaces_ret =3D NULL; =20 - if (!dom->conn->networkDriver || - !dom->conn->networkDriver->networkGetDHCPLeases) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Network driver does not support DHCP lease query= ")); + if (!(conn =3D virGetConnectNetwork())) return -1; - } =20 for (i =3D 0; i < vm->def->nnets; i++) { if (vm->def->nets[i]->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) continue; =20 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr); + virObjectUnref(network); - network =3D virNetworkLookupByName(dom->conn, + network =3D virNetworkLookupByName(conn, vm->def->nets[i]->data.network.na= me); + if (!network) + goto error; =20 if ((n_leases =3D virNetworkGetDHCPLeases(network, macaddr, &leases, 0)) < 0) @@ -21723,7 +21722,7 @@ qemuDomainInterfaceAddresses(virDomainPtr dom, =20 switch (source) { case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE: - ret =3D qemuGetDHCPInterfaces(dom, vm, ifaces); + ret =3D qemuGetDHCPInterfaces(vm, ifaces); break; =20 case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT: --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1575453366; cv=none; d=zohomail.com; s=zohoarc; b=VLmtCpZGeer5RROsjTM2VS5pOAMFtu+wwiJVf7WfDIjHBhIZG5uPEbg0org6q6y07hCIm3KnN2/PUGqfiUw5Td62JrKbs0GBPw0Iz8lFq5QFITno6HyWdjIA+I9zY+IWgMZ2JIuhwC8KyfDv6yylSExAGVsNt3EH3tbvlWGLsuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453366; h=Content-Type:Content-Transfer-Encoding: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=Ny77mx8kkVt3QTE3b5xMmfQblCphvQ5d4SwdT1eiRvw=; b=lNaJl1qs9ppY7U83bhPi3OklvKSlvyvqX5u8CY9b3kog37X/BRzx6HvvjPX0pOs9aGtNSZOv74ls+K/Zppy/iF+aRfvldi4Mz3q6UYG+VB1PtZWK5SOzFpVHJ9QOvoq5cPs662NmQ9TESrdjxtyKm2Nct4mRvhZLHT8/pMSCByA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1575453366093790.1330671296754; Wed, 4 Dec 2019 01:56:06 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-39sGL4zCPKKkGsEqdQ223Q-1; Wed, 04 Dec 2019 04:56:01 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2CEFB8C052B; Wed, 4 Dec 2019 09:55:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02CE210375D5; Wed, 4 Dec 2019 09:55:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ABC9A18089D6; Wed, 4 Dec 2019 09:55:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49thxw023738 for ; Wed, 4 Dec 2019 04:55:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id B2B6D5DA70; Wed, 4 Dec 2019 09:55:43 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B73E5DA7D for ; Wed, 4 Dec 2019 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453363; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ny77mx8kkVt3QTE3b5xMmfQblCphvQ5d4SwdT1eiRvw=; b=DLXjapwxyOy+saMyTvFxBCthX4sn1ym9K5XUm9Im6Gnw1dvqx77SYqbkjA8DdJ/5XPEOKT PDHwmMOamoWmRzEFfmpCIuXMw7d8lnc6RYaPN3AIGOP7gZ9A5OeTS07GKh8NnxclcjM+Rp vNUueQRTZYnoN8GRbws+OuEl1W5pZnY= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:28 +0100 Message-Id: <5029304f2a2a95ca77c33ee7b9ccf72c757e8d70.1575453027.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/9] qemuGetDHCPInterfaces: Move some variables inside the loop X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 39sGL4zCPKKkGsEqdQ223Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some variables are not used outside of the for() loop. Move their declaration to clean up the code a bit. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_driver.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e5be74c461..2bc2081d0b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21553,26 +21553,27 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm, virDomainInterfacePtr **ifaces) { g_autoptr(virConnect) conn =3D NULL; + virDomainInterfacePtr *ifaces_ret =3D NULL; + size_t ifaces_count =3D 0; int rv =3D -1; int n_leases =3D 0; - size_t i, j; - size_t ifaces_count =3D 0; - g_autoptr(virNetwork) network =3D NULL; - char macaddr[VIR_MAC_STRING_BUFLEN]; - virDomainInterfacePtr iface =3D NULL; virNetworkDHCPLeasePtr *leases =3D NULL; - virDomainInterfacePtr *ifaces_ret =3D NULL; + size_t i; =20 if (!(conn =3D virGetConnectNetwork())) return -1; =20 for (i =3D 0; i < vm->def->nnets; i++) { + g_autoptr(virNetwork) network =3D NULL; + char macaddr[VIR_MAC_STRING_BUFLEN]; + virDomainInterfacePtr iface =3D NULL; + size_t j; + if (vm->def->nets[i]->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) continue; =20 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr); =20 - virObjectUnref(network); network =3D virNetworkLookupByName(conn, vm->def->nets[i]->data.network.na= me); if (!network) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575453375; cv=none; d=zohomail.com; s=zohoarc; b=TtQo6vdcnFR/wHBIwyFZ1acDuoUAhfngH1NTyfEocsLILfktILSzF9A5jRLWtI7ve5J9qTbL/Gq2Bgw7PfspeLAdApYbv5J2yotY3UfS4EGAKsVgKM5HB/9EZeLGBVwlYUeFuOex6PonwBNSRnFQID6ZJGhN3ydxLv+CcMsfNSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453375; h=Content-Type:Content-Transfer-Encoding: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=7STID+xWWcwFWO3uPE+vJPmu7IbD0i9df3veGcdE1q4=; b=XAzzzBDPXuNMEzndzxa3aO1gTlfW7GNdHdnpI9yeTsqwIsGeKuP++vYqy6KWZepkVd3CRHL0JQR9jCG6L7tKu4EgMNp+pbFv5kyS5tdO6aWtQtBK6vz5NJXIeL4F2SqmFTuNtmabzmegfMWNgK3ERCiNsPa8dA/WaQdmLO9l2IM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 157545337505754.38586497183417; Wed, 4 Dec 2019 01:56:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-I8S60KRuNLew8-8ALZMY3w-1; Wed, 04 Dec 2019 04:56:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8D8A184CE81; Wed, 4 Dec 2019 09:56:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B841260FC4; Wed, 4 Dec 2019 09:56:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5C33718089D8; Wed, 4 Dec 2019 09:56:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tjlP023750 for ; Wed, 4 Dec 2019 04:55:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0B9345DA70; Wed, 4 Dec 2019 09:55:45 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 881125DA7F for ; Wed, 4 Dec 2019 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453373; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7STID+xWWcwFWO3uPE+vJPmu7IbD0i9df3veGcdE1q4=; b=YBq//WkweS5gZfnv8ZkUMzfWBG1tDBWtPyjlGN3aWy+E7CO4lQfxgDkbVkXq4C01MDnjWl GK8EE9JvbyQ+5lOLPxxhf9DGgDnC8DnCUqw0y89RXS7QKZI/I1WvWZpJ8rgik/7k5rsIPA 24u0JemKIu5x4qoLIt6N/LAPpyTFtTc= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:29 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/9] qemuGetDHCPInterfaces: Switch to GLib X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: I8S60KRuNLew8-8ALZMY3w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" If we use glib alloc functions, we can drop the 'cleanup' label and @rv variable and also simplify the code a bit. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/qemu/qemu_driver.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2bc2081d0b..2d2a83cd8b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -21555,9 +21555,6 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm, g_autoptr(virConnect) conn =3D NULL; virDomainInterfacePtr *ifaces_ret =3D NULL; size_t ifaces_count =3D 0; - int rv =3D -1; - int n_leases =3D 0; - virNetworkDHCPLeasePtr *leases =3D NULL; size_t i; =20 if (!(conn =3D virGetConnectNetwork())) @@ -21566,6 +21563,8 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm, for (i =3D 0; i < vm->def->nnets; i++) { g_autoptr(virNetwork) network =3D NULL; char macaddr[VIR_MAC_STRING_BUFLEN]; + virNetworkDHCPLeasePtr *leases =3D NULL; + int n_leases =3D 0; virDomainInterfacePtr iface =3D NULL; size_t j; =20 @@ -21584,21 +21583,15 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm, goto error; =20 if (n_leases) { - if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0) - goto error; - - if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0) - goto error; + ifaces_ret =3D g_renew(typeof(*ifaces_ret), ifaces_ret, ifaces= _count + 1); + ifaces_ret[ifaces_count] =3D g_new0(typeof(**ifaces_ret), 1); + iface =3D ifaces_ret[ifaces_count]; + ifaces_count++; =20 - iface =3D ifaces_ret[ifaces_count - 1]; /* Assuming each lease corresponds to a separate IP */ iface->naddrs =3D n_leases; - - if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0) - goto error; - + iface->addrs =3D g_new0(typeof(*iface->addrs), iface->naddrs); iface->name =3D g_strdup(vm->def->nets[i]->ifname); - iface->hwaddr =3D g_strdup(macaddr); } =20 @@ -21607,28 +21600,17 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm, virDomainIPAddressPtr ip_addr =3D &iface->addrs[j]; =20 ip_addr->addr =3D g_strdup(lease->ipaddr); - ip_addr->type =3D lease->type; ip_addr->prefix =3D lease->prefix; - } =20 - for (j =3D 0; j < n_leases; j++) - virNetworkDHCPLeaseFree(leases[j]); + virNetworkDHCPLeaseFree(lease); + } =20 VIR_FREE(leases); } =20 *ifaces =3D g_steal_pointer(&ifaces_ret); - rv =3D ifaces_count; - - cleanup: - if (leases) { - for (i =3D 0; i < n_leases; i++) - virNetworkDHCPLeaseFree(leases[i]); - } - VIR_FREE(leases); - - return rv; + return ifaces_count; =20 error: if (ifaces_ret) { @@ -21637,7 +21619,7 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm, } VIR_FREE(ifaces_ret); =20 - goto cleanup; + return -1; } =20 =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1575453423; cv=none; d=zohomail.com; s=zohoarc; b=QlW36XB2v85Cf1jBE54SnVsaB50tnTBNNv6lQ5c47ApFjEWL9nj8TxVf7O+Hvim5FPZtCxmHT9YyfxmGMYsMFTVc46aFB3RhHjlYEw42+KIzCzE0bdrSfT7eBGubUwswvFfsnkab8b4i7csUDKWkIsWkCY6GtAOTTVdLXyZ6Z2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453423; h=Content-Type:Content-Transfer-Encoding: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=tNk+HRD9Dw48sEsA5T5gjT0OdPOXYAO587FNTG6Zu80=; b=hpUDxQyq1ULyGB/eJg8/IUg9MMfX9B6WiCxYiY7nn3HxJGeGDbM3qA0qjxdNBDRwC9Ch7otBIl2EJpuRMfDrWMgapiTYS6bd9dNtFJSPuo1Uz9EhMba6U6Ceo5RWC0ZvZvrSOGb1rqOGIq38aYnUjvrMJurLKcie5GIW8JlT56U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1575453423358486.0669967272272; Wed, 4 Dec 2019 01:57:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-FcAsUDZGPLCbjQxvoiGtng-1; Wed, 04 Dec 2019 04:56:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A8E991083A51; Wed, 4 Dec 2019 09:56:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 802CD60F8D; Wed, 4 Dec 2019 09:56:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3E53D180880B; Wed, 4 Dec 2019 09:56:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tjG2023760 for ; Wed, 4 Dec 2019 04:55:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id CF4555DA7B; Wed, 4 Dec 2019 09:55:45 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57DEC5DA70 for ; Wed, 4 Dec 2019 09:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453422; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tNk+HRD9Dw48sEsA5T5gjT0OdPOXYAO587FNTG6Zu80=; b=hSDN0Yf4aX+ryJD4CFo+vThmI+Fr3+DaTeq2RrFKXbZYVxFu6JVXk7n4LHWOMwuzpJOFh5 0IQ9xQR+9D9woZgBcLgWZiVeguoantXCx54qNThOCoSKkJh7VGkZT+Y5cIoIcTY+ixTRjF Y2ga+OLbnfFOLuAAm/KoP6aL7QNztcI= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:30 +0100 Message-Id: <6b0c88f2267c0d4ef1565431b04ebe4cc995fc49.1575453027.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/9] libxl: Don't use dom->conn to lookup virNetwork X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: FcAsUDZGPLCbjQxvoiGtng-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When using the monolithic daemon, then dom->conn has all driver tables filled in properly and thus it's safe to call an API other than virDomain*(). However, when using split daemons then dom->conn has only hypervisor driver table set (dom->conn->driver) and the rest is NULL. Therefore, if we want to call a non-domain API (virNetworkLookupByName() in this case), we have obtain the cached connection object accessible via virGetConnectNetwork(). Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/libxl/libxl_driver.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 44a74e8779..ccef4f3955 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -6235,10 +6235,10 @@ static int libxlNodeGetSecurityModel(virConnectPtr = conn, } =20 static int -libxlGetDHCPInterfaces(virDomainPtr dom, - virDomainObjPtr vm, +libxlGetDHCPInterfaces(virDomainObjPtr vm, virDomainInterfacePtr **ifaces) { + g_autoptr(virConnect) conn =3D NULL; int rv =3D -1; int n_leases =3D 0; size_t i, j; @@ -6249,12 +6249,8 @@ libxlGetDHCPInterfaces(virDomainPtr dom, virNetworkDHCPLeasePtr *leases =3D NULL; virDomainInterfacePtr *ifaces_ret =3D NULL; =20 - if (!dom->conn->networkDriver || - !dom->conn->networkDriver->networkGetDHCPLeases) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Network driver does not support DHCP lease query= ")); + if (!(conn =3D virGetConnectNetwork())) return -1; - } =20 for (i =3D 0; i < vm->def->nnets; i++) { if (vm->def->nets[i]->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) @@ -6262,8 +6258,10 @@ libxlGetDHCPInterfaces(virDomainPtr dom, =20 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr); virObjectUnref(network); - network =3D virNetworkLookupByName(dom->conn, + network =3D virNetworkLookupByName(conn, vm->def->nets[i]->data.network.na= me); + if (!network) + goto error; =20 if ((n_leases =3D virNetworkGetDHCPLeases(network, macaddr, &leases, 0)) < 0) @@ -6351,7 +6349,7 @@ libxlDomainInterfaceAddresses(virDomainPtr dom, =20 switch (source) { case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE: - ret =3D libxlGetDHCPInterfaces(dom, vm, ifaces); + ret =3D libxlGetDHCPInterfaces(vm, ifaces); break; =20 default: --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575453357; cv=none; d=zohomail.com; s=zohoarc; b=jKV4lOeBBeqalw8RTqPgzU/NdFFa+H/IoHWgeidrKv9UkrR3tbai4iKz7t9JQMnw1hmpjFjNzs10oELjQJwo41Hy4lbMTKnW/QJ4TgDbb7EPAikGpVZMkH2Ajniei9El0F9/vIDAm7lz7teUn0pgJjdpXtwyAAGJY7/On7/yaGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453357; h=Content-Type:Content-Transfer-Encoding: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=oKJkkVCOJlc+iToheEerECWEBRgg7DjCoowMlp8f9Pk=; b=GevvU6gcCwAESbyK7fwPkuyBuILtRUZRYrhT3cF1o2dyug3ejefYYAZpm2fpOecUhazTBwKykXsOaO9QYyU7d3TpTq4OuVDllbormJDEHjbVEHEYVuA4lMy8t4msRKrXmfM5asKeDm1Nbafjo4a8MrnnYSRP6Wlksj8E8NYl6uY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575453357153979.4464660523413; Wed, 4 Dec 2019 01:55:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-241-DNxAfFRPMVq3cMFp30oYCw-1; Wed, 04 Dec 2019 04:55:54 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B6D8101F7F0; Wed, 4 Dec 2019 09:55:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1495A5DA76; Wed, 4 Dec 2019 09:55:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 82F595BC10; Wed, 4 Dec 2019 09:55:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tkn1023771 for ; Wed, 4 Dec 2019 04:55:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9EB5B5DA7B; Wed, 4 Dec 2019 09:55:46 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27A7D5DA70 for ; Wed, 4 Dec 2019 09:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453356; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=oKJkkVCOJlc+iToheEerECWEBRgg7DjCoowMlp8f9Pk=; b=cEeSz2k0kCAuw4M7EJyI56VN6qQ9+uT/Uz3bbYtzLZtWGz0ibxfADHysINJO/GS0YIPLtv A7/iOsvsyk9btTSP5pTVNUhd4ZmVWHQ0pKw+W+1SzYvp1ah0lkq8bQ4I7eUqohmCdd3+8L xQbQZTd2qBFHOmLyjOietx6mmbUx6og= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/9] libxlGetDHCPInterfaces: Move some variables inside the loop X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: DNxAfFRPMVq3cMFp30oYCw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Some variables are not used outside of the for() loop. Move their declaration to clean up the code a bit. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/libxl/libxl_driver.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index ccef4f3955..6064436681 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -6239,25 +6239,27 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, virDomainInterfacePtr **ifaces) { g_autoptr(virConnect) conn =3D NULL; + virDomainInterfacePtr *ifaces_ret =3D NULL; + size_t ifaces_count =3D 0; int rv =3D -1; int n_leases =3D 0; - size_t i, j; - size_t ifaces_count =3D 0; - virNetworkPtr network =3D NULL; - char macaddr[VIR_MAC_STRING_BUFLEN]; - virDomainInterfacePtr iface =3D NULL; virNetworkDHCPLeasePtr *leases =3D NULL; - virDomainInterfacePtr *ifaces_ret =3D NULL; + size_t i; =20 if (!(conn =3D virGetConnectNetwork())) return -1; =20 for (i =3D 0; i < vm->def->nnets; i++) { + g_autoptr(virNetwork) network =3D NULL; + char macaddr[VIR_MAC_STRING_BUFLEN]; + virDomainInterfacePtr iface =3D NULL; + size_t j; + if (vm->def->nets[i]->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) continue; =20 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr); - virObjectUnref(network); + network =3D virNetworkLookupByName(conn, vm->def->nets[i]->data.network.na= me); if (!network) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575453361; cv=none; d=zohomail.com; s=zohoarc; b=Hj75OxYY5Zgf/uXzVhgnVcs0lDd3k0ilk3KrKZrF9cKL9uoRShH3lyDoLrCajFJw014TPTjwpJkSkQpcBi2qQ1pWNnsbI9cFlsp2zdy8QnvkBbpOmz2BHLBLFOwNqK3OsJSH5WLH2WUIvY2tdDhZ5PCYhRANwnGJp2uBduMp9Lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453361; h=Content-Type:Content-Transfer-Encoding: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=FneD+QNfGI46RNMuRPE1N0p5gs7ljD8O7+xFSdLI6RA=; b=M/meRPgUfuVRW41qvhuANYZCrw5LE7VZCE5aAbzrhj9GwGe8CipjzEYvI/7DVFzsXV0H0S8vSbfVoIjG6wZySKovrBFWPRlwit/DLf3Jb02eC1lpsZFMJ8AzK87Z8bD3tS4Na5k1PFRjvmSPIw08h7Fmhefbsc7CyJAdlQk8MW0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1575453361548740.8088683805432; Wed, 4 Dec 2019 01:56:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-xOhvK2UIObyXctssGQGf8w-1; Wed, 04 Dec 2019 04:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88CE6189F964; Wed, 4 Dec 2019 09:55:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FA865DA76; Wed, 4 Dec 2019 09:55:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1EA455BC14; Wed, 4 Dec 2019 09:55:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tlYj023777 for ; Wed, 4 Dec 2019 04:55:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 765C45DE53; Wed, 4 Dec 2019 09:55:47 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB8ED5DA70 for ; Wed, 4 Dec 2019 09:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453360; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FneD+QNfGI46RNMuRPE1N0p5gs7ljD8O7+xFSdLI6RA=; b=HpD7OosMfDAM2+trHgLZ3pWsnonQtn/lB+e8yEccjfbCAQ3E9RLEBgHCpA2+Sj/Z3DJzoH ZvjAKIZ2Ulk94G8w+NyjICyL25imLNBoq6pgyTFVYRp3GoI+mfoinKHA7ipy+X6RBrMsPo 8Uk1KflZ5Hy3HgdtuXegkNtdOuSl16U= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:32 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/9] libxlGetDHCPInterfaces: Switch to GLib X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: xOhvK2UIObyXctssGQGf8w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" If we use glib alloc functions, we can drop the 'cleanup' label and @rv variable and also simplify the code a bit. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/libxl/libxl_driver.c | 41 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 6064436681..7467111618 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -6241,9 +6241,6 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, g_autoptr(virConnect) conn =3D NULL; virDomainInterfacePtr *ifaces_ret =3D NULL; size_t ifaces_count =3D 0; - int rv =3D -1; - int n_leases =3D 0; - virNetworkDHCPLeasePtr *leases =3D NULL; size_t i; =20 if (!(conn =3D virGetConnectNetwork())) @@ -6252,6 +6249,8 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, for (i =3D 0; i < vm->def->nnets; i++) { g_autoptr(virNetwork) network =3D NULL; char macaddr[VIR_MAC_STRING_BUFLEN]; + virNetworkDHCPLeasePtr *leases =3D NULL; + int n_leases =3D 0; virDomainInterfacePtr iface =3D NULL; size_t j; =20 @@ -6270,21 +6269,16 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, goto error; =20 if (n_leases) { - if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0) - goto error; + ifaces_ret =3D g_renew(typeof(*ifaces_ret), ifaces_ret, ifaces= _count + 1); + ifaces_ret[ifaces_count] =3D g_new0(typeof(**ifaces_ret), 1); + iface =3D ifaces_ret[ifaces_count]; + ifaces_count++; =20 - if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0) - goto error; - - iface =3D ifaces_ret[ifaces_count - 1]; /* Assuming each lease corresponds to a separate IP */ iface->naddrs =3D n_leases; =20 - if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0) - goto error; - + iface->addrs =3D g_new0(typeof(*iface->addrs), iface->naddrs); iface->name =3D g_strdup(vm->def->nets[i]->ifname); - iface->hwaddr =3D g_strdup(macaddr); } =20 @@ -6293,30 +6287,17 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, virDomainIPAddressPtr ip_addr =3D &iface->addrs[j]; =20 ip_addr->addr =3D g_strdup(lease->ipaddr); - ip_addr->type =3D lease->type; ip_addr->prefix =3D lease->prefix; - } =20 - for (j =3D 0; j < n_leases; j++) virNetworkDHCPLeaseFree(leases[j]); + } =20 VIR_FREE(leases); } =20 - *ifaces =3D ifaces_ret; - ifaces_ret =3D NULL; - rv =3D ifaces_count; - - cleanup: - virObjectUnref(network); - if (leases) { - for (i =3D 0; i < n_leases; i++) - virNetworkDHCPLeaseFree(leases[i]); - } - VIR_FREE(leases); - - return rv; + *ifaces =3D g_steal_pointer(&ifaces_ret); + return ifaces_count; =20 error: if (ifaces_ret) { @@ -6325,7 +6306,7 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, } VIR_FREE(ifaces_ret); =20 - goto cleanup; + return -1; } =20 =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1575453383; cv=none; d=zohomail.com; s=zohoarc; b=L2h5xBcBsIKmr9rUtArmBOcSAWA0eFvAuxgT+kXLPG5x6lFspWNRZB/cU/28hMcd41tMtlmz/QKWGxPtBHIWuWHjdlmsgmp3itI/flAriD9Br3moMRMlBgP/4p6RINEJdtAMh+N9j5Lkz+e6CafPG0S4HSRvfoSomGm3SCwbBGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453383; h=Content-Type:Content-Transfer-Encoding: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=qaUBm4GDidh9W8wA69sBV+iXysDwidhxneB4xMK/OUk=; b=QPQ1TboCXJXUhQHjxxWg23acaTP5i1t+oxPbXdE1FgsvZ7BKvRCoYPYEpBfQSc2p5VAG+4w/zikbYF72RjeIjDXNe1Q89shqWxYmefiuZ30y65uUUf52UJOeDhgYMseIhJSmCa/sur7T8rzSDGzkWHdz2/G6Egnkw+5fiK+XfqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575453383061521.3817349943151; Wed, 4 Dec 2019 01:56:23 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-lSm_Sd3EOBSW5eoylPCMIQ-1; Wed, 04 Dec 2019 04:56:01 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33E74100F7CA; Wed, 4 Dec 2019 09:55:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CA535DA7D; Wed, 4 Dec 2019 09:55:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B15225BC16; Wed, 4 Dec 2019 09:55:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tmjA023792 for ; Wed, 4 Dec 2019 04:55:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 41FB25DA7E; Wed, 4 Dec 2019 09:55:48 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC4845DA70 for ; Wed, 4 Dec 2019 09:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453381; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qaUBm4GDidh9W8wA69sBV+iXysDwidhxneB4xMK/OUk=; b=ONR2AziVy66w+N/yH7gqU7kqKvK/m7Vr9GMZhHq6Qylc1GY1BN8fw4cYk+tkna3YEbdsay MMzaTRZjUSBkULW2PpLxFMF0loVvzZ74OOYI3s0Gz9JnJXHBS8fE2JJUi8qwmodRvvup/Y nMM/8QgEEBVCSwHLgTd++ymWqjXPEyU= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:33 +0100 Message-Id: <20476dce4727bcd74c58f2fed19386da539b697d.1575453027.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/9] lxc: Cleanup virConnectPtr usage X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: lSm_Sd3EOBSW5eoylPCMIQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are some functions which pass virConnectPtr around for one reason and one reason only: to obtain virLXCDriverPtr in the end. Might replace the argument and pass a pointer to the driver right from the start. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/lxc/lxc_driver.c | 12 +++++------- src/lxc/lxc_process.c | 40 ++++++++++++++++++++++------------------ src/lxc/lxc_process.h | 2 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 826bf074e3..e4be45fca2 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3803,9 +3803,8 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, } =20 =20 -/* XXX conn required for network -> bridge resolution */ static int -lxcDomainAttachDeviceNetLive(virConnectPtr conn, +lxcDomainAttachDeviceNetLive(virLXCDriverPtr driver, virDomainObjPtr vm, virDomainNetDefPtr net) { @@ -3866,7 +3865,7 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, goto cleanup; break; case VIR_DOMAIN_NET_TYPE_DIRECT: { - if (!(veth =3D virLXCProcessSetupInterfaceDirect(conn, vm->def, ne= t))) + if (!(veth =3D virLXCProcessSetupInterfaceDirect(driver, vm->def, = net))) goto cleanup; } break; case VIR_DOMAIN_NET_TYPE_USER: @@ -4233,8 +4232,7 @@ lxcDomainAttachDeviceHostdevLive(virLXCDriverPtr driv= er, =20 =20 static int -lxcDomainAttachDeviceLive(virConnectPtr conn, - virLXCDriverPtr driver, +lxcDomainAttachDeviceLive(virLXCDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev) { @@ -4248,7 +4246,7 @@ lxcDomainAttachDeviceLive(virConnectPtr conn, break; =20 case VIR_DOMAIN_DEVICE_NET: - ret =3D lxcDomainAttachDeviceNetLive(conn, vm, + ret =3D lxcDomainAttachDeviceNetLive(driver, vm, dev->data.net); if (!ret) dev->data.net =3D NULL; @@ -4736,7 +4734,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr do= m, true) < 0) goto endjob; =20 - if ((ret =3D lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_= copy)) < 0) + if ((ret =3D lxcDomainAttachDeviceLive(driver, vm, dev_copy)) < 0) goto endjob; /* * update domain status forcibly because the domain status may be diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 9b62a93096..f5d2fb0145 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -326,13 +326,13 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm, } =20 =20 -char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn, - virDomainDefPtr def, - virDomainNetDefPtr net) +char * +virLXCProcessSetupInterfaceDirect(virLXCDriverPtr driver, + virDomainDefPtr def, + virDomainNetDefPtr net) { char *ret =3D NULL; char *res_ifname =3D NULL; - virLXCDriverPtr driver =3D conn->privateData; const virNetDevBandwidth *bw; const virNetDevVPortProfile *prof; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); @@ -392,9 +392,10 @@ static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPAC= E_LAST] =3D { [VIR_LXC_DOMAIN_NAMESPACE_SHAREUTS] =3D "uts", }; =20 -static int virLXCProcessSetupNamespaceName(virConnectPtr conn, int ns_type= , const char *name) +static int virLXCProcessSetupNamespaceName(virLXCDriverPtr driver, + int ns_type, + const char *name) { - virLXCDriverPtr driver =3D conn->privateData; int fd =3D -1; virDomainObjPtr vm; virLXCDomainObjPrivatePtr priv; @@ -474,7 +475,7 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, = const char *name) =20 /** * virLXCProcessSetupNamespaces: - * @conn: pointer to connection + * @driver: pointer to driver structure * @def: pointer to virtual machines namespaceData * @nsFDs: out parameter to store the namespace FD * @@ -483,9 +484,10 @@ static int virLXCProcessSetupNamespaceNet(int ns_type,= const char *name) * * Returns 0 on success or -1 in case of error */ -static int virLXCProcessSetupNamespaces(virConnectPtr conn, - lxcDomainDefPtr lxcDef, - int *nsFDs) +static int +virLXCProcessSetupNamespaces(virLXCDriverPtr driver, + lxcDomainDefPtr lxcDef, + int *nsFDs) { size_t i; =20 @@ -500,7 +502,8 @@ static int virLXCProcessSetupNamespaces(virConnectPtr c= onn, case VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NONE: continue; case VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NAME: - if ((nsFDs[i] =3D virLXCProcessSetupNamespaceName(conn, i, lxc= Def->ns_val[i])) < 0) + if ((nsFDs[i] =3D virLXCProcessSetupNamespaceName(driver, i, + lxcDef->ns_val= [i])) < 0) return -1; break; case VIR_LXC_DOMAIN_NAMESPACE_SOURCE_PID: @@ -519,7 +522,7 @@ static int virLXCProcessSetupNamespaces(virConnectPtr c= onn, =20 /** * virLXCProcessSetupInterfaces: - * @conn: pointer to connection + * @driver: pointer to driver structure * @def: pointer to virtual machine structure * @veths: string list of interface names * @@ -529,9 +532,10 @@ static int virLXCProcessSetupNamespaces(virConnectPtr = conn, * * Returns 0 on success or -1 in case of error */ -static int virLXCProcessSetupInterfaces(virConnectPtr conn, - virDomainDefPtr def, - char ***veths) +static int +virLXCProcessSetupInterfaces(virLXCDriverPtr driver, + virDomainDefPtr def, + char ***veths) { int ret =3D -1; size_t i; @@ -585,7 +589,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr c= onn, goto cleanup; break; case VIR_DOMAIN_NET_TYPE_DIRECT: - if (!(veth =3D virLXCProcessSetupInterfaceDirect(conn, def, ne= t))) + if (!(veth =3D virLXCProcessSetupInterfaceDirect(driver, def, = net))) goto cleanup; break; =20 @@ -1344,11 +1348,11 @@ int virLXCProcessStart(virConnectPtr conn, } =20 VIR_DEBUG("Setting up Interfaces"); - if (virLXCProcessSetupInterfaces(conn, vm->def, &veths) < 0) + if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0) goto cleanup; =20 VIR_DEBUG("Setting up namespaces if any"); - if (virLXCProcessSetupNamespaces(conn, vm->def->namespaceData, nsInher= itFDs) < 0) + if (virLXCProcessSetupNamespaces(driver, vm->def->namespaceData, nsInh= eritFDs) < 0) goto cleanup; =20 VIR_DEBUG("Preparing to launch"); diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h index 1bf359b229..383f6f714d 100644 --- a/src/lxc/lxc_process.h +++ b/src/lxc/lxc_process.h @@ -50,6 +50,6 @@ int virLXCProcessValidateInterface(virDomainNetDefPtr net= ); char *virLXCProcessSetupInterfaceTap(virDomainDefPtr vm, virDomainNetDefPtr net, const char *brname); -char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn, +char *virLXCProcessSetupInterfaceDirect(virLXCDriverPtr driver, virDomainDefPtr def, virDomainNetDefPtr net); --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Feb 7 20:38:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1575453365; cv=none; d=zohomail.com; s=zohoarc; b=hcLYjC6bS1LJCQW+CbrfidPmtOP0cb7Pnmhbf62KtJl9nADoOLDGdFpo9lEKvEJpw7ZZsa+hUD7VXAijPmy7x8cTxPnr0wgv6PZsw4VwjEdUMb1zv6bauj6zEEexjB7a8IrbHvFnOW2UALjwQBXsWYRjVJ1t/6kkHtBnA9H87Jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575453365; h=Content-Type:Content-Transfer-Encoding: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=+5ejl7ecDJL8fFLJKd1cbRLIA5I6NPAVTHO6q0X2K2Q=; b=mwfbz2OsqeyEl+wf97kbBDbId2efVu0LeAw+TfjSGF27jU5+Bt9J7irMmq6utMOta7uprlFF+yZ2uGqWyKoo9/vtQW2i/tlnqDUaFhPJFkIzDTrLZqIBBsD6LrAH5aY3g9pt8nuUPePs8OayZ3K9dRM3zVypFTgXZDsBlOhY3q4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 157545336571251.83770085688707; Wed, 4 Dec 2019 01:56:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-O_MXNoDrPwqz1XGUh1o7kw-1; Wed, 04 Dec 2019 04:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2473100F045; Wed, 4 Dec 2019 09:55:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6DE25DA7B; Wed, 4 Dec 2019 09:55:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 556CC18089D0; Wed, 4 Dec 2019 09:55:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB49tnUN023797 for ; Wed, 4 Dec 2019 04:55:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 14DFB5DA7B; Wed, 4 Dec 2019 09:55:49 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90BE35E24D for ; Wed, 4 Dec 2019 09:55:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575453363; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+5ejl7ecDJL8fFLJKd1cbRLIA5I6NPAVTHO6q0X2K2Q=; b=GAHf6JG1H81E9nUttw2WY4do6n26NBI1CIvlGaQFx3yX3UuKzhE6ya8PQt+L7A3T0WDoho apwO/2ZgqjKVxAw4YkBP45hOO2V7F5+QAibKuaCr73X9KPUU/mteTgV9KMRxGbVy9M2Bh7 62cHpy6UxJgiBEIpUj0tbXKTDQRbhuk= From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 4 Dec 2019 10:55:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 9/9] get_nonnull_domain: Drop useless comment X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: O_MXNoDrPwqz1XGUh1o7kw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The intent of get_nonnull_domain() is not to validate virDomain as sent by the client but just to construct the virDomain structure. The validation is then done in each API when looking up the domain in our internal hash tables. Signed-off-by: Michal Privoznik Reviewed-by: Cole Robinson --- src/remote/remote_daemon_dispatch.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index f369ffb02a..a96e008242 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -7240,9 +7240,6 @@ remoteDispatchNetworkPortGetParameters(virNetServerPt= r server G_GNUC_UNUSED, static virDomainPtr get_nonnull_domain(virConnectPtr conn, remote_nonnull_domain domain) { - /* Should we believe the domain.id sent by the client? Maybe - * this should be a check rather than an assignment? XXX - */ return virGetDomain(conn, domain.name, BAD_CAST domain.uuid, domain.id= ); } =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list