[PATCH 2/2] vmx: handle shared folders parsing

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

 



This patch adds support for parsing vmx files with
shared folders enabled.

Update test suite accordingly.
---
 src/vmx/vmx.c                              |  134 +++++++++++++++++++++++++++-
 src/vmx/vmx.h                              |    2 +
 tests/vmx2xmldata/vmx2xml-sharedfolder.vmx |    9 ++
 tests/vmx2xmldata/vmx2xml-sharedfolder.xml |   22 +++++
 tests/vmx2xmltest.c                        |    2 +
 5 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100644 tests/vmx2xmldata/vmx2xml-sharedfolder.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-sharedfolder.xml

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 8a26f8c..d4f75ee 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1237,6 +1237,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 shared_folders_num = 0;
 
     if (ctx->parseFileName == NULL) {
         VMX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1676,7 +1678,37 @@ 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", &shared_folders_num,
+                                0, true) < 0) {
+            goto cleanup;
+        }
+
+        if (shared_folders_num) {
+            if (VIR_ALLOC_N(def->fss, shared_folders_num) < 0) {
+                virReportOOMError();
+                goto cleanup;
+            }
+
+            def->nfss = 0;
+
+            for (port = 0; port < shared_folders_num; ++port) {
+                if (virVMXParseFileSystem(conf, port,
+                                          &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) {
@@ -2288,6 +2320,106 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, virConfPtr conf,
 
 
 
+int virVMXParseFileSystem(virConfPtr conf, int index, 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) {
+        VMX_ERROR(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", index);
+
+    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 = strdup(hostPath);
+
+    /* vmx:guestName */
+    if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0) {
+        goto cleanup;
+    }
+
+    (*def)->dst = strdup(guestName);
+
+    /* 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)
 {
diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h
index 656aafa..8ae0707 100644
--- a/src/vmx/vmx.h
+++ b/src/vmx/vmx.h
@@ -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 index, 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
index 0000000..e60fcd4
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-sharedfolder.vmx
@@ -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
index 0000000..52b75de
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-sharedfolder.xml
@@ -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>
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 35740ea..4913152 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -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");
 
-- 
1.7.10.4

--
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]