Blame SOURCES/0015-man-lvmautoactivation.patch

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