From 45452edc37e1091704ba5e47029652e7b61e2923 Mon Sep 17 00:00:00 2001 From: Rick Macklem Date: Sun, 12 Apr 2009 19:04:27 +0000 Subject: [PATCH] Change nfsserver so that it uses the nfssvc() system call provided in sys/nfs/nfs_nfssvc.c by registering with it using the nfsd_call_nfsserver function pointer. Also, add the build glue for nfs_nfssvc.c optionally based on "nfsserver" and also as a loadable module. Submitted by: rmacklem Reviewed by: kib Approved by: kib (mentor) --- sys/conf/files | 1 + sys/modules/Makefile | 1 + sys/modules/nfssvc/Makefile | 9 +++++++++ sys/nfsserver/nfs.h | 16 +++++++++------- sys/nfsserver/nfs_srvkrpc.c | 18 ++++-------------- sys/nfsserver/nfs_srvsubs.c | 17 +++++------------ sys/nfsserver/nfs_syscalls.c | 20 ++++---------------- 7 files changed, 33 insertions(+), 49 deletions(-) create mode 100644 sys/modules/nfssvc/Makefile diff --git a/sys/conf/files b/sys/conf/files index e2fe0f099862..b7d30e0b00d8 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2469,6 +2469,7 @@ nfsserver/nfs_srvsock.c optional nfsserver nfsserver/nfs_srvcache.c optional nfsserver nfsserver/nfs_srvsubs.c optional nfsserver nfsserver/nfs_syscalls.c optional nfsserver +nfs/nfs_nfssvc.c optional nfsserver nlm/nlm_advlock.c optional nfslockd nfsclient nlm/nlm_prot_clnt.c optional nfslockd nlm/nlm_prot_impl.c optional nfslockd diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 4329717bce68..969f70428c73 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -187,6 +187,7 @@ SUBDIR= ${_3dfx} \ nfsclient \ nfslockd \ nfsserver \ + nfssvc \ nge \ nmdm \ ${_nsp} \ diff --git a/sys/modules/nfssvc/Makefile b/sys/modules/nfssvc/Makefile new file mode 100644 index 000000000000..0073d1300393 --- /dev/null +++ b/sys/modules/nfssvc/Makefile @@ -0,0 +1,9 @@ + +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../nfs +KMOD= nfssvc +SRCS= nfs_nfssvc.c \ + opt_nfs.h + +.include diff --git a/sys/nfsserver/nfs.h b/sys/nfsserver/nfs.h index 27093777aea4..b47ffea89340 100644 --- a/sys/nfsserver/nfs.h +++ b/sys/nfsserver/nfs.h @@ -40,6 +40,8 @@ #include "opt_nfs.h" #endif +#include + /* * Tunable constants for nfs */ @@ -115,13 +117,6 @@ struct nfsd_nfsd_args { #include #endif -/* - * Flags for nfssvc() system call. - */ -#define NFSSVC_OLDNFSD 0x004 -#define NFSSVC_ADDSOCK 0x008 -#define NFSSVC_NFSD 0x010 - /* * vfs.nfsrv sysctl(3) identifiers */ @@ -447,6 +442,13 @@ int nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 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 --git a/sys/nfsserver/nfs_srvkrpc.c b/sys/nfsserver/nfs_srvkrpc.c index c6896fff0259..77bdec85c62e 100644 --- a/sys/nfsserver/nfs_srvkrpc.c +++ b/sys/nfsserver/nfs_srvkrpc.c @@ -151,6 +151,9 @@ int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd, /* * 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 @@ int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd, * - 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 @@ nfssvc(struct thread *td, struct nfssvc_args *uap) } else { error = ENXIO; } - if (error == EINTR || error == ERESTART) - error = 0; return (error); } diff --git a/sys/nfsserver/nfs_srvsubs.c b/sys/nfsserver/nfs_srvsubs.c index 00e52166ebbf..d1544639a14d 100644 --- a/sys/nfsserver/nfs_srvsubs.c +++ b/sys/nfsserver/nfs_srvsubs.c @@ -100,10 +100,6 @@ struct nfsd_head nfsd_head; 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 @@ static const short *nfsrv_v3errmap[] = { nfsv3err_commit, }; +extern int (*nfsd_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 @@ nfsrv_modevent(module_t mod, int type, void *data) NFSD_UNLOCK(); #endif - error = syscall_register(&nfssvc_offset, &nfssvc_sysent, - &nfssvc_prev_sysent); - if (error) - break; - registered = 1; + nfsd_call_nfsserver = nfssvc_nfsserver; break; case MOD_UNLOAD: @@ -573,8 +566,7 @@ nfsrv_modevent(module_t mod, int type, void *data) break; } - if (registered) - syscall_deregister(&nfssvc_offset, &nfssvc_prev_sysent); + nfsd_call_nfsserver = NULL; callout_drain(&nfsrv_callout); #ifdef NFS_LEGACYRPC nfsrv_destroycache(); /* Free the server request cache */ @@ -596,6 +588,7 @@ DECLARE_MODULE(nfsserver, nfsserver_mod, SI_SUB_VFS, SI_ORDER_ANY); /* 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 --git a/sys/nfsserver/nfs_syscalls.c b/sys/nfsserver/nfs_syscalls.c index 326d623e92be..59a30a3b0a7a 100644 --- a/sys/nfsserver/nfs_syscalls.c +++ b/sys/nfsserver/nfs_syscalls.c @@ -112,6 +112,9 @@ extern u_long sb_max_adj; * NFS server system calls */ +/* + * 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: @@ -123,27 +126,14 @@ extern u_long sb_max_adj; * - 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 @@ nfssvc(struct thread *td, struct nfssvc_args *uap) } else { error = ENXIO; } - if (error == EINTR || error == ERESTART) - error = 0; return (error); }