puffs_priv.h revision 1.16 1 /* $NetBSD: puffs_priv.h,v 1.16 2007/07/01 18:39:39 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_fdnotify_fn fdnotfn;
44
45 struct kevent *evs;
46 size_t nfds;
47
48 struct timespec timeout;
49 struct timespec *timp;
50
51 LIST_HEAD(, puffs_fctrl_io) fb_ios;
52 LIST_HEAD(, puffs_fctrl_io) fb_ios_rmlist;
53 };
54
55 struct puffs_fctrl_io {
56 int io_fd;
57 int stat;
58
59 struct puffs_framebuf *cur_in;
60
61 TAILQ_HEAD(, puffs_framebuf) snd_qing; /* queueing to be sent */
62 TAILQ_HEAD(, puffs_framebuf) res_qing; /* q'ing for rescue */
63
64 LIST_ENTRY(puffs_fctrl_io) fio_entries;
65 };
66 #define FIO_WR 0x01
67 #define FIO_WRGONE 0x02
68 #define FIO_RDGONE 0x04
69 #define FIO_DEAD 0x08
70
71 #define FIO_EN_WRITE(fio) (!(fio->stat & FIO_WR)&& !TAILQ_EMPTY(&fio->snd_qing))
72 #define FIO_RM_WRITE(fio) ((fio->stat & FIO_WR) && TAILQ_EMPTY(&fio->snd_qing))
73
74 /*
75 * usermount: describes one file system instance
76 */
77 struct puffs_usermount {
78 struct puffs_ops pu_ops;
79 struct puffs_kargs pu_kargs;
80
81 uint32_t pu_flags;
82 size_t pu_cc_stacksize;
83
84 int pu_kq;
85 int pu_haskq;
86 int pu_state;
87 #define PU_STATEMASK 0xff
88 #define PU_INLOOP 0x100
89 #define PU_ASYNCFD 0x200
90 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
91
92 struct puffs_node *pu_pn_root;
93
94 LIST_HEAD(, puffs_node) pu_pnodelst;
95 LIST_HEAD(, puffs_cc) pu_ccnukelst;
96
97 struct puffs_node *(*pu_cmap)(void *);
98
99 pu_pathbuild_fn pu_pathbuild;
100 pu_pathtransform_fn pu_pathtransform;
101 pu_pathcmp_fn pu_pathcmp;
102 pu_pathfree_fn pu_pathfree;
103 pu_namemod_fn pu_namemod;
104
105 struct puffs_framectrl pu_framectrl;
106
107 puffs_ml_loop_fn pu_ml_lfn;
108 struct timespec pu_ml_timeout;
109 struct timespec *pu_ml_timep;
110
111 void *pu_privdata;
112 };
113
114 /* call context */
115
116 struct puffs_cc {
117 struct puffs_usermount *pcc_pu;
118 struct puffs_req *pcc_preq;
119
120 ucontext_t pcc_uc; /* "continue" */
121 ucontext_t pcc_uc_ret; /* "yield" */
122 void *pcc_stack;
123
124 int pcc_flags;
125 struct puffs_putreq *pcc_ppr;
126
127 TAILQ_ENTRY(puffs_cc) entries;
128 LIST_ENTRY(puffs_cc) nlst_entries;
129 };
130 #define PCC_FAKECC 0x01
131 #define PCC_REALCC 0x02
132 #define PCC_DONE 0x04
133 #define PCC_BORROWED 0x08
134
135 #define pcc_callstat(a) (a->pcc_flags & PCC_CALL_MASK)
136 #define pcc_callset(a, b) (a->pcc_flags = (a->pcc_flags & ~PCC_CALL_MASK) | b)
137
138 #define pcc_init_local(ap) \
139 do { \
140 memset(ap, 0, sizeof(*ap)); \
141 (ap)->pcc_flags = PCC_FAKECC; \
142 } while (/*CONSTCOND*/0)
143
144 /*
145 * Reqs
146 */
147
148 struct puffs_getreq {
149 struct puffs_usermount *pgr_pu;
150
151 struct puffs_reqh_get pgr_phg;
152 struct puffs_reqh_get pgr_phg_orig;
153
154 struct puffs_req *pgr_nextpreq;
155 size_t pgr_advance;
156
157 /* diagnostics */
158 int pgr_nppr;
159 };
160
161 struct puffs_putreq {
162 struct puffs_usermount *ppr_pu;
163
164 struct puffs_reqh_put ppr_php;
165
166 /* to adjust next request info */
167 void **ppr_buf;
168 size_t *ppr_buflen;
169 uint64_t *ppr_id;
170
171 /* for delayed action freeing of preq's */
172 TAILQ_HEAD(, puffs_cc) ppr_pccq;
173
174 /* diagnostics */
175 struct puffs_getreq *ppr_pgr;
176 };
177
178 struct puffs_newinfo {
179 void **pni_cookie;
180 enum vtype *pni_vtype;
181 voff_t *pni_size;
182 dev_t *pni_rdev;
183 };
184
185 #define PUFFS_MAKEKCRED(to, from) \
186 /*LINTED: tnilxnaht, the cast is ok */ \
187 const struct puffs_kcred *to = (const void *)from
188 #define PUFFS_MAKECRED(to, from) \
189 /*LINTED: tnilxnaht, the cast is ok */ \
190 const struct puffs_cred *to = (const void *)from
191 #define PUFFS_KCREDTOCRED(to, from) \
192 /*LINTED: tnilxnaht, the cast is ok */ \
193 to = (void *)from
194
195 #define PUFFS_MAKEKCID(to, from) \
196 /*LINTED: tnilxnaht, the cast is ok */ \
197 const struct puffs_kcid *to = (const void *)from
198 #define PUFFS_MAKECID(to, from) \
199 /*LINTED: tnilxnaht, the cast is ok */ \
200 const struct puffs_cid *to = (const void *)from
201 #define PUFFS_KCIDTOCID(to, from) \
202 /*LINTED: tnilxnaht, the cast is ok */ \
203 to = (void *)from
204
205 __BEGIN_DECLS
206
207 void puffs_calldispatcher(struct puffs_cc *);
208
209 void puffs_framev_input(struct puffs_usermount *, struct puffs_framectrl *,
210 struct puffs_fctrl_io *, struct puffs_putreq *);
211 int puffs_framev_output(struct puffs_usermount *, struct puffs_framectrl*,
212 struct puffs_fctrl_io *);
213 void puffs_framev_exit(struct puffs_usermount *);
214 void puffs_framev_readclose(struct puffs_usermount *,
215 struct puffs_fctrl_io *, int);
216 void puffs_framev_writeclose(struct puffs_usermount *,
217 struct puffs_fctrl_io *, int);
218
219 void puffs_goto(struct puffs_cc *);
220
221 __END_DECLS
222
223 #endif /* _PUFFS_PRIVATE_H_ */
224