From 99d895014d971395fe7a739838952e7405eb4dda Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Mon, 12 Jan 2015 14:02:57 +0100 Subject: [PATCH] dev-type: filter out partitioned device-mapper devices as unsuitable for use as PVs Normally, if there are partitions defined on top of device-mapper device, there should be a device-mapper device created for each partiton on top of the old one and once the underlying DM device is used by another devices (partition mappings in this case), it can't be used as a PV anymore. However, sometimes, it may happen the partition mappings are missing - either the partitioning tool is not creating them if it does not contain full support for device-mapper devices or the mappings were removed. Better safe than sorry - check for partition header on DM devs and filter them out as unsuitable for PVs in case the check is positive. Whatever the user is doing, let's do our best to prevent unwanted corruption (...by running pvcreate on top of such device that would corrupt the partition header). --- WHATS_NEW | 1 + lib/device/dev-type.c | 3 +++ test/shell/test-partition.sh | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index 11611dd75..e295e6c08 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.115 - ===================================== + Filter out partitioned device-mapper devices as unsuitable for use as PVs. Also notify lvmetad about filtered device if using pvscan --cache DevicePath. Use LVM's own selection instead of awk expressions in clvmd startup scripts. Do not filter out snapshot origin LVs as unusable devices for an LVM stack. diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c index 001248d45..a84f7e97b 100644 --- a/lib/device/dev-type.c +++ b/lib/device/dev-type.c @@ -272,6 +272,9 @@ static int _is_partitionable(struct dev_types *dt, struct device *dev) { int parts = major_max_partitions(dt, MAJOR(dev->dev)); + if (MAJOR(dev->dev) == dt->device_mapper_major) + return 1; + /* All MD devices are partitionable via blkext (as of 2.6.28) */ if (MAJOR(dev->dev) == dt->md_major) return 1; diff --git a/test/shell/test-partition.sh b/test/shell/test-partition.sh index af04b4ef5..e79216e4c 100644 --- a/test/shell/test-partition.sh +++ b/test/shell/test-partition.sh @@ -28,4 +28,5 @@ pvs "$dev1" # create small partition table echo "1 2" | sfdisk "$dev1" -pvs "$dev1" +aux notify_lvmetad "$dev1" +not pvs "$dev1"