]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: use consistent if-else braces in remaining spots
authorEric Blake <eblake@redhat.com>
Wed, 3 Sep 2014 19:39:21 +0000 (13:39 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 4 Sep 2014 20:34:03 +0000 (14:34 -0600)
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>
19 files changed:
daemon/stream.c
src/esx/esx_vi_generator.py
src/esx/esx_vi_types.c
src/remote/remote_driver.c
src/rpc/virnetsocket.c
src/security/virt-aa-helper.c
src/uml/uml_driver.c
src/util/viralloc.c
src/util/virbuffer.c
src/util/virdbus.c
src/util/virnetdev.c
src/util/virnetdevvportprofile.c
src/util/virpci.c
src/util/virsocketaddr.c
src/util/viruri.c
tests/cputest.c
tests/testutils.c
tools/virsh-domain.c
tools/virsh-host.c

index bac39c5690dca2644451c0c7b59c8b8abd6f7196..88bc85871f68576b0a047d45eca621e47ab5aecd 100644 (file)
@@ -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"),
index 0b75f18d48dbff38dc59135aefde1a897b08a7fa..bc026bd710fdf764a5e7905cdb366d5ee61a42a7 100755 (executable)
@@ -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
 
index f147e74a9bb7655a39c9a7ba7249927445b41870..4c7dc306d2fcc3c859abff618723e4efe15e5a29 100644 (file)
@@ -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;
-    }
+    return esxVI_Type_Other;
 }
 
 
index 8bc4baa98ab77ebda71f6bd9bb5558d8f99e56fa..915e8e5b3d1c21c28461edb25eec336a2727a426 100644 (file)
@@ -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)"));
index 9780e175896969d89ad27b17e5628c0d39757b49..586a0d744aee31146d85d5ad7bae4b21be11c71e 100644 (file)
@@ -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);
index a0b104c36425f81c03e6f5208f20137c86a29767..9c3860be6f70b45e66ec9192d692325d49a324bb 100644 (file)
@@ -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)
-            return rc;
+    } 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);
index 7039afc8526c683e09e9dabfd84c6eead5db1f5b..5bede072c880b5b4f4e1dab552de05c6424aeffe 100644 (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"));
index be9f0fea600ee41e2c2a47f5672ea2abbd2ef99a..dc423f5eea2baa5ea4152350cb4473906ff186e4 100644 (file)
@@ -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;
     }
index 025f0ab7d2710a820625ab8b7fe47b9d57d43927..52ffa0814793c87506b1a064d120de79000f5162 100644 (file)
@@ -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];
index 31251fe106b0a6aed8b138e558c0a5663fbd1283..a63338a206a46850a428c119c83b591d3a6380df 100644 (file)
@@ -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"));
         }
index fc9ec1e4b8f1fd416770ca920868292bac1dc438..6a8c6aef839042a58d38abd55643c92bc331ff91 100644 (file)
@@ -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;
         }
index 0f43b023190a3c6b405d6cb3f604ef98f66897e0..75679b08186fd142769ec9b98ec922c570f312c5 100644 (file)
@@ -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++;
     }
index f1d4499f8bbd979bd34b7bd8c2319aaefc150c25..d8e465faebf2bb968bca246f1482c7c80a590c82 100644 (file)
@@ -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);
index 20806e20861e8068d152fe5a1aa276c1cdf30649..7cc4bded5ee5cf4fca544fdc1a113be741ac209c 100644 (file)
@@ -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++;
         }
index 1bb3e9706a249bb5e42fc6a315dbdddba5b4f69f..69e764980cc75de1b4ce1ebfef8491b78c743bad 100644 (file)
@@ -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;
 
-        /* Empty section (eg. "&&"). */
-        if (end == query)
+        if (end == query) {
+            /* Empty section (eg. "&&"). */
             goto next;
-
-        /* If there is no '=' character, then we have just "name"
-         * and consistent with CGI.pm we assume value is "".
-         */
-        else if (!eq) {
+        } else if (!eq) {
+            /* If there is no '=' character, then we have just "name"
+             * and consistent with CGI.pm we assume value is "".
+             */
             name = xmlURIUnescapeString(query, end - query, NULL);
             if (!name) goto no_memory;
-        }
-        /* Or if we have "name=" here (works around annoying
-         * problem when calling xmlURIUnescapeString with len = 0).
-         */
-        else if (eq+1 == end) {
+        } else if (eq+1 == end) {
+            /* Or if we have "name=" here (works around annoying
+             * problem when calling xmlURIUnescapeString with len = 0).
+             */
             name = xmlURIUnescapeString(query, eq - query, NULL);
             if (!name) goto no_memory;
-        }
-        /* If the '=' character is at the beginning then we have
-         * "=value" and consistent with CGI.pm we _ignore_ this.
-         */
-        else if (query == eq)
+        } else if (query == eq) {
+            /* If the '=' character is at the beginning then we have
+             * "=value" and consistent with CGI.pm we _ignore_ this.
+             */
             goto next;
-
-        /* Otherwise it's "name=value". */
-        else {
+        } else {
+            /* Otherwise it's "name=value". */
             name = xmlURIUnescapeString(query, eq - query, NULL);
             if (!name)
                 goto no_memory;
index 38cd71e82154e723cfb1e4361e3c41412ef4e98a..94c0ebceadf4b66c1d3bd912f0d57471970774b8 100644 (file)
@@ -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");
         }
index 5bdfcc5e04f4b54320780d09aea15ab4cc26fc05..dd65fe86b8ac1d0f1d5c06d6ce36e81da4f89138 100644 (file)
@@ -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;
index c75cd73b5b4faccb754d78c4f3d9276645904f89..68d49d6374f2ccaf3d47ae490e0b266849accb9f 100644 (file)
@@ -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;
     }
index ad821b3ac1f3b472f46f6a564089d6800a6606c9..7fc212038a18f30e2f22aa3952ea6cd815da86f5 100644 (file)
@@ -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;
     }