From owner-svn-src-projects@freebsd.org Sun Sep 23 02:16:49 2018 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A639810AA821 for ; Sun, 23 Sep 2018 02:16:49 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D9288C438; Sun, 23 Sep 2018 02:16:49 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3985124449; Sun, 23 Sep 2018 02:16:49 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w8N2GnlL007771; Sun, 23 Sep 2018 02:16:49 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w8N2GmYk007766; Sun, 23 Sep 2018 02:16:48 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201809230216.w8N2GmYk007766@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 23 Sep 2018 02:16:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r338895 - in projects/nfsv42/sys/fs: nfs nfsserver X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: in projects/nfsv42/sys/fs: nfs nfsserver X-SVN-Commit-Revision: 338895 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Sep 2018 02:16:50 -0000 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,