Skip to contentSkip to conversation

main - devices: factor common list functions

PATCH David Teigland 1 participant 1 message Nov 7, 2022 Library code

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c98617c593a84e32ff8ee32ecf2382d4e1369c16
Commit:        c98617c593a84e32ff8ee32ecf2382d4e1369c16
Parent:        761b922178c8522fd9abb207ba31bd27f9fa9dc4
Author:        David Teigland <[email protected]>
AuthorDate:    Mon Nov 7 11:38:46 2022 -0600
Committer:     David Teigland <[email protected]>
CommitterDate: Mon Nov 7 11:38:46 2022 -0600

devices: factor common list functions

which were duplicated in various places

---
 lib/Makefile.in                  |  1 +
 lib/cache/lvmcache.c             | 48 ++++++++---------------------
 lib/cache/lvmcache.h             |  2 --
 lib/device/dev_util.c            | 66 ++++++++++++++++++++++++++++++++++++++++
 lib/device/device.h              | 12 ++++++++
 lib/device/device_id.c           | 17 ++---------
 lib/metadata/metadata-exported.h |  6 ----
 tools/pvscan.c                   |  2 +-
 tools/toollib.c                  | 34 +++------------------
 tools/vgimportclone.c            | 15 ++-------
 10 files changed, 102 insertions(+), 101 deletions(-)
lib/Makefile.in +1 -0
index 3380b28fb..50c7a1fd2 100644
@@ -43,6 +43,7 @@ SOURCES =\
 	device/filesystem.c \
 	device/online.c \
 	device/parse_vpd.c \
+	device/dev_util.c \
 	display/display.c \
 	error/errseg.c \
 	unknown/unknown.c \
lib/cache/lvmcache.c +13 -35

117 lines not on this page · raw message

