Skip to contentSkip to conversation

master - tidy: prefer not using else after return

PATCH Zdenek Kabelac 1 participant 1 message Jul 20, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0bf836aa14f98eb83969a6e81695a024f56a5eb5
Commit:        0bf836aa14f98eb83969a6e81695a024f56a5eb5
Parent:        0d0a3397c22b9d5342584299acd814f6c8221c18
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Wed Jul 19 16:16:12 2017 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Thu Jul 20 11:18:29 2017 +0200

tidy: prefer not using else after return

clang-tidy: avoid using 'else' after return - give more readable code, and also saves indention level.

---
 daemons/dmeventd/dmeventd.c           |    3 +-
 daemons/dmeventd/libdevmapper-event.c |   17 +++++-----
 lib/activate/activate.c               |   12 +++++--
 lib/activate/dev_manager.c            |    9 +++--
 lib/activate/fs.c                     |   20 ++++++-----
 lib/cache/lvmetad.c                   |   13 ++++---
 lib/config/config.c                   |    3 +-
 lib/device/dev-cache.c                |   10 +++---
 lib/device/dev-io.c                   |    4 +-
 lib/device/dev-type.c                 |   24 +++++++-------
 lib/filters/filter-sysfs.c            |    5 ++-
 lib/format_text/format-text.c         |   21 ++++++------
 lib/locking/cluster_locking.c         |    9 +++--
 lib/locking/locking.c                 |   10 +++--
 lib/locking/lvmlockd.c                |   43 +++++++++++++------------
 lib/metadata/lv.c                     |   40 +++++++++++------------
 lib/metadata/lv_manip.c               |   42 ++++++++++++++----------
 lib/metadata/metadata.c               |   14 +++++---
 lib/metadata/mirror.c                 |   12 +++++--
 lib/metadata/pv_manip.c               |    9 +++--
 lib/metadata/raid_manip.c             |   48 +++++++++++++++++++---------
 lib/replicator/replicator.c           |    4 ++-
 lib/report/report.c                   |   56 +++++++++++++++++---------------
 libdm/ioctl/libdm-iface.c             |   19 ++++++-----
 libdm/libdm-common.c                  |   13 +++----
 libdm/libdm-report.c                  |   10 +++--
 tools/dmsetup.c                       |    7 ++--
 tools/lvconvert.c                     |   17 ++++++----
 tools/lvcreate.c                      |    4 ++-
 tools/polldaemon.c                    |   33 ++++++++++---------
 tools/toollib.c                       |   14 +++++---
 tools/vgdisplay.c                     |   17 ++++++----
 32 files changed, 318 insertions(+), 244 deletions(-)
daemons/dmeventd/dmeventd.c +2 -1
index a2883a1..3a92ab6 100644
@@ -2252,7 +2252,8 @@ int main(int argc, char *argv[])
 					 "for %ld second(s), exiting.",
 					 (long) (time(NULL) - _idle_since));
 				break;
