|
|
a0a1f4 |
diff -up nfs-utils-2.3.3/configure.ac.orig nfs-utils-2.3.3/configure.ac
|
|
|
a0a1f4 |
--- nfs-utils-2.3.3/configure.ac.orig 2020-06-09 10:58:50.178258035 -0400
|
|
|
a0a1f4 |
+++ nfs-utils-2.3.3/configure.ac 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
@@ -639,6 +639,7 @@ AC_CONFIG_FILES([
|
|
|
a0a1f4 |
tools/rpcgen/Makefile
|
|
|
a0a1f4 |
tools/mountstats/Makefile
|
|
|
a0a1f4 |
tools/nfs-iostat/Makefile
|
|
|
a0a1f4 |
+ tools/nfsdclnts/Makefile
|
|
|
a0a1f4 |
tools/nfsconf/Makefile
|
|
|
a0a1f4 |
tools/nfsdclddb/Makefile
|
|
|
a0a1f4 |
utils/Makefile
|
|
|
a0a1f4 |
diff -up nfs-utils-2.3.3/tools/Makefile.am.orig nfs-utils-2.3.3/tools/Makefile.am
|
|
|
a0a1f4 |
--- nfs-utils-2.3.3/tools/Makefile.am.orig 2020-06-09 10:58:50.178258035 -0400
|
|
|
a0a1f4 |
+++ nfs-utils-2.3.3/tools/Makefile.am 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
@@ -12,6 +12,6 @@ if CONFIG_NFSDCLD
|
|
|
a0a1f4 |
OPTDIRS += nfsdclddb
|
|
|
a0a1f4 |
endif
|
|
|
a0a1f4 |
|
|
|
a0a1f4 |
-SUBDIRS = locktest rpcdebug nlmtest mountstats nfs-iostat $(OPTDIRS)
|
|
|
a0a1f4 |
+SUBDIRS = locktest rpcdebug nlmtest mountstats nfs-iostat nfsdclnts $(OPTDIRS)
|
|
|
a0a1f4 |
|
|
|
a0a1f4 |
MAINTAINERCLEANFILES = Makefile.in
|
|
|
a0a1f4 |
diff -up nfs-utils-2.3.3/tools/nfsdclnts/Makefile.am.orig nfs-utils-2.3.3/tools/nfsdclnts/Makefile.am
|
|
|
a0a1f4 |
--- nfs-utils-2.3.3/tools/nfsdclnts/Makefile.am.orig 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
+++ nfs-utils-2.3.3/tools/nfsdclnts/Makefile.am 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
@@ -0,0 +1,13 @@
|
|
|
a0a1f4 |
+## Process this file with automake to produce Makefile.in
|
|
|
a0a1f4 |
+PYTHON_FILES = nfsdclnts.py
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+man8_MANS = nfsdclnts.man
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+EXTRA_DIST = $(man8_MANS) $(PYTHON_FILES)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+all-local: $(PYTHON_FILES)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+install-data-hook:
|
|
|
a0a1f4 |
+ $(INSTALL) -m 755 nfsdclnts.py $(DESTDIR)$(sbindir)/nfsdclnts
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+MAINTAINERCLEANFILES=Makefile.in
|
|
|
a0a1f4 |
diff -up nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.man.orig nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.man
|
|
|
a0a1f4 |
--- nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.man.orig 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
+++ nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.man 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
@@ -0,0 +1,180 @@
|
|
|
a0a1f4 |
+.\"
|
|
|
a0a1f4 |
+.\" nfsdclnts(8)
|
|
|
a0a1f4 |
+.\"
|
|
|
a0a1f4 |
+.TH "NFSDCLTS" "8" "2020-05-09" "nfsdclnts" "nfsdclnts"
|
|
|
a0a1f4 |
+.ie \n(.g .ds Aq \(aq
|
|
|
a0a1f4 |
+.el .ds Aq '
|
|
|
a0a1f4 |
+.ss \n[.ss] 0
|
|
|
a0a1f4 |
+.nh
|
|
|
a0a1f4 |
+.ad l
|
|
|
a0a1f4 |
+.de URL
|
|
|
a0a1f4 |
+\fI\\$2\fP <\\$1>\\$3
|
|
|
a0a1f4 |
+..
|
|
|
a0a1f4 |
+.als MTO URL
|
|
|
a0a1f4 |
+.if \n[.g] \{\
|
|
|
a0a1f4 |
+. mso www.tmac
|
|
|
a0a1f4 |
+. am URL
|
|
|
a0a1f4 |
+. ad l
|
|
|
a0a1f4 |
+. .
|
|
|
a0a1f4 |
+. am MTO
|
|
|
a0a1f4 |
+. ad l
|
|
|
a0a1f4 |
+. .
|
|
|
a0a1f4 |
+. LINKSTYLE blue R < >
|
|
|
a0a1f4 |
+.\}
|
|
|
a0a1f4 |
+.SH "NAME"
|
|
|
a0a1f4 |
+nfsdclnts \- print various nfs client information for knfsd server.
|
|
|
a0a1f4 |
+.SH "SYNOPSIS"
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts\fP [\fI\-h\fP] [\fI\-t type\fP] [\fI\-\-clientinfo\fP] [\fI\-\-hostname\fP] [\fI\-q\fP]
|
|
|
a0a1f4 |
+.SH "DESCRIPTION"
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+The nfsdclnts(8) command parses the content present in /proc/fs/nfsd/clients/ directories. nfsdclnts(8) displays files which are open, locked, delegated by the nfs\-client. It also prints useful client information such as hostname, clientID, NFS version mounted by the nfs\-client.
|
|
|
a0a1f4 |
+.SH "OPTIONS"
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-t, \-\-type\fP=TYPE
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Specify the type of file to be displayed. Takes only one TYPE at a time.
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fIopen\fP, \fIlock\fP, \fIdeleg\fP, \fIlayout\fP, or \fIall\fP
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+open: displays the open files by nfs\-client(s).
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+lock: displays the files locked by nfs\-client(s).
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+layout: displays the files for which layout is given.
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+deleg: displays delegated files information and delegation type.
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+all: prints all the above type.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-\-clientinfo\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+displays various nfs\-client info fields such as version of nfs mounted at nfs\-client and clientID.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-\-hostname\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Print hostname of nfs\-client instead of ip-address.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-q, \-\-quiet\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Hide the header information.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-v, \-\-verbose\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Verbose operation, show debug messages.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-f, \-\-file\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Instead of processing all client directories under /proc/fs/nfsd/clients, one can provide a specific
|
|
|
a0a1f4 |
+states file to process. One should make sure that info file resides in the same directory as states file.
|
|
|
a0a1f4 |
+If the info file is not valid or present the fields would be marked as "N/A".
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB\-h, \-\-help\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Print help explaining the command line options.
|
|
|
a0a1f4 |
+.SH "EXAMPLES"
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts \-\-type open\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+List all files with open type only.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+.if n .RS 4
|
|
|
a0a1f4 |
+.nf
|
|
|
a0a1f4 |
+Inode number | Type | Access | Deny | ip address | Filename
|
|
|
a0a1f4 |
+33823232 | open | r\- | \-\- | [::1]:757 | testfile
|
|
|
a0a1f4 |
+.fi
|
|
|
a0a1f4 |
+.if n .RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts \-\-type deleg\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+List all files with deleg type only.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+.if n .RS 4
|
|
|
a0a1f4 |
+.nf
|
|
|
a0a1f4 |
+Inode number | Type | Access | ip address | Filename
|
|
|
a0a1f4 |
+33823232 | deleg | r | [::1]:757 | testfile
|
|
|
a0a1f4 |
+.fi
|
|
|
a0a1f4 |
+.if n .RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts \-\-hostname\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Print hostname instead of ip\-address.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+.if n .RS 4
|
|
|
a0a1f4 |
+.nf
|
|
|
a0a1f4 |
+Inode number | Type | Access | Deny | Hostname | Filename
|
|
|
a0a1f4 |
+33823232 | open | r\- | \-\- | nfs\-server | testfile
|
|
|
a0a1f4 |
+33823232 | deleg | r | | nfs\-server | testfile
|
|
|
a0a1f4 |
+.fi
|
|
|
a0a1f4 |
+.if n .RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts \-\-clientinfo\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Print client information.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+.if n .RS 4
|
|
|
a0a1f4 |
+.nf
|
|
|
a0a1f4 |
+Inode number | Type | Access | Deny | ip address | Client ID | vers | Filename
|
|
|
a0a1f4 |
+33823232 | open | r\- | \-\- | [::1]:757 | 0xc79a009f5eb65e84 | 4.2 | testfile
|
|
|
a0a1f4 |
+33823232 | deleg | r | | [::1]:757 | 0xc79a009f5eb65e84 | 4.2 | testfile
|
|
|
a0a1f4 |
+.fi
|
|
|
a0a1f4 |
+.if n .RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts \-\-file /proc/fs/nfsd/clients/3/states -t open\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Process specific states file.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+.if n .RS 4
|
|
|
a0a1f4 |
+.nf
|
|
|
a0a1f4 |
+Inode number | Type | Access | Deny | ip address | Client ID | vers | Filename
|
|
|
a0a1f4 |
+33823232 | open | r\- | \-\- | [::1]:757 | 0xc79a009f5eb65e84 | 4.2 | testfile
|
|
|
a0a1f4 |
+.fi
|
|
|
a0a1f4 |
+.if n .RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fBnfsdclnts \-\-quiet \-\-hostname\fP
|
|
|
a0a1f4 |
+.RS 4
|
|
|
a0a1f4 |
+Hide the header information.
|
|
|
a0a1f4 |
+.RE
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+.if n .RS 4
|
|
|
a0a1f4 |
+.nf
|
|
|
a0a1f4 |
+33823232 | open | r\- | \-\- | nfs\-server | testfile
|
|
|
a0a1f4 |
+33823232 | deleg | r | | nfs\-server | testfile
|
|
|
a0a1f4 |
+.fi
|
|
|
a0a1f4 |
+.if n .RE
|
|
|
a0a1f4 |
+.SH "FILES"
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB/proc/fs/nfsd/clients/\fP
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+Displays basic information about each NFSv4 client.
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB/proc/fs/nfsd/clients/#/info\fP
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+Displays information about all the opens held by the given client, including open modes, device numbers, inode numbers, and open owners.
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+\fB/proc/fs/nfsd/clients/#/states\fP
|
|
|
a0a1f4 |
+.SH "NOTES"
|
|
|
a0a1f4 |
+.sp
|
|
|
a0a1f4 |
+/proc/fs/nfsd/clients/ support was initially introduced in 5.3 kernel and is only implemented for mount points using NFSv4.
|
|
|
a0a1f4 |
+.SH "BUGS"
|
|
|
a0a1f4 |
+Please report any BUGs to \c
|
|
|
a0a1f4 |
+.MTO "linux\-nfs\(atvger.kernel.org" "" ""
|
|
|
a0a1f4 |
+.SH SEE ALSO
|
|
|
a0a1f4 |
+.BR nfsd (8),
|
|
|
a0a1f4 |
+.BR exportfs (8),
|
|
|
a0a1f4 |
+.BR idmapd (8),
|
|
|
a0a1f4 |
+.BR statd (8)
|
|
|
a0a1f4 |
+.SH "AUTHORS"
|
|
|
a0a1f4 |
+Achilles Gaikwad <agaikwad@redhat.com> and
|
|
|
a0a1f4 |
+Kenneth D'souza <kdsouza@redhat.com>
|
|
|
a0a1f4 |
diff -up nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.py.orig nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.py
|
|
|
a0a1f4 |
--- nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.py.orig 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
+++ nfs-utils-2.3.3/tools/nfsdclnts/nfsdclnts.py 2020-06-09 11:02:04.203102954 -0400
|
|
|
a0a1f4 |
@@ -0,0 +1,254 @@
|
|
|
a0a1f4 |
+#!/usr/bin/python3
|
|
|
a0a1f4 |
+# -*- python-mode -*-
|
|
|
a0a1f4 |
+'''
|
|
|
a0a1f4 |
+ Copyright (C) 2020
|
|
|
a0a1f4 |
+ Authors: Achilles Gaikwad <agaikwad@redhat.com>
|
|
|
a0a1f4 |
+ Kenneth D'souza <kdsouza@redhat.com>
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ This program is free software: you can redistribute it and/or modify
|
|
|
a0a1f4 |
+ it under the terms of the GNU General Public License as published by
|
|
|
a0a1f4 |
+ the Free Software Foundation, either version 3 of the License, or
|
|
|
a0a1f4 |
+ (at your option) any later version.
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ This program is distributed in the hope that it will be useful,
|
|
|
a0a1f4 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a0a1f4 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
a0a1f4 |
+ GNU General Public License for more details.
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ You should have received a copy of the GNU General Public License
|
|
|
a0a1f4 |
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
a0a1f4 |
+'''
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+import multiprocessing as mp
|
|
|
a0a1f4 |
+import os
|
|
|
a0a1f4 |
+import signal
|
|
|
a0a1f4 |
+import sys
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+try:
|
|
|
a0a1f4 |
+ import argparse
|
|
|
a0a1f4 |
+except ImportError:
|
|
|
a0a1f4 |
+ print('%s: Failed to import argparse - make sure argparse is installed!'
|
|
|
a0a1f4 |
+ % sys.argv[0])
|
|
|
a0a1f4 |
+ sys.exit(1)
|
|
|
a0a1f4 |
+try:
|
|
|
a0a1f4 |
+ import yaml
|
|
|
a0a1f4 |
+except ImportError:
|
|
|
a0a1f4 |
+ print('%s: Failed to import yaml - make sure python3-pyyaml is installed!'
|
|
|
a0a1f4 |
+ % sys.argv[0])
|
|
|
a0a1f4 |
+ sys.exit(1)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+BBOLD = '\033[1;30;47m' #Bold black text with white background.
|
|
|
a0a1f4 |
+ENDC = '\033[m' #Rest to defaults
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+def init_worker():
|
|
|
a0a1f4 |
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+# this function converts the info file to a dictionary format, sorta.
|
|
|
a0a1f4 |
+def file_to_dict(path):
|
|
|
a0a1f4 |
+ client_info = {}
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ with open(path) as f:
|
|
|
a0a1f4 |
+ for line in f:
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ (key, val) = line.split(':', 1)
|
|
|
a0a1f4 |
+ client_info[key] = val.strip()
|
|
|
a0a1f4 |
+ # FIXME: There has to be a better way of converting the info file to a dictionary.
|
|
|
a0a1f4 |
+ except ValueError as reason:
|
|
|
a0a1f4 |
+ if verbose:
|
|
|
a0a1f4 |
+ print('Exception occured, %s' % reason)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ if len(client_info) == 0 and verbose:
|
|
|
a0a1f4 |
+ print("Provided %s file is not valid" %path)
|
|
|
a0a1f4 |
+ return client_info
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ except OSError as reason:
|
|
|
a0a1f4 |
+ if verbose:
|
|
|
a0a1f4 |
+ print('%s' % reason)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+# this function gets the paths from /proc/fs/nfsd/clients/
|
|
|
a0a1f4 |
+# returns a list of paths for each client which has nfs-share mounted.
|
|
|
a0a1f4 |
+def getpaths():
|
|
|
a0a1f4 |
+ path = []
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ dirs = os.listdir('/proc/fs/nfsd/clients/')
|
|
|
a0a1f4 |
+ except OSError as reason:
|
|
|
a0a1f4 |
+ exit('%s' % reason)
|
|
|
a0a1f4 |
+ if len(dirs) !=0:
|
|
|
a0a1f4 |
+ for i in dirs:
|
|
|
a0a1f4 |
+ path.append('/proc/fs/nfsd/clients/' + i + '/states')
|
|
|
a0a1f4 |
+ return (path)
|
|
|
a0a1f4 |
+ else:
|
|
|
a0a1f4 |
+ exit('Nothing to process')
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+# A single function to rule them all, in this function we gather all the data
|
|
|
a0a1f4 |
+# from already populated data_list and client_info.
|
|
|
a0a1f4 |
+def printer(data_list, argument):
|
|
|
a0a1f4 |
+ client_info_path = data_list.pop()
|
|
|
a0a1f4 |
+ client_info = file_to_dict(client_info_path)
|
|
|
a0a1f4 |
+ for i in data_list:
|
|
|
a0a1f4 |
+ for key in i:
|
|
|
a0a1f4 |
+ inode = i[key]['superblock'].split(':')[-1]
|
|
|
a0a1f4 |
+ # The ip address is quoted, so we dequote it.
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ client_ip = client_info['address'][1:-1]
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ client_ip = "N/A"
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ # if the nfs-server reboots while the nfs-client holds the files open,
|
|
|
a0a1f4 |
+ # the nfs-server would print the filename as '/'. For such instaces we
|
|
|
a0a1f4 |
+ # print the output as disconnected dentry instead of '/'.
|
|
|
a0a1f4 |
+ if(i[key]['filename']=='/'):
|
|
|
a0a1f4 |
+ fname = 'disconnected dentry'
|
|
|
a0a1f4 |
+ else:
|
|
|
a0a1f4 |
+ fname = i[key]['filename'].split('/')[-1]
|
|
|
a0a1f4 |
+ except KeyError:
|
|
|
a0a1f4 |
+ # for older kernels which do not have the fname patch in kernel, they
|
|
|
a0a1f4 |
+ # won't be able to see the fname field. Therefore post it as N/A.
|
|
|
a0a1f4 |
+ fname = "N/A"
|
|
|
a0a1f4 |
+ otype = i[key]['type']
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ access = i[key]['access']
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ access = ''
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ deny = i[key]['deny']
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ deny = ''
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ hostname = client_info['name'].split()[-1].split('"')[0]
|
|
|
a0a1f4 |
+ hostname = hostname.split('.')[0]
|
|
|
a0a1f4 |
+ # if the hostname is too long, it messes up with the output being in columns,
|
|
|
a0a1f4 |
+ # therefore we truncate the hostname followed by two '..' as suffix.
|
|
|
a0a1f4 |
+ if len(hostname) > 20:
|
|
|
a0a1f4 |
+ hostname = hostname[0:20] + '..'
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ hostname = "N/A"
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ clientid = client_info['clientid']
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ clientid = "N/A"
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ minorversion = "4." + client_info['minor version']
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ minorversion = "N/A"
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ otype = i[key]['type']
|
|
|
a0a1f4 |
+ # since some fields do not have deny column, we drop those if -t is either
|
|
|
a0a1f4 |
+ # layout or lock.
|
|
|
a0a1f4 |
+ drop = ['layout', 'lock']
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ # Printing the output this way instead of a single string which is concatenated
|
|
|
a0a1f4 |
+ # this makes it better to quickly add more columns in future.
|
|
|
a0a1f4 |
+ if(otype == argument.type or argument.type == 'all'):
|
|
|
a0a1f4 |
+ print('%-13s' %inode, end='| ')
|
|
|
a0a1f4 |
+ print('%-7s' %otype, end='| ')
|
|
|
a0a1f4 |
+ if (argument.type not in drop):
|
|
|
a0a1f4 |
+ print('%-7s' %access, end='| ')
|
|
|
a0a1f4 |
+ if (argument.type not in drop and argument.type !='deleg'):
|
|
|
a0a1f4 |
+ print('%-5s' %deny, end='| ')
|
|
|
a0a1f4 |
+ if (argument.hostname == True):
|
|
|
a0a1f4 |
+ print('%-22s' %hostname, end='| ')
|
|
|
a0a1f4 |
+ else:
|
|
|
a0a1f4 |
+ print('%-22s' %client_ip, end='| ')
|
|
|
a0a1f4 |
+ if (argument.clientinfo == True) :
|
|
|
a0a1f4 |
+ print('%-20s' %clientid, end='| ')
|
|
|
a0a1f4 |
+ print('%-5s' %minorversion, end='| ')
|
|
|
a0a1f4 |
+ print(fname)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+def opener(path):
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ with open(path, 'r') as nfsdata:
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ data = yaml.load(nfsdata, Loader = yaml.BaseLoader)
|
|
|
a0a1f4 |
+ if data is not None:
|
|
|
a0a1f4 |
+ clientinfo = path.rsplit('/', 1)[0] + '/info'
|
|
|
a0a1f4 |
+ data.append(clientinfo)
|
|
|
a0a1f4 |
+ return data
|
|
|
a0a1f4 |
+ except:
|
|
|
a0a1f4 |
+ if verbose:
|
|
|
a0a1f4 |
+ print("Exception occurred, Please make sure %s is a YAML file" %path)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ except OSError as reason:
|
|
|
a0a1f4 |
+ if verbose:
|
|
|
a0a1f4 |
+ print('%s' % reason)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+def print_cols(argument):
|
|
|
a0a1f4 |
+ title_inode = 'Inode number'
|
|
|
a0a1f4 |
+ title_otype = 'Type'
|
|
|
a0a1f4 |
+ title_access = 'Access'
|
|
|
a0a1f4 |
+ title_deny = 'Deny'
|
|
|
a0a1f4 |
+ title_fname = 'Filename'
|
|
|
a0a1f4 |
+ title_clientID = 'Client ID'
|
|
|
a0a1f4 |
+ title_hostname = 'Hostname'
|
|
|
a0a1f4 |
+ title_ip = 'ip address'
|
|
|
a0a1f4 |
+ title_nfsvers = 'vers'
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ drop = ['lock', 'layout']
|
|
|
a0a1f4 |
+ print(BBOLD, end='')
|
|
|
a0a1f4 |
+ print('%-13s' %title_inode, end='| ')
|
|
|
a0a1f4 |
+ print('%-7s' %title_otype, end='| ')
|
|
|
a0a1f4 |
+ if (argument.type not in drop):
|
|
|
a0a1f4 |
+ print('%-7s' %title_access, end='| ')
|
|
|
a0a1f4 |
+ if (argument.type not in drop and argument.type !='deleg'):
|
|
|
a0a1f4 |
+ print('%-5s' %title_deny, end='| ')
|
|
|
a0a1f4 |
+ if (argument.hostname == True):
|
|
|
a0a1f4 |
+ print('%-22s' %title_hostname, end='| ')
|
|
|
a0a1f4 |
+ else:
|
|
|
a0a1f4 |
+ print('%-22s' %title_ip, end='| ')
|
|
|
a0a1f4 |
+ if (argument.clientinfo == True):
|
|
|
a0a1f4 |
+ print('%-20s' %title_clientID, end='| ')
|
|
|
a0a1f4 |
+ print('%-5s' %title_nfsvers, end='| ')
|
|
|
a0a1f4 |
+ print(title_fname, end='')
|
|
|
a0a1f4 |
+ print(ENDC)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+def nfsd4_show():
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ parser = argparse.ArgumentParser(description = 'Parse the nfsd states and clientinfo files.')
|
|
|
a0a1f4 |
+ parser.add_argument('-t', '--type', metavar = 'type', type = str, choices = ['open',
|
|
|
a0a1f4 |
+ 'deleg', 'lock', 'layout', 'all'],
|
|
|
a0a1f4 |
+ default = 'all',
|
|
|
a0a1f4 |
+ help = 'Input the type that you want to be printed: open, lock, deleg, layout, all')
|
|
|
a0a1f4 |
+ parser.add_argument('--clientinfo', action = 'store_true',
|
|
|
a0a1f4 |
+ help = 'output clients information, --hostname is implied.')
|
|
|
a0a1f4 |
+ parser.add_argument('--hostname', action = 'store_true',
|
|
|
a0a1f4 |
+ help = 'print hostname of client instead of its ip address. Longer hostnames are truncated.')
|
|
|
a0a1f4 |
+ parser.add_argument('-v', '--verbose', action = 'store_true',
|
|
|
a0a1f4 |
+ help = 'Verbose operation, show debug messages.')
|
|
|
a0a1f4 |
+ parser.add_argument('-f', '--file', nargs='+', type = str, metavar='',
|
|
|
a0a1f4 |
+ help = 'pass client states file, provided that info file resides in the same directory.')
|
|
|
a0a1f4 |
+ parser.add_argument('-q', '--quiet', action = 'store_true',
|
|
|
a0a1f4 |
+ help = 'don\'t print the header information')
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ args = parser.parse_args()
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ global verbose
|
|
|
a0a1f4 |
+ verbose = False
|
|
|
a0a1f4 |
+ if args.verbose:
|
|
|
a0a1f4 |
+ verbose = True
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ if args.file:
|
|
|
a0a1f4 |
+ paths = args.file
|
|
|
a0a1f4 |
+ else:
|
|
|
a0a1f4 |
+ paths = getpaths()
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ p = mp.Pool(mp.cpu_count(), init_worker)
|
|
|
a0a1f4 |
+ try:
|
|
|
a0a1f4 |
+ result = p.map(opener, paths)
|
|
|
a0a1f4 |
+ ### Drop None entries from list
|
|
|
a0a1f4 |
+ final_result = list(filter(None, result))
|
|
|
a0a1f4 |
+ p.close()
|
|
|
a0a1f4 |
+ p.join()
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ if len(final_result) !=0 and not args.quiet:
|
|
|
a0a1f4 |
+ print_cols(args)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ for item in final_result:
|
|
|
a0a1f4 |
+ printer(item, args)
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+ except KeyboardInterrupt:
|
|
|
a0a1f4 |
+ print('Caught KeyboardInterrupt, terminating workers')
|
|
|
a0a1f4 |
+ p.terminate()
|
|
|
a0a1f4 |
+ p.join()
|
|
|
a0a1f4 |
+
|
|
|
a0a1f4 |
+if __name__ == "__main__":
|
|
|
a0a1f4 |
+ nfsd4_show()
|