Fix double releasing of vg when repairing of vg is requested
PATCH 1/1 Fix double releasing of vg when repairing of vg is requested
Fix double releasing of vg when repairing of vg is requested.
Several commands calls process_each_vg() and in provided callback it explicitly recovers VG if inconsistent. (vgchange, vgconvert, vgscan)
It means that old VG is released and re-read but the function above (process_one_vg) tries to unlock and release old VG.
Patch moves the repair logic into _process_one_vg() function.
It always tries to read vg (even inconsistent) and then decides what to do according new defined parameter.
Also patch unifies inconsistent error messages.
The only slight change if for vgremove command, where
it now tries to repair VG before it removes if force arg is given. (It works similar way before, just the order of operation changed).
[maybe this somehow collide with proposed vg_read changes, but this is serious bug which should be fixed asap...]
--- lib/metadata/metadata-exported.h | 10 ++++++++++ test/t-inconsistent-metadata.sh | 10 +++++----- tools/polldaemon.c | 15 +++------------ tools/reporter.c | 24 ++++++------------------ tools/toollib.c | 38 ++++++++++++++++++++++++++++---------- tools/toollib.h | 2 +- tools/vgcfgbackup.c | 13 +++---------- tools/vgchange.c | 16 ++-------------- tools/vgck.c | 13 ++----------- tools/vgconvert.c | 16 ++-------------- tools/vgdisplay.c | 10 ++-------- tools/vgexport.c | 13 ++----------- tools/vgimport.c | 9 ++------- tools/vgremove.c | 6 ++++-- tools/vgscan.c | 17 ++--------------- 15 files changed, 74 insertions(+), 138 deletions(-)
lib/metadata/metadata-exported.h +10 -0
@@ -153,6 +153,16 @@ typedef enum { DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */ } force_t; +/* +* What to do if VG is inconsistent +* FIXME: remove this after vg_read changes +*/ +typedef enum { +VG_INCONSISTENT_ABORT =0 ,/* Abort operation */ +VG_INCONSISTENT_CONTINUE =1 ,/* Process operation but do not try repair */ +VG_INCONSISTENT_REPAIR =2 /* Try to repair VG before processing */ +}inconsistent_t ; +struct cmd_context ;struct format_handler ;struct labeller ;
test/t-inconsistent-metadata.sh +5 -5
@@ -26,7 +26,7 @@ init() { lvresize -L 8192K $vg/resized restore_dev $dev1 } - + check() { lvs -o lv_name,lv_size --units k $vg | tee lvs.out grep resized lvs.out | grep 8192
@@ -43,20 +43,20 @@ check # vgdisplay doesn't change anything init vgdisplay 2>&1 | tee cmd.out -grep "Volume group \"$vg\" inconsistent" cmd.out +grep "Volume group $vg inconsistent" cmd.out vgdisplay 2>&1 | tee cmd.out -grep "Volume group \"$vg\" inconsistent" cmd.out +grep "Volume group $vg inconsistent" cmd.out # lvs fixes up init lvs 2>&1 | tee cmd.out grep "Inconsistent metadata found for VG $vg - updating" cmd.out vgdisplay 2>&1 | tee cmd.out -not grep "Volume group \"$vg\" inconsistent" cmd.out +not grep "Volume group $vg inconsistent" cmd.out check # vgs doesn't fix up... (why?) init vgs 2>&1 | tee cmd.out vgdisplay 2>&1 | tee cmd.out -grep "Volume group \"$vg\" inconsistent" cmd.out +grep "Volume group $vg inconsistent" cmd.out
tools/polldaemon.c +3 -12
@@ -182,17 +182,6 @@ static int _poll_vg(struct cmd_context *cmd, const char *vgname,const char *name;int finished; -if (!vg) { -log_error ("Couldn't read volume group %s" , vgname); -return ECMD_FAILED ; - } - -if (!consistent) { -log_error ("Volume Group %s inconsistent - skipping" , vgname); -/* FIXME Should we silently recover it here or not? */ -return ECMD_FAILED ; - } -if (!vg_check_status (vg,EXPORTED_VG ))return ECMD_FAILED ;
@@ -218,7 +207,9 @@ static void _poll_for_all_vgs(struct cmd_context *cmd, {while (1 ) { parms->outstanding_count =0 ; -process_each_vg (cmd,0 ,NULL ,LCK_VG_WRITE ,1 , parms, _poll_vg); +/* FIXME Should we silently recover it here or not? */ +process_each_vg (cmd,0 ,NULL ,LCK_VG_WRITE , +VG_INCONSISTENT_ABORT , parms, _poll_vg);if (!parms->outstanding_count)break ;sleep (parms->interval);
tools/reporter.c +6 -18
@@ -20,11 +20,6 @@ static int _vgs_single(struct cmd_context *cmd __attribute((unused)), const char *vg_name, struct volume_group *vg, int consistent __attribute((unused)), void *handle) { - if (!vg) { - log_error("Volume group %s not found", vg_name); -return ECMD_FAILED ; - } - if (!report_object(handle, vg, NULL, NULL, NULL, NULL)) return ECMD_FAILED;
@@ -184,11 +179,6 @@ static int _pvs_in_vg(struct cmd_context *cmd, const char *vg_name, int consistent __attribute((unused)), void *handle) { -if (!vg) { -log_error ("Volume group %s not found" , vg_name); -return ECMD_FAILED ; - } -return process_each_pv_in_vg (cmd, vg,NULL , handle, &_pvs_single); }
@@ -197,11 +187,6 @@ static int _pvsegs_in_vg(struct cmd_context *cmd, const char *vg_name, int consistent __attribute((unused)), void *handle) { -if (!vg) { -log_error ("Volume group %s not found" , vg_name); -return ECMD_FAILED ; - } -return process_each_pv_in_vg (cmd, vg,NULL , handle, &_pvsegs_single); }
@@ -382,7 +367,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, &_lvs_single);break ;case VGS : - r =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , + r =process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_CONTINUE , report_handle, &_vgs_single);break ;case LABEL :
@@ -394,7 +380,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, r =process_each_pv (cmd, argc, argv,NULL ,LCK_VG_READ ,0 , report_handle, &_pvs_single); else - r =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , + r =process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_CONTINUE , report_handle, &_pvs_in_vg);break ;case SEGS :
@@ -406,7 +393,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, r =process_each_pv (cmd, argc, argv,NULL ,LCK_VG_READ ,0 , report_handle, &_pvsegs_single); else - r =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , + r =process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_CONTINUE , report_handle, &_pvsegs_in_vg);break ; }
tools/toollib.c +28 -10
@@ -449,7 +449,7 @@ int process_each_segment_in_lv(struct cmd_context *cmd, static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, const char *vgid, struct dm_list *tags, struct dm_list *arg_vgnames, - uint32_t lock_type, int consistent, void *handle, + uint32_t lock_type, inconsistent_t repair_vg, void *handle, int ret_max, int (*process_single) (struct cmd_context * cmd, const char *vg_name,
@@ -457,6 +457,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, int consistent, void *handle)) { struct volume_group *vg; +int consistent =0 ;int ret =0 ;if (!lock_vol (cmd, vg_name, lock_type)) {
@@ -472,31 +473,48 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, }if (!vg_check_status (vg,CLUSTERED )) { -unlock_and_release_vg (cmd, vg, vg_name); -return ECMD_FAILED ; + ret_max =ECMD_FAILED ; + goto out; }if (!dm_list_empty (tags)) {/* 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)) { + !str_list_match_list (tags, &vg->tags)) + goto out; + } + +if (!consistent) +switch (repair_vg) { +case VG_INCONSISTENT_ABORT : +log_error ("Volume group %s inconsistent - skipping" , vg_name); + ret_max =ECMD_FAILED ; + goto out; +case VG_INCONSISTENT_CONTINUE : +log_error ("Volume group %s inconsistent" , vg_name); +break ; +case VG_INCONSISTENT_REPAIR :unlock_and_release_vg (cmd, vg, vg_name); -return ret_max; +dev_close_all (); +log_error ("Volume group %s inconsistent" , vg_name); +if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE ))) +return ECMD_FAILED ; + consistent =1 ; +break ; } - }if ((ret =process_single (cmd, vg_name, vg, consistent, handle)) > ret_max) { ret_max = ret; } +out:unlock_and_release_vg (cmd, vg, vg_name); -return ret_max; } int process_each_vg(struct cmd_context *cmd, int argc, char **argv, - uint32_t lock_type, int consistent, void *handle, + uint32_t lock_type, inconsistent_t repair_vg, void *handle, int (*process_single) (struct cmd_context * cmd, const char *vg_name, struct volume_group * vg,
@@ -563,7 +581,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,continue ; ret_max =_process_one_vg (cmd, vg_name, vgid, &tags, &arg_vgnames, - lock_type, consistent, handle, + lock_type, repair_vg, handle, ret_max, process_single);if (sigint_caught ())return ret_max;
@@ -575,7 +593,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,continue ;/* FIXME Unnecessary? */ ret_max =_process_one_vg (cmd, vg_name,NULL , &tags, &arg_vgnames, - lock_type, consistent, handle, + lock_type, repair_vg, handle, ret_max, process_single);if (sigint_caught ())return ret_max;
tools/toollib.h +1 -1
@@ -27,7 +27,7 @@ struct volume_group *recover_vg(struct cmd_context *cmd, const char *vgname, uint32_t lock_type); int process_each_vg(struct cmd_context *cmd, int argc, char **argv, - uint32_t lock_type, int consistent, void *handle, + uint32_t lock_type, inconsistent_t repair_vg, void *handle, int (*process_single) (struct cmd_context * cmd, const char *vg_name, struct volume_group * vg,
tools/vgcfgbackup.c +3 -10
@@ -54,14 +54,6 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,char **last_filename = (char **)handle;char *filename; -if (!vg) { -log_error ("Volume group \"%s\" not found" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) -log_error ("WARNING: Volume group \"%s\" inconsistent" , vg_name); -if (arg_count (cmd, file_ARG)) {if (!(filename =_expand_filename (arg_value (cmd, file_ARG), vg->name, last_filename))) {
@@ -98,8 +90,9 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)init_pvmove (1 ); - ret =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , &last_filename, - &vg_backup_single); + ret =process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_CONTINUE , + &last_filename, &vg_backup_single);dm_free (last_filename);
tools/vgchange.c +2 -14
@@ -526,19 +526,6 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name, {int r =ECMD_FAILED ; -if (!vg) { -log_error ("Unable to find volume group \"%s\"" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) { -unlock_and_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 ))) -return ECMD_FAILED ; - } -if (!(vg_status (vg) &LVM_WRITE ) && !arg_count (cmd, available_ARG)) {log_error ("Volume group \"%s\" is read-only" , vg->name);return ECMD_FAILED ;
@@ -633,6 +620,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)return process_each_vg (cmd, argc, argv, (arg_count (cmd, available_ARG)) ? -LCK_VG_READ :LCK_VG_WRITE ,0 ,NULL , +LCK_VG_READ :LCK_VG_WRITE , +VG_INCONSISTENT_REPAIR ,NULL , &vgchange_single); }
tools/vgck.c +2 -11
@@ -21,16 +21,6 @@ static int vgck_single(struct cmd_context *cmd __attribute((unused)), struct volume_group *vg, int consistent, void *handle __attribute((unused))) { -if (!vg) { -log_error ("Volume group \"%s\" not found" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) { -log_error ("Volume group \"%s\" inconsistent" , vg_name); -return ECMD_FAILED ; - } -if (!vg_check_status (vg,EXPORTED_VG ))return ECMD_FAILED ;
@@ -42,6 +32,7 @@ static int vgck_single(struct cmd_context *cmd __attribute((unused)),int vgck (struct cmd_context *cmd,int argc,char **argv) { -return process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 ,NULL , +return process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_ABORT ,NULL , &vgck_single); }
tools/vgconvert.c +2 -14
@@ -32,19 +32,6 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,struct lvinfo info;int active =0 ; -if (!vg) { -log_error ("Unable to find volume group \"%s\"" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) { -unlock_and_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 ))) -return ECMD_FAILED ; - } -if (!vg_check_status (vg,LVM_WRITE |EXPORTED_VG ))return ECMD_FAILED ;
@@ -233,6 +220,7 @@ int vgconvert(struct cmd_context *cmd, int argc, char **argv)return EINVALID_CMD_LINE ; } -return process_each_vg (cmd, argc, argv,LCK_VG_WRITE ,0 ,NULL , +return process_each_vg (cmd, argc, argv,LCK_VG_WRITE , +VG_INCONSISTENT_REPAIR ,NULL , &vgconvert_single); }
tools/vgdisplay.c +2 -8
@@ -20,13 +20,6 @@ static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name, void *handle __attribute((unused))) {/* FIXME Do the active check here if activevolumegroups_ARG ? */ -if (!vg) { -log_error ("Volume group \"%s\" doesn't exist" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) -log_error ("WARNING: Volume group \"%s\" inconsistent" , vg_name);vg_check_status (vg,EXPORTED_VG );
@@ -98,7 +91,8 @@ int vgdisplay(struct cmd_context *cmd, int argc, char **argv)} **********/ -return process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 ,NULL , +return process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_CONTINUE ,NULL , vgdisplay_single);/******** FIXME Need to count number processed
tools/vgexport.c +2 -11
@@ -23,16 +23,6 @@ static int vgexport_single(struct cmd_context *cmd __attribute((unused)),struct pv_list *pvl;struct physical_volume *pv; -if (!vg) { -log_error ("Unable to find volume group \"%s\"" , vg_name); - goto error; - } - -if (!consistent) { -log_error ("Volume group %s inconsistent" , vg_name); - goto error; - } -if (!vg_check_status (vg,EXPORTED_VG |LVM_WRITE )) { goto error; }
@@ -78,6 +68,7 @@ int vgexport(struct cmd_context *cmd, int argc, char **argv)return ECMD_FAILED ; } -return process_each_vg (cmd, argc, argv,LCK_VG_WRITE ,1 ,NULL , +return process_each_vg (cmd, argc, argv,LCK_VG_WRITE , +VG_INCONSISTENT_ABORT ,NULL , &vgexport_single); }
tools/vgimport.c +2 -7
@@ -23,12 +23,6 @@ static int vgimport_single(struct cmd_context *cmd __attribute((unused)),struct pv_list *pvl;struct physical_volume *pv; -if (!vg || !consistent) { -log_error ("Unable to find exported volume group \"%s\"" , - vg_name); - goto error; - } -if (!(vg_status (vg) &EXPORTED_VG )) {log_error ("Volume group \"%s\" is not exported" , vg_name); goto error;
@@ -74,6 +68,7 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)return ECMD_FAILED ; } -return process_each_vg (cmd, argc, argv,LCK_VG_WRITE ,1 ,NULL , +return process_each_vg (cmd, argc, argv,LCK_VG_WRITE , +VG_INCONSISTENT_ABORT ,NULL , &vgimport_single); }
tools/vgremove.c +4 -2
@@ -40,8 +40,10 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)return ECMD_FAILED ; } - ret =process_each_vg (cmd, argc, argv, -LCK_VG_WRITE ,1 , + ret =process_each_vg (cmd, argc, argv,LCK_VG_WRITE , +arg_count (cmd, force_ARG) ? +VG_INCONSISTENT_REPAIR : +VG_INCONSISTENT_ABORT ,NULL , &vgremove_single);unlock_vg (cmd,VG_ORPHANS );
tools/vgscan.c +2 -15
@@ -19,20 +19,6 @@ static int vgscan_single(struct cmd_context *cmd, const char *vg_name, struct volume_group *vg, int consistent, void *handle __attribute((unused))) { -if (!vg) { -log_error ("Volume group \"%s\" not found" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) { -unlock_and_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 */ -if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE ))) -return ECMD_FAILED ; - } -log_print ("Found %svolume group \"%s\" using metadata type %s" , (vg_status (vg) &EXPORTED_VG ) ?"exported " :"" , vg_name, vg->fid->fmt->name);
@@ -61,7 +47,8 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)log_print ("Reading all physical volumes. This may take a while..." ); - maxret =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 ,NULL , + maxret =process_each_vg (cmd, argc, argv,LCK_VG_READ , +VG_INCONSISTENT_REPAIR ,NULL , &vgscan_single);if (arg_count (cmd, mknodes_ARG)) {
PATCH 1/1 Fix double releasing of vg when repairing of vg is requested
Quoted 2 lines · Milan Broz
[maybe this somehow collide with proposed
vg_readchanges, but this is serious bug which should be fixed asap...]
Yes, it does collide with vg_read changes, and it also duplicates one of the patches that already unifies the recovery process. There are other crash bugs waiting for the vg_read patches to be applied, so maybe it would be best to get the vg_read patches applied, then...
See also this message:
Subject: Re: [lvm-devel][PATCH] Fix segfault when using vgsplit in stacked environment
Message-ID: <[email protected]>
which has a patch that fixes a vgsplit segfault that needs new vg_read.
If there's no better interim fix though and this is really urgent, I guess that vg_read patches will have to give way. I would however ask that this patch be reverted before applying vg_read bits, because I have rewritten and rebased vg_read more than enough times already...
Yours,
Petr.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentation