Home | History | Annotate | Line # | Download | only in libperfuse
perfuse_priv.h revision 1.35
      1  1.35  enami /*  $NetBSD: perfuse_priv.h,v 1.35 2014/09/03 23:59:58 enami Exp $ */
      2   1.1   manu 
      3   1.1   manu /*-
      4  1.17   manu  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
      5   1.1   manu  *
      6   1.1   manu  *  Redistribution and use in source and binary forms, with or without
      7   1.1   manu  *  modification, are permitted provided that the following conditions
      8   1.1   manu  *  are met:
      9   1.1   manu  *  1. Redistributions of source code must retain the above copyright
     10   1.1   manu  *     notice, this list of conditions and the following disclaimer.
     11   1.1   manu  *  2. Redistributions in binary form must reproduce the above copyright
     12   1.1   manu  *     notice, this list of conditions and the following disclaimer in the
     13   1.1   manu  *     documentation and/or other materials provided with the distribution.
     14   1.1   manu  *
     15   1.1   manu  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16   1.1   manu  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17   1.1   manu  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18   1.1   manu  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19   1.1   manu  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20   1.1   manu  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21   1.1   manu  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22   1.1   manu  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23   1.1   manu  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24   1.1   manu  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25   1.1   manu  *  POSSIBILITY OF SUCH DAMAGE.
     26   1.1   manu  */
     27   1.1   manu 
     28   1.1   manu #ifndef _PERFUSE_PRIV_H_
     29   1.1   manu #define _PERFUSE_PRIV_H_
     30   1.1   manu 
     31  1.28   manu #include <unistd.h>
     32   1.1   manu #include <syslog.h>
     33   1.1   manu #include <paths.h>
     34   1.1   manu #include <err.h>
     35   1.1   manu #include <sysexits.h>
     36  1.28   manu #include <signal.h>
     37   1.1   manu #include <puffs.h>
     38   1.1   manu 
     39   1.1   manu #include "perfuse_if.h"
     40   1.1   manu #include "fuse.h"
     41   1.1   manu 
     42  1.31   manu /* From src/sys/fs/puffs/puffs_vfsops.c */
     43  1.31   manu #ifndef PUFFS_PNODEBUCKETS
     44  1.31   manu #define PUFFS_PNODEBUCKETS 256
     45  1.31   manu #endif /* PUFFS_PNODEBUCKETS */
     46  1.31   manu 
     47  1.24   manu #define PERFUSE_TRACECOUNT_MAX 4096
     48  1.24   manu #define PERFUSE_TRACEPATH_MAX 256
     49  1.24   manu struct perfuse_trace {
     50  1.24   manu 	int pt_opcode;
     51  1.24   manu 	char pt_path[PERFUSE_TRACEPATH_MAX];
     52  1.24   manu 	char pt_extra[BUFSIZ];
     53  1.24   manu 	int pt_error;
     54  1.24   manu 	enum { inxchg, done } pt_status;
     55  1.24   manu 	struct timespec pt_start;
     56  1.24   manu 	struct timespec pt_end;
     57  1.24   manu 	TAILQ_ENTRY(perfuse_trace) pt_list;
     58  1.24   manu };
     59  1.24   manu 
     60  1.31   manu LIST_HEAD(perfuse_node_hashlist, perfuse_node_data);
     61   1.1   manu struct perfuse_state {
     62   1.1   manu 	void *ps_private;	/* Private field for libperfuse user */
     63   1.1   manu 	struct puffs_usermount *ps_pu;
     64   1.1   manu 	struct puffs_node *ps_root;
     65   1.3   manu 	uid_t ps_owner_uid;
     66   1.1   manu 	int ps_flags;
     67   1.1   manu #define PS_NO_ACCESS	0x0001	/* access is unimplemented; */
     68   1.1   manu #define PS_NO_CREAT	0x0004	/* create is unimplemented */
     69   1.1   manu #define PS_INLOOP	0x0008	/* puffs mainloop started */
     70  1.17   manu 	uint64_t ps_fsid;
     71   1.1   manu 	uint32_t ps_max_readahead;
     72   1.1   manu 	uint32_t ps_max_write;
     73   1.1   manu 	uint64_t ps_syncreads;
     74   1.1   manu 	uint64_t ps_syncwrites;
     75   1.1   manu 	uint64_t ps_asyncreads;
     76   1.1   manu 	uint64_t ps_asyncwrites;
     77   1.1   manu 	char *ps_source;
     78   1.1   manu 	char *ps_target;
     79   1.1   manu 	char *ps_filesystemtype;
     80   1.1   manu 	int ps_mountflags;
     81   1.1   manu 	uint64_t ps_unique;
     82   1.1   manu 	perfuse_new_msg_fn ps_new_msg;
     83   1.1   manu 	perfuse_xchg_msg_fn ps_xchg_msg;
     84   1.1   manu 	perfuse_destroy_msg_fn ps_destroy_msg;
     85   1.1   manu 	perfuse_get_inhdr_fn ps_get_inhdr;
     86   1.1   manu 	perfuse_get_inpayload_fn ps_get_inpayload;
     87   1.1   manu 	perfuse_get_outhdr_fn ps_get_outhdr;
     88   1.1   manu 	perfuse_get_outpayload_fn ps_get_outpayload;
     89  1.18   manu 	perfuse_umount_fn ps_umount;
     90  1.24   manu 	TAILQ_HEAD(,perfuse_trace) ps_trace;
     91  1.24   manu 	uint64_t ps_tracecount;
     92  1.31   manu 	struct perfuse_node_hashlist *ps_nidhash;
     93  1.31   manu 	int ps_nnidhash;
     94  1.31   manu 	int ps_nodecount;
     95  1.31   manu 	int ps_nodeleakcount;
     96  1.31   manu 	int ps_xchgcount;
     97   1.1   manu };
     98   1.1   manu 
     99   1.1   manu 
    100  1.12   manu enum perfuse_qtype {
    101  1.12   manu 	PCQ_READDIR,
    102  1.12   manu 	PCQ_READ,
    103  1.12   manu 	PCQ_WRITE,
    104  1.12   manu 	PCQ_AFTERWRITE,
    105  1.13   manu 	PCQ_OPEN,
    106  1.22   manu 	PCQ_AFTERXCHG,
    107  1.31   manu 	PCQ_RESIZE,
    108  1.31   manu 	PCQ_REF
    109  1.12   manu };
    110  1.11   manu 
    111  1.10   manu #ifdef PERFUSE_DEBUG
    112  1.27   matt extern const char * const perfuse_qtypestr[];
    113  1.10   manu #endif
    114   1.1   manu 
    115   1.1   manu struct perfuse_cc_queue {
    116   1.1   manu 	enum perfuse_qtype pcq_type;
    117   1.1   manu 	struct puffs_cc *pcq_cc;
    118   1.1   manu 	TAILQ_ENTRY(perfuse_cc_queue) pcq_next;
    119  1.31   manu 	const char *pcq_func;
    120  1.31   manu 	int pcq_line;
    121   1.1   manu };
    122   1.1   manu 
    123   1.1   manu struct perfuse_node_data {
    124   1.5   manu 	uint64_t pnd_rfh;
    125   1.5   manu 	uint64_t pnd_wfh;
    126  1.23   manu 	uint64_t pnd_nodeid;			/* nodeid, this is not inode */
    127  1.31   manu 	uint64_t pnd_parent_nodeid;		/* parent's nodeid */
    128  1.31   manu 	uint32_t pnd_hashidx;			/* node hash index */
    129  1.26   manu 	uint64_t pnd_fuse_nlookup;		/* vnode refcount */
    130  1.26   manu 	int pnd_puffs_nlookup;			/* vnode refcount */
    131   1.1   manu 	uint64_t pnd_lock_owner;
    132   1.1   manu 	struct dirent *pnd_dirent;		/* native buffer for readdir */
    133   1.7   manu 	off_t pnd_dirent_len;
    134   1.1   manu 	struct fuse_dirent *pnd_all_fd;		/* FUSE buffer for readdir */
    135   1.1   manu 	size_t pnd_all_fd_len;
    136  1.21   manu 	uint64_t pnd_fd_cookie;			/* opaque readdir ref from fs */
    137   1.1   manu 	TAILQ_HEAD(,perfuse_cc_queue) pnd_pcq;	/* queued requests */
    138   1.1   manu 	int pnd_flags;
    139  1.11   manu #define PND_RECLAIMED		0x001	/* reclaim pending */
    140  1.11   manu #define PND_INREADDIR		0x002	/* readdir in progress */
    141  1.11   manu #define PND_DIRTY		0x004	/* There is some data to sync */
    142  1.11   manu #define PND_RFH			0x008	/* Read FH allocated */
    143  1.11   manu #define PND_WFH			0x010	/* Write FH allocated */
    144  1.11   manu #define PND_REMOVED		0x020	/* Node was removed */
    145  1.11   manu #define PND_INWRITE		0x040	/* write in progress */
    146  1.12   manu #define PND_INOPEN		0x100	/* open in progress */
    147  1.31   manu #define PND_NODELEAK		0x200	/* node reclaim ignored */
    148  1.31   manu #define PND_INVALID		0x400	/* node freed, usage is a bug */
    149  1.22   manu #define PND_INRESIZE		0x800	/* resize in progress */
    150   1.5   manu 
    151   1.5   manu #define PND_OPEN		(PND_RFH|PND_WFH)	/* File is open */
    152  1.12   manu #define PND_BUSY		(PND_INREADDIR|PND_INWRITE|PND_INOPEN)
    153  1.31   manu 
    154  1.31   manu 	LIST_ENTRY(perfuse_node_data) pnd_nident;
    155  1.11   manu 	puffs_cookie_t pnd_pn;
    156  1.14   manu 	char pnd_name[MAXPATHLEN];	/* node name */
    157  1.31   manu 	struct timespec pnd_cn_expire;
    158  1.31   manu 	int pnd_inxchg;
    159  1.31   manu 	int pnd_ref;
    160   1.1   manu };
    161   1.1   manu 
    162   1.1   manu #define PERFUSE_NODE_DATA(opc)	\
    163   1.1   manu 	((struct perfuse_node_data *)puffs_pn_getpriv((struct puffs_node *)opc))
    164   1.1   manu 
    165   1.1   manu 
    166   1.1   manu #define UNSPEC_REPLY_LEN PERFUSE_UNSPEC_REPLY_LEN /* shorter! */
    167   1.1   manu #define NO_PAYLOAD_REPLY_LEN 0
    168   1.1   manu 
    169   1.1   manu #define GET_INHDR(ps, pm) ps->ps_get_inhdr(pm)
    170   1.1   manu #define GET_INPAYLOAD(ps, pm, type) \
    171   1.1   manu 	(struct type *)(void *)ps->ps_get_inpayload(pm)
    172   1.1   manu #define _GET_INPAYLOAD(ps, pm, type) (type)ps->ps_get_inpayload(pm)
    173   1.1   manu #define GET_OUTHDR(ps, pm) ps->ps_get_outhdr(pm)
    174   1.1   manu #define GET_OUTPAYLOAD(ps, pm, type) \
    175   1.1   manu 	(struct type *)(void *)ps->ps_get_outpayload(pm)
    176   1.1   manu #define _GET_OUTPAYLOAD(ps, pm, type) (type)ps->ps_get_outpayload(pm)
    177   1.1   manu 
    178   1.1   manu __BEGIN_DECLS
    179   1.1   manu 
    180  1.14   manu struct puffs_node *perfuse_new_pn(struct puffs_usermount *, const char *,
    181   1.1   manu     struct puffs_node *);
    182  1.31   manu void perfuse_destroy_pn(struct puffs_usermount *, struct puffs_node *);
    183  1.12   manu void perfuse_new_fh(puffs_cookie_t, uint64_t, int);
    184   1.1   manu void perfuse_destroy_fh(puffs_cookie_t, uint64_t);
    185   1.5   manu uint64_t perfuse_get_fh(puffs_cookie_t, int);
    186   1.1   manu uint64_t perfuse_next_unique(struct puffs_usermount *);
    187  1.31   manu char *perfuse_node_path(struct perfuse_state *, puffs_cookie_t);
    188  1.11   manu int perfuse_node_close_common(struct puffs_usermount *, puffs_cookie_t, int);
    189  1.32   manu int perfuse_ns_match(const int, const char *);
    190  1.19   manu const char *perfuse_native_ns(const int, const char *, char *);
    191   1.1   manu 
    192   1.1   manu char *perfuse_fs_mount(int, ssize_t);
    193   1.1   manu 
    194   1.1   manu 
    195   1.1   manu /*
    196  1.19   manu  * ops.c - filesystem operations
    197   1.1   manu  */
    198   1.1   manu int perfuse_fs_unmount(struct puffs_usermount *, int);
    199   1.1   manu int perfuse_fs_statvfs(struct puffs_usermount *, struct statvfs *);
    200   1.1   manu int perfuse_fs_sync(struct puffs_usermount *, int,
    201   1.1   manu     const struct puffs_cred *);
    202   1.1   manu int perfuse_fs_fhtonode(struct puffs_usermount *, void *, size_t,
    203   1.1   manu     struct puffs_newinfo *);
    204   1.1   manu int perfuse_fs_nodetofh(struct puffs_usermount *, puffs_cookie_t,
    205   1.1   manu     void *, size_t *);
    206   1.1   manu void perfuse_fs_suspend(struct puffs_usermount *, int);
    207   1.1   manu int perfuse_node_lookup(struct puffs_usermount *,
    208   1.1   manu     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *);
    209   1.1   manu int perfuse_node_create(struct puffs_usermount *,
    210   1.1   manu     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    211   1.1   manu     const struct vattr *);
    212   1.1   manu int perfuse_node_mknod(struct puffs_usermount *,
    213   1.1   manu     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    214   1.1   manu     const struct vattr *);
    215   1.1   manu int perfuse_node_open(struct puffs_usermount *,
    216   1.1   manu     puffs_cookie_t, int, const struct puffs_cred *);
    217   1.1   manu int perfuse_node_close(struct puffs_usermount *,
    218   1.1   manu     puffs_cookie_t, int, const struct puffs_cred *);
    219   1.1   manu int perfuse_node_access(struct puffs_usermount *,
    220   1.1   manu     puffs_cookie_t, int, const struct puffs_cred *);
    221   1.1   manu int perfuse_node_getattr(struct puffs_usermount *,
    222   1.1   manu     puffs_cookie_t, struct vattr *, const struct puffs_cred *);
    223   1.1   manu int perfuse_node_setattr(struct puffs_usermount *,
    224   1.1   manu     puffs_cookie_t, const struct vattr *, const struct puffs_cred *);
    225   1.1   manu int perfuse_node_poll(struct puffs_usermount *, puffs_cookie_t, int *);
    226   1.1   manu int perfuse_node_fsync(struct puffs_usermount *,
    227   1.1   manu     puffs_cookie_t, const struct puffs_cred *, int, off_t, off_t);
    228   1.1   manu int perfuse_node_remove(struct puffs_usermount *,
    229   1.1   manu     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    230   1.1   manu int perfuse_node_link(struct puffs_usermount *,
    231   1.1   manu     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    232   1.1   manu int perfuse_node_rename(struct puffs_usermount *,
    233   1.1   manu     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *,
    234   1.1   manu     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    235   1.1   manu int perfuse_node_mkdir(struct puffs_usermount *,
    236   1.1   manu     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    237   1.1   manu     const struct vattr *);
    238   1.1   manu int perfuse_node_rmdir(struct puffs_usermount *,
    239   1.1   manu     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    240   1.1   manu int perfuse_node_symlink(struct puffs_usermount *,
    241   1.1   manu     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    242   1.1   manu     const struct vattr *, const char *);
    243   1.1   manu int perfuse_node_readdir(struct puffs_usermount *,
    244   1.1   manu     puffs_cookie_t, struct dirent *, off_t *, size_t *,
    245   1.1   manu     const struct puffs_cred *, int *, off_t *, size_t *);
    246   1.1   manu int perfuse_node_readlink(struct puffs_usermount *,
    247   1.1   manu     puffs_cookie_t, const struct puffs_cred *, char *, size_t *);
    248   1.1   manu int perfuse_node_reclaim(struct puffs_usermount *, puffs_cookie_t);
    249   1.1   manu int perfuse_node_inactive(struct puffs_usermount *, puffs_cookie_t);
    250   1.1   manu int perfuse_node_print(struct puffs_usermount *, puffs_cookie_t);
    251   1.1   manu int perfuse_node_pathconf(struct puffs_usermount *,
    252  1.35  enami     puffs_cookie_t, int, register_t *);
    253   1.1   manu int perfuse_node_advlock(struct puffs_usermount *,
    254   1.1   manu     puffs_cookie_t, void *, int, struct flock *, int);
    255   1.1   manu int perfuse_node_read(struct puffs_usermount *, puffs_cookie_t,
    256   1.1   manu     uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    257   1.1   manu int perfuse_node_write(struct puffs_usermount *, puffs_cookie_t,
    258   1.1   manu     uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    259  1.31   manu int perfuse_node_write2(struct puffs_usermount *, puffs_cookie_t,
    260  1.31   manu     uint8_t *, off_t, size_t *, const struct puffs_cred *, int, int);
    261  1.33   manu int perfuse_node_open2(struct puffs_usermount *,
    262  1.33   manu     puffs_cookie_t, int, const struct puffs_cred *, int *);
    263   1.1   manu void perfuse_cache_write(struct puffs_usermount *,
    264   1.1   manu     puffs_cookie_t, size_t, struct puffs_cacherun *);
    265  1.19   manu int perfuse_node_getextattr(struct puffs_usermount *, puffs_cookie_t,
    266  1.19   manu     int, const char *, size_t *, uint8_t *, size_t *,
    267  1.19   manu     const struct puffs_cred *);
    268  1.19   manu int perfuse_node_setextattr(struct puffs_usermount *, puffs_cookie_t,
    269  1.19   manu     int, const char *, uint8_t *, size_t *, const struct puffs_cred *);
    270  1.19   manu int perfuse_node_listextattr(struct puffs_usermount *, puffs_cookie_t,
    271  1.20   manu     int, size_t *, uint8_t *, size_t *, int, const struct puffs_cred *);
    272  1.19   manu int perfuse_node_deleteextattr(struct puffs_usermount *, puffs_cookie_t,
    273  1.19   manu     int, const char *, const struct puffs_cred *);
    274  1.29   manu int perfuse_node_getattr_ttl(struct puffs_usermount *,
    275  1.29   manu     puffs_cookie_t, struct vattr *, const struct puffs_cred *,
    276  1.29   manu     struct timespec *);
    277  1.29   manu int perfuse_node_setattr_ttl(struct puffs_usermount *,
    278  1.29   manu     puffs_cookie_t, struct vattr *, const struct puffs_cred *,
    279  1.31   manu     struct timespec *, int);
    280   1.1   manu 
    281  1.25   manu struct perfuse_trace *perfuse_trace_begin(struct perfuse_state *,
    282  1.25   manu     puffs_cookie_t, perfuse_msg_t *);
    283  1.25   manu void perfuse_trace_end(struct perfuse_state *, struct perfuse_trace *, int);
    284  1.24   manu char *perfuse_opdump_in(struct perfuse_state *, perfuse_msg_t *);
    285  1.31   manu struct perfuse_node_data *perfuse_node_bynodeid(struct perfuse_state *,
    286  1.31   manu     uint64_t);
    287  1.31   manu void perfuse_node_cache(struct perfuse_state *, puffs_cookie_t);
    288  1.31   manu void perfuse_cache_flush(puffs_cookie_t);
    289  1.24   manu 
    290   1.1   manu __END_DECLS
    291   1.1   manu 
    292   1.1   manu #endif /* _PERFUSE_PRIV_H_ */
    293