summaryrefslogtreecommitdiff
path: root/tools/lvchange.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2021-04-01 17:20:00 -0500
committerDavid Teigland <teigland@redhat.com>2021-04-07 15:32:49 -0500
commit0a28e3c44b05470061f15516e1c89a84fa2e8569 (patch)
tree887956f2093739bade20e57c94ecfc03f3bc463a /tools/lvchange.c
parent6f6583afede02dddec41b85f896c9d4e73d87beb (diff)
downloadlvm2-0a28e3c44b05470061f15516e1c89a84fa2e8569.tar.gz
Add metadata-based autoactivation property for VG and LV
The autoactivation property can be specified in lvcreate or vgcreate for new LVs/VGs, and the property can be changed by lvchange or vgchange for existing LVs/VGs. --setautoactivation y|n enables|disables autoactivation of a VG or LV. Autoactivation is enabled by default, which is consistent with past behavior. The disabled state is stored as a new flag in the VG metadata, and the absence of the flag allows autoactivation. If autoactivation is disabled for the VG, then no LVs in the VG will be autoactivated (the LV autoactivation property will have no effect.) When autoactivation is enabled for the VG, then autoactivation can be controlled on individual LVs. The state of this property can be reported for LVs/VGs using the "-o autoactivation" option in lvs/vgs commands, which will report "enabled", or "" for the disabled state. Previous versions of lvm do not recognize this property. Since autoactivation is enabled by default, the disabled setting will have no effect in older lvm versions. If the VG is modified by older lvm versions, the disabled state will also be dropped from the metadata. The autoactivation property is an alternative to using the lvm.conf auto_activation_volume_list, which is still applied to to VGs/LVs in addition to the new property. If VG or LV autoactivation is disabled either in metadata or in auto_activation_volume_list, it will not be autoactivated. An autoactivation command will silently skip activating an LV when the autoactivation property is disabled. To determine the effective autoactivation behavior for a specific LV, multiple settings would need to be checked: the VG autoactivation property, the LV autoactivation property, the auto_activation_volume_list. The "activation skip" property would also be relevant, since it applies to both normal and auto activation.
Diffstat (limited to 'tools/lvchange.c')
-rw-r--r--tools/lvchange.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 0189c365e..8293f5035 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -215,6 +215,10 @@ static int _lvchange_activate(struct cmd_context *cmd, struct logical_volume *lv
!lv_passes_auto_activation_filter(cmd, lv))
return 1;
+ if ((activate == CHANGE_AAY) &&
+ ((lv->status & LV_NOAUTOACTIVATE) || (lv->vg->status & NOAUTOACTIVATE)))
+ return 1;
+
if (!lv_change_activate(cmd, lv, activate))
return_0;
@@ -1009,6 +1013,28 @@ static int _lvchange_activation_skip(struct logical_volume *lv, uint32_t *mr)
return 1;
}
+static int _lvchange_autoactivation(struct logical_volume *lv, uint32_t *mr)
+{
+ int aa_no_arg = !arg_int_value(lv->vg->cmd, setautoactivation_ARG, 0);
+ int aa_no_meta = (lv->status & LV_NOAUTOACTIVATE);
+
+ if ((aa_no_arg && aa_no_meta) || (!aa_no_arg && !aa_no_meta))
+ return 1;
+
+ if (aa_no_arg)
+ lv->status |= LV_NOAUTOACTIVATE;
+ else
+ lv->status &= ~LV_NOAUTOACTIVATE;
+
+ log_verbose("Changing autoactivation flag to %s for LV %s.",
+ display_lvname(lv), aa_no_arg ? "no" : "yes");
+
+ /* Request caller to commit+backup metadata */
+ *mr |= MR_COMMIT;
+
+ return 1;
+}
+
static int _lvchange_compression(struct logical_volume *lv, uint32_t *mr)
{
struct cmd_context *cmd = lv->vg->cmd;
@@ -1112,6 +1138,7 @@ static int _option_allows_group_commit(int opt_enum)
metadataprofile_ARG,
detachprofile_ARG,
setactivationskip_ARG,
+ setautoactivation_ARG,
-1
};
@@ -1250,6 +1277,11 @@ static int _lvchange_properties_single(struct cmd_context *cmd,
doit += _lvchange_activation_skip(lv, &mr);
break;
+ case setautoactivation_ARG:
+ docmds++;
+ doit += _lvchange_autoactivation(lv, &mr);
+ break;
+
case compression_ARG:
docmds++;
doit += _lvchange_compression(lv, &mr);