]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs_admin: support label queries for mounted filesystems
authorDarrick J. Wong <djwong@kernel.org>
Thu, 10 Jun 2021 21:28:07 +0000 (14:28 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 2 Jul 2021 23:28:41 +0000 (16:28 -0700)
Adapt this tool to call xfs_io if the block device in question is
mounted.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
db/xfs_admin.sh

index 409975b22286b16cee059370113329ab92639890..21c9d71baff11eb2ca71d9d35e3cbc6d26679206 100755 (executable)
@@ -8,9 +8,34 @@ status=0
 DB_OPTS=""
 REPAIR_OPTS=""
 REPAIR_DEV_OPTS=""
+IO_OPTS=""
 LOG_OPTS=""
 USAGE="Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-O v5_feature] [-r rtdev] [-U uuid] device [logdev]"
 
+# Try to find a loop device associated with a file.  We only want to return
+# one loopdev (multiple loop devices can attach to a single file) so we grab
+# the last line and return it if it's actually a block device.
+try_find_loop_dev_for_file() {
+       local x="$(losetup -O NAME -j "$1" 2> /dev/null | tail -n 1)"
+       test -b "$x" && echo "$x"
+}
+
+try_find_mount_point_for_bdev() {
+       local arg="$1"
+
+       # See if we can map the arg to a loop device
+       loopdev="$(try_find_loop_dev_for_file "${arg}")"
+       test -n "${loopdev}" && arg="${loopdev}"
+
+       if [ ! -b "${arg}" ]; then
+               return 1
+       fi
+
+       # If we find a mountpoint for the device, do a live query;
+       # otherwise try reading the fs with xfs_db.
+       findmnt -t xfs -f -n -o TARGET "${arg}" 2> /dev/null
+}
+
 while getopts "c:efjlL:O:pr:uU:V" c
 do
        case $c in
@@ -18,8 +43,10 @@ do
        e)      DB_OPTS=$DB_OPTS" -c 'version extflg'";;
        f)      DB_OPTS=$DB_OPTS" -f";;
        j)      DB_OPTS=$DB_OPTS" -c 'version log2'";;
-       l)      DB_OPTS=$DB_OPTS" -r -c label";;
-       L)      DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";;
+       l)      DB_OPTS=$DB_OPTS" -r -c label";
+               IO_OPTS=$IO_OPTS" -r -c label";;
+       L)      DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";
+               IO_OPTS=$IO_OPTS" -c 'label -s "$OPTARG"'";;
        O)      REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG";;
        p)      DB_OPTS=$DB_OPTS" -c 'version projid32bit'";;
        r)      REPAIR_DEV_OPTS=" -r '$OPTARG'";;
@@ -43,6 +70,16 @@ case $# in
                        LOG_OPTS=" -l '$2'"
                fi
 
+               if [ -n "$IO_OPTS" ]; then
+                       mntpt="$(try_find_mount_point_for_bdev "$1")"
+                       if [ $? -eq 0 ]; then
+                               eval xfs_io -x -p xfs_admin $IO_OPTS "$mntpt"
+                               status=$?
+                               DB_OPTS=""
+                               REPAIR_OPTS=""
+                       fi
+               fi
+
                if [ -n "$DB_OPTS" ]
                then
                        eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_OPTS "$1"