nfsstat: fix server rpc stats header

linux/net/sunrpc/stats.c has:

/*
 * Get RPC server stats
 */
void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) {
...
        seq_printf(seq,
                "rpc %u %u %u %u %u\n",
                        statp->rpccnt,
                        statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
                        statp->rpcbadfmt,
                        statp->rpcbadauth,
                        statp->rpcbadclnt);
...

But when /proc/net/rpc/nfsd contains

rpc 1 2 3 4 5

nfsstat -sv prints:

Server rpc stats:
calls      badcalls   badclnt    badauth    xdrcall
1          2          3          4          5

Change this to match the kernel:

Server rpc stats:
calls      badcalls   badfmt     badauth    badclnt
1          2          3          4          5

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1142842.

Signed-off-by: Marko Myllynen <myllynen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steve Dickson <steved@redhat.com>
umount: make it sensitive to -v

Let's print verbose messages like original non-libmount version.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
mountstats: Don't display retrans stats unless there are re-xmit

Clean up display of RPC statistics by omitting retransmit statistics
when there have been no retransmissions.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsidmap: keyctl_invalidate kernel compatibility

Change the keyctl_invalidate call to use the syscall interface
directly so that when building with libkeyutils missing keyctl_invalidate
the build succeeds.  Attempt to use _invalidate and fall back to
_revoke if the current kernel is missing _invalidate.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsidmap: set the correct DEFAULT_KEYRING string

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
nfsidmap: Correct a failure to set key timeout values

The caller must be a possesor of the key to set the attributes, so link the
destination keyring to the current thread's keyring before instantiation so
that after instantiation the timeout can be set.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
exportfs: changes handling of unresolvable entries

The patch to nfs/exportfs to allow nfsd to start when
there are some, but not all, unresolvable entries in
/etc/exports.

Signed-off-by: Henrique Martins <linux@martins.cc>
Signed-off-by: Steve Dickson <steved@redhat.com>
configure: Fixed logic around $enable_gss and $enable_svcgss

Signed-off-by: Steve Dickson <steved@redhat.com>
configure: Fixed typo in configure.ac

Signed-off-by: Steve Dickson <steved@redhat.com>
rpc.mountd: set nonblocking mode if no libtirpc

If mountd is built without libtirpc and it is started using "-p XXX"
option, the tcp listeners and the sockets waiting for UDP messages
are not in non-blocking mode. Thus if running with multiple threads (-t XX),
all threads will wake up from select on a connection request or a UDP
message, but only one thread will succeed. All others will wait on
accept() or read() for the next event.

Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
rpc.mountd: set nonblocking mode with libtirpc

If mountd is built with libtirpc the tcp listeners and the sockets
waiting for UDP messages are not in non-blocking mode. Thus if running
with multiple threads (-t XX), all threads will wake up from select on
a connection request or a UDP message, but only one thread will succeed.
All others will wait on accept() or read() for the next event.

Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
rpc.mountd: set libtirpc nonblocking mode to avoid DOS

This patch is experimental. In works fine in that it removes the
vulnerability against a DOS attack. rpc.mountd can be blocked by
a bad client, that sends many RPC requests but never reads the
responses. This might happen intentionally or caused by a wrong
network config (MTU). The patch switches on the nonblocking
mode of libtirpc. In that mode writes can block for a max of 2 seconds.
Attackers are forced to send requests slower, as libtirpc will close
a connection if it finds two requests to read at the same time.

Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
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>
exportfs: warn when really nothing is exported

Throw 'No file systems exported!' iff no volume is exported rather
then if some exports file is empty.  Typically this can happen if
the default /etc/exports file is empty and admin installed
configuration into /etc/exports.d directory.

This is follow-up for e725def62c73b4 commit.

Signed-off-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
mountstats: Sort RPC statistics by operation count

Sort the RPC statistics in descending order by operation count, so
that the most frequently executed operation appears at the top of
the listing (a la `top`).

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Add string.h to source files that need it

Signed-off-by: Steve Dickson <steved@redhat.com>
mountd: talk to kernel using file descriptors instead of FILE

Signed-off-by: Steve Dickson <steved@redhat.com>