fuse_i.h 23 KB
Newer Older
Miklos Szeredi's avatar
Miklos Szeredi committed
1 2
/*
  FUSE: Filesystem in Userspace
Miklos Szeredi's avatar
Miklos Szeredi committed
3
  Copyright (C) 2001-2008  Miklos Szeredi <miklos@szeredi.hu>
Miklos Szeredi's avatar
Miklos Szeredi committed
4 5 6 7 8

  This program can be distributed under the terms of the GNU GPL.
  See the file COPYING.
*/

Tejun Heo's avatar
Tejun Heo committed
9 10 11
#ifndef _FS_FUSE_I_H
#define _FS_FUSE_I_H

12 13 14 15
#ifndef pr_fmt
# define pr_fmt(fmt) "fuse: " fmt
#endif

Miklos Szeredi's avatar
Miklos Szeredi committed
16 17
#include <linux/fuse.h>
#include <linux/fs.h>
18
#include <linux/mount.h>
Miklos Szeredi's avatar
Miklos Szeredi committed
19 20 21 22 23
#include <linux/wait.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
#include <linux/backing-dev.h>
24
#include <linux/mutex.h>
Miklos Szeredi's avatar
Miklos Szeredi committed
25
#include <linux/rwsem.h>
Tejun Heo's avatar
Tejun Heo committed
26 27
#include <linux/rbtree.h>
#include <linux/poll.h>
28
#include <linux/workqueue.h>
29
#include <linux/kref.h>
Seth Forshee's avatar
Seth Forshee committed
30
#include <linux/xattr.h>
31
#include <linux/pid_namespace.h>
32
#include <linux/refcount.h>
33
#include <linux/user_namespace.h>
Miklos Szeredi's avatar
Miklos Szeredi committed
34

35 36 37 38 39
/** Default max number of pages that can be used in a single read request */
#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32

/** Maximum of max_pages received in init_out */
#define FUSE_MAX_MAX_PAGES 256
40

Miklos Szeredi's avatar
Miklos Szeredi committed
41 42 43
/** Bias for fi->writectr, meaning new writepages must not be sent */
#define FUSE_NOWRITE INT_MIN

44 45 46
/** It could be as large as PATH_MAX, but would that have any uses? */
#define FUSE_NAME_MAX 1024

47
/** Number of dentries for each connection in the control filesystem */
48
#define FUSE_CTL_NUM_DENTRIES 5
49 50 51 52 53 54

/** List of active connections */
extern struct list_head fuse_conn_list;

/** Global mutex protecting fuse_conn_list and the control filesystem */
extern struct mutex fuse_mutex;
Miklos Szeredi's avatar
Miklos Szeredi committed
55

56 57 58 59
/** Module parameters */
extern unsigned max_user_bgreq;
extern unsigned max_user_congthresh;

60 61
/* One forget request */
struct fuse_forget_link {
62
	struct fuse_forget_one forget_one;
63 64 65
	struct fuse_forget_link *next;
};

Miklos Szeredi's avatar
Miklos Szeredi committed
66 67 68 69 70 71 72 73 74
/** FUSE inode */
struct fuse_inode {
	/** Inode data */
	struct inode inode;

