On Fri, Feb 11, 2022 at 12:41:48PM -0800, Ritika Srivastava wrote: > 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. I'm confused here. What's the benefit of doing this? Doesn't this create partition devices, just like kpartx would? -Ben > > Signed-off-by: Ritika Srivastava <ritika.srivastava@xxxxxxxxxx> > --- > 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@xxxxxxxxxx > https://listman.redhat.com/mailman/listinfo/dm-devel -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel