fs.h 118 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds's avatar
Linus Torvalds committed
2
3
4
5
#ifndef _LINUX_FS_H
#define _LINUX_FS_H

#include <linux/linkage.h>
6
#include <linux/wait_bit.h>
Linus Torvalds's avatar
Linus Torvalds committed
7
8
#include <linux/kdev_t.h>
#include <linux/dcache.h>
9
#include <linux/path.h>
Linus Torvalds's avatar
Linus Torvalds committed
10
11
12
#include <linux/stat.h>
#include <linux/cache.h>
#include <linux/list.h>
13
#include <linux/list_lru.h>
14
#include <linux/llist.h>
Linus Torvalds's avatar
Linus Torvalds committed
15
#include <linux/radix-tree.h>
Matthew Wilcox's avatar
Matthew Wilcox committed
16
#include <linux/xarray.h>
17
#include <linux/rbtree.h>
Linus Torvalds's avatar
Linus Torvalds committed
18
#include <linux/init.h>
19
#include <linux/pid.h>
20
#include <linux/bug.h>
21
#include <linux/mutex.h>
22
#include <linux/rwsem.h>
23
#include <linux/mm_types.h>
24
#include <linux/capability.h>
25
#include <linux/semaphore.h>
26
#include <linux/fcntl.h>
27
#include <linux/rculist_bl.h>
28
#include <linux/atomic.h>
29
#include <linux/shrinker.h>
30
#include <linux/migrate_mode.h>
31
#include <linux/uidgid.h>
32
#include <linux/lockdep.h>
33
#include <linux/percpu-rwsem.h>
34
#include <linux/workqueue.h>
35
#include <linux/delayed_call.h>
36
#include <linux/uuid.h>
37
#include <linux/errseq.h>
38
#include <linux/ioprio.h>
39
#include <linux/fs_types.h>
40
41
#include <linux/build_bug.h>
#include <linux/stddef.h>
Linus Torvalds's avatar
Linus Torvalds committed
42
43

#include <asm/byteorder.h>
44
#include <uapi/linux/fs.h>
Linus Torvalds's avatar
Linus Torvalds committed
45

46
struct backing_dev_info;
47
struct bdi_writeback;
48
struct bio;
49
struct export_operations;
50
struct fiemap_extent_info;
51
struct hd_geometry;
Linus Torvalds's avatar
Linus Torvalds committed
52
struct iovec;
53
struct kiocb;
Alexey Dobriyan's avatar
Alexey Dobriyan committed
54
struct kobject;
Linus Torvalds's avatar
Linus Torvalds committed
55
56
57
58
59
struct pipe_inode_info;
struct poll_table_struct;
struct kstatfs;
struct vm_area_struct;
struct vfsmount;
60
struct cred;
61
struct swap_info_struct;
62
struct seq_file;
63
struct workqueue_struct;
64
struct iov_iter;
65
66
struct fscrypt_info;
struct fscrypt_operations;
67
68
struct fsverity_info;
struct fsverity_operations;
Al Viro's avatar
Al Viro committed
69
struct fs_context;
70
struct fs_parameter_spec;
Linus Torvalds's avatar
Linus Torvalds committed
71

72
extern void __init inode_init(void);
Linus Torvalds's avatar
Linus Torvalds committed
73
extern void __init inode_init_early(void);
74
75
extern void __init files_init(void);
extern void __init files_maxfiles_init(void);
Linus Torvalds's avatar
Linus Torvalds committed
76

77
extern struct files_stat_struct files_stat;
78
extern unsigned long get_max_files(void);
79
extern unsigned int sysctl_nr_open;
80
81
extern struct inodes_stat_t inodes_stat;
extern int leases_enable, lease_break_time;
Kees Cook's avatar
Kees Cook committed
82
83
extern int sysctl_protected_symlinks;
extern int sysctl_protected_hardlinks;
84
85
extern int sysctl_protected_fifos;
extern int sysctl_protected_regular;
86

Hongtao Lyu's avatar
update    
Hongtao Lyu committed
87
88
/////////////////changing here

Hongtao Lyu's avatar
Hongtao Lyu committed
89
//const char* default_sBPF_openat_prog(const char * filename);
Hongtao Lyu's avatar
update    
Hongtao Lyu committed
90

Hongtao Lyu's avatar
Hongtao Lyu committed
91
92
static int flag_openat_sBPF=0;
static const char* (*sBPF_hook_openat_prog)(const char * filename)=NULL;
Hongtao Lyu's avatar
update    
Hongtao Lyu committed
93
94
95
96


/////////////////////////////////

Christoph Hellwig's avatar
Christoph Hellwig committed
97
98
typedef __kernel_rwf_t rwf_t;

Linus Torvalds's avatar
Linus Torvalds committed
99
100
101
struct buffer_head;
typedef int (get_block_t)(struct inode *inode, sector_t iblock,
			struct buffer_head *bh_result, int create);
102
typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
103
			ssize_t bytes, void *private);
Linus Torvalds's avatar
Linus Torvalds committed
104

105
106
107
108
109
110
111
112
113
114
115
116
#define MAY_EXEC		0x00000001
#define MAY_WRITE		0x00000002
#define MAY_READ		0x00000004
#define MAY_APPEND		0x00000008
#define MAY_ACCESS		0x00000010
#define MAY_OPEN		0x00000020
#define MAY_CHDIR		0x00000040
/* called from RCU mode, don't block */
#define MAY_NOT_BLOCK		0x00000080

/*
 * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond
117
 * to O_WRONLY and O_RDWR via the strange trick in do_dentry_open()
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
 */

/* file is open for reading */
#define FMODE_READ		((__force fmode_t)0x1)
/* file is open for writing */
#define FMODE_WRITE		((__force fmode_t)0x2)
/* file is seekable */
#define FMODE_LSEEK		((__force fmode_t)0x4)
/* file can be accessed using pread */
#define FMODE_PREAD		((__force fmode_t)0x8)
/* file can be accessed using pwrite */
#define FMODE_PWRITE		((__force fmode_t)0x10)
/* File is opened for execution with sys_execve / sys_uselib */
#define FMODE_EXEC		((__force fmode_t)0x20)
/* File is opened with O_NDELAY (only set for block devices) */
#define FMODE_NDELAY		((__force fmode_t)0x40)
/* File is opened with O_EXCL (only set for block devices) */
#define FMODE_EXCL		((__force fmode_t)0x80)
/* File is opened using open(.., 3, ..) and is writeable only for ioctls
   (specialy hack for floppy.c) */
