* [PATCH v2 0/2] get UUID of mounted filesystems @ 2022-12-19 18:18 Catherine Hoang 2022-12-19 18:18 ` [PATCH v2 1/2] xfs_io: add fsuuid command Catherine Hoang 2022-12-19 18:18 ` [PATCH v2 2/2] xfs_admin: get UUID of mounted filesystem Catherine Hoang 0 siblings, 2 replies; 7+ messages in thread From: Catherine Hoang @ 2022-12-19 18:18 UTC (permalink / raw) To: linux-xfs Hi all, This series adds a new fsuuid command and adapts xfs_admin to call xfs_io when a filesystem is mounted. This is a precursor to enabling xfs_admin to set the UUID of a mounted filesystem. v1->v2: - Add fsuuid command to xfs_io man page - xfs_admin returns error if both online and offline options are specified - Update xfs_admin man page Comments and feedback appreciated! Catherine Catherine Hoang (2): xfs_io: add fsuuid command xfs_admin: get UUID of mounted filesystem db/xfs_admin.sh | 27 ++++++++++++++++++++---- io/Makefile | 6 +++--- io/fsuuid.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ io/init.c | 1 + io/io.h | 1 + man/man8/xfs_admin.8 | 4 ++++ man/man8/xfs_io.8 | 3 +++ 7 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 io/fsuuid.c -- 2.25.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] xfs_io: add fsuuid command 2022-12-19 18:18 [PATCH v2 0/2] get UUID of mounted filesystems Catherine Hoang @ 2022-12-19 18:18 ` Catherine Hoang 2022-12-20 21:55 ` Darrick J. Wong 2022-12-19 18:18 ` [PATCH v2 2/2] xfs_admin: get UUID of mounted filesystem Catherine Hoang 1 sibling, 1 reply; 7+ messages in thread From: Catherine Hoang @ 2022-12-19 18:18 UTC (permalink / raw) To: linux-xfs Add support for the fsuuid command to retrieve the UUID of a mounted filesystem. Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> Reviewed-by: Allison Henderson <allison.henderson@oracle.com> --- io/Makefile | 6 +++--- io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ io/init.c | 1 + io/io.h | 1 + man/man8/xfs_io.8 | 3 +++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 io/fsuuid.c diff --git a/io/Makefile b/io/Makefile index 498174cf..53fef09e 100644 --- a/io/Makefile +++ b/io/Makefile @@ -10,12 +10,12 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh HFILES = init.h io.h CFILES = init.c \ attr.c bmap.c bulkstat.c crc32cselftest.c cowextsize.c encrypt.c \ - file.c freeze.c fsync.c getrusage.c imap.c inject.c label.c link.c \ - mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ + file.c freeze.c fsuuid.c fsync.c getrusage.c imap.c inject.c label.c \ + link.c mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ resblks.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \ truncate.c utimes.c -LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) +LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBUUID) LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) LLDFLAGS = -static-libtool-libs diff --git a/io/fsuuid.c b/io/fsuuid.c new file mode 100644 index 00000000..7e14a95d --- /dev/null +++ b/io/fsuuid.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Oracle. + * All Rights Reserved. + */ + +#include "libxfs.h" +#include "command.h" +#include "init.h" +#include "io.h" +#include "libfrog/fsgeom.h" +#include "libfrog/logging.h" + +static cmdinfo_t fsuuid_cmd; + +static int +fsuuid_f( + int argc, + char **argv) +{ + struct xfs_fsop_geom fsgeo; + int ret; + char bp[40]; + + ret = -xfrog_geometry(file->fd, &fsgeo); + + if (ret) { + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); + exitcode = 1; + } else { + platform_uuid_unparse((uuid_t *)fsgeo.uuid, bp); + printf("UUID = %s\n", bp); + } + + return 0; +} + +void +fsuuid_init(void) +{ + fsuuid_cmd.name = "fsuuid"; + fsuuid_cmd.cfunc = fsuuid_f; + fsuuid_cmd.argmin = 0; + fsuuid_cmd.argmax = 0; + fsuuid_cmd.flags = CMD_FLAG_ONESHOT | CMD_NOMAP_OK; + fsuuid_cmd.oneline = _("get mounted filesystem UUID"); + + add_command(&fsuuid_cmd); +} diff --git a/io/init.c b/io/init.c index 033ed67d..104cd2c1 100644 --- a/io/init.c +++ b/io/init.c @@ -56,6 +56,7 @@ init_commands(void) flink_init(); freeze_init(); fsmap_init(); + fsuuid_init(); fsync_init(); getrusage_init(); help_init(); diff --git a/io/io.h b/io/io.h index 64b7a663..fe474faf 100644 --- a/io/io.h +++ b/io/io.h @@ -94,6 +94,7 @@ extern void encrypt_init(void); extern void file_init(void); extern void flink_init(void); extern void freeze_init(void); +extern void fsuuid_init(void); extern void fsync_init(void); extern void getrusage_init(void); extern void help_init(void); diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 223b5152..ef7087b3 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1455,6 +1455,9 @@ This option is not compatible with the flag. .RE .PD +.TP +.B fsuuid +Print the mounted filesystem UUID. .SH OTHER COMMANDS -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] xfs_io: add fsuuid command 2022-12-19 18:18 ` [PATCH v2 1/2] xfs_io: add fsuuid command Catherine Hoang @ 2022-12-20 21:55 ` Darrick J. Wong 2022-12-21 7:11 ` Catherine Hoang 0 siblings, 1 reply; 7+ messages in thread From: Darrick J. Wong @ 2022-12-20 21:55 UTC (permalink / raw) To: Catherine Hoang; +Cc: linux-xfs On Mon, Dec 19, 2022 at 10:18:23AM -0800, Catherine Hoang wrote: > Add support for the fsuuid command to retrieve the UUID of a mounted > filesystem. > > Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> > Reviewed-by: Allison Henderson <allison.henderson@oracle.com> > --- > io/Makefile | 6 +++--- > io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ > io/init.c | 1 + > io/io.h | 1 + > man/man8/xfs_io.8 | 3 +++ > 5 files changed, 57 insertions(+), 3 deletions(-) > create mode 100644 io/fsuuid.c > > diff --git a/io/Makefile b/io/Makefile > index 498174cf..53fef09e 100644 > --- a/io/Makefile > +++ b/io/Makefile > @@ -10,12 +10,12 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh > HFILES = init.h io.h > CFILES = init.c \ > attr.c bmap.c bulkstat.c crc32cselftest.c cowextsize.c encrypt.c \ > - file.c freeze.c fsync.c getrusage.c imap.c inject.c label.c link.c \ > - mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ > + file.c freeze.c fsuuid.c fsync.c getrusage.c imap.c inject.c label.c \ > + link.c mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ > resblks.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \ > truncate.c utimes.c > > -LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) > +LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBUUID) > LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) > LLDFLAGS = -static-libtool-libs > > diff --git a/io/fsuuid.c b/io/fsuuid.c > new file mode 100644 > index 00000000..7e14a95d > --- /dev/null > +++ b/io/fsuuid.c > @@ -0,0 +1,49 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2022 Oracle. > + * All Rights Reserved. > + */ > + > +#include "libxfs.h" > +#include "command.h" > +#include "init.h" > +#include "io.h" > +#include "libfrog/fsgeom.h" > +#include "libfrog/logging.h" > + > +static cmdinfo_t fsuuid_cmd; > + > +static int > +fsuuid_f( > + int argc, > + char **argv) > +{ > + struct xfs_fsop_geom fsgeo; > + int ret; > + char bp[40]; > + > + ret = -xfrog_geometry(file->fd, &fsgeo); > + > + if (ret) { > + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); > + exitcode = 1; > + } else { > + platform_uuid_unparse((uuid_t *)fsgeo.uuid, bp); > + printf("UUID = %s\n", bp); Lowercase "uuid" to match the xfs_db uuid command. With that fixed, Reviewed-by: Darrick J. Wong <djwong@kernel.org> --D > + } > + > + return 0; > +} > + > +void > +fsuuid_init(void) > +{ > + fsuuid_cmd.name = "fsuuid"; > + fsuuid_cmd.cfunc = fsuuid_f; > + fsuuid_cmd.argmin = 0; > + fsuuid_cmd.argmax = 0; > + fsuuid_cmd.flags = CMD_FLAG_ONESHOT | CMD_NOMAP_OK; > + fsuuid_cmd.oneline = _("get mounted filesystem UUID"); > + > + add_command(&fsuuid_cmd); > +} > diff --git a/io/init.c b/io/init.c > index 033ed67d..104cd2c1 100644 > --- a/io/init.c > +++ b/io/init.c > @@ -56,6 +56,7 @@ init_commands(void) > flink_init(); > freeze_init(); > fsmap_init(); > + fsuuid_init(); > fsync_init(); > getrusage_init(); > help_init(); > diff --git a/io/io.h b/io/io.h > index 64b7a663..fe474faf 100644 > --- a/io/io.h > +++ b/io/io.h > @@ -94,6 +94,7 @@ extern void encrypt_init(void); > extern void file_init(void); > extern void flink_init(void); > extern void freeze_init(void); > +extern void fsuuid_init(void); > extern void fsync_init(void); > extern void getrusage_init(void); > extern void help_init(void); > diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 > index 223b5152..ef7087b3 100644 > --- a/man/man8/xfs_io.8 > +++ b/man/man8/xfs_io.8 > @@ -1455,6 +1455,9 @@ This option is not compatible with the > flag. > .RE > .PD > +.TP > +.B fsuuid > +Print the mounted filesystem UUID. > > > .SH OTHER COMMANDS > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] xfs_io: add fsuuid command 2022-12-20 21:55 ` Darrick J. Wong @ 2022-12-21 7:11 ` Catherine Hoang 2022-12-21 16:24 ` Darrick J. Wong 0 siblings, 1 reply; 7+ messages in thread From: Catherine Hoang @ 2022-12-21 7:11 UTC (permalink / raw) To: Darrick J. Wong; +Cc: linux-xfs@vger.kernel.org > On Dec 20, 2022, at 1:55 PM, Darrick J. Wong <djwong@kernel.org> wrote: > > On Mon, Dec 19, 2022 at 10:18:23AM -0800, Catherine Hoang wrote: >> Add support for the fsuuid command to retrieve the UUID of a mounted >> filesystem. >> >> Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> >> Reviewed-by: Allison Henderson <allison.henderson@oracle.com> >> --- >> io/Makefile | 6 +++--- >> io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ >> io/init.c | 1 + >> io/io.h | 1 + >> man/man8/xfs_io.8 | 3 +++ >> 5 files changed, 57 insertions(+), 3 deletions(-) >> create mode 100644 io/fsuuid.c >> >> diff --git a/io/Makefile b/io/Makefile >> index 498174cf..53fef09e 100644 >> --- a/io/Makefile >> +++ b/io/Makefile >> @@ -10,12 +10,12 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh >> HFILES = init.h io.h >> CFILES = init.c \ >> attr.c bmap.c bulkstat.c crc32cselftest.c cowextsize.c encrypt.c \ >> - file.c freeze.c fsync.c getrusage.c imap.c inject.c label.c link.c \ >> - mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ >> + file.c freeze.c fsuuid.c fsync.c getrusage.c imap.c inject.c label.c \ >> + link.c mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ >> resblks.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \ >> truncate.c utimes.c >> >> -LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) >> +LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBUUID) >> LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) >> LLDFLAGS = -static-libtool-libs >> >> diff --git a/io/fsuuid.c b/io/fsuuid.c >> new file mode 100644 >> index 00000000..7e14a95d >> --- /dev/null >> +++ b/io/fsuuid.c >> @@ -0,0 +1,49 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Copyright (c) 2022 Oracle. >> + * All Rights Reserved. >> + */ >> + >> +#include "libxfs.h" >> +#include "command.h" >> +#include "init.h" >> +#include "io.h" >> +#include "libfrog/fsgeom.h" >> +#include "libfrog/logging.h" >> + >> +static cmdinfo_t fsuuid_cmd; >> + >> +static int >> +fsuuid_f( >> + int argc, >> + char **argv) >> +{ >> + struct xfs_fsop_geom fsgeo; >> + int ret; >> + char bp[40]; >> + >> + ret = -xfrog_geometry(file->fd, &fsgeo); >> + >> + if (ret) { >> + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); >> + exitcode = 1; >> + } else { >> + platform_uuid_unparse((uuid_t *)fsgeo.uuid, bp); >> + printf("UUID = %s\n", bp); > > Lowercase "uuid" to match the xfs_db uuid command. I noticed xfs_db also prints “uuid" in uppercase, so I didn’t change it > > With that fixed, > Reviewed-by: Darrick J. Wong <djwong@kernel.org> Thanks for reviewing! > > --D > >> + } >> + >> + return 0; >> +} >> + >> +void >> +fsuuid_init(void) >> +{ >> + fsuuid_cmd.name = "fsuuid"; >> + fsuuid_cmd.cfunc = fsuuid_f; >> + fsuuid_cmd.argmin = 0; >> + fsuuid_cmd.argmax = 0; >> + fsuuid_cmd.flags = CMD_FLAG_ONESHOT | CMD_NOMAP_OK; >> + fsuuid_cmd.oneline = _("get mounted filesystem UUID"); >> + >> + add_command(&fsuuid_cmd); >> +} >> diff --git a/io/init.c b/io/init.c >> index 033ed67d..104cd2c1 100644 >> --- a/io/init.c >> +++ b/io/init.c >> @@ -56,6 +56,7 @@ init_commands(void) >> flink_init(); >> freeze_init(); >> fsmap_init(); >> + fsuuid_init(); >> fsync_init(); >> getrusage_init(); >> help_init(); >> diff --git a/io/io.h b/io/io.h >> index 64b7a663..fe474faf 100644 >> --- a/io/io.h >> +++ b/io/io.h >> @@ -94,6 +94,7 @@ extern void encrypt_init(void); >> extern void file_init(void); >> extern void flink_init(void); >> extern void freeze_init(void); >> +extern void fsuuid_init(void); >> extern void fsync_init(void); >> extern void getrusage_init(void); >> extern void help_init(void); >> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 >> index 223b5152..ef7087b3 100644 >> --- a/man/man8/xfs_io.8 >> +++ b/man/man8/xfs_io.8 >> @@ -1455,6 +1455,9 @@ This option is not compatible with the >> flag. >> .RE >> .PD >> +.TP >> +.B fsuuid >> +Print the mounted filesystem UUID. >> >> >> .SH OTHER COMMANDS >> -- >> 2.25.1 >> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] xfs_io: add fsuuid command 2022-12-21 7:11 ` Catherine Hoang @ 2022-12-21 16:24 ` Darrick J. Wong 0 siblings, 0 replies; 7+ messages in thread From: Darrick J. Wong @ 2022-12-21 16:24 UTC (permalink / raw) To: Catherine Hoang; +Cc: linux-xfs@vger.kernel.org On Wed, Dec 21, 2022 at 07:11:42AM +0000, Catherine Hoang wrote: > > On Dec 20, 2022, at 1:55 PM, Darrick J. Wong <djwong@kernel.org> wrote: > > > > On Mon, Dec 19, 2022 at 10:18:23AM -0800, Catherine Hoang wrote: > >> Add support for the fsuuid command to retrieve the UUID of a mounted > >> filesystem. > >> > >> Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> > >> Reviewed-by: Allison Henderson <allison.henderson@oracle.com> > >> --- > >> io/Makefile | 6 +++--- > >> io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ > >> io/init.c | 1 + > >> io/io.h | 1 + > >> man/man8/xfs_io.8 | 3 +++ > >> 5 files changed, 57 insertions(+), 3 deletions(-) > >> create mode 100644 io/fsuuid.c > >> > >> diff --git a/io/Makefile b/io/Makefile > >> index 498174cf..53fef09e 100644 > >> --- a/io/Makefile > >> +++ b/io/Makefile > >> @@ -10,12 +10,12 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh > >> HFILES = init.h io.h > >> CFILES = init.c \ > >> attr.c bmap.c bulkstat.c crc32cselftest.c cowextsize.c encrypt.c \ > >> - file.c freeze.c fsync.c getrusage.c imap.c inject.c label.c link.c \ > >> - mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ > >> + file.c freeze.c fsuuid.c fsync.c getrusage.c imap.c inject.c label.c \ > >> + link.c mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ > >> resblks.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \ > >> truncate.c utimes.c > >> > >> -LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) > >> +LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBUUID) > >> LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) > >> LLDFLAGS = -static-libtool-libs > >> > >> diff --git a/io/fsuuid.c b/io/fsuuid.c > >> new file mode 100644 > >> index 00000000..7e14a95d > >> --- /dev/null > >> +++ b/io/fsuuid.c > >> @@ -0,0 +1,49 @@ > >> +// SPDX-License-Identifier: GPL-2.0 > >> +/* > >> + * Copyright (c) 2022 Oracle. > >> + * All Rights Reserved. > >> + */ > >> + > >> +#include "libxfs.h" > >> +#include "command.h" > >> +#include "init.h" > >> +#include "io.h" > >> +#include "libfrog/fsgeom.h" > >> +#include "libfrog/logging.h" > >> + > >> +static cmdinfo_t fsuuid_cmd; > >> + > >> +static int > >> +fsuuid_f( > >> + int argc, > >> + char **argv) > >> +{ > >> + struct xfs_fsop_geom fsgeo; > >> + int ret; > >> + char bp[40]; > >> + > >> + ret = -xfrog_geometry(file->fd, &fsgeo); > >> + > >> + if (ret) { > >> + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); > >> + exitcode = 1; > >> + } else { > >> + platform_uuid_unparse((uuid_t *)fsgeo.uuid, bp); > >> + printf("UUID = %s\n", bp); > > > > Lowercase "uuid" to match the xfs_db uuid command. > > I noticed xfs_db also prints “uuid" in uppercase, so I didn’t change it Lol, dunno why I didn't notice that. :/ Carry on! --D > > With that fixed, > > Reviewed-by: Darrick J. Wong <djwong@kernel.org> > > Thanks for reviewing! > > > > --D > > > >> + } > >> + > >> + return 0; > >> +} > >> + > >> +void > >> +fsuuid_init(void) > >> +{ > >> + fsuuid_cmd.name = "fsuuid"; > >> + fsuuid_cmd.cfunc = fsuuid_f; > >> + fsuuid_cmd.argmin = 0; > >> + fsuuid_cmd.argmax = 0; > >> + fsuuid_cmd.flags = CMD_FLAG_ONESHOT | CMD_NOMAP_OK; > >> + fsuuid_cmd.oneline = _("get mounted filesystem UUID"); > >> + > >> + add_command(&fsuuid_cmd); > >> +} > >> diff --git a/io/init.c b/io/init.c > >> index 033ed67d..104cd2c1 100644 > >> --- a/io/init.c > >> +++ b/io/init.c > >> @@ -56,6 +56,7 @@ init_commands(void) > >> flink_init(); > >> freeze_init(); > >> fsmap_init(); > >> + fsuuid_init(); > >> fsync_init(); > >> getrusage_init(); > >> help_init(); > >> diff --git a/io/io.h b/io/io.h > >> index 64b7a663..fe474faf 100644 > >> --- a/io/io.h > >> +++ b/io/io.h > >> @@ -94,6 +94,7 @@ extern void encrypt_init(void); > >> extern void file_init(void); > >> extern void flink_init(void); > >> extern void freeze_init(void); > >> +extern void fsuuid_init(void); > >> extern void fsync_init(void); > >> extern void getrusage_init(void); > >> extern void help_init(void); > >> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 > >> index 223b5152..ef7087b3 100644 > >> --- a/man/man8/xfs_io.8 > >> +++ b/man/man8/xfs_io.8 > >> @@ -1455,6 +1455,9 @@ This option is not compatible with the > >> flag. > >> .RE > >> .PD > >> +.TP > >> +.B fsuuid > >> +Print the mounted filesystem UUID. > >> > >> > >> .SH OTHER COMMANDS > >> -- > >> 2.25.1 > >> > ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] xfs_admin: get UUID of mounted filesystem 2022-12-19 18:18 [PATCH v2 0/2] get UUID of mounted filesystems Catherine Hoang 2022-12-19 18:18 ` [PATCH v2 1/2] xfs_io: add fsuuid command Catherine Hoang @ 2022-12-19 18:18 ` Catherine Hoang 2022-12-20 22:29 ` Darrick J. Wong 1 sibling, 1 reply; 7+ messages in thread From: Catherine Hoang @ 2022-12-19 18:18 UTC (permalink / raw) To: linux-xfs Adapt this tool to call xfs_io to retrieve the UUID of a mounted filesystem. This is a precursor to enabling xfs_admin to set the UUID of a mounted filesystem. Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> Reviewed-by: Allison Henderson <allison.henderson@oracle.com> --- db/xfs_admin.sh | 27 +++++++++++++++++++++++---- man/man8/xfs_admin.8 | 4 ++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/db/xfs_admin.sh b/db/xfs_admin.sh index 409975b2..cc9a2150 100755 --- a/db/xfs_admin.sh +++ b/db/xfs_admin.sh @@ -6,10 +6,12 @@ status=0 DB_OPTS="" +DB_EXTRA_OPTS="" +IO_OPTS="" REPAIR_OPTS="" REPAIR_DEV_OPTS="" LOG_OPTS="" -USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev] [-U uuid] device [logdev]" +USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev] [-U uuid] [mountpoint|device] [logdev]" while getopts "c:efjlL:O:pr:uU:V" c do @@ -23,7 +25,8 @@ do O) REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG";; p) DB_OPTS=$DB_OPTS" -c 'version projid32bit'";; r) REPAIR_DEV_OPTS=" -r '$OPTARG'";; - u) DB_OPTS=$DB_OPTS" -r -c uuid";; + u) DB_EXTRA_OPTS=$DB_EXTRA_OPTS" -r -c uuid"; + IO_OPTS=$IO_OPTS" -r -c fsuuid";; U) DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";; V) xfs_db -p xfs_admin -V status=$? @@ -38,14 +41,30 @@ set -- extra $@ shift $OPTIND case $# in 1|2) + # Target either a device or mountpoint, not both + if [ -n "$(findmnt -t xfs -T $1)" ]; then + if [ -n "$DB_OPTS" ] || [ -n "$REPAIR_OPTS" ]; then + echo "Offline options target a device, not mountpoint." + exit 2 + fi + DB_EXTRA_OPTS="" + else + IO_OPTS="" + fi + # Pick up the log device, if present if [ -n "$2" ]; then LOG_OPTS=" -l '$2'" fi - if [ -n "$DB_OPTS" ] + if [ -n "$DB_OPTS" ] || [ -n "$DB_EXTRA_OPTS" ] + then + eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_OPTS $DB_EXTRA_OPTS "$1" + status=$? + fi + if [ -n "$IO_OPTS" ] then - eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_OPTS "$1" + eval xfs_io -x -p xfs_admin $IO_OPTS "$1" status=$? fi if [ -n "$REPAIR_OPTS" ] diff --git a/man/man8/xfs_admin.8 b/man/man8/xfs_admin.8 index 4794d677..2c7ddc15 100644 --- a/man/man8/xfs_admin.8 +++ b/man/man8/xfs_admin.8 @@ -19,7 +19,11 @@ xfs_admin \- change parameters of an XFS filesystem .B \-r .I rtdev ] +[ +.I mount-point +| .I device +] [ .I logdev ] -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] xfs_admin: get UUID of mounted filesystem 2022-12-19 18:18 ` [PATCH v2 2/2] xfs_admin: get UUID of mounted filesystem Catherine Hoang @ 2022-12-20 22:29 ` Darrick J. Wong 0 siblings, 0 replies; 7+ messages in thread From: Darrick J. Wong @ 2022-12-20 22:29 UTC (permalink / raw) To: Catherine Hoang; +Cc: linux-xfs On Mon, Dec 19, 2022 at 10:18:24AM -0800, Catherine Hoang wrote: > Adapt this tool to call xfs_io to retrieve the UUID of a mounted filesystem. > This is a precursor to enabling xfs_admin to set the UUID of a mounted > filesystem. > > Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> > Reviewed-by: Allison Henderson <allison.henderson@oracle.com> > --- > db/xfs_admin.sh | 27 +++++++++++++++++++++++---- > man/man8/xfs_admin.8 | 4 ++++ > 2 files changed, 27 insertions(+), 4 deletions(-) > > diff --git a/db/xfs_admin.sh b/db/xfs_admin.sh > index 409975b2..cc9a2150 100755 > --- a/db/xfs_admin.sh > +++ b/db/xfs_admin.sh > @@ -6,10 +6,12 @@ > > status=0 > DB_OPTS="" > +DB_EXTRA_OPTS="" > +IO_OPTS="" > REPAIR_OPTS="" > REPAIR_DEV_OPTS="" > LOG_OPTS="" > -USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev] [-U uuid] device [logdev]" > +USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev] [-U uuid] [mountpoint|device] [logdev]" I don't think it's necessary to expand xfs_admin to take a mount point, since findmnt returns the mount point associated with a block device. > > while getopts "c:efjlL:O:pr:uU:V" c > do > @@ -23,7 +25,8 @@ do > O) REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG";; > p) DB_OPTS=$DB_OPTS" -c 'version projid32bit'";; > r) REPAIR_DEV_OPTS=" -r '$OPTARG'";; > - u) DB_OPTS=$DB_OPTS" -r -c uuid";; > + u) DB_EXTRA_OPTS=$DB_EXTRA_OPTS" -r -c uuid"; > + IO_OPTS=$IO_OPTS" -r -c fsuuid";; > U) DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";; > V) xfs_db -p xfs_admin -V > status=$? > @@ -38,14 +41,30 @@ set -- extra $@ > shift $OPTIND > case $# in > 1|2) > + # Target either a device or mountpoint, not both > + if [ -n "$(findmnt -t xfs -T $1)" ]; then Note that xfs_io acts upon a mountpoint, not a block device, so you need to save the mount point that findmnt returns here. You might also want to look at the -o option to constrain its output to only the information you need. > + if [ -n "$DB_OPTS" ] || [ -n "$REPAIR_OPTS" ]; then > + echo "Offline options target a device, not mountpoint." > + exit 2 > + fi > + DB_EXTRA_OPTS="" > + else > + IO_OPTS="" Hmm. DB_EXTRA_OPS is really the container of xfs_db commands that also have xfs_io alternatives, whereas DB_OPTS/REPAIR_OPTS are things that require an unmounted fs. Yet we can't access OPTIND until after we've completely finished getopts processing. I suspect this isn't a great way to be handling this, because what does "EXTRA" mean, actually? It's not immediately obvious from the name. I can't help but wonder if the behaviors would be clearer if we tracked explicitly which subcommands require a mounted fs, which ones require an unmounted fs (nearly all of them), and which ones can go back and forth. Something like this: require_offline="" require_online="" DB_OPTS="" REPAIR_OPTS="" IO_OPTS="" <more initialization> while getopts "c:efjlL:O:pr:uU:V" c do case $c in c) REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG require_offline=1 ;; <more options here> u) DB_OPTS=$DB_OPTS" -r -c uuid" IO_OPTS=$IO_OPTS" -c uuid" ;; U) DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'" require_offline=1 ;; <rest of options here> done ...and then later on when it's time to take action... if mntpt="$(findmnt -t xfs -f -n -o TARGET "$1" 2>/dev/null)"; then # filesystem is mounted if [ -n "$require_offline" ]; then echo "$1: filesystem is mounted." exit 2 fi exec xfs_io -p xfs_admin "$IO_OPTS" "$mntpt" fi # filesystem is not mounted if [ -n "$require_offline" ]; then echo "$1: filesystem is not mounted" exit 2 fi <regular DB_OPTS/REPAIR_OPTS processing> --D > + fi > + > # Pick up the log device, if present > if [ -n "$2" ]; then > LOG_OPTS=" -l '$2'" > fi > > - if [ -n "$DB_OPTS" ] > + if [ -n "$DB_OPTS" ] || [ -n "$DB_EXTRA_OPTS" ] > + then > + eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_OPTS $DB_EXTRA_OPTS "$1" > + status=$? > + fi > + if [ -n "$IO_OPTS" ] > then > - eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_OPTS "$1" > + eval xfs_io -x -p xfs_admin $IO_OPTS "$1" > status=$? > fi > if [ -n "$REPAIR_OPTS" ] > diff --git a/man/man8/xfs_admin.8 b/man/man8/xfs_admin.8 > index 4794d677..2c7ddc15 100644 > --- a/man/man8/xfs_admin.8 > +++ b/man/man8/xfs_admin.8 > @@ -19,7 +19,11 @@ xfs_admin \- change parameters of an XFS filesystem > .B \-r > .I rtdev > ] > +[ > +.I mount-point > +| > .I device > +] > [ > .I logdev > ] > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-12-21 16:25 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-12-19 18:18 [PATCH v2 0/2] get UUID of mounted filesystems Catherine Hoang 2022-12-19 18:18 ` [PATCH v2 1/2] xfs_io: add fsuuid command Catherine Hoang 2022-12-20 21:55 ` Darrick J. Wong 2022-12-21 7:11 ` Catherine Hoang 2022-12-21 16:24 ` Darrick J. Wong 2022-12-19 18:18 ` [PATCH v2 2/2] xfs_admin: get UUID of mounted filesystem Catherine Hoang 2022-12-20 22:29 ` Darrick J. Wong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox