vg mempool: fix tools
PATCH 6/6 vg mempool: fix tools
Properly release VG memory pool in all CLI tools.
Signed-off-by Milan Broz <[email protected]>
--- tools/lvconvert.c | 5 ++- tools/lvcreate.c | 2 +- tools/lvrename.c | 14 ++++----- tools/lvresize.c | 2 +- tools/polldaemon.c | 6 ++-- tools/pvchange.c | 54 ++++++++++++++-------------------- tools/pvcreate.c | 1 + tools/pvdisplay.c | 3 ++ tools/pvmove.c | 56 ++++++++++++----------------------- tools/pvresize.c | 64 +++++++++++++++++----------------------- tools/reporter.c | 4 ++ tools/toollib.c | 25 ++++++++++----- tools/vgchange.c | 2 +- tools/vgconvert.c | 2 +- tools/vgcreate.c | 2 + tools/vgextend.c | 16 ++++------ tools/vgmerge.c | 18 ++++------- tools/vgreduce.c | 83 ++++++++++++++++++++------------------------------- tools/vgrename.c | 16 +++++----- tools/vgscan.c | 2 +- tools/vgsplit.c | 43 +++++++++++++-------------- 21 files changed, 187 insertions(+), 233 deletions(-)
tools/lvconvert.c +3 -2
@@ -772,11 +772,12 @@ bad:if (ret ==ECMD_PROCESSED && lp.need_polling) {if (!lv_info (cmd, lvl->lv, &info,1 ,0 ) || !info.exists) {log_print ("Conversion starts after activation" ); -return ret; + goto out; } ret =lvconvert_poll (cmd, lp.lv_name_full, lp.wait_completion ?0 :1U ); } - +out: +vg_release (vg);return ret; }
tools/lvcreate.c +1 -1
@@ -904,6 +904,6 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)if (!_lvcreate (cmd, vg, &lp)) r =ECMD_FAILED ; -unlock_vg (cmd, lp.vg_name); +unlock_release_vg (cmd, vg, lp.vg_name);return r; }
tools/lvrename.c +6 -8
@@ -27,8 +27,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; +struct volume_group *vg =NULL ;struct lv_list *lvl;if (argc ==3 ) {
@@ -115,14 +116,11 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)if (!lv_rename (cmd, lvl->lv, lv_name_new)) goto error; -unlock_vg (cmd, vg_name); -log_print ("Renamed \"%s\" to \"%s\" in volume group \"%s\"" , lv_name_old, lv_name_new, vg_name); -return ECMD_PROCESSED ; - - error: -unlock_vg (cmd, vg_name); -return ECMD_FAILED ; + r =ECMD_PROCESSED ; +error: +unlock_release_vg (cmd, vg, vg_name); +return r; }
tools/lvresize.c +1 -1
@@ -684,7 +684,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)if (!(r =_lvresize (cmd, vg, &lp))) stack; -unlock_vg (cmd, lp.vg_name); +unlock_release_vg (cmd, vg, lp.vg_name);return r; }
tools/polldaemon.c +3 -3
@@ -157,17 +157,17 @@ static int _wait_for_single_mirror(struct cmd_context *cmd, const char *name, parms->lv_type))) {log_error ("ABORTING: Can't find mirror LV in %s for %s" , vg->name, name); -unlock_vg (cmd, vg->name); +unlock_release_vg (cmd, vg, vg->name);return 0 ; }if (!_check_mirror_status (cmd, vg, lv_mirr, name, parms, &finished)) { -unlock_vg (cmd, vg->name); +unlock_release_vg (cmd, vg, vg->name);return 0 ; } -unlock_vg (cmd, vg->name); +unlock_release_vg (cmd, vg, vg->name); }return 1 ;
tools/pvchange.c +22 -32
138 lines not on this page · raw message
tools/pvcreate.c +1 -0
@@ -310,6 +310,7 @@ static int pvcreate_validate_params(struct cmd_context *cmd, pp->pe_start =pv_pe_start (existing_pv); pp->extent_size =pv_pe_size (existing_pv); pp->extent_count =pv_pe_count (existing_pv); +vg_release (vg); }if (arg_count (cmd, yes_ARG) && !arg_count (cmd, force_ARG)) {
tools/pvdisplay.c +3 -0
@@ -22,6 +22,7 @@ static int _pvdisplay_single(struct cmd_context *cmd,struct pv_list *pvl;int ret =ECMD_PROCESSED ;uint64_t size; +struct volume_group *old_vg = vg;const char *pv_name =pv_dev_name (pv);const char *vg_name =NULL ;
@@ -82,6 +83,8 @@ static int _pvdisplay_single(struct cmd_context *cmd, out:if (vg_name)unlock_vg (cmd, vg_name); +if (!old_vg) +vg_release (vg);return ret; }
tools/pvmove.c +19 -37
102 lines not on this page · raw message
tools/pvresize.c +27 -37
144 lines not on this page · raw message
tools/reporter.c +4 -0
@@ -124,6 +124,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,struct pv_list *pvl;int ret =ECMD_PROCESSED ;const char *vg_name =NULL ; +struct volume_group *old_vg = vg;if (is_pv (pv) && !is_orphan (pv) && !vg) { vg_name =pv_vg_name (pv);
@@ -155,6 +156,9 @@ out:if (vg_name)unlock_vg (cmd, vg_name); +if (!old_vg) +vg_release (vg); +return ret; }
tools/toollib.c +17 -8
@@ -279,6 +279,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, } } + vg =NULL ; dm_list_iterate_items(strl, vgnames) { vgname = strl->str;if (is_orphan_vg (vgname))
@@ -300,21 +301,24 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,if (!vg_check_status (vg,CLUSTERED )) {if (ret_max <ECMD_FAILED ) ret_max =ECMD_FAILED ; +vg_release (vg);continue ; }log_error ("Volume group \"%s\" " "inconsistent" , vgname); } +vg_release (vg);if (!vg || !(vg =recover_vg (cmd, vgname, lock_type))) {if (ret_max <ECMD_FAILED ) ret_max =ECMD_FAILED ; +vg_release (vg);continue ; } }if (!vg_check_status (vg,CLUSTERED )) { -unlock_vg (cmd, vgname); +unlock_release_vg (cmd, vg, vgname);if (ret_max <ECMD_FAILED ) ret_max =ECMD_FAILED ;continue ;
@@ -337,6 +341,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, dm_pool_strdup(cmd->mem, lv_name + 1))) {log_error ("strlist allocation failed" ); +vg_release (vg);return ECMD_FAILED ; } }
@@ -344,7 +349,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, ret =process_each_lv_in_vg (cmd, vg, &lvnames, tags_arg, handle, process_single); -unlock_vg (cmd, vgname); +unlock_release_vg (cmd, vg, vgname);if (ret > ret_max) ret_max = ret;if (sigint_caught ())
@@ -368,6 +373,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,const char *vg_name =NULL ;int ret_max =ECMD_PROCESSED ;int ret; +struct volume_group *old_vg = vg;if (!vg && !is_orphan (pv)) { vg_name =pv_vg_name (pv);
@@ -385,6 +391,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,if (!(pvl =find_pv_in_vg (vg,pv_dev_name (pv)))) {log_error ("Unable to find %s in volume group %s" ,pv_dev_name (pv), vg_name); +vg_release (vg);return ECMD_FAILED ; }
@@ -401,6 +408,8 @@ int process_each_segment_in_pv(struct cmd_context *cmd,if (vg_name)unlock_vg (cmd, vg_name); +if (!old_vg) +vg_release (vg);return ret_max; }
@@ -453,7 +462,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, }if (!vg_check_status (vg,CLUSTERED )) { -unlock_vg (cmd, vg_name); +unlock_release_vg (cmd, vg, vg_name);return ECMD_FAILED ; }
@@ -461,7 +470,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name,/* Only process if a tag matches or it's on arg_vgnames */ if (!str_list_match_item (arg_vgnames, vg_name) && !str_list_match_list (tags, &vg->tags)) { -unlock_vg (cmd, vg_name); +unlock_release_vg (cmd, vg, vg_name);return ret_max; } }
@@ -471,7 +480,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, ret_max = ret; } -unlock_vg (cmd, vg_name); +unlock_release_vg (cmd, vg, vg_name);return ret_max; }
@@ -743,12 +752,12 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,continue ; }if (!consistent) { -unlock_vg (cmd, sll->str); +unlock_release_vg (cmd, vg, sll->str);continue ; }if (!vg_check_status (vg,CLUSTERED )) { -unlock_vg (cmd, sll->str); +unlock_release_vg (cmd, vg, sll->str);continue ; }
@@ -756,7 +765,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, handle, process_single); -unlock_vg (cmd, sll->str); +unlock_release_vg (cmd, vg, sll->str);if (ret > ret_max) ret_max = ret;
tools/vgchange.c +1 -1
@@ -532,7 +532,7 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name, }if (!consistent) { -unlock_vg (cmd, vg_name); +unlock_release_vg (cmd, vg, vg_name);dev_close_all ();log_error ("Volume group \"%s\" inconsistent" , vg_name);if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE )))
tools/vgconvert.c +1 -1
@@ -38,7 +38,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, }if (!consistent) { -unlock_vg (cmd, vg_name); +unlock_release_vg (cmd, vg, vg_name);dev_close_all ();log_error ("Volume group \"%s\" inconsistent" , vg_name);if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE )))
tools/vgcreate.c +2 -0
@@ -116,9 +116,11 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)log_print ("%s%colume group \"%s\" successfully created" , clustered_message, *clustered_message ?'v' :'V' , vg->name); +vg_release (vg);return ECMD_PROCESSED ; bad: +vg_release (vg);unlock_vg (cmd, vp_new.vg_name);unlock_vg (cmd,VG_ORPHANS );return ECMD_FAILED ;
tools/vgextend.c +6 -10
@@ -19,6 +19,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) {char *vg_name;struct volume_group *vg =NULL ; +int r =ECMD_FAILED ;if (!argc) { log_error("Please enter volume group name and "
@@ -45,7 +46,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) CLUSTERED | EXPORTED_VG | LVM_WRITE | RESIZEABLE_VG, CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) { -unlock_vg (cmd,VG_ORPHANS ); +unlock_vg (cmd,VG_ORPHANS );return ECMD_FAILED ; }/********** FIXME
@@ -71,16 +72,11 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) goto error;backup (vg); - -unlock_vg (cmd, vg_name); -unlock_vg (cmd,VG_ORPHANS ); -log_print ("Volume group \"%s\" successfully extended" , vg_name); + r =ECMD_PROCESSED ; -return ECMD_PROCESSED ; - - error: -unlock_vg (cmd, vg_name); +error: +unlock_release_vg (cmd, vg, vg_name);unlock_vg (cmd,VG_ORPHANS ); -return ECMD_FAILED ; +return r; }
tools/vgmerge.c +7 -11
@@ -20,6 +20,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, {struct volume_group *vg_to, *vg_from;struct lv_list *lvl1, *lvl2; +int r =ECMD_FAILED ;if (!strcmp (vg_name_to, vg_name_from)) {log_error ("Duplicate volume group name \"%s\"" , vg_name_from);
@@ -37,7 +38,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, LCK_VG_WRITE | LCK_NONBLOCK, CLUSTERED | EXPORTED_VG | LVM_WRITE, CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) { -unlock_vg (cmd, vg_name_to); +unlock_release_vg (cmd, vg_to, vg_name_to);return ECMD_FAILED ; }
@@ -114,18 +115,13 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,/* FIXME Remove /dev/vgfrom */ backup (vg_to); - -unlock_vg (cmd, vg_name_from); -unlock_vg (cmd, vg_name_to); -log_print ("Volume group \"%s\" successfully merged into \"%s\"" , vg_from->name, vg_to->name); -return ECMD_PROCESSED ; - - bad: -unlock_vg (cmd, vg_name_from); -unlock_vg (cmd, vg_name_to); -return ECMD_FAILED ; + r =ECMD_PROCESSED ; +bad: +unlock_release_vg (cmd, vg_from, vg_name_from); +unlock_release_vg (cmd, vg_to, vg_name_to); +return r; }int vgmerge (struct cmd_context *cmd,int argc,char **argv)
tools/vgreduce.c +33 -50
176 lines not on this page · raw message
tools/vgrename.c +8 -8
@@ -28,7 +28,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,char *vg_name_new;const char *vgid =NULL , *vg_name, *vg_name_old;char old_path[NAME_LEN ], new_path[NAME_LEN ]; -struct volume_group *vg, *vg_new; +struct volume_group *vg =NULL , *vg_new =NULL ; vg_name_old =skip_dev_dir (cmd, old_vg_path,NULL ); vg_name_new =skip_dev_dir (cmd, new_vg_path,NULL );
@@ -83,7 +83,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path, }if (!vg_check_status (vg,CLUSTERED |LVM_WRITE )) { -unlock_vg (cmd, vg_name_old); +unlock_release_vg (cmd, vg, vg_name_old);return 0 ; }
@@ -91,7 +91,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,vg_check_status (vg,EXPORTED_VG );if (lvs_in_vg_activated_by_uuid_only (vg)) { -unlock_vg (cmd, vg_name_old); +unlock_release_vg (cmd, vg, vg_name_old);log_error ("Volume group \"%s\" still has active LVs" , vg_name_old);/* FIXME Remove this restriction */
@@ -101,7 +101,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,log_verbose ("Checking for new volume group \"%s\"" , vg_name_new);if (!lock_vol (cmd, vg_name_new,LCK_VG_WRITE |LCK_NONBLOCK )) { -unlock_vg (cmd, vg_name_old); +unlock_release_vg (cmd, vg, vg_name_old);log_error ("Can't get lock for %s" , vg_name_new);return 0 ; }
@@ -151,8 +151,8 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,backup (vg);backup_remove (cmd, vg_name_old); -unlock_vg (cmd, vg_name_new); -unlock_vg (cmd, vg_name_old); +unlock_release_vg (cmd, vg_new, vg_name_new); +unlock_release_vg (cmd, vg, vg_name_old);log_print ("Volume group \"%s\" successfully renamed to \"%s\"" , vg_name_old, vg_name_new);
@@ -164,8 +164,8 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,return 1 ; error: -unlock_vg (cmd, vg_name_new); -unlock_vg (cmd, vg_name_old); +unlock_release_vg (cmd, vg_new, vg_name_new); +unlock_release_vg (cmd, vg, vg_name_old);return 0 ; }
tools/vgscan.c +1 -1
@@ -25,7 +25,7 @@ static int vgscan_single(struct cmd_context *cmd, const char *vg_name, }if (!consistent) { -unlock_vg (cmd, vg_name); +unlock_release_vg (cmd, vg, vg_name);dev_close_all ();log_error ("Volume group \"%s\" inconsistent" , vg_name);/* Don't allow partial switch to this program */
tools/vgsplit.c +21 -22
81 lines not on this page · raw message