HAMMER VFS - Fix serious bug when downgrading (and later upgrading) a PFS
[dragonfly.git] / sys / vfs / nfs / nfsm_subs.h
blobc0f93695f3aaf3670713fe77bc356dc522e8b197
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 *);
92 union {
93 struct {
94 int must_commit;
95 } writerpc;
96 } u;
99 #define info_writerpc u.writerpc
101 typedef struct nfsm_info *nfsm_info_t;
103 #define NULLOUT(nfsmexp) \
104 do { if ((nfsmexp) == NULL) { \
105 error = EBADRPC; goto nfsmout; } \
106 } while(0)
108 #define NEGATIVEOUT(nfsmexp) \
109 do { if ((nfsmexp) < 0) { \
110 error = EBADRPC; goto nfsmout; } \
111 } while(0)
113 #define NEGKEEPOUT(nfsmexp) \
114 do { if ((nfsmexp) < 0) { \
115 goto nfsmout; } \
116 } while(0)
118 #define NEGREPLYOUT(nfsmexp) \
119 do { \
120 int rv = (nfsmexp); \
121 if (rv < 0) { \
122 if (rv == -2) \
123 nfsm_reply(&info, nfsd, slp, 0, &error); \
124 goto nfsmout; \
126 } while(0)
128 #define ERROROUT(nfsmexp) if ((error = (nfsmexp)) != 0) goto nfsmout
131 * These macros do strange and peculiar things to mbuf chains for
132 * the assistance of the nfs code. To attempt to use them for any
133 * other purpose will be dangerous. (they make weird assumptions)
137 * First define what the actual subs. return
139 void nfsm_reqhead(nfsm_info_t info, struct vnode *vp,
140 u_long procid, int hsiz);
141 struct mbuf *nfsm_rpchead (struct ucred *cr, int nmflag, int procid,
142 int auth_type, int auth_len, char *auth_str,
143 int verf_len, char *verf_str,
144 struct mbuf *mrest, int mrest_len,
145 struct mbuf **mbp, u_int32_t *xidp);
146 void *nfsm_build(nfsm_info_t info, int bytes);
147 void *nfsm_dissect(nfsm_info_t info, int bytes);
148 int nfsm_fhtom(nfsm_info_t info, struct vnode *vp);
149 void nfsm_srvfhtom(nfsm_info_t info, fhandle_t *fhp);
150 void nfsm_srvpostop_fh(nfsm_info_t info, fhandle_t *fhp);
151 int nfsm_mtofh(nfsm_info_t info, struct vnode *dvp,
152 struct vnode **vpp, int *gotvpp);
153 int nfsm_getfh(nfsm_info_t info, nfsfh_t **fhpp);
154 int nfsm_loadattr(nfsm_info_t info, struct vnode *vp, struct vattr *vap);
155 int nfsm_postop_attr(nfsm_info_t info, struct vnode *vp,
156 int *attrp, int lflags);
157 int nfsm_wcc_data(nfsm_info_t info, struct vnode *vp, int *attrp);
158 void nfsm_v3attrbuild(nfsm_info_t info, struct vattr *vap, int full);
159 int nfsm_strsiz(nfsm_info_t info, int maxlen);
160 int nfsm_srvstrsiz(nfsm_info_t info, int maxlen, int *errorp);
161 int nfsm_srvnamesiz(nfsm_info_t info, int *errorp);
162 int nfsm_mtouio(nfsm_info_t info, struct uio *uiop, int len);
163 int nfsm_mtobio(nfsm_info_t info, struct bio *bio, int len);
165 int nfsm_uiotom(nfsm_info_t info, struct uio *uiop, int len);
166 int nfsm_biotom(nfsm_info_t info, struct bio *bio, int off, int len);
167 int nfsm_request(nfsm_info_t info, struct vnode *vp, int procnum,
168 thread_t td, struct ucred *cred, int *errorp);
169 void nfsm_request_bio(nfsm_info_t info, struct vnode *vp, int procnum,
170 thread_t td, struct ucred *cred);
171 int nfsm_strtom(nfsm_info_t info, const void *data, int len, int maxlen);
172 int nfsm_reply(nfsm_info_t info, struct nfsrv_descript *nfsd,
173 struct nfssvc_sock *slp, int siz, int *errorp);
174 void nfsm_writereply(nfsm_info_t info, struct nfsrv_descript *nfsd,
175 struct nfssvc_sock *slp, int error, int siz);
176 int nfsm_adv(nfsm_info_t info, int len);
177 int nfsm_srvmtofh(nfsm_info_t info, struct nfsrv_descript *nfsd,
178 fhandle_t *fhp, int *errorp);
179 void *_nfsm_clget(nfsm_info_t info, struct mbuf **mp1, struct mbuf **mp2,
180 char **bp, char **be);
181 int nfsm_srvsattr(nfsm_info_t info, struct vattr *vap);
182 int nfsm_mbuftouio(struct mbuf **mrep, struct uio *uiop,
183 int siz, caddr_t *dpos);
184 int nfsm_mbuftobio(struct mbuf **mrep, struct bio *bio,
185 int siz, caddr_t *dpos);
186 int nfsm_uiotombuf (struct uio *uiop, struct mbuf **mq,
187 int siz, caddr_t *bpos);
188 int nfsm_biotombuf (struct bio *bio, struct mbuf **mq, int off,
189 int siz, caddr_t *bpos);
190 int nfsm_disct(struct mbuf **mdp, caddr_t *dposp, int siz,
191 int left, caddr_t *cp2);
192 int nfsm_strtmbuf (struct mbuf **, char **, const char *, long);
193 void nfsm_adj(struct mbuf *mp, int len, int nul);
194 void nfsm_srvwcc_data(nfsm_info_t info, struct nfsrv_descript *nfsd,
195 int before_ret, struct vattr *before_vap,
196 int after_ret, struct vattr *after_vap);
197 void nfsm_srvpostop_attr(nfsm_info_t info, struct nfsrv_descript *nfsd,
198 int after_ret, struct vattr *after_vap);
199 void nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
200 struct nfs_fattr *fp);
202 int nfs_request (struct nfsm_info *, nfsm_state_t, nfsm_state_t);
204 #define nfsm_clget(info, mp1, mp2, bp, be) \
205 ((bp >= be) ? _nfsm_clget(info, &mp1, &mp2, &bp, &be) : (void *)bp)
207 #define nfsm_rndup(a) (((a) + 3) & (~0x3))
209 #define NFSV3_WCCRATTR 0
210 #define NFSV3_WCCCHK 1
212 #endif