#define FMODE_WRITE_IOCTL	((__force fmode_t)0x100)
/* 32bit hashes as llseek() offset (for directories) */
#define FMODE_32BITHASH         ((__force fmode_t)0x200)
/* 64bit hashes as llseek() offset (for directories) */
#define FMODE_64BITHASH         ((__force fmode_t)0x400)

/*
 * Don't update ctime and mtime.
 *
 * Currently a special hack for the XFS open_by_handle ioctl, but we'll
 * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon.
 */
#define FMODE_NOCMTIME		((__force fmode_t)0x800)

/* Expect random access pattern */
#define FMODE_RANDOM		((__force fmode_t)0x1000)

/* File is huge (eg. /dev/kmem): treat loff_t as unsigned */
#define FMODE_UNSIGNED_OFFSET	((__force fmode_t)0x2000)

/* File is opened with O_PATH; almost nothing can be done with it */
#define FMODE_PATH		((__force fmode_t)0x4000)

161
162
/* File needs atomic accesses to f_pos */
#define FMODE_ATOMIC_POS	((__force fmode_t)0x8000)
163
164
/* Write access to underlying fs */
#define FMODE_WRITER		((__force fmode_t)0x10000)
165
166
167
168
/* Has read method(s) */
#define FMODE_CAN_READ          ((__force fmode_t)0x20000)
/* Has write method(s) */
#define FMODE_CAN_WRITE         ((__force fmode_t)0x40000)
169

Al Viro's avatar
Al Viro committed
170
#define FMODE_OPENED		((__force fmode_t)0x80000)
171
#define FMODE_CREATED		((__force fmode_t)0x100000)
Al Viro's avatar
Al Viro committed
172

173
174
175
/* File is stream-like */
#define FMODE_STREAM		((__force fmode_t)0x200000)

176
/* File was opened by fanotify and shouldn't generate fanotify events */
177
#define FMODE_NONOTIFY		((__force fmode_t)0x4000000)
178

179
/* File is capable of returning -EAGAIN if I/O will block */
180
181
182
183
#define FMODE_NOWAIT		((__force fmode_t)0x8000000)

/* File represents mount that needs unmounting */
#define FMODE_NEED_UNMOUNT	((__force fmode_t)0x10000000)
184

185
/* File does not contribute to nr_files count */
186
#define FMODE_NOACCOUNT		((__force fmode_t)0x20000000)
187

188
189
190
191
192
193
194
195
/*
 * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
 * that indicates that they should check the contents of the iovec are
 * valid, but not check the memory that the iovec elements
 * points too.
 */
#define CHECK_IOVEC_ONLY -1

Linus Torvalds's avatar
Linus Torvalds committed
196
197
198
199
/*
 * Attribute flags.  These should be or-ed together to figure out what
 * has been changed!
 */
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#define ATTR_MODE	(1 << 0)
#define ATTR_UID	(1 << 1)
#define ATTR_GID	(1 << 2)
#define ATTR_SIZE	(1 << 3)
#define ATTR_ATIME	(1 << 4)
#define ATTR_MTIME	(1 << 5)
#define ATTR_CTIME	(1 << 6)
#define ATTR_ATIME_SET	(1 << 7)
#define ATTR_MTIME_SET	(1 << 8)
#define ATTR_FORCE	(1 << 9) /* Not a change, but a change it */
#define ATTR_KILL_SUID	(1 << 11)
#define ATTR_KILL_SGID	(1 << 12)
#define ATTR_FILE	(1 << 13)
#define ATTR_KILL_PRIV	(1 << 14)
#define ATTR_OPEN	(1 << 15) /* Truncating from open(O_TRUNC) */
#define ATTR_TIMES_SET	(1 << 16)
216
#define ATTR_TOUCH	(1 << 17)
Linus Torvalds's avatar
Linus Torvalds committed
217

Miklos Szeredi's avatar
Miklos Szeredi committed
218
219
220
221
222
223
224
/*
 * Whiteout is represented by a char device.  The following constants define the
 * mode and device number to use.
 */
#define WHITEOUT_MODE 0
#define WHITEOUT_DEV 0

Linus Torvalds's avatar
Linus Torvalds committed
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * This is the Inode Attributes structure, used for notify_change().  It
 * uses the above definitions as flags, to know which values have changed.
 * Also, in this manner, a Filesystem can look at only the values it cares
 * about.  Basically, these are the attributes that the VFS layer can
 * request to change from the FS layer.
 *
 * Derek Atkins <warlord@MIT.EDU> 94-10-20
 */
struct iattr {
	unsigned int	ia_valid;
	umode_t		ia_mode;
237
238
	kuid_t		ia_uid;
	kgid_t		ia_gid;
Linus Torvalds's avatar
Linus Torvalds committed
239
	loff_t		ia_size;
240
241
242
	struct timespec64 ia_atime;
	struct timespec64 ia_mtime;
	struct timespec64 ia_ctime;
243
244

	/*
Lucas De Marchi's avatar
Lucas De Marchi committed
245
	 * Not an attribute, but an auxiliary info for filesystems wanting to
246
247
248
249
	 * implement an ftruncate() like method.  NOTE: filesystem should
	 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
	 */
	struct file	*ia_file;
Linus Torvalds's avatar
Linus Torvalds committed
250
251
252
253
254
255
256
};

/*
 * Includes for diskquotas.
 */
#include <linux/quota.h>

257
258
259
260
261
262
/*
 * Maximum number of layers of fs stack.  Needs to be limited to
 * prevent kernel stack overflow
 */
