Skip to contentSkip to conversation

master - refactor: make device type recognition code common for general use

PATCH Peter Rajnoha 1 participant 1 message Jun 12, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c6f48b7c1a0271255405346c50d6bee8cc8b9241
Commit:        c6f48b7c1a0271255405346c50d6bee8cc8b9241
Parent:        1778d34cefdfe30055ac4a7e82438e4484004491
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Jun 12 12:08:56 2013 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Jun 12 12:08:56 2013 +0200

refactor: make device type recognition code common for general use

Changes:

- move device type registration out of "type filter" (filter.c) to a separate and new dev-type.[ch] for common use throughout the code

- the structure for keeping the major numbers detected for available device types and available partitioning available is stored in "dev_types" structure now

- move common partitioning detection code to dev-type.[ch] as well together with other device-related functions bound to dev_types (see dev-type.h for the interface)

The dev-type interface contains all common functions used to detect subsystems/device types, signature/superblock recognition code, type-specific device properties and other common device properties (bound to dev_types), including partitioning support.

- add dev_types instance to cmd context as cmd->dev_types for common use

- use cmd->dev_types throughout as a central point for providing information about device types

---
 include/.symlinks.in            |    1 +
 lib/cache/lvmcache.c            |   14 +-
 lib/cache/lvmcache.h            |    1 +
 lib/commands/toolcontext.c      |   28 ++-
 lib/commands/toolcontext.h      |    2 +
 lib/device/dev-cache.c          |    1 +
 lib/device/dev-luks.c           |    1 +
 lib/device/dev-md.c             |   39 ++--
 lib/device/dev-swap.c           |    1 +
 lib/device/dev-type.c           |  443 +++++++++++++++++++++++++++++----------
 lib/device/dev-type.h           |   76 +++++++
 lib/device/device-types.h       |   73 ++++----
 lib/device/device.h             |   16 --
 lib/filters/filter-composite.c  |    2 -
 lib/filters/filter-md.c         |    6 +-
 lib/filters/filter-md.h         |    3 +-
 lib/filters/filter-mpath.c      |   25 +--
 lib/filters/filter-mpath.h      |    3 +-
 lib/filters/filter-persistent.c |   17 +-
 lib/filters/filter-persistent.h |    4 +-
 lib/filters/filter-regex.c      |    1 -
 lib/filters/filter-regex.h      |    1 -
 lib/filters/filter-sysfs.h      |    1 -
 lib/filters/filter.c            |  274 +-----------------------
 lib/filters/filter.h            |   27 +--
 lib/format1/disk-rep.c          |   11 +-
 lib/format_pool/disk_rep.c      |    9 +-
 lib/metadata/metadata.c         |    8 +-
 lib/metadata/pv_manip.c         |    4 +-
 29 files changed, 559 insertions(+), 533 deletions(-)
include/.symlinks.in +1 -0
index 1c883ae..facadbe 100644
@@ -15,6 +15,7 @@
 @top_srcdir@/lib/datastruct/lvm-types.h
 @top_srcdir@/lib/datastruct/str_list.h
 @top_srcdir@/lib/device/dev-cache.h
+ at top_srcdir@/lib/device/dev-type.h
 @top_srcdir@/lib/device/device.h
 @top_srcdir@/lib/display/display.h
 @top_srcdir@/lib/filters/filter-composite.h
