conf: domain: Move checks from virDomainDiskDefParseXML to virDomainDiskDefValidate

Move the rest of the validations to the vaidation code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-04-15 17:27:01 +02:00
parent 73fbf346dc
commit 61fd7174c2
2 changed files with 44 additions and 44 deletions

View File

@ -9440,8 +9440,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
if (!(wwn = virXMLNodeContentString(cur)))
return NULL;
if (!virValidateWWN(wwn))
return NULL;
} else if (!vendor &&
virXMLNodeNameEqual(cur, "vendor")) {
if (!(vendor = virXMLNodeContentString(cur)))
@ -9462,48 +9460,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
}
}
/* Only CDROM and Floppy devices are allowed missing source path
* to indicate no media present. LUN is for raw access CD-ROMs
* that are not attached to a physical device presently */
if (virStorageSourceIsEmpty(def->src) &&
def->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
virReportError(VIR_ERR_NO_SOURCE,
target ? "%s" : NULL, target);
return NULL;
}
if (!target) {
if (def->src->srcpool) {
tmp = g_strdup_printf("pool = '%s', volume = '%s'",
def->src->srcpool->pool, def->src->srcpool->volume);
virReportError(VIR_ERR_NO_TARGET, "%s", tmp);
VIR_FREE(tmp);
} else {
virReportError(VIR_ERR_NO_TARGET, def->src->path ? "%s" : NULL, def->src->path);
}
return NULL;
}
if (def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
!STRPREFIX(target, "fd")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid floppy device name: %s"), target);
return NULL;
}
if ((def->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
def->device == VIR_DOMAIN_DISK_DEVICE_LUN) &&
!STRPREFIX((const char *)target, "hd") &&
!STRPREFIX((const char *)target, "sd") &&
!STRPREFIX((const char *)target, "vd") &&
!STRPREFIX((const char *)target, "xvd") &&
!STRPREFIX((const char *)target, "ubd")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid harddisk device name: %s"), target);
return NULL;
}
if (snapshot) {
def->snapshot = virDomainSnapshotLocationTypeFromString(snapshot);
if (def->snapshot <= 0) {

View File

@ -699,6 +699,50 @@ virDomainDiskDefValidate(const virDomainDef *def,
}
}
if (disk->wwn && !virValidateWWN(disk->wwn))
return -1;
if (!disk->dst) {
if (disk->src->srcpool) {
virReportError(VIR_ERR_NO_TARGET, _("pool = '%s', volume = '%s'"),
disk->src->srcpool->pool,
disk->src->srcpool->volume);
} else {
virReportError(VIR_ERR_NO_TARGET,
disk->src->path ? "%s" : NULL, disk->src->path);
}
return -1;
}
if ((disk->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) &&
!STRPREFIX(disk->dst, "hd") &&
!STRPREFIX(disk->dst, "sd") &&
!STRPREFIX(disk->dst, "vd") &&
!STRPREFIX(disk->dst, "xvd") &&
!STRPREFIX(disk->dst, "ubd")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid harddisk device name: %s"), disk->dst);
return -1;
}
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
!STRPREFIX(disk->dst, "fd")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid floppy device name: %s"), disk->dst);
return -1;
}
/* Only CDROM and Floppy devices are allowed missing source path to
* indicate no media present. LUN is for raw access CD-ROMs that are not
* attached to a physical device presently */
if (virStorageSourceIsEmpty(disk->src) &&
disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
virReportError(VIR_ERR_NO_SOURCE, "%s", disk->dst);
return -1;
}
return 0;
}