return ret;
}
+/**
+ * prlsdkDomainHasSnapshots:
+ *
+ * This function detects where a domain specified by @sdkdom
+ * has snapshots. It doesn't count them correctly.
+ *
+ * @sdkdom: domain handle
+ * @found: a value more than zero if snapshots present
+ *
+ * Returns 0 if function succeeds, -1 otherwise.
+ */
+static int
+prlsdkDomainHasSnapshots(PRL_HANDLE sdkdom, int* found)
+{
+ int ret = -1;
+ PRL_RESULT pret;
+ PRL_HANDLE job;
+ PRL_HANDLE result;
+ char *snapshotxml = NULL;
+ unsigned int len, paramsCount;
+ xmlDocPtr xml = NULL;
+ xmlXPathContextPtr ctxt = NULL;
+
+ if (!found)
+ goto cleanup;
+ job = PrlVm_GetSnapshotsTreeEx(sdkdom, PGST_WITHOUT_SCREENSHOTS);
+ if (PRL_FAILED(getJobResult(job, &result)))
+ goto cleanup;
+
+ pret = PrlResult_GetParamsCount(result, ¶msCount);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ if (!paramsCount)
+ goto cleanup;
+
+ pret = PrlResult_GetParamAsString(result, 0, &len);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ if (VIR_ALLOC_N(snapshotxml, len+1) < 0)
+ goto cleanup;
+
+ pret = PrlResult_GetParamAsString(result, snapshotxml, &len);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ if (len <= 1) {
+ /* The document is empty that means no snapshots */
+ *found = 0;
+ ret = 0;
+ goto cleanup;
+ }
+
+ if (!(xml = virXMLParseStringCtxt(snapshotxml, "SavedStateItem", &ctxt)))
+ goto cleanup;
+
+ *found = virXMLChildElementCount(ctxt->node);
+ ret = 0;
+
+ cleanup:
+
+ xmlXPathFreeContext(ctxt);
+ xmlFreeDoc(xml);
+ VIR_FREE(snapshotxml);
+ return ret;
+}
int
-prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom)
+prlsdkUnregisterDomain(vzConnPtr privconn, virDomainObjPtr dom, unsigned int flags)
{
vzDomObjPtr privdom = dom->privateData;
PRL_HANDLE job;
size_t i;
+ int snapshotfound = 0;
+ VIRTUAL_MACHINE_STATE domainState;
+
+ if (prlsdkGetDomainState(privdom->sdkdom, &domainState) < 0)
+ return -1;
+
+ if (VMS_SUSPENDED == domainState &&
+ !(flags & VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)) {
+
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("Refusing to undefine while domain managed "
+ "save image exists"));
+ return -1;
+ }
+
+ if (prlsdkDomainHasSnapshots(privdom->sdkdom, &snapshotfound) < 0)
+ return -1;
+ if (snapshotfound && !(flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("Refusing to undefine while snapshots exist"));
+ return -1;
+ }
if (prlsdkDetachDomainHardDisks(privdom->sdkdom))
return -1;