[libvirt] [PATCH v2 00/22] Remove unnecessary curly brackets around one-line bodies

Brackets were removed by the following script in the root directory of libvirt's repository: for i in $(git ls-files | grep '\.[ch]$'); do echo -n "$i ... "; emacs $i --batch --eval \ '(replace-regexp "^\\([[:space:]]*\\(if\\|for\\|while\\).*)\\)[[:space:]]*{\\(\n[^\n;]*;[^\n;]*\\)\n[[:space:]]*}$" "\\1\\3" nil (point-min) (point-max))' \ -f save-buffer &>/dev/null; echo done; done v2: - Smaller patches, so there has to be none allowed through by moderators - Only curly brackets around one-line bodies with one-line preceding conditions removed - syntax-check! (with some other bracket-spacing.pl cleanups Martin Kletzander (22): virt-aa-helper: Trick invalid syntax-check Remove unnecessary curly brackets in daemon/ and examples/ Remove unnecessary curly brackets in src/esx/esx_driver.c Remove unnecessary curly brackets in rest of src/esx/ Remove unnecessary curly brackets in src/vmx/vmx.c Remove unnecessary curly brackets in src/conf/ Remove unnecessary curly brackets in src/hyperv/ Remove unnecessary curly brackets in src/node_device/ Remove unnecessary curly brackets in src/qemu/ Remove unnecessary curly brackets in src/storage/ Remove unnecessary curly brackets in src/test/test_driver.c Remove unnecessary curly brackets in src/util/ Remove unnecessary curly brackets in src/vbox/ Remove unnecessary curly brackets in rest of src/[a-n]*/ Remove unnecessary curly brackets in rest of src/[o-u]*/ Remove unnecessary curly brackets in rest of src/ Remove unnecessary curly brackets in tools/ Remove unnecessary curly brackets in tests/ docs: Adjust contributor guidelines about curly brackets bracket-spacing: Don't modify current line bracket-spacing: Remove pointless cycles bracket-spacing: Add syntax-check for unnecessary curly brackets HACKING | 8 +- build-aux/bracket-spacing.pl | 74 ++++-- daemon/libvirtd.c | 15 +- daemon/remote.c | 12 +- docs/hacking.html.in | 4 +- examples/object-events/event-test.c | 3 +- examples/openauth/openauth.c | 9 +- src/access/viraccessdriverstack.c | 3 +- src/bhyve/bhyve_driver.c | 3 +- src/conf/capabilities.c | 3 +- src/conf/domain_conf.c | 135 ++++------- src/conf/interface_conf.c | 9 +- src/conf/network_conf.c | 51 ++-- src/conf/node_device_conf.c | 15 +- src/conf/nwfilter_conf.c | 12 +- src/conf/object_event.c | 6 +- src/conf/storage_conf.c | 24 +- src/datatypes.c | 6 +- src/driver.c | 3 +- src/esx/esx_device_monitor.c | 3 +- src/esx/esx_driver.c | 390 ++++++++++-------------------- src/esx/esx_interface_driver.c | 12 +- src/esx/esx_network_driver.c | 57 ++--- src/esx/esx_nwfilter_driver.c | 3 +- src/esx/esx_secret_driver.c | 3 +- src/esx/esx_storage_backend_iscsi.c | 45 ++-- src/esx/esx_storage_backend_vmfs.c | 51 ++-- src/esx/esx_storage_driver.c | 81 +++---- src/esx/esx_util.c | 45 ++-- src/esx/esx_vi.c | 249 +++++++------------ src/esx/esx_vi_types.c | 45 ++-- src/hyperv/hyperv_device_monitor.c | 3 +- src/hyperv/hyperv_driver.c | 87 +++---- src/hyperv/hyperv_interface_driver.c | 3 +- src/hyperv/hyperv_network_driver.c | 3 +- src/hyperv/hyperv_nwfilter_driver.c | 3 +- src/hyperv/hyperv_secret_driver.c | 3 +- src/hyperv/hyperv_storage_driver.c | 3 +- src/hyperv/hyperv_util.c | 6 +- src/hyperv/hyperv_wmi.c | 39 +-- src/interface/interface_backend_udev.c | 12 +- src/libvirt-lxc.c | 3 +- src/libvirt-nodedev.c | 3 +- src/libvirt-storage.c | 6 +- src/libxl/libxl_driver.c | 12 +- src/locking/lock_daemon.c | 3 +- src/locking/lock_driver_sanlock.c | 6 +- src/lxc/lxc_container.c | 9 +- src/lxc/lxc_driver.c | 9 +- src/lxc/lxc_process.c | 6 +- src/network/bridge_driver.c | 6 +- src/network/bridge_driver_linux.c | 3 +- src/node_device/node_device_driver.c | 21 +- src/node_device/node_device_hal.c | 6 +- src/node_device/node_device_udev.c | 87 +++---- src/nwfilter/nwfilter_dhcpsnoop.c | 3 +- src/nwfilter/nwfilter_ebiptables_driver.c | 12 +- src/nwfilter/nwfilter_gentech_driver.c | 9 +- src/nwfilter/nwfilter_learnipaddr.c | 3 +- src/openvz/openvz_conf.c | 3 +- src/openvz/openvz_driver.c | 27 +-- src/phyp/phyp_driver.c | 21 +- src/qemu/qemu_agent.c | 3 +- src/qemu/qemu_capabilities.c | 9 +- src/qemu/qemu_cgroup.c | 6 +- src/qemu/qemu_command.c | 6 +- src/qemu/qemu_conf.c | 3 +- src/qemu/qemu_domain.c | 3 +- src/qemu/qemu_driver.c | 45 ++-- src/qemu/qemu_hotplug.c | 6 +- src/qemu/qemu_migration.c | 3 +- src/qemu/qemu_monitor_json.c | 12 +- src/qemu/qemu_monitor_text.c | 6 +- src/qemu/qemu_process.c | 18 +- src/remote/remote_driver.c | 3 +- src/rpc/virnetclient.c | 9 +- src/rpc/virnetserver.c | 3 +- src/rpc/virnetserverclient.c | 3 +- src/rpc/virnetserverservice.c | 3 +- src/security/security_manager.c | 3 +- src/security/virt-aa-helper.c | 9 +- src/storage/parthelper.c | 3 +- src/storage/storage_backend.c | 9 +- src/storage/storage_backend_disk.c | 15 +- src/storage/storage_backend_fs.c | 6 +- src/storage/storage_backend_mpath.c | 27 +-- src/storage/storage_backend_rbd.c | 30 +-- src/storage/storage_backend_scsi.c | 6 +- src/storage/storage_driver.c | 9 +- src/test/test_driver.c | 57 ++--- src/uml/uml_conf.c | 6 +- src/uml/uml_driver.c | 9 +- src/util/virauth.c | 12 +- src/util/virbitmap.c | 6 +- src/util/virbuffer.c | 3 +- src/util/vircommand.c | 9 +- src/util/virconf.c | 15 +- src/util/virdbus.c | 3 +- src/util/virdnsmasq.c | 3 +- src/util/vireventpoll.c | 9 +- src/util/virfile.c | 6 +- src/util/virfirewall.c | 6 +- src/util/viriscsi.c | 9 +- src/util/virlockspace.c | 6 +- src/util/virlog.c | 3 +- src/util/virnetdev.c | 6 +- src/util/virnetdevbridge.c | 3 +- src/util/virnetdevmacvlan.c | 9 +- src/util/virnetdevtap.c | 6 +- src/util/virpci.c | 15 +- src/util/virsexpr.c | 24 +- src/util/virstorageencryption.c | 3 +- src/util/virstoragefile.c | 6 +- src/util/virsysinfo.c | 3 +- src/util/virthreadpool.c | 3 +- src/util/virutil.c | 9 +- src/util/virxml.c | 18 +- src/vbox/vbox_MSCOMGlue.c | 30 +-- src/vbox/vbox_XPCOMCGlue.c | 33 +-- src/vbox/vbox_common.c | 51 ++-- src/vbox/vbox_network.c | 15 +- src/vbox/vbox_snapshot_conf.c | 21 +- src/vbox/vbox_storage.c | 30 +-- src/vbox/vbox_tmpl.c | 30 +-- src/vmware/vmware_conf.c | 3 +- src/vmware/vmware_driver.c | 6 +- src/vmx/vmx.c | 243 +++++++------------ src/xen/block_stats.c | 3 +- src/xen/xen_driver.c | 6 +- src/xen/xen_hypervisor.c | 6 +- src/xen/xend_internal.c | 18 +- src/xen/xm_internal.c | 6 +- src/xenapi/xenapi_driver.c | 12 +- src/xenapi/xenapi_utils.c | 9 +- src/xenconfig/xen_common.c | 6 +- src/xenconfig/xen_sxpr.c | 6 +- tests/commandhelper.c | 3 +- tests/esxutilstest.c | 12 +- tests/eventtest.c | 3 +- tests/openvzutilstest.c | 6 +- tests/securityselinuxlabeltest.c | 6 +- tests/shunloadtest.c | 6 +- tests/utiltest.c | 3 +- tests/virbuftest.c | 3 +- tests/virhashtest.c | 30 +-- tests/virtimetest.c | 3 +- tests/vmx2xmltest.c | 12 +- tests/xml2vmxtest.c | 27 +-- tools/virsh-console.c | 6 +- tools/virsh-domain.c | 27 +-- tools/virsh-edit.c | 6 +- tools/virsh-host.c | 3 +- tools/virsh-pool.c | 6 +- tools/virsh-volume.c | 12 +- tools/virsh.c | 18 +- tools/wireshark/src/packet-libvirt.c | 6 +- 156 files changed, 1050 insertions(+), 2006 deletions(-) -- 2.1.3

Rule sc_prohibit_newline_at_end_of_diagnostic for syntax-check does check for passing strings ending with '\n' to known functions. But when setting IFS, '\n' needs to be part of that (and is by default). The order of individual characters in IFS doesn't matter, so transposing last two of them fixes it for the future. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 1f299a0..e102c3c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1257,7 +1257,7 @@ main(int argc, char **argv) vah_error(ctl, 1, _("could not set PATH")); } - if (setenv("IFS", " \t\n", 1) != 0) { + if (setenv("IFS", " \n\t", 1) != 0) { vah_error(ctl, 1, _("could not set IFS")); } -- 2.1.3

On 11/13/2014 07:37 AM, Martin Kletzander wrote:
Rule sc_prohibit_newline_at_end_of_diagnostic for syntax-check does check for passing strings ending with '\n' to known functions. But when setting IFS, '\n' needs to be part of that (and is by default). The order of individual characters in IFS doesn't matter, so transposing last two of them fixes it for the future.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 1f299a0..e102c3c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1257,7 +1257,7 @@ main(int argc, char **argv) vah_error(ctl, 1, _("could not set PATH")); }
- if (setenv("IFS", " \t\n", 1) != 0) { + if (setenv("IFS", " \n\t", 1) != 0) {
NACK. IFS is one of those things that even though on paper the POSIX standard says order doesn't matter for anything besides the first character, in practice, changing it to anything other than space-tab-newline is liable to break things. Rather, reading cfg.mk, I see: # Like the above, but prohibit a newline at the end of a diagnostic. # This is subject to false positives partly because it naively looks for # `\n"', which may not be the end of the string, and also because it takes # two lines of context (the -A2) after the line with the function name. It looks like the reason you wrote this patch is because once the _previous_ vah_error() call gets turned into a one-line if body, then the setenv() call starts to be part of the -A2 context of the vah_error. But I think you can work around that by creative newlines, as in: if ... vah_error(...); if (setenv("IFS", " \t\n", 1) != 0) { or even creative comments: if ... vah_error(...); /* ensure the traditional IFS setting */ if (setenv("IFS", " \t\n", 1) != 0) { -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 11/13/2014 09:37 AM, Martin Kletzander wrote:
Rule sc_prohibit_newline_at_end_of_diagnostic for syntax-check does check for passing strings ending with '\n' to known functions. But when setting IFS, '\n' needs to be part of that (and is by default). The order of individual characters in IFS doesn't matter, so transposing last two of them fixes it for the future.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
I was just about to point out that this particular change did seem out of place with the rest of the series (forgot to do that in my .0 response)... I'm sure glad Eric has the standards knowledge! John
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 1f299a0..e102c3c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1257,7 +1257,7 @@ main(int argc, char **argv) vah_error(ctl, 1, _("could not set PATH")); }
- if (setenv("IFS", " \t\n", 1) != 0) { + if (setenv("IFS", " \n\t", 1) != 0) { vah_error(ctl, 1, _("could not set IFS")); }

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- daemon/libvirtd.c | 15 +++++---------- daemon/remote.c | 12 ++++-------- examples/object-events/event-test.c | 3 +-- examples/openauth/openauth.c | 9 +++------ 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 1864bfd..b7f82c5 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -981,9 +981,8 @@ static int migrateProfile(void) if (!(home = virGetUserDirectory())) goto cleanup; - if (virAsprintf(&old_base, "%s/.libvirt", home) < 0) { + if (virAsprintf(&old_base, "%s/.libvirt", home) < 0) goto cleanup; - } /* if the new directory is there or the old one is not: do nothing */ if (!(config_dir = virGetUserConfigDirectory())) @@ -998,21 +997,18 @@ static int migrateProfile(void) } /* test if we already attempted to migrate first */ - if (virAsprintf(&updated, "%s/DEPRECATED-DIRECTORY", old_base) < 0) { + if (virAsprintf(&updated, "%s/DEPRECATED-DIRECTORY", old_base) < 0) goto cleanup; - } - if (virFileExists(updated)) { + if (virFileExists(updated)) goto cleanup; - } config_home = virGetEnvBlockSUID("XDG_CONFIG_HOME"); if (config_home && config_home[0] != '\0') { if (VIR_STRDUP(xdg_dir, config_home) < 0) goto cleanup; } else { - if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) { + if (virAsprintf(&xdg_dir, "%s/.config", home) < 0) goto cleanup; - } } old_umask = umask(077); @@ -1164,9 +1160,8 @@ int main(int argc, char **argv) { c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx); - if (c == -1) { + if (c == -1) break; - } switch (c) { case 0: diff --git a/daemon/remote.c b/daemon/remote.c index c93c97a..1d7082e 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -500,9 +500,8 @@ remoteRelayDomainEventGraphics(virConnectPtr conn, authScheme, callback->callbackID); VIR_DEBUG("Subject %d", subject->nidentity); - for (i = 0; i < subject->nidentity; i++) { + for (i = 0; i < subject->nidentity; i++) VIR_DEBUG(" %s=%s", subject->identities[i].type, subject->identities[i].name); - } /* build return data */ memset(&data, 0, sizeof(data)); @@ -4268,9 +4267,8 @@ remoteDispatchDomainOpenGraphicsFd(virNetServerPtr server ATTRIBUTE_UNUSED, cleanup: VIR_FORCE_CLOSE(fd); - if (rv < 0) { + if (rv < 0) virNetMessageSaveError(rerr); - } if (dom) virDomainFree(dom); @@ -5689,9 +5687,8 @@ remoteDispatchDomainCreateXMLWithFiles(virNetServerPtr server ATTRIBUTE_UNUSED, rv = 0; cleanup: - for (i = 0; i < nfiles; i++) { + for (i = 0; i < nfiles; i++) VIR_FORCE_CLOSE(files[i]); - } VIR_FREE(files); if (rv < 0) virNetMessageSaveError(rerr); @@ -5741,9 +5738,8 @@ static int remoteDispatchDomainCreateWithFiles(virNetServerPtr server ATTRIBUTE_ rv = 0; cleanup: - for (i = 0; i < nfiles; i++) { + for (i = 0; i < nfiles; i++) VIR_FORCE_CLOSE(files[i]); - } VIR_FREE(files); if (rv < 0) virNetMessageSaveError(rerr); diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c index 0c6faf4..8987ee5 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -730,9 +730,8 @@ int main(int argc, char **argv) virConnectUnregisterCloseCallback(dconn, connectClose); VIR_DEBUG("Closing connection"); - if (dconn && virConnectClose(dconn) < 0) { + if (dconn && virConnectClose(dconn) < 0) printf("error closing\n"); - } printf("done\n"); return 0; diff --git a/examples/openauth/openauth.c b/examples/openauth/openauth.c index fae96e0..0be977e 100644 --- a/examples/openauth/openauth.c +++ b/examples/openauth/openauth.c @@ -132,9 +132,8 @@ showDomains(virConnectPtr conn) goto out; } - if (numNames > 0) { + if (numNames > 0) printf("Inactive domains:\n"); - } for (i = 0; i < numNames; i++) { printf(" %s\n", *(nameList + i)); @@ -181,9 +180,8 @@ authCallback(virConnectCredentialPtr cred, unsigned int ncred, void *cbdata) case VIR_CRED_AUTHNAME: cred[i].result = strdup(authData->username); - if (cred[i].result == NULL) { + if (cred[i].result == NULL) return -1; - } cred[i].resultlen = strlen(cred[i].result); break; @@ -191,9 +189,8 @@ authCallback(virConnectCredentialPtr cred, unsigned int ncred, void *cbdata) case VIR_CRED_PASSPHRASE: cred[i].result = strdup(authData->password); - if (cred[i].result == NULL) { + if (cred[i].result == NULL) return -1; - } cred[i].resultlen = strlen(cred[i].result); break; -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/esx/esx_driver.c | 390 +++++++++++++++++---------------------------------- 1 file changed, 130 insertions(+), 260 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index af567d2..1cbebb9 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -66,9 +66,8 @@ struct _esxVMX_Data { static void esxFreePrivate(esxPrivate **priv) { - if (!priv || !(*priv)) { + if (!priv || !(*priv)) return; - } esxVI_Context_Free(&(*priv)->host); esxVI_Context_Free(&(*priv)->vCenter); @@ -174,26 +173,22 @@ esxParseVMXFileName(const char *fileName, void *opaque) tmp = (char *)STRSKIP(fileName, hostMount->mountInfo->path); - if (!tmp) { + if (!tmp) continue; - } /* Found a match. Strip leading separators */ - while (*tmp == '/' || *tmp == '\\') { + while (*tmp == '/' || *tmp == '\\') ++tmp; - } - if (VIR_STRDUP(strippedFileName, tmp) < 0) { + if (VIR_STRDUP(strippedFileName, tmp) < 0) goto cleanup; - } tmp = strippedFileName; /* Convert \ to / */ while (*tmp != '\0') { - if (*tmp == '\\') { + if (*tmp == '\\') *tmp = '/'; - } ++tmp; } @@ -207,9 +202,8 @@ esxParseVMXFileName(const char *fileName, void *opaque) /* Fallback to direct datastore name match */ if (!result && STRPREFIX(fileName, "/vmfs/volumes/")) { - if (VIR_STRDUP(copyOfFileName, fileName) < 0) { + if (VIR_STRDUP(copyOfFileName, fileName) < 0) goto cleanup; - } /* Expected format: '/vmfs/volumes/<datastore>/<path>' */ if (!(tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) || @@ -244,9 +238,8 @@ esxParseVMXFileName(const char *fileName, void *opaque) /* If it's an absolute path outside of a datastore just use it as is */ if (!result && *fileName == '/') { /* FIXME: need to deal with Windows paths here too */ - if (VIR_STRDUP(result, fileName) < 0) { + if (VIR_STRDUP(result, fileName) < 0) goto cleanup; - } } if (!result) { @@ -312,16 +305,14 @@ esxFormatVMXFileName(const char *fileName, void *opaque) } /* Detect separator type */ - if (strchr(hostMount->mountInfo->path, '\\')) { + if (strchr(hostMount->mountInfo->path, '\\')) separator = '\\'; - } /* Strip trailing separators */ length = strlen(hostMount->mountInfo->path); - while (length > 0 && hostMount->mountInfo->path[length - 1] == separator) { + while (length > 0 && hostMount->mountInfo->path[length - 1] == separator) --length; - } /* Format as <mount>[/<directory>]/<file>, convert / to \ when necessary */ virBufferAdd(&buffer, hostMount->mountInfo->path, length); @@ -330,9 +321,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque) tmp = directoryAndFileName; while (*tmp != '\0') { - if (*tmp == '/') { + if (*tmp == '/') *tmp = separator; - } ++tmp; } @@ -347,9 +337,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque) result = virBufferContentAndReset(&buffer); } else if (*fileName == '/') { /* FIXME: need to deal with Windows paths here too */ - if (VIR_STRDUP(result, fileName) < 0) { + if (VIR_STRDUP(result, fileName) < 0) goto cleanup; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not handle file name '%s'"), fileName); @@ -451,13 +440,11 @@ esxSupportsLongMode(esxPrivate *priv) esxVI_ParsedHostCpuIdInfo parsedHostCpuIdInfo; char edxLongModeBit = '?'; - if (priv->supportsLongMode != esxVI_Boolean_Undefined) { + if (priv->supportsLongMode != esxVI_Boolean_Undefined) return priv->supportsLongMode; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return esxVI_Boolean_Undefined; - } if (esxVI_String_AppendValueToList(&propertyNameList, "hardware.cpuFeature") < 0 || @@ -529,9 +516,8 @@ esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid) esxVI_ObjectContent *hostSystem = NULL; char *uuid_string = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "hardware.systemInfo.uuid") < 0 || @@ -571,9 +557,8 @@ esxCapsInit(esxPrivate *priv) virCapsPtr caps = NULL; virCapsGuestPtr guest = NULL; - if (supportsLongMode == esxVI_Boolean_Undefined) { + if (supportsLongMode == esxVI_Boolean_Undefined) return NULL; - } if (supportsLongMode == esxVI_Boolean_True) { caps = virCapabilitiesNew(VIR_ARCH_X86_64, true, true); @@ -587,9 +572,8 @@ esxCapsInit(esxPrivate *priv) virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr"); - if (esxLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0) { + if (esxLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0) goto failure; - } /* i686 */ guest = virCapabilitiesAddGuest(caps, "hvm", @@ -597,13 +581,11 @@ esxCapsInit(esxPrivate *priv) NULL, NULL, 0, NULL); - if (!guest) { + if (!guest) goto failure; - } - if (!virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL)) { + if (!virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL)) goto failure; - } /* x86_64 */ if (supportsLongMode == esxVI_Boolean_True) { @@ -612,13 +594,11 @@ esxCapsInit(esxPrivate *priv) NULL, NULL, 0, NULL); - if (!guest) { + if (!guest) goto failure; - } - if (!virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL)) { + if (!virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL)) goto failure; - } } return caps; @@ -655,9 +635,8 @@ esxConnectToHost(esxPrivate *priv, return -1; } - if (esxUtil_ResolveHostname(conn->uri->server, ipAddress, NI_MAXHOST) < 0) { + if (esxUtil_ResolveHostname(conn->uri->server, ipAddress, NI_MAXHOST) < 0) return -1; - } if (conn->uri->user) { if (VIR_STRDUP(username, conn->uri->user) < 0) @@ -680,9 +659,8 @@ esxConnectToHost(esxPrivate *priv, password = esxUtil_EscapeForXml(unescapedPassword); - if (!password) { + if (!password) goto cleanup; - } if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport, conn->uri->server, conn->uri->port) < 0) @@ -720,9 +698,8 @@ esxConnectToHost(esxPrivate *priv, } /* Warn if host is in maintenance mode */ - if (inMaintenanceMode == esxVI_Boolean_True) { + if (inMaintenanceMode == esxVI_Boolean_True) VIR_WARN("The server is in maintenance mode"); - } if (VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) < 0) goto cleanup; @@ -763,14 +740,12 @@ esxConnectToVCenter(esxPrivate *priv, return -1; } - if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0) { + if (esxUtil_ResolveHostname(hostname, ipAddress, NI_MAXHOST) < 0) return -1; - } if (conn->uri->user) { - if (VIR_STRDUP(username, conn->uri->user) < 0) { + if (VIR_STRDUP(username, conn->uri->user) < 0) goto cleanup; - } } else { username = virAuthGetUsername(conn, auth, "esx", "administrator", hostname); @@ -789,9 +764,8 @@ esxConnectToVCenter(esxPrivate *priv, password = esxUtil_EscapeForXml(unescapedPassword); - if (!password) { + if (!password) goto cleanup; - } if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport, hostname, conn->uri->port) < 0) @@ -895,9 +869,8 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* Decline if the URI is NULL or the scheme is NULL */ - if (!conn->uri || !conn->uri->scheme) { + if (!conn->uri || !conn->uri->scheme) return VIR_DRV_OPEN_DECLINED; - } /* Decline if the scheme is not one of {vpx|esx|gsx} */ plus = strchr(conn->uri->scheme, '+'); @@ -946,9 +919,8 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, if (VIR_ALLOC(priv) < 0) goto cleanup; - if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0) { + if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0) goto cleanup; - } priv->maxVcpus = -1; priv->supportsVMotion = esxVI_Boolean_Undefined; @@ -1043,9 +1015,8 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, /* Setup capabilities */ priv->caps = esxCapsInit(priv); - if (!priv->caps) { + if (!priv->caps) goto cleanup; - } if (!(priv->xmlopt = virVMXDomainXMLConfInit())) goto cleanup; @@ -1098,13 +1069,11 @@ esxSupportsVMotion(esxPrivate *priv) esxVI_String *propertyNameList = NULL; esxVI_ObjectContent *hostSystem = NULL; - if (priv->supportsVMotion != esxVI_Boolean_Undefined) { + if (priv->supportsVMotion != esxVI_Boolean_Undefined) return priv->supportsVMotion; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return esxVI_Boolean_Undefined; - } if (esxVI_String_AppendValueToList(&propertyNameList, "capability.vmotionSupported") < 0 || @@ -1173,9 +1142,8 @@ esxConnectSupportsFeature(virConnectPtr conn, int feature) case VIR_DRV_FEATURE_MIGRATION_V1: supportsVMotion = esxSupportsVMotion(priv); - if (supportsVMotion == esxVI_Boolean_Undefined) { + if (supportsVMotion == esxVI_Boolean_Undefined) return -1; - } /* Migration is only possible via a vCenter and if VMotion is enabled */ return priv->vCenter && @@ -1219,9 +1187,8 @@ esxConnectGetHostname(virConnectPtr conn) const char *domainName = NULL; char *complete = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_String_AppendValueListToList (&propertyNameList, @@ -1301,9 +1268,8 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) memset(nodeinfo, 0, sizeof(*nodeinfo)); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "hardware.cpuInfo.hz\0" @@ -1448,13 +1414,11 @@ esxConnectListDomains(virConnectPtr conn, int *ids, int maxids) esxVI_VirtualMachinePowerState powerState; int count = 0; - if (maxids == 0) { + if (maxids == 0) return 0; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -1470,9 +1434,8 @@ esxConnectListDomains(virConnectPtr conn, int *ids, int maxids) goto cleanup; } - if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) { + if (powerState != esxVI_VirtualMachinePowerState_PoweredOn) continue; - } if (esxUtil_ParseVirtualMachineIDString(virtualMachine->obj->value, &ids[count]) < 0 || @@ -1485,9 +1448,8 @@ esxConnectListDomains(virConnectPtr conn, int *ids, int maxids) count++; - if (count >= maxids) { + if (count >= maxids) break; - } } success = true; @@ -1506,9 +1468,8 @@ esxConnectNumOfDomains(virConnectPtr conn) { esxPrivate *priv = conn->privateData; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return esxVI_LookupNumberOfDomainsByPowerState (priv->primary, esxVI_VirtualMachinePowerState_PoweredOn, false); @@ -1529,9 +1490,8 @@ esxDomainLookupByID(virConnectPtr conn, int id) unsigned char uuid_candidate[VIR_UUID_BUFLEN]; virDomainPtr domain = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "configStatus\0" @@ -1551,9 +1511,8 @@ esxDomainLookupByID(virConnectPtr conn, int id) } /* Only running/suspended domains have an ID != -1 */ - if (powerState == esxVI_VirtualMachinePowerState_PoweredOff) { + if (powerState == esxVI_VirtualMachinePowerState_PoweredOff) continue; - } VIR_FREE(name_candidate); @@ -1563,24 +1522,21 @@ esxDomainLookupByID(virConnectPtr conn, int id) goto cleanup; } - if (id != id_candidate) { + if (id != id_candidate) continue; - } domain = virGetDomain(conn, name_candidate, uuid_candidate); - if (!domain) { + if (!domain) goto cleanup; - } domain->id = id; break; } - if (!domain) { + if (!domain) virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id); - } cleanup: esxVI_String_Free(&propertyNameList); @@ -1603,9 +1559,8 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) char *name = NULL; virDomainPtr domain = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "name\0" @@ -1620,9 +1575,8 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) domain = virGetDomain(conn, name, uuid); - if (!domain) { + if (!domain) goto cleanup; - } /* Only running/suspended virtual machines have an ID != -1 */ if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { @@ -1652,9 +1606,8 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) unsigned char uuid[VIR_UUID_BUFLEN]; virDomainPtr domain = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "configStatus\0" @@ -1678,9 +1631,8 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) domain = virGetDomain(conn, name, uuid); - if (!domain) { + if (!domain) goto cleanup; - } /* Only running/suspended virtual machines have an ID != -1 */ if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { @@ -1710,9 +1662,8 @@ esxDomainSuspend(virDomainPtr domain) esxVI_TaskInfoState taskInfoState; char *taskInfoErrorMessage = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -1768,9 +1719,8 @@ esxDomainResume(virDomainPtr domain) esxVI_TaskInfoState taskInfoState; char *taskInfoErrorMessage = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -1825,9 +1775,8 @@ esxDomainShutdownFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -1844,9 +1793,8 @@ esxDomainShutdownFlags(virDomainPtr domain, unsigned int flags) goto cleanup; } - if (esxVI_ShutdownGuest(priv->primary, virtualMachine->obj) < 0) { + if (esxVI_ShutdownGuest(priv->primary, virtualMachine->obj) < 0) goto cleanup; - } result = 0; @@ -1876,9 +1824,8 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -1895,9 +1842,8 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags) goto cleanup; } - if (esxVI_RebootGuest(priv->primary, virtualMachine->obj) < 0) { + if (esxVI_RebootGuest(priv->primary, virtualMachine->obj) < 0) goto cleanup; - } result = 0; @@ -1932,9 +1878,8 @@ esxDomainDestroyFlags(virDomainPtr domain, ctx = priv->host; } - if (esxVI_EnsureSession(ctx) < 0) { + if (esxVI_EnsureSession(ctx) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -2005,9 +1950,8 @@ esxDomainGetMaxMemory(virDomainPtr domain) esxVI_DynamicProperty *dynamicProperty = NULL; unsigned long memoryMB = 0; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return 0; - } if (esxVI_String_AppendValueToList(&propertyNameList, "config.hardware.memoryMB") < 0 || @@ -2061,9 +2005,8 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) esxVI_TaskInfoState taskInfoState; char *taskInfoErrorMessage = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -2130,9 +2073,8 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory) esxVI_TaskInfoState taskInfoState; char *taskInfoErrorMessage = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask (priv->primary, domain->uuid, NULL, &virtualMachine, @@ -2211,9 +2153,8 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) memset(info, 0, sizeof(*info)); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "runtime.powerState\0" @@ -2261,9 +2202,8 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) memory_limit = dynamicProperty->val->int64; - if (memory_limit > 0) { + if (memory_limit > 0) memory_limit *= 1024; /* Scale from megabyte to kilobyte */ - } } else { VIR_WARN("Unexpected '%s' property", dynamicProperty->name); } @@ -2277,15 +2217,13 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) /* FIXME: Currently no host for a vpx:// connection */ if (priv->host) { if (info->state == VIR_DOMAIN_RUNNING && priv->usedCpuTimeCounterId >= 0) { - if (esxVI_Int_Alloc(&counterId) < 0) { + if (esxVI_Int_Alloc(&counterId) < 0) goto cleanup; - } counterId->value = priv->usedCpuTimeCounterId; - if (esxVI_Int_AppendToList(&counterIdList, counterId) < 0) { + if (esxVI_Int_AppendToList(&counterIdList, counterId) < 0) goto cleanup; - } if (esxVI_QueryPerfCounter(priv->host, counterIdList, &perfCounterInfo) < 0) { @@ -2353,9 +2291,8 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) } } - if (priv->usedCpuTimeCounterId < 0) { + if (priv->usedCpuTimeCounterId < 0) VIR_WARN("Could not find 'used CPU time' performance counter"); - } } /* @@ -2442,9 +2379,8 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) querySpec->entity = NULL; querySpec->format = NULL; - if (querySpec->metricId) { + if (querySpec->metricId) querySpec->metricId->instance = NULL; - } } #endif @@ -2477,9 +2413,8 @@ esxDomainGetState(virDomainPtr domain, virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -2608,15 +2543,13 @@ esxDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus, return -1; } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } maxVcpus = esxDomainGetMaxVcpus(domain); - if (maxVcpus < 0) { + if (maxVcpus < 0) return -1; - } if (nvcpus > maxVcpus) { virReportError(VIR_ERR_INVALID_ARG, @@ -2686,15 +2619,13 @@ esxDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) return -1; } - if (priv->maxVcpus > 0) { + if (priv->maxVcpus > 0) return priv->maxVcpus; - } priv->maxVcpus = -1; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "capability.maxSupportedVcpus") < 0 || @@ -2760,9 +2691,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) memset(&data, 0, sizeof(data)); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "config.files.vmPathName\0" @@ -2795,9 +2725,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) url = virBufferContentAndReset(&buffer); - if (esxVI_CURL_Download(priv->primary->curl, url, &vmx, 0, NULL) < 0) { + if (esxVI_CURL_Download(priv->primary->curl, url, &vmx, 0, NULL) < 0) goto cleanup; - } data.ctx = priv->primary; @@ -2819,17 +2748,15 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def = virVMXParseConfig(&ctx, priv->xmlopt, vmx); if (def) { - if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { + if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) def->id = id; - } xml = virDomainDefFormat(def, flags); } cleanup: - if (!url) { + if (!url) virBufferFreeAndReset(&buffer); - } esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&virtualMachine); @@ -2877,9 +2804,8 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, priv->xmlopt, nativeConfig); - if (def) { + if (def) xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE); - } virDomainDefFree(def); @@ -2913,17 +2839,15 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, virtualHW_version = esxVI_ProductVersionToDefaultVirtualHWVersion (priv->primary->productLine, priv->primary->productVersion); - if (virtualHW_version < 0) { + if (virtualHW_version < 0) return NULL; - } def = virDomainDefParseString(domainXml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE); - if (!def) { + if (!def) return NULL; - } data.ctx = priv->primary; data.datastorePathWithoutFileName = NULL; @@ -2954,13 +2878,11 @@ esxConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxname int count = 0; size_t i; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "name\0" @@ -2977,9 +2899,8 @@ esxConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxname goto cleanup; } - if (powerState == esxVI_VirtualMachinePowerState_PoweredOn) { + if (powerState == esxVI_VirtualMachinePowerState_PoweredOn) continue; - } names[count] = NULL; @@ -2990,18 +2911,16 @@ esxConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxname ++count; - if (count >= maxnames) { + if (count >= maxnames) break; - } } success = true; cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -3019,9 +2938,8 @@ esxConnectNumOfDefinedDomains(virConnectPtr conn) { esxPrivate *priv = conn->privateData; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return esxVI_LookupNumberOfDomainsByPowerState (priv->primary, esxVI_VirtualMachinePowerState_PoweredOn, true); @@ -3044,9 +2962,8 @@ esxDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -3130,18 +3047,16 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) memset(&data, 0, sizeof(data)); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } /* Parse domain XML */ def = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE); - if (!def) { + if (!def) return NULL; - } /* Check if an existing domain should be edited */ if (esxVI_LookupVirtualMachineByUuid(priv->primary, def->uuid, NULL, @@ -3169,9 +3084,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) virtualHW_version = esxVI_ProductVersionToDefaultVirtualHWVersion (priv->primary->productLine, priv->primary->productVersion); - if (virtualHW_version < 0) { + if (virtualHW_version < 0) goto cleanup; - } data.ctx = priv->primary; data.datastorePathWithoutFileName = NULL; @@ -3183,9 +3097,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) vmx = virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version); - if (!vmx) { + if (!vmx) goto cleanup; - } /* * Build VMX datastore URL. Use the source of the first file-based harddisk @@ -3246,9 +3159,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) escapedName = esxUtil_EscapeDatastoreItem(def->name); - if (!escapedName) { + if (!escapedName) goto cleanup; - } virBufferURIEncodeString(&buffer, escapedName); virBufferAddLit(&buffer, ".vmx?dcPath="); @@ -3267,9 +3179,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) /* Upload VMX file */ VIR_DEBUG("Uploading .vmx config, url='%s' vmx='%s'", url, vmx); - if (esxVI_CURL_Upload(priv->primary->curl, url, vmx) < 0) { + if (esxVI_CURL_Upload(priv->primary->curl, url, vmx) < 0) goto cleanup; - } /* Register the domain */ if (directoryName) { @@ -3302,16 +3213,14 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) domain = virGetDomain(conn, def->name, def->uuid); - if (domain) { + if (domain) domain->id = -1; - } /* FIXME: Add proper rollback in case of an error */ cleanup: - if (!url) { + if (!url) virBufferFreeAndReset(&buffer); - } virDomainDefFree(def); VIR_FREE(vmx); @@ -3354,9 +3263,8 @@ esxDomainUndefineFlags(virDomainPtr domain, ctx = priv->host; } - if (esxVI_EnsureSession(ctx) < 0) { + if (esxVI_EnsureSession(ctx) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -3374,9 +3282,8 @@ esxDomainUndefineFlags(virDomainPtr domain, goto cleanup; } - if (esxVI_UnregisterVM(ctx, virtualMachine->obj) < 0) { + if (esxVI_UnregisterVM(ctx, virtualMachine->obj) < 0) goto cleanup; - } result = 0; @@ -3407,14 +3314,12 @@ esxDomainGetAutostart(virDomainPtr domain, int *autostart) *autostart = 0; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } /* Check general autostart config */ - if (esxVI_LookupAutoStartDefaults(priv->primary, &defaults) < 0) { + if (esxVI_LookupAutoStartDefaults(priv->primary, &defaults) < 0) goto cleanup; - } if (defaults->enabled != esxVI_Boolean_True) { /* Autostart is disabled in general, exit early here */ @@ -3423,9 +3328,8 @@ esxDomainGetAutostart(virDomainPtr domain, int *autostart) } /* Check specific autostart config */ - if (esxVI_LookupAutoStartPowerInfoList(priv->primary, &powerInfoList) < 0) { + if (esxVI_LookupAutoStartPowerInfoList(priv->primary, &powerInfoList) < 0) goto cleanup; - } if (!powerInfoList) { /* powerInfo list is empty, exit early here */ @@ -3442,9 +3346,8 @@ esxDomainGetAutostart(virDomainPtr domain, int *autostart) for (powerInfo = powerInfoList; powerInfo; powerInfo = powerInfo->_next) { if (STREQ(powerInfo->key->value, virtualMachine->obj->value)) { - if (STRCASEEQ(powerInfo->startAction, "powerOn")) { + if (STRCASEEQ(powerInfo->startAction, "powerOn")) *autostart = 1; - } break; } @@ -3475,9 +3378,8 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) esxVI_AutoStartPowerInfo *powerInfo = NULL; esxVI_AutoStartPowerInfo *newPowerInfo = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid, NULL, &virtualMachine, @@ -3493,9 +3395,8 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) * autostart. If it's enabled then the autostart behavior depends on * the per-domain autostart config. */ - if (esxVI_LookupAutoStartDefaults(priv->primary, &defaults) < 0) { + if (esxVI_LookupAutoStartDefaults(priv->primary, &defaults) < 0) goto cleanup; - } if (defaults->enabled != esxVI_Boolean_True) { /* @@ -3520,9 +3421,8 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) } /* Enable autostart in general */ - if (esxVI_AutoStartDefaults_Alloc(&spec->defaults) < 0) { + if (esxVI_AutoStartDefaults_Alloc(&spec->defaults) < 0) goto cleanup; - } spec->defaults->enabled = esxVI_Boolean_True; } @@ -3616,9 +3516,8 @@ esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) if (VIR_STRDUP(type, "allocation") < 0) return NULL; - if (nparams) { + if (nparams) *nparams = 3; /* reservation, limit, shares */ - } return type; } @@ -3641,9 +3540,8 @@ esxDomainGetSchedulerParametersFlags(virDomainPtr domain, virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueListToList(&propertyNameList, "config.cpuAllocation.reservation\0" @@ -3775,9 +3673,8 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain, NULL) < 0) return -1; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask (priv->primary, domain->uuid, NULL, &virtualMachine, @@ -3789,9 +3686,8 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain, for (i = 0; i < nparams; ++i) { if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_RESERVATION)) { - if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) { + if (esxVI_Long_Alloc(&spec->cpuAllocation->reservation) < 0) goto cleanup; - } if (params[i].value.l < 0) { virReportError(VIR_ERR_INVALID_ARG, @@ -3802,9 +3698,8 @@ esxDomainSetSchedulerParametersFlags(virDomainPtr domain, spec->cpuAllocation->reservation->value = params[i].value.l; } else if (STREQ(params[i].field, VIR_DOMAIN_SCHEDULER_LIMIT)) { - if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) { + if (esxVI_Long_Alloc(&spec->cpuAllocation->limit) < 0) goto cleanup; - } if (params[i].value.l < -1) { virReportError(VIR_ERR_INVALID_ARG, @@ -3963,9 +3858,8 @@ esxDomainMigratePerform(virDomainPtr domain, return -1; } - if (esxVI_EnsureSession(priv->vCenter) < 0) { + if (esxVI_EnsureSession(priv->vCenter) < 0) return -1; - } /* Parse migration URI */ if (!(parsedUri = virURIParse(uri))) @@ -4094,9 +3988,8 @@ esxNodeGetFreeMemory(virConnectPtr conn) esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_ResourcePoolResourceUsage *resourcePoolResourceUsage = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return 0; - } /* Get memory usage of resource pool */ if (esxVI_String_AppendValueToList(&propertyNameList, @@ -4195,9 +4088,8 @@ esxDomainIsActive(virDomainPtr domain) esxVI_String *propertyNameList = NULL; esxVI_VirtualMachinePowerState powerState; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList(&propertyNameList, "runtime.powerState") < 0 || @@ -4299,16 +4191,14 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE | VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } def = virDomainSnapshotDefParseString(xmlDesc, priv->caps, priv->xmlopt, 0, 0); - if (!def) { + if (!def) return NULL; - } if (def->ndisks) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -4381,9 +4271,8 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, memset(&def, 0, sizeof(def)); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, &rootSnapshotList) < 0 || @@ -4433,9 +4322,8 @@ esxDomainSnapshotNum(virDomainPtr domain, unsigned int flags) recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) == 0; leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } /* ESX snapshots do not require libvirt to maintain any metadata. */ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) @@ -4478,13 +4366,11 @@ esxDomainSnapshotListNames(virDomainPtr domain, char **names, int nameslen, return -1; } - if (nameslen == 0 || (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)) { + if (nameslen == 0 || (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)) return 0; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid, &rootSnapshotTreeList) < 0) { @@ -4518,9 +4404,8 @@ esxDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot, unsigned int flags) recurse = (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) != 0; leaves = (flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) != 0; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, &rootSnapshotTreeList) < 0 || @@ -4571,13 +4456,11 @@ esxDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot, return -1; } - if (nameslen == 0) { + if (nameslen == 0) return 0; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, &rootSnapshotTreeList) < 0 || @@ -4615,9 +4498,8 @@ esxDomainSnapshotLookupByName(virDomainPtr domain, const char *name, virCheckFlags(0, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, domain->uuid, &rootSnapshotTreeList) < 0 || @@ -4645,9 +4527,8 @@ esxDomainHasCurrentSnapshot(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupCurrentSnapshotTree(priv->primary, domain->uuid, ¤tSnapshotTree, @@ -4676,9 +4557,8 @@ esxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(0, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, &rootSnapshotList) < 0 || @@ -4714,9 +4594,8 @@ esxDomainSnapshotCurrent(virDomainPtr domain, unsigned int flags) virCheckFlags(0, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (esxVI_LookupCurrentSnapshotTree(priv->primary, domain->uuid, ¤tSnapshotTree, @@ -4743,9 +4622,8 @@ esxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } /* Check that snapshot exists. */ if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, @@ -4781,9 +4659,8 @@ esxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } /* Check that snapshot exists. If so, there is no metadata. */ if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, @@ -4815,9 +4692,8 @@ esxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(0, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, &rootSnapshotList) < 0 || @@ -4870,13 +4746,11 @@ esxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, unsigned int flags) virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) { + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) removeChildren = esxVI_Boolean_True; - } if (esxVI_LookupRootSnapshotTreeList(priv->primary, snapshot->domain->uuid, &rootSnapshotList) < 0 || @@ -4941,9 +4815,8 @@ esxDomainSetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params, NULL) < 0) return -1; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_LookupVirtualMachineByUuidAndPrepareForTask (priv->primary, domain->uuid, NULL, &virtualMachine, @@ -4955,9 +4828,8 @@ esxDomainSetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params, for (i = 0; i < nparams; ++i) { if (STREQ(params[i].field, VIR_DOMAIN_MEMORY_MIN_GUARANTEE)) { - if (esxVI_Long_Alloc(&spec->memoryAllocation->reservation) < 0) { + if (esxVI_Long_Alloc(&spec->memoryAllocation->reservation) < 0) goto cleanup; - } spec->memoryAllocation->reservation->value = VIR_DIV_UP(params[i].value.ul, 1024); /* Scale from kilobytes to megabytes */ @@ -5010,9 +4882,8 @@ esxDomainGetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params, return 0; } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } if (esxVI_String_AppendValueToList (&propertyNameList, "config.memoryAllocation.reservation") < 0 || @@ -5249,9 +5120,8 @@ esxConnectListAllDomains(virConnectPtr conn, cleanup: if (doms) { - for (id = 0; id < count; id++) { + for (id = 0; id < count; id++) virDomainFree(doms[id]); - } VIR_FREE(doms); } -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/esx/esx_device_monitor.c | 3 +- src/esx/esx_interface_driver.c | 12 +- src/esx/esx_network_driver.c | 57 +++------ src/esx/esx_nwfilter_driver.c | 3 +- src/esx/esx_secret_driver.c | 3 +- src/esx/esx_storage_backend_iscsi.c | 45 +++---- src/esx/esx_storage_backend_vmfs.c | 51 +++----- src/esx/esx_storage_driver.c | 81 ++++-------- src/esx/esx_util.c | 45 +++---- src/esx/esx_vi.c | 249 ++++++++++++------------------------ src/esx/esx_vi_types.c | 45 +++---- 11 files changed, 198 insertions(+), 396 deletions(-) diff --git a/src/esx/esx_device_monitor.c b/src/esx/esx_device_monitor.c index 613cef6..bf71145 100644 --- a/src/esx/esx_device_monitor.c +++ b/src/esx/esx_device_monitor.c @@ -43,9 +43,8 @@ esxNodeDeviceOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_ESX) { + if (conn->driver->no != VIR_DRV_ESX) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index 5fb9b1a..20c9361 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -46,9 +46,8 @@ esxInterfaceOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_ESX) { + if (conn->driver->no != VIR_DRV_ESX) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } @@ -98,9 +97,8 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames) int count = 0; size_t i; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } if (esxVI_EnsureSession(priv->primary) < 0 || esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) { @@ -119,9 +117,8 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames) cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -234,9 +231,8 @@ esxInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags) if (physicalNic->spec->ip) { protocol.family = (char *)"ipv4"; - if (physicalNic->spec->ip->dhcp == esxVI_Boolean_True) { + if (physicalNic->spec->ip->dhcp == esxVI_Boolean_True) protocol.dhcp = 1; - } if (physicalNic->spec->ip->ipAddress && physicalNic->spec->ip->subnetMask && diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 6fae4ff..8defcd6 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -52,9 +52,8 @@ esxNetworkOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_ESX) { + if (conn->driver->no != VIR_DRV_ESX) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } @@ -105,9 +104,8 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames) int count = 0; size_t i; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } if (esxVI_EnsureSession(priv->primary) < 0 || esxVI_LookupHostVirtualSwitchList(priv->primary, @@ -127,9 +125,8 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames) cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -181,9 +178,8 @@ esxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) hostVirtualSwitch = hostVirtualSwitch->_next) { md5_buffer(hostVirtualSwitch->key, strlen(hostVirtualSwitch->key), md5); - if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) { + if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) break; - } } if (!hostVirtualSwitch) { @@ -265,34 +261,30 @@ esxBandwidthToShapingPolicy(virNetDevBandwidthPtr bandwidth, return 0; } - if (esxVI_HostNetworkTrafficShapingPolicy_Alloc(shapingPolicy) < 0) { + if (esxVI_HostNetworkTrafficShapingPolicy_Alloc(shapingPolicy) < 0) goto cleanup; - } (*shapingPolicy)->enabled = esxVI_Boolean_True; if (bandwidth->in->average > 0) { - if (esxVI_Long_Alloc(&(*shapingPolicy)->averageBandwidth) < 0) { + if (esxVI_Long_Alloc(&(*shapingPolicy)->averageBandwidth) < 0) goto cleanup; - } /* Scale kilobytes per second to bits per second */ (*shapingPolicy)->averageBandwidth->value = bandwidth->in->average * 8 * 1000; } if (bandwidth->in->peak > 0) { - if (esxVI_Long_Alloc(&(*shapingPolicy)->peakBandwidth) < 0) { + if (esxVI_Long_Alloc(&(*shapingPolicy)->peakBandwidth) < 0) goto cleanup; - } /* Scale kilobytes per second to bits per second */ (*shapingPolicy)->peakBandwidth->value = bandwidth->in->peak * 8 * 1000; } if (bandwidth->in->burst > 0) { - if (esxVI_Long_Alloc(&(*shapingPolicy)->burstSize) < 0) { + if (esxVI_Long_Alloc(&(*shapingPolicy)->burstSize) < 0) goto cleanup; - } /* Scale kilobytes to bytes */ (*shapingPolicy)->burstSize->value = bandwidth->in->burst * 1024; @@ -301,9 +293,8 @@ esxBandwidthToShapingPolicy(virNetDevBandwidthPtr bandwidth, result = 0; cleanup: - if (result < 0) { + if (result < 0) esxVI_HostNetworkTrafficShapingPolicy_Free(shapingPolicy); - } return result; } @@ -328,16 +319,14 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) unsigned char md5[MD5_DIGEST_SIZE]; /* MD5_DIGEST_SIZE = VIR_UUID_BUFLEN = 16 */ - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } /* Parse network XML */ def = virNetworkDefParseString(xml); - if (!def) { + if (!def) return NULL; - } /* Check if an existing HostVirtualSwitch should be edited */ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, def->name, @@ -372,9 +361,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) /* Verify that specified HostPortGroups don't exist already */ if (def->nPortGroups > 0) { - if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) { + if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) goto cleanup; - } for (i = 0; i < def->nPortGroups; ++i) { for (hostPortGroup = hostPortGroupList; hostPortGroup; @@ -405,9 +393,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) (esxVI_HostVirtualSwitchBridge *)hostVirtualSwitchBondBridge; /* Lookup PhysicalNic list and match by name to get key */ - if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) { + if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) goto cleanup; - } for (i = 0; i < def->forward.nifs; ++i) { bool found = false; @@ -447,9 +434,8 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml) hostVirtualSwitchSpec->numPorts->value = 128; if (def->bandwidth) { - if (esxVI_HostNetworkPolicy_Alloc(&hostVirtualSwitchSpec->policy) < 0) { + if (esxVI_HostNetworkPolicy_Alloc(&hostVirtualSwitchSpec->policy) < 0) goto cleanup; - } if (esxBandwidthToShapingPolicy (def->bandwidth, @@ -530,9 +516,8 @@ esxNetworkUndefine(virNetworkPtr network) esxVI_HostPortGroup *hostPortGroup = NULL; esxVI_HostPortGroupPort *hostPortGroupPort = NULL; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } /* Lookup HostVirtualSwitch and HostPortGroup list*/ if (esxVI_LookupHostVirtualSwitchByName(priv->primary, network->name, @@ -630,9 +615,8 @@ esxShapingPolicyToBandwidth(esxVI_HostNetworkTrafficShapingPolicy *shapingPolicy return -1; } - if (!shapingPolicy || shapingPolicy->enabled != esxVI_Boolean_True) { + if (!shapingPolicy || shapingPolicy->enabled != esxVI_Boolean_True) return 0; - } if (VIR_ALLOC(*bandwidth) < 0 || VIR_ALLOC((*bandwidth)->in) < 0 || @@ -682,9 +666,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) esxVI_String *networkName = NULL; virNetworkDefPtr def; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } if (VIR_ALLOC(def) < 0) goto cleanup; @@ -718,9 +701,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) goto cleanup; /* Find PhysicalNic by key */ - if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) { + if (esxVI_LookupPhysicalNicList(priv->primary, &physicalNicList) < 0) goto cleanup; - } for (physicalNicKey = hostVirtualSwitch->pnic; physicalNicKey; physicalNicKey = physicalNicKey->_next) { @@ -781,9 +763,8 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) } /* Find HostPortGroup by key */ - if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) { + if (esxVI_LookupHostPortGroupList(priv->primary, &hostPortGroupList) < 0) goto cleanup; - } for (hostPortGroupKey = hostVirtualSwitch->portgroup; hostPortGroupKey; hostPortGroupKey = hostPortGroupKey->_next) { diff --git a/src/esx/esx_nwfilter_driver.c b/src/esx/esx_nwfilter_driver.c index d7ab60f..705035c 100644 --- a/src/esx/esx_nwfilter_driver.c +++ b/src/esx/esx_nwfilter_driver.c @@ -43,9 +43,8 @@ esxNWFilterOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_ESX) { + if (conn->driver->no != VIR_DRV_ESX) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/esx/esx_secret_driver.c b/src/esx/esx_secret_driver.c index 4ce8ae4..de398af 100644 --- a/src/esx/esx_secret_driver.c +++ b/src/esx/esx_secret_driver.c @@ -41,9 +41,8 @@ esxSecretOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_ESX) { + if (conn->driver->no != VIR_DRV_ESX) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c index 2e2a270..e4d2692 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -104,9 +104,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, esxVI_HostInternetScsiHbaStaticTarget *target; size_t i; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba) < 0) { @@ -140,9 +139,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } } esxVI_HostInternetScsiHba_Free(&hostInternetScsiHba); @@ -222,9 +220,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, target; target = target->_next) { md5_buffer(target->iScsiName, strlen(target->iScsiName), md5); - if (memcmp(uuid, md5, VIR_UUID_STRING_BUFLEN) == 0) { + if (memcmp(uuid, md5, VIR_UUID_STRING_BUFLEN) == 0) break; - } } if (!target) { @@ -304,15 +301,13 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) memset(&def, 0, sizeof(def)); - if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba)) { + if (esxVI_LookupHostInternetScsiHba(priv->primary, &hostInternetScsiHba)) goto cleanup; - } for (target = hostInternetScsiHba->configuredStaticTarget; target; target = target->_next) { - if (STREQ(target->iScsiName, pool->name)) { + if (STREQ(target->iScsiName, pool->name)) break; - } } if (!target) { @@ -338,9 +333,8 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) def.source.hosts[0].name = target->address; - if (target->port) { + if (target->port) def.source.hosts[0].port = target->port->value; - } /* TODO: add CHAP authentication params */ xml = virStoragePoolDefFormat(&def); @@ -403,9 +397,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, return 0; } - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) { + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; - } for (scsiLun = scsiLunList; scsiLun && count < maxnames; scsiLun = scsiLun->_next) { @@ -425,9 +418,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -452,9 +444,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, unsigned char md5[MD5_DIGEST_SIZE]; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) { + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; - } for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) { @@ -500,9 +491,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path) unsigned char md5[MD5_DIGEST_SIZE]; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) { + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; - } for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) { hostScsiDisk = esxVI_HostScsiDisk_DynamicCast(scsiLun); @@ -548,13 +538,11 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key) char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; /* key may be LUN device path */ - if (STRPREFIX(key, "/")) { + if (STRPREFIX(key, "/")) return esxStorageVolLookupByPath(conn, key); - } - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) { + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; - } for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) { @@ -631,9 +619,8 @@ esxStorageVolGetInfo(virStorageVolPtr volume, esxVI_ScsiLun *scsiLun; esxVI_HostScsiDisk *hostScsiDisk = NULL; - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) { + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; - } for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) { @@ -687,9 +674,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, memset(&pool, 0, sizeof(pool)); memset(&def, 0, sizeof(def)); - if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) { + if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) goto cleanup; - } for (scsiLun = scsiLunList; scsiLun; scsiLun = scsiLun->_next) { @@ -715,9 +701,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, virUUIDFormat(md5, uuid_string); - if (VIR_STRDUP(def.key, uuid_string) < 0) { + if (VIR_STRDUP(def.key, uuid_string) < 0) goto cleanup; - } /* iSCSI LUN exposes a block device */ def.type = VIR_STORAGE_VOL_BLOCK; diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backend_vmfs.c index 2e163c1..fa423e9 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -120,9 +120,8 @@ esxConnectNumOfStoragePools(virConnectPtr conn) esxVI_ObjectContent *datastoreList = NULL; esxVI_ObjectContent *datastore = NULL; - if (esxVI_LookupDatastoreList(priv->primary, NULL, &datastoreList) < 0) { + if (esxVI_LookupDatastoreList(priv->primary, NULL, &datastoreList) < 0) return -1; - } for (datastore = datastoreList; datastore; datastore = datastore->_next) { @@ -149,9 +148,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, int count = 0; size_t i; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } if (esxVI_String_AppendValueToList(&propertyNameList, "summary.name") < 0 || @@ -185,9 +183,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -295,9 +292,8 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, md5_buffer(hostMount->mountInfo->path, strlen(hostMount->mountInfo->path), md5); - if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) { + if (memcmp(uuid, md5, VIR_UUID_BUFLEN) == 0) break; - } } if (!datastore) { @@ -580,9 +576,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, return -1; } - if (maxnames == 0) { + if (maxnames == 0) return 0; - } if (esxVI_LookupDatastoreContentByDatastoreName(priv->primary, pool->name, &searchResultsList) < 0) { @@ -626,9 +621,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -807,9 +801,8 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key) goto cleanup; } - if (esxUtil_ReformatUuid(uuid_string, key_candidate) < 0) { + if (esxUtil_ReformatUuid(uuid_string, key_candidate) < 0) goto cleanup; - } if (STREQ(key, key_candidate)) { /* Found matching UUID */ @@ -873,9 +866,8 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, /* Parse config */ def = virStorageVolDefParseString(&poolDef, xmldesc); - if (!def) { + if (!def) goto cleanup; - } if (def->type != VIR_STORAGE_VOL_FILE) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -914,16 +906,14 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, directoryName = esxUtil_EscapeDatastoreItem(unescapedDirectoryName); - if (!directoryName) { + if (!directoryName) goto cleanup; - } fileName = esxUtil_EscapeDatastoreItem(unescapedDirectoryAndFileName + strlen(unescapedDirectoryName) + 1); - if (!fileName) { + if (!fileName) goto cleanup; - } if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name, directoryName) < 0) @@ -1012,14 +1002,12 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, goto cleanup; } - if (esxUtil_ReformatUuid(uuid_string, key) < 0) { + if (esxUtil_ReformatUuid(uuid_string, key) < 0) goto cleanup; - } } else { /* Fall back to the path as key */ - if (VIR_STRDUP(key, datastorePath) < 0) { + if (VIR_STRDUP(key, datastorePath) < 0) goto cleanup; - } } } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1099,9 +1087,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, /* Parse config */ def = virStorageVolDefParseString(&poolDef, xmldesc); - if (!def) { + if (!def) goto cleanup; - } if (def->type != VIR_STORAGE_VOL_FILE) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1140,16 +1127,14 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, directoryName = esxUtil_EscapeDatastoreItem(unescapedDirectoryName); - if (!directoryName) { + if (!directoryName) goto cleanup; - } fileName = esxUtil_EscapeDatastoreItem(unescapedDirectoryAndFileName + strlen(unescapedDirectoryName) + 1); - if (!fileName) { + if (!fileName) goto cleanup; - } if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name, directoryName) < 0) @@ -1204,14 +1189,12 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - if (esxUtil_ReformatUuid(uuid_string, key) < 0) { + if (esxUtil_ReformatUuid(uuid_string, key) < 0) goto cleanup; - } } else { /* Fall back to the path as key */ - if (VIR_STRDUP(key, datastorePath) < 0) { + if (VIR_STRDUP(key, datastorePath) < 0) goto cleanup; - } } } else { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/esx/esx_storage_driver.c b/src/esx/esx_storage_driver.c index ff3f167..b8e2fda 100644 --- a/src/esx/esx_storage_driver.c +++ b/src/esx/esx_storage_driver.c @@ -60,9 +60,8 @@ esxStorageOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_ESX) { + if (conn->driver->no != VIR_DRV_ESX) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } @@ -85,16 +84,14 @@ esxConnectNumOfStoragePools(virConnectPtr conn) size_t i; int tmp; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } for (i = 0; i < LAST_BACKEND; ++i) { tmp = backends[i]->connectNumOfStoragePools(conn); - if (tmp < 0) { + if (tmp < 0) return -1; - } count += tmp; } @@ -113,20 +110,17 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, int maxnames) size_t i; int tmp; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } for (i = 0; i < LAST_BACKEND; ++i) { tmp = backends[i]->connectListStoragePools(conn, &names[count], maxnames - count); - if (tmp < 0) { + if (tmp < 0) goto cleanup; - } count += tmp; } @@ -135,9 +129,8 @@ esxConnectListStoragePools(virConnectPtr conn, char **const names, int maxnames) cleanup: if (! success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -176,16 +169,14 @@ esxStoragePoolLookupByName(virConnectPtr conn, const char *name) virCheckNonNullArgReturn(name, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } for (i = 0; i < LAST_BACKEND; ++i) { pool = backends[i]->storagePoolLookupByName(conn, name); - if (pool) { + if (pool) return pool; - } } virReportError(VIR_ERR_NO_STORAGE_POOL, @@ -204,17 +195,15 @@ esxStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virStoragePoolPtr pool; char uuid_string[VIR_UUID_STRING_BUFLEN] = ""; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } /* invoke backend drive method to search all known pools */ for (i = 0; i < LAST_BACKEND; ++i) { pool = backends[i]->storagePoolLookupByUUID(conn, uuid); - if (pool) { + if (pool) return pool; - } } virUUIDFormat(uuid, uuid_string); @@ -243,9 +232,8 @@ esxStoragePoolRefresh(virStoragePoolPtr pool, unsigned int flags) virCheckNonNullArgReturn(pool->privateData, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storagePoolRefresh(pool, flags); } @@ -262,9 +250,8 @@ esxStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) memset(info, 0, sizeof(*info)); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storagePoolGetInfo(pool, info); } @@ -279,9 +266,8 @@ esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags) virCheckNonNullArgReturn(pool->privateData, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } return backend->storagePoolGetXMLDesc(pool, flags); } @@ -326,9 +312,8 @@ esxStoragePoolNumOfVolumes(virStoragePoolPtr pool) virCheckNonNullArgReturn(pool->privateData, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storagePoolNumOfVolumes(pool); } @@ -344,9 +329,8 @@ esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, virCheckNonNullArgReturn(pool->privateData, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storagePoolListVolumes(pool, names, maxnames); } @@ -361,9 +345,8 @@ esxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) virCheckNonNullArgReturn(pool->privateData, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } return backend->storageVolLookupByName(pool, name); } @@ -375,9 +358,8 @@ esxStorageVolLookupByPath(virConnectPtr conn, const char *path) { esxPrivate *priv = conn->privateData; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } /* * FIXME: calling backends blindly may set unwanted error codes @@ -408,16 +390,14 @@ esxStorageVolLookupByKey(virConnectPtr conn, const char *key) esxPrivate *priv = conn->privateData; size_t i; - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } for (i = 0; i < LAST_BACKEND; ++i) { volume = backends[i]->storageVolLookupByKey(conn, key); - if (volume) { + if (volume) return volume; - } } virReportError(VIR_ERR_NO_STORAGE_VOL, @@ -438,9 +418,8 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc, virCheckNonNullArgReturn(pool->privateData, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } return backend->storageVolCreateXML(pool, xmldesc, flags); } @@ -456,9 +435,8 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc, virCheckNonNullArgReturn(pool->privateData, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } return backend->storageVolCreateXMLFrom(pool, xmldesc, sourceVolume, flags); } @@ -473,9 +451,8 @@ esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags) virCheckNonNullArgReturn(volume->privateData, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storageVolDelete(volume, flags); } @@ -490,9 +467,8 @@ esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags) virCheckNonNullArgReturn(volume->privateData, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storageVolWipe(volume, flags); } @@ -507,9 +483,8 @@ esxStorageVolGetInfo(virStorageVolPtr volume, virStorageVolInfoPtr info) virCheckNonNullArgReturn(volume->privateData, -1); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return -1; - } return backend->storageVolGetInfo(volume, info); } @@ -524,9 +499,8 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume, unsigned int flags) virCheckNonNullArgReturn(volume->privateData, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } return backend->storageVolGetXMLDesc(volume, flags); } @@ -541,9 +515,8 @@ esxStorageVolGetPath(virStorageVolPtr volume) virCheckNonNullArgReturn(volume->privateData, NULL); - if (esxVI_EnsureSession(priv->primary) < 0) { + if (esxVI_EnsureSession(priv->primary) < 0) return NULL; - } return backend->storageVolGetPath(volume); } diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index 9a41241..2dd9f78 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -166,9 +166,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) result = 0; cleanup: - if (result < 0) { + if (result < 0) esxUtil_FreeParsedUri(parsedUri); - } return result; } @@ -179,9 +178,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURIPtr uri) void esxUtil_FreeParsedUri(esxUtil_ParsedUri **parsedUri) { - if (!parsedUri || !(*parsedUri)) { + if (!parsedUri || !(*parsedUri)) return; - } VIR_FREE((*parsedUri)->transport); VIR_FREE((*parsedUri)->vCenter); @@ -197,18 +195,16 @@ int esxUtil_ParseVirtualMachineIDString(const char *id_string, int *id) { /* Try to parse an integer from the complete string. */ - if (virStrToLong_i(id_string, NULL, 10, id) == 0) { + if (virStrToLong_i(id_string, NULL, 10, id) == 0) return 0; - } /* * If that fails try to parse an integer from the string tail * assuming the naming scheme Virtual Center seems to use. */ if (STRPREFIX(id_string, "vm-")) { - if (virStrToLong_i(id_string + 3, NULL, 10, id) == 0) { + if (virStrToLong_i(id_string + 3, NULL, 10, id) == 0) return 0; - } } return -1; @@ -234,9 +230,8 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName, return -1; } - if (VIR_STRDUP(copyOfDatastorePath, datastorePath) < 0) { + if (VIR_STRDUP(copyOfDatastorePath, datastorePath) < 0) goto cleanup; - } /* Expected format: '[<datastore>] <path>' where <path> is optional */ if (!(tmp = STRSKIP(copyOfDatastorePath, "[")) || *tmp == ']' || @@ -270,30 +265,25 @@ esxUtil_ParseDatastorePath(const char *datastorePath, char **datastoreName, /* Split <path> into <directory>/<file> and remove /<file> */ tmp = strrchr(preliminaryDirectoryAndFileName, '/'); - if (tmp) { + if (tmp) *tmp = '\0'; - } - if (VIR_STRDUP(*directoryName, preliminaryDirectoryAndFileName) < 0) { + if (VIR_STRDUP(*directoryName, preliminaryDirectoryAndFileName) < 0) goto cleanup; - } } result = 0; cleanup: if (result < 0) { - if (datastoreName) { + if (datastoreName) VIR_FREE(*datastoreName); - } - if (directoryName) { + if (directoryName) VIR_FREE(*directoryName); - } - if (directoryAndFileName) { + if (directoryAndFileName) VIR_FREE(*directoryAndFileName); - } } VIR_FREE(copyOfDatastorePath); @@ -408,20 +398,17 @@ esxUtil_EscapeBase64(const char *string) virBufferAddChar(&buffer, base64[(c1 >> 2) & 0x3f]); virBufferAddChar(&buffer, base64[((c1 << 4) + (c2 >> 4)) & 0x3f]); - if (length > 1) { + if (length > 1) virBufferAddChar(&buffer, base64[((c2 << 2) + (c3 >> 6)) & 0x3f]); - } - if (length > 2) { + if (length > 2) virBufferAddChar(&buffer, base64[c3 & 0x3f]); - } length -= length > 3 ? 3 : length; } - if (*tmp1 != '\0') { + if (*tmp1 != '\0') virBufferAddChar(&buffer, '-'); - } } } @@ -450,9 +437,8 @@ esxUtil_ReplaceSpecialWindowsPathChars(char *string) --length; } - if (*tmp != '\0') { + if (*tmp != '\0') ++tmp; - } } } @@ -472,9 +458,8 @@ esxUtil_EscapeDatastoreItem(const char *string) escaped1 = virVMXEscapeHexPercent(replaced); - if (!escaped1) { + if (!escaped1) goto cleanup; - } escaped2 = esxUtil_EscapeBase64(escaped1); diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index d28b8e0..a87f2c0 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -98,26 +98,22 @@ ESX_VI__TEMPLATE__FREE(CURL, if (shared) { esxVI_SharedCURL_Remove(shared, item); - if (shared->count == 0) { + if (shared->count == 0) esxVI_SharedCURL_Free(&shared); - } } if (multi) { esxVI_MultiCURL_Remove(multi, item); - if (multi->count == 0) { + if (multi->count == 0) esxVI_MultiCURL_Free(&multi); - } } - if (item->handle) { + if (item->handle) curl_easy_cleanup(item->handle); - } - if (item->headers) { + if (item->headers) curl_slist_free_all(item->headers); - } virMutexDestroy(&item->lock); }) @@ -129,19 +125,16 @@ esxVI_CURL_ReadString(char *data, size_t size, size_t nmemb, void *userdata) size_t available = 0; size_t requested = size * nmemb; - if (!content) { + if (!content) return 0; - } available = strlen(content); - if (available == 0) { + if (available == 0) return 0; - } - if (requested > available) { + if (requested > available) requested = available; - } memcpy(data, content, requested); @@ -162,9 +155,8 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t nmemb, void *userdata) * are meant to download small things such as VMX files, VMDK metadata * files and SOAP responses. */ - if (size * nmemb > INT32_MAX / 2 - virBufferUse(buffer)) { + if (size * nmemb > INT32_MAX / 2 - virBufferUse(buffer)) return 0; - } virBufferAdd(buffer, data, size * nmemb); @@ -193,9 +185,8 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type, * To handle this properly in order to pass the info string to VIR_DEBUG * a zero terminated copy of the info string has to be allocated. */ - if (VIR_ALLOC_N(buffer, size + 1) < 0) { + if (VIR_ALLOC_N(buffer, size + 1) < 0) return 0; - } if (!virStrncpy(buffer, info, size, size + 1)) { VIR_FREE(buffer); @@ -204,9 +195,8 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, curl_infotype type, switch (type) { case CURLINFO_TEXT: - if (size > 0 && buffer[size - 1] == '\n') { + if (size > 0 && buffer[size - 1] == '\n') buffer[size - 1] = '\0'; - } VIR_DEBUG("CURLINFO_TEXT [[[[%s]]]]", buffer); break; @@ -430,9 +420,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, if (virBufferCheckError(&buffer) < 0) goto cleanup; - if (length) { + if (length) *length = virBufferUse(&buffer); - } *content = virBufferContentAndReset(&buffer); @@ -557,13 +546,11 @@ ESX_VI__TEMPLATE__FREE(SharedCURL, return; } - if (item->handle) { + if (item->handle) curl_share_cleanup(item->handle); - } - for (i = 0; i < ARRAY_CARDINALITY(item->locks); ++i) { + for (i = 0; i < ARRAY_CARDINALITY(item->locks); ++i) virMutexDestroy(&item->locks[i]); - } }) int @@ -735,9 +722,8 @@ ESX_VI__TEMPLATE__FREE(MultiCURL, return; } - if (item->handle) { + if (item->handle) curl_multi_cleanup(item->handle); - } #if ESX_EMULATE_CURL_MULTI_WAIT VIR_FREE(item->pollfds); @@ -856,9 +842,8 @@ esxVI_MultiCURL_Wait(esxVI_MultiCURL *multi, int *runningHandles) curl_multi_timeout(multi->handle, &timeout); - if (timeout < 0) { + if (timeout < 0) timeout = 1000; /* default to 1 sec timeout */ - } do { rc = poll(multi->pollfds, multi->npollfds, timeout); @@ -980,9 +965,8 @@ ESX_VI__TEMPLATE__ALLOC(Context) /* esxVI_Context_Free */ ESX_VI__TEMPLATE__FREE(Context, { - if (item->sessionLock) { + if (item->sessionLock) virMutexDestroy(item->sessionLock); - } esxVI_CURL_Free(&item->curl); VIR_FREE(item->url); @@ -1036,9 +1020,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, return -1; } - if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) { + if (esxVI_RetrieveServiceContent(ctx, &ctx->service) < 0) return -1; - } if (STRNEQ(ctx->service->about->apiType, "HostAgent") && STRNEQ(ctx->service->about->apiType, "VirtualCenter")) { @@ -1121,9 +1104,8 @@ esxVI_Context_Connect(esxVI_Context *ctx, const char *url, ctx->hasQueryVirtualDiskUuid = true; } - if (ctx->productLine == esxVI_ProductLine_VPX) { + if (ctx->productLine == esxVI_ProductLine_VPX) ctx->hasSessionIsActive = true; - } if (esxVI_Login(ctx, username, password, NULL, &ctx->session) < 0 || esxVI_BuildSelectSetCollection(ctx) < 0) { @@ -1212,9 +1194,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) if (folder) { /* It's a folder, use it as new lookup root */ - if (root != ctx->service->rootFolder) { + if (root != ctx->service->rootFolder) esxVI_ManagedObjectReference_Free(&root); - } root = folder->_reference; folder->_reference = NULL; @@ -1227,9 +1208,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) } /* Build datacenter path */ - if (virBufferUse(&buffer) > 0) { + if (virBufferUse(&buffer) > 0) virBufferAddChar(&buffer, '/'); - } virBufferAdd(&buffer, item, -1); @@ -1255,9 +1235,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (root != ctx->service->rootFolder) { + if (root != ctx->service->rootFolder) esxVI_ManagedObjectReference_Free(&root); - } root = ctx->datacenter->hostFolder; @@ -1272,9 +1251,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) if (folder) { /* It's a folder, use it as new lookup root */ - if (root != ctx->datacenter->hostFolder) { + if (root != ctx->datacenter->hostFolder) esxVI_ManagedObjectReference_Free(&root); - } root = folder->_reference; folder->_reference = NULL; @@ -1288,9 +1266,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) } /* Build compute resource path */ - if (virBufferUse(&buffer) > 0) { + if (virBufferUse(&buffer) > 0) virBufferAddChar(&buffer, '/'); - } virBufferAdd(&buffer, item, -1); @@ -1355,9 +1332,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) result = 0; cleanup: - if (result < 0) { + if (result < 0) virBufferFreeAndReset(&buffer); - } if (root != ctx->service->rootFolder && (!ctx->datacenter || root != ctx->datacenter->hostFolder)) { @@ -1431,9 +1407,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, return -1; } - if (esxVI_Response_Alloc(response) < 0) { + if (esxVI_Response_Alloc(response) < 0) return -1; - } virMutexLock(&ctx->curl->lock); @@ -1448,9 +1423,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, virMutexUnlock(&ctx->curl->lock); - if ((*response)->responseCode < 0) { + if ((*response)->responseCode < 0) goto cleanup; - } if (virBufferCheckError(&buffer) < 0) goto cleanup; @@ -1462,9 +1436,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, _("(esx execute response)"), &xpathContext); - if (!(*response)->document) { + if (!(*response)->document) goto cleanup; - } xmlXPathRegisterNs(xpathContext, BAD_CAST "soapenv", BAD_CAST "http://schemas.xmlsoap.org/soap/envelope/"); @@ -1710,9 +1683,8 @@ esxVI_Enumeration_Deserialize(const esxVI_Enumeration *enumeration, *value = 0; /* undefined */ - if (esxVI_String_DeserializeValue(node, &name) < 0) { + if (esxVI_String_DeserializeValue(node, &name) < 0) return -1; - } for (i = 0; enumeration->values[i].name; ++i) { if (STREQ(name, enumeration->values[i].name)) { @@ -1755,9 +1727,8 @@ esxVI_List_Append(esxVI_List **list, esxVI_List *item) next = *list; - while (next->_next) { + while (next->_next) next = next->_next; - } next->_next = item; @@ -1810,9 +1781,8 @@ esxVI_List_CastFromAnyType(esxVI_AnyType *anyType, esxVI_List **list, return -1; } - if (!anyType) { + if (!anyType) return 0; - } if (! STRPREFIX(anyType->other, "ArrayOf")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1865,14 +1835,12 @@ esxVI_List_Serialize(esxVI_List *list, const char *element, return -1; } - if (!list) { + if (!list) return 0; - } for (item = list; item; item = item->_next) { - if (serializeFunc(item, element, output) < 0) { + if (serializeFunc(item, element, output) < 0) return -1; - } } return 0; @@ -1890,9 +1858,8 @@ esxVI_List_Deserialize(xmlNodePtr node, esxVI_List **list, return -1; } - if (!node) { + if (!node) return 0; - } for (; node; node = node->next) { if (node->type != XML_ELEMENT_NODE) { @@ -2193,9 +2160,8 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, return -1; } - if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) { + if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) return -1; - } objectSpec->obj = root; objectSpec->skip = esxVI_Boolean_False; @@ -2254,9 +2220,8 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, } } - if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) { + if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) goto cleanup; - } propertySpec->type = (char *)type; propertySpec->pathSet = propertyNameList; @@ -2325,13 +2290,11 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx, propertySpec->pathSet = NULL; } - if (!objectSpec_isAppended) { + if (!objectSpec_isAppended) esxVI_ObjectSpec_Free(&objectSpec); - } - if (!propertySpec_isAppended) { + if (!propertySpec_isAppended) esxVI_PropertySpec_Free(&propertySpec); - } esxVI_PropertyFilterSpec_Free(&propertyFilterSpec); @@ -2463,9 +2426,8 @@ esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName, for (dynamicProperty = objectContent->propSet; dynamicProperty; dynamicProperty = dynamicProperty->_next) { if (STREQ(dynamicProperty->name, propertyName)) { - if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) { + if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) return -1; - } break; } @@ -2709,9 +2671,8 @@ esxVI_GetVirtualMachineIdentity(esxVI_ObjectContent *virtualMachine, return 0; failure: - if (name) { + if (name) VIR_FREE(*name); - } return -1; } @@ -2760,9 +2721,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, count++; } - if (count >= nameslen) { + if (count >= nameslen) break; - } if (recurse) { result = esxVI_GetSnapshotTreeNames(snapshotTree->childSnapshotList, @@ -2770,9 +2730,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, nameslen - count, true, leaves); - if (result < 0) { + if (result < 0) goto failure; - } count += result; } @@ -2781,9 +2740,8 @@ esxVI_GetSnapshotTreeNames(esxVI_VirtualMachineSnapshotTree *snapshotTreeList, return count; failure: - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } return -1; } @@ -2817,9 +2775,8 @@ esxVI_GetSnapshotTreeByName if (esxVI_GetSnapshotTreeByName(candidate->childSnapshotList, name, snapshotTree, snapshotTreeParent, occurrence) > 0) { - if (snapshotTreeParent && !(*snapshotTreeParent)) { + if (snapshotTreeParent && !(*snapshotTreeParent)) *snapshotTreeParent = candidate; - } return 1; } @@ -2987,13 +2944,11 @@ esxVI_LookupVirtualMachineByName(esxVI_Context *ctx, const char *name, goto cleanup; } - if (STRNEQ(name, name_candidate)) { + if (STRNEQ(name, name_candidate)) continue; - } - if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) { + if (esxVI_ObjectContent_DeepCopy(virtualMachine, candidate) < 0) goto cleanup; - } break; } @@ -3126,9 +3081,8 @@ esxVI_LookupDatastoreByName(esxVI_Context *ctx, const char *name, } if (STREQ(name_candidate, name)) { - if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) { + if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) goto cleanup; - } /* Found datastore with matching name */ result = 0; @@ -3199,9 +3153,8 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, } } - if (!datastoreHostMountList) { + if (!datastoreHostMountList) continue; - } for (datastoreHostMount = datastoreHostMountList; datastoreHostMount; @@ -3212,9 +3165,8 @@ esxVI_LookupDatastoreByAbsolutePath(esxVI_Context *ctx, } if (STRPREFIX(absolutePath, datastoreHostMount->mountInfo->path)) { - if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) { + if (esxVI_ObjectContent_DeepCopy(datastore, candidate) < 0) goto cleanup; - } /* Found datastore with matching mount path */ result = 0; @@ -3284,13 +3236,11 @@ esxVI_LookupDatastoreHostMount(esxVI_Context *ctx, for (candidate = hostMountList; candidate; candidate = candidate->_next) { - if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value)) { + if (STRNEQ(ctx->hostSystem->_reference->value, candidate->key->value)) continue; - } - if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0) { + if (esxVI_DatastoreHostMount_DeepCopy(hostMount, candidate) < 0) goto cleanup; - } break; } @@ -3392,9 +3342,8 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine /* Lookup task info for each task */ for (recentTask = recentTaskList; recentTask; recentTask = recentTask->_next) { - if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) { + if (esxVI_LookupTaskInfoByTask(ctx, recentTask, &taskInfo) < 0) goto cleanup; - } if (taskInfo->state == esxVI_TaskInfoState_Queued || taskInfo->state == esxVI_TaskInfoState_Running) { @@ -3412,9 +3361,8 @@ esxVI_LookupPendingTaskInfoListByVirtualMachine result = 0; cleanup: - if (result < 0) { + if (result < 0) esxVI_TaskInfo_Free(pendingTaskInfoList); - } esxVI_String_Free(&propertyNameList); esxVI_ManagedObjectReference_Free(&recentTaskList); @@ -3509,9 +3457,8 @@ esxVI_LookupRootSnapshotTreeList result = 0; cleanup: - if (result < 0) { + if (result < 0) esxVI_VirtualMachineSnapshotTree_Free(rootSnapshotTreeList); - } esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&virtualMachine); @@ -3651,9 +3598,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, datastoreName) < 0) goto cleanup; - if (VIR_STRDUP(fileName, directoryAndFileName) < 0) { + if (VIR_STRDUP(fileName, directoryAndFileName) < 0) goto cleanup; - } } else { if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", datastoreName, directoryName) < 0) @@ -3669,9 +3615,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, goto cleanup; } - if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0) { + if (VIR_STRDUP(fileName, directoryAndFileName + length + 1) < 0) goto cleanup; - } } /* Lookup HostDatastoreBrowser */ @@ -3736,9 +3681,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, floppyImageFileQuery = NULL; } - if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0) { + if (esxVI_String_Alloc(&searchSpec->matchPattern) < 0) goto cleanup; - } searchSpec->matchPattern->value = fileName; @@ -3786,9 +3730,8 @@ esxVI_LookupFileInfoByDatastorePath(esxVI_Context *ctx, cleanup: /* Don't double free fileName */ - if (searchSpec && searchSpec->matchPattern) { + if (searchSpec && searchSpec->matchPattern) searchSpec->matchPattern->value = NULL; - } VIR_FREE(datastoreName); VIR_FREE(directoryName); @@ -3967,17 +3910,15 @@ esxVI_LookupStorageVolumeKeyByDatastorePath(esxVI_Context *ctx, if (VIR_ALLOC_N(*key, VIR_UUID_STRING_BUFLEN) < 0) goto cleanup; - if (esxUtil_ReformatUuid(uuid_string, *key) < 0) { + if (esxUtil_ReformatUuid(uuid_string, *key) < 0) goto cleanup; - } } } if (!(*key)) { /* Other files don't have a UUID, fall back to the path as key */ - if (VIR_STRDUP(*key, datastorePath) < 0) { + if (VIR_STRDUP(*key, datastorePath) < 0) goto cleanup; - } } result = 0; @@ -4157,17 +4098,15 @@ esxVI_LookupPhysicalNicByName(esxVI_Context *ctx, const char *name, return -1; } - if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) { + if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) goto cleanup; - } /* Search for a matching physical NIC */ for (candidate = physicalNicList; candidate; candidate = candidate->_next) { if (STRCASEEQ(candidate->device, name)) { - if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) { + if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) goto cleanup; - } /* Found physical NIC with matching name */ result = 0; @@ -4206,17 +4145,15 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac, return -1; } - if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) { + if (esxVI_LookupPhysicalNicList(ctx, &physicalNicList) < 0) goto cleanup; - } /* Search for a matching physical NIC */ for (candidate = physicalNicList; candidate; candidate = candidate->_next) { if (STRCASEEQ(candidate->mac, mac)) { - if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) { + if (esxVI_PhysicalNic_DeepCopy(physicalNic, candidate) < 0) goto cleanup; - } /* Found physical NIC with matching MAC address */ result = 0; @@ -4299,9 +4236,8 @@ esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name, return -1; } - if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0) { + if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0) goto cleanup; - } /* Search for a matching HostVirtualSwitch */ for (candidate = hostVirtualSwitchList; candidate; @@ -4421,9 +4357,8 @@ esxVI_HandleVirtualMachineQuestion elementDescription = elementDescription->_next) { virBufferAsprintf(&buffer, "'%s'", elementDescription->label); - if (elementDescription->_next) { + if (elementDescription->_next) virBufferAddLit(&buffer, ", "); - } if (!answerChoice && questionInfo->choice->defaultIndex && @@ -4489,9 +4424,8 @@ esxVI_HandleVirtualMachineQuestion result = 0; cleanup: - if (result < 0) { + if (result < 0) virBufferFreeAndReset(&buffer); - } VIR_FREE(possibleAnswers); @@ -4533,16 +4467,14 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, if (VIR_STRDUP(version, "") < 0) return -1; - if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) { + if (esxVI_ObjectSpec_Alloc(&objectSpec) < 0) goto cleanup; - } objectSpec->obj = task; objectSpec->skip = esxVI_Boolean_False; - if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) { + if (esxVI_PropertySpec_Alloc(&propertySpec) < 0) goto cleanup; - } propertySpec->type = task->type; @@ -4581,9 +4513,8 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, * esxVI_LookupTaskInfoByTask() and esxVI_CancelTask() * don't overwrite the actual error */ - if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) { + if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) goto cleanup; - } if (taskInfo->cancelable == esxVI_Boolean_True) { if (esxVI_CancelTask(ctx, task) < 0 && blocked) { @@ -4602,17 +4533,15 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } } - if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) { + if (esxVI_WaitForUpdates(ctx, version, &updateSet) < 0) goto cleanup; - } VIR_FREE(version); if (VIR_STRDUP(version, updateSet->version) < 0) goto cleanup; - if (!updateSet->filterSet) { + if (!updateSet->filterSet) continue; - } for (propertyFilterUpdate = updateSet->filterSet; propertyFilterUpdate; @@ -4634,27 +4563,22 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, } } - if (!propertyValue) { + if (!propertyValue) continue; - } - if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) { + if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, &state) < 0) goto cleanup; - } } - if (esxVI_DestroyPropertyFilter(ctx, propertyFilter) < 0) { + if (esxVI_DestroyPropertyFilter(ctx, propertyFilter) < 0) VIR_DEBUG("DestroyPropertyFilter failed"); - } - if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) { + if (esxVI_TaskInfoState_CastFromAnyType(propertyValue, finalState) < 0) goto cleanup; - } if (*finalState != esxVI_TaskInfoState_Success) { - if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) { + if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) goto cleanup; - } if (!taskInfo->error) { if (VIR_STRDUP(*errorMessage, _("Unknown error")) < 0) @@ -4677,21 +4601,17 @@ esxVI_WaitForTaskCompletion(esxVI_Context *ctx, * Remove values given by the caller from the data structures to prevent * them from being freed by the call to esxVI_PropertyFilterSpec_Free(). */ - if (objectSpec) { + if (objectSpec) objectSpec->obj = NULL; - } - if (propertySpec) { + if (propertySpec) propertySpec->type = NULL; - } - if (!objectSpec_isAppended) { + if (!objectSpec_isAppended) esxVI_ObjectSpec_Free(&objectSpec); - } - if (!propertySpec_isAppended) { + if (!propertySpec_isAppended) esxVI_PropertySpec_Free(&propertySpec); - } esxVI_PropertyFilterSpec_Free(&propertyFilterSpec); esxVI_ManagedObjectReference_Free(&propertyFilter); @@ -4849,9 +4769,8 @@ esxVI_LookupHostInternetScsiHbaStaticTargetByName for (candidate = hostInternetScsiHba->configuredStaticTarget; candidate; candidate = candidate->_next) { - if (STREQ(candidate->iScsiName, name)) { + if (STREQ(candidate->iScsiName, name)) break; - } } if (!candidate) { @@ -4863,9 +4782,8 @@ esxVI_LookupHostInternetScsiHbaStaticTargetByName goto cleanup; } - if (esxVI_HostInternetScsiHbaStaticTarget_DeepCopy(target, candidate) < 0) { + if (esxVI_HostInternetScsiHbaStaticTarget_DeepCopy(target, candidate) < 0) goto cleanup; - } result = 0; @@ -5044,9 +4962,8 @@ esxVI_LookupHostScsiTopologyLunListByTargetName } } - if (!found || !hostScsiTopologyTarget) { + if (!found || !hostScsiTopologyTarget) goto cleanup; - } if (!hostScsiTopologyTarget->lun) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index 4c7dc30..1502467 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -944,13 +944,11 @@ esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src) return -1; } - if (!src) { + if (!src) return 0; - } - if (esxVI_AnyType_Alloc(dest) < 0) { + if (esxVI_AnyType_Alloc(dest) < 0) goto failure; - } (*dest)->_type = src->_type; (*dest)->node = xmlCopyNode(src->node, 1); @@ -1015,9 +1013,8 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) return -1; } - if (esxVI_AnyType_Alloc(anyType) < 0) { + if (esxVI_AnyType_Alloc(anyType) < 0) return -1; - } (*anyType)->node = xmlCopyNode(node, 1); @@ -1151,9 +1148,8 @@ esxVI_String_ListContainsValue(esxVI_String *stringList, const char *value) esxVI_String *string; for (string = stringList; string; string = string->_next) { - if (STREQ(string->value, value)) { + if (STREQ(string->value, value)) return true; - } } return false; @@ -1167,16 +1163,14 @@ esxVI_String_AppendValueToList(esxVI_String **stringList, const char *value) { esxVI_String *string = NULL; - if (esxVI_String_Alloc(&string) < 0) { + if (esxVI_String_Alloc(&string) < 0) return -1; - } if (VIR_STRDUP(string->value, value) < 0) goto failure; - if (esxVI_String_AppendToList(stringList, string) < 0) { + if (esxVI_String_AppendToList(stringList, string) < 0) goto failure; - } return 0; @@ -1194,16 +1188,14 @@ esxVI_String_AppendValueListToList(esxVI_String **stringList, const char *value = valueList; while (value && *value != '\0') { - if (esxVI_String_AppendValueToList(&stringListToAppend, value) < 0) { + if (esxVI_String_AppendValueToList(&stringListToAppend, value) < 0) goto failure; - } value += strlen(value) + 1; } - if (esxVI_String_AppendToList(stringList, stringListToAppend) < 0) { + if (esxVI_String_AppendToList(stringList, stringListToAppend) < 0) goto failure; - } return 0; @@ -1230,9 +1222,8 @@ esxVI_String_DeepCopyValue(char **dest, const char *src) return -1; } - if (!src) { + if (!src) return 0; - } return VIR_STRDUP(*dest, src); } @@ -1263,9 +1254,8 @@ esxVI_String_SerializeValue(const char *value, const char *element, return -1; } - if (!value) { + if (!value) return 0; - } ESV_VI__XML_TAG__OPEN(output, element, "xsd:string"); @@ -1483,9 +1473,8 @@ esxVI_DateTime_Deserialize(xmlNodePtr node, esxVI_DateTime **dateTime) return -1; } - if (esxVI_DateTime_Alloc(dateTime) < 0) { + if (esxVI_DateTime_Alloc(dateTime) < 0) return -1; - } (*dateTime)->value = (char *)xmlNodeListGetString(node->doc, node->children, 1); @@ -1577,9 +1566,8 @@ esxVI_DateTime_ConvertToCalendarTime(esxVI_DateTime *dateTime, tz_offset = tz_hours * 60 * 60 + tz_minutes * 60; - if (sign == '-') { + if (sign == '-') tz_offset = -tz_offset; - } } else if (STREQ(tmp, "Z")) { /* Z refers to UTC. tz_offset is already initialized to zero */ } else { @@ -1657,9 +1645,8 @@ esxVI_MethodFault_Deserialize(xmlNodePtr node, esxVI_MethodFault **methodFault) return -1; } - if (esxVI_MethodFault_Alloc(methodFault) < 0) { + if (esxVI_MethodFault_Alloc(methodFault) < 0) return -1; - } (*methodFault)->_actualType = (char *)xmlGetNsProp(node, BAD_CAST "type", @@ -1723,9 +1710,8 @@ esxVI_ManagedObjectReference_Serialize return -1; } - if (!managedObjectReference) { + if (!managedObjectReference) return 0; - } virBufferAddLit(output, "<"); virBufferAdd(output, element, -1); @@ -1753,9 +1739,8 @@ esxVI_ManagedObjectReference_Deserialize return -1; } - if (esxVI_ManagedObjectReference_Alloc(managedObjectReference) < 0) { + if (esxVI_ManagedObjectReference_Alloc(managedObjectReference) < 0) return -1; - } (*managedObjectReference)->type = (char *)xmlGetNoNsProp(node, BAD_CAST "type"); -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/vmx/vmx.c | 243 ++++++++++++++++++++-------------------------------------- 1 file changed, 81 insertions(+), 162 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 389a012..e6bf5c3 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -565,9 +565,8 @@ virVMXEscapeHex(const char *string, char escape, const char *special) /* Calculate length of escaped string */ while (*tmp1 != '\0') { - if (*tmp1 == escape || strspn(tmp1, special) > 0) { + if (*tmp1 == escape || strspn(tmp1, special) > 0) length += 2; - } ++tmp1; ++length; @@ -610,9 +609,8 @@ virVMXUnescapeHex(char *string, char escape) /* Unescape from 'cXX' where c is the escape char and X is a hex digit */ while (*tmp1 != '\0') { if (*tmp1 == escape) { - if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) { + if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) return -1; - } *tmp2++ = virHexToBin(tmp1[1]) * 16 + virHexToBin(tmp1[2]); tmp1 += 3; @@ -676,9 +674,8 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, value = virConfGetValue(conf, name); if (value == NULL) { - if (optional) { + if (optional) return 0; - } virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing essential config entry '%s'"), name); @@ -692,9 +689,8 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, } if (value->str == NULL) { - if (optional) { + if (optional) return 0; - } virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing essential config entry '%s'"), name); @@ -882,9 +878,8 @@ virVMXSCSIDiskNameToControllerAndUnit(const char *name, int *controller, int *un *unit = idx % 15; /* Skip the controller ifself at unit 7 */ - if (*unit >= 7) { + if (*unit >= 7) ++(*unit); - } return 0; } @@ -1082,17 +1077,15 @@ virVMXHandleLegacySCSIDiskDriverName(virDomainDefPtr def, const char *driver = virDomainDiskGetDriver(disk); char *copy; - if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver) { + if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver) return 0; - } if (VIR_STRDUP(copy, driver) < 0) return -1; tmp = copy; - for (; *tmp != '\0'; ++tmp) { + for (; *tmp != '\0'; ++tmp) *tmp = c_tolower(*tmp); - } model = virDomainControllerModelSCSITypeFromString(copy); VIR_FREE(copy); @@ -1278,14 +1271,12 @@ virVMXParseConfig(virVMXContext *ctx, conf = virConfReadMem(vmx, strlen(vmx), VIR_CONF_FLAG_VMX_FORMAT); - if (conf == NULL) { + if (conf == NULL) return NULL; - } /* vmx:.encoding */ - if (virVMXGetConfigString(conf, ".encoding", &encoding, true) < 0) { + if (virVMXGetConfigString(conf, ".encoding", &encoding, true) < 0) goto cleanup; - } if (encoding == NULL || STRCASEEQ(encoding, "UTF-8")) { /* nothing */ @@ -1295,17 +1286,15 @@ virVMXParseConfig(virVMXContext *ctx, utf8 = virVMXConvertToUTF8(encoding, vmx); - if (utf8 == NULL) { + if (utf8 == NULL) goto cleanup; - } conf = virConfReadMem(utf8, strlen(utf8), VIR_CONF_FLAG_VMX_FORMAT); VIR_FREE(utf8); - if (conf == NULL) { + if (conf == NULL) goto cleanup; - } } /* Allocate domain def */ @@ -1344,14 +1333,12 @@ virVMXParseConfig(virVMXContext *ctx, /* vmx:uuid.bios -> def:uuid */ /* FIXME: Need to handle 'uuid.action = "create"' */ - if (virVMXGetConfigUUID(conf, "uuid.bios", def->uuid, true) < 0) { + if (virVMXGetConfigUUID(conf, "uuid.bios", def->uuid, true) < 0) goto cleanup; - } /* vmx:displayName -> def:name */ - if (virVMXGetConfigString(conf, "displayName", &def->name, true) < 0) { + if (virVMXGetConfigString(conf, "displayName", &def->name, true) < 0) goto cleanup; - } if (def->name != NULL) { if (virVMXUnescapeHexPercent(def->name) < 0 || @@ -1378,9 +1365,8 @@ virVMXParseConfig(virVMXContext *ctx, } /* vmx:memsize -> def:mem.max_balloon */ - if (virVMXGetConfigLong(conf, "memsize", &memsize, 32, true) < 0) { + if (virVMXGetConfigLong(conf, "memsize", &memsize, 32, true) < 0) goto cleanup; - } if (memsize <= 0 || memsize % 4 != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1397,15 +1383,13 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (sched_mem_max < 0) { + if (sched_mem_max < 0) sched_mem_max = memsize; - } def->mem.cur_balloon = sched_mem_max * 1024; /* Scale from megabytes to kilobytes */ - if (def->mem.cur_balloon > def->mem.max_balloon) { + if (def->mem.cur_balloon > def->mem.max_balloon) def->mem.cur_balloon = def->mem.max_balloon; - } /* vmx:sched.mem.minsize -> def:mem.min_guarantee */ if (virVMXGetConfigLong(conf, "sched.mem.minsize", &sched_mem_minsize, 0, @@ -1413,20 +1397,17 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (sched_mem_minsize < 0) { + if (sched_mem_minsize < 0) sched_mem_minsize = 0; - } def->mem.min_guarantee = sched_mem_minsize * 1024; /* Scale from megabytes to kilobytes */ - if (def->mem.min_guarantee > def->mem.max_balloon) { + if (def->mem.min_guarantee > def->mem.max_balloon) def->mem.min_guarantee = def->mem.max_balloon; - } /* vmx:numvcpus -> def:vcpus */ - if (virVMXGetConfigLong(conf, "numvcpus", &numvcpus, 1, true) < 0) { + if (virVMXGetConfigLong(conf, "numvcpus", &numvcpus, 1, true) < 0) goto cleanup; - } if (numvcpus <= 0 || (numvcpus % 2 != 0 && numvcpus != 1)) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1474,9 +1455,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (number + 1 > cpumasklen) { + if (number + 1 > cpumasklen) cpumasklen = number + 1; - } ignore_value(virBitmapSetBit(def->cpumask, number)); ++count; @@ -1542,9 +1522,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; /* vmx:guestOS -> def:os.arch */ - if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0) { + if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0) goto cleanup; - } if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) { def->os.arch = VIR_ARCH_X86_64; @@ -1558,9 +1537,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (smbios_reflecthost) { + if (smbios_reflecthost) def->os.smbios_mode = VIR_DOMAIN_SMBIOS_HOST; - } /* def:features */ /* FIXME */ @@ -1574,13 +1552,11 @@ virVMXParseConfig(virVMXContext *ctx, def->ngraphics = 0; - if (virVMXParseVNC(conf, &def->graphics[def->ngraphics]) < 0) { + if (virVMXParseVNC(conf, &def->graphics[def->ngraphics]) < 0) goto cleanup; - } - if (def->graphics[def->ngraphics] != NULL) { + if (def->graphics[def->ngraphics] != NULL) ++def->ngraphics; - } /* def:disks: 4 * 15 scsi + 2 * 2 ide + 2 floppy = 66 */ if (VIR_ALLOC_N(def->disks, 66) < 0) @@ -1595,9 +1571,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (! present) { + if (! present) continue; - } for (unit = 0; unit < 16; ++unit) { if (unit == 7) { @@ -1625,9 +1600,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->disks[def->ndisks] != NULL) { + if (def->disks[def->ndisks] != NULL) ++def->ndisks; - } } } @@ -1651,9 +1625,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->disks[def->ndisks] != NULL) { + if (def->disks[def->ndisks] != NULL) ++def->ndisks; - } } } @@ -1665,9 +1638,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->disks[def->ndisks] != NULL) { + if (def->disks[def->ndisks] != NULL) ++def->ndisks; - } } /* def:controllers */ @@ -1716,9 +1688,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->fss[def->nfss] != NULL) { + if (def->fss[def->nfss] != NULL) ++def->nfss; - } } } } @@ -1735,9 +1706,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->nets[def->nnets] != NULL) { + if (def->nets[def->nnets] != NULL) ++def->nnets; - } } /* def:inputs */ @@ -1749,9 +1719,8 @@ virVMXParseConfig(virVMXContext *ctx, def->nvideos = 0; - if (virVMXParseSVGA(conf, &def->videos[def->nvideos]) < 0) { + if (virVMXParseSVGA(conf, &def->videos[def->nvideos]) < 0) goto cleanup; - } def->nvideos = 1; @@ -1773,9 +1742,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->serials[def->nserials] != NULL) { + if (def->serials[def->nserials] != NULL) ++def->nserials; - } } /* def:parallels */ @@ -1790,9 +1758,8 @@ virVMXParseConfig(virVMXContext *ctx, goto cleanup; } - if (def->parallels[def->nparallels] != NULL) { + if (def->parallels[def->nparallels] != NULL) ++def->nparallels; - } } success = true; @@ -1831,9 +1798,8 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) return -1; } - if (! enabled) { + if (! enabled) return 0; - } if (VIR_ALLOC(*def) < 0) goto failure; @@ -1864,9 +1830,8 @@ virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def) (*def)->data.vnc.port = 0; (*def)->data.vnc.autoport = true; } else { - if (port < 5900 || port > 5964) { + if (port < 5900 || port > 5964) VIR_WARN("VNC port %lld it out of [5900..5964] range", port); - } (*def)->data.vnc.port = port; (*def)->data.vnc.autoport = false; @@ -1910,9 +1875,8 @@ virVMXParseSCSIController(virConfPtr conf, int controller, bool *present, snprintf(virtualDev_name, sizeof(virtualDev_name), "scsi%d.virtualDev", controller); - if (virVMXGetConfigBoolean(conf, present_name, present, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, present_name, present, false, true) < 0) goto cleanup; - } if (! *present) { result = 0; @@ -1927,9 +1891,8 @@ virVMXParseSCSIController(virConfPtr conf, int controller, bool *present, if (virtualDev_string != NULL) { tmp = virtualDev_string; - for (; *tmp != '\0'; ++tmp) { + for (; *tmp != '\0'; ++tmp) *tmp = c_tolower(*tmp); - } *virtualDev = virVMXControllerModelSCSITypeFromString(virtualDev_string); @@ -2045,9 +2008,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con virIndexToDiskName (controllerOrBus * 15 + (unit < 7 ? unit : unit - 1), "sd"); - if ((*def)->dst == NULL) { + if ((*def)->dst == NULL) goto cleanup; - } } else if (busType == VIR_DOMAIN_DISK_BUS_IDE) { if (controllerOrBus < 0 || controllerOrBus > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2067,9 +2029,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con (*def)->dst = virIndexToDiskName(controllerOrBus * 2 + unit, "hd"); - if ((*def)->dst == NULL) { + if ((*def)->dst == NULL) goto cleanup; - } } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%s'"), @@ -2098,9 +2059,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con (*def)->dst = virIndexToDiskName(unit, "fd"); - if ((*def)->dst == NULL) { + if ((*def)->dst == NULL) goto cleanup; - } } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported bus type '%s' for device type '%s'"), @@ -2125,9 +2085,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con VMX_BUILD_NAME(mode); /* vmx:present */ - if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) goto cleanup; - } /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, @@ -2136,14 +2095,12 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } /* FIXME: Need to distiguish between active and inactive domains here */ - if (! present/* && ! startConnected*/) { + if (! present/* && ! startConnected*/) goto ignore; - } /* vmx:deviceType -> def:type */ - if (virVMXGetConfigString(conf, deviceType_name, &deviceType, true) < 0) { + if (virVMXGetConfigString(conf, deviceType_name, &deviceType, true) < 0) goto cleanup; - } /* vmx:clientDevice */ if (virVMXGetConfigBoolean(conf, clientDevice_name, &clientDevice, false, @@ -2152,9 +2109,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } /* vmx:mode -> def:transient */ - if (virVMXGetConfigString(conf, mode_name, &mode, true) < 0) { + if (virVMXGetConfigString(conf, mode_name, &mode, true) < 0) goto cleanup; - } if (clientDevice) { /* @@ -2165,14 +2121,12 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } /* vmx:fileType -> def:type */ - if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0) { + if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0) goto cleanup; - } /* vmx:fileName -> def:src, def:type */ - if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0) { + if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0) goto cleanup; - } /* vmx:writeThrough -> def:cachemode */ if (virVMXGetConfigBoolean(conf, writeThrough_name, &writeThrough, false, @@ -2396,31 +2350,26 @@ int virVMXParseFileSystem(virConfPtr conf, int number, virDomainFSDefPtr *def) VMX_BUILD_NAME(writeAccess); /* vmx:present */ - if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) goto cleanup; - } /* vmx:enabled */ - if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0) goto cleanup; - } - if (!(present && enabled)) { + if (!(present && enabled)) goto ignore; - } /* vmx:hostPath */ - if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0) { + if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0) goto cleanup; - } (*def)->src = hostPath; hostPath = NULL; /* vmx:guestName */ - if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0) { + if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0) goto cleanup; - } (*def)->dst = guestName; guestName = NULL; @@ -2522,9 +2471,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) VMX_BUILD_NAME(vnet); /* vmx:present */ - if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) goto cleanup; - } /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, @@ -2533,9 +2481,8 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) } /* FIXME: Need to distiguish between active and inactive domains here */ - if (! present/* && ! startConnected*/) { + if (! present/* && ! startConnected*/) goto ignore; - } /* vmx:connectionType -> def:type */ if (virVMXGetConfigString(conf, connectionType_name, &connectionType, @@ -2736,9 +2683,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, VMX_BUILD_NAME_EXTRA(network_endPoint, "network.endPoint"); /* vmx:present */ - if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) goto cleanup; - } /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, @@ -2747,19 +2693,16 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, } /* FIXME: Need to distiguish between active and inactive domains here */ - if (! present/* && ! startConnected*/) { + if (! present/* && ! startConnected*/) goto ignore; - } /* vmx:fileType -> def:type */ - if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) { + if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) goto cleanup; - } /* vmx:fileName -> def:data.file.path */ - if (virVMXGetConfigString(conf, fileName_name, &fileName, true) < 0) { + if (virVMXGetConfigString(conf, fileName_name, &fileName, true) < 0) goto cleanup; - } /* vmx:network.endPoint -> def:data.tcp.listen */ if (virVMXGetConfigString(conf, network_endPoint_name, &network_endPoint, @@ -2780,9 +2723,8 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, (*def)->source.data.file.path = ctx->parseFileName(fileName, ctx->opaque); - if ((*def)->source.data.file.path == NULL) { + if ((*def)->source.data.file.path == NULL) goto cleanup; - } } else if (STRCASEEQ(fileType, "pipe")) { /* * FIXME: Differences between client/server and VM/application pipes @@ -2924,9 +2866,8 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port, VMX_BUILD_NAME(fileName); /* vmx:present */ - if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) { + if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) goto cleanup; - } /* vmx:startConnected */ if (virVMXGetConfigBoolean(conf, startConnected_name, &startConnected, @@ -2935,19 +2876,16 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port, } /* FIXME: Need to distiguish between active and inactive domains here */ - if (! present/* && ! startConnected*/) { + if (! present/* && ! startConnected*/) goto ignore; - } /* vmx:fileType -> def:type */ - if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) { + if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0) goto cleanup; - } /* vmx:fileName -> def:data.file.path */ - if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0) { + if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0) goto cleanup; - } /* Setup virDomainChrDef */ if (STRCASEEQ(fileType, "device")) { @@ -2962,9 +2900,8 @@ virVMXParseParallel(virVMXContext *ctx, virConfPtr conf, int port, (*def)->source.data.file.path = ctx->parseFileName(fileName, ctx->opaque); - if ((*def)->source.data.file.path == NULL) { + if ((*def)->source.data.file.path == NULL) goto cleanup; - } } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Expecting VMX entry '%s' to be 'device' or 'file' but " @@ -3122,15 +3059,13 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe /* def:name -> vmx:displayName */ preliminaryDisplayName = virVMXEscapeHexPipe(def->name); - if (preliminaryDisplayName == NULL) { + if (preliminaryDisplayName == NULL) goto cleanup; - } displayName = virVMXEscapeHexPercent(preliminaryDisplayName); - if (displayName == NULL) { + if (displayName == NULL) goto cleanup; - } virBufferAsprintf(&buffer, "displayName = \"%s\"\n", displayName); @@ -3188,9 +3123,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe sched_cpu_affinity_length = 0; bit = -1; - while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0) { + while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0) ++sched_cpu_affinity_length; - } if (sched_cpu_affinity_length < def->maxvcpus) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3204,9 +3138,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0) { virBufferAsprintf(&buffer, "%d", bit); - if (sched_cpu_affinity_length > 1) { + if (sched_cpu_affinity_length > 1) virBufferAddChar(&buffer, ','); - } --sched_cpu_affinity_length; } @@ -3233,9 +3166,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe for (i = 0; i < def->ngraphics; ++i) { switch (def->graphics[i]->type) { case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - if (virVMXFormatVNC(def->graphics[i], &buffer) < 0) { + if (virVMXFormatVNC(def->graphics[i], &buffer) < 0) goto cleanup; - } break; @@ -3277,9 +3209,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_CDROM: case VIR_DOMAIN_DISK_DEVICE_LUN: - if (virVMXFormatDisk(ctx, def->disks[i], &buffer) < 0) { + if (virVMXFormatDisk(ctx, def->disks[i], &buffer) < 0) goto cleanup; - } break; @@ -3301,9 +3232,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe for (i = 0; i < 2; ++i) { /* floppy[0..1].present defaults to true, disable it explicitly */ - if (! floppy_present[i]) { + if (! floppy_present[i]) virBufferAsprintf(&buffer, "floppy%zu.present = \"false\"\n", i); - } } /* def:fss */ @@ -3313,16 +3243,14 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe } for (i = 0; i < def->nfss; ++i) { - if (virVMXFormatFileSystem(def->fss[i], i, &buffer) < 0) { + if (virVMXFormatFileSystem(def->fss[i], i, &buffer) < 0) goto cleanup; - } } /* def:nets */ for (i = 0; i < def->nnets; ++i) { - if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0) { + if (virVMXFormatEthernet(def->nets[i], i, &buffer) < 0) goto cleanup; - } } /* def:inputs */ @@ -3339,9 +3267,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe goto cleanup; } - if (virVMXFormatSVGA(def->videos[0], &buffer) < 0) { + if (virVMXFormatSVGA(def->videos[0], &buffer) < 0) goto cleanup; - } } /* def:hostdevs */ @@ -3349,16 +3276,14 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe /* def:serials */ for (i = 0; i < def->nserials; ++i) { - if (virVMXFormatSerial(ctx, def->serials[i], &buffer) < 0) { + if (virVMXFormatSerial(ctx, def->serials[i], &buffer) < 0) goto cleanup; - } } /* def:parallels */ for (i = 0; i < def->nparallels; ++i) { - if (virVMXFormatParallel(ctx, def->parallels[i], &buffer) < 0) { + if (virVMXFormatParallel(ctx, def->parallels[i], &buffer) < 0) goto cleanup; - } } /* Get final VMX output */ @@ -3368,9 +3293,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe vmx = virBufferContentAndReset(&buffer); cleanup: - if (vmx == NULL) { + if (vmx == NULL) virBufferFreeAndReset(&buffer); - } VIR_FREE(preliminaryDisplayName); VIR_FREE(displayName); @@ -3518,9 +3442,8 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, fileName = ctx->formatFileName(src, ctx->opaque); - if (fileName == NULL) { + if (fileName == NULL) return -1; - } virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n", busType, controllerOrBus, unit, fileName); @@ -3575,9 +3498,8 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, return -1; } - if (virVMXFloppyDiskNameToUnit(def->dst, &unit) < 0) { + if (virVMXFloppyDiskNameToUnit(def->dst, &unit) < 0) return -1; - } floppy_present[unit] = true; @@ -3589,9 +3511,8 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def, if (src) { fileName = ctx->formatFileName(src, ctx->opaque); - if (fileName == NULL) { + if (fileName == NULL) return -1; - } virBufferAsprintf(buffer, "floppy%d.fileName = \"%s\"\n", unit, fileName); @@ -3784,9 +3705,8 @@ virVMXFormatSerial(virVMXContext *ctx, virDomainChrDefPtr def, fileName = ctx->formatFileName(def->source.data.file.path, ctx->opaque); - if (fileName == NULL) { + if (fileName == NULL) return -1; - } virBufferAsprintf(buffer, "serial%d.fileName = \"%s\"\n", def->target.port, fileName); @@ -3891,9 +3811,8 @@ virVMXFormatParallel(virVMXContext *ctx, virDomainChrDefPtr def, fileName = ctx->formatFileName(def->source.data.file.path, ctx->opaque); - if (fileName == NULL) { + if (fileName == NULL) return -1; - } virBufferAsprintf(buffer, "parallel%d.fileName = \"%s\"\n", def->target.port, fileName); -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/conf/capabilities.c | 3 +- src/conf/domain_conf.c | 135 +++++++++++++++----------------------------- src/conf/interface_conf.c | 9 +-- src/conf/network_conf.c | 51 ++++++----------- src/conf/node_device_conf.c | 15 ++--- src/conf/nwfilter_conf.c | 12 ++-- src/conf/object_event.c | 6 +- src/conf/storage_conf.c | 24 +++----- 8 files changed, 85 insertions(+), 170 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index dc2c01a..37d19c1 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -219,9 +219,8 @@ virCapabilitiesDispose(void *object) VIR_FREE(caps->host.migrateTrans[i]); VIR_FREE(caps->host.migrateTrans); - for (i = 0; i < caps->host.nsecModels; i++) { + for (i = 0; i < caps->host.nsecModels; i++) virCapabilitiesClearSecModel(&caps->host.secModels[i]); - } VIR_FREE(caps->host.secModels); VIR_FREE(caps->host.pagesSize); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2c65276..5f4b9f6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2008,9 +2008,8 @@ virDomainVcpuPinDefArrayFree(virDomainVcpuPinDefPtr *def, if (!def) return; - for (i = 0; i < nvcpupin; i++) { + for (i = 0; i < nvcpupin; i++) virDomainVcpuPinDefFree(def[i]); - } VIR_FREE(def); } @@ -2689,9 +2688,8 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) { VIR_FREE(info->alias); - if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) { + if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) VIR_FREE(info->addr.usb.port); - } memset(&info->addr, 0, sizeof(info->addr)); info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE; VIR_FREE(info->romfile); @@ -4804,9 +4802,8 @@ virDomainDiskDefAssignAddress(virDomainXMLOptionPtr xmlopt, def->info.addr.drive.unit = idx % 15; /* Skip the SCSI controller at unit 7 */ - if (def->info.addr.drive.unit >= 7) { + if (def->info.addr.drive.unit >= 7) ++def->info.addr.drive.unit; - } } else { /* For a narrow SCSI bus we define the default mapping to be * 7 units per bus, 1 bus per controller, many controllers */ @@ -5081,9 +5078,8 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, error: ctxt->node = saved_node; - for (; i > 0; i--) { + for (; i > 0; i--) virSecurityLabelDefFree(def->seclabels[i - 1]); - } VIR_FREE(def->seclabels); def->nseclabels = 0; VIR_FREE(list); @@ -5187,9 +5183,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, return 0; error: - for (i = 0; i < nseclabels; i++) { + for (i = 0; i < nseclabels; i++) virSecurityDeviceLabelDefFree(seclabels[i]); - } VIR_FREE(seclabels); VIR_FREE(list); return -1; @@ -6143,9 +6138,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } } else { - if (def->bus == VIR_DOMAIN_DISK_BUS_USB) { + if (def->bus == VIR_DOMAIN_DISK_BUS_USB) def->removable = VIR_TRISTATE_SWITCH_ABSENT; - } } if (def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY && @@ -8329,9 +8323,8 @@ virDomainChrDefParseXML(xmlXPathContextPtr ctxt, if (cur->type == XML_ELEMENT_NODE) { if (xmlStrEqual(cur->name, BAD_CAST "target")) { seenTarget = true; - if (virDomainChrDefParseTargetXML(def, cur) < 0) { + if (virDomainChrDefParseTargetXML(def, cur) < 0) goto error; - } } } cur = cur->next; @@ -9105,9 +9098,8 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if (virDomainGraphicsListenGetType(def, i) == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { found = virDomainGraphicsListenGetAddress(def, i); - if (STREQ_NULLABLE(found, listenAddr)) { + if (STREQ_NULLABLE(found, listenAddr)) matched = true; - } break; } } @@ -9243,16 +9235,14 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.rdp.port = 0; if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { - if (STREQ(replaceUser, "yes")) { + if (STREQ(replaceUser, "yes")) def->data.rdp.replaceUser = true; - } VIR_FREE(replaceUser); } if ((multiUser = virXMLPropString(node, "multiUser")) != NULL) { - if (STREQ(multiUser, "yes")) { + if (STREQ(multiUser, "yes")) def->data.rdp.multiUser = true; - } VIR_FREE(multiUser); } @@ -10452,9 +10442,8 @@ virDomainRedirdevDefParseXML(xmlNodePtr node, if (remaining < 0) goto error; - if (def->source.chr.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) { + if (def->source.chr.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) def->source.chr.data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR; - } if (virDomainDeviceInfoParseXML(node, bootHash, &def->info, flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0) @@ -10648,9 +10637,8 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, goto error; ctxt->node = node; - if ((n = virXPathNodeSet("./usbdev", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./usbdev", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->usbdevs, n) < 0) goto error; @@ -11709,9 +11697,8 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, } /* analysis of the boot devices */ - if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) goto cleanup; - } if (n > 0 && deviceBoot) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -13250,9 +13237,8 @@ virDomainDefParseXML(xmlDocPtr xml, def->os.init = virXPathString("string(./os/init[1])", ctxt); def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt); - if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0) goto error; - } if (VIR_ALLOC_N(def->os.initargv, n+1) < 0) goto error; @@ -13392,9 +13378,8 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(nodes); /* analysis of the filesystems */ - if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/filesystem", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->fss, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13408,9 +13393,8 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(nodes); /* analysis of the network devices */ - if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/interface", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->nets, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13437,9 +13421,8 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of the smartcard devices */ - if ((n = virXPathNodeSet("./devices/smartcard", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/smartcard", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->smartcards, n) < 0) goto error; @@ -13455,9 +13438,8 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of the character devices */ - if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/parallel", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->parallels, n) < 0) goto error; @@ -13531,9 +13513,8 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/channel", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->channels, n) < 0) goto error; @@ -13571,9 +13552,8 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of the input devices */ - if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/input", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->inputs, n) < 0) goto error; @@ -13613,9 +13593,8 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(nodes); /* analysis of the graphics devices */ - if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/graphics", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->graphics, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13649,9 +13628,8 @@ virDomainDefParseXML(xmlDocPtr xml, } /* analysis of the sound devices */ - if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/sound", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->sounds, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13666,9 +13644,8 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(nodes); /* analysis of the video devices */ - if ((n = virXPathNodeSet("./devices/video", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/video", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->videos, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13723,9 +13700,8 @@ virDomainDefParseXML(xmlDocPtr xml, } /* analysis of the host devices */ - if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/hostdev", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_REALLOC_N(def->hostdevs, def->nhostdevs + n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13754,9 +13730,8 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of the watchdog devices */ def->watchdog = NULL; - if ((n = virXPathNodeSet("./devices/watchdog", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/watchdog", ctxt, &nodes)) < 0) goto error; - } if (n > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("only a single watchdog device is supported")); @@ -13774,9 +13749,8 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of the memballoon devices */ def->memballoon = NULL; - if ((n = virXPathNodeSet("./devices/memballoon", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/memballoon", ctxt, &nodes)) < 0) goto error; - } if (n > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("only a single memory balloon device is supported")); @@ -13824,9 +13798,8 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); - if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0) goto error; - } if (n > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -13842,9 +13815,8 @@ virDomainDefParseXML(xmlDocPtr xml, } /* analysis of the hub devices */ - if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/hub", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->hubs, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13865,9 +13837,8 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(nodes); /* analysis of the redirected devices */ - if ((n = virXPathNodeSet("./devices/redirdev", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/redirdev", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->redirdevs, n) < 0) goto error; for (i = 0; i < n; i++) { @@ -13890,9 +13861,8 @@ virDomainDefParseXML(xmlDocPtr xml, VIR_FREE(nodes); /* analysis of the redirection filter rules */ - if ((n = virXPathNodeSet("./devices/redirfilter", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/redirfilter", ctxt, &nodes)) < 0) goto error; - } if (n > 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("only one set of redirection filter rule is supported")); @@ -13911,9 +13881,8 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of the panic devices */ def->panic = NULL; - if ((n = virXPathNodeSet("./devices/panic", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/panic", ctxt, &nodes)) < 0) goto error; - } if (n > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("only a single panic device is supported")); @@ -13930,9 +13899,8 @@ virDomainDefParseXML(xmlDocPtr xml, } /* analysis of the shmem devices */ - if ((n = virXPathNodeSet("./devices/shmem", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./devices/shmem", ctxt, &nodes)) < 0) goto error; - } if (n && VIR_ALLOC_N(def->shmems, n) < 0) goto error; @@ -14106,9 +14074,8 @@ virDomainObjParseXML(xmlDocPtr xml, } obj->pid = (pid_t)val; - if ((n = virXPathNodeSet("./taint", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./taint", ctxt, &nodes)) < 0) goto error; - } for (i = 0; i < n; i++) { char *str = virXMLPropString(nodes[i], "flag"); if (str) { @@ -15886,9 +15853,8 @@ virDomainEmulatorPinAdd(virDomainDefPtr def, int virDomainEmulatorPinDel(virDomainDefPtr def) { - if (!def->cputune.emulatorpin) { + if (!def->cputune.emulatorpin) return 0; - } virDomainVcpuPinDefFree(def->cputune.emulatorpin); def->cputune.emulatorpin = NULL; @@ -16588,9 +16554,8 @@ virDomainControllerDefFormat(virBufferPtr buf, "<controller type='%s' index='%u'", type, def->idx); - if (model) { + if (model) virBufferEscapeString(buf, " model='%s'", model); - } switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: @@ -17556,9 +17521,8 @@ virDomainChrDefFormat(virBufferPtr buf, } case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO: { - if (def->target.name) { + if (def->target.name) virBufferEscapeString(buf, " name='%s'", def->target.name); - } break; } @@ -18114,9 +18078,8 @@ virDomainTimerDefFormat(virBufferPtr buf, } if (def->name == VIR_DOMAIN_TIMER_NAME_TSC) { - if (def->frequency > 0) { + if (def->frequency > 0) virBufferAsprintf(buf, " frequency='%lu'", def->frequency); - } if (def->mode != -1) { const char *mode @@ -18138,15 +18101,12 @@ virDomainTimerDefFormat(virBufferPtr buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); virBufferAddLit(buf, "<catchup"); - if (def->catchup.threshold > 0) { + if (def->catchup.threshold > 0) virBufferAsprintf(buf, " threshold='%lu'", def->catchup.threshold); - } - if (def->catchup.slew > 0) { + if (def->catchup.slew > 0) virBufferAsprintf(buf, " slew='%lu'", def->catchup.slew); - } - if (def->catchup.limit > 0) { + if (def->catchup.limit > 0) virBufferAsprintf(buf, " limit='%lu'", def->catchup.limit); - } virBufferAddLit(buf, "/>\n"); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</timer>\n"); @@ -20536,9 +20496,8 @@ virDomainNetGetActualBridgeName(virDomainNetDefPtr iface) return iface->data.bridge.brname; if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && iface->data.network.actual && - iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { + iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_BRIDGE) return iface->data.network.actual->data.bridge.brname; - } return NULL; } @@ -20549,9 +20508,8 @@ virDomainNetGetActualDirectDev(virDomainNetDefPtr iface) return iface->data.direct.linkdev; if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && iface->data.network.actual && - iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_DIRECT) { + iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_DIRECT) return iface->data.network.actual->data.direct.linkdev; - } return NULL; } @@ -20562,9 +20520,8 @@ virDomainNetGetActualDirectMode(virDomainNetDefPtr iface) return iface->data.direct.mode; if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && iface->data.network.actual && - iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_DIRECT) { + iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_DIRECT) return iface->data.network.actual->data.direct.mode; - } return 0; } @@ -20575,9 +20532,8 @@ virDomainNetGetActualHostdev(virDomainNetDefPtr iface) return &iface->data.hostdev.def; if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && iface->data.network.actual && - iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) { + iface->data.network.actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) return &iface->data.network.actual->data.hostdev.def; - } return NULL; } @@ -20612,9 +20568,8 @@ virDomainNetGetActualBandwidth(virDomainNetDefPtr iface) * its bandwidth rather than the NetDef's bandwidth. */ if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && - iface->data.network.actual) { + iface->data.network.actual) return iface->data.network.actual->bandwidth; - } return iface->bandwidth; } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 10c7c09..c2eb945 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -60,9 +60,8 @@ void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def) if (def == NULL) return; - for (i = 0; i < def->nips; i++) { + for (i = 0; i < def->nips; i++) virInterfaceIpDefFree(def->ips[i]); - } VIR_FREE(def->ips); VIR_FREE(def->family); VIR_FREE(def->gateway); @@ -106,9 +105,8 @@ void virInterfaceDefFree(virInterfaceDefPtr def) } /* free all protos */ - for (pp = 0; pp < def->nprotos; pp++) { + for (pp = 0; pp < def->nprotos; pp++) virInterfaceProtocolDefFree(def->protos[pp]); - } VIR_FREE(def->protos); VIR_FREE(def); } @@ -1081,9 +1079,8 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def, virInterfaceProtocolDefFormat(buf, def); } - if (def->type != VIR_INTERFACE_TYPE_BRIDGE) { + if (def->type != VIR_INTERFACE_TYPE_BRIDGE) virInterfaceLinkFormat(buf, &def->lnk); - } switch (def->type) { case VIR_INTERFACE_TYPE_ETHERNET: if (def->mac) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 3bad07d..067334e 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -218,14 +218,12 @@ virNetworkForwardDefClear(virNetworkForwardDefPtr def) { size_t i; - for (i = 0; i < def->npfs && def->pfs; i++) { + for (i = 0; i < def->npfs && def->pfs; i++) virNetworkForwardPfDefClear(&def->pfs[i]); - } VIR_FREE(def->pfs); - for (i = 0; i < def->nifs && def->ifs; i++) { + for (i = 0; i < def->nifs && def->ifs; i++) virNetworkForwardIfDefClear(&def->ifs[i]); - } VIR_FREE(def->ifs); def->nifs = def->npfs = 0; } @@ -244,19 +242,16 @@ virNetworkDefFree(virNetworkDefPtr def) virNetworkForwardDefClear(&def->forward); - for (i = 0; i < def->nips && def->ips; i++) { + for (i = 0; i < def->nips && def->ips; i++) virNetworkIpDefClear(&def->ips[i]); - } VIR_FREE(def->ips); - for (i = 0; i < def->nroutes && def->routes; i++) { + for (i = 0; i < def->nroutes && def->routes; i++) virNetworkRouteDefClear(&def->routes[i]); - } VIR_FREE(def->routes); - for (i = 0; i < def->nPortGroups && def->portGroups; i++) { + for (i = 0; i < def->nPortGroups && def->portGroups; i++) virPortGroupDefClear(&def->portGroups[i]); - } VIR_FREE(def->portGroups); virNetworkDNSDefClear(&def->dns); @@ -596,9 +591,8 @@ virNetworkDefGetIpByIndex(const virNetworkDef *def, if (!def->ips || n >= def->nips) return NULL; - if (family == AF_UNSPEC) { + if (family == AF_UNSPEC) return &def->ips[n]; - } /* find the nth ip of type "family" */ for (i = 0; i < def->nips; i++) { @@ -1363,9 +1357,8 @@ virNetworkIPDefParseXML(const char *networkName, result = 0; cleanup: - if (result < 0) { + if (result < 0) virNetworkIpDefClear(def); - } VIR_FREE(address); VIR_FREE(netmask); @@ -1589,9 +1582,8 @@ virNetworkRouteDefParseXML(const char *networkName, result = 0; cleanup: - if (result < 0) { + if (result < 0) virNetworkRouteDefClear(def); - } VIR_FREE(address); VIR_FREE(netmask); VIR_FREE(gateway); @@ -1663,9 +1655,8 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def, result = 0; cleanup: - if (result < 0) { + if (result < 0) virPortGroupDefClear(def); - } VIR_FREE(isDefault); VIR_FREE(trustGuestRxFilters); @@ -2483,9 +2474,8 @@ virNetworkIpDefFormat(virBufferPtr buf, virBufferAddLit(buf, "<ip"); - if (def->family) { + if (def->family) virBufferAsprintf(buf, " family='%s'", def->family); - } if (VIR_SOCKET_ADDR_VALID(&def->address)) { char *addr = virSocketAddrFormat(&def->address); if (!addr) @@ -2500,9 +2490,8 @@ virNetworkIpDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " netmask='%s'", addr); VIR_FREE(addr); } - if (def->prefix > 0) { + if (def->prefix > 0) virBufferAsprintf(buf, " prefix='%u'", def->prefix); - } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); @@ -2580,9 +2569,8 @@ virNetworkRouteDefFormat(virBufferPtr buf, virBufferAddLit(buf, "<route"); - if (def->family) { + if (def->family) virBufferAsprintf(buf, " family='%s'", def->family); - } if (VIR_SOCKET_ADDR_VALID(&def->address)) { char *addr = virSocketAddrFormat(&def->address); @@ -2599,9 +2587,8 @@ virNetworkRouteDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " netmask='%s'", addr); VIR_FREE(addr); } - if (def->has_prefix) { + if (def->has_prefix) virBufferAsprintf(buf, " prefix='%u'", def->prefix); - } if (VIR_SOCKET_ADDR_VALID(&def->gateway)) { char *addr = virSocketAddrFormat(&def->gateway); if (!addr) @@ -2609,9 +2596,8 @@ virNetworkRouteDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " gateway='%s'", addr); VIR_FREE(addr); } - if (def->has_metric && def->metric > 0) { + if (def->has_metric && def->metric > 0) virBufferAsprintf(buf, " metric='%u'", def->metric); - } virBufferAddLit(buf, "/>\n"); result = 0; @@ -2624,9 +2610,8 @@ virPortGroupDefFormat(virBufferPtr buf, const virPortGroupDef *def) { virBufferAsprintf(buf, "<portgroup name='%s'", def->name); - if (def->isDefault) { + if (def->isDefault) virBufferAddLit(buf, " default='yes'"); - } if (def->trustGuestRxFilters) virBufferAsprintf(buf, " trustGuestRxFilters='%s'", virTristateBoolTypeToString(def->trustGuestRxFilters)); @@ -2703,9 +2688,8 @@ virNetworkDefFormatBuf(virBufferPtr buf, bool shortforward; virBufferAddLit(buf, "<network"); - if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0)) { + if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0)) virBufferAsprintf(buf, " connections='%d'", def->connections); - } if (def->ipv6nogw) virBufferAddLit(buf, " ipv6='yes'"); if (def->trustGuestRxFilters) @@ -3326,9 +3310,8 @@ char *virNetworkAllocateBridge(virNetworkObjListPtr nets, do { if (virAsprintf(&newname, template, id) < 0) return NULL; - if (!virNetworkBridgeInUse(nets, newname, NULL)) { + if (!virNetworkBridgeInUse(nets, newname, NULL)) return newname; - } VIR_FREE(newname); id++; diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 2a947df..2a609e4 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -669,9 +669,8 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, data->storage.vendor = virXPathString("string(./vendor[1])", ctxt); data->storage.serial = virXPathString("string(./serial[1])", ctxt); - if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) goto out; - } for (i = 0; i < n; i++) { char *type = virXMLPropString(nodes[i], "type"); @@ -841,9 +840,8 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } } - if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) goto out; - } for (i = 0; i < n; i++) { type = virXMLPropString(nodes[i], "type"); @@ -1453,9 +1451,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, /* Parse device capabilities */ nodes = NULL; - if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) { + if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) goto error; - } if (n == 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1656,13 +1653,11 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) VIR_FREE(data->pci_dev.product_name); VIR_FREE(data->pci_dev.vendor_name); VIR_FREE(data->pci_dev.physical_function); - for (i = 0; i < data->pci_dev.num_virtual_functions; i++) { + for (i = 0; i < data->pci_dev.num_virtual_functions; i++) VIR_FREE(data->pci_dev.virtual_functions[i]); - } VIR_FREE(data->pci_dev.virtual_functions); - for (i = 0; i < data->pci_dev.nIommuGroupDevices; i++) { + for (i = 0; i < data->pci_dev.nIommuGroupDevices; i++) VIR_FREE(data->pci_dev.iommuGroupDevices[i]); - } VIR_FREE(data->pci_dev.iommuGroupDevices); virPCIEDeviceInfoFree(data->pci_dev.pci_express); break; diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 4b22709..074d745 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -535,9 +535,8 @@ checkVlanVlanID(enum attrDatatype datatype, union data *value, int32_t res; res = value->ui; - if (res < 0 || res > 4095) { + if (res < 0 || res > 4095) res = -1; - } if (res != -1) { nwf->p.vlanHdrFilter.dataVlanID.u.u16 = res; @@ -2899,9 +2898,8 @@ static virNWFilterCallbackDriverPtr callbackDrvArray[MAX_CALLBACK_DRIVER]; void virNWFilterRegisterCallbackDriver(virNWFilterCallbackDriverPtr cbd) { - if (nCallbackDriver < MAX_CALLBACK_DRIVER) { + if (nCallbackDriver < MAX_CALLBACK_DRIVER) callbackDrvArray[nCallbackDriver++] = cbd; - } } void @@ -3141,9 +3139,8 @@ virNWFilterObjLoad(virNWFilterObjListPtr nwfilters, virNWFilterDefPtr def; virNWFilterObjPtr nwfilter; - if (!(def = virNWFilterDefParseFile(path))) { + if (!(def = virNWFilterDefParseFile(path))) return NULL; - } if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { virReportError(VIR_ERR_XML_ERROR, @@ -3177,9 +3174,8 @@ virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters, int ret = -1; if (!(dir = opendir(configDir))) { - if (errno == ENOENT) { + if (errno == ENOENT) return 0; - } virReportSystemError(errno, _("Failed to open dir '%s'"), configDir); return -1; diff --git a/src/conf/object_event.c b/src/conf/object_event.c index beef3e1..06eedff 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -388,9 +388,8 @@ virObjectEventCallbackListAddID(virConnectPtr conn, callback, opaque, legacy, callbackID, serverFilter); /* Check incoming */ - if (!cbList) { + if (!cbList) return -1; - } /* If there is no additional filtering, then check if we already * have this callback on our list. */ @@ -460,9 +459,8 @@ virObjectEventQueueClear(virObjectEventQueuePtr queue) if (!queue) return; - for (i = 0; i < queue->count; i++) { + for (i = 0; i < queue->count; i++) virObjectUnref(queue->events[i]); - } VIR_FREE(queue->events); queue->count = 0; } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 1251b47..6ad37f8 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -333,9 +333,8 @@ virStorageVolDefFree(virStorageVolDefPtr def) VIR_FREE(def->name); VIR_FREE(def->key); - for (i = 0; i < def->source.nextent; i++) { + for (i = 0; i < def->source.nextent; i++) VIR_FREE(def->source.extents[i].path); - } VIR_FREE(def->source.extents); virStorageSourceClear(&def->target); @@ -370,9 +369,8 @@ virStoragePoolSourceClear(virStoragePoolSourcePtr source) if (!source) return; - for (i = 0; i < source->nhost; i++) { + for (i = 0; i < source->nhost; i++) VIR_FREE(source->hosts[i].name); - } VIR_FREE(source->hosts); for (i = 0; i < source->ndevice; i++) @@ -481,9 +479,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, relnode = ctxt->node; ctxt->node = node; - if ((options = virStoragePoolOptionsForPoolType(pool_type)) == NULL) { + if ((options = virStoragePoolOptionsForPoolType(pool_type)) == NULL) goto cleanup; - } source->name = virXPathString("string(./name)", ctxt); if (pool_type == VIR_STORAGE_POOL_RBD && source->name == NULL) { @@ -833,9 +830,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) goto error; } - if ((options = virStoragePoolOptionsForPoolType(ret->type)) == NULL) { + if ((options = virStoragePoolOptionsForPoolType(ret->type)) == NULL) goto error; - } source_node = virXPathNode("./source", ctxt); if (source_node) { @@ -945,13 +941,11 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) * path and permissions */ if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) { if (ret->type == VIR_STORAGE_POOL_LOGICAL) { - if (virAsprintf(&target_path, "/dev/%s", ret->source.name) < 0) { + if (virAsprintf(&target_path, "/dev/%s", ret->source.name) < 0) goto error; - } } else if (ret->type == VIR_STORAGE_POOL_ZFS) { - if (virAsprintf(&target_path, "/dev/zvol/%s", ret->source.name) < 0) { + if (virAsprintf(&target_path, "/dev/zvol/%s", ret->source.name) < 0) goto error; - } } else { target_path = virXPathString("string(./target/path)", ctxt); if (!target_path) { @@ -1814,9 +1808,8 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def; virStoragePoolObjPtr pool; - if (!(def = virStoragePoolDefParseFile(path))) { + if (!(def = virStoragePoolDefParseFile(path))) return NULL; - } if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { virReportError(VIR_ERR_XML_ERROR, @@ -2006,9 +1999,8 @@ virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def) virBufferAddLit(&buf, "<sources>\n"); virBufferAdjustIndent(&buf, 2); - for (i = 0; i < def->nsources; i++) { + for (i = 0; i < def->nsources; i++) virStoragePoolSourceFormat(&buf, options, &def->sources[i]); - } virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</sources>\n"); -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/hyperv/hyperv_device_monitor.c | 3 +- src/hyperv/hyperv_driver.c | 87 ++++++++++++------------------------ src/hyperv/hyperv_interface_driver.c | 3 +- src/hyperv/hyperv_network_driver.c | 3 +- src/hyperv/hyperv_nwfilter_driver.c | 3 +- src/hyperv/hyperv_secret_driver.c | 3 +- src/hyperv/hyperv_storage_driver.c | 3 +- src/hyperv/hyperv_util.c | 6 +-- src/hyperv/hyperv_wmi.c | 39 ++++++---------- 9 files changed, 50 insertions(+), 100 deletions(-) diff --git a/src/hyperv/hyperv_device_monitor.c b/src/hyperv/hyperv_device_monitor.c index 23411cd..c24c384 100644 --- a/src/hyperv/hyperv_device_monitor.c +++ b/src/hyperv/hyperv_device_monitor.c @@ -40,9 +40,8 @@ hypervNodeDeviceOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_HYPERV) { + if (conn->driver->no != VIR_DRV_HYPERV) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 5ffcb85..ece943e 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -49,9 +49,8 @@ VIR_LOG_INIT("hyperv.hyperv_driver"); static void hypervFreePrivate(hypervPrivate **priv) { - if (priv == NULL || *priv == NULL) { + if (priv == NULL || *priv == NULL) return; - } if ((*priv)->client != NULL) { /* FIXME: This leaks memory due to bugs in openwsman <= 2.2.6 */ @@ -78,17 +77,15 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* Decline if the URI is NULL or the scheme is NULL */ - if (conn->uri == NULL || conn->uri->scheme == NULL) { + if (conn->uri == NULL || conn->uri->scheme == NULL) return VIR_DRV_OPEN_DECLINED; - } /* Decline if the scheme is not hyperv */ plus = strchr(conn->uri->scheme, '+'); if (plus == NULL) { - if (STRCASENEQ(conn->uri->scheme, "hyperv")) { + if (STRCASENEQ(conn->uri->scheme, "hyperv")) return VIR_DRV_OPEN_DECLINED; - } } else { if (plus - conn->uri->scheme != 6 || STRCASENEQLEN(conn->uri->scheme, "hyperv", 6)) { @@ -119,9 +116,8 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags if (VIR_ALLOC(priv) < 0) goto cleanup; - if (hypervParseUri(&priv->parsedUri, conn->uri) < 0) { + if (hypervParseUri(&priv->parsedUri, conn->uri) < 0) goto cleanup; - } /* Set the port dependent on the transport protocol if no port is * specified. This allows us to rely on the port parameter being @@ -182,9 +178,8 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags virBufferAddLit(&query, "where "); virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_PHYSICAL); - if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) { + if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; - } if (computerSystem == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -239,9 +234,8 @@ hypervConnectGetHostname(virConnectPtr conn) virBufferAddLit(&query, WIN32_COMPUTERSYSTEM_WQL_SELECT); - if (hypervGetWin32ComputerSystemList(priv, &query, &computerSystem) < 0) { + if (hypervGetWin32ComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; - } if (computerSystem == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -276,9 +270,8 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) virBufferAddLit(&query, WIN32_COMPUTERSYSTEM_WQL_SELECT); /* Get Win32_ComputerSystem */ - if (hypervGetWin32ComputerSystemList(priv, &query, &computerSystem) < 0) { + if (hypervGetWin32ComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; - } if (computerSystem == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -295,9 +288,8 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) "ResultClass = Win32_Processor", computerSystem->data->Name); - if (hypervGetWin32ProcessorList(priv, &query, &processorList) < 0) { + if (hypervGetWin32ProcessorList(priv, &query, &processorList) < 0) goto cleanup; - } if (processorList == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -368,9 +360,8 @@ hypervConnectListDomains(virConnectPtr conn, int *ids, int maxids) Msvm_ComputerSystem *computerSystem = NULL; int count = 0; - if (maxids == 0) { + if (maxids == 0) return 0; - } virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); virBufferAddLit(&query, "where "); @@ -387,9 +378,8 @@ hypervConnectListDomains(virConnectPtr conn, int *ids, int maxids) computerSystem = computerSystem->next) { ids[count++] = computerSystem->data->ProcessID; - if (count >= maxids) { + if (count >= maxids) break; - } } success = true; @@ -451,9 +441,8 @@ hypervDomainLookupByID(virConnectPtr conn, int id) virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); virBufferAsprintf(&query, "and ProcessID = %d", id); - if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) { + if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; - } if (computerSystem == NULL) { virReportError(VIR_ERR_NO_DOMAIN, _("No domain with ID %d"), id); @@ -486,9 +475,8 @@ hypervDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); virBufferAsprintf(&query, "and Name = \"%s\"", uuid_string); - if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) { + if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; - } if (computerSystem == NULL) { virReportError(VIR_ERR_NO_DOMAIN, @@ -519,9 +507,8 @@ hypervDomainLookupByName(virConnectPtr conn, const char *name) virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); virBufferAsprintf(&query, "and ElementName = \"%s\"", name); - if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) { + if (hypervGetMsvmComputerSystemList(priv, &query, &computerSystem) < 0) goto cleanup; - } if (computerSystem == NULL) { virReportError(VIR_ERR_NO_DOMAIN, @@ -546,9 +533,8 @@ hypervDomainSuspend(virDomainPtr domain) hypervPrivate *priv = domain->conn->privateData; Msvm_ComputerSystem *computerSystem = NULL; - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } if (computerSystem->data->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_ENABLED) { @@ -575,9 +561,8 @@ hypervDomainResume(virDomainPtr domain) hypervPrivate *priv = domain->conn->privateData; Msvm_ComputerSystem *computerSystem = NULL; - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } if (computerSystem->data->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_PAUSED) { @@ -607,9 +592,8 @@ hypervDomainDestroyFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } if (!hypervIsMsvmComputerSystemActive(computerSystem, &in_transition) || in_transition) { @@ -665,9 +649,8 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) virUUIDFormat(domain->uuid, uuid_string); /* Get Msvm_ComputerSystem */ - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } /* Get Msvm_VirtualSystemSettingData */ virBufferAsprintf(&query, @@ -764,15 +747,13 @@ hypervDomainGetState(virDomainPtr domain, int *state, int *reason, virCheckFlags(0, -1); - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } *state = hypervMsvmComputerSystemEnabledStateToDomainState(computerSystem); - if (reason != NULL) { + if (reason != NULL) *reason = 0; - } result = 0; @@ -805,9 +786,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virUUIDFormat(domain->uuid, uuid_string); /* Get Msvm_ComputerSystem */ - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } /* Get Msvm_VirtualSystemSettingData */ virBufferAsprintf(&query, @@ -932,9 +912,8 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn int count = 0; size_t i; - if (maxnames == 0) { + if (maxnames == 0) return 0; - } virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); virBufferAddLit(&query, "where "); @@ -954,18 +933,16 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn ++count; - if (count >= maxnames) { + if (count >= maxnames) break; - } } success = true; cleanup: if (!success) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) VIR_FREE(names[i]); - } count = -1; } @@ -1022,9 +999,8 @@ hypervDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } if (hypervIsMsvmComputerSystemActive(computerSystem, NULL)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -1103,9 +1079,8 @@ hypervDomainIsActive(virDomainPtr domain) hypervPrivate *priv = domain->conn->privateData; Msvm_ComputerSystem *computerSystem = NULL; - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } result = hypervIsMsvmComputerSystemActive(computerSystem, NULL) ? 1 : 0; @@ -1144,9 +1119,8 @@ hypervDomainManagedSave(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } if (!hypervIsMsvmComputerSystemActive(computerSystem, &in_transition) || in_transition) { @@ -1175,9 +1149,8 @@ hypervDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } result = computerSystem->data->EnabledState == MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED ? 1 : 0; @@ -1199,9 +1172,8 @@ hypervDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags) virCheckFlags(0, -1); - if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - } if (computerSystem->data->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED) { @@ -1338,9 +1310,8 @@ hypervConnectListAllDomains(virConnectPtr conn, cleanup: if (doms) { - for (i = 0; i < count; ++i) { + for (i = 0; i < count; ++i) virDomainFree(doms[i]); - } VIR_FREE(doms); } diff --git a/src/hyperv/hyperv_interface_driver.c b/src/hyperv/hyperv_interface_driver.c index 9b9e4e6..6529e37 100644 --- a/src/hyperv/hyperv_interface_driver.c +++ b/src/hyperv/hyperv_interface_driver.c @@ -40,9 +40,8 @@ hypervInterfaceOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_HYPERV) { + if (conn->driver->no != VIR_DRV_HYPERV) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/hyperv/hyperv_network_driver.c b/src/hyperv/hyperv_network_driver.c index ab2daad..93f3718 100644 --- a/src/hyperv/hyperv_network_driver.c +++ b/src/hyperv/hyperv_network_driver.c @@ -40,9 +40,8 @@ hypervNetworkOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_HYPERV) { + if (conn->driver->no != VIR_DRV_HYPERV) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/hyperv/hyperv_nwfilter_driver.c b/src/hyperv/hyperv_nwfilter_driver.c index 6165bf7..fc6ae19 100644 --- a/src/hyperv/hyperv_nwfilter_driver.c +++ b/src/hyperv/hyperv_nwfilter_driver.c @@ -40,9 +40,8 @@ hypervNWFilterOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_HYPERV) { + if (conn->driver->no != VIR_DRV_HYPERV) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/hyperv/hyperv_secret_driver.c b/src/hyperv/hyperv_secret_driver.c index 65587f0..31cf915 100644 --- a/src/hyperv/hyperv_secret_driver.c +++ b/src/hyperv/hyperv_secret_driver.c @@ -40,9 +40,8 @@ hypervSecretOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_HYPERV) { + if (conn->driver->no != VIR_DRV_HYPERV) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/hyperv/hyperv_storage_driver.c b/src/hyperv/hyperv_storage_driver.c index e3d4170..8fa1343 100644 --- a/src/hyperv/hyperv_storage_driver.c +++ b/src/hyperv/hyperv_storage_driver.c @@ -40,9 +40,8 @@ hypervStorageOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->driver->no != VIR_DRV_HYPERV) { + if (conn->driver->no != VIR_DRV_HYPERV) return VIR_DRV_OPEN_DECLINED; - } return VIR_DRV_OPEN_SUCCESS; } diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index ebf9eac..73b3269 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -78,9 +78,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) result = 0; cleanup: - if (result < 0) { + if (result < 0) hypervFreeParsedUri(parsedUri); - } return result; } @@ -90,9 +89,8 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) void hypervFreeParsedUri(hypervParsedUri **parsedUri) { - if (parsedUri == NULL || *parsedUri == NULL) { + if (parsedUri == NULL || *parsedUri == NULL) return; - } VIR_FREE((*parsedUri)->transport); diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 3027601..13acd09 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -157,9 +157,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, response = wsmc_action_enumerate(priv->client, root, options, filter); - if (hyperyVerifyResponse(priv->client, response, "enumeration") < 0) { + if (hyperyVerifyResponse(priv->client, response, "enumeration") < 0) goto cleanup; - } enumContext = wsmc_get_enum_context(response); @@ -170,9 +169,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, response = wsmc_action_pull(priv->client, resourceUri, options, filter, enumContext); - if (hyperyVerifyResponse(priv->client, response, "pull") < 0) { + if (hyperyVerifyResponse(priv->client, response, "pull") < 0) goto cleanup; - } node = ws_xml_get_soap_body(response); @@ -198,9 +196,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, goto cleanup; } - if (ws_xml_get_child(node, 0, resourceUri, className) == NULL) { + if (ws_xml_get_child(node, 0, resourceUri, className) == NULL) break; - } data = ws_deserialize(serializerContext, node, serializerInfo, className, resourceUri, NULL, 0, 0); @@ -240,13 +237,11 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, result = 0; cleanup: - if (options != NULL) { + if (options != NULL) wsmc_options_destroy(options); - } - if (filter != NULL) { + if (filter != NULL) filter_destroy(filter); - } if (data != NULL) { #if WS_SERIALIZER_FREE_MEM_WORKS @@ -275,9 +270,8 @@ hypervFreeObject(hypervPrivate *priv ATTRIBUTE_UNUSED, hypervObject *object) WsSerializerContextH serializerContext; #endif - if (object == NULL) { + if (object == NULL) return; - } #if WS_SERIALIZER_FREE_MEM_WORKS serializerContext = wsmc_get_serialization_context(priv->client); @@ -431,9 +425,8 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, response = wsmc_action_invoke(priv->client, MSVM_COMPUTERSYSTEM_RESOURCE_URI, options, "RequestStateChange", NULL); - if (hyperyVerifyResponse(priv->client, response, "invocation") < 0) { + if (hyperyVerifyResponse(priv->client, response, "invocation") < 0) goto cleanup; - } /* Check return value */ returnValue = ws_xml_get_xpath_value(response, (char *)"/s:Envelope/s:Body/p:RequestStateChange_OUTPUT/p:ReturnValue"); @@ -468,9 +461,8 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, virBufferAddLit(&query, MSVM_CONCRETEJOB_WQL_SELECT); virBufferAsprintf(&query, "where InstanceID = \"%s\"", instanceID); - if (hypervGetMsvmConcreteJobList(priv, &query, &concreteJob) < 0) { + if (hypervGetMsvmConcreteJobList(priv, &query, &concreteJob) < 0) goto cleanup; - } if (concreteJob == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -521,9 +513,8 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, result = 0; cleanup: - if (options != NULL) { + if (options != NULL) wsmc_options_destroy(options); - } ws_xml_destroy_doc(response); VIR_FREE(selector); @@ -576,9 +567,8 @@ bool hypervIsMsvmComputerSystemActive(Msvm_ComputerSystem *computerSystem, bool *in_transition) { - if (in_transition != NULL) { + if (in_transition != NULL) *in_transition = false; - } switch (computerSystem->data->EnabledState) { case MSVM_COMPUTERSYSTEM_ENABLEDSTATE_UNKNOWN: @@ -602,9 +592,8 @@ hypervIsMsvmComputerSystemActive(Msvm_ComputerSystem *computerSystem, case MSVM_COMPUTERSYSTEM_ENABLEDSTATE_STOPPING: case MSVM_COMPUTERSYSTEM_ENABLEDSTATE_PAUSING: case MSVM_COMPUTERSYSTEM_ENABLEDSTATE_RESUMING: - if (in_transition != NULL) { + if (in_transition != NULL) *in_transition = true; - } return true; @@ -634,9 +623,8 @@ hypervMsvmComputerSystemToDomain(virConnectPtr conn, *domain = virGetDomain(conn, computerSystem->data->ElementName, uuid); - if (*domain == NULL) { + if (*domain == NULL) return -1; - } if (hypervIsMsvmComputerSystemActive(computerSystem, NULL)) { (*domain)->id = computerSystem->data->ProcessID; @@ -667,9 +655,8 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr domain, virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL); virBufferAsprintf(&query, "and Name = \"%s\"", uuid_string); - if (hypervGetMsvmComputerSystemList(priv, &query, computerSystem) < 0) { + if (hypervGetMsvmComputerSystemList(priv, &query, computerSystem) < 0) return -1; - } if (*computerSystem == NULL) { virReportError(VIR_ERR_NO_DOMAIN, -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/node_device/node_device_driver.c | 21 +++------ src/node_device/node_device_hal.c | 6 +-- src/node_device/node_device_udev.c | 87 ++++++++++++------------------------ 3 files changed, 38 insertions(+), 76 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 5d58ca7..5d0efb4 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -48,9 +48,8 @@ static int update_caps(virNodeDeviceObjPtr dev) virNodeDevCapsDefPtr cap = dev->def->caps; while (cap) { - if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) { + if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) detect_scsi_host_caps(&dev->def->caps->data); - } if (cap->type == VIR_NODE_DEV_CAP_NET && virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.lnk) < 0) return -1; @@ -494,14 +493,12 @@ find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn) dev = nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); - if (dev != NULL) { + if (dev != NULL) break; - } sleep(5); - if (get_time(&now) == -1) { + if (get_time(&now) == -1) break; - } } nodeDeviceLock(driver); @@ -527,16 +524,14 @@ nodeDeviceCreateXML(virConnectPtr conn, nodeDeviceLock(driver); def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt_type); - if (def == NULL) { + if (def == NULL) goto cleanup; - } if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) goto cleanup; - if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) goto cleanup; - } if (virNodeDeviceGetParentHost(&driver->devs, def->name, @@ -556,9 +551,8 @@ nodeDeviceCreateXML(virConnectPtr conn, /* We don't check the return value, because one way or another, * we're returning what we get... */ - if (dev == NULL) { + if (dev == NULL) virReportError(VIR_ERR_NO_NODE_DEVICE, NULL); - } cleanup: nodeDeviceUnlock(driver); @@ -590,9 +584,8 @@ nodeDeviceDestroy(virNodeDevicePtr dev) if (virNodeDeviceDestroyEnsureACL(dev->conn, obj->def) < 0) goto out; - if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) goto out; - } /* virNodeDeviceGetParentHost will cause the device object's lock to be diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index ec37223..c32b1fe 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -255,9 +255,8 @@ gather_scsi_host_cap(LibHalContext *ctx, const char *udi, retval = detect_scsi_host_caps(d); - if (retval == -1) { + if (retval == -1) goto out; - } out: return retval; @@ -551,9 +550,8 @@ dev_refresh(const char *udi) } nodeDeviceUnlock(driverState); - if (dev) { + if (dev) dev_create(udi); - } } static void diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index f580a9b..343ef85 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -166,9 +166,8 @@ static int udevGetIntProperty(struct udev_device *udev_device, ret = udevGetDeviceProperty(udev_device, property_key, &udev_value); if (ret == PROPERTY_FOUND) { - if (udevStrToLong_i(udev_value, NULL, base, value) != 0) { + if (udevStrToLong_i(udev_value, NULL, base, value) != 0) ret = PROPERTY_ERROR; - } } VIR_FREE(udev_value); @@ -187,9 +186,8 @@ static int udevGetUintProperty(struct udev_device *udev_device, ret = udevGetDeviceProperty(udev_device, property_key, &udev_value); if (ret == PROPERTY_FOUND) { - if (udevStrToLong_ui(udev_value, NULL, base, value) != 0) { + if (udevStrToLong_ui(udev_value, NULL, base, value) != 0) ret = PROPERTY_ERROR; - } } VIR_FREE(udev_value); @@ -266,9 +264,8 @@ static int udevGetIntSysfsAttr(struct udev_device *udev_device, ret = udevGetDeviceSysfsAttr(udev_device, attr_name, &udev_value); if (ret == PROPERTY_FOUND) { - if (udevStrToLong_i(udev_value, NULL, base, value) != 0) { + if (udevStrToLong_i(udev_value, NULL, base, value) != 0) ret = PROPERTY_ERROR; - } } VIR_FREE(udev_value); @@ -287,9 +284,8 @@ static int udevGetUintSysfsAttr(struct udev_device *udev_device, ret = udevGetDeviceSysfsAttr(udev_device, attr_name, &udev_value); if (ret == PROPERTY_FOUND) { - if (udevStrToLong_ui(udev_value, NULL, base, value) != 0) { + if (udevStrToLong_ui(udev_value, NULL, base, value) != 0) ret = PROPERTY_ERROR; - } } VIR_FREE(udev_value); @@ -307,9 +303,8 @@ static int udevGetUint64SysfsAttr(struct udev_device *udev_device, ret = udevGetDeviceSysfsAttr(udev_device, attr_name, &udev_value); if (ret == PROPERTY_FOUND) { - if (udevStrToLong_ull(udev_value, NULL, 0, value) != 0) { + if (udevStrToLong_ull(udev_value, NULL, 0, value) != 0) ret = PROPERTY_ERROR; - } } VIR_FREE(udev_value); @@ -329,9 +324,8 @@ static int udevGenerateDeviceName(struct udev_device *device, udev_device_get_subsystem(device), udev_device_get_sysname(device)); - if (s != NULL) { + if (s != NULL) virBufferAsprintf(&buf, "_%s", s); - } if (virBufferCheckError(&buf) < 0) return -1; @@ -339,9 +333,8 @@ static int udevGenerateDeviceName(struct udev_device *device, def->name = virBufferContentAndReset(&buf); for (i = 0; i < strlen(def->name); i++) { - if (!(c_isalnum(*(def->name + i)))) { + if (!(c_isalnum(*(def->name + i)))) *(def->name + i) = '_'; - } } return ret; @@ -490,9 +483,8 @@ static int udevProcessPCI(struct udev_device *device, goto out; } - if (udevGenerateDeviceName(device, def, NULL) != 0) { + if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; - } rc = udevGetIntSysfsAttr(device, "numa_node", @@ -636,9 +628,8 @@ static int udevProcessUSBDevice(struct udev_device *device, } } - if (udevGenerateDeviceName(device, def, NULL) != 0) { + if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; - } ret = 0; @@ -681,9 +672,8 @@ static int udevProcessUSBInterface(struct udev_device *device, goto out; } - if (udevGenerateDeviceName(device, def, NULL) != 0) { + if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; - } ret = 0; @@ -724,9 +714,8 @@ static int udevProcessNetworkInterface(struct udev_device *device, goto out; } - if (udevGenerateDeviceName(device, def, data->net.address) != 0) { + if (udevGenerateDeviceName(device, def, data->net.address) != 0) goto out; - } if (virNetDevGetLinkInfo(data->net.ifname, &data->net.lnk) < 0) goto out; @@ -762,9 +751,8 @@ static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED, detect_scsi_host_caps(&def->caps->data); - if (udevGenerateDeviceName(device, def, NULL) != 0) { + if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; - } ret = 0; @@ -785,9 +773,8 @@ static int udevProcessSCSITarget(struct udev_device *device ATTRIBUTE_UNUSED, if (VIR_STRDUP(data->scsi_target.name, sysname) < 0) goto out; - if (udevGenerateDeviceName(device, def, NULL) != 0) { + if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; - } ret = 0; @@ -864,9 +851,8 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED, filename = last_component(def->sysfs_path); - if (udevStrToLong_ui(filename, &p, 10, &data->scsi.host) == -1) { + if (udevStrToLong_ui(filename, &p, 10, &data->scsi.host) == -1) goto out; - } if ((p == NULL) || (udevStrToLong_ui(p+1, &p, @@ -891,9 +877,8 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED, switch (udevGetUintSysfsAttr(device, "type", &tmp, 0)) { case PROPERTY_FOUND: - if (udevGetSCSIType(def, tmp, &data->scsi.type) == -1) { + if (udevGetSCSIType(def, tmp, &data->scsi.type) == -1) goto out; - } break; case PROPERTY_MISSING: break; /* No type is not an error */ @@ -903,9 +888,8 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED, break; } - if (udevGenerateDeviceName(device, def, NULL) != 0) { + if (udevGenerateDeviceName(device, def, NULL) != 0) goto out; - } ret = 0; @@ -1099,9 +1083,8 @@ static int udevKludgeStorageType(virNodeDeviceDefPtr def) static void udevStripSpaces(char *s) { - if (s == NULL) { + if (s == NULL) return; - } while (virFileStripSuffix(s, " ")) { /* do nothing */ @@ -1184,9 +1167,8 @@ static int udevProcessStorage(struct udev_device *device, } else { /* If udev doesn't have it, perhaps we can guess it. */ - if (udevKludgeStorageType(def) != 0) { + if (udevKludgeStorageType(def) != 0) goto out; - } } } @@ -1204,9 +1186,8 @@ static int udevProcessStorage(struct udev_device *device, goto out; } - if (udevGenerateDeviceName(device, def, data->storage.serial) != 0) { + if (udevGenerateDeviceName(device, def, data->storage.serial) != 0) goto out; - } out: VIR_DEBUG("Storage ret=%d", ret); @@ -1376,9 +1357,8 @@ static int udevSetParent(struct udev_device *device, do { parent_device = udev_device_get_parent(parent_device); - if (parent_device == NULL) { + if (parent_device == NULL) break; - } parent_sysfs_path = udev_device_get_syspath(parent_device); if (parent_sysfs_path == NULL) { @@ -1434,17 +1414,14 @@ static int udevAddOneDevice(struct udev_device *device) if (VIR_ALLOC(def->caps) != 0) goto out; - if (udevGetDeviceType(device, &def->caps->type) != 0) { + if (udevGetDeviceType(device, &def->caps->type) != 0) goto out; - } - if (udevGetDeviceDetails(device, def) != 0) { + if (udevGetDeviceDetails(device, def) != 0) goto out; - } - if (udevSetParent(device, def) != 0) { + if (udevSetParent(device, def) != 0) goto out; - } /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ @@ -1544,9 +1521,8 @@ static int nodeStateCleanup(void) udev_monitor_unref(udev_monitor); } - if (udev != NULL) { + if (udev != NULL) udev_unref(udev); - } virNodeDeviceObjListFree(&driverState->devs); nodeDeviceUnlock(driverState); @@ -1681,9 +1657,8 @@ udevGetDMIData(union _virNodeDevCapData *data) out: VIR_FREE(tmp); - if (device != NULL) { + if (device != NULL) udev_device_unref(device); - } return; } #endif @@ -1719,9 +1694,8 @@ static int udevSetupSystemDev(void) ret = 0; out: - if (ret == -1) { + if (ret == -1) virNodeDeviceDefFree(def); - } return ret; } @@ -1834,9 +1808,8 @@ static int nodeStateInitialize(bool privileged, nodeDeviceUnlock(driverState); out: - if (ret == -1) { + if (ret == -1) nodeStateCleanup(); - } return ret; } @@ -1853,9 +1826,8 @@ static virDrvOpenStatus nodeDeviceOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (driverState == NULL) { + if (driverState == NULL) return VIR_DRV_OPEN_DECLINED; - } conn->nodeDevicePrivateData = driverState; @@ -1896,9 +1868,8 @@ int udevNodeRegister(void) { VIR_DEBUG("Registering udev node device backend"); - if (virRegisterNodeDeviceDriver(&udevNodeDeviceDriver) < 0) { + if (virRegisterNodeDeviceDriver(&udevNodeDeviceDriver) < 0) return -1; - } return virRegisterStateDriver(&udevStateDriver); } -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_agent.c | 3 +-- src/qemu/qemu_capabilities.c | 9 +++------ src/qemu/qemu_cgroup.c | 6 ++---- src/qemu/qemu_command.c | 6 ++---- src/qemu/qemu_conf.c | 3 +-- src/qemu/qemu_domain.c | 3 +-- src/qemu/qemu_driver.c | 45 +++++++++++++++----------------------------- src/qemu/qemu_hotplug.c | 6 ++---- src/qemu/qemu_migration.c | 3 +-- src/qemu/qemu_monitor_json.c | 12 ++++-------- src/qemu/qemu_monitor_text.c | 6 ++---- src/qemu/qemu_process.c | 18 ++++++------------ 12 files changed, 40 insertions(+), 80 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 9f673bf..8df1330 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -381,9 +381,8 @@ static int qemuAgentIOProcessData(qemuAgentPtr mon, int got = nl - (data + used); for (i = 0; i < strlen(LINE_ENDING); i++) data[used + got + i] = '\0'; - if (qemuAgentIOProcessLine(mon, data + used, msg) < 0) { + if (qemuAgentIOProcessLine(mon, data + used, msg) < 0) return -1; - } used += got + strlen(LINE_ENDING); } else { break; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 74a3b24..7ae25f1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1179,9 +1179,8 @@ virQEMUCapsComputeCmdFlags(const char *help, if (is_kvm && (version >= 10000 || kvm_version >= 74)) virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNET_HDR); - if (strstr(help, ",vhost=")) { + if (strstr(help, ",vhost=")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_VHOST_NET); - } /* Do not use -no-shutdown if qemu doesn't support it or SIGTERM handling * is most likely buggy when used with -no-shutdown (which applies for qemu @@ -1937,9 +1936,8 @@ void virQEMUCapsDispose(void *obj) VIR_FREE(qemuCaps->machineAliases); VIR_FREE(qemuCaps->machineMaxCpus); - for (i = 0; i < qemuCaps->ncpuDefinitions; i++) { + for (i = 0; i < qemuCaps->ncpuDefinitions; i++) VIR_FREE(qemuCaps->cpuDefinitions[i]); - } VIR_FREE(qemuCaps->cpuDefinitions); virBitmapFree(qemuCaps->flags); @@ -2827,9 +2825,8 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps) qemuCaps->arch = VIR_ARCH_NONE; qemuCaps->usedQMP = false; - for (i = 0; i < qemuCaps->ncpuDefinitions; i++) { + for (i = 0; i < qemuCaps->ncpuDefinitions; i++) VIR_FREE(qemuCaps->cpuDefinitions[i]); - } VIR_FREE(qemuCaps->cpuDefinitions); qemuCaps->ncpuDefinitions = 0; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 3b1d16d..0e94cae 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -920,9 +920,8 @@ qemuSetupCgroupVcpuPin(virCgroupPtr cgroup, size_t i; for (i = 0; i < nvcpupin; i++) { - if (vcpuid == vcpupin[i]->vcpuid) { + if (vcpuid == vcpupin[i]->vcpuid) return qemuSetupCgroupEmulatorPin(cgroup, vcpupin[i]->cpumask); - } } return -1; @@ -937,9 +936,8 @@ qemuSetupCgroupIOThreadsPin(virCgroupPtr cgroup, size_t i; for (i = 0; i < niothreadspin; i++) { - if (iothreadid == iothreadspin[i]->vcpuid) { + if (iothreadid == iothreadspin[i]->vcpuid) return qemuSetupCgroupEmulatorPin(cgroup, iothreadspin[i]->cpumask); - } } return -1; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f674ba9..6df351f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8862,9 +8862,8 @@ qemuBuildCommandLine(virConnectPtr conn, _("network disks are only supported with -drive")); goto error; } else { - if (VIR_STRDUP(file, disk->src->path) < 0) { + if (VIR_STRDUP(file, disk->src->path) < 0) goto error; - } } /* Don't start with source if the tray is open for @@ -10144,9 +10143,8 @@ static int qemuStringToArgvEnv(const char *args, start = curr; /* accept a space in CEPH_ARGS */ - if (STRPREFIX(curr, "CEPH_ARGS=-m ")) { + if (STRPREFIX(curr, "CEPH_ARGS=-m ")) start += strlen("CEPH_ARGS=-m "); - } if (*start == '\'') { if (start == curr) curr++; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 1ae90ff..4764bef 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1018,9 +1018,8 @@ qemuSharedDeviceEntryFree(void *payload, const void *name ATTRIBUTE_UNUSED) if (!entry) return; - for (i = 0; i < entry->ref; i++) { + for (i = 0; i < entry->ref; i++) VIR_FREE(entry->domains[i]); - } VIR_FREE(entry->domains); VIR_FREE(entry); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8e91a48..01bf39b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -495,9 +495,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data) size_t i; virBufferAddLit(buf, "<vcpus>\n"); virBufferAdjustIndent(buf, 2); - for (i = 0; i < priv->nvcpupids; i++) { + for (i = 0; i < priv->nvcpupids; i++) virBufferAsprintf(buf, "<vcpu pid='%d'/>\n", priv->vcpupids[i]); - } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</vcpus>\n"); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 411179d..7e21ffd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -995,9 +995,8 @@ qemuStateStop(void) for (i = 0; i < numDomains; i++) { flags[i] = VIR_DOMAIN_SAVE_RUNNING; if (virDomainGetState(domains[i], &state, NULL, 0) == 0) { - if (state == VIR_DOMAIN_PAUSED) { + if (state == VIR_DOMAIN_PAUSED) flags[i] = VIR_DOMAIN_SAVE_PAUSED; - } } virDomainSuspend(domains[i]); } @@ -1840,9 +1839,8 @@ static int qemuDomainSuspend(virDomainPtr dom) "%s", _("domain is pmsuspended")); goto endjob; } else if (state != VIR_DOMAIN_PAUSED) { - if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0) { + if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0) goto endjob; - } if (eventDetail >= 0) { event = virDomainEventLifecycleNewFromObj(vm, @@ -4043,9 +4041,8 @@ processGuestPanicEvent(virQEMUDriverPtr driver, switch (action) { case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_DESTROY: - if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0) { + if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0) goto cleanup; - } /* fall through */ case VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY: @@ -4074,15 +4071,13 @@ processGuestPanicEvent(virQEMUDriverPtr driver, virDomainAuditStop(vm, "destroyed"); - if (!vm->persistent) { + if (!vm->persistent) qemuDomainRemoveInactive(driver, vm); - } break; case VIR_DOMAIN_LIFECYCLE_CRASH_COREDUMP_RESTART: - if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0) { + if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0) goto cleanup; - } /* fall through */ case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART: @@ -4955,9 +4950,8 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, &targetDef) < 0) goto cleanup; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (flags & VIR_DOMAIN_AFFECT_LIVE) targetDef = vm->def; - } /* Coverity didn't realize that targetDef must be set if we got here. */ sa_assert(targetDef); @@ -4973,9 +4967,8 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, if (ncpumaps > targetDef->vcpus) ncpumaps = targetDef->vcpus; - if (ncpumaps < 1) { + if (ncpumaps < 1) goto cleanup; - } /* initialize cpumaps */ memset(cpumaps, 0xff, maplen * ncpumaps); @@ -5233,9 +5226,8 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, /* initialize cpumaps */ memset(cpumaps, 0xff, maplen); - if (maxcpu % 8) { + if (maxcpu % 8) cpumaps[maplen - 1] &= (1 << maxcpu % 8) - 1; - } if (targetDef->cputune.emulatorpin) { cpumask = targetDef->cputune.emulatorpin->cpumask; @@ -9532,9 +9524,8 @@ qemuSetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr cgroup, if (period == 0 && quota == 0) return 0; - if (priv->nvcpupids == 0 || priv->vcpupids[0] == vm->pid) { + if (priv->nvcpupids == 0 || priv->vcpupids[0] == vm->pid) return 0; - } if (virCgroupNewEmulator(cgroup, false, &cgroup_emulator) < 0) goto cleanup; @@ -10510,12 +10501,10 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, /* average is mandatory, peak and burst are optional. So if no * average is given, we free inbound/outbound here which causes * inbound/outbound to not be set. */ - if (!bandwidth->in->average) { + if (!bandwidth->in->average) VIR_FREE(bandwidth->in); - } - if (!bandwidth->out->average) { + if (!bandwidth->out->average) VIR_FREE(bandwidth->out); - } if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (VIR_ALLOC(newBandwidth) < 0) @@ -14860,9 +14849,8 @@ qemuDomainSnapshotReparentChildren(void *payload, virDomainSnapshotObjPtr snap = payload; virQEMUSnapReparentPtr rep = data; - if (rep->err < 0) { + if (rep->err < 0) return; - } VIR_FREE(snap->def->parent); snap->parent = rep->parent; @@ -15036,9 +15024,8 @@ static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd, qemuDomainObjExitMonitor(driver, vm); endjob: - if (!qemuDomainObjEndJob(driver, vm)) { + if (!qemuDomainObjEndJob(driver, vm)) vm = NULL; - } cleanup: if (vm) @@ -15905,9 +15892,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, } device = qemuDiskPathToAlias(vm, path, &idx); - if (!device) { + if (!device) goto endjob; - } disk = vm->def->disks[idx]; if (disk->mirror) { virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, @@ -17032,9 +17018,8 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, } device = qemuDiskPathToAlias(vm, disk, NULL); - if (!device) { + if (!device) goto endjob; - } if (flags & VIR_DOMAIN_AFFECT_LIVE) { qemuDomainObjEnterMonitor(driver, vm); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 13bcd88..b9a0cee 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -468,9 +468,8 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver, goto cleanup; } - if (!(devstr = qemuBuildControllerDevStr(vm->def, controller, priv->qemuCaps, NULL))) { + if (!(devstr = qemuBuildControllerDevStr(vm->def, controller, priv->qemuCaps, NULL))) goto cleanup; - } } if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers+1) < 0) @@ -3095,9 +3094,8 @@ qemuFindDisk(virDomainDefPtr def, const char *dst) size_t i; for (i = 0; i < def->ndisks; i++) { - if (STREQ(def->disks[i]->dst, dst)) { + if (STREQ(def->disks[i]->dst, dst)) return i; - } } return -1; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index bef5b94..b0e1024 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2837,9 +2837,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0); endjob: - if (!qemuMigrationJobFinish(driver, vm)) { + if (!qemuMigrationJobFinish(driver, vm)) vm = NULL; - } goto cleanup; } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 91a7aba..744a862 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -565,9 +565,8 @@ static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr da { const char *action; int actionID; - if (!(action = virJSONValueObjectGetString(data, "action"))) { + if (!(action = virJSONValueObjectGetString(data, "action"))) VIR_WARN("missing action in watchdog event"); - } if (action) { if ((actionID = qemuMonitorWatchdogActionTypeFromString(action)) < 0) { VIR_WARN("unknown action %s in watchdog event", action); @@ -602,9 +601,8 @@ qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, virJSONValuePtr data) action = "ignore"; } - if ((device = virJSONValueObjectGetString(data, "device")) == NULL) { + if ((device = virJSONValueObjectGetString(data, "device")) == NULL) VIR_WARN("missing device in disk io error event"); - } if (virJSONValueObjectGetBoolean(data, "nospace", &nospc) == 0 && nospc) reason = "enospc"; @@ -4451,9 +4449,8 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon, virJSONValuePtr result = NULL; cmd = qemuMonitorJSONMakeCommand("query-block", NULL); - if (!cmd) { + if (!cmd) return -1; - } ret = qemuMonitorJSONCommand(mon, cmd, &result); @@ -4485,9 +4482,8 @@ int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon) virJSONValuePtr reply = NULL; cmd = qemuMonitorJSONMakeCommand("system_wakeup", NULL); - if (!cmd) { + if (!cmd) return -1; - } ret = qemuMonitorJSONCommand(mon, cmd, &reply); diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 46d2782..e40c676 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -123,9 +123,8 @@ int qemuMonitorTextIOProcess(qemuMonitorPtr mon ATTRIBUTE_UNUSED, */ if (msg->txLength > 0) { char *tmp; - if ((tmp = strchr(msg->txBuffer, '\r'))) { + if ((tmp = strchr(msg->txBuffer, '\r'))) *tmp = '\0'; - } } /* QEMU echos the command back to us, full of control @@ -144,9 +143,8 @@ int qemuMonitorTextIOProcess(qemuMonitorPtr mon ATTRIBUTE_UNUSED, skip = strstr(data + used, msg->txBuffer); /* After the junk we should have a line ending... */ - if (skip) { + if (skip) start = strstr(skip + strlen(msg->txBuffer), LINE_ENDING); - } /* ... then our command reply data, following by a (qemu) prompt */ if (start) { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6350bfa..7518138 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -627,9 +627,8 @@ qemuProcessFakeReboot(void *opaque) cleanup: if (vm) { - if (ret == -1) { + if (ret == -1) ignore_value(qemuProcessKill(vm, VIR_QEMU_PROCESS_KILL_FORCE)); - } if (virObjectUnref(vm)) virObjectUnlock(vm); } @@ -1830,9 +1829,8 @@ qemuProcessExtractTTYPath(const char *haystack, VIR_FREE(*path); /* First look for our magic string */ - if (!(tmp = strstr(haystack + *offset, needle))) { + if (!(tmp = strstr(haystack + *offset, needle))) return 1; - } tmp += sizeof(needle); dev = tmp; @@ -3470,9 +3468,8 @@ qemuProcessReconnect(void *opaque) priv->agentError = true; } - if (qemuUpdateActivePCIHostdevs(driver, obj->def) < 0) { + if (qemuUpdateActivePCIHostdevs(driver, obj->def) < 0) goto error; - } if (qemuUpdateActiveUSBHostdevs(driver, obj->def) < 0) goto error; @@ -4511,9 +4508,8 @@ int qemuProcessStart(virConnectPtr conn, } VIR_DEBUG("Writing early domain status to disk"); - if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) goto cleanup; - } VIR_DEBUG("Waiting for handshake from child"); if (virCommandHandshakeWait(cmd) < 0) { @@ -4562,9 +4558,8 @@ int qemuProcessStart(virConnectPtr conn, } VIR_DEBUG("Labelling done, completing handshake to child"); - if (virCommandHandshakeNotify(cmd) < 0) { + if (virCommandHandshakeNotify(cmd) < 0) goto cleanup; - } VIR_DEBUG("Handshake complete, child running"); if (migrateFrom) @@ -4929,9 +4924,8 @@ void qemuProcessStop(virQEMUDriverPtr driver, /* Clear out dynamically assigned labels */ for (i = 0; i < vm->def->nseclabels; i++) { - if (vm->def->seclabels[i]->type == VIR_DOMAIN_SECLABEL_DYNAMIC) { + if (vm->def->seclabels[i]->type == VIR_DOMAIN_SECLABEL_DYNAMIC) VIR_FREE(vm->def->seclabels[i]->label); - } VIR_FREE(vm->def->seclabels[i]->imagelabel); } -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/storage/parthelper.c | 3 +-- src/storage/storage_backend.c | 9 +++------ src/storage/storage_backend_disk.c | 15 +++++---------- src/storage/storage_backend_fs.c | 6 ++---- src/storage/storage_backend_mpath.c | 27 +++++++++------------------ src/storage/storage_backend_rbd.c | 30 ++++++++++-------------------- src/storage/storage_backend_scsi.c | 6 ++---- src/storage/storage_driver.c | 9 +++------ 8 files changed, 35 insertions(+), 70 deletions(-) diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index 84e7ba0..8de32fd 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -91,9 +91,8 @@ int main(int argc, char **argv) if (VIR_STRDUP_QUIET(canonical_path, path) < 0) return 2; } else { - if (virFileResolveLink(path, &canonical_path) != 0) { + if (virFileResolveLink(path, &canonical_path) != 0) return 2; - } partsep = *canonical_path && c_isdigit(canonical_path[strlen(canonical_path)-1]) ? "p" : ""; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 00cfe74..98720f6 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -182,9 +182,8 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol, } #ifdef __linux__ - if (ioctl(fd, BLKBSZGET, &wbytes) < 0) { + if (ioctl(fd, BLKBSZGET, &wbytes) < 0) wbytes = 0; - } #endif if ((wbytes == 0) && fstat(fd, &st) == 0) wbytes = st.st_blksize; @@ -395,9 +394,8 @@ createRawFile(int fd, virStorageVolDefPtr vol, (vol->target.allocation < inputvol->target.capacity); ret = virStorageBackendCopyToFD(vol, inputvol, fd, &remain, want_sparse); - if (ret < 0) { + if (ret < 0) goto cleanup; - } } if (remain && need_alloc) { @@ -631,9 +629,8 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool, virCommandSetGID(cmd, -1); if (!filecreated) { - if (virCommandRun(cmd, NULL) < 0) { + if (virCommandRun(cmd, NULL) < 0) return -1; - } if (stat(vol->target.path, &st) < 0) { virReportSystemError(errno, _("failed to create %s"), vol->target.path); diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index abab1e1..4b05e8c 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -171,9 +171,8 @@ virStorageBackendDiskMakeFreeExtent(virStoragePoolObjPtr pool, return -1; /* Don't bother to re-alloc freeExtents - it'll be free'd shortly */ /* first block reported as free, even if it is not */ - if (dev->freeExtents[dev->nfreeExtent].start == 0) { + if (dev->freeExtents[dev->nfreeExtent].start == 0) dev->freeExtents[dev->nfreeExtent].start = SECTOR_SIZE; - } pool->def->available += (dev->freeExtents[dev->nfreeExtent].end - @@ -349,9 +348,8 @@ virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, return -1; } - if (virStorageBackendDiskReadGeometry(pool) != 0) { + if (virStorageBackendDiskReadGeometry(pool) != 0) return -1; - } return virStorageBackendDiskReadPartitions(pool, NULL); } @@ -467,9 +465,8 @@ virStorageBackendDiskPartTypeToCreate(virStoragePoolObjPtr pool) partType == VIR_STORAGE_VOL_DISK_TYPE_EXTENDED) count++; } - if (count >= 4) { + if (count >= 4) return VIR_STORAGE_VOL_DISK_TYPE_LOGICAL; - } } /* for all other cases, all partitions are primary */ @@ -587,9 +584,8 @@ virStorageBackendDiskPartBoundaries(virStoragePoolObjPtr pool, } /* if we are creating a logical partition, we need one extra block between partitions (or actually move start one block) */ - if (partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) { + if (partType == VIR_STORAGE_VOL_DISK_TYPE_LOGICAL) size -= SECTOR_SIZE; - } } if (size > neededSize && (smallestSize == 0 || @@ -659,9 +655,8 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED, goto cleanup; } - if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) { + if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) goto cleanup; - } virCommandAddArg(cmd, partFormat); if (virStorageBackendDiskPartBoundaries(pool, &startOffset, diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 0f8ceee..f4bf5d6 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -639,9 +639,8 @@ virStorageBackendFileSystemProbe(const char *device, error: VIR_FREE(libblkid_format); - if (probe != NULL) { + if (probe != NULL) blkid_free_probe(probe); - } return ret; } @@ -737,9 +736,8 @@ virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool, ok_to_mkfs = true; } - if (ok_to_mkfs) { + if (ok_to_mkfs) ret = virStorageBackendExecuteMKFS(device, format); - } error: return ret; diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index f21ae4c..b67dc2a 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -119,14 +119,12 @@ virStorageBackendIsMultipath(const char *dev_name) goto out; } - if (STREQ(target_type, "multipath")) { + if (STREQ(target_type, "multipath")) ret = 1; - } out: - if (dmt != NULL) { + if (dmt != NULL) dm_task_destroy(dmt); - } return ret; } @@ -138,21 +136,17 @@ virStorageBackendGetMinorNumber(const char *dev_name, uint32_t *minor) struct dm_task *dmt; struct dm_info info; - if (!(dmt = dm_task_create(DM_DEVICE_INFO))) { + if (!(dmt = dm_task_create(DM_DEVICE_INFO))) goto out; - } - if (!dm_task_set_name(dmt, dev_name)) { + if (!dm_task_set_name(dmt, dev_name)) goto out; - } - if (!dm_task_run(dmt)) { + if (!dm_task_run(dmt)) goto out; - } - if (!dm_task_get_info(dmt, &info)) { + if (!dm_task_get_info(dmt, &info)) goto out; - } *minor = info.minor; ret = 0; @@ -177,9 +171,8 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, do { is_mpath = virStorageBackendIsMultipath(names->name); - if (is_mpath < 0) { + if (is_mpath < 0) goto out; - } if (is_mpath == 1) { @@ -193,9 +186,8 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, goto out; } - if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0) { + if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0) goto out; - } VIR_FREE(map_device); } @@ -247,9 +239,8 @@ virStorageBackendGetMaps(virStoragePoolObjPtr pool) virStorageBackendCreateVols(pool, names); out: - if (dmt != NULL) { + if (dmt != NULL) dm_task_destroy(dmt); - } return retval; } diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index bddbc1d..5a16eff 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -330,13 +330,11 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn, ptr.cluster = NULL; ptr.ioctx = NULL; - if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) { + if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) goto cleanup; - } - if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) { + if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) goto cleanup; - } struct rados_cluster_stat_t clusterstat; r = rados_cluster_stat(ptr.cluster, &clusterstat); @@ -428,17 +426,14 @@ static int virStorageBackendRBDDeleteVol(virConnectPtr conn, VIR_DEBUG("Removing RBD image %s/%s", pool->def->source.name, vol->name); - if (flags & VIR_STORAGE_VOL_DELETE_ZEROED) { + if (flags & VIR_STORAGE_VOL_DELETE_ZEROED) VIR_WARN("%s", _("This storage backend does not supported zeroed removal of volumes")); - } - if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) { + if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) goto cleanup; - } - if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) { + if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) goto cleanup; - } r = rbd_remove(ptr.ioctx, vol->name); if (r < 0) { @@ -555,17 +550,14 @@ static int virStorageBackendRBDRefreshVol(virConnectPtr conn, ptr.ioctx = NULL; int ret = -1; - if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) { + if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) goto cleanup; - } - if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) { + if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) goto cleanup; - } - if (volStorageBackendRBDRefreshVolInfo(vol, pool, &ptr) < 0) { + if (volStorageBackendRBDRefreshVolInfo(vol, pool, &ptr) < 0) goto cleanup; - } ret = 0; @@ -589,13 +581,11 @@ static int virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED, virCheckFlags(0, -1); - if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) { + if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) goto cleanup; - } - if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) { + if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) goto cleanup; - } r = rbd_open(ptr.ioctx, vol->name, &image, NULL); if (r < 0) { diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c index 3f61610..c952b71 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -256,9 +256,8 @@ getNewStyleBlockDevice(const char *lun_path, while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) { - if (STREQLEN(block_dirent->d_name, ".", 1)) { + if (STREQLEN(block_dirent->d_name, ".", 1)) continue; - } if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0) { closedir(block_dir); @@ -397,9 +396,8 @@ processLU(virStoragePoolObjPtr pool, VIR_DEBUG("%u:%u:%u:%u is a Direct-Access LUN", host, bus, target, lun); - if (getBlockDevice(host, bus, target, lun, &block_device) < 0) { + if (getBlockDevice(host, bus, target, lun, &block_device) < 0) goto out; - } if (virStorageBackendSCSINewLun(pool, host, bus, target, lun, diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index fe6059a..9b89a67 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -484,9 +484,8 @@ storageConnectListDefinedStoragePools(virConnectPtr conn, cleanup: storageDriverUnlock(); - for (i = 0; i < got; i++) { + for (i = 0; i < got; i++) VIR_FREE(names[i]); - } memset(names, 0, nnames * sizeof(*names)); return -1; } @@ -1650,9 +1649,8 @@ storageVolCreateXML(virStoragePoolPtr obj, /* Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ VIR_FREE(voldef->key); - if (backend->createVol(obj->conn, pool, voldef) < 0) { + if (backend->createVol(obj->conn, pool, voldef) < 0) goto cleanup; - } pool->volumes.objs[pool->volumes.count++] = voldef; volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name, @@ -1830,9 +1828,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj, * Wipe any key the user may have suggested, as volume creation * will generate the canonical key. */ VIR_FREE(newvol->key); - if (backend->createVol(obj->conn, pool, newvol) < 0) { + if (backend->createVol(obj->conn, pool, newvol) < 0) goto cleanup; - } pool->volumes.objs[pool->volumes.count++] = newvol; volobj = virGetStorageVol(obj->conn, pool->def->name, newvol->name, -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/test/test_driver.c | 57 +++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6421f99..d7844bd 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -960,9 +960,8 @@ testParseNodeInfo(virNodeInfoPtr nodeInfo, xmlXPathContextPtr ctxt) nodeInfo->sockets * nodeInfo->nodes); ret = virXPathLong("string(/node/cpu/active[1])", ctxt, &l); if (ret == 0) { - if (l < nodeInfo->cpus) { + if (l < nodeInfo->cpus) nodeInfo->cpus = l; - } } else if (ret == -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid node cpu active value")); @@ -1070,9 +1069,8 @@ testParseDomains(testConnPtr privconn, virDomainObjPtr obj; num = virXPathNodeSet("/node/domain", ctxt, &nodes); - if (num < 0) { + if (num < 0) goto error; - } for (i = 0; i < num; i++) { virDomainDefPtr def; @@ -1137,9 +1135,8 @@ testParseNetworks(testConnPtr privconn, virNetworkObjPtr obj; num = virXPathNodeSet("/node/network", ctxt, &nodes); - if (num < 0) { + if (num < 0) goto error; - } for (i = 0; i < num; i++) { virNetworkDefPtr def; @@ -1177,9 +1174,8 @@ testParseInterfaces(testConnPtr privconn, virInterfaceObjPtr obj; num = virXPathNodeSet("/node/interface", ctxt, &nodes); - if (num < 0) { + if (num < 0) goto error; - } for (i = 0; i < num; i++) { virInterfaceDefPtr def; @@ -1225,9 +1221,8 @@ testOpenVolumesForPool(const char *file, num = virXPathNodeSet(vol_xpath, ctxt, &nodes); VIR_FREE(vol_xpath); - if (num < 0) { + if (num < 0) goto error; - } for (i = 0; i < num; i++) { xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, @@ -1275,9 +1270,8 @@ testParseStorage(testConnPtr privconn, virStoragePoolObjPtr obj; num = virXPathNodeSet("/node/pool", ctxt, &nodes); - if (num < 0) { + if (num < 0) goto error; - } for (i = 0; i < num; i++) { virStoragePoolDefPtr def; @@ -1328,9 +1322,8 @@ testParseNodedevs(testConnPtr privconn, virNodeDeviceObjPtr obj; num = virXPathNodeSet("/node/device", ctxt, &nodes); - if (num < 0) { + if (num < 0) goto error; - } for (i = 0; i < num; i++) { virNodeDeviceDefPtr def; @@ -1430,9 +1423,8 @@ testOpenFromFile(virConnectPtr conn, const char *file) if (!(privconn->eventState = virObjectEventStateNew())) goto error; - if (!(doc = virXMLParseFileCtxt(file, &ctxt))) { + if (!(doc = virXMLParseFileCtxt(file, &ctxt))) goto error; - } if (!xmlStrEqual(ctxt->node->name, BAD_CAST "node")) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -2713,9 +2705,8 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, case VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG: ret = testDomainUpdateVCPUs(privconn, privdom, nrCpus, 0); - if (ret == 0) { + if (ret == 0) persistentDef->vcpus = nrCpus; - } break; } @@ -2806,9 +2797,8 @@ static int testDomainGetVcpus(virDomainPtr domain, unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); for (i = 0; i < maxcpu; i++) { - if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i)) { + if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i)) VIR_USE_CPU(cpumap, i); - } } } } @@ -2866,9 +2856,8 @@ static int testDomainPinVcpu(virDomainPtr domain, memset(privcpumap, 0, privmaplen); for (i = 0; i < maxcpu; i++) { - if (VIR_CPU_USABLE(cpumap, maplen, 0, i)) { + if (VIR_CPU_USABLE(cpumap, maplen, 0, i)) VIR_USE_CPU(privcpumap, i); - } } ret = 0; @@ -4064,9 +4053,8 @@ static int testConnectNumOfInterfaces(virConnectPtr conn) testDriverLock(privconn); for (i = 0; (i < privconn->ifaces.count); i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); - if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) { + if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) count++; - } virInterfaceObjUnlock(privconn->ifaces.objs[i]); } testDriverUnlock(privconn); @@ -4111,9 +4099,8 @@ static int testConnectNumOfDefinedInterfaces(virConnectPtr conn) testDriverLock(privconn); for (i = 0; i < privconn->ifaces.count; i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); - if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) { + if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) count++; - } virInterfaceObjUnlock(privconn->ifaces.objs[i]); } testDriverUnlock(privconn); @@ -6058,14 +6045,12 @@ testNodeDeviceCreateXML(virConnectPtr conn, testDriverLock(driver); def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL); - if (def == NULL) { + if (def == NULL) goto cleanup; - } /* We run these next two simply for validation */ - if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) goto cleanup; - } if (virNodeDeviceGetParentHost(&driver->devs, def->name, @@ -6093,9 +6078,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, } - if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) { + if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) goto cleanup; - } virNodeDeviceObjUnlock(obj); dev = virGetNodeDevice(conn, def->name); @@ -6126,9 +6110,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) goto out; } - if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) { + if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) goto out; - } if (VIR_STRDUP(parent_name, obj->def->parent) < 0) goto out; @@ -7033,9 +7016,8 @@ testDomainSnapshotReparentChildren(void *payload, virDomainSnapshotObjPtr snap = payload; testSnapReparentDataPtr rep = data; - if (rep->err < 0) { + if (rep->err < 0) return; - } VIR_FREE(snap->def->parent); snap->parent = rep->parent; @@ -7077,9 +7059,8 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot, testDomainSnapshotDiscardAll, &rem); if (rem.current) { - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) snap->def->current = true; - } vm->current_snapshot = snap; } } else if (snap->nchildren) { -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/util/virauth.c | 12 ++++-------- src/util/virbitmap.c | 6 ++---- src/util/virbuffer.c | 3 +-- src/util/vircommand.c | 9 +++------ src/util/virconf.c | 15 +++++---------- src/util/virdbus.c | 3 +-- src/util/virdnsmasq.c | 3 +-- src/util/vireventpoll.c | 9 +++------ src/util/virfile.c | 6 ++---- src/util/virfirewall.c | 6 ++---- src/util/viriscsi.c | 9 +++------ src/util/virlockspace.c | 6 ++---- src/util/virlog.c | 3 +-- src/util/virnetdev.c | 6 ++---- src/util/virnetdevbridge.c | 3 +-- src/util/virnetdevmacvlan.c | 9 +++------ src/util/virnetdevtap.c | 6 ++---- src/util/virpci.c | 15 +++++---------- src/util/virsexpr.c | 24 ++++++++---------------- src/util/virstorageencryption.c | 3 +-- src/util/virstoragefile.c | 6 ++---- src/util/virsysinfo.c | 3 +-- src/util/virthreadpool.c | 3 +-- src/util/virutil.c | 9 +++------ src/util/virxml.c | 18 ++++++------------ 25 files changed, 65 insertions(+), 130 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index f82e546..adb093e 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -172,15 +172,13 @@ virAuthGetUsernamePath(const char *path, return NULL; } } else { - if (virAsprintf(&prompt, _("Enter username for %s"), hostname) < 0) { + if (virAsprintf(&prompt, _("Enter username for %s"), hostname) < 0) return NULL; - } } for (ncred = 0; ncred < auth->ncredtype; ncred++) { - if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) { + if (auth->credtype[ncred] != VIR_CRED_AUTHNAME) continue; - } cred.type = VIR_CRED_AUTHNAME; cred.prompt = prompt; @@ -189,9 +187,8 @@ virAuthGetUsernamePath(const char *path, cred.result = NULL; cred.resultlen = 0; - if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) { + if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) VIR_FREE(cred.result); - } break; } @@ -261,9 +258,8 @@ virAuthGetPasswordPath(const char *path, cred.result = NULL; cred.resultlen = 0; - if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) { + if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) VIR_FREE(cred.result); - } break; } diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 04a2388..05c50e4 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -640,9 +640,8 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) bits = bitmap->map[nl] & ~((1UL << nb) - 1); - while (bits == 0 && ++nl < bitmap->map_len) { + while (bits == 0 && ++nl < bitmap->map_len) bits = bitmap->map[nl]; - } if (bits == 0) return -1; @@ -726,9 +725,8 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos) bits = ~bitmap->map[nl] & ~((1UL << nb) - 1); - while (bits == 0 && ++nl < bitmap->map_len) { + while (bits == 0 && ++nl < bitmap->map_len) bits = ~bitmap->map[nl]; - } if (nl == bitmap->map_len - 1) { /* Ensure tail bits are ignored. */ diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 52ffa08..16a81e7 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -368,9 +368,8 @@ virBufferVasprintf(virBufferPtr buf, const char *format, va_list argptr) buf->content[buf->use] = 0; grow_size = (count + 1 > 1000) ? count + 1 : 1000; - if (virBufferGrow(buf, grow_size) < 0) { + if (virBufferGrow(buf, grow_size) < 0) return; - } size = buf->size - buf->use; if ((count = vsnprintf(&buf->content[buf->use], diff --git a/src/util/vircommand.c b/src/util/vircommand.c index cbe94f8..6527d85 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -558,9 +558,8 @@ virExec(virCommandPtr cmd) pid = virFork(); - if (pid < 0) { + if (pid < 0) goto cleanup; - } if (pid) { /* parent */ VIR_FORCE_CLOSE(null); @@ -3021,9 +3020,8 @@ virCommandRunNul(virCommandPtr cmd, v[i] = NULL; virCommandSetOutputFD(cmd, &fd); - if (virCommandRunAsync(cmd, NULL) < 0) { + if (virCommandRunAsync(cmd, NULL) < 0) goto cleanup; - } if ((fp = VIR_FDOPEN(fd, "r")) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3050,9 +3048,8 @@ virCommandRunNul(virCommandPtr cmd, if (func(n_tok, v, data) < 0) goto cleanup; n_tok = 0; - for (i = 0; i < n_columns; i++) { + for (i = 0; i < n_columns; i++) VIR_FREE(v[i]); - } } } diff --git a/src/util/virconf.c b/src/util/virconf.c index e221fb5..0a17eff 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -502,9 +502,8 @@ virConfParseValue(virConfParserCtxtPtr ctxt) } NEXT; SKIP_BLANKS_AND_EOL; - if (CUR == ']') { + if (CUR == ']') break; - } tmp = virConfParseValue(ctxt); if (tmp == NULL) { virConfFreeList(lst); @@ -529,9 +528,8 @@ virConfParseValue(virConfParserCtxtPtr ctxt) _("numbers not allowed in VMX format")); return NULL; } - if (virConfParseLong(ctxt, &l) < 0) { + if (virConfParseLong(ctxt, &l) < 0) return NULL; - } type = VIR_CONF_LONG; } else { virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("expecting a value")); @@ -654,9 +652,8 @@ virConfParseStatement(virConfParserCtxtPtr ctxt) char *comm = NULL; SKIP_BLANKS_AND_EOL; - if (CUR == '#') { + if (CUR == '#') return virConfParseComment(ctxt); - } name = virConfParseName(ctxt); if (name == NULL) return -1; @@ -768,9 +765,8 @@ virConfReadFile(const char *filename, unsigned int flags) return NULL; } - if ((len = virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content)) < 0) { + if ((len = virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content)) < 0) return NULL; - } conf = virConfParse(filename, content, len, flags); @@ -888,9 +884,8 @@ virConfSetValue(virConfPtr conf, cur = conf->entries; while (cur != NULL) { - if ((cur->name != NULL) && (STREQ(cur->name, setting))) { + if ((cur->name != NULL) && (STREQ(cur->name, setting))) break; - } prev = cur; cur = cur->next; } diff --git a/src/util/virdbus.c b/src/util/virdbus.c index 7c24cbf..8abb247 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -546,9 +546,8 @@ static void virDBusTypeStackFree(virDBusTypeStack **stack, /* The iter in the first level of the stack is the * root iter which must not be freed */ - for (i = 1; i < *nstack; i++) { + for (i = 1; i < *nstack; i++) VIR_FREE((*stack)[i].iter); - } VIR_FREE(*stack); } diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index d2c4aa9..97652c0 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -726,9 +726,8 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool force) caps->binaryPath); return -1; } - if (!force && caps->mtime == sb.st_mtime) { + if (!force && caps->mtime == sb.st_mtime) return 0; - } caps->mtime = sb.st_mtime; /* Make sure the binary we are about to try exec'ing exists. diff --git a/src/util/vireventpoll.c b/src/util/vireventpoll.c index 13f40dc..ffda206 100644 --- a/src/util/vireventpoll.c +++ b/src/util/vireventpoll.c @@ -221,9 +221,8 @@ int virEventPollAddTimeout(int frequency, unsigned long long now; int ret; - if (virTimeMillisNow(&now) < 0) { + if (virTimeMillisNow(&now) < 0) return -1; - } virMutexLock(&eventLoop.lock); if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) { @@ -270,9 +269,8 @@ void virEventPollUpdateTimeout(int timer, int frequency) return; } - if (virTimeMillisNow(&now) < 0) { + if (virTimeMillisNow(&now) < 0) return; - } virMutexLock(&eventLoop.lock); for (i = 0; i < eventLoop.timeoutsCount; i++) { @@ -643,9 +641,8 @@ int virEventPollRunOnce(void) ret = poll(fds, nfds, timeout); if (ret < 0) { EVENT_DEBUG("Poll got error event %d", errno); - if (errno == EINTR || errno == EAGAIN) { + if (errno == EINTR || errno == EAGAIN) goto retry; - } virReportSystemError(errno, "%s", _("Unable to poll on file handles")); goto error_unlocked; diff --git a/src/util/virfile.c b/src/util/virfile.c index 64f0e5b..b4d762f 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1180,9 +1180,8 @@ virBuildPathInternal(char **path, ...) va_end(ap); *path = virBufferContentAndReset(&buf); - if (*path == NULL) { + if (*path == NULL) ret = -1; - } return ret; } @@ -2047,9 +2046,8 @@ virFileOpenForked(const char *path, int openflags, mode_t mode, /* XXX This makes assumptions about errno being < 255, which is * not true on Hurd. */ VIR_FORCE_CLOSE(pair[1]); - if (ret < 0) { + if (ret < 0) VIR_FORCE_CLOSE(fd); - } ret = -ret; if ((ret & 0xff) != ret) { VIR_WARN("unable to pass desired return value %d", ret); diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index bab1634..49afb78 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -321,9 +321,8 @@ virFirewallAddRuleFullV(virFirewallPtr firewall, rule->queryOpaque = opaque; rule->ignoreErrors = ignoreErrors; - while ((str = va_arg(args, char *)) != NULL) { + while ((str = va_arg(args, char *)) != NULL) ADD_ARG(rule, str); - } if (group->addingRollback) { if (VIR_APPEND_ELEMENT_COPY(group->rollback, @@ -529,9 +528,8 @@ void virFirewallRuleAddArgList(virFirewallPtr firewall, va_start(list, rule); - while ((str = va_arg(list, char *)) != NULL) { + while ((str = va_arg(list, char *)) != NULL) ADD_ARG(rule, str); - } va_end(list); diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 5e29be9..ef8fb59 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -157,9 +157,8 @@ virStorageBackendIQNFound(const char *initiatoriqn, *newline = '\0'; iqn = strrchr(line, ','); - if (iqn == NULL) { + if (iqn == NULL) continue; - } iqn++; if (STREQ(iqn, initiatoriqn)) { @@ -185,9 +184,8 @@ virStorageBackendIQNFound(const char *initiatoriqn, ret = IQN_ERROR; out: - if (ret == IQN_MISSING) { + if (ret == IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); - } VIR_FREE(line); VIR_FORCE_FCLOSE(fp); @@ -451,9 +449,8 @@ virISCSIScanTargets(const char *portal, *ntargetsret = list.ntargets; *targetsret = list.targets; } else { - for (i = 0; i < list.ntargets; i++) { + for (i = 0; i < list.ntargets; i++) VIR_FREE(list.targets[i]); - } VIR_FREE(list.targets); } diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index 8969ab0..2366a74 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -679,9 +679,8 @@ int virLockSpaceReleaseResource(virLockSpacePtr lockspace, } for (i = 0; i < res->nOwners; i++) { - if (res->owners[i] == owner) { + if (res->owners[i] == owner) break; - } } if (i == res->nOwners) { @@ -723,9 +722,8 @@ virLockSpaceRemoveResourcesForOwner(const void *payload, VIR_DEBUG("res %s owner %lld", res->name, (unsigned long long)data->owner); for (i = 0; i < res->nOwners; i++) { - if (res->owners[i] == data->owner) { + if (res->owners[i] == data->owner) break; - } } if (i == res->nOwners) diff --git a/src/util/virlog.c b/src/util/virlog.c index 286ad9e..14eb129 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -578,9 +578,8 @@ virLogVMessage(virLogSourcePtr source, /* * serialize the error message, add level and timestamp */ - if (virVasprintfQuiet(&str, fmt, vargs) < 0) { + if (virVasprintfQuiet(&str, fmt, vargs) < 0) goto cleanup; - } ret = virLogFormatString(&msg, linenr, funcname, priority, str); if (ret < 0) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 3831009..3514978 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1185,9 +1185,8 @@ virNetDevGetVirtualFunctions(const char *pfname, goto cleanup; } - if (virPCIGetNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) { + if (virPCIGetNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) VIR_INFO("VF does not have an interface name"); - } } ret = 0; @@ -1758,9 +1757,8 @@ virNetDevRestoreVfConfig(const char *pflinkdev, int vf, stateDir, pflinkdev, vf) < 0) return rc; - if (virFileReadAll(path, 128, &fileData) < 0) { + if (virFileReadAll(path, 128, &fileData) < 0) goto cleanup; - } if ((vlan = strchr(fileData, '\n'))) { char *endptr; diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index d388358..15434de 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -265,9 +265,8 @@ int virNetDevBridgeCreate(const char *brname) goto cleanup; } - if (virNetDevSetName(ifr.ifr_name, brname) == -1) { + if (virNetDevSetName(ifr.ifr_name, brname) == -1) goto cleanup; - } ret = 0; cleanup: diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index c83341c..89e221d 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -682,9 +682,8 @@ virNetDevMacVLanVPortProfileCallback(struct nlmsghdr *hdr, } } - if (!indicate) { + if (!indicate) return; - } VIR_INFO("Re-send 802.1qbg associate request:"); VIR_INFO(" if: %s", calld->cr_ifname); @@ -851,9 +850,8 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname, return -1; if (ret) { - if (STRPREFIX(tgifname, prefix)) { + if (STRPREFIX(tgifname, prefix)) goto create_name; - } virReportSystemError(EEXIST, _("Unable to create macvlan device %s"), tgifname); return -1; @@ -983,9 +981,8 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname, int ret = 0; int vf = -1; - if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) { + if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) ignore_value(virNetDevRestoreMacAddress(linkdev, stateDir)); - } if (ifname) { if (virNetDevVPortProfileDisassociate(ifname, diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 3674f9b..85688ab 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -108,9 +108,8 @@ virNetDevTapGetRealDeviceName(char *ifname ATTRIBUTE_UNUSED) while (virDirRead(dirp, &dp, "/dev") > 0) { if (STRPREFIX(dp->d_name, "tap")) { struct ifreq ifr; - if (virAsprintf(&devpath, "/dev/%s", dp->d_name) < 0) { + if (virAsprintf(&devpath, "/dev/%s", dp->d_name) < 0) goto cleanup; - } if ((fd = open(devpath, O_RDWR)) < 0) { if (errno == EBUSY) { VIR_FREE(devpath); @@ -444,9 +443,8 @@ int virNetDevTapCreate(char **ifname, VIR_FREE(dev_path); } - if (virNetDevSetName(ifr.ifr_name, *ifname) == -1) { + if (virNetDevSetName(ifr.ifr_name, *ifname) == -1) goto cleanup; - } ret = 0; diff --git a/src/util/virpci.c b/src/util/virpci.c index d8e465f..f60d0fa 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1127,9 +1127,8 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev) goto reprobe; /* Xen's pciback.ko wants you to use remove_slot on the specific device */ - if (virPCIDriverFile(&path, driver, "remove_slot") < 0) { + if (virPCIDriverFile(&path, driver, "remove_slot") < 0) goto cleanup; - } if (virFileExists(path) && virFileWriteStr(path, dev->name, 0) < 0) { virReportSystemError(errno, @@ -1214,9 +1213,8 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, * is triggered for such a device, it will also be immediately * bound by the stub. */ - if (virPCIDriverFile(&path, stubDriverName, "new_id") < 0) { + if (virPCIDriverFile(&path, stubDriverName, "new_id") < 0) goto cleanup; - } if (virFileWriteStr(path, dev->id, 0) < 0) { virReportSystemError(errno, @@ -1242,9 +1240,8 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, */ if (!virFileLinkPointsTo(driverLink, stubDriverPath)) { /* Xen's pciback.ko wants you to use new_slot first */ - if (virPCIDriverFile(&path, stubDriverName, "new_slot") < 0) { + if (virPCIDriverFile(&path, stubDriverName, "new_slot") < 0) goto remove_id; - } if (virFileExists(path) && virFileWriteStr(path, dev->name, 0) < 0) { virReportSystemError(errno, @@ -1255,9 +1252,8 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev, } dev->remove_slot = true; - if (virPCIDriverFile(&path, stubDriverName, "bind") < 0) { + if (virPCIDriverFile(&path, stubDriverName, "bind") < 0) goto remove_id; - } if (virFileWriteStr(path, dev->name, 0) < 0) { virReportSystemError(errno, @@ -1505,9 +1501,8 @@ virPCIDeviceReadID(virPCIDevicePtr dev, const char *id_name) char *path = NULL; char *id_str; - if (virPCIFile(&path, dev->name, id_name) < 0) { + if (virPCIFile(&path, dev->name, id_name) < 0) return NULL; - } /* ID string is '0xNNNN\n' ... i.e. 7 bytes */ if (virFileReadAll(path, 7, &id_str) < 0) { diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c index f8a0ccd..885c382 100644 --- a/src/util/virsexpr.c +++ b/src/util/virsexpr.c @@ -65,9 +65,8 @@ sexpr_free(struct sexpr *sexpr) { int serrno = errno; - if (sexpr == NULL) { + if (sexpr == NULL) return; - } switch (sexpr->kind) { case SEXPR_CONS: @@ -163,9 +162,8 @@ append(struct sexpr *lst, const struct sexpr *value) if (nil == NULL) return -1; - while (lst->kind != SEXPR_NIL) { + while (lst->kind != SEXPR_NIL) lst = lst->u.s.cdr; - } lst->kind = SEXPR_CONS; lst->u.s.car = (struct sexpr *) value; @@ -300,9 +298,8 @@ _string2sexpr(const char *buffer, size_t * end) ptr = trim(ptr + tmp_len); } - if (*ptr == ')') { + if (*ptr == ')') ptr++; - } } else { const char *start; @@ -394,13 +391,11 @@ sexpr_lookup_key(const struct sexpr *sexpr, const char *node) ptr = buffer; token = strsep(&ptr, "/"); - if (sexpr->kind != SEXPR_CONS || sexpr->u.s.car->kind != SEXPR_VALUE) { + if (sexpr->kind != SEXPR_CONS || sexpr->u.s.car->kind != SEXPR_VALUE) goto cleanup; - } - if (STRNEQ(sexpr->u.s.car->u.value, token)) { + if (STRNEQ(sexpr->u.s.car->u.value, token)) goto cleanup; - } for (token = strsep(&ptr, "/"); token; token = strsep(&ptr, "/")) { const struct sexpr *i; @@ -419,14 +414,12 @@ sexpr_lookup_key(const struct sexpr *sexpr, const char *node) } } - if (i->kind == SEXPR_NIL) { + if (i->kind == SEXPR_NIL) break; - } } - if (token != NULL) { + if (token != NULL) goto cleanup; - } result = (struct sexpr *) sexpr; @@ -538,9 +531,8 @@ sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...) result = virVasprintf(&node, fmt, ap); va_end(ap); - if (result < 0) { + if (result < 0) return NULL; - } value = sexpr_node(sexpr, node); diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryption.c index b5fed58..ec4a8cb 100644 --- a/src/util/virstorageencryption.c +++ b/src/util/virstorageencryption.c @@ -193,9 +193,8 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) ret->format = format; n = virXPathNodeSet("./secret", ctxt, &nodes); - if (n < 0) { + if (n < 0) goto cleanup; - } if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0) goto cleanup; ret->nsecrets = n; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 8e9d115..aa97f75 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1204,9 +1204,8 @@ int virStorageFileGetLVMKey(const char *path, char *tmp = *key; /* Find first non-space character */ - while (*tmp && c_isspace(*tmp)) { + while (*tmp && c_isspace(*tmp)) tmp++; - } /* Kill leading spaces */ if (tmp != *key) memmove(*key, tmp, strlen(tmp)+1); @@ -1919,9 +1918,8 @@ virStorageSourceInitChainElement(virStorageSourcePtr newelem, { int ret = -1; - if (force) { + if (force) virStorageSourceSeclabelsClear(newelem); - } if (!newelem->seclabels && virStorageSourceSeclabelsCopy(newelem, old) < 0) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 1bb6392..d644dbc 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -179,9 +179,8 @@ virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) eol = strchr(base, '\n'); cur = strchr(base, ':') + 1; - if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) { + if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) return -1; - } processor = &ret->processor[ret->nprocessor - 1]; virSkipSpaces(&cur); diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 4c46f28..98d2124 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -122,9 +122,8 @@ static void virThreadPoolWorker(void *opaque) if (job == pool->jobList.firstPrio) { virThreadPoolJobPtr tmp = job->next; while (tmp) { - if (tmp->priority) { + if (tmp->priority) break; - } tmp = tmp->next; } pool->jobList.firstPrio = tmp; diff --git a/src/util/virutil.c b/src/util/virutil.c index c178515..88c8baf 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -603,9 +603,8 @@ char *virIndexToDiskName(int idx, const char *prefix) strcpy(name, prefix); name[offset + i] = '\0'; - for (i = i - 1, ctr = idx; ctr >= 0; --i, ctr = ctr / 26 - 1) { + for (i = i - 1, ctr = idx; ctr >= 0; --i, ctr = ctr / 26 - 1) name[offset + i] = 'a' + (ctr % 26); - } return name; } @@ -1539,9 +1538,8 @@ virValidateWWN(const char *wwn) size_t i; const char *p = wwn; - if (STRPREFIX(wwn, "0x")) { + if (STRPREFIX(wwn, "0x")) p += 2; - } for (i = 0; p[i]; i++) { if (!c_isxdigit(p[i])) @@ -2563,9 +2561,8 @@ virGetListenFDs(void) VIR_DEBUG("Disabling inheritance of passed FD %d", fd); - if (virSetInherit(fd, false) < 0) { + if (virSetInherit(fd, false) < 0) VIR_WARN("Couldn't disable inheritance of passed FD %d", fd); - } } return nfds; diff --git a/src/util/virxml.c b/src/util/virxml.c index 27ecf14..7f591fb 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -185,9 +185,8 @@ virXPathLongBase(const char *xpath, } else if ((obj != NULL) && (obj->type == XPATH_NUMBER) && (!(isnan(obj->floatval)))) { *value = (long) obj->floatval; - if (*value != obj->floatval) { + if (*value != obj->floatval) ret = -2; - } } else { ret = -1; } @@ -291,9 +290,8 @@ virXPathULongBase(const char *xpath, } else if ((obj != NULL) && (obj->type == XPATH_NUMBER) && (!(isnan(obj->floatval)))) { *value = (unsigned long) obj->floatval; - if (*value != obj->floatval) { + if (*value != obj->floatval) ret = -2; - } } else { ret = -1; } @@ -408,9 +406,8 @@ virXPathULongLong(const char *xpath, } else if ((obj != NULL) && (obj->type == XPATH_NUMBER) && (!(isnan(obj->floatval)))) { *value = (unsigned long long) obj->floatval; - if (*value != obj->floatval) { + if (*value != obj->floatval) ret = -2; - } } else { ret = -1; } @@ -455,9 +452,8 @@ virXPathLongLong(const char *xpath, } else if ((obj != NULL) && (obj->type == XPATH_NUMBER) && (!(isnan(obj->floatval)))) { *value = (long long) obj->floatval; - if (*value != obj->floatval) { + if (*value != obj->floatval) ret = -2; - } } else { ret = -1; } @@ -655,9 +651,8 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) base = ctxt->input->base; /* skip backwards over any end-of-lines */ - while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) { + while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) cur--; - } /* search backwards for beginning-of-line (to max buff size) */ while ((cur > base) && (*(cur) != '\n') && (*(cur) != '\r')) @@ -669,9 +664,8 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) /* search forward for end-of-line (to max buff size) */ /* copy selected text to our buffer */ - while ((*cur != 0) && (*(cur) != '\n') && (*(cur) != '\r')) { + while ((*cur != 0) && (*(cur) != '\n') && (*(cur) != '\r')) virBufferAddChar(&buf, *cur++); - } /* create blank line with problem pointer */ contextstr = virBufferContentAndReset(&buf); -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/vbox/vbox_MSCOMGlue.c | 30 +++++++++---------------- src/vbox/vbox_XPCOMCGlue.c | 33 ++++++++++------------------ src/vbox/vbox_common.c | 51 +++++++++++++++---------------------------- src/vbox/vbox_network.c | 15 +++++-------- src/vbox/vbox_snapshot_conf.c | 21 ++++++------------ src/vbox/vbox_storage.c | 30 +++++++++---------------- src/vbox/vbox_tmpl.c | 30 +++++++++---------------- 7 files changed, 70 insertions(+), 140 deletions(-) diff --git a/src/vbox/vbox_MSCOMGlue.c b/src/vbox/vbox_MSCOMGlue.c index c1d3ec3..7208d73 100644 --- a/src/vbox/vbox_MSCOMGlue.c +++ b/src/vbox/vbox_MSCOMGlue.c @@ -385,9 +385,8 @@ vboxLookupRegistryValue(HKEY key, const char *keyName, const char *valueName) goto cleanup; } - if (value[length - 1] != '\0') { + if (value[length - 1] != '\0') value[length] = '\0'; - } cleanup: return value; @@ -421,17 +420,15 @@ vboxLookupVersionInRegistry(void) * the actual version number is in the VersionExt key then. */ value = vboxLookupRegistryValue(key, keyName, "Version"); - if (value == NULL) { + if (value == NULL) goto cleanup; - } if (STREQ(value, "%VER%")) { VIR_FREE(value); value = vboxLookupRegistryValue(key, keyName, "VersionExt"); - if (value == NULL) { + if (value == NULL) goto cleanup; - } } if (virParseVersionString(value, &vboxVersion, false) < 0) { @@ -478,13 +475,11 @@ vboxUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString) int length = WideCharToMultiByte(CP_UTF8, 0, pwszString, -1, NULL, 0, NULL, NULL); - if (length < 1) { + if (length < 1) return -1; - } - if (VIR_ALLOC_N(*ppszString, length) < 0) { + if (VIR_ALLOC_N(*ppszString, length) < 0) return -1; - } return WideCharToMultiByte(CP_UTF8, 0, pwszString, -1, *ppszString, length, NULL, NULL); @@ -495,15 +490,13 @@ vboxUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString) { int length = MultiByteToWideChar(CP_UTF8, 0, pszString, -1, NULL, 0); - if (length < 1) { + if (length < 1) return -1; - } *ppwszString = SysAllocStringLen(NULL, length); - if (*ppwszString == NULL) { + if (*ppwszString == NULL) return -1; - } return MultiByteToWideChar(CP_UTF8, 0, pszString, -1, *ppwszString, length); } @@ -668,9 +661,8 @@ vboxGetFunctions(unsigned int version) int VBoxCGlueInit(unsigned int *version) { - if (vboxLookupVersionInRegistry() < 0) { + if (vboxLookupVersionInRegistry() < 0) return -1; - } *version = vboxGetVersion(); g_pfnGetFunctions = vboxGetFunctions; @@ -708,9 +700,8 @@ vboxArrayGetHelper(vboxArray *array, HRESULT hrc, SAFEARRAY *safeArray) array->count = 0; array->handle = NULL; - if (FAILED(hrc)) { + if (FAILED(hrc)) return hrc; - } hrc = SafeArrayAccessData(safeArray, (void **)&items); @@ -781,9 +772,8 @@ vboxArrayGetWithUintArg(vboxArray *array, void *self, void *getter, PRUint32 arg void vboxArrayRelease(vboxArray *array) { - if (array->handle == NULL) { + if (array->handle == NULL) return; - } SafeArrayUnaccessData(array->handle); SafeArrayDestroy(array->handle); diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index aaa7c60..944eb95 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -99,9 +99,8 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, return -1; if (!virFileExists(name)) { - if (!ignoreMissing) { + if (!ignoreMissing) VIR_ERROR(_("Library '%s' doesn't exist"), name); - } VIR_FREE(name); return -1; @@ -130,9 +129,8 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, * FIXME: Don't warn in this case as it currently breaks make check * on systems without VirtualBox. */ - if (dir != NULL) { + if (dir != NULL) VIR_WARN("Could not dlopen '%s': %s", name, dlerror()); - } goto cleanup; } @@ -206,29 +204,25 @@ VBoxCGlueInit(unsigned int *version) /* If the user specifies the location, try only that. */ if (home != NULL) { - if (tryLoadOne(home, false, false, version) < 0) { + if (tryLoadOne(home, false, false, version) < 0) return -1; - } } /* Try the additionally configured location. */ if (VBOX_XPCOMC_DIR[0] != '\0') { - if (tryLoadOne(VBOX_XPCOMC_DIR, true, true, version) >= 0) { + if (tryLoadOne(VBOX_XPCOMC_DIR, true, true, version) >= 0) return 0; - } } /* Try the known locations. */ for (i = 0; i < ARRAY_CARDINALITY(knownDirs); ++i) { - if (tryLoadOne(knownDirs[i], true, true, version) >= 0) { + if (tryLoadOne(knownDirs[i], true, true, version) >= 0) return 0; - } } /* Finally try the dynamic linker search path. */ - if (tryLoadOne(NULL, false, true, version) >= 0) { + if (tryLoadOne(NULL, false, true, version) >= 0) return 0; - } /* No luck, return failure. */ return -1; @@ -271,9 +265,8 @@ vboxArrayGetHelper(vboxArray *array, nsresult nsrc, void **items, PRUint32 count array->items = NULL; array->count = 0; - if (NS_FAILED(nsrc)) { + if (NS_FAILED(nsrc)) return nsrc; - } array->items = items; array->count = count; @@ -338,16 +331,14 @@ vboxArrayRelease(vboxArray *array) size_t i; nsISupports *supports; - if (array->items == NULL) { + if (array->items == NULL) return; - } for (i = 0; i < array->count; ++i) { supports = array->items[i]; - if (supports != NULL) { + if (supports != NULL) supports->vtbl->Release(supports); - } } pVBoxFuncs_v2_2->pfnComUnallocMem(array->items); @@ -365,16 +356,14 @@ vboxArrayUnalloc(vboxArray *array) size_t i; void *item; - if (array->items == NULL) { + if (array->items == NULL) return; - } for (i = 0; i < array->count; ++i) { item = array->items[i]; - if (item != NULL) { + if (item != NULL) pVBoxFuncs_v2_2->pfnComUnallocMem(item); - } } pVBoxFuncs_v2_2->pfnComUnallocMem(array->items); diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index cd5b478..bffec82 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -955,9 +955,8 @@ vboxSetBootDeviceOrder(virDomainDefPtr def, vboxGlobalData *data, } /* Clear the defaults first */ - for (i = 0; i < maxBootPosition; i++) { + for (i = 0; i < maxBootPosition; i++) gVBoxAPI.UIMachine.SetBootOrder(machine, i+1, DeviceType_Null); - } for (i = 0; (i < def->os.nBootDevs) && (i < maxBootPosition); i++) { PRUint32 device = DeviceType_Null; @@ -2115,9 +2114,8 @@ vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, vboxIIDUnion } } - if (STREQ(valueTypeUtf8, "vrdp")) { + if (STREQ(valueTypeUtf8, "vrdp")) vrdpPresent = 1; - } if (!vrdpPresent && !sdlPresent && !guiPresent) { /* if nothing is selected it means either the machine xml @@ -2159,9 +2157,8 @@ vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, vboxIIDUnion VBOX_UTF8_TO_UTF16("sdl", &sessionType); } - if (vrdpPresent) { + if (vrdpPresent) VBOX_UTF8_TO_UTF16("vrdp", &sessionType); - } rc = gVBoxAPI.UIMachine.LaunchVMProcess(data, machine, iid, sessionType, env, @@ -2995,9 +2992,8 @@ vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, IMachine *ma IUSBDeviceFilter *deviceFilter = deviceFilters.items[i]; gVBoxAPI.UIUSBDeviceFilter.GetActive(deviceFilter, &active); - if (active) { + if (active) def->nhostdevs++; - } } if (def->nhostdevs == 0) @@ -3222,9 +3218,8 @@ vboxDumpIDEHDDsNew(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) /* cleanup on error */ if (error) { - for (i = 0; i < def->ndisks; i++) { + for (i = 0; i < def->ndisks; i++) VIR_FREE(def->disks[i]); - } VIR_FREE(def->disks); def->ndisks = 0; } @@ -3393,14 +3388,12 @@ vboxDumpDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) } gVBoxAPI.UIVRDxServer.GetAllowMultiConnection(VRDxServer, &allowMultiConnection); - if (allowMultiConnection) { + if (allowMultiConnection) def->graphics[def->ngraphics]->data.rdp.multiUser = true; - } gVBoxAPI.UIVRDxServer.GetReuseSingleConnection(VRDxServer, &reuseSingleConnection); - if (reuseSingleConnection) { + if (reuseSingleConnection) def->graphics[def->ngraphics]->data.rdp.replaceUser = true; - } def->ngraphics++; } else { @@ -3488,9 +3481,8 @@ vboxDumpNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine, PR PRBool enabled = PR_FALSE; gVBoxAPI.UINetworkAdapter.GetEnabled(adapter, &enabled); - if (enabled) { + if (enabled) def->nnets++; - } VBOX_RELEASE(adapter); } @@ -3498,9 +3490,8 @@ vboxDumpNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine, PR /* Allocate memory for the networkcards which are enabled */ if ((def->nnets > 0) && (VIR_ALLOC_N(def->nets, def->nnets) >= 0)) { - for (i = 0; i < def->nnets; i++) { + for (i = 0; i < def->nnets; i++) ignore_value(VIR_ALLOC(def->nets[i])); - } } /* Now get the details about the network cards here */ @@ -3669,9 +3660,8 @@ vboxDumpSerial(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine, PRU PRBool enabled = PR_FALSE; gVBoxAPI.UISerialPort.GetEnabled(serialPort, &enabled); - if (enabled) { + if (enabled) def->nserials++; - } VBOX_RELEASE(serialPort); } @@ -3679,9 +3669,8 @@ vboxDumpSerial(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine, PRU /* Allocate memory for the serial ports which are enabled */ if ((def->nserials > 0) && (VIR_ALLOC_N(def->serials, def->nserials) >= 0)) { - for (i = 0; i < def->nserials; i++) { + for (i = 0; i < def->nserials; i++) ignore_value(VIR_ALLOC(def->serials[i])); - } } /* Now get the details about the serial ports here */ @@ -3759,9 +3748,8 @@ vboxDumpParallel(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine, P PRBool enabled = PR_FALSE; gVBoxAPI.UIParallelPort.GetEnabled(parallelPort, &enabled); - if (enabled) { + if (enabled) def->nparallels++; - } VBOX_RELEASE(parallelPort); } @@ -3769,9 +3757,8 @@ vboxDumpParallel(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine, P /* Allocate memory for the parallel ports which are enabled */ if ((def->nparallels > 0) && (VIR_ALLOC_N(def->parallels, def->nparallels) >= 0)) { - for (i = 0; i < def->nparallels; i++) { + for (i = 0; i < def->nparallels; i++) ignore_value(VIR_ALLOC(def->parallels[i])); - } } /* Now get the details about the parallel ports here */ @@ -4078,9 +4065,8 @@ static int vboxConnectNumOfDefinedDomains(virConnectPtr conn) continue; gVBoxAPI.UIMachine.GetState(machine, &state); - if (gVBoxAPI.machineStateChecker.Inactive(state)) { + if (gVBoxAPI.machineStateChecker.Inactive(state)) ret++; - } } cleanup: @@ -5765,9 +5751,8 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def, ret = 0; cleanup: if (ret < 0) { - for (i = 0; i < def->ndisks; i++) { + for (i = 0; i < def->ndisks; i++) VIR_FREE(def->disks[i].src); - } VIR_FREE(def->disks); def->ndisks = 0; } @@ -6053,13 +6038,11 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, def->dom->os.arch = virArchFromHost(); gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount); def->dom->maxvcpus = def->dom->vcpus = CPUCount; - if (vboxSnapshotGetReadWriteDisks(def, snapshot) < 0) { + if (vboxSnapshotGetReadWriteDisks(def, snapshot) < 0) VIR_DEBUG("Could not get read write disks for snapshot"); - } - if (vboxSnapshotGetReadOnlyDisks(snapshot, def) < 0) { + if (vboxSnapshotGetReadOnlyDisks(snapshot, def) < 0) VIR_DEBUG("Could not get Readonly disks for snapshot"); - } } rc = gVBoxAPI.UISnapshot.GetDescription(snap, &str16); diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c index 792e547..7472537 100644 --- a/src/vbox/vbox_network.c +++ b/src/vbox/vbox_network.c @@ -429,9 +429,8 @@ vboxSocketFormatAddrUtf16(vboxGlobalData *data, virSocketAddrPtr addr) utf8 = virSocketAddrFormat(addr); - if (utf8 == NULL) { + if (utf8 == NULL) return NULL; - } VBOX_UTF8_TO_UTF16(utf8, &utf16); VIR_FREE(utf8); @@ -820,9 +819,8 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, VBOX_UTF16_TO_UTF8(utf16, &utf8); - if (virSocketAddrParse(addr, utf8, AF_UNSPEC) < 0) { + if (virSocketAddrParse(addr, utf8, AF_UNSPEC) < 0) goto cleanup; - } result = 0; @@ -927,9 +925,8 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) VBOX_UTF16_FREE(fromIPAddressUtf16); VBOX_UTF16_FREE(toIPAddressUtf16); - if (errorOccurred) { + if (errorOccurred) goto cleanup; - } } else { ipdef->nranges = 0; } @@ -957,9 +954,8 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) VBOX_UTF16_FREE(macAddressUtf16); VBOX_UTF16_FREE(ipAddressUtf16); - if (errorOccurred) { + if (errorOccurred) goto cleanup; - } } } else { ipdef->nhosts = 0; @@ -982,9 +978,8 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) VBOX_UTF16_FREE(networkMaskUtf16); VBOX_UTF16_FREE(ipAddressUtf16); - if (errorOccurred) { + if (errorOccurred) goto cleanup; - } } DEBUGIID("Network UUID", &vboxnet0IID); diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 7af1231..57df1fd 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -226,9 +226,8 @@ virVBoxSnapshotConfRetrieveSnapshot(xmlNodePtr snapshotNode, xPathContext->node = snapshotNode; descriptionNode = virXPathNode("./vbox:Description", xPathContext); - if (descriptionNode != NULL) { + if (descriptionNode != NULL) snapshot->description = virXMLNodeToString(descriptionNode->doc, descriptionNode); - } hardwareNode = virXPathNode("./vbox:Hardware", xPathContext); if (hardwareNode == NULL) { @@ -447,9 +446,8 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, for (i = 0; i < snapshot->nchildren; i++) { xmlNodePtr child = xmlNewNode(NULL, BAD_CAST "Snapshot"); xmlAddChild(snapshotsNode, child); - if (virVBoxSnapshotConfSerializeSnapshot(child, snapshot->children[i]) < 0) { + if (virVBoxSnapshotConfSerializeSnapshot(child, snapshot->children[i]) < 0) goto cleanup; - } } } result = 0; @@ -850,9 +848,8 @@ virVBoxSnapshotConfAddHardDiskToMediaRegistry(virVBoxSnapshotConfHardDiskPtr har goto cleanup; parentDisk->children[parentDisk->nchildren - 1] = hardDisk; - if (hardDisk->parent == NULL) { + if (hardDisk->parent == NULL) hardDisk->parent = parentDisk; - } ret = 0; cleanup: @@ -915,9 +912,8 @@ virVBoxSnapshotConfRemoveSnapshot(virVBoxSnapshotConfMachinePtr machine, parentSnapshot = snapshot->parent; snapshot->parent = NULL; - while (i < parentSnapshot->nchildren && parentSnapshot->children[i] != snapshot) { + while (i < parentSnapshot->nchildren && parentSnapshot->children[i] != snapshot) ++i; - } if (VIR_DELETE_ELEMENT(parentSnapshot->children, i, parentSnapshot->nchildren) < 0) goto cleanup; @@ -975,9 +971,8 @@ virVBoxSnapshotConfRemoveHardDisk(virVBoxSnapshotConfMediaRegistryPtr mediaRegis parentHardDisk = hardDisk->parent; i = 0; - while (i < parentHardDisk->nchildren && parentHardDisk->children[i] != hardDisk) { + while (i < parentHardDisk->nchildren && parentHardDisk->children[i] != hardDisk) ++i; - } hardDisk->parent = NULL; if (VIR_DELETE_ELEMENT(parentHardDisk->children, i, parentHardDisk->nchildren) < 0) goto cleanup; @@ -1320,9 +1315,8 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath, xmlNodePtr node = nodes[i]; xPathContext->node = node; xmlNodePtr sourceNode = virXPathNode("./source", xPathContext); - if (sourceNode) { + if (sourceNode) ret[i] = virXMLPropString(sourceNode, "file"); - } } result = 0; @@ -1382,9 +1376,8 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath, xmlNodePtr node = nodes[i]; xPathContext->node = node; xmlNodePtr sourceNode = virXPathNode("./source", xPathContext); - if (sourceNode) { + if (sourceNode) ret[i] = virXMLPropString(sourceNode, "file"); - } } result = 0; diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 0cf7a33..194484c 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -120,9 +120,8 @@ static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool) size_t i; int ret = -1; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj, gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj)); @@ -162,9 +161,8 @@ vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nname size_t i; int ret = -1; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj, gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj)); @@ -218,9 +216,8 @@ vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name) size_t i; virStorageVolPtr ret = NULL; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } if (!name) return ret; @@ -296,9 +293,8 @@ vboxStorageVolLookupByKey(virConnectPtr conn, const char *key) nsresult rc; virStorageVolPtr ret = NULL; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } VBOX_IID_INITIALIZE(&hddIID); if (!key) @@ -366,9 +362,8 @@ vboxStorageVolLookupByPath(virConnectPtr conn, const char *path) nsresult rc; virStorageVolPtr ret = NULL; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } VBOX_IID_INITIALIZE(&hddIID); @@ -449,9 +444,8 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, resultCodeUnion resultCode; virStorageVolPtr ret = NULL; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } virCheckFlags(0, NULL); @@ -553,9 +547,8 @@ static int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags) vboxIIDUnion hddIID; int ret = -1; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } VBOX_IID_INITIALIZE(&hddIID); virCheckFlags(0, -1); @@ -707,9 +700,8 @@ static int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info nsresult rc; int ret = -1; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } if (!info) return ret; @@ -767,9 +759,8 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) nsresult rc; char *ret = NULL; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } virCheckFlags(0, NULL); @@ -856,9 +847,8 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) nsresult rc; char *ret = NULL; - if (!data->vboxObj) { + if (!data->vboxObj) return ret; - } if (virUUIDParse(vol->key, uuid) < 0) { virReportError(VIR_ERR_INVALID_ARG, diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index b2e9ef4..de8744d 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -251,9 +251,8 @@ static void nsIDtoChar(unsigned char *uuid, const nsID *iid) uuidstrdst[16] = uuidstrsrc[14]; uuidstrdst[17] = uuidstrsrc[15]; - for (i = 18; i < VIR_UUID_STRING_BUFLEN; i++) { + for (i = 18; i < VIR_UUID_STRING_BUFLEN; i++) uuidstrdst[i] = uuidstrsrc[i]; - } uuidstrdst[VIR_UUID_STRING_BUFLEN-1] = '\0'; ignore_value(virUUIDParse(uuidstrdst, uuid)); @@ -291,9 +290,8 @@ static void nsIDFromChar(nsID *iid, const unsigned char *uuid) uuidstrdst[16] = uuidstrsrc[14]; uuidstrdst[17] = uuidstrsrc[15]; - for (i = 18; i < VIR_UUID_STRING_BUFLEN; i++) { + for (i = 18; i < VIR_UUID_STRING_BUFLEN; i++) uuidstrdst[i] = uuidstrsrc[i]; - } uuidstrdst[VIR_UUID_STRING_BUFLEN-1] = '\0'; ignore_value(virUUIDParse(uuidstrdst, uuidinterim)); @@ -399,13 +397,11 @@ typedef struct _vboxIID_v2_x vboxIID_v2_x; static void vboxIIDUnalloc_v2_x(vboxGlobalData *data, vboxIID_v2_x *iid) { - if (iid->value == NULL) { + if (iid->value == NULL) return; - } - if (iid->value != &iid->backing) { + if (iid->value != &iid->backing) data->pFuncs->pfnComUnallocMem(iid->value); - } iid->value = NULL; } @@ -500,9 +496,8 @@ typedef struct _vboxIID_v3_x vboxIID_v3_x; static void vboxIIDUnalloc_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid) { - if (iid->value != NULL && iid->owner) { + if (iid->value != NULL && iid->owner) data->pFuncs->pfnUtf16Free(iid->value); - } iid->value = NULL; iid->owner = true; @@ -1770,9 +1765,8 @@ vboxConnectDomainEventRegister(virConnectPtr conn, data->vboxCallback = vboxAllocCallbackObj(); if (data->vboxCallback != NULL) { rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj, data->vboxCallback); - if (NS_SUCCEEDED(rc)) { + if (NS_SUCCEEDED(rc)) vboxRet = 0; - } } } else { vboxRet = 0; @@ -1809,9 +1803,8 @@ vboxConnectDomainEventRegister(virConnectPtr conn, if (ret >= 0) { return 0; } else { - if (data->vboxObj && data->vboxCallback) { + if (data->vboxObj && data->vboxCallback) data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback); - } return -1; } } @@ -1876,9 +1869,8 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn, data->vboxCallback = vboxAllocCallbackObj(); if (data->vboxCallback != NULL) { rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj, data->vboxCallback); - if (NS_SUCCEEDED(rc)) { + if (NS_SUCCEEDED(rc)) vboxRet = 0; - } } } else { vboxRet = 0; @@ -1917,9 +1909,8 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn, if (ret >= 0) { return ret; } else { - if (data->vboxObj && data->vboxCallback) { + if (data->vboxObj && data->vboxCallback) data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback); - } return -1; } } @@ -2350,9 +2341,8 @@ _attachDVD(vboxGlobalData *data, IMachine *machine, const char *src) VBOX_UTF8_TO_UTF16(src, &dvdfileUtf16); data->vboxObj->vtbl->FindDVDImage(data->vboxObj, dvdfileUtf16, &dvdImage); - if (!dvdImage) { + if (!dvdImage) data->vboxObj->vtbl->OpenDVDImage(data->vboxObj, dvdfileUtf16, dvdemptyuuid.value, &dvdImage); - } if (!dvdImage) goto cleanup; -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/access/viraccessdriverstack.c | 3 +-- src/bhyve/bhyve_driver.c | 3 +-- src/datatypes.c | 6 ++---- src/driver.c | 3 +-- src/interface/interface_backend_udev.c | 12 ++++-------- src/libvirt-lxc.c | 3 +-- src/libvirt-nodedev.c | 3 +-- src/libvirt-storage.c | 6 ++---- src/libxl/libxl_driver.c | 12 ++++-------- src/locking/lock_daemon.c | 3 +-- src/locking/lock_driver_sanlock.c | 6 ++---- src/lxc/lxc_container.c | 9 +++------ src/lxc/lxc_driver.c | 9 +++------ src/lxc/lxc_process.c | 6 ++---- src/network/bridge_driver.c | 6 ++---- src/network/bridge_driver_linux.c | 3 +-- src/nwfilter/nwfilter_dhcpsnoop.c | 3 +-- src/nwfilter/nwfilter_ebiptables_driver.c | 12 ++++-------- src/nwfilter/nwfilter_gentech_driver.c | 9 +++------ src/nwfilter/nwfilter_learnipaddr.c | 3 +-- 20 files changed, 40 insertions(+), 80 deletions(-) diff --git a/src/access/viraccessdriverstack.c b/src/access/viraccessdriverstack.c index 11ed4f6..b43a743 100644 --- a/src/access/viraccessdriverstack.c +++ b/src/access/viraccessdriverstack.c @@ -54,9 +54,8 @@ static void virAccessDriverStackCleanup(virAccessManagerPtr manager) virAccessDriverStackPrivatePtr priv = virAccessManagerGetPrivateData(manager); size_t i; - for (i = 0; i < priv->managersLen; i++) { + for (i = 0; i < priv->managersLen; i++) virObjectUnref(priv->managers[i]); - } VIR_FREE(priv->managers); } diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 331f310..664e631 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1154,9 +1154,8 @@ bhyveStateInitialize(bool priveleged, return 0; } - if (VIR_ALLOC(bhyve_driver) < 0) { + if (VIR_ALLOC(bhyve_driver) < 0) return -1; - } if (virMutexInit(&bhyve_driver->lock) < 0) { VIR_FREE(bhyve_driver); diff --git a/src/datatypes.c b/src/datatypes.c index 87e3550..b4f6765 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -450,9 +450,8 @@ virStoragePoolDispose(void *obj) virUUIDFormat(pool->uuid, uuidstr); VIR_DEBUG("release pool %p %s %s", pool, pool->name, uuidstr); - if (pool->privateDataFreeFunc) { + if (pool->privateDataFreeFunc) pool->privateDataFreeFunc(pool->privateData); - } VIR_FREE(pool->name); virObjectUnref(pool->conn); @@ -525,9 +524,8 @@ virStorageVolDispose(void *obj) virStorageVolPtr vol = obj; VIR_DEBUG("release vol %p %s", vol, vol->name); - if (vol->privateDataFreeFunc) { + if (vol->privateDataFreeFunc) vol->privateDataFreeFunc(vol->privateData); - } VIR_FREE(vol->key); VIR_FREE(vol->name); diff --git a/src/driver.c b/src/driver.c index 71569e6..1be32ef 100644 --- a/src/driver.c +++ b/src/driver.c @@ -85,9 +85,8 @@ virDriverLoadModule(const char *name) *tmp = c_toupper(*tmp); } - if (virAsprintfQuiet(®func, "%sRegister", fixedname) < 0) { + if (virAsprintfQuiet(®func, "%sRegister", fixedname) < 0) goto cleanup; - } regsym = dlsym(handle, regfunc); if (!regsym) { diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 1dbbfe7..e9fd941 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -845,9 +845,8 @@ udevGetIfaceDefBond(struct udev *udev, return 0; error: - for (i = 0; slave_count != -1 && i < slave_count; i++) { + for (i = 0; slave_count != -1 && i < slave_count; i++) VIR_FREE(slave_list[i]); - } VIR_FREE(slave_list); return -1; @@ -952,9 +951,8 @@ udevGetIfaceDefBridge(struct udev *udev, return 0; error: - for (i = 0; member_count != -1 && i < member_count; i++) { + for (i = 0; member_count != -1 && i < member_count; i++) VIR_FREE(member_list[i]); - } VIR_FREE(member_list); return -1; @@ -1102,14 +1100,12 @@ udevGetIfaceDef(struct udev *udev, const char *name) * to prevent false positives */ vlan_parent_dev = strrchr(name, '.'); - if (vlan_parent_dev) { + if (vlan_parent_dev) ifacedef->type = VIR_INTERFACE_TYPE_VLAN; - } /* Fallback check to see if this is a bond device */ - if (udev_device_get_sysattr_value(dev, "bonding/mode")) { + if (udev_device_get_sysattr_value(dev, "bonding/mode")) ifacedef->type = VIR_INTERFACE_TYPE_BOND; - } } switch (ifacedef->type) { diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index 58892df..8553570 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -145,9 +145,8 @@ virDomainLxcEnterNamespace(virDomainPtr domain, if (virProcessSetNamespaces(nfdlist, fdlist) < 0) { if (oldfdlist && noldfdlist) { - for (i = 0; i < *noldfdlist; i++) { + for (i = 0; i < *noldfdlist; i++) VIR_FORCE_CLOSE((*oldfdlist)[i]); - } VIR_FREE(*oldfdlist); *noldfdlist = 0; } diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index c19aeef..b6c6d1e 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -741,9 +741,8 @@ virNodeDeviceDestroy(virNodeDevicePtr dev) if (dev->conn->nodeDeviceDriver && dev->conn->nodeDeviceDriver->nodeDeviceDestroy) { int retval = dev->conn->nodeDeviceDriver->nodeDeviceDestroy(dev); - if (retval < 0) { + if (retval < 0) goto error; - } return 0; } diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c index 190c718..54c7332 100644 --- a/src/libvirt-storage.c +++ b/src/libvirt-storage.c @@ -1746,9 +1746,8 @@ virStorageVolWipe(virStorageVolPtr vol, if (conn->storageDriver && conn->storageDriver->storageVolWipe) { int ret; ret = conn->storageDriver->storageVolWipe(vol, flags); - if (ret < 0) { + if (ret < 0) goto error; - } return ret; } @@ -1789,9 +1788,8 @@ virStorageVolWipePattern(virStorageVolPtr vol, if (conn->storageDriver && conn->storageDriver->storageVolWipePattern) { int ret; ret = conn->storageDriver->storageVolWipePattern(vol, algorithm, flags); - if (ret < 0) { + if (ret < 0) goto error; - } return ret; } diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index d2c077c..8cbf3c0 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -246,9 +246,8 @@ libxlDriverShouldLoad(bool privileged) * xenfs to /proc/xen. */ status = virFileReadAll(HYPERVISOR_CAPABILITIES, 10, &output); - if (status >= 0) { + if (status >= 0) status = strncmp(output, "control_d", 9); - } VIR_FREE(output); if (status) { VIR_INFO("No Xen capabilities detected, probably not running " @@ -1792,9 +1791,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, goto endjob; } - if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && vm->def->maxvcpus < max) { + if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && vm->def->maxvcpus < max) max = vm->def->maxvcpus; - } if (nvcpus > max) { virReportError(VIR_ERR_INVALID_ARG, @@ -1964,9 +1962,8 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu, &flags, &targetDef) < 0) goto endjob; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (flags & VIR_DOMAIN_AFFECT_LIVE) targetDef = vm->def; - } /* Make sure coverity knows targetDef is valid at this point. */ sa_assert(targetDef); @@ -2066,9 +2063,8 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps, &flags, &targetDef) < 0) goto cleanup; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (flags & VIR_DOMAIN_AFFECT_LIVE) targetDef = vm->def; - } /* Make sure coverity knows targetDef is valid at this point. */ sa_assert(targetDef); diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 75244e8..8cc6979 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -1160,9 +1160,8 @@ int main(int argc, char **argv) { c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx); - if (c == -1) { + if (c == -1) break; - } switch (c) { case 0: diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index 0318f25..d84a419 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -1008,9 +1008,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock, VIR_DEBUG("Acquire completed fd=%d", sock); if (res_free) { - for (i = 0; i < res_count; i++) { + for (i = 0; i < res_count; i++) VIR_FREE(res_args[i]); - } VIR_FREE(res_args); } @@ -1021,9 +1020,8 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock, error: if (res_free) { - for (i = 0; i < res_count; i++) { + for (i = 0; i < res_count; i++) VIR_FREE(res_args[i]); - } VIR_FREE(res_args); } VIR_FREE(opt); diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 8aba3ba..db823d6 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -396,9 +396,8 @@ int lxcContainerSendContinue(int control) VIR_DEBUG("Send continue on fd %d", control); writeCount = safewrite(control, &msg, sizeof(msg)); - if (writeCount != sizeof(msg)) { + if (writeCount != sizeof(msg)) goto error_out; - } rc = 0; error_out: @@ -858,14 +857,12 @@ static int lxcContainerMountBasicFS(bool userns_enabled, */ if (userns_enabled && netns_disabled && STREQ(mnt->src, "sysfs")) { - if (VIR_STRDUP(mnt_src, "/sys") < 0) { + if (VIR_STRDUP(mnt_src, "/sys") < 0) goto cleanup; - } mnt_mflags = MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY|MS_BIND; } else { - if (VIR_STRDUP(mnt_src, mnt->src) < 0) { + if (VIR_STRDUP(mnt_src, mnt->src) < 0) goto cleanup; - } mnt_mflags = mnt->mflags; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index da94cd4..cf2a3c8 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1586,9 +1586,8 @@ static int lxcStateInitialize(bool privileged, return 0; } - if (VIR_ALLOC(lxc_driver) < 0) { + if (VIR_ALLOC(lxc_driver) < 0) return -1; - } if (virMutexInit(&lxc_driver->lock) < 0) { VIR_FREE(lxc_driver); return -1; @@ -1972,9 +1971,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, vm->def->cputune.period = params[i].value.ul; } - if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (flags & VIR_DOMAIN_AFFECT_CONFIG) vmdef->cputune.period = params[i].value.ul; - } } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) { if (flags & VIR_DOMAIN_AFFECT_LIVE) { rc = lxcSetVcpuBWLive(priv->cgroup, 0, params[i].value.l); @@ -1985,9 +1983,8 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom, vm->def->cputune.quota = params[i].value.l; } - if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (flags & VIR_DOMAIN_AFFECT_CONFIG) vmdef->cputune.quota = params[i].value.l; - } } } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 6c83fdb..37ddbbc 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -536,9 +536,8 @@ static void virLXCProcessMonitorEOFNotify(virLXCMonitorPtr mon, if (vm) virObjectUnlock(vm); - if (event) { + if (event) virObjectEventStateQueue(driver->domainEventState, event); - } } static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED, @@ -826,9 +825,8 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, virCommandAddArgFormat(cmd, "%d", handshakefd); virCommandAddArg(cmd, "--background"); - for (i = 0; i < nveths; i++) { + for (i = 0; i < nveths; i++) virCommandAddArgList(cmd, "--veth", veths[i], NULL); - } virCommandPassFD(cmd, handshakefd, 0); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 12c3b50..6cb421c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1340,9 +1340,8 @@ networkStartDhcpDaemon(virNetworkObjPtr network) goto cleanup; ret = virCommandRun(cmd, NULL); - if (ret < 0) { + if (ret < 0) goto cleanup; - } /* * There really is no race here - when dnsmasq daemonizes, its @@ -2016,9 +2015,8 @@ networkStartNetworkVirtual(virNetworkObjPtr network) v6present = true; /* Add the IP address/netmask to the bridge */ - if (networkAddAddrToBridge(network, ipdef) < 0) { + if (networkAddAddrToBridge(network, ipdef) < 0) goto err2; - } } /* Bring up the bridge interface */ diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_linux.c index 6b32838..aa2ad10 100644 --- a/src/network/bridge_driver_linux.c +++ b/src/network/bridge_driver_linux.c @@ -74,9 +74,8 @@ int networkCheckRouteCollision(virNetworkDefPtr def) /* NUL-terminate the line, so sscanf doesn't go beyond a newline. */ char *nl = strchr(cur, '\n'); - if (nl) { + if (nl) *nl++ = '\0'; - } num = sscanf(cur, "%16s %127s %*s %*s %*s %*s %*s %127s", iface, dest, mask); diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index a2f58ba..6da8983 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -315,9 +315,8 @@ virNWFilterSnoopActivate(virNWFilterSnoopReqPtr req) virNWFilterSnoopActiveLock(); - if (virHashAddEntry(virNWFilterSnoopState.active, key, (void *)0x1) < 0) { + if (virHashAddEntry(virNWFilterSnoopState.active, key, (void *)0x1) < 0) VIR_FREE(key); - } virNWFilterSnoopActiveUnlock(); diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 2b89439..377b59b 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3084,14 +3084,12 @@ virNWFilterRuleInstSort(const void *a, const void *b) /* ensure root chain commands appear before all others since we will need them to create the child chains */ if (root_a) { - if (root_b) { + if (root_b) goto normal; - } return -1; /* a before b */ } - if (root_b) { + if (root_b) return 1; /* b before a */ - } normal: /* priorities are limited to range [-1000, 1000] */ return insta->priority - instb->priority; @@ -3165,9 +3163,8 @@ ebtablesGetProtoIdxByFiltername(const char *filtername) enum l3_proto_idx idx; for (idx = 0; idx < L3_PROTO_LAST_IDX; idx++) { - if (STRPREFIX(filtername, l3_protocols[idx].val)) { + if (STRPREFIX(filtername, l3_protocols[idx].val)) return idx; - } } return -1; @@ -3303,9 +3300,8 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, cleanup: VIR_FREE(filter_names); if (ret < 0) { - for (i = 0; i < *ninsts; i++) { + for (i = 0; i < *ninsts; i++) VIR_FREE(*insts[i]); - } VIR_FREE(*insts); *ninsts = 0; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 79fc422..701f8d8 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -567,9 +567,8 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, switch (useNewFilter) { case INSTANTIATE_FOLLOW_NEWFILTER: - if (obj->newDef) { + if (obj->newDef) next_filter = obj->newDef; - } break; case INSTANTIATE_ALWAYS: break; @@ -1139,15 +1138,13 @@ virNWFilterDomainFWUpdateCB(virDomainObjPtr obj, break; case STEP_TEAR_NEW: - if (!virHashLookup(cb->skipInterfaces, net->ifname)) { + if (!virHashLookup(cb->skipInterfaces, net->ifname)) ret = virNWFilterRollbackUpdateFilter(net); - } break; case STEP_TEAR_OLD: - if (!virHashLookup(cb->skipInterfaces, net->ifname)) { + if (!virHashLookup(cb->skipInterfaces, net->ifname)) ret = virNWFilterTearOldFilter(net); - } break; case STEP_APPLY_CURRENT: diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 911079e..1b875c3 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -797,9 +797,8 @@ virNWFilterLearnInit(void) threadsTerminate = false; pendingLearnReq = virHashCreate(0, freeLearnReqEntry); - if (!pendingLearnReq) { + if (!pendingLearnReq) return -1; - } ifaceLockMap = virHashCreate(0, virHashValueFree); if (!ifaceLockMap) { -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/openvz/openvz_conf.c | 3 +-- src/openvz/openvz_driver.c | 27 +++++++++------------------ src/phyp/phyp_driver.c | 21 +++++++-------------- src/remote/remote_driver.c | 3 +-- src/rpc/virnetclient.c | 9 +++------ src/rpc/virnetserver.c | 3 +-- src/rpc/virnetserverclient.c | 3 +-- src/rpc/virnetserverservice.c | 3 +-- src/security/security_manager.c | 3 +-- src/security/virt-aa-helper.c | 9 +++------ src/uml/uml_conf.c | 6 ++---- src/uml/uml_driver.c | 9 +++------ 12 files changed, 33 insertions(+), 66 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 856c9f5..edf37d0 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -660,9 +660,8 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va if (fp == NULL) goto error; temp_fd = open(temp_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (temp_fd == -1) { + if (temp_fd == -1) goto error; - } while (1) { if (getline(&line, &line_size, fp) <= 0) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index a0346b4..d9e27a1 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -619,9 +619,8 @@ static int openvzDomainSuspend(virDomainPtr dom) if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) { openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) goto cleanup; - } virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); } @@ -658,9 +657,8 @@ static int openvzDomainResume(virDomainPtr dom) if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) { openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) goto cleanup; - } virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED); } @@ -1113,9 +1111,8 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, openvzSetProgramSentinal(progstart, vm->def->name); - if (virRun(progstart, NULL) < 0) { + if (virRun(progstart, NULL) < 0) goto cleanup; - } vm->pid = strtoI(vm->def->name); vm->def->id = vm->pid; @@ -1172,9 +1169,8 @@ openvzDomainCreateWithFlags(virDomainPtr dom, unsigned int flags) } openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) goto cleanup; - } vm->pid = strtoI(vm->def->name); vm->def->id = vm->pid; @@ -1218,9 +1214,8 @@ openvzDomainUndefineFlags(virDomainPtr dom, goto cleanup; openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) goto cleanup; - } if (virDomainObjIsActive(vm)) { vm->persistent = 0; @@ -1264,9 +1259,8 @@ openvzDomainSetAutostart(virDomainPtr dom, int autostart) } openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) goto cleanup; - } ret = 0; cleanup: @@ -1357,9 +1351,8 @@ static int openvzDomainSetVcpusInternal(virDomainObjPtr vm, str_vcpus[31] = '\0'; openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) return -1; - } vm->def->maxvcpus = vm->def->vcpus = nvcpus; return 0; @@ -1719,9 +1712,8 @@ openvzDomainSetMemoryInternal(virDomainObjPtr vm, snprintf(str_mem, sizeof(str_mem), "%llu", mem * 1024); openvzSetProgramSentinal(prog, vm->def->name); - if (virRun(prog, NULL) < 0) { + if (virRun(prog, NULL) < 0) goto cleanup; - } return 0; @@ -2052,9 +2044,8 @@ openvzUpdateDevice(virDomainDefPtr vmdef, return -1; } - if (openvzSetDiskQuota(vmdef, fs, persist) < 0) { + if (openvzSetDiskQuota(vmdef, fs, persist) < 0) return -1; - } cur->space_hard_limit = fs->space_hard_limit; cur->space_soft_limit = fs->space_soft_limit; } else { diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 386d25f..269d030 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -172,9 +172,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status, } } - if (channel == NULL) { + if (channel == NULL) goto err; - } while ((rc = libssh2_channel_exec(channel, cmd)) == LIBSSH2_ERROR_EAGAIN) { @@ -185,9 +184,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status, } } - if (rc != 0) { + if (rc != 0) goto err; - } for (;;) { /* loop until we block */ @@ -223,9 +221,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status, } } - if (rc == 0) { + if (rc == 0) exitcode = libssh2_channel_get_exit_status(channel); - } (*exit_status) = exitcode; libssh2_channel_free(channel); @@ -731,9 +728,8 @@ phypUUIDTable_Pull(virConnectPtr conn) do { amount = sizeof(buffer); - if ((fileinfo.st_size - got) < amount) { + if ((fileinfo.st_size - got) < amount) amount = fileinfo.st_size - got; - } rc = libssh2_channel_read(channel, buffer, amount); if (rc > 0) { @@ -849,9 +845,8 @@ phypUUIDTable_Init(virConnectPtr conn) cleanup: if (ret < 0 && table_created) { - for (i = 0; i < uuid_table->nlpars; i++) { + for (i = 0; i < uuid_table->nlpars; i++) VIR_FREE(uuid_table->lpars[i]); - } VIR_FREE(uuid_table->lpars); } VIR_FREE(ids); @@ -1718,18 +1713,16 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml) domain_name = escape_specialcharacters(domain->name); - if (domain_name == NULL) { + if (domain_name == NULL) goto cleanup; - } if (VIR_STRDUP(def->os.type, "aix") < 0) goto cleanup; dev = virDomainDeviceDefParse(xml, def, phyp_driver->caps, NULL, VIR_DOMAIN_XML_INACTIVE); - if (!dev) { + if (!dev) goto cleanup; - } if (! (vios_name = diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 5ca6655..04e5360 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -4069,9 +4069,8 @@ static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype) sasl_callback_t *cbs; size_t i; int n; - if (VIR_ALLOC_N(cbs, ncredtype+1) < 0) { + if (VIR_ALLOC_N(cbs, ncredtype+1) < 0) return NULL; - } for (i = 0, n = 0; i < ncredtype; i++) { int id = remoteAuthCredVir2SASL(credtype[i]); diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index a156fe1..8657b0e 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -160,9 +160,8 @@ static void virNetClientCallQueue(virNetClientCallPtr *head, virNetClientCallPtr call) { virNetClientCallPtr tmp = *head; - while (tmp && tmp->next) { + while (tmp && tmp->next) tmp = tmp->next; - } if (tmp) tmp->next = call; else @@ -237,9 +236,8 @@ static bool virNetClientCallMatchPredicate(virNetClientCallPtr head, { virNetClientCallPtr tmp = head; while (tmp) { - if (pred(tmp, opaque)) { + if (pred(tmp, opaque)) return true; - } tmp = tmp->next; } return false; @@ -1535,9 +1533,8 @@ static int virNetClientIOEventLoop(virNetClientPtr client, /* If we have existing SASL decoded data, pretend * the socket became readable so we consume it */ - if (virNetSocketHasCachedData(client->sock)) { + if (virNetSocketHasCachedData(client->sock)) fds[0].revents |= POLLIN; - } /* If wantClose flag is set, pretend there was an error on the socket */ diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 3d3e422..47d83ba 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -1233,9 +1233,8 @@ void virNetServerClose(virNetServerPtr srv) virObjectLock(srv); - for (i = 0; i < srv->nservices; i++) { + for (i = 0; i < srv->nservices; i++) virNetServerServiceClose(srv->services[i]); - } virObjectUnlock(srv); } diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index c6ef84c..b2a4fdf 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -496,9 +496,8 @@ virNetServerClientPtr virNetServerClientNewPostExecRestart(virJSONValuePtr objec _("Missing privateData field in JSON state document")); goto error; } - if (!(client->privateData = privNew(client, child, privOpaque))) { + if (!(client->privateData = privNew(client, child, privOpaque))) goto error; - } client->privateDataFreeFunc = privFree; client->privateDataPreExecRestart = privPreExecRestart; } diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 647007b..d84b6de 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -516,7 +516,6 @@ void virNetServerServiceClose(virNetServerServicePtr svc) if (!svc) return; - for (i = 0; i < svc->nsocks; i++) { + for (i = 0; i < svc->nsocks; i++) virNetSocketClose(svc->socks[i]); - } } diff --git a/src/security/security_manager.c b/src/security/security_manager.c index 8671620..302f54d 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -875,9 +875,8 @@ virSecurityManagerGetNested(virSecurityManagerPtr mgr) { virSecurityManagerPtr* list = NULL; - if (STREQ("stack", mgr->drv->name)) { + if (STREQ("stack", mgr->drv->name)) return virSecurityStackGetNested(mgr); - } if (VIR_ALLOC_N(list, 2) < 0) return NULL; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index e102c3c..c4e687c 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1253,13 +1253,11 @@ main(int argc, char **argv) /* clear the environment */ environ = NULL; - if (setenv("PATH", "/sbin:/usr/sbin", 1) != 0) { + if (setenv("PATH", "/sbin:/usr/sbin", 1) != 0) vah_error(ctl, 1, _("could not set PATH")); - } - if (setenv("IFS", " \n\t", 1) != 0) { + if (setenv("IFS", " \n\t", 1) != 0) vah_error(ctl, 1, _("could not set IFS")); - } if (!(progname = strrchr(argv[0], '/'))) progname = argv[0]; @@ -1290,9 +1288,8 @@ main(int argc, char **argv) } else if (ctl->cmd == 'c' || ctl->cmd == 'r') { char *included_files = NULL; - if (ctl->cmd == 'c' && virFileExists(profile)) { + if (ctl->cmd == 'c' && virFileExists(profile)) vah_error(ctl, 1, _("profile exists")); - } if (ctl->append && ctl->newfile) { if (vah_add_file(&buf, ctl->newfile, "rw") != 0) diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index a99e8e9..9dcd4ae 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -172,9 +172,8 @@ umlBuildCommandLineNet(virConnectPtr conn, case VIR_DOMAIN_NET_TYPE_ETHERNET: /* ethNNN=tuntap,tapname,macaddr,gateway */ virBufferAddLit(&buf, "tuntap,"); - if (def->ifname) { + if (def->ifname) virBufferAdd(&buf, def->ifname, -1); - } if (def->data.ethernet.ipaddr) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("IP address not supported for ethernet interface")); @@ -215,9 +214,8 @@ umlBuildCommandLineNet(virConnectPtr conn, } bridge = virNetworkGetBridgeName(network); virNetworkFree(network); - if (bridge == NULL) { + if (bridge == NULL) goto error; - } if (umlConnectTapDevice(conn, vm, def, bridge) < 0) { VIR_FREE(bridge); diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 2baf2fa..b01d631 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -336,9 +336,8 @@ umlInotifyEvent(int watch, dom = virDomainObjListFindByName(driver->domains, name); - if (!dom) { + if (!dom) continue; - } if (e.mask & IN_DELETE) { VIR_DEBUG("Got inotify domain shutdown '%s'", name); @@ -1335,9 +1334,8 @@ static int umlGetProcessInfo(unsigned long long *cpuTime, pid_t pid) FILE *pidinfo; unsigned long long usertime, systime; - if (virAsprintf(&proc, "/proc/%lld/stat", (long long) pid) < 0) { + if (virAsprintf(&proc, "/proc/%lld/stat", (long long) pid) < 0) return -1; - } if (!(pidinfo = fopen(proc, "r"))) { /* VM probably shut down, so fake 0 */ @@ -2306,9 +2304,8 @@ static int umlDomainDetachUmlDisk(struct uml_driver *driver, char *reply; for (i = 0; i < vm->def->ndisks; i++) { - if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) { + if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) break; - } } if (i == vm->def->ndisks) { -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/vmware/vmware_conf.c | 3 +-- src/vmware/vmware_driver.c | 6 ++---- src/xen/block_stats.c | 3 +-- src/xen/xen_driver.c | 6 ++---- src/xen/xen_hypervisor.c | 6 ++---- src/xen/xend_internal.c | 18 ++++++------------ src/xen/xm_internal.c | 6 ++---- src/xenapi/xenapi_driver.c | 12 ++++-------- src/xenapi/xenapi_utils.c | 9 +++------ src/xenconfig/xen_common.c | 6 ++---- src/xenconfig/xen_sxpr.c | 6 ++---- 11 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 81ac4ae..5c8a7be 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -432,9 +432,8 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) goto cleanup; } - if (vmwareParsePath(src, &directoryName, &fileName) < 0) { + if (vmwareParsePath(src, &directoryName, &fileName) < 0) goto cleanup; - } if (!virFileHasSuffix(fileName, ".vmdk")) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index c3fa2dc..5379876 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -313,9 +313,8 @@ vmwareStopVM(struct vmware_driver *driver, vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type)); vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath); - if (virRun(cmd, NULL) < 0) { + if (virRun(cmd, NULL) < 0) return -1; - } vm->def->id = -1; virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason); @@ -345,9 +344,8 @@ vmwareStartVM(struct vmware_driver *driver, virDomainObjPtr vm) else vmwareSetSentinal(cmd, NULL); - if (virRun(cmd, NULL) < 0) { + if (virRun(cmd, NULL) < 0) return -1; - } if ((vm->def->id = vmwareExtractPid(vmxPath)) < 0) { vmwareStopVM(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); diff --git a/src/xen/block_stats.c b/src/xen/block_stats.c index 58e796d..e1e10a2 100644 --- a/src/xen/block_stats.c +++ b/src/xen/block_stats.c @@ -107,9 +107,8 @@ read_bd_stat(int device, int domid, const char *str) VIR_FREE(path); - if (r >= 0) { + if (r >= 0) return r; - } } return -1; diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 5f7c98f..7334142 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2550,15 +2550,13 @@ xenUnifiedNodeDeviceAssignedDomainId(virNodeDevicePtr dev) /* Get active domains */ numdomains = xenUnifiedConnectNumOfDomains(conn); - if (numdomains < 0) { + if (numdomains < 0) return ret; - } if (numdomains > 0) { if (VIR_ALLOC_N(ids, numdomains) < 0) goto out; - if ((numdomains = xenUnifiedConnectListDomains(conn, &ids[0], numdomains)) < 0) { + if ((numdomains = xenUnifiedConnectListDomains(conn, &ids[0], numdomains)) < 0) goto out; - } } /* Get pci bdf */ diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 4be8891..2473532 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2258,9 +2258,8 @@ get_cpu_flags(virConnectPtr conn, const char **hvm, int *pae, int *longmode) if (STREQLEN((const char *)®s.r_ebx, "AuthcAMDenti", 12)) { if (pread(fd, ®s, sizeof(regs), 0x80000001) == sizeof(regs)) { /* Read secure virtual machine bit (bit 2 of ECX feature ID) */ - if ((regs.r_ecx >> 2) & 1) { + if ((regs.r_ecx >> 2) & 1) *hvm = "svm"; - } if ((regs.r_edx >> 6) & 1) *pae = 1; } @@ -2935,9 +2934,8 @@ xenHypervisorNodeGetCellsFreeMemory(virConnectPtr conn, else op_sys.u.availheap.node = cell; ret = xenHypervisorDoV2Sys(priv->handle, &op_sys); - if (ret < 0) { + if (ret < 0) return -1; - } if (hv_versions.sys_interface >= 5) freeMems[i] = op_sys.u.availheap5.avail_bytes; else diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index f1322c4..b233b6b 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -147,14 +147,12 @@ wr_sync(int fd, void *buffer, size_t size, int do_read) } /* recoverable error, retry */ - if ((len == -1) && ((errno == EAGAIN) || (errno == EINTR))) { + if ((len == -1) && ((errno == EAGAIN) || (errno == EINTR))) continue; - } /* eof */ - if (len == 0) { + if (len == 0) break; - } /* unrecoverable error */ if (len == -1) { @@ -1759,9 +1757,8 @@ xenDaemonNodeGetTopology(virConnectPtr conn, virCapsPtr caps) struct sexpr *root; root = sexpr_get(conn, "/xend/node/"); - if (root == NULL) { + if (root == NULL) return -1; - } ret = sexpr_to_xend_topology(root, caps); sexpr_free(root); @@ -2078,9 +2075,8 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid) names = xenDaemonListDomainsOld(conn); tmp = names; - if (names == NULL) { + if (names == NULL) return NULL; - } while (*tmp != NULL) { id = xenDaemonDomainLookupByName_ids(conn, *tmp, &ident[0]); if (id >= 0) { @@ -2160,9 +2156,8 @@ xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def) ret = xenDaemonDomainCreateXML(conn, sexpr); VIR_FREE(sexpr); - if (ret != 0) { + if (ret != 0) goto error; - } /* This comes before wait_for_devices, to ensure that latter cleanup will destroy the domain upon failure */ @@ -2562,9 +2557,8 @@ xenDaemonDomainGetAutostart(virConnectPtr conn, *autostart = 0; tmp = sexpr_node(root, "domain/on_xend_start"); - if (tmp && STREQ(tmp, "start")) { + if (tmp && STREQ(tmp, "start")) *autostart = 1; - } sexpr_free(root); return 0; diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 30985d8..293b2ab 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -121,9 +121,8 @@ xenXMConfigReaper(const void *payload, if (entry->refreshedAt != args->now) { const char *olddomname = entry->def->name; char *nameowner = (char *)virHashLookup(args->priv->nameConfigMap, olddomname); - if (nameowner && STREQ(nameowner, key)) { + if (nameowner && STREQ(nameowner, key)) virHashRemoveEntry(args->priv->nameConfigMap, olddomname); - } return 1; } return 0; @@ -231,9 +230,8 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename) /* If we currently own the name, then release it and re-acquire it later - just in case it was renamed */ nameowner = (char *)virHashLookup(priv->nameConfigMap, entry->def->name); - if (nameowner && STREQ(nameowner, filename)) { + if (nameowner && STREQ(nameowner, filename)) virHashRemoveEntry(priv->nameConfigMap, entry->def->name); - } /* Clear existing config entry which needs refresh */ virDomainDefFree(entry->def); diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index ed4f7e8..7048556 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1493,16 +1493,13 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) } defPtr->maxvcpus = defPtr->vcpus = xenapiDomainGetMaxVcpus(dom); enum xen_on_normal_exit action; - if (xen_vm_get_actions_after_shutdown(session, &action, vm)) { + if (xen_vm_get_actions_after_shutdown(session, &action, vm)) defPtr->onPoweroff = xenapiNormalExitEnum2virDomainLifecycle(action); - } - if (xen_vm_get_actions_after_reboot(session, &action, vm)) { + if (xen_vm_get_actions_after_reboot(session, &action, vm)) defPtr->onReboot = xenapiNormalExitEnum2virDomainLifecycle(action); - } enum xen_on_crash_behaviour crash; - if (xen_vm_get_actions_after_crash(session, &crash, vm)) { + if (xen_vm_get_actions_after_crash(session, &crash, vm)) defPtr->onCrash = xenapiCrashExitEnum2virDomainLifecycle(action); - } xen_vm_get_platform(session, &result, vm); if (result != NULL) { size_t i; @@ -2060,9 +2057,8 @@ call_func(const void *data, size_t len, void *user_handle, fflush(stdout); #endif CURL *curl = curl_easy_init(); - if (!curl) { + if (!curl) return -1; - } xen_comms comms = { .func = result_func, .handle = result_handle diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c index c71dd15..91bc649 100644 --- a/src/xenapi/xenapi_utils.c +++ b/src/xenapi/xenapi_utils.c @@ -84,9 +84,8 @@ xenapiUtil_RequestPassword(virConnectAuthPtr auth, const char *username, cred.result = NULL; cred.resultlen = 0; - if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) { + if ((*(auth->cb))(&cred, 1, auth->cbdata) < 0) VIR_FREE(cred.result); - } break; } @@ -105,9 +104,8 @@ xenapiUtil_ParseQuery(virConnectPtr conn, virURIPtr uri, int *noVerify) for (i = 0; i < uri->paramsCount; i++) { virURIParamPtr queryParam = &uri->params[i]; if (STRCASEEQ(queryParam->name, "no_verify")) { - if (noVerify == NULL) { + if (noVerify == NULL) continue; - } if (virStrToLong_i(queryParam->value, NULL, 10, noVerify) < 0 || (*noVerify != 0 && *noVerify != 1)) { xenapiSessionErrorHandler(conn, VIR_ERR_INVALID_ARG, @@ -282,9 +280,8 @@ mapDomainPinVcpu(unsigned char *cpumap, int maplen) size_t i, j; for (i = 0; i < maplen; i++) { for (j = 0; j < 8; j++) { - if (cpumap[i] & (1 << j)) { + if (cpumap[i] & (1 << j)) virBufferAsprintf(&buf, "%zu,", (8*i)+j); - } } } if (virBufferCheckError(&buf) < 0) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 32954f3..29c6c34 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -729,9 +729,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def) !(chr = xenParseSxprChar(str, NULL))) goto cleanup; if (chr) { - if (VIR_ALLOC_N(def->parallels, 1) < 0) { + if (VIR_ALLOC_N(def->parallels, 1) < 0) goto cleanup; - } chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port = 0; @@ -762,9 +761,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def) goto cleanup; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port = portnum; - if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) { + if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) goto cleanup; - } value = value->next; } diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 6623ea8..a667814 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -1959,16 +1959,14 @@ xenFormatSxprNet(virConnectPtr conn, if (def->model != NULL && STREQ(def->model, "netfront")) { virBufferAddLit(buf, "(type netfront)"); } else { - if (def->model != NULL) { + if (def->model != NULL) virBufferEscapeSexpr(buf, "(model '%s')", def->model); - } /* * apparently (type ioemu) breaks paravirt drivers on HVM so skip * this from XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU */ - if (xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU) { + if (xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU) virBufferAddLit(buf, "(type ioemu)"); - } } } -- 2.1.3

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- tools/virsh-console.c | 6 ++---- tools/virsh-domain.c | 27 +++++++++------------------ tools/virsh-edit.c | 6 ++---- tools/virsh-host.c | 3 +-- tools/virsh-pool.c | 6 ++---- tools/virsh-volume.c | 12 ++++-------- tools/virsh.c | 18 ++++++------------ tools/wireshark/src/packet-libvirt.c | 6 ++---- 8 files changed, 28 insertions(+), 56 deletions(-) diff --git a/tools/virsh-console.c b/tools/virsh-console.c index c245df7..f0faf8c 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -224,9 +224,8 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, con->terminalToStream.offset, avail); if (got < 0) { - if (errno != EAGAIN) { + if (errno != EAGAIN) virConsoleShutdown(con); - } return; } if (got == 0) { @@ -268,9 +267,8 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, con->streamToTerminal.data, con->streamToTerminal.offset); if (done < 0) { - if (errno != EAGAIN) { + if (errno != EAGAIN) virConsoleShutdown(con); - } return; } memmove(con->streamToTerminal.data, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 8e743f1..cde2b4e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -161,9 +161,8 @@ vshNodeGetCPUCount(virConnectPtr conn) if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) { /* fall back to nodeinfo */ vshResetLibvirtError(); - if (virNodeGetInfo(conn, &nodeinfo) == 0) { + if (virNodeGetInfo(conn, &nodeinfo) == 0) ret = VIR_NODEINFO_MAXCPUS(nodeinfo); - } } return ret; } @@ -3446,9 +3445,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe = true; } - if (nvram) { + if (nvram) flags |= VIR_DOMAIN_UNDEFINE_NVRAM; - } if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -3498,9 +3496,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags &= ~VIR_DOMAIN_UNDEFINE_MANAGED_SAVE; managed_save_safe = true; } - if (has_snapshots == 0) { + if (has_snapshots == 0) snapshots_safe = true; - } if (has_snapshots_metadata == 0) { flags &= ~VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe = true; @@ -6180,9 +6177,8 @@ vshPrintPinInfo(unsigned char *cpumaps, size_t cpumaplen, int cpu, lastcpu; bool bit, lastbit, isInvert; - if (!cpumaps || cpumaplen <= 0 || maxcpu <= 0 || vcpuindex < 0) { + if (!cpumaps || cpumaplen <= 0 || maxcpu <= 0 || vcpuindex < 0) return false; - } bit = lastbit = isInvert = false; lastcpu = -1; @@ -6202,9 +6198,8 @@ vshPrintPinInfo(unsigned char *cpumaps, size_t cpumaplen, vshPrint(ctl, "-%d", cpu - 1); lastbit = bit; } - if (bit && !isInvert) { + if (bit && !isInvert) vshPrint(ctl, "-%d", maxcpu - 1); - } return true; } @@ -6361,9 +6356,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) { + if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) goto cleanup; - } cpumaplen = VIR_CPU_MAPLEN(maxcpu); @@ -7928,13 +7922,11 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) kibibytes = VIR_DIV_UP(bytes, 1024); if (flags == -1) { - if (virDomainSetMemory(dom, kibibytes) != 0) { + if (virDomainSetMemory(dom, kibibytes) != 0) ret = false; - } } else { - if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) { + if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) ret = false; - } } virDomainFree(dom); @@ -9488,9 +9480,8 @@ doMigrate(void *opaque) if (vshCommandOptBool(cmd, "rdma-pin-all")) flags |= VIR_MIGRATE_RDMA_PIN_ALL; - if (vshCommandOptBool(cmd, "offline")) { + if (vshCommandOptBool(cmd, "offline")) flags |= VIR_MIGRATE_OFFLINE; - } if (vshCommandOptBool(cmd, "abort-on-error")) flags |= VIR_MIGRATE_ABORT_ON_ERROR; diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c index 10298f6..41a6d53 100644 --- a/tools/virsh-edit.c +++ b/tools/virsh-edit.c @@ -85,9 +85,8 @@ do { goto edit_cleanup; /* Compare original XML with edited. Has it changed at all? */ - if (STREQ(doc, doc_edited)) { + if (STREQ(doc, doc_edited)) EDIT_NOT_CHANGED; - } redefine: msg = NULL; @@ -109,9 +108,8 @@ do { } /* Everything checks out, so redefine the object. */ - if (!msg && !(EDIT_DEFINE)) { + if (!msg && !(EDIT_DEFINE)) msg = _("Failed."); - } if (msg) { int c = vshAskReedit(ctl, msg); diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 28b160d..20765e5 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -376,9 +376,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup; vshPrint(ctl, _("Node %d:\n"), cell); - for (j = 0; j < npages; j++) { + for (j = 0; j < npages; j++) vshPrint(ctl, "%uKiB: %lld\n", pagesize[j], counts[j]); - } vshPrint(ctl, "%c", '\n'); } diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 0b8dba5..a05608b 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -470,13 +470,11 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false; - if (vshCommandOptBool(cmd, "no-overwrite")) { + if (vshCommandOptBool(cmd, "no-overwrite")) flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE; - } - if (vshCommandOptBool(cmd, "overwrite")) { + if (vshCommandOptBool(cmd, "overwrite")) flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE; - } if (virStoragePoolBuild(pool, flags) == 0) { vshPrint(ctl, _("Pool %s built\n"), name); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 4f810f8..9b6b4c9 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -687,9 +687,8 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) return false; } - if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; - } if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) goto cleanup; @@ -885,9 +884,8 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd) bool ret = true; const char *name; - if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; - } if (virStorageVolDelete(vol, 0) == 0) { vshPrint(ctl, _("Vol %s deleted\n"), name); @@ -945,9 +943,8 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd) int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO; int funcRet; - if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; - } if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0) goto out; @@ -1741,9 +1738,8 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) virStorageVolPtr vol; char * StorageVolPath; - if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; - } if ((StorageVolPath = virStorageVolGetPath(vol)) == NULL) { virStorageVolFree(vol); diff --git a/tools/virsh.c b/tools/virsh.c index 036b517..eb648bd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -499,9 +499,8 @@ vshPrintRaw(vshControl *ctl, ...) char *key; va_start(ap, ctl); - while ((key = va_arg(ap, char *)) != NULL) { + while ((key = va_arg(ap, char *)) != NULL) vshPrint(ctl, "%s\r\n", key); - } va_end(ap); } @@ -874,9 +873,8 @@ cmdCd(vshControl *ctl, const vshCmd *cmd) return false; } - if (vshCommandOptString(cmd, "dir", &dir) <= 0) { + if (vshCommandOptString(cmd, "dir", &dir) <= 0) dir = dir_malloced = virGetUserDirectory(); - } if (!dir) dir = "/"; @@ -1136,9 +1134,8 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, const vshCmdOptDef *ret = NULL; char *alias = NULL; - if (STREQ(name, helpopt.name)) { + if (STREQ(name, helpopt.name)) return &helpopt; - } for (i = 0; cmd->opts && cmd->opts[i].name; i++) { const vshCmdOptDef *opt = &cmd->opts[i]; @@ -1642,9 +1639,8 @@ vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) if (ret <= 0) return ret; - if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK)) { + if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK)) return -1; - } *value = arg->data; return 1; } @@ -1839,9 +1835,8 @@ vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) opt = opt ? opt->next : cmd->opts; while (opt) { - if (opt->def->type == VSH_OT_ARGV) { + if (opt->def->type == VSH_OT_ARGV) return opt; - } opt = opt->next; } return NULL; @@ -3703,9 +3698,8 @@ main(int argc, char **argv) else progname++; - if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI"))) { + if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI"))) ctl->name = vshStrdup(ctl, defaultConn); - } vshInitDebug(ctl); diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/packet-libvirt.c index 5c3c369..f7aa7ed 100644 --- a/tools/wireshark/src/packet-libvirt.c +++ b/tools/wireshark/src/packet-libvirt.c @@ -249,9 +249,8 @@ find_payload_dissector(guint32 proc, guint32 type, first = pds[0].proc; last = pds[length-1].proc; - if (proc < first || proc > last) { + if (proc < first || proc > last) return NULL; - } pd = &pds[proc-first]; /* There is no guarantee to proc numbers has no gap */ @@ -329,9 +328,8 @@ dissect_libvirt_payload_xdr_data(tvbuff_t *tvb, proto_tree *tree, gint payload_l xdr_destroy(&xdrs); g_free(payload_data); - if (nfds != 0) { + if (nfds != 0) dissect_libvirt_fds(tvb, start + payload_length, nfds); - } } static void -- 2.1.3

On 11/13/2014 09:37 AM, Martin Kletzander wrote:
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- tools/virsh-console.c | 6 ++---- tools/virsh-domain.c | 27 +++++++++------------------ tools/virsh-edit.c | 6 ++---- tools/virsh-host.c | 3 +-- tools/virsh-pool.c | 6 ++---- tools/virsh-volume.c | 12 ++++-------- tools/virsh.c | 18 ++++++------------ tools/wireshark/src/packet-libvirt.c | 6 ++---- 8 files changed, 28 insertions(+), 56 deletions(-)
diff --git a/tools/virsh-console.c b/tools/virsh-console.c index c245df7..f0faf8c 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -224,9 +224,8 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED, con->terminalToStream.offset, avail); if (got < 0) { - if (errno != EAGAIN) { + if (errno != EAGAIN) virConsoleShutdown(con); - } return; } if (got == 0) { @@ -268,9 +267,8 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, con->streamToTerminal.data, con->streamToTerminal.offset); if (done < 0) { - if (errno != EAGAIN) { + if (errno != EAGAIN) virConsoleShutdown(con); - } return; } memmove(con->streamToTerminal.data, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 8e743f1..cde2b4e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -161,9 +161,8 @@ vshNodeGetCPUCount(virConnectPtr conn) if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) { /* fall back to nodeinfo */ vshResetLibvirtError(); - if (virNodeGetInfo(conn, &nodeinfo) == 0) { + if (virNodeGetInfo(conn, &nodeinfo) == 0) ret = VIR_NODEINFO_MAXCPUS(nodeinfo); - } } return ret; } @@ -3446,9 +3445,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags |= VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe = true; } - if (nvram) { + if (nvram) flags |= VIR_DOMAIN_UNDEFINE_NVRAM; - }
if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) return false; @@ -3498,9 +3496,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags &= ~VIR_DOMAIN_UNDEFINE_MANAGED_SAVE; managed_save_safe = true; } - if (has_snapshots == 0) { + if (has_snapshots == 0) snapshots_safe = true; - } if (has_snapshots_metadata == 0) { flags &= ~VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe = true; @@ -6180,9 +6177,8 @@ vshPrintPinInfo(unsigned char *cpumaps, size_t cpumaplen, int cpu, lastcpu; bool bit, lastbit, isInvert;
- if (!cpumaps || cpumaplen <= 0 || maxcpu <= 0 || vcpuindex < 0) { + if (!cpumaps || cpumaplen <= 0 || maxcpu <= 0 || vcpuindex < 0) return false; - }
bit = lastbit = isInvert = false; lastcpu = -1; @@ -6202,9 +6198,8 @@ vshPrintPinInfo(unsigned char *cpumaps, size_t cpumaplen, vshPrint(ctl, "-%d", cpu - 1); lastbit = bit; } - if (bit && !isInvert) { + if (bit && !isInvert) vshPrint(ctl, "-%d", maxcpu - 1); - }
return true; } @@ -6361,9 +6356,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) goto cleanup; }
- if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) { + if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) goto cleanup; - }
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
@@ -7928,13 +7922,11 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) kibibytes = VIR_DIV_UP(bytes, 1024);
if (flags == -1) { - if (virDomainSetMemory(dom, kibibytes) != 0) { + if (virDomainSetMemory(dom, kibibytes) != 0) ret = false; - } } else { - if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) { + if (virDomainSetMemoryFlags(dom, kibibytes, flags) < 0) ret = false; - } }
virDomainFree(dom); @@ -9488,9 +9480,8 @@ doMigrate(void *opaque) if (vshCommandOptBool(cmd, "rdma-pin-all")) flags |= VIR_MIGRATE_RDMA_PIN_ALL;
- if (vshCommandOptBool(cmd, "offline")) { + if (vshCommandOptBool(cmd, "offline")) flags |= VIR_MIGRATE_OFFLINE; - }
if (vshCommandOptBool(cmd, "abort-on-error")) flags |= VIR_MIGRATE_ABORT_ON_ERROR; diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c index 10298f6..41a6d53 100644 --- a/tools/virsh-edit.c +++ b/tools/virsh-edit.c @@ -85,9 +85,8 @@ do { goto edit_cleanup;
/* Compare original XML with edited. Has it changed at all? */ - if (STREQ(doc, doc_edited)) { + if (STREQ(doc, doc_edited)) EDIT_NOT_CHANGED; - }
And this is one where the fears of removing the brackets sets in - inline MACROs that do not have a 'do { ... } while(0)' definition.... I thought perhaps it'd be vbox and the funky macros there, but if you look at the #define for EDIT_NOT_CHANGED it differs within the various virsh-*.c files. For example, in virsh-domain.c there's: #define EDIT_NOT_CHANGED \ vshPrint(ctl, _("Saved image %s XML configuration " \ "not changed.\n"), file); \ ret = true; goto edit_cleanup; So, in effect the second line will always be executed as I'm reading things. there's also : #define EDIT_NOT_CHANGED \ vshPrint(ctl, "%s", _("Metadata not changed")); \ ret = true; \ goto edit_cleanup; and #define EDIT_NOT_CHANGED \ vshPrint(ctl, _("Domain %s XML configuration not changed.\n"), \ virDomainGetName(dom)); \ ret = true; goto edit_cleanup; I think modifying the macros to have the do {...} while(0); syntax will do the trick. John
redefine: msg = NULL; @@ -109,9 +108,8 @@ do { }
/* Everything checks out, so redefine the object. */ - if (!msg && !(EDIT_DEFINE)) { + if (!msg && !(EDIT_DEFINE)) msg = _("Failed."); - }
if (msg) { int c = vshAskReedit(ctl, msg); diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 28b160d..20765e5 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -376,9 +376,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) goto cleanup;
vshPrint(ctl, _("Node %d:\n"), cell); - for (j = 0; j < npages; j++) { + for (j = 0; j < npages; j++) vshPrint(ctl, "%uKiB: %lld\n", pagesize[j], counts[j]); - } vshPrint(ctl, "%c", '\n'); }
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 0b8dba5..a05608b 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -470,13 +470,11 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name))) return false;
- if (vshCommandOptBool(cmd, "no-overwrite")) { + if (vshCommandOptBool(cmd, "no-overwrite")) flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE; - }
- if (vshCommandOptBool(cmd, "overwrite")) { + if (vshCommandOptBool(cmd, "overwrite")) flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE; - }
if (virStoragePoolBuild(pool, flags) == 0) { vshPrint(ctl, _("Pool %s built\n"), name); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 4f810f8..9b6b4c9 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -687,9 +687,8 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) return false; }
- if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; - }
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0) goto cleanup; @@ -885,9 +884,8 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd) bool ret = true; const char *name;
- if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; - }
if (virStorageVolDelete(vol, 0) == 0) { vshPrint(ctl, _("Vol %s deleted\n"), name); @@ -945,9 +943,8 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd) int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO; int funcRet;
- if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) return false; - }
if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0) goto out; @@ -1741,9 +1738,8 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) virStorageVolPtr vol; char * StorageVolPath;
- if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) { + if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; - }
if ((StorageVolPath = virStorageVolGetPath(vol)) == NULL) { virStorageVolFree(vol); diff --git a/tools/virsh.c b/tools/virsh.c index 036b517..eb648bd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -499,9 +499,8 @@ vshPrintRaw(vshControl *ctl, ...) char *key;
va_start(ap, ctl); - while ((key = va_arg(ap, char *)) != NULL) { + while ((key = va_arg(ap, char *)) != NULL) vshPrint(ctl, "%s\r\n", key); - } va_end(ap); }
@@ -874,9 +873,8 @@ cmdCd(vshControl *ctl, const vshCmd *cmd) return false; }
- if (vshCommandOptString(cmd, "dir", &dir) <= 0) { + if (vshCommandOptString(cmd, "dir", &dir) <= 0) dir = dir_malloced = virGetUserDirectory(); - } if (!dir) dir = "/";
@@ -1136,9 +1134,8 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, const vshCmdOptDef *ret = NULL; char *alias = NULL;
- if (STREQ(name, helpopt.name)) { + if (STREQ(name, helpopt.name)) return &helpopt; - }
for (i = 0; cmd->opts && cmd->opts[i].name; i++) { const vshCmdOptDef *opt = &cmd->opts[i]; @@ -1642,9 +1639,8 @@ vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) if (ret <= 0) return ret;
- if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK)) { + if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK)) return -1; - } *value = arg->data; return 1; } @@ -1839,9 +1835,8 @@ vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) opt = opt ? opt->next : cmd->opts;
while (opt) { - if (opt->def->type == VSH_OT_ARGV) { + if (opt->def->type == VSH_OT_ARGV) return opt; - } opt = opt->next; } return NULL; @@ -3703,9 +3698,8 @@ main(int argc, char **argv) else progname++;
- if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI"))) { + if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI"))) ctl->name = vshStrdup(ctl, defaultConn); - }
vshInitDebug(ctl);
diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/packet-libvirt.c index 5c3c369..f7aa7ed 100644 --- a/tools/wireshark/src/packet-libvirt.c +++ b/tools/wireshark/src/packet-libvirt.c @@ -249,9 +249,8 @@ find_payload_dissector(guint32 proc, guint32 type,
first = pds[0].proc; last = pds[length-1].proc; - if (proc < first || proc > last) { + if (proc < first || proc > last) return NULL; - }
pd = &pds[proc-first]; /* There is no guarantee to proc numbers has no gap */ @@ -329,9 +328,8 @@ dissect_libvirt_payload_xdr_data(tvbuff_t *tvb, proto_tree *tree, gint payload_l xdr_destroy(&xdrs); g_free(payload_data);
- if (nfds != 0) { + if (nfds != 0) dissect_libvirt_fds(tvb, start + payload_length, nfds); - } }
static void

Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- tests/commandhelper.c | 3 +-- tests/esxutilstest.c | 12 ++++-------- tests/eventtest.c | 3 +-- tests/openvzutilstest.c | 6 ++---- tests/securityselinuxlabeltest.c | 6 ++---- tests/shunloadtest.c | 6 ++---- tests/utiltest.c | 3 +-- tests/virbuftest.c | 3 +-- tests/virhashtest.c | 30 ++++++++++-------------------- tests/virtimetest.c | 3 +-- tests/vmx2xmltest.c | 12 ++++-------- tests/xml2vmxtest.c | 27 +++++++++------------------ 12 files changed, 38 insertions(+), 76 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 86ed891..015efda 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -70,9 +70,8 @@ int main(int argc, char **argv) { if (!log) goto cleanup; - for (i = 1; i < argc; i++) { + for (i = 1; i < argc; i++) fprintf(log, "ARG:%s\n", argv[i]); - } origenv = environ; n = 0; diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index 41c0807..44bdc84 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -54,9 +54,8 @@ testParseDatastorePath(const void *data ATTRIBUTE_UNUSED) goto failure; } - if (paths[i].result < 0) { + if (paths[i].result < 0) continue; - } if (STRNEQ(paths[i].datastoreName, datastoreName)) { virtTestDifference(stderr, paths[i].datastoreName, datastoreName); @@ -138,9 +137,8 @@ testConvertDateTimeToCalendarTime(const void *data ATTRIBUTE_UNUSED) return -1; } - if (times[i].calendarTime != calendarTime) { + if (times[i].calendarTime != calendarTime) return -1; - } } return 0; @@ -186,9 +184,8 @@ testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED) escaped = esxUtil_EscapeDatastoreItem(datastoreItems[i].string); - if (escaped == NULL) { + if (escaped == NULL) return -1; - } if (STRNEQ(datastoreItems[i].escaped, escaped)) { VIR_FREE(escaped); @@ -228,9 +225,8 @@ testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED) utf8 = virVMXConvertToUTF8("Windows-1252", windows1252ToUTF8[i].windows1252); - if (utf8 == NULL) { + if (utf8 == NULL) return -1; - } if (STRNEQ(windows1252ToUTF8[i].utf8, utf8)) { VIR_FREE(utf8); diff --git a/tests/eventtest.c b/tests/eventtest.c index 87b49d3..13adbf6 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -124,9 +124,8 @@ static int eventThreadJobDone; ATTRIBUTE_NORETURN static void *eventThreadLoop(void *data ATTRIBUTE_UNUSED) { while (1) { pthread_mutex_lock(&eventThreadMutex); - while (!eventThreadRunOnce) { + while (!eventThreadRunOnce) pthread_cond_wait(&eventThreadRunCond, &eventThreadMutex); - } eventThreadRunOnce = 0; pthread_mutex_unlock(&eventThreadMutex); diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index ed2c098..f5a8d12 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -42,9 +42,8 @@ testReadConfigParam(const void *data ATTRIBUTE_UNUSED) char *conf = NULL; char *value = NULL; - if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0) { + if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0) return -1; - } for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) { if (openvzReadConfigParam(conf, configParams[i].param, @@ -52,9 +51,8 @@ testReadConfigParam(const void *data ATTRIBUTE_UNUSED) goto cleanup; } - if (configParams[i].ret != 1) { + if (configParams[i].ret != 1) continue; - } if (STRNEQ(configParams[i].value, value)) { virtTestDifference(stderr, configParams[i].value, value); diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 455eb74..8106c77 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -120,9 +120,8 @@ testSELinuxLoadFileList(const char *testname, abs_srcdir, testname) < 0) goto cleanup; - if (!(fp = fopen(path, "r"))) { + if (!(fp = fopen(path, "r"))) goto cleanup; - } if (VIR_ALLOC_N(line, 1024) < 0) goto cleanup; @@ -191,9 +190,8 @@ testSELinuxLoadDef(const char *testname) abs_srcdir, testname) < 0) goto cleanup; - if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) { + if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) goto cleanup; - } if (!(def = virDomainDefParseString(xmlstr, caps, xmlopt, QEMU_EXPECTED_VIRT_TYPES, diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c index 80f5351..37d990d 100644 --- a/tests/shunloadtest.c +++ b/tests/shunloadtest.c @@ -74,9 +74,8 @@ static void *threadMain(void *arg) pthread_cond_signal(&cond); } - while (!quit) { + while (!quit) pthread_cond_wait(&cond, &lock); - } pthread_mutex_unlock(&lock); return NULL; @@ -126,9 +125,8 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv) /* Wait for the thread to start and call libvirt */ pthread_mutex_lock(&lock); - while (!running && !failstart) { + while (!running && !failstart) pthread_cond_wait(&cond, &lock); - } /* Close the shared library (and thus make libvirt.so * non-resident */ diff --git a/tests/utiltest.c b/tests/utiltest.c index 89e82aa..8950cf2 100644 --- a/tests/utiltest.c +++ b/tests/utiltest.c @@ -124,9 +124,8 @@ testParseVersionString(const void *data ATTRIBUTE_UNUSED) return -1; } - if (result < 0) { + if (result < 0) continue; - } if (version != versions[i].version) { if (virTestGetDebug() > 0) { diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 2398890..554a8c0 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -38,9 +38,8 @@ static int testBufInfiniteLoop(const void *data) * which was the case after the above addchar at the time of the bug. * This test is a bit fragile, since it relies on virBuffer internals. */ - if (virAsprintf(&addstr, "%*s", buf->a - buf->b - 1, "a") < 0) { + if (virAsprintf(&addstr, "%*s", buf->a - buf->b - 1, "a") < 0) goto out; - } if (info->doEscape) virBufferEscapeString(buf, "%s", addstr); diff --git a/tests/virhashtest.c b/tests/virhashtest.c index 340dc84..c9d189b 100644 --- a/tests/virhashtest.c +++ b/tests/virhashtest.c @@ -531,17 +531,15 @@ testHashGetItems(const void *data ATTRIBUTE_UNUSED) virHashAddEntry(hash, keya, value3) < 0 || virHashAddEntry(hash, keyc, value1) < 0 || virHashAddEntry(hash, keyb, value2) < 0) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to create hash"); - } goto cleanup; } if (!(array = virHashGetItems(hash, NULL)) || array[3].key || array[3].value) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to get items with NULL sort"); - } goto cleanup; } VIR_FREE(array); @@ -554,9 +552,8 @@ testHashGetItems(const void *data ATTRIBUTE_UNUSED) STRNEQ(array[2].key, "c") || STRNEQ(array[2].value, "1") || array[3].key || array[3].value) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to get items with key sort"); - } goto cleanup; } VIR_FREE(array); @@ -569,9 +566,8 @@ testHashGetItems(const void *data ATTRIBUTE_UNUSED) STRNEQ(array[2].key, "a") || STRNEQ(array[2].value, "3") || array[3].key || array[3].value) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to get items with value sort"); - } goto cleanup; } @@ -612,44 +608,38 @@ testHashEqual(const void *data ATTRIBUTE_UNUSED) virHashAddEntry(hash1, keyc, value3_l) < 0 || virHashAddEntry(hash2, keya, value1_u) < 0 || virHashAddEntry(hash2, keyb, value2_u) < 0) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to create hashes"); - } goto cleanup; } if (virHashEqual(hash1, hash2, testHashEqualCompValue)) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed equal test for different number of elements"); - } goto cleanup; } if (virHashAddEntry(hash2, keyc, value4_u) < 0) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to add element to hash2"); - } goto cleanup; } if (virHashEqual(hash1, hash2, testHashEqualCompValue)) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed equal test for same number of elements"); - } goto cleanup; } if (virHashUpdateEntry(hash2, keyc, value3_u) < 0) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed to update element in hash2"); - } goto cleanup; } if (!virHashEqual(hash1, hash2, testHashEqualCompValue)) { - if (virTestGetVerbose()) { + if (virTestGetVerbose()) testError("\nfailed equal test for equal hash tables"); - } goto cleanup; } diff --git a/tests/virtimetest.c b/tests/virtimetest.c index 64bf19b..9ab38ae 100644 --- a/tests/virtimetest.c +++ b/tests/virtimetest.c @@ -88,9 +88,8 @@ testTimeLocalOffset(const void *args) } tzset(); - if (virTimeLocalOffsetFromUTC(&actual) < 0) { + if (virTimeLocalOffsetFromUTC(&actual) < 0) return -1; - } if (data->offset != actual) { VIR_DEBUG("Expect Offset %ld got %ld\n", diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 5c103dd..6b1e724 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -27,9 +27,8 @@ testCapsInit(void) caps = virCapabilitiesNew(VIR_ARCH_I686, true, true); - if (caps == NULL) { + if (caps == NULL) return; - } virCapabilitiesAddHostMigrateTransport(caps, "esx"); @@ -39,9 +38,8 @@ testCapsInit(void) VIR_ARCH_I686, NULL, NULL, 0, NULL); - if (guest == NULL) { + if (guest == NULL) goto failure; - } if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL) == NULL) { @@ -54,9 +52,8 @@ testCapsInit(void) VIR_ARCH_X86_64, NULL, NULL, 0, NULL); - if (guest == NULL) { + if (guest == NULL) goto failure; - } if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL) == NULL) { @@ -201,9 +198,8 @@ mymain(void) testCapsInit(); - if (caps == NULL) { + if (caps == NULL) return EXIT_FAILURE; - } if (!(xmlopt = virVMXDomainXMLConfInit())) return EXIT_FAILURE; diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 58418dc..ca9445d 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -27,9 +27,8 @@ testCapsInit(void) caps = virCapabilitiesNew(VIR_ARCH_I686, true, true); - if (caps == NULL) { + if (caps == NULL) return; - } virCapabilitiesAddHostMigrateTransport(caps, "esx"); @@ -40,9 +39,8 @@ testCapsInit(void) VIR_ARCH_I686, NULL, NULL, 0, NULL); - if (guest == NULL) { + if (guest == NULL) goto failure; - } if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL) == NULL) { @@ -55,9 +53,8 @@ testCapsInit(void) VIR_ARCH_X86_64, NULL, NULL, 0, NULL); - if (guest == NULL) { + if (guest == NULL) goto failure; - } if (virCapabilitiesAddGuestDomain(guest, "vmware", NULL, NULL, 0, NULL) == NULL) { @@ -81,21 +78,18 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) char *formatted = NULL; virDomainDefPtr def = NULL; - if (virtTestLoadFile(xml, &xmlData) < 0) { + if (virtTestLoadFile(xml, &xmlData) < 0) goto failure; - } - if (virtTestLoadFile(vmx, &vmxData) < 0) { + if (virtTestLoadFile(vmx, &vmxData) < 0) goto failure; - } def = virDomainDefParseString(xmlData, caps, xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE); - if (def == NULL) { + if (def == NULL) goto failure; - } if (!virDomainDefCheckABIStability(def, def)) { fprintf(stderr, "ABI stability check failed on %s", xml); @@ -104,9 +98,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) formatted = virVMXFormatConfig(&ctx, xmlopt, def, virtualHW_version); - if (formatted == NULL) { + if (formatted == NULL) goto failure; - } if (STRNEQ(vmxData, formatted)) { virtTestDifference(stderr, vmxData, formatted); @@ -207,9 +200,8 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED) success = true; cleanup: - if (! success) { + if (! success) VIR_FREE(absolutePath); - } VIR_FREE(copyOfDatastorePath); @@ -233,9 +225,8 @@ mymain(void) testCapsInit(); - if (caps == NULL) { + if (caps == NULL) return EXIT_FAILURE; - } if (!(xmlopt = virVMXDomainXMLConfInit())) return EXIT_FAILURE; -- 2.1.3

After recent discussion it looks like curly brackets around one-line bodies are preferred if the preceding condition is, itself, multiline. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- HACKING | 8 ++++---- docs/hacking.html.in | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/HACKING b/HACKING index 8f42e51..0f36405 100644 --- a/HACKING +++ b/HACKING @@ -370,10 +370,10 @@ although use of a semicolon is not currently rejected. Curly braces ============ -Omit the curly braces around an "if", "while", "for" etc. body only when that -body occupies a single line. In every other case we require the braces. This -ensures that it is trivially easy to identify a single-'statement' loop: each -has only one 'line' in its body. +Omit the curly braces around an "if", "while", "for" etc. body only when both +that body and the condition itself occupy a single line. In every other case +we require the braces. This ensures that it is trivially easy to identify a +single-'statement' loop: each has only one 'line' in its body. Omitting braces with a single-line body is fine: diff --git a/docs/hacking.html.in b/docs/hacking.html.in index b1553a5..fac1417 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -462,8 +462,8 @@ <p> Omit the curly braces around an <code>if</code>, <code>while</code>, - <code>for</code> etc. body only - when that body occupies a single line. In every other case we require + <code>for</code> etc. body only when both that body and the condition + itself occupy a single line. In every other case we require the braces. This ensures that it is trivially easy to identify a single-<i>statement</i> loop: each has only one <i>line</i> in its body. </p> -- 2.1.3

On 11/13/2014 07:37 AM, Martin Kletzander wrote:
After recent discussion it looks like curly brackets around one-line bodies are preferred if the preceding condition is, itself, multiline.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- HACKING | 8 ++++---- docs/hacking.html.in | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
+++ b/docs/hacking.html.in @@ -462,8 +462,8 @@
<p> Omit the curly braces around an <code>if</code>, <code>while</code>, - <code>for</code> etc. body only - when that body occupies a single line. In every other case we require + <code>for</code> etc. body only when both that body and the condition + itself occupy a single line. In every other case we require the braces. This ensures that it is trivially easy to identify a single-<i>statement</i> loop: each has only one <i>line</i> in its body. </p>
I think we want a few more examples, and mention that the ultimate measure of whether {} are required or prohibited is whether syntax-check complains. if (condition1 && condition2) { // multi-line, at same indentation, {} required statement(); } if (condition1(arg1, arg2)) // indentation makes it obvious it is single line, statement(); // {} is optional (not enforced either way) if (condition1) statement(); // single-line; {} is forbidden -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

In bracket-spacing.pl, the current $line is being modified in $data. That, however, spoils that $data for another check. Introduce new $tmpdata variable that can be used for temporary modifications. The difference between $data and $line is that $data are as much cleaned as possible from non-code blocks and these changes must be kept. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- build-aux/bracket-spacing.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index ac01a56..5fce2b7 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -31,6 +31,8 @@ foreach my $file (@ARGV) { while (defined (my $line = <FILE>)) { my $data = $line; + # For temporary modifications + my $tmpdata; # Kill any quoted , ; = or " $data =~ s/'[";,=]'/'X'/g; @@ -77,12 +79,15 @@ foreach my $file (@ARGV) { # # foo (*bar, wizz); # - while ($data =~ /(\w+)\s\((?!\*)/) { + # We also don't want to spoil the $data so it can be used + # later on. + $tmpdata = $data; + while ($tmpdata =~ /(\w+)\s\((?!\*)/) { my $kw = $1; # Allow space after keywords only if ($kw =~ /^(if|for|while|switch|return)$/) { - $data =~ s/($kw\s\()/XXX(/; + $tmpdata =~ s/($kw\s\()/XXX(/; } else { print "$file:$.: $line"; $ret = 1; @@ -147,9 +152,10 @@ foreach my $file (@ARGV) { # Require spaces around assignment '=', compounds and '==' # with the exception of virAssertCmpInt() - $data =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/; - while ($data =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ || - $data =~ /=[^= \\\n]/) { + $tmpdata = $data; + $tmpdata =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/; + while ($tmpdata =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ || + $tmpdata =~ /=[^= \\\n]/) { print "$file:$.: $line"; $ret = 1; last; -- 2.1.3

On 11/13/2014 07:37 AM, Martin Kletzander wrote:
In bracket-spacing.pl, the current $line is being modified in $data. That, however, spoils that $data for another check. Introduce new $tmpdata variable that can be used for temporary modifications. The difference between $data and $line is that $data are as much cleaned as possible from non-code blocks and these changes must be kept.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- build-aux/bracket-spacing.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
ACK; this one should be safe to go in at any point. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Change while () { smth; last; } to if () { smth; } as 'last' in perl is analogous to 'break' in C. These are probably copy-paste leftovers from creating new syntax-check rules. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- build-aux/bracket-spacing.pl | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index 5fce2b7..d178703 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -97,26 +97,23 @@ foreach my $file (@ARGV) { # Require whitespace immediately after keywords, # but none after the opening bracket - while ($data =~ /\b(if|for|while|switch|return)\(/ || - $data =~ /\b(if|for|while|switch|return)\s+\(\s/) { + if ($data =~ /\b(if|for|while|switch|return)\(/ || + $data =~ /\b(if|for|while|switch|return)\s+\(\s/) { print "$file:$.: $line"; $ret = 1; - last; } # Forbid whitespace between )( of a function typedef - while ($data =~ /\(\*\w+\)\s+\(/) { + if ($data =~ /\(\*\w+\)\s+\(/) { print "$file:$.: $line"; $ret = 1; - last; } # Forbid whitespace following ( or prior to ) - while ($data =~ /\S\s+\)/ || - $data =~ /\(\s+\S/) { + if ($data =~ /\S\s+\)/ || + $data =~ /\(\s+\S/) { print "$file:$.: $line"; $ret = 1; - last; } # Forbid whitespace before ";" or ",". Things like below are allowed: @@ -129,36 +126,32 @@ foreach my $file (@ARGV) { # errno == EINTR) # ; # - while ($data =~ /[^;\s]\s+[;,]/) { + if ($data =~ /[^;\s]\s+[;,]/) { print "$file:$.: $line"; $ret = 1; - last; } # Require EOL, macro line continuation, or whitespace after ";". # Allow "for (;;)" as an exception. - while ($data =~ /;[^ \\\n;)]/) { + if ($data =~ /;[^ \\\n;)]/) { print "$file:$.: $line"; $ret = 1; - last; } # Require EOL, space, or enum/struct end after comma. - while ($data =~ /,[^ \\\n)}]/) { + if ($data =~ /,[^ \\\n)}]/) { print "$file:$.: $line"; $ret = 1; - last; } # Require spaces around assignment '=', compounds and '==' # with the exception of virAssertCmpInt() $tmpdata = $data; $tmpdata =~ s/(virAssertCmpInt\(.* ).?=,/$1op,/; - while ($tmpdata =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ || - $tmpdata =~ /=[^= \\\n]/) { + if ($tmpdata =~ /[^ ]\b[!<>&|\-+*\/%\^=]?=[^=]/ || + $tmpdata =~ /=[^= \\\n]/) { print "$file:$.: $line"; $ret = 1; - last; } } close FILE; -- 2.1.3

On 11/13/2014 07:37 AM, Martin Kletzander wrote:
Change while () { smth; last; } to if () { smth; } as 'last' in perl is analogous to 'break' in C. These are probably copy-paste leftovers from creating new syntax-check rules.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- build-aux/bracket-spacing.pl | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
ACK. Should be safe to go in now. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

We're looking for three consecutive lines, first one is a if/for/while with a condition and start of body, second one is a body with one and only semicolon and third is end of the body by itself. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- build-aux/bracket-spacing.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index d178703..eb2d372 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -27,6 +27,11 @@ my $ret = 0; my $incomment = 0; foreach my $file (@ARGV) { + # Per-file variables for multiline Curly Bracket (cb_) check + my $cb_linenum = 0; + my $cb_code = ""; + my $cb_scolon = 0; + open FILE, $file; while (defined (my $line = <FILE>)) { @@ -153,6 +158,36 @@ foreach my $file (@ARGV) { print "$file:$.: $line"; $ret = 1; } + + # One line conditional statements with one line bodies should + # not use curly brackets. We also need to use $line instead $data as + if ($data =~ /^\s*(if|while|for)\b.*\{$/) { + $cb_linenum = $.; + $cb_code = $line; + $cb_scolon = 0; + } + + # We need to check for exactly one semicolon inside the body, + # because empty statements (e.g. with comment only) are + # allowed + if ($cb_linenum == $. - 1 && $data =~ /^[^;]*;[^;]*$/) { + $cb_code .= $line; + $cb_scolon = 1; + } + + if ($data =~ /^\s*}\s*$/ && + $cb_linenum == $. - 2 && + $cb_scolon) { + + print "$file:$cb_linenum-$.:\n$cb_code$line"; + $ret = 1; + + # There _should_ be no need to reset the values; but to + # keep my inner piece... + $cb_linenum = 0; + $cb_scolon = 0; + $cb_code = ""; + } } close FILE; } -- 2.1.3

On 11/13/2014 09:37 AM, Martin Kletzander wrote:
We're looking for three consecutive lines, first one is a if/for/while with a condition and start of body, second one is a body with one and only semicolon and third is end of the body by itself.
And because of a later ";;" check - one cannot entirely work around this single colon count...
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- build-aux/bracket-spacing.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl index d178703..eb2d372 100755 --- a/build-aux/bracket-spacing.pl +++ b/build-aux/bracket-spacing.pl @@ -27,6 +27,11 @@ my $ret = 0; my $incomment = 0;
foreach my $file (@ARGV) { + # Per-file variables for multiline Curly Bracket (cb_) check + my $cb_linenum = 0; + my $cb_code = ""; + my $cb_scolon = 0; + open FILE, $file;
while (defined (my $line = <FILE>)) { @@ -153,6 +158,36 @@ foreach my $file (@ARGV) { print "$file:$.: $line"; $ret = 1; } + + # One line conditional statements with one line bodies should + # not use curly brackets. We also need to use $line instead $data as
as what?
+ if ($data =~ /^\s*(if|while|for)\b.*\{$/) { + $cb_linenum = $.; + $cb_code = $line; + $cb_scolon = 0; + } + + # We need to check for exactly one semicolon inside the body, + # because empty statements (e.g. with comment only) are + # allowed + if ($cb_linenum == $. - 1 && $data =~ /^[^;]*;[^;]*$/) { + $cb_code .= $line; + $cb_scolon = 1; + } + + if ($data =~ /^\s*}\s*$/ && + $cb_linenum == $. - 2 && + $cb_scolon) { +
[1] Perhaps maybe an additional print here indicating failure is because of single line condition no need for brackets
+ print "$file:$cb_linenum-$.:\n$cb_code$line"; + $ret = 1; + + # There _should_ be no need to reset the values; but to + # keep my inner piece... + $cb_linenum = 0; + $cb_scolon = 0; + $cb_code = ""; + }
[1]I have to say the error one gets if they violate this rule: maint.mk: incorrect whitespace, see HACKING for rules make: *** [bracket-spacing-check] Error 1 Is rather ambiguous - I was trying to find a way around the EDIT_NOT_CHANGED issue from 17/22 without changing the macro and when I saw the message it really didn't seem to convey the message that other checks seem to convey. This is not an incorrect whitespace - it's extraneous/unnecessary brackets (although I do understand the error comes from the file name - it's just odd to see). BTW: I *did* find a way around the check, although I know it's not a proper comment... - if (STREQ(doc, doc_edited)) + if (STREQ(doc, doc_edited)) { + // comment EDIT_NOT_CHANGED; + } John
} close FILE; }

On 11/13/2014 04:18 PM, John Ferlan wrote:
[1]I have to say the error one gets if they violate this rule:
maint.mk: incorrect whitespace, see HACKING for rules make: *** [bracket-spacing-check] Error 1
Maybe we should change the message in cfg.mk to state 'incorrect formatting' instead of the current 'incorrect whitespace', now that the script covers more than just whitespace formatting. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 11/13/2014 07:37 AM, Martin Kletzander wrote:
We're looking for three consecutive lines, first one is a if/for/while with a condition and start of body, second one is a body with one and only semicolon and third is end of the body by itself.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> ---
+ + # There _should_ be no need to reset the values; but to + # keep my inner piece...
s/piece/peace/ -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 11/13/2014 09:37 AM, Martin Kletzander wrote:
Brackets were removed by the following script in the root directory of libvirt's repository:
for i in $(git ls-files | grep '\.[ch]$'); do echo -n "$i ... "; emacs $i --batch --eval \ '(replace-regexp "^\\([[:space:]]*\\(if\\|for\\|while\\).*)\\)[[:space:]]*{\\(\n[^\n;]*;[^\n;]*\\)\n[[:space:]]*}$" "\\1\\3" nil (point-min) (point-max))' \ -f save-buffer &>/dev/null; echo done; done
v2: - Smaller patches, so there has to be none allowed through by moderators - Only curly brackets around one-line bodies with one-line preceding conditions removed - syntax-check! (with some other bracket-spacing.pl cleanups
ACK series in general - although something needs to be done about 17/22 and the comment in 22/22 probably needs an adjustment as well as a way hopefully to indicate what rule is being violated. I've scanned each of the changes looking for a similar MACRO issue - most #define macros are capitalized so it's fairly easy to spot (although the old eyes did get weary of looking at all the changes here). There are a few though (like testError()) that don't follow the upcase, so I'm not sure if I missed anything. It's too bad there isn't a way to find current existing usages where all that's on the between the { && } is a reserved word like goto, return, break, continue... Perhaps the VIR_ macros, auto incr/decr, etc. Then see what's left over in order to make sure we're not hitting any "hidden" macro type case. John
Martin Kletzander (22): virt-aa-helper: Trick invalid syntax-check Remove unnecessary curly brackets in daemon/ and examples/ Remove unnecessary curly brackets in src/esx/esx_driver.c Remove unnecessary curly brackets in rest of src/esx/ Remove unnecessary curly brackets in src/vmx/vmx.c Remove unnecessary curly brackets in src/conf/ Remove unnecessary curly brackets in src/hyperv/ Remove unnecessary curly brackets in src/node_device/ Remove unnecessary curly brackets in src/qemu/ Remove unnecessary curly brackets in src/storage/ Remove unnecessary curly brackets in src/test/test_driver.c Remove unnecessary curly brackets in src/util/ Remove unnecessary curly brackets in src/vbox/ Remove unnecessary curly brackets in rest of src/[a-n]*/ Remove unnecessary curly brackets in rest of src/[o-u]*/ Remove unnecessary curly brackets in rest of src/ Remove unnecessary curly brackets in tools/ Remove unnecessary curly brackets in tests/ docs: Adjust contributor guidelines about curly brackets bracket-spacing: Don't modify current line bracket-spacing: Remove pointless cycles bracket-spacing: Add syntax-check for unnecessary curly brackets
HACKING | 8 +- build-aux/bracket-spacing.pl | 74 ++++-- daemon/libvirtd.c | 15 +- daemon/remote.c | 12 +- docs/hacking.html.in | 4 +- examples/object-events/event-test.c | 3 +- examples/openauth/openauth.c | 9 +- src/access/viraccessdriverstack.c | 3 +- src/bhyve/bhyve_driver.c | 3 +- src/conf/capabilities.c | 3 +- src/conf/domain_conf.c | 135 ++++------- src/conf/interface_conf.c | 9 +- src/conf/network_conf.c | 51 ++-- src/conf/node_device_conf.c | 15 +- src/conf/nwfilter_conf.c | 12 +- src/conf/object_event.c | 6 +- src/conf/storage_conf.c | 24 +- src/datatypes.c | 6 +- src/driver.c | 3 +- src/esx/esx_device_monitor.c | 3 +- src/esx/esx_driver.c | 390 ++++++++++-------------------- src/esx/esx_interface_driver.c | 12 +- src/esx/esx_network_driver.c | 57 ++--- src/esx/esx_nwfilter_driver.c | 3 +- src/esx/esx_secret_driver.c | 3 +- src/esx/esx_storage_backend_iscsi.c | 45 ++-- src/esx/esx_storage_backend_vmfs.c | 51 ++-- src/esx/esx_storage_driver.c | 81 +++---- src/esx/esx_util.c | 45 ++-- src/esx/esx_vi.c | 249 +++++++------------ src/esx/esx_vi_types.c | 45 ++-- src/hyperv/hyperv_device_monitor.c | 3 +- src/hyperv/hyperv_driver.c | 87 +++---- src/hyperv/hyperv_interface_driver.c | 3 +- src/hyperv/hyperv_network_driver.c | 3 +- src/hyperv/hyperv_nwfilter_driver.c | 3 +- src/hyperv/hyperv_secret_driver.c | 3 +- src/hyperv/hyperv_storage_driver.c | 3 +- src/hyperv/hyperv_util.c | 6 +- src/hyperv/hyperv_wmi.c | 39 +-- src/interface/interface_backend_udev.c | 12 +- src/libvirt-lxc.c | 3 +- src/libvirt-nodedev.c | 3 +- src/libvirt-storage.c | 6 +- src/libxl/libxl_driver.c | 12 +- src/locking/lock_daemon.c | 3 +- src/locking/lock_driver_sanlock.c | 6 +- src/lxc/lxc_container.c | 9 +- src/lxc/lxc_driver.c | 9 +- src/lxc/lxc_process.c | 6 +- src/network/bridge_driver.c | 6 +- src/network/bridge_driver_linux.c | 3 +- src/node_device/node_device_driver.c | 21 +- src/node_device/node_device_hal.c | 6 +- src/node_device/node_device_udev.c | 87 +++---- src/nwfilter/nwfilter_dhcpsnoop.c | 3 +- src/nwfilter/nwfilter_ebiptables_driver.c | 12 +- src/nwfilter/nwfilter_gentech_driver.c | 9 +- src/nwfilter/nwfilter_learnipaddr.c | 3 +- src/openvz/openvz_conf.c | 3 +- src/openvz/openvz_driver.c | 27 +-- src/phyp/phyp_driver.c | 21 +- src/qemu/qemu_agent.c | 3 +- src/qemu/qemu_capabilities.c | 9 +- src/qemu/qemu_cgroup.c | 6 +- src/qemu/qemu_command.c | 6 +- src/qemu/qemu_conf.c | 3 +- src/qemu/qemu_domain.c | 3 +- src/qemu/qemu_driver.c | 45 ++-- src/qemu/qemu_hotplug.c | 6 +- src/qemu/qemu_migration.c | 3 +- src/qemu/qemu_monitor_json.c | 12 +- src/qemu/qemu_monitor_text.c | 6 +- src/qemu/qemu_process.c | 18 +- src/remote/remote_driver.c | 3 +- src/rpc/virnetclient.c | 9 +- src/rpc/virnetserver.c | 3 +- src/rpc/virnetserverclient.c | 3 +- src/rpc/virnetserverservice.c | 3 +- src/security/security_manager.c | 3 +- src/security/virt-aa-helper.c | 9 +- src/storage/parthelper.c | 3 +- src/storage/storage_backend.c | 9 +- src/storage/storage_backend_disk.c | 15 +- src/storage/storage_backend_fs.c | 6 +- src/storage/storage_backend_mpath.c | 27 +-- src/storage/storage_backend_rbd.c | 30 +-- src/storage/storage_backend_scsi.c | 6 +- src/storage/storage_driver.c | 9 +- src/test/test_driver.c | 57 ++--- src/uml/uml_conf.c | 6 +- src/uml/uml_driver.c | 9 +- src/util/virauth.c | 12 +- src/util/virbitmap.c | 6 +- src/util/virbuffer.c | 3 +- src/util/vircommand.c | 9 +- src/util/virconf.c | 15 +- src/util/virdbus.c | 3 +- src/util/virdnsmasq.c | 3 +- src/util/vireventpoll.c | 9 +- src/util/virfile.c | 6 +- src/util/virfirewall.c | 6 +- src/util/viriscsi.c | 9 +- src/util/virlockspace.c | 6 +- src/util/virlog.c | 3 +- src/util/virnetdev.c | 6 +- src/util/virnetdevbridge.c | 3 +- src/util/virnetdevmacvlan.c | 9 +- src/util/virnetdevtap.c | 6 +- src/util/virpci.c | 15 +- src/util/virsexpr.c | 24 +- src/util/virstorageencryption.c | 3 +- src/util/virstoragefile.c | 6 +- src/util/virsysinfo.c | 3 +- src/util/virthreadpool.c | 3 +- src/util/virutil.c | 9 +- src/util/virxml.c | 18 +- src/vbox/vbox_MSCOMGlue.c | 30 +-- src/vbox/vbox_XPCOMCGlue.c | 33 +-- src/vbox/vbox_common.c | 51 ++-- src/vbox/vbox_network.c | 15 +- src/vbox/vbox_snapshot_conf.c | 21 +- src/vbox/vbox_storage.c | 30 +-- src/vbox/vbox_tmpl.c | 30 +-- src/vmware/vmware_conf.c | 3 +- src/vmware/vmware_driver.c | 6 +- src/vmx/vmx.c | 243 +++++++------------ src/xen/block_stats.c | 3 +- src/xen/xen_driver.c | 6 +- src/xen/xen_hypervisor.c | 6 +- src/xen/xend_internal.c | 18 +- src/xen/xm_internal.c | 6 +- src/xenapi/xenapi_driver.c | 12 +- src/xenapi/xenapi_utils.c | 9 +- src/xenconfig/xen_common.c | 6 +- src/xenconfig/xen_sxpr.c | 6 +- tests/commandhelper.c | 3 +- tests/esxutilstest.c | 12 +- tests/eventtest.c | 3 +- tests/openvzutilstest.c | 6 +- tests/securityselinuxlabeltest.c | 6 +- tests/shunloadtest.c | 6 +- tests/utiltest.c | 3 +- tests/virbuftest.c | 3 +- tests/virhashtest.c | 30 +-- tests/virtimetest.c | 3 +- tests/vmx2xmltest.c | 12 +- tests/xml2vmxtest.c | 27 +-- tools/virsh-console.c | 6 +- tools/virsh-domain.c | 27 +-- tools/virsh-edit.c | 6 +- tools/virsh-host.c | 3 +- tools/virsh-pool.c | 6 +- tools/virsh-volume.c | 12 +- tools/virsh.c | 18 +- tools/wireshark/src/packet-libvirt.c | 6 +- 156 files changed, 1050 insertions(+), 2006 deletions(-)
-- 2.1.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 11/13/2014 04:52 PM, John Ferlan wrote:
On 11/13/2014 09:37 AM, Martin Kletzander wrote:
Brackets were removed by the following script in the root directory of libvirt's repository:
for i in $(git ls-files | grep '\.[ch]$'); do echo -n "$i ... "; emacs $i --batch --eval \ '(replace-regexp "^\\([[:space:]]*\\(if\\|for\\|while\\).*)\\)[[:space:]]*{\\(\n[^\n;]*;[^\n;]*\\)\n[[:space:]]*}$" "\\1\\3" nil (point-min) (point-max))' \ -f save-buffer &>/dev/null; echo done; done
v2: - Smaller patches, so there has to be none allowed through by moderators - Only curly brackets around one-line bodies with one-line preceding conditions removed - syntax-check! (with some other bracket-spacing.pl cleanups
ACK series in general - although something needs to be done about 17/22 and the comment in 22/22 probably needs an adjustment as well as a way hopefully to indicate what rule is being violated.
I have not closely reviewed the series, and the perl in patch 22/22 is complex enough that I don't feel I have enough time to do it justice in a quick review today. I'll trust John's review - he did have a good point about multiline macro bodies needing do {} while (0) guards - maybe we add yet another syntax check for that? I'm guessing you wrote the series by applying patch 22 first, then fixing in pieces until things work; so if 22 is good and syntax-check passes, then all the other patches prove we silenced the syntax problems (but not necessarily that the transformations to silence the problems were correct, as was the case with macros in tools/). At any rate, this series will be a conflict magnet to other pending patches, so if we're going to take it, I don't want to hold it up for a long time. The fact that you have a syntax-check to enforce things is a huge improvement over the v1 proposal. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Nov 13, 2014 at 05:09:04PM -0700, Eric Blake wrote:
On 11/13/2014 04:52 PM, John Ferlan wrote:
On 11/13/2014 09:37 AM, Martin Kletzander wrote:
Brackets were removed by the following script in the root directory of libvirt's repository:
for i in $(git ls-files | grep '\.[ch]$'); do echo -n "$i ... "; emacs $i --batch --eval \ '(replace-regexp "^\\([[:space:]]*\\(if\\|for\\|while\\).*)\\)[[:space:]]*{\\(\n[^\n;]*;[^\n;]*\\)\n[[:space:]]*}$" "\\1\\3" nil (point-min) (point-max))' \ -f save-buffer &>/dev/null; echo done; done
v2: - Smaller patches, so there has to be none allowed through by moderators - Only curly brackets around one-line bodies with one-line preceding conditions removed - syntax-check! (with some other bracket-spacing.pl cleanups
ACK series in general - although something needs to be done about 17/22 and the comment in 22/22 probably needs an adjustment as well as a way hopefully to indicate what rule is being violated.
I have not closely reviewed the series, and the perl in patch 22/22 is complex enough that I don't feel I have enough time to do it justice in a quick review today. I'll trust John's review - he did have a good point about multiline macro bodies needing do {} while (0) guards - maybe we add yet another syntax check for that? I'm guessing you wrote
I wouldn't believe we have multi-line macros without its own body. Anyway, I fixed that. I started working on the syntax-check for multiline macros without do-while block, but it's going to be a bit painful.
the series by applying patch 22 first, then fixing in pieces until things work; so if 22 is good and syntax-check passes, then all the other patches prove we silenced the syntax problems (but not necessarily that the transformations to silence the problems were correct, as was the case with macros in tools/).
Actually, no. I had few variations of that syntax-check, but the only thing I was pretty sure about was that (regexp-replace) I did. Then it was just a matter of splitting it into small enough chunks so it doesn't have to be allowed to list by moderator and so it makes sense.
At any rate, this series will be a conflict magnet to other pending patches, so if we're going to take it, I don't want to hold it up for a long time. The fact that you have a syntax-check to enforce things is a huge improvement over the v1 proposal.
I fixed everything and after discussion with John pushed the fixed versions, thank you for spotting all the details. Martin
participants (3)
-
Eric Blake
-
John Ferlan
-
Martin Kletzander