maint: use consistent if-else braces in conf and friends

I'm about to add a syntax check that enforces our documented
HACKING style of always using matching {} on if-else statements.

This patch focuses on code shared between multiple drivers.

* src/conf/domain_conf.c (virDomainFSDefParseXML)
(virSysinfoParseXML, virDomainNetDefParseXML)
(virDomainWatchdogDefParseXML)
(virDomainRedirFilterUSBDevDefParseXML): Correct use of {}.
* src/conf/interface_conf.c (virInterfaceDefParseDhcp)
(virInterfaceDefParseIp, virInterfaceVlanDefFormat)
(virInterfaceDefParseStartMode, virInterfaceDefParseBondMode)
(virInterfaceDefParseBondMiiCarrier)
(virInterfaceDefParseBondArpValid): Likewise.
* src/conf/node_device_conf.c (virNodeDevCapStorageParseXML):
Likewise.
* src/conf/nwfilter_conf.c (virNWFilterRuleDetailsParse)
(virNWFilterRuleParse, virNWFilterDefParseXML): Likewise.
* src/conf/secret_conf.c (secretXMLParseNode): Likewise.
* src/cpu/cpu_x86.c (x86Baseline, x86FeatureLoad, x86ModelLoad):
Likewise.
* src/network/bridge_driver.c (networkKillDaemon)
(networkDnsmasqConfContents): Likewise.
* src/node_device/node_device_hal.c (dev_refresh): Likewise.
* src/nwfilter/nwfilter_gentech_driver.c (virNWFilterInstantiate):
Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(_iptablesCreateRuleInstance): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2014-09-03 11:29:38 -06:00
parent 3020594ac5
commit ff78ff7c93
11 changed files with 92 additions and 79 deletions

View File

