lib: Almost eliminate use of virTristateBoolTypeFromString()

There are couple of places where virTristateBoolTypeFromString()
is called. Well, the same result can be achieved by
virXMLPropTristateBool() and on fewer lines.

Note there are couple of places left untouched because those
don't care about error reporting and thus are shorter they way
they are now.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2022-01-20 13:58:49 +01:00
parent 9086ae4fac
commit 0fe2d8dd33
13 changed files with 153 additions and 310 deletions

View File

@ -328,7 +328,6 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
g_autofree char *cpuMode = NULL;
g_autofree char *fallback = NULL;
g_autofree char *vendor_id = NULL;
g_autofree char *tscScaling = NULL;
g_autofree virHostCPUTscInfo *tsc = NULL;
*cpu = NULL;
@ -427,6 +426,8 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
if (def->type == VIR_CPU_TYPE_HOST) {
g_autofree char *arch = virXPathString("string(./arch[1])", ctxt);
xmlNodePtr counter_node = NULL;
if (!arch) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing CPU architecture"));
@ -446,7 +447,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
return -1;
}
if (virXPathBoolean("boolean(./counter[@name='tsc'])", ctxt) > 0) {
if ((counter_node = virXPathNode("./counter[@name='tsc'])", ctxt))) {
tsc = g_new0(virHostCPUTscInfo, 1);
if (virXPathULongLong("string(./counter[@name='tsc']/@frequency)",
@ -456,17 +457,10 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
return -1;
}
tscScaling = virXPathString("string(./counter[@name='tsc']/@scaling)",
ctxt);
if (tscScaling) {
int scaling = virTristateBoolTypeFromString(tscScaling);
if (scaling < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid TSC scaling attribute"));
return -1;
}
tsc->scaling = scaling;
}
if (virXMLPropTristateBool(counter_node, "scaling",
VIR_XML_PROP_NONE,
&tsc->scaling) < 0)
return -1;
def->tsc = g_steal_pointer(&tsc);
}

View File

@ -6912,23 +6912,16 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node,
virDomainHostdevDef *def,
unsigned int flags)
{
g_autofree char *filtering = NULL;
xmlNodePtr address = NULL;
xmlNodePtr origstates = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
ctxt->node = node;
if ((filtering = virXMLPropString(node, "writeFiltering"))) {
int val;
if ((val = virTristateBoolTypeFromString(filtering)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown pci writeFiltering setting '%s'"),
filtering);
return -1;
}
def->writeFiltering = val;
}
if (virXMLPropTristateBool(node, "writeFiltering",
VIR_XML_PROP_NONE,
&def->writeFiltering) < 0)
return -1;
if ((address = virXPathNode("./address", ctxt)) &&
virPCIDeviceAddressParseXML(address, &def->source.subsys.u.pci.addr) < 0)
@ -7305,22 +7298,22 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
virDomainHostdevSubsysSCSI *scsisrc = &def->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHost *scsihostsrc = &def->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev;
g_autofree char *managed = NULL;
virTristateBool managed;
g_autofree char *sgio = NULL;
g_autofree char *rawio = NULL;
g_autofree char *backendStr = NULL;
g_autofree char *model = NULL;
int rv;
/* @managed can be read from the xml document - it is always an
* attribute of the toplevel element, no matter what type of
* element that might be (pure hostdev, or higher level device
* (e.g. <interface>) with type='hostdev')
*/
if ((managed = virXMLPropString(node, "managed")) != NULL)
ignore_value(virStringParseYesNo(managed, &def->managed));
ignore_value(virXMLPropTristateBool(node, "managed",
VIR_XML_PROP_NONE, &managed));
virTristateBoolToBool(managed, &def->managed);
sgio = virXMLPropString(node, "sgio");
rawio = virXMLPropString(node, "rawio");
model = virXMLPropString(node, "model");
/* @type is passed in from the caller rather than read from the
@ -7373,19 +7366,15 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
}
}
if (rawio) {
if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("rawio is only supported for scsi host device"));
return -1;
}
if ((scsisrc->rawio = virTristateBoolTypeFromString(rawio)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown hostdev rawio setting '%s'"),
rawio);
return -1;
}
if ((rv = virXMLPropTristateBool(node, "rawio",
VIR_XML_PROP_NONE,
&scsisrc->rawio)) < 0) {
return -1;
} else if (rv > 0 &&
def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("rawio is only supported for scsi host device"));
return -1;
}
if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
@ -10259,6 +10248,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
xmlNodePtr vlan_node = NULL;
xmlNodePtr bandwidth_node = NULL;
xmlNodePtr tmpNode;
xmlNodePtr mac_node = NULL;
g_autoptr(GHashTable) filterparams = NULL;
virDomainActualNetDef *actual = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
@ -10266,7 +10256,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
int rv, val;
g_autofree char *macaddr = NULL;
g_autofree char *macaddr_type = NULL;
g_autofree char *macaddr_check = NULL;
g_autofree char *network = NULL;
g_autofree char *portgroup = NULL;
g_autofree char *portid = NULL;
@ -10467,7 +10456,9 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
if ((vhost = virXPathString("string(./backend/@vhost)", ctxt)))
vhost_path = virFileSanitizePath(vhost);
if ((macaddr = virXPathString("string(./mac/@address)", ctxt))) {
mac_node = virXPathNode("./mac", ctxt);
if ((macaddr = virXMLPropString(mac_node, "address"))) {
if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unable to parse mac address '%s'"),
@ -10498,17 +10489,10 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt,
def->mac_type = tmp;
}
if ((macaddr_check = virXPathString("string(./mac/@check)", ctxt))) {
int tmpCheck;
if ((tmpCheck = virTristateBoolTypeFromString(macaddr_check)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid mac address check value: '%s'"),
macaddr_check);
goto error;
}
def->mac_check = tmpCheck;
}
if (virXMLPropTristateBool(mac_node, "check",
VIR_XML_PROP_NONE,
&def->mac_check) < 0)
goto error;
if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info,
flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
@ -14165,40 +14149,21 @@ static virDomainVideoAccelDef *
virDomainVideoAccelDefParseXML(xmlNodePtr node)
{
g_autofree virDomainVideoAccelDef *def = NULL;
int val;
g_autofree char *accel2d = NULL;
g_autofree char *accel3d = NULL;
g_autofree char *rendernode = NULL;
accel3d = virXMLPropString(node, "accel3d");
accel2d = virXMLPropString(node, "accel2d");
rendernode = virXMLPropString(node, "rendernode");
if (!accel3d && !accel2d && !rendernode) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("missing values for acceleration"));
return NULL;
}
def = g_new0(virDomainVideoAccelDef, 1);
if (accel3d) {
if ((val = virTristateBoolTypeFromString(accel3d)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown accel3d value '%s'"), accel3d);
return NULL;
}
def->accel3d = val;
}
if (virXMLPropTristateBool(node, "accel3d",
VIR_XML_PROP_NONE,
&def->accel3d) < 0)
return NULL;
if (accel2d) {
if ((val = virTristateBoolTypeFromString(accel2d)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown accel2d value '%s'"), accel2d);
return NULL;
}
def->accel2d = val;
}
if (virXMLPropTristateBool(node, "accel2d",
VIR_XML_PROP_NONE,
&def->accel2d) < 0)
return NULL;
if (rendernode)
def->rendernode = virFileSanitizePath(rendernode);
@ -14633,20 +14598,13 @@ virDomainEventActionParseXML(xmlXPathContextPtr ctxt,
static int
virDomainPMStateParseXML(xmlXPathContextPtr ctxt,
const char *xpath,
int *val)
virTristateBool *val)
{
g_autofree char *tmp = virXPathString(xpath, ctxt);
xmlNodePtr node = virXPathNode(xpath, ctxt);
if (tmp) {
*val = virTristateBoolTypeFromString(tmp);
if (*val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown PM state value %s"), tmp);
return -1;
}
}
return 0;
return virXMLPropTristateBool(node, "enabled",
VIR_XML_PROP_NONE,
val);
}
@ -16972,19 +16930,10 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
}
if ((node = virXPathNode("./os/bootmenu[1]", ctxt))) {
tmp = virXMLPropString(node, "enable");
if (tmp) {
def->os.bootmenu = virTristateBoolTypeFromString(tmp);
if (def->os.bootmenu <= 0) {
/* In order not to break misconfigured machines, this
* should not emit an error, but rather set the bootmenu
* to disabled */
VIR_WARN("disabling bootmenu due to unknown option '%s'",
tmp);
def->os.bootmenu = VIR_TRISTATE_BOOL_NO;
}
VIR_FREE(tmp);
}
if (virXMLPropTristateBool(node, "enable",
VIR_XML_PROP_NONE,
&def->os.bootmenu) < 0)
return -1;
tmp = virXMLPropString(node, "timeout");
if (tmp && def->os.bootmenu == VIR_TRISTATE_BOOL_YES) {
@ -18388,26 +18337,21 @@ virDomainDefParseBootFirmwareOptions(virDomainDef *def,
features = g_new0(int, VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_LAST);
for (i = 0; i < n; i++) {
g_autofree char *name = virXMLPropString(nodes[i], "name");
g_autofree char *enabled = virXMLPropString(nodes[i], "enabled");
int feature = virDomainOsDefFirmwareFeatureTypeFromString(name);
int val = virTristateBoolTypeFromString(enabled);
unsigned int feature;
virTristateBool enabled;
if (feature < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid firmware feature name '%s'"),
name);
if (virXMLPropEnum(nodes[i], "name",
virDomainOsDefFirmwareFeatureTypeFromString,
VIR_XML_PROP_REQUIRED,
&feature) < 0)
return -1;
}
if (val < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid firmware feature enabled value '%s'"),
enabled);
if (virXMLPropTristateBool(nodes[i], "enabled",
VIR_XML_PROP_REQUIRED,
&enabled) < 0)
return -1;
}
features[feature] = val;
features[feature] = enabled;
}
def->os.firmwareFeatures = g_steal_pointer(&features);
@ -19523,12 +19467,12 @@ virDomainDefLifecycleParse(virDomainDef *def,
return -1;
if (virDomainPMStateParseXML(ctxt,
"string(./pm/suspend-to-mem/@enabled)",
"./pm/suspend-to-mem",
&def->pm.s3) < 0)
return -1;
if (virDomainPMStateParseXML(ctxt,
"string(./pm/suspend-to-disk/@enabled)",
"./pm/suspend-to-disk",
&def->pm.s4) < 0)
return -1;
@ -30565,6 +30509,7 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDef *iface,
break;
case VIR_TRISTATE_BOOL_ABSENT:
case VIR_TRISTATE_BOOL_NO:
case VIR_TRISTATE_BOOL_LAST:
actual->data.hostdev.def.managed = false;
break;
}