lib/cache/lvmcache.h +0 -2
index 934246274..7dde3cda3 100644
@@ -186,8 +186,6 @@ int lvmcache_vginfo_has_pvid(struct lvmcache_vginfo *vginfo, const char *pvid_ar
 uint64_t lvmcache_max_metadata_size(void);
 void lvmcache_save_metadata_size(uint64_t val);
 
-int dev_in_device_list(struct device *dev, struct dm_list *head);
-
 bool lvmcache_has_bad_metadata(struct device *dev);
 
 bool lvmcache_has_old_metadata(struct cmd_context *cmd, const char *vgname, const char *vgid, struct device *dev);
lib/device/dev_util.c new file +66 -0

66 lines not on this page · raw message

lib/device/device.h +12 -0
index a047158d8..446104218 100644
@@ -179,6 +179,12 @@ struct device_list {
 	struct device *dev;
 };
 
+struct device_id_list {
+	struct dm_list list;
+	struct device *dev;
+	char pvid[ID_LEN + 1];
+};
+
 struct device_area {
 	struct device *dev;
 	uint64_t start;		/* Bytes */
@@ -235,4 +241,10 @@ int parse_vpd_ids(const unsigned char *vpd_data, int vpd_datalen, struct dm_list
 int format_t10_id(const unsigned char *in, int in_bytes, unsigned char *out, int out_bytes);
 int parse_vpd_serial(const unsigned char *in, char *out, int outsize);
 
+/* dev_util */
+int device_id_list_remove(struct dm_list *devices, struct device *dev);
+struct device_id_list *device_id_list_find_dev(struct dm_list *devices, struct device *dev);
+int device_list_remove(struct dm_list *devices, struct device *dev);
+struct device_list *device_list_find_dev(struct dm_list *devices, struct device *dev);
+
 #endif
lib/device/device_id.c +3 -14
index 599e357be..aae875776 100644
@@ -2208,7 +2208,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
 		 * scanned_devs are the devices that have been scanned,
 		 * so they are the only devs we can verify PVID for.
 		 */
-		if (scanned_devs && !dev_in_device_list(dev, scanned_devs))
+		if (scanned_devs && !device_list_find_dev(scanned_devs, dev))
 			continue;
 
 		/*
@@ -2310,7 +2310,7 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
 		 * scanned_devs are the devices that have been scanned,
 		 * so they are the only devs we can verify PVID for.
 		 */
-		if (scanned_devs && !dev_in_device_list(dev, scanned_devs))
+		if (scanned_devs && !device_list_find_dev(scanned_devs, dev))
 			continue;
 
 		/*
@@ -2462,17 +2462,6 @@ void device_ids_validate(struct cmd_context *cmd, struct dm_list *scanned_devs,
 	}
 }
 
-static struct device_id_list *_device_id_list_find_dev(struct dm_list *list, struct device *dev)
-{
-	struct device_id_list *dil;
-
-	dm_list_iterate_items(dil, list) {
-		if (dil->dev == dev)
-			return dil;
-	}
-	return NULL;
-}
-
 /*
  * Validate entries with suspect sys_serial values.  A sys_serial du (devices
  * file entry) matched a device with the same serial number, but the PVID did
@@ -2612,7 +2601,7 @@ void device_ids_check_serial(struct cmd_context *cmd, struct dm_list *scan_devs,
 					  du->idname, du->pvid, dev_name(dev));
 
 				/* update file if this dev pairing is new or different */
-				if (!(dil = _device_id_list_find_dev(&prev_devs, dev)))
+				if (!(dil = device_id_list_find_dev(&prev_devs, dev)))
 					update_file = 1;
 				else if (memcmp(dil->pvid, du->pvid, ID_LEN))
 					update_file = 1;
lib/metadata/metadata-exported.h +0 -6
index 04f32cace..c7eaa5233 100644
@@ -590,12 +590,6 @@ struct vgnameid_list {
 	const char *vgid;
 };
 
-struct device_id_list {
-	struct dm_list list;
-	struct device *dev;
-	char pvid[ID_LEN + 1];
-};
-
 #define PV_PE_START_CALC ((uint64_t) -1) /* Calculate pe_start value */
 
 /*
tools/pvscan.c +1 -1
index 1c58e4a5b..96935a43b 100644
@@ -703,7 +703,7 @@ static int _pvscan_aa_quick(struct cmd_context *cmd, struct pvscan_aa_params *pp
 	 * devices used by the VG we read.
 	 */
 	dm_list_iterate_items(pvl, &vg->pvs) {
-		if (dev_in_device_list(pvl->pv->dev, &devs))
+		if (device_list_find_dev(&devs, pvl->pv->dev))
 			continue;
 		log_error_pvscan(cmd, "activation for VG %s found different devices.", vgname);
 		ret = ECMD_FAILED;
tools/toollib.c +4 -30
index 5305e811b..ae6f311ba 100644
@@ -4133,32 +4133,6 @@ static int _get_arg_devices(struct cmd_context *cmd,
 	return ret_max;
 }
 
-static int _device_list_remove(struct dm_list *devices, struct device *dev)
-{
-	struct device_id_list *dil;
-
-	dm_list_iterate_items(dil, devices) {
-		if (dil->dev == dev) {
-			dm_list_del(&dil->list);
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
-static struct device_id_list *_device_list_find_dev(struct dm_list *devices, struct device *dev)
-{
-	struct device_id_list *dil;
-
-	dm_list_iterate_items(dil, devices) {
-		if (dil->dev == dev)
-			return dil;
-	}
-
-	return NULL;
-}
-
 /* Process devices that are not PVs. */
 
 static int _process_other_devices(struct cmd_context *cmd,
@@ -4263,8 +4237,8 @@ static int _process_duplicate_pvs(struct cmd_context *cmd,
 	dm_list_iterate_items(devl, &unused_duplicate_devs) {
 		/* Duplicates are displayed if -a is used or the dev is named as an arg. */
 
-		if ((dil = _device_list_find_dev(arg_devices, devl->dev)))
-			_device_list_remove(arg_devices, devl->dev);
+		if ((dil = device_id_list_find_dev(arg_devices, devl->dev)))
+			device_id_list_remove(arg_devices, devl->dev);
 
 		if (!process_other_devices && !dil)
 			continue;
@@ -4384,8 +4358,8 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
 		/* Remove each arg_devices entry as it is processed. */
 
 		if (arg_devices && !dm_list_empty(arg_devices)) {
-			if ((dil = _device_list_find_dev(arg_devices, pv->dev)))
-				_device_list_remove(arg_devices, dil->dev);
+			if ((dil = device_id_list_find_dev(arg_devices, pv->dev)))
+				device_id_list_remove(arg_devices, dil->dev);
 		}
 
 		if (!process_pv && dil)
tools/vgimportclone.c +2 -13
index 9e426c942..60ef20762 100644
@@ -25,17 +25,6 @@ struct vgimportclone_params {
 	unsigned import_vg:1;
 };
 
-static struct device_list *_get_device_list(struct dm_list *list, struct device *dev)
-{
-	struct device_list *devl;
-
-	dm_list_iterate_items(devl, list) {
-		if (devl->dev == dev)
-			return devl;
-	}
-	return NULL;
-}
-
 static int _update_vg(struct cmd_context *cmd, struct volume_group *vg,
 		      struct vgimportclone_params *vp)
 {
@@ -82,7 +71,7 @@ static int _update_vg(struct cmd_context *cmd, struct volume_group *vg,
 	 */
 
 	dm_list_iterate_items(pvl, &vg->pvs) {
-		if ((devl = _get_device_list(&vp->new_devs, pvl->pv->dev))) {
+		if ((devl = device_list_find_dev(&vp->new_devs, pvl->pv->dev))) {
 			dm_list_del(&devl->list);
 			dm_list_add(&tmp_devs, &devl->list);
 		} else {
@@ -192,7 +181,7 @@ static int _get_other_devs(struct cmd_context *cmd, struct dm_list *new_devs, st
 		return_0;
 
 	while ((dev = dev_iter_get(cmd, iter))) {
-		if (_get_device_list(new_devs, dev))
+		if (device_list_find_dev(new_devs, dev))
 			continue;
 		if (!(devl = zalloc(sizeof(*devl)))) {
 			r = 0;