	/** Unique ID, which identifies the inode between userspace
	 * and kernel */
	u64 nodeid;

75 76 77
	/** Number of lookups on this inode */
	u64 nlookup;

78
	/** The request used for sending the FORGET message */
79
	struct fuse_forget_link *forget;
80

Miklos Szeredi's avatar
Miklos Szeredi committed
81
	/** Time in jiffies until the file attributes are valid */
82
	u64 i_time;
83

84 85 86
	/* Which attributes are invalid */
	u32 inval_mask;

87 88
	/** The sticky bit in inode->i_mode may have been removed, so
	    preserve the original mode */
Al Viro's avatar
Al Viro committed
89
	umode_t orig_i_mode;
90

91 92 93
	/** 64 bit inode number */
	u64 orig_ino;

94 95
	/** Version of last attribute change */
	u64 attr_version;
96

97 98 99
	union {
		/* Write related fields (regular file only) */
		struct {
100
			/* Files usable in writepage.  Protected by fi->lock */
101
			struct list_head write_files;
Miklos Szeredi's avatar
Miklos Szeredi committed
102

103 104
			/* Writepages pending on truncate or fsync */
			struct list_head queued_writes;
Miklos Szeredi's avatar
Miklos Szeredi committed
105

106 107 108
			/* Number of sent writes, a negative bias
			 * (FUSE_NOWRITE) means more writes are blocked */
			int writectr;
Miklos Szeredi's avatar
Miklos Szeredi committed
109

110 111
			/* Waitq for writepage completion */
			wait_queue_head_t page_waitq;
Miklos Szeredi's avatar
Miklos Szeredi committed
112

113 114 115
			/* List of writepage requestst (pending or sent) */
			struct list_head writepages;
		};
116

117 118 119 120
		/* readdir cache (directory only) */
		struct {
			/* true if fully cached */
			bool cached;
121

122 123
			/* size of cache */
			loff_t size;
124

125 126
			/* position at end of cache (position of next entry) */
			loff_t pos;
127

128 129
			/* version of the cache */
			u64 version;
130

131 132 133
			/* modification time of directory when cache was
			 * started */
			struct timespec64 mtime;
134

135 136
			/* iversion of directory when cache was started */
			u64 iversion;
137

138 139 140 141
			/* protects above fields */
			spinlock_t lock;
		} rdc;
	};
142

143 144
	/** Miscellaneous bits describing inode state */
	unsigned long state;
145 146 147

	/** Lock for serializing lookup and readdir for back compatibility*/
	struct mutex mutex;
148 149 150

	/** Lock to protect write related fields */
	spinlock_t lock;
151 152 153 154 155 156
};

/** FUSE inode state bits */
enum {
	/** Advise readdirplus  */
	FUSE_I_ADVISE_RDPLUS,
157 158
	/** Initialized with readdirplus */
	FUSE_I_INIT_RDPLUS,
159 160
	/** An operation changing file size is in progress  */
	FUSE_I_SIZE_UNSTABLE,
Miklos Szeredi's avatar
Miklos Szeredi committed
161 162
};

163
struct fuse_conn;
164
struct fuse_release_args;
165

166 167
/** FUSE specific file data */
struct fuse_file {
168 169 170
	/** Fuse connection for this file */
	struct fuse_conn *fc;

171 172
	/* Argument space reserved for release */
	struct fuse_release_args *release_args;
173

Tejun Heo's avatar
Tejun Heo committed
174 175 176
	/** Kernel file handle guaranteed to be unique */
	u64 kh;

177 178
	/** File handle used by userspace */
	u64 fh;
179

180 181 182
	/** Node id of this file */
	u64 nodeid;

183
	/** Refcount */
184
	refcount_t count;
185

186 187 188
	/** FOPEN_* flags returned by open */
	u32 open_flags;

189 190
	/** Entry on inode's write_files list */
	struct list_head write_entry;
Tejun Heo's avatar
Tejun Heo committed
191

192 193 194 195 196 197 198 199 200 201 202 203 204
	/* Readdir related */
	struct {
		/*
		 * Protects below fields against (crazy) parallel readdir on
		 * same open file.  Uncontended in the normal case.
		 */
		struct mutex lock;

		/* Dir stream position */
		loff_t pos;

		/* Offset in cache */
		loff_t cache_off;
205 206 207 208

		/* Version of cache we are reading */
		u64 version;

209 210
	} readdir;

Tejun Heo's avatar
Tejun Heo committed
211 212 213 214 215
	/** RB node to be linked on fuse_conn->polled_files */
	struct rb_node polled_node;

	/** Wait queue head for poll */
	wait_queue_head_t poll_wait;
Miklos Szeredi's avatar
Miklos Szeredi committed
216 217 218

	/** Has flock been performed on this file? */
	bool flock:1;
219 220
};

221 222 223 224 225 226 227 228 229 230 231 232
/** One input argument of a request */
struct fuse_in_arg {
	unsigned size;
	const void *value;
};

/** One output argument of a request */
struct fuse_arg {
	unsigned size;
	void *value;
};

