DM-Devel Archive mirror
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: DM-DEVEL ML <dm-devel@lists.linux.dev>
Cc: Glenn Washburn <development@efficientek.com>,
	Martin Wilck <mwilck@suse.com>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	Christophe Varoqui <christophe.varoqui@opensvc.com>
Subject: [PATCH] kpartx: Add -N option to allow specifying a devmapping name
Date: Thu,  4 Apr 2024 19:23:32 -0500	[thread overview]
Message-ID: <20240405002332.442743-1-development@efficientek.com> (raw)

Running `kpartx -a disk.img` will create device names like
`/dev/mapper/loopNpM` where `N` and `M` are positive integers. The issue is
that `loopN` is not known before hand. `losetup -f` can be used to figure
out what the next loop device will be, but the loop device might be taken
by something else between then and when kpartx finds the next loop device.
Add a new option `-N` which takes a string argument that will be used as
the base name of the devmapper device.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 kpartx/kpartx.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 46cb76bac678..750b889327e9 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -88,7 +88,7 @@ initpts(void)
 	addpts("ps3", read_ps3_pt);
 }
 
-static char short_opts[] = "rladfgvp:t:snu";
+static char short_opts[] = "rladfgvp:t:snuN:";
 
 /* Used in gpt.c */
 int force_gpt=0;
@@ -99,7 +99,7 @@ static int
 usage(void) {
 	printf(VERSION_STRING);
 	printf("Usage:\n");
-	printf("  kpartx [-a|-d|-u|-l] [-r] [-p] [-f] [-g] [-s|-n] [-v] wholedisk\n");
+	printf("  kpartx [-a|-d|-u|-l] [-r] [-p] [-f] [-g] [-s|-n] [-v] [-N name] wholedisk\n");
 	printf("\t-a add partition devmappings\n");
 	printf("\t-r devmappings will be readonly\n");
 	printf("\t-d del partition devmappings\n");
@@ -111,6 +111,7 @@ usage(void) {
 	printf("\t-v verbose\n");
 	printf("\t-n nosync mode. Return before the partitions are created\n");
 	printf("\t-s sync mode (Default). Don't return until the partitions are created\n");
+	printf("\t-N use name as base name for device\n");
 	return 1;
 }
 
@@ -312,6 +313,9 @@ main(int argc, char **argv){
 		case 'u':
 			what = UPDATE;
 			break;
+		case 'N':
+			mapname = optarg;
+			break;
 		default:
 			usage();
 			exit(1);
-- 
2.34.1


             reply	other threads:[~2024-04-05  0:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05  0:23 Glenn Washburn [this message]
2024-04-05 16:52 ` [PATCH] kpartx: Add -N option to allow specifying a devmapping name 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=20240405002332.442743-1-development@efficientek.com \
    --to=development@efficientek.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=mwilck@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).