|
|
05be62 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
05be62 |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
05be62 |
Date: Tue, 9 Feb 2021 17:16:04 -0600
|
|
|
05be62 |
Subject: [PATCH] kpartx: free loop device after listing partitions
|
|
|
05be62 |
|
|
|
05be62 |
If "kpartx -l" is run on a file that doesn't already have a loop device
|
|
|
05be62 |
associated with it, it will create a loop device to run the command.
|
|
|
05be62 |
Starting with da59d15c6 ("Fix loopback file with kpartx -av"), it will
|
|
|
05be62 |
not free the loop device when exitting. This is because it checks if the
|
|
|
05be62 |
the file it stat()ed is a regular file, before freeing the loop device.
|
|
|
05be62 |
However, after da59d15c6, stat() is rerun on the loop device itself, so
|
|
|
05be62 |
the check fails. There is no need to check this, if loopcreated is
|
|
|
05be62 |
true, then the file will be a kpartx created loop device, and should be
|
|
|
05be62 |
freed.
|
|
|
05be62 |
|
|
|
05be62 |
Also, keep kpartx from printing that the loop device has been removed
|
|
|
05be62 |
at normal verbosity.
|
|
|
05be62 |
|
|
|
05be62 |
Fixes: da59d15c6 ("Fix loopback file with kpartx -av")
|
|
|
05be62 |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
05be62 |
---
|
|
|
05be62 |
kpartx/kpartx.c | 9 +++++----
|
|
|
05be62 |
1 file changed, 5 insertions(+), 4 deletions(-)
|
|
|
05be62 |
|
|
|
05be62 |
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
|
|
|
05be62 |
index 653ce0c8..a337a07b 100644
|
|
|
05be62 |
--- a/kpartx/kpartx.c
|
|
|
05be62 |
+++ b/kpartx/kpartx.c
|
|
|
05be62 |
@@ -407,7 +407,7 @@ main(int argc, char **argv){
|
|
|
05be62 |
fprintf(stderr, "can't del loop : %s\n",
|
|
|
05be62 |
loopdev);
|
|
|
05be62 |
r = 1;
|
|
|
05be62 |
- } else
|
|
|
05be62 |
+ } else if (verbose)
|
|
|
05be62 |
fprintf(stderr, "loop deleted : %s\n", loopdev);
|
|
|
05be62 |
}
|
|
|
05be62 |
goto end;
|
|
|
05be62 |
@@ -649,16 +649,17 @@ main(int argc, char **argv){
|
|
|
05be62 |
if (n > 0)
|
|
|
05be62 |
break;
|
|
|
05be62 |
}
|
|
|
05be62 |
- if (what == LIST && loopcreated && S_ISREG (buf.st_mode)) {
|
|
|
05be62 |
+ if (what == LIST && loopcreated) {
|
|
|
05be62 |
if (fd != -1)
|
|
|
05be62 |
close(fd);
|
|
|
05be62 |
if (del_loop(device)) {
|
|
|
05be62 |
if (verbose)
|
|
|
05be62 |
- printf("can't del loop : %s\n",
|
|
|
05be62 |
+ fprintf(stderr, "can't del loop : %s\n",
|
|
|
05be62 |
device);
|
|
|
05be62 |
exit(1);
|
|
|
05be62 |
}
|
|
|
05be62 |
- printf("loop deleted : %s\n", device);
|
|
|
05be62 |
+ if (verbose)
|
|
|
05be62 |
+ fprintf(stderr, "loop deleted : %s\n", device);
|
|
|
05be62 |
}
|
|
|
05be62 |
|
|
|
05be62 |
end:
|
|
|
05be62 |
--
|
|
|
05be62 |
2.17.2
|
|
|
05be62 |
|