2010/12/8 Jean-Baptiste Rouault <jean-baptiste.rouault(a)diateam.net>:
---
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