mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
domain_conf: move all ChrSource checks to domain_validate.c
Next patch will move a validation to virDomainSmartcardDefValidate(), but this function can't be moved alone to domain_validate.c without making virDomainChrSourceDefValidate(), from domain_conf.c, public. Given that the idea is to eventually move all validations to domain_validate.c anyways, let's move all ChrSource related validations in a single punch. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
b9e56a0fa0
commit
4abfb330ea
@ -6058,137 +6058,6 @@ virDomainDefHasUSB(const virDomainDef *def)
|
||||
}
|
||||
|
||||
|
||||
#define SERIAL_CHANNEL_NAME_CHARS \
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."
|
||||
|
||||
|
||||
static int
|
||||
virDomainChrSourceDefValidate(const virDomainChrSourceDef *src_def,
|
||||
const virDomainChrDef *chr_def,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
switch ((virDomainChrType) src_def->type) {
|
||||
case VIR_DOMAIN_CHR_TYPE_NULL:
|
||||
case VIR_DOMAIN_CHR_TYPE_PTY:
|
||||
case VIR_DOMAIN_CHR_TYPE_VC:
|
||||
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
||||
case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
|
||||
case VIR_DOMAIN_CHR_TYPE_LAST:
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_FILE:
|
||||
case VIR_DOMAIN_CHR_TYPE_DEV:
|
||||
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
||||
if (!src_def->data.file.path) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source path attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_NMDM:
|
||||
if (!src_def->data.nmdm.master) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing master path attribute for nmdm device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!src_def->data.nmdm.slave) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing slave path attribute for nmdm device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||
if (!src_def->data.tcp.host) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source host attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!src_def->data.tcp.service) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source service attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src_def->data.tcp.listen && src_def->data.tcp.reconnect.enabled) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("chardev reconnect is possible only for connect mode"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||
if (!src_def->data.udp.connectService) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source service attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||
/* The source path can be auto generated for certain specific
|
||||
* types of channels, but in most cases we should report an
|
||||
* error if the user didn't provide it */
|
||||
if (!src_def->data.nix.path &&
|
||||
!(chr_def &&
|
||||
chr_def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
|
||||
(chr_def->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN ||
|
||||
chr_def->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source path attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src_def->data.nix.listen && src_def->data.nix.reconnect.enabled) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("chardev reconnect is possible only for connect mode"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
|
||||
if (!src_def->data.spiceport.channel) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("Missing source channel attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
if (strspn(src_def->data.spiceport.channel,
|
||||
SERIAL_CHANNEL_NAME_CHARS) < strlen(src_def->data.spiceport.channel)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("Invalid character in source channel for char device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (virSecurityDeviceLabelDefValidate(src_def->seclabels,
|
||||
src_def->nseclabels,
|
||||
def->seclabels,
|
||||
def->nseclabels) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainRedirdevDefValidate(const virDomainDef *def,
|
||||
const virDomainRedirdevDef *redirdev)
|
||||
{
|
||||
if (redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB &&
|
||||
!virDomainDefHasUSB(def)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("cannot add redirected USB device: "
|
||||
"USB is disabled for this domain"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return virDomainChrSourceDefValidate(redirdev->source, NULL, def);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainNetDefValidatePortOptions(const char *macstr,
|
||||
@ -6379,36 +6248,6 @@ virDomainControllerDefValidate(const virDomainControllerDef *controller)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainChrDefValidate(const virDomainChrDef *chr,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
return virDomainChrSourceDefValidate(chr->source, chr, def);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainSmartcardDefValidate(const virDomainSmartcardDef *smartcard,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
if (smartcard->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH)
|
||||
return virDomainChrSourceDefValidate(smartcard->data.passthru, NULL, def);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainRNGDefValidate(const virDomainRNGDef *rng,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD)
|
||||
return virDomainChrSourceDefValidate(rng->source.chardev, NULL, def);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev)
|
||||
{
|
||||
|
@ -328,3 +328,164 @@ virDomainDiskDefValidate(const virDomainDef *def,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#define SERIAL_CHANNEL_NAME_CHARS \
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."
|
||||
|
||||
static int
|
||||
virDomainChrSourceDefValidate(const virDomainChrSourceDef *src_def,
|
||||
const virDomainChrDef *chr_def,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
switch ((virDomainChrType) src_def->type) {
|
||||
case VIR_DOMAIN_CHR_TYPE_NULL:
|
||||
case VIR_DOMAIN_CHR_TYPE_PTY:
|
||||
case VIR_DOMAIN_CHR_TYPE_VC:
|
||||
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
||||
case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
|
||||
case VIR_DOMAIN_CHR_TYPE_LAST:
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_FILE:
|
||||
case VIR_DOMAIN_CHR_TYPE_DEV:
|
||||
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
||||
if (!src_def->data.file.path) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source path attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_NMDM:
|
||||
if (!src_def->data.nmdm.master) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing master path attribute for nmdm device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!src_def->data.nmdm.slave) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing slave path attribute for nmdm device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||
if (!src_def->data.tcp.host) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source host attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!src_def->data.tcp.service) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source service attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src_def->data.tcp.listen && src_def->data.tcp.reconnect.enabled) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("chardev reconnect is possible only for connect mode"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||
if (!src_def->data.udp.connectService) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source service attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||
/* The source path can be auto generated for certain specific
|
||||
* types of channels, but in most cases we should report an
|
||||
* error if the user didn't provide it */
|
||||
if (!src_def->data.nix.path &&
|
||||
!(chr_def &&
|
||||
chr_def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
|
||||
(chr_def->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN ||
|
||||
chr_def->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Missing source path attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src_def->data.nix.listen && src_def->data.nix.reconnect.enabled) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("chardev reconnect is possible only for connect mode"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
|
||||
if (!src_def->data.spiceport.channel) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("Missing source channel attribute for char device"));
|
||||
return -1;
|
||||
}
|
||||
if (strspn(src_def->data.spiceport.channel,
|
||||
SERIAL_CHANNEL_NAME_CHARS) < strlen(src_def->data.spiceport.channel)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("Invalid character in source channel for char device"));
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (virSecurityDeviceLabelDefValidate(src_def->seclabels,
|
||||
src_def->nseclabels,
|
||||
def->seclabels,
|
||||
def->nseclabels) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainRedirdevDefValidate(const virDomainDef *def,
|
||||
const virDomainRedirdevDef *redirdev)
|
||||
{
|
||||
if (redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB &&
|
||||
!virDomainDefHasUSB(def)) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("cannot add redirected USB device: "
|
||||
"USB is disabled for this domain"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return virDomainChrSourceDefValidate(redirdev->source, NULL, def);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainChrDefValidate(const virDomainChrDef *chr,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
return virDomainChrSourceDefValidate(chr->source, chr, def);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainRNGDefValidate(const virDomainRNGDef *rng,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
if (rng->backend == VIR_DOMAIN_RNG_BACKEND_EGD)
|
||||
return virDomainChrSourceDefValidate(rng->source.chardev, NULL, def);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainSmartcardDefValidate(const virDomainSmartcardDef *smartcard,
|
||||
const virDomainDef *def)
|
||||
{
|
||||
if (smartcard->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH)
|
||||
return virDomainChrSourceDefValidate(smartcard->data.passthru, NULL, def);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -34,3 +34,11 @@ int virSecurityDeviceLabelDefValidate(virSecurityDeviceLabelDefPtr *seclabels,
|
||||
size_t nvmSeclabels);
|
||||
int virDomainDiskDefValidate(const virDomainDef *def,
|
||||
const virDomainDiskDef *disk);
|
||||
int virDomainRedirdevDefValidate(const virDomainDef *def,
|
||||
const virDomainRedirdevDef *redirdev);
|
||||
int virDomainChrDefValidate(const virDomainChrDef *chr,
|
||||
const virDomainDef *def);
|
||||
int virDomainRNGDefValidate(const virDomainRNGDef *rng,
|
||||
const virDomainDef *def);
|
||||
int virDomainSmartcardDefValidate(const virDomainSmartcardDef *smartcard,
|
||||
const virDomainDef *def);
|
||||
|
Loading…
x
Reference in New Issue
Block a user