From 1631c5728b76fc514f64621e664d92fb75686978 Mon Sep 17 00:00:00 2001 From: Frederick Dilger Date: Fri, 17 May 2024 14:19:17 -0600 Subject: [PATCH] LU-17516 utils: new --mdt and --ost options for lfs df 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 Change-Id: I196b7c9c0c385850372331587936fa5cf6b71d93 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55156 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Timothy Day Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- lustre/doc/lfs-df.1 | 16 ++++++++++++++++ lustre/tests/sanity.sh | 26 ++++++++++++++++++++++++++ lustre/utils/lfs.c | 20 +++++++++++++++++--- 3 files changed, 59 insertions(+), 3 deletions(-) mode change 100644 => 100755 lustre/utils/lfs.c diff --git a/lustre/doc/lfs-df.1 b/lustre/doc/lfs-df.1 index 8306769..bbd3b50 100644 --- a/lustre/doc/lfs-df.1 +++ b/lustre/doc/lfs-df.1 @@ -6,6 +6,8 @@ lfs-df \- report Lustre filesystem disk usage .RB [ --lazy | -l ] .RB [ --pool | -p .IR [. ]] +.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 . diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index db72a9e..76f2d0a 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c old mode 100644 new mode 100755 index 2b8898c..e2bf6ca --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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 [.]] [path]"}, + "[--mdt|-m] [--ost|-o]\n" + "[--pool|-p [.]] [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)) { -- 1.8.3.1