]> xenbits.xensource.com Git - libvirt.git/commitdiff
vmx: handle shared folders parsing
authorJean-Baptiste Rouault <jean-baptiste.rouault@diateam.net>
Wed, 11 Jul 2012 10:16:35 +0000 (12:16 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 21 Jul 2012 18:15:02 +0000 (20:15 +0200)
This patch adds support for parsing vmx files with
shared folders enabled.

Update test suite accordingly.

src/vmx/vmx.c
src/vmx/vmx.h
tests/vmx2xmldata/vmx2xml-sharedfolder.vmx [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-sharedfolder.xml [new file with mode: 0644]
tests/vmx2xmltest.c

index e9131272f8e683d599ef9c311e1d80568a47e60b..e3dd125fc5ad0dd8be6ce03c81a1ec61d0c2b48e 100644 (file)
@@ -1233,6 +1233,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx)
     bool present;
     int scsi_virtualDev[4] = { -1, -1, -1, -1 };
     int unit;
+    bool hgfs_disabled = true;
+    long long sharedFolder_maxNum = 0;
 
     if (ctx->parseFileName == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1672,7 +1674,39 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, const char *vmx)
     }
 
     /* def:fss */
-    /* FIXME */
+    if (virVMXGetConfigBoolean(conf, "isolation.tools.hgfs.disable",
+                               &hgfs_disabled, true, true) < 0) {
+        goto cleanup;
+    }
+
+    if (!hgfs_disabled) {
+        if (virVMXGetConfigLong(conf, "sharedFolder.maxNum", &sharedFolder_maxNum,
+                                0, true) < 0) {
+            goto cleanup;
+        }
+
+        if (sharedFolder_maxNum > 0) {
+            int number;
+
+            if (VIR_ALLOC_N(def->fss, sharedFolder_maxNum) < 0) {
+                virReportOOMError();
+                goto cleanup;
+            }
+
+            def->nfss = 0;
+
+            for (number = 0; number < sharedFolder_maxNum; ++number) {
+                if (virVMXParseFileSystem(conf, number,
+                                          &def->fss[def->nfss]) < 0) {
+                    goto cleanup;
+                }
+
+                if (def->fss[def->nfss] != NULL) {
+                    ++def->nfss;
+                }
+            }
+        }
+    }
 
     /* def:nets */
     if (VIR_ALLOC_N(def->nets, 4) < 0) {
@@ -2284,6 +2318,108 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf,
 
 
 
+int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def)
+{
+    int result = -1;
+    char prefix[48] = "";
+
+    char present_name[48] = "";
+    bool present = false;
+
+    char enabled_name[48] = "";
+    bool enabled = false;
+
+    char hostPath_name[48] = "";
+    char *hostPath = NULL;
+
+    char guestName_name[48] = "";
+    char *guestName = NULL;
+
+    char writeAccess_name[48] = "";
+    bool writeAccess = false;
+
+    if (def == NULL || *def != NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+        return -1;
+    }
+
+    if (VIR_ALLOC(*def) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
+    (*def)->type = VIR_DOMAIN_FS_TYPE_MOUNT;
+
+    snprintf(prefix, sizeof(prefix), "sharedFolder%d", number);
+
+    VMX_BUILD_NAME(present);
+    VMX_BUILD_NAME(enabled);
+    VMX_BUILD_NAME(hostPath);
+    VMX_BUILD_NAME(guestName);
+    VMX_BUILD_NAME(writeAccess);
+
+    /* vmx:present */
+    if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) {
+        goto cleanup;
+    }
+
+    /* vmx:enabled */
+    if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0) {
+        goto cleanup;
+    }
+
+    if (!(present && enabled)) {
+        goto ignore;
+    }
+
+    /* vmx:hostPath */
+    if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0) {
+        goto cleanup;
+    }
+
+    (*def)->src = hostPath;
+    hostPath = NULL;
+
+    /* vmx:guestName */
+    if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0) {
+        goto cleanup;
+    }
+
+    (*def)->dst = guestName;
+    guestName = NULL;
+
+    /* vmx:writeAccess */
+    if (virVMXGetConfigBoolean(conf, writeAccess_name, &writeAccess, false,
+                               true) < 0) {
+        goto cleanup;
+    }
+
+    (*def)->readonly = !writeAccess;
+
+    result = 0;
+
+  cleanup:
+    if (result < 0) {
+        virDomainFSDefFree(*def);
+        *def = NULL;
+    }
+
+    VIR_FREE(hostPath);
+    VIR_FREE(guestName);
+
+    return result;
+
+  ignore:
+    virDomainFSDefFree(*def);
+    *def = NULL;
+
+    result = 0;
+
+    goto cleanup;
+}
+
+
+
 int
 virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
 {
index 64f5abce00a4839253785f802aa77343cfa93dcb..f9093133afff6a8d2d1a685928d32f717b48d4aa 100644 (file)
@@ -90,6 +90,8 @@ int virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf,
                     int device, int busType, int controllerOrBus, int unit,
                     virDomainDiskDefPtr *def);
 
+int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def);
+
 int virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def);
 
 int virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
diff --git a/tests/vmx2xmldata/vmx2xml-sharedfolder.vmx b/tests/vmx2xmldata/vmx2xml-sharedfolder.vmx
new file mode 100644 (file)
index 0000000..e60fcd4
--- /dev/null
@@ -0,0 +1,9 @@
+config.version = "8"
+virtualHW.version = "4"
+isolation.tools.hgfs.disable = "false"
+sharedFolder.maxnum = "1"
+sharedFolder0.present = "true"
+sharedFolder0.enabled = "true"
+sharedFolder0.hostPath = "/path/to/shared"
+sharedFolder0.guestName = "shared"
+sharedFolder0.writeAccess = "true"
diff --git a/tests/vmx2xmldata/vmx2xml-sharedfolder.xml b/tests/vmx2xmldata/vmx2xml-sharedfolder.xml
new file mode 100644 (file)
index 0000000..52b75de
--- /dev/null
@@ -0,0 +1,22 @@
+<domain type='vmware'>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory unit='KiB'>32768</memory>
+  <currentMemory unit='KiB'>32768</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/path/to/shared'/>
+      <target dir='shared'/>
+    </filesystem>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
index 35740ea423d044815cd6fe7f7e523afcfa3f5408..49131524e09501193d4bd17e3c140f1b03b4aaaa 100644 (file)
@@ -240,6 +240,8 @@ mymain(void)
     DO_TEST("floppy-file", "floppy-file");
     DO_TEST("floppy-device", "floppy-device");
 
+    DO_TEST("sharedfolder", "sharedfolder");
+
     DO_TEST("ethernet-e1000", "ethernet-e1000");
     DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2");