* [PATCH] xfs_df: a df(1)-like command to list per-ag block and inode usage
@ 2009-09-10 22:46 Josef 'Jeff' Sipek
2009-09-10 23:21 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Josef 'Jeff' Sipek @ 2009-09-10 22:46 UTC (permalink / raw)
To: xfs; +Cc: Josef 'Jeff' Sipek
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
---
db/Makefile | 3 +-
db/xfs_df.sh | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 146 insertions(+), 1 deletions(-)
create mode 100755 db/xfs_df.sh
diff --git a/db/Makefile b/db/Makefile
index 93ab040..96f220e 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -14,7 +14,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
io.h malloc.h metadump.h output.h print.h quit.h sb.h sig.h strvec.h \
text.h type.h write.h attrset.h
CFILES = $(HFILES:.h=.c)
-LSRCFILES = xfs_admin.sh xfs_check.sh xfs_ncheck.sh xfs_metadump.sh
+LSRCFILES = xfs_admin.sh xfs_check.sh xfs_ncheck.sh xfs_metadump.sh xfs_df.sh
LSRCFILES += xfs_check64.sh xfs_ncheck64.sh
LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
@@ -42,4 +42,5 @@ install: default
$(INSTALL) -m 755 xfs_check.sh $(PKG_BIN_DIR)/xfs_check
$(INSTALL) -m 755 xfs_ncheck.sh $(PKG_BIN_DIR)/xfs_ncheck
$(INSTALL) -m 755 xfs_metadump.sh $(PKG_BIN_DIR)/xfs_metadump
+ $(INSTALL) -m 755 xfs_df.sh $(PKG_BIN_DIR)/xfs_df
install-dev:
diff --git a/db/xfs_df.sh b/db/xfs_df.sh
new file mode 100755
index 0000000..27840ac
--- /dev/null
+++ b/db/xfs_df.sh
@@ -0,0 +1,144 @@
+#!/bin/sh
+#
+# Copyright (c) 2007-2009 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+
+status=0
+DB_OPTS="-p xfs_df -r"
+USAGE="Usage: xfs_df [-i] <device>|<mount>"
+
+while test $# -gt 1; do
+ case "$1" in
+ -i)
+ print_inodes=t
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+
+dev="$1"
+
+if [ -z "$dev" -o $# -ne 1 ]; then
+ echo $USAGE 2>&1
+ exit 1
+fi
+
+if [ -d "$dev" ]; then
+ # it's a dir => assume mountpoint
+
+ mnt=`echo "$dev" | sed -e 's,/$,,'`
+ [ "$dev" = "/" ] && mnt="/"
+
+ fdev=`awk -v "mnt=$mnt" '
+ ($2 == mnt && $3 == "xfs") { print $1; exit }
+ ' < /proc/mounts`
+
+ if [ -z "$fdev" ]; then
+ echo "\"$dev\" looks like a mountpoint, but is not mounted as xfs"
+ exit 2
+ fi
+
+ dev="$fdev"
+elif [ -b "$dev" -o -f "$dev" ] ; then
+ # just use the path specified
+ true
+else
+ # ???
+ echo "\"$dev\" is not a device or mountpoint"
+ exit 3
+fi
+
+abort()
+{
+ echo "Error executing xfs_db" >&2
+ exit 4
+}
+
+db_wrapper()
+{
+ tmp=`xfs_db $DB_OPTS "$@" "$dev"`
+ status=$?
+ [ $status -ne 0 ] && abort
+ echo "$tmp" | awk '{print $3}'
+}
+
+agcount=`db_wrapper -c 'sb 0' -c 'p agcount'`
+blocksize=`db_wrapper -c 'sb 0' -c 'p blocksize'`
+
+maxagno=`expr $agcount - 1`
+
+echo "$dev:"
+
+case "$print_inodes" in
+ t)
+ echo "AG Inodes IUsed IFree Use%"
+
+ tot_ino=0
+ tot_use=0
+ tot_fre=0
+
+ for ag in `seq 0 $maxagno`; do
+ count=`db_wrapper -c "agi $ag" -c "p count"`
+ freecount=`db_wrapper -c "agi $ag" -c "p freecount"`
+
+ used=`expr $count - $freecount`
+
+ if [ $count -gt 0 ]; then
+ pused=`expr $used \* 100`
+ pused=`expr $pused / $count`
+ else
+ pused=0
+ fi
+
+ tot_ino=`expr $tot_ino + $count`
+ tot_use=`expr $tot_use + $used`
+ tot_fre=`expr $tot_fre + $freecount`
+
+ printf "%3d %8d %8d %8d %3d%%\n" $ag $count $used $freecount $pused
+ done
+
+ pused=`expr $tot_use \* 100`
+ pused=`expr $pused / $tot_ino`
+ printf "ALL %8d %8d %8d %3d%%\n" $tot_ino $tot_use $tot_fre $pused
+ ;;
+ *)
+ echo "AG 1K-blocks Used Available Use%"
+
+ tot_blo=0
+ tot_use=0
+ tot_ava=0
+
+ for ag in `seq 0 $maxagno`; do
+ length=`db_wrapper -c "agf $ag" -c "p length"`
+ freeblks=`db_wrapper -c "agf $ag" -c "p freeblks"`
+
+ displen=`expr $length \* $blocksize`
+ displen=`expr $displen / 1024`
+
+ dispfree=`expr $freeblks \* $blocksize`
+ dispfree=`expr $dispfree / 1024`
+
+ dispused=`expr $displen - $dispfree`
+
+ pused=`expr $dispused \* 100`
+ pused=`expr $pused / $displen`
+
+ tot_blo=`expr $tot_blo + $displen`
+ tot_use=`expr $tot_use + $dispused`
+ tot_ava=`expr $tot_ava + $dispfree`
+
+ printf "%3d %10d %10d %10d %3d%%\n" $ag $displen $dispused $dispfree $pused
+ done
+
+ pused=`expr $tot_use \* 100`
+ pused=`expr $pused / $tot_blo`
+ printf "ALL %10d %10d %10d %3d%%\n" $tot_blo $tot_use $tot_ava $pused
+ ;;
+esac
--
1.6.0.6
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs_df: a df(1)-like command to list per-ag block and inode usage
2009-09-10 22:46 [PATCH] xfs_df: a df(1)-like command to list per-ag block and inode usage Josef 'Jeff' Sipek
@ 2009-09-10 23:21 ` Christoph Hellwig
2009-09-10 23:31 ` Josef 'Jeff' Sipek
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2009-09-10 23:21 UTC (permalink / raw)
To: Josef 'Jeff' Sipek; +Cc: xfs
On Thu, Sep 10, 2009 at 06:46:26PM -0400, Josef 'Jeff' Sipek wrote:
> +++ b/db/xfs_df.sh
> @@ -0,0 +1,144 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2007-2009 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
> +#
> +# This program is free software; you can redistribute it and/or modify it
> +# under the terms of the GNU General Public License version 2 as published
> +# by the Free Software Foundation.
> +#
> +
> +status=0
> +DB_OPTS="-p xfs_df -r"
> +USAGE="Usage: xfs_df [-i] <device>|<mount>"
> +
> +while test $# -gt 1; do
> + case "$1" in
> + -i)
> + print_inodes=t
> + ;;
> + *)
> + break
> + ;;
> + esac
> + shift
> +done
> +
> +dev="$1"
Can you use the same boilerplate code as the other wrappers for
xfs_db parsing the options and showing the usage to make things more
consistant?
Also any new tools in xfsprogs should really come with a manpage.
> +case "$print_inodes" in
> + t)
> + echo "AG Inodes IUsed IFree Use%"
> +
> + tot_ino=0
> + tot_use=0
> + tot_fre=0
> +
> + for ag in `seq 0 $maxagno`; do
> + count=`db_wrapper -c "agi $ag" -c "p count"`
> + freecount=`db_wrapper -c "agi $ag" -c "p freecount"`
> +
> + used=`expr $count - $freecount`
> +
> + if [ $count -gt 0 ]; then
> + pused=`expr $used \* 100`
> + pused=`expr $pused / $count`
> + else
> + pused=0
> + fi
Wouldn't it be much easier to implement all this in C as a new xfs_db
subcommand?
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs_df: a df(1)-like command to list per-ag block and inode usage
2009-09-10 23:21 ` Christoph Hellwig
@ 2009-09-10 23:31 ` Josef 'Jeff' Sipek
0 siblings, 0 replies; 3+ messages in thread
From: Josef 'Jeff' Sipek @ 2009-09-10 23:31 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: xfs
On Thu, Sep 10, 2009 at 07:21:39PM -0400, Christoph Hellwig wrote:
> On Thu, Sep 10, 2009 at 06:46:26PM -0400, Josef 'Jeff' Sipek wrote:
> > +++ b/db/xfs_df.sh
> > @@ -0,0 +1,144 @@
> > +#!/bin/sh
> > +#
> > +# Copyright (c) 2007-2009 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
> > +#
> > +# This program is free software; you can redistribute it and/or modify it
> > +# under the terms of the GNU General Public License version 2 as published
> > +# by the Free Software Foundation.
> > +#
> > +
> > +status=0
> > +DB_OPTS="-p xfs_df -r"
> > +USAGE="Usage: xfs_df [-i] <device>|<mount>"
> > +
> > +while test $# -gt 1; do
> > + case "$1" in
> > + -i)
> > + print_inodes=t
> > + ;;
> > + *)
> > + break
> > + ;;
> > + esac
> > + shift
> > +done
> > +
> > +dev="$1"
>
> Can you use the same boilerplate code as the other wrappers for
> xfs_db parsing the options and showing the usage to make things more
> consistant?
You mean using getopts? Yeah, I was going to, but decided against it since
there's only one option -i, and the other arg is a device name. I'll fix it
up.
> Also any new tools in xfsprogs should really come with a manpage.
Oh, right...documentation :)
> > +case "$print_inodes" in
> > + t)
> > + echo "AG Inodes IUsed IFree Use%"
> > +
> > + tot_ino=0
> > + tot_use=0
> > + tot_fre=0
> > +
> > + for ag in `seq 0 $maxagno`; do
> > + count=`db_wrapper -c "agi $ag" -c "p count"`
> > + freecount=`db_wrapper -c "agi $ag" -c "p freecount"`
> > +
> > + used=`expr $count - $freecount`
> > +
> > + if [ $count -gt 0 ]; then
> > + pused=`expr $used \* 100`
> > + pused=`expr $pused / $count`
> > + else
> > + pused=0
> > + fi
>
> Wouldn't it be much easier to implement all this in C as a new xfs_db
> subcommand?
Ideally, db could do some basic expressions, e.g.,
xfs_db> agi 0
xfs_db> print (count-freecount)/count
expr = 0.12345
I tried looking at db code to make it have a quiet mode (so a print will not
display the 'field = ' part), but I got a bit lost. It's quite possible that
making a df command in db would be simple, I'd have to look at the code
more (it'd certainly run faster).
Josef 'Jeff' Sipek.
--
What is the difference between Mechanical Engineers and Civil Engineers?
Mechanical Engineers build weapons, Civil Engineers build targets.
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-10 23:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-10 22:46 [PATCH] xfs_df: a df(1)-like command to list per-ag block and inode usage Josef 'Jeff' Sipek
2009-09-10 23:21 ` Christoph Hellwig
2009-09-10 23:31 ` Josef 'Jeff' Sipek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox