summaryrefslogtreecommitdiff
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 10:46:19 -0500
commit98ae330ce462e00a4c96c2c274271f28b56937fc (patch)
treeb3b5a7b68abea5985bbde3efc1f075a3f5b9f4ea
parent6f6583afede02dddec41b85f896c9d4e73d87beb (diff)
downloadlvm2-dev-dct-autoactivation-setting.tar.gz
Add metadata-based autoactivation property for VG and LVdev-dct-autoactivation-setting
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. --autoactivation n|y disables|enables 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", and "" 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. 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.
-rw-r--r--lib/format_text/flags.c2
-rw-r--r--lib/metadata/lv_manip.c4
-rw-r--r--lib/metadata/metadata-exported.h6
-rw-r--r--lib/metadata/metadata.h1
-rw-r--r--lib/report/columns.h2
-rw-r--r--lib/report/properties.c4
-rw-r--r--lib/report/report.c17
-rw-r--r--test/shell/autoactivation-metadata.sh335
-rw-r--r--tools/args.h28
-rw-r--r--tools/command-lines.in10
-rw-r--r--tools/lvchange.c32
-rw-r--r--tools/lvcreate.c3
-rw-r--r--tools/vgchange.c31
-rw-r--r--tools/vgcreate.c3
14 files changed, 466 insertions, 12 deletions
diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c
index 4cee14aa7..3890a40cc 100644
--- a/lib/format_text/flags.c
+++ b/lib/format_text/flags.c
@@ -35,6 +35,7 @@ static const struct flag _vg_flags[] = {
{LVM_READ, "READ", STATUS_FLAG},
{LVM_WRITE, "WRITE", STATUS_FLAG},
{LVM_WRITE_LOCKED, "WRITE_LOCKED", COMPATIBLE_FLAG},
+ {NOAUTOACTIVATE, "NOAUTOACTIVATE", COMPATIBLE_FLAG},
{CLUSTERED, "CLUSTERED", STATUS_FLAG},
{SHARED, "SHARED", STATUS_FLAG},
{PARTIAL_VG, NULL, 0},
@@ -70,6 +71,7 @@ static const struct flag _lv_flags[] = {
{LV_REMOVE_AFTER_RESHAPE, "REMOVE_AFTER_RESHAPE", SEGTYPE_FLAG},
{LV_WRITEMOSTLY, "WRITEMOSTLY", STATUS_FLAG},
{LV_ACTIVATION_SKIP, "ACTIVATION_SKIP", COMPATIBLE_FLAG},
+ {LV_NOAUTOACTIVATE, "NOAUTOACTIVATE", COMPATIBLE_FLAG},
{LV_ERROR_WHEN_FULL, "ERROR_WHEN_FULL", COMPATIBLE_FLAG},
{LV_METADATA_FORMAT, "METADATA_FORMAT", SEGTYPE_FLAG},
{LV_CROP_METADATA, "CROP_METADATA", SEGTYPE_FLAG},
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index b38acf883..ff2a673eb 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -8569,6 +8569,10 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
lv_set_activation_skip(lv, lp->activation_skip & ACTIVATION_SKIP_SET,
lp->activation_skip & ACTIVATION_SKIP_SET_ENABLED);
+
+ if (lp->noautoactivate)
+ lv->status |= LV_NOAUTOACTIVATE;
+
/*
* Check for autoactivation.
* If the LV passes the auto activation filter, activate
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 8ae067ebc..176227818 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -57,7 +57,9 @@
#define ALLOCATABLE_PV UINT64_C(0x0000000000000008) /* PV */
#define ARCHIVED_VG ALLOCATABLE_PV /* VG, reuse same bit */
-//#define SPINDOWN_LV UINT64_C(0x0000000000000010) /* LV */
+#define LV_NOAUTOACTIVATE UINT64_C(0x0000000000000010) /* LV - also a PV flag */
+#define NOAUTOACTIVATE UINT64_C(0x0000000000000010) /* VG - also a PV flag */
+
//#define BADBLOCK_ON UINT64_C(0x0000000000000020) /* LV */
#define VISIBLE_LV UINT64_C(0x0000000000000040) /* LV */
#define FIXED_MINOR UINT64_C(0x0000000000000080) /* LV */
@@ -159,6 +161,7 @@
#define LV_CACHE_USES_CACHEVOL UINT64_C(0x4000000000000000) /* LV - also a PV flag */
+
/* Format features flags */
#define FMT_SEGMENTS 0x00000001U /* Arbitrary segment params? */
// #define FMT_MDAS 0x00000002U /* Proper metadata areas? */
@@ -972,6 +975,7 @@ struct lvcreate_params {
#define ACTIVATION_SKIP_SET_ENABLED 0x02 /* set the LV activation skip flag state to 'enabled' */
#define ACTIVATION_SKIP_IGNORE 0x04 /* request to ignore LV activation skip flag (if any) */
int activation_skip; /* activation skip flags */
+ int noautoactivate; /* 1 if --autoactivation n */
activation_change_t activate; /* non-snapshot, non-mirror */
thin_discards_t discards; /* thin */
thin_zero_t zero_new_blocks;
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index 3ea77ce2e..dfd576e3c 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -55,7 +55,6 @@
/* May any free extents on this PV be used or must they be left free? */
-#define SPINDOWN_LV UINT64_C(0x00000010) /* LV */
#define BADBLOCK_ON UINT64_C(0x00000020) /* LV */
//#define VIRTUAL UINT64_C(0x00010000) /* LV - internal use only */
#define PRECOMMITTED UINT64_C(0x00200000) /* VG - internal use only */
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 8d2f7a993..12b78b766 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -61,6 +61,7 @@ FIELD(LVS, lv, STR, "AllocPol", lvid, 10, lvallocationpolicy, lv_allocation_poli
FIELD(LVS, lv, BIN, "AllocLock", lvid, 10, lvallocationlocked, lv_allocation_locked, "Set if LV is locked against allocation changes.", 0)
FIELD(LVS, lv, BIN, "FixMin", lvid, 10, lvfixedminor, lv_fixed_minor, "Set if LV has fixed minor number assigned.", 0)
FIELD(LVS, lv, BIN, "SkipAct", lvid, 15, lvskipactivation, lv_skip_activation, "Set if LV is skipped on activation.", 0)
+FIELD(LVS, lv, BIN, "AutoAct", lvid, 0, lvautoactivation, lv_autoactivation, "Set if LV autoactivation is enabled.", 0)
FIELD(LVS, lv, STR, "WhenFull", lvid, 15, lvwhenfull, lv_when_full, "For thin pools, behavior when full.", 0)
FIELD(LVS, lv, STR, "Active", lvid, 0, lvactive, lv_active, "Active state of the LV.", 0)
FIELD(LVS, lv, BIN, "ActLocal", lvid, 10, lvactivelocally, lv_active_locally, "Set if the LV is active locally.", 0)
@@ -222,6 +223,7 @@ FIELD(VGS, vg, STR, "Attr", cmd, 5, vgstatus, vg_attr, "Various attributes - see
FIELD(VGS, vg, STR, "VPerms", cmd, 10, vgpermissions, vg_permissions, "VG permissions.", 0)
FIELD(VGS, vg, BIN, "Extendable", cmd, 0, vgextendable, vg_extendable, "Set if VG is extendable.", 0)
FIELD(VGS, vg, BIN, "Exported", cmd, 10, vgexported, vg_exported, "Set if VG is exported.", 0)
+FIELD(VGS, vg, BIN, "AutoAct", cmd, 0, vgautoactivation, vg_autoactivation, "Set if VG autoactivation is enabled.", 0)
FIELD(VGS, vg, BIN, "Partial", cmd, 10, vgpartial, vg_partial, "Set if VG is partial.", 0)
FIELD(VGS, vg, STR, "AllocPol", cmd, 10, vgallocationpolicy, vg_allocation_policy, "VG allocation policy.", 0)
FIELD(VGS, vg, BIN, "Clustered", cmd, 10, vgclustered, vg_clustered, "Set if VG is clustered.", 0)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index f2174b83c..12ea890f4 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -269,6 +269,8 @@ GET_PV_STR_PROPERTY_FN(pv_device_id_type, pv->device_id_type)
#define _vg_extendable_get prop_not_implemented_get
#define _vg_exported_set prop_not_implemented_set
#define _vg_exported_get prop_not_implemented_get
+#define _vg_autoactivation_set prop_not_implemented_set
+#define _vg_autoactivation_get prop_not_implemented_get
#define _vg_partial_set prop_not_implemented_set
#define _vg_partial_get prop_not_implemented_get
#define _vg_allocation_policy_set prop_not_implemented_set
@@ -323,6 +325,8 @@ GET_PV_STR_PROPERTY_FN(pv_device_id_type, pv->device_id_type)
#define _lv_skip_activation_get prop_not_implemented_get
#define _lv_check_needed_set prop_not_implemented_set
#define _lv_check_needed_get prop_not_implemented_get
+#define _lv_autoactivation_set prop_not_implemented_set
+#define _lv_autoactivation_get prop_not_implemented_get
#define _lv_historical_set prop_not_implemented_set
#define _lv_historical_get prop_not_implemented_get
diff --git a/lib/report/report.c b/lib/report/report.c
index 2f5811a96..222d3f4b6 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3573,6 +3573,15 @@ static int _vgexported_disp(struct dm_report *rh, struct dm_pool *mem,
return _binary_disp(rh, mem, field, exported, GET_FIRST_RESERVED_NAME(vg_exported_y), private);
}
+static int _vgautoactivation_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ const struct volume_group *vg = (const struct volume_group *)data;
+ int aa_yes = (vg->status & NOAUTOACTIVATE) ? 0 : 1;
+ return _binary_disp(rh, mem, field, aa_yes, "enabled", private);
+}
+
static int _vgpartial_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
@@ -3969,6 +3978,14 @@ static int _lvskipactivation_disp(struct dm_report *rh, struct dm_pool *mem,
return _binary_disp(rh, mem, field, skip_activation, "skip activation", private);
}
+static int _lvautoactivation_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ int aa_yes = (((const struct logical_volume *) data)->status & LV_NOAUTOACTIVATE) ? 0 : 1;
+ return _binary_disp(rh, mem, field, aa_yes, "enabled", private);
+}
+
static int _lvhistorical_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
diff --git a/test/shell/autoactivation-metadata.sh b/test/shell/autoactivation-metadata.sh
new file mode 100644
index 000000000..cb81d1e56
--- /dev/null
+++ b/test/shell/autoactivation-metadata.sh
@@ -0,0 +1,335 @@
+
+SKIP_WITH_LVMPOLLD=1
+
+RUNDIR="/run"
+test -d "$RUNDIR" || RUNDIR="/var/run"
+PVS_ONLINE_DIR="$RUNDIR/lvm/pvs_online"
+VGS_ONLINE_DIR="$RUNDIR/lvm/vgs_online"
+PVS_LOOKUP_DIR="$RUNDIR/lvm/pvs_lookup"
+
+_clear_online_files() {
+ # wait till udev is finished
+ aux udev_wait
+ rm -f "$PVS_ONLINE_DIR"/*
+ rm -f "$VGS_ONLINE_DIR"/*
+ rm -f "$PVS_LOOKUP_DIR"/*
+}
+
+. lib/inittest
+
+aux prepare_devs 1
+
+#
+# test lvchange --autoactivation
+#
+
+# default
+vgcreate $SHARED $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation "enabled"
+
+lvchange -aay $vg/$lv1
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+lvchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+_clear_online_files
+
+# --aa=n
+lvchange --autoactivation n $vg/$lv1
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation ""
+
+lvchange -aay $vg/$lv1
+check lv_field $vg/$lv1 lv_active ""
+lvchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+_clear_online_files
+
+# --aa=y
+lvchange --autoactivation y $vg/$lv1
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation "enabled"
+
+lvchange -aay $vg/$lv1
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+lvchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+_clear_online_files
+
+vgremove -y $vg
+
+#
+# test vgchange --autoactivation
+#
+
+# default
+vgcreate $SHARED $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+
+# --aa=n
+vgchange --autoactivation n $vg
+check vg_field $vg autoactivation ""
+check lv_field $vg/$lv1 autoactivation "enabled"
+
+lvchange -aay $vg/$lv1
+check lv_field $vg/$lv1 lv_active ""
+lvchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+_clear_online_files
+
+# --aa=y
+vgchange --autoactivation y $vg
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation "enabled"
+
+lvchange -aay $vg/$lv1
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+lvchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+lvchange -an $vg/$lv1
+_clear_online_files
+
+vgremove -y $vg
+
+#
+# test vgcreate --autoactivation, lvcreate --autoactivation
+#
+
+vgcreate $SHARED $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+lvcreate -n $lv2 -l1 --autoactivation y -an $vg
+lvcreate -n $lv3 -l1 --autoactivation n -an $vg
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation "enabled"
+check lv_field $vg/$lv2 autoactivation "enabled"
+check lv_field $vg/$lv3 autoactivation ""
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active "active"
+check lv_field $vg/$lv3 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+lvchange -aay $vg/$lv3
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active "active"
+check lv_field $vg/$lv3 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active "active"
+check lv_field $vg/$lv3 lv_active ""
+vgchange -an $vg
+vgremove -y $vg
+_clear_online_files
+
+vgcreate $SHARED --autoactivation y $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+lvcreate -n $lv2 -l1 --autoactivation y -an $vg
+lvcreate -n $lv3 -l1 --autoactivation n -an $vg
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation "enabled"
+check lv_field $vg/$lv2 autoactivation "enabled"
+check lv_field $vg/$lv3 autoactivation ""
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active "active"
+check lv_field $vg/$lv3 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+lvchange -aay $vg/$lv3
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active "active"
+check lv_field $vg/$lv3 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active "active"
+check lv_field $vg/$lv3 lv_active ""
+vgchange -an $vg
+vgremove -y $vg
+_clear_online_files
+
+vgcreate $SHARED --autoactivation n $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+lvcreate -n $lv2 -l1 --autoactivation y -an $vg
+lvcreate -n $lv3 -l1 --autoactivation n -an $vg
+check vg_field $vg autoactivation ""
+check lv_field $vg/$lv1 autoactivation "enabled"
+check lv_field $vg/$lv2 autoactivation "enabled"
+check lv_field $vg/$lv3 autoactivation ""
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+check lv_field $vg/$lv3 lv_active ""
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+lvchange -aay $vg/$lv3
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+check lv_field $vg/$lv3 lv_active ""
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+check lv_field $vg/$lv3 lv_active ""
+vgremove -y $vg
+_clear_online_files
+
+
+#
+# test combination of --aa and auto_activation_volume_list
+#
+
+vgcreate $SHARED $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+lvcreate -n $lv2 -l1 --autoactivation n -an $vg
+check vg_field $vg autoactivation "enabled"
+check lv_field $vg/$lv1 autoactivation "enabled"
+check lv_field $vg/$lv2 autoactivation ""
+
+# list prevents all aa, metadata settings don't matter
+aux lvmconf "activation/auto_activation_volume_list = [ ]"
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+_clear_online_files
+
+# list allows all vg aa, metadata allows lv1 -> lv1 activated
+aux lvmconf "activation/auto_activation_volume_list = [ \"$vg\" ]"
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+_clear_online_files
+
+# list allows lv1, metadata allows lv1 -> lv1 activated
+aux lvmconf "activation/auto_activation_volume_list = [ \"$vg/$lv1\" ]"
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active "active"
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+_clear_online_files
+
+# list allows lv2, metadata allows lv1 -> nothing activated
+aux lvmconf "activation/auto_activation_volume_list = [ \"$vg/$lv2\" ]"
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+_clear_online_files
+
+vgremove -y $vg
+
+vgcreate $SHARED --autoactivation n $vg "$dev1"
+lvcreate -n $lv1 -l1 -an $vg
+lvcreate -n $lv2 -l1 --autoactivation n -an $vg
+check vg_field $vg autoactivation ""
+check lv_field $vg/$lv1 autoactivation "enabled"
+check lv_field $vg/$lv2 autoactivation ""
+
+# list prevents all aa, metadata settings don't matter
+aux lvmconf "activation/auto_activation_volume_list = [ ]"
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+_clear_online_files
+
+# list allows lv1, metadata disallows vg -> nothing activated
+aux lvmconf "activation/auto_activation_volume_list = [ \"$vg/$lv1\" ]"
+vgchange -aay $vg
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+lvchange -aay $vg/$lv1
+lvchange -aay $vg/$lv2
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+pvscan --cache -aay "$dev1"
+check lv_field $vg/$lv1 lv_active ""
+check lv_field $vg/$lv2 lv_active ""
+vgchange -an $vg
+_clear_online_files
+
+vgremove -y $vg
+
diff --git a/tools/args.h b/tools/args.h
index c1d32be32..875318c3d 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -87,6 +87,17 @@ arg(atversion_ARG, '\0', "atversion", string_VAL, 0, 0,
"which does not contain any newer settings for which LVM would\n"
"issue a warning message when checking the configuration.\n")
+arg(autoactivation_ARG, '\0', "autoactivation", bool_VAL, 0, 0,
+ "Set the autoactivation property on a VG or LV.\n"
+ "Display the property with vgs or lvs \"-o autoactivation\".\n"
+ "When the autoactivation property is disabled, the VG or LV\n"
+ "will not be activated by a command doing autoactivation\n"
+ "(vgchange, lvchange, or pvscan using -aay.)\n"
+ "If autoactivation is disabled on a VG, no LVs will be autoactivated\n"
+ "in that VG, and the LV autoactivation property has no effect.\n"
+ "If autoactivation is enabled on a VG, autoactivation can be disabled\n"
+ "for individual LVs.\n")
+
arg(binary_ARG, '\0', "binary", 0, 0, 0,
"Use binary values \"0\" or \"1\" instead of descriptive literal values\n"
"for columns that have exactly two valid values to report (not counting\n"
@@ -960,12 +971,17 @@ arg(activate_ARG, 'a', "activate", activation_VAL, 0, 0,
"link and present this as the name of the device.\n"
"The location and name of the underlying device node may depend on\n"
"the distribution, configuration (e.g. udev), or release version.\n"
- "\\fBay\\fP specifies autoactivation, in which case an LV is activated\n"
- "only if it matches an item in lvm.conf activation/auto_activation_volume_list.\n"
- "If the list is not set, all LVs are considered to match, and if\n"
- "if the list is set but empty, no LVs match.\n"
- "Autoactivation should be used during system boot to make it possible\n"
- "to select which LVs should be automatically activated by the system.\n"
+ "\\fBay\\fP specifies autoactivation, which is used by system-generated\n"
+ "activation commands. By default, LVs are autoactivated.\n"
+ "An autoactivation property can be set on a VG or LV to disable autoactivation,\n"
+ "see --autoactivation y|n in vgchange, lvchange, vgcreate, and lvcreate.\n"
+ "Display the property with vgs or lvs \"-o autoactivation\".\n"
+ "The lvm.conf auto_activation_volume_list includes names of VGs or LVs\n"
+ "that should be autoactivated, and anything not listed is not autoactivated.\n"
+ "When auto_activation_volume_list is undefined (the default), it has no effect.\n"
+ "If auto_activation_volume_list is defined and empty, no LVs are autoactivated.\n"
+ "Items included by auto_activation_volume_list will not be autoactivated if\n"
+ "the autoactivation property has been disabled.\n"
"See \\fBlvmlockd\\fP(8) for more information about activation options \\fBey\\fP and \\fBsy\\fP for shared VGs.\n"
"#lvcreate\n"
"Controls the active state of the new LV.\n"
diff --git a/tools/command-lines.in b/tools/command-lines.in
index 528811f52..b225636f5 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -227,7 +227,8 @@ OO_LVCHANGE_META: --addtag Tag, --deltag Tag,
--errorwhenfull Bool, --discards Discards, --zero Bool,
--cachemode CacheMode, --cachepolicy String, --cachesettings String,
--minrecoveryrate SizeKB, --maxrecoveryrate SizeKB,
---writebehind Number, --writemostly WriteMostlyPV, --persistent n
+--writebehind Number, --writemostly WriteMostlyPV, --persistent n,
+--autoactivation Bool
# It's unfortunate that activate needs to be optionally allowed here;
# it should only be used explicitly, but it's been previously allowed
@@ -799,7 +800,7 @@ OO_LVCREATE: --addtag Tag, --alloc Alloc, --autobackup Bool, --activate Active,
--metadataprofile String, --minor Number, --monitor Bool, --name String, --nosync,
--noudevsync, --permission Permission, --persistent Bool, --readahead Readahead,
--reportformat ReportFmt, --setactivationskip Bool, --wipesignatures Bool,
---zero Bool
+--zero Bool, --autoactivation Bool
OO_LVCREATE_CACHE: --cachemode CacheMode, --cachepolicy String, --cachesettings String,
--chunksize SizeKB, --cachemetadataformat CacheMetadataFormat
@@ -1662,7 +1663,8 @@ OO_VGCHANGE_META: --addtag Tag, --deltag Tag,
--logicalvolume Uint32, --maxphysicalvolumes Uint32, --alloc Alloc, --uuid,
--pvmetadatacopies MetadataCopiesPV, --vgmetadatacopies MetadataCopiesVG,
--physicalextentsize SizeMB, --resizeable Bool,
---profile String, --detachprofile, --metadataprofile String
+--profile String, --detachprofile, --metadataprofile String,
+--autoactivation Bool
vgchange OO_VGCHANGE_META
OO: --poll Bool, OO_VGCHANGE
@@ -1742,7 +1744,7 @@ OO: --addtag Tag, --alloc Alloc, --autobackup Bool, --clustered Bool, --maxlogic
--physicalextentsize SizeMB, --force, --zero Bool, --labelsector Number,
--metadatasize SizeMB, --pvmetadatacopies MetadataCopiesPV, --vgmetadatacopies MetadataCopiesVG,
--reportformat ReportFmt, --dataalignment SizeKB, --dataalignmentoffset SizeKB,
---shared, --systemid String, --locktype LockType
+--shared, --systemid String, --locktype LockType, --autoactivation Bool
ID: vgcreate_general
---
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 0189c365e..9f9238bee 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, autoactivation_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,
+ autoactivation_ARG,
-1
};
@@ -1250,6 +1277,11 @@ static int _lvchange_properties_single(struct cmd_context *cmd,
doit += _lvchange_activation_skip(lv, &mr);
break;
+ case autoactivation_ARG:
+ docmds++;
+ doit += _lvchange_autoactivation(lv, &mr);
+ break;
+
case compression_ARG:
docmds++;
doit += _lvchange_compression(lv, &mr);
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 1ce561fc3..bd04bb677 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -742,6 +742,9 @@ static int _read_activation_params(struct cmd_context *cmd,
if (arg_is_set(cmd, ignoreactivationskip_ARG))
lp->activation_skip |= ACTIVATION_SKIP_IGNORE;
+ if (arg_is_set(cmd, autoactivation_ARG) && !arg_int_value(cmd, autoactivation_ARG, 1))
+ lp->noautoactivate = 1;
+
return 1;
}
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 58c8ddc84..d9d285605 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -117,6 +117,10 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd, struct volume_group *vg,
!lv_passes_auto_activation_filter(cmd, lv))
continue;
+ /* vg NOAUTOACTIVATE flag was already checked */
+ if ((activate == CHANGE_AAY) && (lv->status & LV_NOAUTOACTIVATE))
+ continue;
+
expected_count++;
if (!lv_change_activate(cmd, lv, activate)) {
@@ -209,6 +213,11 @@ int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
return 0;
}
+ if ((activate == CHANGE_AAY) && (vg->status & NOAUTOACTIVATE)) {
+ log_debug("Autoactivation is disabled for VG %s.", vg->name);
+ return 1;
+ }
+
/*
* Safe, since we never write out new metadata here. Required for
* partial activation to work.
@@ -317,6 +326,26 @@ static int _vgchange_resizeable(struct cmd_context *cmd,
return 1;
}
+static int _vgchange_autoactivation(struct cmd_context *cmd,
+ struct volume_group *vg)
+{
+ int aa_no_arg = !arg_int_value(cmd, autoactivation_ARG, 0);
+ int aa_no_meta = (vg->status & NOAUTOACTIVATE) ? 1 : 0;
+
+ if ((aa_no_arg && aa_no_meta) || (!aa_no_arg && !aa_no_meta)) {
+ log_error("Volume group autoactivation is already %s.",
+ aa_no_arg ? "no" : "yes");
+ return 0;
+ }
+
+ if (aa_no_arg)
+ vg->status |= NOAUTOACTIVATE;
+ else
+ vg->status &= ~NOAUTOACTIVATE;
+
+ return 1;
+}
+
static int _vgchange_logicalvolume(struct cmd_context *cmd,
struct volume_group *vg)
{
@@ -619,6 +648,7 @@ static int _vgchange_single(struct cmd_context *cmd, const char *vg_name,
{ logicalvolume_ARG, &_vgchange_logicalvolume },
{ maxphysicalvolumes_ARG, &_vgchange_physicalvolumes },
{ resizeable_ARG, &_vgchange_resizeable },
+ { autoactivation_ARG, &_vgchange_autoactivation },
{ deltag_ARG, &_vgchange_deltag },
{ addtag_ARG, &_vgchange_addtag },
{ physicalextentsize_ARG, &_vgchange_pesize },
@@ -707,6 +737,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
arg_is_set(cmd, logicalvolume_ARG) ||
arg_is_set(cmd, maxphysicalvolumes_ARG) ||
arg_is_set(cmd, resizeable_ARG) ||
+ arg_is_set(cmd, autoactivation_ARG) ||
arg_is_set(cmd, uuid_ARG) ||
arg_is_set(cmd, physicalextentsize_ARG) ||
arg_is_set(cmd, alloc_ARG) ||
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index 73066e9a4..819ddfeff 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -118,6 +118,9 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
!vg_set_mda_copies(vg, vp_new.vgmetadatacopies))
goto_bad;
+ if (arg_is_set(cmd, autoactivation_ARG) && !arg_int_value(cmd, autoactivation_ARG, 1))
+ vg->status |= NOAUTOACTIVATE;
+
/* attach the pv's */
if (!vg_extend_each_pv(vg, &pp))
goto_bad;