#define FILESYSTEM_MAX_STACK_DEPTH 2

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/** 
 * enum positive_aop_returns - aop return codes with specific semantics
 *
 * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
 * 			    completed, that the page is still locked, and
 * 			    should be considered active.  The VM uses this hint
 * 			    to return the page to the active list -- it won't
 * 			    be a candidate for writeback again in the near
 * 			    future.  Other callers must be careful to unlock
 * 			    the page if they get this return.  Returned by
 * 			    writepage(); 
 *
 * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
 *  			unlocked it and the page might have been truncated.
 *  			The caller should back up to acquiring a new page and
 *  			trying again.  The aop will be taking reasonable
 *  			precautions not to livelock.  If the caller held a page
 *  			reference, it should drop it before retrying.  Returned
281
 *  			by readpage().
282
283
284
285
286
287
288
289
290
291
292
293
 *
 * address_space_operation functions return these large constants to indicate
 * special semantics to the caller.  These are much larger than the bytes in a
 * page to allow for functions that return the number of bytes operated on in a
 * given page.
 */

enum positive_aop_returns {
	AOP_WRITEPAGE_ACTIVATE	= 0x80000,
	AOP_TRUNCATED_PAGE	= 0x80001,
};

294
295
#define AOP_FLAG_CONT_EXPAND		0x0001 /* called from cont_expand */
#define AOP_FLAG_NOFS			0x0002 /* used by filesystem to direct
296
297
						* helper code (eg buffer layer)
						* to clear GFP_FS from alloc */
298

Linus Torvalds's avatar
Linus Torvalds committed
299
300
301
302
303
304
/*
 * oh the beauties of C type declarations.
 */
struct page;
struct address_space;
struct writeback_control;
305
struct readahead_control;
Linus Torvalds's avatar
Linus Torvalds committed
306

307
308
/*
 * Write life time hint values.
309
 * Stored in struct inode as u8.
310
311
312
313
314
315
316
317
318
319
 */
enum rw_hint {
	WRITE_LIFE_NOT_SET	= 0,
	WRITE_LIFE_NONE		= RWH_WRITE_LIFE_NONE,
	WRITE_LIFE_SHORT	= RWH_WRITE_LIFE_SHORT,
	WRITE_LIFE_MEDIUM	= RWH_WRITE_LIFE_MEDIUM,
	WRITE_LIFE_LONG		= RWH_WRITE_LIFE_LONG,
	WRITE_LIFE_EXTREME	= RWH_WRITE_LIFE_EXTREME,
};

320
#define IOCB_EVENTFD		(1 << 0)
321
322
#define IOCB_APPEND		(1 << 1)
#define IOCB_DIRECT		(1 << 2)
323
#define IOCB_HIPRI		(1 << 3)
324
325
#define IOCB_DSYNC		(1 << 4)
#define IOCB_SYNC		(1 << 5)
326
#define IOCB_WRITE		(1 << 6)
327
#define IOCB_NOWAIT		(1 << 7)
328
#define IOCB_NOIO		(1 << 9)
329
330
331

struct kiocb {
	struct file		*ki_filp;
332
333
334
335

	/* The 'ki_filp' pointer is shared in a union for aio */
	randomized_struct_fields_start

336
337
338
339
	loff_t			ki_pos;
	void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
	void			*private;
	int			ki_flags;
340
	u16			ki_hint;
341
	u16			ki_ioprio; /* See linux/ioprio.h */
342
	unsigned int		ki_cookie; /* for ->iopoll */
343
344
345

	randomized_struct_fields_end
};
346
347
348
349
350
351

static inline bool is_sync_kiocb(struct kiocb *kiocb)
{
	return kiocb->ki_complete == NULL;
}

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
 * "descriptor" for what we're up to with a read.
 * This allows us to use the same read code yet
 * have multiple different users of the data that
 * we read from a file.
 *
 * The simplest case just copies the data to user
 * mode.
 */
typedef struct {
	size_t written;
	size_t count;
	union {
		char __user *buf;
		void *data;
	} arg;
	int error;
} read_descriptor_t;

typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
		unsigned long, unsigned long);
Nick Piggin's avatar
Nick Piggin committed
373

Linus Torvalds's avatar
Linus Torvalds committed
374
375
376
377
378
379
380
struct address_space_operations {
	int (*writepage)(struct page *page, struct writeback_control *wbc);
	int (*readpage)(struct file *, struct page *);

	/* Write back some dirty pages from this mapping. */
	int (*writepages)(struct address_space *, struct writeback_control *);

381
	/* Set a page dirty.  Return true if this dirtied it */
Linus Torvalds's avatar
Linus Torvalds committed
382
383
	int (*set_page_dirty)(struct page *page);

384
385
386
387
	/*
	 * Reads in the requested pages. Unlike ->readpage(), this is
	 * PURELY used for read-ahead!.
	 */
Linus Torvalds's avatar
Linus Torvalds committed
388
389
	int (*readpages)(struct file *filp, struct address_space *mapping,
			struct list_head *pages, unsigned nr_pages);
390
	void (*readahead)(struct readahead_control *);
Linus Torvalds's avatar
Linus Torvalds committed
391

392
393
394
395
396
397
398
	int (*write_begin)(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned flags,
				struct page **pagep, void **fsdata);
	int (*write_end)(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned copied,
				struct page *page, void *fsdata);

Linus Torvalds's avatar
Linus Torvalds committed
399
400
	/* Unfortunately this kludge is needed for FIBMAP. Don't use it */
	sector_t (*bmap)(struct address_space *, sector_t);
401
	void (*invalidatepage) (struct page *, unsigned int, unsigned int);
Al Viro's avatar
Al Viro committed
402
	int (*releasepage) (struct page *, gfp_t);
403
	void (*freepage)(struct page *);
404
	ssize_t (*direct_IO)(struct kiocb *, struct iov_iter *iter);
405
	/*
406
407
	 * migrate the contents of a page to the specified target. If
	 * migrate_mode is MIGRATE_ASYNC, it must not block.
408
	 */
409
	int (*migratepage) (struct address_space *,
410
			struct page *, struct page *, enum migrate_mode);
411
412
	bool (*isolate_page)(struct page *, isolate_mode_t);
	void (*putback_page)(struct page *);
413
	int (*launder_page) (struct page *);
414
	int (*is_partially_uptodate) (struct page *, unsigned long,
415
					unsigned long);
416
	void (*is_dirty_writeback) (struct page *, bool *, bool *);
417
	int (*error_remove_page)(struct address_space *, struct page *);
418
419