-			} else if (idle_exit_timeout) {
+			}
+			if (idle_exit_timeout) {
 				now = time(NULL);
 				if (now < _idle_since)
 					_idle_since = now; /* clock change? */
daemons/dmeventd/libdevmapper-event.c +8 -9
index b23b6c1..210e384 100644
@@ -250,10 +250,9 @@ static int _daemon_read(struct dm_event_fifos *fifos,
 		if (ret < 0) {
 			if ((errno == EINTR) || (errno == EAGAIN))
 				continue;
-			else {
-				log_error("Unable to read from event server.");
-				return 0;
-			}
+
+			log_error("Unable to read from event server.");
+			return 0;
 		}
 
 		bytes += ret;
@@ -329,10 +328,9 @@ static int _daemon_write(struct dm_event_fifos *fifos,
 		if (ret < 0) {
 			if ((errno == EINTR) || (errno == EAGAIN))
 				continue;
-			else {
-				log_error("Unable to talk to event daemon.");
-				return 0;
-			}
+
+			log_error("Unable to talk to event daemon.");
+			return 0;
 		}
 
 		bytes += ret;
@@ -454,7 +452,8 @@ static int _start_daemon(char *dmeventd_path, struct dm_event_fifos *fifos)
 		if (close(fifos->client))
 			log_sys_debug("close", fifos->client_path);
 		return 1;
-	} else if (errno != ENXIO && errno != ENOENT)  {
+	}
+	if (errno != ENXIO && errno != ENOENT)  {
 		/* problem */
 		log_sys_error("open", fifos->client_path);
 		return 0;
lib/activate/activate.c +9 -3
index d73e8b1..1bbd1b5 100644
@@ -797,14 +797,18 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
 				status->info.exists = 0; /* So pool LV is not active */
 		}
 		return 1;
-	} else if (lv_is_external_origin(lv)) {
+	}
+
+	if (lv_is_external_origin(lv)) {
 		if (!_lv_info(cmd, lv, 0, &status->info, NULL, NULL,
 			      with_open_count, with_read_ahead))
 			return_0;
 
 		(void) _lv_info(cmd, lv, 1, NULL, lv_seg, &status->seg_status, 0, 0);
 		return 1;
-	} else if (lv_is_origin(lv)) {
+	}
+
+	if (lv_is_origin(lv)) {
 		/* Query segment status for 'layered' (-real) device most of the time,
 		 * only for merging snapshot, query its progress.
 		 * TODO: single LV may need couple status to be exposed at once....
@@ -821,7 +825,9 @@ int lv_info_with_seg_status(struct cmd_context *cmd,
 			/* Grab STATUS from layered -real */
 			(void) _lv_info(cmd, lv, 1, NULL, lv_seg, &status->seg_status, 0, 0);
 		return 1;
-	} else if (lv_is_cow(lv)) {
+	}
+
+	if (lv_is_cow(lv)) {
 		if (lv_is_merging_cow(lv)) {
 			olv = origin_from_cow(lv);
 
lib/activate/dev_manager.c +5 -4
index daddfc8..8d96259 100644
@@ -1056,10 +1056,11 @@ static int _percent(struct dev_manager *dm, const char *name, const char *dlid,
 		if (_percent_run(dm, NULL, dlid, target_type, wait, lv, percent,
 				 event_nr, fail_if_percent_unsupported))
 			return 1;
-		else if (_original_uuid_format_check_required(dm->cmd) &&
-			 _percent_run(dm, NULL, dlid + sizeof(UUID_PREFIX) - 1,
-				      target_type, wait, lv, percent,
-				      event_nr, fail_if_percent_unsupported))
+
+		if (_original_uuid_format_check_required(dm->cmd) &&
+		    _percent_run(dm, NULL, dlid + sizeof(UUID_PREFIX) - 1,
+				 target_type, wait, lv, percent,
+				 event_nr, fail_if_percent_unsupported))
 			return 1;
 	}
 
lib/activate/fs.c +11 -9
index 2f455ba..a0b8bff 100644
@@ -186,11 +186,11 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
 			    !stat(lv_path, &buf)) {
 				if (buf_lp.st_rdev == buf.st_rdev)
 					return 1;
-				else
-					log_warn("Symlink %s that should have been "
-						 "created by udev does not have "
-						 "correct target. Falling back to "
-						 "direct link creation", lv_path);
+
+				log_warn("Symlink %s that should have been "
+					 "created by udev does not have "
+					 "correct target. Falling back to "
+					 "direct link creation", lv_path);
 			} else
 				log_warn("Symlink %s that should have been "
 					 "created by udev could not be checked "
@@ -239,7 +239,9 @@ static int _rm_link(const char *dev_dir, const char *vg_name,
 			return 1;
 		log_sys_error("lstat", lv_path);
 		return 0;
-	} else if (dm_udev_get_sync_support() && udev_checking() && check_udev)
+	}
+
+	if (dm_udev_get_sync_support() && udev_checking() && check_udev)
 		log_warn("The link %s should have been removed by udev "
 			 "but it is still present. Falling back to "
 			 "direct link removal.", lv_path);
@@ -478,9 +480,9 @@ int fs_rename_lv(const struct logical_volume *lv, const char *dev,
 			 _fs_op(FS_ADD, lv->vg->cmd->dev_dir, lv->vg->name,
 				lv->name, dev, "", lv->vg->cmd->current_settings.udev_rules));
 	}
-	else 
-		return _fs_op(FS_RENAME, lv->vg->cmd->dev_dir, lv->vg->name, lv->name,
-			      dev, old_lvname, lv->vg->cmd->current_settings.udev_rules);
+
+	return _fs_op(FS_RENAME, lv->vg->cmd->dev_dir, lv->vg->name, lv->name,
+		      dev, old_lvname, lv->vg->cmd->current_settings.udev_rules);
 }
 
 void fs_unlock(void)
lib/cache/lvmetad.c +7 -6
index 5490675..2e0ee51 100644
@@ -145,13 +145,14 @@ int lvmetad_connect(struct cmd_context *cmd)
 		_lvmetad_use = 1;
 		_lvmetad_cmd = cmd;
 		return 1;
-	} else {
-		log_debug_lvmetad("Failed to connect to lvmetad: %s", strerror(_lvmetad.error));
-		_lvmetad_connected = 0;
-		_lvmetad_use = 0;
-		_lvmetad_cmd = NULL;
-		return 0;
 	}
+
+	log_debug_lvmetad("Failed to connect to lvmetad: %s", strerror(_lvmetad.error));
+	_lvmetad_connected = 0;
+	_lvmetad_use = 0;
+	_lvmetad_cmd = NULL;
+
+	return 0;
 }
 
 int lvmetad_used(void)
