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