233 234 235 236 237 238
/** FUSE page descriptor */
struct fuse_page_desc {
	unsigned int length;
	unsigned int offset;
};

239
struct fuse_args {
240
	uint64_t nodeid;
241 242 243
	uint32_t opcode;
	unsigned short in_numargs;
	unsigned short out_numargs;
244
	bool force:1;
245
	bool noreply:1;
246
	bool nocreds:1;
247 248
	bool in_pages:1;
	bool out_pages:1;
249
	bool out_argvar:1;
250 251
	bool page_zeroing:1;
	bool page_replace:1;
252 253
	struct fuse_in_arg in_args[3];
	struct fuse_arg out_args[2];
254
	void (*end)(struct fuse_conn *fc, struct fuse_args *args, int error);
255 256
};

257 258 259 260 261 262 263
struct fuse_args_pages {
	struct fuse_args args;
	struct page **pages;
	struct fuse_page_desc *descs;
	unsigned int num_pages;
};

264 265
#define FUSE_ARGS(args) struct fuse_args args = {}

266 267
/** The request IO state (for asynchronous processing) */
struct fuse_io_priv {
268
	struct kref refcnt;
269 270 271 272 273 274 275
	int async;
	spinlock_t lock;
	unsigned reqs;
	ssize_t bytes;
	size_t size;
	__u64 offset;
	bool write;
276
	bool should_dirty;
277 278
	int err;
	struct kiocb *iocb;
279
	struct completion *done;
280
	bool blocking;
281 282
};

283
#define FUSE_IO_PRIV_SYNC(i) \
284
{					\
285
	.refcnt = KREF_INIT(1),		\
286
	.async = 0,			\
287
	.iocb = i,			\
288 289
}

Miklos Szeredi's avatar
Miklos Szeredi committed
290 291 292 293 294 295 296 297 298 299
/**
 * Request flags
 *
 * FR_ISREPLY:		set if the request has reply
 * FR_FORCE:		force sending of the request even if interrupted
 * FR_BACKGROUND:	request is sent in the background
 * FR_WAITING:		request is counted as "waiting"
 * FR_ABORTED:		the request was aborted
 * FR_INTERRUPTED:	the request has been interrupted
 * FR_LOCKED:		data is being copied to/from the request
Miklos Szeredi's avatar
Miklos Szeredi committed
300 301 302
 * FR_PENDING:		request is not yet in userspace
 * FR_SENT:		request is in userspace, waiting for an answer
 * FR_FINISHED:		request is finished
303
 * FR_PRIVATE:		request is on private list
Miklos Szeredi's avatar
Miklos Szeredi committed
304 305 306 307 308 309 310 311 312
 */
enum fuse_req_flag {
	FR_ISREPLY,
	FR_FORCE,
	FR_BACKGROUND,
	FR_WAITING,
	FR_ABORTED,
	FR_INTERRUPTED,
	FR_LOCKED,
Miklos Szeredi's avatar
Miklos Szeredi committed
313 314 315
	FR_PENDING,
	FR_SENT,
	FR_FINISHED,
316
	FR_PRIVATE,
Miklos Szeredi's avatar
Miklos Szeredi committed
317 318
};

319 320
/**
 * A request to the client
321 322 323 324
 *
 * .waitq.lock protects the following fields:
 *   - FR_ABORTED
 *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
325 326
 */
struct fuse_req {
327 328
	/** This can be on either pending processing or io lists in
	    fuse_conn */
329 330
	struct list_head list;

331 332 333
	/** Entry on the interrupts list  */
	struct list_head intr_entry;

334 335 336
	/* Input/output arguments */
	struct fuse_args *args;

337
	/** refcount */
338
	refcount_t count;
339

Miklos Szeredi's avatar
Miklos Szeredi committed
340 341
	/* Request flags, updated with test/set/clear_bit() */
	unsigned long flags;
342

343 344 345 346
	/* The request input header */
	struct {
		struct fuse_in_header h;
	} in;
347

348 349 350 351
	/* The request output header */
	struct {
		struct fuse_out_header h;
	} out;
352 353 354 355 356 357

	/** Used to wake up the task waiting for completion of request*/
	wait_queue_head_t waitq;

};

