Skip to contentSkip to conversation

get UUID of mounted filesystems

PATCH In review Catherine Hoang 3 participants 6 messages Jan 5, 2023 – Jan 13, 2023

lore
Share & tools
lore
#0 lore raw

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

v2->v3
- Keep track of which commands require a mounted/unmounted fs
- Return error if both online and offline options are specified

Comments and feedback appreciated!

Catherine

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

 db/xfs_admin.sh   | 61 +++++++++++++++++++++++++++++++++++++++--------
 io/Makefile       |  6 ++---
 io/fsuuid.c       | 49 +++++++++++++++++++++++++++++++++++++
 io/init.c         |  1 +
 io/io.h           |  1 +
 man/man8/xfs_io.8 |  3 +++
 6 files changed, 108 insertions(+), 13 deletions(-)
 create mode 100644 io/fsuuid.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 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
#2 lore raw

PATCH v3 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 | 61 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 51 insertions(+), 10 deletions(-)
db/xfs_admin.sh +51 -10
index 409975b2..b73fb3ad 100755
@@ -5,8 +5,11 @@
 #
 
 status=0
+require_offline=""
+require_online=""
 DB_OPTS=""
 REPAIR_OPTS=""
+IO_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]"
@@ -14,17 +17,37 @@ USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev
 while getopts "c:efjlL:O:pr:uU:V" c
 do
 	case $c in
-	c)	REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG;;
-	e)	DB_OPTS=$DB_OPTS" -c 'version extflg'";;
-	f)	DB_OPTS=$DB_OPTS" -f";;
-	j)	DB_OPTS=$DB_OPTS" -c 'version log2'";;
+	c)	REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG
+		require_offline=1
+		;;
+	e)	DB_OPTS=$DB_OPTS" -c 'version extflg'"
+		require_offline=1
+		;;
+	f)	DB_OPTS=$DB_OPTS" -f"
+		require_offline=1
+		;;
+	j)	DB_OPTS=$DB_OPTS" -c 'version log2'"
+		require_offline=1
+		;;
 	l)	DB_OPTS=$DB_OPTS" -r -c label";;
-	L)	DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";;
-	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_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";;
+	L)	DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'"
+		require_offline=1
+		;;
+	O)	REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG"
+		require_offline=1
+		;;
+	p)	DB_OPTS=$DB_OPTS" -c 'version projid32bit'"
+		require_offline=1
+		;;
+	r)	REPAIR_DEV_OPTS=" -r '$OPTARG'"
+		require_offline=1
+		;;
+	u)	DB_OPTS=$DB_OPTS" -r -c uuid"
+		IO_OPTS=$IO_OPTS" -r -c fsuuid"
+		;;
+	U)	DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'"
+		require_offline=1
+		;;
 	V)	xfs_db -p xfs_admin -V
 		status=$?
 		exit $status
@@ -38,6 +61,24 @@ set -- extra $@
 shift $OPTIND
 case $# in
 	1|2)
+		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
+
+			if [ -n "$IO_OPTS" ]; then
+				exec xfs_io -p xfs_admin $IO_OPTS "$mntpt"
+			fi
+		fi
+
+		# filesystem is not mounted
+		if [ -n "$require_online" ]; then
+			echo "$1: filesystem is not mounted"
+			exit 2
+		fi
+
 		# Pick up the log device, if present
 		if [ -n "$2" ]; then
 			LOG_OPTS=" -l '$2'"
Signature · 1 line
2.25.1
Reviewed-by on v3 2/2
#3 lore raw

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

Quoted 36 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 | 61 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 51 insertions(+), 10 deletions(-)
db/xfs_admin.sh +6 -4
index 409975b2..b73fb3ad 100755
@@ -5,8 +5,11 @@
 #
 
 status=0
+require_offline=""
+require_online=""
 DB_OPTS=""
 REPAIR_OPTS=""
+IO_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]"
@@ -14,17 +17,37 @@ USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev
 while getopts "c:efjlL:O:pr:uU:V" c
 do
 	case $c in
-	c)	REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG;;
-	e)	DB_OPTS=$DB_OPTS" -c 'version extflg'";;
-	f)	DB_OPTS=$DB_OPTS" -f";;
-	j)	DB_OPTS=$DB_OPTS" -c 'version log2'";;
+	c)	REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG
+		require_offline=1
+		;;

db/xfs_admin.sh USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev · line 32

