Home | History | Annotate | Line # | Download | only in libpuffs
puffs_priv.h revision 1.39.6.1
      1  1.39.6.1  wrstuden /*	$NetBSD: puffs_priv.h,v 1.39.6.1 2008/09/18 04:39:24 wrstuden Exp $	*/
      2       1.1     pooka 
      3       1.1     pooka /*
      4      1.38     pooka  * Copyright (c) 2006, 2007, 2008 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.30     pooka #ifdef PUFFS_WITH_THREADS
     38      1.30     pooka #include <pthread.h>
     39      1.30     pooka 
     40      1.30     pooka extern pthread_mutex_t pu_lock;
     41      1.31     pooka #define PU_LOCK() pthread_mutex_lock(&pu_lock)
     42      1.31     pooka #define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
     43      1.30     pooka #else
     44      1.30     pooka #define PU_LOCK()
     45      1.30     pooka #define PU_UNLOCK()
     46      1.30     pooka #endif
     47      1.30     pooka 
     48      1.37     pooka #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(pu,c) : (struct puffs_node*)c)
     49       1.4     pooka 
     50       1.9     pooka struct puffs_framectrl {
     51      1.10     pooka 	puffs_framev_readframe_fn rfb;
     52      1.10     pooka 	puffs_framev_writeframe_fn wfb;
     53      1.11     pooka 	puffs_framev_cmpframe_fn cmpfb;
     54      1.21     pooka 	puffs_framev_gotframe_fn gotfb;
     55      1.10     pooka 	puffs_framev_fdnotify_fn fdnotfn;
     56       1.9     pooka };
     57       1.9     pooka 
     58       1.9     pooka struct puffs_fctrl_io {
     59      1.33     pooka 	struct puffs_framectrl *fctrl;
     60      1.33     pooka 
     61       1.9     pooka 	int io_fd;
     62      1.10     pooka 	int stat;
     63       1.9     pooka 
     64      1.19     pooka 	int rwait;
     65      1.19     pooka 	int wwait;
     66      1.19     pooka 
     67       1.9     pooka 	struct puffs_framebuf *cur_in;
     68       1.9     pooka 
     69       1.9     pooka 	TAILQ_HEAD(, puffs_framebuf) snd_qing;	/* queueing to be sent */
     70       1.9     pooka 	TAILQ_HEAD(, puffs_framebuf) res_qing;	/* q'ing for rescue */
     71      1.19     pooka 	LIST_HEAD(, puffs_fbevent) ev_qing;	/* q'ing for events */
     72       1.9     pooka 
     73       1.9     pooka 	LIST_ENTRY(puffs_fctrl_io) fio_entries;
     74       1.9     pooka };
     75      1.10     pooka #define FIO_WR		0x01
     76      1.10     pooka #define FIO_WRGONE	0x02
     77      1.10     pooka #define FIO_RDGONE	0x04
     78      1.10     pooka #define FIO_DEAD	0x08
     79      1.17     pooka #define FIO_ENABLE_R	0x10
     80      1.17     pooka #define FIO_ENABLE_W	0x20
     81      1.10     pooka 
     82      1.19     pooka #define FIO_EN_WRITE(fio)				\
     83      1.19     pooka     (!(fio->stat & FIO_WR)				\
     84      1.19     pooka       && ((!TAILQ_EMPTY(&fio->snd_qing)			\
     85      1.19     pooka             && (fio->stat & FIO_ENABLE_W))		\
     86      1.19     pooka          || fio->wwait))
     87      1.17     pooka 
     88      1.17     pooka #define FIO_RM_WRITE(fio)			\
     89      1.17     pooka     ((fio->stat & FIO_WR)			\
     90      1.19     pooka       && (((TAILQ_EMPTY(&fio->snd_qing)		\
     91      1.19     pooka         || (fio->stat & FIO_ENABLE_W) == 0))	\
     92      1.19     pooka 	&& (fio->wwait == 0)))
     93       1.7     pooka 
     94      1.28     pooka 
     95       1.5     pooka /*
     96       1.5     pooka  * usermount: describes one file system instance
     97       1.5     pooka  */
     98       1.5     pooka struct puffs_usermount {
     99       1.5     pooka 	struct puffs_ops	pu_ops;
    100      1.18     pooka 
    101      1.18     pooka 	int			pu_fd;
    102      1.18     pooka 	size_t			pu_maxreqlen;
    103       1.5     pooka 
    104       1.5     pooka 	uint32_t		pu_flags;
    105      1.27     pooka 	int			pu_cc_stackshift;
    106       1.5     pooka 
    107  1.39.6.1  wrstuden 	ucontext_t		pu_mainctx;
    108      1.38     pooka #define PUFFS_CCMAXSTORE 32
    109      1.38     pooka 	int			pu_cc_nstored;
    110      1.38     pooka 
    111       1.9     pooka 	int			pu_kq;
    112       1.5     pooka 	int			pu_state;
    113  1.39.6.1  wrstuden #define PU_STATEMASK	0x00ff
    114  1.39.6.1  wrstuden #define PU_INLOOP	0x0100
    115  1.39.6.1  wrstuden #define PU_ASYNCFD	0x0200
    116  1.39.6.1  wrstuden #define PU_HASKQ	0x0400
    117  1.39.6.1  wrstuden #define PU_PUFFSDAEMON	0x0800
    118  1.39.6.1  wrstuden #define PU_MAINRESTORE	0x1000
    119       1.9     pooka #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
    120  1.39.6.1  wrstuden #define PU_SETSFLAG(pu, s) (pu->pu_state |= (s))
    121  1.39.6.1  wrstuden #define PU_CLRSFLAG(pu, s) \
    122  1.39.6.1  wrstuden     (pu->pu_state = ((pu->pu_state &= ~(s)) | (pu->pu_state & PU_STATEMASK)))
    123      1.32     pooka 	int			pu_dpipe[2];
    124       1.5     pooka 
    125       1.5     pooka 	struct puffs_node	*pu_pn_root;
    126       1.5     pooka 
    127       1.5     pooka 	LIST_HEAD(, puffs_node)	pu_pnodelst;
    128      1.38     pooka 
    129      1.38     pooka 	LIST_HEAD(, puffs_cc)	pu_ccmagazin;
    130      1.39     pooka 	TAILQ_HEAD(, puffs_cc)	pu_lazyctx;
    131      1.25     pooka 	TAILQ_HEAD(, puffs_cc)	pu_sched;
    132       1.5     pooka 
    133      1.37     pooka 	pu_cmap_fn		pu_cmap;
    134       1.5     pooka 
    135       1.5     pooka 	pu_pathbuild_fn		pu_pathbuild;
    136       1.5     pooka 	pu_pathtransform_fn	pu_pathtransform;
    137       1.5     pooka 	pu_pathcmp_fn		pu_pathcmp;
    138       1.5     pooka 	pu_pathfree_fn		pu_pathfree;
    139       1.5     pooka 	pu_namemod_fn		pu_namemod;
    140       1.5     pooka 
    141      1.22     pooka 	pu_errnotify_fn		pu_errnotify;
    142      1.22     pooka 
    143      1.29     pooka 	pu_prepost_fn		pu_oppre;
    144      1.29     pooka 	pu_prepost_fn		pu_oppost;
    145      1.29     pooka 
    146      1.33     pooka 	struct puffs_framectrl	pu_framectrl[2];
    147      1.33     pooka #define PU_FRAMECTRL_FS   0
    148      1.33     pooka #define PU_FRAMECTRL_USER 1
    149      1.33     pooka 	LIST_HEAD(, puffs_fctrl_io) pu_ios;
    150      1.33     pooka 	LIST_HEAD(, puffs_fctrl_io) pu_ios_rmlist;
    151      1.33     pooka 	struct kevent		*pu_evs;
    152      1.33     pooka 	size_t			pu_nfds;
    153       1.7     pooka 
    154      1.10     pooka 	puffs_ml_loop_fn	pu_ml_lfn;
    155      1.10     pooka 	struct timespec		pu_ml_timeout;
    156      1.10     pooka 	struct timespec		*pu_ml_timep;
    157      1.10     pooka 
    158      1.18     pooka 	struct puffs_kargs	*pu_kargp;
    159      1.18     pooka 
    160      1.34     pooka 	uint64_t		pu_nextreq;
    161      1.10     pooka 	void			*pu_privdata;
    162       1.5     pooka };
    163       1.5     pooka 
    164       1.2     pooka /* call context */
    165       1.2     pooka 
    166      1.39     pooka struct puffs_cc;
    167      1.39     pooka typedef void (*puffs_ccfunc)(struct puffs_cc *);
    168      1.39     pooka 
    169       1.2     pooka struct puffs_cc {
    170       1.2     pooka 	struct puffs_usermount	*pcc_pu;
    171      1.33     pooka 	struct puffs_framebuf	*pcc_pb;
    172       1.2     pooka 
    173      1.39     pooka 	/* real cc */
    174      1.39     pooka 	union {
    175      1.39     pooka 		struct {
    176      1.39     pooka 			ucontext_t	uc;		/* "continue"	*/
    177      1.39     pooka 			ucontext_t	uc_ret;		/* "yield" 	*/
    178      1.39     pooka 		} real;
    179      1.39     pooka 		struct {
    180      1.39     pooka 			puffs_ccfunc	func;
    181      1.39     pooka 			void		*farg;
    182      1.39     pooka 		} fake;
    183      1.39     pooka 	} pcc_u;
    184       1.2     pooka 
    185      1.24     pooka 	pid_t			pcc_pid;
    186      1.24     pooka 	lwpid_t			pcc_lid;
    187      1.24     pooka 
    188       1.2     pooka 	int			pcc_flags;
    189       1.2     pooka 
    190      1.38     pooka 	TAILQ_ENTRY(puffs_cc)	pcc_schedent;
    191      1.38     pooka 	LIST_ENTRY(puffs_cc)	pcc_rope;
    192       1.2     pooka };
    193      1.39     pooka #define pcc_uc		pcc_u.real.uc
    194      1.39     pooka #define pcc_uc_ret 	pcc_u.real.uc_ret
    195      1.39     pooka #define pcc_func	pcc_u.fake.func
    196      1.39     pooka #define pcc_farg	pcc_u.fake.farg
    197      1.39     pooka #define PCC_DONE	0x01
    198      1.39     pooka #define PCC_BORROWED	0x02
    199      1.39     pooka #define PCC_HASCALLER	0x04
    200      1.39     pooka #define PCC_MLCONT	0x08
    201       1.2     pooka 
    202      1.16     pooka struct puffs_newinfo {
    203      1.16     pooka 	void		**pni_cookie;
    204      1.16     pooka 	enum vtype	*pni_vtype;
    205      1.16     pooka 	voff_t		*pni_size;
    206      1.16     pooka 	dev_t		*pni_rdev;
    207      1.16     pooka };
    208      1.16     pooka 
    209      1.13     pooka #define PUFFS_MAKEKCRED(to, from)					\
    210      1.13     pooka 	/*LINTED: tnilxnaht, the cast is ok */				\
    211      1.15     pooka 	const struct puffs_kcred *to = (const void *)from
    212      1.13     pooka #define PUFFS_MAKECRED(to, from)					\
    213      1.13     pooka 	/*LINTED: tnilxnaht, the cast is ok */				\
    214      1.15     pooka 	const struct puffs_cred *to = (const void *)from
    215      1.13     pooka #define PUFFS_KCREDTOCRED(to, from)					\
    216      1.13     pooka 	/*LINTED: tnilxnaht, the cast is ok */				\
    217      1.15     pooka 	to = (void *)from
    218       1.9     pooka 
    219       1.2     pooka __BEGIN_DECLS
    220       1.2     pooka 
    221      1.39     pooka void	puffs__framev_input(struct puffs_usermount *, struct puffs_framectrl *,
    222      1.33     pooka 			   struct puffs_fctrl_io *);
    223      1.39     pooka int	puffs__framev_output(struct puffs_usermount *, struct puffs_framectrl*,
    224      1.33     pooka 			    struct puffs_fctrl_io *);
    225      1.39     pooka void	puffs__framev_exit(struct puffs_usermount *);
    226      1.39     pooka void	puffs__framev_readclose(struct puffs_usermount *,
    227      1.10     pooka 			       struct puffs_fctrl_io *, int);
    228      1.39     pooka void	puffs__framev_writeclose(struct puffs_usermount *,
    229      1.10     pooka 				struct puffs_fctrl_io *, int);
    230      1.39     pooka void	puffs__framev_notify(struct puffs_fctrl_io *, int);
    231      1.33     pooka void	*puffs__framebuf_getdataptr(struct puffs_framebuf *);
    232      1.33     pooka int	puffs__framev_addfd_ctrl(struct puffs_usermount *, int, int,
    233      1.33     pooka 				 struct puffs_framectrl *);
    234      1.33     pooka void	puffs__framebuf_moveinfo(struct puffs_framebuf *,
    235      1.33     pooka 				 struct puffs_framebuf *);
    236      1.10     pooka 
    237      1.39     pooka void	puffs__theloop(struct puffs_cc *);
    238      1.39     pooka void	puffs__ml_dispatch(struct puffs_usermount *, struct puffs_framebuf *);
    239      1.39     pooka 
    240      1.39     pooka int	puffs__cc_create(struct puffs_usermount *, puffs_ccfunc,
    241      1.39     pooka 			 struct puffs_cc **);
    242      1.39     pooka void	puffs__cc_cont(struct puffs_cc *);
    243      1.39     pooka void	puffs__cc_destroy(struct puffs_cc *, int);
    244      1.39     pooka void	puffs__cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
    245      1.39     pooka void	puffs__goto(struct puffs_cc *);
    246  1.39.6.1  wrstuden int	puffs__cc_savemain(struct puffs_usermount *);
    247  1.39.6.1  wrstuden int	puffs__cc_restoremain(struct puffs_usermount *);
    248  1.39.6.1  wrstuden void	puffs__cc_exit(struct puffs_usermount *);
    249      1.39     pooka 
    250      1.39     pooka int	puffs__fsframe_read(struct puffs_usermount *, struct puffs_framebuf *,
    251      1.39     pooka 			    int, int *);
    252      1.39     pooka int	puffs__fsframe_write(struct puffs_usermount *, struct puffs_framebuf *,
    253      1.39     pooka 			    int, int *);
    254      1.39     pooka int	puffs__fsframe_cmp(struct puffs_usermount *, struct puffs_framebuf *,
    255      1.39     pooka 			   struct puffs_framebuf *, int *);
    256      1.39     pooka void	puffs__fsframe_gotframe(struct puffs_usermount *,
    257      1.39     pooka 			        struct puffs_framebuf *);
    258      1.33     pooka 
    259      1.34     pooka uint64_t	puffs__nextreq(struct puffs_usermount *pu);
    260      1.34     pooka 
    261       1.2     pooka __END_DECLS
    262       1.2     pooka 
    263       1.1     pooka #endif /* _PUFFS_PRIVATE_H_ */
    264