@ -6579,15 +6579,15 @@ virDomainFSDefParseXML(xmlNodePtr node,
xmlStrEqual(cur->name, BAD_CAST "source")) {
if (def->type == VIR_DOMAIN_FS_TYPE_MOUNT ||
def->type == VIR_DOMAIN_FS_TYPE_BIND)
def->type == VIR_DOMAIN_FS_TYPE_BIND) {
source = virXMLPropString(cur, "dir");
else if (def->type == VIR_DOMAIN_FS_TYPE_FILE)
} else if (def->type == VIR_DOMAIN_FS_TYPE_FILE) {
source = virXMLPropString(cur, "file");
else if (def->type == VIR_DOMAIN_FS_TYPE_BLOCK)
} else if (def->type == VIR_DOMAIN_FS_TYPE_BLOCK) {
source = virXMLPropString(cur, "dev");
else if (def->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
} else if (def->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) {
source = virXMLPropString(cur, "name");
else if (def->type == VIR_DOMAIN_FS_TYPE_RAM) {
} else if (def->type == VIR_DOMAIN_FS_TYPE_RAM) {
usage = virXMLPropString(cur, "usage");
units = virXMLPropString(cur, "units");
}
@ -7129,11 +7129,11 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
def->data.vhostuser->data.nix.path = vhostuser_path;
vhostuser_path = NULL;
if (STREQ(vhostuser_mode, "server"))
if (STREQ(vhostuser_mode, "server")) {
def->data.vhostuser->data.nix.listen = true;
else if (STREQ(vhostuser_mode, "client"))
} else if (STREQ(vhostuser_mode, "client")) {
def->data.vhostuser->data.nix.listen = false;
else {
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Wrong <source> 'mode' attribute "
"specified with <interface "
@ -9315,9 +9315,9 @@ virDomainWatchdogDefParseXML(xmlNodePtr node,
}
action = virXMLPropString(node, "action");
if (action == NULL)
if (action == NULL) {
def->action = VIR_DOMAIN_WATCHDOG_ACTION_RESET;
else {
} else {
def->action = virDomainWatchdogActionTypeFromString(action);
if (def->action < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -9612,9 +9612,9 @@ virSysinfoParseXML(xmlNodePtr node,
"%s", _("malformed <sysinfo> uuid element"));
goto error;
}
if (uuid_generated)
if (uuid_generated) {
memcpy(domUUID, uuidbuf, VIR_UUID_BUFLEN);
else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
} else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
virReportError(VIR_ERR_XML_DETAIL, "%s",
_("UUID mismatch between <uuid> and "
"<sysinfo>"));
@ -10148,11 +10148,11 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
allow = virXMLPropString(node, "allow");
if (allow) {
if (STREQ(allow, "yes"))
if (STREQ(allow, "yes")) {
def->allow = true;
else if (STREQ(allow, "no"))
} else if (STREQ(allow, "no")) {
def->allow = false;
else {
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Invalid allow value, either 'yes' or 'no'"));
goto error;

View File

@ -154,15 +154,15 @@ virInterfaceDefParseStartMode(virInterfaceDefPtr def,
char *tmp;
tmp = virXPathString("string(./start/@mode)", ctxt);
if (tmp == NULL)
if (tmp == NULL) {
def->startmode = VIR_INTERFACE_START_UNSPECIFIED;
else if (STREQ(tmp, "onboot"))
} else if (STREQ(tmp, "onboot")) {
def->startmode = VIR_INTERFACE_START_ONBOOT;
else if (STREQ(tmp, "hotplug"))
} else if (STREQ(tmp, "hotplug")) {
def->startmode = VIR_INTERFACE_START_HOTPLUG;
else if (STREQ(tmp, "none"))
} else if (STREQ(tmp, "none")) {
def->startmode = VIR_INTERFACE_START_NONE;
else {
} else {
virReportError(VIR_ERR_XML_ERROR,
_("unknown interface startmode %s"), tmp);
VIR_FREE(tmp);
@ -181,21 +181,21 @@ virInterfaceDefParseBondMode(xmlXPathContextPtr ctxt)
tmp = virXPathString("string(./@mode)", ctxt);
if (tmp == NULL)
return VIR_INTERFACE_BOND_NONE;
if (STREQ(tmp, "balance-rr"))
if (STREQ(tmp, "balance-rr")) {
ret = VIR_INTERFACE_BOND_BALRR;
else if (STREQ(tmp, "active-backup"))
} else if (STREQ(tmp, "active-backup")) {
ret = VIR_INTERFACE_BOND_ABACKUP;
else if (STREQ(tmp, "balance-xor"))
} else if (STREQ(tmp, "balance-xor")) {
ret = VIR_INTERFACE_BOND_BALXOR;
else if (STREQ(tmp, "broadcast"))
} else if (STREQ(tmp, "broadcast")) {
ret = VIR_INTERFACE_BOND_BCAST;
else if (STREQ(tmp, "802.3ad"))
} else if (STREQ(tmp, "802.3ad")) {
ret = VIR_INTERFACE_BOND_8023AD;
else if (STREQ(tmp, "balance-tlb"))
} else if (STREQ(tmp, "balance-tlb")) {
ret = VIR_INTERFACE_BOND_BALTLB;
else if (STREQ(tmp, "balance-alb"))
} else if (STREQ(tmp, "balance-alb")) {
ret = VIR_INTERFACE_BOND_BALALB;
else {
} else {
virReportError(VIR_ERR_XML_ERROR,
_("unknown bonding mode %s"), tmp);
ret = -1;
@ -213,11 +213,11 @@ virInterfaceDefParseBondMiiCarrier(xmlXPathContextPtr ctxt)
tmp = virXPathString("string(./miimon/@carrier)", ctxt);
if (tmp == NULL)
return VIR_INTERFACE_BOND_MII_NONE;
if (STREQ(tmp, "ioctl"))
if (STREQ(tmp, "ioctl")) {
ret = VIR_INTERFACE_BOND_MII_IOCTL;
else if (STREQ(tmp, "netif"))
} else if (STREQ(tmp, "netif")) {
ret = VIR_INTERFACE_BOND_MII_NETIF;
else {
} else {
virReportError(VIR_ERR_XML_ERROR,
_("unknown mii bonding carrier %s"), tmp);
ret = -1;
@ -235,13 +235,13 @@ virInterfaceDefParseBondArpValid(xmlXPathContextPtr ctxt)
tmp = virXPathString("string(./arpmon/@validate)", ctxt);
if (tmp == NULL)
return VIR_INTERFACE_BOND_ARP_NONE;
if (STREQ(tmp, "active"))
if (STREQ(tmp, "active")) {
ret = VIR_INTERFACE_BOND_ARP_ACTIVE;
else if (STREQ(tmp, "backup"))
} else if (STREQ(tmp, "backup")) {
ret = VIR_INTERFACE_BOND_ARP_BACKUP;
else if (STREQ(tmp, "all"))
} else if (STREQ(tmp, "all")) {
ret = VIR_INTERFACE_BOND_ARP_ALL;
else {
} else {
virReportError(VIR_ERR_XML_ERROR,
_("unknown arp bonding validate %s"), tmp);
ret = -1;
@ -264,18 +264,19 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
/* Not much to do in the current version */
tmp = virXPathString("string(./@peerdns)", ctxt);
if (tmp) {
if (STREQ(tmp, "yes"))
if (STREQ(tmp, "yes")) {
def->peerdns = 1;
else if (STREQ(tmp, "no"))
} else if (STREQ(tmp, "no")) {
def->peerdns = 0;
else {
} else {
virReportError(VIR_ERR_XML_ERROR,
_("unknown dhcp peerdns value %s"), tmp);
ret = -1;
}
VIR_FREE(tmp);
} else
} else {
def->peerdns = -1;
}
ctxt->node = save;
return ret;
@ -293,9 +294,9 @@ virInterfaceDefParseIp(virInterfaceIpDefPtr def,
def->address = tmp;
if (tmp != NULL) {
ret = virXPathLong("string(./@prefix)", ctxt, &l);
if (ret == 0)
if (ret == 0) {
def->prefix = (int) l;
else if (ret == -2) {
} else if (ret == -2) {
virReportError(VIR_ERR_XML_ERROR,
"%s", _("Invalid ip address prefix value"));
return -1;
@ -961,8 +962,9 @@ virInterfaceVlanDefFormat(virBufferPtr buf, const virInterfaceDef *def)
def->data.vlan.devname);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</vlan>\n");
} else
} else {
virBufferAddLit(buf, "/>\n");
}
return 0;
}

View File

@ -683,9 +683,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
goto out;
}
if (STREQ(type, "hotpluggable"))
if (STREQ(type, "hotpluggable")) {
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE;
else if (STREQ(type, "removable")) {
} else if (STREQ(type, "removable")) {
xmlNodePtr orignode2;
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE;

View File

@ -1858,10 +1858,12 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
item->u.u8 = uint_val;
found = true;
data.ui = uint_val;
} else
} else {
rc = -1;
} else
}
} else {
rc = -1;
}
break;
case DATATYPE_UINT16_HEX:
@ -1873,10 +1875,12 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
item->u.u16 = uint_val;
found = true;
data.ui = uint_val;
} else
} else {
rc = -1;
} else
}
} else {
rc = -1;
}
break;
case DATATYPE_UINT32_HEX:
@ -1887,8 +1891,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
item->u.u32 = uint_val;
found = true;
data.ui = uint_val;
} else
} else {
rc = -1;
}
break;
case DATATYPE_IPADDR:
@ -1904,8 +1909,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
item->u.u8 = (uint8_t)uint_val;
found = true;
data.ui = uint_val;
} else
} else {
rc = -1;
}
} else {
if (virSocketAddrParseIPv4(&ipaddr, prop) < 0) {
rc = -1;
@ -1951,8 +1957,9 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
item->u.u8 = (uint8_t)uint_val;
found = true;
data.ui = uint_val;
} else
} else {
rc = -1;
}
} else {
if (virSocketAddrParseIPv6(&ipaddr, prop) < 0) {
rc = -1;
@ -2457,8 +2464,9 @@ virNWFilterRuleParse(xmlNodePtr node)
i++;
if (!virAttr[i].id)
break;
} else
} else {
break;
}
}
}
@ -2667,8 +2675,9 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
virNWFilterEntryFree(entry);
goto cleanup;
}
} else
} else {
virNWFilterEntryFree(entry);
}
}
curr = curr->next;
}