358
struct fuse_iqueue {
359 360 361
	/** Connection established */
	unsigned connected;

362 363 364
	/** Lock protecting accesses to members of this structure */
	spinlock_t lock;

365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
	/** Readers of the connection are waiting on this */
	wait_queue_head_t waitq;

	/** The next unique request id */
	u64 reqctr;

	/** The list of pending requests */
	struct list_head pending;

	/** Pending interrupts */
	struct list_head interrupts;

	/** Queue of pending forgets */
	struct fuse_forget_link forget_list_head;
	struct fuse_forget_link *forget_list_tail;

	/** Batching of FORGET requests (positive indicates FORGET batch) */
	int forget_batch;

	/** O_ASYNC requests */
	struct fasync_struct *fasync;
};

388 389 390
#define FUSE_PQ_HASH_BITS 8
#define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)

391
struct fuse_pqueue {
392 393 394
	/** Connection established */
	unsigned connected;

Miklos Szeredi's avatar
Miklos Szeredi committed
395 396 397
	/** Lock protecting accessess to  members of this structure */
	spinlock_t lock;

398 399
	/** Hash table of requests being processed */
	struct list_head *processing;
400 401 402 403 404

	/** The list of requests under I/O */
	struct list_head io;
};

405 406 407 408 409 410 411
/**
 * Fuse device instance
 */
struct fuse_dev {
	/** Fuse connection for this device */
	struct fuse_conn *fc;

412 413 414
	/** Processing queue */
	struct fuse_pqueue pq;

415 416 417 418
	/** list entry on fc->devices */
	struct list_head entry;
};

Miklos Szeredi's avatar
Miklos Szeredi committed
419 420 421 422 423 424 425 426
/**
 * A Fuse connection.
 *
 * This structure is created, when the filesystem is mounted, and is
 * destroyed, when the client device is closed and the filesystem is
 * unmounted.
 */
struct fuse_conn {
427 428 429
	/** Lock protecting accessess to  members of this structure */
	spinlock_t lock;

430
	/** Refcount */
431
	refcount_t count;
432

433 434 435
	/** Number of fuse_dev's */
	atomic_t dev_count;

Al Viro's avatar
Al Viro committed
436 437
	struct rcu_head rcu;

Miklos Szeredi's avatar
Miklos Szeredi committed
438
	/** The user id for this mount */
439
	kuid_t user_id;
Miklos Szeredi's avatar
Miklos Szeredi committed
440

441
	/** The group id for this mount */
442
	kgid_t group_id;
443

444 445 446
	/** The pid namespace for this mount */
	struct pid_namespace *pid_ns;

447 448 449
	/** The user namespace for this mount */
	struct user_namespace *user_ns;

450 451 452
	/** Maximum read size */
	unsigned max_read;

Miklos Szeredi's avatar
Miklos Szeredi committed
453 454 455
	/** Maximum write size */
	unsigned max_write;

456 457 458
	/** Maxmum number of pages that can be used in a single request */
	unsigned int max_pages;

459 460
	/** Input queue */
	struct fuse_iqueue iq;
461

Tejun Heo's avatar
Tejun Heo committed
462
	/** The next unique kernel file handle */
463
	atomic64_t khctr;
Tejun Heo's avatar
Tejun Heo committed
464

Tejun Heo's avatar
Tejun Heo committed
465 466 467
	/** rbtree of fuse_files waiting for poll events indexed by ph */
	struct rb_root polled_files;

468 469 470 471 472 473
	/** Maximum number of outstanding background requests */
	unsigned max_background;

	/** Number of background requests at which congestion starts */
	unsigned congestion_threshold;

474 475 476
	/** Number of requests currently in the background */
	unsigned num_background;

477 478 479 480 481 482
	/** Number of background requests currently queued for userspace */
	unsigned active_background;

	/** The list of background requests set aside for later queuing */
	struct list_head bg_queue;

Kirill Tkhai's avatar
Kirill Tkhai committed
483 484 485 486
	/** Protects: max_background, congestion_threshold, num_background,
	 * active_background, bg_queue, blocked */
	spinlock_t bg_lock;

487 488 489 490
	/** Flag indicating that INIT reply has been received. Allocating
	 * any fuse request will be suspended until the flag is set */
	int initialized;

491 492 493 494 495 496 497
	/** Flag indicating if connection is blocked.  This will be
	    the case before the INIT reply is received, and if there
	    are too many outstading backgrounds requests */
	int blocked;

