]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: support domain undefine
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Fri, 28 Feb 2014 19:18:43 +0000 (23:18 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Fri, 28 Feb 2014 19:23:44 +0000 (23:23 +0400)
Implement domainUndefine and required helper functions:
 - domainIsActive
 - domainIsPersistent

src/bhyve/bhyve_driver.c
src/bhyve/bhyve_utils.h

index accb37fa4aec859ea344e15bed4d7784c39c1c0a..23fab9013f769cb0e32c80b50e9b5735ab228731 100644 (file)
@@ -256,6 +256,44 @@ cleanup:
     return ret;
 }
 
+static int
+bhyveDomainIsActive(virDomainPtr domain)
+{
+    virDomainObjPtr obj;
+    int ret = -1;
+
+    if (!(obj = bhyveDomObjFromDomain(domain)))
+        goto cleanup;
+
+    if (virDomainIsActiveEnsureACL(domain->conn, obj->def) < 0)
+        goto cleanup;
+
+    ret = virDomainObjIsActive(obj);
+
+cleanup:
+    virObjectUnlock(obj);
+    return ret;
+}
+
+static int
+bhyveDomainIsPersistent(virDomainPtr domain)
+{
+    virDomainObjPtr obj;
+    int ret = -1;
+
+    if (!(obj = bhyveDomObjFromDomain(domain)))
+        goto cleanup;
+
+    if (virDomainIsPersistentEnsureACL(domain->conn, obj->def) < 0)
+        goto cleanup;
+
+    ret = obj->persistent;
+
+cleanup:
+    virObjectUnlock(obj);
+    return ret;
+}
+
 static char *
 bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
 {
@@ -312,6 +350,44 @@ cleanup:
     return dom;
 }
 
+static int
+bhyveDomainUndefine(virDomainPtr domain)
+{
+    bhyveConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr vm;
+    int ret = -1;
+
+    if (!(vm = bhyveDomObjFromDomain(domain)))
+        goto cleanup;
+
+    if (virDomainUndefineEnsureACL(domain->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (!vm->persistent) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("Cannot undefine transient domain"));
+        goto cleanup;
+    }
+
+    if (virDomainDeleteConfig(BHYVE_CONFIG_DIR,
+                              BHYVE_AUTOSTART_DIR,
+                              vm) < 0)
+        goto cleanup;
+
+    if (virDomainObjIsActive(vm)) {
+        vm->persistent = 0;
+    } else {
+        virDomainObjListRemove(privconn->domains, vm);
+        vm = NULL;
+    }
+
+    ret = 0;
+
+cleanup:
+    virObjectUnlock(vm);
+    return ret;
+}
+
 static int
 bhyveConnectListDomains(virConnectPtr conn, int *ids, int maxids)
 {
@@ -620,7 +696,10 @@ static virDriver bhyveDriver = {
     .domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */
     .domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */
     .domainDefineXML = bhyveDomainDefineXML, /* 1.2.2 */
+    .domainUndefine = bhyveDomainUndefine, /* 1.2.2 */
     .domainGetXMLDesc = bhyveDomainGetXMLDesc, /* 1.2.2 */
+    .domainIsActive = bhyveDomainIsActive, /* 1.2.2 */
+    .domainIsPersistent = bhyveDomainIsPersistent, /* 1.2.2 */
     .nodeGetCPUStats = bhyveNodeGetCPUStats, /* 1.2.2 */
     .nodeGetMemoryStats = bhyveNodeGetMemoryStats, /* 1.2.2 */
 };
index 7579f4a38994ee7403bbb8d9ad71725c2757c71c..0810caa70378ef81a1a79445dd9d7ab6f70ca94c 100644 (file)
@@ -27,6 +27,7 @@
 # include "configmake.h"
 # include "virthread.h"
 
+# define BHYVE_AUTOSTART_DIR    SYSCONFDIR "/libvirt/bhyve/autostart"
 # define BHYVE_CONFIG_DIR       SYSCONFDIR "/libvirt/bhyve"
 # define BHYVE_STATE_DIR        LOCALSTATEDIR "/run/libvirt/bhyve"
 # define BHYVE_LOG_DIR          LOCALSTATEDIR "/log/libvirt/bhyve"