View File

@ -159,11 +159,11 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
prop = virXPathString("string(./@ephemeral)", ctxt);
if (prop != NULL) {
if (STREQ(prop, "yes"))
if (STREQ(prop, "yes")) {
def->ephemeral = true;
else if (STREQ(prop, "no"))
} else if (STREQ(prop, "no")) {
def->ephemeral = false;
else {
} else {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'ephemeral'"));
goto cleanup;
@ -173,11 +173,11 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
prop = virXPathString("string(./@private)", ctxt);
if (prop != NULL) {
if (STREQ(prop, "yes"))
if (STREQ(prop, "yes")) {
def->private = true;
else if (STREQ(prop, "no"))
} else if (STREQ(prop, "no")) {
def->private = false;
else {
} else {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'private'"));
goto cleanup;

View File

@ -1,7 +1,7 @@
/*
* cpu_x86.c: CPU driver for CPUs with x86 compatible CPUID instruction
*
* Copyright (C) 2009-2011, 2013 Red Hat, Inc.
* Copyright (C) 2009-2014 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -710,9 +710,9 @@ x86FeatureLoad(xmlXPathContextPtr ctxt,
goto error;
}
if (map->features == NULL)
if (map->features == NULL) {
map->features = feature;
else {
} else {
feature->next = map->features;
map->features = feature;
}
@ -1048,9 +1048,9 @@ x86ModelLoad(xmlXPathContextPtr ctxt,
goto error;
}
if (map->models == NULL)
if (map->models == NULL) {
map->models = model;
else {
} else {
model->next = map->models;
map->models = model;
}
@ -1882,9 +1882,9 @@ x86Baseline(virCPUDefPtr *cpus,
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->match = VIR_CPU_MATCH_EXACT;
if (!cpus[0]->vendor)
if (!cpus[0]->vendor) {
outputVendor = false;
else if (!(vendor = x86VendorFind(map, cpus[0]->vendor))) {
} else if (!(vendor = x86VendorFind(map, cpus[0]->vendor))) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("Unknown CPU vendor %s"), cpus[0]->vendor);
goto error;
@ -1914,9 +1914,9 @@ x86Baseline(virCPUDefPtr *cpus,
goto error;
}
if (cpus[i]->vendor)
if (cpus[i]->vendor) {
vn = cpus[i]->vendor;
else {
} else {
outputVendor = false;
if (model->vendor)
vn = model->vendor->name;

View File

@ -782,9 +782,9 @@ networkKillDaemon(pid_t pid, const char *daemonName, const char *networkName)
*/
for (i = 0; i < 25; i++) {
int signum = 0;
if (i == 0)
if (i == 0) {
signum = SIGTERM;
else if (i == 15) {
} else if (i == 15) {
signum = SIGKILL;
signame = "KILL";
}
@ -1221,9 +1221,9 @@ networkDnsmasqConfContents(virNetworkObjPtr network,
/* Are we doing RA instead of radvd? */
if (DNSMASQ_RA_SUPPORT(caps)) {
if (ipv6def)
if (ipv6def) {
virBufferAddLit(&configbuf, "enable-ra\n");
else {
} else {
for (i = 0;
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_INET6, i));
i++) {

View File

@ -546,8 +546,9 @@ dev_refresh(const char *udi)
* to sub-capabilities (like net.80203) is nasty ... so avoid it.
*/
virNodeDeviceObjRemove(&driverState->devs, dev);
} else
} else {
VIR_DEBUG("no device named %s", name);
}
nodeDeviceUnlock(driverState);
if (dev) {

View File

@ -1509,9 +1509,9 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
return 0;
}
if (rule->action == VIR_NWFILTER_RULE_ACTION_ACCEPT)
if (rule->action == VIR_NWFILTER_RULE_ACTION_ACCEPT) {
target = accept_target;
else {
} else {
target = virNWFilterJumpTargetTypeToString(rule->action);
skipMatch = defMatch;
}

View File

@ -1,7 +1,7 @@
/*
* nwfilter_gentech_driver.c: generic technology driver
*
* Copyright (C) 2011, 2013 Red Hat, Inc.
* Copyright (C) 2011-2014 Red Hat, Inc.
* Copyright (C) 2010 IBM Corp.
* Copyright (C) 2010 Stefan Berger
*
@ -699,8 +699,9 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED,
filter->name, learning);
goto err_exit;
}
} else
} else {
goto err_unresolvable_vars;
}
} else if (virHashSize(missing_vars->hashTable) > 1) {
goto err_unresolvable_vars;
} else if (!forceWithPendingReq &&

View File

@ -414,9 +414,9 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
goto error;
}
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE)
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
ok_to_mklabel = true;
else {
} else {
int check;
check = virStorageBackendDiskFindLabel(