[patch] /proc/fs/nfsd/exports

G. Allen Morris III (gam3@dharma.sehda.com)
Tue, 03 Nov 1998 22:08:21 -0800


Here is a patch to fs/nfsd that lets you print the kernel exports
through /proc/fs/nfsd/exports.

Allen

------------------------- cut here ----------------------------
Index: linux/fs/nfsd/export.c
diff -c linux/fs/nfsd/export.c:1.1.2.30 linux/fs/nfsd/export.c:1.1.2.9.2.1
*** linux/fs/nfsd/export.c:1.1.2.30 Tue Nov 3 14:38:31 1998
--- linux/fs/nfsd/export.c Sat Oct 31 21:59:35 1998
***************
*** 615,620 ****
--- 615,726 ----
return NULL;
}

+ struct flags {
+ int flag;
+ char *name[2];
+ } expflags[] = {
+ { NFSEXP_READONLY, {"ro", "rw"}},
+ { NFSEXP_INSECURE_PORT, {"insecure", ""}},
+ { NFSEXP_ROOTSQUASH, {"root_squash", "no_root_squash"}},
+ { NFSEXP_ALLSQUASH, {"all_squash", ""}},
+ { NFSEXP_ASYNC, {"async", ""}},
+ { NFSEXP_GATHERED_WRITES, {"wdelay", ""}},
+ { NFSEXP_UIDMAP, {"uidmap", ""}},
+ { NFSEXP_KERBEROS, { "kerberos", ""}},
+ { NFSEXP_SUNSECURE, { "sunsecure", ""}},
+ { NFSEXP_CROSSMNT, {"crossmnt", ""}},
+ { 0, {"", ""}}
+ };
+
+ static int
+ exp_flags(char *buffer, int flag)
+ {
+ int len = 0, first = 0;
+ struct flags *flg = expflags;
+
+ for (;flg->flag;flg++) {
+ int state = (flg->flag & flag)?0:1;
+ if (!flg->flag)
+ break;
+ if (*flg->name[state]) {
+ len += sprintf(buffer + len, "%s%s",
+ first++?",":"", flg->name[state]);
+ }
+ }
+ return len;
+ }
+
+ int
+ exp_procfs_exports(char *buffer, char **start, off_t offset,
+ int length, int *eof, void *data)
+ {
+ struct svc_clnthash **hp, **head, *tmp;
+ struct svc_client *clp;
+ svc_export *exp;
+ off_t pos = 0;
+ off_t begin = 0;
+ int len = 0;
+ int i,j;
+
+ len += sprintf(buffer, "# Version 1.0\n");
+ len += sprintf(buffer+len, "# Path Client(Flags) # IPs\n");
+
+ for (clp = clients; clp; clp = clp->cl_next) {
+ for (i = 0; i < NFSCLNT_EXPMAX; i++) {
+ exp = clp->cl_export[i];
+ while (exp) {
+ int first = 0;
+ len += sprintf(buffer+len, "%s\t", exp->ex_path);
+ len += sprintf(buffer+len, "%s", clp->cl_ident);
+ len += sprintf(buffer+len, "(");
+
+ len += exp_flags(buffer+len, exp->ex_flags);
+ len += sprintf(buffer+len, ") # ");
+ for (j = 0; j < clp->cl_naddr; j++) {
+ struct in_addr addr = clp->cl_addr[j];
+
+ head = &clnt_hash[CLIENT_HASH(addr.s_addr)];
+ for (hp = head; (tmp = *hp) != NULL; hp = &(tmp->h_next)) {
+ if (tmp->h_addr.s_addr == addr.s_addr) {
+ if (first++) len += sprintf(buffer+len, "%s", " ");
+ if (tmp->h_client != clp)
+ len += sprintf(buffer+len, "(");
+ len += sprintf(buffer+len, "%d.%d.%d.%d",
+ htonl(addr.s_addr) >> 24 & 0xff,
+ htonl(addr.s_addr) >> 16 & 0xff,
+ htonl(addr.s_addr) >> 8 & 0xff,
+ htonl(addr.s_addr) >> 0 & 0xff);
+ if (tmp->h_client != clp)
+ len += sprintf(buffer+len, ")");
+ break;
+ }
+ }
+ }
+ exp = exp->ex_next;
+
+ buffer[len++]='\n';
+
+ pos=begin+len;
+ if(pos<offset) {
+ len=0;
+ begin=pos;
+ }
+ if (pos > offset + length)
+ goto done;
+ }
+ }
+ }
+
+ *eof = 1;
+
+ done:
+ *start = buffer + (offset - begin);
+ len -= (offset - begin);
+ if ( len > length )
+ len = length;
+ return len;
+ }
+
/*
* Add or modify a client.
* Change requests may involve the list of host addresses. The list of
Index: linux/fs/nfsd/nfsctl.c
diff -c linux/fs/nfsd/nfsctl.c:1.1.2.17 linux/fs/nfsd/nfsctl.c:1.1.2.3.6.1
*** linux/fs/nfsd/nfsctl.c:1.1.2.17 Tue Nov 3 14:38:32 1998
--- linux/fs/nfsd/nfsctl.c Sat Oct 31 21:59:35 1998
***************
*** 21,26 ****
--- 21,27 ----
#include <linux/version.h>
#include <linux/unistd.h>
#include <linux/malloc.h>
+ #include <linux/proc_fs.h>

#include <linux/nfs.h>
#include <linux/sunrpc/svc.h>
***************
*** 53,58 ****
--- 54,77 ----

static int initialized = 0;

+ #ifdef CONFIG_PROC_FS
+
+ int exp_procfs_exports(char *buffer, char **start, off_t offset,
+ int length, int *eof, void *data);
+
+ void proc_export_init()
+ {
+ struct proc_dir_entry *nfs_export_ent = NULL;
+
+ if (!(nfs_export_ent = create_proc_entry("fs/nfs", S_IFDIR, 0)))
+ return;
+ if (!(nfs_export_ent = create_proc_entry("fs/nfs/exports", 0, 0)))
+ return;
+ nfs_export_ent->read_proc = exp_procfs_exports;
+ }
+
+ #endif
+
/*
* Initialize nfsd
*/
***************
*** 68,73 ****
--- 87,95 ----
nfsd_lockd_init(); /* lockd->nfsd callbacks */
nfsd_racache_init(); /* Readahead param cache */
nfsd_fh_init(); /* FH table */
+ #ifdef CONFIG_PROC_FS
+ proc_export_init();
+ #endif
initialized = 1;
}

***************
*** 290,295 ****
--- 312,319 ----
nfsd_cache_shutdown();
nfsd_fh_free();
#ifdef CONFIG_PROC_FS
+ remove_proc_entry("fs/nfs/exports", NULL);
+ remove_proc_entry("fs/nfs", NULL);
nfsd_stat_shutdown();
#endif
nfsd_lockd_shutdown();

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/