lib/config/config.c +2 -1
index daf5fa3..04dded7 100644
@@ -481,7 +481,8 @@ int override_config_tree_from_profile(struct cmd_context *cmd,
 
 	if (profile->source == CONFIG_PROFILE_COMMAND)
 		return _override_config_tree_from_command_profile(cmd, profile);
-	else if (profile->source == CONFIG_PROFILE_METADATA)
+
+	if (profile->source == CONFIG_PROFILE_METADATA)
 		return _override_config_tree_from_metadata_profile(cmd, profile);
 
 	log_error(INTERNAL_ERROR "override_config_tree_from_profile: incorrect profile source type");
lib/device/dev-cache.c +5 -5
index 9a4dbc9..7802e45 100644
@@ -320,8 +320,8 @@ static int _compare_paths(const char *path0, const char *path1)
 	/* ASCII comparison */
 	if (strcmp(path0, path1) < 0)
 		return 0;
-	else
-		return 1;
+
+	return 1;
 }
 
 static int _add_alias(struct device *dev, const char *path)
@@ -898,10 +898,10 @@ int dev_cache_index_devs(void)
 			if (errno == ENOENT) {
 				sysfs_has_dev_block = 0;
 				return 1;
-			} else {
-				log_sys_error("stat", path);
-				return 0;
 			}
+
+			log_sys_error("stat", path);
+			return 0;
 		}
 	} else if (!sysfs_has_dev_block)
 		return 1;
lib/device/dev-io.c +2 -2
index a9a2374..519b5c7 100644
@@ -405,8 +405,8 @@ int dev_get_size(struct device *dev, uint64_t *size)
 
 	if ((dev->flags & DEV_REGULAR))
 		return _dev_get_size_file(dev, size);
-	else
-		return _dev_get_size_dev(dev, size);
+
+	return _dev_get_size_dev(dev, size);
 }
 
 int dev_get_read_ahead(struct device *dev, uint32_t *read_ahead)
lib/device/dev-type.c +12 -12
index 325b66b..aa22e3b 100644
@@ -615,38 +615,38 @@ static int _blkid_wipe(blkid_probe probe, struct device *dev, const char *name,
 			if (force < DONT_PROMPT) {
 				log_error(MSG_FAILED_SIG_OFFSET, type, name);
 				return 0;
-			} else {
-				log_error("WARNING: " MSG_FAILED_SIG_OFFSET MSG_WIPING_SKIPPED, type, name);
-				return 2;
 			}
+
+			log_error("WARNING: " MSG_FAILED_SIG_OFFSET MSG_WIPING_SKIPPED, type, name);
+			return 2;
 		}
 		if (blkid_probe_lookup_value(probe, "SBMAGIC", &magic, &len)) {
 			if (force < DONT_PROMPT) {
 				log_error(MSG_FAILED_SIG_LENGTH, type, name);
 				return 0;
-			} else {
-				log_warn("WARNING: " MSG_FAILED_SIG_LENGTH MSG_WIPING_SKIPPED, type, name);
-				return 2;
 			}
+
+			log_warn("WARNING: " MSG_FAILED_SIG_LENGTH MSG_WIPING_SKIPPED, type, name);
+			return 2;
 		}
 	} else if (!blkid_probe_lookup_value(probe, "PTTYPE", &type, NULL)) {
 		if (blkid_probe_lookup_value(probe, "PTMAGIC_OFFSET", &offset, NULL)) {
 			if (force < DONT_PROMPT) {
 				log_error(MSG_FAILED_SIG_OFFSET, type, name);
 				return 0;
-			} else {
-				log_warn("WARNING: " MSG_FAILED_SIG_OFFSET MSG_WIPING_SKIPPED, type, name);
-				return 2;
 			}
+
+			log_warn("WARNING: " MSG_FAILED_SIG_OFFSET MSG_WIPING_SKIPPED, type, name);
+			return 2;
 		}
 		if (blkid_probe_lookup_value(probe, "PTMAGIC", &magic, &len)) {
 			if (force < DONT_PROMPT) {
 				log_error(MSG_FAILED_SIG_LENGTH, type, name);
 				return 0;
-			} else {
-				log_warn("WARNING: " MSG_FAILED_SIG_LENGTH MSG_WIPING_SKIPPED, type, name);
-				return 2;
 			}
+
+			log_warn("WARNING: " MSG_FAILED_SIG_LENGTH MSG_WIPING_SKIPPED, type, name);
+			return 2;
 		}
 		usage = "partition table";
 	} else
lib/filters/filter-sysfs.c +3 -2
index 6dacd5d..93862e6 100644
@@ -274,8 +274,9 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
 	if (!_set_lookup(ds, dev->dev)) {
 		log_debug_devs("%s: Skipping (sysfs)", dev_name(dev));
 		return 0;
-	} else
-		return 1;
+	}
+
+	return 1;
 }
 
 static void _destroy(struct dev_filter *f)
