puffs_priv.h revision 1.10 1 /* $NetBSD: puffs_priv.h,v 1.10 2007/05/15 13:44:47 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 * 3. The name of the company nor the name of the author may be used to
15 * endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #ifndef _PUFFS_PRIVATE_H_
32 #define _PUFFS_PRIVATE_H_
33
34 #include <sys/types.h>
35 #include <fs/puffs/puffs_msgif.h>
36
37 #include <puffs.h>
38 #include <ucontext.h>
39
40 #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(c) : (struct puffs_node *)c)
41
42 struct puffs_framectrl {
43 puffs_framev_readframe_fn rfb;
44 puffs_framev_writeframe_fn wfb;
45 puffs_framev_respcmp_fn cmpfb;
46 puffs_framev_fdnotify_fn fdnotfn;
47
48 struct kevent *evs;
49 size_t nfds;
50
51 struct timespec timeout;
52 struct timespec *timp;
53
54 LIST_HEAD(, puffs_fctrl_io) fb_ios;
55 LIST_HEAD(, puffs_fctrl_io) fb_ios_rmlist;
56 };
57
58 struct puffs_fctrl_io {
59 int io_fd;
60 int stat;
61
62 struct puffs_framebuf *cur_in;
63
64 TAILQ_HEAD(, puffs_framebuf) snd_qing; /* queueing to be sent */
65 TAILQ_HEAD(, puffs_framebuf) res_qing; /* q'ing for rescue */
66
67 LIST_ENTRY(puffs_fctrl_io) fio_entries;
68 };
69 #define FIO_WR 0x01
70 #define FIO_WRGONE 0x02
71 #define FIO_RDGONE 0x04
72 #define FIO_DEAD 0x08
73
74 #define FIO_EN_WRITE(fio) (!(fio->stat & FIO_WR)&& !TAILQ_EMPTY(&fio->snd_qing))
75 #define FIO_RM_WRITE(fio) ((fio->stat & FIO_WR) && TAILQ_EMPTY(&fio->snd_qing))
76
77 /*
78 * usermount: describes one file system instance
79 */
80 struct puffs_usermount {
81 struct puffs_ops pu_ops;
82 struct puffs_kargs pu_kargs;
83
84 uint32_t pu_flags;
85 size_t pu_cc_stacksize;
86
87 int pu_kq;
88 int pu_haskq;
89 int pu_state;
90 #define PU_STATEMASK 0xff
91 #define PU_INLOOP 0x100
92 #define PU_ASYNCFD 0x200
93 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
94
95 struct puffs_node *pu_pn_root;
96
97 LIST_HEAD(, puffs_node) pu_pnodelst;
98 LIST_HEAD(, puffs_cc) pu_ccnukelst;
99
100 struct puffs_node *(*pu_cmap)(void *);
101
102 pu_pathbuild_fn pu_pathbuild;
103 pu_pathtransform_fn pu_pathtransform;
104 pu_pathcmp_fn pu_pathcmp;
105 pu_pathfree_fn pu_pathfree;
106 pu_namemod_fn pu_namemod;
107
108 struct puffs_framectrl pu_framectrl;
109
110 puffs_ml_loop_fn pu_ml_lfn;
111 struct timespec pu_ml_timeout;
112 struct timespec *pu_ml_timep;
113
114 void *pu_privdata;
115 };
116
117 /* call context */
118
119 struct puffs_cc {
120 struct puffs_usermount *pcc_pu;
121 struct puffs_req *pcc_preq;
122
123 ucontext_t pcc_uc; /* "continue" */
124 ucontext_t pcc_uc_ret; /* "yield" */
125 void *pcc_stack;
126
127 int pcc_flags;
128 struct puffs_putreq *pcc_ppr;
129
130 TAILQ_ENTRY(puffs_cc) entries;
131 LIST_ENTRY(puffs_cc) nlst_entries;
132 };
133 #define PCC_FAKECC 0x01
134 #define PCC_REALCC 0x02
135 #define PCC_DONE 0x04
136 #define PCC_BORROWED 0x08
137
138 #define pcc_callstat(a) (a->pcc_flags & PCC_CALL_MASK)
139 #define pcc_callset(a, b) (a->pcc_flags = (a->pcc_flags & ~PCC_CALL_MASK) | b)
140
141 #define pcc_init_local(ap) \
142 do { \
143 memset(ap, 0, sizeof(*ap)); \
144 (ap)->pcc_flags = PCC_FAKECC; \
145 } while (/*CONSTCOND*/0)
146
147 /*
148 * Reqs
149 */
150
151 struct puffs_getreq {
152 struct puffs_usermount *pgr_pu;
153
154 struct puffs_reqh_get pgr_phg;
155 struct puffs_reqh_get pgr_phg_orig;
156
157 struct puffs_req *pgr_nextpreq;
158 size_t pgr_advance;
159
160 /* diagnostics */
161 int pgr_nppr;
162 };
163
164 struct puffs_putreq {
165 struct puffs_usermount *ppr_pu;
166
167 struct puffs_reqh_put ppr_php;
168
169 /* to adjust next request info */
170 void **ppr_buf;
171 size_t *ppr_buflen;
172 uint64_t *ppr_id;
173
174 /* for delayed action freeing of preq's */
175 TAILQ_HEAD(, puffs_cc) ppr_pccq;
176
177 /* diagnostics */
178 struct puffs_getreq *ppr_pgr;
179 };
180
181
182 __BEGIN_DECLS
183
184 void puffs_calldispatcher(struct puffs_cc *);
185
186 void puffs_framev_input(struct puffs_usermount *, struct puffs_framectrl *,
187 struct puffs_fctrl_io *, struct puffs_putreq *);
188 int puffs_framev_output(struct puffs_usermount *, struct puffs_framectrl*,
189 struct puffs_fctrl_io *);
190 void puffs_framev_exit(struct puffs_usermount *);
191 void puffs_framev_readclose(struct puffs_usermount *,
192 struct puffs_fctrl_io *, int);
193 void puffs_framev_writeclose(struct puffs_usermount *,
194 struct puffs_fctrl_io *, int);
195
196 void puffs_goto(struct puffs_cc *);
197
198 __END_DECLS
199
200 #endif /* _PUFFS_PRIVATE_H_ */
201