2008-01-28 21:35:49 +03:00
|
|
|
/* $NetBSD: puffs_priv.h,v 1.39 2008/01/28 18:35:50 pooka Exp $ */
|
2006-12-08 02:15:20 +03:00
|
|
|
|
|
|
|
/*
|
2008-01-17 00:29:59 +03:00
|
|
|
* Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved.
|
2006-12-08 02:15:20 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PUFFS_PRIVATE_H_
|
|
|
|
#define _PUFFS_PRIVATE_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fs/puffs/puffs_msgif.h>
|
|
|
|
|
|
|
|
#include <puffs.h>
|
2006-12-29 18:28:11 +03:00
|
|
|
#include <ucontext.h>
|
|
|
|
|
2007-10-29 18:52:44 +03:00
|
|
|
#ifdef PUFFS_WITH_THREADS
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
extern pthread_mutex_t pu_lock;
|
2007-10-31 19:09:09 +03:00
|
|
|
#define PU_LOCK() pthread_mutex_lock(&pu_lock)
|
|
|
|
#define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
|
2007-10-29 18:52:44 +03:00
|
|
|
#else
|
|
|
|
#define PU_LOCK()
|
|
|
|
#define PU_UNLOCK()
|
|
|
|
#endif
|
|
|
|
|
2007-12-25 23:38:01 +03:00
|
|
|
#define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(pu,c) : (struct puffs_node*)c)
|
2007-01-15 03:39:02 +03:00
|
|
|
|
2007-05-12 01:27:13 +04:00
|
|
|
struct puffs_framectrl {
|
2007-05-15 17:44:46 +04:00
|
|
|
puffs_framev_readframe_fn rfb;
|
|
|
|
puffs_framev_writeframe_fn wfb;
|
2007-05-20 20:24:37 +04:00
|
|
|
puffs_framev_cmpframe_fn cmpfb;
|
2007-09-01 20:42:42 +04:00
|
|
|
puffs_framev_gotframe_fn gotfb;
|
2007-05-15 17:44:46 +04:00
|
|
|
puffs_framev_fdnotify_fn fdnotfn;
|
2007-05-12 01:27:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct puffs_fctrl_io {
|
2007-12-05 00:24:10 +03:00
|
|
|
struct puffs_framectrl *fctrl;
|
|
|
|
|
2007-05-12 01:27:13 +04:00
|
|
|
int io_fd;
|
2007-05-15 17:44:46 +04:00
|
|
|
int stat;
|
2007-05-12 01:27:13 +04:00
|
|
|
|
2007-07-20 17:14:55 +04:00
|
|
|
int rwait;
|
|
|
|
int wwait;
|
|
|
|
|
2007-05-12 01:27:13 +04:00
|
|
|
struct puffs_framebuf *cur_in;
|
|
|
|
|
|
|
|
TAILQ_HEAD(, puffs_framebuf) snd_qing; /* queueing to be sent */
|
|
|
|
TAILQ_HEAD(, puffs_framebuf) res_qing; /* q'ing for rescue */
|
2007-07-20 17:14:55 +04:00
|
|
|
LIST_HEAD(, puffs_fbevent) ev_qing; /* q'ing for events */
|
2007-05-12 01:27:13 +04:00
|
|
|
|
|
|
|
LIST_ENTRY(puffs_fctrl_io) fio_entries;
|
|
|
|
};
|
2007-05-15 17:44:46 +04:00
|
|
|
#define FIO_WR 0x01
|
|
|
|
#define FIO_WRGONE 0x02
|
|
|
|
#define FIO_RDGONE 0x04
|
|
|
|
#define FIO_DEAD 0x08
|
2007-07-08 01:13:41 +04:00
|
|
|
#define FIO_ENABLE_R 0x10
|
|
|
|
#define FIO_ENABLE_W 0x20
|
2007-05-15 17:44:46 +04:00
|
|
|
|
2007-07-20 17:14:55 +04:00
|
|
|
#define FIO_EN_WRITE(fio) \
|
|
|
|
(!(fio->stat & FIO_WR) \
|
|
|
|
&& ((!TAILQ_EMPTY(&fio->snd_qing) \
|
|
|
|
&& (fio->stat & FIO_ENABLE_W)) \
|
|
|
|
|| fio->wwait))
|
2007-07-08 01:13:41 +04:00
|
|
|
|
|
|
|
#define FIO_RM_WRITE(fio) \
|
|
|
|
((fio->stat & FIO_WR) \
|
2007-07-20 17:14:55 +04:00
|
|
|
&& (((TAILQ_EMPTY(&fio->snd_qing) \
|
|
|
|
|| (fio->stat & FIO_ENABLE_W) == 0)) \
|
|
|
|
&& (fio->wwait == 0)))
|
2007-05-05 19:48:18 +04:00
|
|
|
|
2007-10-26 21:35:01 +04:00
|
|
|
|
2007-04-12 19:09:00 +04:00
|
|
|
/*
|
|
|
|
* usermount: describes one file system instance
|
|
|
|
*/
|
|
|
|
struct puffs_usermount {
|
|
|
|
struct puffs_ops pu_ops;
|
2007-07-19 16:52:28 +04:00
|
|
|
|
|
|
|
int pu_fd;
|
|
|
|
size_t pu_maxreqlen;
|
2007-04-12 19:09:00 +04:00
|
|
|
|
|
|
|
uint32_t pu_flags;
|
2007-10-26 17:51:14 +04:00
|
|
|
int pu_cc_stackshift;
|
2007-04-12 19:09:00 +04:00
|
|
|
|
2008-01-28 21:35:49 +03:00
|
|
|
struct puffs_cc *pu_cc_main;
|
2008-01-17 00:29:59 +03:00
|
|
|
#define PUFFS_CCMAXSTORE 32
|
|
|
|
int pu_cc_nstored;
|
|
|
|
|
2007-05-12 01:27:13 +04:00
|
|
|
int pu_kq;
|
2007-04-12 19:09:00 +04:00
|
|
|
int pu_state;
|
2007-05-12 01:27:13 +04:00
|
|
|
#define PU_STATEMASK 0xff
|
|
|
|
#define PU_INLOOP 0x100
|
2007-05-15 17:44:46 +04:00
|
|
|
#define PU_ASYNCFD 0x200
|
2007-10-25 14:59:45 +04:00
|
|
|
#define PU_HASKQ 0x400
|
2007-11-16 21:35:10 +03:00
|
|
|
#define PU_PUFFSDAEMON 0x800
|
2007-05-12 01:27:13 +04:00
|
|
|
#define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
|
2007-11-16 21:35:10 +03:00
|
|
|
int pu_dpipe[2];
|
2007-04-12 19:09:00 +04:00
|
|
|
|
|
|
|
struct puffs_node *pu_pn_root;
|
|
|
|
|
|
|
|
LIST_HEAD(, puffs_node) pu_pnodelst;
|
2008-01-17 00:29:59 +03:00
|
|
|
|
|
|
|
LIST_HEAD(, puffs_cc) pu_ccmagazin;
|
2008-01-28 21:35:49 +03:00
|
|
|
TAILQ_HEAD(, puffs_cc) pu_lazyctx;
|
2007-10-21 23:25:58 +04:00
|
|
|
TAILQ_HEAD(, puffs_cc) pu_sched;
|
2007-04-12 19:09:00 +04:00
|
|
|
|
2007-12-25 23:38:01 +03:00
|
|
|
pu_cmap_fn pu_cmap;
|
2007-04-12 19:09:00 +04:00
|
|
|
|
|
|
|
pu_pathbuild_fn pu_pathbuild;
|
|
|
|
pu_pathtransform_fn pu_pathtransform;
|
|
|
|
pu_pathcmp_fn pu_pathcmp;
|
|
|
|
pu_pathfree_fn pu_pathfree;
|
|
|
|
pu_namemod_fn pu_namemod;
|
|
|
|
|
2007-09-28 01:14:49 +04:00
|
|
|
pu_errnotify_fn pu_errnotify;
|
|
|
|
|
2007-10-28 21:40:30 +03:00
|
|
|
pu_prepost_fn pu_oppre;
|
|
|
|
pu_prepost_fn pu_oppost;
|
|
|
|
|
2007-12-05 00:24:10 +03:00
|
|
|
struct puffs_framectrl pu_framectrl[2];
|
|
|
|
#define PU_FRAMECTRL_FS 0
|
|
|
|
#define PU_FRAMECTRL_USER 1
|
|
|
|
LIST_HEAD(, puffs_fctrl_io) pu_ios;
|
|
|
|
LIST_HEAD(, puffs_fctrl_io) pu_ios_rmlist;
|
|
|
|
struct kevent *pu_evs;
|
|
|
|
size_t pu_nfds;
|
2007-05-05 19:48:18 +04:00
|
|
|
|
2007-05-15 17:44:46 +04:00
|
|
|
puffs_ml_loop_fn pu_ml_lfn;
|
|
|
|
struct timespec pu_ml_timeout;
|
|
|
|
struct timespec *pu_ml_timep;
|
|
|
|
|
2007-07-19 16:52:28 +04:00
|
|
|
struct puffs_kargs *pu_kargp;
|
|
|
|
|
2007-12-05 15:11:56 +03:00
|
|
|
uint64_t pu_nextreq;
|
2007-05-15 17:44:46 +04:00
|
|
|
void *pu_privdata;
|
2007-04-12 19:09:00 +04:00
|
|
|
};
|
|
|
|
|
2006-12-29 18:28:11 +03:00
|
|
|
/* call context */
|
|
|
|
|
2008-01-28 21:35:49 +03:00
|
|
|
struct puffs_cc;
|
|
|
|
typedef void (*puffs_ccfunc)(struct puffs_cc *);
|
|
|
|
|
2006-12-29 18:28:11 +03:00
|
|
|
struct puffs_cc {
|
|
|
|
struct puffs_usermount *pcc_pu;
|
2007-12-05 00:24:10 +03:00
|
|
|
struct puffs_framebuf *pcc_pb;
|
2006-12-29 18:28:11 +03:00
|
|
|
|
2008-01-28 21:35:49 +03:00
|
|
|
/* real cc */
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
ucontext_t uc; /* "continue" */
|
|
|
|
ucontext_t uc_ret; /* "yield" */
|
|
|
|
} real;
|
|
|
|
struct {
|
|
|
|
puffs_ccfunc func;
|
|
|
|
void *farg;
|
|
|
|
} fake;
|
|
|
|
} pcc_u;
|
2006-12-29 18:28:11 +03:00
|
|
|
|
2007-10-21 18:28:05 +04:00
|
|
|
pid_t pcc_pid;
|
|
|
|
lwpid_t pcc_lid;
|
|
|
|
|
2006-12-29 18:28:11 +03:00
|
|
|
int pcc_flags;
|
|
|
|
|
2008-01-17 00:29:59 +03:00
|
|
|
TAILQ_ENTRY(puffs_cc) pcc_schedent;
|
|
|
|
LIST_ENTRY(puffs_cc) pcc_rope;
|
2006-12-29 18:28:11 +03:00
|
|
|
};
|
2008-01-28 21:35:49 +03:00
|
|
|
#define pcc_uc pcc_u.real.uc
|
|
|
|
#define pcc_uc_ret pcc_u.real.uc_ret
|
|
|
|
#define pcc_func pcc_u.fake.func
|
|
|
|
#define pcc_farg pcc_u.fake.farg
|
|
|
|
#define PCC_DONE 0x01
|
|
|
|
#define PCC_BORROWED 0x02
|
|
|
|
#define PCC_HASCALLER 0x04
|
|
|
|
#define PCC_MLCONT 0x08
|
2006-12-29 18:28:11 +03:00
|
|
|
|
2007-07-01 22:39:39 +04:00
|
|
|
struct puffs_newinfo {
|
|
|
|
void **pni_cookie;
|
|
|
|
enum vtype *pni_vtype;
|
|
|
|
voff_t *pni_size;
|
|
|
|
dev_t *pni_rdev;
|
|
|
|
};
|
|
|
|
|
2007-07-01 19:30:15 +04:00
|
|
|
#define PUFFS_MAKEKCRED(to, from) \
|
|
|
|
/*LINTED: tnilxnaht, the cast is ok */ \
|
2007-07-01 21:42:19 +04:00
|
|
|
const struct puffs_kcred *to = (const void *)from
|
2007-07-01 19:30:15 +04:00
|
|
|
#define PUFFS_MAKECRED(to, from) \
|
|
|
|
/*LINTED: tnilxnaht, the cast is ok */ \
|
2007-07-01 21:42:19 +04:00
|
|
|
const struct puffs_cred *to = (const void *)from
|
2007-07-01 19:30:15 +04:00
|
|
|
#define PUFFS_KCREDTOCRED(to, from) \
|
|
|
|
/*LINTED: tnilxnaht, the cast is ok */ \
|
2007-07-01 21:42:19 +04:00
|
|
|
to = (void *)from
|
2007-05-12 01:27:13 +04:00
|
|
|
|
2006-12-29 18:28:11 +03:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2008-01-28 21:35:49 +03:00
|
|
|
void puffs__framev_input(struct puffs_usermount *, struct puffs_framectrl *,
|
2007-12-05 00:24:10 +03:00
|
|
|
struct puffs_fctrl_io *);
|
2008-01-28 21:35:49 +03:00
|
|
|
int puffs__framev_output(struct puffs_usermount *, struct puffs_framectrl*,
|
2007-12-05 00:24:10 +03:00
|
|
|
struct puffs_fctrl_io *);
|
2008-01-28 21:35:49 +03:00
|
|
|
void puffs__framev_exit(struct puffs_usermount *);
|
|
|
|
void puffs__framev_readclose(struct puffs_usermount *,
|
2007-05-15 17:44:46 +04:00
|
|
|
struct puffs_fctrl_io *, int);
|
2008-01-28 21:35:49 +03:00
|
|
|
void puffs__framev_writeclose(struct puffs_usermount *,
|
2007-05-15 17:44:46 +04:00
|
|
|
struct puffs_fctrl_io *, int);
|
2008-01-28 21:35:49 +03:00
|
|
|
void puffs__framev_notify(struct puffs_fctrl_io *, int);
|
2007-12-05 00:24:10 +03:00
|
|
|
void *puffs__framebuf_getdataptr(struct puffs_framebuf *);
|
|
|
|
int puffs__framev_addfd_ctrl(struct puffs_usermount *, int, int,
|
|
|
|
struct puffs_framectrl *);
|
|
|
|
void puffs__framebuf_moveinfo(struct puffs_framebuf *,
|
|
|
|
struct puffs_framebuf *);
|
2007-05-15 17:44:46 +04:00
|
|
|
|
2008-01-28 21:35:49 +03:00
|
|
|
void puffs__theloop(struct puffs_cc *);
|
|
|
|
void puffs__ml_dispatch(struct puffs_usermount *, struct puffs_framebuf *);
|
|
|
|
|
|
|
|
int puffs__cc_create(struct puffs_usermount *, puffs_ccfunc,
|
|
|
|
struct puffs_cc **);
|
|
|
|
void puffs__cc_cont(struct puffs_cc *);
|
|
|
|
void puffs__cc_destroy(struct puffs_cc *, int);
|
|
|
|
void puffs__cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
|
|
|
|
void puffs__goto(struct puffs_cc *);
|
|
|
|
|
|
|
|
int puffs__fsframe_read(struct puffs_usermount *, struct puffs_framebuf *,
|
|
|
|
int, int *);
|
|
|
|
int puffs__fsframe_write(struct puffs_usermount *, struct puffs_framebuf *,
|
|
|
|
int, int *);
|
|
|
|
int puffs__fsframe_cmp(struct puffs_usermount *, struct puffs_framebuf *,
|
|
|
|
struct puffs_framebuf *, int *);
|
|
|
|
void puffs__fsframe_gotframe(struct puffs_usermount *,
|
|
|
|
struct puffs_framebuf *);
|
2007-12-05 00:24:10 +03:00
|
|
|
|
2007-12-05 15:11:56 +03:00
|
|
|
uint64_t puffs__nextreq(struct puffs_usermount *pu);
|
|
|
|
|
2006-12-29 18:28:11 +03:00
|
|
|
__END_DECLS
|
|
|
|
|
2006-12-08 02:15:20 +03:00
|
|
|
#endif /* _PUFFS_PRIVATE_H_ */
|