nfsv4 sharing nfssvc() with the regular nfsd
Rick Macklem
rmacklem at uoguelph.ca
Thu Apr 2 14:55:19 PDT 2009
For nfsv4 to live side-by-side with the regular nfsd, they must either
share the nfssvc() system call or a new one must be allocated for nfsv4.
As such, I've cobbled some code to-gether to allow the nfssvc() syscall
to be shared. It basically consists of a small module called nfssvc with
only the nfssvc() syscall function in it, where nfsserver and nfsv4
"register" with it by setting the appropriate function pointer non-null.
These functions are then called, based on the NFSSVC_xxx flag value. (I've
coalesced the NFSSVC_xxx flags into a separate .h file, to avoid
confusion.)
I also deleted the following, since I believe that it is just cruft.
(sysproto.h is included in all of these files.)
#ifndef _SYS_SYSPROTO_H_
struct nfssvc_args {
int flag;
caddr_t argp;
};
#endif
Is there a reason for the above?
I've attached the "diff -u" in case anyone would be willing to
review it, rick.
diff -u -r -N nfsserver/nfs.h nfsserver.new/nfs.h
--- nfsserver/nfs.h 2009-04-02 03:55:57.000000000 -0400
+++ nfsserver.new/nfs.h 2009-04-02 05:34:17.000000000 -0400
@@ -40,6 +40,8 @@
#include "opt_nfs.h"
#endif
+#include <nfs/nfssvc.h>
+
/*
* Tunable constants for nfs
*/
@@ -116,13 +118,6 @@
#endif
/*
- * Flags for nfssvc() system call.
- */
-#define NFSSVC_OLDNFSD 0x004
-#define NFSSVC_ADDSOCK 0x008
-#define NFSSVC_NFSD 0x010
-
-/*
* vfs.nfsrv sysctl(3) identifiers
*/
#define NFS_NFSRVSTATS 1 /* struct: struct nfsrvstats */
@@ -447,6 +442,13 @@
struct mbuf **mrq);
int nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
struct mbuf **mrq);
+/*
+ * #ifdef _SYS_SYSPROTO_H_ so that it is only defined when sysproto.h
+ * has been included, so that "struct nfssvc_args" is defined.
+ */
+#ifdef _SYS_SYSPROTO_H_
+int nfssvc_nfsserver(struct thread *, struct nfssvc_args *);
+#endif
#endif /* _KERNEL */
#endif
diff -u -r -N nfsserver/nfs_srvkrpc.c nfsserver.new/nfs_srvkrpc.c
--- nfsserver/nfs_srvkrpc.c 2009-04-02 03:55:57.000000000 -0400
+++ nfsserver.new/nfs_srvkrpc.c 2009-04-02 05:34:17.000000000 -0400
@@ -151,6 +151,9 @@
/*
* NFS server system calls
*/
+/*
+ * This is now called from nfssvc() in nfs/nfs_nfssvc.c.
+ */
/*
* Nfs server psuedo system call for the nfsd's
@@ -163,25 +166,14 @@
* - sockaddr with no IPv4-mapped addresses
* - mask for both INET and INET6 families if there is IPv4-mapped overlap
*/
-#ifndef _SYS_SYSPROTO_H_
-struct nfssvc_args {
- int flag;
- caddr_t argp;
-};
-#endif
int
-nfssvc(struct thread *td, struct nfssvc_args *uap)
+nfssvc_nfsserver(struct thread *td, struct nfssvc_args *uap)
{
struct file *fp;
struct nfsd_addsock_args addsockarg;
struct nfsd_nfsd_args nfsdarg;
int error;
- KASSERT(!mtx_owned(&Giant), ("nfssvc(): called with Giant"));
-
- error = priv_check(td, PRIV_NFS_DAEMON);
- if (error)
- return (error);
if (uap->flag & NFSSVC_ADDSOCK) {
error = copyin(uap->argp, (caddr_t)&addsockarg,
sizeof(addsockarg));
@@ -208,8 +200,6 @@
} else {
error = ENXIO;
}
- if (error == EINTR || error == ERESTART)
- error = 0;
return (error);
}
diff -u -r -N nfsserver/nfs_srvsubs.c nfsserver.new/nfs_srvsubs.c
--- nfsserver/nfs_srvsubs.c 2009-04-02 03:55:57.000000000 -0400
+++ nfsserver.new/nfs_srvsubs.c 2009-04-02 05:34:17.000000000 -0400
@@ -100,10 +100,6 @@
int nfsd_head_flag;
#endif
-static int nfssvc_offset = SYS_nfssvc;
-static struct sysent nfssvc_prev_sysent;
-MAKE_SYSENT(nfssvc);
-
struct mtx nfsd_mtx;
/*
@@ -519,13 +515,14 @@
nfsv3err_commit,
};
+extern int (*call_nfsserver)(struct thread *, struct nfssvc_args *);
+
/*
* Called once to initialize data structures...
*/
static int
nfsrv_modevent(module_t mod, int type, void *data)
{
- static int registered;
int error = 0;
switch (type) {
@@ -560,11 +557,7 @@
NFSD_UNLOCK();
#endif
- error = syscall_register(&nfssvc_offset, &nfssvc_sysent,
- &nfssvc_prev_sysent);
- if (error)
- break;
- registered = 1;
+ call_nfsserver = nfssvc_nfsserver;
break;
case MOD_UNLOAD:
@@ -573,8 +566,7 @@
break;
}
- if (registered)
- syscall_deregister(&nfssvc_offset, &nfssvc_prev_sysent);
+ call_nfsserver = NULL;
callout_drain(&nfsrv_callout);
#ifdef NFS_LEGACYRPC
nfsrv_destroycache(); /* Free the server request cache */
@@ -596,6 +588,7 @@
/* So that loader and kldload(2) can find us, wherever we are.. */
MODULE_VERSION(nfsserver, 1);
+MODULE_DEPEND(nfsserver, nfssvc, 1, 1, 1);
#ifndef NFS_LEGACYRPC
MODULE_DEPEND(nfsserver, krpc, 1, 1, 1);
#endif
diff -u -r -N nfsserver/nfs_syscalls.c nfsserver.new/nfs_syscalls.c
--- nfsserver/nfs_syscalls.c 2009-04-02 03:55:57.000000000 -0400
+++ nfsserver.new/nfs_syscalls.c 2009-04-02 05:34:17.000000000 -0400
@@ -113,6 +113,9 @@
*/
/*
+ * This is now called from nfssvc() in nfs/nfs_nfssvc.c.
+ */
+/*
* Nfs server psuedo system call for the nfsd's
* Based on the flag value it either:
* - adds a socket to the selection list
@@ -123,27 +126,14 @@
* - sockaddr with no IPv4-mapped addresses
* - mask for both INET and INET6 families if there is IPv4-mapped overlap
*/
-#ifndef _SYS_SYSPROTO_H_
-struct nfssvc_args {
- int flag;
- caddr_t argp;
-};
-#endif
int
-nfssvc(struct thread *td, struct nfssvc_args *uap)
+nfssvc_nfsserver(struct thread *td, struct nfssvc_args *uap)
{
struct file *fp;
struct sockaddr *nam;
struct nfsd_addsock_args nfsdarg;
int error;
- KASSERT(!mtx_owned(&Giant), ("nfssvc(): called with Giant"));
-
- AUDIT_ARG(cmd, uap->flag);
-
- error = priv_check(td, PRIV_NFS_DAEMON);
- if (error)
- return (error);
NFSD_LOCK();
while (nfssvc_sockhead_flag & SLP_INIT) {
nfssvc_sockhead_flag |= SLP_WANTINIT;
@@ -181,8 +171,6 @@
} else {
error = ENXIO;
}
- if (error == EINTR || error == ERESTART)
- error = 0;
return (error);
}
diff -u -r -N nfs/nfs_nfssvc.c nfs.new/nfs_nfssvc.c
--- nfs/nfs_nfssvc.c 1969-12-31 19:00:00.000000000 -0500
+++ nfs.new/nfs_nfssvc.c 2009-04-02 05:34:47.000000000 -0400
@@ -0,0 +1,152 @@
+/*-
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+
+#include "opt_nfs.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/sysproto.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/priv.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/module.h>
+#include <sys/sysent.h>
+#include <sys/syscall.h>
+#include <sys/sysproto.h>
+
+#include <security/audit/audit.h>
+
+#include <nfs/nfssvc.h>
+
+static int nfssvc_offset = SYS_nfssvc;
+static struct sysent nfssvc_prev_sysent;
+MAKE_SYSENT(nfssvc);
+
+/*
+ * This tiny module simply handles the nfssvc() system call. The other
+ * nfs modules that use the system call register themselves by setting
+ * the call_xxx function pointers non-NULL.
+ */
+
+int (*call_nfsserver)(struct thread *, struct nfssvc_args *) = NULL;
+int (*call_nfsv4)(struct thread *, struct nfssvc_args *) = NULL;
+int (*call_nfsv4client)(struct thread *, struct nfssvc_args *) = NULL;
+int (*call_nfsv4server)(struct thread *, struct nfssvc_args *) = NULL;
+
+/*
+ * Nfs server psuedo system call for the nfsd's
+ */
+int
+nfssvc(struct thread *td, struct nfssvc_args *uap)
+{
+ int error;
+
+ KASSERT(!mtx_owned(&Giant), ("nfssvc(): called with Giant"));
+
+ AUDIT_ARG(cmd, uap->flag);
+
+ error = priv_check(td, PRIV_NFS_DAEMON);
+ if (error)
+ return (error);
+ error = EINVAL;
+ if ((uap->flag & (NFSSVC_ADDSOCK | NFSSVC_OLDNFSD | NFSSVC_NFSD)) &&
+ call_nfsserver != NULL)
+ error = (*call_nfsserver)(td, uap);
+ else if ((uap->flag & (NFSSVC_CBADDSOCK | NFSSVC_NFSCBD)) &&
+ call_nfsv4client != NULL)
+ error = (*call_nfsv4client)(td, uap);
+ else if ((uap->flag & (NFSSVC_IDNAME | NFSSVC_GETSTATS |
+ NFSSVC_GSSDADDPORT | NFSSVC_GSSDADDFIRST | NFSSVC_GSSDDELETEALL |
+ NFSSVC_NFSUSERDPORT | NFSSVC_NFSUSERDDELPORT)) &&
+ call_nfsv4 != NULL)
+ error = (*call_nfsv4)(td, uap);
+ else if ((uap->flag & (NFSSVC_NFSDNFSD | NFSSVC_NFSDADDSOCK |
+ NFSSVC_PUBLICFH | NFSSVC_V4ROOTEXPORT | NFSSVC_NOPUBLICFH |
+ NFSSVC_STABLERESTART | NFSSVC_ADMINREVOKE |
+ NFSSVC_DUMPCLIENTS | NFSSVC_DUMPLOCKS)) &&
+ call_nfsv4server != NULL)
+ error = (*call_nfsv4server)(td, uap);
+ if (error == EINTR || error == ERESTART)
+ error = 0;
+ return (error);
+}
+
+/*
+ * Called once to initialize data structures...
+ */
+static int
+nfssvc_modevent(module_t mod, int type, void *data)
+{
+ static int registered;
+ int error = 0;
+
+ switch (type) {
+ case MOD_LOAD:
+ error = syscall_register(&nfssvc_offset, &nfssvc_sysent,
+ &nfssvc_prev_sysent);
+ if (error)
+ break;
+ registered = 1;
+ break;
+
+ case MOD_UNLOAD:
+ if (call_nfsserver != NULL || call_nfsv4 != NULL ||
+ call_nfsv4client != NULL || call_nfsv4server != NULL) {
+ error = EBUSY;
+ break;
+ }
+ if (registered)
+ syscall_deregister(&nfssvc_offset, &nfssvc_prev_sysent);
+ registered = 0;
+ break;
+ default:
+ error = EOPNOTSUPP;
+ break;
+ }
+ return error;
+}
+static moduledata_t nfssvc_mod = {
+ "nfssvc",
+ nfssvc_modevent,
+ NULL,
+};
+DECLARE_MODULE(nfssvc, nfssvc_mod, SI_SUB_VFS, SI_ORDER_ANY);
+
+/* So that loader and kldload(2) can find us, wherever we are.. */
+MODULE_VERSION(nfssvc, 1);
+
diff -u -r -N nfs/nfssvc.h nfs.new/nfssvc.h
--- nfs/nfssvc.h 1969-12-31 19:00:00.000000000 -0500
+++ nfs.new/nfssvc.h 2009-04-02 05:34:47.000000000 -0400
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#ifndef _NFS_NFSSVC_H_
+#define _NFS_NFSSVC_H_
+
+/*
+ * Flags for nfssvc() system call.
+ */
+#define NFSSVC_OLDNFSD 0x004
+#define NFSSVC_ADDSOCK 0x008
+#define NFSSVC_NFSD 0x010
+
+/*
+ * and ones for nfsv4.
+ */
+#define NFSSVC_NOPUBLICFH 0x00000020
+#define NFSSVC_STABLERESTART 0x00000040
+#define NFSSVC_NFSDNFSD 0x00000080
+#define NFSSVC_NFSDADDSOCK 0x00000100
+#define NFSSVC_IDNAME 0x00000200
+#define NFSSVC_GSSDDELETEALL 0x00000400
+#define NFSSVC_GSSDADDPORT 0x00000800
+#define NFSSVC_NFSUSERDPORT 0x00001000
+#define NFSSVC_NFSUSERDDELPORT 0x00002000
+#define NFSSVC_V4ROOTEXPORT 0x00004000
+#define NFSSVC_ADMINREVOKE 0x00008000
+#define NFSSVC_DUMPCLIENTS 0x00010000
+#define NFSSVC_DUMPLOCKS 0x00020000
+#define NFSSVC_GSSDADDFIRST 0x00040000
+#define NFSSVC_PUBLICFH 0x00080000
+#define NFSSVC_NFSCBD 0x00100000
+#define NFSSVC_CBADDSOCK 0x00200000
+#define NFSSVC_GETSTATS 0x00400000
+
+#endif /* _NFS_NFSSVC_H */
More information about the freebsd-fs
mailing list