All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ritika Srivastava <ritika.srivastava@oracle.com>
To: dm-devel@redhat.com
Subject: [dm-devel]  [PATCH] kpartx: Add -P option for partition scanning
Date: Fri, 11 Feb 2022 12:41:48 -0800	[thread overview]
Message-ID: <1644612108-2445-1-git-send-email-ritika.srivastava@oracle.com> (raw)

Add -P, partition scanning option to kpartx which would set
LO_FLAGS_PARTSCAN flag during loop device creation.
This option is same as losetup -P option.

Signed-off-by: Ritika Srivastava <ritika.srivastava@oracle.com>
---
 kpartx/kpartx.c | 17 +++++++++++++----
 kpartx/lopart.c |  5 ++++-
 kpartx/lopart.h |  2 +-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 3c49999..a26d0a2 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -87,7 +87,7 @@ initpts(void)
 	addpts("ps3", read_ps3_pt);
 }
 
-static char short_opts[] = "rladfgvp:t:snu";
+static char short_opts[] = "rladfPgvp:t:snu";
 
 /* Used in gpt.c */
 int force_gpt=0;
@@ -98,7 +98,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] [-P] wholedisk\n");
 	printf("\t-a add partition devmappings\n");
 	printf("\t-r devmappings will be readonly\n");
 	printf("\t-d del partition devmappings\n");
@@ -110,6 +110,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-P create partitioned loop device\n");
 	return 1;
 }
 
@@ -228,7 +229,7 @@ xmalloc (size_t size) {
 
 int
 main(int argc, char **argv){
-	int i, j, m, n, op, off, arg, c, d, ro=0;
+	int i, j, m, n, op, off, arg, c, d, ro=0, partscan = 0;
 	int fd = -1;
 	struct slice all;
 	struct pt *ptp;
@@ -311,6 +312,9 @@ main(int argc, char **argv){
 		case 'u':
 			what = UPDATE;
 			break;
+		case 'P':
+			partscan = 1;
+			break;
 		default:
 			usage();
 			exit(1);
@@ -328,6 +332,11 @@ main(int argc, char **argv){
 		exit(1);
 	}
 
+	if (what != ADD && partscan == 1)       {
+		printf("-P option is allowed only during loop device setup\n");
+		exit(1);
+	}
+
 	if (hotplug) {
 		/* already got [disk]device */
 	} else if (optind == argc-2) {
@@ -359,7 +368,7 @@ main(int argc, char **argv){
 			exit (0);
 
 		if (!loopdev) {
-			if (set_loop(&loopdev, rpath, 0, &ro)) {
+			if (set_loop(&loopdev, rpath, 0, &ro, partscan)) {
 				fprintf(stderr, "can't set up loop\n");
 				exit (1);
 			}
diff --git a/kpartx/lopart.c b/kpartx/lopart.c
index 512a59f..9a1ce48 100644
--- a/kpartx/lopart.c
+++ b/kpartx/lopart.c
@@ -233,7 +233,8 @@ no_loop_fd:
 	return NULL;
 }
 
-int set_loop(char **device, const char *file, int offset, int *loopro)
+int set_loop(char **device, const char *file, int offset, int *loopro,
+	     int partscan)
 {
 	struct loop_info loopinfo;
 	int fd = -1, ret = 1, ffd, mode;
@@ -264,6 +265,8 @@ int set_loop(char **device, const char *file, int offset, int *loopro)
 	loopinfo.lo_offset = offset;
 	loopinfo.lo_encrypt_type = LO_CRYPT_NONE;
 	loopinfo.lo_encrypt_key_size = 0;
+	if (partscan == 1)
+		loopinfo.lo_flags |= LO_FLAGS_PARTSCAN;
 
 	if (ioctl(fd, LOOP_SET_FD, (void*)(uintptr_t)(ffd)) < 0) {
 		perror ("ioctl: LOOP_SET_FD");
diff --git a/kpartx/lopart.h b/kpartx/lopart.h
index c73ab23..81534e2 100644
--- a/kpartx/lopart.h
+++ b/kpartx/lopart.h
@@ -1,4 +1,4 @@
 extern int verbose;
-extern int set_loop (char **, const char *, int, int *);
+extern int set_loop (char **, const char *, int, int *, int);
 extern int del_loop (const char *);
 extern char * find_loop_by_file (const char *);
-- 
2.27.0

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


             reply	other threads:[~2022-02-11 23:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 20:41 Ritika Srivastava [this message]
2022-02-22 18:16 ` [dm-devel] [PATCH] kpartx: Add -P option for partition scanning Ritika Srivastava
2022-02-22 18:27 ` Benjamin Marzinski
2022-02-22 18:59   ` Ritika Srivastava
2022-02-22 19:31     ` Benjamin Marzinski
2022-02-22 22:16       ` Ritika Srivastava
2022-02-28 22:44         ` Benjamin Marzinski
2022-03-02  0:07           ` Ritika Srivastava
2022-03-02 18:38             ` Benjamin Marzinski
2022-03-03 10:57               ` Martin Wilck
2022-03-03 17:38                 ` Ritika Srivastava
2022-02-11 22:34 Ritika Srivastava

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=1644612108-2445-1-git-send-email-ritika.srivastava@oracle.com \
    --to=ritika.srivastava@oracle.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.