lib/format_text/format-text.c +11 -10
index bf8cd02..91f8816 100644
@@ -152,8 +152,8 @@ static uint64_t _get_prev_sector_circular(uint64_t region_start,
 {
 	if (region_ptr >= region_start + SECTOR_SIZE)
 		return region_ptr - SECTOR_SIZE;
-	else
-		return (region_start + region_size - SECTOR_SIZE);
+
+	return (region_start + region_size - SECTOR_SIZE);
 }
 
 /*
@@ -447,9 +447,9 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
 	if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) &&
 	    (isspace(vgnamebuf[len]) || vgnamebuf[len] == '{'))
 		return rlocn;
-	else
-		log_debug_metadata("Volume group name found in metadata does "
-				   "not match expected name %s.", vgname);
+
+	log_debug_metadata("Volume group name found in metadata does "
+			   "not match expected name %s.", vgname);
 
       bad:
 	if ((info = lvmcache_info_from_pvid(dev_area->dev->pvid, dev_area->dev, 0)) &&
@@ -893,8 +893,9 @@ static struct volume_group *_vg_read_file_name(struct format_instance *fid,
 		log_error("'%s' does not contain volume group '%s'.",
 			  read_path, vgname);
 		return NULL;
-	} else
-		log_debug_metadata("Read volume group %s from %s", vg->name, read_path);
+	}
+
+	log_debug_metadata("Read volume group %s from %s", vg->name, read_path);
 
 	return vg;
 }
@@ -1634,10 +1635,10 @@ static int _text_pv_initialise(const struct format_type *fmt,
 				log_error("%s: Bootloader area would overlap "
 					  "data area.", pv_dev_name(pv));
 				return 0;
-			} else {
-				pv->ba_start = pva->ba_start ? : final_alignment;
-				pv->ba_size = pva->ba_size;
 			}
+
+			pv->ba_start = pva->ba_start ? : final_alignment;
+			pv->ba_size = pva->ba_size;
 		}
 	}
 
lib/locking/cluster_locking.c +6 -3
index b031833..a04d9c7 100644
@@ -519,11 +519,14 @@ static int decode_lock_type(const char *response)
 {
 	if (!response)
 		return LCK_NULL;
-	else if (!strcmp(response, "EX"))
+
+	if (!strcmp(response, "EX"))
 		return LCK_EXCL;
-	else if (!strcmp(response, "CR"))
+
+	if (!strcmp(response, "CR"))
 		return LCK_READ;
-	else if (!strcmp(response, "PR"))
+
+	if (!strcmp(response, "PR"))
 		return LCK_PREAD;
 
 	return_0;
lib/locking/locking.c +6 -4
index afc001a..2886fc4 100644
@@ -187,9 +187,9 @@ int init_locking(int type, struct cmd_context *cmd, int suppress_messages)
 				  "be inaccessible.");
 		if (init_file_locking(&_locking, cmd, suppress_messages))
 			return 1;
-		else
-			log_error_suppress(suppress_messages,
-					   "File-based locking initialisation failed.");
+
+		log_error_suppress(suppress_messages,
+				   "File-based locking initialisation failed.");
 	}
 
 	if (!ignorelockingfailure())
@@ -232,7 +232,9 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname)
 		log_error("%s exists: Is the original LVM driver using "
 			  "this volume group?", path);
 		return 0;
-	} else if (errno != ENOENT && errno != ENOTDIR) {
+	}
+
+	if (errno != ENOENT && errno != ENOTDIR) {
 		log_sys_error("stat", path);
 		return 0;
 	}
lib/locking/lvmlockd.c +23 -20

90 lines not on this page · raw message

lib/metadata/lv.c +19 -21
index c87bb6b..e3815c9 100644
@@ -581,8 +581,8 @@ static char *_do_lv_origin_dup(struct dm_pool *mem, const struct logical_volume
 
 	if (uuid)
 		return lv_uuid_dup(mem, origin_lv);
-	else
-		return lv_name_dup(mem, origin_lv);
+
+	return lv_name_dup(mem, origin_lv);
 }
 
 char *lv_origin_dup(struct dm_pool *mem, const struct logical_volume *lv)
@@ -650,6 +650,7 @@ char *lv_modules_dup(struct dm_pool *mem, const struct logical_volume *lv)
 
 	if (!list_lv_modules(mem, lv, modules))
 		return_NULL;
+
 	return tags_format_and_copy(mem, modules);
 }
 
@@ -675,8 +676,8 @@ static char *_do_lv_mirror_log_dup(struct dm_pool *mem, const struct logical_vol
 
 	if (uuid)
 		return lv_uuid_dup(mem, mirror_log_lv);
-	else
-		return lv_name_dup(mem, mirror_log_lv);
+
+	return lv_name_dup(mem, mirror_log_lv);
 }
 
 char *lv_mirror_log_dup(struct dm_pool *mem, const struct logical_volume *lv)
@@ -708,8 +709,8 @@ static char *_do_lv_pool_lv_dup(struct dm_pool *mem, const struct logical_volume
 
 	if (uuid)
 		return lv_uuid_dup(mem, pool_lv);
-	else
-		return lv_name_dup(mem, pool_lv);
+
+	return lv_name_dup(mem, pool_lv);
 }
 
 char *lv_pool_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
@@ -741,8 +742,8 @@ static char *_do_lv_data_lv_dup(struct dm_pool *mem, const struct logical_volume
 
 	if (uuid)
 		return lv_uuid_dup(mem, data_lv);
-	else
-		return lv_name_dup(mem, data_lv);
+
+	return lv_name_dup(mem, data_lv);
 }
 
 char *lv_data_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
@@ -774,8 +775,8 @@ static char *_do_lv_metadata_lv_dup(struct dm_pool *mem, const struct logical_vo
 
 	if (uuid)
 		return lv_uuid_dup(mem, metadata_lv);
-	else
-		return lv_name_dup(mem, metadata_lv);
+
+	return lv_name_dup(mem, metadata_lv);
 }
 
 char *lv_metadata_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
@@ -792,7 +793,8 @@ const char *lv_layer(const struct logical_volume *lv)
 {
 	if (lv_is_thin_pool(lv))
 		return "tpool";
-	else if (lv_is_origin(lv) || lv_is_external_origin(lv))
+
+	if (lv_is_origin(lv) || lv_is_external_origin(lv))
 		return "real";
 
 	return NULL;
@@ -841,8 +843,8 @@ static char *_do_lv_convert_lv_dup(struct dm_pool *mem, const struct logical_vol
 
 	if (uuid)
 		return lv_uuid_dup(mem, convert_lv);
-	else
-		return lv_name_dup(mem, convert_lv);
+
+	return lv_name_dup(mem, convert_lv);
 }
 
 char *lv_convert_lv_dup(struct dm_pool *mem, const struct logical_volume *lv)
@@ -877,8 +879,8 @@ static char *_do_lv_move_pv_dup(struct dm_pool *mem, const struct logical_volume
 
 			if (uuid)
 				return pv_uuid_dup(mem, pvseg->pv);
-			else
-				return pv_name_dup(mem, pvseg->pv);
+
+			return pv_name_dup(mem, pvseg->pv);
 		}
 	}
 
@@ -1104,12 +1106,8 @@ int lv_raid_healthy(const struct logical_volume *lv)
 	if (!lv_raid_dev_health(raid_seg->lv, &raid_health))
 		return_0;
 
-	if (lv_is_raid(lv)) {
-		if (strchr(raid_health, 'D'))
-			return 0;
-		else
-			return 1;
-	}
+	if (lv_is_raid(lv))
+		return (strchr(raid_health, 'D')) ? 0 : 1;
 
 	/* Find out which sub-LV this is. */
 	for (s = 0; s < raid_seg->area_count; s++)
lib/metadata/lv_manip.c +25 -17

91 lines not on this page · raw message

lib/metadata/metadata.c +9 -5
index 45495dc..d8f993c 100644
@@ -198,7 +198,9 @@ static int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
 		log_error("Physical volume '%s' is already in volume group "
 			  "'%s'", pv_name, pv->vg_name);
 		return 0;
-	} else if (!new_pv) {
+	}
+
+	if (!new_pv) {
 		if ((used = is_used_pv(pv)) < 0)
 			return_0;
 
@@ -730,7 +732,9 @@ static int vg_extend_single_pv(struct volume_group *vg, char *pv_name,
 		log_error("%s not identified as an existing "
 			  "physical volume", pv_name);
 		return 0;
-	} else if (!pv && pp) {
+	}
+
+	if (!pv && pp) {
 		if (!(pv = pvcreate_vol(vg->cmd, pv_name, pp, 0)))
 			return_0;
 		new_pv = 1;
@@ -5725,10 +5729,10 @@ static int _access_vg_lock_type(struct cmd_context *cmd, struct volume_group *vg
 			log_error("Cannot access VG %s due to failed lock.", vg->name);
 			*failure |= FAILED_LOCK_MODE;
 			return 0;
-		} else {
-			log_warn("Reading VG %s without a lock.", vg->name);
-			return 1;
 		}
+
+		log_warn("Reading VG %s without a lock.", vg->name);
+		return 1;
 	}
 
 	if (test_mode()) {
lib/metadata/mirror.c +8 -4
index 52e1488..7496ddc 100644
@@ -1532,8 +1532,8 @@ const char *get_pvmove_pvname_from_lv(const struct logical_volume *lv)
 
 	if (pvmove_lv)
 		return get_pvmove_pvname_from_lv_mirr(pvmove_lv);
-	else
-		return NULL;
+
+	return NULL;
 }
 
 struct logical_volume *find_pvmove_lv(struct volume_group *vg,
@@ -2170,7 +2170,9 @@ int lv_add_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
 		return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEG,
 							   mirrors, region_size,
 							   pvs, alloc);
-	} else if (flags & MIRROR_BY_SEGMENTED_LV) {
+	}
+
+	if (flags & MIRROR_BY_SEGMENTED_LV) {
 		if (stripes > 1) {
 			log_error("Striped-mirroring is not supported on "
 				  "segment-by-segment mirroring.");
@@ -2180,7 +2182,9 @@ int lv_add_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
 		return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEGMENTED_LV,
 							   mirrors, region_size,
 							   pvs, alloc);
-	} else if (flags & MIRROR_BY_LV) {
+	}
+
+	if (flags & MIRROR_BY_LV) {
 		if (!mirrors)
 			return add_mirror_log(cmd, lv, log_count,
 					      region_size, pvs, alloc);
lib/metadata/pv_manip.c +5 -4
index a8cd763..de6644e 100644
@@ -358,10 +358,11 @@ static uint32_t _overlap_pe(const struct pv_segment *pvseg,
 
 	start = max(pvseg->pe, per->start);
 	end = min(pvseg->pe + pvseg->len, per->start + per->count);
+
 	if (end < start)
 		return 0;
-	else
-		return end - start;
+
+	return end - start;
 }
 
 /*
@@ -608,8 +609,8 @@ static int pv_resize(struct physical_volume *pv,
 
 		if (new_pe_count > old_pe_count)
 			return _extend_pv(pv, vg, old_pe_count, new_pe_count);
-		else
-			return _reduce_pv(pv, vg, old_pe_count, new_pe_count);
+
+		return _reduce_pv(pv, vg, old_pe_count, new_pe_count);
 	}
 
 	return 1;
lib/metadata/raid_manip.c +32 -16

118 lines not on this page · raw message

lib/replicator/replicator.c +3 -1
index aaf2296..8f43f8b 100644
@@ -627,7 +627,9 @@ static int _replicator_dev_add_target_line(struct dev_manager *dm,
 		if (!(rdev_dlid = build_dm_uuid(mem, seg->lv->rdevice->lv, NULL)))
 			return_0;
 		return dm_tree_node_add_target_area(node, NULL, rdev_dlid, 0);
-	} else if (seg->lv->rdevice->rsite->site_index) {
+	}
+
+	if (seg->lv->rdevice->rsite->site_index) {
 		log_error("Active site with site_index != 0 (%s, %d)",
 			  seg->lv->rdevice->rsite->name,
 			  seg->lv->rdevice->rsite->site_index);
lib/report/report.c +30 -26

140 lines not on this page · raw message

libdm/ioctl/libdm-iface.c +11 -8
index 65e75f6..c47e084 100644
@@ -208,8 +208,9 @@ static int _get_proc_number(const char *file, const char *name,
 		if (require_module_loaded) {
 			log_error("%s: No entry for %s found", file, name);
 			return 0;
-		} else
-			return 2;
+		}
+
+		return 2;
 	}
 
 	return 1;
@@ -368,11 +369,11 @@ int dm_is_dm_major(uint32_t major)
 			return 0;
 		return dm_bit(_dm_bitset, major) ? 1 : 0;
 	}
-	else {
-		if (!_dm_device_major)
-			return 0;
-		return (major == _dm_device_major) ? 1 : 0;
-	}
+
+	if (!_dm_device_major)
+		return 0;
+
+	return (major == _dm_device_major) ? 1 : 0;
 }
 
 static void _close_control_fd(void)
@@ -1704,7 +1705,9 @@ static int _do_dm_ioctl_unmangle_string(char *str, const char *str_name,
 		log_debug_activation("_do_dm_ioctl_unmangle_string: failed to "
 				     "unmangle %s \"%s\"", str_name, str);
 		return 0;
-	} else if (r)
+	}
+
+	if (r)
 		memcpy(str, buf, strlen(buf) + 1);
 
 	return 1;
libdm/libdm-common.c +6 -7
index d8cf946..e983b03 100644
@@ -1137,13 +1137,12 @@ static int _rename_dev_node(const char *old_name, const char *new_name,
 				 errno == ENOENT)
 				/* assume udev already deleted this */
 				return 1;
-			else {
-				log_warn("The node %s should have been renamed to %s "
-					 "by udev but old node is still present. "
-					 "Falling back to direct old node removal.",
-					 oldpath, newpath);
-				return _rm_dev_node(old_name, 0);
-			}
+
+			log_warn("The node %s should have been renamed to %s "
+				 "by udev but old node is still present. "
+				 "Falling back to direct old node removal.",
+				 oldpath, newpath);
+			return _rm_dev_node(old_name, 0);
 		}
 
 		if (unlink(newpath) < 0) {
libdm/libdm-report.c +6 -4
index a5100d4..d2371db 100644
@@ -1013,16 +1013,18 @@ static int _field_match(struct dm_report *rh, const char *field, size_t flen,
 			rh->report_types |= implicit ? _implicit_report_fields[f].type
 						     : rh->fields[f].type;
 			return 1;
-		} else
-			return _add_field(rh, f, implicit, 0) ? 1 : 0;
+		}
+
+		return _add_field(rh, f, implicit, 0) ? 1 : 0;
 	}
 
 	if ((type = _all_match(rh, field, flen))) {
 		if (report_type_only) {
 			rh->report_types |= type;
 			return 1;
-		} else
-			return  _add_all_fields(rh, type);
+		}
+
+		return  _add_all_fields(rh, type);
 	}
 
 	return 0;
