[Midnightbsd-cvs] src [9792] trunk/sys: nfs changes

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Feb 24 14:32:05 EST 2018


Revision: 9792
          http://svnweb.midnightbsd.org/src/?rev=9792
Author:   laffer1
Date:     2018-02-24 14:32:04 -0500 (Sat, 24 Feb 2018)
Log Message:
-----------
nfs changes

Modified Paths:
--------------
    trunk/sys/conf/files
    trunk/sys/fs/nfs/nfs_commonkrpc.c
    trunk/sys/fs/nfs/nfs_commonport.c
    trunk/sys/fs/nfs/nfs_commonsubs.c
    trunk/sys/fs/nfs/nfs_var.h
    trunk/sys/fs/nfs/nfsm_subs.h
    trunk/sys/fs/nfs/nfsport.h
    trunk/sys/fs/nfsclient/nfs_clkrpc.c
    trunk/sys/fs/nfsserver/nfs_nfsdkrpc.c
    trunk/sys/fs/nfsserver/nfs_nfsdport.c
    trunk/sys/fs/nfsserver/nfs_nfsdsocket.c
    trunk/sys/modules/nfsd/Makefile
    trunk/sys/modules/nfsserver/Makefile

Added Paths:
-----------
    trunk/sys/fs/nfsserver/nfs_fha_new.c
    trunk/sys/fs/nfsserver/nfs_fha_new.h

Modified: trunk/sys/conf/files
===================================================================
--- trunk/sys/conf/files	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/conf/files	2018-02-24 19:32:04 UTC (rev 9792)
@@ -2183,6 +2183,7 @@
 fs/nfsclient/nfs_clport.c	optional nfscl
 fs/nfsclient/nfs_clbio.c	optional nfscl
 fs/nfsclient/nfs_clnfsiod.c	optional nfscl
+fs/nfsserver/nfs_fha_new.c	optional nfsd inet
 fs/nfsserver/nfs_nfsdsocket.c	optional nfsd inet
 fs/nfsserver/nfs_nfsdsubs.c	optional nfsd inet
 fs/nfsserver/nfs_nfsdstate.c	optional nfsd inet
@@ -3002,6 +3003,7 @@
 nfs/krpc_subr.c			optional bootp nfsclient | bootp nfscl
 nfs/nfs_common.c		optional nfsclient | nfsserver
 nfs/nfs_diskless.c		optional nfsclient nfs_root | nfscl nfs_root
+nfs/nfs_fha.c			optional nfsserver | nfsd
 nfs/nfs_lock.c			optional nfsclient | nfscl | nfslockd | nfsd
 nfsclient/nfs_bio.c		optional nfsclient
 nfsclient/nfs_node.c		optional nfsclient
@@ -3010,7 +3012,7 @@
 nfsclient/nfs_nfsiod.c		optional nfsclient
 nfsclient/nfs_vfsops.c		optional nfsclient
 nfsclient/nfs_vnops.c		optional nfsclient
-nfsserver/nfs_fha.c		optional nfsserver
+nfsserver/nfs_fha_old.c		optional nfsserver
 nfsserver/nfs_serv.c		optional nfsserver
 nfsserver/nfs_srvkrpc.c		optional nfsserver
 nfsserver/nfs_srvsubs.c		optional nfsserver

Modified: trunk/sys/fs/nfs/nfs_commonkrpc.c
===================================================================
--- trunk/sys/fs/nfs/nfs_commonkrpc.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfs/nfs_commonkrpc.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -771,7 +771,7 @@
 	 * These could cause pointer alignment problems, so copy them to
 	 * well aligned mbufs.
 	 */
-	newnfs_realign(&nd->nd_mrep);
+	newnfs_realign(&nd->nd_mrep, M_WAITOK);
 	nd->nd_md = nd->nd_mrep;
 	nd->nd_dpos = NFSMTOD(nd->nd_md, caddr_t);
 	nd->nd_repstat = 0;

Modified: trunk/sys/fs/nfs/nfs_commonport.c
===================================================================
--- trunk/sys/fs/nfs/nfs_commonport.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfs/nfs_commonport.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -126,11 +126,11 @@
 /*
  * These architectures don't need re-alignment, so just return.
  */
