1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-25 18:50:51 +03:00

cleanup: stack usage

Shortening code with macros return_0, return_NULL.
Add some missing stack prints in error paths.
This commit is contained in:
Zdenek Kabelac 2013-07-01 11:27:11 +02:00
parent b90450b8a0
commit 47419d21ac
12 changed files with 40 additions and 70 deletions

View File

@ -614,10 +614,8 @@ int dm_event_register_handler(const struct dm_event_handler *dmevh)
struct dm_task *dmt;
struct dm_event_daemon_message msg = { 0, 0, NULL };
if (!(dmt = _get_device_info(dmevh))) {
stack;
return 0;
}
if (!(dmt = _get_device_info(dmevh)))
return_0;
uuid = dm_task_get_uuid(dmt);
@ -643,10 +641,8 @@ int dm_event_unregister_handler(const struct dm_event_handler *dmevh)
struct dm_task *dmt;
struct dm_event_daemon_message msg = { 0, 0, NULL };
if (!(dmt = _get_device_info(dmevh))) {
stack;
return 0;
}
if (!(dmt = _get_device_info(dmevh)))
return_0;
uuid = dm_task_get_uuid(dmt);

View File

@ -516,8 +516,7 @@ static int decode_lock_type(const char *response)
else if (!strcmp(response, "PR"))
return LCK_PREAD;
stack;
return 0;
return_0;
}
#ifdef CLUSTER_LOCKING_INTERNAL

View File

@ -672,10 +672,8 @@ static int _children_suspended(struct dm_tree_node *node,
if (dlink->node->presuspend_node == node)
continue;
if (!(dinfo = dm_tree_node_get_info(dlink->node))) {
stack; /* FIXME Is this normal? */
return 0;
}
if (!(dinfo = dm_tree_node_get_info(dlink->node)))
return_0; /* FIXME Is this normal? */
if (!dinfo->suspended)
return 0;
@ -920,10 +918,8 @@ static int _node_has_closed_parents(struct dm_tree_node *node,
if (!_uuid_prefix_matches(uuid, uuid_prefix, uuid_prefix_len))
continue;
if (!(dinfo = dm_tree_node_get_info(dlink->node))) {
stack; /* FIXME Is this normal? */
return 0;
}
if (!(dinfo = dm_tree_node_get_info(dlink->node)))
return_0; /* FIXME Is this normal? */
/* Refresh open_count */
if (!_info_by_dev(dinfo->major, dinfo->minor, 1, &info, NULL, NULL, NULL) ||

View File

@ -303,10 +303,8 @@ static struct rx_node *_term(struct parse_sp *ps)
switch (ps->type) {
case 0:
if (!(n = _node(ps->mem, CHARSET, NULL, NULL))) {
stack;
return NULL;
}
if (!(n = _node(ps->mem, CHARSET, NULL, NULL)))
return_NULL;
dm_bit_copy(n->charset, ps->charset);
_rx_get_token(ps); /* match charset */
@ -354,10 +352,8 @@ static struct rx_node *_closure_term(struct parse_sp *ps)
return l;
}
if (!n) {
stack;
return NULL;
}
if (!n)
return_NULL;
_rx_get_token(ps);
l = n;

View File

@ -87,10 +87,8 @@ int ttree_insert(struct ttree *tt, unsigned int *key, void *data)
count++;
while (count--) {
if (!(*c = _tree_node(tt->mem, k))) {
stack;
return 0;
}
if (!(*c = _tree_node(tt->mem, k)))
return_0;
if (count) {
k = *key++;
@ -107,10 +105,8 @@ struct ttree *ttree_create(struct dm_pool *mem, unsigned int klen)
{
struct ttree *tt;
if (!(tt = dm_pool_zalloc(mem, sizeof(*tt)))) {
stack;
return NULL;
}
if (!(tt = dm_pool_zalloc(mem, sizeof(*tt))))
return_NULL;
tt->klen = klen;
tt->mem = mem;

View File

@ -485,10 +485,8 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
}
/* Default is never striped, regardless of existing LV configuration. */
if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size)) {
stack;
return 0;
}
if (!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size))
return_0;
lp->segtype = get_segtype_from_string(cmd, arg_str_value(cmd, type_ARG, find_config_tree_str(cmd, global_mirror_segtype_default_CFG)));
if (!lp->segtype)
@ -1283,10 +1281,8 @@ static int _lvconvert_mirrors_aux(struct cmd_context *cmd,
* linear-to-mirror conversion.
*/
if (!_lv_update_log_type(cmd, lp, lv,
operable_pvs, new_log_count)) {
stack;
return 0;
}
operable_pvs, new_log_count))
return_0;
/* Insert a temporary layer for syncing,
* only if the original lv is using disk log. */
@ -1314,8 +1310,8 @@ static int _lvconvert_mirrors_aux(struct cmd_context *cmd,
"and dmsetup may be required.");
return 0;
}
stack;
return 0;
return_0;
}
if (seg->log_lv)
lv->status |= CONVERTING;
@ -1356,10 +1352,8 @@ out:
*/
if ((lv->status & MIRRORED) && (old_log_count != new_log_count)) {
if (!_lv_update_log_type(cmd, lp, lv,
operable_pvs, new_log_count)) {
stack;
return 0;
}
operable_pvs, new_log_count))
return_0;
}
out_skip_log_convert:

