NFS - Stability pass / recent work.
[dragonfly.git] / sys / vfs / nfs / nfsm_subs.h
blobb10c76365303ac459d607ffe2b96561868d19c15
1 /*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
36 * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
37 * $FreeBSD: src/sys/nfs/nfsm_subs.h,v 1.27.2.1 2000/10/28 16:27:27 dwmalone Exp $
38 * $DragonFly: src/sys/vfs/nfs/nfsm_subs.h,v 1.10 2008/09/17 21:44:25 dillon Exp $
42 #ifndef _NFS_NFSM_SUBS_H_
43 #define _NFS_NFSM_SUBS_H_
45 struct ucred;
46 struct vnode;
48 enum nfsm_state {
49 NFSM_STATE_SETUP,
50 NFSM_STATE_AUTH,
51 NFSM_STATE_TRY,
52 NFSM_STATE_WAITREPLY,
53 NFSM_STATE_PROCESSREPLY,
54 NFSM_STATE_DONE
57 typedef enum nfsm_state nfsm_state_t;
60 struct nfsm_info {
62 * These fields are used by various nfsm_* functions during
63 * the construction or deconstruction of a RPC.
65 struct mbuf *mb;
66 struct mbuf *md;
67 struct mbuf *mrep;
68 struct mbuf *mreq;
69 caddr_t bpos;
70 caddr_t dpos;
71 int v3;
74 * These fields are used by the request processing state
75 * machine. mreq, md, dpos, and mrep above are also used.
77 nfsm_state_t state;
78 u_int32_t procnum;
79 struct vnode *vp;
80 struct thread *td;
81 struct ucred *cred;
82 struct nfsreq *req;
83 struct nfsmount *nmp;
84 int unused01;
85 int error;
88 * Retained state for higher level VOP and BIO operations
90 struct bio *bio;
91 void (*done)(struct nfsm_info *);
94 typedef struct nfsm_info *nfsm_info_t;
96 #define NULLOUT(nfsmexp) \
97 do { if ((nfsmexp) == NULL) { \
98 error = EBADRPC; goto nfsmout; } \
99 } while(0)
101 #define NEGATIVEOUT(nfsmexp) \
102 do { if ((nfsmexp) < 0) { \
103 error = EBADRPC; goto nfsmout; } \
104 } while(0)
106 #define NEGKEEPOUT(nfsmexp) \
107 do { if ((nfsmexp) < 0) { \
108 goto nfsmout; } \
109 } while(0)
111 #define NEGREPLYOUT(nfsmexp) \
112 do { \
113 int rv = (nfsmexp); \
114 if (rv < 0) { \
115 if (rv == -2) \
116 nfsm_reply(&info, nfsd, slp, 0, &error); \
117 goto nfsmout; \
119 } while(0)
121 #define ERROROUT(nfsmexp) if ((error = (nfsmexp)) != 0) goto nfsmout
124 * These macros do strange and peculiar things to mbuf chains for
125 * the assistance of the nfs code. To attempt to use them for any
126 * other purpose will be dangerous. (they make weird assumptions)
130 * First define what the actual subs. return
132 void nfsm_reqhead(nfsm_info_t info, struct vnode *vp,
133 u_long procid, int hsiz);
134 struct mbuf *nfsm_rpchead (struct ucred *cr, int nmflag, int procid,
135 int auth_type, int auth_len, char *auth_str,
136 int verf_len, char *verf_str,
137 struct mbuf *mrest, int mrest_len,
138 struct mbuf **mbp, u_int32_t *xidp);
139 void *nfsm_build(nfsm_info_t info, int bytes);
140 void *nfsm_dissect(nfsm_info_t info, int bytes);
141 int nfsm_fhtom(nfsm_info_t info, struct vnode *vp);
142 void nfsm_srvfhtom(nfsm_info_t info, fhandle_t *fhp);
143 void nfsm_srvpostop_fh(nfsm_info_t info, fhandle_t *fhp);
144 int nfsm_mtofh(nfsm_info_t info, struct vnode *dvp,
145 struct vnode **vpp, int *gotvpp);
146 int nfsm_getfh(nfsm_info_t info, nfsfh_t **fhpp);
147 int nfsm_loadattr(nfsm_info_t info, struct vnode *vp, struct vattr *vap);
148 int nfsm_postop_attr(nfsm_info_t info, struct vnode *vp,
149 int *attrp, int lflags);
150 int nfsm_wcc_data(nfsm_info_t info, struct vnode *vp, int *attrp);
151 void nfsm_v3attrbuild(nfsm_info_t info, struct vattr *vap, int full);
152 int nfsm_strsiz(nfsm_info_t info, int maxlen);
153 int nfsm_srvstrsiz(nfsm_info_t info, int maxlen, int *errorp);
154 int nfsm_srvnamesiz(nfsm_info_t info, int *errorp);
155 int nfsm_mtouio(nfsm_info_t info, struct uio *uiop, int len);
156 int nfsm_mtobio(nfsm_info_t info, struct bio *bio, int len);
158 int nfsm_uiotom(nfsm_info_t info, struct uio *uiop, int len);
159 int nfsm_biotom(nfsm_info_t info, struct bio *bio, int len);
160 int nfsm_request(nfsm_info_t info, struct vnode *vp, int procnum,
161 thread_t td, struct ucred *cred, int *errorp);
162 void nfsm_request_bio(nfsm_info_t info, struct vnode *vp, int procnum,
163 thread_t td, struct ucred *cred);
164 int nfsm_strtom(nfsm_info_t info, const void *data, int len, int maxlen);
165 int nfsm_reply(nfsm_info_t info, struct nfsrv_descript *nfsd,
166 struct nfssvc_sock *slp, int siz, int *errorp);
167 void nfsm_writereply(nfsm_info_t info, struct nfsrv_descript *nfsd,
168 struct nfssvc_sock *slp, int error, int siz);
169 int nfsm_adv(nfsm_info_t info, int len);
170 int nfsm_srvmtofh(nfsm_info_t info, struct nfsrv_descript *nfsd,
171 fhandle_t *fhp, int *errorp);
172 void *_nfsm_clget(nfsm_info_t info, struct mbuf **mp1, struct mbuf **mp2,
173 char **bp, char **be);
174 int nfsm_srvsattr(nfsm_info_t info, struct vattr *vap);
175 int nfsm_mbuftouio(struct mbuf **mrep, struct uio *uiop,
176 int siz, caddr_t *dpos);
177 int nfsm_mbuftobio(struct mbuf **mrep, struct bio *bio,
178 int siz, caddr_t *dpos);
179 int nfsm_uiotombuf (struct uio *uiop, struct mbuf **mq,
180 int siz, caddr_t *bpos);
181 int nfsm_biotombuf (struct bio *bio, struct mbuf **mq,
182 int siz, caddr_t *bpos);
183 int nfsm_disct(struct mbuf **mdp, caddr_t *dposp, int siz,
184 int left, caddr_t *cp2);
185 int nfsm_strtmbuf (struct mbuf **, char **, const char *, long);
186 void nfsm_adj(struct mbuf *mp, int len, int nul);
187 void nfsm_srvwcc_data(nfsm_info_t info, struct nfsrv_descript *nfsd,
188 int before_ret, struct vattr *before_vap,
189 int after_ret, struct vattr *after_vap);
190 void nfsm_srvpostop_attr(nfsm_info_t info, struct nfsrv_descript *nfsd,
191 int after_ret, struct vattr *after_vap);
192 void nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
193 struct nfs_fattr *fp);
195 int nfs_request (struct nfsm_info *, nfsm_state_t, nfsm_state_t);
197 #define nfsm_clget(info, mp1, mp2, bp, be) \
198 ((bp >= be) ? _nfsm_clget(info, &mp1, &mp2, &bp, &be) : (void *)bp)
200 #define nfsm_rndup(a) (((a) + 3) & (~0x3))
202 #define NFSV3_WCCRATTR 0
203 #define NFSV3_WCCCHK 1
205 #endif