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