	/** waitq for blocked connection */
	wait_queue_head_t blocked_waitq;
498

499 500
	/** Connection established, cleared on umount, connection
	    abort and device release */
501
	unsigned connected;
502

503 504 505
	/** Connection aborted via sysfs */
	bool aborted;

506 507 508
	/** Connection failed (version mismatch).  Cannot race with
	    setting other bitfields since it is only set once in INIT
	    reply, before any other request, and never cleared */
Miklos Szeredi's avatar
Miklos Szeredi committed
509
	unsigned conn_error:1;
510

511
	/** Connection successful.  Only set in INIT */
Miklos Szeredi's avatar
Miklos Szeredi committed
512
	unsigned conn_init:1;
513

514
	/** Do readpages asynchronously?  Only set in INIT */
Miklos Szeredi's avatar
Miklos Szeredi committed
515
	unsigned async_read:1;
516

517 518 519
	/** Return an unique read error after abort.  Only set in INIT */
	unsigned abort_err:1;

520
	/** Do not send separate SETATTR request before open(O_TRUNC)  */
Miklos Szeredi's avatar
Miklos Szeredi committed
521
	unsigned atomic_o_trunc:1;
522

523
	/** Filesystem supports NFS exporting.  Only set in INIT */
Miklos Szeredi's avatar
Miklos Szeredi committed
524
	unsigned export_support:1;
525

526 527 528
	/** write-back cache policy (default is write-through) */
	unsigned writeback_cache:1;

529 530 531
	/** allow parallel lookups and readdir (default is serialized) */
	unsigned parallel_dirops:1;

532 533 534
	/** handle fs handles killing suid/sgid/cap on write/chown/trunc */
	unsigned handle_killpriv:1;

535 536 537
	/** cache READLINK responses in page cache */
	unsigned cache_symlinks:1;

538 539 540 541 542
	/*
	 * The following bitfields are only for optimization purposes
	 * and hence races in setting them will not cause malfunction
	 */

543 544 545
	/** Is open/release not implemented by fs? */
	unsigned no_open:1;

546 547 548
	/** Is opendir/releasedir not implemented by fs? */
	unsigned no_opendir:1;

549
	/** Is fsync not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
550
	unsigned no_fsync:1;
551

552
	/** Is fsyncdir not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
553
	unsigned no_fsyncdir:1;
554

555
	/** Is flush not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
556
	unsigned no_flush:1;
557

558
	/** Is setxattr not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
559
	unsigned no_setxattr:1;
560 561

	/** Is getxattr not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
562
	unsigned no_getxattr:1;
563 564

	/** Is listxattr not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
565
	unsigned no_listxattr:1;
566 567

	/** Is removexattr not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
568
	unsigned no_removexattr:1;
569

Miklos Szeredi's avatar
Miklos Szeredi committed
570
	/** Are posix file locking primitives not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
571
	unsigned no_lock:1;
572

573
	/** Is access not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
574
	unsigned no_access:1;
575

576
	/** Is create not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
577
	unsigned no_create:1;
578

579
	/** Is interrupt not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
580
	unsigned no_interrupt:1;
581

582
	/** Is bmap not implemented by fs? */
Miklos Szeredi's avatar
Miklos Szeredi committed
583
	unsigned no_bmap:1;
584

Tejun Heo's avatar
Tejun Heo committed
585 586 587
	/** Is poll not implemented by fs? */
	unsigned no_poll:1;

588
	/** Do multi-page cached writes */
Miklos Szeredi's avatar
Miklos Szeredi committed
589
	unsigned big_writes:1;
590

591 592 593
	/** Don't apply umask to creation modes */
	unsigned dont_mask:1;

Miklos Szeredi's avatar
Miklos Szeredi committed
594 595 596
	/** Are BSD file locking primitives not implemented by fs? */
	unsigned no_flock:1;

597 598 599
	/** Is fallocate not implemented by fs? */
	unsigned no_fallocate:1;

Miklos Szeredi's avatar
Miklos Szeredi committed
600 601 602
	/** Is rename with flags implemented by fs? */
	unsigned no_rename2:1;

603 604 605
	/** Use enhanced/automatic page cache invalidation. */
	unsigned auto_inval_data:1;

606 607 608
	/** Filesystem is fully reponsible for page cache invalidation. */
	unsigned explicit_inval_data:1;

609
	/** Does the filesystem support readdirplus? */
610 611
	unsigned do_readdirplus:1;

612 613 614
	/** Does the filesystem want adaptive readdirplus? */
	unsigned readdirplus_auto:1;

615 616 617
	/** Does the filesystem support asynchronous direct-IO submission? */
	unsigned async_dio:1;

618 619 620
	/** Is lseek not implemented by fs? */
	unsigned no_lseek:1;

Seth Forshee's avatar
Seth Forshee committed
621 622 623
	/** Does the filesystem support posix acls? */
	unsigned posix_acl:1;

624 625 626 627 628 629
	/** Check permissions based on the file mode or not? */
	unsigned default_permissions:1;

