Home | History | Annotate | Line # | Download | only in libpuffs
puffs_priv.h revision 1.28
      1 /*	$NetBSD: puffs_priv.h,v 1.28 2007/10/26 17:35:02 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 struct puffs_executor {
     91 	struct puffs_req		*pex_preq;
     92 	TAILQ_ENTRY(puffs_executor)	pex_entries;
     93 };
     94 
     95 /*
     96  * usermount: describes one file system instance
     97  */
     98 struct puffs_usermount {
     99 	struct puffs_ops	pu_ops;
    100 
    101 	int			pu_fd;
    102 	size_t			pu_maxreqlen;
    103 
    104 	uint32_t		pu_flags;
    105 	int			pu_cc_stackshift;
    106 
    107 	int			pu_kq;
    108 	int			pu_state;
    109 #define PU_STATEMASK	0xff
    110 #define PU_INLOOP	0x100
    111 #define PU_ASYNCFD	0x200
    112 #define PU_HASKQ	0x400
    113 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
    114 
    115 	struct puffs_node	*pu_pn_root;
    116 
    117 	LIST_HEAD(, puffs_node)	pu_pnodelst;
    118 	LIST_HEAD(, puffs_cc)	pu_ccnukelst;
    119 	TAILQ_HEAD(, puffs_cc)	pu_sched;
    120 
    121 	TAILQ_HEAD(, puffs_executor) pu_exq;
    122 
    123 	struct puffs_node	*(*pu_cmap)(void *);
    124 
    125 	pu_pathbuild_fn		pu_pathbuild;
    126 	pu_pathtransform_fn	pu_pathtransform;
    127 	pu_pathcmp_fn		pu_pathcmp;
    128 	pu_pathfree_fn		pu_pathfree;
    129 	pu_namemod_fn		pu_namemod;
    130 
    131 	pu_errnotify_fn		pu_errnotify;
    132 
    133 	struct puffs_framectrl	pu_framectrl;
    134 
    135 	puffs_ml_loop_fn	pu_ml_lfn;
    136 	struct timespec		pu_ml_timeout;
    137 	struct timespec		*pu_ml_timep;
    138 
    139 	struct puffs_kargs	*pu_kargp;
    140 
    141 	void			*pu_privdata;
    142 };
    143 
    144 /* call context */
    145 
    146 struct puffs_cc {
    147 	struct puffs_usermount	*pcc_pu;
    148 	struct puffs_req	*pcc_preq;
    149 
    150 	ucontext_t		pcc_uc;		/* "continue" 		*/
    151 	ucontext_t		pcc_uc_ret;	/* "yield" 		*/
    152 	void			*pcc_stack;
    153 
    154 	pid_t			pcc_pid;
    155 	lwpid_t			pcc_lid;
    156 
    157 	int			pcc_flags;
    158 	struct puffs_putreq	*pcc_ppr;
    159 
    160 	TAILQ_ENTRY(puffs_cc)	entries;
    161 	LIST_ENTRY(puffs_cc)	nlst_entries;
    162 };
    163 #define PCC_FAKECC	0x01
    164 #define PCC_REALCC	0x02
    165 #define PCC_DONE	0x04
    166 #define PCC_BORROWED	0x08
    167 #define PCC_HASCALLER	0x10
    168 #define PCC_THREADED	0x20
    169 
    170 #define pcc_callstat(a)	   (a->pcc_flags & PCC_CALL_MASK)
    171 #define pcc_callset(a, b)  (a->pcc_flags = (a->pcc_flags & ~PCC_CALL_MASK) | b)
    172 
    173 #define pcc_init_unreal(ap, type) 					\
    174 do {									\
    175 	memset(ap, 0, sizeof(*ap));					\
    176 	(ap)->pcc_flags = type;						\
    177 } while (/*CONSTCOND*/0)
    178 
    179 /*
    180  * Reqs
    181  */
    182 
    183 struct puffs_getreq {
    184 	struct puffs_usermount	*pgr_pu;
    185 
    186 	void			*pgr_buf;
    187 };
    188 
    189 struct puffs_putreq {
    190 	struct puffs_usermount *ppr_pu;
    191 
    192 	TAILQ_HEAD(, puffs_cc)	ppr_pccq;
    193 };
    194 
    195 struct puffs_newinfo {
    196 	void		**pni_cookie;
    197 	enum vtype	*pni_vtype;
    198 	voff_t		*pni_size;
    199 	dev_t		*pni_rdev;
    200 };
    201 
    202 #define PUFFS_MAKEKCRED(to, from)					\
    203 	/*LINTED: tnilxnaht, the cast is ok */				\
    204 	const struct puffs_kcred *to = (const void *)from
    205 #define PUFFS_MAKECRED(to, from)					\
    206 	/*LINTED: tnilxnaht, the cast is ok */				\
    207 	const struct puffs_cred *to = (const void *)from
    208 #define PUFFS_KCREDTOCRED(to, from)					\
    209 	/*LINTED: tnilxnaht, the cast is ok */				\
    210 	to = (void *)from
    211 
    212 #define PUFFS_MAKEKCID(to, from)					\
    213 	/*LINTED: tnilxnaht, the cast is ok */				\
    214 	const struct puffs_kcid *to = (const void *)from
    215 #define PUFFS_MAKECID(to, from)						\
    216 	/*LINTED: tnilxnaht, the cast is ok */				\
    217 	const struct puffs_cid *to = (const void *)from
    218 #define PUFFS_KCIDTOCID(to, from)					\
    219 	/*LINTED: tnilxnaht, the cast is ok */				\
    220 	to = (void *)from
    221 
    222 __BEGIN_DECLS
    223 
    224 void	puffs_calldispatcher(struct puffs_cc *);
    225 
    226 void	puffs_framev_input(struct puffs_usermount *, struct puffs_framectrl *,
    227 			   struct puffs_fctrl_io *, struct puffs_putreq *);
    228 int	puffs_framev_output(struct puffs_usermount *, struct puffs_framectrl*,
    229 			    struct puffs_fctrl_io *, struct puffs_putreq *);
    230 void	puffs_framev_exit(struct puffs_usermount *);
    231 void	puffs_framev_readclose(struct puffs_usermount *,
    232 			       struct puffs_fctrl_io *, int);
    233 void	puffs_framev_writeclose(struct puffs_usermount *,
    234 				struct puffs_fctrl_io *, int);
    235 void	puffs_framev_notify(struct puffs_fctrl_io *, int);
    236 
    237 int	puffs_cc_create(struct puffs_usermount *, struct puffs_req *,
    238 			int, struct puffs_cc **);
    239 void	puffs_cc_destroy(struct puffs_cc *);
    240 void	puffs_cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
    241 void	puffs_goto(struct puffs_cc *);
    242 
    243 __END_DECLS
    244 
    245 #endif /* _PUFFS_PRIVATE_H_ */
    246