From nobody Sun Feb 8 07:07:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15328068829221000.1183945860439; Sat, 28 Jul 2018 12:41:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3051730820E6; Sat, 28 Jul 2018 19:41:21 +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 F00862010CEA; Sat, 28 Jul 2018 19:41:20 +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 9AAD23F7D2; Sat, 28 Jul 2018 19:41:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJfDwX020553 for ; Sat, 28 Jul 2018 15:41:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 13BE810512; Sat, 28 Jul 2018 19:41:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0922B89DFA for ; Sat, 28 Jul 2018 19:41:12 +0000 (UTC) Received: from mail-pl0-f42.google.com (mail-pl0-f42.google.com [209.85.160.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2420230832E4 for ; Sat, 28 Jul 2018 19:41:11 +0000 (UTC) Received: by mail-pl0-f42.google.com with SMTP id f6-v6so3740055plo.1 for ; Sat, 28 Jul 2018 12:41:11 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=TLRNwpicCHt0zoXGrO5LNqfLMhIfbkStpCEi1ZOV3rs=; b=b8yJsMR/sTd1lS4TkuNRasmjl1sdFYeY5KHHU6/ggvv6IPy1LdNXQ2NByMGPUI2cGy Lp7Za6J8wJn3xXI/3c/vbMN/NNdiyavIiXDTKwUW/H6a3Y+TN+n6B/GYZeg756D4dBvX t7Rapm8+Glo/bbOi6R0BvUwMqFcZc3Ypc5XmfN9OYC4nD4FbHvANvGju8NM2F7rp+vgK ofaPGtNV1lpH6U1HqAu63foQbHZsRA5VPvKrdVCTqEmLjDz/OBjMs6p4rs5emTtpcF07 K5ngvd0HODUGd5EtDwJfoe4AHhZ+egdwlKok2e1ur3GKxYnzhpBUgAov3TviaOC6hhlg G2wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=TLRNwpicCHt0zoXGrO5LNqfLMhIfbkStpCEi1ZOV3rs=; b=fHatVWcm/xBEVo0XF/WF2igte9mCo0R0Vq+PqJikjGesZLLHuXLqVFxrL1Qd/iKxeN MGP+j58TXF/q+A7UWyyBvIQAE66YjjoTO+eiVCPQ7hWCNIietBy0Hgvu5JHLPfSGSJTk Nhb50F3nGHEdYhTZ5fR3BCk9g1onB2KPfHCV2Kj4kkuC0UPszpclz7aO2m3MZ/s3pZOm ikNubhdt2s1DIVhhhKUBOxFw3C5dkdUhVvN0sM3R/W1m4IBhT41nLdmZchg9JhwI0val mbr/LpRlIFff+oMsaLgTg1CUMo7WnyH+8B6Tn/a/Pknjv5i7Nh0gZeoGfbNncsdv54Yt bw8Q== X-Gm-Message-State: AOUpUlH0I/G7N0OkAHO0PPZQByQJYihmPJNyVmrsZSZnezstIG2HZwpl pKLSwtToBvFI5RPG67Gmq3dC5gEd X-Google-Smtp-Source: AAOMgpe4cOyisRUhLjr9dNt/QV51feMcvisTU0MHuir7bcXD5DC18w88xUrtmpl1mgV3NHaQUCgmSQ== X-Received: by 2002:a17:902:b609:: with SMTP id b9-v6mr10644961pls.321.1532806870409; Sat, 28 Jul 2018 12:41:10 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:33 +0530 Message-Id: <1532800907-29115-19-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:41:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 28 Jul 2018 19:41:11 +0000 (UTC) for IP:'209.85.160.42' DOMAIN:'mail-pl0-f42.google.com' HELO:'mail-pl0-f42.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.42 mail-pl0-f42.google.com 209.85.160.42 mail-pl0-f42.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 18/32] util: netdevopenvswitch: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 28 Jul 2018 19:41:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virnetdevopenvswitch.c | 106 +++++++++++++++---------------------= ---- 1 file changed, 40 insertions(+), 66 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index a9c5e2a..eae5861 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -76,9 +76,7 @@ virNetDevOpenvswitchAddTimeout(virCommandPtr cmd) static int virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, virNetDevVlanPtr vir= tVlan) { - int ret =3D -1; size_t i =3D 0; - virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 if (!virtVlan || !virtVlan->nTags) return 0; @@ -98,7 +96,12 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, vi= rNetDevVlanPtr virtVlan) } =20 if (virtVlan->trunk) { - virBufferAddLit(&buf, "trunk=3D"); + VIR_AUTOPTR(virBuffer) buf =3D NULL; + + if (VIR_ALLOC(buf) < 0) + return -1; + + virBufferAddLit(buf, "trunk=3D"); =20 /* * Trunk ports have at least one VLAN. Do the first one @@ -106,24 +109,21 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd,= virNetDevVlanPtr virtVlan) * start of the for loop if there are more than one VLANs * on this trunk port. */ - virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); + virBufferAsprintf(buf, "%d", virtVlan->tag[i]); =20 for (i =3D 1; i < virtVlan->nTags; i++) { - virBufferAddLit(&buf, ","); - virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); + virBufferAddLit(buf, ","); + virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } =20 - if (virBufferCheckError(&buf) < 0) - goto cleanup; - virCommandAddArg(cmd, virBufferCurrentContent(&buf)); + if (virBufferCheckError(buf) < 0) + return -1; + virCommandAddArg(cmd, virBufferCurrentContent(buf)); } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=3D%d", virtVlan->tag[0]); } =20 - ret =3D 0; - cleanup: - virBufferFreeAndReset(&buf); - return ret; + return 0; } =20 /** @@ -144,11 +144,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virNetDevVPortProfilePtr ovsport, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; char vmuuidstr[VIR_UUID_STRING_BUFLEN]; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) attachedmac_ex_id =3D NULL; VIR_AUTOFREE(char *) ifaceid_ex_id =3D NULL; VIR_AUTOFREE(char *) profile_ex_id =3D NULL; @@ -160,17 +159,17 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, =20 if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=3D\"%s\= "", macaddrstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=3D\"%s\"", ifuuidstr) < 0) - goto cleanup; + return -1; if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=3D\"%s\"", vmuuidstr) < 0) - goto cleanup; + return -1; if (ovsport->profileID[0] !=3D '\0') { if (virAsprintf(&profile_ex_id, "external-ids:port-profile=3D\"%s\= "", ovsport->profileID) < 0) - goto cleanup; + return -1; } =20 cmd =3D virCommandNew(OVSVSCTL); @@ -179,7 +178,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, ifname, "--", "add-port", brname, ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (ovsport->profileID[0] =3D=3D '\0') { virCommandAddArgList(cmd, @@ -204,13 +203,10 @@ int virNetDevOpenvswitchAddPort(const char *brname, c= onst char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to add port %s to OVS bridge %s"), ifname, brname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -223,8 +219,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, */ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, co= nst char *ifname) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -233,13 +228,10 @@ int virNetDevOpenvswitchRemovePort(const char *brname= ATTRIBUTE_UNUSED, const ch if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to delete port %s from OVS"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -253,9 +245,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname A= TTRIBUTE_UNUSED, const ch */ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; size_t len; - int ret =3D -1; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -269,7 +260,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to get OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 /* Wipeout the newline, if it exists */ @@ -277,10 +268,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate,= const char *ifname) if (len > 0) (*migrate)[len - 1] =3D '\0'; =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -294,8 +282,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, = const char *ifname) */ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname) { - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!migrate) { VIR_DEBUG("No OVS port data for interface %s", ifname); @@ -312,13 +299,10 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate,= const char *ifname) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to run command to set OVS port data for " "interface %s"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** @@ -334,11 +318,10 @@ int virNetDevOpenvswitchInterfaceStats(const char *ifname, virDomainInterfaceStatsPtr stats) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) output =3D NULL; char *tmp; bool gotStats =3D false; - int ret =3D -1; =20 /* Just ensure the interface exists in ovs */ cmd =3D virCommandNew(OVSVSCTL); @@ -350,7 +333,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, /* no ovs-vsctl or interface 'ifname' doesn't exists in ovs */ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface not found")); - goto cleanup; + return -1; } =20 #define GET_STAT(name, member) \ @@ -369,7 +352,7 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, *tmp !=3D '\n') { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ _("Fail to parse ovs-vsctl output")); \ - goto cleanup; \ + return -1; \ } \ gotStats =3D true; \ } \ @@ -389,14 +372,10 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, if (!gotStats) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Interface doesn't have any statistics")); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -467,7 +446,7 @@ int virNetDevOpenvswitchGetVhostuserIfname(const char *path, char **ifname) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ovs_timeout =3D NULL; char *tmpIfname =3D NULL; char **tokens =3D NULL; @@ -504,7 +483,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, =20 cleanup: virStringListFreeCount(tokens, ntokens); - virCommandFree(cmd); return ret; } =20 @@ -520,8 +498,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, int virNetDevOpenvswitchUpdateVlan(const char *ifname, virNetDevVlanPtr virtVlan) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(OVSVSCTL); virNetDevOpenvswitchAddTimeout(cmd); @@ -532,16 +509,13 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname, "--", "--if-exists", "set", "Port", ifname, NULL); =20 if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - goto cleanup; + return -1; =20 if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to set vlan configuration on port %s"), i= fname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list