From: Peter Krempa Date: Fri, 2 Dec 2022 13:46:42 +0000 (+0100) Subject: virDomainDeviceDefParse: Separate code for parsing type X-Git-Tag: v9.1.0-rc1~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9cfc3876ef01180c9b66ac61d5e816b728ba421;p=thirdparty%2Flibvirt.git virDomainDeviceDefParse: Separate code for parsing type Move the code into a new function named virDomainDeviceDefParseType. The separation will make it easier to change the type of the 'type' field in side of virDomainDeviceDef. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b21efeacf9..c980eb8556 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13729,6 +13729,32 @@ virDomainCryptoDefParseXML(virDomainXMLOption *xmlopt, } +static int +virDomainDeviceDefParseType(const char *typestr, + int *type) +{ + int tmp; + + /* Mapping of serial, parallel, console and channel to VIR_DOMAIN_DEVICE_CHR. */ + if (STREQ(typestr, "channel") || + STREQ(typestr, "console") || + STREQ(typestr, "parallel") || + STREQ(typestr, "serial")) { + *type = VIR_DOMAIN_DEVICE_CHR; + return 0; + } + + if ((tmp = virDomainDeviceTypeFromString(typestr)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown device type '%s'"), typestr); + return -1; + } + + *type = tmp; + return 0; +} + + virDomainDeviceDef * virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, @@ -13748,21 +13774,8 @@ virDomainDeviceDefParse(const char *xmlStr, dev = g_new0(virDomainDeviceDef, 1); - if ((dev->type = virDomainDeviceTypeFromString((const char *) node->name)) < 0) { - /* Some crazy mapping of serial, parallel, console and channel to - * VIR_DOMAIN_DEVICE_CHR. */ - if (virXMLNodeNameEqual(node, "channel") || - virXMLNodeNameEqual(node, "console") || - virXMLNodeNameEqual(node, "parallel") || - virXMLNodeNameEqual(node, "serial")) { - dev->type = VIR_DOMAIN_DEVICE_CHR; - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown device type '%s'"), - node->name); - return NULL; - } - } + if (virDomainDeviceDefParseType((const char *)node->name, &dev->type) < 0) + return NULL; switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: