Skip to contentSkip to conversation

get UUID of mounted filesystems

PATCH Superseded Catherine Hoang 4 participants 9 messages Dec 7, 2022 – Dec 13, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover get UUID of mounted filesystems

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.

Comments and feedback appreciated!

Catherine

Catherine Hoang (2):
xfs_io: add fsuuid command
xfs_admin: get UUID of mounted filesystem

 db/xfs_admin.sh | 21 ++++++++++++++++++---
 io/Makefile     |  6 +++---
 io/fsuuid.c     | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 io/init.c       |  1 +
 io/io.h         |  1 +
 5 files changed, 72 insertions(+), 6 deletions(-)
 create mode 100644 io/fsuuid.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 xfs_io: add fsuuid command

Add support for the fsuuid command to retrieve the UUID of a mounted filesystem.

---
 io/Makefile |  6 +++---
 io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 io/init.c   |  1 +
 io/io.h     |  1 +
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 io/fsuuid.c
io/Makefile +3 -3
index 498174cf..53fef09e 100644
@@ -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
 
io/fsuuid.c new file +49 -0

49 lines not on this page · raw message

io/init.c +1 -0
index 033ed67d..104cd2c1 100644
@@ -56,6 +56,7 @@ init_commands(void)
 	flink_init();
 	freeze_init();
 	fsmap_init();
+	fsuuid_init();
 	fsync_init();
 	getrusage_init();
 	help_init();
io/io.h +1 -0
index 64b7a663..fe474faf 100644
@@ -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);
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v1 1/2] xfs_io: add fsuuid command

Quoted 60 lines · Catherine Hoang

Add support for the fsuuid command to retrieve the UUID of a mounted filesystem.

---
 io/Makefile |  6 +++---
 io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 io/init.c   |  1 +
 io/io.h     |  1 +
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 io/fsuuid.c
io/Makefile +3 -3
index 498174cf..53fef09e 100644
@@ -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
 
io/fsuuid.c new file +22 -0
new file mode 100644
index 00000000..7e14a95d
@@ -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;

io/fsuuid.c line 32

Quoted 10 lines
io/fsuuid.c new file +10 -0
+	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.

Quoted 6 lines
io/fsuuid.c new file +6 -0
+	}
+
+	return 0;
+}
+
+void

io/fsuuid.c line 48

Quoted 10 lines
io/fsuuid.c new file +10 -0
+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);

New xfs_io commands should be added to man/man/xfs_io.8.

Other than those two issues, this looks good to me.

--D

Quoted 28 lines
io/fsuuid.c new file +1 -0
+}
io/init.c +1 -0
index 033ed67d..104cd2c1 100644
@@ -56,6 +56,7 @@ init_commands(void)
 	flink_init();
 	freeze_init();
 	fsmap_init();
+	fsuuid_init();
 	fsync_init();
 	getrusage_init();
 	help_init();
io/io.h +1 -0
index 64b7a663..fe474faf 100644
@@ -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);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH v1 1/2] xfs_io: add fsuuid command

In reply to Catherine Hoang
Quoted 4 lines · Catherine Hoang

Add support for the fsuuid command to retrieve the UUID of a mounted filesystem.

Nits aside, I think this is fine

Quoted 114 lines

---
 io/Makefile |  6 +++---
 io/fsuuid.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ io/init.c   |  1 +
 io/io.h     |  1 +

 4 files changed, 54 insertions(+), 3 deletions(-)

 create mode 100644 io/fsuuid.c

io/Makefile +0 -0
index 498174cf..53fef09e 100644
@@ -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

io/Makefile +1 -1
-LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
+LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)

$(LIBUUID)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) LLDFLAGS = -static-libtool-libs

io/fsuuid.c new file +49 -0
new file mode 100644
index 00000000..7e14a95d
@@ -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);
+}
io/init.c +1 -0
index 033ed67d..104cd2c1 100644
@@ -56,6 +56,7 @@ init_commands(void)
         flink_init();
         freeze_init();
         fsmap_init();
+       fsuuid_init();
         fsync_init();
         getrusage_init();
         help_init();
io/io.h +1 -0
index 64b7a663..fe474faf 100644
@@ -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);
#4 lore raw

PATCH 2/2 xfs_admin: get UUID of mounted filesystem

In reply to Catherine Hoang

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.

---
 db/xfs_admin.sh | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
db/xfs_admin.sh +18 -3
index 409975b2..0dcb9940 100755
@@ -6,6 +6,8 @@
 
 status=0
 DB_OPTS=""
+DB_EXTRA_OPTS=""
+IO_OPTS=""
 REPAIR_OPTS=""
 REPAIR_DEV_OPTS=""
 LOG_OPTS=""
@@ -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,26 @@ set -- extra $@
 shift $OPTIND
 case $# in
 	1|2)
