diff --git a/WHATS_NEW b/WHATS_NEW index 2a24d8e7c..e84088238 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.00.32 - ==================================== + Skip devices that are too small to be PVs. Fix pvchange -x segfault with lvm2-format orphan. Cope with empty msdos partition tables. Add CONTRIBUTORS file. diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index f6ce6f62b..fd6ea9c93 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -238,12 +238,14 @@ int dev_get_size(const struct device *dev, uint64_t *size) if (ioctl(fd, BLKGETSIZE64, size) < 0) { log_sys_error("ioctl BLKGETSIZE64", name); - close(fd); + if (close(fd)) + log_sys_error("close", name); return 0; } *size >>= BLKSIZE_SHIFT; /* Convert to sectors */ - close(fd); + if (close(fd)) + log_sys_error("close", name); log_very_verbose("%s: size is %" PRIu64 " sectors", name, *size); diff --git a/lib/filters/filter.c b/lib/filters/filter.c index a8d873342..bd133bc30 100644 --- a/lib/filters/filter.c +++ b/lib/filters/filter.c @@ -18,6 +18,7 @@ #include "filter.h" #include "lvm-string.h" #include "config.h" +#include "metadata.h" #include #include @@ -75,7 +76,8 @@ static int _passes_lvm_type_device_filter(struct dev_filter *f, struct device *dev) { const char *name = dev_name(dev); - int ret = 1; + int ret = 0; + uint64_t size; /* Is this a recognised device type? */ if (!_max_partitions_by_major[MAJOR(dev->dev)]) { @@ -90,12 +92,26 @@ static int _passes_lvm_type_device_filter(struct dev_filter *f, return 0; } - if (is_partitioned_dev(dev)) { - log_debug("%s: Skipping: partition table signature found", - name); - ret = 0; + /* Check it's not too small */ + if (!dev_get_size(dev, &size)) { + log_debug("%s: Skipping: dev_get_size failed", name); + goto out; } + if (size < PV_MIN_SIZE) { + log_debug("%s: Skipping: Too small to hold a PV", name); + goto out; + } + + if (is_partitioned_dev(dev)) { + log_debug("%s: Skipping: Partition table signature found", + name); + goto out; + } + + ret = 1; + + out: dev_close(dev); return ret;