Skip to contentSkip to conversation

master - pvscan: autoactivate without lvmetad

PATCH David Teigland 1 participant 1 message Jul 10, 2018

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=db741e75a21bd9327ed1478e42495f2b0a419be9
Commit:        db741e75a21bd9327ed1478e42495f2b0a419be9
Parent:        c47655f23154c5483c6f097cdd1918deb9fe2f89
Author:        David Teigland <[email protected]>
AuthorDate:    Thu Jun 28 14:48:03 2018 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Mon Jul 9 16:11:24 2018 -0500

pvscan: autoactivate without lvmetad

When lvmetad is not used, use temporary files to record which PVs have appeared. Use these temp files to determine when a VG is complete, to trigger autoactivation.

This change allows us to remove lvmetad while keeping the same autoactivation behavior that lvmetad provides.

The temp files are created in /run/lvm/pvs_online/ and are named for the PVID of the PV. The files contain the major:minor of the device the PV was read from.

e.g. if VG foo has dev1 and dev2, then:

. pvscan --cache -aay dev1
reads vg metadata from dev1
creates /run/lvm/pvs_online/<pvid-of-dev1>
checks if all vg->pvs are online: no

. pvscan --cache -aay dev2
reads vg metadata from dev2
creates /run/lvm/pvs_online/<pvid-of-dev2>
checks if all vg->pvs are online: yes
autoactivates vg

A 'pvscan --cache dev' (without -aay) still records that dev is online.

A 'pvscan --cache --major X --minor Y' after a device is gone will remove the temp file for it.

A 'pvscan --cache [-aay]' (no devs) resets the state of temp files by removing them all, then scanning all devs and creating temp files for PVs that are found.

If no online files exist, the first pvscan --cache scans all devs and creates temp files for any PVs found.

The scope of the temp files is only pvscan, and they are only used for pvscan-based autoactivation. No other commands are concerned with or aware of these temp files. When lvm creates or removes PVs, no attempt is made to update the temp files.

---
 lib/cache/lvmcache.c |   12 +-
 lib/cache/lvmcache.h |    2 +
 tools/pvscan.c       |  655 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 659 insertions(+), 10 deletions(-)
lib/cache/lvmcache.c +6 -6
index f15b352..f20928b 100644
@@ -419,7 +419,7 @@ int vg_has_duplicate_pvs(struct volume_group *vg)
 	return 0;
 }
 
-static int _dev_in_device_list(struct device *dev, struct dm_list *head)
+int dev_in_device_list(struct device *dev, struct dm_list *head)
 {
 	struct device_list *devl;
 
@@ -432,7 +432,7 @@ static int _dev_in_device_list(struct device *dev, struct dm_list *head)
 
 int lvmcache_dev_is_unchosen_duplicate(struct device *dev)
 {
-	return _dev_in_device_list(dev, &_unused_duplicate_devs);
+	return dev_in_device_list(dev, &_unused_duplicate_devs);
 }
 
 /*
@@ -601,8 +601,8 @@ next:
 			continue;
 		}
 
-		prev_unchosen1 = _dev_in_device_list(dev1, &_unused_duplicate_devs);
-		prev_unchosen2 = _dev_in_device_list(dev2, &_unused_duplicate_devs);
+		prev_unchosen1 = dev_in_device_list(dev1, &_unused_duplicate_devs);
+		prev_unchosen2 = dev_in_device_list(dev2, &_unused_duplicate_devs);
 
 		if (!prev_unchosen1 && !prev_unchosen2) {
 			/*
@@ -612,8 +612,8 @@ next:
 			 * want the same duplicate preference to be preserved
 			 * in each instance of lvmcache for a single command.
 			 */
-			prev_unchosen1 = _dev_in_device_list(dev1, &cmd->unused_duplicate_devs);
-			prev_unchosen2 = _dev_in_device_list(dev2, &cmd->unused_duplicate_devs);
+			prev_unchosen1 = dev_in_device_list(dev1, &cmd->unused_duplicate_devs);
+			prev_unchosen2 = dev_in_device_list(dev2, &cmd->unused_duplicate_devs);
 		}
 
 		dev1_major = MAJOR(dev1->dev);
lib/cache/lvmcache.h +2 -0
index 008f110..92e27a2 100644
@@ -210,4 +210,6 @@ struct volume_group *lvmcache_get_saved_vg(const char *vgid, int precommitted);
 struct volume_group *lvmcache_get_saved_vg_latest(const char *vgid);
 void lvmcache_drop_saved_vgid(const char *vgid);
 
+int dev_in_device_list(struct device *dev, struct dm_list *head);
+
 #endif
tools/pvscan.c +651 -4

694 lines not on this page · raw message