Quoted 10 lines
db/xfs_admin.sh +9 -0
+	e)	DB_OPTS=$DB_OPTS" -c 'version extflg'"
+		require_offline=1
+		;;
+	f)	DB_OPTS=$DB_OPTS" -f"
+		require_offline=1
+		;;
+	j)	DB_OPTS=$DB_OPTS" -c 'version log2'"
+		require_offline=1
+		;;
 	l)	DB_OPTS=$DB_OPTS" -r -c label";;

Now that xfs_admin can issue commands directly against mounted filesystems, I suppose it ought to wire up support for querying and changing the label as well. Doing that should be trivial, and definitely an idea for a separate patch:

# xfs_io -c 'label' /mnt
label = "hi"
# xfs_io -c 'label -s bye' /mnt
label = "bye"
# xfs_io -c 'label' /mnt
label = "bye"

*This* patch looks correct to me, so

--D

Quoted 55 lines
db/xfs_admin.sh +36 -6
-	L)	DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";;
-	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_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";;
+	L)	DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'"
+		require_offline=1
+		;;
+	O)	REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG"
+		require_offline=1
+		;;
+	p)	DB_OPTS=$DB_OPTS" -c 'version projid32bit'"
+		require_offline=1
+		;;
+	r)	REPAIR_DEV_OPTS=" -r '$OPTARG'"
+		require_offline=1
+		;;
+	u)	DB_OPTS=$DB_OPTS" -r -c uuid"
+		IO_OPTS=$IO_OPTS" -r -c fsuuid"
+		;;
+	U)	DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'"
+		require_offline=1
+		;;
 	V)	xfs_db -p xfs_admin -V
 		status=$?
 		exit $status
@@ -38,6 +61,24 @@ set -- extra $@
 shift $OPTIND
 case $# in
 	1|2)
+		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
+
+			if [ -n "$IO_OPTS" ]; then
+				exec xfs_io -p xfs_admin $IO_OPTS "$mntpt"
+			fi
+		fi
+
+		# filesystem is not mounted
+		if [ -n "$require_online" ]; then
+			echo "$1: filesystem is not mounted"
+			exit 2
+		fi
+
 		# Pick up the log device, if present
 		if [ -n "$2" ]; then
 			LOG_OPTS=" -l '$2'"
Signature · 1 line
2.25.1
#4 lore raw

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

Quoted 55 lines · Darrick J. Wong
Quoted 45 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 | 61 +++++++++++++++++++++++++++++++++++++++++--------

1 file changed, 51 insertions(+), 10 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..b73fb3ad 100755
@@ -5,8 +5,11 @@
 #
 

status=0

db/xfs_admin.sh +2 -0
+require_offline=""
+require_online=""

DB_OPTS=""
REPAIR_OPTS=""
+IO_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]"

db/xfs_admin.sh +0 -0
@@ -14,17 +17,37 @@ USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev

while getopts "c:efjlL:O:pr:uU:V" c
do
case $c in

db/xfs_admin.sh +12 -4
-	c)	REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG;;
-	e)	DB_OPTS=$DB_OPTS" -c 'version extflg'";;
-	f)	DB_OPTS=$DB_OPTS" -f";;
-	j)	DB_OPTS=$DB_OPTS" -c 'version log2'";;
+	c)	REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG
+		require_offline=1
+		;;
+	e)	DB_OPTS=$DB_OPTS" -c 'version extflg'"
+		require_offline=1
+		;;
+	f)	DB_OPTS=$DB_OPTS" -f"
+		require_offline=1
+		;;
+	j)	DB_OPTS=$DB_OPTS" -c 'version log2'"
+		require_offline=1
+		;;
Quoted 1 line
	l)	DB_OPTS=$DB_OPTS" -r -c label";;

Now that xfs_admin can issue commands directly against mounted filesystems, I suppose it ought to wire up support for querying and changing the label as well. Doing that should be trivial, and definitely an idea for a separate patch:

Quoted 6 lines
# xfs_io -c 'label' /mnt
label = "hi"
# xfs_io -c 'label -s bye' /mnt
label = "bye"
# xfs_io -c 'label' /mnt
label = "bye"

Sure, I can do that in a separate patch. Thank you!

Quoted 61 lines

*This* patch looks correct to me, so

--D

