1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

maint: use consistent if-else braces in lxc, vbox, phyp

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@redhat.com>
This commit is contained in:
Eric Blake 2014-09-03 13:28:14 -06:00
parent fb6d650717
commit 279b1b106d
5 changed files with 64 additions and 54 deletions

View File

@ -2246,17 +2246,17 @@ lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
if (STREQ(src->path, dest->path)) { if (STREQ(src->path, dest->path)) {
found = true; found = true;
if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) if (STREQ(type, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT)) {
dest->weight = src->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; 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; 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; 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; dest->wbps = src->wbps;
else { } else {
virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter %s"), virReportError(VIR_ERR_INVALID_ARG, _("Unknown parameter %s"),
type); type);
return -1; return -1;
@ -2272,17 +2272,17 @@ lxcDomainMergeBlkioDevice(virBlkioDevicePtr *dest_array,
return -1; return -1;
dest = &(*dest_array)[*dest_size - 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; 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; 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; 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; 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; dest->wbps = src->wbps;
else { } else {
*dest_size = *dest_size - 1; *dest_size = *dest_size - 1;
return -1; return -1;
} }

View File

@ -1,4 +1,5 @@
/* /*
* Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2012 Fujitsu Limited. * Copyright (C) 2012 Fujitsu Limited.
* *
* lxc_fuse.c: fuse filesystem support for libvirt lxc * 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_atime = sb.st_atime;
stbuf->st_ctime = sb.st_ctime; stbuf->st_ctime = sb.st_ctime;
stbuf->st_mtime = sb.st_mtime; stbuf->st_mtime = sb.st_mtime;
} else } else {
res = -ENOENT; res = -ENOENT;
}
cleanup: cleanup:
VIR_FREE(mempath); VIR_FREE(mempath);
@ -163,47 +165,47 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
*ptr = '\0'; *ptr = '\0';
if (STREQ(line, "MemTotal") && 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", virBufferAsprintf(new_meminfo, "MemTotal: %8llu kB\n",
meminfo.memtotal); meminfo.memtotal);
else if (STREQ(line, "MemFree") && } else if (STREQ(line, "MemFree") &&
(def->mem.hard_limit || def->mem.max_balloon)) (def->mem.hard_limit || def->mem.max_balloon)) {
virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n", virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n",
(meminfo.memtotal - meminfo.memusage)); (meminfo.memtotal - meminfo.memusage));
else if (STREQ(line, "Buffers")) } else if (STREQ(line, "Buffers")) {
virBufferAsprintf(new_meminfo, "Buffers: %8d kB\n", 0); 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", virBufferAsprintf(new_meminfo, "Cached: %8llu kB\n",
meminfo.cached); meminfo.cached);
else if (STREQ(line, "Active")) } else if (STREQ(line, "Active")) {
virBufferAsprintf(new_meminfo, "Active: %8llu kB\n", virBufferAsprintf(new_meminfo, "Active: %8llu kB\n",
(meminfo.active_anon + meminfo.active_file)); (meminfo.active_anon + meminfo.active_file));
else if (STREQ(line, "Inactive")) } else if (STREQ(line, "Inactive")) {
virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n", virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n",
(meminfo.inactive_anon + meminfo.inactive_file)); (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", virBufferAsprintf(new_meminfo, "Active(anon): %8llu kB\n",
meminfo.active_anon); meminfo.active_anon);
else if (STREQ(line, "Inactive(anon)")) } else if (STREQ(line, "Inactive(anon)")) {
virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n", virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n",
meminfo.inactive_anon); meminfo.inactive_anon);
else if (STREQ(line, "Active(file)")) } else if (STREQ(line, "Active(file)")) {
virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n", virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n",
meminfo.active_file); meminfo.active_file);
else if (STREQ(line, "Inactive(file)")) } else if (STREQ(line, "Inactive(file)")) {
virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n", virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n",
meminfo.inactive_file); meminfo.inactive_file);
else if (STREQ(line, "Unevictable")) } else if (STREQ(line, "Unevictable")) {
virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n", virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n",
meminfo.unevictable); 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", virBufferAsprintf(new_meminfo, "SwapTotal: %8llu kB\n",
(meminfo.swaptotal - meminfo.memtotal)); (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", virBufferAsprintf(new_meminfo, "SwapFree: %8llu kB\n",
(meminfo.swaptotal - meminfo.memtotal - (meminfo.swaptotal - meminfo.memtotal -
meminfo.swapusage + meminfo.memusage)); meminfo.swapusage + meminfo.memusage));
else { } else {
*ptr = ':'; *ptr = ':';
virBufferAdd(new_meminfo, line, -1); virBufferAdd(new_meminfo, line, -1);
} }

View File

@ -336,16 +336,17 @@ phypConnectNumOfDomainsGeneric(virConnectPtr conn, unsigned int type)
const char *state; const char *state;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (type == 0) if (type == 0) {
state = "|grep Running"; state = "|grep Running";
else if (type == 1) { } else if (type == 1) {
if (system_type == HMC) { if (system_type == HMC) {
state = "|grep \"Not Activated\""; state = "|grep \"Not Activated\"";
} else { } else {
state = "|grep \"Open Firmware\""; state = "|grep \"Open Firmware\"";
} }
} else } else {
state = " "; state = " ";
}
virBufferAddLit(&buf, "lssyscfg -r lpar"); virBufferAddLit(&buf, "lssyscfg -r lpar");
if (system_type == HMC) if (system_type == HMC)
@ -787,8 +788,9 @@ phypUUIDTable_Init(virConnectPtr conn)
VIR_WARN("Unable to generate UUID for domain %d", VIR_WARN("Unable to generate UUID for domain %d",
ids[i]); ids[i]);
} }
} else } else {
goto cleanup; goto cleanup;
}
if (phypUUIDTable_WriteFile(conn) == -1) if (phypUUIDTable_WriteFile(conn) == -1)
goto cleanup; goto cleanup;
@ -1019,8 +1021,9 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
virReportError(VIR_ERR_AUTH_FAILED, virReportError(VIR_ERR_AUTH_FAILED,
"%s", _("Authentication failed")); "%s", _("Authentication failed"));
goto disconnect; goto disconnect;
} else } else {
goto exit; goto exit;
}
} else if (rc == LIBSSH2_ERROR_NONE) { } else if (rc == LIBSSH2_ERROR_NONE) {
goto exit; goto exit;
@ -2204,9 +2207,9 @@ phypStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
goto cleanup; goto cleanup;
} }
if (vol->name != NULL) if (vol->name != NULL) {
voldef.name = vol->name; voldef.name = vol->name;
else { } else {
VIR_ERROR(_("Unable to determine storage pool's name.")); VIR_ERROR(_("Unable to determine storage pool's name."));
goto cleanup; goto cleanup;
} }
@ -2313,9 +2316,9 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes,
ret = phypExecBuffer(session, &buf, &exit_status, conn, false); ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
/* I need to parse the textual return in order to get the volumes */ /* 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; goto cleanup;
else { } else {
volumes_list = ret; volumes_list = ret;
while (got < nvolumes) { while (got < nvolumes) {
@ -2327,10 +2330,11 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes,
goto cleanup; goto cleanup;
char_ptr++; char_ptr++;
volumes_list = char_ptr; volumes_list = char_ptr;
} else } else {
break; break;
} }
} }
}
success = true; success = true;
@ -2512,9 +2516,9 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools, int npools)
ret = phypExecBuffer(session, &buf, &exit_status, conn, false); ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
/* I need to parse the textual return in order to get the storage pools */ /* 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; goto cleanup;
else { } else {
storage_pools = ret; storage_pools = ret;
while (got < npools) { while (got < npools) {
@ -2526,10 +2530,11 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools, int npools)
goto cleanup; goto cleanup;
char_ptr++; char_ptr++;
storage_pools = char_ptr; storage_pools = char_ptr;
} else } else {
break; break;
} }
} }
}
success = true; success = true;
@ -2643,9 +2648,9 @@ phypStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
virStoragePoolDef def; virStoragePoolDef def;
memset(&def, 0, sizeof(virStoragePoolDef)); memset(&def, 0, sizeof(virStoragePoolDef));
if (pool->name != NULL) if (pool->name != NULL) {
def.name = pool->name; def.name = pool->name;
else { } else {
VIR_ERROR(_("Unable to determine storage pool's name.")); VIR_ERROR(_("Unable to determine storage pool's name."));
goto err; goto err;
} }
@ -3134,9 +3139,9 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames
ret = phypExecBuffer(session, &buf, &exit_status, conn, false); ret = phypExecBuffer(session, &buf, &exit_status, conn, false);
/* I need to parse the textual return in order to get the domains */ /* 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; goto cleanup;
else { } else {
domains = ret; domains = ret;
while (got < nnames) { while (got < nnames) {
@ -3148,10 +3153,11 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames
goto cleanup; goto cleanup;
char_ptr++; char_ptr++;
domains = char_ptr; domains = char_ptr;
} else } else {
break; break;
} }
} }
}
success = true; success = true;
@ -3617,8 +3623,9 @@ phypDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
} else if (ncpus < nvcpus) { } else if (ncpus < nvcpus) {
operation = 'a'; operation = 'a';
amount = nvcpus - ncpus; amount = nvcpus - ncpus;
} else } else {
return 0; return 0;
}
virBufferAddLit(&buf, "chhwres -r proc"); virBufferAddLit(&buf, "chhwres -r proc");
if (system_type == HMC) if (system_type == HMC)

View File

@ -1291,8 +1291,7 @@ vboxAttachSound(virDomainDefPtr def, IMachine *machine)
if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_SB16) { if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_SB16) {
gVBoxAPI.UIAudioAdapter.SetAudioController(audioAdapter, gVBoxAPI.UIAudioAdapter.SetAudioController(audioAdapter,
AudioControllerType_SB16); AudioControllerType_SB16);
} else } else if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_AC97) {
if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_AC97) {
gVBoxAPI.UIAudioAdapter.SetAudioController(audioAdapter, gVBoxAPI.UIAudioAdapter.SetAudioController(audioAdapter,
AudioControllerType_AC97); AudioControllerType_AC97);
} }
@ -3381,9 +3380,10 @@ vboxDumpDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
} }
def->ngraphics++; def->ngraphics++;
} else } else {
virReportOOMError(); virReportOOMError();
} }
}
VBOX_RELEASE(VRDxServer); VBOX_RELEASE(VRDxServer);
} }
} }
@ -6510,8 +6510,9 @@ static int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
ret = vboxDomainCreate(dom); ret = vboxDomainCreate(dom);
if (!ret) if (!ret)
gVBoxAPI.snapshotRestore(dom, machine, prevSnapshot); gVBoxAPI.snapshotRestore(dom, machine, prevSnapshot);
} else } else {
ret = 0; ret = 0;
}
cleanup: cleanup:
VBOX_RELEASE(prevSnapshot); VBOX_RELEASE(prevSnapshot);
@ -7093,8 +7094,7 @@ static int vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot delete metadata of a snapshot with children")); _("cannot delete metadata of a snapshot with children"));
goto cleanup; goto cleanup;
} else } else if (gVBoxAPI.vboxSnapshotRedefine) {
if (gVBoxAPI.vboxSnapshotRedefine) {
ret = vboxDomainSnapshotDeleteMetadataOnly(snapshot); ret = vboxDomainSnapshotDeleteMetadataOnly(snapshot);
} }
goto cleanup; goto cleanup;

View File

@ -3642,8 +3642,9 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
#else /* VBOX_API_VERSION >= 4000000 */ #else /* VBOX_API_VERSION >= 4000000 */
def.target.capacity = hddLogicalSize; def.target.capacity = hddLogicalSize;
#endif /* VBOX_API_VERSION >= 4000000 */ #endif /* VBOX_API_VERSION >= 4000000 */
} else } else {
defOk = 0; defOk = 0;
}
rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize); rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetSize, &hddActualSize);
if (NS_SUCCEEDED(rc) && defOk) if (NS_SUCCEEDED(rc) && defOk)