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