[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 5/6] 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.

Signed-off-by: Eric Blake <eblake redhat com>
---
 daemon/stream.c                  |  6 +++---
 src/esx/esx_vi_types.c           |  6 ++----
 src/remote/remote_driver.c       | 14 +++++++-------
 src/rpc/virnetsocket.c           | 18 +++++++++---------
 src/security/virt-aa-helper.c    | 14 +++++++-------
 src/uml/uml_driver.c             |  4 ++--
 src/util/viralloc.c              |  6 +++---
 src/util/virbuffer.c             |  6 +++---
 src/util/virdbus.c               |  4 ++--
 src/util/virnetdev.c             |  4 ++--
 src/util/virnetdevvportprofile.c |  3 ++-
 src/util/virpci.c                | 10 ++++------
 src/util/virsocketaddr.c         |  8 ++++----
 src/util/viruri.c                | 38 +++++++++++++++++---------------------
 tests/cputest.c                  |  6 +++---
 tests/testutils.c                |  4 ++--
 tools/virsh-domain.c             |  8 ++++----
 tools/virsh-host.c               |  8 ++++----
 18 files changed, 80 insertions(+), 87 deletions(-)

diff --git a/daemon/stream.c b/daemon/stream.c
index bac39c5..88bc858 100644
--- a/daemon/stream.c
+++ b/daemon/stream.c
@@ -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"),
diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c
index f147e74..4c7dc30 100644
--- a/src/esx/esx_vi_types.c
+++ b/src/esx/esx_vi_types.c
@@ -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;
 }


diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8bc4baa..915e8e5 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -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)"));
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 9780e17..586a0d7 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -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);
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index a0b104c..9c3860b 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -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);
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 7039afc..22fa6db 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -2362,9 +2362,9 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml)

     if (dev->type == VIR_DOMAIN_DEVICE_DISK &&
         dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-        if (dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_UML)
+        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"));
         }
diff --git a/src/util/viralloc.c b/src/util/viralloc.c
index be9f0fe..dc423f5 100644
--- a/src/util/viralloc.c
+++ b/src/util/viralloc.c
@@ -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;
     }
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c
index 025f0ab..52ffa08 100644
--- a/src/util/virbuffer.c
+++ b/src/util/virbuffer.c
@@ -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];
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index 31251fe..a63338a 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -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"));
         }
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index fc9ec1e..cf526ec 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -1047,9 +1047,9 @@ int virNetDevValidateConfig(const char *ifname,
     }

     if (ifindex != -1) {
-        if (virNetDevGetIndex(ifname, &idx) < 0)
+        if (virNetDevGetIndex(ifname, &idx) < 0) {
             goto cleanup;
-        else if (idx != ifindex) {
+        } else if (idx != ifindex) {
             ret = 0;
             goto cleanup;
         }
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 0f43b02..75679b0 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -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++;
     }
diff --git a/src/util/virpci.c b/src/util/virpci.c
index f1d4499..d8e465f 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -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);
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 20806e2..7cc4bde 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -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++;
         }
diff --git a/src/util/viruri.c b/src/util/viruri.c
index 1bb3e97..69e7649 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -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;
diff --git a/tests/cputest.c b/tests/cputest.c
index 38cd71e..94c0ebc 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -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");
         }
diff --git a/tests/testutils.c b/tests/testutils.c
index 5bdfcc5..dd65fe8 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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;
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c75cd73..68d49d6 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -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;
     }
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index ad821b3..7fc2120 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -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;
     }
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]