From 33daa8de6b1be011ff80132a6d9d4331bd7d0e45 Mon Sep 17 00:00:00 2001 From: bjh21 Date: Tue, 19 Sep 2000 17:04:50 +0000 Subject: [PATCH] New kernel option, NFS_V2_ONLY, which aims to reduce the NFS client to just that required to support NFSv2 mounts. Not finished yet, but already provides some 44k of saving in code size on arm26. More savings, and some documentation, are still to come. --- sys/conf/files | 3 ++- sys/nfs/nfs.h | 6 +++++- sys/nfs/nfs_bio.c | 8 +++++++- sys/nfs/nfs_boot.c | 8 ++++++-- sys/nfs/nfs_node.c | 3 ++- sys/nfs/nfs_socket.c | 3 ++- sys/nfs/nfs_subs.c | 3 ++- sys/nfs/nfs_syscalls.c | 3 ++- sys/nfs/nfs_vfsops.c | 21 +++++++++++++++++++-- sys/nfs/nfs_vnops.c | 40 ++++++++++++++++++++++------------------ 10 files changed, 69 insertions(+), 29 deletions(-) diff --git a/sys/conf/files b/sys/conf/files index c9fe8f06dd7b..685b45f5c1b2 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.390 2000/09/18 22:15:21 itojun Exp $ +# $NetBSD: files,v 1.391 2000/09/19 17:04:50 bjh21 Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -21,6 +21,7 @@ defopt opt_ntp.h PPS_SYNC NTP defopt opt_nfs_boot.h NFS_BOOT_BOOTP NFS_BOOT_BOOTPARAM NFS_BOOT_DHCP NFS_BOOT_GATEWAY NFS_BOOT_TCP NFS_BOOT_OPTIONS NFS_BOOT_RWSIZE +defopt opt_nfs.h NFS_V2_ONLY defopt NFSSERVER defopt opt_kmempages.h NKMEMPAGES NKMEMPAGES_MIN NKMEMPAGES_MAX diff --git a/sys/nfs/nfs.h b/sys/nfs/nfs.h index 978070fdc290..ca705c9e0310 100644 --- a/sys/nfs/nfs.h +++ b/sys/nfs/nfs.h @@ -1,4 +1,4 @@ -/* $NetBSD: nfs.h,v 1.22 2000/06/09 00:00:17 fvdl Exp $ */ +/* $NetBSD: nfs.h,v 1.23 2000/09/19 17:04:50 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. @@ -102,7 +102,11 @@ extern int nfs_niothreads; /* Number of async_daemons desired */ #define NMOD(a) ((a) % nfs_asyncdaemons) #define NFS_CMPFH(n, f, s) \ ((n)->n_fhsize == (s) && !memcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) +#ifdef NFS_V2_ONLY +#define NFS_ISV3(v) (0) +#else #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) +#endif #define NFS_SRVMAXDATA(n) \ (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \ NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA) diff --git a/sys/nfs/nfs_bio.c b/sys/nfs/nfs_bio.c index 64ae906ddd25..230b9a092dce 100644 --- a/sys/nfs/nfs_bio.c +++ b/sys/nfs/nfs_bio.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_bio.c,v 1.50 2000/06/27 17:52:28 mrg Exp $ */ +/* $NetBSD: nfs_bio.c,v 1.51 2000/09/19 17:04:50 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993 @@ -38,6 +38,8 @@ * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95 */ +#include "opt_nfs.h" + #include #include #include @@ -98,9 +100,11 @@ nfs_bioread(vp, uio, ioflag, cred, cflag) if (vp->v_type != VDIR && uio->uio_offset < 0) return (EINVAL); p = uio->uio_procp; +#ifndef NFS_V2_ONLY if ((nmp->nm_flag & NFSMNT_NFSV3) && !(nmp->nm_iflag & NFSMNT_GOTFSINFO)) (void)nfs_fsinfo(nmp, vp, cred, p); +#endif if (vp->v_type != VDIR && (uio->uio_offset + uio->uio_resid) > nmp->nm_maxfilesize) return (EFBIG); @@ -573,9 +577,11 @@ nfs_write(v) np->n_flag &= ~NWRITEERR; return (np->n_error); } +#ifndef NFS_V2_ONLY if ((nmp->nm_flag & NFSMNT_NFSV3) && !(nmp->nm_iflag & NFSMNT_GOTFSINFO)) (void)nfs_fsinfo(nmp, vp, cred, p); +#endif if (ioflag & (IO_APPEND | IO_SYNC)) { if (np->n_flag & NMODIFIED) { np->n_attrstamp = 0; diff --git a/sys/nfs/nfs_boot.c b/sys/nfs/nfs_boot.c index 676c169fd168..2960a2828964 100644 --- a/sys/nfs/nfs_boot.c +++ b/sys/nfs/nfs_boot.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_boot.c,v 1.53 2000/03/29 03:43:33 simonb Exp $ */ +/* $NetBSD: nfs_boot.c,v 1.54 2000/09/19 17:04:51 bjh21 Exp $ */ /*- * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc. @@ -41,6 +41,7 @@ * about where to mount root from, what pathnames, etc. */ +#include "opt_nfs.h" #include "opt_nfs_boot.h" #include @@ -564,8 +565,11 @@ nfs_boot_getfh(ndm) #endif args->fh = ndm->ndm_fh; args->hostname = ndm->ndm_host; - args->flags = NFSMNT_NFSV3 | NFSMNT_NOCONN | NFSMNT_RESVPORT; + args->flags = NFSMNT_NOCONN | NFSMNT_RESVPORT; +#ifndef NFS_V2_ONLY + args->flags |= NFSMNT_NFSV3; +#endif #ifdef NFS_BOOT_OPTIONS args->flags |= NFS_BOOT_OPTIONS; #endif diff --git a/sys/nfs/nfs_node.c b/sys/nfs/nfs_node.c index 8f94f53f3502..8ab80f97fade 100644 --- a/sys/nfs/nfs_node.c +++ b/sys/nfs/nfs_node.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_node.c,v 1.34 2000/08/03 06:15:02 thorpej Exp $ */ +/* $NetBSD: nfs_node.c,v 1.35 2000/09/19 17:04:51 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993 @@ -38,6 +38,7 @@ * @(#)nfs_node.c 8.6 (Berkeley) 5/22/95 */ +#include "opt_nfs.h" #include #include diff --git a/sys/nfs/nfs_socket.c b/sys/nfs/nfs_socket.c index 4b99f234b8b7..c83a95b3e166 100644 --- a/sys/nfs/nfs_socket.c +++ b/sys/nfs/nfs_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_socket.c,v 1.58 2000/06/27 17:52:33 mrg Exp $ */ +/* $NetBSD: nfs_socket.c,v 1.59 2000/09/19 17:04:51 bjh21 Exp $ */ /* * Copyright (c) 1989, 1991, 1993, 1995 @@ -43,6 +43,7 @@ */ #include "fs_nfs.h" +#include "opt_nfs.h" #include "opt_nfsserver.h" #include "opt_inet.h" diff --git a/sys/nfs/nfs_subs.c b/sys/nfs/nfs_subs.c index d785c9e81425..afb95b35b91d 100644 --- a/sys/nfs/nfs_subs.c +++ b/sys/nfs/nfs_subs.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_subs.c,v 1.81 2000/08/03 20:41:32 thorpej Exp $ */ +/* $NetBSD: nfs_subs.c,v 1.82 2000/09/19 17:04:51 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993 @@ -39,6 +39,7 @@ */ #include "fs_nfs.h" +#include "opt_nfs.h" #include "opt_nfsserver.h" #include "opt_iso.h" #include "opt_inet.h" diff --git a/sys/nfs/nfs_syscalls.c b/sys/nfs/nfs_syscalls.c index 27cc5ff6f743..c2415420072d 100644 --- a/sys/nfs/nfs_syscalls.c +++ b/sys/nfs/nfs_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_syscalls.c,v 1.42 2000/08/23 23:17:14 nathanw Exp $ */ +/* $NetBSD: nfs_syscalls.c,v 1.43 2000/09/19 17:04:51 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993 @@ -39,6 +39,7 @@ */ #include "fs_nfs.h" +#include "opt_nfs.h" #include "opt_nfsserver.h" #include "opt_iso.h" #include "opt_inet.h" diff --git a/sys/nfs/nfs_vfsops.c b/sys/nfs/nfs_vfsops.c index 7c16b17fe0d5..0b6b3e1c588c 100644 --- a/sys/nfs/nfs_vfsops.c +++ b/sys/nfs/nfs_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_vfsops.c,v 1.94 2000/08/23 09:59:22 enami Exp $ */ +/* $NetBSD: nfs_vfsops.c,v 1.95 2000/09/19 17:04:51 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993, 1995 @@ -40,6 +40,7 @@ #if defined(_KERNEL) && !defined(_LKM) #include "opt_compat_netbsd.h" +#include "opt_nfs.h" #endif #include @@ -139,7 +140,12 @@ nfs_statfs(mp, sbp, p) int32_t t1, t2; caddr_t bpos, dpos, cp2; struct nfsmount *nmp = VFSTONFS(mp); - int error = 0, v3 = (nmp->nm_flag & NFSMNT_NFSV3), retattr; + int error = 0, retattr; +#ifdef NFS_V2_ONLY + const int v3 = 0; +#else + int v3 = (nmp->nm_flag & NFSMNT_NFSV3); +#endif struct mbuf *mreq, *mrep = NULL, *md, *mb, *mb2; struct ucred *cred; struct nfsnode *np; @@ -206,6 +212,7 @@ nfs_statfs(mp, sbp, p) return (error); } +#ifndef NFS_V2_ONLY /* * nfs version 3 fsinfo rpc call */ @@ -271,6 +278,7 @@ nfs_fsinfo(nmp, vp, cred, p) nfsm_reqdone; return (error); } +#endif /* * Mount a remote root fs via. NFS. It goes like this: @@ -447,12 +455,14 @@ nfs_decode_args(nmp, argp) nmp->nm_retry = NFS_MAXREXMIT; } +#ifndef NFS_V2_ONLY if (argp->flags & NFSMNT_NFSV3) { if (argp->sotype == SOCK_DGRAM) maxio = NFS_MAXDGRAMDATA; else maxio = NFS_MAXDATA; } else +#endif maxio = NFS_V2MAXDATA; if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) { @@ -558,6 +568,9 @@ nfs_mount(mp, path, data, ndp, p) return (error); if (args.version != NFS_ARGSVERSION) return (EPROGMISMATCH); +#ifdef NFS_V2_ONLY + args.flags &= ~(NFSMNT_NFSV3 | NFSMNT_NQNFS); +#endif if (mp->mnt_flag & MNT_UPDATE) { struct nfsmount *nmp = VFSTONFS(mp); @@ -638,6 +651,7 @@ mountnfs(argp, mp, nam, pth, hst, vpp, p) vfs_getnewfsid(mp); nmp->nm_mountp = mp; +#ifndef NFS_V2_ONLY if (argp->flags & NFSMNT_NQNFS) /* * We have to set mnt_maxsymlink to a non-zero value so @@ -646,8 +660,11 @@ mountnfs(argp, mp, nam, pth, hst, vpp, p) * unsuspecting binaries). */ mp->mnt_maxsymlinklen = 1; +#endif +#ifndef NFS_V2_ONLY if ((argp->flags & NFSMNT_NFSV3) == 0) +#endif /* * V2 can only handle 32 bit filesizes. For v3, nfs_fsinfo * will fill this in. diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 99b0d76d7c00..6eff0e2a144e 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_vnops.c,v 1.118 2000/09/19 00:00:18 fvdl Exp $ */ +/* $NetBSD: nfs_vnops.c,v 1.119 2000/09/19 17:04:51 bjh21 Exp $ */ /* * Copyright (c) 1989, 1993 @@ -42,6 +42,8 @@ * vnode op calls for Sun NFS version 2 and 3 */ +#include "opt_nfs.h" + #include #include #include @@ -301,7 +303,7 @@ nfs_access(v) int error = 0, attrflag, cachevalid; struct mbuf *mreq, *mrep, *md, *mb, *mb2; u_int32_t mode, rmode; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); struct nfsnode *np = VTONFS(vp); cachevalid = (np->n_accstamp != -1 && @@ -577,7 +579,7 @@ nfs_getattr(v) caddr_t bpos, dpos; int error = 0; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); /* * Update local times for special files. @@ -705,7 +707,7 @@ nfs_setattrrpc(vp, vap, cred, procp) u_int32_t *tl; int error = 0, wccflag = NFSV3_WCCRATTR; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); nfsstats.rpccnt[NFSPROC_SETATTR]++; nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH(v3) + NFSX_SATTR(v3)); @@ -771,7 +773,7 @@ nfs_lookup(v) nfsfh_t *fhp; struct nfsnode *np; int lockparent, wantparent, error = 0, attrflag, fhsize; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); cnp->cn_flags &= ~PDIRUNLOCK; flags = cnp->cn_flags; @@ -994,7 +996,7 @@ nfs_readlinkrpc(vp, uiop, cred) caddr_t bpos, dpos, cp2; int error = 0, len, attrflag; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); nfsstats.rpccnt[NFSPROC_READLINK]++; nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH(v3)); @@ -1027,7 +1029,7 @@ nfs_readrpc(vp, uiop, cred) struct mbuf *mreq, *mrep, *md, *mb, *mb2; struct nfsmount *nmp; int error = 0, len, retlen, tsiz, eof, attrflag; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); #ifndef nolint eof = 0; @@ -1092,7 +1094,8 @@ nfs_writerpc(vp, uiop, cred, iomode, must_commit) struct mbuf *mreq, *mrep, *md, *mb, *mb2; struct nfsmount *nmp = VFSTONFS(vp->v_mount); int error = 0, len, tsiz, wccflag = NFSV3_WCCRATTR, rlen, commit; - int v3 = NFS_ISV3(vp), committed = NFSV3WRITE_FILESYNC; + const int v3 = NFS_ISV3(vp); + int committed = NFSV3WRITE_FILESYNC; #ifndef DIAGNOSTIC if (uiop->uio_iovcnt != 1) @@ -1211,7 +1214,7 @@ nfs_mknodrpc(dvp, vpp, cnp, vap) int error = 0, wccflag = NFSV3_WCCRATTR, gotvp = 0; struct mbuf *mreq, *mrep, *md, *mb, *mb2; u_int32_t rdev; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); if (vap->va_type == VCHR || vap->va_type == VBLK) rdev = txdr_unsigned(vap->va_rdev); @@ -1328,7 +1331,7 @@ nfs_create(v) caddr_t bpos, dpos, cp2; int error, wccflag = NFSV3_WCCRATTR, gotvp = 0, fmode = 0; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); /* * Oops, not for me.. @@ -1511,7 +1514,7 @@ nfs_removerpc(dvp, name, namelen, cred, proc) caddr_t bpos, dpos, cp2; int error = 0, wccflag = NFSV3_WCCRATTR; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); nfsstats.rpccnt[NFSPROC_REMOVE]++; nfsm_reqhead(dvp, NFSPROC_REMOVE, @@ -1632,7 +1635,7 @@ nfs_renamerpc(fdvp, fnameptr, fnamelen, tdvp, tnameptr, tnamelen, cred, proc) caddr_t bpos, dpos, cp2; int error = 0, fwccflag = NFSV3_WCCRATTR, twccflag = NFSV3_WCCRATTR; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(fdvp); + const int v3 = NFS_ISV3(fdvp); nfsstats.rpccnt[NFSPROC_RENAME]++; nfsm_reqhead(fdvp, NFSPROC_RENAME, @@ -1678,6 +1681,7 @@ nfs_link(v) caddr_t bpos, dpos, cp2; int error = 0, wccflag = NFSV3_WCCRATTR, attrflag = 0; struct mbuf *mreq, *mrep, *md, *mb, *mb2; + /* XXX Should be const and initialised? */ int v3; if (dvp->v_mount != vp->v_mount) { @@ -1746,7 +1750,7 @@ nfs_symlink(v) int slen, error = 0, wccflag = NFSV3_WCCRATTR, gotvp; struct mbuf *mreq, *mrep, *md, *mb, *mb2; struct vnode *newvp = (struct vnode *)0; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); nfsstats.rpccnt[NFSPROC_SYMLINK]++; slen = strlen(ap->a_target); @@ -1815,7 +1819,7 @@ nfs_mkdir(v) int error = 0, wccflag = NFSV3_WCCRATTR; int gotvp = 0; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); len = cnp->cn_namelen; nfsstats.rpccnt[NFSPROC_MKDIR]++; @@ -1894,7 +1898,7 @@ nfs_rmdir(v) caddr_t bpos, dpos, cp2; int error = 0, wccflag = NFSV3_WCCRATTR; struct mbuf *mreq, *mrep, *md, *mb, *mb2; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); if (dvp == vp) { vrele(dvp); @@ -2036,7 +2040,7 @@ nfs_readdirrpc(vp, uiop, cred) u_quad_t fileno; int error = 0, tlen, more_dirs = 1, blksiz = 0, bigenough = 1; int attrflag, nrpcs = 0, reclen; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); nfsquad_t cookie; #ifdef DIAGNOSTIC @@ -2528,7 +2532,7 @@ nfs_lookitup(dvp, name, len, cred, procp, npp) int error = 0, fhlen, attrflag; struct mbuf *mreq, *mrep, *md, *mb, *mb2; nfsfh_t *nfhp; - int v3 = NFS_ISV3(dvp); + const int v3 = NFS_ISV3(dvp); nfsstats.rpccnt[NFSPROC_LOOKUP]++; nfsm_reqhead(dvp, NFSPROC_LOOKUP, @@ -2968,7 +2972,7 @@ nfs_pathconf(v) int error = 0, attrflag; unsigned int l; u_int64_t maxsize; - int v3 = NFS_ISV3(vp); + const int v3 = NFS_ISV3(vp); switch (ap->a_name) { /* Names that can be resolved locally. */