All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: device-mapper development <dm-devel@redhat.com>,
	Martin Wilck <Martin.Wilck@suse.com>
Subject: [dm-devel] [PATCH] kpartx: free loop device after listing partitions
Date: Wed, 24 Feb 2021 00:05:13 -0600	[thread overview]
Message-ID: <1614146713-19694-1-git-send-email-bmarzins@redhat.com> (raw)

If "kpartx -l" is run on a file that doesn't already have a loop device
associated with it, it will create a loop device to run the command.
Starting with da59d15c6 ("Fix loopback file with kpartx -av"), it will
not free the loop device when exitting. This is because it checks if the
the file it stat()ed is a regular file, before freeing the loop device.
However, after da59d15c6, stat() is rerun on the loop device itself, so
the check fails.  There is no need to check this, if loopcreated is
true, then the file will be a kpartx created loop device, and should be
freed.

Also, keep kpartx from printing that the loop device has been removed
at normal verbosity.

Fixes: da59d15c6 ("Fix loopback file with kpartx -av")
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 kpartx/kpartx.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 6a7933fa..8ff116b8 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -424,7 +424,7 @@ main(int argc, char **argv){
 					fprintf(stderr, "can't del loop : %s\n",
 					       loopdev);
 				r = 1;
-			} else
+			} else if (verbose)
 				fprintf(stderr, "loop deleted : %s\n", loopdev);
 		}
 		goto end;
@@ -668,16 +668,17 @@ main(int argc, char **argv){
 		if (n > 0)
 			break;
 	}
-	if (what == LIST && loopcreated && S_ISREG (buf.st_mode)) {
+	if (what == LIST && loopcreated) {
 		if (fd != -1)
 			close(fd);
 		if (del_loop(device)) {
 			if (verbose)
-				printf("can't del loop : %s\n",
+				fprintf(stderr, "can't del loop : %s\n",
 					device);
 			exit(1);
 		}
-		printf("loop deleted : %s\n", device);
+		if (verbose)
+			fprintf(stderr, "loop deleted : %s\n", device);
 	}
 
 end:
-- 
2.17.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


             reply	other threads:[~2021-02-24  6:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24  6:05 Benjamin Marzinski [this message]
2021-03-12 15:53 ` [dm-devel] [PATCH] kpartx: free loop device after listing partitions Martin Wilck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1614146713-19694-1-git-send-email-bmarzins@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=Martin.Wilck@suse.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.