From nobody Tue May 7 01:24:03 2024 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=1602074160; cv=none; d=zohomail.com; s=zohoarc; b=iUmjSxXS0vy/w2BZyNXK3ImRg/GGrXoJjgCJOPCrV4Ijr/Ebw2XWldP5UIiWmnYYlGE9o+e98UKPCZFVQLv5hm3dxzP5EUcUoYRf5UwD7bzkT3XpGlI2ldjnGidkbUQt0jA2zKhvJAtk3iCbt+MKnjmoU0EdJgKm1Y5DaDdO5NE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074160; 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=Azrms0tjGo5015u2uv6eb/TaB6T/R+a/Po61vXWyrV4=; b=JT0p83UKlRW5uoeaH254QhaRk+IE1JGGeJzparbMjn0MxcK73KwOOeHj8epDRp533Fv+FsSax5yyJ+nTjzfDdaWIB0Cq/0YWonczRhNSoVivFAs3+RpYJWlssiieuaMy4hjRYAim8fPG/+zAnOgXyb3Ll8lNlV57iCuHP2RDZSg= 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 1602074160339475.018514136799; Wed, 7 Oct 2020 05:36:00 -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-583-pnNIm0fePnWA0zM_gDeaxA-1; Wed, 07 Oct 2020 08:35:56 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F1BA875110; Wed, 7 Oct 2020 12:35:48 +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 3D63E702E7; Wed, 7 Oct 2020 12:35:48 +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 0A8428C7A7; Wed, 7 Oct 2020 12:35:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZeud012383 for ; Wed, 7 Oct 2020 08:35:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 409EC757DF; Wed, 7 Oct 2020 12:35:40 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC562702E7 for ; Wed, 7 Oct 2020 12:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074159; 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=Azrms0tjGo5015u2uv6eb/TaB6T/R+a/Po61vXWyrV4=; b=cvEHtsnM7AbkLhfEUQmPfDapZG3Wk39eYPOtoWjvBzfE1Vky2z2HXKPubrvAtG7vPCiKqS 6PEo5wN+SanjZurK878NIic5ABY3VX4utg5rkbDAA4li1b4Arrt/mfcF7/QwcYaesKr+8a 8g8ySynhH5qIY4im67GXftxwc0qmGxk= X-MC-Unique: pnNIm0fePnWA0zM_gDeaxA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 01/16] qemu: agent: remove redundant checks Date: Wed, 7 Oct 2020 14:35:22 +0200 Message-Id: <06c6ea08c5e2a0d420e6ef502a71a7e5b2227360.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.11 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) virJSONValueObjectGetArray returns NULL if the object with the supplied key is not an array. Calling virJSONValueIsArray right after is redundant. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 09116e749c..456f0b69e6 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1444,12 +1444,6 @@ qemuAgentGetVCPUs(qemuAgentPtr agent, goto cleanup; } =20 - if (!virJSONValueIsArray(data)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed guest-get-vcpus data array")); - goto cleanup; - } - ndata =3D virJSONValueArraySize(data); =20 *info =3D g_new0(qemuAgentCPUInfo, ndata); @@ -2314,12 +2308,6 @@ qemuAgentGetUsers(qemuAgentPtr agent, return -1; } =20 - if (!virJSONValueIsArray(data)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed guest-get-users data array")); - return -1; - } - ndata =3D virJSONValueArraySize(data); =20 if (virTypedParamsAddUInt(params, nparams, maxparams, --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074152; cv=none; d=zohomail.com; s=zohoarc; b=jFtFz8AYhCNCZXWNBaeQw8yDiKo2vreUuyE72QfoFeTthV/qTAhyBXRolbziPFBWN2cLSVAAQXNA2fwfkU6q1UnKXqoKuJ0FNuQrUzdk3IoIjFC45sUmiJPmO2K0ZgSfWtSIuZ9WkG5flMSQfwRsbQVJB8b5RArEHifmdHKZLYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074152; 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=new3y/tGX65S/8fzYLVyQ6sZoxt9K6AqcfR/THibqxs=; b=LmqI7WsXLvB9UG+sYMIKlr462ZGXEMb4kog12/edEWBjZqSiWvIOeZfa6dEO5nw1u2mMnAjZnz90HeefdH8WJZWyMUWnv+aKE9UXzvZv/KDIqq2StfEfGk1EVgEJIVS8NkA+Cm2ZOKBdvuqYKXYQ1VXIQsl0+cMonzi1Jaxx3yw= 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 160207415208065.47509672810122; Wed, 7 Oct 2020 05:35:52 -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-263-OwNqVcZvO7WKL8BSuFoi7A-1; Wed, 07 Oct 2020 08:35:48 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E3FD10BBEC3; Wed, 7 Oct 2020 12:35:42 +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 516A819C4F; Wed, 7 Oct 2020 12:35:42 +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 DC64918408A1; Wed, 7 Oct 2020 12:35:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZf04012392 for ; Wed, 7 Oct 2020 08:35:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1280D757DF; Wed, 7 Oct 2020 12:35:41 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E354702E7 for ; Wed, 7 Oct 2020 12:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074150; 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=new3y/tGX65S/8fzYLVyQ6sZoxt9K6AqcfR/THibqxs=; b=fpDoTYRGrdm6d7nEqz31F4MdFWQriPvmjqRJ+vh1bplab0ST5ZVlaiQtNDOzEsZ8jeC0AW 6z710pnqP5jb8DSxPQ1GhsTQU4VRLiHNqgqiU13EM5wAYfXPb8suhhkGOQ12OXT1K2/SIn 45NhFeXEcqCmRjDbPFP5l1m2wRM1Xwo= X-MC-Unique: OwNqVcZvO7WKL8BSuFoi7A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 02/16] qemu: agent: split out qemuAgentGetInterfaceOneAddress Date: Wed, 7 Oct 2020 14:35:23 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.23 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) A function that takes one entry from the "ip-addresses" array returned by "guest-network-get-interfaces" and converts it into virDomainIPAddress. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 78 +++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 456f0b69e6..fc7b65de2a 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2059,6 +2059,51 @@ qemuAgentGetFSInfo(qemuAgentPtr agent, return ret; } =20 + +static int +qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr ip_addr, + virJSONValuePtr ip_addr_obj, + const char *name) +{ + const char *type, *addr; + + type =3D virJSONValueObjectGetString(ip_addr_obj, "ip-address-type"); + if (!type) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("qemu agent didn't provide 'ip-address-type'" + " field for interface '%s'"), name); + return -1; + } else if (STREQ(type, "ipv4")) { + ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV4; + } else if (STREQ(type, "ipv6")) { + ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV6; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown ip address type '%s'"), + type); + return -1; + } + + addr =3D virJSONValueObjectGetString(ip_addr_obj, "ip-address"); + if (!addr) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("qemu agent didn't provide 'ip-address'" + " field for interface '%s'"), name); + return -1; + } + ip_addr->addr =3D g_strdup(addr); + + if (virJSONValueObjectGetNumberUint(ip_addr_obj, "prefix", + &ip_addr->prefix) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed 'prefix' field")); + return -1; + } + + return 0; +} + + /* * qemuAgentGetInterfaces: * @agent: agent object @@ -2176,7 +2221,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, addrs_count =3D iface->naddrs; =20 for (j =3D 0; j < virJSONValueArraySize(ip_addr_arr); j++) { - const char *type, *addr; virJSONValuePtr ip_addr_obj =3D virJSONValueArrayGet(ip_addr_a= rr, j); virDomainIPAddressPtr ip_addr; =20 @@ -2192,38 +2236,8 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, goto error; } =20 - type =3D virJSONValueObjectGetString(ip_addr_obj, "ip-address-= type"); - if (!type) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("qemu agent didn't provide 'ip-address-ty= pe'" - " field for interface '%s'"), name); + if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name= ) < 0) goto error; - } else if (STREQ(type, "ipv4")) { - ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV4; - } else if (STREQ(type, "ipv6")) { - ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV6; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown ip address type '%s'"), - type); - goto error; - } - - addr =3D virJSONValueObjectGetString(ip_addr_obj, "ip-address"= ); - if (!addr) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("qemu agent didn't provide 'ip-address'" - " field for interface '%s'"), name); - goto error; - } - ip_addr->addr =3D g_strdup(addr); - - if (virJSONValueObjectGetNumberUint(ip_addr_obj, "prefix", - &ip_addr->prefix) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("malformed 'prefix' field")); - goto error; - } } =20 iface->naddrs =3D addrs_count; --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074162; cv=none; d=zohomail.com; s=zohoarc; b=KXYzmHHJTiMnDe2E6QJ1HdNDFXswYfsGXt8ZUOR9uUQcKsh/+FaLbgof4ckhybG3FUE7Pr9fk2aJLp3rctix6tFJh31rciPiQAP0D8dbLkD/tslUh9b2OBRPp3Y9S4L1GAgTSLXvBpFUM6c3GrWTSO+Qc/yHowGOkweF4AicyuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074162; 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=BVOtSLNZBJUtMV2yqmEqw5IWpdmwO3QXpjPy0R1HQdI=; b=K1+bK/kjte0vd0fw69e+ExIm7oxrEX+KkqzaZpZSaCwi7vT0KKSKcPw7Om5lZ8K4bCMLDJwKqmgGJVcP+mk27RDeENu67VuoCxwk13v+DF/htvNw4N5a5QK+Kma7QwlTmfn/jndZlY28WRtfBYgi51NsWyJ1Py9kA0TedprQlGs= 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 1602074162206745.8431214015613; Wed, 7 Oct 2020 05:36:02 -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-245-J6fjXF32PSupLOjAat2iUw-1; Wed, 07 Oct 2020 08:35:57 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DB2710BBECF; Wed, 7 Oct 2020 12:35:51 +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 180F719C4F; Wed, 7 Oct 2020 12:35:51 +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 D323A18408AD; Wed, 7 Oct 2020 12:35:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZfTA012399 for ; Wed, 7 Oct 2020 08:35:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id D79AD702E7; Wed, 7 Oct 2020 12:35:41 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F95276642 for ; Wed, 7 Oct 2020 12:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074161; 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=BVOtSLNZBJUtMV2yqmEqw5IWpdmwO3QXpjPy0R1HQdI=; b=FIW5MC+JDCQD+s1otKCOgGkI1TLk+2W70OvPq06ud5uZ5gCQpt24v+fx1dHsb4ptM/DUjA OBcVdpAkA6AoguNWFoyajpPMvOUZYZrzjVbZNKZFIbms9zvBQSdc/IaCsIXOD0xBKdUNWV sRU9MryNSktByfaBl9g6zHqgg4qZOSc= X-MC-Unique: J6fjXF32PSupLOjAat2iUw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 03/16] qemu: agent: remove impossible errors Date: Wed, 7 Oct 2020 14:35:24 +0200 Message-Id: <3e44696c6ef8c1d12257b77846df4eb13ac54bb6.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.23 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) For both 'ip_addr_arr' and 'ret_array', we: 1) already checked that they are arrays 2) only iterate up to the array size Remove the duplicate checks. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index fc7b65de2a..51c597f57e 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2160,13 +2160,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, const char *hwaddr, *ifname_s, *name =3D NULL; virDomainInterfacePtr iface =3D NULL; =20 - /* Shouldn't happen but doesn't hurt to check neither */ - if (!tmp_iface) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qemu agent reply missing interface entry in = array")); - goto error; - } - /* interface name is required to be presented */ name =3D virJSONValueObjectGetString(tmp_iface, "name"); if (!name) { @@ -2229,13 +2222,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, =20 ip_addr =3D &iface->addrs[addrs_count - 1]; =20 - /* Shouldn't happen but doesn't hurt to check neither */ - if (!ip_addr_obj) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qemu agent reply missing IP addr in arra= y")); - goto error; - } - if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name= ) < 0) goto error; } --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074230; cv=none; d=zohomail.com; s=zohoarc; b=NSw5OSipDnct588zN1pAvVuJxx+LSeM/hX0THy5OFszWbeNgb1eYF8rjzwJJ37lNXdzwT+/24XP49LTxOl6FFOjK9u8jQczFYNbEbOnFz+MJGM2b0/6JuD6uCsz78b4H8Nd36o2ctYEmHa1RsMGTdW1DwGzCSj5cRQt3K/QKadk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074230; 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=3fXJVVXwLet1778KcwDhT3SoY73k1GddfF5vt3JsB2M=; b=Iv9rapYHhyuf+l4JafyEN/dISSwa5VedwT9dt2EHi0ZBXwu1J78GiHkksEvp/gEclvCwQk1hMfyfkynsIMddGZDnMPQ0cSu5ApyhF9X9+XzMBCTcGySKRvaWAXnhuLR2U/KMo7Kfnv9NQ40XVqCIhh/bMkdpDPDnQP036TxMMCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 160207423026158.73596814609084; Wed, 7 Oct 2020 05:37:10 -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-278-YIKbJeTAMaGyEBASLF1StQ-1; Wed, 07 Oct 2020 08:36:01 -0400 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 D6DAB81CBE9; Wed, 7 Oct 2020 12:35:53 +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 B4B615D9FC; Wed, 7 Oct 2020 12:35: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 7E0EB8C7A8; Wed, 7 Oct 2020 12:35:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZg5b012412 for ; Wed, 7 Oct 2020 08:35:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id A92E97664C; Wed, 7 Oct 2020 12:35:42 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3137C702E7 for ; Wed, 7 Oct 2020 12:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074229; 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=3fXJVVXwLet1778KcwDhT3SoY73k1GddfF5vt3JsB2M=; b=LxRisosGkebtIPmYu79lRdL6I4nYoGkR3ioABuY5BPUF4DKkztPlxjKmEJL07c6gIsU/Mo wHOTZOtXRALSWkrC3TtxqgDuLSshxM9HwEW0H44B5OZMwp7da52A5lGVjRoBMRAaLkQhFj 1AcnxSWDighnswcavTUVEH0OGbMUxxI= X-MC-Unique: YIKbJeTAMaGyEBASLF1StQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 04/16] qemu: agent: reduce scope of addrs_count Date: Wed, 7 Oct 2020 14:35:25 +0200 Message-Id: <511f9d2c23244669ab9a40d31f459b4ed80f8aea.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 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) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 51c597f57e..c6878c8590 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2125,7 +2125,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, virJSONValuePtr reply =3D NULL; virJSONValuePtr ret_array =3D NULL; size_t ifaces_count =3D 0; - size_t addrs_count =3D 0; virDomainInterfacePtr *ifaces_ret =3D NULL; virHashTablePtr ifaces_store =3D NULL; char **ifname =3D NULL; @@ -2159,6 +2158,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, virJSONValuePtr ip_addr_arr =3D NULL; const char *hwaddr, *ifname_s, *name =3D NULL; virDomainInterfacePtr iface =3D NULL; + size_t addrs_count =3D 0; =20 /* interface name is required to be presented */ name =3D virJSONValueObjectGetString(tmp_iface, "name"); --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074226; cv=none; d=zohomail.com; s=zohoarc; b=nU+J31Tc8iFZuaCHxP5VHxd6ZcisrJy9L3Bu9G9i/Q5+4HCMpzvEnOQAzL0Bb1QYtucDwG6BiCHmgFXvU6Sk8w3sXFNYcHSnX6DYBl7nSMLgxtWj5PJ167SzsriudEeRNu06yL34oz6ZUUwW6cJg5SNuXII1aSwe8Ywud5VZ4ac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074226; 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=0o2HMpnlc3HFQEb+HvmqJgDv/yZhkTtmEKq82bBa+e4=; b=XEmabt1pA/GF+alN3Gj2hwotcQ9r8JG4DM/B5bAWAzkRP5HN8NZtDhCbTmuemZWAvmI2OhpiSq4LGIIwLkUztOLYUOyBrNYe6l8e9asBqEfkTjdXjATxtI7t8rIfbMFBBWxgBi33PzARVoOp8As0Elw0nSlzk3hKIiXShRcpw2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602074226664436.55963971977553; Wed, 7 Oct 2020 05:37:06 -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-54-dbvWcnv3OfyRem491FQH8A-1; Wed, 07 Oct 2020 08:35:58 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A07ED9CC09; Wed, 7 Oct 2020 12:35:44 +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 7E30876644; Wed, 7 Oct 2020 12:35:44 +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 4CD178C7A3; Wed, 7 Oct 2020 12:35:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZhkJ012422 for ; Wed, 7 Oct 2020 08:35:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D2ED702E7; Wed, 7 Oct 2020 12:35:43 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0368976642 for ; Wed, 7 Oct 2020 12:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074225; 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=0o2HMpnlc3HFQEb+HvmqJgDv/yZhkTtmEKq82bBa+e4=; b=V8nCCCTOmFlnuO4hRQMqAYBCu5Bzl+YZ1RWcpwCJ7EGsiF3vHWuUOG+QRo3wAz5U//tKPi liH9gjBtcHrnfVcX/1eSxDRp7/5cXvpEjClOF38KmKg/jmyiBUC1dbFqVEIXueAf4nYJES eM7K+sSQ+k1c0srbG2lNCcRBtPbjiOA= X-MC-Unique: dbvWcnv3OfyRem491FQH8A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 05/16] qemu: agent: expand addrs upfront Date: Wed, 7 Oct 2020 14:35:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.11 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) qemuAgentGetInterfaceOneAddress returns exactly one address for every iteration of the loop (and we error out if not). Instead of expanding the addrs by one on every iteration, do it upfront since we know how many times the loop will execute. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index c6878c8590..0394a72518 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2213,20 +2213,18 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, /* If current iface already exists, continue with the count */ addrs_count =3D iface->naddrs; =20 + 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; - - if (VIR_EXPAND_N(iface->addrs, addrs_count, 1) < 0) - goto error; - - ip_addr =3D &iface->addrs[addrs_count - 1]; + virDomainIPAddressPtr ip_addr =3D iface->addrs + iface->naddrs; + iface->naddrs++; =20 if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name= ) < 0) goto error; } - - iface->naddrs =3D addrs_count; } =20 *ifaces =3D g_steal_pointer(&ifaces_ret); --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074167; cv=none; d=zohomail.com; s=zohoarc; b=HVFdAl0+O+41zsnH8xXqBU2rpARCybbm6P53byGwbCQcYoRM7m3t0ZewEDQz9YUWS/FC6oUILGh9rXx1gilFtH+6TOHWWiJjGznpR4RIlrTlXXk/TjI6s4l1WQcRjylYVxYek15pa+M5nZpFN2rYPvvPJGIYRjuKPMWCBAfTX88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074167; 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=xoIgAJeZXDhDQ86H8FYbASMdw3Ui364XzgUMTiaGe9s=; b=HH4+VA7KhKIgODEaDQ6Ts+w6pozpXKsSoXz83W7K9t0tYuLRKGfgKkEbCXVJ0NkpRuoIK5xuiq8iePb+NxNK1SZEyctCBC7bcCiJGMdvMaVnnM6xzoL8mS+cyKJps6mBbRKrnh6loNyUDS+ogISGhIWh8zRVuaMglEgKWXZHbh4= 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 1602074167317174.2496290895475; Wed, 7 Oct 2020 05:36:07 -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-525-OTPNzLYGP_SS4WtVOuY1XA-1; Wed, 07 Oct 2020 08:36:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E42FF10BBEF3; Wed, 7 Oct 2020 12:35: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 BECCB7664E; Wed, 7 Oct 2020 12:35: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 8B64718408A1; Wed, 7 Oct 2020 12:35:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZiLY012431 for ; Wed, 7 Oct 2020 08:35:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4EAF1757DF; Wed, 7 Oct 2020 12:35:44 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA869702E7 for ; Wed, 7 Oct 2020 12:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074166; 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=xoIgAJeZXDhDQ86H8FYbASMdw3Ui364XzgUMTiaGe9s=; b=fHoPmTOuzeJJoxe6cyloUcuPRvGWh74q+XYA2Kqc77mnq4DnBJK9SZCWXV05IhMXEd9DIL ZUDveRzI5rePH+8cYCLfqMHWHsvxgMv4L1v6qha3oplz/bwCrCuUZyUwSpMlYSBQj1XMIp NYC0YqOwQ1kR9028CbN5LOFtfj5NXGA= X-MC-Unique: OTPNzLYGP_SS4WtVOuY1XA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 06/16] qemu: agent: use g_auto for ifname Date: Wed, 7 Oct 2020 14:35:27 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.11 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) This lets us conveniently reduce its scope to the outer loop. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 0394a72518..b11f8afde7 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2127,7 +2127,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, size_t ifaces_count =3D 0; virDomainInterfacePtr *ifaces_ret =3D NULL; virHashTablePtr ifaces_store =3D NULL; - char **ifname =3D NULL; =20 /* Hash table to handle the interface alias */ if (!(ifaces_store =3D virHashCreate(ifaces_count, NULL))) { @@ -2158,6 +2157,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, 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 */ @@ -2194,10 +2194,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, iface->hwaddr =3D g_strdup(hwaddr); } =20 - /* Has to be freed for each interface. */ - g_strfreev(ifname); - ifname =3D NULL; - /* as well as IP address which - moreover - * can be presented multiple times */ ip_addr_arr =3D virJSONValueObjectGet(tmp_iface, "ip-addresses"); @@ -2242,8 +2238,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, virDomainInterfaceFree(ifaces_ret[i]); } VIR_FREE(ifaces_ret); - g_strfreev(ifname); - goto cleanup; } =20 --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074284; cv=none; d=zohomail.com; s=zohoarc; b=bQIq0NgiUJYzfHdQQ5Or7+f4wKTZJL7+mTwlzpY9FlrDU4FnF1nPDwo2nLQVb2p/8NwZkDudqMDP+HPvXBFMcCvVOL/XFhADLm65lY+fXFmxrAFg2HTs1sCOoM2gmWk2PyL/Zu8MzCJCM4Q08jQEOtFOvsMzTNLsUEeFpjEgqDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074284; 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=ZMuKCrXDX5aATaFvypslxCwbRol7w5e+gKE8fOOo38o=; b=RV1lbN/Jm8/9ydD5/bmy/uZ+spkxbgfILZFjq7xOoHCC1JUhbcE5+vNhfqWIRnJV0h5bmTdDPpNA/V1eMMcsayUBlXjqZQf9AuVU2Sc0ldnBQ0A3LhTs1tojJQzlRspLpcfe+nteMx555TtxQovKEqVaR5O9YkcL7TU36TJWCWM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602074284298182.5975519185016; Wed, 7 Oct 2020 05:38:04 -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-455-Zbnfr-tmOL-jl-cSxsQD1Q-1; Wed, 07 Oct 2020 08:36:06 -0400 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 B9E6A9CC2F; Wed, 7 Oct 2020 12:35:59 +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 9954E5D9DD; Wed, 7 Oct 2020 12:35:59 +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 3ADCA18408B7; Wed, 7 Oct 2020 12:35:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZjDF012445 for ; Wed, 7 Oct 2020 08:35:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FAD3702E7; Wed, 7 Oct 2020 12:35:45 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C07976648 for ; Wed, 7 Oct 2020 12:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074282; 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=ZMuKCrXDX5aATaFvypslxCwbRol7w5e+gKE8fOOo38o=; b=Ydt9kxe7MufSD9WlIaqtW+pMfuIYyr0IVsLms1UA5pQNuhXF6Tiz2djYUyocLzWYI9527x rXIZqWdNl7+3B2hdH45IS65UFdHoqJt1yp854HnG9bxpMJM9INg6h1VSFcK+Xs+xrMQ0qH QXeK/C05iKt+HR4cxriWVxg6HLSGTKk= X-MC-Unique: Zbnfr-tmOL-jl-cSxsQD1Q-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 07/16] qemu: agent: use virHashNew Date: Wed, 7 Oct 2020 14:35:28 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 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) We're passing 'ifaces_count' to virHashCreate as the initial hash table size just after we've initialized it to zero. This translates to a default of 256 inside virHashCreateFull. Instead of this obfuscation, use virHashNew (default of 32), to make it obvious we don't care about the initial hash size. Also remove the error handling, since neither of the functions return any errors after switching to g_new0. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index b11f8afde7..a09fb4da2a 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2129,10 +2129,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, virHashTablePtr ifaces_store =3D NULL; =20 /* Hash table to handle the interface alias */ - if (!(ifaces_store =3D virHashCreate(ifaces_count, NULL))) { - virHashFree(ifaces_store); - return -1; - } + ifaces_store =3D virHashNew(NULL); =20 if (!(cmd =3D qemuAgentMakeCommand("guest-network-get-interfaces", NUL= L))) goto cleanup; --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074174; cv=none; d=zohomail.com; s=zohoarc; b=GjeumJuDOp4fxB5qgf1duCEHWNzlCx5KKTM1lc6B3UZFur7bo9+4y0uSypI0S0YS5QsVLamWaDavD9Zmplz7wxpmQXr/byzHGQRMJFETye2VB26V+snGibk6rCWaNJCYIDMfDttK0S6vonwPcOqcGW1qad1PCi3rvoIeTHR/EhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074174; 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=N2XRHhKpYc/TDKwToWVaDhpobAUxK0IFWfPKRJBnbQ8=; b=WvbCBSii9BqVi7hJdE5vN8o/DY16UqyONOZZiQqnHOwhTpFvyNs7bo+tlU1v38CZU3qCGQcaHKCmC22sJ5kvG3d7LBtWynJu+38XOd4xApr8/+6CIRhp1CG0UAYqkvaaD67klTAK6xjxnNZEcWmUVnyNVrw0hqp54Q/Nf3iGBSM= 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 1602074174155409.91752211727214; Wed, 7 Oct 2020 05:36:14 -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-341-_X1bWYe1NfOVVHWiihvWsA-1; Wed, 07 Oct 2020 08:36:09 -0400 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 6B7EC8064D9; Wed, 7 Oct 2020 12:36:02 +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 4836E5D9DD; Wed, 7 Oct 2020 12:36:02 +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 13C178C7AA; Wed, 7 Oct 2020 12:36:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZjo9012454 for ; Wed, 7 Oct 2020 08:35:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id E4997702E7; Wed, 7 Oct 2020 12:35:45 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CEFF76642 for ; Wed, 7 Oct 2020 12:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074172; 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=N2XRHhKpYc/TDKwToWVaDhpobAUxK0IFWfPKRJBnbQ8=; b=OkMiTSsHz0AbEvXNu405Amr/pM567OJqUXL9QHTy1w6C1DE5ce7IvvgVkT+1cQNpeu/b6L fc7Wvmobf5/AYTT43jpsM0t+iJxGpnASyODyfdI4GTjdEjM6z3FSzlNdLtHVTQynjpgngp p6Gqd3Cn9aQuXL9gzoMFDv2oGvNfN/M= X-MC-Unique: _X1bWYe1NfOVVHWiihvWsA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 08/16] qemu: agent: simplify access to ifaces_ret Date: Wed, 7 Oct 2020 14:35:29 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 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) We have a local 'iface' variable that contains the same value eventually. Initialize it early instead of indexing two more times. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index a09fb4da2a..721ff55fff 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2176,15 +2176,13 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0) goto error; =20 - ifaces_ret[ifaces_count - 1] =3D g_new0(virDomainInterface, 1); + iface =3D g_new0(virDomainInterface, 1); + ifaces_ret[ifaces_count - 1] =3D iface; =20 - if (virHashAddEntry(ifaces_store, ifname_s, - ifaces_ret[ifaces_count - 1]) < 0) + if (virHashAddEntry(ifaces_store, ifname_s, iface) < 0) goto error; =20 - iface =3D ifaces_ret[ifaces_count - 1]; iface->naddrs =3D 0; - iface->name =3D g_strdup(ifname_s); =20 hwaddr =3D virJSONValueObjectGetString(tmp_iface, "hardware-ad= dress"); --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074169; cv=none; d=zohomail.com; s=zohoarc; b=Ea5Af2jSJXlQoANcunNp9iP+1xLyXpK3jhxcKK840BeaqITi+2TyLw35mAL1IGhOL+biFQFCsrqHOH9aRdA2v9o9v6n/ZdjlGTh+I+GSA7ZvqZOPxxMkNqrNb+4v+xsGdBWdcRrdL5zswyhKVfMHU6DCnR8mL4+Fh/TD+vM6twI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074169; 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=9HktDvJCoTAXX791jB+uQQeFZXrQS9lmKc1LPoDbNIo=; b=nI9ssixEz9LRcZi6F50DLqfFy4Pldnhwy7itKZJoLRoqPDIPV3zxX67i7B/VC2d8CZ7y9o9BjxZi1I5Rvb0jjgnkj0wjcgE0P65BeMbibL4XPLWwHVE12lHm//ZxLYfVbcMqqkldsKl1GOwlRajdxHRxNl2h89RNodCpqY7xFJM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 160207416981399.40372385976968; Wed, 7 Oct 2020 05:36:09 -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-336-RFx-jSqGPg2df4yafizhwg-1; Wed, 07 Oct 2020 08:36:01 -0400 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 3A2D1192AB6F; Wed, 7 Oct 2020 12:35:51 +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 195315D9DD; Wed, 7 Oct 2020 12:35:51 +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 D36AC18408AE; Wed, 7 Oct 2020 12:35:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZkSM012460 for ; Wed, 7 Oct 2020 08:35:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id B614C76642; Wed, 7 Oct 2020 12:35:46 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DE04702E7 for ; Wed, 7 Oct 2020 12:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074168; 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=9HktDvJCoTAXX791jB+uQQeFZXrQS9lmKc1LPoDbNIo=; b=bQDYilLnX/Se2C4Yy/2eGMV7DYvl8FaTE6NILWu0mkIkMalIIxz6hKOXJQ8K7B6BnVQxwq O3/DLlVaaMqnVBOeKIYT86t1KOZKTttUnbHbyTskOrgJoQRwsao7a5DSg0YY3+x7ksfiRU HtBwJbbcnGzsLRd5GCQjy+ei/MXoS6o= X-MC-Unique: RFx-jSqGPg2df4yafizhwg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 09/16] qemu: agent: split out qemuAgentGetInterfaceAddresses Date: Wed, 7 Oct 2020 14:35:30 +0200 Message-Id: <3e0b95db2723669a8433efffccbdad8a756fdc02.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 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 Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 162 +++++++++++++++++++++++++----------------- 1 file changed, 98 insertions(+), 64 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 721ff55fff..e614fdd7c4 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2104,6 +2104,101 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressP= tr ip_addr, } =20 =20 +/** + * qemuAgentGetInterfaceAddresses: + * @ifaces_ret: the array to put/update the interface in + * @ifaces_count: the number of interfaces in that array + * @ifaces_store: hash table into @ifaces_ret by interface name + * @tmp_iface: one item from the JSON array of interfaces + * + * This function processes @tmp_iface (which represents + * information about a single interface) and adds the information + * into the ifaces_ret array. + * + * If we're processing an interface alias, the suffix is stripped + * and information is appended to the entry found via the @ifaces_store + * hash table. + * + * Otherwise, the next free position in @ifaces_ret is used, + * its address added to @ifaces_store, and @ifaces_count incremented. + */ +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; + iface->naddrs++; + + if (qemuAgentGetInterfaceOneAddress(ip_addr, ip_addr_obj, name) < = 0) + return -1; + } + + return 0; +} + + /* * qemuAgentGetInterfaces: * @agent: agent object @@ -2120,7 +2215,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,71 +2246,10 @@ 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; - } - - /* 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; - 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 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074164; cv=none; d=zohomail.com; s=zohoarc; b=IRrxsH4yM90G7T4XlJ8Pw1PsSkCWg4fWPV+60DdlNYzKkCY83wZXKEG4i0Fh8SBfuB53Vi0BK8z/uxaGwHdD/26xliffhJ8klQ2/OSBkIR9vlN96DWVfhHG3ha7fHX2r9+N+geemtByH31M89VREQA86dkTagpEh/LzcMiEBvfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074164; 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=309E6hwMU/jWzNFxrATfKrjTXe/lEUN0y/TtUreJaQk=; b=RcnxquIFd6DIbPNz1zjGFiDCcmLay6oKQgvo9S/M4FSWANRQkE1kHKK1F619sPa6aalt2XnQnoqpVI0T6yj+bGV3wr1hqV9Mozt//hMgQagPjMhMRpQTlSPCpgUYJdbqPyhYVf/pecCeO38lR11yJA8n1MP1Tunz/Dz6f3BWmlU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602074164022719.9303693013107; Wed, 7 Oct 2020 05:36:04 -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-42-3EqyNuVPNHqsgJ4ANsFlGA-1; Wed, 07 Oct 2020 08:35:59 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D8464100830E; Wed, 7 Oct 2020 12:35:53 +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 B325E702E7; Wed, 7 Oct 2020 12:35: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 7DBCD8C7A7; Wed, 7 Oct 2020 12:35:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZle0012466 for ; Wed, 7 Oct 2020 08:35:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 87FD8702E7; Wed, 7 Oct 2020 12:35:47 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 103F276644 for ; Wed, 7 Oct 2020 12:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074162; 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=309E6hwMU/jWzNFxrATfKrjTXe/lEUN0y/TtUreJaQk=; b=hlV2vgJNEzzSzNKifqXbm5bMQQ1Ykt96w2d2CTTtejtWBQuazwFdaVdHRy44EhzrNdVHvp grN3DOF3qu6u3cZcJWAkkxpHCU1w7YWGukj1S9h2ro0D4zGNoN0V74MyUlX4NsatQ/wSvf dhrxruxta4++kPgJcSpmXzra6PdqrJI= X-MC-Unique: 3EqyNuVPNHqsgJ4ANsFlGA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 10/16] qemu: agent: use GetArray to remove a check Date: Wed, 7 Oct 2020 14:35:31 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.11 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) The error check for ValueObjectGet("return") is redundant, qemuAgentCommand already checked for us that the reply contains a "return" object. It does not guarantee, that it is an array. Use virJSONValueObjectGetArray that combines getting the object with checking for its type and return the more helpful of the two error messages. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index e614fdd7c4..e7ea03f840 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2232,13 +2232,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) goto cleanup; =20 - if (!(ret_array =3D virJSONValueObjectGet(reply, "return"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("qemu agent didn't provide 'return' field")); - goto cleanup; - } - - if (!virJSONValueIsArray(ret_array)) { + if (!(ret_array =3D virJSONValueObjectGetArray(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu agent didn't return an array of interfaces"= )); goto cleanup; --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074230; cv=none; d=zohomail.com; s=zohoarc; b=TAiYg4oI2rBVMNw5ASnwOlcPPU/qriWUtWIKn/cVbepY+hbB8uwtJtRCvmnzPAGHOfrU1XVJjeL0ZMY4x170PAj+E5Q8HnXedBCd8mC4x4UIdvsUkddDTzPJ4Q/mIdfwJyY7gRRaAECv0sh87eewRAGSUgFtQ2ZwXUmhrf2gpIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074230; 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=iuiGs13s2Rw/yK77QKWbQcsDFtHoCF8RQ7PgTctWN4o=; b=lH3Cdz74GS9Wq6vq47QtgsnqczqydkX5u/CD2499yQQTX+9Xjm/s3Pb5sHibCbTEOzHuyniJBBomC2Irj8yODDebxGBPA+GWJBjWK9s2fDDzlx8Xhvg32H7PHp/ANW1v9PAeYSigfxgYTekswydcch9I2g5d4fenyVSkhjv5CA8= 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 1602074230262762.7949474303965; Wed, 7 Oct 2020 05:37:10 -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-545-2ydTV0g2PTWPeJj0qnrb2g-1; Wed, 07 Oct 2020 08:36:13 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A28D805EFB; Wed, 7 Oct 2020 12:36:05 +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 067A527CCD; Wed, 7 Oct 2020 12:36:04 +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 A1E118C7AD; Wed, 7 Oct 2020 12:36:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZmfd012479 for ; Wed, 7 Oct 2020 08:35:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 58E067664B; Wed, 7 Oct 2020 12:35:48 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id D517D76644 for ; Wed, 7 Oct 2020 12:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074229; 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=iuiGs13s2Rw/yK77QKWbQcsDFtHoCF8RQ7PgTctWN4o=; b=Sv4oiwd5PbWG5JmQzYOUw55rBOGxtl2PSvSA6jOqFViszhf11gTKpr+lojiEWp3SFSpxew v82yDQSMFW+qX3lmOreEdApFmSf5tusG2FNMYPRV/6iUP2UFdoIF5mMRvqDPVbYmuJs1LR j9B9pcj/qUaV7CMj03A9ygCkpaLDJbs= X-MC-Unique: 2ydTV0g2PTWPeJj0qnrb2g-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 11/16] qemu: agent: use g_auto in qemuAgentGetInterfaces Date: Wed, 7 Oct 2020 14:35:32 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.23 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) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index e7ea03f840..39c955fdf1 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2216,12 +2216,12 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, { int ret =3D -1; size_t i; - virJSONValuePtr cmd =3D NULL; - virJSONValuePtr reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValuePtr ret_array =3D NULL; size_t ifaces_count =3D 0; virDomainInterfacePtr *ifaces_ret =3D NULL; - virHashTablePtr ifaces_store =3D NULL; + g_autoptr(virHashTable) ifaces_store =3D NULL; =20 /* Hash table to handle the interface alias */ ifaces_store =3D virHashNew(NULL); @@ -2250,9 +2250,6 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, ret =3D ifaces_count; =20 cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - virHashFree(ifaces_store); return ret; =20 error: --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074232; cv=none; d=zohomail.com; s=zohoarc; b=FBjz0klnozHhf3DoEvgDP8WjyQy8QMMQiZj+IsYwhlZneAHLz01NnZzcl00rhkuXhzDtlXdI1Ty/dKhR5uN9I1TXqvUnzPPgdj+yQ8THOl/VgS83Y9rDEIcgAMKn4r2kIi/Zf0kmazib6b62Guw6ZtVq+N2Y4g1z+USQf5Qm7Wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074232; 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=gIFwzcDqbuqjUvReHboIYeKa0RV3SmDzz5ZOB8Gituw=; b=YaNScTTTmAsKnB2OyB8GwwM+8/511uU5AcwrRcO+4CGdUdnGIjlKrJadVm/UdljmFDMonNUbXG6flg8Xm9y28vbHo55YCLl/QWpBuHJI3O1Sh+BnO2eFs8I1YfWzJjkiUSY2o98L4IkP43y+Arwz/GAH4F/Of0omBJChFe5xslY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602074232835249.23707214969397; Wed, 7 Oct 2020 05:37:12 -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-298-zxgT-S_YPaGxElZtIHDVvA-1; Wed, 07 Oct 2020 08:36:03 -0400 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 A6924192AB83; Wed, 7 Oct 2020 12:35: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 8315D5C221; Wed, 7 Oct 2020 12:35: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 42D038C7AC; Wed, 7 Oct 2020 12:35:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZnTC012493 for ; Wed, 7 Oct 2020 08:35:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D28D702E7; Wed, 7 Oct 2020 12:35:49 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8E6F76644 for ; Wed, 7 Oct 2020 12:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074231; 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=gIFwzcDqbuqjUvReHboIYeKa0RV3SmDzz5ZOB8Gituw=; b=flQeJHVLfosJHDaG2DjOrvME+2Tt4h6eUyvB1kOvqW725Uell1DyAhaEigZOYNo5tSQmQx aGLjhS3ir8RcHB9ARNeOe9Afl4xIbVUTIYgeYFxsdT7t+T/dEElrgqN18haYaj740lbgpn ByC4vrbjM+n8Rqg3kqNplq2sbv6Fz5s= X-MC-Unique: zxgT-S_YPaGxElZtIHDVvA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 12/16] qemu: agent: remove cleanup in qemuAgentGetInterfaces Date: Wed, 7 Oct 2020 14:35:33 +0200 Message-Id: <65cf3407a98f0badc8a6a8208713fb54ccb079f2.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 39c955fdf1..06e143b0b9 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2214,7 +2214,6 @@ int qemuAgentGetInterfaces(qemuAgentPtr agent, virDomainInterfacePtr **ifaces) { - int ret =3D -1; size_t i; g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; @@ -2227,15 +2226,15 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, ifaces_store =3D virHashNew(NULL); =20 if (!(cmd =3D qemuAgentMakeCommand("guest-network-get-interfaces", NUL= L))) - goto cleanup; + return -1; =20 if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) - goto cleanup; + return -1; =20 if (!(ret_array =3D virJSONValueObjectGetArray(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu agent didn't return an array of interfaces"= )); - goto cleanup; + return -1; } =20 for (i =3D 0; i < virJSONValueArraySize(ret_array); i++) { @@ -2247,10 +2246,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, } =20 *ifaces =3D g_steal_pointer(&ifaces_ret); - ret =3D ifaces_count; - - cleanup: - return ret; + return ifaces_count; =20 error: if (ifaces_ret) { @@ -2258,7 +2254,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, virDomainInterfaceFree(ifaces_ret[i]); } VIR_FREE(ifaces_ret); - goto cleanup; + return -1; } =20 =20 --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074171; cv=none; d=zohomail.com; s=zohoarc; b=g9jvsdoqaOfHIG/9T2d0rdgz3JOriBlcla4sxNRWSVoYfcZg02CmwQiUslmMMvfOykw5i0AF8ubp6i5U2WrSCnnnwWljO8+pCdLU32+Smuss2+xizDeKt9hIsIRZoMavF1VdDzAvT3jR/JIbk/nnnupSe2gvLvjjmJMnPBq+E3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074171; 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=uYXXk+8gE7PsG6Cj3+I1T0fYhdYanOUPHnMt+cdSSrU=; b=Gh6QzLltn0GYqWIAEnwgq89OASPP/9JLRURhJMdiRiYS/0hsfOYj67SrCdUg/8OXFiKuWn1C32Gbs+LKw+E65vy6WZVdS1AQwBteVekqkC5sVrrJLRtCq/jmdE7ILl7dzZc3+zYFJFl2A0CR6Nx7kwPPHdVCp3q8+ArFngx7wFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602074171795675.9144522748827; Wed, 7 Oct 2020 05:36:11 -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-538-zDiuZesbMS6c1euHkSbTFg-1; Wed, 07 Oct 2020 08:36:06 -0400 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 8992981F000; Wed, 7 Oct 2020 12:35:59 +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 3A2C05C22E; Wed, 7 Oct 2020 12:35:59 +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 ED6108C7AC; Wed, 7 Oct 2020 12:35:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZoVp012498 for ; Wed, 7 Oct 2020 08:35:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id F2A1D702E7; Wed, 7 Oct 2020 12:35:49 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B2157664C for ; Wed, 7 Oct 2020 12:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074170; 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=uYXXk+8gE7PsG6Cj3+I1T0fYhdYanOUPHnMt+cdSSrU=; b=XklybphqfDRcgda0PDdmaAbU+ie99OpJAxPdOyr4OS9lqFz5ZENqawSqiVf1Wbx649GnZq Hl7/pfXD/p5A4wJJy/OuxNTs7jeooXl6YREj+bAXvv85csmS8LSs3yUa0zLE5DJziM+IcM ohVUXhf+0cTUs4Bx29owRPUM581/hQo= X-MC-Unique: zDiuZesbMS6c1euHkSbTFg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 13/16] qemuAgentGetInterfaceAddresses: turn ifname into char* Date: Wed, 7 Oct 2020 14:35:34 +0200 Message-Id: <6b12c315bca0a39c8e946dcba4326fa7fde70b90.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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) We only care about the first part of the 'ifname' string, splitting it is overkill. Instead, just replace the ':' with a '\0' in a copy of the string. This reduces the count of the varaibles containing some form of the interface name to two. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 06e143b0b9..5cb6257bfc 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2129,9 +2129,9 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr = **ifaces_ret, virJSONValuePtr tmp_iface) { virJSONValuePtr ip_addr_arr =3D NULL; - const char *hwaddr, *ifname_s, *name =3D NULL; + const char *hwaddr, *name =3D NULL; virDomainInterfacePtr iface =3D NULL; - g_auto(GStrv) ifname =3D NULL; + g_autofree char *ifname =3D NULL; size_t addrs_count =3D 0; size_t j; =20 @@ -2144,10 +2144,9 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr= **ifaces_ret, } =20 /* Handle interface alias (:) */ - ifname =3D virStringSplit(name, ":", 2); - ifname_s =3D ifname[0]; + ifname =3D g_strdelimit(g_strdup(name), ":", '\0'); =20 - iface =3D virHashLookup(ifaces_store, ifname_s); + iface =3D virHashLookup(ifaces_store, ifname); =20 /* If the hash table doesn't contain this iface, add it */ if (!iface) { @@ -2157,11 +2156,11 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePt= r **ifaces_ret, iface =3D g_new0(virDomainInterface, 1); (*ifaces_ret)[*ifaces_count - 1] =3D iface; =20 - if (virHashAddEntry(ifaces_store, ifname_s, iface) < 0) + if (virHashAddEntry(ifaces_store, ifname, iface) < 0) return -1; =20 iface->naddrs =3D 0; - iface->name =3D g_strdup(ifname_s); + iface->name =3D g_strdup(ifname); =20 hwaddr =3D virJSONValueObjectGetString(tmp_iface, "hardware-addres= s"); iface->hwaddr =3D g_strdup(hwaddr); --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1602074164; cv=none; d=zohomail.com; s=zohoarc; b=C7UkSfWVrHcsG4eNjOWbs+d4rUE7o0w7NE3Zxe0dNVFzT0GVqG/JNjs/hq0JF65DfdvLkIC14nHM2WfrpKlfAhVNmX+0llv/FW2rcDAAcI/njmRfXU/yxBNoI8wLpIBevDCMm6H5ILl1KWVN6U3LU75py6vx2IPtguZFBpPEmmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074164; 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=3Xylamo07JXCQP5Xyj3lzIq/bktN0Msjrxf7JVW+kso=; b=JG/Mr5lnko3F0+ASmttzvX1k84oS0mHNI3lxWTys+IcCF6L1opp5mA4c7O8QpYTtoIJwjQQZgU7ng1kteIwl+N5QjD3ZcO8g0/MPg8Vzeo16mObxr+3ZkGZ865uBLP42Gd9vJZdfxs2O/RECZdentJ9Yv6YvMgwaQwbBhDc+VAI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1602074164528805.8112047250266; Wed, 7 Oct 2020 05:36:04 -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-336-g4oONQIEMiW9PJ6em242kw-1; Wed, 07 Oct 2020 08:36:00 -0400 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 94896100856D; Wed, 7 Oct 2020 12:35:54 +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 715F05D9DD; Wed, 7 Oct 2020 12:35:54 +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 3B29C8C7A9; Wed, 7 Oct 2020 12:35:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZokj012512 for ; Wed, 7 Oct 2020 08:35:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C4A0F76644; Wed, 7 Oct 2020 12:35:50 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C6D0702E7 for ; Wed, 7 Oct 2020 12:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074163; 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=3Xylamo07JXCQP5Xyj3lzIq/bktN0Msjrxf7JVW+kso=; b=LwWkki6EqNAdfzk1GLjW3w667A7a5H2l1LlF7ybe7QDvtIVfihNYcrRufNZScqAk5qJXND 1BLsJZOjzwbGVrru5arauYmzVPk5Vd/qGnBADFAgwmq/zr62d+LUROIXgaC3G/A0Cpr0NY wyyK91PmhEncBI8KBIupNAoiFgCFSPI= X-MC-Unique: g4oONQIEMiW9PJ6em242kw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 14/16] qemu: agent: rename tmp_iface to iface_obj Date: Wed, 7 Oct 2020 14:35:35 +0200 Message-Id: <8920f3db0ddc0d35e0c16ff6baacfea09c23aac0.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.14 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) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 5cb6257bfc..301707b136 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2109,9 +2109,9 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr= ip_addr, * @ifaces_ret: the array to put/update the interface in * @ifaces_count: the number of interfaces in that array * @ifaces_store: hash table into @ifaces_ret by interface name - * @tmp_iface: one item from the JSON array of interfaces + * @iface_obj: one item from the JSON array of interfaces * - * This function processes @tmp_iface (which represents + * This function processes @iface_obj (which represents * information about a single interface) and adds the information * into the ifaces_ret array. * @@ -2126,7 +2126,7 @@ static int qemuAgentGetInterfaceAddresses(virDomainInterfacePtr **ifaces_ret, size_t *ifaces_count, virHashTablePtr ifaces_store, - virJSONValuePtr tmp_iface) + virJSONValuePtr iface_obj) { virJSONValuePtr ip_addr_arr =3D NULL; const char *hwaddr, *name =3D NULL; @@ -2136,7 +2136,7 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr = **ifaces_ret, size_t j; =20 /* interface name is required to be presented */ - name =3D virJSONValueObjectGetString(tmp_iface, "name"); + name =3D virJSONValueObjectGetString(iface_obj, "name"); if (!name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("qemu agent didn't provide 'name' field")); @@ -2162,13 +2162,13 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePt= r **ifaces_ret, iface->naddrs =3D 0; iface->name =3D g_strdup(ifname); =20 - hwaddr =3D virJSONValueObjectGetString(tmp_iface, "hardware-addres= s"); + hwaddr =3D virJSONValueObjectGetString(iface_obj, "hardware-addres= s"); iface->hwaddr =3D g_strdup(hwaddr); } =20 /* as well as IP address which - moreover - * can be presented multiple times */ - ip_addr_arr =3D virJSONValueObjectGet(tmp_iface, "ip-addresses"); + ip_addr_arr =3D virJSONValueObjectGet(iface_obj, "ip-addresses"); if (!ip_addr_arr) return 0; =20 @@ -2237,10 +2237,10 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, } =20 for (i =3D 0; i < virJSONValueArraySize(ret_array); i++) { - virJSONValuePtr tmp_iface =3D virJSONValueArrayGet(ret_array, i); + virJSONValuePtr iface_obj =3D virJSONValueArrayGet(ret_array, i); =20 if (qemuAgentGetInterfaceAddresses(&ifaces_ret, &ifaces_count, - ifaces_store, tmp_iface) < 0) + ifaces_store, iface_obj) < 0) goto error; } =20 --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074224; cv=none; d=zohomail.com; s=zohoarc; b=kOi3BFRA6G01F3E7hqpiMxcup0YoRV3RqnMa1PMOeZ7BLdqdTY+yA2ftwapdJQLw+Iep5gAjeeWEa/8wTfJFwe1pf1ebpPjAPx9tjCoMeX7p+qo/dXpP1OSFGJUxX8Ni5zjRr5Ps4hC3Y/ai620s1o0OTPg/0beYTt2GNf5y2t4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074224; 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=d0a+vQrI47tdNnHMf9mfazedFKe954OpXEYJRhXgqxw=; b=LGCWZnLYQ+HyG0RZaIiCyUZKPWLyCKpNY4ArKkHeXRBjkKKYSH959OADIlHTY0XZmw8jgQ9n1i6CLGDE0osjtNcNhiO4om7Tin2GcKvnmbFsIQ+Kb8eycZMivY7hzca2HkBWE1q3f08st8RVJPUp7XQwPdNHN8JKOAFSU04OO8g= 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 1602074224584865.4421477163894; Wed, 7 Oct 2020 05:37:04 -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-295-wpFchEY2MLWNMqiWR4BapA-1; Wed, 07 Oct 2020 08:36:09 -0400 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 3734D9CC12; Wed, 7 Oct 2020 12:36:02 +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 11EA21002C29; Wed, 7 Oct 2020 12:36:02 +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 CEAEA18408C2; Wed, 7 Oct 2020 12:36:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZpSv012528 for ; Wed, 7 Oct 2020 08:35:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 97940702E7; Wed, 7 Oct 2020 12:35:51 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F8477664D for ; Wed, 7 Oct 2020 12:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074223; 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=d0a+vQrI47tdNnHMf9mfazedFKe954OpXEYJRhXgqxw=; b=NbSPZX9b1Q3isZZgT2zI6rk89+vTUQFQxJos0mWqRw3+bZz7I1S7fjJzT0XGfioBl0e47t OjYZneAnkemZ/IPJiU8cUrLx7kv1oD9iRgHCQlW7/w9nVq1mBZuxPmP/uCqV6YYEED6R44 w7+TQCE5YNP/mP935hjnq7xjNdhqAkc= X-MC-Unique: wpFchEY2MLWNMqiWR4BapA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 15/16] qemuAgentGetInterfaceOneAddress: check for errors early Date: Wed, 7 Oct 2020 14:35:36 +0200 Message-Id: <75018cef85786837a908f923003cb9fb8ee23681.1602074066.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.22 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) For readability, and to ensure we do allocation when returning 0. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 301707b136..60247e1616 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2073,11 +2073,9 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPt= r ip_addr, _("qemu agent didn't provide 'ip-address-type'" " field for interface '%s'"), name); return -1; - } else if (STREQ(type, "ipv4")) { - ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV4; - } else if (STREQ(type, "ipv6")) { - ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV6; - } else { + } + + if (STRNEQ(type, "ipv4") && STRNEQ(type, "ipv6")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown ip address type '%s'"), type); @@ -2091,7 +2089,6 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPtr= ip_addr, " field for interface '%s'"), name); return -1; } - ip_addr->addr =3D g_strdup(addr); =20 if (virJSONValueObjectGetNumberUint(ip_addr_obj, "prefix", &ip_addr->prefix) < 0) { @@ -2100,6 +2097,12 @@ qemuAgentGetInterfaceOneAddress(virDomainIPAddressPt= r ip_addr, return -1; } =20 + if (STREQ(type, "ipv4")) + ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV4; + else + ip_addr->type =3D VIR_IP_ADDR_TYPE_IPV6; + + ip_addr->addr =3D g_strdup(addr); return 0; } =20 --=20 2.26.2 From nobody Tue May 7 01:24:03 2024 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=1602074175; cv=none; d=zohomail.com; s=zohoarc; b=KyMOeBANlAHxW3LJK4IpSbCLbVdjba566x4cUyJdbItbZev8MgNEtSXEbSYIAABL5XAExD8Jl+IFuSgu7ZfC+aBQE6Frpq4VGLesxGkvTkRz0nis08xGMJssf0QAj6aMgRA0tTtjlwBweD8i4G6jdv/KKNcLJlOrEr33AJ7bHBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602074175; 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=r9zlxBgG91tosCDth8A6MliDJXFaGvPd4MZWvYeAJqc=; b=APO/rRybt7ios3Lj1+6O655jO0xx38mgdVfx+HzRY6iUS2tFsX78MlTBHRrWGgZGkX1xQt+FVzeRlwThk0LGY1eM+8dJ1rbi2JrRSk94M0FOLxihps6u3kY/KxYhbpRhsaZW3vCUSmVV9JZ9GaWbL9qlaiBrUDzQ169NJuAhkcc= 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 1602074175123630.3502560092498; Wed, 7 Oct 2020 05:36:15 -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-491-AaESouR9MGmrCDHzDDaSiQ-1; Wed, 07 Oct 2020 08:36:11 -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 CE8A381CAFD; Wed, 7 Oct 2020 12:36:04 +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 A73D555797; Wed, 7 Oct 2020 12:36:04 +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 7142918408C3; Wed, 7 Oct 2020 12:36:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 097CZq1F012537 for ; Wed, 7 Oct 2020 08:35:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68CE0702E7; Wed, 7 Oct 2020 12:35:52 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id E560A76644 for ; Wed, 7 Oct 2020 12:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602074173; 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=r9zlxBgG91tosCDth8A6MliDJXFaGvPd4MZWvYeAJqc=; b=CS0hhP5zYLJw7OSZBnPRXeZjErS/qIHiJWD4zN/Yf/iFta3Tci/EBl25Djjmuy4Y04XjjX 5owDyUHTPzurRSDI6nFZkUHvy0pYy5BQ+q2yqrojfsq4H/OFBxlbA1N8HjxZu5t/TwExB+ B2PYyHwAA53Q+p4Nv1FNh+ovp1NDUDM= X-MC-Unique: AaESouR9MGmrCDHzDDaSiQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv2 16/16] qemu: agent: split out qemuAgentGetAllInterfaceAddresses Date: Wed, 7 Oct 2020 14:35:37 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Remove more logic from qemuAgentGetInterfaces. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Jonathon Jongsma Reviewed-by: Neal Gompa --- src/qemu/qemu_agent.c | 57 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 60247e1616..c9c4b034d3 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2201,6 +2201,37 @@ qemuAgentGetInterfaceAddresses(virDomainInterfacePtr= **ifaces_ret, } =20 =20 +static int +qemuAgentGetAllInterfaceAddresses(virDomainInterfacePtr **ifaces_ret, + virJSONValuePtr ret_array) +{ + g_autoptr(virHashTable) ifaces_store =3D NULL; + size_t ifaces_count =3D 0; + size_t i; + + /* Hash table to handle the interface alias */ + ifaces_store =3D virHashNew(NULL); + + for (i =3D 0; i < virJSONValueArraySize(ret_array); i++) { + virJSONValuePtr iface_obj =3D virJSONValueArrayGet(ret_array, i); + + if (qemuAgentGetInterfaceAddresses(ifaces_ret, &ifaces_count, + ifaces_store, iface_obj) < 0) + goto error; + } + + return ifaces_count; + + error: + if (ifaces_ret) { + for (i =3D 0; i < ifaces_count; i++) + virDomainInterfaceFree(*ifaces_ret[i]); + } + VIR_FREE(*ifaces_ret); + return -1; +} + + /* * qemuAgentGetInterfaces: * @agent: agent object @@ -2216,16 +2247,9 @@ int qemuAgentGetInterfaces(qemuAgentPtr agent, virDomainInterfacePtr **ifaces) { - size_t i; g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; virJSONValuePtr ret_array =3D NULL; - size_t ifaces_count =3D 0; - virDomainInterfacePtr *ifaces_ret =3D NULL; - g_autoptr(virHashTable) ifaces_store =3D NULL; - - /* Hash table to handle the interface alias */ - ifaces_store =3D virHashNew(NULL); =20 if (!(cmd =3D qemuAgentMakeCommand("guest-network-get-interfaces", NUL= L))) return -1; @@ -2239,24 +2263,7 @@ qemuAgentGetInterfaces(qemuAgentPtr agent, return -1; } =20 - for (i =3D 0; i < virJSONValueArraySize(ret_array); i++) { - virJSONValuePtr iface_obj =3D virJSONValueArrayGet(ret_array, i); - - if (qemuAgentGetInterfaceAddresses(&ifaces_ret, &ifaces_count, - ifaces_store, iface_obj) < 0) - goto error; - } - - *ifaces =3D g_steal_pointer(&ifaces_ret); - return ifaces_count; - - error: - if (ifaces_ret) { - for (i =3D 0; i < ifaces_count; i++) - virDomainInterfaceFree(ifaces_ret[i]); - } - VIR_FREE(ifaces_ret); - return -1; + return qemuAgentGetAllInterfaceAddresses(ifaces, ret_array); } =20 =20 --=20 2.26.2