conf: disk: Simplify checking if source definition was parsed

Previously we had to check for 3 fields to see if the source was filled.
Repurpose one of the variables as a boolean flag and use it instead of
combining multiple sources.

For the condition that checks that only CDROM/FLOPPY drives can be empty
we can use the virStorageSourceIsEmpty() helper.
This commit is contained in:
Peter Krempa 2015-03-12 17:33:09 +01:00
parent 158340e2fb
commit 7a8f54bf4c

View File

@ -5908,7 +5908,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
char *sgio = NULL; char *sgio = NULL;
char *driverName = NULL; char *driverName = NULL;
char *driverType = NULL; char *driverType = NULL;
const char *source = NULL; bool source = false;
char *target = NULL; char *target = NULL;
char *trans = NULL; char *trans = NULL;
char *bus = NULL; char *bus = NULL;
@ -5972,13 +5972,13 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
cur = node->children; cur = node->children;
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) { if (cur->type == XML_ELEMENT_NODE) {
if (!source && !def->src->hosts && !def->src->srcpool && if (!source && xmlStrEqual(cur->name, BAD_CAST "source")) {
xmlStrEqual(cur->name, BAD_CAST "source")) {
sourceNode = cur; sourceNode = cur;
if (virDomainDiskSourceParse(cur, ctxt, def->src) < 0) if (virDomainDiskSourceParse(cur, ctxt, def->src) < 0)
goto error; goto error;
source = def->src->path;
source = true;
if (def->src->type == VIR_STORAGE_TYPE_NETWORK) { if (def->src->type == VIR_STORAGE_TYPE_NETWORK) {
if (def->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) if (def->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI)
@ -6405,7 +6405,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
/* Only CDROM and Floppy devices are allowed missing source path /* Only CDROM and Floppy devices are allowed missing source path
* to indicate no media present. LUN is for raw access CD-ROMs * to indicate no media present. LUN is for raw access CD-ROMs
* that are not attached to a physical device presently */ * that are not attached to a physical device presently */
if (source == NULL && def->src->hosts == NULL && !def->src->srcpool && if (virStorageSourceIsEmpty(def->src) &&
(def->device == VIR_DOMAIN_DISK_DEVICE_DISK || (def->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE))) { (flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE))) {
virReportError(VIR_ERR_NO_SOURCE, virReportError(VIR_ERR_NO_SOURCE,
@ -6437,7 +6437,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
virReportError(VIR_ERR_NO_TARGET, "%s", tmp); virReportError(VIR_ERR_NO_TARGET, "%s", tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
} else { } else {
virReportError(VIR_ERR_NO_TARGET, source ? "%s" : NULL, source); virReportError(VIR_ERR_NO_TARGET, def->src->path ? "%s" : NULL, def->src->path);
} }
goto error; goto error;
} }