	/** Allow other than the mounter user to access the filesystem ? */
	unsigned allow_other:1;

630 631 632
	/** Does the filesystem support copy_file_range? */
	unsigned no_copy_file_range:1;

633 634 635
	/* Send DESTROY request */
	unsigned int destroy:1;

636 637 638
	/** The number of requests waiting for completion */
	atomic_t num_waiting;

639 640 641
	/** Negotiated minor version */
	unsigned minor;

642 643 644
	/** Entry on the fuse_conn_list */
	struct list_head entry;

645 646
	/** Device ID from super block */
	dev_t dev;
647 648 649 650 651 652

	/** Dentries in the control filesystem */
	struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];

	/** number of dentries used in the above array */
	int ctl_ndents;
653

654 655
	/** Key for lock owner ID scrambling */
	u32 scramble_key[4];
656

657
	/** Version counter for attribute changes */
658
	atomic64_t attr_version;
Tejun Heo's avatar
Tejun Heo committed
659 660 661

	/** Called on final put */
	void (*release)(struct fuse_conn *);
John Muir's avatar
John Muir committed
662 663 664 665 666 667

	/** Super block for this connection. */
	struct super_block *sb;

	/** Read/write semaphore to hold when accessing sb. */
	struct rw_semaphore killsb;
668 669 670

	/** List of device instances belonging to this connection */
	struct list_head devices;
Miklos Szeredi's avatar
Miklos Szeredi committed
671 672 673 674
};

static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
{
675
	return sb->s_fs_info;
Miklos Szeredi's avatar
Miklos Szeredi committed
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
}

static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
{
	return get_fuse_conn_super(inode->i_sb);
}

static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
{
	return container_of(inode, struct fuse_inode, inode);
}

static inline u64 get_node_id(struct inode *inode)
{
	return get_fuse_inode(inode)->nodeid;
}

Miklos Szeredi's avatar
Miklos Szeredi committed
693 694 695 696 697
static inline int invalid_nodeid(u64 nodeid)
{
	return !nodeid || nodeid == FUSE_ROOT_ID;
}

698 699 700 701 702
static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
{
	return atomic64_read(&fc->attr_version);
}

703
/** Device operations */
704
extern const struct file_operations fuse_dev_operations;
705

Al Viro's avatar
Al Viro committed
706
extern const struct dentry_operations fuse_dentry_operations;
707
extern const struct dentry_operations fuse_root_dentry_operations;
Miklos Szeredi's avatar
Miklos Szeredi committed
708

John Muir's avatar
John Muir committed
709 710 711 712 713
/**
 * Inode to nodeid comparison.
 */
int fuse_inode_eq(struct inode *inode, void *_nodeidp);

714 715 716
/**
 * Get a filled in inode
 */
Miklos Szeredi's avatar
Miklos Szeredi committed
717
struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
718 719
			int generation, struct fuse_attr *attr,
			u64 attr_valid, u64 attr_version);
720

Al Viro's avatar
Al Viro committed
721
int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
722 723
		     struct fuse_entry_out *outarg, struct inode **inode);

