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