From nobody Tue Feb 10 04:02:59 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=1632719300; cv=none; d=zohomail.com; s=zohoarc; b=QQjXc5MzL2iF67SFerkyWJDqqp6LxokdJTKj0r2qawJmWdNzOZHMBPOqx+LT+XZQXuk0IPq4Rg0Nivh8YOjyUAoDgKhiFAcs9cpfw+joxE+WQDNwtuF+hGujHiTEZcCMalHkOXAalhOOwb6DC6ZT+YBu+c3uyNJxrrO5ZL9Qpwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719300; 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=RHIkpEiULOi7Fi/wkgXGlzv4KfU+1REJBXMDWIRKaII=; b=Y2W2vHA+I2ebfjuwCYcYcq6cgENjM1B3Yv8G4T1uJ4CH+ZUCNHAH5L0VlfUkFONg2WWxYSrZ4mx50CTs4S9NgucFlWcBQNIS/mGqJFPLTxuYCTE1vb0RcW/Y/1xWL2KY0psCze5Q0rYUri6yF5wHgnBqPFSKdsBd73MdGrv6d04= 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 1632719300920735.4201715216245; Sun, 26 Sep 2021 22:08:20 -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-479-j-mymzRyOr2awMOm0KHDtA-1; Mon, 27 Sep 2021 01:08:18 -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 9D83136304; Mon, 27 Sep 2021 05:08:11 +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 7F23E5C1BB; Mon, 27 Sep 2021 05:08:11 +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 510BE1806D01; Mon, 27 Sep 2021 05:08:11 +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 18R582q4004201 for ; Mon, 27 Sep 2021 01:08:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id A50B7179B3; Mon, 27 Sep 2021 05:08:02 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 173D8652A1 for ; Mon, 27 Sep 2021 05:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719299; 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=RHIkpEiULOi7Fi/wkgXGlzv4KfU+1REJBXMDWIRKaII=; b=FUIlDrz2ufKd6jNTazS/1L0IqaTt+8W67P/bVRTkHkz43+7oCupWKMIdfnsIGGc7ZVer2N 8XqHTTwRg1NNqBTlkzgFof17xLFQnczVmVl/rODDBCsJFO2hIX2LkP24sDTf0dRD1JK15G 8Cyo2yFgeSLiEWdm6rmsQryNCgH9Z/0= X-MC-Unique: j-mymzRyOr2awMOm0KHDtA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/8] virsh: Add wrapper for virStorageVolFree Date: Mon, 27 Sep 2021 07:07:46 +0200 Message-Id: <3fe845cc428bdaddc3ffcfefa1a6016b17363c20.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: 1632719302582100005 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-volume.c | 4 +- tools/virsh-domain.c | 3 +- tools/virsh-util.c | 11 ++++++ tools/virsh-util.h | 5 +++ tools/virsh-volume.c | 72 ++++++++++------------------------ 6 files changed, 40 insertions(+), 57 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 111d2109e8..2bdbd14c80 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|Secret|StoragePool)Fre= e\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Secret|StoragePool|Sto= rageVol)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-volume.c b/tools/virsh-completer-volume.c index 1d83643c69..ac3c472177 100644 --- a/tools/virsh-completer-volume.c +++ b/tools/virsh-completer-volume.c @@ -65,7 +65,7 @@ virshStorageVolNameCompleter(vshControl *ctl, =20 cleanup: for (i =3D 0; i < nvols; i++) - virStorageVolFree(vols[i]); + virshStorageVolFree(vols[i]); g_free(vols); return ret; } @@ -104,7 +104,7 @@ virshStorageVolKeyCompleter(vshControl *ctl, const char *key =3D virStorageVolGetKey(vols[j]); tmp[nvols] =3D g_strdup(key); nvols++; - virStorageVolFree(vols[j]); + virshStorageVolFree(vols[j]); } =20 g_free(vols); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 461a5e19f6..b1943b3875 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3942,8 +3942,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) for (i =3D 0; i < nvols; i++) { VIR_FREE(vols[i].source); VIR_FREE(vols[i].target); - if (vols[i].vol) - virStorageVolFree(vols[i].vol); + virshStorageVolFree(vols[i].vol); } VIR_FREE(vols); =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index d537501387..c680c5b3d4 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -318,6 +318,17 @@ virshStoragePoolFree(virStoragePoolPtr pool) } =20 =20 +void +virshStorageVolFree(virStorageVolPtr vol) +{ + if (!vol) + return; + + vshSaveLibvirtHelperError(); + virStorageVolFree(vol); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + int virshDomainGetXMLFromDom(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 3ff6f16784..ce3462a865 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -69,6 +69,11 @@ void virshStoragePoolFree(virStoragePoolPtr pool); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStoragePool, virshStoragePoolFree); =20 +typedef virStorageVol virshStorageVol; +void +virshStorageVolFree(virStorageVolPtr vol); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStorageVol, virshStorageVolFree); + int virshDomainState(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 6e8f7721a3..b896ebbbf9 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -153,8 +153,7 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, vshError(ctl, _("Requested volume '%s' is not in pool '%s'"), n, virStoragePoolGetName(pool)); - virStorageVolFree(vol); - vol =3D NULL; + g_clear_pointer(&vol, virshStorageVolFree); } } } @@ -230,7 +229,7 @@ static bool cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr vol =3D NULL; + g_autoptr(virshStorageVol) vol =3D NULL; g_autofree char *xml =3D NULL; bool printXML =3D vshCommandOptBool(cmd, "print-xml"); const char *name, *capacityStr =3D NULL, *allocationStr =3D NULL, *for= mat =3D NULL; @@ -287,7 +286,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) =20 /* Convert the snapshot parameters into backingStore XML */ if (snapshotStrVol) { - virStorageVolPtr snapVol; + g_autoptr(virshStorageVol) snapVol =3D NULL; g_autofree char *snapshotStrVolPath =3D NULL; /* Lookup snapshot backing volume. Try the backing-vol * parameter as a name */ @@ -330,7 +329,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) } =20 if ((snapshotStrVolPath =3D virStorageVolGetPath(snapVol)) =3D=3D = NULL) { - virStorageVolFree(snapVol); goto cleanup; } =20 @@ -343,9 +341,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) snapshotStrFormat); virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - - /* Cleanup snapshot allocations */ - virStorageVolFree(snapVol); } =20 virBufferAdjustIndent(&buf, -2); @@ -366,8 +361,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (vol) - virStorageVolFree(vol); return ret; } =20 @@ -398,7 +391,7 @@ static bool cmdVolCreate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; const char *from =3D NULL; bool ret =3D false; unsigned int flags =3D 0; @@ -421,7 +414,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) if ((vol =3D virStorageVolCreateXML(pool, buffer, flags))) { vshPrintExtra(ctl, _("Vol %s created from %s\n"), virStorageVolGetName(vol), from); - virStorageVolFree(vol); ret =3D true; } else { vshError(ctl, _("Failed to create vol from %s"), from); @@ -468,7 +460,8 @@ static bool cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr newvol =3D NULL, inputvol =3D NULL; + g_autoptr(virshStorageVol) newvol =3D NULL; + g_autoptr(virshStorageVol) inputvol =3D NULL; const char *from =3D NULL; bool ret =3D false; g_autofree char *buffer =3D NULL; @@ -506,10 +499,6 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (inputvol) - virStorageVolFree(inputvol); - if (newvol) - virStorageVolFree(newvol); return ret; } =20 @@ -574,7 +563,8 @@ static bool cmdVolClone(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) origpool =3D NULL; - virStorageVolPtr origvol =3D NULL, newvol =3D NULL; + g_autoptr(virshStorageVol) origvol =3D NULL; + g_autoptr(virshStorageVol) newvol =3D NULL; const char *name =3D NULL; g_autofree char *origxml =3D NULL; xmlChar *newxml =3D NULL; @@ -624,10 +614,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) =20 cleanup: xmlFree(newxml); - if (origvol) - virStorageVolFree(origvol); - if (newvol) - virStorageVolFree(newvol); return ret; } =20 @@ -667,7 +653,7 @@ static bool cmdVolUpload(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; - virStorageVolPtr vol =3D NULL; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; virStreamPtr st =3D NULL; @@ -745,8 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (vol) - virStorageVolFree(vol); if (st) virStreamFree(st); VIR_FORCE_CLOSE(fd); @@ -789,7 +773,7 @@ static bool cmdVolDownload(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; - virStorageVolPtr vol =3D NULL; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; virStreamPtr st =3D NULL; @@ -867,8 +851,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) VIR_FORCE_CLOSE(fd); if (!ret && created) unlink(file); - if (vol) - virStorageVolFree(vol); if (st) virStreamFree(st); return ret; @@ -901,7 +883,7 @@ static const vshCmdOptDef opts_vol_delete[] =3D { static bool cmdVolDelete(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D true; const char *name; bool delete_snapshots =3D vshCommandOptBool(cmd, "delete-snapshots"); @@ -920,7 +902,6 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStorageVolFree(vol); return ret; } =20 @@ -956,7 +937,7 @@ VIR_ENUM_IMPL(virshStorageVolWipeAlgorithm, static bool cmdVolWipe(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; const char *name; const char *algorithm_str =3D NULL; @@ -989,7 +970,6 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Vol %s wiped\n"), name); ret =3D true; out: - virStorageVolFree(vol); return ret; } =20 @@ -1043,7 +1023,7 @@ static bool cmdVolInfo(vshControl *ctl, const vshCmd *cmd) { virStorageVolInfo info; - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool bytes =3D vshCommandOptBool(cmd, "bytes"); bool physical =3D vshCommandOptBool(cmd, "physical"); int rc; @@ -1063,7 +1043,6 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) rc =3D virStorageVolGetInfo(vol, &info); =20 if (rc < 0) { - virStorageVolFree(vol); return false; } =20 @@ -1090,7 +1069,6 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit= ); } =20 - virStorageVolFree(vol); return true; } =20 @@ -1136,7 +1114,7 @@ static const vshCmdOptDef opts_vol_resize[] =3D { static bool cmdVolResize(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; const char *capacityStr =3D NULL; unsigned long long capacity =3D 0; unsigned int flags =3D 0; @@ -1190,7 +1168,6 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) } =20 cleanup: - virStorageVolFree(vol); return ret; } =20 @@ -1216,7 +1193,7 @@ static const vshCmdOptDef opts_vol_dumpxml[] =3D { static bool cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D true; char *dump; =20 @@ -1231,7 +1208,6 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStorageVolFree(vol); return ret; } =20 @@ -1263,8 +1239,7 @@ virshStorageVolListFree(struct virshStorageVolList *l= ist) =20 if (list && list->vols) { for (i =3D 0; i < list->nvols; i++) { - if (list->vols[i]) - virStorageVolFree(list->vols[i]); + virshStorageVolFree(list->vols[i]); } g_free(list->vols); } @@ -1537,14 +1512,13 @@ static const vshCmdOptDef opts_vol_name[] =3D { static bool cmdVolName(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; =20 if (!(vol =3D virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL, VIRSH_BYUUID))) return false; =20 vshPrint(ctl, "%s\n", virStorageVolGetName(vol)); - virStorageVolFree(vol); return true; } =20 @@ -1574,7 +1548,7 @@ static bool cmdVolPool(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; char uuid[VIR_UUID_STRING_BUFLEN]; =20 /* Use the supplied string to locate the volume */ @@ -1587,7 +1561,6 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) pool =3D virStoragePoolLookupByVolume(vol); if (pool =3D=3D NULL) { vshError(ctl, "%s", _("failed to get parent pool")); - virStorageVolFree(vol); return false; } =20 @@ -1601,8 +1574,6 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s\n", virStoragePoolGetName(pool)); } =20 - /* Cleanup */ - virStorageVolFree(vol); return true; } =20 @@ -1628,13 +1599,12 @@ static const vshCmdOptDef opts_vol_key[] =3D { static bool cmdVolKey(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; =20 if (!(vol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; =20 vshPrint(ctl, "%s\n", virStorageVolGetKey(vol)); - virStorageVolFree(vol); return true; } =20 @@ -1660,19 +1630,17 @@ static const vshCmdOptDef opts_vol_path[] =3D { static bool cmdVolPath(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; g_autofree char *StorageVolPath =3D NULL; =20 if (!(vol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; =20 if ((StorageVolPath =3D virStorageVolGetPath(vol)) =3D=3D NULL) { - virStorageVolFree(vol); return false; } =20 vshPrint(ctl, "%s\n", StorageVolPath); - virStorageVolFree(vol); return true; } =20 --=20 2.32.0