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