	/* swapfile support */
420
421
422
	int (*swap_activate)(struct swap_info_struct *sis, struct file *file,
				sector_t *span);
	void (*swap_deactivate)(struct file *file);
Linus Torvalds's avatar
Linus Torvalds committed
423
424
};

Jens Axboe's avatar
Jens Axboe committed
425
426
extern const struct address_space_operations empty_aops;

427
428
429
430
431
432
433
434
435
436
437
438
/*
 * pagecache_write_begin/pagecache_write_end must be used by general code
 * to write into the pagecache.
 */
int pagecache_write_begin(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned flags,
				struct page **pagep, void **fsdata);

int pagecache_write_end(struct file *, struct address_space *mapping,
				loff_t pos, unsigned len, unsigned copied,
				struct page *page, void *fsdata);

439
440
441
442
443
444
/**
 * struct address_space - Contents of a cacheable, mappable object.
 * @host: Owner, either the inode or the block_device.
 * @i_pages: Cached pages.
 * @gfp_mask: Memory allocation flags to use for allocating pages.
 * @i_mmap_writable: Number of VM_SHARED mappings.
445
 * @nr_thps: Number of THPs in the pagecache (non-shmem only).
446
447
448
449
450
451
452
453
454
455
456
457
 * @i_mmap: Tree of private and shared mappings.
 * @i_mmap_rwsem: Protects @i_mmap and @i_mmap_writable.
 * @nrpages: Number of page entries, protected by the i_pages lock.
 * @nrexceptional: Shadow or DAX entries, protected by the i_pages lock.
 * @writeback_index: Writeback starts here.
 * @a_ops: Methods.
 * @flags: Error bits and flags (AS_*).
 * @wb_err: The most recent error which has occurred.
 * @private_lock: For use by the owner of the address_space.
 * @private_list: For use by the owner of the address_space.
 * @private_data: For use by the owner of the address_space.
 */
Linus Torvalds's avatar
Linus Torvalds committed
458
struct address_space {
459
460
461
462
	struct inode		*host;
	struct xarray		i_pages;
	gfp_t			gfp_mask;
	atomic_t		i_mmap_writable;
463
464
465
466
#ifdef CONFIG_READ_ONLY_THP_FOR_FS
	/* number of thp, only for non-shmem files */
	atomic_t		nr_thps;
#endif
467
468
469
	struct rb_root_cached	i_mmap;
	struct rw_semaphore	i_mmap_rwsem;
	unsigned long		nrpages;
470
	unsigned long		nrexceptional;
471
472
473
	pgoff_t			writeback_index;
	const struct address_space_operations *a_ops;
	unsigned long		flags;
474
	errseq_t		wb_err;
475
476
477
	spinlock_t		private_lock;
	struct list_head	private_list;
	void			*private_data;
478
} __attribute__((aligned(sizeof(long)))) __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
479
480
	/*
	 * On most architectures that alignment is already the case; but
Lucas De Marchi's avatar
Lucas De Marchi committed
481
	 * must be enforced here for CRIS, to let the least significant bit
Linus Torvalds's avatar
Linus Torvalds committed
482
483
	 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
	 */
484
struct request_queue;
Linus Torvalds's avatar
Linus Torvalds committed
485
486
487

struct block_device {
	dev_t			bd_dev;  /* not a kdev_t - it's a search key */
488
	int			bd_openers;
Linus Torvalds's avatar
Linus Torvalds committed
489
	struct inode *		bd_inode;	/* will die */
490
	struct super_block *	bd_super;
491
	struct mutex		bd_mutex;	/* open/close mutex */
492
	void *			bd_claiming;
Linus Torvalds's avatar
Linus Torvalds committed
493
494
	void *			bd_holder;
	int			bd_holders;
495
	bool			bd_write_holder;
496
#ifdef CONFIG_SYSFS
497
	struct list_head	bd_holder_disks;
498
#endif
Linus Torvalds's avatar
Linus Torvalds committed
499
500
	struct block_device *	bd_contains;
	unsigned		bd_block_size;
501
	u8			bd_partno;
Linus Torvalds's avatar
Linus Torvalds committed
502
503
504
505
506
	struct hd_struct *	bd_part;
	/* number of times partitions within this device have been opened. */
	unsigned		bd_part_count;
	int			bd_invalidated;
	struct gendisk *	bd_disk;
507
	struct request_queue *  bd_queue;
508
	struct backing_dev_info *bd_bdi;
Linus Torvalds's avatar
Linus Torvalds committed
509
510
511
512
513
514
515
516
	struct list_head	bd_list;
	/*
	 * Private data.  You must have bd_claim'ed the block_device
	 * to use this.  NOTE:  bd_claim allows an owner to claim
	 * the same device multiple times, the owner must take special
	 * care to not mess up bd_private for that case.
	 */
	unsigned long		bd_private;
517
518
519
520
521

	/* The counter of freeze processes */
	int			bd_fsfreeze_count;
	/* Mutex for freeze */
	struct mutex		bd_fsfreeze_mutex;
522
} __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
523

524
525
526
527
528
/* XArray tags, for tagging dirty and writeback pages in the pagecache. */
#define PAGECACHE_TAG_DIRTY	XA_MARK_0
#define PAGECACHE_TAG_WRITEBACK	XA_MARK_1
#define PAGECACHE_TAG_TOWRITE	XA_MARK_2

Linus Torvalds's avatar
Linus Torvalds committed
529
/*
530
 * Returns true if any of the pages in the mapping are marked with the tag.
Linus Torvalds's avatar
Linus Torvalds committed
531
 */
532
533
534
535
static inline bool mapping_tagged(struct address_space *mapping, xa_mark_t tag)
{
	return xa_marked(&mapping->i_pages, tag);
}
Linus Torvalds's avatar
Linus Torvalds committed
536

537
538
static inline void i_mmap_lock_write(struct address_space *mapping)
{
539
	down_write(&mapping->i_mmap_rwsem);
540
541
}

542
543
544
545
546
static inline int i_mmap_trylock_write(struct address_space *mapping)
{
	return down_write_trylock(&mapping->i_mmap_rwsem);
}

