[dm-devel] [PATCH 06/31] kpartx: fix part deletion without partition table

Martin Wilck mwilck at suse.com
Sat Sep 2 22:38:35 UTC 2017


If we are deleting partition mappings, there's no need to
parse the partition table. We just look for mappings created
by kpartx and destroy them. Without this patch, kpartx fails
to delete partition mappings on devices on which the partition
table has been destroyed.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 kpartx/kpartx.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 62f54308..442b6bd9 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -394,6 +394,22 @@ main(int argc, char **argv){
 
 	/* add/remove partitions to the kernel devmapper tables */
 	int r = 0;
+
+	if (what == DELETE) {
+		r = dm_remove_partmaps(mapname, uuid, buf.st_rdev,
+				       verbose);
+		if (loopdev) {
+			if (del_loop(loopdev)) {
+				if (verbose)
+					fprintf(stderr, "can't del loop : %s\n",
+					       loopdev);
+				r = 1;
+			} else
+				fprintf(stderr, "loop deleted : %s\n", loopdev);
+		}
+		goto end;
+	}
+
 	for (i = 0; i < ptct; i++) {
 		ptp = &pts[i];
 
@@ -461,20 +477,6 @@ main(int argc, char **argv){
 
 			break;
 
-		case DELETE:
-			r = dm_remove_partmaps(mapname, uuid, buf.st_rdev,
-					       verbose);
-			if (loopdev) {
-				if (del_loop(loopdev)) {
-					if (verbose)
-						printf("can't del loop : %s\n",
-						       loopdev);
-					exit(1);
-				}
-				printf("loop deleted : %s\n", loopdev);
-			}
-			break;
-
 		case ADD:
 		case UPDATE:
 			/* ADD and UPDATE share the same code that adds new partitions. */
@@ -656,6 +658,7 @@ main(int argc, char **argv){
 		printf("loop deleted : %s\n", device);
 	}
 
+end:
 	dm_lib_release();
 	dm_lib_exit();
 
-- 
2.14.0




More information about the dm-devel mailing list