429878
From 25dbe3dd825a629ff7f67cb43342cc345071d3f7 Mon Sep 17 00:00:00 2001
429878
From: David Teigland <teigland@redhat.com>
429878
Date: Wed, 24 Nov 2021 16:03:39 -0600
ab86b0
Subject: [PATCH 15/54] man: lvmautoactivation
429878
429878
new topical man page describing autoactivation
429878
---
429878
 man/Makefile.in              |   2 +-
429878
 man/lvm.8_main               |   1 +
429878
 man/lvmautoactivation.7_main | 280 +++++++++++++++++++++++++++++++++++
429878
 man/pvscan.8_des             |  63 ++++----
429878
 4 files changed, 309 insertions(+), 37 deletions(-)
429878
 create mode 100644 man/lvmautoactivation.7_main
429878
429878
diff --git a/man/Makefile.in b/man/Makefile.in
429878
index 40248d640..ba6f2046f 100644
429878
--- a/man/Makefile.in
429878
+++ b/man/Makefile.in
429878
@@ -33,7 +33,7 @@ CMIRRORDMAN = cmirrord.8
429878
 LVMDBUSDMAN = lvmdbusd.8
429878
 
429878
 MAN5=lvm.conf.5
429878
-MAN7=lvmsystemid.7 lvmreport.7 lvmraid.7
429878
+MAN7=lvmsystemid.7 lvmreport.7 lvmraid.7 lvmautoactivation.7
429878
 
429878
 MAN8=lvm.8 lvmdump.8 lvm-fullreport.8 lvm-lvpoll.8 \
429878
      lvcreate.8 lvchange.8 lvmconfig.8 lvconvert.8 lvdisplay.8 \
429878
diff --git a/man/lvm.8_main b/man/lvm.8_main
429878
index 6f86d0353..a008a3bc0 100644
429878
--- a/man/lvm.8_main
429878
+++ b/man/lvm.8_main
429878
@@ -579,6 +579,7 @@ Prepends source file name and code line number with libdm debugging.
429878
 .BR lvmraid (7),
429878
 .BR lvmthin (7),
429878
 .BR lvmcache (7),
429878
+.BR lvmautoactivation (7),
429878
 .P
429878
 .BR dmsetup (8),
429878
 .BR dmstats (8),