547
548
static inline void i_mmap_unlock_write(struct address_space *mapping)
{
549
	up_write(&mapping->i_mmap_rwsem);
550
551
}

552
553
554
555
556
557
558
559
560
561
static inline void i_mmap_lock_read(struct address_space *mapping)
{
	down_read(&mapping->i_mmap_rwsem);
}

static inline void i_mmap_unlock_read(struct address_space *mapping)
{
	up_read(&mapping->i_mmap_rwsem);
}

562
563
564
565
566
567
568
569
570
571
static inline void i_mmap_assert_locked(struct address_space *mapping)
{
	lockdep_assert_held(&mapping->i_mmap_rwsem);
}

static inline void i_mmap_assert_write_locked(struct address_space *mapping)
{
	lockdep_assert_held_write(&mapping->i_mmap_rwsem);
}

Linus Torvalds's avatar
Linus Torvalds committed
572
573
574
575
576
/*
 * Might pages of this file be mapped into userspace?
 */
static inline int mapping_mapped(struct address_space *mapping)
{
577
	return	!RB_EMPTY_ROOT(&mapping->i_mmap.rb_root);
Linus Torvalds's avatar
Linus Torvalds committed
578
579
580
581
582
583
584
}

/*
 * Might pages of this file have been modified in userspace?
 * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
 * marks vma as VM_SHARED if it is shared, and the file was opened for
 * writing i.e. vma may be mprotected writable even if now readonly.
585
586
587
 *
 * If i_mmap_writable is negative, no new writable mappings are allowed. You
 * can only deny writable mappings, if none exists right now.
Linus Torvalds's avatar
Linus Torvalds committed
588
589
590
 */
static inline int mapping_writably_mapped(struct address_space *mapping)
{
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
	return atomic_read(&mapping->i_mmap_writable) > 0;
}

static inline int mapping_map_writable(struct address_space *mapping)
{
	return atomic_inc_unless_negative(&mapping->i_mmap_writable) ?
		0 : -EPERM;
}

static inline void mapping_unmap_writable(struct address_space *mapping)
{
	atomic_dec(&mapping->i_mmap_writable);
}

static inline int mapping_deny_writable(struct address_space *mapping)
{
	return atomic_dec_unless_positive(&mapping->i_mmap_writable) ?
		0 : -EBUSY;
}

static inline void mapping_allow_writable(struct address_space *mapping)
{
	atomic_inc(&mapping->i_mmap_writable);
Linus Torvalds's avatar
Linus Torvalds committed
614
615
616
617
618
619
620
621
622
623
624
625
626
}

/*
 * Use sequence counter to get consistent i_size on 32-bit processors.
 */
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
#include <linux/seqlock.h>
#define __NEED_I_SIZE_ORDERED
#define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
#else
#define i_size_ordered_init(inode) do { } while (0)
#endif

Al Viro's avatar
Al Viro committed
627
628
struct posix_acl;
#define ACL_NOT_CACHED ((void *)(-1))
629
#define ACL_DONT_CACHE ((void *)(-3))
Al Viro's avatar
Al Viro committed
630

631
632
633
634
635
636
637
638
639
640
641
642
static inline struct posix_acl *
uncached_acl_sentinel(struct task_struct *task)
{
	return (void *)task + 1;
}

static inline bool
is_uncached_acl(struct posix_acl *acl)
{
	return (long)acl & 1;
}

643
644
645
#define IOP_FASTPERM	0x0001
#define IOP_LOOKUP	0x0002
#define IOP_NOFOLLOW	0x0004
646
#define IOP_XATTR	0x0008
647
#define IOP_DEFAULT_READLINK	0x0010
648

649
650
struct fsnotify_mark_connector;

651
652
653
654
655
/*
 * Keep mostly read-only and often accessed (especially for
 * the RCU path lookup and 'stat' data) fields at the beginning
 * of the 'struct inode'
 */
Linus Torvalds's avatar
Linus Torvalds committed
656
struct inode {
657
	umode_t			i_mode;
658
	unsigned short		i_opflags;
659
660
	kuid_t			i_uid;
	kgid_t			i_gid;
661
662
663
664
665
666
667
	unsigned int		i_flags;

#ifdef CONFIG_FS_POSIX_ACL
	struct posix_acl	*i_acl;
	struct posix_acl	*i_default_acl;
#endif

668
669
	const struct inode_operations	*i_op;
	struct super_block	*i_sb;
670
	struct address_space	*i_mapping;
671

672
673
674
#ifdef CONFIG_SECURITY
	void			*i_security;
#endif
675

676
677
	/* Stat data, not accessed from path walking */
	unsigned long		i_ino;
Miklos Szeredi's avatar
Miklos Szeredi committed
678
679
680
681
682
683
684
685
686
687
688
	/*
	 * Filesystems may only read i_nlink directly.  They shall use the
	 * following functions for modification:
	 *
	 *    (set|clear|inc|drop)_nlink
	 *    inode_(inc|dec)_link_count
	 */
	union {
		const unsigned int i_nlink;
		unsigned int __i_nlink;
	};
689
	dev_t			i_rdev;
690
	loff_t			i_size;
691
692
693
	struct timespec64	i_atime;
	struct timespec64	i_mtime;
	struct timespec64	i_ctime;
694
695
	spinlock_t		i_lock;	/* i_blocks, i_bytes, maybe i_size */
	unsigned short          i_bytes;
696
697
	u8			i_blkbits;
	u8			i_write_hint;
698
699
700
701
702
703
704
705
	blkcnt_t		i_blocks;

#ifdef __NEED_I_SIZE_ORDERED
	seqcount_t		i_size_seqcount;
#endif

	/* Misc */
	unsigned long		i_state;
706
	struct rw_semaphore	i_rwsem;
707

708
	unsigned long		dirtied_when;	/* jiffies of first dirtying */
709
	unsigned long		dirtied_time_when;
710

Linus Torvalds's avatar
Linus Torvalds committed
711
	struct hlist_node	i_hash;
712
	struct list_head	i_io_list;	/* backing dev IO list */
713
714
#ifdef CONFIG_CGROUP_WRITEBACK
	struct bdi_writeback	*i_wb;		/* the associated cgroup wb */
715
716
717
718
719