tools/dmsetup.c +4 -3
index cbaae22..803ae56 100644
@@ -4538,10 +4538,11 @@ static int _ls(CMD_ARGS)
 	if ((_switches[TARGET_ARG] && _target) ||
 	    (_switches[EXEC_ARG] && _command_to_exec))
 		return _status(cmd, NULL, argc, argv, NULL, 0);
-	else if ((_switches[TREE_ARG]))
+
+	if ((_switches[TREE_ARG]))
 		return _display_tree(cmd, NULL, 0, NULL, NULL, 0);
-	else
-		return _process_all(cmd, NULL, argc, argv, 0, _display_name);
+
+	return _process_all(cmd, NULL, argc, argv, 0, _display_name);
 }
 
 static int _mangle(CMD_ARGS)
tools/lvconvert.c +10 -7
index cfdf5de..d90e675 100644
@@ -341,9 +341,9 @@ static int _lvconvert_poll_by_id(struct cmd_context *cmd, struct poll_operation_
 				(MERGING | (is_merging_origin_thin ? THIN_VOLUME : SNAPSHOT)),
 				is_merging_origin_thin ? &_lvconvert_thin_merge_fns : &_lvconvert_merge_fns,
 				"Merged", id);
-	else
-		return poll_daemon(cmd, background, CONVERTING,
-				&_lvconvert_mirror_fns, "Converted", id);
+
+	return poll_daemon(cmd, background, CONVERTING,
+			   &_lvconvert_mirror_fns, "Converted", id);
 }
 
 int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,