724 725 726
/**
 * Send FORGET command
 */
727 728 729 730
void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
		       u64 nodeid, u64 nlookup);

struct fuse_forget_link *fuse_alloc_forget(void);
731

732
/*
733
 * Initialize READ or READDIR request
734
 */
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
struct fuse_io_args {
	union {
		struct {
			struct fuse_read_in in;
			u64 attr_ver;
		} read;
		struct {
			struct fuse_write_in in;
			struct fuse_write_out out;
		} write;
	};
	struct fuse_args_pages ap;
	struct fuse_io_priv *io;
	struct fuse_file *ff;
};

void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_t pos,
			 size_t count, int opcode);

754 755 756 757

/**
 * Send OPEN or OPENDIR request
 */
758
int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
759

Tejun Heo's avatar
Tejun Heo committed
760
struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
761
void fuse_file_free(struct fuse_file *ff);
762
void fuse_finish_open(struct inode *inode, struct file *file);
763

764
void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
765

766 767 768
/**
 * Send RELEASE or RELEASEDIR request
 */
769
void fuse_release_common(struct file *file, bool isdir);
770

771 772 773
/**
 * Send FSYNC or FSYNCDIR request
 */
774
int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
775
		      int datasync, int opcode);
776

Tejun Heo's avatar
Tejun Heo committed
777 778 779 780 781 782
/**
 * Notify poll wakeup
 */
int fuse_notify_poll_wakeup(struct fuse_conn *fc,
			    struct fuse_notify_poll_wakeup_out *outarg);

783
/**
784
 * Initialize file operations on a regular file
785 786 787
 */
void fuse_init_file_inode(struct inode *inode);

788
/**
789
 * Initialize inode operations on regular files and special files
790 791 792 793
 */
void fuse_init_common(struct inode *inode);

/**
794
 * Initialize inode and file operations on a directory
795 796 797 798
 */
void fuse_init_dir(struct inode *inode);

/**
799
 * Initialize inode operations on a symlink
800 801 802 803 804 805
 */
void fuse_init_symlink(struct inode *inode);

/**
 * Change attributes of an inode
 */
806 807
void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
			    u64 attr_valid, u64 attr_version);
808

Miklos Szeredi's avatar
Miklos Szeredi committed
809 810 811
void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
				   u64 attr_valid);

812 813 814 815 816 817 818 819 820 821
/**
 * Initialize the client device
 */
int fuse_dev_init(void);

/**
 * Cleanup the client device
 */
void fuse_dev_cleanup(void);

822
int fuse_ctl_init(void);
823
void __exit fuse_ctl_cleanup(void);
824

825 826 827 828
/**
 * Simple request sending that does request allocation and freeing
 */
ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
829 830
int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,
			   gfp_t gfp_flags);
831

832 833 834 835 836
/**
 * End a finished request
 */
void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req);

837
/* Abort all requests */
Miklos Szeredi's avatar
Miklos Szeredi committed
838
void fuse_abort_conn(struct fuse_conn *fc);
839
void fuse_wait_aborted(struct fuse_conn *fc);
840

841 842 843 844
/**
 * Invalidate inode attributes
 */
void fuse_invalidate_attr(struct inode *inode);
845

Miklos Szeredi's avatar
Miklos Szeredi committed
846 847
void fuse_invalidate_entry_cache(struct dentry *entry);

848 849
void fuse_invalidate_atime(struct inode *inode);

Miklos Szeredi's avatar
Miklos Szeredi committed
850 851 852
u64 entry_attr_timeout(struct fuse_entry_out *o);
void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);

853 854 855 856 857
/**
 * Acquire reference to fuse_conn
 */
struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);

858 859 860
/**
 * Initialize fuse_conn
 */
861
void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
862

863 864 865 866 867
/**
 * Release reference to fuse_conn
 */
void fuse_conn_put(struct fuse_conn *fc);

868 869 870
struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
void fuse_dev_free(struct fuse_dev *fud);

871 872 873 874 875 876 877 878 879
/**
 * Add connection to control filesystem
 */
int fuse_ctl_add_conn(struct fuse_conn *fc);