-void
-newnfs_realign(struct mbuf **pm)
+int
+newnfs_realign(struct mbuf **pm, int how)
 {
 
-	return;
+	return (0);
 }
 #else	/* !__NO_STRICT_ALIGNMENT */
 /*
@@ -149,8 +149,8 @@
  *	with TCP.  Use vfs.nfs.realign_count and realign_test to check this.
  *
  */
-void
-newnfs_realign(struct mbuf **pm)
+int
+newnfs_realign(struct mbuf **pm, int how)
 {
 	struct mbuf *m, *n;
 	int off, space;
@@ -167,11 +167,11 @@
 			space = m_length(m, NULL);
 			if (space >= MINCLSIZE) {
 				/* NB: m_copyback handles space > MCLBYTES */
-				n = m_getcl(M_WAITOK, MT_DATA, 0);
+				n = m_getcl(how, MT_DATA, 0);
 			} else
-				n = m_get(M_WAITOK, MT_DATA);
+				n = m_get(how, MT_DATA);
 			if (n == NULL)
-				return;
+				return (ENOMEM);
 			/*
 			 * Align the remainder of the mbuf chain.
 			 */
@@ -189,6 +189,8 @@
 		}
 		pm = &m->m_next;
 	}
+
+	return (0);
 }
 #endif	/* __NO_STRICT_ALIGNMENT */
 

Modified: trunk/sys/fs/nfs/nfs_commonsubs.c
===================================================================
--- trunk/sys/fs/nfs/nfs_commonsubs.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfs/nfs_commonsubs.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -252,7 +252,7 @@
  * cases.
  */
 APPLESTATIC void *
-nfsm_dissct(struct nfsrv_descript *nd, int siz)
+nfsm_dissct(struct nfsrv_descript *nd, int siz, int how)
 {
 	mbuf_t mp2;
 	int siz2, xfer;
@@ -277,7 +277,9 @@
 	} else if (siz > ncl_mbuf_mhlen) {
 		panic("nfs S too big");
 	} else {
-		NFSMGET(mp2);
+		MGET(mp2, MT_DATA, how);
+		if (mp2 == NULL)
+			return (NULL);
 		mbuf_setnext(mp2, mbuf_next(nd->nd_md));
 		mbuf_setnext(nd->nd_md, mp2);
 		mbuf_setlen(nd->nd_md, mbuf_len(nd->nd_md) - left);

Modified: trunk/sys/fs/nfs/nfs_var.h
===================================================================
--- trunk/sys/fs/nfs/nfs_var.h	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfs/nfs_var.h	2018-02-24 19:32:04 UTC (rev 9792)
@@ -232,7 +232,7 @@
 int nfsm_mbufuio(struct nfsrv_descript *, struct uio *, int);
 int nfsm_fhtom(struct nfsrv_descript *, u_int8_t *, int, int);
 int nfsm_advance(struct nfsrv_descript *, int, int);
-void *nfsm_dissct(struct nfsrv_descript *, int);
+void *nfsm_dissct(struct nfsrv_descript *, int, int);
 void newnfs_trimleading(struct nfsrv_descript *);
 void newnfs_trimtrailing(struct nfsrv_descript *, mbuf_t,
     caddr_t);

Modified: trunk/sys/fs/nfs/nfsm_subs.h
===================================================================
--- trunk/sys/fs/nfs/nfsm_subs.h	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfs/nfsm_subs.h	2018-02-24 19:32:04 UTC (rev 9792)
@@ -100,11 +100,27 @@
 		retp = (void *)nd->nd_dpos; 
 		nd->nd_dpos += siz; 
 	} else { 
-		retp = nfsm_dissct(nd, siz); 
+		retp = nfsm_dissct(nd, siz, M_WAITOK); 
 	}
 	return (retp);
 }
 
