Whamcloud - gitweb
LU-17516 utils: new --mdt and --ost options for lfs df 56/55156/7
authorFrederick Dilger <fdilger@whamcloud.com>
Fri, 17 May 2024 20:19:17 +0000 (14:19 -0600)
committerOleg Drokin <green@whamcloud.com>
Mon, 10 Jun 2024 06:13:58 +0000 (06:13 +0000)
Added [--mdt | -m] and [--ost | -o] options for 'lfs df' to print
only usage of the respective MDT or OST devices in mntdf(). If both
"--mdt" and "--ost" are specified it will show both types of devices
which is identical to having neither specified.

Signed-off-by: Frederick Diger <fdilger@whamcloud.com>
Change-Id: I196b7c9c0c385850372331587936fa5cf6b71d93
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55156
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/doc/lfs-df.1
lustre/tests/sanity.sh
lustre/utils/lfs.c [changed mode: 0644->0755]

index 8306769..bbd3b50 100644 (file)
@@ -6,6 +6,8 @@ lfs-df \- report Lustre filesystem disk usage
 .RB [ --lazy | -l ]
 .RB [ --pool | -p
 .IR <fsname> [. <pool> ]]
+.RB [ --mdt | -m ]
+.RB [ --ost | -o ]
 .RB [ --verbose | -v ]
 .RI [ path ]
 .SH DESCRIPTION
@@ -134,6 +136,20 @@ the client.  This avoids blocking the
 output if a target is offline or unreachable, and only returns the
 space on OSTs that can currently be accessed.
 .TP
+.BR -m ", " --mdt
+Filter output to show information on
+.B MDT
+devices. Can be used with
+.BR -o
+to show both types of devices, which is equivalent to having neither option.
+.TP
+.BR -o ", " --ost
+Filter output to show information on
+.B OST
+devices. Can be used with
+.BR -m
+to show both types of devices, which is equivalent to having neither option.
+.TP
 .BR -p ", " --pool= [ \fIfsname\fR .] \fIpool\fR
 Limit the usage to report only MDTs and OSTs that are in the specified
 .IR pool .
index db72a9e..76f2d0a 100755 (executable)
@@ -8941,6 +8941,32 @@ test_56da() { # LU-14179
 }
 run_test 56da "test lfs find with long paths"
 
+test_56db() {
+       local mdts=$($LFS df -m | grep -c MDT)
+       local osts=$($LFS df -m | grep -c OST)
+
+       $LFS df
+
+       (( mdts == MDSCOUNT )) ||
+               error "lfs df -m showed $mdts MDTs, not $MDSCOUNT"
+       (( osts == 0 )) ||
+               error "lfs df -m showed $osts OSTs, not 0"
+}
+run_test 56db "test 'lfs df -m' only shows MDT devices"
+
+test_56dc() {
+       local mdts=$($LFS df -o | grep -c MDT)
+       local osts=$($LFS df -o | grep -c OST)
+
+       $LFS df
+
+       (( osts == OSTCOUNT )) ||
+               error "lfs df -o showed $osts OSTs, not $OSTCOUNT"
+       (( mdts == 0 )) ||
+               error "lfs df -o showed $mdts MDTs, not 0"
+}
+run_test 56dc "test 'lfs df -o' only shows OST devices"
+
 test_56ea() { #LU-10378
        local path=$DIR/$tdir
        local pool=$TESTNAME
old mode 100644 (file)
new mode 100755 (executable)
index 2b8898c..e2bf6ca
@@ -420,7 +420,8 @@ command_t cmdlist[] = {
         "report filesystem disk space usage or inodes usage "
         "of each MDS and all OSDs or a batch belonging to a specific pool.\n"
         "Usage: df [--inodes|-i] [--human-readable|-h] [--lazy|-l]\n"
-        "          [--pool|-p <fsname>[.<pool>]] [path]"},
+        "[--mdt|-m] [--ost|-o]\n"
+        "[--pool|-p <fsname>[.<pool>]] [path]"},
        {"getname", lfs_getname, 0,
         "list instances and specified mount points [for specified path only]\n"
         "Usage: getname [--help|-h] [--instance|-i] [--fsname|-n] [path ...]"},
@@ -7791,7 +7792,7 @@ static int lfs_df(int argc, char **argv)
 {
        char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'};
        enum mntdf_flags flags = MNTDF_SHOW;
-       int ops = LL_STATFS_LMV | LL_STATFS_LOV;
+       int ops = 0;
        int c, rc = 0, rc1 = 0, index = 0, arg_idx = 0;
        char fsname[PATH_MAX] = "", *pool_name = NULL;
        struct option long_opts[] = {
@@ -7801,9 +7802,12 @@ static int lfs_df(int argc, char **argv)
        { .val = 'l',   .name = "lazy",         .has_arg = no_argument },
        { .val = 'p',   .name = "pool",         .has_arg = required_argument },
        { .val = 'v',   .name = "verbose",      .has_arg = no_argument },
+       { .val = 'm',   .name = "mdt",          .has_arg = no_argument },
+       { .val = 'o',   .name = "ost",          .has_arg = no_argument },
        { .name = NULL} };
 
-       while ((c = getopt_long(argc, argv, "hHilp:v", long_opts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "hHilmop:v",
+                               long_opts, NULL)) != -1) {
                switch (c) {
                case 'h':
                        flags = (flags & ~MNTDF_DECIMAL) | MNTDF_COOKED;
@@ -7817,6 +7821,12 @@ static int lfs_df(int argc, char **argv)
                case 'l':
                        flags |= MNTDF_LAZY;
                        break;
+               case 'm':
+                       ops |= LL_STATFS_LMV;
+                       break;
+               case 'o':
+                       ops |= LL_STATFS_LOV;
+                       break;
                case 'p':
                        pool_name = optarg;
                        break;
@@ -7830,6 +7840,10 @@ static int lfs_df(int argc, char **argv)
                }
        }
 
+       /* Handle case where neither MDT nor OST flag is specified */
+       if (!ops)
+               ops |= LL_STATFS_LMV | LL_STATFS_LOV;
+
        /* Handle case where path is not specified */
        if (optind == argc) {
                while (!llapi_search_mounts(path, index++, mntdir, fsname)) {