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