1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

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 reread  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).
This commit is contained in:
Milan Broz 2009-06-05 20:00:52 +00:00
parent 89b7d5cb4c
commit 66086ce962
16 changed files with 79 additions and 139 deletions

View File

@ -1,5 +1,9 @@
Version 2.02.48 - Version 2.02.48 -
=============================== ===============================
Try to repair vg before actual vgremove when force flag provided.
Fix possible double release of VG after recovery.
Add parameter to process_each_vg specifying what to do with inconsistent VG.
Unify error messages when procesing inconsistent volume group.
Use lvconvert --repair instead of vgreduce in mirror dmeventd DSO. Use lvconvert --repair instead of vgreduce in mirror dmeventd DSO.
Introduce lvconvert --use_policies (repair policy according to lvm.conf). Introduce lvconvert --use_policies (repair policy according to lvm.conf).
Fix clvmd-corosync to match new corosync API. Fix clvmd-corosync to match new corosync API.

View File

@ -153,6 +153,16 @@ typedef enum {
DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */ DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */
} force_t; } 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 cmd_context;
struct format_handler; struct format_handler;
struct labeller; struct labeller;

View File

@ -26,7 +26,7 @@ init() {
lvresize -L 8192K $vg/resized lvresize -L 8192K $vg/resized
restore_dev $dev1 restore_dev $dev1
} }
check() { check() {
lvs -o lv_name,lv_size --units k $vg | tee lvs.out lvs -o lv_name,lv_size --units k $vg | tee lvs.out
grep resized lvs.out | grep 8192 grep resized lvs.out | grep 8192
@ -43,20 +43,20 @@ check
# vgdisplay doesn't change anything # vgdisplay doesn't change anything
init init
vgdisplay 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
vgdisplay 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
# lvs fixes up # lvs fixes up
init init
lvs 2>&1 | tee cmd.out lvs 2>&1 | tee cmd.out
grep "Inconsistent metadata found for VG $vg - updating" cmd.out grep "Inconsistent metadata found for VG $vg - updating" cmd.out
vgdisplay 2>&1 | tee 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 check
# vgs doesn't fix up... (why?) # vgs doesn't fix up... (why?)
init init
vgs 2>&1 | tee cmd.out vgs 2>&1 | tee cmd.out
vgdisplay 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

View File

@ -182,17 +182,6 @@ static int _poll_vg(struct cmd_context *cmd, const char *vgname,
const char *name; const char *name;
int finished; 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)) if (!vg_check_status(vg, EXPORTED_VG))
return ECMD_FAILED; return ECMD_FAILED;
@ -218,7 +207,9 @@ static void _poll_for_all_vgs(struct cmd_context *cmd,
{ {
while (1) { while (1) {
parms->outstanding_count = 0; 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) if (!parms->outstanding_count)
break; break;
sleep(parms->interval); sleep(parms->interval);

View File

@ -20,11 +20,6 @@ static int _vgs_single(struct cmd_context *cmd __attribute((unused)),
const char *vg_name, struct volume_group *vg, const char *vg_name, struct volume_group *vg,
int consistent __attribute((unused)), void *handle) 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)) if (!report_object(handle, vg, NULL, NULL, NULL, NULL))
return ECMD_FAILED; return ECMD_FAILED;
@ -184,11 +179,6 @@ static int _pvs_in_vg(struct cmd_context *cmd, const char *vg_name,
int consistent __attribute((unused)), int consistent __attribute((unused)),
void *handle) 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); 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)), int consistent __attribute((unused)),
void *handle) 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); 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); &_lvs_single);
break; break;
case VGS: 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); report_handle, &_vgs_single);
break; break;
case LABEL: 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, r = process_each_pv(cmd, argc, argv, NULL, LCK_VG_READ,
0, report_handle, &_pvs_single); 0, report_handle, &_pvs_single);
else 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); report_handle, &_pvs_in_vg);
break; break;
case SEGS: 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, r = process_each_pv(cmd, argc, argv, NULL, LCK_VG_READ,
0, report_handle, &_pvsegs_single); 0, report_handle, &_pvsegs_single);
else 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); report_handle, &_pvsegs_in_vg);
break; break;
} }

