2010-12-17 10:28:20 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2011-03-18 17:32:35 +00:00
|
|
|
/*
|
2014-01-03 17:57:37 +00:00
|
|
|
* Copyright (C) 2011-2014 Red Hat, Inc.
|
2014-04-09 09:59:53 +00:00
|
|
|
* Copyright (C) 2010-2014, diateam (www.diateam.net)
|
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>
|
|
|
|
|
|
|
|
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2010-12-17 10:28:20 +00:00
|
|
|
#include "cpu/cpu.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2010-12-21 21:39:55 +00:00
|
|
|
#include "vmx.h"
|
2010-12-17 10:28:20 +00:00
|
|
|
#include "vmware_conf.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2018-04-14 09:25:43 +00:00
|
|
|
#include "virlog.h"
|
2020-02-16 21:59:28 +00:00
|
|
|
#include "virutil.h"
|
2018-04-14 09:25:43 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_VMWARE
|
|
|
|
|
|
|
|
VIR_LOG_INIT("vmware.vmware_conf");
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(vmwareDriver,
|
|
|
|
VMWARE_DRIVER_LAST,
|
2013-09-14 04:28:30 +00:00
|
|
|
"player",
|
2013-09-24 16:24:31 +00:00
|
|
|
"ws",
|
2019-01-20 16:30:15 +00:00
|
|
|
"fusion",
|
|
|
|
);
|
2013-09-14 04:28:30 +00:00
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
/* Free all memory associated with a vmware_driver structure */
|
|
|
|
void
|
|
|
|
vmwareFreeDriver(struct vmware_driver *driver)
|
|
|
|
{
|
|
|
|
if (!driver)
|
|
|
|
return;
|
|
|
|
|
|
|
|
virMutexDestroy(&driver->lock);
|
2013-01-11 13:54:15 +00:00
|
|
|
virObjectUnref(driver->domains);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(driver->caps);
|
2013-03-31 18:03:42 +00:00
|
|
|
virObjectUnref(driver->xmlopt);
|
2013-09-15 04:28:20 +00:00
|
|
|
VIR_FREE(driver->vmrun);
|
2010-12-17 10:28:20 +00:00
|
|
|
VIR_FREE(driver);
|
|
|
|
}
|
|
|
|
|
Fix default console type setting
The default console type may vary based on the OS type. ie a Xen
paravirt guests wants a 'xen' console, while a fullvirt guests
wants a 'serial' console.
A plain integer default console type in the capabilities does
not suffice. Instead introduce a callback that is passed the
OS type.
* src/conf/capabilities.h: Use a callback for default console
type
* src/conf/domain_conf.c, src/conf/domain_conf.h: Use callback
for default console type. Add missing LXC/OpenVZ console types.
* src/esx/esx_driver.c, src/libxl/libxl_conf.c,
src/lxc/lxc_conf.c, src/openvz/openvz_conf.c,
src/phyp/phyp_driver.c, src/qemu/qemu_capabilities.c,
src/uml/uml_conf.c, src/vbox/vbox_tmpl.c,
src/vmware/vmware_conf.c, src/xen/xen_hypervisor.c,
src/xenapi/xenapi_driver.c: Set default console type callback
2011-10-20 13:56:20 +00:00
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
virCapsPtr
|
|
|
|
vmwareCapsInit(void)
|
|
|
|
{
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
virCapsGuestPtr guest = NULL;
|
|
|
|
|
2012-12-10 22:28:09 +00:00
|
|
|
if ((caps = virCapabilitiesNew(virArchFromHost(),
|
2014-07-14 12:56:13 +00:00
|
|
|
false, false)) == NULL)
|
2010-12-17 10:28:20 +00:00
|
|
|
goto error;
|
|
|
|
|
2019-11-29 09:55:59 +00:00
|
|
|
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
|
2010-12-17 10:28:20 +00:00
|
|
|
goto error;
|
|
|
|
|
2017-03-29 13:52:31 +00:00
|
|
|
if (virCapabilitiesInitCaches(caps) < 0)
|
2018-04-14 09:25:43 +00:00
|
|
|
VIR_WARN("Failed to get host CPU cache info");
|
2017-03-29 13:52:31 +00:00
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
/* i686 guests are always supported */
|
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
2015-04-17 22:09:16 +00:00
|
|
|
VIR_DOMAIN_OSTYPE_HVM,
|
2012-12-10 22:28:09 +00:00
|
|
|
VIR_ARCH_I686,
|
2010-12-17 10:28:20 +00:00
|
|
|
NULL, NULL, 0, NULL)) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
2015-04-17 22:38:10 +00:00
|
|
|
VIR_DOMAIN_VIRT_VMWARE,
|
2010-12-17 10:28:20 +00:00
|
|
|
NULL, NULL, 0, NULL) == NULL)
|
|
|
|
goto error;
|
2017-03-15 08:07:38 +00:00
|
|
|
guest = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2017-03-15 08:07:38 +00:00
|
|
|
if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
|
2010-12-17 10:28:20 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* x86_64 guests are supported if
|
|
|
|
* - Host arch is x86_64
|
|
|
|
* Or
|
|
|
|
* - Host CPU is x86_64 with virtualization extensions
|
|
|
|
*/
|
2012-12-10 22:28:09 +00:00
|
|
|
if (caps->host.arch == VIR_ARCH_X86_64 ||
|
2017-03-15 08:07:38 +00:00
|
|
|
(virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "lm") &&
|
|
|
|
(virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "vmx") ||
|
|
|
|
virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "svm")))) {
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
2015-04-17 22:09:16 +00:00
|
|
|
VIR_DOMAIN_OSTYPE_HVM,
|
2012-12-10 22:28:09 +00:00
|
|
|
VIR_ARCH_X86_64,
|
2010-12-17 10:28:20 +00:00
|
|
|
NULL, NULL, 0, NULL)) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
2015-04-17 22:38:10 +00:00
|
|
|
VIR_DOMAIN_VIRT_VMWARE,
|
2010-12-17 10:28:20 +00:00
|
|
|
NULL, NULL, 0, NULL) == NULL)
|
|
|
|
goto error;
|
2017-03-15 08:10:12 +00:00
|
|
|
guest = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
error:
|
2017-03-15 08:10:12 +00:00
|
|
|
virCapabilitiesFreeGuest(guest);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2017-03-15 08:10:12 +00:00
|
|
|
return NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareLoadDomains(struct vmware_driver *driver)
|
|
|
|
{
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
char *vmxPath = NULL;
|
|
|
|
char *vmx = NULL;
|
|
|
|
vmwareDomainPtr pDomain;
|
|
|
|
char *directoryName = NULL;
|
|
|
|
char *fileName = NULL;
|
|
|
|
int ret = -1;
|
2010-12-21 21:39:55 +00:00
|
|
|
virVMXContext ctx;
|
2010-12-17 10:28:20 +00:00
|
|
|
char *outbuf = NULL;
|
|
|
|
char *str;
|
|
|
|
char *saveptr = NULL;
|
|
|
|
virCommandPtr cmd;
|
|
|
|
|
2010-12-21 21:39:55 +00:00
|
|
|
ctx.parseFileName = vmwareCopyVMXFileName;
|
2015-09-11 10:00:47 +00:00
|
|
|
ctx.formatFileName = NULL;
|
|
|
|
ctx.autodetectSCSIControllerModel = NULL;
|
|
|
|
ctx.datacenterPath = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2013-09-15 04:28:20 +00:00
|
|
|
cmd = virCommandNewArgList(driver->vmrun, "-T",
|
2013-09-14 04:28:30 +00:00
|
|
|
vmwareDriverTypeToString(driver->type),
|
2010-12-17 10:28:20 +00:00
|
|
|
"list", NULL);
|
|
|
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (str = outbuf; (vmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
str = NULL) {
|
|
|
|
|
|
|
|
if (vmxPath[0] != '/')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (virFileReadAll(vmxPath, 10000, &vmx) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((vmdef =
|
2015-11-28 04:12:33 +00:00
|
|
|
virVMXParseConfig(&ctx, driver->xmlopt,
|
|
|
|
driver->caps, vmx)) == NULL) {
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-03-28 13:55:55 +00:00
|
|
|
if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
|
2013-03-31 18:03:42 +00:00
|
|
|
driver->xmlopt,
|
2013-03-28 13:55:55 +00:00
|
|
|
0, 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);
|
|
|
|
|
|
|
|
if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
/* vmrun list only reports running vms */
|
2011-05-04 09:07:01 +00:00
|
|
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
|
|
|
|
VIR_DOMAIN_RUNNING_UNKNOWN);
|
2010-12-17 10:28:20 +00:00
|
|
|
vm->persistent = 1;
|
|
|
|
|
2018-04-23 14:40:48 +00:00
|
|
|
virDomainObjEndAPI(&vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
vmdef = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
VIR_FREE(outbuf);
|
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
VIR_FREE(directoryName);
|
|
|
|
VIR_FREE(fileName);
|
|
|
|
VIR_FREE(vmx);
|
2012-07-11 13:35:46 +00:00
|
|
|
virObjectUnref(vm);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vmwareSetSentinal(const char **prog, const char *key)
|
|
|
|
{
|
|
|
|
const char **tmp = prog;
|
|
|
|
|
|
|
|
while (tmp && *tmp) {
|
2013-07-30 16:49:53 +00:00
|
|
|
if (*tmp == PROGRAM_SENTINEL) {
|
2010-12-17 10:28:20 +00:00
|
|
|
*tmp = key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-18 14:30:35 +00:00
|
|
|
int
|
|
|
|
vmwareParseVersionStr(int type, const char *verbuf, unsigned long *version)
|
|
|
|
{
|
|
|
|
const char *pattern;
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case VMWARE_DRIVER_PLAYER:
|
|
|
|
pattern = "VMware Player ";
|
|
|
|
break;
|
|
|
|
case VMWARE_DRIVER_WORKSTATION:
|
|
|
|
pattern = "VMware Workstation ";
|
|
|
|
break;
|
2013-09-24 16:24:31 +00:00
|
|
|
case VMWARE_DRIVER_FUSION:
|
|
|
|
pattern = "\nVMware Fusion Information:\nVMware Fusion ";
|
|
|
|
break;
|
2013-09-18 14:30:35 +00:00
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Invalid driver type: %d"), type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-09 09:59:53 +00:00
|
|
|
if ((tmp = strstr(verbuf, pattern)) == NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot find version pattern \"%s\""), pattern);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tmp = STRSKIP(tmp, pattern)) == NULL) {
|
2013-09-18 14:30:35 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("failed to parse %sversion"), pattern);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virParseVersionString(tmp, version, false) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("version parsing error"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-17 10:28:20 +00:00
|
|
|
int
|
|
|
|
vmwareExtractVersion(struct vmware_driver *driver)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2013-09-24 16:24:30 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
char * outbuf = NULL;
|
2013-09-24 16:24:30 +00:00
|
|
|
char *bin = NULL;
|
|
|
|
char *vmwarePath = NULL;
|
|
|
|
|
2019-12-20 16:48:02 +00:00
|
|
|
vmwarePath = g_path_get_dirname(driver->vmrun);
|
2013-09-24 16:24:30 +00:00
|
|
|
|
|
|
|
switch (driver->type) {
|
|
|
|
case VMWARE_DRIVER_PLAYER:
|
2019-10-22 13:26:14 +00:00
|
|
|
bin = g_strdup_printf("%s/%s", vmwarePath, "vmplayer");
|
2013-09-24 16:24:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VMWARE_DRIVER_WORKSTATION:
|
2019-10-22 13:26:14 +00:00
|
|
|
bin = g_strdup_printf("%s/%s", vmwarePath, "vmware");
|
2013-09-24 16:24:30 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-24 16:24:31 +00:00
|
|
|
case VMWARE_DRIVER_FUSION:
|
2019-10-22 13:26:14 +00:00
|
|
|
bin = g_strdup_printf("%s/%s", vmwarePath, "vmware-vmx");
|
2013-09-24 16:24:31 +00:00
|
|
|
break;
|
|
|
|
|
2013-09-24 16:24:30 +00:00
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2014-01-03 17:57:37 +00:00
|
|
|
_("invalid driver type for version detection"));
|
2013-09-24 16:24:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
cmd = virCommandNewArgList(bin, "-v", NULL);
|
|
|
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
2014-01-03 17:57:37 +00:00
|
|
|
virCommandSetErrorBuffer(cmd, &outbuf);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-04-08 16:01:32 +00:00
|
|
|
if (vmwareParseVersionStr(driver->type, outbuf, &driver->version) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
VIR_FREE(outbuf);
|
2013-09-24 16:24:30 +00:00
|
|
|
VIR_FREE(bin);
|
|
|
|
VIR_FREE(vmwarePath);
|
2010-12-17 10:28:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virDomainDefPtr def)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (def->ngraphics == 0) {
|
|
|
|
pDomain->gui = true;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
pDomain->gui = false;
|
|
|
|
for (i = 0; i < def->ngraphics; i++) {
|
|
|
|
if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) {
|
|
|
|
pDomain->gui = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 21:41:28 +00:00
|
|
|
static int
|
|
|
|
vmwareParsePath(const char *path, char **directory, char **filename)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
|
|
|
char *separator;
|
|
|
|
|
|
|
|
separator = strrchr(path, '/');
|
|
|
|
|
|
|
|
if (separator != NULL) {
|
2014-03-18 21:41:28 +00:00
|
|
|
separator++;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (*separator == '\0') {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("path '%s' doesn't reference a file"), path);
|
2010-12-17 10:28:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-10-24 17:41:34 +00:00
|
|
|
*directory = g_strndup(path, separator - path - 1);
|
2019-10-20 11:49:46 +00:00
|
|
|
*filename = g_strdup(separator);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
} else {
|
2019-10-20 11:49:46 +00:00
|
|
|
*filename = g_strdup(path);
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
void
|
2010-12-17 10:28:20 +00:00
|
|
|
vmwareConstructVmxPath(char *directoryName, char *name, char **vmxPath)
|
|
|
|
{
|
2013-07-04 10:17:55 +00:00
|
|
|
if (directoryName != NULL)
|
2019-10-22 13:26:14 +00:00
|
|
|
*vmxPath = g_strdup_printf("%s/%s.vmx", directoryName, name);
|
2013-07-18 10:13:46 +00:00
|
|
|
else
|
2019-10-22 13:26:14 +00:00
|
|
|
*vmxPath = g_strdup_printf("%s.vmx", name);
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath)
|
|
|
|
{
|
|
|
|
virDomainDiskDefPtr disk = NULL;
|
|
|
|
char *directoryName = NULL;
|
|
|
|
char *fileName = NULL;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2014-03-18 21:41:28 +00:00
|
|
|
const char *src;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Build VMX URL. Use the source of the first file-based harddisk
|
|
|
|
* to deduce the path for the VMX file. Don't just use the
|
2014-04-20 20:07:46 +00:00
|
|
|
* first disk, because it may be CDROM disk and ISO images are normally not
|
2010-12-17 10:28:20 +00:00
|
|
|
* located in the virtual machine's directory. This approach
|
|
|
|
* isn't perfect but should work in the majority of cases.
|
|
|
|
*/
|
|
|
|
if (vmdef->ndisks < 1) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain XML doesn't contain any disks, "
|
|
|
|
"cannot deduce datastore and path for VMX file"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < vmdef->ndisks; ++i) {
|
|
|
|
if (vmdef->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
virDomainDiskGetType(vmdef->disks[i]) == VIR_STORAGE_TYPE_FILE) {
|
2010-12-17 10:28:20 +00:00
|
|
|
disk = vmdef->disks[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disk == NULL) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Domain XML doesn't contain any file-based harddisks, "
|
|
|
|
"cannot deduce datastore and path for VMX file"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-03-18 21:41:28 +00:00
|
|
|
src = virDomainDiskGetSource(disk);
|
|
|
|
if (!src) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("First file-based harddisk has no source, cannot "
|
|
|
|
"deduce datastore and path for VMX file"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:29:45 +00:00
|
|
|
if (vmwareParsePath(src, &directoryName, &fileName) < 0)
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2019-03-06 14:07:26 +00:00
|
|
|
if (!virStringHasCaseSuffix(fileName, ".vmdk")) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Expecting source '%s' of first file-based harddisk "
|
2014-03-18 21:41:28 +00:00
|
|
|
"to be a VMDK image"), src);
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
vmwareConstructVmxPath(directoryName, vmdef->name, vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
VIR_FREE(directoryName);
|
|
|
|
VIR_FREE(fileName);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareMoveFile(char *srcFile, char *dstFile)
|
|
|
|
{
|
2020-04-21 17:17:59 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if (!virFileExists(srcFile)) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("file %s does not exist"),
|
|
|
|
srcFile);
|
2010-12-17 10:28:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(srcFile, dstFile))
|
|
|
|
return 0;
|
|
|
|
|
2020-04-21 17:17:59 +00:00
|
|
|
cmd = virCommandNewArgList("mv", srcFile, dstFile, NULL);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("failed to move file to %s "), dstFile);
|
2010-12-17 10:28:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareMakePath(char *srcDir, char *srcName, char *srcExt, char **outpath)
|
|
|
|
{
|
2019-10-22 13:26:14 +00:00
|
|
|
*outpath = g_strdup_printf("%s/%s.%s", srcDir, srcName, srcExt);
|
2013-07-18 10:13:46 +00:00
|
|
|
return 0;
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vmwareExtractPid(const char * vmxPath)
|
|
|
|
{
|
|
|
|
char *vmxDir = NULL;
|
|
|
|
char *logFilePath = NULL;
|
|
|
|
FILE *logFile = NULL;
|
|
|
|
char line[1024];
|
|
|
|
char *tmp = NULL;
|
build: use correct type for pid and similar types
No thanks to 64-bit windows, with 64-bit pid_t, we have to avoid
constructs like 'int pid'. Our API in libvirt-qemu cannot be
changed without breaking ABI; but then again, libvirt-qemu can
only be used on systems that support UNIX sockets, which rules
out Windows (even if qemu could be compiled there) - so for all
points on the call chain that interact with this API decision,
we require a different variable name to make it clear that we
audited the use for safety.
Adding a syntax-check rule only solves half the battle; anywhere
that uses printf on a pid_t still needs to be converted, but that
will be a separate patch.
* cfg.mk (sc_correct_id_types): New syntax check.
* src/libvirt-qemu.c (virDomainQemuAttach): Document why we didn't
use pid_t for pid, and validate for overflow.
* include/libvirt/libvirt-qemu.h (virDomainQemuAttach): Tweak name
for syntax check.
* src/vmware/vmware_conf.c (vmwareExtractPid): Likewise.
* src/driver.h (virDrvDomainQemuAttach): Likewise.
* tools/virsh.c (cmdQemuAttach): Likewise.
* src/remote/qemu_protocol.x (qemu_domain_attach_args): Likewise.
* src/qemu_protocol-structs (qemu_domain_attach_args): Likewise.
* src/util/cgroup.c (virCgroupPidCode, virCgroupKillInternal):
Likewise.
* src/qemu/qemu_command.c(qemuParseProcFileStrings): Likewise.
(qemuParseCommandLinePid): Use pid_t for pid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* src/conf/domain_conf.h (_virDomainObj): Likewise.
* src/probes.d (rpc_socket_new): Likewise.
* src/qemu/qemu_command.h (qemuParseCommandLinePid): Likewise.
* src/qemu/qemu_driver.c (qemudGetProcessInfo, qemuDomainAttach):
Likewise.
* src/qemu/qemu_process.c (qemuProcessAttach): Likewise.
* src/qemu/qemu_process.h (qemuProcessAttach): Likewise.
* src/uml/uml_driver.c (umlGetProcessInfo): Likewise.
* src/util/virnetdev.h (virNetDevSetNamespace): Likewise.
* src/util/virnetdev.c (virNetDevSetNamespace): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput): Likewise.
* src/conf/storage_conf.h (_virStoragePerms): Use mode_t, uid_t,
and gid_t rather than int.
* src/security/security_dac.c (virSecurityDACSetOwnership): Likewise.
* src/conf/storage_conf.c (virStorageDefParsePerms): Avoid
compiler warning.
2012-02-10 23:08:11 +00:00
|
|
|
int pid_value = -1;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2019-12-20 16:48:02 +00:00
|
|
|
vmxDir = g_path_get_dirname(vmxPath);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
logFilePath = g_strdup_printf("%s/vmware.log", vmxDir);
|
2010-12-17 10:28:20 +00:00
|
|
|
|
|
|
|
if ((logFile = fopen(logFilePath, "r")) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!fgets(line, sizeof(line), logFile)) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unable to read vmware log file"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tmp = strstr(line, " pid=")) == NULL) {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot find pid in vmware log file"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp += strlen(" pid=");
|
|
|
|
|
build: use correct type for pid and similar types
No thanks to 64-bit windows, with 64-bit pid_t, we have to avoid
constructs like 'int pid'. Our API in libvirt-qemu cannot be
changed without breaking ABI; but then again, libvirt-qemu can
only be used on systems that support UNIX sockets, which rules
out Windows (even if qemu could be compiled there) - so for all
points on the call chain that interact with this API decision,
we require a different variable name to make it clear that we
audited the use for safety.
Adding a syntax-check rule only solves half the battle; anywhere
that uses printf on a pid_t still needs to be converted, but that
will be a separate patch.
* cfg.mk (sc_correct_id_types): New syntax check.
* src/libvirt-qemu.c (virDomainQemuAttach): Document why we didn't
use pid_t for pid, and validate for overflow.
* include/libvirt/libvirt-qemu.h (virDomainQemuAttach): Tweak name
for syntax check.
* src/vmware/vmware_conf.c (vmwareExtractPid): Likewise.
* src/driver.h (virDrvDomainQemuAttach): Likewise.
* tools/virsh.c (cmdQemuAttach): Likewise.
* src/remote/qemu_protocol.x (qemu_domain_attach_args): Likewise.
* src/qemu_protocol-structs (qemu_domain_attach_args): Likewise.
* src/util/cgroup.c (virCgroupPidCode, virCgroupKillInternal):
Likewise.
* src/qemu/qemu_command.c(qemuParseProcFileStrings): Likewise.
(qemuParseCommandLinePid): Use pid_t for pid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* src/conf/domain_conf.h (_virDomainObj): Likewise.
* src/probes.d (rpc_socket_new): Likewise.
* src/qemu/qemu_command.h (qemuParseCommandLinePid): Likewise.
* src/qemu/qemu_driver.c (qemudGetProcessInfo, qemuDomainAttach):
Likewise.
* src/qemu/qemu_process.c (qemuProcessAttach): Likewise.
* src/qemu/qemu_process.h (qemuProcessAttach): Likewise.
* src/uml/uml_driver.c (umlGetProcessInfo): Likewise.
* src/util/virnetdev.h (virNetDevSetNamespace): Likewise.
* src/util/virnetdev.c (virNetDevSetNamespace): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput): Likewise.
* src/conf/storage_conf.h (_virStoragePerms): Use mode_t, uid_t,
and gid_t rather than int.
* src/security/security_dac.c (virSecurityDACSetOwnership): Likewise.
* src/conf/storage_conf.c (virStorageDefParsePerms): Avoid
compiler warning.
2012-02-10 23:08:11 +00:00
|
|
|
/* Although 64-bit windows allows 64-bit pid_t, a domain id has to be
|
|
|
|
* 32 bits. For now, we just reject pid values that overflow int. */
|
|
|
|
if (virStrToLong_i(tmp, &tmp, 10, &pid_value) < 0 || *tmp != ' ') {
|
2012-07-18 13:22:54 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot parse pid in vmware log file"));
|
2010-12-17 10:28:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2010-12-17 10:28:20 +00:00
|
|
|
VIR_FREE(vmxDir);
|
|
|
|
VIR_FREE(logFilePath);
|
|
|
|
VIR_FORCE_FCLOSE(logFile);
|
build: use correct type for pid and similar types
No thanks to 64-bit windows, with 64-bit pid_t, we have to avoid
constructs like 'int pid'. Our API in libvirt-qemu cannot be
changed without breaking ABI; but then again, libvirt-qemu can
only be used on systems that support UNIX sockets, which rules
out Windows (even if qemu could be compiled there) - so for all
points on the call chain that interact with this API decision,
we require a different variable name to make it clear that we
audited the use for safety.
Adding a syntax-check rule only solves half the battle; anywhere
that uses printf on a pid_t still needs to be converted, but that
will be a separate patch.
* cfg.mk (sc_correct_id_types): New syntax check.
* src/libvirt-qemu.c (virDomainQemuAttach): Document why we didn't
use pid_t for pid, and validate for overflow.
* include/libvirt/libvirt-qemu.h (virDomainQemuAttach): Tweak name
for syntax check.
* src/vmware/vmware_conf.c (vmwareExtractPid): Likewise.
* src/driver.h (virDrvDomainQemuAttach): Likewise.
* tools/virsh.c (cmdQemuAttach): Likewise.
* src/remote/qemu_protocol.x (qemu_domain_attach_args): Likewise.
* src/qemu_protocol-structs (qemu_domain_attach_args): Likewise.
* src/util/cgroup.c (virCgroupPidCode, virCgroupKillInternal):
Likewise.
* src/qemu/qemu_command.c(qemuParseProcFileStrings): Likewise.
(qemuParseCommandLinePid): Use pid_t for pid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* src/conf/domain_conf.h (_virDomainObj): Likewise.
* src/probes.d (rpc_socket_new): Likewise.
* src/qemu/qemu_command.h (qemuParseCommandLinePid): Likewise.
* src/qemu/qemu_driver.c (qemudGetProcessInfo, qemuDomainAttach):
Likewise.
* src/qemu/qemu_process.c (qemuProcessAttach): Likewise.
* src/qemu/qemu_process.h (qemuProcessAttach): Likewise.
* src/uml/uml_driver.c (umlGetProcessInfo): Likewise.
* src/util/virnetdev.h (virNetDevSetNamespace): Likewise.
* src/util/virnetdev.c (virNetDevSetNamespace): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput): Likewise.
* src/conf/storage_conf.h (_virStoragePerms): Use mode_t, uid_t,
and gid_t rather than int.
* src/security/security_dac.c (virSecurityDACSetOwnership): Likewise.
* src/conf/storage_conf.c (virStorageDefParsePerms): Avoid
compiler warning.
2012-02-10 23:08:11 +00:00
|
|
|
return pid_value;
|
2010-12-17 10:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2019-10-14 12:45:33 +00:00
|
|
|
vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSED)
|
2010-12-17 10:28:20 +00:00
|
|
|
{
|
2013-05-03 12:50:46 +00:00
|
|
|
char *path;
|
2010-12-17 10:28:20 +00:00
|
|
|
|
2019-10-18 11:27:03 +00:00
|
|
|
path = g_strdup(datastorePath);
|
2010-12-17 10:28:20 +00:00
|
|
|
return path;
|
|
|
|
}
|