	/* foreign inode detection, see wbc_detach_inode() */
	int			i_wb_frn_winner;
	u16			i_wb_frn_avg_time;
	u16			i_wb_frn_history;
720
#endif
Nick Piggin's avatar
Nick Piggin committed
721
	struct list_head	i_lru;		/* inode LRU list */
Linus Torvalds's avatar
Linus Torvalds committed
722
	struct list_head	i_sb_list;
723
	struct list_head	i_wb_list;	/* backing dev writeback list */
Nick Piggin's avatar
Nick Piggin committed
724
	union {
725
		struct hlist_head	i_dentry;
Nick Piggin's avatar
Nick Piggin committed
726
727
		struct rcu_head		i_rcu;
	};
728
	atomic64_t		i_version;
729
	atomic64_t		i_sequence; /* see futex */
730
	atomic_t		i_count;
Christoph Hellwig's avatar
Christoph Hellwig committed
731
	atomic_t		i_dio_count;
732
	atomic_t		i_writecount;
733
#if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING)
Mimi Zohar's avatar
Mimi Zohar committed
734
735
	atomic_t		i_readcount; /* struct files open RO */
#endif
Al Viro's avatar
Al Viro committed
736
737
738
739
	union {
		const struct file_operations	*i_fop;	/* former ->i_op->default_file_ops */
		void (*free_inode)(struct inode *);
	};
740
	struct file_lock_context	*i_flctx;
Linus Torvalds's avatar
Linus Torvalds committed
741
742
	struct address_space	i_data;
	struct list_head	i_devices;
743
744
	union {
		struct pipe_inode_info	*i_pipe;
745
		struct block_device	*i_bdev;
746
		struct cdev		*i_cdev;
Al Viro's avatar
Al Viro committed
747
		char			*i_link;
Al Viro's avatar
Al Viro committed
748
		unsigned		i_dir_seq;
749
	};
Linus Torvalds's avatar
Linus Torvalds committed
750
751
752

	__u32			i_generation;

753
754
#ifdef CONFIG_FSNOTIFY
	__u32			i_fsnotify_mask; /* all events this inode cares about */
755
	struct fsnotify_mark_connector __rcu	*i_fsnotify_marks;
Robert Love's avatar
Robert Love committed
756
757
#endif

758
#ifdef CONFIG_FS_ENCRYPTION
759
760
761
	struct fscrypt_info	*i_crypt_info;
#endif

762
763
764
765
#ifdef CONFIG_FS_VERITY
	struct fsverity_info	*i_verity_info;
#endif

766
	void			*i_private; /* fs or device private pointer */
767
} __randomize_layout;
Linus Torvalds's avatar
Linus Torvalds committed
768

769
770
struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode);

Fabian Frederick's avatar
Fabian Frederick committed
771
772
773
774
775
static inline unsigned int i_blocksize(const struct inode *node)
{
	return (1 << node->i_blkbits);
}

Al Viro's avatar
Al Viro committed
776
777
778
779
780
static inline int inode_unhashed(struct inode *inode)
{
	return hlist_unhashed(&inode->i_hash);
}

Al Viro's avatar
Al Viro committed
781
782
783
784
785
786
787
788
789
790
791
/*
 * __mark_inode_dirty expects inodes to be hashed.  Since we don't
 * want special inodes in the fileset inode space, we make them
 * appear hashed, but do not put on any lists.  hlist_del()
 * will work fine and require no locking.
 */
static inline void inode_fake_hash(struct inode *inode)
{
	hlist_add_fake(&inode->i_hash);
}

792
793
794
795
796
797
/*
 * inode->i_mutex nesting subclasses for the lock validator:
 *
 * 0: the object of the current VFS operation
 * 1: parent
 * 2: child/target
798
799
 * 3: xattr
 * 4: second non-directory
800
801
802
 * 5: second parent (when locking independent directories in rename)
 *
 * I_MUTEX_NONDIR2 is for certain operations (such as rename) which lock two
803
 * non-directories at once.
804
805
 *
 * The locking order between these classes is
806
 * parent[2] -> child -> grandchild -> normal -> xattr -> second non-directory
807
808
809
810
811
812
 */
enum inode_i_mutex_lock_class
{
	I_MUTEX_NORMAL,
	I_MUTEX_PARENT,
	I_MUTEX_CHILD,
813
	I_MUTEX_XATTR,
814
815
	I_MUTEX_NONDIR2,
	I_MUTEX_PARENT2,
816
817
};

