Date: Sun, 23 Sep 2018 02:16:48 +0000 (UTC) From: Rick Macklem <rmacklem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r338895 - in projects/nfsv42/sys/fs: nfs nfsserver Message-ID: <201809230216.w8N2GmYk007766@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rmacklem Date: Sun Sep 23 02:16:47 2018 New Revision: 338895 URL: https://svnweb.freebsd.org/changeset/base/338895 Log: Add the IO Advise operation to the NFSv4.2 server. At this time, it only handles WILLNEED and DONTNEED, since those are the ones handled by VOP_ADVISE(). Modified: projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c projects/nfsv42/sys/fs/nfs/nfs_var.h projects/nfsv42/sys/fs/nfs/nfsproto.h projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c projects/nfsv42/sys/fs/nfsserver/nfs_nfsdsocket.c Modified: projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c ============================================================================== --- projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c Sat Sep 22 23:02:45 2018 (r338894) +++ projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c Sun Sep 23 02:16:47 2018 (r338895) @@ -170,7 +170,7 @@ struct nfsv4_opflag nfsv4_opflag[NFSV42_NOPS] = { { 0, 0, 0, 0, LK_EXCLUSIVE, 1, 1 }, /* Copy */ { 0, 0, 0, 0, LK_EXCLUSIVE, 1, 1 }, /* Copy Notify */ { 0, 0, 0, 0, LK_EXCLUSIVE, 1, 1 }, /* Deallocate */ - { 0, 0, 0, 0, LK_EXCLUSIVE, 1, 1 }, /* IO Advise */ + { 0, 1, 0, 1, LK_SHARED, 1, 0 }, /* IO Advise */ { 0, 1, 0, 1, LK_EXCLUSIVE, 1, 0 }, /* Layout Error */ { 0, 1, 0, 1, LK_EXCLUSIVE, 1, 0 }, /* Layout Stats */ { 0, 0, 0, 0, LK_EXCLUSIVE, 1, 1 }, /* Offload Cancel */ Modified: projects/nfsv42/sys/fs/nfs/nfs_var.h ============================================================================== --- projects/nfsv42/sys/fs/nfs/nfs_var.h Sat Sep 22 23:02:45 2018 (r338894) +++ projects/nfsv42/sys/fs/nfs/nfs_var.h Sun Sep 23 02:16:47 2018 (r338895) @@ -277,6 +277,8 @@ int nfsrvd_layoutcommit(struct nfsrv_descript *, int, vnode_t, NFSPROC_T *, struct nfsexstuff *); int nfsrvd_layoutreturn(struct nfsrv_descript *, int, vnode_t, NFSPROC_T *, struct nfsexstuff *); +int nfsrvd_ioadvise(struct nfsrv_descript *, int, + vnode_t, NFSPROC_T *, struct nfsexstuff *); int nfsrvd_layouterror(struct nfsrv_descript *, int, vnode_t, NFSPROC_T *, struct nfsexstuff *); int nfsrvd_layoutstats(struct nfsrv_descript *, int, Modified: projects/nfsv42/sys/fs/nfs/nfsproto.h ============================================================================== --- projects/nfsv42/sys/fs/nfs/nfsproto.h Sat Sep 22 23:02:45 2018 (r338894) +++ projects/nfsv42/sys/fs/nfs/nfsproto.h Sun Sep 23 02:16:47 2018 (r338895) @@ -835,6 +835,24 @@ struct nfsv3_sattr { u_int32_t sa_mtimetype; nfstime3 sa_mtime; }; + +/* + * IO Advise hint bits for NFSv4.2. + * Since these go on the wire as a bitmap, the NFSATTRBIT macros are + * used to manipulate these bits. + */ +#define NFSV4IOHINT_NORMAL 0 +#define NFSV4IOHINT_SEQUENTIAL 1 +#define NFSV4IOHINT_SEQUENTIALBACK 2 +#define NFSV4IOHINT_RANDOM 3 +#define NFSV4IOHINT_WILLNEED 4 +#define NFSV4IOHINT_WILLNEEDOPTUN 5 +#define NFSV4IOHINT_DONTNEED 6 +#define NFSV4IOHINT_NOREUSE 7 +#define NFSV4IOHINT_READ 8 +#define NFSV4IOHINT_WRITE 9 +#define NFSV4IOHINT_INITPROXIMITY 10 + #endif /* _KERNEL */ /* Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c ============================================================================== --- projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Sat Sep 22 23:02:45 2018 (r338894) +++ projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c Sun Sep 23 02:16:47 2018 (r338895) @@ -4783,6 +4783,93 @@ nfsmout: } /* + * nfsv4 io_advise service + */ +APPLESTATIC int +nfsrvd_ioadvise(struct nfsrv_descript *nd, __unused int isdgram, + vnode_t vp, NFSPROC_T *p, struct nfsexstuff *exp) +{ + uint32_t *tl; + nfsv4stateid_t stateid; + nfsattrbit_t hints; + int error = 0, ret; + off_t offset, len; + + if (nfs_rootfhset == 0 || nfsd_checkrootexp(nd) != 0) { + nd->nd_repstat = NFSERR_WRONGSEC; + goto nfsmout; + } + NFSM_DISSECT(tl, uint32_t *, NFSX_STATEID + 2 * NFSX_HYPER); + stateid.seqid = fxdr_unsigned(uint32_t, *tl++); + NFSBCOPY(tl, stateid.other, NFSX_STATEIDOTHER); + tl += (NFSX_STATEIDOTHER / NFSX_UNSIGNED); + offset = fxdr_hyper(tl); tl += 2; + len = fxdr_hyper(tl); tl += 2; + error = nfsrv_getattrbits(nd, &hints, NULL, NULL); + if (error != 0) + goto nfsmout; + /* + * For the special stateid of other all 0s and seqid == 1, set + * the stateid to the current stateid, if it is set. + */ + if (stateid.seqid == 1 && stateid.other[0] == 0 && + stateid.other[1] == 0 && stateid.other[2] == 0) { + if ((nd->nd_flag & ND_CURSTATEID) != 0) { + stateid = nd->nd_curstateid; + stateid.seqid = 0; + } else { + nd->nd_repstat = NFSERR_BADSTATEID; + goto nfsmout; + } + } + + if (offset < 0) { + nd->nd_repstat = NFSERR_INVAL; + goto nfsmout; + } + if (len < 0) + len = 0; + + /* + * For now, we can only handle WILLNEED and DONTNEED and don't use + * the stateid. + */ + if ((NFSISSET_ATTRBIT(&hints, NFSV4IOHINT_WILLNEED) && + !NFSISSET_ATTRBIT(&hints, NFSV4IOHINT_DONTNEED)) || + (NFSISSET_ATTRBIT(&hints, NFSV4IOHINT_DONTNEED) && + !NFSISSET_ATTRBIT(&hints, NFSV4IOHINT_WILLNEED))) { + NFSVOPUNLOCK(vp, 0); + if (NFSISSET_ATTRBIT(&hints, NFSV4IOHINT_WILLNEED)) { + ret = VOP_ADVISE(vp, offset, len, POSIX_FADV_WILLNEED); + NFSZERO_ATTRBIT(&hints); + if (ret == 0) + NFSSETBIT_ATTRBIT(&hints, NFSV4IOHINT_WILLNEED); + else + NFSSETBIT_ATTRBIT(&hints, NFSV4IOHINT_NORMAL); + } else { + ret = VOP_ADVISE(vp, offset, len, POSIX_FADV_DONTNEED); + NFSZERO_ATTRBIT(&hints); + if (ret == 0) + NFSSETBIT_ATTRBIT(&hints, NFSV4IOHINT_DONTNEED); + else + NFSSETBIT_ATTRBIT(&hints, NFSV4IOHINT_NORMAL); + } + vrele(vp); + } else { + NFSZERO_ATTRBIT(&hints); + NFSSETBIT_ATTRBIT(&hints, NFSV4IOHINT_NORMAL); + vput(vp); + } + nfsrv_putattrbit(nd, &hints); + NFSEXITCODE2(error, nd); + return (error); +nfsmout: + vput(vp); + NFSEXITCODE2(error, nd); + return (error); +} + +/* * nfsv4 getdeviceinfo service */ APPLESTATIC int Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdsocket.c ============================================================================== --- projects/nfsv42/sys/fs/nfsserver/nfs_nfsdsocket.c Sat Sep 22 23:02:45 2018 (r338894) +++ projects/nfsv42/sys/fs/nfsserver/nfs_nfsdsocket.c Sun Sep 23 02:16:47 2018 (r338895) @@ -202,7 +202,7 @@ int (*nfsrv4_ops0[NFSV42_NOPS])(struct nfsrv_descript nfsrvd_notsupp, nfsrvd_notsupp, nfsrvd_notsupp, - nfsrvd_notsupp, + nfsrvd_ioadvise, nfsrvd_layouterror, nfsrvd_layoutstats, nfsrvd_notsupp,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201809230216.w8N2GmYk007766>