View File

@ -263,7 +263,7 @@ struct _virDomainHostdevSubsysSCSIiSCSI {
struct _virDomainHostdevSubsysSCSI {
int protocol; /* enum virDomainHostdevSCSIProtocolType */
int sgio; /* enum virDomainDeviceSGIO */
int rawio; /* enum virTristateBool */
virTristateBool rawio;
union {
virDomainHostdevSubsysSCSIHost host;
virDomainHostdevSubsysSCSIiSCSI iscsi;
@ -1706,8 +1706,8 @@ typedef enum {
VIR_ENUM_DECL(virDomainVideoVGAConf);
struct _virDomainVideoAccelDef {
int accel2d; /* enum virTristateBool */
int accel3d; /* enum virTristateBool */
virTristateBool accel2d;
virTristateBool accel3d;
char *rendernode;
};
@ -2325,7 +2325,7 @@ struct _virDomainOSDef {
char *machine;
size_t nBootDevs;
int bootDevs[VIR_DOMAIN_BOOT_LAST];
int bootmenu; /* enum virTristateBool */
virTristateBool bootmenu;
unsigned int bm_timeout;
bool bm_timeout_set;
char *init;
@ -2688,9 +2688,8 @@ struct _virDomainMemtune {
};
struct _virDomainPowerManagement {
/* These options are of type enum virTristateBool */
int s3;
int s4;
virTristateBool s3;
virTristateBool s4;
};
struct _virDomainPerfDef {

View File

@ -928,37 +928,21 @@ virNetworkDNSDefParseXML(const char *networkName,
g_autofree xmlNodePtr *srvNodes = NULL;
g_autofree xmlNodePtr *txtNodes = NULL;
g_autofree xmlNodePtr *fwdNodes = NULL;
g_autofree char *forwardPlainNames = NULL;
g_autofree char *enable = NULL;
int nhosts, nsrvs, ntxts, nfwds;
size_t i;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
ctxt->node = node;
enable = virXPathString("string(./@enable)", ctxt);
if (enable) {
def->enable = virTristateBoolTypeFromString(enable);
if (def->enable <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid dns enable setting '%s' "
"in network '%s'"),
enable, networkName);
return -1;
}
}
if (virXMLPropTristateBool(node, "enable",
VIR_XML_PROP_NONE,
&def->enable) < 0)
return -1;
forwardPlainNames = virXPathString("string(./@forwardPlainNames)", ctxt);
if (forwardPlainNames) {
def->forwardPlainNames = virTristateBoolTypeFromString(forwardPlainNames);
if (def->forwardPlainNames <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid dns forwardPlainNames setting '%s' "
"in network '%s'"),
forwardPlainNames, networkName);
return -1;
}
}
if (virXMLPropTristateBool(node, "forwardPlainNames",
VIR_XML_PROP_NONE,
&def->forwardPlainNames) < 0)
return -1;
nfwds = virXPathNodeSet("./forwarder", ctxt, &fwdNodes);
if (nfwds < 0) {
@ -1076,7 +1060,6 @@ virNetworkIPDefParseXML(const char *networkName,
xmlNodePtr dhcp;
g_autofree char *address = NULL;
g_autofree char *netmask = NULL;
g_autofree char *localPtr = NULL;
unsigned long prefix = 0;
int prefixRc;
int ret = -1;
@ -1121,16 +1104,10 @@ virNetworkIPDefParseXML(const char *networkName,
else
def->prefix = prefix;
localPtr = virXPathString("string(./@localPtr)", ctxt);
if (localPtr) {
def->localPTR = virTristateBoolTypeFromString(localPtr);
if (def->localPTR <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid localPtr value '%s' in network '%s'"),
localPtr, networkName);
goto cleanup;
}
}
if (virXMLPropTristateBool(node, "localPtr",
VIR_XML_PROP_NONE,
&def->localPTR) < 0)
goto cleanup;
/* validate address, etc. for each family */
if ((def->family == NULL) || (STREQ(def->family, "ipv4"))) {
@ -1217,19 +1194,11 @@ int
virNetworkPortOptionsParseXML(xmlXPathContextPtr ctxt,
virTristateBool *isolatedPort)
{
g_autofree char *str = NULL;
int tmp = VIR_TRISTATE_BOOL_ABSENT;
xmlNodePtr port_node = virXPathNode("./port", ctxt);
if ((str = virXPathString("string(./port/@isolated)", ctxt))) {
if ((tmp = virTristateBoolTypeFromString(str)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown port isolated value '%s'"), str);
return -1;
}
}
*isolatedPort = tmp;
return 0;
return virXMLPropTristateBool(port_node, "isolated",
VIR_XML_PROP_NONE,
isolatedPort);
}
@ -1248,7 +1217,6 @@ virNetworkPortGroupParseXML(virPortGroupDef *def,
xmlNodePtr vlanNode;
xmlNodePtr bandwidth_node;
g_autofree char *isDefault = NULL;
g_autofree char *trustGuestRxFilters = NULL;
int ret = -1;
@ -1265,17 +1233,10 @@ virNetworkPortGroupParseXML(virPortGroupDef *def,
isDefault = virXPathString("string(./@default)", ctxt);
def->isDefault = isDefault && STRCASEEQ(isDefault, "yes");
trustGuestRxFilters
= virXPathString("string(./@trustGuestRxFilters)", ctxt);
if (trustGuestRxFilters) {
if ((def->trustGuestRxFilters
= virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid trustGuestRxFilters setting '%s' "
"in portgroup"), trustGuestRxFilters);
goto cleanup;
}
}
if (virXMLPropTristateBool(node, "trustGuestRxFilters",
VIR_XML_PROP_NONE,
&def->trustGuestRxFilters) < 0)
goto cleanup;
virtPortNode = virXPathNode("./virtualport", ctxt);
if (virtPortNode &&
@ -1662,7 +1623,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
{
g_autoptr(virNetworkDef) def = NULL;
g_autofree char *uuid = NULL;
g_autofree char *localOnly = NULL;
g_autofree char *stp = NULL;
g_autofree char *stpDelay = NULL;
g_autofree char *macTableManager = NULL;
@ -1676,11 +1636,11 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr virtPortNode = NULL;
xmlNodePtr forwardNode = NULL;
g_autofree char *ipv6nogwStr = NULL;
g_autofree char *trustGuestRxFilters = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
xmlNodePtr bandwidthNode = NULL;
xmlNodePtr vlanNode;
xmlNodePtr metadataNode = NULL;
xmlNodePtr domain_node = NULL;
def = g_new0(virNetworkDef, 1);
@ -1724,32 +1684,18 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
}
}
trustGuestRxFilters
= virXPathString("string(./@trustGuestRxFilters)", ctxt);
if (trustGuestRxFilters) {
if ((def->trustGuestRxFilters
= virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid trustGuestRxFilters setting '%s' "
"in network '%s'"),
trustGuestRxFilters, def->name);
return NULL;
}
}
if (virXMLPropTristateBool(ctxt->node, "trustGuestRxFilters",
VIR_XML_PROP_NONE,
&def->trustGuestRxFilters) < 0)
return NULL;
/* Parse network domain information */
def->domain = virXPathString("string(./domain[1]/@name)", ctxt);
localOnly = virXPathString("string(./domain[1]/@localOnly)", ctxt);
if (localOnly) {
def->domainLocalOnly = virTristateBoolTypeFromString(localOnly);
if (def->domainLocalOnly <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid domain localOnly setting '%s' "
"in network '%s'"),
localOnly, def->name);
return NULL;
}
}
domain_node = virXPathNode("./domain[1]", ctxt);
def->domain = virXMLPropString(domain_node, "name");
if (virXMLPropTristateBool(domain_node, "localOnly",
VIR_XML_PROP_NONE,
&def->domainLocalOnly) < 0)
return NULL;
if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) &&
virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, false) < 0)

View File

@ -158,8 +158,8 @@ struct _virNetworkDNSForwarder {
typedef struct _virNetworkDNSDef virNetworkDNSDef;
struct _virNetworkDNSDef {
int enable; /* enum virTristateBool */
int forwardPlainNames; /* enum virTristateBool */
virTristateBool enable;
virTristateBool forwardPlainNames;
size_t ntxts;
virNetworkDNSTxtDef *txts;
size_t nhosts;
@ -184,7 +184,7 @@ struct _virNetworkIPDef {
unsigned int prefix; /* ipv6 - only prefix allowed */
virSocketAddr netmask; /* ipv4 - either netmask or prefix specified */
int localPTR; /* virTristateBool */
virTristateBool localPTR;
size_t nranges; /* Zero or more dhcp ranges */
virNetworkDHCPRangeDef *ranges;
@ -243,7 +243,7 @@ struct _virPortGroupDef {
virNetDevVPortProfile *virtPortProfile;
virNetDevBandwidth *bandwidth;
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool trustGuestRxFilters;
};
typedef struct _virNetworkDef virNetworkDef;
@ -257,7 +257,7 @@ struct _virNetworkDef {
char *bridgeZone; /* name of firewalld zone for bridge */
int macTableManager; /* enum virNetworkBridgeMACTableManager */
char *domain;
int domainLocalOnly; /* enum virTristateBool: yes disables dns forwarding */
virTristateBool domainLocalOnly; /* yes disables dns forwarding */
unsigned long delay; /* Bridge forward delay (ms) */
bool stp; /* Spanning tree protocol */
unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in config */
@ -284,7 +284,7 @@ struct _virNetworkDef {
virPortGroupDef *portGroups;
virNetDevBandwidth *bandwidth;
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool trustGuestRxFilters;
virTristateBool isolatedPort;
/* Application-specific custom metadata */

View File

@ -804,22 +804,21 @@ static int
virStoragePoolDefParseFeatures(virStoragePoolDef *def,
xmlXPathContextPtr ctxt)
{
g_autofree char *cow = virXPathString("string(./features/cow/@state)", ctxt);
xmlNodePtr node = virXPathNode("./features/cow", ctxt);
virTristateBool val;
int rv;
if (cow) {
int val;
if ((rv = virXMLPropTristateBool(node, "state",
VIR_XML_PROP_NONE,
&val)) < 0) {
return -1;
} else if (rv > 0) {
if (def->type != VIR_STORAGE_POOL_FS &&
def->type != VIR_STORAGE_POOL_DIR) {
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("cow feature may only be used for 'fs' and 'dir' pools"));
return -1;
}
if ((val = virTristateBoolTypeFromString(cow)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid storage pool cow feature state '%s'"),
cow);
return -1;
}
def->features.cow = val;
}

View File

@ -322,24 +322,16 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt)
{
virStoragePRDef *prd;
virStoragePRDef *ret = NULL;
g_autofree char *managed = NULL;
g_autofree char *type = NULL;
g_autofree char *path = NULL;
g_autofree char *mode = NULL;
prd = g_new0(virStoragePRDef, 1);
if (!(managed = virXPathString("string(./@managed)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing @managed attribute for <reservations/>"));
if (virXMLPropTristateBool(ctxt->node, "managed",
VIR_XML_PROP_REQUIRED,
&prd->managed) < 0)
goto cleanup;
}
if ((prd->managed = virTristateBoolTypeFromString(managed)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid value for 'managed': %s"), managed);
goto cleanup;
}
type = virXPathString("string(./source[1]/@type)", ctxt);
path = virXPathString("string(./source[1]/@path)", ctxt);

View File

@ -226,7 +226,7 @@ struct _virStorageAuthDef {
typedef struct _virStoragePRDef virStoragePRDef;
struct _virStoragePRDef {
int managed; /* enum virTristateBool */
virTristateBool managed;
char *path;
/* manager object alias */

View File

@ -87,12 +87,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
xmlNodePtr vlanNode;
xmlNodePtr bandwidthNode;
xmlNodePtr addressNode;
g_autofree char *trustGuestRxFilters = NULL;
xmlNodePtr rxfiltersNode = NULL;
xmlNodePtr plugNode = NULL;
g_autofree char *mac = NULL;
g_autofree char *macmgr = NULL;
g_autofree char *mode = NULL;
g_autofree char *plugtype = NULL;
g_autofree char *managed = NULL;
g_autofree char *driver = NULL;
def = g_new0(virNetworkPortDef, 1);
@ -169,18 +169,13 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
return NULL;
trustGuestRxFilters
= virXPathString("string(./rxfilters/@trustGuest)", ctxt);
if (trustGuestRxFilters) {
if ((def->trustGuestRxFilters
= virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid guest rx filters trust setting '%s' "),
trustGuestRxFilters);
return NULL;
}
}
rxfiltersNode = virXPathNode("./rxfilters", ctxt);
if (virXMLPropTristateBool(rxfiltersNode, "trustGuest",
VIR_XML_PROP_NONE,
&def->trustGuestRxFilters) < 0)
return NULL;
plugNode = virXPathNode("./plug", ctxt);
plugtype = virXPathString("string(./plug/@type)", ctxt);
if (plugtype &&
@ -228,14 +223,10 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
break;
case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI:
managed = virXPathString("string(./plug/@managed)", ctxt);
if (managed &&
(def->plug.hostdevpci.managed =
virTristateBoolTypeFromString(managed)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid managed setting '%s' in network port"), mode);
if (virXMLPropTristateBool(plugNode, "managed",
VIR_XML_PROP_NONE,
&def->plug.hostdevpci.managed) < 0)
return NULL;
}
driver = virXPathString("string(./plug/driver/@name)", ctxt);
if (driver &&
(def->plug.hostdevpci.driver =

View File

@ -55,7 +55,7 @@ struct _virNetworkPortDef {
virNetDevBandwidth *bandwidth;
unsigned int class_id; /* class ID for bandwidth 'floor' */
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
virTristateBool trustGuestRxFilters;
virTristateBool isolatedPort;
int plugtype; /* virNetworkPortPlugType */
@ -71,7 +71,7 @@ struct _virNetworkPortDef {
struct {
virPCIDeviceAddress addr; /* PCI Address of device */
int driver; /* virNetworkForwardDriverNameType */
int managed;
virTristateBool managed;
} hostdevpci;
} plug;
};

View File

@ -1603,8 +1603,8 @@ x86ModelParseFeatures(virCPUx86Model *model,
for (i = 0; i < n; i++) {
g_autofree char *ftname = NULL;
g_autofree char *removed = NULL;
virCPUx86Feature *feature;
virTristateBool rem;
if (!(ftname = virXMLPropString(nodes[i], "name"))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@ -1620,21 +1620,14 @@ x86ModelParseFeatures(virCPUx86Model *model,
return -1;
}
if ((removed = virXMLPropString(nodes[i], "removed"))) {
int rem;
if (virXMLPropTristateBool(nodes[i], "removed",
VIR_XML_PROP_NONE,
&rem) < 0)
return -1;
if ((rem = virTristateBoolTypeFromString(removed)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid 'removed' attribute for feature %s "
"in model %s"),
ftname, model->name);
return -1;
}
if (rem == VIR_TRISTATE_BOOL_YES) {
model->removedFeatures[nremoved++] = g_strdup(ftname);
continue;
}
if (rem == VIR_TRISTATE_BOOL_YES) {
model->removedFeatures[nremoved++] = g_strdup(ftname);
continue;
}
if (x86DataAdd(&model->data, &feature->data))

View File

@ -3758,7 +3758,6 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
xmlXPathContextPtr ctxt,
const char *typeStr)
{
g_autofree char *migratability = NULL;
xmlNodePtr hostCPUNode;
g_autofree xmlNodePtr *nodes = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
@ -3766,6 +3765,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
g_autofree char *xpath = g_strdup_printf("./hostCPU[@type='%s']", typeStr);
size_t i;
int n;
virTristateBool migratability;
int val;
if (!(hostCPUNode = virXPathNode(xpath, ctxt))) {
@ -3781,13 +3781,12 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
return -1;
}
if (!(migratability = virXMLPropString(hostCPUNode, "migratability")) ||
(val = virTristateBoolTypeFromString(migratability)) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid migratability value for host CPU model"));
if (virXMLPropTristateBool(hostCPUNode, "migratability",
VIR_XML_PROP_REQUIRED,
&migratability) < 0)
return -1;
}
hostCPU->migratability = val == VIR_TRISTATE_BOOL_YES;
virTristateBoolToBool(migratability, &hostCPU->migratability);
ctxt->node = hostCPUNode;
@ -3798,7 +3797,6 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
for (i = 0; i < n; i++) {
qemuMonitorCPUProperty *prop = hostCPU->props + i;
g_autofree char *type = NULL;
g_autofree char *migratable = NULL;
ctxt->node = nodes[i];
@ -3850,17 +3848,11 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
break;
}
if ((migratable = virXMLPropString(ctxt->node, "migratable"))) {
if ((val = virTristateBoolTypeFromString(migratable)) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown migratable value for '%s' host "
"CPU model property"),
prop->name);
return -1;
}
if (virXMLPropTristateBool(ctxt->node, "migratable",
VIR_XML_PROP_NONE,
&prop->migratable) < 0)
return -1;
prop->migratable = val;
}
}
}

View File

@ -2829,19 +2829,11 @@ int
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
virTristateBool *allowReboot)
{
int val;
g_autofree char *valStr = NULL;
xmlNodePtr node = virXPathNode("./allowReboot", ctxt);
if ((valStr = virXPathString("string(./allowReboot/@value)", ctxt))) {
if ((val = virTristateBoolTypeFromString(valStr)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid allowReboot value '%s'"), valStr);
return -1;
}
*allowReboot = val;
}
return 0;
return virXMLPropTristateBool(node, "value",
VIR_XML_PROP_NONE,
allowReboot);
}