[PATCH] bhyve: support domain undefine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Implement domainUndefine and required helper functions:
 - domainIsActive
 - domainIsPersistent
---
 src/bhyve/bhyve_driver.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/bhyve/bhyve_utils.h  |  1 +
 2 files changed, 80 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index accb37f..23fab90 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -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)
 {
@@ -313,6 +351,44 @@ cleanup:
 }
 
 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)
 {
     bhyveConnPtr privconn = conn->privateData;
@@ -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 */
 };
diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
index 7579f4a..0810caa 100644
--- a/src/bhyve/bhyve_utils.h
+++ b/src/bhyve/bhyve_utils.h
@@ -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"
-- 
1.8.4.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]