[libvirt PATCH v2 4/5] vmx: Allow missing cdrom image file in virVMXParseFileName

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

 



This will be used later.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/esx/esx_driver.c     | 13 +++++++++----
 src/vmware/vmware_conf.c |  2 +-
 src/vmx/vmx.c            | 12 +++++++-----
 src/vmx/vmx.h            |  5 ++++-
 tests/vmx2xmltest.c      | 13 ++++++++++++-
 5 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 86d5396147a3..0271f81a5655 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -128,7 +128,8 @@ esxFreePrivate(esxPrivate **priv)
 static int
 esxParseVMXFileName(const char *fileName,
                     void *opaque,
-                    char **out)
+                    char **out,
+                    bool allow_missing)
 {
     esxVMX_Data *data = opaque;
     esxVI_String *propertyNameList = NULL;
@@ -222,9 +223,13 @@ esxParseVMXFileName(const char *fileName,
         }
 
         if (!datastoreList) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("File name '%s' refers to non-existing datastore '%s'"),
-                           fileName, datastoreName);
+            if (allow_missing) {
+                ret = 0;
+            } else {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("File name '%s' refers to non-existing datastore '%s'"),
+                               fileName, datastoreName);
+            }
             goto cleanup;
         }
 
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index c90cb10faf7c..4b0832f50b3c 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -509,7 +509,7 @@ vmwareExtractPid(const char * vmxPath)
 
 int
 vmwareCopyVMXFileName(const char *datastorePath, void *opaque G_GNUC_UNUSED,
-                      char **out)
+                      char **out, bool allow_missing G_GNUC_UNUSED)
 {
     *out = g_strdup(datastorePath);
 
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index b2b2244415a1..4d098a5fa4d6 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2411,7 +2411,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
             }
 
             virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE);
-            if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0)
+            if (ctx->parseFileName(fileName, ctx->opaque, &tmp, false) < 0)
                 goto cleanup;
             virDomainDiskSetSource(*def, tmp);
             VIR_FREE(tmp);
@@ -2448,7 +2448,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
             }
 
             virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE);
-            if (ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0)
+            if (ctx->parseFileName(fileName, ctx->opaque, &tmp, true) < 0)
                 goto cleanup;
             virDomainDiskSetSource(*def, tmp);
             VIR_FREE(tmp);
@@ -2515,7 +2515,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
 
             virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE);
             if (fileName &&
-                ctx->parseFileName(fileName, ctx->opaque, &tmp) < 0)
+                ctx->parseFileName(fileName, ctx->opaque, &tmp, false) < 0)
                 goto cleanup;
             virDomainDiskSetSource(*def, tmp);
             VIR_FREE(tmp);
@@ -2977,7 +2977,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
         (*def)->source->type = VIR_DOMAIN_CHR_TYPE_FILE;
         if (ctx->parseFileName(fileName,
                               ctx->opaque,
-                              &(*def)->source->data.file.path) < 0)
+                              &(*def)->source->data.file.path,
+                              false) < 0)
             goto cleanup;
     } else if (STRCASEEQ(fileType, "pipe")) {
         /*
@@ -3142,7 +3143,8 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port,
         (*def)->source->type = VIR_DOMAIN_CHR_TYPE_FILE;
         if (ctx->parseFileName(fileName,
                               ctx->opaque,
-                              &(*def)->source->data.file.path) < 0)
+                              &(*def)->source->data.file.path,
+                              false) < 0)
             goto cleanup;
     } else {
         virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h
index e5420c970a4b..550c1264f3b8 100644
--- a/src/vmx/vmx.h
+++ b/src/vmx/vmx.h
@@ -36,7 +36,10 @@ virDomainXMLOptionPtr virVMXDomainXMLConfInit(virCapsPtr caps);
  * Context
  */
 
-typedef int (*virVMXParseFileName)(const char *fileName, void *opaque, char **src);
+typedef int (*virVMXParseFileName)(const char *fileName,
+                                   void *opaque,
+                                   char **src,
+                                   bool allow_missing);
 typedef char * (*virVMXFormatFileName)(const char *src, void *opaque);
 typedef int (*virVMXAutodetectSCSIControllerModel)(virDomainDiskDefPtr def,
                                                    int *model, void *opaque);
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 412b201f0242..116d729a0147 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -130,7 +130,8 @@ testCompareHelper(const void *data)
 static int
 testParseVMXFileName(const char *fileName,
                      void *opaque G_GNUC_UNUSED,
-                     char **src)
+                     char **src,
+                     bool allow_missing)
 {
     g_autofree char *copyOfFileName = NULL;
     char *tmp = NULL;
@@ -149,6 +150,16 @@ testParseVMXFileName(const char *fileName,
             return -1;
         }
 
+        if (STREQ(datastoreName, "missing") ||
+            STREQ(directoryAndFileName, "missing")) {
+            if (allow_missing)
+                return 0;
+
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "Missing file name '%s'", fileName);
+            return -1;
+        }
+
         *src = g_strdup_printf("[%s] %s", datastoreName, directoryAndFileName);
     } else if (STRPREFIX(fileName, "/")) {
         /* Found absolute path referencing a file outside a datastore */
-- 
2.29.2




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

  Powered by Linux