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