fuse: save space in struct fuse_req
[deliverable/linux.git] / fs / fuse / fuse_i.h
CommitLineData
d8a5ba45
MS
1/*
2 FUSE: Filesystem in Userspace
d7133114 3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
d8a5ba45
MS
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include <linux/fuse.h>
10#include <linux/fs.h>
51eb01e7 11#include <linux/mount.h>
d8a5ba45
MS
12#include <linux/wait.h>
13#include <linux/list.h>
14#include <linux/spinlock.h>
15#include <linux/mm.h>
16#include <linux/backing-dev.h>
bafa9654 17#include <linux/mutex.h>
d8a5ba45 18
334f485d
MS
19/** Max number of pages that can be used in a single read request */
20#define FUSE_MAX_PAGES_PER_REQ 32
21
08a53cdc 22/** Maximum number of outstanding background requests */
f92b99b9
MS
23#define FUSE_MAX_BACKGROUND 12
24
25/** Congestion starts at 75% of maximum */
26#define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100)
08a53cdc 27
1d3d752b
MS
28/** It could be as large as PATH_MAX, but would that have any uses? */
29#define FUSE_NAME_MAX 1024
30
bafa9654
MS
31/** Number of dentries for each connection in the control filesystem */
32#define FUSE_CTL_NUM_DENTRIES 3
33
1e9a4ed9
MS
34/** If the FUSE_DEFAULT_PERMISSIONS flag is given, the filesystem
35 module will check permissions based on the file mode. Otherwise no
36 permission checking is done in the kernel */
37#define FUSE_DEFAULT_PERMISSIONS (1 << 0)
38
39/** If the FUSE_ALLOW_OTHER flag is given, then not only the user
40 doing the mount will be allowed to access the filesystem */
41#define FUSE_ALLOW_OTHER (1 << 1)
42
bafa9654
MS
43/** List of active connections */
44extern struct list_head fuse_conn_list;
45
46/** Global mutex protecting fuse_conn_list and the control filesystem */
47extern struct mutex fuse_mutex;
413ef8cb 48
d8a5ba45
MS
49/** FUSE inode */
50struct fuse_inode {
51 /** Inode data */
52 struct inode inode;
53
54 /** Unique ID, which identifies the inode between userspace
55 * and kernel */
56 u64 nodeid;
57
9e6268db
MS
58 /** Number of lookups on this inode */
59 u64 nlookup;
60
e5e5558e
MS
61 /** The request used for sending the FORGET message */
62 struct fuse_req *forget_req;
63
d8a5ba45 64 /** Time in jiffies until the file attributes are valid */
0a0898cf 65 u64 i_time;
ebc14c4d
MS
66
67 /** The sticky bit in inode->i_mode may have been removed, so
68 preserve the original mode */
69 mode_t orig_i_mode;
1fb69e78
MS
70
71 /** Version of last attribute change */
72 u64 attr_version;
93a8c3cd
MS
73
74 /** Files usable in writepage. Protected by fc->lock */
75 struct list_head write_files;
d8a5ba45
MS
76};
77
b6aeaded
MS
78/** FUSE specific file data */
79struct fuse_file {
80 /** Request reserved for flush and release */
33649c91 81 struct fuse_req *reserved_req;
b6aeaded
MS
82
83 /** File handle used by userspace */
84 u64 fh;
c756e0a4
MS
85
86 /** Refcount */
87 atomic_t count;
93a8c3cd
MS
88
89 /** Entry on inode's write_files list */
90 struct list_head write_entry;
b6aeaded
MS
91};
92
334f485d
MS
93/** One input argument of a request */
94struct fuse_in_arg {
95 unsigned size;
96 const void *value;
97};
98
99/** The request input */
100struct fuse_in {
101 /** The request header */
102 struct fuse_in_header h;
103
104 /** True if the data for the last argument is in req->pages */
105 unsigned argpages:1;
106
107 /** Number of arguments */
108 unsigned numargs;
109
110 /** Array of arguments */
111 struct fuse_in_arg args[3];
112};
113
114/** One output argument of a request */
115struct fuse_arg {
116 unsigned size;
117 void *value;
118};
119
120/** The request output */
121struct fuse_out {
122 /** Header returned from userspace */
123 struct fuse_out_header h;
124
095da6cb
MS
125 /*
126 * The following bitfields are not changed during the request
127 * processing
128 */
129
334f485d
MS
130 /** Last argument is variable length (can be shorter than
131 arg->size) */
132 unsigned argvar:1;
133
134 /** Last argument is a list of pages to copy data to */
135 unsigned argpages:1;
136
137 /** Zero partially or not copied pages */
138 unsigned page_zeroing:1;
139
140 /** Number or arguments */
141 unsigned numargs;
142
143 /** Array of arguments */
144 struct fuse_arg args[3];
145};
146
83cfd493
MS
147/** The request state */
148enum fuse_req_state {
149 FUSE_REQ_INIT = 0,
150 FUSE_REQ_PENDING,
151 FUSE_REQ_READING,
152 FUSE_REQ_SENT,
a4d27e75 153 FUSE_REQ_WRITING,
83cfd493
MS
154 FUSE_REQ_FINISHED
155};
156
64c6d8ed
MS
157struct fuse_conn;
158
334f485d
MS
159/**
160 * A request to the client
161 */
162struct fuse_req {
ce1d5a49
MS
163 /** This can be on either pending processing or io lists in
164 fuse_conn */
334f485d
MS
165 struct list_head list;
166
a4d27e75
MS
167 /** Entry on the interrupts list */
168 struct list_head intr_entry;
169
334f485d
MS
170 /** refcount */
171 atomic_t count;
172
a4d27e75
MS
173 /** Unique ID for the interrupt request */
174 u64 intr_unique;
175
095da6cb
MS
176 /*
177 * The following bitfields are either set once before the
178 * request is queued or setting/clearing them is protected by
d7133114 179 * fuse_conn->lock
095da6cb
MS
180 */
181
334f485d
MS
182 /** True if the request has reply */
183 unsigned isreply:1;
184
51eb01e7
MS
185 /** Force sending of the request even if interrupted */
186 unsigned force:1;
187
f9a2842e
MS
188 /** The request was aborted */
189 unsigned aborted:1;
334f485d
MS
190
191 /** Request is sent in the background */
192 unsigned background:1;
193
a4d27e75
MS
194 /** The request has been interrupted */
195 unsigned interrupted:1;
196
334f485d
MS
197 /** Data is being copied to/from the request */
198 unsigned locked:1;
199
9bc5ddda
MS
200 /** Request is counted as "waiting" */
201 unsigned waiting:1;
202
83cfd493
MS
203 /** State of the request */
204 enum fuse_req_state state;
334f485d
MS
205
206 /** The request input */
207 struct fuse_in in;
208
209 /** The request output */
210 struct fuse_out out;
211
212 /** Used to wake up the task waiting for completion of request*/
213 wait_queue_head_t waitq;
214
215 /** Data for asynchronous requests */
216 union {
e5e5558e 217 struct fuse_forget_in forget_in;
b57d4264
MS
218 struct {
219 struct fuse_release_in in;
220 struct vfsmount *vfsmount;
221 struct dentry *dentry;
222 } release;
3ec870d5
MS
223 struct fuse_init_in init_in;
224 struct fuse_init_out init_out;
361b1eb5 225 struct fuse_read_in read_in;
b25e82e5
MS
226 struct {
227 struct fuse_write_in in;
228 struct fuse_write_out out;
229 } write;
71421259 230 struct fuse_lk_in lk_in;
334f485d
MS
231 } misc;
232
233 /** page vector */
234 struct page *pages[FUSE_MAX_PAGES_PER_REQ];
235
236 /** number of pages in vector */
237 unsigned num_pages;
238
239 /** offset of data on first page */
240 unsigned page_offset;
241
334f485d 242 /** File used in the request (or NULL) */
c756e0a4 243 struct fuse_file *ff;
64c6d8ed
MS
244
245 /** Request completion callback */
246 void (*end)(struct fuse_conn *, struct fuse_req *);
33649c91
MS
247
248 /** Request is stolen from fuse_file->reserved_req */
249 struct file *stolen_file;
334f485d
MS
250};
251
d8a5ba45
MS
252/**
253 * A Fuse connection.
254 *
255 * This structure is created, when the filesystem is mounted, and is
256 * destroyed, when the client device is closed and the filesystem is
257 * unmounted.
258 */
259struct fuse_conn {
d7133114
MS
260 /** Lock protecting accessess to members of this structure */
261 spinlock_t lock;
262
d2a85164
MS
263 /** Mutex protecting against directory alias creation */
264 struct mutex inst_mutex;
265
bafa9654
MS
266 /** Refcount */
267 atomic_t count;
268
d8a5ba45
MS
269 /** The user id for this mount */
270 uid_t user_id;
271
87729a55
MS
272 /** The group id for this mount */
273 gid_t group_id;
274
1e9a4ed9
MS
275 /** The fuse mount flags for this mount */
276 unsigned flags;
277
db50b96c
MS
278 /** Maximum read size */
279 unsigned max_read;
280
413ef8cb
MS
281 /** Maximum write size */
282 unsigned max_write;
283
334f485d
MS
284 /** Readers of the connection are waiting on this */
285 wait_queue_head_t waitq;
286
287 /** The list of pending requests */
288 struct list_head pending;
289
290 /** The list of requests being processed */
291 struct list_head processing;
292
d77a1d5b
MS
293 /** The list of requests under I/O */
294 struct list_head io;
295
08a53cdc
MS
296 /** Number of requests currently in the background */
297 unsigned num_background;
298
a4d27e75
MS
299 /** Pending interrupts */
300 struct list_head interrupts;
301
08a53cdc
MS
302 /** Flag indicating if connection is blocked. This will be
303 the case before the INIT reply is received, and if there
304 are too many outstading backgrounds requests */
305 int blocked;
306
307 /** waitq for blocked connection */
308 wait_queue_head_t blocked_waitq;
de5e3dec
MS
309
310 /** waitq for reserved requests */
311 wait_queue_head_t reserved_req_waitq;
08a53cdc 312
334f485d
MS
313 /** The next unique request id */
314 u64 reqctr;
315
69a53bf2
MS
316 /** Connection established, cleared on umount, connection
317 abort and device release */
095da6cb 318 unsigned connected;
1e9a4ed9 319
095da6cb
MS
320 /** Connection failed (version mismatch). Cannot race with
321 setting other bitfields since it is only set once in INIT
322 reply, before any other request, and never cleared */
334f485d
MS
323 unsigned conn_error : 1;
324
0ec7ca41
MS
325 /** Connection successful. Only set in INIT */
326 unsigned conn_init : 1;
327
9cd68455
MS
328 /** Do readpages asynchronously? Only set in INIT */
329 unsigned async_read : 1;
330
6ff958ed
MS
331 /** Do not send separate SETATTR request before open(O_TRUNC) */
332 unsigned atomic_o_trunc : 1;
333
095da6cb
MS
334 /*
335 * The following bitfields are only for optimization purposes
336 * and hence races in setting them will not cause malfunction
337 */
338
b6aeaded
MS
339 /** Is fsync not implemented by fs? */
340 unsigned no_fsync : 1;
341
82547981
MS
342 /** Is fsyncdir not implemented by fs? */
343 unsigned no_fsyncdir : 1;
344
b6aeaded
MS
345 /** Is flush not implemented by fs? */
346 unsigned no_flush : 1;
347
92a8780e
MS
348 /** Is setxattr not implemented by fs? */
349 unsigned no_setxattr : 1;
350
351 /** Is getxattr not implemented by fs? */
352 unsigned no_getxattr : 1;
353
354 /** Is listxattr not implemented by fs? */
355 unsigned no_listxattr : 1;
356
357 /** Is removexattr not implemented by fs? */
358 unsigned no_removexattr : 1;
359
71421259
MS
360 /** Are file locking primitives not implemented by fs? */
361 unsigned no_lock : 1;
362
31d40d74
MS
363 /** Is access not implemented by fs? */
364 unsigned no_access : 1;
365
fd72faac
MS
366 /** Is create not implemented by fs? */
367 unsigned no_create : 1;
368
a4d27e75
MS
369 /** Is interrupt not implemented by fs? */
370 unsigned no_interrupt : 1;
371
b2d2272f
MS
372 /** Is bmap not implemented by fs? */
373 unsigned no_bmap : 1;
374
0cd5b885
MS
375 /** The number of requests waiting for completion */
376 atomic_t num_waiting;
377
45714d65
MS
378 /** Negotiated minor version */
379 unsigned minor;
380
d8a5ba45
MS
381 /** Backing dev info */
382 struct backing_dev_info bdi;
f543f253 383
bafa9654
MS
384 /** Entry on the fuse_conn_list */
385 struct list_head entry;
386
387 /** Unique ID */
388 u64 id;
389
390 /** Dentries in the control filesystem */
391 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
392
393 /** number of dentries used in the above array */
394 int ctl_ndents;
385a17bf
JD
395
396 /** O_ASYNC requests */
397 struct fasync_struct *fasync;
9c8ef561
MS
398
399 /** Key for lock owner ID scrambling */
400 u32 scramble_key[4];
0ec7ca41
MS
401
402 /** Reserved request for the DESTROY message */
403 struct fuse_req *destroy_req;
1fb69e78
MS
404
405 /** Version counter for attribute changes */
406 u64 attr_version;
d8a5ba45
MS
407};
408
d8a5ba45
MS
409static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
410{
6383bdaa 411 return sb->s_fs_info;
d8a5ba45
MS
412}
413
414static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
415{
416 return get_fuse_conn_super(inode->i_sb);
417}
418
419static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
420{
421 return container_of(inode, struct fuse_inode, inode);
422}
423
424static inline u64 get_node_id(struct inode *inode)
425{
426 return get_fuse_inode(inode)->nodeid;
427}
428
334f485d 429/** Device operations */
4b6f5d20 430extern const struct file_operations fuse_dev_operations;
334f485d 431
e5e5558e
MS
432/**
433 * Get a filled in inode
434 */
435struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
1fb69e78
MS
436 int generation, struct fuse_attr *attr,
437 u64 attr_valid, u64 attr_version);
e5e5558e
MS
438
439/**
440 * Send FORGET command
441 */
442void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
9e6268db 443 unsigned long nodeid, u64 nlookup);
e5e5558e 444
04730fef 445/**
361b1eb5 446 * Initialize READ or READDIR request
04730fef 447 */
a6643094 448void fuse_read_fill(struct fuse_req *req, struct file *file,
361b1eb5 449 struct inode *inode, loff_t pos, size_t count, int opcode);
04730fef
MS
450
451/**
452 * Send OPEN or OPENDIR request
453 */
454int fuse_open_common(struct inode *inode, struct file *file, int isdir);
455
fd72faac
MS
456struct fuse_file *fuse_file_alloc(void);
457void fuse_file_free(struct fuse_file *ff);
458void fuse_finish_open(struct inode *inode, struct file *file,
459 struct fuse_file *ff, struct fuse_open_out *outarg);
460
c756e0a4
MS
461/** Fill in ff->reserved_req with a RELEASE request */
462void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode);
463
04730fef
MS
464/**
465 * Send RELEASE or RELEASEDIR request
466 */
467int fuse_release_common(struct inode *inode, struct file *file, int isdir);
468
82547981
MS
469/**
470 * Send FSYNC or FSYNCDIR request
471 */
472int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
473 int isdir);
474
b6aeaded 475/**
1779381d 476 * Initialize file operations on a regular file
b6aeaded
MS
477 */
478void fuse_init_file_inode(struct inode *inode);
479
e5e5558e 480/**
1779381d 481 * Initialize inode operations on regular files and special files
e5e5558e
MS
482 */
483void fuse_init_common(struct inode *inode);
484
485/**
1779381d 486 * Initialize inode and file operations on a directory
e5e5558e
MS
487 */
488void fuse_init_dir(struct inode *inode);
489
490/**
1779381d 491 * Initialize inode operations on a symlink
e5e5558e
MS
492 */
493void fuse_init_symlink(struct inode *inode);
494
495/**
496 * Change attributes of an inode
497 */
1fb69e78
MS
498void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
499 u64 attr_valid, u64 attr_version);
e5e5558e 500
334f485d
MS
501/**
502 * Initialize the client device
503 */
504int fuse_dev_init(void);
505
506/**
507 * Cleanup the client device
508 */
509void fuse_dev_cleanup(void);
510
bafa9654
MS
511int fuse_ctl_init(void);
512void fuse_ctl_cleanup(void);
513
334f485d
MS
514/**
515 * Allocate a request
516 */
517struct fuse_req *fuse_request_alloc(void);
518
519/**
520 * Free a request
521 */
522void fuse_request_free(struct fuse_req *req);
523
334f485d 524/**
33649c91 525 * Get a request, may fail with -ENOMEM
334f485d 526 */
ce1d5a49 527struct fuse_req *fuse_get_req(struct fuse_conn *fc);
334f485d 528
33649c91
MS
529/**
530 * Gets a requests for a file operation, always succeeds
531 */
532struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file);
533
334f485d 534/**
ce1d5a49
MS
535 * Decrement reference count of a request. If count goes to zero free
536 * the request.
334f485d
MS
537 */
538void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
539
540/**
7c352bdf 541 * Send a request (synchronous)
334f485d
MS
542 */
543void request_send(struct fuse_conn *fc, struct fuse_req *req);
544
334f485d
MS
545/**
546 * Send a request with no reply
547 */
548void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
549
550/**
551 * Send a request in the background
552 */
553void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
554
5a5fb1ea 555/* Abort all requests */
69a53bf2
MS
556void fuse_abort_conn(struct fuse_conn *fc);
557
e5e5558e
MS
558/**
559 * Invalidate inode attributes
560 */
561void fuse_invalidate_attr(struct inode *inode);
bafa9654
MS
562
563/**
564 * Acquire reference to fuse_conn
565 */
566struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
567
568/**
569 * Release reference to fuse_conn
570 */
571void fuse_conn_put(struct fuse_conn *fc);
572
573/**
574 * Add connection to control filesystem
575 */
576int fuse_ctl_add_conn(struct fuse_conn *fc);
577
578/**
579 * Remove connection from control filesystem
580 */
581void fuse_ctl_remove_conn(struct fuse_conn *fc);
a5bfffac
TS
582
583/**
584 * Is file type valid?
585 */
586int fuse_valid_type(int m);
e57ac683
MS
587
588/**
589 * Is task allowed to perform filesystem operation?
590 */
591int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task);
f3332114
MS
592
593u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
bcb4be80
MS
594
595int fuse_update_attributes(struct inode *inode, struct kstat *stat,
596 struct file *file, bool *refreshed);
This page took 0.30662 seconds and 5 git commands to generate.