esx: Fix floppy.fileName handling in the vmx file parser

The vmx file parsing code was reporting errors when parsing floppy.fileName
entries if the filename didn't end in .flp. There is no such restriction in
ESX; even using the GUI to configure floppy filenames you can specify any
arbitrary file with any extension.

Fix by changing the vmx parsing code so that it uses the floppy.fileType
value to determine whether floppy.fileName refers to a block device or a
regular file.

Also remove code that would have generated an error if no floppy.fileName
was specified. This is not an error either.

Updated the floppy tests in vmx2xmltest.c and xml2vmxtest.c.
This commit is contained in:
Geoff Hickey 2013-10-14 18:14:33 -04:00 committed by Daniel P. Berrange
parent 8f35fd21cc
commit 842f6fd338
5 changed files with 19 additions and 25 deletions

View File

@ -2250,27 +2250,14 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
goto cleanup; goto cleanup;
} }
} else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { } else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (virFileHasSuffix(fileName, ".flp")) { if (fileType != NULL && STRCASEEQ(fileType, "device")) {
if (fileType != NULL) {
if (STRCASENEQ(fileType, "file")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be 'file' but "
"found '%s'"), fileType_name, fileType);
goto cleanup;
}
}
(*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
(*def)->src = ctx->parseFileName(fileName, ctx->opaque);
if ((*def)->src == NULL) {
goto cleanup;
}
} else if (fileType != NULL && STRCASEEQ(fileType, "device")) {
(*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK; (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
(*def)->src = fileName; (*def)->src = fileName;
fileName = NULL; fileName = NULL;
} else if (fileType != NULL && STRCASEEQ(fileType, "file")) {
(*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
(*def)->src = ctx->parseFileName(fileName, ctx->opaque);
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid or not yet handled value '%s' " _("Invalid or not yet handled value '%s' "
@ -3538,13 +3525,6 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,
virBufferAsprintf(buffer, "floppy%d.fileType = \"file\"\n", unit); virBufferAsprintf(buffer, "floppy%d.fileType = \"file\"\n", unit);
if (def->src != NULL) { if (def->src != NULL) {
if (! virFileHasSuffix(def->src, ".flp")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Image file for floppy '%s' has unsupported "
"suffix, expecting '.flp'"), def->dst);
return -1;
}
fileName = ctx->formatFileName(def->src, ctx->opaque); fileName = ctx->formatFileName(def->src, ctx->opaque);
if (fileName == NULL) { if (fileName == NULL) {

View File

@ -3,3 +3,6 @@ virtualHW.version = "4"
floppy0.present = "true" floppy0.present = "true"
floppy0.fileType = "file" floppy0.fileType = "file"
floppy0.fileName = "floppy.flp" floppy0.fileName = "floppy.flp"
floppy1.present = "true"
floppy1.fileType = "file"
floppy1.fileName = "floppy"

View File

@ -16,6 +16,11 @@
<target dev='fda' bus='fdc'/> <target dev='fda' bus='fdc'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk> </disk>
<disk type='file' device='floppy'>
<source file='[datastore] directory/floppy'/>
<target dev='fdb' bus='fdc'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<controller type='fdc' index='0'/> <controller type='fdc' index='0'/>
<video> <video>
<model type='vmvga' vram='4096'/> <model type='vmvga' vram='4096'/>

View File

@ -9,4 +9,6 @@ numvcpus = "1"
floppy0.present = "true" floppy0.present = "true"
floppy0.fileType = "file" floppy0.fileType = "file"
floppy0.fileName = "/vmfs/volumes/testing/floppy.flp" floppy0.fileName = "/vmfs/volumes/testing/floppy.flp"
floppy1.present = "false" floppy1.present = "true"
floppy1.fileType = "file"
floppy1.fileName = "/vmfs/volumes/testing/floppy1"

View File

@ -10,5 +10,9 @@
<source file='[testing] floppy.flp'/> <source file='[testing] floppy.flp'/>
<target dev='fda' bus='fdc'/> <target dev='fda' bus='fdc'/>
</disk> </disk>
<disk type='file' device='floppy'>
<source file='[testing] floppy1'/>
<target dev='fdb' bus='fdc'/>
</disk>
</devices> </devices>
</domain> </domain>