+static __inline void *
+nfsm_dissect_nonblock(struct nfsrv_descript *nd, int siz)
+{
+	int tt1; 
+	void *retp;
+
+	tt1 = NFSMTOD(nd->nd_md, caddr_t) + nd->nd_md->m_len - nd->nd_dpos; 
+	if (tt1 >= siz) { 
+		retp = (void *)nd->nd_dpos; 
+		nd->nd_dpos += siz; 
+	} else { 
+		retp = nfsm_dissct(nd, siz, M_NOWAIT); 
+	}
+	return (retp);
+}
+
 #define	NFSM_DISSECT(a, c, s) 						\
 	do {								\
 		(a) = (c)nfsm_dissect(nd, (s));	 			\
@@ -113,6 +129,15 @@
 			goto nfsmout; 					\
 		}							\
 	} while (0)
+
+#define	NFSM_DISSECT_NONBLOCK(a, c, s) 					\
+	do {								\
+		(a) = (c)nfsm_dissect_nonblock(nd, (s));		\
+		if ((a) == NULL) { 					\
+			error = EBADRPC; 				\
+			goto nfsmout; 					\
+		}							\
+	} while (0)
 #endif	/* !APPLE */
 
 #define	NFSM_STRSIZ(s, m)  						\

Modified: trunk/sys/fs/nfs/nfsport.h
===================================================================
--- trunk/sys/fs/nfs/nfsport.h	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfs/nfsport.h	2018-02-24 19:32:04 UTC (rev 9792)
@@ -730,7 +730,7 @@
  */
 int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
     int, int);
-void newnfs_realign(struct mbuf **);
+int newnfs_realign(struct mbuf **, int);
 
 /*
  * If the port runs on an SMP box that can enforce Atomic ops with low

Modified: trunk/sys/fs/nfsclient/nfs_clkrpc.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clkrpc.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfsclient/nfs_clkrpc.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -82,7 +82,7 @@
 	 */
 	nd.nd_mrep = rqst->rq_args;
 	rqst->rq_args = NULL;
-	newnfs_realign(&nd.nd_mrep);
+	newnfs_realign(&nd.nd_mrep, M_WAITOK);
 	nd.nd_md = nd.nd_mrep;
 	nd.nd_dpos = mtod(nd.nd_md, caddr_t);
 	nd.nd_nam = svc_getrpccaller(rqst);

