summaryrefslogtreecommitdiffstats
path: root/tools/vgchange.c
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2012-06-27 08:59:34 -0400
committerPeter Rajnoha <prajnoha@redhat.com>2012-06-28 09:42:47 -0400
commit95ced7a7be26499fed2ffa03d71002e73c2d3ca9 (patch)
tree464f48c0ffaacad9afa14072307ccb506fc34826 /tools/vgchange.c
parent2729720fd329f2c33cddeeded591a06fe4b6a147 (diff)
downloadlvm2-95ced7a7be26499fed2ffa03d71002e73c2d3ca9.tar.gz
lvm2-95ced7a7be26499fed2ffa03d71002e73c2d3ca9.tar.xz
lvm2-95ced7a7be26499fed2ffa03d71002e73c2d3ca9.zip
activate: add autoactivation hooks
Define an 'activation_handler' that gets called automatically on PV appearance/disappearance while processing the lvmetad_pv_found and lvmetad_pv_gone functions that are supposed to update the lvmetad state based on PV availability state. For now, the actual support is for PV appearance only, leaving room for PV disappearance support as well (which is a more complex problem to solve as this needs to count with possible device stack). Add a new activation change mode - CHANGE_AAY exposed as '--activate ay/-aay' argument ('activate automatically'). Factor out the vgchange activation functionality for use in other tools (like pvscan...).
Diffstat (limited to 'tools/vgchange.c')
-rw-r--r--tools/vgchange.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/tools/vgchange.c b/tools/vgchange.c
index fdad81f1..29562a58 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -81,8 +81,8 @@ static int _poll_lvs_in_vg(struct cmd_context *cmd,
return count;
}
-static int _activate_lvs_in_vg(struct cmd_context *cmd,
- struct volume_group *vg, int activate)
+static int _activate_lvs_in_vg(struct cmd_context *cmd, struct volume_group *vg,
+ activation_change_t activate)
{
struct lv_list *lvl;
struct logical_volume *lv;
@@ -211,35 +211,32 @@ static int _vgchange_background_polling(struct cmd_context *cmd, struct volume_g
return 1;
}
-static int _vgchange_activate(struct cmd_context *cmd, struct volume_group *vg)
+int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
+ activation_change_t activate)
{
- int lv_open, active, monitored = 0;
- int activate_arg, r = 1;
- int activate = 1;
+ int lv_open, active, monitored = 0, r = 1, do_activate = 1;
+
+ if ((activate == CHANGE_AN) || (activate == CHANGE_ALN))
+ do_activate = 0;
/*
* Safe, since we never write out new metadata here. Required for
* partial activation to work.
*/
- cmd->handles_missing_pvs = 1;
-
- activate_arg = arg_uint_value(cmd, activate_ARG, 0);
-
- if ((activate_arg == CHANGE_AN) || (activate_arg == CHANGE_ALN))
- activate = 0;
+ cmd->handles_missing_pvs = 1;
/* FIXME: Force argument to deactivate them? */
- if (!activate && (lv_open = lvs_in_vg_opened(vg))) {
+ if (!do_activate && (lv_open = lvs_in_vg_opened(vg))) {
log_error("Can't deactivate volume group \"%s\" with %d open "
"logical volume(s)", vg->name, lv_open);
return 0;
}
/* FIXME Move into library where clvmd can use it */
- if (activate)
+ if (do_activate)
check_current_backup(vg);
- if (activate && (active = lvs_in_vg_activated(vg))) {
+ if (do_activate && (active = lvs_in_vg_activated(vg))) {
log_verbose("%d logical volume(s) in volume group \"%s\" "
"already active", active, vg->name);
if (dmeventd_monitor_mode() != DMEVENTD_MONITOR_IGNORE) {
@@ -252,7 +249,7 @@ static int _vgchange_activate(struct cmd_context *cmd, struct volume_group *vg)
}
}
- if (!_activate_lvs_in_vg(cmd, vg, activate_arg))
+ if (!_activate_lvs_in_vg(cmd, vg, activate))
r = 0;
/* Print message only if there was not found a missing VG */
@@ -509,7 +506,7 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
}
if (arg_count(cmd, activate_ARG)) {
- if (!_vgchange_activate(cmd, vg))
+ if (!vgchange_activate(cmd, vg, arg_uint_value(cmd, activate_ARG, CHANGE_AY)))
return ECMD_FAILED;
}