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