diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 0b1e981231..fedd84a307 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -6069,3 +6069,43 @@ char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, vboxIIDUnalloc(&domiid); return ret; } + +int vboxDomainSnapshotNum(virDomainPtr dom, unsigned int flags) +{ + VBOX_OBJECT_CHECK(dom->conn, int, -1); + vboxIIDUnion iid; + IMachine *machine = NULL; + nsresult rc; + PRUint32 snapshotCount; + + virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); + + if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0) + goto cleanup; + + /* VBox snapshots do not require libvirt to maintain any metadata. */ + if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) { + ret = 0; + goto cleanup; + } + + rc = gVBoxAPI.UIMachine.GetSnapshotCount(machine, &snapshotCount); + if (NS_FAILED(rc)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("could not get snapshot count for domain %s"), + dom->name); + goto cleanup; + } + + /* VBox has at most one root snapshot. */ + if (snapshotCount && (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)) + ret = 1; + else + ret = snapshotCount; + + cleanup: + VBOX_RELEASE(machine); + vboxIIDUnalloc(&iid); + return ret; +} diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index c5493bc465..38c9ca35e5 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -1523,53 +1523,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data, return snapshot; } -static int -vboxDomainSnapshotNum(virDomainPtr dom, - unsigned int flags) -{ - VBOX_OBJECT_CHECK(dom->conn, int, -1); - vboxIID iid = VBOX_IID_INITIALIZER; - IMachine *machine = NULL; - nsresult rc; - PRUint32 snapshotCount; - - virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | - VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); - - vboxIIDFromUUID(&iid, dom->uuid); - rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_NO_DOMAIN, "%s", - _("no domain with matching UUID")); - goto cleanup; - } - - /* VBox snapshots do not require libvirt to maintain any metadata. */ - if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) { - ret = 0; - goto cleanup; - } - - rc = machine->vtbl->GetSnapshotCount(machine, &snapshotCount); - if (NS_FAILED(rc)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("could not get snapshot count for domain %s"), - dom->name); - goto cleanup; - } - - /* VBox has at most one root snapshot. */ - if (snapshotCount && (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)) - ret = 1; - else - ret = snapshotCount; - - cleanup: - VBOX_RELEASE(machine); - vboxIIDUnalloc(&iid); - return ret; -} - static int vboxDomainSnapshotListNames(virDomainPtr dom, char **names, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 6b04b57216..ba75d007d0 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -577,6 +577,7 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom, unsigned int flags); char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, unsigned int flags); +int vboxDomainSnapshotNum(virDomainPtr dom, unsigned int flags); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);