Re: [Patch v3] Add VMware Workstation and Player driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/12/8 Jean-Baptiste Rouault <jean-baptiste.rouault@xxxxxxxxxxx>:
> ---
> Âcfg.mk           Â|  Â1 +
> Âconfigure.ac        Â|  Â7 +
> Âinclude/libvirt/virterror.h | Â Â1 +
> Âpo/POTFILES.in       Â|  Â2 +
> Âsrc/Makefile.am       |  24 +-
> Âsrc/driver.h        Â|  Â3 +-
> Âsrc/libvirt.c        |  15 +
> Âsrc/util/virterror.c    Â|  Â3 +
> Âsrc/vmware/vmware_conf.c  Â| Â453 +++++++++++++++
> Âsrc/vmware/vmware_conf.h  Â|  82 +++
> Âsrc/vmware/vmware_driver.c Â| 1351 +++++++++++++++++++++++++++++++++++++++++++
> Âsrc/vmware/vmware_driver.h Â| Â 25 +
> Â12 files changed, 1963 insertions(+), 4 deletions(-)
> Âcreate mode 100644 src/vmware/vmware_conf.c
> Âcreate mode 100644 src/vmware/vmware_conf.h
> Âcreate mode 100644 src/vmware/vmware_driver.c
> Âcreate mode 100644 src/vmware/vmware_driver.h
>


> diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
> new file mode 100644
> index 0000000..2255b52
> --- /dev/null
> +++ b/src/vmware/vmware_conf.c

> +#include <config.h>
> +
> +#include <string.h>
> +#include <sys/utsname.h>
> +
> +#include "command.h"
> +#include "cpu/cpu.h"
> +#include "memory.h"
> +#include "nodeinfo.h"
> +#include "util/files.h"
> +#include "uuid.h"
> +#include "virterror_internal.h"
> +#include "../esx/esx_vmx.h"
> +
> +#include "vmware_conf.h"
> +
> +#define VMWARE_MAX_ARG 20

This define is unused.


