This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: STABLE3 - Add optional human-readable output to gfs_tool df
- From: Bob Peterson <rpeterso at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Thu, 15 Jan 2009 23:39:47 +0000 (UTC)
- Subject: cluster: STABLE3 - Add optional human-readable output to gfs_tool df
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=7b5692646333ed520c369d933eb35be045dda528
Commit: 7b5692646333ed520c369d933eb35be045dda528
Parent: 64ee0047e38f40e16b3a8277bc7aec5c5d986e36
Author: Bob Peterson <rpeterso@redhat.com>
AuthorDate: Thu Jan 15 12:22:10 2009 -0600
Committer: Bob Peterson <rpeterso@redhat.com>
CommitterDate: Thu Jan 15 17:39:56 2009 -0600
Add optional human-readable output to gfs_tool df
bz 459131
I added two new options: -k will produce output in K, like df.
Option -H will produce output in human-readable format, like df -h
---
gfs/gfs_tool/df.c | 87 ++++++++++++++++++++++++++++++++++++----------
gfs/gfs_tool/gfs_tool.h | 6 +++-
gfs/gfs_tool/main.c | 12 ++++++-
gfs/man/gfs_tool.8 | 22 ++++++++----
4 files changed, 99 insertions(+), 28 deletions(-)
diff --git a/gfs/gfs_tool/df.c b/gfs/gfs_tool/df.c
index 26aa65a..9a1ffbb 100644
--- a/gfs/gfs_tool/df.c
+++ b/gfs/gfs_tool/df.c
@@ -20,6 +20,54 @@
#define SIZE (4096)
/**
+ * anthropomorphize - make a uint64_t number more human
+ */
+static const char *anthropomorphize(uint64_t inhuman_value)
+{
+ const char *symbols = " KMGTPE";
+ int i;
+ uint64_t val = inhuman_value;
+ static char out_val[32];
+
+ memset(out_val, 0, sizeof(out_val));
+ for (i = 0; i < 6 && val > 1024; i++)
+ val /= 1024;
+ sprintf(out_val, "%"PRIu64"%c", val, symbols[i]);
+ return out_val;
+}
+
+/**
+ * printit - parse out and print values according to the output type
+ */
+static void printit(char *stat_gfs, const char *label, uint64_t used,
+ uint64_t free, unsigned int percentage)
+{
+ uint64_t block_size = name2u64(stat_gfs, "bsize");
+
+ switch (output_type) {
+ case OUTPUT_BLOCKS:
+ printf(" %-15s%-15"PRIu64"%-15"PRIu64"%-15"PRIu64"%u%%\n",
+ label, used + free, used, free, percentage);
+ break;
+ case OUTPUT_K:
+ printf(" %-15s%-15"PRIu64"%-15"PRIu64"%-15"PRIu64"%u%%\n",
+ label, ((used + free) * block_size) / 1024,
+ (used * block_size) / 1024, (free * block_size) / 1024,
+ percentage);
+ break;
+ case OUTPUT_HUMAN:
+ /* Need to do three separate printfs here because function
+ anthropomorphize re-uses the same static space. */
+ printf(" %-15s%-15s", label,
+ anthropomorphize((used + free) * block_size));
+ printf("%-15s", anthropomorphize(used * block_size));
+ printf("%-15s%u%%\n", anthropomorphize(free * block_size),
+ percentage);
+ break;
+ }
+}
+
+/**
* do_df_one - print out information about one filesystem
* @path: the path to the filesystem
*
@@ -172,37 +220,38 @@ do_df_one(char *path)
printf(" Local caching = %s\n", (name2u32(args, "localcaching")) ? "TRUE" : "FALSE");
printf(" Oopses OK = %s\n", (name2u32(args, "oopses_ok")) ? "TRUE" : "FALSE");
printf("\n");
- printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total", "Used", "Free", "use%");
+ switch (output_type) {
+ case OUTPUT_BLOCKS:
+ printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total Blocks",
+ "Used Blocks", "Free Blocks", "use%");
+ break;
+ case OUTPUT_K:
+ printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total K",
+ "Used K", "Free K", "use%");
+ break;
+ case OUTPUT_HUMAN:
+ printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total",
+ "Used", "Free", "use%");
+ break;
+ }
printf(" ------------------------------------------------------------------------\n");
percentage = (name2u64(stat_gfs, "used_dinode") + name2u64(stat_gfs, "free_dinode")) ?
(100.0 * name2u64(stat_gfs, "used_dinode") / (name2u64(stat_gfs, "used_dinode") +
name2u64(stat_gfs, "free_dinode")) + 0.5) : 0;
- printf(" %-15s%-15"PRIu64"%-15"PRIu64"%-15"PRIu64"%u%%\n",
- "inodes",
- name2u64(stat_gfs, "used_dinode") + name2u64(stat_gfs, "free_dinode"),
- name2u64(stat_gfs, "used_dinode"),
- name2u64(stat_gfs, "free_dinode"),
- percentage);
+ printit(stat_gfs, "inodes", name2u64(stat_gfs, "used_dinode"),
+ name2u64(stat_gfs, "free_dinode"), percentage);
percentage = (name2u64(stat_gfs, "used_meta") + name2u64(stat_gfs, "free_meta")) ?
(100.0 * name2u64(stat_gfs, "used_meta") / (name2u64(stat_gfs, "used_meta") +
name2u64(stat_gfs, "free_meta")) + 0.5) : 0;
- printf(" %-15s%-15"PRIu64"%-15"PRIu64"%-15"PRIu64"%u%%\n",
- "metadata",
- name2u64(stat_gfs, "used_meta") + name2u64(stat_gfs, "free_meta"),
- name2u64(stat_gfs, "used_meta"),
- name2u64(stat_gfs, "free_meta"),
- percentage);
+ printit(stat_gfs, "metadata", name2u64(stat_gfs, "used_meta"),
+ name2u64(stat_gfs, "free_meta"), percentage);
percentage = (used_data + name2u64(stat_gfs, "free")) ?
(100.0 * used_data / (used_data + name2u64(stat_gfs, "free")) + 0.5) : 0;
- printf(" %-15s%-15"PRIu64"%-15"PRIu64"%-15"PRIu64"%u%%\n",
- "data",
- used_data + name2u64(stat_gfs, "free"),
- used_data,
- name2u64(stat_gfs, "free"),
- percentage);
+ printit(stat_gfs, "data", used_data, name2u64(stat_gfs, "free"),
+ percentage);
}
diff --git a/gfs/gfs_tool/gfs_tool.h b/gfs/gfs_tool/gfs_tool.h
index 1e45d43..025917e 100644
--- a/gfs/gfs_tool/gfs_tool.h
+++ b/gfs/gfs_tool/gfs_tool.h
@@ -18,6 +18,10 @@ do { \
} while (0)
+#define OUTPUT_BLOCKS 0
+#define OUTPUT_K 1
+#define OUTPUT_HUMAN 2
+
extern char *prog_name;
extern char *action;
extern int override;
@@ -25,7 +29,7 @@ extern int expert;
extern int debug;
extern int continuous;
extern int interval;
-
+extern int output_type;
/* From counters.c */
diff --git a/gfs/gfs_tool/main.c b/gfs/gfs_tool/main.c
index 3de8580..03b88d5 100644
--- a/gfs/gfs_tool/main.c
+++ b/gfs/gfs_tool/main.c
@@ -22,6 +22,7 @@ int expert = FALSE;
int debug = FALSE;
int continuous = FALSE;
int interval = 1;
+int output_type = OUTPUT_BLOCKS;
static const char *usage[] = {
"Clear a flag on a inode\n",
@@ -141,8 +142,9 @@ decode_arguments(int argc, char *argv[])
int cont = TRUE;
int optchar;
+ output_type = OUTPUT_BLOCKS;
while (cont) {
- optchar = getopt(argc, argv, "cDhi:OVX");
+ optchar = getopt(argc, argv, "cDhHki:OVX");
switch (optchar) {
case 'c':
@@ -157,10 +159,18 @@ decode_arguments(int argc, char *argv[])
print_usage();
exit(EXIT_SUCCESS);
+ case 'H':
+ output_type = OUTPUT_HUMAN;
+ break;
+
case 'i':
sscanf(optarg, "%u", &interval);
break;
+ case 'k':
+ output_type = OUTPUT_K;
+ break;
+
case 'O':
override = TRUE;
break;
diff --git a/gfs/man/gfs_tool.8 b/gfs/man/gfs_tool.8
index fe78259..44ca7e3 100644
--- a/gfs/man/gfs_tool.8
+++ b/gfs/man/gfs_tool.8
@@ -5,23 +5,31 @@ gfs_tool - interface to gfs ioctl calls
.SH SYNOPSIS
.B gfs_tool
-\fICOMMAND\fR [\fIOPTION\fR]...
+\fICOMMAND\fR [\fIOPTION\fR] [\fIPARAMETERS ...\fR]
.SH DESCRIPTION
gfs_tool is an interface to a variety of the GFS ioctl calls.
-
+.TP
+Specifying gfs_tool -h prints gfs_tool command line usage (help).
+.TP
+Specifying gfs_tool -V prints the gfs_tool version information.
.SH COMMANDS
.TP
\fBclearflag\fP \fIFlag\fR \fIFile1\fR \fIFile2\fR \fI...\fR
Clear an attribute flag on a file.
.TP
-\fBcounters\fP \fIMountPoint\fR [-c]
-Print out statistics about a filesystem. If -c is used, gfs_tool continues
-to run printing out the stats once a second.
+\fBcounters\fP \fIMountPoint\fR [-c] [-i \fIinterval\fR]
+Print out statistics about a filesystem. If -c is specified, gfs_tool
+keeps running printing out the statistics once per second or, if
+specified, the interval given with the -i option, in seconds.
.TP
-\fBdf\fP \fIMountPoint\fR
+\fBdf\fP \fIMountPoint\fR [-k]|[-H]
Print out a space usage summary of a given filesystem. The information
-printed is more detailed than a standard "df".
+printed is more detailed than a standard "df". If -k is specified, the
+output is given in kilobytes (KB). If -H is specified, the output is
+given in human readable format (similar to df -h). If neither -k nor -H
+are specified, the output is given in file system blocks.
+
.TP
\fBfreeze\fP \fIMountPoint\fR
Freeze (quiesce) a GFS cluster.