Quoted 55 lines
db/xfs_admin.sh +18 -6
-	L)	DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";;
-	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_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";;
+	L)	DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'"
+		require_offline=1
+		;;
+	O)	REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG"
+		require_offline=1
+		;;
+	p)	DB_OPTS=$DB_OPTS" -c 'version projid32bit'"
+		require_offline=1
+		;;
+	r)	REPAIR_DEV_OPTS=" -r '$OPTARG'"
+		require_offline=1
+		;;
+	u)	DB_OPTS=$DB_OPTS" -r -c uuid"
+		IO_OPTS=$IO_OPTS" -r -c fsuuid"
+		;;
+	U)	DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'"
+		require_offline=1
+		;;
	V)	xfs_db -p xfs_admin -V
		status=$?
		exit $status
db/xfs_admin.sh +0 -0
@@ -38,6 +61,24 @@ set -- extra $@

shift $OPTIND
case $# in

	1|2)
db/xfs_admin.sh +18 -0
+		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
+
+			if [ -n "$IO_OPTS" ]; then
+				exec xfs_io -p xfs_admin $IO_OPTS "$mntpt"
+			fi
+		fi
+
+		# filesystem is not mounted
+		if [ -n "$require_online" ]; then
+			echo "$1: filesystem is not mounted"
+			exit 2
+		fi
+
		# Pick up the log device, if present
		if [ -n "$2" ]; then
			LOG_OPTS=" -l '$2'"
Signature · 1 line
2.25.1
Reviewed-by on v3 2/2
#5 lore raw

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

In reply to Catherine Hoang
Quoted 7 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.

Sorry for the delay here, this patch looks good to me, you can add my review:

Quoted 98 lines

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

 1 file changed, 51 insertions(+), 10 deletions(-)
db/xfs_admin.sh +0 -0
index 409975b2..b73fb3ad 100755
@@ -5,8 +5,11 @@
  #


 status=0

db/xfs_admin.sh +2 -0
+require_offline=""
+require_online=""

 DB_OPTS=""
 REPAIR_OPTS=""
+IO_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]"

db/xfs_admin.sh +0 -0
@@ -14,17 +17,37 @@ USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L

label] [-O v5_feature] [-r rtdev
 while getopts "c:efjlL:O:pr:uU:V" c
 do
        case $c in
-       c)      REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG;; -       e)      DB_OPTS=$DB_OPTS" -c 'version extflg'";; -       f)      DB_OPTS=$DB_OPTS" -f";;
-       j)      DB_OPTS=$DB_OPTS" -c 'version log2'";; +       c)      REPAIR_OPTS=$REPAIR_OPTS" -c lazycount="$OPTARG +               require_offline=1
+               ;;
+       e)      DB_OPTS=$DB_OPTS" -c 'version extflg'" +               require_offline=1
+               ;;
+       f)      DB_OPTS=$DB_OPTS" -f"
+               require_offline=1
+               ;;
+       j)      DB_OPTS=$DB_OPTS" -c 'version log2'"
+               require_offline=1
+               ;;
        l)      DB_OPTS=$DB_OPTS" -r -c label";;
-       L)      DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";; -       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_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";; +       L)      DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'" +               require_offline=1
+               ;;
+       O)      REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG"
+               require_offline=1
+               ;;
+       p)      DB_OPTS=$DB_OPTS" -c 'version projid32bit'" +               require_offline=1
+               ;;
+       r)      REPAIR_DEV_OPTS=" -r '$OPTARG'"
+               require_offline=1
+               ;;
+       u)      DB_OPTS=$DB_OPTS" -r -c uuid"
+               IO_OPTS=$IO_OPTS" -r -c fsuuid"
+               ;;
+       U)      DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'" +               require_offline=1
+               ;;
        V)      xfs_db -p xfs_admin -V
                status=$?
                exit $status

db/xfs_admin.sh +0 -0
@@ -38,6 +61,24 @@ set -- extra $@

 shift $OPTIND
 case $# in
        1|2)
+               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
+
+                       if [ -n "$IO_OPTS" ]; then
+                               exec xfs_io -p xfs_admin $IO_OPTS "$mntpt"
+                       fi
+               fi

db/xfs_admin.sh +7 -0
+
+               # filesystem is not mounted
+               if [ -n "$require_online" ]; then
+                       echo "$1: filesystem is not mounted"
+                       exit 2
+               fi
+

                # Pick up the log device, if present if [ -n "$2" ]; then LOG_OPTS=" -l '$2'"