From nobody Tue Feb 10 04:02:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632719352; cv=none; d=zohomail.com; s=zohoarc; b=Avrx1Z+ty/Nkf8103OSjL0srL2dP99fGDRSSRfGhYq1eux4F5di4jT94YVz1j2zt1EF7gh2PpkzDDdOawqXrbITilvzygEHaqhhrXH4KloboOkMfD30fqHiCiUs17KKsF6tSwOXYutbm5ceWKJM7KZHdfu6VMs2V+JB+XX2q1h0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719352; 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=IkSMyrasqaVxygbUEhQSp+KMRZ24xyJKUL2fr1Jdrxc=; b=OF01/L8ks4+DAGm8KPPrGtquy2+gGdqsNp+AByw6WsVqB0FsxYuDNQQ1yVleSGvVt0Uz5kqUZAZsNqZ4rS/y31XGnnfv6LsVDdCRBLxf4gLo5TddboNIaL67zx9197w+twiUa9B6UK0UVVIlmvf+HxL2n26UzO8HFR8JK1fcXjY= 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) 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 1632719352194102.74060129416773; Sun, 26 Sep 2021 22:09: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-29-7Lb4zWbEPaqlRS0pdq9vMg-1; Mon, 27 Sep 2021 01:08:22 -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 57F40101F008; Mon, 27 Sep 2021 05:08:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38D1E5C1BB; Mon, 27 Sep 2021 05:08:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 072594EA3A; Mon, 27 Sep 2021 05:08:17 +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 18R5848a004230 for ; Mon, 27 Sep 2021 01:08:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 938FD53E08; Mon, 27 Sep 2021 05:08:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 057B860657 for ; Mon, 27 Sep 2021 05:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719351; 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=IkSMyrasqaVxygbUEhQSp+KMRZ24xyJKUL2fr1Jdrxc=; b=J0k0FzW/Bi9b8fPlL5i7qAGf8z9zjx5ZFydlJo6LruT7sUSGeLu5kWIiWqzIJ1jgaF2gaB PGxnOE0yOyNhOOQv4PGI1hwBxxrbWZtuND+dohFi1be0ShqD1yVLpBkj7p7cjSBx15Cp0I zfvLOqS5qif/B/pCsZXv005/kVM3Q+0= X-MC-Unique: 7Lb4zWbEPaqlRS0pdq9vMg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/8] virsh: Add wrapper for virNodeDeviceFree Date: Mon, 27 Sep 2021 07:07:48 +0200 Message-Id: <58f9333f85be3af0a6f7269481cf09f943e798d2.1632718996.git.mprivozn@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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632719353778100001 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-nodedev.c | 3 +- tools/virsh-nodedev.c | 49 ++++++++++----------------------- tools/virsh-util.c | 11 ++++++++ tools/virsh-util.h | 5 ++++ 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 0c0d844d6c..6c230826bd 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -868,7 +868,7 @@ sc_gettext_init: $(_sc_search_regexp) =20 sc_prohibit_obj_free_apis_in_virsh: - @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|Secret|Storage= Pool|StorageVol)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|Sec= ret|StoragePool|StorageVol)Free\b' \ in_vc_files=3D'virsh.*\.[ch]$$' \ exclude=3D'sc_prohibit_obj_free_apis_in_virsh' \ halt=3D'avoid using public virXXXFree in virsh, use virsh-prefixed wrappe= rs instead' \ diff --git a/tools/virsh-completer-nodedev.c b/tools/virsh-completer-nodede= v.c index d595b687fd..d10bf2b78c 100644 --- a/tools/virsh-completer-nodedev.c +++ b/tools/virsh-completer-nodedev.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-nodedev.h" +#include "virsh-util.h" #include "conf/node_device_conf.h" #include "viralloc.h" #include "virsh-nodedev.h" @@ -58,7 +59,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 for (i =3D 0; i < ndevs; i++) - virNodeDeviceFree(devs[i]); + virshNodeDeviceFree(devs[i]); g_free(devs); return ret; } diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index f72359121f..c989a77ad2 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -20,6 +20,7 @@ =20 #include #include "virsh-nodedev.h" +#include "virsh-util.h" =20 #include "internal.h" #include "viralloc.h" @@ -55,7 +56,7 @@ static const vshCmdOptDef opts_node_device_create[] =3D { static bool cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; virshControl *priv =3D ctl->privData; @@ -73,7 +74,6 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Node device %s created from %s\n"), virNodeDeviceGetName(dev), from); - virNodeDeviceFree(dev); return true; } =20 @@ -140,7 +140,7 @@ vshFindNodeDevice(vshControl *ctl, const char *value) static bool cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; const char *device_value =3D NULL; =20 @@ -160,8 +160,6 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -207,8 +205,7 @@ virshNodeDeviceListFree(struct virshNodeDeviceList *lis= t) =20 if (list && list->devices) { for (i =3D 0; i < list->ndevices; i++) { - if (list->devices[i]) - virNodeDeviceFree(list->devices[i]); + virshNodeDeviceFree(list->devices[i]); } g_free(list->devices); } @@ -327,8 +324,7 @@ virshNodeDeviceListCollect(vshControl *ctl, =20 remove_entry: /* the device has to be removed as it failed one of the filters */ - virNodeDeviceFree(list->devices[i]); - list->devices[i] =3D NULL; + g_clear_pointer(&list->devices[i], virshNodeDeviceFree); deleted++; } =20 @@ -576,7 +572,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = =3D { static bool cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr device =3D NULL; + g_autoptr(virshNodeDevice) device =3D NULL; g_autofree char *xml =3D NULL; const char *device_value =3D NULL; bool ret =3D false; @@ -596,8 +592,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (device) - virNodeDeviceFree(device); return ret; } =20 @@ -634,7 +628,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; const char *driverName =3D NULL; - virNodeDevicePtr device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -664,7 +658,6 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, _("Failed to detach device %s"), name); =20 - virNodeDeviceFree(device); return ret; } =20 @@ -696,7 +689,7 @@ static bool cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; - virNodeDevicePtr device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -715,7 +708,6 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cm= d) ret =3D false; } =20 - virNodeDeviceFree(device); return ret; } =20 @@ -747,7 +739,7 @@ static bool cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; - virNodeDevicePtr device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -766,7 +758,6 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNodeDeviceFree(device); return ret; } =20 @@ -910,7 +901,7 @@ static const vshCmdOptDef opts_node_device_event[] =3D { static bool cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; int eventId =3D -1; int timeout =3D 0; @@ -988,8 +979,6 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >=3D 0 && virConnectNodeDeviceEventDeregisterAny(priv->conn, eventId) < 0) ret =3D false; - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -1020,7 +1009,7 @@ static const vshCmdOptDef opts_node_device_undefine[]= =3D { static bool cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; const char *device_value =3D NULL; =20 @@ -1041,8 +1030,6 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *= cmd G_GNUC_UNUSED) =20 ret =3D true; cleanup: - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -1071,7 +1058,7 @@ static const vshCmdOptDef opts_node_device_define[] = =3D { static bool cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; virshControl *priv =3D ctl->privData; @@ -1089,7 +1076,6 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cm= d G_GNUC_UNUSED) =20 vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"), virNodeDeviceGetName(dev), from); - virNodeDeviceFree(dev); return true; } =20 @@ -1121,7 +1107,7 @@ static bool cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; - virNodeDevice *device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -1140,7 +1126,6 @@ cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNodeDeviceFree(device); return ret; } =20 @@ -1175,7 +1160,7 @@ static const vshCmdOptDef opts_node_device_autostart[= ] =3D { static bool cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; const char *name =3D NULL; int autostart; @@ -1204,8 +1189,6 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd = *cmd) =20 ret =3D true; cleanup: - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -1237,7 +1220,7 @@ static const vshCmdOptDef opts_node_device_info[] =3D= { static bool cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr device =3D NULL; + g_autoptr(virshNodeDevice) device =3D NULL; const char *device_value =3D NULL; bool ret =3D false; int autostart; @@ -1265,8 +1248,6 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (device) - virNodeDeviceFree(device); return ret; } =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index f7b649983e..5034f4773f 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -307,6 +307,17 @@ virshNetworkFree(virNetworkPtr network) } =20 =20 +void +virshNodeDeviceFree(virNodeDevicePtr device) +{ + if (!device) + return; + + vshSaveLibvirtHelperError(); + virNodeDeviceFree(device); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshSecretFree(virSecretPtr secret) { diff --git a/tools/virsh-util.h b/tools/virsh-util.h index e8df0a6618..06e311b21a 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -64,6 +64,11 @@ void virshNetworkFree(virNetworkPtr network); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNetwork, virshNetworkFree); =20 +typedef virNodeDevice virshNodeDevice; +void +virshNodeDeviceFree(virNodeDevicePtr device); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNodeDevice, virshNodeDeviceFree); + typedef virSecret virshSecret; void virshSecretFree(virSecretPtr secret); --=20 2.32.0