429878
diff --git a/man/lvmautoactivation.7_main b/man/lvmautoactivation.7_main
429878
new file mode 100644
429878
index 000000000..87c15a3d1
429878
--- /dev/null
429878
+++ b/man/lvmautoactivation.7_main
429878
@@ -0,0 +1,280 @@
429878
+.TH "LVMAUTOACTIVATION" "7" "LVM TOOLS #VERSION#" "Red Hat, Inc" "\""
429878
+.
429878
+.SH NAME
429878
+.
429878
+lvmautoactivation \(em LVM autoactivation
429878
+.
429878
+.SH DESCRIPTION
429878
+.
429878
+Autoactivation is the activation of LVs performed automatically by the
429878
+system in response to LVM devices being attached to the machine.  When all
429878
+PVs in a VG have been attached, the VG is complete, and LVs in the VG are
429878
+activated.
429878
+.P
429878
+Autoactivation of VGs, or specific LVs, can be prevented using vgchange or
429878
+lvchange --setautoactivation n.  The lvm.conf auto_activation_volume_list
429878
+is another way to limit autoactivation.
429878
+.P
429878
+The most common form of autoactivation is "event based", in which complete
429878
+VGs are activated in response to uevents which occur during system startup
429878
+or at any time after the system has started.  Another form of
429878
+autoactivation is "service based" in which complete VGs are activated at a
429878
+fixed point during system startup by a systemd service, and are not
429878
+activated in response to uevents.  This can be controlled with the
429878
+lvm.conf setting event_activation.
429878
+.P
429878
+Event based autoactivation is driven by udev, udev rules, and systemd.
429878
+When a device is attached to a machine, a uevent is generated by the
429878
+kernel to notify userspace of the new device.  systemd-udev runs udev
429878
+rules to process the new device.  Udev rules use blkid to identify the
429878
+device as an LVM PV and then execute the lvm-specific udev rule for the
429878
+device, which triggers autoactivation.
429878
+.P
429878
+There are two variations of event based autoactivation that may be used a
429878
+system, depending on the LVM udev rule that is installed (found in
429878
+/lib/udev/rules.d/.)  The following summarizes the steps in each rule
429878
+which lead to autoactivation:
429878
+.P
429878
+.B 69-dm-lvm-metad.rules
429878
+.
429878
+.IP \[bu] 2
429878
+device /dev/name with major:minor X:Y is attached to the machine
429878
+.
429878
+.IP \[bu] 2
429878
+systemd/udev runs blkid to identify /dev/name as an LVM PV
429878
+.
429878
+.IP \[bu] 2
429878
+udev rule 69-dm-lvm-metad.rules is run for /dev/name
429878
+.
429878
+.IP \[bu] 2
429878
+the lvm udev rule runs the systemd service lvm2-pvscan@X:Yservice
429878
+.
429878
+.IP \[bu] 2
429878
+the lvm2-pvscan service runs:
429878
+.br
429878
+pvscan --cache -aay --major X --minor Y
429878
+.
429878
+.IP \[bu] 2
429878
+pvscan reads the device, records that the PV is online
429878
+(see pvs_online), and checks if the VG is complete.
429878
+.
429878
+.IP \[bu] 2
429878
+if the VG is complete, pvscan creates the vgs_online temp file,
429878
+and activates the VG.
429878
+.
429878
+.IP \[bu] 2
429878
+the activation command output can be seen from
429878
+systemctl status lvm2-pvscan*
429878
+.P
429878
+.B 69-dm-lvm.rules
429878
+.
429878
+.IP \[bu] 2
429878
+device /dev/name with major:minor X:Y is attached to the machine
429878
+.
429878
+.IP \[bu] 2
429878
+systemd/udev runs blkid to identify /dev/name as an LVM PV
429878
+.
429878
+.IP \[bu] 2
429878
+udev rule 69-dm-lvm.rules is run for /dev/name
429878
+.
429878
+.IP \[bu] 2
429878
+the lvm udev rule runs:
429878
+.br
429878
+pvscan --cache --listvg --checkcomplete --vgonline
429878
+.br
429878
+--autoactivation event --udevoutput --journal=output /dev/name
429878
+.
429878
+.IP \[bu] 2
429878
+pvscan reads the device, records that the PV is online
429878
+(see pvs_online), and checks if the VG is complete.
429878
+.
429878
+.IP \[bu] 2
429878
+if the VG is complete, pvscan creates the vgs_online temp file,
429878
+and prints the name of the VG for the udev rule to import:
429878
+LVM_VG_NAME_COMPLETE='vgname'
429878
+.
429878
+.IP \[bu] 2
429878
+if the lvm udev rule sees LVM_VG_NAME_COMPLETE from pvscan,
429878
+it activates the VG using a transient systemd service named
429878
+lvm-activate-<vgname>.
429878
+.
429878
+.IP \[bu] 2
429878
+the lvm-activate-<vgname> service runs
429878
+.br
429878
+vgchange -aay --autoactivation event <vgname>
429878
+.
429878
+.IP \[bu] 2
429878
+the activation command output can be seen from
429878
+systemctl status lvm-activate-<vgname>
429878
+.P
429878
+.
429878
+.SS pvscan options
429878
+.P
429878
+.B --cache
429878
+.br
429878
+Read the <device> arg (and only that device), and record that
429878
+the PV is online by creating the /run/lvm/pvs_online/<pvid>
429878
+file containing the name of the VG and the device for the PV.
429878
+.P
429878
+.B -aay
429878
+.br
429878
+Activate the VG from the pvscan command
429878
+(includes implicit --checkcomplete and --vgonline.)
429878
+.P
429878
+.B --checkcomplete
429878
+.br
429878
+Check if the VG is complete, i.e. all PVs are present on
429878
+the system, by checking /run/lvm/pvs_online/<pvid> files.
429878
+.P
429878
+.B --vgonline
429878
+.br
429878
+Create /run/lvm/vgs_online/<vgname> if the VG is complete
429878
+(used to ensure only one command performs activation.)
429878
+.P
429878
+.B --autoactivation event
429878
+.br
429878
+Inform the command it is used for event based autoactivation.
429878
+.P
429878
+.B --listvg
429878
+.br
429878
+Print the name of the VG using the device.
429878
+.P
429878
+.B --udevoutput
429878
+.br
429878
+Only print output that can be imported to the udev rule,
429878
+using the udev environment key format, i.e. NAME='value'.
429878
+.P
429878
+.B --journal=output
429878
+.br
429878
+Send standard command output to the journal (when stdout
429878
+is reserved for udev output.)
429878
+.P
429878
+.SS Temp files
429878
+.P
429878
+Autoactivation commands use a number of temp files in /run/lvm (with the
429878
+expectation that /run is cleared between boots.)
429878
+.P
429878
+.B pvs_online
429878
+.br
429878
+pvscan --cache creates a file here for each PV that is attached.  The file
429878
+is named with the PVID and contains the VG name and device information.
429878
+The existence of the file is used to determine when all PVs for a given VG
429878
+are present.  The device information in these files is also used to
429878
+optimize locating devices for a VG when the VG is activated.
429878
+.P
429878
+.B pvs_lookup
429878
+.br
429878
+pvscan --cache creates a file here named for a VG (if one doesn't already
429878
+exist.)  The file contains a list of PVIDs in the VG.  This is needed when
429878
+a PV is processed which has no VG metadata, in which case the list of
429878
+PVIDs from the lookup file is used to check if the VG is complete.
429878
+.P
429878
+.B vgs_online
429878
+.br
429878
+The first activation command (pvscan or vgchange) to create a file here,
429878
+named for the VG, will activate the VG.  This resolves a race when
429878
+concurrent commands attempt to activate a VG at once.
429878
+.
429878
+.SH EXAMPLES
429878
+.P
429878
+VG "vg" contains two PVs:
429878
+.nf
429878
+$ pvs -o name,vgname,uuid /dev/sdb /dev/sdc
429878
+  PV         VG PV UUID                               
429878
+  /dev/sdb   vg 1uKpaT-lFOZ-NLHX-j4jI-OBi1-QpdE-HZ5hZY
429878
+  /dev/sdc   vg 5J3tM8-aIPe-2vbd-DBe7-bvRq-TGj0-DaKV2G
429878
+.fi
429878
+.P
429878
+use of --cache:
429878
+.nf
429878
+$ pvscan --cache /dev/sdb
429878
+  pvscan[12922] PV /dev/sdb online.
429878
+$ pvscan --cache /dev/sdc
429878
+  pvscan[12923] PV /dev/sdc online.
429878
+
429878
+$ cat /run/lvm/pvs_online/1uKpaTlFOZNLHXj4jIOBi1QpdEHZ5hZY 
429878
+8:16
429878
+vg:vg
429878
+dev:/dev/sdb
429878
+$ cat /run/lvm/pvs_online/5J3tM8aIPe2vbdDBe7bvRqTGj0DaKV2G 
429878
+8:32
429878
+vg:vg
429878
+dev:/dev/sdc
429878
+.fi
429878
+.P
429878
+use of -aay:
429878
+.nf
429878
+$ pvscan --cache -aay /dev/sdb
429878
+  pvscan[12935] PV /dev/sdb online, VG vg incomplete (need 1).
429878
+$ pvscan --cache -aay /dev/sdc
429878
+  pvscan[12936] PV /dev/sdc online, VG vg is complete.
429878
+  pvscan[12936] VG vg run autoactivation.
429878
+  1 logical volume(s) in volume group "vg" now active
429878
+
429878
+$ cat /run/lvm/pvs_online/1uKpaTlFOZNLHXj4jIOBi1QpdEHZ5hZY 
429878
+8:16
429878
+vg:vg
429878
+dev:/dev/sdb
429878
+$ cat /run/lvm/pvs_online/5J3tM8aIPe2vbdDBe7bvRqTGj0DaKV2G 
429878
+8:32
429878
+vg:vg
429878
+dev:/dev/sdc
429878
+$ ls /run/lvm/vgs_online/vg 
429878
+/run/lvm/vgs_online/vg
429878
+.fi
429878
+.P
429878
+use of --listvg:
429878
+.nf
429878
+$ pvscan --cache --listvg /dev/sdb
429878
+  VG vg
429878
+$ pvscan --cache --listvg /dev/sdc
429878
+  VG vg
429878
+
429878
+$ cat /run/lvm/pvs_online/1uKpaTlFOZNLHXj4jIOBi1QpdEHZ5hZY 
429878
+8:16
429878
+vg:vg
429878
+dev:/dev/sdb
429878
+$ cat /run/lvm/pvs_online/5J3tM8aIPe2vbdDBe7bvRqTGj0DaKV2G 
429878
+8:32
429878
+vg:vg
429878
+dev:/dev/sdc
429878
+.fi
429878
+.P
429878
+use of --checkcomplete:
429878
+.nf
429878
+$ pvscan --cache --listvg --checkcomplete --vgonline /dev/sdb
429878
+  pvscan[12996] PV /dev/sdb online, VG vg incomplete (need 1).
429878
+  VG vg incomplete
429878
+$ pvscan --cache --listvg --checkcomplete --vgonline /dev/sdc
429878
+  pvscan[12997] PV /dev/sdc online, VG vg is complete.
429878
+  VG vg complete
429878
+.fi
429878
+.P
429878
+use of --udevoutput:
429878
+.nf
429878
+$ pvscan --cache --listvg --checkcomplete --vgonline --udevoutput /dev/sdb
429878
+LVM_VG_NAME_INCOMPLETE='vg'
429878
+$ pvscan --cache --listvg --checkcomplete --vgonline --udevoutput /dev/sdc
429878
+LVM_VG_NAME_COMPLETE='vg'
429878
+.fi
429878
+.P
429878
+use of --listlvs:
429878
+.nf
429878
+$ lvs -o name,devices vg
429878
+  LV    Devices                
429878
+  lvol0 /dev/sdb(0)            
429878
+  lvol1 /dev/sdc(0)            
429878
+  lvol2 /dev/sdb(1),/dev/sdc(1)
429878
+
429878
+$ pvscan --cache --listlvs --checkcomplete /dev/sdb
429878
+  pvscan[13288] PV /dev/sdb online, VG vg incomplete (need 1).
429878
+  VG vg incomplete
429878
+  LV vg/lvol0 complete
429878
+  LV vg/lvol2 incomplete
429878
+$ pvscan --cache --listlvs --checkcomplete /dev/sdc
429878
+  pvscan[13289] PV /dev/sdc online, VG vg is complete.
429878
+  VG vg complete
429878
+  LV vg/lvol1 complete
429878
+  LV vg/lvol2 complete
429878
+.fi
429878
+
429878
diff --git a/man/pvscan.8_des b/man/pvscan.8_des
429878
index b20b987da..4c5929955 100644
429878
--- a/man/pvscan.8_des
429878
+++ b/man/pvscan.8_des
429878
@@ -4,56 +4,47 @@ like
429878
 or
429878
 .BR pvdisplay (8).
429878
 .P
429878
-When the --cache and -aay options are used, pvscan records which PVs are
429878
-available on the system, and activates LVs in completed VGs.  A VG is
429878
-complete when pvscan sees that the final PV in the VG has appeared.  This
429878
-is used by event-based system startup (systemd, udev) to activate LVs.
429878
-.P
429878
-The four main variations of this are:
429878
+When --cache is used, pvscan updates runtime lvm state on the system, or
429878
+with -aay performs autoactivation.
429878
 .P
429878
 .B pvscan --cache
429878
 .I device
429878
 .P
429878
-If device is present, lvm adds a record that the PV on device is online.
429878
+If device is present, lvm records that the PV on device is online.
429878
 If device is not present, lvm removes the online record for the PV.
429878
-In most cases, the pvscan will only read the named devices.
429878
+pvscan only reads the named device.
429878
 .P
429878
-.B pvscan --cache -aay
429878
-.IR device ...
429878
+.B pvscan --cache
429878
 .P
429878
-This begins by performing the same steps as above.  Afterward, if the VG
429878
-for the specified PV is complete, then pvscan will activate LVs in the VG
429878
-(the same as vgchange -aay vgname would do.)
429878
+Updates the runtime state for all lvm devices.
429878
 .P
429878
-.B pvscan --cache
429878
+.B pvscan --cache -aay
429878
+.I device
429878
 .P
429878
-This first clears all existing PV online records, then scans all devices
429878
-on the system, adding PV online records for any PVs that are found.
429878
+Performs the --cache steps for the device, then checks if the VG using the
429878
+device is complete.  If so, LVs in the VG are autoactivated, the same as
429878
+vgchange -aay vgname would do.  (A device name may be replaced with major
429878
+and minor numbers.)
429878
 .P
429878
 .B pvscan --cache -aay
429878
 .P
429878
-This begins by performing the same steps as pvscan --cache.  Afterward, it
429878
-activates LVs in any complete VGs.
429878
+Performs the --cache steps for all devices, then autoactivates any complete VGs.
429878
 .P
429878
-To prevent devices from being scanned by pvscan --cache, add them
429878
-to
429878
-.BR lvm.conf (5)
429878
-.B devices/global_filter.
429878
-For more information, see:
429878
-.br
429878
-.B lvmconfig --withcomments devices/global_filter
429878
+.B pvscan --cache --listvg|--listlvs
429878
+.I device
429878
+.P
429878
+Performs the --cache steps for the device, then prints the name of the VG
429878
+using the device, or the names of LVs using the device.  --checkcomplete
429878
+is usually included to check if all PVs for the VG or LVs are online.
429878
+When this command is called by a udev rule, the output must conform to
429878
+udev rule specifications (see --udevoutput.)  The udev rule will use the
429878
+results to perform autoactivation.
429878
 .P
429878
-Auto-activation of VGs or LVs can be enabled/disabled using:
429878
-.br
429878
+Autoactivation of VGs or LVs can be enabled/disabled using vgchange or
429878
+lvchange with --setautoactivation y|n, or by adding names to
429878
 .BR lvm.conf (5)
429878
 .B activation/auto_activation_volume_list
429878
 .P
429878
-For more information, see:
429878
-.br
429878
-.B lvmconfig --withcomments activation/auto_activation_volume_list
429878
-.P
429878
-To disable auto-activation, explicitly set this list to an empty list,
429878
-i.e. auto_activation_volume_list = [ ].
429878
-.P
429878
-When this setting is undefined (e.g. commented), then all LVs are
429878
-auto-activated.
429878
+See
429878
+.BR lvmautoactivation (7)
429878
+for more information about how pvscan is used for autoactivation.
429878
-- 
ab86b0
2.34.3
429878