View File

@ -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, static int _process_one_vg(struct cmd_context *cmd, const char *vg_name,
const char *vgid, const char *vgid,
struct dm_list *tags, struct dm_list *arg_vgnames, 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 ret_max,
int (*process_single) (struct cmd_context * cmd, int (*process_single) (struct cmd_context * cmd,
const char *vg_name, 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)) int consistent, void *handle))
{ {
struct volume_group *vg; struct volume_group *vg;
int consistent = 0;
int ret = 0; int ret = 0;
if (!lock_vol(cmd, vg_name, lock_type)) { 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)) { if (!vg_check_status(vg, CLUSTERED)) {
unlock_and_release_vg(cmd, vg, vg_name); ret_max = ECMD_FAILED;
return ECMD_FAILED; goto out;
} }
if (!dm_list_empty(tags)) { if (!dm_list_empty(tags)) {
/* Only process if a tag matches or it's on arg_vgnames */ /* Only process if a tag matches or it's on arg_vgnames */
if (!str_list_match_item(arg_vgnames, vg_name) && if (!str_list_match_item(arg_vgnames, vg_name) &&
!str_list_match_list(tags, &vg->tags)) { !str_list_match_list(tags, &vg->tags))
unlock_and_release_vg(cmd, vg, vg_name); goto out;
return ret_max;
}
} }
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);
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, if ((ret = process_single(cmd, vg_name, vg, consistent,
handle)) > ret_max) { handle)) > ret_max) {
ret_max = ret; ret_max = ret;
} }
out:
unlock_and_release_vg(cmd, vg, vg_name); unlock_and_release_vg(cmd, vg, vg_name);
return ret_max; return ret_max;
} }
int process_each_vg(struct cmd_context *cmd, int argc, char **argv, 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, int (*process_single) (struct cmd_context * cmd,
const char *vg_name, const char *vg_name,
struct volume_group * vg, struct volume_group * vg,
@ -563,7 +581,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
continue; continue;
ret_max = _process_one_vg(cmd, vg_name, vgid, &tags, ret_max = _process_one_vg(cmd, vg_name, vgid, &tags,
&arg_vgnames, &arg_vgnames,
lock_type, consistent, handle, lock_type, repair_vg, handle,
ret_max, process_single); ret_max, process_single);
if (sigint_caught()) if (sigint_caught())
return ret_max; return ret_max;
@ -575,7 +593,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
continue; /* FIXME Unnecessary? */ continue; /* FIXME Unnecessary? */
ret_max = _process_one_vg(cmd, vg_name, NULL, &tags, ret_max = _process_one_vg(cmd, vg_name, NULL, &tags,
&arg_vgnames, &arg_vgnames,
lock_type, consistent, handle, lock_type, repair_vg, handle,
ret_max, process_single); ret_max, process_single);
if (sigint_caught()) if (sigint_caught())
return ret_max; return ret_max;

View File

@ -27,7 +27,7 @@ struct volume_group *recover_vg(struct cmd_context *cmd, const char *vgname,
uint32_t lock_type); uint32_t lock_type);
int process_each_vg(struct cmd_context *cmd, int argc, char **argv, 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, int (*process_single) (struct cmd_context * cmd,
const char *vg_name, const char *vg_name,
struct volume_group * vg, struct volume_group * vg,

View File

@ -54,14 +54,6 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
char **last_filename = (char **)handle; char **last_filename = (char **)handle;
char *filename; 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 (arg_count(cmd, file_ARG)) {
if (!(filename = _expand_filename(arg_value(cmd, file_ARG), if (!(filename = _expand_filename(arg_value(cmd, file_ARG),
vg->name, last_filename))) { vg->name, last_filename))) {
@ -98,8 +90,9 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
init_pvmove(1); init_pvmove(1);
ret = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, &last_filename, ret = process_each_vg(cmd, argc, argv, LCK_VG_READ,
&vg_backup_single); VG_INCONSISTENT_CONTINUE,
&last_filename, &vg_backup_single);
dm_free(last_filename); dm_free(last_filename);

View File

@ -526,19 +526,6 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
{ {
int r = ECMD_FAILED; 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)) { if (!(vg_status(vg) & LVM_WRITE) && !arg_count(cmd, available_ARG)) {
log_error("Volume group \"%s\" is read-only", vg->name); log_error("Volume group \"%s\" is read-only", vg->name);
return ECMD_FAILED; return ECMD_FAILED;
@ -633,6 +620,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
return process_each_vg(cmd, argc, argv, return process_each_vg(cmd, argc, argv,
(arg_count(cmd, available_ARG)) ? (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); &vgchange_single);
} }

View File

@ -21,16 +21,6 @@ static int vgck_single(struct cmd_context *cmd __attribute((unused)),
struct volume_group *vg, int consistent, struct volume_group *vg, int consistent,
void *handle __attribute((unused))) 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)) if (!vg_check_status(vg, EXPORTED_VG))
return ECMD_FAILED; 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) 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); &vgck_single);
} }