+		# Use xfs_io if mounted and xfs_db if not mounted
+		if [ -n "$(findmnt -t xfs -T $1)" ]; then
+			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" ]
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v1 2/2] xfs_admin: get UUID of mounted filesystem

Quoted 14 lines · Catherine Hoang

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.

---
 db/xfs_admin.sh | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..0dcb9940 100755

db/xfs_admin.sh line 10

Quoted 5 lines
db/xfs_admin.sh +2 -0
@@ -6,6 +6,8 @@
 
 status=0
 DB_OPTS=""
+DB_EXTRA_OPTS=""
+IO_OPTS=""

This seemed oddly familiar until I remembered that we've been here before:
https://lore.kernel.org/linux-xfs/[email protected]/

And now that I've reread that thread, I've now realized /why/ I gave up on adding things to this script -- there were too many questions from the maintainer for which I couldn't come up with any satisfying answer. Then I burned out and gave up.

Ofc now we have a new maintainer, so I'll put the questions to the new one. To summarize:

What happens if there are multiple sources of truth because the fs is mounted? Do we stop after processing the online options and ignore the offline ones? Do we keep going, even though -f is almost certainly required?

If the user specifies multiple options, is it ok to change the order in which we run them so that we can run xfs_io and then xfs_db?

If it's not ok to change the order, how do we make the two tools run in lockstep so we only have to open the filesystem once?

If it's not ok to change the order and we cannot do lockstep, is it ok to invoke io/db once for each subcommand instead of assembling a giant cli option array like we now for db?

If we have to invoke io/db multiple times, what do we do if the state changes between invocations (e.g. someone else mounts the block dev or unmounts the fs)? What happens if this all results in multiple xfs_repair invocations?

Can we prohibit people from running multiple subcommands? Even if that's a breaking change for someone who might be relying on the exact behaviors of this shell script?

What if, instead of trying to find answers to all these annoying questions, we instead decide that either all the subcommands have to target a mountpoint or they all have to target a blockdev, or xfs_admin will exit with an error code?

--D

Quoted 45 lines
db/xfs_admin.sh +16 -3
 REPAIR_OPTS=""
 REPAIR_DEV_OPTS=""
 LOG_OPTS=""
@@ -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,26 @@ set -- extra $@
 shift $OPTIND
 case $# in
 	1|2)
+		# Use xfs_io if mounted and xfs_db if not mounted
+		if [ -n "$(findmnt -t xfs -T $1)" ]; then
+			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" ]
Signature · 1 line
2.25.1
Reviewed-by
#6 lore raw

Re: [PATCH v1 2/2] xfs_admin: get UUID of mounted filesystem

Quoted 69 lines · Darrick J. Wong
Quoted 19 lines · Catherine Hoang

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.

---
 db/xfs_admin.sh | 21 ++++++++++++++++++---

 1 file changed, 18 insertions(+), 3 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..0dcb9940 100755
@@ -6,6 +6,8 @@


 status=0
 DB_OPTS=""

db/xfs_admin.sh

Quoted 2 lines
db/xfs_admin.sh +2 -0
+DB_EXTRA_OPTS=""
+IO_OPTS=""

This seemed oddly familiar until I remembered that we've been here before:
https://lore.kernel.org/linux-xfs/[email protected]/

And now that I've reread that thread, I've now realized /why/ I gave up
on adding things to this script -- there were too many questions from the maintainer for which I couldn't come up with any satisfying answer.
Then I burned out and gave up.

Ofc now we have a new maintainer, so I'll put the questions to the new
one.  To summarize:

What happens if there are multiple sources of truth because the fs is mounted?  Do we stop after processing the online options and ignore the
offline ones?  Do we keep going, even though -f is almost certainly required?

If the user specifies multiple options, is it ok to change the order in
which we run them so that we can run xfs_io and then xfs_db?

If it's not ok to change the order, how do we make the two tools run in
lockstep so we only have to open the filesystem once?

If it's not ok to change the order and we cannot do lockstep, is it ok
to invoke io/db once for each subcommand instead of assembling a giant
cli option array like we now for db?

If we have to invoke io/db multiple times, what do we do if the state changes between invocations (e.g. someone else mounts the block dev or
unmounts the fs)?  What happens if this all results in multiple xfs_repair invocations?

Can we prohibit people from running multiple subcommands?  Even if that's a breaking change for someone who might be relying on the exact
behaviors of this shell script?

Quoted 7 lines

What if, instead of trying to find answers to all these annoying questions, we instead decide that either all the subcommands have to target a mountpoint or they all have to target a blockdev, or xfs_admin
will exit with an error code?

--D

So I applied Catherines patches, but it doesnt exactly have the same behaviors Eric commented on since this set doesnt have the extra label changes. Unless I missed some other behavioral issues with other flags that you are meaning to refer to? Otherwise I don't see that this introducing any odd behaviors. It's certainly not that the above questions are not valid, but I think it's reasonable for them to be addressed as a separate fix.

