Skip to contentSkip to conversation

get UUID of mounted filesystems

PATCH Superseded Catherine Hoang 2 participants 7 messages Dec 19, 2022 – Dec 21, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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.

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
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 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 +
 man/man8/xfs_io.8 |  3 +++
 5 files changed, 57 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);
man/man8/xfs_io.8 +3 -0
index 223b5152..ef7087b3 100644
@@ -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
Signature · 1 line
2.25.1
Reviewed-by on v2 1/2
#2 lore raw

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

Quoted 62 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 +
 man/man8/xfs_io.8 |  3 +++
 5 files changed, 57 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.

With that fixed,

--D

Quoted 58 lines
io/fsuuid.c new file +17 -0
+	}
+
+	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);
man/man8/xfs_io.8 +3 -0
index 223b5152..ef7087b3 100644
@@ -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
Signature · 1 line
2.25.1
#3 lore raw

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

Quoted 69 lines · Darrick J. Wong
Quoted 66 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 +
man/man8/xfs_io.8 |  3 +++
5 files changed, 57 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 \
io/Makefile +2 -2
-	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 +26 -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);
+
Quoted 8 lines

io/fsuuid.c line 32

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

Quoted 3 lines

With that fixed,

Thanks for reviewing!

Quoted 61 lines

--D

Quoted 58 lines
io/fsuuid.c new file +17 -0
+	}
+
+	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);
man/man8/xfs_io.8 +0 -0
index 223b5152..ef7087b3 100644
@@ -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

Signature · 1 line
2.25.1
#4 lore raw

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

Quoted 78 lines · Catherine Hoang
Quoted 69 lines · Darrick J. Wong
Quoted 66 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 +
man/man8/xfs_io.8 |  3 +++
5 files changed, 57 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 \
io/Makefile +2 -2
-	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 +26 -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);
+
Quoted 8 lines

io/fsuuid.c line 32

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

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

Quoted 66 lines
Quoted 2 lines

With that fixed,

Thanks for reviewing!

Quoted 61 lines

--D

Quoted 58 lines
io/fsuuid.c new file +17 -0
+	}
+
+	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);
man/man8/xfs_io.8 +0 -0
index 223b5152..ef7087b3 100644
@@ -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

Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 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      | 27 +++++++++++++++++++++++----
 man/man8/xfs_admin.8 |  4 ++++
 2 files changed, 27 insertions(+), 4 deletions(-)
db/xfs_admin.sh +23 -4
index 409975b2..cc9a2150 100755
@@ -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" ]
man/man8/xfs_admin.8 +4 -0
index 4794d677..2c7ddc15 100644
@@ -19,7 +19,11 @@ xfs_admin \- change parameters of an XFS filesystem
 .B \-r
 .I rtdev
 ]
+[
+.I mount-point
+|
 .I device
+]
 [
 .I logdev
 ]
Signature · 1 line
2.25.1
#6 lore raw

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

Quoted 16 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      | 27 +++++++++++++++++++++++----
 man/man8/xfs_admin.8 |  4 ++++
 2 files changed, 27 insertions(+), 4 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..cc9a2150 100755

db/xfs_admin.sh line 14

Quoted 10 lines
db/xfs_admin.sh +3 -1
@@ -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.

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

db/xfs_admin.sh set -- extra $@ · line 45

Quoted 5 lines
db/xfs_admin.sh +2 -0
@@ -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.

db/xfs_admin.sh set -- extra $@ · line 52

Quoted 7 lines
db/xfs_admin.sh +7 -0
+			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

Quoted 39 lines
db/xfs_admin.sh +9 -2
+		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" ]
man/man8/xfs_admin.8 +4 -0
index 4794d677..2c7ddc15 100644
@@ -19,7 +19,11 @@ xfs_admin \- change parameters of an XFS filesystem
 .B \-r
 .I rtdev
 ]
+[
+.I mount-point
+|
 .I device
+]
 [
 .I logdev
 ]
Signature · 1 line
2.25.1