From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10821 invoked by alias); 15 Jan 2009 23:37:16 -0000 Received: (qmail 10814 invoked by alias); 15 Jan 2009 23:37:16 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_64,J_CHICKENPOX_66,J_CHICKENPOX_74,KAM_MX,SPF_HELO_PASS X-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_64,J_CHICKENPOX_66,J_CHICKENPOX_74,KAM_MX,SPF_HELO_PASS X-Spam-Check-By: sourceware.org X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on bastion.fedora.phx.redhat.com Subject: cluster: STABLE2 - Add optional human-readable output to gfs_tool df To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: cluster.git X-Git-Refname: refs/heads/STABLE2 X-Git-Reftype: branch X-Git-Oldrev: 822896e4c07187867eae40d877e4b4ff2230c8ac X-Git-Newrev: d0bc69ba94169486d96595ab73c2cddaa018fd0b From: Bob Peterson Message-Id: <20090115233633.9B84A120529@lists.fedorahosted.org> Date: Thu, 15 Jan 2009 23:37:00 -0000 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2009-q1/txt/msg00131.txt.bz2 Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=d0bc69ba94169486d96595ab73c2cddaa018fd0b Commit: d0bc69ba94169486d96595ab73c2cddaa018fd0b Parent: 822896e4c07187867eae40d877e4b4ff2230c8ac Author: Bob Peterson AuthorDate: Thu Jan 15 12:22:10 2009 -0600 Committer: Bob Peterson CommitterDate: Thu Jan 15 17:35:13 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.