mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
maint: use consistent if-else braces in remaining spots
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 all remaining problems, where there weren't enough issues to warrant splitting it further. * src/remote/remote_driver.c (doRemoteOpen): Correct use of {}. * src/security/virt-aa-helper.c (vah_add_path, valid_path, main): Likewise. * src/rpc/virnetsocket.c (virNetSocketNewConnectLibSSH2): Likewise. * src/esx/esx_vi_types.c (esxVI_Type_FromString): Likewise. * src/uml/uml_driver.c (umlDomainDetachDevice): Likewise. * src/util/viralloc.c (virShrinkN): Likewise. * src/util/virbuffer.c (virBufferURIEncodeString): Likewise. * src/util/virdbus.c (virDBusCall): Likewise. * src/util/virnetdev.c (virNetDevValidateConfig): Likewise. * src/util/virnetdevvportprofile.c (virNetDevVPortProfileGetNthParent): Likewise. * src/util/virpci.c (virPCIDeviceIterDevices) (virPCIDeviceWaitForCleanup) (virPCIDeviceIsBehindSwitchLackingACS): Likewise. * src/util/virsocketaddr.c (virSocketAddrGetNumNetmaskBits): Likewise. * src/util/viruri.c (virURIParseParams): Likewise. * daemon/stream.c (daemonStreamHandleAbort): Likewise. * tests/testutils.c (virtTestResult): Likewise. * tests/cputest.c (cpuTestBaseline): Likewise. * tools/virsh-domain.c (cmdDomPMSuspend): Likewise. * tools/virsh-host.c (cmdNodeSuspend): Likewise. * src/esx/esx_vi_generator.py (Type.generate_typefromstring): Tweak generated code. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
279b1b106d
commit
d194d6e7e6
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* stream.c: APIs for managing client streams
|
||||
*
|
||||
* Copyright (C) 2009, 2011 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
|
||||
@ -612,10 +612,10 @@ daemonStreamHandleAbort(virNetServerClientPtr client,
|
||||
virStreamEventRemoveCallback(stream->st);
|
||||
virStreamAbort(stream->st);
|
||||
|
||||
if (msg->header.status == VIR_NET_ERROR)
|
||||
if (msg->header.status == VIR_NET_ERROR) {
|
||||
virReportError(VIR_ERR_RPC,
|
||||
"%s", _("stream aborted at client request"));
|
||||
else {
|
||||
} else {
|
||||
VIR_WARN("unexpected stream status %d", msg->header.status);
|
||||
virReportError(VIR_ERR_RPC,
|
||||
_("stream aborted with unexpected status %d"),
|
||||
|
@ -3,6 +3,7 @@
|
||||
#
|
||||
# esx_vi_generator.py: generates most of the SOAP type mapping code
|
||||
#
|
||||
# Copyright (C) 2014 Red Hat, Inc.
|
||||
# Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte@googlemail.com>
|
||||
# Copyright (C) 2013 Ata E Husain Bohra <ata.husain@hotmail.com>
|
||||
#
|
||||
@ -433,9 +434,8 @@ class Type:
|
||||
|
||||
|
||||
def generate_typefromstring(self):
|
||||
string = " else if (STREQ(type, \"%s\")) {\n" % self.name
|
||||
string = " if (STREQ(type, \"%s\"))\n" % self.name
|
||||
string += " return esxVI_Type_%s;\n" % self.name
|
||||
string += " }\n"
|
||||
|
||||
return string
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* esx_vi_types.c: client for the VMware VI API 2.5 to manage ESX hosts
|
||||
*
|
||||
* Copyright (C) 2010 Red Hat, Inc.
|
||||
* Copyright (C) 2010, 2014 Red Hat, Inc.
|
||||
* Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte@googlemail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -873,9 +873,7 @@ esxVI_Type_FromString(const char *type)
|
||||
|
||||
#include "esx_vi_types.generated.typefromstring"
|
||||
|
||||
else {
|
||||
return esxVI_Type_Other;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -606,9 +606,9 @@ doRemoteOpen(virConnectPtr conn,
|
||||
else
|
||||
transport = trans_unix;
|
||||
} else {
|
||||
if (STRCASEEQ(transport_str, "tls"))
|
||||
if (STRCASEEQ(transport_str, "tls")) {
|
||||
transport = trans_tls;
|
||||
else if (STRCASEEQ(transport_str, "unix")) {
|
||||
} else if (STRCASEEQ(transport_str, "unix")) {
|
||||
if (conn->uri->server) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("using unix socket and remote "
|
||||
@ -618,15 +618,15 @@ doRemoteOpen(virConnectPtr conn,
|
||||
} else {
|
||||
transport = trans_unix;
|
||||
}
|
||||
} else if (STRCASEEQ(transport_str, "ssh"))
|
||||
} else if (STRCASEEQ(transport_str, "ssh")) {
|
||||
transport = trans_ssh;
|
||||
else if (STRCASEEQ(transport_str, "libssh2"))
|
||||
} else if (STRCASEEQ(transport_str, "libssh2")) {
|
||||
transport = trans_libssh2;
|
||||
else if (STRCASEEQ(transport_str, "ext"))
|
||||
} else if (STRCASEEQ(transport_str, "ext")) {
|
||||
transport = trans_ext;
|
||||
else if (STRCASEEQ(transport_str, "tcp"))
|
||||
} else if (STRCASEEQ(transport_str, "tcp")) {
|
||||
transport = trans_tcp;
|
||||
else {
|
||||
} else {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("remote_open: transport in URL not recognised "
|
||||
"(should be tls|unix|ssh|ext|tcp|libssh2)"));
|
||||
|
@ -843,13 +843,13 @@ virNetSocketNewConnectLibSSH2(const char *host,
|
||||
if (virNetSSHSessionAuthSetCallback(sess, auth) != 0)
|
||||
goto error;
|
||||
|
||||
if (STRCASEEQ("auto", knownHostsVerify))
|
||||
if (STRCASEEQ("auto", knownHostsVerify)) {
|
||||
verify = VIR_NET_SSH_HOSTKEY_VERIFY_AUTO_ADD;
|
||||
else if (STRCASEEQ("ignore", knownHostsVerify))
|
||||
} else if (STRCASEEQ("ignore", knownHostsVerify)) {
|
||||
verify = VIR_NET_SSH_HOSTKEY_VERIFY_IGNORE;
|
||||
else if (STRCASEEQ("normal", knownHostsVerify))
|
||||
} else if (STRCASEEQ("normal", knownHostsVerify)) {
|
||||
verify = VIR_NET_SSH_HOSTKEY_VERIFY_NORMAL;
|
||||
else {
|
||||
} else {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("Invalid host key verification method: '%s'"),
|
||||
knownHostsVerify);
|
||||
@ -873,20 +873,20 @@ virNetSocketNewConnectLibSSH2(const char *host,
|
||||
authMethodNext = authMethodsCopy;
|
||||
|
||||
while ((authMethod = strsep(&authMethodNext, ","))) {
|
||||
if (STRCASEEQ(authMethod, "keyboard-interactive"))
|
||||
if (STRCASEEQ(authMethod, "keyboard-interactive")) {
|
||||
ret = virNetSSHSessionAuthAddKeyboardAuth(sess, username, -1);
|
||||
else if (STRCASEEQ(authMethod, "password"))
|
||||
} else if (STRCASEEQ(authMethod, "password")) {
|
||||
ret = virNetSSHSessionAuthAddPasswordAuth(sess,
|
||||
uri,
|
||||
username);
|
||||
else if (STRCASEEQ(authMethod, "privkey"))
|
||||
} else if (STRCASEEQ(authMethod, "privkey")) {
|
||||
ret = virNetSSHSessionAuthAddPrivKeyAuth(sess,
|
||||
username,
|
||||
privkey,
|
||||
NULL);
|
||||
else if (STRCASEEQ(authMethod, "agent"))
|
||||
} else if (STRCASEEQ(authMethod, "agent")) {
|
||||
ret = virNetSSHSessionAuthAddAgentAuth(sess, username);
|
||||
else {
|
||||
} else {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("Invalid authentication method: '%s'"),
|
||||
authMethod);
|
||||
|
@ -579,9 +579,9 @@ valid_path(const char *path, const bool readonly)
|
||||
if (STRNEQLEN(path, "/", 1))
|
||||
return 1;
|
||||
|
||||
if (!virFileExists(path))
|
||||
if (!virFileExists(path)) {
|
||||
vah_warning(_("path does not exist, skipping file type checks"));
|
||||
else {
|
||||
} else {
|
||||
if (stat(path, &sb) == -1)
|
||||
return -1;
|
||||
|
||||
@ -777,9 +777,9 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi
|
||||
vah_error(NULL, 0, _("could not find realpath for disk"));
|
||||
return rc;
|
||||
}
|
||||
} else
|
||||
if (VIR_STRDUP_QUIET(tmp, path) < 0)
|
||||
} else if (VIR_STRDUP_QUIET(tmp, path) < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (strchr(perms, 'w') != NULL)
|
||||
readonly = false;
|
||||
@ -1269,9 +1269,9 @@ main(int argc, char **argv)
|
||||
APPARMOR_DIR "/libvirt", ctl->uuid) < 0)
|
||||
vah_error(ctl, 0, _("could not allocate memory"));
|
||||
|
||||
if (ctl->cmd == 'a')
|
||||
if (ctl->cmd == 'a') {
|
||||
rc = parserLoad(ctl->uuid);
|
||||
else if (ctl->cmd == 'R' || ctl->cmd == 'D') {
|
||||
} else if (ctl->cmd == 'R' || ctl->cmd == 'D') {
|
||||
rc = parserRemove(ctl->uuid);
|
||||
if (ctl->cmd == 'D') {
|
||||
unlink(include_file);
|
||||
|
@ -2364,10 +2364,9 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml)
|
||||
dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
|
||||
if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML)
|
||||
ret = umlDomainDetachUmlDisk(driver, vm, dev);
|
||||
else {
|
||||
else
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("This type of disk cannot be hot unplugged"));
|
||||
}
|
||||
} else {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
"%s", _("This type of device cannot be hot unplugged"));
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* viralloc.c: safer memory allocation
|
||||
*
|
||||
* Copyright (C) 2010-2013 Red Hat, Inc.
|
||||
* Copyright (C) 2010-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2008 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -368,10 +368,10 @@ int virResizeN(void *ptrptr,
|
||||
*/
|
||||
void virShrinkN(void *ptrptr, size_t size, size_t *countptr, size_t toremove)
|
||||
{
|
||||
if (toremove < *countptr)
|
||||
if (toremove < *countptr) {
|
||||
ignore_value(virReallocN(ptrptr, size, *countptr -= toremove,
|
||||
false, 0, NULL, NULL, 0));
|
||||
else {
|
||||
} else {
|
||||
virFree(ptrptr);
|
||||
*countptr = 0;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* virbuffer.c: buffers for libvirt
|
||||
*
|
||||
* Copyright (C) 2005-2008, 2010-2013 Red Hat, Inc.
|
||||
* Copyright (C) 2005-2008, 2010-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
|
||||
@ -585,9 +585,9 @@ virBufferURIEncodeString(virBufferPtr buf, const char *str)
|
||||
return;
|
||||
|
||||
for (p = str; *p; ++p) {
|
||||
if (c_isalnum(*p))
|
||||
if (c_isalnum(*p)) {
|
||||
buf->content[buf->use++] = *p;
|
||||
else {
|
||||
} else {
|
||||
uc = (unsigned char) *p;
|
||||
buf->content[buf->use++] = '%';
|
||||
buf->content[buf->use++] = hex[uc >> 4];
|
||||
|
@ -1422,9 +1422,9 @@ virDBusCall(DBusConnection *conn,
|
||||
call,
|
||||
VIR_DBUS_METHOD_CALL_TIMEOUT_MILLIS,
|
||||
error ? error : &localerror))) {
|
||||
if (error)
|
||||
if (error) {
|
||||
ret = 0;
|
||||
else {
|
||||
} else {
|
||||
virReportError(VIR_ERR_DBUS_SERVICE, _("%s: %s"), member,
|
||||
localerror.message ? localerror.message : _("unknown error"));
|
||||
}
|
||||
|
@ -1049,7 +1049,7 @@ int virNetDevValidateConfig(const char *ifname,
|
||||
if (ifindex != -1) {
|
||||
if (virNetDevGetIndex(ifname, &idx) < 0)
|
||||
goto cleanup;
|
||||
else if (idx != ifindex) {
|
||||
if (idx != ifindex) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -815,8 +815,9 @@ virNetDevVPortProfileGetNthParent(const char *ifname, int ifindex, unsigned int
|
||||
if (tb[IFLA_LINK]) {
|
||||
ifindex = *(int *)RTA_DATA(tb[IFLA_LINK]);
|
||||
ifname = NULL;
|
||||
} else
|
||||
} else {
|
||||
end = true;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
@ -492,8 +492,7 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
|
||||
virPCIDeviceFree(check);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
else if (rc == 1) {
|
||||
} else if (rc == 1) {
|
||||
VIR_DEBUG("%s %s: iter matched on %s", dev->id, dev->name, check->name);
|
||||
*matched = check;
|
||||
ret = 1;
|
||||
@ -1468,8 +1467,7 @@ virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, const char *matcher)
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
in_matching_device = false;
|
||||
|
||||
/* expected format: <start>-<end> : <domain>:<bus>:<slot>.<function> */
|
||||
@ -2272,9 +2270,9 @@ virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr dev)
|
||||
* into play since devices on the root bus can't P2P without going
|
||||
* through the root IOMMU.
|
||||
*/
|
||||
if (dev->bus == 0)
|
||||
if (dev->bus == 0) {
|
||||
return 0;
|
||||
else {
|
||||
} else {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to find parent device for %s"),
|
||||
dev->name);
|
||||
|
@ -693,9 +693,9 @@ int virSocketAddrGetNumNetmaskBits(const virSocketAddr *netmask)
|
||||
j = i << 3;
|
||||
while (j < (8 * 4)) {
|
||||
bit = 1 << (7 - (j & 7));
|
||||
if ((tm[j >> 3] & bit)) {
|
||||
if ((tm[j >> 3] & bit))
|
||||
c++;
|
||||
} else
|
||||
else
|
||||
break;
|
||||
j++;
|
||||
}
|
||||
@ -727,9 +727,9 @@ int virSocketAddrGetNumNetmaskBits(const virSocketAddr *netmask)
|
||||
j = i << 4;
|
||||
while (j < (16 * 8)) {
|
||||
bit = 1 << (15 - (j & 0xf));
|
||||
if ((tm[j >> 4] & bit)) {
|
||||
if ((tm[j >> 4] & bit))
|
||||
c++;
|
||||
} else
|
||||
else
|
||||
break;
|
||||
j++;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* viruri.c: URI parsing wrappers for libxml2 functions
|
||||
*
|
||||
* Copyright (C) 2012 Red Hat, Inc.
|
||||
* Copyright (C) 2012-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
|
||||
@ -80,32 +80,28 @@ virURIParseParams(virURIPtr uri)
|
||||
eq = strchr(query, '=');
|
||||
if (eq && eq >= end) eq = NULL;
|
||||
|
||||
if (end == query) {
|
||||
/* Empty section (eg. "&&"). */
|
||||
if (end == query)
|
||||
goto next;
|
||||
|
||||
} else if (!eq) {
|
||||
/* If there is no '=' character, then we have just "name"
|
||||
* and consistent with CGI.pm we assume value is "".
|
||||
*/
|
||||
else if (!eq) {
|
||||
name = xmlURIUnescapeString(query, end - query, NULL);
|
||||
if (!name) goto no_memory;
|
||||
}
|
||||
} else if (eq+1 == end) {
|
||||
/* Or if we have "name=" here (works around annoying
|
||||
* problem when calling xmlURIUnescapeString with len = 0).
|
||||
*/
|
||||
else if (eq+1 == end) {
|
||||
name = xmlURIUnescapeString(query, eq - query, NULL);
|
||||
if (!name) goto no_memory;
|
||||
}
|
||||
} else if (query == eq) {
|
||||
/* If the '=' character is at the beginning then we have
|
||||
* "=value" and consistent with CGI.pm we _ignore_ this.
|
||||
*/
|
||||
else if (query == eq)
|
||||
goto next;
|
||||
|
||||
} else {
|
||||
/* Otherwise it's "name=value". */
|
||||
else {
|
||||
name = xmlURIUnescapeString(query, eq - query, NULL);
|
||||
if (!name)
|
||||
goto no_memory;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cputest.c: Test the libvirtd internal CPU APIs
|
||||
*
|
||||
* Copyright (C) 2010-2013 Red Hat, Inc.
|
||||
* Copyright (C) 2010-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
|
||||
@ -333,9 +333,9 @@ cpuTestBaseline(const void *arg)
|
||||
baseline = cpuBaseline(cpus, ncpus, NULL, 0, data->flags);
|
||||
if (data->result < 0) {
|
||||
virResetLastError();
|
||||
if (!baseline)
|
||||
if (!baseline) {
|
||||
ret = 0;
|
||||
else if (virTestGetVerbose()) {
|
||||
} else if (virTestGetVerbose()) {
|
||||
fprintf(stderr, "\n%-70s... ",
|
||||
"cpuBaseline was expected to fail but it succeeded");
|
||||
}
|
||||
|
@ -115,9 +115,9 @@ void virtTestResult(const char *name, int ret, const char *msg, ...)
|
||||
testCounter++;
|
||||
if (virTestGetVerbose()) {
|
||||
fprintf(stderr, "%3zu) %-60s ", testCounter, name);
|
||||
if (ret == 0)
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "OK\n");
|
||||
else {
|
||||
} else {
|
||||
fprintf(stderr, "FAILED\n");
|
||||
if (msg) {
|
||||
char *str;
|
||||
|
@ -2920,13 +2920,13 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (STREQ(target, "mem"))
|
||||
if (STREQ(target, "mem")) {
|
||||
suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
|
||||
else if (STREQ(target, "disk"))
|
||||
} else if (STREQ(target, "disk")) {
|
||||
suspendTarget = VIR_NODE_SUSPEND_TARGET_DISK;
|
||||
else if (STREQ(target, "hybrid"))
|
||||
} else if (STREQ(target, "hybrid")) {
|
||||
suspendTarget = VIR_NODE_SUSPEND_TARGET_HYBRID;
|
||||
else {
|
||||
} else {
|
||||
vshError(ctl, "%s", _("Invalid target"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -803,13 +803,13 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (STREQ(target, "mem"))
|
||||
if (STREQ(target, "mem")) {
|
||||
suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
|
||||
else if (STREQ(target, "disk"))
|
||||
} else if (STREQ(target, "disk")) {
|
||||
suspendTarget = VIR_NODE_SUSPEND_TARGET_DISK;
|
||||
else if (STREQ(target, "hybrid"))
|
||||
} else if (STREQ(target, "hybrid")) {
|
||||
suspendTarget = VIR_NODE_SUSPEND_TARGET_HYBRID;
|
||||
else {
|
||||
} else {
|
||||
vshError(ctl, "%s", _("Invalid target"));
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user