2 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
3 * Copyright (c) 2013 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/sysproto.h>
33 #include <sys/kernel.h>
34 #include <sys/vnode.h>
35 #include <sys/malloc.h>
36 #include <sys/mount.h>
38 #include <sys/sysctl.h>
41 #include <nfs/xdr_subs.h>
42 #include <nfs/nfsproto.h>
43 #include <nfs/nfs_fha.h>
44 #include <nfsserver/nfs.h>
45 #include <nfsserver/nfsm_subs.h>
46 #include <nfsserver/nfs_fha_old.h>
48 static void fhaold_init(void *foo);
49 static void fhaold_uninit(void *foo);
50 rpcproc_t fhaold_get_procnum(rpcproc_t procnum);
51 int fhaold_realign(struct mbuf **mb, int malloc_flags);
52 int fhaold_get_fh(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos);
53 int fhaold_is_read(rpcproc_t procnum);
54 int fhaold_is_write(rpcproc_t procnum);
55 int fhaold_get_offset(struct mbuf **md, caddr_t *dpos, int v3,
56 struct fha_info *info);
57 int fhaold_no_offset(rpcproc_t procnum);
58 void fhaold_set_locktype(rpcproc_t procnum, struct fha_info *info);
59 static int fheold_stats_sysctl(SYSCTL_HANDLER_ARGS);
61 static struct fha_params fhaold_softc;
63 SYSCTL_DECL(_vfs_nfsrv);
65 extern SVCPOOL *nfsrv_pool;
67 SYSINIT(nfs_fhaold, SI_SUB_ROOT_CONF, SI_ORDER_ANY, fhaold_init, NULL);
68 SYSUNINIT(nfs_fhaold, SI_SUB_ROOT_CONF, SI_ORDER_ANY, fhaold_uninit, NULL);
71 fhaold_init(void *foo)
73 struct fha_params *softc;
75 softc = &fhaold_softc;
77 bzero(softc, sizeof(*softc));
80 * Setup the callbacks for this FHA personality.
82 softc->callbacks.get_procnum = fhaold_get_procnum;
83 softc->callbacks.realign = fhaold_realign;
84 softc->callbacks.get_fh = fhaold_get_fh;
85 softc->callbacks.is_read = fhaold_is_read;
86 softc->callbacks.is_write = fhaold_is_write;
87 softc->callbacks.get_offset = fhaold_get_offset;
88 softc->callbacks.no_offset = fhaold_no_offset;
89 softc->callbacks.set_locktype = fhaold_set_locktype;
90 softc->callbacks.fhe_stats_sysctl = fheold_stats_sysctl;
92 snprintf(softc->server_name, sizeof(softc->server_name),
95 softc->pool = &nfsrv_pool;
98 * Initialize the sysctl context list for the fha module.
100 sysctl_ctx_init(&softc->sysctl_ctx);
101 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
102 SYSCTL_STATIC_CHILDREN(_vfs_nfsrv), OID_AUTO, "fha", CTLFLAG_RD,
104 if (softc->sysctl_tree == NULL) {
105 printf("%s: unable to allocate sysctl tree\n", __func__);
112 fhaold_uninit(void *foo)
114 struct fha_params *softc;
116 softc = &fhaold_softc;
123 fhaold_get_procnum(rpcproc_t procnum)
125 if (procnum > NFSV2PROC_STATFS)
128 return (nfsrv_nfsv3_procid[procnum]);
132 fhaold_realign(struct mbuf **mb, int malloc_flags)
134 return (nfs_realign(mb, malloc_flags));
138 fhaold_get_fh(fhandle_t *fh, int v3, struct mbuf **md, caddr_t *dpos)
140 return (nfsm_srvmtofh_xx(fh, v3, md, dpos));
144 fhaold_is_read(rpcproc_t procnum)
146 if (procnum == NFSPROC_READ)
153 fhaold_is_write(rpcproc_t procnum)
155 if (procnum == NFSPROC_WRITE)
162 fhaold_get_offset(struct mbuf **md, caddr_t *dpos, int v3,
163 struct fha_info *info)
168 tl = nfsm_dissect_xx_nonblock(2 * NFSX_UNSIGNED, md, dpos);
171 info->offset = fxdr_hyper(tl);
173 tl = nfsm_dissect_xx_nonblock(NFSX_UNSIGNED, md, dpos);
176 info->offset = fxdr_unsigned(uint32_t, *tl);
185 fhaold_no_offset(rpcproc_t procnum)
187 if (procnum == NFSPROC_FSSTAT ||
188 procnum == NFSPROC_FSINFO ||
189 procnum == NFSPROC_PATHCONF ||
190 procnum == NFSPROC_NOOP ||
191 procnum == NFSPROC_NULL)
198 fhaold_set_locktype(rpcproc_t procnum, struct fha_info *info)
202 case NFSPROC_GETATTR:
205 case NFSPROC_READLINK:
207 case NFSPROC_READDIR:
208 case NFSPROC_READDIRPLUS:
210 info->locktype = LK_SHARED;
212 case NFSPROC_SETATTR:
215 case NFSPROC_SYMLINK:
223 case NFSPROC_PATHCONF:
226 info->locktype = LK_EXCLUSIVE;
232 fheold_stats_sysctl(SYSCTL_HANDLER_ARGS)
234 return (fhe_stats_sysctl(oidp, arg1, arg2, req, &fhaold_softc));
238 fhaold_assign(SVCTHREAD *this_thread, struct svc_req *req)
240 return (fha_assign(this_thread, req, &fhaold_softc));