svn commit: r358055 - projects/nfs-over-tls/sys/fs/nfsclient
Rick Macklem
rmacklem at FreeBSD.org
Mon Feb 17 21:29:06 UTC 2020
Author: rmacklem
Date: Mon Feb 17 21:29:05 2020
New Revision: 358055
URL: https://svnweb.freebsd.org/changeset/base/358055
Log:
Update the last three NFS files for ext_pgs and TLS support.
Modified:
projects/nfs-over-tls/sys/fs/nfsclient/nfs_clcomsubs.c
projects/nfs-over-tls/sys/fs/nfsclient/nfs_clkrpc.c
projects/nfs-over-tls/sys/fs/nfsclient/nfs_clvfsops.c
Modified: projects/nfs-over-tls/sys/fs/nfsclient/nfs_clcomsubs.c
==============================================================================
--- projects/nfs-over-tls/sys/fs/nfsclient/nfs_clcomsubs.c Mon Feb 17 21:15:26 2020 (r358054)
+++ projects/nfs-over-tls/sys/fs/nfsclient/nfs_clcomsubs.c Mon Feb 17 21:29:05 2020 (r358055)
@@ -64,7 +64,7 @@ nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *ui
struct mbuf *mp, *mp2;
int xfer, left, mlen;
int uiosiz, clflg, rem;
- char *cp, *tcp;
+ char *mcp, *tcp;
KASSERT(uiop->uio_iovcnt == 1, ("nfsm_uiotombuf: iovcnt != 1"));
@@ -74,6 +74,7 @@ nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *ui
clflg = 0;
rem = NFSM_RNDUP(siz) - siz;
mp = mp2 = nd->nd_mb;
+ mcp = nd->nd_bpos;
while (siz > 0) {
left = uiop->uio_iov->iov_len;
uiocp = uiop->uio_iov->iov_base;
@@ -81,35 +82,42 @@ nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *ui
left = siz;
uiosiz = left;
while (left > 0) {
- mlen = M_TRAILINGSPACE(mp);
- if (mlen == 0) {
- if (clflg)
- NFSMCLGET(mp, M_WAITOK);
- else
- NFSMGET(mp);
- mbuf_setlen(mp, 0);
- mbuf_setnext(mp2, mp);
- mp2 = mp;
+ if ((nd->nd_flag & ND_EXTPG) != 0)
+ mlen = nd->nd_bextpgsiz;
+ else
mlen = M_TRAILINGSPACE(mp);
+ if (mlen == 0) {
+ if ((nd->nd_flag & ND_EXTPG) != 0) {
+ mp = nfsm_add_ext_pgs(mp,
+ nd->nd_maxextsiz, &nd->nd_bextpg);
+ mcp = (char *)(void *)PHYS_TO_DMAP(
+ mp->m_ext.ext_pgs->pa[nd->nd_bextpg]);
+ nd->nd_bextpgsiz = PAGE_SIZE;
+ } else {
+ if (clflg)
+ NFSMCLGET(mp, M_WAITOK);
+ else
+ NFSMGET(mp);
+ mp->m_len = 0;
+ mlen = M_TRAILINGSPACE(mp);
+ mcp = mtod(mp, char *);
+ mp2->m_next = mp;
+ mp2 = mp;
+ }
}
xfer = (left > mlen) ? mlen : left;
-#ifdef notdef
- /* Not Yet.. */
- if (uiop->uio_iov->iov_op != NULL)
- (*(uiop->uio_iov->iov_op))
- (uiocp, NFSMTOD(mp, caddr_t) + mbuf_len(mp),
- xfer);
- else
-#endif
if (uiop->uio_segflg == UIO_SYSSPACE)
- NFSBCOPY(uiocp, NFSMTOD(mp, caddr_t) + mbuf_len(mp),
- xfer);
+ NFSBCOPY(uiocp, mcp, xfer);
else
- copyin(CAST_USER_ADDR_T(uiocp), NFSMTOD(mp, caddr_t)
- + mbuf_len(mp), xfer);
- mbuf_setlen(mp, mbuf_len(mp) + xfer);
+ copyin(uiocp, mcp, xfer);
+ mp->m_len += xfer;
left -= xfer;
uiocp += xfer;
+ mcp += xfer;
+ if ((nd->nd_flag & ND_EXTPG) != 0) {
+ nd->nd_bextpgsiz -= xfer;
+ mp->m_ext.ext_pgs->last_pg_len += xfer;
+ }
uiop->uio_offset += xfer;
uiop->uio_resid -= xfer;
}
@@ -120,18 +128,30 @@ nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *ui
siz -= uiosiz;
}
if (rem > 0) {
- if (rem > M_TRAILINGSPACE(mp)) {
+ if ((nd->nd_flag & ND_EXTPG) == 0 && rem >
+ M_TRAILINGSPACE(mp)) {
NFSMGET(mp);
- mbuf_setlen(mp, 0);
- mbuf_setnext(mp2, mp);
+ mp->m_len = 0;
+ mp2->m_next = mp;
+ mcp = mtod(mp, char *);
+ } else if ((nd->nd_flag & ND_EXTPG) != 0 && rem >
+ nd->nd_bextpgsiz) {
+ mp = nfsm_add_ext_pgs(mp, nd->nd_maxextsiz,
+ &nd->nd_bextpg);
+ mcp = (char *)(void *)
+ PHYS_TO_DMAP(mp->m_ext.ext_pgs->pa[nd->nd_bextpg]);
+ nd->nd_bextpgsiz = PAGE_SIZE;
}
- cp = NFSMTOD(mp, caddr_t) + mbuf_len(mp);
for (left = 0; left < rem; left++)
- *cp++ = '\0';
- mbuf_setlen(mp, mbuf_len(mp) + rem);
- nd->nd_bpos = cp;
+ *mcp++ = '\0';
+ mp->m_len += rem;
+ nd->nd_bpos = mcp;
+ if ((nd->nd_flag & ND_EXTPG) != 0) {
+ nd->nd_bextpgsiz -= rem;
+ mp->m_ext.ext_pgs->last_pg_len += rem;
+ }
} else
- nd->nd_bpos = NFSMTOD(mp, caddr_t) + mbuf_len(mp);
+ nd->nd_bpos = mcp;
nd->nd_mb = mp;
}
@@ -141,13 +161,14 @@ nfsm_uiombuf(struct nfsrv_descript *nd, struct uio *ui
* NOTE: can ony handle iovcnt == 1
*/
struct mbuf *
-nfsm_uiombuflist(struct uio *uiop, int siz, struct mbuf **mbp, char **cpp)
+nfsm_uiombuflist(int flag, int maxextsiz, struct uio *uiop, int siz,
+ struct mbuf **mbp, char **cpp)
{
char *uiocp;
struct mbuf *mp, *mp2, *firstmp;
int xfer, left, mlen;
- int uiosiz, clflg;
- char *tcp;
+ int uiosiz, clflg, bextpg, bextpgsiz = 0;
+ char *mcp, *tcp;
KASSERT(uiop->uio_iovcnt == 1, ("nfsm_uiotombuf: iovcnt != 1"));
@@ -155,11 +176,21 @@ nfsm_uiombuflist(struct uio *uiop, int siz, struct mbu
clflg = 1;
else
clflg = 0;
- if (clflg != 0)
- NFSMCLGET(mp, M_WAITOK);
- else
- NFSMGET(mp);
- mbuf_setlen(mp, 0);
+ if ((flag & ND_EXTPG) != 0) {
+ mp = mb_alloc_ext_plus_pages(PAGE_SIZE, M_WAITOK,
+ false, mb_free_mext_pgs);
+ mcp = (char *)(void *)
+ PHYS_TO_DMAP(mp->m_ext.ext_pgs->pa[0]);
+ bextpgsiz = PAGE_SIZE;
+ bextpg = 0;
+ } else {
+ if (clflg != 0)
+ NFSMCLGET(mp, M_WAITOK);
+ else
+ NFSMGET(mp);
+ mp->m_len = 0;
+ mcp = mtod(mp, char *);
+ }
firstmp = mp2 = mp;
while (siz > 0) {
left = uiop->uio_iov->iov_len;
@@ -168,27 +199,42 @@ nfsm_uiombuflist(struct uio *uiop, int siz, struct mbu
left = siz;
uiosiz = left;
while (left > 0) {
- mlen = M_TRAILINGSPACE(mp);
- if (mlen == 0) {
- if (clflg)
- NFSMCLGET(mp, M_WAITOK);
- else
- NFSMGET(mp);
- mbuf_setlen(mp, 0);
- mbuf_setnext(mp2, mp);
- mp2 = mp;
+ if ((flag & ND_EXTPG) != 0)
+ mlen = bextpgsiz;
+ else
mlen = M_TRAILINGSPACE(mp);
+ if (mlen == 0) {
+ if ((flag & ND_EXTPG) != 0) {
+ mp = nfsm_add_ext_pgs(mp, maxextsiz,
+ &bextpg);
+ mcp = (char *)(void *)PHYS_TO_DMAP(
+ mp->m_ext.ext_pgs->pa[bextpg]);
+ mlen = bextpgsiz = PAGE_SIZE;
+ } else {
+ if (clflg)
+ NFSMCLGET(mp, M_WAITOK);
+ else
+ NFSMGET(mp);
+ mp->m_len = 0;
+ mcp = mtod(mp, char *);
+ mlen = M_TRAILINGSPACE(mp);
+ mp2->m_next = mp;
+ mp2 = mp;
+ }
}
xfer = (left > mlen) ? mlen : left;
if (uiop->uio_segflg == UIO_SYSSPACE)
- NFSBCOPY(uiocp, NFSMTOD(mp, caddr_t) +
- mbuf_len(mp), xfer);
+ NFSBCOPY(uiocp, mcp, xfer);
else
- copyin(uiocp, NFSMTOD(mp, caddr_t) +
- mbuf_len(mp), xfer);
- mbuf_setlen(mp, mbuf_len(mp) + xfer);
+ copyin(uiocp, mcp, xfer);
+ mp->m_len += xfer;
left -= xfer;
uiocp += xfer;
+ mcp += xfer;
+ if ((flag & ND_EXTPG) != 0) {
+ bextpgsiz -= xfer;
+ mp->m_ext.ext_pgs->last_pg_len += xfer;
+ }
uiop->uio_offset += xfer;
uiop->uio_resid -= xfer;
}
@@ -199,7 +245,7 @@ nfsm_uiombuflist(struct uio *uiop, int siz, struct mbu
siz -= uiosiz;
}
if (cpp != NULL)
- *cpp = NFSMTOD(mp, caddr_t) + mbuf_len(mp);
+ *cpp = mcp;
if (mbp != NULL)
*mbp = mp;
return (firstmp);
Modified: projects/nfs-over-tls/sys/fs/nfsclient/nfs_clkrpc.c
==============================================================================
--- projects/nfs-over-tls/sys/fs/nfsclient/nfs_clkrpc.c Mon Feb 17 21:15:26 2020 (r358054)
+++ projects/nfs-over-tls/sys/fs/nfsclient/nfs_clkrpc.c Mon Feb 17 21:29:05 2020 (r358055)
@@ -37,6 +37,7 @@
__FBSDID("$FreeBSD$");
#include "opt_kgssapi.h"
+#include "opt_kern_tls.h"
#include <fs/nfs/nfsport.h>
@@ -54,6 +55,10 @@ static int nfs_cbproc(struct nfsrv_descript *, u_int32
extern u_long sb_max_adj;
extern int nfs_numnfscbd;
extern int nfscl_debuglevel;
+extern bool nfs_use_ext_pgs;
+#ifdef KERN_TLS
+extern u_int ktls_maxlen;
+#endif
/*
* NFS client system calls for handling callbacks.
@@ -108,6 +113,15 @@ nfscb_program(struct svc_req *rqst, SVCXPRT *xprt)
mac_cred_associate_nfsd(nd.nd_cred);
#endif
#endif
+ if ((xprt->xp_tls || nfs_use_ext_pgs) && PMAP_HAS_DMAP != 0) {
+ nd.nd_flag |= ND_EXTPG;
+ nd.nd_maxextsiz = 16384;
+#ifdef KERN_TLS
+ if (xprt->xp_tls)
+ nd.nd_maxextsiz = min(TLS_MAX_MSG_SIZE_V10_2,
+ ktls_maxlen);
+#endif
+ }
cacherep = nfs_cbproc(&nd, rqst->rq_xid);
} else {
NFSMGET(nd.nd_mreq);
Modified: projects/nfs-over-tls/sys/fs/nfsclient/nfs_clvfsops.c
==============================================================================
--- projects/nfs-over-tls/sys/fs/nfsclient/nfs_clvfsops.c Mon Feb 17 21:15:26 2020 (r358054)
+++ projects/nfs-over-tls/sys/fs/nfsclient/nfs_clvfsops.c Mon Feb 17 21:29:05 2020 (r358055)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include "opt_bootp.h"
#include "opt_nfsroot.h"
+#include "opt_kern_tls.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -116,7 +117,7 @@ static void nfs_decode_args(struct mount *mp, struct n
static int mountnfs(struct nfs_args *, struct mount *,
struct sockaddr *, char *, u_char *, int, u_char *, int,
u_char *, int, struct vnode **, struct ucred *,
- struct thread *, int, int, int);
+ struct thread *, int, int, int, uint32_t);
static void nfs_getnlminfo(struct vnode *, uint8_t *, size_t *,
struct sockaddr_storage *, int *, off_t *,
struct timeval *);
@@ -535,7 +536,7 @@ nfs_mountdiskless(char *path,
nam = sodupsockaddr((struct sockaddr *)sin, M_WAITOK);
if ((error = mountnfs(args, mp, nam, path, NULL, 0, dirpath, dirlen,
NULL, 0, vpp, td->td_ucred, td, NFS_DEFAULT_NAMETIMEO,
- NFS_DEFAULT_NEGNAMETIMEO, 0)) != 0) {
+ NFS_DEFAULT_NEGNAMETIMEO, 0, 0)) != 0) {
printf("nfs_mountroot: mount %s on /: %d\n", path, error);
return (error);
}
@@ -737,7 +738,7 @@ static const char *nfs_opts[] = { "from", "nfs_args",
"resvport", "readahead", "hostname", "timeo", "timeout", "addr", "fh",
"nfsv3", "sec", "principal", "nfsv4", "gssname", "allgssname", "dirpath",
"minorversion", "nametimeo", "negnametimeo", "nocto", "noncontigwr",
- "pnfs", "wcommitsize", "oneopenown",
+ "pnfs", "wcommitsize", "oneopenown", "tls",
NULL };
/*
@@ -888,9 +889,11 @@ nfs_mount(struct mount *mp)
int dirlen, has_nfs_args_opt, has_nfs_from_opt,
krbnamelen, srvkrbnamelen;
size_t hstlen;
+ uint32_t newflag;
has_nfs_args_opt = 0;
has_nfs_from_opt = 0;
+ newflag = 0;
hst = malloc(MNAMELEN, M_TEMP, M_WAITOK);
if (vfs_filteropt(mp->mnt_optnew, nfs_opts)) {
error = EINVAL;
@@ -974,6 +977,8 @@ nfs_mount(struct mount *mp)
args.flags |= NFSMNT_PNFS;
if (vfs_getopt(mp->mnt_optnew, "oneopenown", NULL, NULL) == 0)
args.flags |= NFSMNT_ONEOPENOWN;
+ if (vfs_getopt(mp->mnt_optnew, "tls", NULL, NULL) == 0)
+ newflag |= NFSMNT_TLS;
if (vfs_getopt(mp->mnt_optnew, "readdirsize", (void **)&opt, NULL) == 0) {
if (opt == NULL) {
vfs_mount_error(mp, "illegal readdirsize");
@@ -1328,7 +1333,7 @@ nfs_mount(struct mount *mp)
args.fh = nfh;
error = mountnfs(&args, mp, nam, hst, krbname, krbnamelen, dirpath,
dirlen, srvkrbname, srvkrbnamelen, &vp, td->td_ucred, td,
- nametimeo, negnametimeo, minvers);
+ nametimeo, negnametimeo, minvers, newflag);
out:
if (!error) {
MNT_ILOCK(mp);
@@ -1377,7 +1382,7 @@ mountnfs(struct nfs_args *argp, struct mount *mp, stru
char *hst, u_char *krbname, int krbnamelen, u_char *dirpath, int dirlen,
u_char *srvkrbname, int srvkrbnamelen, struct vnode **vpp,
struct ucred *cred, struct thread *td, int nametimeo, int negnametimeo,
- int minvers)
+ int minvers, uint32_t newflag)
{
struct nfsmount *nmp;
struct nfsnode *np;
@@ -1396,9 +1401,22 @@ mountnfs(struct nfs_args *argp, struct mount *mp, stru
free(nam, M_SONAME);
return (0);
} else {
+ /* NFS-over-TLS requires "options KERN_TLS" and a DMAP. */
+ if ((newflag & NFSMNT_TLS) != 0) {
+ error = EINVAL;
+#ifdef KERN_TLS
+ if (PMAP_HAS_DMAP != 0)
+ error = 0;
+#endif
+ if (error != 0) {
+ free(nam, M_SONAME);
+ return (error);
+ }
+ }
nmp = malloc(sizeof (struct nfsmount) +
krbnamelen + dirlen + srvkrbnamelen + 2,
M_NEWNFSMNT, M_WAITOK | M_ZERO);
+ nmp->nm_newflag = newflag;
TAILQ_INIT(&nmp->nm_bufq);
TAILQ_INIT(&nmp->nm_sess);
if (clval == 0)
@@ -2002,6 +2020,8 @@ void nfscl_retopts(struct nfsmount *nmp, char *buffer,
nfscl_printopt(nmp, nmp->nm_sotype != SOCK_STREAM, ",udp", &buf, &blen);
nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_RESVPORT) != 0, ",resvport",
&buf, &blen);
+ nfscl_printopt(nmp, (nmp->nm_newflag & NFSMNT_TLS) != 0, ",tls", &buf,
+ &blen);
nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCONN) != 0, ",noconn",
&buf, &blen);
nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_SOFT) == 0, ",hard", &buf,
More information about the svn-src-projects
mailing list