Al Viro's avatar
Al Viro committed
818
819
static inline void inode_lock(struct inode *inode)
{
820
	down_write(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
821
822
823
824
}

static inline void inode_unlock(struct inode *inode)
{
825
826
827
828
829
830
831
832
833
834
835
	up_write(&inode->i_rwsem);
}

static inline void inode_lock_shared(struct inode *inode)
{
	down_read(&inode->i_rwsem);
}

static inline void inode_unlock_shared(struct inode *inode)
{
	up_read(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
836
837
838
839
}

static inline int inode_trylock(struct inode *inode)
{
840
841
842
843
844
845
	return down_write_trylock(&inode->i_rwsem);
}

static inline int inode_trylock_shared(struct inode *inode)
{
	return down_read_trylock(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
846
847
848
849
}

static inline int inode_is_locked(struct inode *inode)
{
850
	return rwsem_is_locked(&inode->i_rwsem);
Al Viro's avatar
Al Viro committed
851
852
853
854
}

static inline void inode_lock_nested(struct inode *inode, unsigned subclass)
{
855
	down_write_nested(&inode->i_rwsem, subclass);
Al Viro's avatar
Al Viro committed
856
857
}

858
859
860
861
862
static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
{
	down_read_nested(&inode->i_rwsem, subclass);
}

863
864
865
void lock_two_nondirectories(struct inode *, struct inode*);
void unlock_two_nondirectories(struct inode *, struct inode*);

Linus Torvalds's avatar
Linus Torvalds committed
866
867
868
869
870
871
872
873
874
875
/*
 * NOTE: in a 32bit arch with a preemptable kernel and
 * an UP compile the i_size_read/write must be atomic
 * with respect to the local cpu (unlike with preempt disabled),
 * but they don't need to be atomic with respect to other cpus like in
 * true SMP (so they need either to either locally disable irq around
 * the read or for example on x86 they can be still implemented as a
 * cmpxchg8b without the need of the lock prefix). For SMP compiles
 * and 64bit archs it makes no difference if preempt is enabled or not.
 */
876
static inline loff_t i_size_read(const struct inode *inode)
Linus Torvalds's avatar
Linus Torvalds committed
877
878
879
880
881
882
883
884
885
886
{
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
	loff_t i_size;
	unsigned int seq;

	do {
		seq = read_seqcount_begin(&inode->i_size_seqcount);
		i_size = inode->i_size;
	} while (read_seqcount_retry(&inode->i_size_seqcount, seq));
	return i_size;
887
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
Linus Torvalds's avatar
Linus Torvalds committed
888
889
890
891
892
893
894
895
896
897
898
	loff_t i_size;

	preempt_disable();
	i_size = inode->i_size;
	preempt_enable();
	return i_size;
#else
	return inode->i_size;
#endif
}

899
900
901
902
903
/*
 * NOTE: unlike i_size_read(), i_size_write() does need locking around it
 * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount
 * can be lost, resulting in subsequent i_size_read() calls spinning forever.
 */
Linus Torvalds's avatar
Linus Torvalds committed
904
905
906
static inline void i_size_write(struct inode *inode, loff_t i_size)
{
#if BITS_PER_LONG==32 && defined(CONFIG_SMP)
907
	preempt_disable();
Linus Torvalds's avatar
Linus Torvalds committed
908
909
910
	write_seqcount_begin(&inode->i_size_seqcount);
	inode->i_size = i_size;
	write_seqcount_end(&inode->i_size_seqcount);
911
	preempt_enable();
912
#elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPTION)
Linus Torvalds's avatar
Linus Torvalds committed
913
914
915
916
917
918
919
920
	preempt_disable();
	inode->i_size = i_size;
	preempt_enable();
#else
	inode->i_size = i_size;
#endif
}

921
static inline unsigned iminor(const struct inode *inode)
Linus Torvalds's avatar
Linus Torvalds committed
922
923
924
925
{
	return MINOR(inode->i_rdev);
}

926
static inline unsigned imajor(const struct inode *inode)
Linus Torvalds's avatar
Linus Torvalds committed
927
928
929
930
931
932
933
934
{
	return MAJOR(inode->i_rdev);
}

extern struct block_device *I_BDEV(struct inode *inode);

struct fown_struct {
	rwlock_t lock;          /* protects pid, uid, euid fields */
935
936
	struct pid *pid;	/* pid or -pgrp where SIGIO should be sent */
	enum pid_type pid_type;	/* Kind of process group SIGIO should be sent to */
937
	kuid_t uid, euid;	/* uid/euid of process setting the owner */
Linus Torvalds's avatar
Linus Torvalds committed
938
939
940
941
942
943
944
	int signum;		/* posix.1b rt signal to be delivered on IO */
};

/*
 * Track a single file's readahead state
 */
struct file_ra_state {
945
946
947
	pgoff_t start;			/* where readahead started */
	unsigned int size;		/* # of readahead pages */
	unsigned int async_size;	/* do asynchronous readahead when
948
					   there are only # of pages ahead */
949

950
	unsigned int ra_pages;		/* Maximum readahead window */
951
	unsigned int mmap_miss;		/* Cache miss stat for mmap accesses */
952
	loff_t prev_pos;		/* Cache last read() position */
Linus Torvalds's avatar
Linus Torvalds committed
953
954
};

955
956
957
958
959
/*
 * Check if @index falls in the readahead windows.
 */
static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
{
960
961
	return (index >= ra->start &&
		index <  ra->start + ra->size);
962
963
}

Linus Torvalds's avatar
Linus Torvalds committed
964
struct file {
965
	union {
966
		struct llist_node	fu_llist;
967
968
		struct rcu_head 	fu_rcuhead;
	} f_u;
969
	struct path		f_path;
970
	struct inode		*f_inode;	/* cached value */
971
	const struct file_operations	*f_op;
972
973

	/*
974
	 * Protects f_ep_links, f_flags.
975
976
977
	 * Must not be taken from IRQ context.
	 */
	spinlock_t		f_lock;
978
	enum rw_hint		f_write_hint;
Al Viro's avatar
Al Viro committed
979
	atomic_long_t		f_count;
Linus Torvalds's avatar
Linus Torvalds committed
980
	unsigned int 		f_flags;
981
	fmode_t			f_mode;
982
	struct mutex		f_pos_lock;
Linus Torvalds's avatar
Linus Torvalds committed
983
984
	loff_t			f_pos;
	struct fown_struct	f_owner;
985
	const struct cred	*f_cred;
Linus Torvalds's avatar
Linus Torvalds committed
986
987
	struct file_ra_state	f_ra;

988
	u64			f_version;
989
#ifdef CONFIG_SECURITY
Linus Torvalds's avatar
Linus Torvalds committed
990
	void			*f_security;
991
#endif
Linus Torvalds's avatar
Linus Torvalds committed
992
993
994
995
996
997
	/* needed for tty driver, and maybe others */
	void			*private_data;

#ifdef CONFIG_EPOLL
	/* Used by fs/eventpoll.c to link all the hooks to this file */
	struct list_head	f_ep_links;
Jason Baron's avatar
Jason Baron committed
998
	struct list_head	f_tfile_llink;
Linus Torvalds's avatar
Linus Torvalds committed
999
1000
#endif /* #ifdef CONFIG_EPOLL */
	struct address_space	*f_mapping;
1001
	errseq_t		f_wb_err;
1002
	errseq_t		f_sb_err; /* for syncfs */
1003
1004
} __randomize_layout
  __attribute__((aligned(4)));	/* lest something weird decides that 2 is OK */
Linus Torvalds's avatar
Linus Torvalds committed
1005

1006
1007
1008
1009
struct file_handle {
	__u32 handle_bytes;
	int handle_type;
	/* file identifier */
1010
	unsigned char f_handle[];
1011
1012
};

Al Viro's avatar
Al Viro committed
1013
1014
1015
1016
1017
static inline struct file *get_file(struct file *f)
{
	atomic_long_inc(&f->f_count);
	return f;
}
1018
1019
1020
#define get_file_rcu_many(x, cnt)	\
	atomic_long_add_unless(&(x)->f_count, (cnt), 0)
#define get_file_rcu(x) get_file_rcu_many((x), 1)
Al Viro's avatar
Al Viro committed
1021
#define file_count(x)	atomic_long_read(&(x)->f_count)
Linus Torvalds's avatar
Linus Torvalds committed
1022
1023
1024
1025
1026
1027

#define	MAX_NON_LFS	((1UL<<31) - 1)

/* Page cache limit. The filesystems should put that into their s_maxbytes 
   limits, otherwise bad things can happen in VM. */ 
#if BITS_PER_LONG==32
1028
#define MAX_LFS_FILESIZE	((loff_t)ULONG_MAX << PAGE_SHIFT)
Linus Torvalds's avatar
Linus Torvalds committed
1029
#elif BITS_PER_LONG==64
1030
#define MAX_LFS_FILESIZE 	((loff_t)LLONG_MAX)
Linus Torvalds's avatar
Linus Torvalds committed
1031
1032
1033
1034
#endif

#define FL_POSIX	1
#define FL_FLOCK	2
1035
#define FL_DELEG	4	/* NFSv4 delegation */
Linus Torvalds's avatar
Linus Torvalds committed
1036
#define FL_ACCESS	8	/* not trying to lock, just looking */
1037
#define FL_EXISTS	16	/* when unlocking, test for existence */
Linus Torvalds's avatar
Linus Torvalds committed
1038
#define FL_LEASE	32	/* lease held on this file */
1039
#define FL_CLOSE	64	/* unlock on close */
Linus Torvalds's avatar
Linus Torvalds committed
1040
#define FL_SLEEP	128	/* A blocking lock */
1041
1042
#define FL_DOWNGRADE_PENDING	256 /* Lease is being downgraded */
#define FL_UNLOCK_PENDING	512 /* Lease is being broken */
1043
#define FL_OFDLCK	1024	/* lock is "owned" by struct file */
1044
#define FL_LAYOUT	2048	/* outstanding pNFS layout */
Linus Torvalds's avatar
Linus Torvalds committed
1045

1046
1047
#define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)

1048
1049
1050
1051
1052
1053
/*
 * Special return value from posix_lock_file() and vfs_lock_file() for
 * asynchronous locking.
 */
#define FILE_LOCK_DEFERRED 1

1054
/* legacy typedef, should eventually be removed */
1055
typedef void *fl_owner_t;
Linus Torvalds's avatar
Linus Torvalds committed
1056

1057
1058
struct file_lock;

Linus Torvalds's avatar
Linus Torvalds committed
1059
1060
1061
1062
1063
1064
struct file_lock_operations {
	void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
	void (*fl_release_private)(struct file_lock *);
};

struct lock_manager_operations {
1065
1066
	fl_owner_t (*lm_get_owner)(fl_owner_t);
	void (*lm_put_owner)(fl_owner_t);
1067
	void (*lm_notify)(struct file_lock *);	/* unblock callback */
1068
	int (*lm_grant)(struct file_lock *, int);
1069
	bool (*lm_break)(struct file_lock *);
1070
	int (*lm_change)(struct file_lock *, int, struct list_head *);
1071
	void (*lm_setup)(struct file_lock *, void **);
1072
	bool (*lm_breaker_owns_lease)(struct file_lock *);
Linus Torvalds's avatar
Linus Torvalds committed
1073
1074
};

1075
1076
struct lock_manager {
	struct list_head list;
1077
1078
1079
1080
1081
	/*
	 * NFSv4 and up also want opens blocked during the grace period;
	 * NLM doesn't care:
	 */
	bool block_opens;
1082
1083
};

1084
1085
struct net;
void locks_start_grace(struct net *, struct lock_manager *);
1086
void locks_end_grace(struct lock_manager *);
1087
1088
bool locks_in_grace(struct net *);
bool opens_in_grace(struct net *);
1089

Linus Torvalds's avatar
Linus Torvalds committed
1090
1091
1092
/* that will die - we need it for nfs_lock_info */
#include <linux/nfs_fs_i.h>

1093
1094
1095
1096
1097
1098
1099
1100
1101
/*
 * struct file_lock represents a generic "file lock". It's used to represent
 * POSIX byte range locks, BSD (flock) locks, and leases. It's important to
 * note that the same struct is used to represent both a request for a lock and
 * the lock itself, but the same object is never used for both.
 *
 * FIXME: should we create a separate "struct lock_request" to help distinguish
 * these two uses?
 *
1102
 * The varous i_flctx lists are ordered by:
1103
 *
1104
1105
1106
 * 1) lock owner
 * 2) lock range start
 * 3) lock range end
1107
1108
1109
 *
 * Obviously, the last two criteria only matter for POSIX locks.
 */
Linus Torvalds's avatar
Linus Torvalds committed
1110
struct file_lock {
1111
	struct file_lock *fl_blocker;	/* The lock, that is blocking us */
1112
	struct list_head fl_list;	/* link into file_lock_context */
1113
	struct hlist_node fl_link;	/* node in global lists */
1114
1115
1116
1117
1118
1119
	struct list_head fl_blocked_requests;	/* list of requests with
						 * ->fl_blocker pointing here
						 */
	struct list_head fl_blocked_member;	/* node in
						 * ->fl_blocker->fl_blocked_requests
						 */
Linus Torvalds's avatar
Linus Torvalds committed
1120
	fl_owner_t fl_owner;
1121
	unsigned int fl_flags;
1122
	unsigned char fl_type;
Linus Torvalds's avatar
Linus Torvalds committed
1123
	unsigned int fl_pid;
1124
	int fl_link_cpu;		/* what cpu's list is this on? */
Linus Torvalds's avatar
Linus Torvalds committed
1125
1126
1127
1128
1129
1130
	wait_queue_head_t fl_wait;
	struct file *fl_file;