libvirt/src/vmware/vmware_conf.c

522 lines
14 KiB
C
Raw Normal View History

/*---------------------------------------------------------------------------*/
/*
* Copyright (C) 2011-2014 Red Hat, Inc.
* Copyright (C) 2010-2014, diateam (www.diateam.net)
*
* 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
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
/*---------------------------------------------------------------------------*/
#include <config.h>
#include "vircommand.h"
#include "cpu/cpu.h"
2012-12-12 18:06:53 +00:00
#include "viralloc.h"
#include "virfile.h"
2012-12-13 18:01:25 +00:00
#include "viruuid.h"
#include "virerror.h"
#include "vmx.h"
#include "vmware_conf.h"
#include "virstring.h"
#include "virlog.h"
#include "virutil.h"
#define VIR_FROM_THIS VIR_FROM_VMWARE
VIR_LOG_INIT("vmware.vmware_conf");
VIR_ENUM_IMPL(vmwareDriver,
VMWARE_DRIVER_LAST,
"player",
"ws",
"fusion",
);
/* Free all memory associated with a vmware_driver structure */
void
vmwareFreeDriver(struct vmware_driver *driver)
{
if (!driver)
return;
virMutexDestroy(&driver->lock);
virObjectUnref(driver->domains);
virObjectUnref(driver->caps);
virObjectUnref(driver->xmlopt);
VIR_FREE(driver->vmrun);
VIR_FREE(driver);
}
virCapsPtr
vmwareCapsInit(void)
{
virCapsPtr caps = NULL;
virCapsGuestPtr guest = NULL;
if ((caps = virCapabilitiesNew(virArchFromHost(),
capabilities: use bool instead of int While preparing to add a capability for active commit, I noticed that the existing code was abusing int for boolean values. * src/conf/capabilities.h (_virCapsGuestFeature, _virCapsHost) (virCapabilitiesNew, virCapabilitiesAddGuestFeature): Improve types. * src/conf/capabilities.c (virCapabilitiesNew) (virCapabilitiesAddGuestFeature): Adjust signature. * src/bhyve/bhyve_capabilities.c (virBhyveCapsBuild): Update clients. * src/esx/esx_driver.c (esxCapsInit): Likewise. * src/libxl/libxl_conf.c (libxlMakeCapabilities): Likewise. * src/lxc/lxc_conf.c (virLXCDriverCapsInit): Likewise. * src/openvz/openvz_conf.c (openvzCapsInit): Likewise. * src/parallels/parallels_driver.c (parallelsBuildCapabilities): Likewise. * src/phyp/phyp_driver.c (phypCapsInit): Likewise. * src/qemu/qemu_capabilities.c (virQEMUCapsInit) (virQEMUCapsInitGuestFromBinary): Likewise. * src/security/virt-aa-helper.c (get_definition): Likewise. * src/test/test_driver.c (testBuildCapabilities): Likewise. * src/uml/uml_conf.c (umlCapsInit): Likewise. * src/vbox/vbox_tmpl.c (vboxCapsInit): Likewise. * src/vmware/vmware_conf.c (vmwareCapsInit): Likewise. * src/xen/xen_hypervisor.c (xenHypervisorBuildCapabilities): Likewise. * src/xenapi/xenapi_driver.c (getCapsObject): Likewise. * tests/qemucaps2xmltest.c (testGetCaps): Likewise. * tests/testutils.c (virTestGenericCapsInit): Likewise. * tests/testutilslxc.c (testLXCCapsInit): Likewise. * tests/testutilsqemu.c (testQemuCapsInit): Likewise. * tests/testutilsxen.c (testXenCapsInit): Likewise. * tests/vircaps2xmltest.c (buildVirCapabilities): Likewise. * tests/vircapstest.c (buildNUMATopology): Likewise. * tests/vmx2xmltest.c (testCapsInit): Likewise. * tests/xml2vmxtest.c (testCapsInit): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2014-07-14 12:56:13 +00:00
false, false)) == NULL)
goto error;
if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
goto error;
if (virCapabilitiesInitCaches(caps) < 0)
VIR_WARN("Failed to get host CPU cache info");
/* i686 guests are always supported */
if ((guest = virCapabilitiesAddGuest(caps,
VIR_DOMAIN_OSTYPE_HVM,
VIR_ARCH_I686,
NULL, NULL, 0, NULL)) == NULL)
goto error;
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL) == NULL)
goto error;
guest = NULL;
if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
goto error;
/* x86_64 guests are supported if
* - Host arch is x86_64
* Or
* - Host CPU is x86_64 with virtualization extensions
*/
if (caps->host.arch == VIR_ARCH_X86_64 ||
(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")))) {
if ((guest = virCapabilitiesAddGuest(caps,
VIR_DOMAIN_OSTYPE_HVM,
VIR_ARCH_X86_64,
NULL, NULL, 0, NULL)) == NULL)
goto error;
if (virCapabilitiesAddGuestDomain(guest,
VIR_DOMAIN_VIRT_VMWARE,
NULL, NULL, 0, NULL) == NULL)
goto error;
guest = NULL;
}
return caps;
error:
virCapabilitiesFreeGuest(guest);
virObjectUnref(caps);
return NULL;
}
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;
virVMXContext ctx;
char *outbuf = NULL;
char *str;
char *saveptr = NULL;
virCommandPtr cmd;
ctx.parseFileName = vmwareCopyVMXFileName;
ctx.formatFileName = NULL;
ctx.autodetectSCSIControllerModel = NULL;
ctx.datacenterPath = NULL;
cmd = virCommandNewArgList(driver->vmrun, "-T",
vmwareDriverTypeToString(driver->type),
"list", NULL);
virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
for (str = outbuf; (vmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
str = NULL) {
if (vmxPath[0] != '/')
continue;
if (virFileReadAll(vmxPath, 10000, &vmx) < 0)
goto cleanup;
if ((vmdef =
virVMXParseConfig(&ctx, driver->xmlopt,
driver->caps, vmx)) == NULL) {
goto cleanup;
}
if (!(vm = virDomainObjListAdd(driver->domains, vmdef,
driver->xmlopt,
0, NULL)))
goto cleanup;
pDomain = vm->privateData;
pDomain->vmxPath = g_strdup(vmxPath);
vmwareDomainConfigDisplay(pDomain, vmdef);
if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0)
goto cleanup;
/* vmrun list only reports running vms */
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
VIR_DOMAIN_RUNNING_UNKNOWN);
vm->persistent = 1;
conf: Clean up object referencing for Add and Remove When adding a new object to the domain object list, there should have been 2 virObjectRef calls made one for each list into which the object was placed to match the 2 virObjectUnref calls that would occur during Remove as part of virHashRemoveEntry when virObjectFreeHashData is called when the element is removed from the hash table as set up in virDomainObjListNew. Some drivers (libxl, lxc, qemu, and vz) handled this inconsistency by calling virObjectRef upon successful return from virDomainObjListAdd in order to use virDomainObjEndAPI when done with the returned @vm. While others (bhyve, openvz, test, and vmware) handled this via only calling virObjectUnlock upon successful return from virDomainObjListAdd. This patch will "unify" the approach to use virDomainObjEndAPI for any @vm successfully returned from virDomainObjListAdd. Because list removal is so tightly coupled with list addition, this patch fixes the list removal algorithm to return the object as entered - "locked and reffed". This way, the callers can then decide how to uniformly handle add/remove success and failure. This removes the onus on the caller to "specially handle" the @vm during removal processing. The Add/Remove logic allows for some logic simplification such as in libxl where we can Remove the @vm directly rather than needing to set a @remove_dom boolean and removing after the libxlDomainObjEndJob completes as the @vm is locked/reffed. Signed-off-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-04-23 14:40:48 +00:00
virDomainObjEndAPI(&vm);
vmdef = NULL;
}
ret = 0;
cleanup:
virCommandFree(cmd);
VIR_FREE(outbuf);
virDomainDefFree(vmdef);
VIR_FREE(directoryName);
VIR_FREE(fileName);
VIR_FREE(vmx);
virObjectUnref(vm);
return ret;
}
void
vmwareSetSentinal(const char **prog, const char *key)
{
const char **tmp = prog;
while (tmp && *tmp) {
if (*tmp == PROGRAM_SENTINEL) {
*tmp = key;
break;
}
tmp++;
}
}
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;
case VMWARE_DRIVER_FUSION:
pattern = "\nVMware Fusion Information:\nVMware Fusion ";
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid driver type: %d"), type);
return -1;
}
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) {
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;
}
int
vmwareExtractVersion(struct vmware_driver *driver)
{
int ret = -1;
virCommandPtr cmd = NULL;
char * outbuf = NULL;
char *bin = NULL;
char *vmwarePath = NULL;
vmwarePath = g_path_get_dirname(driver->vmrun);
switch (driver->type) {
case VMWARE_DRIVER_PLAYER:
bin = g_strdup_printf("%s/%s", vmwarePath, "vmplayer");
break;
case VMWARE_DRIVER_WORKSTATION:
bin = g_strdup_printf("%s/%s", vmwarePath, "vmware");
break;
case VMWARE_DRIVER_FUSION:
bin = g_strdup_printf("%s/%s", vmwarePath, "vmware-vmx");
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid driver type for version detection"));
goto cleanup;
}
cmd = virCommandNewArgList(bin, "-v", NULL);
virCommandSetOutputBuffer(cmd, &outbuf);
virCommandSetErrorBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
if (vmwareParseVersionStr(driver->type, outbuf, &driver->version) < 0)
goto cleanup;
ret = 0;
cleanup:
virCommandFree(cmd);
VIR_FREE(outbuf);
VIR_FREE(bin);
VIR_FREE(vmwarePath);
return ret;
}
int
vmwareDomainConfigDisplay(vmwareDomainPtr pDomain, virDomainDefPtr def)
{
size_t i;
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;
}
}
static int
vmwareParsePath(const char *path, char **directory, char **filename)
{
char *separator;
separator = strrchr(path, '/');
if (separator != NULL) {
separator++;
if (*separator == '\0') {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("path '%s' doesn't reference a file"), path);
return -1;
}
*directory = g_strndup(path, separator - path - 1);
*filename = g_strdup(separator);
} else {
*filename = g_strdup(path);
}
return 0;
}
void
vmwareConstructVmxPath(char *directoryName, char *name, char **vmxPath)
{
if (directoryName != NULL)
*vmxPath = g_strdup_printf("%s/%s.vmx", directoryName, name);
else
*vmxPath = g_strdup_printf("%s.vmx", name);
}
int
vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath)
{
virDomainDiskDefPtr disk = NULL;
char *directoryName = NULL;
char *fileName = NULL;
int ret = -1;
size_t i;
const char *src;
/*
* 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
* first disk, because it may be CDROM disk and ISO images are normally not
* located in the virtual machine's directory. This approach
* isn't perfect but should work in the majority of cases.
*/
if (vmdef->ndisks < 1) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain XML doesn't contain any disks, "
"cannot deduce datastore and path for VMX file"));
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) {
disk = vmdef->disks[i];
break;
}
}
if (disk == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Domain XML doesn't contain any file-based harddisks, "
"cannot deduce datastore and path for VMX file"));
goto cleanup;
}
src = virDomainDiskGetSource(disk);
if (!src) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("First file-based harddisk has no source, cannot "
"deduce datastore and path for VMX file"));
goto cleanup;
}
if (vmwareParsePath(src, &directoryName, &fileName) < 0)
goto cleanup;
if (!virStringHasCaseSuffix(fileName, ".vmdk")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting source '%s' of first file-based harddisk "
"to be a VMDK image"), src);
goto cleanup;
}
vmwareConstructVmxPath(directoryName, vmdef->name, vmxPath);
ret = 0;
cleanup:
VIR_FREE(directoryName);
VIR_FREE(fileName);
return ret;
}
int
vmwareMoveFile(char *srcFile, char *dstFile)
{
g_autoptr(virCommand) cmd = NULL;
if (!virFileExists(srcFile)) {
virReportError(VIR_ERR_INTERNAL_ERROR, _("file %s does not exist"),
srcFile);
return -1;
}
if (STREQ(srcFile, dstFile))
return 0;
cmd = virCommandNewArgList("mv", srcFile, dstFile, NULL);
if (virCommandRun(cmd, NULL) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to move file to %s "), dstFile);
return -1;
}
return 0;
}
int
vmwareMakePath(char *srcDir, char *srcName, char *srcExt, char **outpath)
{
*outpath = g_strdup_printf("%s/%s.%s", srcDir, srcName, srcExt);
return 0;
}
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;
vmxDir = g_path_get_dirname(vmxPath);
logFilePath = g_strdup_printf("%s/vmware.log", vmxDir);
if ((logFile = fopen(logFilePath, "r")) == NULL)
goto cleanup;
if (!fgets(line, sizeof(line), logFile)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("unable to read vmware log file"));
goto cleanup;
}
if ((tmp = strstr(line, " pid=")) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot find pid in vmware log file"));
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 != ' ') {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot parse pid in vmware log file"));
goto cleanup;
}
cleanup:
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;
}
char *
vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSED)
{
char *path;
path = g_strdup(datastorePath);
return path;
}