From nobody Sun Feb 8 03:57:55 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 1532806865508407.1724948109802; Sat, 28 Jul 2018 12:41:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09059C057F81; Sat, 28 Jul 2018 19:41:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE8F16092D; Sat, 28 Jul 2018 19:41: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 1B56918037F3; Sat, 28 Jul 2018 19:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6SJefwP020386 for ; Sat, 28 Jul 2018 15:40:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id F38E06092F; Sat, 28 Jul 2018 19:40:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA01E6092D for ; Sat, 28 Jul 2018 19:40:37 +0000 (UTC) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 1551A3086246 for ; Sat, 28 Jul 2018 19:40:36 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id y10-v6so2877343pfn.8 for ; Sat, 28 Jul 2018 12:40:36 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.40.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:40:34 -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=gdsvi2dR8XZPwUh4n5LSSeV4Xziixcvne2rggYk+FwQ=; b=Lru34AZuhw8/h5Et8vNeDUMxAG8M0A6CfjqaGSTxD2zJ8hE3RC+fV2Tx5vi9eUMgpC /dw6EBBYKoQJIUmd7jjgPpzmnUydqXAcf6DeIaJU2p1aiYMPrDgqRxMvXNiUVBhpmkI+ /1ikUmsg3cW930FtLj87yuv8kXOyQxAGudFuZY1gSVu7c0jolVvYMyHwKWOdJDC+6y4Y XuhGcOFepJMlEEXF0YXDJRraM5XtLQJ2BazKMWk0G9zaIk+92LiAvcuMxxybezIyOHeD IJnyUqQzf+dTDQExcaRSQTpdVKlFuW1ea8aEc3/9eXoEVyM5UFh9iRtTzAqljug2dSqR WzUA== 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=gdsvi2dR8XZPwUh4n5LSSeV4Xziixcvne2rggYk+FwQ=; b=VMMnS5s7ZzlikdWhJPO4+Ul1XjXueTi2T/i/Gzui7izjda8qBWrBmG9FEkdpd9C6qq e3EURM5XOM+OEz3jfX0mmZw27XwQN7AoVHZIubGAtBIYsIYArQ84F8lwbpn8kRDFt++0 R4DAks7gXAsAwtnC2lJZR+hGSA3cM6x0lELlSFBUp3c/MeS34U3m6r2EoeIIrbeHmxXD +qdgmmkbUfmvm+FDbPO2eiu2oefvZ2tJlNuv5LCiEtHYq3H5FIi52+iftAoV35Ha7CKO fDvz9TW6IcPiDU3ehiQACnhdSdCCln0EGWWwogqSPwM4nGnOCBgkOksNxNjq4PJHVPSu NAPg== X-Gm-Message-State: AOUpUlE7pLfcbM6drIudMXazY50dM8snnG9mAIyRtMmpuXWmw4pJuNPc lEQJX8dR7e0IZBlQjhrOW3Gt2x3r X-Google-Smtp-Source: AAOMgpekZp4+hyU9scKBOIoB0ylC4ptTML6CTTzNG3q7Sc+lEbFn4B18D1cDckDASlSIgzNgrg/wbw== X-Received: by 2002:a62:1815:: with SMTP id 21-v6mr11777936pfy.227.1532806835371; Sat, 28 Jul 2018 12:40:35 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:17 +0530 Message-Id: <1532800907-29115-3-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.49]); Sat, 28 Jul 2018 19:40:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 28 Jul 2018 19:40:36 +0000 (UTC) for IP:'209.85.210.174' DOMAIN:'mail-pf1-f174.google.com' HELO:'mail-pf1-f174.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.210.174 mail-pf1-f174.google.com 209.85.210.174 mail-pf1-f174.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 02/32] util: iscsi: 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 28 Jul 2018 19:41:03 +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 Reviewed-by: Erik Skultety --- src/util/viriscsi.c | 68 +++++++++++++++++--------------------------------= ---- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 48f4106..81404f8 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -91,7 +91,7 @@ virISCSIGetSession(const char *devpath, VIR_AUTOFREE(char *) error =3D NULL; int exitstatus =3D 0; =20 - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode= ", "session", NULL); virCommandSetErrorBuffer(cmd, &error); =20 @@ -101,15 +101,13 @@ virISCSIGetSession(const char *devpath, vars, virISCSIExtractSession, &cbdata, NULL, &exitstatus) < 0) - goto cleanup; + return NULL; =20 if (cbdata.session =3D=3D NULL && !probe) virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find iscsiadm session: %s"), NULLSTR(error)); =20 - cleanup: - virCommandFree(cmd); return cbdata.session; } =20 @@ -128,7 +126,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, VIR_AUTOFREE(char *) outbuf =3D NULL; VIR_AUTOFREE(char *) iface =3D NULL; VIR_AUTOFREE(char *) iqn =3D NULL; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 *ifacename =3D NULL; @@ -196,7 +194,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - virCommandFree(cmd); return ret; =20 error: @@ -213,7 +210,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, { int ret =3D -1, exitstatus =3D -1; VIR_AUTOFREE(char *) temp_ifacename =3D NULL; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", @@ -272,7 +269,6 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, ret =3D 0; =20 cleanup: - virCommandFree(cmd); if (ret !=3D 0) VIR_FREE(*ifacename); return ret; @@ -285,7 +281,6 @@ virISCSIConnection(const char *portal, const char *target, const char **extraargv) { - int ret =3D -1; const char *const baseargv[] =3D { ISCSIADM, "--mode", "node", @@ -293,7 +288,7 @@ virISCSIConnection(const char *portal, "--targetname", target, NULL }; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); @@ -306,7 +301,7 @@ virISCSIConnection(const char *portal, break; case IQN_MISSING: if (virStorageBackendCreateIfaceIQN(initiatoriqn, &ifacename) = !=3D 0) - goto cleanup; + return -1; /* * iscsiadm doesn't let you send commands to the Interface IQN, * unless you've first issued a 'sendtargets' command to the @@ -317,25 +312,20 @@ virISCSIConnection(const char *portal, */ if (virISCSIScanTargetsInternal(portal, ifacename, true, NULL, NULL) < 0) - goto cleanup; + return -1; =20 break; case IQN_ERROR: default: - goto cleanup; + return -1; } virCommandAddArgList(cmd, "--interface", ifacename, NULL); } =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - - return ret; + return 0; } =20 =20 @@ -362,14 +352,12 @@ virISCSIConnectionLogout(const char *portal, int virISCSIRescanLUNs(const char *session) { - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "session", "-r", session, "-R", NULL); - int ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -419,8 +407,7 @@ virISCSIScanTargetsInternal(const char *portal, int vars[] =3D { 2 }; struct virISCSITargetList list; size_t i; - int ret =3D -1; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "discovery", "--type", "sendtargets", "--portal", portal, @@ -446,7 +433,7 @@ virISCSIScanTargetsInternal(const char *portal, vars, virISCSIGetTargets, &list, NULL, NULL) < 0) - goto cleanup; + return -1; =20 if (ntargetsret && targetsret) { *ntargetsret =3D list.ntargets; @@ -457,10 +444,7 @@ virISCSIScanTargetsInternal(const char *portal, VIR_FREE(list.targets); } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -538,9 +522,8 @@ int virISCSINodeNew(const char *portal, const char *target) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -553,20 +536,17 @@ virISCSINodeNew(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed new node mode for target '%s'"), target); - goto cleanup; + return -1; } =20 if (status !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s failed new mode for target '%s' with status '= %d'"), ISCSIADM, target, status); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -576,9 +556,8 @@ virISCSINodeUpdate(const char *portal, const char *name, const char *value) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -594,11 +573,8 @@ virISCSINodeUpdate(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update '%s' of node mode for target '%= s'"), name, target); - 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