From nobody Sun Feb 8 12:33:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1601967608; cv=none; d=zohomail.com; s=zohoarc; b=IOpm7YW8qfDHF1KKZs6d/lpNen9vXOHWn3RQXypaoHv9x6NiGMiCQS4DszjwwxzBHjfJCPoIb8TBYZtbr9+QLKc4WEwAgd0ORI0qrB0pC2xsTIpNu8RDHYkRcmFuhxxRSXmKwMHqqQVv3JqpBxAv40/v5lAd7L0K1k1ZQpw48pg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601967608; 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=O9ndmYDt9rcvTFJL+ZfWyEPmrCaQq/Ws5XANrj45jpk=; b=KFWOhbq/oozM8CBxAV2VDianAx5Oi9ZB7JjOnu4AuqyB8CH1GCZJpGPSiQnvwrrvaGsAgCaqH/7YMiQB/DCSqdB/UnBsO4DSd1lqCngNQLG6yGyyj4vAOq/thZaGjSdP5O4eQ9BlDvyPZGcnudPre2EnKc5VP40wKBdZ7UqGWBg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601967608939293.1998092823618; Tue, 6 Oct 2020 00:00:08 -0700 (PDT) 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-204-x6B1iTqQMeS2-OucHWrIhA-1; Tue, 06 Oct 2020 02:59:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D6A810866B0; Tue, 6 Oct 2020 06:59:17 +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 265F25578C; Tue, 6 Oct 2020 06:59:17 +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 E3F7244A79; Tue, 6 Oct 2020 06:59:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0966x96e018672 for ; Tue, 6 Oct 2020 02:59:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id B8E7A5C221; Tue, 6 Oct 2020 06:59:09 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 401855C1C4 for ; Tue, 6 Oct 2020 06:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601967607; 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=O9ndmYDt9rcvTFJL+ZfWyEPmrCaQq/Ws5XANrj45jpk=; b=Ojbkigz3krWTWRSjtNdvbqZ4SVc6yoCYzdTD772jzsH356Wi0kPf9Ka4lkyi3vx9sCscpd nO+ejjpC2A04u/TyhG6H2tRM1afOB3MDgWMIIPUL9klPj9XBirdoPKDWnrHUw6SYFAd34l xBmQoaXnoVG95l0x+iNfTXqqC5E87Ws= X-MC-Unique: x6B1iTqQMeS2-OucHWrIhA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 09/14] qemu: agent: split out qemuAgentGetInterfaceAddresses Date: Tue, 6 Oct 2020 08:58:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Convert one interface from the "return" array returned by "guest-network-get-interfaces" to virDomainInterface. Due to the functionality of squashing interface aliases together, this is not a pure function - it either: * Adds the interface to ifaces_ret, incrementing ifaces_count and adds a pointer to it into the ifaces_store hash table. * Adds the additional IP addresses from the interface alias to the existing interface entry, found through the hash table. This does not increment ifaces_count or extend the array. Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_agent.c | 141 +++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 62 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 7a4f5cd6db..b314c610e7 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2104,6 +2104,82 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPt= r ip_addr, } =20 =20 +static int +qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret, + size_t *ifaces_count, + virHashTablePtr ifaces_store, + virJSONValuePtr tmp_iface) +{ + virJSONValuePtr ip_addr_arr =3D NULL; + const char *hwaddr, *ifname_s, *name =3D NULL; + virDomainInterfacePtr iface =3D NULL; + g_auto(GStrv) ifname =3D NULL; + size_t addrs_count =3D 0; + size_t j; + + /* interface name is required to be presented */ + name =3D virJSONValueObjectGetString(tmp_iface, "name"); + if (!name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("qemu agent didn't provide 'name' field")); + return -1; + } + + /* Handle interface alias (:) */ + ifname =3D virStringSplit(name, ":", 2); + ifname_s =3D ifname[0]; + + iface =3D virHashLookup(ifaces_store, ifname_s); + + /* If the hash table doesn't contain this iface, add it */ + if (!iface) { + if (VIR_EXPAND_N(*ifaces_ret, *ifaces_count, 1) < 0) + return -1; + + iface =3D g_new0(virDomainInterface, 1); + (*ifaces_ret)[*ifaces_count - 1] =3D iface; + + if (virHashAddEntry(ifaces_store, ifname_s, iface) < 0) + return -1; + + iface->naddrs =3D 0; + iface->name =3D g_strdup(ifname_s); + + hwaddr =3D virJSONValueObjectGetString(tmp_iface, "hardware-addres= s"); + iface->hwaddr =3D g_strdup(hwaddr); + } + + /* as well as IP address which - moreover - + * can be presented multiple times */ + ip_addr_arr =3D virJSONValueObjectGet(tmp_iface, "ip-addresses"); + if (!ip_addr_arr) + return 0; + + if (!virJSONValueIsArray(ip_addr_arr)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed ip-addresses array")); + return -1; + } + + /* If current iface already exists, continue with the count */ + addrs_count =3D iface->naddrs; + + if (VIR_EXPAND_N(iface->addrs, addrs_count, + virJSONValueArraySize(ip_addr_arr)) < 0) + return -1; + + for (j =3D 0; j < virJSONValueArraySize(ip_addr_arr); j++) { + virJSONValuePtr ip_addr_obj =3D virJSONValueArrayGet(ip_addr_arr, = j); + virDomainIPAddressPtr ip_addr =3D iface->addrs + iface->naddrs++; + + if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name) < = 0) + return -1; + } + + return 0; +} + + /* * qemuAgentGetInterfaces: * @agent: agent object @@ -2120,7 +2196,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, virDomainInterfacePtr **ifaces) { int ret =3D -1; - size_t i, j; + size_t i; virJSONValuePtr cmd =3D NULL; virJSONValuePtr reply =3D NULL; virJSONValuePtr ret_array =3D NULL; @@ -2151,70 +2227,11 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, =20 for (i =3D 0; i < virJSONValueArraySize(ret_array); i++) { virJSONValuePtr tmp_iface =3D virJSONValueArrayGet(ret_array, i); - virJSONValuePtr ip_addr_arr =3D NULL; - const char *hwaddr, *ifname_s, *name =3D NULL; - virDomainInterfacePtr iface =3D NULL; - g_auto(GStrv) ifname =3D NULL; - size_t addrs_count =3D 0; =20 - /* interface name is required to be presented */ - name =3D virJSONValueObjectGetString(tmp_iface, "name"); - if (!name) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qemu agent didn't provide 'name' field")); + if (qemuAgentGetInterfaceAddresses(&ifaces_ret, &ifaces_count, + ifaces_store, tmp_iface) < 0) goto error; - } =20 - /* Handle interface alias (:) */ - ifname =3D virStringSplit(name, ":", 2); - ifname_s =3D ifname[0]; - - iface =3D virHashLookup(ifaces_store, ifname_s); - - /* If the hash table doesn't contain this iface, add it */ - if (!iface) { - if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0) - goto error; - - iface =3D g_new0(virDomainInterface, 1); - ifaces_ret[ifaces_count - 1] =3D iface; - - if (virHashAddEntry(ifaces_store, ifname_s, iface) < 0) - goto error; - - iface->naddrs =3D 0; - iface->name =3D g_strdup(ifname_s); - - hwaddr =3D virJSONValueObjectGetString(tmp_iface, "hardware-ad= dress"); - iface->hwaddr =3D g_strdup(hwaddr); - } - - /* as well as IP address which - moreover - - * can be presented multiple times */ - ip_addr_arr =3D virJSONValueObjectGet(tmp_iface, "ip-addresses"); - if (!ip_addr_arr) - continue; - - if (!virJSONValueIsArray(ip_addr_arr)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed ip-addresses array")); - goto error; - } - - /* If current iface already exists, continue with the count */ - addrs_count =3D iface->naddrs; - - if (VIR_EXPAND_N(iface->addrs, addrs_count, - virJSONValueArraySize(ip_addr_arr)) < 0) - goto error; - - for (j =3D 0; j < virJSONValueArraySize(ip_addr_arr); j++) { - virJSONValuePtr ip_addr_obj =3D virJSONValueArrayGet(ip_addr_a= rr, j); - virDomainIPAddressPtr ip_addr =3D iface->addrs + iface->naddrs= ++; - - if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name= ) < 0) - goto error; - } } =20 *ifaces =3D g_steal_pointer(&ifaces_ret); --=20 2.26.2