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

tools: add common lv_change_activate

Move common code for changing activation state from
vgchange and lvchange to one function.

Fix the order of checks - so we always implicitelly
activate snapshots and thin volumes in exclusive mode,
and we do not allow local deactivation for them.
This commit is contained in:
Zdenek Kabelac 2013-04-11 13:51:08 +02:00
parent 698137ec38
commit a81a2406f1
5 changed files with 56 additions and 67 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.99 -
===================================
Add lv_change_activate() for common activation code in vg/lvchange.
Revert change that allowed identical table reload for RAID.
New lvchange arg, '--syncaction' allows scrubbing of RAID LVs.
Improve RAID kernel status retrieval to include sync_action/mismatch_cnt.

View File

@ -219,44 +219,12 @@ static int _lvchange_activate(struct cmd_context *cmd, struct logical_volume *lv
if (lv_is_cow(lv) && !lv_is_virtual_origin(origin_from_cow(lv)))
lv = origin_from_cow(lv);
if (activate == CHANGE_AAY) {
if (!lv_passes_auto_activation_filter(cmd, lv))
if ((activate == CHANGE_AAY) &&
!lv_passes_auto_activation_filter(cmd, lv))
return 1;
activate = CHANGE_ALY;
}
if (activate == CHANGE_ALN) {
log_verbose("Deactivating logical volume \"%s\" locally",
lv->name);
if (!deactivate_lv_local(cmd, lv))
if (!lv_change_activate(cmd, lv, activate))
return_0;
} else if (activate == CHANGE_AN) {
log_verbose("Deactivating logical volume \"%s\"", lv->name);
if (!deactivate_lv(cmd, lv))
return_0;
} else {
if ((activate == CHANGE_AE) ||
lv_is_origin(lv) ||
lv_is_thin_type(lv)) {
log_verbose("Activating logical volume \"%s\" "
"exclusively", lv->name);
if (!activate_lv_excl(cmd, lv))
return_0;
} else if (activate == CHANGE_ALY) {
log_verbose("Activating logical volume \"%s\" locally",
lv->name);
if (!activate_lv_local(cmd, lv))
return_0;
} else {
log_verbose("Activating logical volume \"%s\"",
lv->name);
if (!activate_lv(cmd, lv))
return_0;
}
if (background_polling())
lv_spawn_background_polling(cmd, lv);
}
return 1;
}

View File

@ -1296,6 +1296,51 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
return 1;
}
/* Shared code for changing activation state for vgchange/lvchange */
int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv,
activation_change_t activate)
{
if (activate == CHANGE_AN) {
log_verbose("Deactivating logical volume \"%s\"", lv->name);
if (!deactivate_lv(cmd, lv))
return_0;
return 1;
} else if ((activate == CHANGE_AE) ||
lv_is_origin(lv) ||
lv_is_thin_type(lv)) {
if (activate == CHANGE_ALN) {
/* origin or thin, all others have _AE */
/* other types of activation are implicitly exclusive */
/* Note: the order of tests is mandatory */
log_error("Cannot deactivate \"%s\" locally.", lv->name);
return 0;
}
log_verbose("Activating logical volume \"%s\" exclusively.", lv->name);
if (!activate_lv_excl(cmd, lv))
return_0;
} else if (activate == CHANGE_ALN) {
log_verbose("Deactivating logical volume \"%s\" locally.", lv->name);
if (!deactivate_lv_local(cmd, lv))
return_0;
return 1;
} else if ((activate == CHANGE_ALY) || (activate == CHANGE_AAY)) {
log_verbose("Activating logical volume \"%s\" locally.", lv->name);
if (!activate_lv_local(cmd, lv))
return_0;
} else { /* CHANGE_AY */
log_verbose("Activating logical volume \"%s\".", lv->name);
if (!activate_lv(cmd, lv))
return_0;
}
/* CHANGE_AN/ALN is not getting here */
if (background_polling() &&
(lv->status & (PVMOVE|CONVERTING|MERGING)))
lv_spawn_background_polling(cmd, lv);
return 1;
}
int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv)
{
int r = 0;

View File

@ -101,6 +101,8 @@ void vgcreate_params_set_defaults(struct vgcreate_params *vp_def,
int vgcreate_params_set_from_args(struct cmd_context *cmd,
struct vgcreate_params *vp_new,
struct vgcreate_params *vp_def);
int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv,
activation_change_t activate);
int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv);
int vg_refresh_visible(struct cmd_context *cmd, struct volume_group *vg);
void lv_spawn_background_polling(struct cmd_context *cmd,

View File

@ -131,43 +131,16 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, struct volume_group *vg,
continue;
}
if (activate == CHANGE_AAY && !lv_passes_auto_activation_filter(cmd, lv))
if ((activate == CHANGE_AAY) &&
!lv_passes_auto_activation_filter(cmd, lv))
continue;
expected_count++;
if (activate == CHANGE_AN) {
if (!deactivate_lv(cmd, lv)) {
if (!lv_change_activate(cmd, lv, activate)) {
stack;
continue;
}
} else if (activate == CHANGE_ALN) {
if (!deactivate_lv_local(cmd, lv)) {
stack;
continue;
}
} else if ((activate == CHANGE_AE) ||
lv_is_origin(lv) ||
lv_is_thin_type(lv)) {
/* FIXME: duplicated test code with lvchange */
if (!activate_lv_excl(cmd, lv)) {
stack;
continue;
}
} else if (activate == CHANGE_AAY || activate == CHANGE_ALY) {
if (!activate_lv_local(cmd, lv)) {
stack;
continue;
}
} else if (!activate_lv(cmd, lv)) {
stack;
continue;
}
if (background_polling() &&
activate != CHANGE_AN && activate != CHANGE_ALN &&
(lv->status & (PVMOVE|CONVERTING|MERGING)))
lv_spawn_background_polling(cmd, lv);
count++;
}