puffs_priv.h revision 1.22 1 /* $NetBSD: puffs_priv.h,v 1.22 2007/09/27 21:14:49 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2006 Antti Kantee. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #ifndef _PUFFS_PRIVATE_H_
29 #define _PUFFS_PRIVATE_H_
30
31 #include <sys/types.h>
32 #include <fs/puffs/puffs_msgif.h>
33
34 #include <puffs.h>
35 #include <ucontext.h>
36
37 #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(c) : (struct puffs_node *)c)
38
39 struct puffs_framectrl {
40 puffs_framev_readframe_fn rfb;
41 puffs_framev_writeframe_fn wfb;
42 puffs_framev_cmpframe_fn cmpfb;
43 puffs_framev_gotframe_fn gotfb;
44 puffs_framev_fdnotify_fn fdnotfn;
45
46 struct kevent *evs;
47 size_t nfds;
48
49 struct timespec timeout;
50 struct timespec *timp;
51
52 LIST_HEAD(, puffs_fctrl_io) fb_ios;
53 LIST_HEAD(, puffs_fctrl_io) fb_ios_rmlist;
54 };
55
56 struct puffs_fctrl_io {
57 int io_fd;
58 int stat;
59
60 int rwait;
61 int wwait;
62
63 struct puffs_framebuf *cur_in;
64
65 TAILQ_HEAD(, puffs_framebuf) snd_qing; /* queueing to be sent */
66 TAILQ_HEAD(, puffs_framebuf) res_qing; /* q'ing for rescue */
67 LIST_HEAD(, puffs_fbevent) ev_qing; /* q'ing for events */
68
69 LIST_ENTRY(puffs_fctrl_io) fio_entries;
70 };
71 #define FIO_WR 0x01
72 #define FIO_WRGONE 0x02
73 #define FIO_RDGONE 0x04
74 #define FIO_DEAD 0x08
75 #define FIO_ENABLE_R 0x10
76 #define FIO_ENABLE_W 0x20
77
78 #define FIO_EN_WRITE(fio) \
79 (!(fio->stat & FIO_WR) \
80 && ((!TAILQ_EMPTY(&fio->snd_qing) \
81 && (fio->stat & FIO_ENABLE_W)) \
82 || fio->wwait))
83
84 #define FIO_RM_WRITE(fio) \
85 ((fio->stat & FIO_WR) \
86 && (((TAILQ_EMPTY(&fio->snd_qing) \
87 || (fio->stat & FIO_ENABLE_W) == 0)) \
88 && (fio->wwait == 0)))
89
90 /*
91 * usermount: describes one file system instance
92 */
93 struct puffs_usermount {
94 struct puffs_ops pu_ops;
95
96 int pu_fd;
97 size_t pu_maxreqlen;
98
99 uint32_t pu_flags;
100 size_t pu_cc_stacksize;
101
102 int pu_kq;
103 int pu_haskq;
104 int pu_state;
105 #define PU_STATEMASK 0xff
106 #define PU_INLOOP 0x100
107 #define PU_ASYNCFD 0x200
108 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
109
110 struct puffs_node *pu_pn_root;
111
112 LIST_HEAD(, puffs_node) pu_pnodelst;
113 LIST_HEAD(, puffs_cc) pu_ccnukelst;
114
115 struct puffs_node *(*pu_cmap)(void *);
116
117 pu_pathbuild_fn pu_pathbuild;
118 pu_pathtransform_fn pu_pathtransform;
119 pu_pathcmp_fn pu_pathcmp;
120 pu_pathfree_fn pu_pathfree;
121 pu_namemod_fn pu_namemod;
122
123 pu_errnotify_fn pu_errnotify;
124
125 struct puffs_framectrl pu_framectrl;
126
127 puffs_ml_loop_fn pu_ml_lfn;
128 struct timespec pu_ml_timeout;
129 struct timespec *pu_ml_timep;
130
131 struct puffs_kargs *pu_kargp;
132
133 void *pu_privdata;
134 };
135
136 /* call context */
137
138 struct puffs_cc {
139 struct puffs_usermount *pcc_pu;
140 struct puffs_req *pcc_preq;
141
142 ucontext_t pcc_uc; /* "continue" */
143 ucontext_t pcc_uc_ret; /* "yield" */
144 void *pcc_stack;
145
146 int pcc_flags;
147 struct puffs_putreq *pcc_ppr;
148
149 TAILQ_ENTRY(puffs_cc) entries;
150 LIST_ENTRY(puffs_cc) nlst_entries;
151 };
152 #define PCC_FAKECC 0x01
153 #define PCC_REALCC 0x02
154 #define PCC_DONE 0x04
155 #define PCC_BORROWED 0x08
156
157 #define pcc_callstat(a) (a->pcc_flags & PCC_CALL_MASK)
158 #define pcc_callset(a, b) (a->pcc_flags = (a->pcc_flags & ~PCC_CALL_MASK) | b)
159
160 #define pcc_init_local(ap) \
161 do { \
162 memset(ap, 0, sizeof(*ap)); \
163 (ap)->pcc_flags = PCC_FAKECC; \
164 } while (/*CONSTCOND*/0)
165
166 /*
167 * Reqs
168 */
169
170 struct puffs_getreq {
171 struct puffs_usermount *pgr_pu;
172
173 struct puffs_reqh_get pgr_phg;
174 struct puffs_reqh_get pgr_phg_orig;
175
176 struct puffs_req *pgr_nextpreq;
177 size_t pgr_advance;
178
179 /* diagnostics */
180 int pgr_nppr;
181 };
182
183 struct puffs_putreq {
184 struct puffs_usermount *ppr_pu;
185
186 struct puffs_reqh_put ppr_php;
187
188 /* to adjust next request info */
189 void **ppr_buf;
190 size_t *ppr_buflen;
191 uint64_t *ppr_id;
192
193 /* for delayed action freeing of preq's */
194 TAILQ_HEAD(, puffs_cc) ppr_pccq;
195
196 /* diagnostics */
197 struct puffs_getreq *ppr_pgr;
198 };
199
200 struct puffs_newinfo {
201 void **pni_cookie;
202 enum vtype *pni_vtype;
203 voff_t *pni_size;
204 dev_t *pni_rdev;
205 };
206
207 #define PUFFS_MAKEKCRED(to, from) \
208 /*LINTED: tnilxnaht, the cast is ok */ \
209 const struct puffs_kcred *to = (const void *)from
210 #define PUFFS_MAKECRED(to, from) \
211 /*LINTED: tnilxnaht, the cast is ok */ \
212 const struct puffs_cred *to = (const void *)from
213 #define PUFFS_KCREDTOCRED(to, from) \
214 /*LINTED: tnilxnaht, the cast is ok */ \
215 to = (void *)from
216
217 #define PUFFS_MAKEKCID(to, from) \
218 /*LINTED: tnilxnaht, the cast is ok */ \
219 const struct puffs_kcid *to = (const void *)from
220 #define PUFFS_MAKECID(to, from) \
221 /*LINTED: tnilxnaht, the cast is ok */ \
222 const struct puffs_cid *to = (const void *)from
223 #define PUFFS_KCIDTOCID(to, from) \
224 /*LINTED: tnilxnaht, the cast is ok */ \
225 to = (void *)from
226
227 __BEGIN_DECLS
228
229 void puffs_calldispatcher(struct puffs_cc *);
230
231 void puffs_framev_input(struct puffs_usermount *, struct puffs_framectrl *,
232 struct puffs_fctrl_io *, struct puffs_putreq *);
233 int puffs_framev_output(struct puffs_usermount *, struct puffs_framectrl*,
234 struct puffs_fctrl_io *, struct puffs_putreq *);
235 void puffs_framev_exit(struct puffs_usermount *);
236 void puffs_framev_readclose(struct puffs_usermount *,
237 struct puffs_fctrl_io *, int);
238 void puffs_framev_writeclose(struct puffs_usermount *,
239 struct puffs_fctrl_io *, int);
240 void puffs_framev_notify(struct puffs_fctrl_io *, int);
241
242 struct puffs_cc *puffs_cc_create(struct puffs_usermount *);
243 void puffs_cc_destroy(struct puffs_cc *);
244 void puffs_goto(struct puffs_cc *);
245
246 __END_DECLS
247
248 #endif /* _PUFFS_PRIVATE_H_ */
249