提交 010c8f0f 编写于 作者: P Peter Krempa

virsh: Add wrapper for virDomainSnapshotFree

Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.
上级 3a344d55
...@@ -1015,10 +1015,10 @@ sc_gettext_init: ...@@ -1015,10 +1015,10 @@ sc_gettext_init:
$(_sc_search_regexp) $(_sc_search_regexp)
sc_prohibit_obj_free_apis_in_virsh: sc_prohibit_obj_free_apis_in_virsh:
@prohibit='\bvirDomainFree\b' \ @prohibit='\bvir(Domain|DomainSnapshot)Free\b' \
in_vc_files='virsh.*\.[ch]$$' \ in_vc_files='virsh.*\.[ch]$$' \
exclude='sc_prohibit_obj_free_apis_in_virsh' \ 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) $(_sc_search_regexp)
# We don't use this feature of maint.mk. # We don't use this feature of maint.mk.
......
...@@ -106,8 +106,7 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, ...@@ -106,8 +106,7 @@ virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
VIR_FREE(doc); VIR_FREE(doc);
return ret; return ret;
} }
...@@ -601,10 +600,8 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -601,10 +600,8 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
if (!ret && name) if (!ret && name)
vshError(ctl, _("Failed to update %s"), name); vshError(ctl, _("Failed to update %s"), name);
if (edited) virshDomainSnapshotFree(edited);
virDomainSnapshotFree(edited); virshDomainSnapshotFree(snapshot);
if (snapshot)
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
} }
...@@ -681,7 +678,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) ...@@ -681,7 +678,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
if (!(snapshot2 = virDomainSnapshotCreateXML(dom, xml, flags))) if (!(snapshot2 = virDomainSnapshotCreateXML(dom, xml, flags)))
goto cleanup; goto cleanup;
virDomainSnapshotFree(snapshot2); virshDomainSnapshotFree(snapshot2);
vshPrintExtra(ctl, _("Snapshot %s set as current"), snapshotname); vshPrintExtra(ctl, _("Snapshot %s set as current"), snapshotname);
ret = true; ret = true;
goto cleanup; goto cleanup;
...@@ -717,8 +714,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) ...@@ -717,8 +714,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
if (!ret) if (!ret)
vshReportError(ctl); vshReportError(ctl);
VIR_FREE(xml); VIR_FREE(xml);
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
...@@ -777,8 +773,7 @@ virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot, ...@@ -777,8 +773,7 @@ virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
} else { } else {
vshResetLibvirtError(); vshResetLibvirtError();
} }
if (parent) virshDomainSnapshotFree(parent);
virDomainSnapshotFree(parent);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xmldoc); xmlFreeDoc(xmldoc);
VIR_FREE(xml); VIR_FREE(xml);
...@@ -906,7 +901,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) ...@@ -906,7 +901,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
if (other) { if (other) {
if (STREQ(name, virDomainSnapshotGetName(other))) if (STREQ(name, virDomainSnapshotGetName(other)))
current = 1; current = 1;
virDomainSnapshotFree(other); virshDomainSnapshotFree(other);
} }
} }
vshPrint(ctl, "%-15s %s\n", _("Current:"), vshPrint(ctl, "%-15s %s\n", _("Current:"),
...@@ -1005,8 +1000,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) ...@@ -1005,8 +1000,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
xmlFreeDoc(xmldoc); xmlFreeDoc(xmldoc);
VIR_FREE(doc); VIR_FREE(doc);
VIR_FREE(parent); VIR_FREE(parent);
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
} }
...@@ -1031,8 +1025,7 @@ virshSnapshotListFree(virshSnapshotListPtr snaplist) ...@@ -1031,8 +1025,7 @@ virshSnapshotListFree(virshSnapshotListPtr snaplist)
return; return;
if (snaplist->snaps) { if (snaplist->snaps) {
for (i = 0; i < snaplist->nsnaps; i++) { for (i = 0; i < snaplist->nsnaps; i++) {
if (snaplist->snaps[i].snap) virshDomainSnapshotFree(snaplist->snaps[i].snap);
virDomainSnapshotFree(snaplist->snaps[i].snap);
VIR_FREE(snaplist->snaps[i].parent); VIR_FREE(snaplist->snaps[i].parent);
} }
VIR_FREE(snaplist->snaps); VIR_FREE(snaplist->snaps);
...@@ -1270,7 +1263,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, ...@@ -1270,7 +1263,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
STRNEQ_NULLABLE(fromname, STRNEQ_NULLABLE(fromname,
snaplist->snaps[i].parent)))) || snaplist->snaps[i].parent)))) ||
(roots && snaplist->snaps[i].parent)) { (roots && snaplist->snaps[i].parent)) {
virDomainSnapshotFree(snaplist->snaps[i].snap); virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL; snaplist->snaps[i].snap = NULL;
VIR_FREE(snaplist->snaps[i].parent); VIR_FREE(snaplist->snaps[i].parent);
deleted++; deleted++;
...@@ -1298,7 +1291,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, ...@@ -1298,7 +1291,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (i == start_index || !snaplist->snaps[i].parent) { if (i == start_index || !snaplist->snaps[i].parent) {
VIR_FREE(names[i]); VIR_FREE(names[i]);
virDomainSnapshotFree(snaplist->snaps[i].snap); virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL; snaplist->snaps[i].snap = NULL;
VIR_FREE(snaplist->snaps[i].parent); VIR_FREE(snaplist->snaps[i].parent);
deleted++; deleted++;
...@@ -1336,7 +1329,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, ...@@ -1336,7 +1329,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
if (!found_parent) { if (!found_parent) {
changed = true; changed = true;
VIR_FREE(names[i]); VIR_FREE(names[i]);
virDomainSnapshotFree(snaplist->snaps[i].snap); virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL; snaplist->snaps[i].snap = NULL;
VIR_FREE(snaplist->snaps[i].parent); VIR_FREE(snaplist->snaps[i].parent);
deleted++; deleted++;
...@@ -1359,7 +1352,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, ...@@ -1359,7 +1352,7 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
case 1: case 1:
break; break;
case 0: case 0:
virDomainSnapshotFree(snaplist->snaps[i].snap); virshDomainSnapshotFree(snaplist->snaps[i].snap);
snaplist->snaps[i].snap = NULL; snaplist->snaps[i].snap = NULL;
VIR_FREE(snaplist->snaps[i].parent); VIR_FREE(snaplist->snaps[i].parent);
deleted++; deleted++;
...@@ -1641,8 +1634,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) ...@@ -1641,8 +1634,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
virshSnapshotListFree(snaplist); virshSnapshotListFree(snaplist);
VIR_FREE(parent_snap); VIR_FREE(parent_snap);
VIR_FREE(state); VIR_FREE(state);
if (start) virshDomainSnapshotFree(start);
virDomainSnapshotFree(start);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
VIR_FREE(doc); VIR_FREE(doc);
...@@ -1708,8 +1700,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) ...@@ -1708,8 +1700,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_FREE(xml); VIR_FREE(xml);
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
...@@ -1768,8 +1759,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd) ...@@ -1768,8 +1759,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
VIR_FREE(parent); VIR_FREE(parent);
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
...@@ -1853,8 +1843,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd) ...@@ -1853,8 +1843,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
...@@ -1935,8 +1924,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) ...@@ -1935,8 +1924,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
ret = true; ret = true;
cleanup: cleanup:
if (snapshot) virshDomainSnapshotFree(snapshot);
virDomainSnapshotFree(snapshot);
virshDomainFree(dom); virshDomainFree(dom);
return ret; return ret;
......
...@@ -160,3 +160,13 @@ virshDomainFree(virDomainPtr dom) ...@@ -160,3 +160,13 @@ virshDomainFree(virDomainPtr dom)
virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ 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 */
}
...@@ -41,6 +41,9 @@ virshCommandOptDomain(vshControl *ctl, ...@@ -41,6 +41,9 @@ virshCommandOptDomain(vshControl *ctl,
void void
virshDomainFree(virDomainPtr dom); virshDomainFree(virDomainPtr dom);
void
virshDomainSnapshotFree(virDomainSnapshotPtr snap);
int int
virshDomainState(vshControl *ctl, virshDomainState(vshControl *ctl,
virDomainPtr dom, virDomainPtr dom,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册