From 7b720df1fbd4136cd1ab8f3fefefd3971b2f7031 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Tue, 19 Jan 2021 17:48:28 -0700 Subject: [PATCH] LU-5170 utils: add lfs df -H for decimal units Running "lfs df -ih" prints a base-two suffix for inode counts, which is somewhat unintuitive (e.g. 100000 becomes 97.2K inodes). While this is consistent with upstream "df", it also has a "-H" option to print the output with decimal suffixes. Add the -H/--si option to "lfs df" also. Document the 'f' (flash) and 'N' (noprecreate) flags for "lfs df". Signed-off-by: Andreas Dilger Change-Id: I06b8df4ae2940107720e57013bf187b3473ebbe5 Reviewed-on: https://review.whamcloud.com/41271 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Olaf Faaland-LLNL Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- lustre/doc/lfs-df.1 | 54 +++++++++++++++++++++++++++++++++++++---------------- lustre/utils/lfs.c | 29 ++++++++++++++++------------ 2 files changed, 55 insertions(+), 28 deletions(-) diff --git a/lustre/doc/lfs-df.1 b/lustre/doc/lfs-df.1 index 7c96492..e55f00f 100644 --- a/lustre/doc/lfs-df.1 +++ b/lustre/doc/lfs-df.1 @@ -2,9 +2,11 @@ .SH NAME lfs df \- report Lustre filesystem disk usage .SH SYNOPSIS -.BR "lfs df" " [" -i "] [" -h "] [" --lazy "] [" --pool | -p +.BR "lfs df" " [" -i "] [" -h | -H ] +.RB [ --lazy | -l ] +.RB [ --pool | -p .IR [. ]] -.RB [ -v ] +.RB [ --verbose | -v ] .RI [ path ] .SH DESCRIPTION .B lfs df @@ -51,11 +53,19 @@ RAID reconstruction. This state is marked on the server automatically for ZFS targets via .BR zed (8), or a (user-supplied) script that monitors the target device and sets -.B lctl set_param obdfilter.\fI\fB.degraded=1 +.B 'lctl set_param obdfilter.\fI\fB.degraded=1' on the OST. This target will be avoided for new allocations, but will still be used for existing files located there or if there are not enough non-degraded OSTs to make up a widely-striped file. .TP +.B N: no-precreate +The target is configured to deny object precreation by the +.B 'lctl set_param obdfilter.\fI\fB.no_precreate=1' +parameter or +.B '-o no_precreate' +mount option. This may be done to add an OST to the filesystem without +allowing objects to be allocated on it yet, or for other reasons. +.TP .B R: read-only The target filesystem is marked read-only due to filesystem corruption detected by ldiskfs or ZFS. No modifications are @@ -72,6 +82,12 @@ will not be used for new object allocations until it has more free space. .B I: out-of-inodes The target filesystem has less than the minimum required free inodes and will not be used for new object allocations until it has more free inodes. +.TP +.B f: flash +The target filesystem is using a flash (non-rotational) storage device. +This lower-case status is only shown in conjunction with the +.B -v +option, since it is not an error condition. .RE .SH OPTIONS The various options supported by @@ -80,7 +96,12 @@ are listed and explained below: .TP .BR -h ", " --human-readable Print output in a human readable format (e.g. 16.3T, 4.25P). -Suffixes are SI base-2 units (i.e. 1 GiB = 1024 MiB). +Suffixes are base-2 units (i.e. 1 GiB = 1024 MiB). +.TP +.BR -H ", " --si +Like +.BR -h , +but suffixes are SI base-10 units (i.e. 1 GB = 1000 MB). .TP .BR -i ", " --inodes Print information about the inode usage and totals for the MDTs and @@ -131,12 +152,13 @@ is equivalent to specifying the mountpoint for the given .BI "lfs df --pool=" "pool /mnt/fsname" .TP .BR -v ", " --verbose -Show deactivated MDTs and OSTs in the listing. By default, any +Show deactivated MDTs and OSTs in the listing, along with any +additional status flags for each MDT and OST. By default, any MDTs and OSTs that are deactivated by the administrator are not shown. However, targets that are only temporarily inaccessible are still shown. .SH EXAMPLES .TP -.B $ lfs df -h /mnt/testfs +.B $ lfs df -hv /mnt/testfs Lists space usage per OST and MDT for the .B testfs filesystem in human readable format. @@ -175,33 +197,33 @@ or they were never added to the filesystem. The and .B testfs-OST0002 targets are currently marked -.B degraded +.BR D egraded (perhaps they both share the same underlying storage controller), while .B testfs-OST0002 is also marked -.B read-only -after detecting non-recoverable corruption in the filesystem. +.BR R ead-only, +after detecting non-recoverable corruption in the backing filesystem. .TP -.B $ lfs df -i +.B $ lfs df -iH List inode usage per OST and MDT for all mounted Lustre filesystems. .RS 0.75i UUID Inodes IUsed IFree IUse% Mounted on .br -testfs-MDT0000_UUID 932160 884609 47551 95% /testfs[MDT:0] +testfs-MDT0000_UUID 932.2k 884.6k 47.6k 95% /testfs[MDT:0] .br -testfs-OST0000_UUID 267456 179649 87807 67% /testfs[OST:0] +testfs-OST0000_UUID 267.5k 179.6k 87.8k 67% /testfs[OST:0] .br -testfs-OST0001_UUID 268864 173466 95398 64% /testfs[OST:1] D +testfs-OST0001_UUID 268.9k 173.5k 95.4k 64% /testfs[OST:1] D .br -testfs-OST0002_UUID 267456 169575 97881 63% /testfs[OST:2] DR +testfs-OST0002_UUID 267.5k 169.6k 97.9k 63% /testfs[OST:2] DR .br OST0003 : inactive device .br -testfs-OST0006_UUID 426144 377448 48696 88% /testfs[OST:3] +testfs-OST0006_UUID 426.1k 377.4k 48.7k 88% /testfs[OST:3] .br -filesystem_summary: 932160 884609 47551 95% /testfs +filesystem_summary: 932.1k 884.6k 47.6k 95% /testfs .br .RE .TP diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 1df070a..3841e47 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -5860,13 +5860,14 @@ enum mntdf_flags { MNTDF_LAZY = 0x0004, MNTDF_VERBOSE = 0x0008, MNTDF_SHOW = 0x0010, + MNTDF_DECIMAL = 0x0020, }; -#define COOK(value) \ +#define COOK(value, base) \ ({ \ int radix = 0; \ - while (value > 1024) { \ - value /= 1024; \ + while (value > base) { \ + value /= base; \ radix++; \ } \ radix; \ @@ -5924,7 +5925,7 @@ static int showdf(char *mntdir, struct obd_statfs *stat, { long long avail, used, total; int ratio = 0; - char *suffix = "KMGTPEZY"; + char *suffix = flags & MNTDF_DECIMAL ? "kMGTPEZY" : "KMGTPEZY"; /* Note if we have >2^64 bytes/fs these buffers will need to be grown */ char tbuf[3 * sizeof(__u64)]; char ubuf[3 * sizeof(__u64)]; @@ -5952,11 +5953,12 @@ static int showdf(char *mntdir, struct obd_statfs *stat, ratio = obd_statfs_ratio(stat, flags & MNTDF_INODES); if (flags & MNTDF_COOKED) { - int i; + int base = flags & MNTDF_DECIMAL ? 1000 : 1024; double cook_val; + int i; cook_val = (double)total; - i = COOK(cook_val); + i = COOK(cook_val, base); if (i > 0) snprintf(tbuf, sizeof(tbuf), HDF, cook_val, suffix[i - 1]); @@ -5964,7 +5966,7 @@ static int showdf(char *mntdir, struct obd_statfs *stat, snprintf(tbuf, sizeof(tbuf), CDF, total); cook_val = (double)used; - i = COOK(cook_val); + i = COOK(cook_val, base); if (i > 0) snprintf(ubuf, sizeof(ubuf), HDF, cook_val, suffix[i - 1]); @@ -5972,7 +5974,7 @@ static int showdf(char *mntdir, struct obd_statfs *stat, snprintf(ubuf, sizeof(ubuf), CDF, used); cook_val = (double)avail; - i = COOK(cook_val); + i = COOK(cook_val, base); if (i > 0) snprintf(abuf, sizeof(abuf), HDF, cook_val, suffix[i - 1]); @@ -6648,18 +6650,21 @@ static int lfs_df(int argc, char **argv) int c, rc = 0, index = 0; char fsname[PATH_MAX] = "", *pool_name = NULL; struct option long_opts[] = { - { .val = 'h', .name = "human-readable", - .has_arg = no_argument }, + { .val = 'h', .name = "human-readable", .has_arg = no_argument }, + { .val = 'H', .name = "si", .has_arg = no_argument }, { .val = 'i', .name = "inodes", .has_arg = no_argument }, { .val = 'l', .name = "lazy", .has_arg = no_argument }, { .val = 'p', .name = "pool", .has_arg = required_argument }, { .val = 'v', .name = "verbose", .has_arg = no_argument }, { .name = NULL} }; - while ((c = getopt_long(argc, argv, "hilp:v", long_opts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "hHilp:v", long_opts, NULL)) != -1) { switch (c) { case 'h': - flags |= MNTDF_COOKED; + flags = (flags & ~MNTDF_DECIMAL) | MNTDF_COOKED; + break; + case 'H': + flags |= MNTDF_COOKED | MNTDF_DECIMAL; break; case 'i': flags |= MNTDF_INODES; -- 1.8.3.1