2007-06-21 18:54:49 +04:00
|
|
|
/* $NetBSD: puffs_sys.h,v 1.41 2007/06/21 14:54:49 pooka Exp $ */
|
2006-10-23 02:43:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Development of this software was supported by the
|
|
|
|
* Google Summer of Code program and the Ulla Tuominen Foundation.
|
|
|
|
* The Google SoC project was mentored by Bill Studenmund.
|
|
|
|
*
|
|
|
|
* 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_SYS_H_
|
|
|
|
#define _PUFFS_SYS_H_
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/kauth.h>
|
2007-03-29 20:04:26 +04:00
|
|
|
#include <sys/mutex.h>
|
2006-10-23 02:43:23 +04:00
|
|
|
#include <sys/queue.h>
|
2006-11-06 14:44:54 +03:00
|
|
|
#include <sys/pool.h>
|
2006-10-23 02:43:23 +04:00
|
|
|
|
|
|
|
#include <fs/puffs/puffs_msgif.h>
|
|
|
|
|
2006-11-08 01:10:18 +03:00
|
|
|
#include <miscfs/genfs/genfs_node.h>
|
|
|
|
|
2006-10-27 02:52:47 +04:00
|
|
|
extern int (**puffs_vnodeop_p)(void *);
|
|
|
|
extern int (**puffs_specop_p)(void *);
|
2006-10-27 16:25:16 +04:00
|
|
|
extern int (**puffs_fifoop_p)(void *);
|
2006-10-27 02:52:47 +04:00
|
|
|
|
|
|
|
extern const struct vnodeopv_desc puffs_vnodeop_opv_desc;
|
|
|
|
extern const struct vnodeopv_desc puffs_specop_opv_desc;
|
2006-10-27 16:25:16 +04:00
|
|
|
extern const struct vnodeopv_desc puffs_fifoop_opv_desc;
|
2006-12-01 15:37:41 +03:00
|
|
|
extern const struct vnodeopv_desc puffs_msgop_opv_desc;
|
2006-10-27 02:52:47 +04:00
|
|
|
|
2006-11-06 14:44:54 +03:00
|
|
|
extern struct pool puffs_pnpool;
|
|
|
|
|
2007-01-02 18:51:21 +03:00
|
|
|
#define PUFFS_NAMEPREFIX "puffs:"
|
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
#define PUFFS_SIZEOPREQ_UIO_IN 1
|
|
|
|
#define PUFFS_SIZEOPREQ_UIO_OUT 2
|
|
|
|
#define PUFFS_SIZEOPREQ_BUF_IN 3
|
|
|
|
#define PUFFS_SIZEOPREQ_BUF_OUT 4
|
|
|
|
|
|
|
|
#define PUFFS_SIZEOP_UIO(a) \
|
|
|
|
(((a)==PUFFS_SIZEOPREQ_UIO_IN)||(a)==PUFFS_SIZEOPREQ_UIO_OUT)
|
|
|
|
#define PUFFS_SIZEOP_BUF(a) \
|
|
|
|
(((a)==PUFFS_SIZEOPREQ_BUF_IN)||(a)==PUFFS_SIZEOPREQ_BUF_OUT)
|
|
|
|
|
|
|
|
/* XXX: alignment-optimization */
|
|
|
|
struct puffs_sizepark {
|
|
|
|
uint64_t pkso_reqid;
|
|
|
|
uint8_t pkso_reqtype;
|
|
|
|
|
|
|
|
struct uio *pkso_uio;
|
|
|
|
void *pkso_copybuf;
|
|
|
|
size_t pkso_bufsize;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(puffs_sizepark) pkso_entries;
|
|
|
|
};
|
|
|
|
|
2006-12-06 02:03:28 +03:00
|
|
|
#ifdef DEBUG
|
2007-02-15 15:14:34 +03:00
|
|
|
#ifndef PUFFSDEBUG
|
|
|
|
#define PUFFSDEBUG
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PUFFSDEBUG
|
2006-12-06 02:03:28 +03:00
|
|
|
extern int puffsdebug; /* puffs_subr.c */
|
|
|
|
#define DPRINTF(x) if (puffsdebug > 0) printf x
|
|
|
|
#define DPRINTF_VERBOSE(x) if (puffsdebug > 1) printf x
|
|
|
|
#else
|
2006-10-23 02:43:23 +04:00
|
|
|
#define DPRINTF(x)
|
2006-12-01 15:37:41 +03:00
|
|
|
#define DPRINTF_VERBOSE(x)
|
2006-12-06 02:03:28 +03:00
|
|
|
#endif
|
2006-10-23 02:43:23 +04:00
|
|
|
|
|
|
|
#define MPTOPUFFSMP(mp) ((struct puffs_mount *)((mp)->mnt_data))
|
|
|
|
#define PMPTOMP(pmp) (pmp->pmp_mp)
|
|
|
|
#define VPTOPP(vp) ((struct puffs_node *)(vp)->v_data)
|
|
|
|
#define VPTOPNC(vp) (((struct puffs_node *)(vp)->v_data)->pn_cookie)
|
|
|
|
#define VPTOPUFFSMP(vp) ((struct puffs_mount*)((struct puffs_node*)vp->v_data))
|
|
|
|
#define FPTOPMP(fp) (((struct puffs_instance *)fp->f_data)->pi_pmp)
|
|
|
|
#define FPTOPI(fp) ((struct puffs_instance *)fp->f_data)
|
|
|
|
|
2007-04-16 17:03:26 +04:00
|
|
|
/* we don't pass the kernel overlay to userspace */
|
|
|
|
#define PUFFS_TOFHSIZE(s) ((s)==0 ? (s) : (s)+4)
|
|
|
|
#define PUFFS_FROMFHSIZE(s) ((s)==0 ? (s) : (s)-4)
|
|
|
|
|
2007-05-07 21:14:54 +04:00
|
|
|
#define ALLOPS(pmp) (pmp->pmp_flags & PUFFS_KFLAG_ALLOPS)
|
2006-12-01 15:37:41 +03:00
|
|
|
#define EXISTSOP(pmp, op) \
|
2007-05-07 21:14:54 +04:00
|
|
|
(ALLOPS(pmp) || ((pmp)->pmp_vnopmask[PUFFS_VN_##op]))
|
2006-12-01 15:37:41 +03:00
|
|
|
|
2006-12-30 04:29:03 +03:00
|
|
|
#define PUFFS_DOCACHE(pmp) (((pmp)->pmp_flags & PUFFS_KFLAG_NOCACHE) == 0)
|
|
|
|
|
2007-03-20 13:21:58 +03:00
|
|
|
#define PUFFS_WCACHEINFO(pmp) 0
|
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
TAILQ_HEAD(puffs_wq, puffs_park);
|
2007-01-16 02:29:08 +03:00
|
|
|
LIST_HEAD(puffs_node_hashlist, puffs_node);
|
2006-10-23 02:43:23 +04:00
|
|
|
struct puffs_mount {
|
2007-03-29 20:04:26 +04:00
|
|
|
kmutex_t pmp_lock;
|
2006-10-23 02:43:23 +04:00
|
|
|
|
2007-04-13 17:31:11 +04:00
|
|
|
struct puffs_kargs pmp_args;
|
2006-12-01 15:37:41 +03:00
|
|
|
#define pmp_flags pmp_args.pa_flags
|
|
|
|
#define pmp_vnopmask pmp_args.pa_vnopmask
|
2006-10-23 02:43:23 +04:00
|
|
|
|
|
|
|
struct puffs_wq pmp_req_touser;
|
2007-05-01 16:18:40 +04:00
|
|
|
int pmp_req_touser_count;
|
2007-03-29 20:04:26 +04:00
|
|
|
kcondvar_t pmp_req_waiter_cv;
|
2006-10-23 02:43:23 +04:00
|
|
|
size_t pmp_req_maxsize;
|
|
|
|
|
|
|
|
struct puffs_wq pmp_req_replywait;
|
|
|
|
TAILQ_HEAD(, puffs_sizepark) pmp_req_sizepark;
|
|
|
|
|
2007-01-16 02:29:08 +03:00
|
|
|
struct puffs_node_hashlist *pmp_pnodehash;
|
2007-04-16 17:03:26 +04:00
|
|
|
int pmp_npnodehash;
|
2006-10-23 02:43:23 +04:00
|
|
|
|
|
|
|
struct mount *pmp_mp;
|
2007-05-17 17:59:22 +04:00
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
struct vnode *pmp_root;
|
2007-05-17 17:59:22 +04:00
|
|
|
void *pmp_root_cookie;
|
|
|
|
enum vtype pmp_root_vtype;
|
|
|
|
vsize_t pmp_root_vsize;
|
|
|
|
dev_t pmp_root_rdev;
|
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
struct selinfo *pmp_sel; /* in puffs_instance */
|
|
|
|
|
2007-05-01 16:18:40 +04:00
|
|
|
unsigned int pmp_refcount;
|
|
|
|
kcondvar_t pmp_refcount_cv;
|
2007-03-29 20:04:26 +04:00
|
|
|
|
2007-05-01 16:18:40 +04:00
|
|
|
kcondvar_t pmp_unmounting_cv;
|
2006-12-11 01:33:31 +03:00
|
|
|
uint8_t pmp_unmounting;
|
2007-05-01 16:18:40 +04:00
|
|
|
|
|
|
|
uint8_t pmp_status;
|
2007-01-27 01:59:49 +03:00
|
|
|
uint8_t pmp_suspend;
|
2007-03-29 20:04:26 +04:00
|
|
|
|
|
|
|
uint64_t pmp_nextreq;
|
2006-10-23 02:43:23 +04:00
|
|
|
};
|
2006-11-17 20:48:02 +03:00
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
#define PUFFSTAT_BEFOREINIT 0
|
|
|
|
#define PUFFSTAT_MOUNTING 1
|
|
|
|
#define PUFFSTAT_RUNNING 2
|
2006-12-11 01:33:31 +03:00
|
|
|
#define PUFFSTAT_DYING 3 /* Do you want your possessions identified? */
|
2006-10-23 02:43:23 +04:00
|
|
|
|
2007-03-20 13:21:58 +03:00
|
|
|
|
2007-05-18 19:46:09 +04:00
|
|
|
#define PNODE_NOREFS 0x01 /* no backend reference */
|
2007-05-19 20:50:49 +04:00
|
|
|
#define PNODE_DYING 0x02 /* NOREF + inactive */
|
|
|
|
#define PNODE_SUSPEND 0x04 /* issue all operations as FAF */
|
|
|
|
#define PNODE_DOINACT 0x08 /* if inactive-on-demand, call inactive */
|
2007-03-20 13:21:58 +03:00
|
|
|
|
|
|
|
#define PNODE_METACACHE_ATIME 0x10 /* cache atime metadata */
|
|
|
|
#define PNODE_METACACHE_CTIME 0x20 /* cache atime metadata */
|
|
|
|
#define PNODE_METACACHE_MTIME 0x40 /* cache atime metadata */
|
|
|
|
#define PNODE_METACACHE_SIZE 0x80 /* cache atime metadata */
|
|
|
|
#define PNODE_METACACHE_MASK 0xf0
|
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
struct puffs_node {
|
2006-11-08 01:10:18 +03:00
|
|
|
struct genfs_node pn_gnode; /* genfs glue */
|
|
|
|
|
2007-05-18 17:53:08 +04:00
|
|
|
kmutex_t pn_mtx;
|
|
|
|
int pn_refcount;
|
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
void *pn_cookie; /* userspace pnode cookie */
|
|
|
|
struct vnode *pn_vp; /* backpointer to vnode */
|
|
|
|
uint32_t pn_stat; /* node status */
|
|
|
|
|
2007-05-18 17:53:08 +04:00
|
|
|
struct selinfo pn_sel; /* for selecting on the node */
|
|
|
|
short pn_revents; /* available events */
|
|
|
|
|
2007-03-20 13:21:58 +03:00
|
|
|
/* metacache */
|
|
|
|
struct timespec pn_mc_atime;
|
|
|
|
struct timespec pn_mc_ctime;
|
|
|
|
struct timespec pn_mc_mtime;
|
|
|
|
u_quad_t pn_mc_size;
|
|
|
|
|
2007-01-16 02:29:08 +03:00
|
|
|
LIST_ENTRY(puffs_node) pn_hashent;
|
2006-10-23 02:43:23 +04:00
|
|
|
};
|
|
|
|
|
2007-03-30 21:48:57 +04:00
|
|
|
typedef void (*parkdone_fn)(struct puffs_req *, void *);
|
|
|
|
|
2007-03-29 20:04:26 +04:00
|
|
|
void puffs_transport_init(void);
|
|
|
|
void puffs_transport_destroy(void);
|
|
|
|
|
|
|
|
void puffs_msgif_init(void);
|
|
|
|
void puffs_msgif_destroy(void);
|
2007-04-04 20:13:51 +04:00
|
|
|
void *puffs_park_alloc(int);
|
|
|
|
void puffs_park_release(void *, int);
|
2007-03-29 20:04:26 +04:00
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
int puffs_vfstouser(struct puffs_mount *, int, void *, size_t);
|
2007-01-27 01:59:49 +03:00
|
|
|
void puffs_suspendtouser(struct puffs_mount *, int);
|
2007-03-30 21:48:57 +04:00
|
|
|
int puffs_vntouser(struct puffs_mount *, int, void *, size_t, size_t,
|
2007-05-07 21:14:54 +04:00
|
|
|
struct vnode *, struct vnode *);
|
2007-03-30 21:48:57 +04:00
|
|
|
int puffs_vntouser_req(struct puffs_mount *, int, void *, size_t, size_t,
|
2007-05-07 21:14:54 +04:00
|
|
|
uint64_t, struct vnode *, struct vnode *);
|
2007-03-30 21:48:57 +04:00
|
|
|
void puffs_vntouser_call(struct puffs_mount *, int, void *, size_t, size_t,
|
2007-05-07 21:14:54 +04:00
|
|
|
parkdone_fn, void *, struct vnode *, struct vnode*);
|
|
|
|
void puffs_vntouser_faf(struct puffs_mount *, int, void *, size_t,
|
|
|
|
struct vnode *);
|
2007-03-20 13:21:58 +03:00
|
|
|
void puffs_cacheop(struct puffs_mount *, struct puffs_park *,
|
|
|
|
struct puffs_cacheinfo *, size_t, void *);
|
|
|
|
struct puffs_park *puffs_cacheop_alloc(void);
|
2006-10-23 02:43:23 +04:00
|
|
|
|
2006-11-08 01:10:18 +03:00
|
|
|
int puffs_getvnode(struct mount *, void *, enum vtype, voff_t, dev_t,
|
2006-10-27 02:52:47 +04:00
|
|
|
struct vnode **);
|
2006-10-23 02:43:23 +04:00
|
|
|
int puffs_newnode(struct mount *, struct vnode *, struct vnode **,
|
2006-10-27 02:52:47 +04:00
|
|
|
void *, struct componentname *, enum vtype, dev_t);
|
2006-10-23 02:43:23 +04:00
|
|
|
void puffs_putvnode(struct vnode *);
|
2007-05-18 17:53:08 +04:00
|
|
|
|
|
|
|
void puffs_releasenode(struct puffs_node *);
|
|
|
|
void puffs_referencenode(struct puffs_node *);
|
|
|
|
|
2007-06-21 18:54:49 +04:00
|
|
|
int puffs_pnode2vnode(struct puffs_mount *, void *, int, struct vnode **);
|
2006-12-29 18:38:37 +03:00
|
|
|
void puffs_makecn(struct puffs_kcn *, const struct componentname *);
|
2006-10-23 02:43:23 +04:00
|
|
|
void puffs_credcvt(struct puffs_cred *, kauth_cred_t);
|
|
|
|
pid_t puffs_lwp2pid(struct lwp *);
|
|
|
|
|
2007-03-30 21:48:57 +04:00
|
|
|
void puffs_parkdone_asyncbioread(struct puffs_req *, void *);
|
2007-05-18 17:53:08 +04:00
|
|
|
void puffs_parkdone_poll(struct puffs_req *, void *);
|
2007-03-30 21:48:57 +04:00
|
|
|
|
2007-05-01 16:18:40 +04:00
|
|
|
void puffs_mp_reference(struct puffs_mount *);
|
|
|
|
void puffs_mp_release(struct puffs_mount *);
|
|
|
|
|
2006-11-08 01:10:18 +03:00
|
|
|
void puffs_updatenode(struct vnode *, int);
|
|
|
|
#define PUFFS_UPDATEATIME 0x01
|
|
|
|
#define PUFFS_UPDATECTIME 0x02
|
|
|
|
#define PUFFS_UPDATEMTIME 0x04
|
|
|
|
#define PUFFS_UPDATESIZE 0x08
|
2006-11-18 11:18:24 +03:00
|
|
|
void puffs_updatevpsize(struct vnode *);
|
2006-11-08 01:10:18 +03:00
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
int puffs_setpmp(pid_t, int, struct puffs_mount *);
|
|
|
|
void puffs_nukebypmp(struct puffs_mount *);
|
|
|
|
|
2007-03-29 20:04:26 +04:00
|
|
|
uint64_t puffs_getreqid(struct puffs_mount *);
|
|
|
|
void puffs_userdead(struct puffs_mount *);
|
2006-10-23 02:43:23 +04:00
|
|
|
|
2006-12-06 02:41:24 +03:00
|
|
|
/* get/put called by ioctl handler */
|
|
|
|
int puffs_getop(struct puffs_mount *, struct puffs_reqh_get *, int);
|
|
|
|
int puffs_putop(struct puffs_mount *, struct puffs_reqh_put *);
|
|
|
|
|
2006-10-23 02:43:23 +04:00
|
|
|
extern int (**puffs_vnodeop_p)(void *);
|
|
|
|
|
|
|
|
MALLOC_DECLARE(M_PUFFS);
|
|
|
|
|
|
|
|
#endif /* _PUFFS_SYS_H_ */
|