[PATCH 2/2] bhyve: domainCreateXML

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

 



Implement bhyveDomainCreteXML function.
---
 src/bhyve/bhyve_driver.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 23e7112..1357e07 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1107,6 +1107,75 @@ bhyveConnectCompareCPU(virConnectPtr conn,
     return ret;
 }
 
+static virDomainPtr
+bhyveDomainCreateXML(virConnectPtr conn,
+                     const char *xml,
+                     unsigned int flags)
+{
+    bhyveConnPtr privconn = conn->privateData;
+    virDomainPtr dom = NULL;
+    virDomainDefPtr def = NULL;
+    virDomainObjPtr vm = NULL;
+    virCapsPtr caps = NULL;
+    int ret;
+    unsigned int start_flags = 0;
+
+    virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL);
+
+    if (flags & VIR_DOMAIN_START_AUTODESTROY)
+        start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
+
+    caps = bhyveDriverGetCapabilities(privconn);
+    if (!caps)
+        return NULL;
+
+    if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt,
+                                       1 << VIR_DOMAIN_VIRT_BHYVE,
+                                       VIR_DOMAIN_XML_INACTIVE)) == NULL)
+        goto cleanup;
+
+    if (virDomainCreateXMLEnsureACL(conn, def) < 0)
+        goto cleanup;
+
+    if (!(vm = virDomainObjListAdd(privconn->domains, def,
+                                   privconn->xmlopt,
+                                   0, NULL)))
+        goto cleanup;
+    def = NULL;
+    vm->persistent = 0;
+
+    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
+    if (!dom)
+        goto cleanup;
+
+    dom->id = vm->def->id;
+
+    if (flags & VIR_DOMAIN_START_AUTODESTROY)
+        start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
+
+    if (virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("Domain is already running"));
+        goto cleanup;
+    }
+
+    ret = virBhyveProcessStart(dom->conn, privconn, vm,
+                               VIR_DOMAIN_RUNNING_BOOTED,
+                               start_flags);
+    if (ret) {
+        virObjectUnref(dom);
+        dom = NULL;
+        goto cleanup;
+    }
+
+ cleanup:
+    virObjectUnref(caps);
+    virDomainDefFree(def);
+    virObjectUnlock(vm);
+
+    return dom;
+}
+
 static virDriver bhyveDriver = {
     .no = VIR_DRV_BHYVE,
     .name = "bhyve",
@@ -1124,6 +1193,7 @@ static virDriver bhyveDriver = {
     .connectNumOfDefinedDomains = bhyveConnectNumOfDefinedDomains, /* 1.2.2 */
     .domainCreate = bhyveDomainCreate, /* 1.2.2 */
     .domainCreateWithFlags = bhyveDomainCreateWithFlags, /* 1.2.3 */
+    .domainCreateXML = bhyveDomainCreateXML, /* 1.2.4 */
     .domainDestroy = bhyveDomainDestroy, /* 1.2.2 */
     .domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */
     .domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */
-- 
1.9.0

--
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]