@@ -1313,7 +1313,9 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
 			log_error("Linear LV %s cannot be converted to %s.",
 				  display_lvname(lv), lp->type_str);
 			return 0;
-		} else if (!strcmp(lp->type_str, SEG_TYPE_NAME_RAID1)) {
+		}
+
+		if (!strcmp(lp->type_str, SEG_TYPE_NAME_RAID1)) {
 			log_error("Raid conversions of LV %s require -m/--mirrors.",
 				  display_lvname(lv));
 			return 0;
@@ -3398,10 +3400,11 @@ static int _lvconvert_repair_pvs_or_thinpool_single(struct cmd_context *cmd, str
 {
 	if (lv_is_thin_pool(lv))
 		return _lvconvert_repair_thinpool(cmd, lv, handle);
-	else if (lv_is_raid(lv) || lv_is_mirror(lv))
+
+	if (lv_is_raid(lv) || lv_is_mirror(lv))
 		return _lvconvert_repair_pvs(cmd, lv, handle);
-	else
-		return_ECMD_FAILED;
+
+	return_ECMD_FAILED;
 }
 
 /*
tools/lvcreate.c +3 -1
index f464896..d2199f5 100644
@@ -628,7 +628,9 @@ static int _read_mirror_and_raid_params(struct cmd_context *cmd,
 		log_error("Only up to %u stripes in %s supported currently.",
 			  max_images / lp->mirrors, lp->segtype->name);
 		return 0;
-	} else if (seg_is_mirrored(lp)) {
+	}
+
+	if (seg_is_mirrored(lp)) {
 		if (lp->mirrors > max_images) {
 			log_error("Only up to %u mirrors in %s supported currently.",
 				  max_images, lp->segtype->name);
tools/polldaemon.c +17 -16
index 33fe947..a4df22e 100644
@@ -559,17 +559,18 @@ static int _lvmpoll_daemon(struct cmd_context *cmd, struct poll_operation_id *id
 		}
 
 		return r ? ECMD_PROCESSED : ECMD_FAILED;
-	} else {
-		/* process all in-flight operations */
-		if (!(handle = init_processing_handle(cmd, NULL))) {
-			log_error("Failed to initialize processing handle.");
-			return ECMD_FAILED;
-		} else {
-			_lvmpolld_poll_for_all_vgs(cmd, parms, handle);
-			destroy_processing_handle(cmd, handle);
-			return ECMD_PROCESSED;
-		}
 	}
+
+	/* process all in-flight operations */
+	if (!(handle = init_processing_handle(cmd, NULL))) {
+		log_error("Failed to initialize processing handle.");
+		return ECMD_FAILED;
+	}
+
+	_lvmpolld_poll_for_all_vgs(cmd, parms, handle);
+	destroy_processing_handle(cmd, handle);
+
+	return ECMD_PROCESSED;
 }
 #else
 #	define _lvmpoll_daemon(cmd, id, parms) (ECMD_FAILED)
