@@ -390,10 +390,11 @@ dm_type(const char * name, char * type)
goto out;
/* Fetch 1st target */
- dm_get_next_target(dmt, NULL, &start, &length,
- &target_type, ¶ms);
-
- if (!target_type)
+ if (dm_get_next_target(dmt, NULL, &start, &length,
+ &target_type, ¶ms) != NULL)
+ /* more than one target */
+ r = -1;
+ else if (!target_type)
r = -1;
else if (!strcmp(target_type, type))
r = 1;
@@ -494,7 +495,7 @@ do_foreach_partmaps (const char * mapname, const char *uuid,
/*
* skip if devmap target is not "linear"
*/
- if (!dm_type(names->name, "linear")) {
+ if (dm_type(names->name, "linear") != 1) {
if (rd->verbose)
printf("%s: is not a linear target. Not removing\n",
names->name);
kpartx -d treats any map that has a "linear" mapping into a device as first target as a partition of this device. This is wrong, because linear mappings may consist of several pieces, combining multiple devices into one (LVM logical volumes are an example of such a mapping). Partitions have to be single-target mappings. Fix this by returning an error in dm_type() if a map with multiple targets is encountered. The "type" of a map with two or more targets is a difficult concept, anyway. test case: truncate -s 1G test0 test1 losetup /dev/loop0 test0 losetup /dev/loop1 test1 dmsetup create <<EOF 0 1000000 linear 7:0 4096 1000000 1000000 linear 7:1 4096 EOF kpartx -d /dev/loop0 -v The map "join" should NOT be deleted. Signed-off-by: Martin Wilck <mwilck@suse.com> --- kpartx/devmapper.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)