Added: trunk/sys/fs/nfsserver/nfs_fha_new.c
===================================================================
--- trunk/sys/fs/nfsserver/nfs_fha_new.c	                        (rev 0)
+++ trunk/sys/fs/nfsserver/nfs_fha_new.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -0,0 +1,545 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Copyright (c) 2013 Spectra Logic Corporation
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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>
+__FBSDID("$FreeBSD$");
+
+#include <fs/nfs/nfsport.h>
+
+#include <rpc/rpc.h>
+#include <nfs/nfs_fha.h>
+#include <fs/nfs/xdr_subs.h>
+#include <fs/nfs/nfs.h>
+#include <fs/nfs/nfsproto.h>
+#include <fs/nfs/nfsm_subs.h>
+#include <fs/nfsserver/nfs_fha_new.h>
+
+static void fhanew_init(void *foo);
+static void fhanew_uninit(void *foo);
+rpcproc_t fhanew_get_procnum(rpcproc_t procnum);
+int fhanew_realign(struct mbuf **mb, int malloc_flags);
+int fhanew_get_fh(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
+int fhanew_is_read(rpcproc_t procnum);
+int fhanew_is_write(rpcproc_t procnum);
+int fhanew_get_offset(struct mbuf **md, caddr_t *dpos, int v3,
+		      struct fha_info *info);
+int fhanew_no_offset(rpcproc_t procnum);
+void fhanew_set_locktype(rpcproc_t procnum, struct fha_info *info);
+static int fhenew_stats_sysctl(SYSCTL_HANDLER_ARGS);
+
+static struct fha_params fhanew_softc;
+
+SYSCTL_DECL(_vfs_nfsd);
+
+extern int newnfs_nfsv3_procid[];
+extern SVCPOOL	*nfsrvd_pool;
+
+SYSINIT(nfs_fhanew, SI_SUB_ROOT_CONF, SI_ORDER_ANY, fhanew_init, NULL);
+SYSUNINIT(nfs_fhanew, SI_SUB_ROOT_CONF, SI_ORDER_ANY, fhanew_uninit, NULL);
+
+static void
+fhanew_init(void *foo)
+{
+	struct fha_params *softc;
+
+	softc = &fhanew_softc;
+
+	bzero(softc, sizeof(*softc));
+
+	/*
+	 * Setup the callbacks for this FHA personality.
+	 */
+	softc->callbacks.get_procnum = fhanew_get_procnum;
+	softc->callbacks.realign = fhanew_realign;
+	softc->callbacks.get_fh = fhanew_get_fh;
+	softc->callbacks.is_read = fhanew_is_read;
+	softc->callbacks.is_write = fhanew_is_write;
+	softc->callbacks.get_offset = fhanew_get_offset;
+	softc->callbacks.no_offset = fhanew_no_offset;
+	softc->callbacks.set_locktype = fhanew_set_locktype;
+	softc->callbacks.fhe_stats_sysctl = fhenew_stats_sysctl;
+
+	snprintf(softc->server_name, sizeof(softc->server_name),
+	    FHANEW_SERVER_NAME);
+
+	softc->pool = &nfsrvd_pool;
+
+	/*
+	 * Initialize the sysctl context list for the fha module.
+	 */
+	sysctl_ctx_init(&softc->sysctl_ctx);
+	softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
+	    SYSCTL_STATIC_CHILDREN(_vfs_nfsd), OID_AUTO, "fha", CTLFLAG_RD,
+	    0, "fha node");
+	if (softc->sysctl_tree == NULL) {
+		printf("%s: unable to allocate sysctl tree\n", __func__);
+		return;
+	}
+
+	fha_init(softc);
+}
+
+static void
+fhanew_uninit(void *foo)
+{
+	struct fha_params *softc;
+
+	softc = &fhanew_softc;
+
+	fha_uninit(softc);
+}
+
+rpcproc_t
+fhanew_get_procnum(rpcproc_t procnum)
+{
+	if (procnum > NFSV2PROC_STATFS)
+		return (-1);
+
+	return (newnfs_nfsv3_procid[procnum]);
+}
+
+int
+fhanew_realign(struct mbuf **mb, int malloc_flags)
+{
+	return (newnfs_realign(mb, malloc_flags));
+}
+
+int
+fhanew_get_fh(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos)
+{
+	struct nfsrv_descript lnd, *nd;
+	uint32_t *tl;
+	int error, len;
+
+	error = 0;
+	len = 0;
+	nd = &lnd;
+
+	nd->nd_md = *md;
+	nd->nd_dpos = *dpos;
+
+	if (v3) {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, NFSX_UNSIGNED);
+		if ((len = fxdr_unsigned(int, *tl)) <= 0 || len > NFSX_FHMAX) {
+			error = EBADRPC;
+			goto nfsmout;
+		}
+	} else {
+		len = NFSX_V2FH;
+	}
+
+	if (len != 0) {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, len);
+		bcopy(tl, fh, len);
+	} else
+		bzero(fh, sizeof(*fh));
+
+nfsmout:
+	*md = nd->nd_md;
+	*dpos = nd->nd_dpos;
+
+	return (error);
+}
+
+int
+fhanew_is_read(rpcproc_t procnum)
+{
+	if (procnum == NFSPROC_READ)
+		return (1);
+	else
+		return (0);
+}
+
+int
+fhanew_is_write(rpcproc_t procnum)
+{
+	if (procnum == NFSPROC_WRITE)
+		return (1);
+	else
+		return (0);
+}
+
+int
+fhanew_get_offset(struct mbuf **md, caddr_t *dpos, int v3,
+		  struct fha_info *info)
+{
+	struct nfsrv_descript lnd, *nd;
+	uint32_t *tl;
+	int error;
+
+	error = 0;
+
+	nd = &lnd;
+	nd->nd_md = *md;
+	nd->nd_dpos = *dpos;
+
+	if (v3) {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, 2 * NFSX_UNSIGNED);
+		info->offset = fxdr_hyper(tl);
+	} else {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, NFSX_UNSIGNED);
+		info->offset = fxdr_unsigned(uint32_t, *tl);
+	}
+
+nfsmout:
+	*md = nd->nd_md;
+	*dpos = nd->nd_dpos;
+
+	return (error);
+}
+
+int
+fhanew_no_offset(rpcproc_t procnum)
+{
+	if (procnum == NFSPROC_FSSTAT ||
+	    procnum == NFSPROC_FSINFO ||
+	    procnum == NFSPROC_PATHCONF ||
+	    procnum == NFSPROC_NOOP ||
+	    procnum == NFSPROC_NULL)
+		return (1);
+	else
+		return (0);
+}
+
+void
+fhanew_set_locktype(rpcproc_t procnum, struct fha_info *info)
+{
+	switch (procnum) {
+	case NFSPROC_NULL:
+	case NFSPROC_GETATTR:
+	case NFSPROC_LOOKUP:
+	case NFSPROC_ACCESS:
+	case NFSPROC_READLINK:
+	case NFSPROC_READ:
+	case NFSPROC_READDIR:
+	case NFSPROC_READDIRPLUS:
+	case NFSPROC_WRITE:
+		info->locktype = LK_SHARED;
+		break;
+	case NFSPROC_SETATTR:
+	case NFSPROC_CREATE:
+	case NFSPROC_MKDIR:
+	case NFSPROC_SYMLINK:
+	case NFSPROC_MKNOD:
+	case NFSPROC_REMOVE:
+	case NFSPROC_RMDIR:
+	case NFSPROC_RENAME:
+	case NFSPROC_LINK:
+	case NFSPROC_FSSTAT:
+	case NFSPROC_FSINFO:
+	case NFSPROC_PATHCONF:
+	case NFSPROC_COMMIT:
+	case NFSPROC_NOOP:
+		info->locktype = LK_EXCLUSIVE;
+		break;
+	}
+}
+
+static int
+fhenew_stats_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	return (fhe_stats_sysctl(oidp, arg1, arg2, req, &fhanew_softc));
+}
+
+
+SVCTHREAD *
+fhanew_assign(SVCTHREAD *this_thread, struct svc_req *req)
+{
+	return (fha_assign(this_thread, req, &fhanew_softc));
+}
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Copyright (c) 2013 Spectra Logic Corporation
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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>
+__FBSDID("$FreeBSD$");
+
+#include <fs/nfs/nfsport.h>
+
+#include <rpc/rpc.h>
+#include <nfs/nfs_fha.h>
+#include <fs/nfs/xdr_subs.h>
+#include <fs/nfs/nfs.h>
+#include <fs/nfs/nfsproto.h>
+#include <fs/nfs/nfsm_subs.h>
+#include <fs/nfsserver/nfs_fha_new.h>
+
+static void fhanew_init(void *foo);
+static void fhanew_uninit(void *foo);
+rpcproc_t fhanew_get_procnum(rpcproc_t procnum);
+int fhanew_realign(struct mbuf **mb, int malloc_flags);
+int fhanew_get_fh(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
+int fhanew_is_read(rpcproc_t procnum);
+int fhanew_is_write(rpcproc_t procnum);
+int fhanew_get_offset(struct mbuf **md, caddr_t *dpos, int v3,
+		      struct fha_info *info);
+int fhanew_no_offset(rpcproc_t procnum);
+void fhanew_set_locktype(rpcproc_t procnum, struct fha_info *info);
+static int fhenew_stats_sysctl(SYSCTL_HANDLER_ARGS);
+
+static struct fha_params fhanew_softc;
+
+SYSCTL_DECL(_vfs_nfsd);
+
+extern int newnfs_nfsv3_procid[];
+extern SVCPOOL	*nfsrvd_pool;
+
+SYSINIT(nfs_fhanew, SI_SUB_ROOT_CONF, SI_ORDER_ANY, fhanew_init, NULL);
+SYSUNINIT(nfs_fhanew, SI_SUB_ROOT_CONF, SI_ORDER_ANY, fhanew_uninit, NULL);
+
+static void
+fhanew_init(void *foo)
+{
+	struct fha_params *softc;
+
+	softc = &fhanew_softc;
+
+	bzero(softc, sizeof(*softc));
+
+	/*
+	 * Setup the callbacks for this FHA personality.
+	 */
+	softc->callbacks.get_procnum = fhanew_get_procnum;
+	softc->callbacks.realign = fhanew_realign;
+	softc->callbacks.get_fh = fhanew_get_fh;
+	softc->callbacks.is_read = fhanew_is_read;
+	softc->callbacks.is_write = fhanew_is_write;
+	softc->callbacks.get_offset = fhanew_get_offset;
+	softc->callbacks.no_offset = fhanew_no_offset;
+	softc->callbacks.set_locktype = fhanew_set_locktype;
+	softc->callbacks.fhe_stats_sysctl = fhenew_stats_sysctl;
+
+	snprintf(softc->server_name, sizeof(softc->server_name),
+	    FHANEW_SERVER_NAME);
+
+	softc->pool = &nfsrvd_pool;
+
+	/*
+	 * Initialize the sysctl context list for the fha module.
+	 */
+	sysctl_ctx_init(&softc->sysctl_ctx);
+	softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
+	    SYSCTL_STATIC_CHILDREN(_vfs_nfsd), OID_AUTO, "fha", CTLFLAG_RD,
+	    0, "fha node");
+	if (softc->sysctl_tree == NULL) {
+		printf("%s: unable to allocate sysctl tree\n", __func__);
+		return;
+	}
+
+	fha_init(softc);
+}
+
+static void
+fhanew_uninit(void *foo)
+{
+	struct fha_params *softc;
+
+	softc = &fhanew_softc;
+
+	fha_uninit(softc);
+}
+
+rpcproc_t
+fhanew_get_procnum(rpcproc_t procnum)
+{
+	if (procnum > NFSV2PROC_STATFS)
+		return (-1);
+
+	return (newnfs_nfsv3_procid[procnum]);
+}
+
+int
+fhanew_realign(struct mbuf **mb, int malloc_flags)
+{
+	return (newnfs_realign(mb, malloc_flags));
+}
+
+int
+fhanew_get_fh(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos)
+{
+	struct nfsrv_descript lnd, *nd;
+	uint32_t *tl;
+	int error, len;
+
+	error = 0;
+	len = 0;
+	nd = &lnd;
+
+	nd->nd_md = *md;
+	nd->nd_dpos = *dpos;
+
+	if (v3) {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, NFSX_UNSIGNED);
+		if ((len = fxdr_unsigned(int, *tl)) <= 0 || len > NFSX_FHMAX) {
+			error = EBADRPC;
+			goto nfsmout;
+		}
+	} else {
+		len = NFSX_V2FH;
+	}
+
+	if (len != 0) {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, len);
+		bcopy(tl, fh, len);
+	} else
+		bzero(fh, sizeof(*fh));
+
+nfsmout:
+	*md = nd->nd_md;
+	*dpos = nd->nd_dpos;
+
+	return (error);
+}
+
+int
+fhanew_is_read(rpcproc_t procnum)
+{
+	if (procnum == NFSPROC_READ)
+		return (1);
+	else
+		return (0);
+}
+
+int
+fhanew_is_write(rpcproc_t procnum)
+{
+	if (procnum == NFSPROC_WRITE)
+		return (1);
+	else
+		return (0);
+}
+
+int
+fhanew_get_offset(struct mbuf **md, caddr_t *dpos, int v3,
+		  struct fha_info *info)
+{
+	struct nfsrv_descript lnd, *nd;
+	uint32_t *tl;
+	int error;
+
+	error = 0;
+
+	nd = &lnd;
+	nd->nd_md = *md;
+	nd->nd_dpos = *dpos;
+
+	if (v3) {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, 2 * NFSX_UNSIGNED);
+		info->offset = fxdr_hyper(tl);
+	} else {
+		NFSM_DISSECT_NONBLOCK(tl, uint32_t *, NFSX_UNSIGNED);
+		info->offset = fxdr_unsigned(uint32_t, *tl);
+	}
+
+nfsmout:
+	*md = nd->nd_md;
+	*dpos = nd->nd_dpos;
+
+	return (error);
+}
+
+int
+fhanew_no_offset(rpcproc_t procnum)
+{
+	if (procnum == NFSPROC_FSSTAT ||
+	    procnum == NFSPROC_FSINFO ||
+	    procnum == NFSPROC_PATHCONF ||
+	    procnum == NFSPROC_NOOP ||
+	    procnum == NFSPROC_NULL)
+		return (1);
+	else
+		return (0);
+}
+
+void
+fhanew_set_locktype(rpcproc_t procnum, struct fha_info *info)
+{
+	switch (procnum) {
+	case NFSPROC_NULL:
+	case NFSPROC_GETATTR:
+	case NFSPROC_LOOKUP:
+	case NFSPROC_ACCESS:
+	case NFSPROC_READLINK:
+	case NFSPROC_READ:
+	case NFSPROC_READDIR:
+	case NFSPROC_READDIRPLUS:
+	case NFSPROC_WRITE:
+		info->locktype = LK_SHARED;
+		break;
+	case NFSPROC_SETATTR:
+	case NFSPROC_CREATE:
+	case NFSPROC_MKDIR:
+	case NFSPROC_SYMLINK:
+	case NFSPROC_MKNOD:
+	case NFSPROC_REMOVE:
+	case NFSPROC_RMDIR:
+	case NFSPROC_RENAME:
+	case NFSPROC_LINK:
+	case NFSPROC_FSSTAT:
+	case NFSPROC_FSINFO:
+	case NFSPROC_PATHCONF:
+	case NFSPROC_COMMIT:
+	case NFSPROC_NOOP:
+		info->locktype = LK_EXCLUSIVE;
+		break;
+	}
+}
+
+static int
+fhenew_stats_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	return (fhe_stats_sysctl(oidp, arg1, arg2, req, &fhanew_softc));
+}
+
+
+SVCTHREAD *
+fhanew_assign(SVCTHREAD *this_thread, struct svc_req *req)
+{
+	return (fha_assign(this_thread, req, &fhanew_softc));
+}