View File

@ -1123,7 +1123,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
if (!init_locking(locking_type, cmd, arg_count(cmd, sysinit_ARG))) {
ret = ECMD_FAILED;
goto out;
goto_out;
}
ret = cmd->command->fn(cmd, argc, argv);
@ -1539,7 +1539,7 @@ int lvm2_main(int argc, char **argv)
}
_exec_lvm1_command(argv);
ret = ECMD_FAILED;
goto out;
goto_out;
}
#ifdef READLINE_SUPPORT
if (!alias && argc == 1) {

View File

@ -16,7 +16,6 @@
#include "tools.h"
#include "lvm-types.h"
/*
* lvrename command implementation.
* Check arguments and call lv_rename() to execute the request.
@ -27,10 +26,9 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
char *lv_name_old, *lv_name_new;
const char *vg_name, *vg_name_new, *vg_name_old;
char *st;
int r = ECMD_FAILED;
struct volume_group *vg = NULL;
struct volume_group *vg;
struct lv_list *lvl;
int r = ECMD_FAILED;
if (argc == 3) {
vg_name = skip_dev_dir(cmd, argv[0], NULL);
@ -90,7 +88,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
if (!validate_name(lv_name_new)) {
log_error("New logical volume name \"%s\" is invalid",
lv_name_new);
lv_name_new);
return EINVALID_CMD_LINE;
}
@ -109,32 +107,30 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
log_error("Existing logical volume \"%s\" not found in "
"volume group \"%s\"", lv_name_old, vg_name);
goto error;
goto bad;
}
if (lvl->lv->status & (RAID_IMAGE | RAID_META)) {
log_error("Cannot rename a RAID %s directly",
(lvl->lv->status & RAID_IMAGE) ? "image" :
"metadata area");
r = ECMD_FAILED;
goto error;
goto bad;
}
if (lv_is_raid_with_tracking(lvl->lv)) {
log_error("Cannot rename %s while it is tracking a split image",
lvl->lv->name);
r = ECMD_FAILED;
goto error;
goto bad;
}
if (!lv_rename(cmd, lvl->lv, lv_name_new))
goto error;
goto_bad;
log_print_unless_silent("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
lv_name_old, lv_name_new, vg_name);
r = ECMD_PROCESSED;
error:
bad:
unlock_and_release_vg(cmd, vg, vg_name);
return r;
}

View File

@ -98,7 +98,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
seg ? : &_free_lv_segment, pvseg)) {
ret = ECMD_FAILED;
goto_out;
goto_out;
}
out:

View File

@ -65,7 +65,6 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
if (vg_read_error(vg) == FAILED_INCONSISTENT) {
log_error("No backup taken: specify filename with -f "
"to backup an inconsistent VG");
stack;
return ECMD_FAILED;
}
@ -76,6 +75,7 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
}
log_print_unless_silent("Volume group \"%s\" successfully backed up.", vg_name);
return ECMD_PROCESSED;
}

View File

@ -246,10 +246,8 @@ static int _vgchange_refresh(struct cmd_context *cmd, struct volume_group *vg)
{
log_verbose("Refreshing volume group \"%s\"", vg->name);
if (!vg_refresh_visible(cmd, vg)) {
stack;
return 0;
}
if (!vg_refresh_visible(cmd, vg))
return_0;
return 1;
}

View File

@ -298,8 +298,7 @@ static struct volume_group *_vgsplit_to(struct cmd_context *cmd,
if (vg_read_error(vg_to)) {
release_vg(vg_to);
stack;
return NULL;
return_NULL;
}
} else if (vg_read_error(vg_to) == SUCCESS) {