mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
domain_conf: move vendor, product and tray checks to domain_validate.c
The 'tray' check isn't a XML parse specific code and can be pushed to the validate callback, in virDomainDiskDefValidate(). 'vendor' and 'product' string sizes are already checked by the domaincommon.rng schema, but can be of use in the validate callback since not all scenarios will go through the XML parsing. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
654e106397
commit
98bc393579
@ -10227,9 +10227,6 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr ctxt,
|
||||
}
|
||||
|
||||
|
||||
#define VENDOR_LEN 8
|
||||
#define PRODUCT_LEN 16
|
||||
|
||||
static virDomainDiskDefPtr
|
||||
virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
xmlNodePtr node,
|
||||
@ -10404,12 +10401,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (!(vendor = virXMLNodeContentString(cur)))
|
||||
return NULL;
|
||||
|
||||
if (strlen(vendor) > VENDOR_LEN) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("disk vendor is more than 8 characters"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!virStringIsPrintable(vendor)) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("disk vendor is not printable string"));
|
||||
@ -10420,12 +10411,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
if (!(product = virXMLNodeContentString(cur)))
|
||||
return NULL;
|
||||
|
||||
if (strlen(product) > PRODUCT_LEN) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("disk product is more than 16 characters"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!virStringIsPrintable(product)) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("disk product is not printable string"));
|
||||
@ -10556,13 +10541,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
|
||||
_("unknown disk tray status '%s'"), tray);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
|
||||
def->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("tray is only valid for cdrom and floppy"));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (removable) {
|
||||
|
@ -225,6 +225,9 @@ virSecurityDeviceLabelDefValidateXML(virSecurityDeviceLabelDefPtr *seclabels,
|
||||
}
|
||||
|
||||
|
||||
#define VENDOR_LEN 8
|
||||
#define PRODUCT_LEN 16
|
||||
|
||||
int
|
||||
virDomainDiskDefValidate(const virDomainDef *def,
|
||||
const virDomainDiskDef *disk)
|
||||
@ -301,5 +304,27 @@ virDomainDiskDefValidate(const virDomainDef *def,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (disk->tray_status &&
|
||||
disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
|
||||
disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("tray is only valid for cdrom and floppy"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (disk->vendor && strlen(disk->vendor) > VENDOR_LEN) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("disk vendor is more than %d characters"),
|
||||
VENDOR_LEN);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (disk->product && strlen(disk->product) > PRODUCT_LEN) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("disk product is more than %d characters"),
|
||||
PRODUCT_LEN);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user