From 6c30bd386f7039cf6f8828f4b8fa0865395828e1 Mon Sep 17 00:00:00 2001
Message-Id: <6c30bd386f7039cf6f8828f4b8fa0865395828e1@dist-git>
From: Pino Toscano <ptoscano@redhat.com>
Date: Mon, 23 Mar 2020 08:49:57 +0100
Subject: [PATCH] vmx: shortcut earlier few 'ignore' cases in virVMXParseDisk()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Move earlier the checks for skipping a hard disk when parsing a CD-DROM,
and for skipping a CD-ROM when parsing a hard disk. This should have no
behaviour changes, and avoids to add repeated checks in following
commits.
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 9a469c0d358bf3fd4b4e55b20360620d6fda44b5)
https://bugzilla.redhat.com/show_bug.cgi?id=1815269
https://bugzilla.redhat.com/show_bug.cgi?id=1816035
https://bugzilla.redhat.com/show_bug.cgi?id=1816034
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Message-Id: <20200323074958.377314-2-ptoscano@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/vmx/vmx.c | 48 ++++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 937bf0c96b..89409870ff 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2215,7 +2215,21 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
/* Setup virDomainDiskDef */
if (device == VIR_DOMAIN_DISK_DEVICE_DISK) {
- if (virFileHasSuffix(fileName, ".vmdk")) {
+ if (virFileHasSuffix(fileName, ".iso") ||
+ STREQ(fileName, "emptyBackingString") ||
+ (deviceType &&
+ (STRCASEEQ(deviceType, "atapi-cdrom") ||
+ STRCASEEQ(deviceType, "cdrom-raw") ||
+ (STRCASEEQ(deviceType, "scsi-passthru") &&
+ STRPREFIX(fileName, "/vmfs/devices/cdrom/"))))) {
+ /*
+ * This function was called in order to parse a harddisk device,
+ * but .iso files, 'atapi-cdrom', 'cdrom-raw', and 'scsi-passthru'
+ * CDROM devices are for CDROM devices only. Just ignore it, another
+ * call to this function to parse a CDROM device may handle it.
+ */
+ goto ignore;
+ } else if (virFileHasSuffix(fileName, ".vmdk")) {
char *tmp;
if (deviceType != NULL) {
@@ -2251,20 +2265,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
if (mode)
(*def)->transient = STRCASEEQ(mode,
"independent-nonpersistent");
- } else if (virFileHasSuffix(fileName, ".iso") ||
- STREQ(fileName, "emptyBackingString") ||
- (deviceType &&
- (STRCASEEQ(deviceType, "atapi-cdrom") ||
- STRCASEEQ(deviceType, "cdrom-raw") ||
- (STRCASEEQ(deviceType, "scsi-passthru") &&
- STRPREFIX(fileName, "/vmfs/devices/cdrom/"))))) {
- /*
- * This function was called in order to parse a harddisk device,
- * but .iso files, 'atapi-cdrom', 'cdrom-raw', and 'scsi-passthru'
- * CDROM devices are for CDROM devices only. Just ignore it, another
- * call to this function to parse a CDROM device may handle it.
- */
- goto ignore;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' "
@@ -2274,7 +2274,15 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
goto cleanup;
}
} else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
- if (virFileHasSuffix(fileName, ".iso")) {
+ if (virFileHasSuffix(fileName, ".vmdk")) {
+ /*
+ * This function was called in order to parse a CDROM device, but
+ * .vmdk files are for harddisk devices only. Just ignore it,
+ * another call to this function to parse a harddisk device may
+ * handle it.
+ */
+ goto ignore;
+ } else if (virFileHasSuffix(fileName, ".iso")) {
char *tmp;
if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) {
@@ -2292,14 +2300,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
goto cleanup;
}
VIR_FREE(tmp);
- } else if (virFileHasSuffix(fileName, ".vmdk")) {
- /*
- * This function was called in order to parse a CDROM device, but
- * .vmdk files are for harddisk devices only. Just ignore it,
- * another call to this function to parse a harddisk device may
- * handle it.
- */
- goto ignore;
} else if (deviceType && STRCASEEQ(deviceType, "atapi-cdrom")) {
virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK);
--
2.26.0