> +int
> +vmwareLoadDomains(struct vmware_driver *driver)
> +{

> + Â Âctx.parseFileName = esxCopyVMXFileName;
> +
> + Â Âcmd = virCommandNewArgList(VMRUN, "-T",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â driver->type == TYPE_PLAYER ? "player" : "ws",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "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;
> +
> + Â Â Â Â/* remove trailing newline */
> + Â Â Â Âlen = strlen(vmxPath);
> + Â Â Â Âif (len && vmxPath[len-1] == '\n')
> + Â Â Â Â Â ÂvmxPath[len-1] = '\0';
> +
> + Â Â Â Âif (virFileReadAll(vmxPath, 10000, &vmx) == -1) {
> + Â Â Â Â Â Âperror("error reading vmx file");
> + Â Â Â Â Â ÂvmwareError(VIR_ERR_INTERNAL_ERROR,
> + Â Â Â Â Â Â Â Â Â Â Â Â_("failed to read vmx file %s"), vmxPath);

We don't use perror in libvirt and virFileReadAll already reports and
error when it fails. So just remove the perror and vmwareError calls.

Yes, I know it's hard to tell which functions already report errors
and which don't :)

> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}


> diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
> new file mode 100644
> index 0000000..5d8a8d5
> --- /dev/null
> +++ b/src/vmware/vmware_driver.c

> +static int
> +vmwareDomainRestore(virConnectPtr conn, const char *path)
> +{

> + Â Âctx.parseFileName = esxCopyVMXFileName;
> +
> + Â Âif (!virFileExists(path)) {
> + Â Â Â ÂvmwareError(VIR_ERR_INTERNAL_ERROR,
> + Â Â Â Â Â Â Â Â Â Â_("file %s does not exist"), path);
> + Â Â Â Âgoto cleanup;
> + Â Â}
> + Â Âif (virFileHasSuffix(path, ".vmx")) { Â Â Â //we want to restore a vm saved in its default directory
> + Â Â Â Âif((tvmx = strdup(path)) == NULL) {
> + Â Â Â Â Â ÂvirReportOOMError();
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Âif((copypath = strdup(path)) == NULL) {
> + Â Â Â Â Â ÂvirReportOOMError();
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Âif (vmwareParsePath(copypath, &fDirectoryName, &fFileName) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> +
> + Â Â Â Âsep = strrchr(fFileName, '.');
> + Â Â Â Âif (sep != NULL)
> + Â Â Â Â Â Â*sep = '\0';
> +
> + Â Â Â Âif (vmwareMakePath(fFileName, fFileName, (char *) "vmss", &fvmss) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> +
> + Â Â Â ÂbaseVmss = basename(fvmss);
> + Â Â} else { Â Â Â Â Â Â Â Â Â Â//we want to restore a vm saved elsewhere
> + Â Â Â Âif (virFileReadAll(path, 1024, &vmxPath) < 0) {
> + Â Â Â Â Â ÂvmwareError(VIR_ERR_INTERNAL_ERROR, "%s",
> + Â Â Â Â Â Â Â Â Â Â Â Â_("failed to read vmxPath"));

virFileReadAll already reports an error.

> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Âif (!virFileHasSuffix(vmxPath, ".vmx")) {
> + Â Â Â Â Â ÂvmwareError(VIR_ERR_INTERNAL_ERROR,
> + Â Â Â Â Â Â Â Â Â Â Â Â_("%s is not a .vmx file"), vmxPath);
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Â/* move files */
> + Â Â Â Âif((copyvmxPath = strdup(vmxPath)) == NULL) {
> + Â Â Â Â Â ÂvirReportOOMError();
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Âif((copypath = strdup(path)) == NULL) {
> + Â Â Â Â Â ÂvirReportOOMError();
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Âif (vmwareParsePath(copypath, &fDirectoryName, &fFileName) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> +
> + Â Â Â Âif (vmwareParsePath(copyvmxPath, &tDirectoryName, &tFileName) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> +
> + Â Â Â Âsep = strrchr(tFileName, '.');
> + Â Â Â Âif (sep != NULL)
> + Â Â Â Â Â Â*sep = '\0';
> +
> + Â Â Â Âif (virFileMakePath(tDirectoryName) != 0) {
> + Â Â Â Â Â ÂvmwareError(VIR_ERR_INTERNAL_ERROR, "%s",
> + Â Â Â Â Â Â Â Â Â Â Â Â_("make path error"));
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â Âif (vmwareMakePath(fDirectoryName, tFileName,(char *) "vmss", &fvmss) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Âif (vmwareMakePath(tDirectoryName, tFileName, (char *) "vmss", &tvmss) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Âif (vmwareMakePath(fDirectoryName, tFileName, (char *) "vmem", &fvmem) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Âif (vmwareMakePath(tDirectoryName, tFileName, (char *) "vmem", &tvmem) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Âif (vmwareMakePath(fDirectoryName, tFileName, (char *) "vmx", &fvmx) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Âif (vmwareMakePath(tDirectoryName, tFileName, (char *) "vmx", &tvmx) < 0)
> + Â Â Â Â Â Âgoto cleanup;
> +
> + Â Â Â Âif ((vmwareMoveFile(fvmss, tvmss) < 0)
> + Â Â Â Â Â Â|| (vmwareMoveFile(fvmem, tvmem) < 0)
> + Â Â Â Â Â Â|| (vmwareMoveFile(fvmx, tvmx) < 0)) {
> + Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â}
> +
> + Â Â Â ÂbaseVmss = basename(tvmss);
> + Â Â}
> +
> + Â Âif (virFileReadAll(tvmx, 10000, &vmx) == -1) {
> + Â Â Â Âperror("error reading vmx file");
> + Â Â Â ÂvmwareError(VIR_ERR_INTERNAL_ERROR,
> + Â Â Â Â Â Â Â Â Â Â_("failed to read vmx file %s"), tvmx);

virFileReadAll already reports an error.

Matthias

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]