lib/cache/lvmcache.c +8 -6
index 6f935db..c0b3299 100644
@@ -1452,6 +1452,8 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
 				   const char *vgname, const char *vgid,
 				   uint32_t vgstatus)
 {
+	const struct format_type *fmt = (const struct format_type *) labeller->private;
+	struct dev_types *dt = fmt->cmd->dev_types;
 	struct label *label;
 	struct lvmcache_info *existing, *info;
 	char pvid_s[ID_LEN + 1] __attribute__((aligned(8)));
@@ -1485,12 +1487,12 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
 	} else {
 		if (existing->dev != dev) {
 			/* Is the existing entry a duplicate pvid e.g. md ? */
-			if (dev_subsystem_part_major(existing->dev) &&
-			    !dev_subsystem_part_major(dev)) {
+			if (dev_subsystem_part_major(dt, existing->dev) &&
+			    !dev_subsystem_part_major(dt, dev)) {
 				log_very_verbose("Ignoring duplicate PV %s on "
 						 "%s - using %s %s",
 						 pvid, dev_name(dev),
-						 dev_subsystem_name(existing->dev),
+						 dev_subsystem_name(dt, existing->dev),
 						 dev_name(existing->dev));
 				return NULL;
 			} else if (dm_is_dm_major(MAJOR(existing->dev->dev)) &&
@@ -1500,12 +1502,12 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
 						 pvid, dev_name(dev),
 						 dev_name(existing->dev));
 				return NULL;
-			} else if (!dev_subsystem_part_major(existing->dev) &&
-				   dev_subsystem_part_major(dev))
+			} else if (!dev_subsystem_part_major(dt, existing->dev) &&
+				   dev_subsystem_part_major(dt, dev))
 				log_very_verbose("Duplicate PV %s on %s - "
 						 "using %s %s", pvid,
 						 dev_name(existing->dev),
-						 dev_subsystem_name(existing->dev),
+						 dev_subsystem_name(dt, existing->dev),
 						 dev_name(dev));
 			else if (!dm_is_dm_major(MAJOR(existing->dev->dev)) &&
 				 dm_is_dm_major(MAJOR(dev->dev)))
lib/cache/lvmcache.h +1 -0
index 119b411..bf26664 100644
@@ -17,6 +17,7 @@
 #define _LVM_CACHE_H
 
 #include "dev-cache.h"
+#include "dev-type.h"
 #include "uuid.h"
 #include "label.h"
 #include "locking.h"
lib/commands/toolcontext.c +23 -5
index dca2329..79c25a5 100644
@@ -820,8 +820,7 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
 		nr_filt++;
 
 	/* device type filter. Required. */
-	cn = find_config_tree_node(cmd, devices_types_CFG);
-	if (!(filters[nr_filt] = lvm_type_filter_create(cmd->proc_dir, cn))) {
+	if (!(filters[nr_filt] = lvm_type_filter_create(cmd->dev_types))) {
 		log_error("Failed to create lvm type filter");
 		goto bad;
 	}
@@ -830,13 +829,13 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
 	/* md component filter. Optional, non-critical. */
 	if (find_config_tree_bool(cmd, devices_md_component_detection_CFG)) {
 		init_md_filtering(1);
-		if ((filters[nr_filt] = md_filter_create()))
+		if ((filters[nr_filt] = md_filter_create(cmd->dev_types)))
 			nr_filt++;
 	}
 
 	/* mpath component filter. Optional, non-critical. */
 	if (find_config_tree_bool(cmd, devices_multipath_component_detection_CFG)) {
-		if ((filters[nr_filt] = mpath_filter_create()))
+		if ((filters[nr_filt] = mpath_filter_create(cmd->dev_types)))
 			nr_filt++;
 	}
 
@@ -898,7 +897,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
 	if (!dev_cache)
 		dev_cache = cache_file;
 
-	if (!(f4 = persistent_filter_create(f3, dev_cache))) {
+	if (!(f4 = persistent_filter_create(cmd->dev_types, f3, dev_cache))) {
 		log_verbose("Failed to create persistent device filter.");
 		f3->destroy(f3);
 		return_0;
@@ -1451,6 +1450,10 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
 	if (!_process_config(cmd))
 		goto_out;
 
+	if (!(cmd->dev_types = create_dev_types(cmd->proc_dir,
+						find_config_tree_node(cmd, devices_types_CFG))))
+		goto_out;
+
 	if (!_init_dev_cache(cmd))
 		goto_out;
 
@@ -1541,6 +1544,15 @@ skip_dlclose:
 	}
 }
 
+static void _destroy_dev_types(struct cmd_context *cmd)
+{
+	if (!cmd->dev_types)
+		return;
+
+	dm_free(cmd->dev_types);
+	cmd->dev_types = NULL;
+}
+
 int refresh_filters(struct cmd_context *cmd)
 {
 	int r, saved_ignore_suspended_devices = ignore_suspended_devices();
@@ -1584,6 +1596,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
 		cmd->filter = NULL;
 	}
 	dev_cache_exit();
+	_destroy_dev_types(cmd);
 	_destroy_tags(cmd);
 
 	cft_cmdline = _destroy_tag_configs(cmd);
@@ -1623,6 +1636,10 @@ int refresh_toolcontext(struct cmd_context *cmd)
 	if (!_process_config(cmd))
 		return 0;
 
+	if (!(cmd->dev_types = create_dev_types(cmd->proc_dir,
+						find_config_tree_node(cmd, devices_types_CFG))))
+		return 0;
+
 	if (!_init_dev_cache(cmd))
 		return 0;
 
@@ -1667,6 +1684,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
 	if (cmd->mem)
 		dm_pool_destroy(cmd->mem);
 	dev_cache_exit();
+	_destroy_dev_types(cmd);
 	_destroy_tags(cmd);
 
 	if ((cft_cmdline = _destroy_tag_configs(cmd)))
lib/commands/toolcontext.h +2 -0
index 307dc77..f6a09a7 100644
@@ -17,6 +17,7 @@
 #define _LVM_TOOLCONTEXT_H
 
 #include "dev-cache.h"
+#include "dev-type.h"
 
 #include <stdio.h>
 #include <limits.h>
@@ -91,6 +92,7 @@ struct cmd_context {
 
 	unsigned independent_metadata_areas:1;	/* Active formats have MDAs outside PVs */
 
+	struct dev_types *dev_types;
 	struct dev_filter *filter;
 	struct dev_filter *lvmetad_filter;
 	int dump_filter;	/* Dump filter when exiting? */
lib/device/dev-cache.c +1 -0
index 0933549..9981967 100644
@@ -18,6 +18,7 @@
 #include "lvm-types.h"
 #include "btree.h"
 #include "filter.h"
+#include "config.h"
 #include "toolcontext.h"
 
 #include <unistd.h>
lib/device/dev-luks.c +1 -0
index 10aae30..2c79a2b 100644
@@ -13,6 +13,7 @@
  */
 
 #include "lib.h"
+#include "dev-type.h"
 #include "metadata.h"
 
 #define LUKS_SIGNATURE "LUKS\xba\xbe"
lib/device/dev-md.c +20 -19
index c4e2316..a8bbe81 100644
@@ -14,9 +14,9 @@
  */
 
 #include "lib.h"
+#include "dev-type.h"
 #include "metadata.h"
 #include "xlate.h"
-#include "filter.h"
 
 #ifdef linux
 
@@ -127,6 +127,7 @@ out:
 }
 
 static int _md_sysfs_attribute_snprintf(char *path, size_t size,
+					struct dev_types *dt,
 					struct device *blkdev,
 					const char *attribute)
 {
@@ -138,13 +139,13 @@ static int _md_sysfs_attribute_snprintf(char *path, size_t size,
 	if (!sysfs_dir || !*sysfs_dir)
 		return ret;
 
-	if (MAJOR(dev) == blkext_major()) {
+	if (MAJOR(dev) == dt->blkext_major) {
 		/* lookup parent MD device from blkext partition */
-		if (!get_primary_dev(blkdev, &dev))
+		if (!dev_get_primary_dev(dt, blkdev, &dev))
 			return ret;
 	}
 
-	if (MAJOR(dev) != md_major())
+	if (MAJOR(dev) != dt->md_major)
 		return ret;
 
 	ret = dm_snprintf(path, size, "%s/dev/block/%d:%d/md/%s", sysfs_dir,
@@ -171,7 +172,7 @@ static int _md_sysfs_attribute_snprintf(char *path, size_t size,
 	return ret;
 }
 
-static int _md_sysfs_attribute_scanf(const char *sysfs_dir,
+static int _md_sysfs_attribute_scanf(struct dev_types *dt,
 				     struct device *dev,
 				     const char *attribute_name,
 				     const char *attribute_fmt,
@@ -181,8 +182,8 @@ static int _md_sysfs_attribute_scanf(const char *sysfs_dir,
 	FILE *fp;
 	int ret = 0;
 
-	if (_md_sysfs_attribute_snprintf(path, PATH_MAX, dev,
-					 attribute_name) < 0)
+	if (_md_sysfs_attribute_snprintf(path, PATH_MAX, dt,
+					 dev, attribute_name) < 0)
 		return ret;
 
 	if (!(fp = fopen(path, "r"))) {
@@ -211,13 +212,13 @@ out:
 /*
  * Retrieve chunk size from md device using sysfs.
  */
-static unsigned long dev_md_chunk_size(const char *sysfs_dir,
+static unsigned long dev_md_chunk_size(struct dev_types *dt,
 				       struct device *dev)
 {
 	const char *attribute = "chunk_size";
 	unsigned long chunk_size_bytes = 0UL;
 
-	if (_md_sysfs_attribute_scanf(sysfs_dir, dev, attribute,
+	if (_md_sysfs_attribute_scanf(dt, dev, attribute,
 				      "%lu", &chunk_size_bytes) != 1)
 		return 0;
 
@@ -230,13 +231,13 @@ static unsigned long dev_md_chunk_size(const char *sysfs_dir,
 /*
  * Retrieve level from md device using sysfs.
  */
-static int dev_md_level(const char *sysfs_dir, struct device *dev)
+static int dev_md_level(struct dev_types *dt, struct device *dev)
 {
 	char level_string[MD_MAX_SYSFS_SIZE];
 	const char *attribute = "level";
 	int level = -1;
 
-	if (_md_sysfs_attribute_scanf(sysfs_dir, dev, attribute,
+	if (_md_sysfs_attribute_scanf(dt, dev, attribute,
 				      "%s", &level_string) != 1)
 		return -1;
 
@@ -253,12 +254,12 @@ static int dev_md_level(const char *sysfs_dir, struct device *dev)
 /*
  * Retrieve raid_disks from md device using sysfs.
  */
-static int dev_md_raid_disks(const char *sysfs_dir, struct device *dev)
+static int dev_md_raid_disks(struct dev_types *dt, struct device *dev)
 {
 	const char *attribute = "raid_disks";
 	int raid_disks = 0;
 
-	if (_md_sysfs_attribute_scanf(sysfs_dir, dev, attribute,
+	if (_md_sysfs_attribute_scanf(dt, dev, attribute,
 				      "%d", &raid_disks) != 1)
 		return 0;
 
@@ -271,22 +272,21 @@ static int dev_md_raid_disks(const char *sysfs_dir, struct device *dev)
 /*
  * Calculate stripe width of md device using its sysfs files.
  */
-unsigned long dev_md_stripe_width(struct device *dev)
+unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev)
 {
-	const char *sysfs_dir = dm_sysfs_dir();
 	unsigned long chunk_size_sectors = 0UL;
 	unsigned long stripe_width_sectors = 0UL;
 	int level, raid_disks, data_disks;
 
-	chunk_size_sectors = dev_md_chunk_size(sysfs_dir, dev);
+	chunk_size_sectors = dev_md_chunk_size(dt, dev);
 	if (!chunk_size_sectors)
 		return 0;
 
-	level = dev_md_level(sysfs_dir, dev);
+	level = dev_md_level(dt, dev);
 	if (level < 0)
 		return 0;
 
-	raid_disks = dev_md_raid_disks(sysfs_dir, dev);
+	raid_disks = dev_md_raid_disks(dt, dev);
 	if (!raid_disks)
 		return 0;
 
@@ -333,7 +333,8 @@ int dev_is_md(struct device *dev __attribute__((unused)),
 	return 0;
 }
 
-unsigned long dev_md_stripe_width(struct device *dev  __attribute__((unused)))
+unsigned long dev_md_stripe_width(struct dev_types *dt __attribute__((unused)),
+				  struct device *dev __attribute__((unused)))
 {
 	return 0UL;
 }
lib/device/dev-swap.c +1 -0
index 346b60a..c3b121b 100644
@@ -13,6 +13,7 @@
  */
 
 #include "lib.h"
+#include "dev-type.h"
 #include "metadata.h"
 
 #ifdef linux
lib/device/dev-type.c +334 -109

531 lines not on this page · raw message

lib/device/dev-type.h new file +76 -0

76 lines not on this page · raw message

lib/device/device-types.h +37 -36

88 lines not on this page · raw message

lib/device/device.h +0 -16
index 025d4ca..1d6304d 100644
@@ -99,20 +99,4 @@ struct device *dev_create_file(const char *filename, struct device *dev,
 /* Return a valid device name from the alias list; NULL otherwise */
 const char *dev_name_confirmed(struct device *dev, int quiet);
 
-/* Does device contain md superblock?  If so, where? */
-int dev_is_md(struct device *dev, uint64_t *sb);
-int dev_is_swap(struct device *dev, uint64_t *signature);
-int dev_is_luks(struct device *dev, uint64_t *signature);
-unsigned long dev_md_stripe_width(struct device *dev);
-
-int is_partitioned_dev(struct device *dev);
-
-int get_primary_dev(const struct device *dev, dev_t *result);
-
-unsigned long dev_alignment_offset(struct device *dev);
-unsigned long dev_minimum_io_size(struct device *dev);
-unsigned long dev_optimal_io_size(struct device *dev);
-unsigned long dev_discard_max_bytes(struct device *dev);
-unsigned long dev_discard_granularity(struct device *dev);
-
 #endif
lib/filters/filter-composite.c +0 -2
index c2b103d..47d147e 100644
@@ -16,8 +16,6 @@
 #include "lib.h"
 #include "filter-composite.h"
 
-#include <stdarg.h>
-
 static int _and_p(struct dev_filter *f, struct device *dev)
 {
 	struct dev_filter **filters;
lib/filters/filter-md.c +3 -3
index 6f289b0..b18cd07 100644
@@ -50,7 +50,7 @@ static void _destroy(struct dev_filter *f)
 	dm_free(f);
 }
 
-struct dev_filter *md_filter_create(void)
+struct dev_filter *md_filter_create(struct dev_types *dt)
 {
 	struct dev_filter *f;
 
@@ -62,14 +62,14 @@ struct dev_filter *md_filter_create(void)
 	f->passes_filter = _ignore_md;
 	f->destroy = _destroy;
 	f->use_count = 0;
-	f->private = NULL;
+	f->private = dt;
 
 	return f;
 }
 
 #else
 
-struct dev_filter *md_filter_create(void)
+struct dev_filter *md_filter_create(struct dev_types *dt)
 {
 	return NULL;
 }
lib/filters/filter-md.h +2 -1
index 6a98f0b..79e4f0e 100644
@@ -16,8 +16,9 @@
 #define _LVM_FILTER_MD_H
 
 #include "dev-cache.h"
+#include "dev-type.h"
 
-struct dev_filter *md_filter_create(void);
+struct dev_filter *md_filter_create(struct dev_types *dt);
 
 #endif
 
lib/filters/filter-mpath.c +11 -14
index f3af268..0e88e65 100644
@@ -13,11 +13,11 @@
  */
 
 #include "lib.h"
-#include "filter.h"
 #include "filter-mpath.h"
 #include "activate.h"
 
 #ifdef linux
+
 #include <dirent.h>
 
 #define MPATH_PREFIX "mpath-"
@@ -115,15 +115,17 @@ static int get_parent_mpath(const char *dir, char *name, int max_size)
 
 static int dev_is_mpath(struct dev_filter *f, struct device *dev)
 {
+	struct dev_types *dt = (struct dev_types *) f->private;
 	const char *name;
 	char path[PATH_MAX+1];
 	char parent_name[PATH_MAX+1];
 	struct stat info;
 	const char *sysfs_dir = dm_sysfs_dir();
-	int major, minor;
+	int major = MAJOR(dev->dev);
+	int minor = MINOR(dev->dev);
 
 	/* Limit this filter only to SCSI devices */
-	if (!major_is_scsi_device(MAJOR(dev->dev)))
+	if (!major_is_scsi_device(dt, MAJOR(dev->dev)))
 		return 0;
 
 	if (!(name = get_sysfs_name(dev)))
@@ -149,8 +151,9 @@ static int dev_is_mpath(struct dev_filter *f, struct device *dev)
 	if (!get_sysfs_get_major_minor(sysfs_dir, parent_name, &major, &minor))
 		return_0;
 
-	if (major != dm_major()) {
-		log_error("mpath major %d is not dm major %d.", major, dm_major());
+	if (major != dt->device_mapper_major) {
+		log_error("mpath major %d is not dm major %d.", major,
+			  dt->device_mapper_major);
 		return 0;
 	}
 
@@ -172,11 +175,10 @@ static void _destroy(struct dev_filter *f)
 	if (f->use_count)
 		log_error(INTERNAL_ERROR "Destroying mpath filter while in use %u times.", f->use_count);
 
-	dm_free(f->private);
 	dm_free(f);
 }
 
-struct dev_filter *mpath_filter_create(void)
+struct dev_filter *mpath_filter_create(struct dev_types *dt)
 {
 	const char *sysfs_dir = dm_sysfs_dir();
 	struct dev_filter *f;
@@ -194,19 +196,14 @@ struct dev_filter *mpath_filter_create(void)
 	f->passes_filter = _ignore_mpath;
 	f->destroy = _destroy;
 	f->use_count = 0;
-
-	if (!(f->private = dm_strdup(sysfs_dir))) {
-		log_error("Cannot duplicate sysfs dir.");
-		dm_free(f);
-		return NULL;
-	}
+	f->private = dt;
 
 	return f;
 }
 
 #else
 
-struct dev_filter *mpath_filter_create(const char *sysfs_dir __attribute__((unused)))
+struct dev_filter *mpath_filter_create(struct device_types *dt)
 {
 	return NULL;
 }
lib/filters/filter-mpath.h +2 -1
index 31585eb..5665f3b 100644
@@ -16,8 +16,9 @@
 #define _LVM_FILTER_MPATH_H
 
 #include "dev-cache.h"
+#include "dev-type.h"
 
-struct dev_filter *mpath_filter_create(void);
+struct dev_filter *mpath_filter_create(struct dev_types *dt);
 
 #endif
 
lib/filters/filter-persistent.c +7 -10
index 799e7d8..a59529d 100644
@@ -14,23 +14,17 @@
  */
 
 #include "lib.h"
-#include "config.h"
-#include "dev-cache.h"
-#include "filter.h"
 #include "filter-persistent.h"
+#include "config.h"
 #include "lvm-file.h"
-#include "lvm-string.h"
 #include "activate.h"
 
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
 struct pfilter {
 	char *file;
 	struct dm_hash_table *devices;
 	struct dev_filter *real;
 	time_t ctime;
+	struct dev_types *dt;
 };
 
 /*
@@ -287,7 +281,7 @@ static int _lookup_p(struct dev_filter *f, struct device *dev)
 	}
 
 	/* Test dm devices every time, so cache them as GOOD. */
-	if (MAJOR(dev->dev) == dm_major()) {
+	if (MAJOR(dev->dev) == pf->dt->device_mapper_major) {
 		if (!l)
 			dm_list_iterate_items(sl, &dev->aliases)
 				if (!dm_hash_insert(pf->devices, sl->str, PF_GOOD_DEVICE)) {
@@ -329,7 +323,8 @@ static void _persistent_destroy(struct dev_filter *f)
 	dm_free(f);
 }
 
-struct dev_filter *persistent_filter_create(struct dev_filter *real,
+struct dev_filter *persistent_filter_create(struct dev_types *dt,
+					    struct dev_filter *real,
 					    const char *file)
 {
 	struct pfilter *pf;
@@ -341,6 +336,8 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
 		return NULL;
 	}
 
+	pf->dt = dt;
+
 	if (!(pf->file = dm_strdup(file))) {
 		log_error("Filename duplication for persistent filter failed.");
 		goto bad;
lib/filters/filter-persistent.h +3 -1
index 58fbc10..bdbf887 100644
@@ -17,8 +17,10 @@
 #define _LVM_FILTER_PERSISTENT_H
 
 #include "dev-cache.h"
+#include "dev-type.h"
 
-struct dev_filter *persistent_filter_create(struct dev_filter *f,
+struct dev_filter *persistent_filter_create(struct dev_types *dt,
+					    struct dev_filter *f,
 					    const char *file);
 
 int persistent_filter_load(struct dev_filter *f, struct dm_config_tree **cft_out);
lib/filters/filter-regex.c +0 -1
index 7172c93..4fe9a7a 100644
@@ -15,7 +15,6 @@
 
 #include "lib.h"
 #include "filter-regex.h"
-#include "device.h"
 
 struct rfilter {
 	struct dm_pool *mem;
lib/filters/filter-regex.h +0 -1
index bb71f56..de05206 100644
@@ -16,7 +16,6 @@
 #ifndef _LVM_FILTER_REGEX_H
 #define _LVM_FILTER_REGEX_H
 
-#include "config.h"
 #include "dev-cache.h"
 
 /*
lib/filters/filter-sysfs.h +0 -1
index 6fb5591..4b26ea6 100644
@@ -15,7 +15,6 @@
 #ifndef _LVM_FILTER_SYSFS_H
 #define _LVM_FILTER_SYSFS_H
 
-#include "config.h"
 #include "dev-cache.h"
 
 struct dev_filter *sysfs_filter_create(void);
lib/filters/filter.c +6 -268

316 lines not on this page · raw message

lib/filters/filter.h +3 -24
index cdbcfe8..e0a0c6a 100644
@@ -16,30 +16,9 @@
 #ifndef _LVM_FILTER_H
 #define _LVM_FILTER_H
 
-#include "config.h"
+#include "dev-cache.h"
+#include "dev-type.h"
 
-#include <sys/stat.h>
-
-#ifdef linux
-#  define MAJOR(dev)	((dev & 0xfff00) >> 8)
-#  define MINOR(dev)	((dev & 0xff) | ((dev >> 12) & 0xfff00))
-#  define MKDEV(ma,mi)	((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12))
-#else
-#  define MAJOR(x) major((x))
-#  define MINOR(x) minor((x))
-#  define MKDEV(x,y) makedev((x),(y))
-#endif
-
-struct dev_filter *lvm_type_filter_create(const char *proc,
-					  const struct dm_config_node *cn);
-
-int dm_major(void);
-int md_major(void);
-int blkext_major(void);
-int max_partitions(int major);
-int major_is_scsi_device(int major);
-
-int dev_subsystem_part_major(const struct device *dev);
-const char *dev_subsystem_name(const struct device *dev);
+struct dev_filter *lvm_type_filter_create(struct dev_types *dt);
 
 #endif
lib/format1/disk-rep.c +6 -5
index 19776e0..bbce317 100644
@@ -18,6 +18,7 @@
 #include "xlate.h"
 #include "filter.h"
 #include "lvmcache.h"
+#include "metadata-exported.h"
 
 #include <fcntl.h>
 
@@ -426,7 +427,7 @@ struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
 	return dl;
 }
 
-static void _add_pv_to_list(struct dm_list *head, struct disk_list *data)
+static void _add_pv_to_list(struct cmd_context *cmd, struct dm_list *head, struct disk_list *data)
 {
 	struct pv_disk *pvd;
 	struct disk_list *diskl;
@@ -435,14 +436,14 @@ static void _add_pv_to_list(struct dm_list *head, struct disk_list *data)
 		pvd = &diskl->pvd;
 		if (!strncmp((char *)data->pvd.pv_uuid, (char *)pvd->pv_uuid,
 			     sizeof(pvd->pv_uuid))) {
-			if (!dev_subsystem_part_major(data->dev)) {
+			if (!dev_subsystem_part_major(cmd->dev_types, data->dev)) {
 				log_very_verbose("Ignoring duplicate PV %s on "
 						 "%s", pvd->pv_uuid,
 						 dev_name(data->dev));
 				return;
 			}
 			log_very_verbose("Duplicate PV %s - using %s %s",
-					 pvd->pv_uuid, dev_subsystem_name(data->dev),
+					 pvd->pv_uuid, dev_subsystem_name(cmd->dev_types, data->dev),
 					 dev_name(data->dev));
 			dm_list_del(&diskl->list);
 			break;
@@ -469,7 +470,7 @@ static int _read_pv_in_vg(struct lvmcache_info *info, void *baton)
 	    !(b->data = read_disk(lvmcache_fmt(info), lvmcache_device(info), b->mem, b->vg_name)))
 		return 0; /* stop here */
 
-	_add_pv_to_list(b->head, b->data);
+	_add_pv_to_list(lvmcache_fmt(info)->cmd, b->head, b->data);
 	return 1;
 }
 
@@ -519,7 +520,7 @@ int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
 	/* Otherwise do a complete scan */
 	for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
 		if ((baton.data = read_disk(fmt, dev, mem, vg_name))) {
-			_add_pv_to_list(head, baton.data);
+			_add_pv_to_list(fmt->cmd, head, baton.data);
 		}
 	}
 	dev_iter_destroy(iter);
lib/format_pool/disk_rep.c +5 -4
index 899a48d..f696463 100644
@@ -20,6 +20,7 @@
 #include "filter.h"
 #include "xlate.h"
 #include "disk_rep.h"
+#include "toolcontext.h"
 
 #include <assert.h>
 
@@ -52,7 +53,7 @@ static int __read_pool_disk(const struct format_type *fmt, struct device *dev,
 	return 1;
 }
 
-static void _add_pl_to_list(struct dm_list *head, struct pool_list *data)
+static void _add_pl_to_list(struct cmd_context *cmd, struct dm_list *head, struct pool_list *data)
 {
 	struct pool_list *pl;
 
@@ -62,14 +63,14 @@ static void _add_pl_to_list(struct dm_list *head, struct pool_list *data)
 
 			id_write_format(&pl->pv_uuid, uuid, ID_LEN + 7);
 
-			if (!dev_subsystem_part_major(data->dev)) {
+			if (!dev_subsystem_part_major(cmd->dev_types, data->dev)) {
 				log_very_verbose("Ignoring duplicate PV %s on "
 						 "%s", uuid,
 						 dev_name(data->dev));
 				return;
 			}
 			log_very_verbose("Duplicate PV %s - using %s %s",
-					 uuid, dev_subsystem_name(data->dev),
+					 uuid, dev_subsystem_name(cmd->dev_types, data->dev),
 					 dev_name(data->dev));
 			dm_list_del(&pl->list);
 			break;
@@ -288,7 +289,7 @@ static int _read_pool_pv(struct lvmcache_info *info, void *baton)
 	if (b->sp_count != b->pl->pd.pl_subpools)
 		return 0;
 
-	_add_pl_to_list(b->head, b->pl);
+	_add_pl_to_list(lvmcache_fmt(info)->cmd, b->head, b->pl);
 
 	if (b->sp_count > b->pl->pd.pl_sp_id && b->sp_devs[b->pl->pd.pl_sp_id] == 0)
 		b->sp_devs[b->pl->pd.pl_sp_id] = b->pl->pd.pl_sp_devs;
lib/metadata/metadata.c +4 -4
index 4e52bd4..c65144c 100644
@@ -84,7 +84,7 @@ unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignm
 	 * Align to stripe-width of underlying md device if present
 	 */
 	if (find_config_tree_bool(pv->fmt->cmd, devices_md_chunk_alignment_CFG)) {
-		temp_pe_align = dev_md_stripe_width(pv->dev);
+		temp_pe_align = dev_md_stripe_width(pv->fmt->cmd->dev_types, pv->dev);
 		if (_alignment_overrides_default(temp_pe_align, default_pe_align))
 			pv->pe_align = temp_pe_align;
 	}
@@ -97,11 +97,11 @@ unsigned long set_pe_align(struct physical_volume *pv, unsigned long data_alignm
 	 *   (e.g. MD's stripe width)
 	 */
 	if (find_config_tree_bool(pv->fmt->cmd, devices_data_alignment_detection_CFG)) {
-		temp_pe_align = dev_minimum_io_size(pv->dev);
+		temp_pe_align = dev_minimum_io_size(pv->fmt->cmd->dev_types, pv->dev);
 		if (_alignment_overrides_default(temp_pe_align, default_pe_align))
 			pv->pe_align = temp_pe_align;
 
-		temp_pe_align = dev_optimal_io_size(pv->dev);
+		temp_pe_align = dev_optimal_io_size(pv->fmt->cmd->dev_types, pv->dev);
 		if (_alignment_overrides_default(temp_pe_align, default_pe_align))
 			pv->pe_align = temp_pe_align;
 	}
@@ -129,7 +129,7 @@ unsigned long set_pe_align_offset(struct physical_volume *pv,
 		goto out;
 
 	if (find_config_tree_bool(pv->fmt->cmd, devices_data_alignment_offset_detection_CFG)) {
-		int align_offset = dev_alignment_offset(pv->dev);
+		int align_offset = dev_alignment_offset(pv->fmt->cmd->dev_types, pv->dev);
 		/* must handle a -1 alignment_offset; means dev is misaligned */
 		if (align_offset < 0)
 			align_offset = 0;
lib/metadata/pv_manip.c +2 -2
index ae453ae..dea49f8 100644
@@ -216,8 +216,8 @@ int discard_pv_segment(struct pv_segment *peg, uint32_t discard_area_reduction)
 		return 1;
 	}
 
-	if (!dev_discard_max_bytes(peg->pv->dev) ||
-	    !dev_discard_granularity(peg->pv->dev))
+	if (!dev_discard_max_bytes(peg->pv->fmt->cmd->dev_types, peg->pv->dev) ||
+	    !dev_discard_granularity(peg->pv->fmt->cmd->dev_types, peg->pv->dev))
 		return 1;
 
 	discard_offset_sectors = (peg->pe + peg->lvseg->area_len - discard_area_reduction) *