Property changes on: trunk/sys/fs/nfsserver/nfs_fha_new.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/fs/nfsserver/nfs_fha_new.h
===================================================================
--- trunk/sys/fs/nfsserver/nfs_fha_new.h	                        (rev 0)
+++ trunk/sys/fs/nfsserver/nfs_fha_new.h	2018-02-24 19:32:04 UTC (rev 9792)
@@ -0,0 +1,79 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Copyright (c) 2013 Spectra Logic Corporation
+ *
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+/* $FreeBSD$ */
+
+#ifndef	_NFS_FHA_NEW_H
+#define	_NFS_FHA_NEW_H 1
+
+#ifdef	_KERNEL
+
+#define	FHANEW_SERVER_NAME	"nfsd"
+
+SVCTHREAD *fhanew_assign(SVCTHREAD *this_thread, struct svc_req *req);
+#endif /* _KERNEL */
+
+#endif /* _NFS_FHA_NEW_H */
+/*-
+ * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
+ * Copyright (c) 2013 Spectra Logic Corporation
+ *
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+/* $FreeBSD$ */
+
+#ifndef	_NFS_FHA_NEW_H
+#define	_NFS_FHA_NEW_H 1
+
+#ifdef	_KERNEL
+
+#define	FHANEW_SERVER_NAME	"nfsd"
+
+SVCTHREAD *fhanew_assign(SVCTHREAD *this_thread, struct svc_req *req);
+#endif /* _KERNEL */
+
+#endif /* _NFS_FHA_NEW_H */


