mountstats: Fix spurious I/O errors

When running mountstats under "watch," occassionally the output
shows "close failed in file object desctructor: sys.excepthook is
missing" and the data display is messed up. This seems to be a
common problem when Python script output is piped to another
program.

Ensure stdout/stderr is completely flushed before mountstats exits,
and add an IOError exception handler to catch these exceptions
gracefully.

Solution suggested by: http://bugs.python.org/issue11380

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
exportfs: Do not fail on empty exports file.

Commit 076dd80 introduced a regression that causes
exportfs to fail when there is an empty /etc/exports
file. A empty /etc/exports file is valid and should
not cause exportfs to fail.

Signed-off-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsdcltrack: use sqlite3_close instead of sqlite3_close_v2

sqlite3_close_v2 wasn't added until v3.7.14 of libsqlite3 so this causes
the build to fail vs. very old sqlite3 libs. Also, Chuck points out that
the documentation says that sqlite3_close_v2 is intended for use with
host languages that are garbage collected, and C isn't.

In practice, we shouldn't ever see sqlite3_close return SQLITE_BUSY here
anyway since the program is single-threaded, so sqlite3_close should be
fine.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsdcltrack: use sqlite3_errmsg instead of sqlite3_errstr

sqlite3_errstr was only added in v3.7.15 of libsqlite3, which makes it
difficult to build against earlier releases. Switch the code over to
use sqlite3_errmsg instead.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
mountstats: Fix up NFS event counters

The event counters in the mountstats program aren't in sync with the
event counters in the kernel.  Removed syncinodes and added
vfsupdatepage, vfssetattr, congestionwait, pnfsreads, and pnfswrites.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Add lists of various counters

The NfsEventCounters and NfsByteCounters were lifted straight from
nfs-iostat.py.  Also added counters for the xprt line (for udp, tcp, and
rdma) as well as for v3 and v4 NFS ops.  These will allow for more
compact code in a couple of places.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Refactor __parse_nfs_line and __parse_rpc_line

Iterate over the newly added counter lists instead of having a ton of
assignment statements.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Refactor compare_iostats

Iterate over the newly added counters instead of using repeated
assignment statements.  Also compute the difference of every counter
where it makes sense -- this will allow support for -S/--since to be
implemented in the future.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Convert existing option parsing to use the getopt module

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Make ms-iostat output match that of nfs-iostat.py

Changes mostly lifted straight from nfs-iostat.py.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Make print_iostat_summary handle newly appearing mounts

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Add support for -f/--file to the mountstats and ms-iostat commands

Add support for the -f/--file option to allow parsing of data from an
arbitrary file instead of /proc/self/mountstats.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Add support for -S/--since to the mountstats and ms-iostat commands

Add support for -S/--since to the mountstats and ms-iostat commands to
display the delta between a previous copy of /proc/self/mountstats and
the current /proc/self/mountstats file.  Can be combined with the -f
option to show the statistics between two different points in time.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Fix IndexError in __parse_nfs_line

If __parse_nfs_line is is called on a line that has 'fstype nfsd', it'll
raise an IndexError trying to parse a nonexistent statvers entry.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Allow mountstats_command to take a variable number of mountpoints

Allow the mountstats command to take a variable number of mountpoints
(including none, in which case it will print stats for all NFS
mountpoints it finds).

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Add support for -R/--raw to mountstats_command

This option displays the mountstats in raw format (i.e. in the same
format as /proc/self/mountstats).  It's intended to be used mainly with
the -S/--since option.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Implement nfsstat_command

Displays nfssstat-like statistics for a single mountpoint (client
statistics only).

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Remove the --start and --end options

All they do is throw 'not implemented' exceptions anyway.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
mountstats: Update the help output

Updated the help output for mounstats, ms-iostat, and ms-nfsstat to make
them constistent.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>