]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add wrapper for virDomainSnapshotFree
authorPeter Krempa <pkrempa@redhat.com>
Tue, 11 Apr 2017 15:21:05 +0000 (17:21 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 12 Apr 2017 12:11:39 +0000 (14:11 +0200)
Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

cfg.mk
tools/virsh-snapshot.c
tools/virsh-util.c
tools/virsh-util.h

diff --git a/cfg.mk b/cfg.mk
index 022c11cd9a7cd66d537db1c6cd14ff931697170a..4c2219524e7733a297a95935a9c738a7c59127b6 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1015,10 +1015,10 @@ sc_gettext_init:
          $(_sc_search_regexp)
 
 sc_prohibit_obj_free_apis_in_virsh:
-       @prohibit='\bvirDomainFree\b' \
+       @prohibit='\bvir(Domain|DomainSnapshot)Free\b' \
        in_vc_files='virsh.*\.[ch]$$'                              \
        exclude='sc_prohibit_obj_free_apis_in_virsh' \
-       halt='avoid using virDomainFree in virsh, use virsh-prefixed wrappers instead' \
+       halt='avoid using virDomain(Snapshot)Free in virsh, use virsh-prefixed wrappers instead' \
          $(_sc_search_regexp)
 
 # We don't use this feature of maint.mk.
index 5af9a7d7afa4529cbd8f7a001d82ce5e08febe96..24cd4abd9d1d1ffadbcca09aaad04f73df37f6b5 100644 (file)
@@ -106,8 +106,7 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
  cleanup:
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     VIR_FREE(doc);
     return ret;
 }
@@ -601,10 +600,8 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
  cleanup:
     if (!ret && name)
         vshError(ctl, _("Failed to update %s"), name);
-    if (edited)
-        virDomainSnapshotFree(edited);
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(edited);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
     return ret;
 }
@@ -681,7 +678,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
         if (!(snapshot2 = virDomainSnapshotCreateXML(dom, xml, flags)))
             goto cleanup;
 
-        virDomainSnapshotFree(snapshot2);
+        virshDomainSnapshotFree(snapshot2);
         vshPrintExtra(ctl, _("Snapshot %s set as current"), snapshotname);
         ret = true;
         goto cleanup;
@@ -717,8 +714,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
     if (!ret)
         vshReportError(ctl);
     VIR_FREE(xml);
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
 
     return ret;
@@ -777,8 +773,7 @@ virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
     } else {
         vshResetLibvirtError();
     }
-    if (parent)
-        virDomainSnapshotFree(parent);
+    virshDomainSnapshotFree(parent);
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xmldoc);
     VIR_FREE(xml);
@@ -906,7 +901,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
         if (other) {
             if (STREQ(name, virDomainSnapshotGetName(other)))
                 current = 1;
-            virDomainSnapshotFree(other);
+            virshDomainSnapshotFree(other);
         }
     }
     vshPrint(ctl, "%-15s %s\n", _("Current:"),
@@ -1005,8 +1000,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
     xmlFreeDoc(xmldoc);
     VIR_FREE(doc);
     VIR_FREE(parent);
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
     return ret;
 }
@@ -1031,8 +1025,7 @@ virshSnapshotListFree(virshSnapshotListPtr snaplist)
         return;
     if (snaplist->snaps) {
         for (i = 0; i < snaplist->nsnaps; i++) {
-            if (snaplist->snaps[i].snap)
-                virDomainSnapshotFree(snaplist->snaps[i].snap);
+            virshDomainSnapshotFree(snaplist->snaps[i].snap);
             VIR_FREE(snaplist->snaps[i].parent);
         }
         VIR_FREE(snaplist->snaps);
@@ -1270,7 +1263,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
                            STRNEQ_NULLABLE(fromname,
                                            snaplist->snaps[i].parent)))) ||
                 (roots && snaplist->snaps[i].parent)) {
-                virDomainSnapshotFree(snaplist->snaps[i].snap);
+                virshDomainSnapshotFree(snaplist->snaps[i].snap);
                 snaplist->snaps[i].snap = NULL;
                 VIR_FREE(snaplist->snaps[i].parent);
                 deleted++;
@@ -1298,7 +1291,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
         for (i = 0; i < count; i++) {
             if (i == start_index || !snaplist->snaps[i].parent) {
                 VIR_FREE(names[i]);
-                virDomainSnapshotFree(snaplist->snaps[i].snap);
+                virshDomainSnapshotFree(snaplist->snaps[i].snap);
                 snaplist->snaps[i].snap = NULL;
                 VIR_FREE(snaplist->snaps[i].parent);
                 deleted++;
@@ -1336,7 +1329,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
                 if (!found_parent) {
                     changed = true;
                     VIR_FREE(names[i]);
-                    virDomainSnapshotFree(snaplist->snaps[i].snap);
+                    virshDomainSnapshotFree(snaplist->snaps[i].snap);
                     snaplist->snaps[i].snap = NULL;
                     VIR_FREE(snaplist->snaps[i].parent);
                     deleted++;
@@ -1359,7 +1352,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
             case 1:
                 break;
             case 0:
-                virDomainSnapshotFree(snaplist->snaps[i].snap);
+                virshDomainSnapshotFree(snaplist->snaps[i].snap);
                 snaplist->snaps[i].snap = NULL;
                 VIR_FREE(snaplist->snaps[i].parent);
                 deleted++;
@@ -1641,8 +1634,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
     virshSnapshotListFree(snaplist);
     VIR_FREE(parent_snap);
     VIR_FREE(state);
-    if (start)
-        virDomainSnapshotFree(start);
+    virshDomainSnapshotFree(start);
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(doc);
@@ -1708,8 +1700,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     VIR_FREE(xml);
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
 
     return ret;
@@ -1768,8 +1759,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     VIR_FREE(parent);
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
 
     return ret;
@@ -1853,8 +1843,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
 
     return ret;
@@ -1935,8 +1924,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    if (snapshot)
-        virDomainSnapshotFree(snapshot);
+    virshDomainSnapshotFree(snapshot);
     virshDomainFree(dom);
 
     return ret;
index 5fdb40855f4ae53dce19330eb1017bbb05c7ecd4..e225d3332b649f5e3a451f121c6ac65c63e3af2e 100644 (file)
@@ -160,3 +160,13 @@ virshDomainFree(virDomainPtr dom)
 
     virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */
 }
+
+
+void
+virshDomainSnapshotFree(virDomainSnapshotPtr snap)
+{
+    if (!snap)
+        return;
+
+    virDomainSnapshotFree(snap); /* sc_prohibit_obj_free_apis_in_virsh */
+}
index 78f7a0ea9b124db759c8715c5d5ef56a3f14f382..2b5aedfba5955519db082453f8fb9ad6b35ecce8 100644 (file)
@@ -41,6 +41,9 @@ virshCommandOptDomain(vshControl *ctl,
 void
 virshDomainFree(virDomainPtr dom);
 
+void
+virshDomainSnapshotFree(virDomainSnapshotPtr snap);
+
 int
 virshDomainState(vshControl *ctl,
                  virDomainPtr dom,