Property changes on: trunk/sys/fs/nfsserver/nfs_fha_new.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/fs/nfsserver/nfs_nfsdkrpc.c
===================================================================
--- trunk/sys/fs/nfsserver/nfs_nfsdkrpc.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfsserver/nfs_nfsdkrpc.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -42,6 +42,9 @@
 #include <rpc/rpc.h>
 #include <rpc/rpcsec_gss.h>
 
+#include <nfs/nfs_fha.h>
+#include <fs/nfsserver/nfs_fha_new.h>
+
 #include <security/mac/mac_framework.h>
 
 NFSDLOCKMUTEX;
@@ -51,7 +54,7 @@
 /*
  * Mapping of old NFS Version 2 RPC numbers to generic numbers.
  */
-static int newnfs_nfsv3_procid[NFS_V3NPROCS] = {
+int newnfs_nfsv3_procid[NFS_V3NPROCS] = {
 	NFSPROC_NULL,
 	NFSPROC_GETATTR,
 	NFSPROC_SETATTR,
@@ -147,7 +150,7 @@
 	 */
 	nd.nd_mrep = rqst->rq_args;
 	rqst->rq_args = NULL;
-	newnfs_realign(&nd.nd_mrep);
+	newnfs_realign(&nd.nd_mrep, M_WAITOK);
 	nd.nd_md = nd.nd_mrep;
 	nd.nd_dpos = mtod(nd.nd_md, caddr_t);
 	nd.nd_nam = svc_getrpccaller(rqst);
@@ -491,8 +494,8 @@
 
 	nfsrvd_pool = svcpool_create("nfsd", SYSCTL_STATIC_CHILDREN(_vfs_nfsd));
 	nfsrvd_pool->sp_rcache = NULL;
-	nfsrvd_pool->sp_assign = NULL;
-	nfsrvd_pool->sp_done = NULL;
+	nfsrvd_pool->sp_assign = fhanew_assign;
+	nfsrvd_pool->sp_done = fha_nd_complete;
 
 	NFSD_LOCK();
 }

Modified: trunk/sys/fs/nfsserver/nfs_nfsdport.c
===================================================================
--- trunk/sys/fs/nfsserver/nfs_nfsdport.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfsserver/nfs_nfsdport.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -2707,9 +2707,11 @@
 		goto out;
 	}
 
