From 91f396b33b026fe0810e4acdf314ad5af7dc20af Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Fri, 28 Feb 2014 23:18:43 +0400 Subject: [PATCH] bhyve: support domain undefine 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 accb37fa4a..23fab9013f 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) { @@ -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 */ }; diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h index 7579f4a389..0810caa703 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"