Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / fs / puffs / puffs_sys.h
blobaa70f7295b3d39f4eef6267d405fae9e956c911d
1 /* $NetBSD: puffs_sys.h,v 1.74 2010/01/07 22:45:31 pooka Exp $ */
3 /*
4 * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
6 * Development of this software was supported by the
7 * Google Summer of Code program and the Ulla Tuominen Foundation.
8 * The Google SoC project was mentored by Bill Studenmund.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #ifndef _PUFFS_SYS_H_
33 #define _PUFFS_SYS_H_
35 #include <sys/param.h>
36 #include <sys/select.h>
37 #include <sys/kauth.h>
38 #include <sys/mutex.h>
39 #include <sys/queue.h>
40 #include <sys/pool.h>
42 #include <fs/puffs/puffs_msgif.h>
44 #include <miscfs/genfs/genfs_node.h>
46 extern int (**puffs_vnodeop_p)(void *);
47 extern int (**puffs_specop_p)(void *);
48 extern int (**puffs_fifoop_p)(void *);
50 extern const struct vnodeopv_desc puffs_vnodeop_opv_desc;
51 extern const struct vnodeopv_desc puffs_specop_opv_desc;
52 extern const struct vnodeopv_desc puffs_fifoop_opv_desc;
53 extern const struct vnodeopv_desc puffs_msgop_opv_desc;
55 extern struct pool puffs_pnpool;
57 #ifdef DEBUG
58 #ifndef PUFFSDEBUG
59 #define PUFFSDEBUG
60 #endif
61 #endif
63 #ifdef PUFFSDEBUG
64 extern int puffsdebug; /* puffs_subr.c */
65 #define DPRINTF(x) if (puffsdebug > 0) printf x
66 #define DPRINTF_VERBOSE(x) if (puffsdebug > 1) printf x
67 #else
68 #define DPRINTF(x)
69 #define DPRINTF_VERBOSE(x)
70 #endif
72 #define MPTOPUFFSMP(mp) ((struct puffs_mount *)((mp)->mnt_data))
73 #define PMPTOMP(pmp) (pmp->pmp_mp)
74 #define VPTOPP(vp) ((struct puffs_node *)(vp)->v_data)
75 #define VPTOPNC(vp) (((struct puffs_node *)(vp)->v_data)->pn_cookie)
76 #define VPTOPUFFSMP(vp) ((struct puffs_mount*)((struct puffs_node*)vp->v_data))
78 /* we don't pass the kernel overlay to userspace */
79 #define PUFFS_TOFHSIZE(s) ((s)==0 ? (s) : (s)+4)
80 #define PUFFS_FROMFHSIZE(s) ((s)==0 ? (s) : (s)-4)
82 #define ALLOPS(pmp) (pmp->pmp_flags & PUFFS_KFLAG_ALLOPS)
83 #define EXISTSOP(pmp, op) \
84 (ALLOPS(pmp) || ((pmp)->pmp_vnopmask[PUFFS_VN_##op]))
86 #define PUFFS_USE_NAMECACHE(pmp) \
87 (((pmp)->pmp_flags & PUFFS_KFLAG_NOCACHE_NAME) == 0)
88 #define PUFFS_USE_PAGECACHE(pmp) \
89 (((pmp)->pmp_flags & PUFFS_KFLAG_NOCACHE_PAGE) == 0)
90 #define PUFFS_USE_FULLPNBUF(pmp) \
91 ((pmp)->pmp_flags & PUFFS_KFLAG_LOOKUP_FULLPNBUF)
93 #define PUFFS_WCACHEINFO(pmp) 0
95 struct puffs_newcookie {
96 puffs_cookie_t pnc_cookie;
98 LIST_ENTRY(puffs_newcookie) pnc_entries;
101 enum puffs_sopreqtype {
102 PUFFS_SOPREQSYS_EXIT,
103 PUFFS_SOPREQ_FLUSH,
104 PUFFS_SOPREQ_UNMOUNT,
107 struct puffs_sopreq {
108 union {
109 struct puffs_req preq;
110 struct puffs_flush pf;
111 } psopr_u;
113 enum puffs_sopreqtype psopr_sopreq;
114 TAILQ_ENTRY(puffs_sopreq) psopr_entries;
116 #define psopr_preq psopr_u.preq
117 #define psopr_pf psopr_u.pf
119 TAILQ_HEAD(puffs_wq, puffs_msgpark);
120 LIST_HEAD(puffs_node_hashlist, puffs_node);
121 struct puffs_mount {
122 kmutex_t pmp_lock;
124 struct puffs_kargs pmp_args;
125 #define pmp_flags pmp_args.pa_flags
126 #define pmp_vnopmask pmp_args.pa_vnopmask
128 struct puffs_wq pmp_msg_touser;
129 int pmp_msg_touser_count;
130 kcondvar_t pmp_msg_waiter_cv;
131 size_t pmp_msg_maxsize;
133 struct puffs_wq pmp_msg_replywait;
135 struct puffs_node_hashlist *pmp_pnodehash;
136 int pmp_npnodehash;
138 LIST_HEAD(, puffs_newcookie) pmp_newcookie;
140 struct mount *pmp_mp;
142 struct vnode *pmp_root;
143 puffs_cookie_t pmp_root_cookie;
144 enum vtype pmp_root_vtype;
145 vsize_t pmp_root_vsize;
146 dev_t pmp_root_rdev;
148 struct putter_instance *pmp_pi;
150 unsigned int pmp_refcount;
151 kcondvar_t pmp_refcount_cv;
153 kcondvar_t pmp_unmounting_cv;
154 uint8_t pmp_unmounting;
156 uint8_t pmp_status;
157 uint8_t pmp_suspend;
159 uint8_t *pmp_curput;
160 size_t pmp_curres;
161 void *pmp_curopaq;
163 uint64_t pmp_nextmsgid;
165 kmutex_t pmp_sopmtx;
166 kcondvar_t pmp_sopcv;
167 int pmp_sopthrcount;
168 TAILQ_HEAD(, puffs_sopreq) pmp_sopreqs;
171 #define PUFFSTAT_BEFOREINIT 0
172 #define PUFFSTAT_MOUNTING 1
173 #define PUFFSTAT_RUNNING 2
174 #define PUFFSTAT_DYING 3 /* Do you want your possessions identified? */
177 #define PNODE_NOREFS 0x01 /* no backend reference */
178 #define PNODE_DYING 0x02 /* NOREFS + inactive */
179 #define PNODE_FAF 0x04 /* issue all operations as FAF */
180 #define PNODE_DOINACT 0x08 /* if inactive-on-demand, call inactive */
182 #define PNODE_METACACHE_ATIME 0x10 /* cache atime metadata */
183 #define PNODE_METACACHE_CTIME 0x20 /* cache atime metadata */
184 #define PNODE_METACACHE_MTIME 0x40 /* cache atime metadata */
185 #define PNODE_METACACHE_SIZE 0x80 /* cache atime metadata */
186 #define PNODE_METACACHE_MASK 0xf0
188 struct puffs_node {
189 struct genfs_node pn_gnode; /* genfs glue */
191 kmutex_t pn_mtx;
192 int pn_refcount;
194 puffs_cookie_t pn_cookie; /* userspace pnode cookie */
195 struct vnode *pn_vp; /* backpointer to vnode */
196 uint32_t pn_stat; /* node status */
198 struct selinfo pn_sel; /* for selecting on the node */
199 short pn_revents; /* available events */
201 /* metacache */
202 struct timespec pn_mc_atime;
203 struct timespec pn_mc_ctime;
204 struct timespec pn_mc_mtime;
205 u_quad_t pn_mc_size;
207 voff_t pn_serversize;
209 LIST_ENTRY(puffs_node) pn_hashent;
212 typedef void (*parkdone_fn)(struct puffs_mount *, struct puffs_req *, void *);
214 struct puffs_msgpark;
215 void puffs_msgif_init(void);
216 void puffs_msgif_destroy(void);
217 int puffs_msgmem_alloc(size_t, struct puffs_msgpark **, void **, int);
218 void puffs_msgmem_release(struct puffs_msgpark *);
220 void puffs_sop_thread(void *);
222 void puffs_msg_setfaf(struct puffs_msgpark *);
223 void puffs_msg_setdelta(struct puffs_msgpark *, size_t);
224 void puffs_msg_setinfo(struct puffs_msgpark *, int, int, puffs_cookie_t);
225 void puffs_msg_setcall(struct puffs_msgpark *, parkdone_fn, void *);
227 void puffs_msg_enqueue(struct puffs_mount *, struct puffs_msgpark *);
228 int puffs_msg_wait(struct puffs_mount *, struct puffs_msgpark *);
229 int puffs_msg_wait2(struct puffs_mount *, struct puffs_msgpark *,
230 struct puffs_node *, struct puffs_node *);
232 void puffs_msg_sendresp(struct puffs_mount *, struct puffs_req *, int);
234 int puffs_getvnode(struct mount *, puffs_cookie_t, enum vtype,
235 voff_t, dev_t, struct vnode **);
236 int puffs_newnode(struct mount *, struct vnode *, struct vnode **,
237 puffs_cookie_t, struct componentname *,
238 enum vtype, dev_t);
239 void puffs_putvnode(struct vnode *);
241 void puffs_releasenode(struct puffs_node *);
242 void puffs_referencenode(struct puffs_node *);
244 #define PUFFS_NOSUCHCOOKIE (-1)
245 int puffs_cookie2vnode(struct puffs_mount *, puffs_cookie_t, int, int,
246 struct vnode **);
247 void puffs_makecn(struct puffs_kcn *, struct puffs_kcred *,
248 const struct componentname *, int);
249 void puffs_credcvt(struct puffs_kcred *, kauth_cred_t);
251 void puffs_parkdone_asyncbioread(struct puffs_mount *,
252 struct puffs_req *, void *);
253 void puffs_parkdone_asyncbiowrite(struct puffs_mount *,
254 struct puffs_req *, void *);
255 void puffs_parkdone_poll(struct puffs_mount *, struct puffs_req *, void *);
257 void puffs_mp_reference(struct puffs_mount *);
258 void puffs_mp_release(struct puffs_mount *);
260 void puffs_gop_size(struct vnode *, off_t, off_t *, int);
261 void puffs_gop_markupdate(struct vnode *, int);
263 void puffs_senderr(struct puffs_mount *, int, int, const char *,
264 puffs_cookie_t);
266 void puffs_updatenode(struct puffs_node *, int, voff_t);
267 #define PUFFS_UPDATEATIME 0x01
268 #define PUFFS_UPDATECTIME 0x02
269 #define PUFFS_UPDATEMTIME 0x04
270 #define PUFFS_UPDATESIZE 0x08
272 void puffs_userdead(struct puffs_mount *);
274 extern int (**puffs_vnodeop_p)(void *);
276 /* for putter */
277 int puffs_msgif_getout(void *, size_t, int, uint8_t **, size_t *, void **);
278 void puffs_msgif_releaseout(void *, void *, int);
279 int puffs_msgif_dispatch(void *, struct putter_hdr *);
280 size_t puffs_msgif_waitcount(void *);
281 int puffs_msgif_close(void *);
283 static __inline int
284 checkerr(struct puffs_mount *pmp, int error, const char *str)
287 if (error < 0 || error > ELAST) {
288 puffs_senderr(pmp, PUFFS_ERR_ERROR, error, str, NULL);
289 error = EPROTO;
292 return error;
295 #define PUFFS_MSG_VARS(type, a) \
296 struct puffs_##type##msg_##a *a##_msg; \
297 struct puffs_msgpark *park_##a = NULL
299 #define PUFFS_MSG_ALLOC(type, a) \
300 puffs_msgmem_alloc(sizeof(struct puffs_##type##msg_##a), \
301 &park_##a, (void *)& a##_msg, 1)
303 #define PUFFS_MSG_RELEASE(a) \
304 do { \
305 if (park_##a) puffs_msgmem_release(park_##a); \
306 } while (/*CONSTCOND*/0)
308 #define PUFFS_MSG_ENQUEUEWAIT(pmp, park, var) \
309 do { \
310 puffs_msg_enqueue(pmp, park); \
311 var = puffs_msg_wait(pmp, park); \
312 } while (/*CONSTCOND*/0)
314 #define PUFFS_MSG_ENQUEUEWAIT2(pmp, park, vp1, vp2, var) \
315 do { \
316 puffs_msg_enqueue(pmp, park); \
317 var = puffs_msg_wait2(pmp, park, vp1, vp2); \
318 } while (/*CONSTCOND*/0)
320 #endif /* _PUFFS_SYS_H_ */