virsh: Add wrapper for virDomainSnapshotFree

Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.
This commit is contained in:
Peter Krempa 2017-04-11 17:21:05 +02:00
parent 3a344d55d9
commit 010c8f0f26
4 changed files with 33 additions and 32 deletions

4
cfg.mk
View File

@ -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.

View 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;

View 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 */
}

View File

@ -41,6 +41,9 @@ virshCommandOptDomain(vshControl *ctl,
void
virshDomainFree(virDomainPtr dom);
void
virshDomainSnapshotFree(virDomainSnapshotPtr snap);
int
virshDomainState(vshControl *ctl,
virDomainPtr dom,