@@ -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();
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@suse.com> --- kpartx/kpartx.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)