/**
 * Remove connection from control filesystem
 */
void fuse_ctl_remove_conn(struct fuse_conn *fc);
880 881 882 883 884

/**
 * Is file type valid?
 */
int fuse_valid_type(int m);
885 886

/**
887
 * Is current process allowed to perform filesystem operation?
888
 */
889
int fuse_allow_current_process(struct fuse_conn *fc);
890 891

u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
Miklos Szeredi's avatar
Miklos Szeredi committed
892

Seth Forshee's avatar
Seth Forshee committed
893 894
void fuse_update_ctime(struct inode *inode);

Miklos Szeredi's avatar
Miklos Szeredi committed
895
int fuse_update_attributes(struct inode *inode, struct file *file);
Miklos Szeredi's avatar
Miklos Szeredi committed
896 897 898 899 900

void fuse_flush_writepages(struct inode *inode);

void fuse_set_nowrite(struct inode *inode);
void fuse_release_nowrite(struct inode *inode);
901

John Muir's avatar
John Muir committed
902 903 904 905 906 907 908 909 910
/**
 * File-system tells the kernel to invalidate cache for the given node id.
 */
int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
			     loff_t offset, loff_t len);

/**
 * File-system tells the kernel to invalidate parent attributes and
 * the dentry matching parent/name.
911 912 913 914 915 916
 *
 * If the child_nodeid is non-zero and:
 *    - matches the inode number for the dentry matching parent/name,
 *    - is not a mount point
 *    - is a file or oan empty directory
 * then the dentry is unhashed (d_delete()).
John Muir's avatar
John Muir committed
917 918
 */
int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
919
			     u64 child_nodeid, struct qstr *name);
John Muir's avatar
John Muir committed
920

921 922
int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
		 bool isdir);
923 924 925 926 927 928 929 930 931 932 933

/**
 * fuse_direct_io() flags
 */

/** If set, it is WRITE; otherwise - READ */
#define FUSE_DIO_WRITE (1 << 0)

/** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
#define FUSE_DIO_CUSE  (1 << 1)

934 935
ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
		       loff_t *ppos, int flags);
936 937
long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
		   unsigned int flags);
938 939
long fuse_ioctl_common(struct file *file, unsigned int cmd,
		       unsigned long arg, unsigned int flags);
Al Viro's avatar
Al Viro committed
940
__poll_t fuse_file_poll(struct file *file, poll_table *wait);
941 942
int fuse_dev_release(struct inode *inode, struct file *file);

943 944
bool fuse_write_update_size(struct inode *inode, loff_t pos);

945
int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
Miklos Szeredi's avatar
Miklos Szeredi committed
946
int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
Miklos Szeredi's avatar
Miklos Szeredi committed
947

948
int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
949 950
		    struct file *file);

951 952
void fuse_set_initialized(struct fuse_conn *fc);

953 954
void fuse_unlock_inode(struct inode *inode, bool locked);
bool fuse_lock_inode(struct inode *inode);
955

Seth Forshee's avatar
Seth Forshee committed
956 957 958 959
int fuse_setxattr(struct inode *inode, const char *name, const void *value,
		  size_t size, int flags);
ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
		      size_t size);
Seth Forshee's avatar
Seth Forshee committed
960
ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
Seth Forshee's avatar
Seth Forshee committed
961
int fuse_removexattr(struct inode *inode, const char *name);
Seth Forshee's avatar
Seth Forshee committed
962
extern const struct xattr_handler *fuse_xattr_handlers[];
Seth Forshee's avatar
Seth Forshee committed
963
extern const struct xattr_handler *fuse_acl_xattr_handlers[];
964
extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
Seth Forshee's avatar
Seth Forshee committed
965 966 967 968

struct posix_acl;
struct posix_acl *fuse_get_acl(struct inode *inode, int type);
int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
Seth Forshee's avatar
Seth Forshee committed
969

Miklos Szeredi's avatar
Miklos Szeredi committed
970 971 972 973

/* readdir.c */
int fuse_readdir(struct file *file, struct dir_context *ctx);

Tejun Heo's avatar
Tejun Heo committed
974
#endif /* _FS_FUSE_I_H */