2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
9 #include <linux/fuse.h>
11 #include <linux/wait.h>
12 #include <linux/list.h>
13 #include <linux/spinlock.h>
15 #include <linux/backing-dev.h>
16 #include <asm/semaphore.h>
18 /** Max number of pages that can be used in a single read request */
19 #define FUSE_MAX_PAGES_PER_REQ 32
21 /** If more requests are outstanding, then the operation will block */
22 #define FUSE_MAX_OUTSTANDING 10
29 /** Unique ID, which identifies the inode between userspace
33 /** Time in jiffies until the file attributes are valid */
37 /** One input argument of a request */
43 /** The request input */
45 /** The request header */
46 struct fuse_in_header h;
48 /** True if the data for the last argument is in req->pages */
51 /** Number of arguments */
54 /** Array of arguments */
55 struct fuse_in_arg args[3];
58 /** One output argument of a request */
64 /** The request output */
66 /** Header returned from userspace */
67 struct fuse_out_header h;
69 /** Last argument is variable length (can be shorter than
73 /** Last argument is a list of pages to copy data to */
76 /** Zero partially or not copied pages */
77 unsigned page_zeroing:1;
79 /** Number or arguments */
82 /** Array of arguments */
83 struct fuse_arg args[3];
90 * A request to the client
93 /** This can be on either unused_list, pending or processing
95 struct list_head list;
100 /** True if the request has reply */
103 /** The request is preallocated */
104 unsigned preallocated:1;
106 /** The request was interrupted */
107 unsigned interrupted:1;
109 /** Request is sent in the background */
110 unsigned background:1;
112 /** Data is being copied to/from the request */
115 /** Request has been sent to userspace */
118 /** The request is finished */
121 /** The request input */
124 /** The request output */
127 /** Used to wake up the task waiting for completion of request*/
128 wait_queue_head_t waitq;
130 /** Data for asynchronous requests */
132 struct fuse_init_in_out init_in_out;
136 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
138 /** number of pages in vector */
141 /** offset of data on first page */
142 unsigned page_offset;
144 /** Inode used in the request */
147 /** Second inode used in the request (or NULL) */
148 struct inode *inode2;
150 /** File used in the request (or NULL) */
157 * This structure is created, when the filesystem is mounted, and is
158 * destroyed, when the client device is closed and the filesystem is
162 /** The superblock of the mounted filesystem */
163 struct super_block *sb;
165 /** The opened client device */
168 /** The user id for this mount */
171 /** Readers of the connection are waiting on this */
172 wait_queue_head_t waitq;
174 /** The list of pending requests */
175 struct list_head pending;
177 /** The list of requests being processed */
178 struct list_head processing;
180 /** Controls the maximum number of outstanding requests */
181 struct semaphore outstanding_sem;
183 /** This counts the number of outstanding requests if
184 outstanding_sem would go negative */
185 unsigned outstanding_debt;
187 /** The list of unused requests */
188 struct list_head unused_list;
190 /** The next unique request id */
193 /** Connection failed (version mismatch) */
194 unsigned conn_error : 1;
196 /** Backing dev info */
197 struct backing_dev_info bdi;
200 static inline struct fuse_conn **get_fuse_conn_super_p(struct super_block *sb)
202 return (struct fuse_conn **) &sb->s_fs_info;
205 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
207 return *get_fuse_conn_super_p(sb);
210 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
212 return get_fuse_conn_super(inode->i_sb);
215 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
217 return container_of(inode, struct fuse_inode, inode);
220 static inline u64 get_node_id(struct inode *inode)
222 return get_fuse_inode(inode)->nodeid;
225 /** Device operations */
226 extern struct file_operations fuse_dev_operations;
229 * This is the single global spinlock which protects FUSE's structures
231 * The following data is protected by this lock:
233 * - the private_data field of the device file
234 * - the s_fs_info field of the super block
235 * - unused_list, pending, processing lists in fuse_conn
236 * - the unique request ID counter reqctr in fuse_conn
237 * - the sb (super_block) field in fuse_conn
238 * - the file (device file) field in fuse_conn
240 extern spinlock_t fuse_lock;
243 * Check if the connection can be released, and if yes, then free the
244 * connection structure
246 void fuse_release_conn(struct fuse_conn *fc);
249 * Initialize the client device
251 int fuse_dev_init(void);
254 * Cleanup the client device
256 void fuse_dev_cleanup(void);
261 struct fuse_req *fuse_request_alloc(void);
266 void fuse_request_free(struct fuse_req *req);
269 * Reinitialize a request, the preallocated flag is left unmodified
271 void fuse_reset_request(struct fuse_req *req);
274 * Reserve a preallocated request
276 struct fuse_req *fuse_get_request(struct fuse_conn *fc);
279 * Reserve a preallocated request, only interruptible by SIGKILL
281 struct fuse_req *fuse_get_request_nonint(struct fuse_conn *fc);
284 * Decrement reference count of a request. If count goes to zero put
285 * on unused list (preallocated) or free reqest (not preallocated).
287 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
290 * Send a request (synchronous, interruptible)
292 void request_send(struct fuse_conn *fc, struct fuse_req *req);
295 * Send a request (synchronous, non-interruptible except by SIGKILL)
297 void request_send_nonint(struct fuse_conn *fc, struct fuse_req *req);
300 * Send a request with no reply
302 void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
305 * Send a request in the background
307 void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
310 * Send the INIT message
312 void fuse_send_init(struct fuse_conn *fc);