puffs_priv.h revision 1.33 1 /* $NetBSD: puffs_priv.h,v 1.33 2007/12/04 21:24:12 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 #ifdef PUFFS_WITH_THREADS
38 #include <pthread.h>
39
40 extern pthread_mutex_t pu_lock;
41 #define PU_LOCK() pthread_mutex_lock(&pu_lock)
42 #define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
43 #else
44 #define PU_LOCK()
45 #define PU_UNLOCK()
46 #endif
47
48 #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(c) : (struct puffs_node *)c)
49
50 struct puffs_framectrl {
51 puffs_framev_readframe_fn rfb;
52 puffs_framev_writeframe_fn wfb;
53 puffs_framev_cmpframe_fn cmpfb;
54 puffs_framev_gotframe_fn gotfb;
55 puffs_framev_fdnotify_fn fdnotfn;
56 };
57
58 struct puffs_fctrl_io {
59 struct puffs_framectrl *fctrl;
60
61 int io_fd;
62 int stat;
63
64 int rwait;
65 int wwait;
66
67 struct puffs_framebuf *cur_in;
68
69 TAILQ_HEAD(, puffs_framebuf) snd_qing; /* queueing to be sent */
70 TAILQ_HEAD(, puffs_framebuf) res_qing; /* q'ing for rescue */
71 LIST_HEAD(, puffs_fbevent) ev_qing; /* q'ing for events */
72
73 LIST_ENTRY(puffs_fctrl_io) fio_entries;
74 };
75 #define FIO_WR 0x01
76 #define FIO_WRGONE 0x02
77 #define FIO_RDGONE 0x04
78 #define FIO_DEAD 0x08
79 #define FIO_ENABLE_R 0x10
80 #define FIO_ENABLE_W 0x20
81
82 #define FIO_EN_WRITE(fio) \
83 (!(fio->stat & FIO_WR) \
84 && ((!TAILQ_EMPTY(&fio->snd_qing) \
85 && (fio->stat & FIO_ENABLE_W)) \
86 || fio->wwait))
87
88 #define FIO_RM_WRITE(fio) \
89 ((fio->stat & FIO_WR) \
90 && (((TAILQ_EMPTY(&fio->snd_qing) \
91 || (fio->stat & FIO_ENABLE_W) == 0)) \
92 && (fio->wwait == 0)))
93
94 struct puffs_executor {
95 struct puffs_framebuf *pex_pufbuf;
96 TAILQ_ENTRY(puffs_executor) pex_entries;
97 };
98
99 /*
100 * usermount: describes one file system instance
101 */
102 struct puffs_usermount {
103 struct puffs_ops pu_ops;
104
105 int pu_fd;
106 size_t pu_maxreqlen;
107
108 uint32_t pu_flags;
109 int pu_cc_stackshift;
110
111 int pu_kq;
112 int pu_state;
113 #define PU_STATEMASK 0xff
114 #define PU_INLOOP 0x100
115 #define PU_ASYNCFD 0x200
116 #define PU_HASKQ 0x400
117 #define PU_PUFFSDAEMON 0x800
118 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
119 int pu_dpipe[2];
120
121 struct puffs_node *pu_pn_root;
122
123 LIST_HEAD(, puffs_node) pu_pnodelst;
124 LIST_HEAD(, puffs_cc) pu_ccnukelst;
125 TAILQ_HEAD(, puffs_cc) pu_sched;
126
127 TAILQ_HEAD(, puffs_executor) pu_exq;
128
129 struct puffs_node *(*pu_cmap)(void *);
130
131 pu_pathbuild_fn pu_pathbuild;
132 pu_pathtransform_fn pu_pathtransform;
133 pu_pathcmp_fn pu_pathcmp;
134 pu_pathfree_fn pu_pathfree;
135 pu_namemod_fn pu_namemod;
136
137 pu_errnotify_fn pu_errnotify;
138
139 pu_prepost_fn pu_oppre;
140 pu_prepost_fn pu_oppost;
141
142 struct puffs_framectrl pu_framectrl[2];
143 #define PU_FRAMECTRL_FS 0
144 #define PU_FRAMECTRL_USER 1
145 LIST_HEAD(, puffs_fctrl_io) pu_ios;
146 LIST_HEAD(, puffs_fctrl_io) pu_ios_rmlist;
147 struct kevent *pu_evs;
148 size_t pu_nfds;
149
150 puffs_ml_loop_fn pu_ml_lfn;
151 struct timespec pu_ml_timeout;
152 struct timespec *pu_ml_timep;
153
154 struct puffs_kargs *pu_kargp;
155
156 void *pu_privdata;
157 };
158
159 /* call context */
160
161 struct puffs_cc {
162 struct puffs_usermount *pcc_pu;
163 struct puffs_framebuf *pcc_pb;
164
165 ucontext_t pcc_uc; /* "continue" */
166 ucontext_t pcc_uc_ret; /* "yield" */
167 void *pcc_stack;
168
169 pid_t pcc_pid;
170 lwpid_t pcc_lid;
171
172 int pcc_flags;
173
174 TAILQ_ENTRY(puffs_cc) entries;
175 LIST_ENTRY(puffs_cc) nlst_entries;
176 };
177 #define PCC_FAKECC 0x01
178 #define PCC_REALCC 0x02
179 #define PCC_DONE 0x04
180 #define PCC_BORROWED 0x08
181 #define PCC_HASCALLER 0x10
182 #define PCC_THREADED 0x20
183
184 #define pcc_callstat(a) (a->pcc_flags & PCC_CALL_MASK)
185 #define pcc_callset(a, b) (a->pcc_flags = (a->pcc_flags & ~PCC_CALL_MASK) | b)
186
187 #define pcc_init_unreal(ap, type) \
188 do { \
189 memset(ap, 0, sizeof(*ap)); \
190 (ap)->pcc_flags = type; \
191 } while (/*CONSTCOND*/0)
192
193 struct puffs_newinfo {
194 void **pni_cookie;
195 enum vtype *pni_vtype;
196 voff_t *pni_size;
197 dev_t *pni_rdev;
198 };
199
200 #define PUFFS_MAKEKCRED(to, from) \
201 /*LINTED: tnilxnaht, the cast is ok */ \
202 const struct puffs_kcred *to = (const void *)from
203 #define PUFFS_MAKECRED(to, from) \
204 /*LINTED: tnilxnaht, the cast is ok */ \
205 const struct puffs_cred *to = (const void *)from
206 #define PUFFS_KCREDTOCRED(to, from) \
207 /*LINTED: tnilxnaht, the cast is ok */ \
208 to = (void *)from
209
210 #define PUFFS_MAKEKCID(to, from) \
211 /*LINTED: tnilxnaht, the cast is ok */ \
212 const struct puffs_kcid *to = (const void *)from
213 #define PUFFS_MAKECID(to, from) \
214 /*LINTED: tnilxnaht, the cast is ok */ \
215 const struct puffs_cid *to = (const void *)from
216 #define PUFFS_KCIDTOCID(to, from) \
217 /*LINTED: tnilxnaht, the cast is ok */ \
218 to = (void *)from
219
220 __BEGIN_DECLS
221
222 void puffs_calldispatcher(struct puffs_cc *);
223
224 void puffs_framev_input(struct puffs_usermount *, struct puffs_framectrl *,
225 struct puffs_fctrl_io *);
226 int puffs_framev_output(struct puffs_usermount *, struct puffs_framectrl*,
227 struct puffs_fctrl_io *);
228 void puffs_framev_exit(struct puffs_usermount *);
229 void puffs_framev_readclose(struct puffs_usermount *,
230 struct puffs_fctrl_io *, int);
231 void puffs_framev_writeclose(struct puffs_usermount *,
232 struct puffs_fctrl_io *, int);
233 void puffs_framev_notify(struct puffs_fctrl_io *, int);
234 void *puffs__framebuf_getdataptr(struct puffs_framebuf *);
235 int puffs__framev_addfd_ctrl(struct puffs_usermount *, int, int,
236 struct puffs_framectrl *);
237 void puffs__framebuf_moveinfo(struct puffs_framebuf *,
238 struct puffs_framebuf *);
239
240 int puffs_cc_create(struct puffs_usermount *, struct puffs_framebuf *,
241 int, struct puffs_cc **);
242 void puffs_cc_destroy(struct puffs_cc *);
243 void puffs_cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
244 void puffs_goto(struct puffs_cc *);
245
246 int puffs_fsframe_read(struct puffs_usermount *, struct puffs_framebuf *,
247 int, int *);
248 int puffs_fsframe_write(struct puffs_usermount *, struct puffs_framebuf *,
249 int, int *);
250 int puffs_fsframe_cmp(struct puffs_usermount *, struct puffs_framebuf *,
251 struct puffs_framebuf *, int *);
252 void puffs_fsframe_gotframe(struct puffs_usermount *,
253 struct puffs_framebuf *);
254
255 int puffs_dopufbuf(struct puffs_usermount *, struct puffs_framebuf *);
256 void *puffs_docc(void *);
257
258 __END_DECLS
259
260 #endif /* _PUFFS_PRIVATE_H_ */
261