As far as the scope of this set is concerned tho, I think what Catherine has here is reasonable.

Quoted 48 lines
Quoted 48 lines

 REPAIR_OPTS=""
 REPAIR_DEV_OPTS=""
 LOG_OPTS=""

db/xfs_admin.sh +2 -1
@@ -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=$?

db/xfs_admin.sh +0 -0
@@ -38,14 +41,26 @@ set -- extra $@

 shift $OPTIND
 case $# in
        1|2)
+               # Use xfs_io if mounted and xfs_db if not mounted +               if [ -n "$(findmnt -t xfs -T $1)" ]; then +                       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" ]

Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH v1 2/2] xfs_admin: get UUID of mounted filesystem

In reply to Darrick J. Wong
Quoted 16 lines · Darrick J. Wong
Quoted 15 lines · Catherine Hoang

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.

---
 db/xfs_admin.sh | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..0dcb9940 100755
@@ -6,6 +6,8 @@
 
Quoted 5 lines

db/xfs_admin.sh line 10

Quoted 4 lines
db/xfs_admin.sh +2 -0
 status=0
 DB_OPTS=""
+DB_EXTRA_OPTS=""
+IO_OPTS=""

I'll try to come back later to this thread with better answers, but I didn't want to leave it with no answer at all, so, from a first glance:

Quoted 9 lines

This seemed oddly familiar until I remembered that we've been here before:
https://lore.kernel.org/linux-xfs/[email protected]/

And now that I've reread that thread, I've now realized /why/ I gave up on adding things to this script -- there were too many questions from the maintainer for which I couldn't come up with any satisfying answer. Then I burned out and gave up.

Quoted 7 lines

Ofc now we have a new maintainer, so I'll put the questions to the new one. To summarize:

What happens if there are multiple sources of truth because the fs is mounted? Do we stop after processing the online options and ignore the offline ones? Do we keep going, even though -f is almost certainly required?

/me has no idea, but to be honest, I'd say, those shouldn't be mixed, either target online, or offline. Both, seems a recipe for disaster IMHO.

Quoted 3 lines

If the user specifies multiple options, is it ok to change the order in which we run them so that we can run xfs_io and then xfs_db?

Good question. I don't think I have a decent answer for that by now. I'm inclined to say it really depends on the semantics of the output, if ordering it doesn't change the expected output I don't see why reordering would be a problem.
On the other hand, I think there is a myriad of possible combinations that would require evaluation to check when we are able to reorder or not. It it worth the effort?

Quoted 7 lines

If it's not ok to change the order, how do we make the two tools run in lockstep so we only have to open the filesystem once?

If it's not ok to change the order and we cannot do lockstep, is it ok to invoke io/db once for each subcommand instead of assembling a giant cli option array like we now for db?

I might be being naive here, but it doesn't sound bad. Performance is no big deal here I believe, so, some extra time invoking io/db once for each subcommand, instead of creating a spaghetti of possible options that may/may not work together, sounds as a good trade off.

Quoted 5 lines

If we have to invoke io/db multiple times, what do we do if the state changes between invocations (e.g. someone else mounts the block dev or unmounts the fs)? What happens if this all results in multiple xfs_repair invocations?

One idea would be to check the FS state before each io/db call, if the state changes, drop a warning to the user and stop operation. Couldn't the xfs_repair be postponed to the end if needed?

Quoted 9 lines

Can we prohibit people from running multiple subcommands? Even if that's a breaking change for someone who might be relying on the exact behaviors of this shell script?

What if, instead of trying to find answers to all these annoying questions, we instead decide that either all the subcommands have to target a mountpoint or they all have to target a blockdev, or xfs_admin will exit with an error code?

TBH this is my favorite idea so far.

Quoted 48 lines

--D

Quoted 45 lines
db/xfs_admin.sh +16 -4
 REPAIR_OPTS=""
 REPAIR_DEV_OPTS=""
 LOG_OPTS=""
@@ -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,26 @@ set -- extra $@
 shift $OPTIND
 case $# in
 	1|2)
+		# Use xfs_io if mounted and xfs_db if not mounted
+		if [ -n "$(findmnt -t xfs -T $1)" ]; then
+			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" ]
--

2.25.1

Signature · 1 line
Carlos Maiolino
#8 lore raw

Re: [PATCH v1 2/2] xfs_admin: get UUID of mounted filesystem

Quoted 39 lines · Carlos Maiolino
Quoted 16 lines · Darrick J. Wong
Quoted 15 lines · Catherine Hoang

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.

---
 db/xfs_admin.sh | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..0dcb9940 100755
@@ -6,6 +6,8 @@
 
Quoted 5 lines

db/xfs_admin.sh line 10