View File

@ -32,19 +32,6 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
struct lvinfo info; struct lvinfo info;
int active = 0; 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)) if (!vg_check_status(vg, LVM_WRITE | EXPORTED_VG))
return ECMD_FAILED; return ECMD_FAILED;
@ -233,6 +220,7 @@ int vgconvert(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; 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); &vgconvert_single);
} }

View File

@ -20,13 +20,6 @@ static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name,
void *handle __attribute((unused))) void *handle __attribute((unused)))
{ {
/* FIXME Do the active check here if activevolumegroups_ARG ? */ /* 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); 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); vgdisplay_single);
/******** FIXME Need to count number processed /******** FIXME Need to count number processed

View File

@ -23,16 +23,6 @@ static int vgexport_single(struct cmd_context *cmd __attribute((unused)),
struct pv_list *pvl; struct pv_list *pvl;
struct physical_volume *pv; 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)) { if (!vg_check_status(vg, EXPORTED_VG | LVM_WRITE)) {
goto error; goto error;
} }
@ -78,6 +68,7 @@ int vgexport(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED; 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); &vgexport_single);
} }

View File

@ -23,12 +23,6 @@ static int vgimport_single(struct cmd_context *cmd __attribute((unused)),
struct pv_list *pvl; struct pv_list *pvl;
struct physical_volume *pv; 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)) { if (!(vg_status(vg) & EXPORTED_VG)) {
log_error("Volume group \"%s\" is not exported", vg_name); log_error("Volume group \"%s\" is not exported", vg_name);
goto error; goto error;
@ -74,6 +68,7 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED; 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); &vgimport_single);
} }

View File

@ -40,8 +40,10 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED; return ECMD_FAILED;
} }
ret = process_each_vg(cmd, argc, argv, ret = process_each_vg(cmd, argc, argv, LCK_VG_WRITE,
LCK_VG_WRITE, 1, arg_count(cmd, force_ARG) ?
VG_INCONSISTENT_REPAIR :
VG_INCONSISTENT_ABORT,
NULL, &vgremove_single); NULL, &vgremove_single);
unlock_vg(cmd, VG_ORPHANS); unlock_vg(cmd, VG_ORPHANS);

View File

@ -19,20 +19,6 @@ static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg, int consistent, struct volume_group *vg, int consistent,
void *handle __attribute((unused))) 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", log_print("Found %svolume group \"%s\" using metadata type %s",
(vg_status(vg) & EXPORTED_VG) ? "exported " : "", vg_name, (vg_status(vg) & EXPORTED_VG) ? "exported " : "", vg_name,
vg->fid->fmt->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..."); 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); &vgscan_single);
if (arg_count(cmd, mknodes_ARG)) { if (arg_count(cmd, mknodes_ARG)) {