From 68366c99b26502a04c34e2380b529c1aea1a1451 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 16 Sep 2005 18:53:01 +0000 Subject: [PATCH] Add is_dm_major() for use in duplicate device detection in lvmcache_add(). --- WHATS_NEW | 3 +++ lib/cache/lvmcache.c | 13 +++++++++++++ lib/filters/filter.c | 19 +++++++++++++++++++ lib/filters/filter.h | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index e15597aab..822477872 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,8 @@ Version 2.01.15 - ================================= + Add is_dm_major() for use in duplicate device detection in lvmcache_add(). + Really switch device number in lvmcache when it says it is doing so. + Option for bitset memory allocation using malloc as well as pool. Don't assume exactly two mirrors when parsing mirror status. Suppress fsync() error message on filesystems that don't support it. Fix yes_no_prompt() error handling. diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 22fcda88a..edcd1520d 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -495,12 +495,25 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid, pvid, dev_name(dev), dev_name(existing->dev)); return NULL; + } else if (is_dm_major(MAJOR(existing->dev->dev)) && + !is_dm_major(MAJOR(dev->dev))) { + log_very_verbose("Ignoring duplicate PV %s on " + "%s - using dm %s", + pvid, dev_name(dev), + dev_name(existing->dev)); + return NULL; } else if (MAJOR(existing->dev->dev) != md_major() && MAJOR(dev->dev) == md_major()) log_very_verbose("Duplicate PV %s on %s - " "using md %s", pvid, dev_name(existing->dev), dev_name(dev)); + else if (!is_dm_major(MAJOR(existing->dev->dev)) && + is_dm_major(MAJOR(dev->dev))) + log_very_verbose("Duplicate PV %s on %s - " + "using dm %s", pvid, + dev_name(existing->dev), + dev_name(dev)); else log_error("Found duplicate PV %s: using %s not " "%s", pvid, dev_name(dev), diff --git a/lib/filters/filter.c b/lib/filters/filter.c index 890eef576..b773ef851 100644 --- a/lib/filters/filter.c +++ b/lib/filters/filter.c @@ -19,6 +19,7 @@ #include "lvm-string.h" #include "config.h" #include "metadata.h" +#include "bitset.h" #include #include @@ -38,12 +39,18 @@ typedef struct { } device_info_t; static int _md_major = -1; +static bitset_t _dm_bitset; int md_major(void) { return _md_major; } +int is_dm_major(int major) +{ + return bit(_dm_bitset, major) ? 1 : 0; +} + /* * Devices are only checked for partition tables if their minor number * is a multiple of the number corresponding to their type below @@ -181,6 +188,11 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn) if (!strncmp("md", line + i, 2) && isspace(*(line + i + 2))) _md_major = line_maj; + /* Look for dm devices */ + if (!strncmp("device-mapper", line + i, 13) && + isspace(*(line + i + 13))) + bit_set(_dm_bitset, line_maj); + /* Go through the valid device names and if there is a match store max number of partitions */ for (j = 0; device_info[j].name != NULL; j++) { @@ -251,6 +263,12 @@ struct dev_filter *lvm_type_filter_create(const char *proc, f->destroy = lvm_type_filter_destroy; f->private = NULL; + if (!(_dm_bitset = bitset_create(NULL, NUMBER_OF_MAJORS))) { + stack; + dbg_free(f); + return NULL; + } + if (!_scan_proc_dev(proc, cn)) { stack; return NULL; @@ -261,6 +279,7 @@ struct dev_filter *lvm_type_filter_create(const char *proc, void lvm_type_filter_destroy(struct dev_filter *f) { + bitset_destroy(_dm_bitset); dbg_free(f); return; } diff --git a/lib/filters/filter.h b/lib/filters/filter.h index b5a5d4dc7..a05062d7d 100644 --- a/lib/filters/filter.h +++ b/lib/filters/filter.h @@ -36,7 +36,7 @@ struct dev_filter *lvm_type_filter_create(const char *proc, void lvm_type_filter_destroy(struct dev_filter *f); int md_major(void); - +int is_dm_major(int major); int max_partitions(int major); #endif