diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c index 33150cb48..7a10e0a31 100644 --- a/lib/locking/lvmlockd.c +++ b/lib/locking/lvmlockd.c @@ -1223,10 +1223,22 @@ static int _lockd_all_lvs(struct cmd_context *cmd, struct volume_group *vg) /* vgremove before the vg is removed */ int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg, - int changing) + int changing, const char *lockopt, int yes) { int lock_type_num = get_lock_type_from_string(vg->lock_type); + if (lockopt && strstr(lockopt, "force")) { + if (!yes && yes_no_prompt("Force unprotected removal of shared VG? [y/n]: ") == 'n') { + log_error("VG not removed."); + return 0; + } + if (vg->sanlock_lv) { + _deactivate_sanlock_lv(cmd, vg); + _remove_sanlock_lv(cmd, vg); + } + return 1; + } + /* * Check that no LVs are active on other hosts. * When removing (not changing), each LV is locked diff --git a/lib/locking/lvmlockd.h b/lib/locking/lvmlockd.h index d486abc09..e1369a704 100644 --- a/lib/locking/lvmlockd.h +++ b/lib/locking/lvmlockd.h @@ -56,7 +56,7 @@ void lvmlockd_disconnect(void); /* vgcreate/vgremove use init/free */ int lockd_init_vg(struct cmd_context *cmd, struct volume_group *vg, const char *lock_type, int lv_lock_count); -int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg, int changing); +int lockd_free_vg_before(struct cmd_context *cmd, struct volume_group *vg, int changing, const char *lockopt, int yes); void lockd_free_vg_final(struct cmd_context *cmd, struct volume_group *vg); /* vgrename */ diff --git a/tools/vgchange.c b/tools/vgchange.c index 8a17cfaec..a44b865b7 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -1215,7 +1215,7 @@ static int _vgchange_locktype(struct cmd_context *cmd, struct volume_group *vg, * lockd type to ..., first undo lockd type */ if (is_lockd_type(vg->lock_type)) { - if (!lockd_free_vg_before(cmd, vg, 1)) + if (!lockd_free_vg_before(cmd, vg, 1, NULL, 0)) return 0; lockd_free_vg_final(cmd, vg); diff --git a/tools/vgremove.c b/tools/vgremove.c index a3252ae80..94615aea3 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -70,7 +70,7 @@ static int _vgremove_single(struct cmd_context *cmd, const char *vg_name, !lvremove_single(cmd, vg->pool_metadata_spare_lv, &void_handle)) return_ECMD_FAILED; - if (!lockd_free_vg_before(cmd, vg, 0)) + if (!lockd_free_vg_before(cmd, vg, 0, arg_str_value(cmd, lockopt_ARG, NULL), arg_is_set(cmd, yes_ARG))) return_ECMD_FAILED; if (!force && !vg_remove_check(vg))