mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
activate_lvs: use exclusive activation
There is no need to differentiation between clustered VG and normal VG. As the activation depends on locking type. Use unconditionally locally exclusive activation for pvmove.
This commit is contained in:
parent
8212e1047e
commit
838592a171
@ -460,19 +460,14 @@ int activate_lv_excl(struct cmd_context *cmd, const struct logical_volume *lv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Lock a list of LVs */
|
/* Lock a list of LVs */
|
||||||
int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusive)
|
int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs)
|
||||||
{
|
{
|
||||||
struct dm_list *lvh;
|
struct dm_list *lvh;
|
||||||
struct lv_list *lvl;
|
struct lv_list *lvl;
|
||||||
|
|
||||||
dm_list_iterate_items(lvl, lvs) {
|
dm_list_iterate_items(lvl, lvs) {
|
||||||
if (!exclusive && !lv_is_active_exclusive(lvl->lv)) {
|
if (!activate_lv_excl_local(cmd, lvl->lv)) {
|
||||||
if (!activate_lv(cmd, lvl->lv)) {
|
log_error("Failed to activate %s", display_lvname(lvl->lv));
|
||||||
log_error("Failed to activate %s", lvl->lv->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else if (!activate_lv_excl(cmd, lvl->lv)) {
|
|
||||||
log_error("Failed to activate %s", lvl->lv->name);
|
|
||||||
dm_list_uniterate(lvh, lvs, &lvl->list) {
|
dm_list_uniterate(lvh, lvs, &lvl->list) {
|
||||||
lvl = dm_list_item(lvh, struct lv_list);
|
lvl = dm_list_item(lvh, struct lv_list);
|
||||||
if (!deactivate_lv(cmd, lvl->lv))
|
if (!deactivate_lv(cmd, lvl->lv))
|
||||||
|
@ -266,6 +266,6 @@ int suspend_lvs(struct cmd_context *cmd, struct dm_list *lvs,
|
|||||||
struct volume_group *vg_to_revert);
|
struct volume_group *vg_to_revert);
|
||||||
int resume_lvs(struct cmd_context *cmd, struct dm_list *lvs);
|
int resume_lvs(struct cmd_context *cmd, struct dm_list *lvs);
|
||||||
int revert_lvs(struct cmd_context *cmd, struct dm_list *lvs);
|
int revert_lvs(struct cmd_context *cmd, struct dm_list *lvs);
|
||||||
int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusive);
|
int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
119
tools/pvmove.c
119
tools/pvmove.c
@ -64,16 +64,6 @@ static int _pvmove_target_present(struct cmd_context *cmd, int clustered)
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned _pvmove_is_exclusive(struct cmd_context *cmd,
|
|
||||||
struct volume_group *vg)
|
|
||||||
{
|
|
||||||
if (vg_is_clustered(vg))
|
|
||||||
if (!_pvmove_target_present(cmd, 1))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allow /dev/vgname/lvname, vgname/lvname or lvname */
|
/* Allow /dev/vgname/lvname, vgname/lvname or lvname */
|
||||||
static const char *_extract_lvname(struct cmd_context *cmd, const char *vgname,
|
static const char *_extract_lvname(struct cmd_context *cmd, const char *vgname,
|
||||||
const char *arg)
|
const char *arg)
|
||||||
@ -346,8 +336,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
|
|||||||
const char *lv_name,
|
const char *lv_name,
|
||||||
struct dm_list *allocatable_pvs,
|
struct dm_list *allocatable_pvs,
|
||||||
alloc_policy_t alloc,
|
alloc_policy_t alloc,
|
||||||
struct dm_list **lvs_changed,
|
struct dm_list **lvs_changed)
|
||||||
unsigned *exclusive)
|
|
||||||
{
|
{
|
||||||
struct logical_volume *lv_mirr, *lv;
|
struct logical_volume *lv_mirr, *lv;
|
||||||
struct lv_segment *seg;
|
struct lv_segment *seg;
|
||||||
@ -555,25 +544,6 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vg_is_clustered(vg) && lv_active_count && *exclusive) {
|
|
||||||
log_error("Cannot move in clustered VG %s, "
|
|
||||||
"clustered mirror (cmirror) not detected "
|
|
||||||
"and LVs are activated non-exclusively.",
|
|
||||||
vg->name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vg_is_clustered(vg) && lv_exclusive_count) {
|
|
||||||
if (lv_active_count) {
|
|
||||||
log_error("Cannot move in clustered VG %s "
|
|
||||||
"if some LVs are activated "
|
|
||||||
"exclusively while others don't.",
|
|
||||||
vg->name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
*exclusive = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lv_add_mirrors(cmd, lv_mirr, 1, 1, 0, 0, log_count,
|
if (!lv_add_mirrors(cmd, lv_mirr, 1, 1, 0, 0, log_count,
|
||||||
allocatable_pvs, alloc,
|
allocatable_pvs, alloc,
|
||||||
(arg_is_set(cmd, atomic_ARG)) ?
|
(arg_is_set(cmd, atomic_ARG)) ?
|
||||||
@ -590,83 +560,37 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
|
|||||||
return lv_mirr;
|
return lv_mirr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _activate_lv(struct cmd_context *cmd, struct logical_volume *lv_mirr,
|
|
||||||
unsigned exclusive)
|
|
||||||
{
|
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
if (exclusive || lv_is_active_exclusive(lv_mirr))
|
|
||||||
r = activate_lv_excl(cmd, lv_mirr);
|
|
||||||
else
|
|
||||||
r = activate_lv(cmd, lv_mirr);
|
|
||||||
|
|
||||||
if (!r)
|
|
||||||
stack;
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called to set up initial pvmove LV only.
|
* Called to set up initial pvmove LV only.
|
||||||
* (Not called after first or any other section completes.)
|
* (Not called after first or any other section completes.)
|
||||||
*/
|
*/
|
||||||
static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
|
static int _update_metadata(struct logical_volume *lv_mirr,
|
||||||
struct logical_volume *lv_mirr,
|
struct dm_list *lvs_changed)
|
||||||
struct dm_list *lvs_changed, unsigned exclusive)
|
|
||||||
{
|
{
|
||||||
int r = 0;
|
struct lv_list *lvl;
|
||||||
|
struct logical_volume *lv = lv_mirr;
|
||||||
|
|
||||||
log_verbose("Setting up pvmove in on-disk volume group metadata.");
|
dm_list_iterate_items(lvl, lvs_changed) {
|
||||||
if (!vg_write(vg)) {
|
lv = lvl->lv;
|
||||||
log_error("ABORTING: Volume group metadata update failed.");
|
break;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!suspend_lvs(cmd, lvs_changed, vg)) {
|
if (!lv_update_and_reload(lv))
|
||||||
log_error("ABORTING: Temporary pvmove mirror activation failed.");
|
return_0;
|
||||||
/* FIXME Add a recovery path for first time too. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Commit on-disk metadata */
|
/* Ensure mirror LV is active */
|
||||||
if (!vg_commit(vg)) {
|
if (!activate_lv_excl_local(lv_mirr->vg->cmd, lv_mirr)) {
|
||||||
log_error("ABORTING: Volume group metadata update failed.");
|
if (test_mode())
|
||||||
if (!resume_lvs(cmd, lvs_changed))
|
return 1;
|
||||||
log_error("Unable to resume logical volumes.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Activate the temporary mirror LV */
|
|
||||||
/* Only the first mirror segment gets activated as a mirror */
|
|
||||||
/* FIXME: Add option to use a log */
|
|
||||||
if (!exclusive && _pvmove_is_exclusive(cmd, vg))
|
|
||||||
exclusive = 1;
|
|
||||||
|
|
||||||
if (!_activate_lv(cmd, lv_mirr, exclusive)) {
|
|
||||||
if (test_mode()) {
|
|
||||||
r = 1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME Run --abort internally here.
|
* FIXME Run --abort internally here.
|
||||||
*/
|
*/
|
||||||
log_error("ABORTING: Temporary pvmove mirror activation failed. Run pvmove --abort.");
|
log_error("ABORTING: Temporary pvmove mirror activation failed. Run pvmove --abort.");
|
||||||
goto out;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = 1;
|
return 1;
|
||||||
|
|
||||||
out:
|
|
||||||
if (!resume_lvs(cmd, lvs_changed)) {
|
|
||||||
log_error("Unable to resume logical volumes.");
|
|
||||||
r = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r)
|
|
||||||
backup(vg);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _copy_id_components(struct cmd_context *cmd,
|
static int _copy_id_components(struct cmd_context *cmd,
|
||||||
@ -698,7 +622,6 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
|
|||||||
struct logical_volume *lv = NULL;
|
struct logical_volume *lv = NULL;
|
||||||
const char *pv_name = pv_dev_name(pv);
|
const char *pv_name = pv_dev_name(pv);
|
||||||
unsigned flags = PVMOVE_FIRST_TIME;
|
unsigned flags = PVMOVE_FIRST_TIME;
|
||||||
unsigned exclusive;
|
|
||||||
int r = ECMD_FAILED;
|
int r = ECMD_FAILED;
|
||||||
|
|
||||||
pp->found_pv = 1;
|
pp->found_pv = 1;
|
||||||
@ -745,8 +668,6 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exclusive = _pvmove_is_exclusive(cmd, vg);
|
|
||||||
|
|
||||||
if ((lv_mirr = find_pvmove_lv(vg, pv_dev(pv), PVMOVE))) {
|
if ((lv_mirr = find_pvmove_lv(vg, pv_dev(pv), PVMOVE))) {
|
||||||
log_print_unless_silent("Detected pvmove in progress for %s.", pv_name);
|
log_print_unless_silent("Detected pvmove in progress for %s.", pv_name);
|
||||||
if (pp->pv_count || lv_name)
|
if (pp->pv_count || lv_name)
|
||||||
@ -758,7 +679,7 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure mirror LV is active */
|
/* Ensure mirror LV is active */
|
||||||
if (!_activate_lv(cmd, lv_mirr, exclusive)) {
|
if (!activate_lv_excl_local(cmd, lv_mirr)) {
|
||||||
log_error("ABORTING: Temporary mirror activation failed.");
|
log_error("ABORTING: Temporary mirror activation failed.");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -783,12 +704,12 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
|
|||||||
|
|
||||||
if (!(lv_mirr = _set_up_pvmove_lv(cmd, vg, source_pvl, lv_name,
|
if (!(lv_mirr = _set_up_pvmove_lv(cmd, vg, source_pvl, lv_name,
|
||||||
allocatable_pvs, pp->alloc,
|
allocatable_pvs, pp->alloc,
|
||||||
&lvs_changed, &exclusive)))
|
&lvs_changed)))
|
||||||
goto_out;
|
goto_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lock lvs_changed and activate (with old metadata) */
|
/* Lock lvs_changed and activate (with old metadata) */
|
||||||
if (!activate_lvs(cmd, lvs_changed, exclusive))
|
if (!activate_lvs(cmd, lvs_changed))
|
||||||
goto_out;
|
goto_out;
|
||||||
|
|
||||||
/* FIXME Presence of a mirror once set PVMOVE - now remove associated logic */
|
/* FIXME Presence of a mirror once set PVMOVE - now remove associated logic */
|
||||||
@ -799,7 +720,7 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (flags & PVMOVE_FIRST_TIME)
|
if (flags & PVMOVE_FIRST_TIME)
|
||||||
if (!_update_metadata(cmd, vg, lv_mirr, lvs_changed, exclusive))
|
if (!_update_metadata(lv_mirr, lvs_changed))
|
||||||
goto_out;
|
goto_out;
|
||||||
|
|
||||||
/* LVs are all in status LOCKED */
|
/* LVs are all in status LOCKED */
|
||||||
|
Loading…
Reference in New Issue
Block a user