2010-12-17 10:28:20 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-02-07 21:14:56 +00:00
|
|
|
/*
|
2015-01-15 14:02:44 +00:00
|
|
|
* Copyright (C) 2011-2015 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);
|
|
|
|
}
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
|
|
|
|
static virDomainObjPtr
|
|
|
|
vmwareDomObjFromDomainLocked(struct vmware_driver *driver,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
|
2018-03-09 15:47:46 +00:00
|
|
|
if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) {
|
2017-10-23 17:19:46 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching uuid '%s'"), uuidstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static virDomainObjPtr
|
|
|
|
vmwareDomObjFromDomain(struct vmware_driver *driver,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
|
|
|
vm = vmwareDomObjFromDomainLocked(driver, uuid);
|
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
static void *
|
2019-10-14 12:45:33 +00:00
|
|
|
vmwareDataAllocFunc(void *opaque G_GNUC_UNUSED)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-10-06 15:28:46 +00:00
|
|
|
static int
|
2019-11-26 16:09:33 +00:00
|
|
|
vmwareDomainDefPostParse(virDomainDefPtr def,
|
2019-10-14 12:45:33 +00:00
|
|
|
unsigned int parseFlags G_GNUC_UNUSED,
|
|
|
|
void *opaque G_GNUC_UNUSED,
|
|
|
|
void *parseOpaque G_GNUC_UNUSED)
|
2014-10-06 15:28:46 +00:00
|
|
|
{
|
2019-12-03 10:49:49 +00:00
|
|
|
struct vmware_driver *driver = opaque;
|
|
|
|
if (!virCapabilitiesDomainSupported(driver->caps, def->os.type,
|
2019-11-26 16:09:33 +00:00
|
|
|
def->os.arch,
|
|
|
|
def->virtType))
|
|
|
|
return -1;
|
|
|
|
|
2014-10-06 15:28:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-10-14 12:45:33 +00:00
|
|
|
vmwareDomainDeviceDefPostParse(virDomainDeviceDefPtr dev G_GNUC_UNUSED,
|
|
|
|
const virDomainDef *def G_GNUC_UNUSED,
|
|
|
|
unsigned int parseFlags G_GNUC_UNUSED,
|
|
|
|
void *opaque G_GNUC_UNUSED,
|
|
|
|
void *parseOpaque G_GNUC_UNUSED)
|
2014-10-06 15:28:46 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virDomainDefParserConfig vmwareDomainDefParserConfig = {
|
|
|
|
.devicesPostParseCallback = vmwareDomainDeviceDefPostParse,
|
|
|
|
.domainPostParseCallback = vmwareDomainDefPostParse,
|
2019-11-27 15:22:45 +00:00
|
|
|
.defArch = VIR_ARCH_I686,
|
2014-10-06 15:28:46 +00:00
|
|
|
};
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
static virDomainXMLOptionPtr
|
2019-12-03 10:49:49 +00:00
|
|
|
vmwareDomainXMLConfigInit(struct vmware_driver *driver)
|
2013-03-05 15:17:24 +00:00
|
|
|
{
|
|
|
|
virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc,
|
|
|
|
.free = vmwareDataFreeFunc };
|
2019-12-03 10:49:49 +00:00
|
|
|
vmwareDomainDefParserConfig.priv = driver;
|
2017-06-01 22:44:46 +00:00
|
|
|
return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv,
|
|
|
|
NULL, NULL, 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,
|
2019-10-14 12:45:33 +00:00
|
|
|
virConnectAuthPtr auth G_GNUC_UNUSED,
|
|
|
|
virConfPtr conf G_GNUC_UNUSED,
|
2013-04-23 12:50:18 +00:00
|
|
|
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;
|
2018-04-14 09:25:42 +00:00
|
|
|
char *vmrun = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2011-07-06 23:08:28 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2018-03-28 11:49:29 +00:00
|
|
|
/* If path isn't /session, then they typoed, so tell them correct path */
|
2018-03-28 13:25:23 +00:00
|
|
|
if (STRNEQ(conn->uri->path, "/session")) {
|
2018-03-28 11:49:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected VMware URI path '%s', try vmwareplayer:///session, vmwarews:///session or vmwarefusion:///session"),
|
|
|
|
NULLSTR(conn->uri->path));
|
|
|
|
return VIR_DRV_OPEN_ERROR;
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
2019-10-15 11:55:26 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS(vmrun_candidates); i++) {
|
2018-04-14 09:25:42 +00:00
|
|
|
vmrun = virFindFileInPath(vmrun_candidates[i]);
|
|
|
|
if (vmrun == NULL)
|
|
|
|
continue;
|
|
|
|
if (virFileResolveLink(vmrun, &driver->vmrun) < 0) {
|
|
|
|
virReportSystemError(errno, _("unable to resolve symlink '%s'"), vmrun);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(vmrun);
|
2013-09-15 04:28:20 +00:00
|
|
|
/* 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;
|
|
|
|
|
2019-12-03 10:49:49 +00:00
|
|
|
if (!(driver->xmlopt = vmwareDomainXMLConfigInit(driver)))
|
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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareFreeDriver(driver);
|
2018-04-14 09:25:42 +00:00
|
|
|
VIR_FREE(vmrun);
|
2010-12-17 10:28:20 +00:00
|
|
|
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 *
|
2019-10-14 12:45:33 +00:00
|
|
|
vmwareConnectGetType(virConnectPtr conn G_GNUC_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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2012-04-02 13:59:32 +00:00
|
|
|
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);
|
|
|
|
|
2014-11-13 14:29:45 +00:00
|
|
|
if (virRun(cmd, NULL) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
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);
|
|
|
|
|
2014-11-13 14:29:45 +00:00
|
|
|
if (virRun(cmd, NULL) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
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
|
2014-11-18 14:19:38 +00:00
|
|
|
vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, 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 *directoryName = NULL;
|
|
|
|
char *fileName = NULL;
|
|
|
|
char *vmxPath = NULL;
|
|
|
|
vmwareDomainPtr pDomain = NULL;
|
2010-12-21 21:39:55 +00:00
|
|
|
virVMXContext ctx;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
|
|
|
|
|
|
|
|
if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
|
2016-05-24 15:20:20 +00:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2014-11-18 14:19:38 +00:00
|
|
|
|
2015-09-11 10:00:47 +00:00
|
|
|
ctx.parseFileName = NULL;
|
2010-12-21 21:39:55 +00:00
|
|
|
ctx.formatFileName = vmwareCopyVMXFileName;
|
2015-09-11 10:00:47 +00:00
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
ctx.datacenterPath = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
2019-11-27 12:29:21 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, parse_flags)) == NULL)
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
2016-11-11 09:17:37 +00:00
|
|
|
|
|
|
|
if (virXMLCheckIllegalChars("name", vmdef->name, "\n") < 0)
|
|
|
|
goto cleanup;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
/* 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;
|
2019-10-20 11:49:46 +00:00
|
|
|
pDomain->vmxPath = g_strdup(vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDomainConfigDisplay(pDomain, vmdef);
|
|
|
|
|
|
|
|
vmdef = NULL;
|
|
|
|
vm->persistent = 1;
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, -1);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-18 14:19:38 +00:00
|
|
|
static virDomainPtr
|
|
|
|
vmwareDomainDefineXML(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
|
|
|
return vmwareDomainDefineXMLFlags(conn, xml, 0);
|
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
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);
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomainLocked(driver, dom->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;
|
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!vm->persistent)
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
}
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
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);
|
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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
}
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
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);
|
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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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);
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
2014-11-18 17:34:42 +00:00
|
|
|
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
|
|
|
|
|
|
|
|
virCheckFlags(VIR_DOMAIN_START_VALIDATE, NULL);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2014-11-18 17:34:42 +00:00
|
|
|
if (flags & VIR_DOMAIN_START_VALIDATE)
|
2016-05-24 15:20:20 +00:00
|
|
|
parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA;
|
2011-07-06 23:08:28 +00:00
|
|
|
|
2015-09-11 10:00:47 +00:00
|
|
|
ctx.parseFileName = NULL;
|
2010-12-21 21:39:55 +00:00
|
|
|
ctx.formatFileName = vmwareCopyVMXFileName;
|
2015-09-11 10:00:47 +00:00
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
ctx.datacenterPath = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDriverLock(driver);
|
|
|
|
|
2019-11-27 12:29:21 +00:00
|
|
|
if ((vmdef = virDomainDefParseString(xml, driver->xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, parse_flags)) == NULL)
|
2010-12-17 10:28:20 +00:00
|
|
|
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,
|
2015-09-22 14:57:52 +00:00
|
|
|
VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
|
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;
|
2019-10-20 11:49:46 +00:00
|
|
|
pDomain->vmxPath = g_strdup(vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmwareDomainConfigDisplay(pDomain, vmdef);
|
|
|
|
vmdef = NULL;
|
|
|
|
|
|
|
|
if (vmwareStartVM(driver, vm) < 0) {
|
2018-04-23 14:40:48 +00:00
|
|
|
if (!vm->persistent)
|
2015-09-22 14:52:03 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
VIR_FREE(vmx);
|
|
|
|
VIR_FREE(vmxPath);
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&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);
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomainLocked(driver, dom->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;
|
|
|
|
|
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);
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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);
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomainLocked(driver, dom->uuid)))
|
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;
|
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
if (virDomainObjIsActive(vm))
|
2011-08-19 13:52:12 +00:00
|
|
|
vm->persistent = 0;
|
2018-04-23 14:40:48 +00:00
|
|
|
else
|
2013-01-11 16:04:47 +00:00
|
|
|
virDomainObjListRemove(driver->domains, vm);
|
2011-08-19 13:52:12 +00:00
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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);
|
2018-03-09 15:59:28 +00:00
|
|
|
vm = virDomainObjListFindByID(driver->domains, id);
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareDriverUnlock(driver);
|
|
|
|
|
|
|
|
if (!vm) {
|
2018-03-09 14:46:47 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching id '%d'"), id);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2019-10-18 11:27:03 +00:00
|
|
|
ret = g_strdup(virDomainOSTypeToString(vm->def->os.type));
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, uuid)))
|
|
|
|
return NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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) {
|
2018-03-09 14:46:47 +00:00
|
|
|
virReportError(VIR_ERR_NO_DOMAIN,
|
|
|
|
_("no domain with matching name '%s'"), name);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-03-28 15:08:03 +00:00
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2018-03-09 14:48:07 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(obj = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = virDomainObjIsActive(obj);
|
|
|
|
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(obj = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = obj->persistent;
|
|
|
|
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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;
|
|
|
|
|
2019-02-14 20:25:01 +00:00
|
|
|
virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
|
2011-07-13 22:24:38 +00:00
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2019-11-27 11:57:34 +00:00
|
|
|
ret = virDomainDefFormat(vm->def, driver->xmlopt,
|
2014-11-18 16:44:00 +00:00
|
|
|
virDomainDefFormatConvertXMLFlags(flags));
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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);
|
|
|
|
|
2019-04-09 10:01:25 +00:00
|
|
|
if (STRNEQ(nativeFormat, VMX_CONFIG_FORMAT_ARGV)) {
|
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;
|
2015-09-11 10:00:47 +00:00
|
|
|
ctx.formatFileName = NULL;
|
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
ctx.datacenterPath = NULL;
|
2012-02-22 09:28:06 +00:00
|
|
|
|
2015-11-28 04:12:33 +00:00
|
|
|
def = virVMXParseConfig(&ctx, driver->xmlopt, driver->caps, nativeConfig);
|
2012-02-22 09:28:06 +00:00
|
|
|
|
|
|
|
if (def != NULL)
|
2019-11-27 11:57:34 +00:00
|
|
|
xml = virDomainDefFormat(def, driver->xmlopt,
|
2016-02-03 21:40:35 +00:00
|
|
|
VIR_DOMAIN_DEF_FORMAT_INACTIVE);
|
2012-02-22 09:28:06 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-09-06 11:59:59 +00:00
|
|
|
virDomainObjListForEach(doms, false, 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;
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
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;
|
2016-06-15 13:34:04 +00:00
|
|
|
info->maxMem = virDomainDefGetMemoryTotal(vm->def);
|
2010-12-17 10:28:20 +00:00
|
|
|
info->memory = vm->def->mem.cur_balloon;
|
2015-10-22 12:59:03 +00:00
|
|
|
info->nrVirtCpu = virDomainDefGetVcpus(vm->def);
|
2010-12-17 10:28:20 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&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);
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(vm = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
2011-05-02 09:35:29 +00:00
|
|
|
|
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;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2011-05-02 09:35:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-23 06:56:13 +00:00
|
|
|
static int
|
2019-10-14 12:45:33 +00:00
|
|
|
vmwareConnectIsAlive(virConnectPtr conn G_GNUC_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;
|
|
|
|
}
|
|
|
|
|
2015-01-15 14:02:44 +00:00
|
|
|
static int
|
|
|
|
vmwareDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct vmware_driver *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2017-10-23 17:19:46 +00:00
|
|
|
if (!(obj = vmwareDomObjFromDomain(driver, dom->uuid)))
|
|
|
|
return -1;
|
|
|
|
|
2015-01-15 14:02:44 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2017-10-23 17:25:34 +00:00
|
|
|
virDomainObjEndAPI(&obj);
|
2015-01-15 14:02:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-11 09:04:57 +00:00
|
|
|
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virHypervisorDriver vmwareHypervisorDriver = {
|
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
|
|
|
.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 */
|
2014-11-18 14:19:38 +00:00
|
|
|
.domainDefineXMLFlags = vmwareDomainDefineXMLFlags, /* 1.2.12 */
|
2011-05-13 13:35:01 +00:00
|
|
|
.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 */
|
2015-01-15 14:02:44 +00:00
|
|
|
.domainHasManagedSaveImage = vmwareDomainHasManagedSaveImage, /* 1.2.13 */
|
2010-12-17 10:28:20 +00:00
|
|
|
};
|
|
|
|
|
2015-01-20 16:16:26 +00:00
|
|
|
static virConnectDriver vmwareConnectDriver = {
|
2018-03-28 09:53:31 +00:00
|
|
|
.localOnly = true,
|
2018-03-27 14:51:45 +00:00
|
|
|
.uriSchemes = (const char *[]){ "vmwareplayer", "vmwarews", "vmwarefusion", NULL },
|
2015-01-20 16:16:26 +00:00
|
|
|
.hypervisorDriver = &vmwareHypervisorDriver,
|
|
|
|
};
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
int
|
|
|
|
vmwareRegister(void)
|
|
|
|
{
|
2015-01-20 16:16:26 +00:00
|
|
|
return virRegisterConnectDriver(&vmwareConnectDriver,
|
|
|
|
false);
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|