Quoted 4 lines
db/xfs_admin.sh +2 -0
 status=0
 DB_OPTS=""
+DB_EXTRA_OPTS=""
+IO_OPTS=""

I'll try to come back later to this thread with better answers, but I didn't want to leave it with no answer at all, so, from a first glance:

Quoted 12 lines

This seemed oddly familiar until I remembered that we've been here before:
https://lore.kernel.org/linux-xfs/[email protected]/

And now that I've reread that thread, I've now realized /why/ I gave up on adding things to this script -- there were too many questions from the maintainer for which I couldn't come up with any satisfying answer. Then I burned out and gave up.

Ofc now we have a new maintainer, so I'll put the questions to the new one. To summarize:

Quoted 7 lines
Quoted 4 lines

What happens if there are multiple sources of truth because the fs is mounted? Do we stop after processing the online options and ignore the offline ones? Do we keep going, even though -f is almost certainly required?

/me has no idea, but to be honest, I'd say, those shouldn't be mixed, either target online, or offline. Both, seems a recipe for disaster IMHO.

Agreed. :)

Quoted 8 lines
Quoted 3 lines

If the user specifies multiple options, is it ok to change the order in which we run them so that we can run xfs_io and then xfs_db?

Good question. I don't think I have a decent answer for that by now. I'm inclined to say it really depends on the semantics of the output, if ordering it doesn't change the expected output I don't see why reordering would be a problem.

Welll... in theory, if some user has hooked up xfs_admin to a program that expects output lines in an exact order, reordering the commands would be a breaking change.

Also, if ordering matters to the underlying xfs_db/xfs_io process, then reordering causes problems if, say, the parameters actually change things on the filesystem, and the order of those changes matters.

(I don't think any of the fs change options actually do matter, at least not the ones that apply to v5 filesystems.)

Quoted 2 lines

On the other hand, I think there is a myriad of possible combinations that would require evaluation to check when we are able to reorder or not.

Yep.

Quoted 1 line

It it worth the effort?

I don't think it is.

Quoted 4 lines
Quoted 4 lines

If it's not ok to change the order, how do we make the two tools run in lockstep so we only have to open the filesystem once?

Quoted 8 lines
Quoted 3 lines

If it's not ok to change the order and we cannot do lockstep, is it ok to invoke io/db once for each subcommand instead of assembling a giant cli option array like we now for db?

I might be being naive here, but it doesn't sound bad. Performance is no big deal here I believe, so, some extra time invoking io/db once for each subcommand, instead of creating a spaghetti of possible options that may/may not work together, sounds as a good trade off.

Yeah. I'm sure we could come up with some pathological sequence where multiple invocations would actually break very badly -- if, say, we were to allow xfs_db to "add" reflink and/or rmap to a filesystem, we'd want to set the NEEDSREPAIR bit to force the user to run xfs_repair to generate the missing btrees.

But what if you did something like:

xfs_admin -O rmap <some other option> -O reflink

which would translate to:

xfs_db -c 'add rmap' $dev
<dev is now marked NEEDSREPAIR>
<other option>
xfs_db -c 'add reflink' $dev
<fails because NEEDSREPAIR set at xfs_db init time>

whereas this:

xfs_admin -O rmap -O reflink

would translate to:

xfs_db -c 'add rmap' -c 'add reflink' $dev
<single command, succeeds>

Or maybe we just don't care if any of that is broken because this is all theoretical. :P

Quoted 14 lines
Quoted 4 lines

If we have to invoke io/db multiple times, what do we do if the state changes between invocations (e.g. someone else mounts the block dev or unmounts the fs)? What happens if this all results in multiple xfs_repair invocations?

One idea would be to check the FS state before each io/db call, if the state changes, drop a warning to the user and stop operation. Couldn't the xfs_repair be postponed to the end if needed?

Quoted 5 lines

Can we prohibit people from running multiple subcommands? Even if that's a breaking change for someone who might be relying on the exact behaviors of this shell script?

Quoted 6 lines
Quoted 4 lines

What if, instead of trying to find answers to all these annoying questions, we instead decide that either all the subcommands have to target a mountpoint or they all have to target a blockdev, or xfs_admin will exit with an error code?

TBH this is my favorite idea so far.

Ok, let's run with this then. :D

--D

Quoted 51 lines
Quoted 48 lines

--D

Quoted 45 lines
db/xfs_admin.sh +16 -4
 REPAIR_OPTS=""
 REPAIR_DEV_OPTS=""
 LOG_OPTS=""
@@ -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,26 @@ set -- extra $@
 shift $OPTIND
 case $# in
 	1|2)
+		# Use xfs_io if mounted and xfs_db if not mounted
+		if [ -n "$(findmnt -t xfs -T $1)" ]; then
+			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" ]
--

2.25.1

Signature · 1 line
Carlos Maiolino