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 drivers that had several issues.
* src/lxc/lxc_fuse.c (lxcProcGetattr, lxcProcReadMeminfo): Correct
use of {}.
* src/lxc/lxc_driver.c (lxcDomainMergeBlkioDevice): Likewise.
* src/phyp/phyp_driver.c (phypConnectNumOfDomainsGeneric)
(phypUUIDTable_Init, openSSHSession, phypStoragePoolListVolumes)
(phypConnectListStoragePools, phypDomainSetVcpusFlags)
(phypStorageVolGetXMLDesc, phypStoragePoolGetXMLDesc)
(phypConnectListDefinedDomains): Likewise.
* src/vbox/vbox_common.c (vboxAttachSound, vboxDumpDisplay)
(vboxDomainRevertToSnapshot, vboxDomainSnapshotDelete): Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolGetXMLDesc): Likewise.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/lxc/lxc_driver.c | 24 ++++++++++++------------
src/lxc/lxc_fuse.c | 34 ++++++++++++++++++----------------
src/phyp/phyp_driver.c | 45 ++++++++++++++++++++++++++-------------------
src/vbox/vbox_common.c | 12 ++++++------
src/vbox/vbox_tmpl.c | 3 ++-
5 files changed, 64 insertions(+), 54 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 66d708a..f93360f 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2246,17 +2246,17 @@ lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
if (STREQ(src->path, dest->path)) {
found = true;
- if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT))
+ if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
dest->weight = src->weight;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
dest->riops = src->riops;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
dest->wiops = src->wiops;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
dest->rbps = src->rbps;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
dest->wbps = src->wbps;
- else {
+ } else {
virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter
%s"),
type);
return -1;
@@ -2272,17 +2272,17 @@ lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
return -1;
dest = &(*dest_array)[*dest_size - 1];
- if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT))
+ if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
dest->weight = src->weight;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS)) {
dest->riops = src->riops;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS)) {
dest->wiops = src->wiops;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_READ_BPS)) {
dest->rbps = src->rbps;
- else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS))
+ } else if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS)) {
dest->wbps = src->wbps;
- else {
+ } else {
*dest_size = *dest_size - 1;
return -1;
}
diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c
index a3a1275..5c18cff 100644
--- a/src/lxc/lxc_fuse.c
+++ b/src/lxc/lxc_fuse.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2012 Fujitsu Limited.
*
* lxc_fuse.c: fuse filesystem support for libvirt lxc
@@ -75,8 +76,9 @@ static int lxcProcGetattr(const char *path, struct stat *stbuf)
stbuf->st_atime = sb.st_atime;
stbuf->st_ctime = sb.st_ctime;
stbuf->st_mtime = sb.st_mtime;
- } else
+ } else {
res = -ENOENT;
+ }
cleanup:
VIR_FREE(mempath);
@@ -163,47 +165,47 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
*ptr = '\0';
if (STREQ(line, "MemTotal") &&
- (def->mem.hard_limit || def->mem.max_balloon))
+ (def->mem.hard_limit || def->mem.max_balloon)) {
virBufferAsprintf(new_meminfo, "MemTotal: %8llu kB\n",
meminfo.memtotal);
- else if (STREQ(line, "MemFree") &&
- (def->mem.hard_limit || def->mem.max_balloon))
+ } else if (STREQ(line, "MemFree") &&
+ (def->mem.hard_limit || def->mem.max_balloon)) {
virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n",
(meminfo.memtotal - meminfo.memusage));
- else if (STREQ(line, "Buffers"))
+ } else if (STREQ(line, "Buffers")) {
virBufferAsprintf(new_meminfo, "Buffers: %8d kB\n", 0);
- else if (STREQ(line, "Cached"))
+ } else if (STREQ(line, "Cached")) {
virBufferAsprintf(new_meminfo, "Cached: %8llu kB\n",
meminfo.cached);
- else if (STREQ(line, "Active"))
+ } else if (STREQ(line, "Active")) {
virBufferAsprintf(new_meminfo, "Active: %8llu kB\n",
(meminfo.active_anon + meminfo.active_file));
- else if (STREQ(line, "Inactive"))
+ } else if (STREQ(line, "Inactive")) {
virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n",
(meminfo.inactive_anon + meminfo.inactive_file));
- else if (STREQ(line, "Active(anon)"))
+ } else if (STREQ(line, "Active(anon)")) {
virBufferAsprintf(new_meminfo, "Active(anon): %8llu kB\n",
meminfo.active_anon);
- else if (STREQ(line, "Inactive(anon)"))
+ } else if (STREQ(line, "Inactive(anon)")) {
virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n",
meminfo.inactive_anon);
- else if (STREQ(line, "Active(file)"))
+ } else if (STREQ(line, "Active(file)")) {
virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n",
meminfo.active_file);
- else if (STREQ(line, "Inactive(file)"))
+ } else if (STREQ(line, "Inactive(file)")) {
virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n",
meminfo.inactive_file);
- else if (STREQ(line, "Unevictable"))
+ } else if (STREQ(line, "Unevictable")) {
virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n",
meminfo.unevictable);
- else if (STREQ(line, "SwapTotal") &&
def->mem.swap_hard_limit)
+ } else if (STREQ(line, "SwapTotal") &&
def->mem.swap_hard_limit) {
virBufferAsprintf(new_meminfo, "SwapTotal: %8llu kB\n",
(meminfo.swaptotal - meminfo.memtotal));
- else if (STREQ(line, "SwapFree") &&
def->mem.swap_hard_limit)
+ } else if (STREQ(line, "SwapFree") &&
def->mem.swap_hard_limit) {
virBufferAsprintf(new_meminfo, "SwapFree: %8llu kB\n",
(meminfo.swaptotal - meminfo.memtotal -
meminfo.swapusage + meminfo.memusage));
- else {
+ } else {
*ptr = ':';
virBufferAdd(new_meminfo, line, -1);
}
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index ea1981a..25f7f2d 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -336,16 +336,17 @@ phypConnectNumOfDomainsGeneric(virConnectPtr conn, unsigned int
type)
const char *state;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- if (type == 0)
+ if (type == 0) {
state = "|grep Running";
- else if (type == 1) {
+ } else if (type == 1) {
if (system_type == HMC) {
state = "|grep \"Not Activated\"";
} else {
state = "|grep \"Open Firmware\"";
}
- } else
+ } else {
state = " ";
+ }
virBufferAddLit(&buf, "lssyscfg -r lpar");
if (system_type == HMC)
@@ -787,8 +788,9 @@ phypUUIDTable_Init(virConnectPtr conn)
VIR_WARN("Unable to generate UUID for domain %d",
ids[i]);
}
- } else
+ } else {
goto cleanup;
+ }
if (phypUUIDTable_WriteFile(conn) == -1)
goto cleanup;
@@ -1019,8 +1021,9 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
virReportError(VIR_ERR_AUTH_FAILED,
"%s", _("Authentication failed"));
goto disconnect;
- } else
+ } else {
goto exit;
+ }
} else if (rc == LIBSSH2_ERROR_NONE) {
goto exit;
@@ -2204,9 +2207,9 @@ phypStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
goto cleanup;
}
- if (vol->name != NULL)
+ if (vol->name != NULL) {
voldef.name = vol->name;
- else {
+ } else {
VIR_ERROR(_("Unable to determine storage pool's name."));
goto cleanup;
}
@@ -2313,9 +2316,9 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const
volumes,
ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
/* I need to parse the textual return in order to get the volumes */
- if (exit_status < 0 || ret == NULL)
+ if (exit_status < 0 || ret == NULL) {
goto cleanup;
- else {
+ } else {
volumes_list = ret;
while (got < nvolumes) {
@@ -2327,8 +2330,9 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const
volumes,
goto cleanup;
char_ptr++;
volumes_list = char_ptr;
- } else
+ } else {
break;
+ }
}
}
@@ -2512,9 +2516,9 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools,
int npools)
ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
/* I need to parse the textual return in order to get the storage pools */
- if (exit_status < 0 || ret == NULL)
+ if (exit_status < 0 || ret == NULL) {
goto cleanup;
- else {
+ } else {
storage_pools = ret;
while (got < npools) {
@@ -2526,8 +2530,9 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools,
int npools)
goto cleanup;
char_ptr++;
storage_pools = char_ptr;
- } else
+ } else {
break;
+ }
}
}
@@ -2643,9 +2648,9 @@ phypStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int
flags)
virStoragePoolDef def;
memset(&def, 0, sizeof(virStoragePoolDef));
- if (pool->name != NULL)
+ if (pool->name != NULL) {
def.name = pool->name;
- else {
+ } else {
VIR_ERROR(_("Unable to determine storage pool's name."));
goto err;
}
@@ -3134,9 +3139,9 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const
names, int nnames
ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
/* I need to parse the textual return in order to get the domains */
- if (exit_status < 0 || ret == NULL)
+ if (exit_status < 0 || ret == NULL) {
goto cleanup;
- else {
+ } else {
domains = ret;
while (got < nnames) {
@@ -3148,8 +3153,9 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const
names, int nnames
goto cleanup;
char_ptr++;
domains = char_ptr;
- } else
+ } else {
break;
+ }
}
}
@@ -3617,8 +3623,9 @@ phypDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
} else if (ncpus < nvcpus) {
operation = 'a';
amount = nvcpus - ncpus;
- } else
+ } else {
return 0;
+ }
virBufferAddLit(&buf, "chhwres -r proc");
if (system_type == HMC)
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index b186ea8..eecfff6 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1291,8 +1291,7 @@ vboxAttachSound(virDomainDefPtr def, IMachine *machine)
if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_SB16) {
gVBoxAPI.UIAudioAdapter.SetAudioController(audioAdapter,
AudioControllerType_SB16);
- } else
- if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_AC97) {
+ } else if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_AC97) {
gVBoxAPI.UIAudioAdapter.SetAudioController(audioAdapter,
AudioControllerType_AC97);
}
@@ -3381,8 +3380,9 @@ vboxDumpDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine
*machine)
}
def->ngraphics++;
- } else
+ } else {
virReportOOMError();
+ }
}
VBOX_RELEASE(VRDxServer);
}
@@ -6510,8 +6510,9 @@ static int vboxDomainRevertToSnapshot(virDomainSnapshotPtr
snapshot,
ret = vboxDomainCreate(dom);
if (!ret)
gVBoxAPI.snapshotRestore(dom, machine, prevSnapshot);
- } else
+ } else {
ret = 0;
+ }
cleanup:
VBOX_RELEASE(prevSnapshot);
@@ -7093,8 +7094,7 @@ static int vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot delete metadata of a snapshot with
children"));
goto cleanup;
- } else
- if (gVBoxAPI.vboxSnapshotRedefine) {
+ } else if (gVBoxAPI.vboxSnapshotRedefine) {
ret = vboxDomainSnapshotDeleteMetadataOnly(snapshot);
}
goto cleanup;
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index f622ac4..e5d6d66 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3642,8 +3642,9 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned
int flags)
#else /* VBOX_API_VERSION >= 4000000 */
def.target.capacity = hddLogicalSize;
#endif /* VBOX_API_VERSION >= 4000000 */
- } else
+ } else {
defOk = 0;
+ }
rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize);
if (NS_SUCCEEDED(rc) && defOk)
--
1.9.3