2010-12-17 10:28:20 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-02-07 21:14:56 +00:00
|
|
|
/*
|
2012-09-12 16:54:42 +00:00
|
|
|
* Copyright (C) 2011-2012 Red Hat, Inc.
|
2011-02-07 21:14:56 +00:00
|
|
|
* Copyright 2010, diateam (www.diateam.net)
|
2013-10-01 02:13:17 +00:00
|
|
|
* Copyright (C) 2013. Doug Goldstein <cardoe@cardoe.com>
|
2010-12-17 10:28:20 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-12-17 10:28:20 +00:00
|
|
|
*/
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
#include "internal.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2010-12-21 21:39:55 +00:00
|
|
|
#include "datatypes.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2010-12-21 21:39:55 +00:00
|
|
|
#include "vmx.h"
|
2010-12-17 10:28:20 +00:00
|
|
|
#include "vmware_conf.h"
|
|
|
|
#include "vmware_driver.h"
|
2013-05-03 12:50:46 +00:00
|
|
|
#include "virstring.h"
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2013-09-15 04:28:20 +00:00
|
|
|
/* Various places we may find the "vmrun" binary,
|
|
|
|
* without a leading / it will be searched in PATH
|
|
|
|
*/
|
|
|
|
static const char * const vmrun_candidates[] = {
|
|
|
|
"vmrun",
|
2013-09-24 16:24:31 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
"/Applications/VMware Fusion.app/Contents/Library/vmrun",
|
|
|
|
"/Library/Application Support/VMware Fusion/vmrun",
|
|
|
|
#endif /* __APPLE__ */
|
2013-09-15 04:28:20 +00:00
|
|
|
};
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static void
|
|
|
|
vmwareDriverLock(struct vmware_driver *driver)
|
|
|
|
{
|
|
|
|
virMutexLock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vmwareDriverUnlock(struct vmware_driver *driver)
|
|
|
|
{
|
|
|
|
virMutexUnlock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
vmwareDataAllocFunc(void)
|
|
|
|
{
|
|
|
|
vmwareDomainPtr dom;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(dom) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dom->vmxPath = NULL;
|
|
|
|
dom->gui = true;
|
|
|
|
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vmwareDataFreeFunc(void *data)
|
|
|
|
{
|
|
|
|
vmwareDomainPtr dom = data;
|
|
|
|
|
|
|
|
VIR_FREE(dom->vmxPath);
|
|
|
|
VIR_FREE(dom);
|
|
|
|
}
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
static virDomainXMLOptionPtr
|
2013-03-05 15:17:24 +00:00
|
|
|
vmwareDomainXMLConfigInit(void)
|
|
|
|
{
|
|
|
|
virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc,
|
|
|
|
.free = vmwareDataFreeFunc };
|
|
|
|
|
2013-02-19 16:29:39 +00:00
|
|
|
return virDomainXMLOptionNew(NULL, &priv, NULL);
|
2013-03-05 15:17:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static virDrvOpenStatus
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver;
|
2013-09-15 04:28:20 +00:00
|
|
|
size_t i;
|
2013-09-24 16:24:30 +00:00
|
|
|
char *tmp;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2011-07-06 23:08:28 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
if (conn->uri == NULL) {
|
|
|
|
/* @TODO accept */
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
} else {
|
|
|
|
if (conn->uri->scheme == NULL ||
|
|
|
|
(STRNEQ(conn->uri->scheme, "vmwareplayer") &&
|
2013-09-24 16:24:31 +00:00
|
|
|
STRNEQ(conn->uri->scheme, "vmwarews") &&
|
|
|
|
STRNEQ(conn->uri->scheme, "vmwarefusion")))
|
2010-12-17 10:28:20 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* If server name is given, its for remote driver */
|
|
|
|
if (conn->uri->server != NULL)
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
/* If path isn't /session, then they typoed, so tell them correct path */
|
|
|
|
if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2013-09-24 16:24:31 +00:00
|
|
|
_("unexpected VMware URI path '%s', try vmwareplayer:///session, vmwarews:///session or vmwarefusion:///session"),
|
2012-07-18 13:22:54 +00:00
|
|
|
NULLSTR(conn->uri->path));
|
2010-12-17 10:28:20 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We now know the URI is definitely for this driver, so beyond
|
|
|
|
* here, don't return DECLINED, always use ERROR */
|
|
|
|
|
2013-09-15 04:28:20 +00:00
|
|
|
if (VIR_ALLOC(driver) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2013-09-15 04:28:20 +00:00
|
|
|
|
|
|
|
/* Find vmrun, which is what this driver uses to communicate to
|
|
|
|
* the VMware hypervisor. We look this up first since we use it
|
|
|
|
* for auto detection of the backend
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(vmrun_candidates); i++) {
|
|
|
|
driver->vmrun = virFindFileInPath(vmrun_candidates[i]);
|
|
|
|
/* If we found one, we can stop looking */
|
|
|
|
if (driver->vmrun)
|
|
|
|
break;
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-15 04:28:20 +00:00
|
|
|
if (driver->vmrun == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("vmrun utility is missing"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (virMutexInit(&driver->lock) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-09-24 16:24:30 +00:00
|
|
|
if ((tmp = STRSKIP(conn->uri->scheme, "vmware")) == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse URI "
|
|
|
|
"scheme '%s'"), conn->uri->scheme);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-01 02:13:17 +00:00
|
|
|
/* Match the non-'vmware' part of the scheme as the driver backend */
|
|
|
|
driver->type = vmwareDriverTypeFromString(tmp);
|
2013-09-24 16:24:30 +00:00
|
|
|
|
|
|
|
if (driver->type == -1) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find valid "
|
|
|
|
"requested VMware backend '%s'"), tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2013-10-01 02:19:13 +00:00
|
|
|
if (vmwareExtractVersion(driver) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(driver->domains = virDomainObjListNew()))
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(driver->caps = vmwareCapsInit()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
if (!(driver->xmlopt = vmwareDomainXMLConfigInit()))
|
2013-03-05 15:17:24 +00:00
|
|
|
goto cleanup;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (vmwareLoadDomains(driver) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
conn->privateData = driver;
|
|
|
|
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
vmwareFreeDriver(driver);
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectClose(virConnectPtr conn)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
|
|
|
|
vmwareFreeDriver(driver);
|
|
|
|
|
|
|
|
conn->privateData = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
return "VMware";
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectGetVersion(virConnectPtr conn, unsigned long *version)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
|
|
|
*version = driver->version;
|
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
static int
|
|
|
|
vmwareUpdateVMStatus(struct vmware_driver *driver, virDomainObjPtr vm)
|
|
|
|
{
|
|
|
|
virCommandPtr cmd;
|
|
|
|
char *outbuf = NULL;
|
|
|
|
char *vmxAbsolutePath = NULL;
|
|
|
|
char *parsedVmxPath = NULL;
|
|
|
|
char *str;
|
|
|
|
char *saveptr = NULL;
|
|
|
|
bool found = false;
|
|
|
|
int oldState = virDomainObjGetState(vm, NULL);
|
|
|
|
int newState;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-09-15 04:28:20 +00:00
|
|
|
cmd = virCommandNewArgList(driver->vmrun, "-T",
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareDriverTypeToString(driver->type),
|
2012-04-02 13:59:32 +00:00
|
|
|
"list", NULL);
|
|
|
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virFileResolveAllLinks(((vmwareDomainPtr) vm->privateData)->vmxPath,
|
|
|
|
&vmxAbsolutePath) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (str = outbuf; (parsedVmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
|
2012-10-17 09:23:12 +00:00
|
|
|
str = NULL) {
|
2012-04-02 13:59:32 +00:00
|
|
|
|
|
|
|
if (parsedVmxPath[0] != '/')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (STREQ(parsedVmxPath, vmxAbsolutePath)) {
|
|
|
|
found = true;
|
|
|
|
/* If the vmx path is in the output, the domain is running or
|
|
|
|
* is paused but we have no way to detect if it is paused or not. */
|
|
|
|
if (oldState == VIR_DOMAIN_PAUSED)
|
|
|
|
newState = oldState;
|
|
|
|
else
|
|
|
|
newState = VIR_DOMAIN_RUNNING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
vm->def->id = -1;
|
|
|
|
newState = VIR_DOMAIN_SHUTOFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainObjSetState(vm, newState, 0);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virCommandFree(cmd);
|
|
|
|
VIR_FREE(outbuf);
|
|
|
|
VIR_FREE(vmxAbsolutePath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static int
|
2011-05-04 09:07:01 +00:00
|
|
|
vmwareStopVM(struct vmware_driver *driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virDomainShutoffReason reason)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
const char *cmd[] = {
|
2013-09-15 04:28:20 +00:00
|
|
|
driver->vmrun, "-T", PROGRAM_SENTINEL, "stop",
|
2013-07-30 16:49:53 +00:00
|
|
|
PROGRAM_SENTINEL, "soft", NULL
|
2010-12-17 10:28:20 +00:00
|
|
|
};
|
|
|
|
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
|
|
|
|
|
|
|
|
if (virRun(cmd, NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->def->id = -1;
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareStartVM(struct vmware_driver *driver, virDomainObjPtr vm)
|
|
|
|
{
|
|
|
|
const char *cmd[] = {
|
2013-09-15 04:28:20 +00:00
|
|
|
driver->vmrun, "-T", PROGRAM_SENTINEL, "start",
|
2013-07-30 16:49:53 +00:00
|
|
|
PROGRAM_SENTINEL, PROGRAM_SENTINEL, NULL
|
2010-12-17 10:28:20 +00:00
|
|
|
};
|
|
|
|
const char *vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_SHUTOFF) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("domain is not in shutoff state"));
|
2010-12-17 10:28:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareSetSentinal(cmd, vmxPath);
|
|
|
|
if (!((vmwareDomainPtr) vm->privateData)->gui)
|
|
|
|
vmwareSetSentinal(cmd, NOGUI);
|
|
|
|
else
|
|
|
|
vmwareSetSentinal(cmd, NULL);
|
|
|
|
|
|
|
|
if (virRun(cmd, NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0) {
|
2011-05-04 09:07:01 +00:00
|
|
|
vmwareStopVM(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
|
2010-12-17 10:28:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
vmwareDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
char *vmx = NULL;
|
|
|
|
char *directoryName = NULL;
|
|
|
|
char *fileName = NULL;
|
|
|
|
char *vmxPath = NULL;
|
|
|
|
vmwareDomainPtr pDomain = NULL;
|
2010-12-21 21:39:55 +00:00
|
|
|
virVMXContext ctx;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
ctx.formatFileName = vmwareCopyVMXFileName;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-03-28 13:55:55 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
|
|
|
|
1 << VIR_DOMAIN_VIRT_VMWARE,
|
2010-12-17 10:28:20 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* generate vmx file */
|
2013-03-15 10:40:17 +00:00
|
|
|
vmx = virVMXFormatConfig(&ctx, driver->xmlopt, vmdef, 7);
|
2010-12-17 10:28:20 +00:00
|
|
|
if (vmx == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (vmwareVmxPath(vmdef, &vmxPath) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* create vmx file */
|
|
|
|
if (virFileWriteStr(vmxPath, vmx, S_IRUSR|S_IWUSR) < 0) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to write vmx file '%s'"), vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assign def */
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
vmdef,
|
2013-03-28 13:55:55 +00:00
|
|
|
driver->xmlopt,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
pDomain = vm->privateData;
|
2013-05-03 12:50:46 +00:00
|
|
|
if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vmwareDomainConfigDisplay(pDomain, vmdef);
|
|
|
|
|
|
|
|
vmdef = NULL;
|
|
|
|
vm->persistent = 1;
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = -1;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
VIR_FREE(vmx);
|
|
|
|
VIR_FREE(directoryName);
|
|
|
|
VIR_FREE(fileName);
|
|
|
|
VIR_FREE(vmxPath);
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-07-21 08:01:44 +00:00
|
|
|
vmwareDomainShutdownFlags(virDomainPtr dom,
|
|
|
|
unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-07-21 08:01:44 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverLock(driver);
|
|
|
|
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
if (vmwareUpdateVMStatus(driver, vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (vmwareStopVM(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!vm->persistent) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-21 08:01:44 +00:00
|
|
|
static int
|
|
|
|
vmwareDomainShutdown(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return vmwareDomainShutdownFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-23 12:50:18 +00:00
|
|
|
static int
|
|
|
|
vmwareDomainDestroy(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return vmwareDomainShutdownFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainDestroyFlags(virDomainPtr dom,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
return vmwareDomainShutdownFlags(dom, flags);
|
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static int
|
|
|
|
vmwareDomainSuspend(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *cmd[] = {
|
2013-09-15 04:28:20 +00:00
|
|
|
driver->vmrun, "-T", PROGRAM_SENTINEL, "pause",
|
2013-07-30 16:49:53 +00:00
|
|
|
PROGRAM_SENTINEL, NULL
|
2010-12-17 10:28:20 +00:00
|
|
|
};
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-09-14 04:28:30 +00:00
|
|
|
if (driver->type == VMWARE_DRIVER_PLAYER) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("vmplayer does not support libvirt suspend/resume"
|
|
|
|
" (vmware pause/unpause) operation "));
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainResume(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *cmd[] = {
|
2013-09-15 04:28:20 +00:00
|
|
|
driver->vmrun, "-T", PROGRAM_SENTINEL, "unpause", PROGRAM_SENTINEL,
|
2010-12-17 10:28:20 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-09-14 04:28:30 +00:00
|
|
|
if (driver->type == VMWARE_DRIVER_PLAYER) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2012-09-12 16:54:42 +00:00
|
|
|
_("vmplayer does not support libvirt suspend/resume "
|
2012-07-18 13:22:54 +00:00
|
|
|
"(vmware pause/unpause) operation "));
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in suspend state"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-07-06 23:08:28 +00:00
|
|
|
vmwareDomainReboot(virDomainPtr dom, unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
const char * vmxPath = NULL;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
const char *cmd[] = {
|
2013-09-15 04:28:20 +00:00
|
|
|
driver->vmrun, "-T", PROGRAM_SENTINEL,
|
2013-07-30 16:49:53 +00:00
|
|
|
"reset", PROGRAM_SENTINEL, "soft", NULL
|
2010-12-17 10:28:20 +00:00
|
|
|
};
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-07-06 23:08:28 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-07-04 02:32:22 +00:00
|
|
|
vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath;
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
|
2011-04-14 09:22:35 +00:00
|
|
|
vmwareSetSentinal(cmd, vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
if (vmwareUpdateVMStatus(driver, vm) < 0)
|
|
|
|
goto cleanup;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("domain is not in running state"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
|
2011-07-06 23:08:28 +00:00
|
|
|
unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
char *vmx = NULL;
|
|
|
|
char *vmxPath = NULL;
|
|
|
|
vmwareDomainPtr pDomain = NULL;
|
2010-12-21 21:39:55 +00:00
|
|
|
virVMXContext ctx;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2011-07-06 23:08:28 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
ctx.formatFileName = vmwareCopyVMXFileName;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt,
|
|
|
|
1 << VIR_DOMAIN_VIRT_VMWARE,
|
2010-12-17 10:28:20 +00:00
|
|
|
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* generate vmx file */
|
2013-03-15 10:40:17 +00:00
|
|
|
vmx = virVMXFormatConfig(&ctx, driver->xmlopt, vmdef, 7);
|
2010-12-17 10:28:20 +00:00
|
|
|
if (vmx == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (vmwareVmxPath(vmdef, &vmxPath) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* create vmx file */
|
|
|
|
if (virFileWriteStr(vmxPath, vmx, S_IRUSR|S_IWUSR) < 0) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to write vmx file '%s'"), vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assign def */
|
2013-01-11 16:04:47 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
vmdef,
|
2013-03-28 13:55:55 +00:00
|
|
|
driver->xmlopt,
|
Merge virDomainObjListIsDuplicate into virDomainObjListAdd
The duplicate VM checking should be done atomically with
virDomainObjListAdd, so shoud not be a separate function.
Instead just use flags to indicate what kind of checks are
required.
This pair, used in virDomainCreateXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainRestoreFlags:
if (virDomainObjListIsDuplicate(privconn->domains, def, 1) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, true)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL)))
goto cleanup;
This pair, used in virDomainDefineXML:
if (virDomainObjListIsDuplicate(privconn->domains, def, 0) < 0)
goto cleanup;
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def, false)))
goto cleanup;
Changes to
if (!(dom = virDomainObjListAdd(privconn->domains,
privconn->caps,
def,
0, NULL)))
goto cleanup;
2013-01-14 14:46:58 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
|
|
|
|
NULL)))
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
pDomain = vm->privateData;
|
2013-05-03 12:50:46 +00:00
|
|
|
if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0)
|
|
|
|
goto cleanup;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDomainConfigDisplay(pDomain, vmdef);
|
|
|
|
vmdef = NULL;
|
|
|
|
|
|
|
|
if (vmwareStartVM(driver, vm) < 0) {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vm = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
VIR_FREE(vmx);
|
|
|
|
VIR_FREE(vmxPath);
|
2012-10-17 09:23:12 +00:00
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainCreateWithFlags(virDomainPtr dom,
|
2011-07-06 23:08:28 +00:00
|
|
|
unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-07-06 23:08:28 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
if (!vm) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
virUUIDFormat(dom->uuid, uuidstr);
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("No domain with matching uuid '%s'"), uuidstr);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
if (vmwareUpdateVMStatus(driver, vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
if (virDomainObjIsActive(vm)) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("Domain is already running"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = vmwareStartVM(driver, vm);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainCreate(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return vmwareDomainCreateWithFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-07-20 03:08:21 +00:00
|
|
|
vmwareDomainUndefineFlags(virDomainPtr dom,
|
|
|
|
unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (!vm) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
|
|
|
virUUIDFormat(dom->uuid, uuidstr);
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s'"), uuidstr);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vm->persistent) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
"%s", _("cannot undefine transient domain"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
if (vmwareUpdateVMStatus(driver, vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-08-19 13:52:12 +00:00
|
|
|
if (virDomainObjIsActive(vm)) {
|
|
|
|
vm->persistent = 0;
|
|
|
|
} else {
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2011-08-19 13:52:12 +00:00
|
|
|
vm = NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-20 03:08:21 +00:00
|
|
|
static int
|
|
|
|
vmwareDomainUndefine(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
return vmwareDomainUndefineFlags(dom, 0);
|
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static virDomainPtr
|
|
|
|
vmwareDomainLookupByID(virConnectPtr conn, int id)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByID(driver->domains, id);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareDomainGetOSType(virDomainPtr dom)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-03 12:50:46 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, vm->def->os.type));
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
vmwareDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr
|
|
|
|
vmwareDomainLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByName(driver->domains, name);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
|
|
|
if (dom)
|
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainIsActive(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(obj);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainIsPersistent(virDomainPtr dom)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
if (!obj) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = obj->persistent;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (obj)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(obj);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2011-07-06 20:40:19 +00:00
|
|
|
vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
|
|
|
|
2011-07-13 22:24:38 +00:00
|
|
|
/* Flags checked by virDomainDefFormat */
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = virDomainDefFormat(vm->def, flags);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-22 09:28:06 +00:00
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
|
|
|
|
const char *nativeConfig,
|
|
|
|
unsigned int flags)
|
2012-02-22 09:28:06 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
virVMXContext ctx;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
|
|
|
if (STRNEQ(nativeFormat, "vmware-vmx")) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Unsupported config format '%s'"), nativeFormat);
|
2012-02-22 09:28:06 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.parseFileName = vmwareCopyVMXFileName;
|
|
|
|
|
2013-03-15 10:40:17 +00:00
|
|
|
def = virVMXParseConfig(&ctx, driver->xmlopt, nativeConfig);
|
2012-02-22 09:28:06 +00:00
|
|
|
|
|
|
|
if (def != NULL)
|
|
|
|
xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
|
|
|
|
|
|
|
|
virDomainDefFree(def);
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
2013-01-11 13:54:15 +00:00
|
|
|
static int vmwareDomainObjListUpdateDomain(virDomainObjPtr dom, void *data)
|
2012-04-02 13:59:32 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = data;
|
2013-01-11 13:54:15 +00:00
|
|
|
virObjectLock(dom);
|
|
|
|
ignore_value(vmwareUpdateVMStatus(driver, dom));
|
|
|
|
virObjectUnlock(dom);
|
|
|
|
return 0;
|
2012-04-02 13:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vmwareDomainObjListUpdateAll(virDomainObjListPtr doms, struct vmware_driver *driver)
|
|
|
|
{
|
2013-01-11 13:54:15 +00:00
|
|
|
virDomainObjListForEach(doms, vmwareDomainObjListUpdateDomain, driver);
|
2012-04-02 13:59:32 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectNumOfDefinedDomains(virConnectPtr conn)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vmwareDomainObjListUpdateAll(driver->domains, driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListNumOfDomains(driver->domains, false, NULL, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectNumOfDomains(virConnectPtr conn)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vmwareDomainObjListUpdateAll(driver->domains, driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListNumOfDomains(driver->domains, true, NULL, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectListDomains(virConnectPtr conn, int *ids, int nids)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vmwareDomainObjListUpdateAll(driver->domains, driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListGetActiveIDs(driver->domains, ids, nids, NULL, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectListDefinedDomains(virConnectPtr conn,
|
|
|
|
char **const names, int nnames)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vmwareDomainObjListUpdateAll(driver->domains, driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
n = virDomainObjListGetInactiveNames(driver->domains, names, nnames,
|
|
|
|
NULL, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vmwareDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
if (vmwareUpdateVMStatus(driver, vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
info->state = virDomainObjGetState(vm, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
info->cpuTime = 0;
|
|
|
|
info->maxMem = vm->def->mem.max_balloon;
|
|
|
|
info->memory = vm->def->mem.cur_balloon;
|
|
|
|
info->nrVirtCpu = vm->def->vcpus;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-02 09:35:29 +00:00
|
|
|
static int
|
|
|
|
vmwareDomainGetState(virDomainPtr dom,
|
|
|
|
int *state,
|
|
|
|
int *reason,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
|
2011-05-02 09:35:29 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN, "%s",
|
|
|
|
_("no domain with matching uuid"));
|
2011-05-02 09:35:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-04-02 13:59:32 +00:00
|
|
|
if (vmwareUpdateVMStatus(driver, vm) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-05-04 09:07:01 +00:00
|
|
|
*state = virDomainObjGetState(vm, reason);
|
2011-05-02 09:35:29 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(vm);
|
2011-05-02 09:35:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-23 06:56:13 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2011-09-23 06:56:13 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-11 09:04:57 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
vmwareConnectListAllDomains(virConnectPtr conn,
|
|
|
|
virDomainPtr **domains,
|
|
|
|
unsigned int flags)
|
2012-06-11 09:04:57 +00:00
|
|
|
{
|
|
|
|
struct vmware_driver *driver = conn->privateData;
|
|
|
|
int ret = -1;
|
|
|
|
|
2012-08-03 15:48:05 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
|
2012-06-11 09:04:57 +00:00
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2013-01-11 16:04:47 +00:00
|
|
|
vmwareDomainObjListUpdateAll(driver->domains, driver);
|
2013-06-24 16:49:47 +00:00
|
|
|
ret = virDomainObjListExport(driver->domains, conn, domains,
|
|
|
|
NULL, flags);
|
2012-06-11 09:04:57 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static virDriver vmwareDriver = {
|
Convert all driver struct intializers to C99 style
Change all the driver struct initializers to use the
C99 style, leaving out unused fields. This will make
it possible to add new APIs without changing every
driver. eg change:
qemudDomainResume, /* domainResume */
qemudDomainShutdown, /* domainShutdown */
NULL, /* domainReboot */
qemudDomainDestroy, /* domainDestroy */
to
.domainResume = qemudDomainResume,
.domainShutdown = qemudDomainShutdown,
.domainDestroy = qemudDomainDestroy,
And get rid of any existing C99 style initializersr which
set NULL, eg change
.listPools = vboxStorageListPools,
.numOfDefinedPools = NULL,
.listDefinedPools = NULL,
.findPoolSources = NULL,
.poolLookupByName = vboxStoragePoolLookupByName,
to
.listPools = vboxStorageListPools,
.poolLookupByName = vboxStoragePoolLookupByName,
2011-05-13 10:16:31 +00:00
|
|
|
.no = VIR_DRV_VMWARE,
|
|
|
|
.name = "VMWARE",
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectOpen = vmwareConnectOpen, /* 0.8.7 */
|
|
|
|
.connectClose = vmwareConnectClose, /* 0.8.7 */
|
|
|
|
.connectGetType = vmwareConnectGetType, /* 0.8.7 */
|
|
|
|
.connectGetVersion = vmwareConnectGetVersion, /* 0.8.7 */
|
|
|
|
.connectListDomains = vmwareConnectListDomains, /* 0.8.7 */
|
|
|
|
.connectNumOfDomains = vmwareConnectNumOfDomains, /* 0.8.7 */
|
|
|
|
.connectListAllDomains = vmwareConnectListAllDomains, /* 0.9.13 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreateXML = vmwareDomainCreateXML, /* 0.8.7 */
|
|
|
|
.domainLookupByID = vmwareDomainLookupByID, /* 0.8.7 */
|
|
|
|
.domainLookupByUUID = vmwareDomainLookupByUUID, /* 0.8.7 */
|
|
|
|
.domainLookupByName = vmwareDomainLookupByName, /* 0.8.7 */
|
|
|
|
.domainSuspend = vmwareDomainSuspend, /* 0.8.7 */
|
|
|
|
.domainResume = vmwareDomainResume, /* 0.8.7 */
|
|
|
|
.domainShutdown = vmwareDomainShutdown, /* 0.8.7 */
|
2011-10-05 17:31:55 +00:00
|
|
|
.domainShutdownFlags = vmwareDomainShutdownFlags, /* 0.9.10 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainReboot = vmwareDomainReboot, /* 0.8.7 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.domainDestroy = vmwareDomainDestroy, /* 0.8.7 */
|
|
|
|
.domainDestroyFlags = vmwareDomainDestroyFlags, /* 0.9.4 */
|
|
|
|
.domainGetOSType = vmwareDomainGetOSType, /* 0.8.7 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainGetInfo = vmwareDomainGetInfo, /* 0.8.7 */
|
|
|
|
.domainGetState = vmwareDomainGetState, /* 0.9.2 */
|
|
|
|
.domainGetXMLDesc = vmwareDomainGetXMLDesc, /* 0.8.7 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectDomainXMLFromNative = vmwareConnectDomainXMLFromNative, /* 0.9.11 */
|
|
|
|
.connectListDefinedDomains = vmwareConnectListDefinedDomains, /* 0.8.7 */
|
|
|
|
.connectNumOfDefinedDomains = vmwareConnectNumOfDefinedDomains, /* 0.8.7 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainCreate = vmwareDomainCreate, /* 0.8.7 */
|
|
|
|
.domainCreateWithFlags = vmwareDomainCreateWithFlags, /* 0.8.7 */
|
|
|
|
.domainDefineXML = vmwareDomainDefineXML, /* 0.8.7 */
|
|
|
|
.domainUndefine = vmwareDomainUndefine, /* 0.8.7 */
|
2011-07-20 03:08:21 +00:00
|
|
|
.domainUndefineFlags = vmwareDomainUndefineFlags, /* 0.9.4 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.domainIsActive = vmwareDomainIsActive, /* 0.8.7 */
|
|
|
|
.domainIsPersistent = vmwareDomainIsPersistent, /* 0.8.7 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectIsAlive = vmwareConnectIsAlive, /* 0.9.8 */
|
2010-12-17 10:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareRegister(void)
|
|
|
|
{
|
|
|
|
if (virRegisterDriver(&vmwareDriver) < 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|