]> xenbits.xensource.com Git - libvirt.git/commitdiff
vmx: Allow missing cdrom image file in virVMXParseFileName
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 21 Dec 2020 15:51:31 +0000 (16:51 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 6 Jan 2021 01:05:10 +0000 (02:05 +0100)
This will be used later.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/esx/esx_driver.c
src/vmware/vmware_conf.c
src/vmware/vmware_conf.h
src/vmx/vmx.c
src/vmx/vmx.h
tests/vmx2xmltest.c

index 86d5396147a3afe87578e5e5e0a668684f0581ec..dde51688f72f1bf7363b48e9e8b6af6ad60bfb71 100644 (file)
@@ -128,7 +128,8 @@ esxFreePrivate(esxPrivate **priv)
 static int
 esxParseVMXFileName(const char *fileName,
                     void *opaque,
-                    char **out)
+                    char **out,
+                    bool allow_missing G_GNUC_UNUSED)
 {
     esxVMX_Data *data = opaque;
     esxVI_String *propertyNameList = NULL;
index 4f7dc3001d2b795cd5a53efd9a9265bca766b2ae..55cd1d6f2d36eec1cf6c1dafea9c91b62a2cb840 100644 (file)
@@ -510,7 +510,8 @@ vmwareExtractPid(const char * vmxPath)
 int
 vmwareParseVMXFileName(const char *datastorePath,
                        void *opaque G_GNUC_UNUSED,
-                       char **out)
+                       char **out,
+                       bool allow_missing G_GNUC_UNUSED)
 {
     *out = g_strdup(datastorePath);
 
index 6f86983f511f75246ab5b689718495677758dec5..4974260e68f6ad90c9cf17016e9af79e865d8e59 100644 (file)
@@ -86,7 +86,8 @@ int vmwareExtractPid(const char * vmxPath);
 int
 vmwareParseVMXFileName(const char *datastorePath,
                        void *opaque,
-                       char **out);
+                       char **out,
+                       bool allow_missing);
 
 char *
 vmwareFormatVMXFileName(const char *datastorePath,
index 97591842f789ff1dcc218c8df1629f022d0a7335..aa5d1d4eedea1949bc77fa7ff136888eafb279f5 100644 (file)
@@ -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, false) < 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,
index e5420c970a4b865a08a92cb308b68c22b8f18c3e..550c1264f3b83318ee42c4282d2f0971bfabc1f4 100644 (file)
@@ -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);
index 7db2edb12c270977fe2d4fa96e0eeb27aea973e0..3a11dfb41ce869e6d5315576e9a62ab9c0648f3f 100644 (file)
@@ -139,7 +139,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;
@@ -160,6 +161,16 @@ testParseVMXFileName(const char *fileName,
             return -1;
         }
 
+        if (STREQ(datastoreName, "missing") ||
+            STRPREFIX(directoryAndFileName, "missing")) {
+            if (allow_missing)
+                return 0;
+
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "Referenced missing file '%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 */