puffs_priv.h revision 1.25 1 /* $NetBSD: puffs_priv.h,v 1.25 2007/10/21 19:25:58 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 TAILQ_HEAD(, puffs_cc) pu_sched;
115
116 struct puffs_node *(*pu_cmap)(void *);
117
118 pu_pathbuild_fn pu_pathbuild;
119 pu_pathtransform_fn pu_pathtransform;
120 pu_pathcmp_fn pu_pathcmp;
121 pu_pathfree_fn pu_pathfree;
122 pu_namemod_fn pu_namemod;
123
124 pu_errnotify_fn pu_errnotify;
125
126 struct puffs_framectrl pu_framectrl;
127
128 puffs_ml_loop_fn pu_ml_lfn;
129 struct timespec pu_ml_timeout;
130 struct timespec *pu_ml_timep;
131
132 struct puffs_kargs *pu_kargp;
133
134 void *pu_privdata;
135 };
136
137 /* call context */
138
139 struct puffs_cc {
140 struct puffs_usermount *pcc_pu;
141 struct puffs_req *pcc_preq;
142
143 ucontext_t pcc_uc; /* "continue" */
144 ucontext_t pcc_uc_ret; /* "yield" */
145 void *pcc_stack;
146
147 pid_t pcc_pid;
148 lwpid_t pcc_lid;
149
150 int pcc_flags;
151 struct puffs_putreq *pcc_ppr;
152
153 TAILQ_ENTRY(puffs_cc) entries;
154 LIST_ENTRY(puffs_cc) nlst_entries;
155 };
156 #define PCC_FAKECC 0x01
157 #define PCC_REALCC 0x02
158 #define PCC_DONE 0x04
159 #define PCC_BORROWED 0x08
160 #define PCC_HASCALLER 0x10
161
162 #define pcc_callstat(a) (a->pcc_flags & PCC_CALL_MASK)
163 #define pcc_callset(a, b) (a->pcc_flags = (a->pcc_flags & ~PCC_CALL_MASK) | b)
164
165 #define pcc_init_local(ap) \
166 do { \
167 memset(ap, 0, sizeof(*ap)); \
168 (ap)->pcc_flags = PCC_FAKECC; \
169 } while (/*CONSTCOND*/0)
170
171 /*
172 * Reqs
173 */
174
175 struct puffs_getreq {
176 struct puffs_usermount *pgr_pu;
177
178 void *pgr_buf;
179 };
180
181 struct puffs_putreq {
182 struct puffs_usermount *ppr_pu;
183
184 TAILQ_HEAD(, puffs_cc) ppr_pccq;
185 };
186
187 struct puffs_newinfo {
188 void **pni_cookie;
189 enum vtype *pni_vtype;
190 voff_t *pni_size;
191 dev_t *pni_rdev;
192 };
193
194 #define PUFFS_MAKEKCRED(to, from) \
195 /*LINTED: tnilxnaht, the cast is ok */ \
196 const struct puffs_kcred *to = (const void *)from
197 #define PUFFS_MAKECRED(to, from) \
198 /*LINTED: tnilxnaht, the cast is ok */ \
199 const struct puffs_cred *to = (const void *)from
200 #define PUFFS_KCREDTOCRED(to, from) \
201 /*LINTED: tnilxnaht, the cast is ok */ \
202 to = (void *)from
203
204 #define PUFFS_MAKEKCID(to, from) \
205 /*LINTED: tnilxnaht, the cast is ok */ \
206 const struct puffs_kcid *to = (const void *)from
207 #define PUFFS_MAKECID(to, from) \
208 /*LINTED: tnilxnaht, the cast is ok */ \
209 const struct puffs_cid *to = (const void *)from
210 #define PUFFS_KCIDTOCID(to, from) \
211 /*LINTED: tnilxnaht, the cast is ok */ \
212 to = (void *)from
213
214 __BEGIN_DECLS
215
216 void puffs_calldispatcher(struct puffs_cc *);
217
218 void puffs_framev_input(struct puffs_usermount *, struct puffs_framectrl *,
219 struct puffs_fctrl_io *, struct puffs_putreq *);
220 int puffs_framev_output(struct puffs_usermount *, struct puffs_framectrl*,
221 struct puffs_fctrl_io *, struct puffs_putreq *);
222 void puffs_framev_exit(struct puffs_usermount *);
223 void puffs_framev_readclose(struct puffs_usermount *,
224 struct puffs_fctrl_io *, int);
225 void puffs_framev_writeclose(struct puffs_usermount *,
226 struct puffs_fctrl_io *, int);
227 void puffs_framev_notify(struct puffs_fctrl_io *, int);
228
229 struct puffs_cc *puffs_cc_create(struct puffs_usermount *);
230 void puffs_cc_destroy(struct puffs_cc *);
231 void puffs_cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
232 void puffs_goto(struct puffs_cc *);
233
234 __END_DECLS
235
236 #endif /* _PUFFS_PRIVATE_H_ */
237