-	if (startwrite)
+	if (startwrite) {
 		vn_start_write(NULL, mpp, V_WAIT);
-
+		if (lktype == LK_SHARED && !(MNT_SHARED_WRITES(mp)))
+			lktype = LK_EXCLUSIVE;
+	}
 	nd->nd_repstat = nfsvno_fhtovp(mp, fhp, nd->nd_nam, lktype, vpp, exp,
 	    &credanon);
 	vfs_unbusy(mp);

Modified: trunk/sys/fs/nfsserver/nfs_nfsdsocket.c
===================================================================
--- trunk/sys/fs/nfsserver/nfs_nfsdsocket.c	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/fs/nfsserver/nfs_nfsdsocket.c	2018-02-24 19:32:04 UTC (rev 9792)
@@ -379,6 +379,7 @@
 				goto out;
 			}
 			if (nd->nd_procnum == NFSPROC_READ ||
+			    nd->nd_procnum == NFSPROC_WRITE ||
 			    nd->nd_procnum == NFSPROC_READDIR ||
 			    nd->nd_procnum == NFSPROC_READLINK ||
 			    nd->nd_procnum == NFSPROC_GETATTR ||

Modified: trunk/sys/modules/nfsd/Makefile
===================================================================
--- trunk/sys/modules/nfsd/Makefile	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/modules/nfsd/Makefile	2018-02-24 19:32:04 UTC (rev 9792)
@@ -1,8 +1,10 @@
-# $FreeBSD$
+# $MidnightBSD$
 
-.PATH: ${.CURDIR}/../../fs/nfsserver
+.PATH: ${.CURDIR}/../../fs/nfsserver ${.CURDIR}/../../nfs
 KMOD=	nfsd
 SRCS=	vnode_if.h \
+	nfs_fha.c \
+	nfs_fha_new.c \
 	nfs_nfsdserv.c \
 	nfs_nfsdcache.c \
 	nfs_nfsdkrpc.c \

Modified: trunk/sys/modules/nfsserver/Makefile
===================================================================
--- trunk/sys/modules/nfsserver/Makefile	2018-02-24 19:31:20 UTC (rev 9791)
+++ trunk/sys/modules/nfsserver/Makefile	2018-02-24 19:32:04 UTC (rev 9792)
@@ -1,9 +1,9 @@
-# $FreeBSD$
+# $MidnightBSD$
 
-.PATH: ${.CURDIR}/../../nfsserver
+.PATH: ${.CURDIR}/../../nfsserver ${.CURDIR}/../../nfs
 KMOD=	nfsserver
 SRCS=	vnode_if.h \
-	nfs_fha.c nfs_serv.c nfs_srvkrpc.c nfs_srvsubs.c \
+	nfs_fha.c nfs_fha_old.c nfs_serv.c nfs_srvkrpc.c nfs_srvsubs.c \
 	opt_mac.h \
 	opt_kgssapi.h \
 	opt_nfs.h



More information about the Midnightbsd-cvs mailing list