@@ -592,7 +593,8 @@ static int _poll_daemon(struct cmd_context *cmd, struct poll_operation_id *id,
 		daemon_mode = become_daemon(cmd, 0);
 		if (daemon_mode == 0)
 			return ECMD_PROCESSED;	    /* Parent */
-		else if (daemon_mode == 1)
+
+		if (daemon_mode == 1)
 			parms->progress_display = 0; /* Child */
 		/* FIXME Use wait_event (i.e. interval = 0) and */
 		/*       fork one daemon per copy? */
@@ -680,9 +682,8 @@ int poll_daemon(struct cmd_context *cmd, unsigned background,
 
 	if (lvmpolld_use())
 		return _lvmpoll_daemon(cmd, id, &parms);
-	else {
-		/* classical polling allows only PMVOVE or 0 values */
-		parms.lv_type &= PVMOVE;
-		return _poll_daemon(cmd, id, &parms);
-	}
+
+	/* classical polling allows only PMVOVE or 0 values */
+	parms.lv_type &= PVMOVE;
+	return _poll_daemon(cmd, id, &parms);
 }
tools/toollib.c +8 -6
index 9e89ed7..5e3fedd 100644
@@ -938,9 +938,9 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
 			if (clustery) {
 				log_error("The --clustered option requires clvmd (locking_type=3).");
 				return 0;
-			} else {
-				lock_type = "none";
 			}
+
+			lock_type = "none";
 		}
 
 	} else if (arg_is_set(cmd, shared_ARG)) {
@@ -4676,11 +4676,11 @@ int pvcreate_params_from_args(struct cmd_context *cmd, struct pvcreate_params *p
 		log_error("labelsector must be less than %lu.",
 			  LABEL_SCAN_SECTORS);
 		return 0;
-	} else {
-		pp->pva.label_sector = arg_int64_value(cmd, labelsector_ARG,
-						  DEFAULT_LABELSECTOR);
 	}
 
+	pp->pva.label_sector = arg_int64_value(cmd, labelsector_ARG,
+					       DEFAULT_LABELSECTOR);
+
 	if (!(cmd->fmt->features & FMT_MDAS) &&
 	    (arg_is_set(cmd, pvmetadatacopies_ARG) ||
 	     arg_is_set(cmd, metadatasize_ARG)   ||
@@ -5084,7 +5084,9 @@ static int _pvcreate_check_single(struct cmd_context *cmd,
 			log_error("Can't get device size of %s.", pv_dev_name(pv));
 			dm_list_move(&pp->arg_fail, &pd->list);
 			return 1;
-		} else if (new_size != size)
+		}
+
+		if (new_size != size)
 			need_size_prompt = 1;
 	}
 
tools/vgdisplay.c +10 -7
index 7fc64b0..f4b0b6f 100644
@@ -60,13 +60,16 @@ int vgdisplay(struct cmd_context *cmd, int argc, char **argv)
 			return EINVALID_CMD_LINE;
 		}
 		return vgs(cmd, argc, argv);
-	} else if (arg_is_set(cmd, aligned_ARG) ||
-		   arg_is_set(cmd, binary_ARG) ||
-		   arg_is_set(cmd, noheadings_ARG) ||
-		   arg_is_set(cmd, options_ARG) ||
-		   arg_is_set(cmd, separator_ARG) ||
-		   arg_is_set(cmd, sort_ARG) || arg_is_set(cmd, unbuffered_ARG)) {
-		log_error("Incompatible options selected");
+	}
+
+	if (arg_is_set(cmd, aligned_ARG) ||
+	    arg_is_set(cmd, binary_ARG) ||
+	    arg_is_set(cmd, noheadings_ARG) ||
+	    arg_is_set(cmd, options_ARG) ||
+	    arg_is_set(cmd, separator_ARG) ||
+	    arg_is_set(cmd, sort_ARG) ||
+	    arg_is_set(cmd, unbuffered_ARG)) {
+		log_error("Incompatible options selected.");
 		return EINVALID_CMD_LINE;
 	}