This will be used later.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/esx/esx_driver.c | 3 ++-
src/vmware/vmware_conf.c | 3 ++-
src/vmware/vmware_conf.h | 3 ++-
src/vmx/vmx.c | 12 +++++++-----
src/vmx/vmx.h | 5 ++++-
tests/vmx2xmltest.c | 13 ++++++++++++-
6 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 86d5396147a3..dde51688f72f 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 G_GNUC_UNUSED)
{
esxVMX_Data *data = opaque;
esxVI_String *propertyNameList = NULL;
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 4f7dc3001d2b..55cd1d6f2d36 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -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);
diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h
index 6f86983f511f..4974260e68f6 100644
--- a/src/vmware/vmware_conf.h
+++ b/src/vmware/vmware_conf.h
@@ -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,
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 97591842f789..aa5d1d4eedea 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, 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,
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 7db2edb12c27..3a11dfb41ce8 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -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 */
--
2.30.0