xref: /openbmc/linux/fs/afs/internal.h (revision c69bf479)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2ec26815aSDavid Howells /* internal AFS stuff
31da177e4SLinus Torvalds  *
408e0e7c8SDavid Howells  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
51da177e4SLinus Torvalds  * Written by David Howells (dhowells@redhat.com)
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #include <linux/compiler.h>
91da177e4SLinus Torvalds #include <linux/kernel.h>
108a79790bSTina Ruchandani #include <linux/ktime.h>
111da177e4SLinus Torvalds #include <linux/fs.h>
121da177e4SLinus Torvalds #include <linux/pagemap.h>
1308e0e7c8SDavid Howells #include <linux/rxrpc.h>
1400d3b7a4SDavid Howells #include <linux/key.h>
15e8edc6e0SAlexey Dobriyan #include <linux/workqueue.h>
1600c541eaSAndrew Morton #include <linux/sched.h>
1780e50be4SChristoph Hellwig #include <linux/fscache.h>
18e1da0222SJens Axboe #include <linux/backing-dev.h>
19ff548773SDavid Howells #include <linux/uuid.h>
200722f186SSouptick Joarder #include <linux/mm_types.h>
210a5143f2SDavid Howells #include <linux/dns_resolver.h>
22f044c884SDavid Howells #include <net/net_namespace.h>
235b86d4ffSDavid Howells #include <net/netns/generic.h>
245b86d4ffSDavid Howells #include <net/sock.h>
258324f0bcSDavid Howells #include <net/af_rxrpc.h>
2600c541eaSAndrew Morton 
2708e0e7c8SDavid Howells #include "afs.h"
2808e0e7c8SDavid Howells #include "afs_vl.h"
2908e0e7c8SDavid Howells 
3008e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15
3108e0e7c8SDavid Howells 
3231143d5dSDavid Howells struct pagevec;
3308e0e7c8SDavid Howells struct afs_call;
3408e0e7c8SDavid Howells 
356c6c1d63SDavid Howells /*
366c6c1d63SDavid Howells  * Partial file-locking emulation mode.  (The problem being that AFS3 only
376c6c1d63SDavid Howells  * allows whole-file locks and no upgrading/downgrading).
386c6c1d63SDavid Howells  */
396c6c1d63SDavid Howells enum afs_flock_mode {
406c6c1d63SDavid Howells 	afs_flock_mode_unset,
416c6c1d63SDavid Howells 	afs_flock_mode_local,	/* Local locking only */
426c6c1d63SDavid Howells 	afs_flock_mode_openafs,	/* Don't get server lock for a partial lock */
436c6c1d63SDavid Howells 	afs_flock_mode_strict,	/* Always get a server lock for a partial lock */
446c6c1d63SDavid Howells 	afs_flock_mode_write,	/* Get an exclusive server lock for a partial lock */
456c6c1d63SDavid Howells };
466c6c1d63SDavid Howells 
4713fcc683SDavid Howells struct afs_fs_context {
4800d3b7a4SDavid Howells 	bool			force;		/* T to force cell type */
49bec5eb61Swanglei 	bool			autocell;	/* T if set auto mount operation */
504d673da1SDavid Howells 	bool			dyn_root;	/* T if dynamic root */
5113fcc683SDavid Howells 	bool			no_cell;	/* T if the source is "none" (for dynroot) */
526c6c1d63SDavid Howells 	enum afs_flock_mode	flock_mode;	/* Partial file-locking emulation mode */
5300d3b7a4SDavid Howells 	afs_voltype_t		type;		/* type of volume requested */
5413fcc683SDavid Howells 	unsigned int		volnamesz;	/* size of volume name */
5500d3b7a4SDavid Howells 	const char		*volname;	/* name of volume to mount */
565b86d4ffSDavid Howells 	struct afs_net		*net;		/* the AFS net namespace stuff */
5700d3b7a4SDavid Howells 	struct afs_cell		*cell;		/* cell in which to find volume */
5800d3b7a4SDavid Howells 	struct afs_volume	*volume;	/* volume record */
5900d3b7a4SDavid Howells 	struct key		*key;		/* key to use for secure mounting */
6000d3b7a4SDavid Howells };
6100d3b7a4SDavid Howells 
628e8d7f13SDavid Howells enum afs_call_state {
6398bf40cdSDavid Howells 	AFS_CALL_CL_REQUESTING,		/* Client: Request is being sent */
6498bf40cdSDavid Howells 	AFS_CALL_CL_AWAIT_REPLY,	/* Client: Awaiting reply */
6598bf40cdSDavid Howells 	AFS_CALL_CL_PROC_REPLY,		/* Client: rxrpc call complete; processing reply */
6698bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_OP_ID,	/* Server: Awaiting op ID */
6798bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_REQUEST,	/* Server: Awaiting request data */
6898bf40cdSDavid Howells 	AFS_CALL_SV_REPLYING,		/* Server: Replying */
6998bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_ACK,		/* Server: Awaiting final ACK */
708e8d7f13SDavid Howells 	AFS_CALL_COMPLETE,		/* Completed or failed */
718e8d7f13SDavid Howells };
72f044c884SDavid Howells 
7308e0e7c8SDavid Howells /*
748b2a464cSDavid Howells  * List of server addresses.
758b2a464cSDavid Howells  */
768b2a464cSDavid Howells struct afs_addr_list {
77ddd2b85fSJann Horn 	struct rcu_head		rcu;
788b2a464cSDavid Howells 	refcount_t		usage;
79d2ddc776SDavid Howells 	u32			version;	/* Version */
8068eb64c3SDavid Howells 	unsigned char		max_addrs;
8168eb64c3SDavid Howells 	unsigned char		nr_addrs;
823bf0fb6fSDavid Howells 	unsigned char		preferred;	/* Preferred address */
8368eb64c3SDavid Howells 	unsigned char		nr_ipv4;	/* Number of IPv4 addresses */
840a5143f2SDavid Howells 	enum dns_record_source	source:8;
850a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
863bf0fb6fSDavid Howells 	unsigned long		failed;		/* Mask of addrs that failed locally/ICMP */
873bf0fb6fSDavid Howells 	unsigned long		responded;	/* Mask of addrs that responded */
888b2a464cSDavid Howells 	struct sockaddr_rxrpc	addrs[];
8968eb64c3SDavid Howells #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
908b2a464cSDavid Howells };
918b2a464cSDavid Howells 
928b2a464cSDavid Howells /*
9308e0e7c8SDavid Howells  * a record of an in-progress RxRPC call
9408e0e7c8SDavid Howells  */
9508e0e7c8SDavid Howells struct afs_call {
9608e0e7c8SDavid Howells 	const struct afs_call_type *type;	/* type of call */
973bf0fb6fSDavid Howells 	struct afs_addr_list	*alist;		/* Address is alist[addr_ix] */
9808e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* processes awaiting completion */
99341f741fSDavid Howells 	struct work_struct	async_work;	/* async I/O processor */
10008e0e7c8SDavid Howells 	struct work_struct	work;		/* actual work processor */
10108e0e7c8SDavid Howells 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
10208e0e7c8SDavid Howells 	struct key		*key;		/* security for this call */
103f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
104a6853b9cSDavid Howells 	struct afs_server	*server;	/* The fileserver record if fs op (pins ref) */
105a6853b9cSDavid Howells 	struct afs_vlserver	*vlserver;	/* The vlserver record if vl op */
10608e0e7c8SDavid Howells 	void			*request;	/* request data (first part) */
107fc276122SDavid Howells 	struct iov_iter		def_iter;	/* Default buffer/data iterator */
108fc276122SDavid Howells 	struct iov_iter		*iter;		/* Iterator currently in use */
109fc276122SDavid Howells 	union {	/* Convenience for ->def_iter */
11012bdcf33SDavid Howells 		struct kvec	kvec[1];
11112bdcf33SDavid Howells 		struct bio_vec	bvec[1];
11212bdcf33SDavid Howells 	};
11308e0e7c8SDavid Howells 	void			*buffer;	/* reply receive buffer */
114ffba718eSDavid Howells 	union {
115ffba718eSDavid Howells 		long			ret0;	/* Value to reply with instead of 0 */
116ffba718eSDavid Howells 		struct afs_addr_list	*ret_alist;
117ffba718eSDavid Howells 		struct afs_vldb_entry	*ret_vldb;
118c3e9f888SDavid Howells 		char			*ret_str;
119ffba718eSDavid Howells 	};
120e49c7b2fSDavid Howells 	struct afs_operation	*op;
121ffba718eSDavid Howells 	unsigned int		server_index;
122341f741fSDavid Howells 	atomic_t		usage;
1238e8d7f13SDavid Howells 	enum afs_call_state	state;
12498bf40cdSDavid Howells 	spinlock_t		state_lock;
12508e0e7c8SDavid Howells 	int			error;		/* error code */
126d001648eSDavid Howells 	u32			abort_code;	/* Remote abort ID or 0 */
12794f699c9SDavid Howells 	unsigned int		max_lifespan;	/* Maximum lifespan to set if not 0 */
12808e0e7c8SDavid Howells 	unsigned		request_size;	/* size of request data */
12908e0e7c8SDavid Howells 	unsigned		reply_max;	/* maximum size of reply */
130bcd89270SMarc Dionne 	unsigned		count2;		/* count used in unmarshalling */
13108e0e7c8SDavid Howells 	unsigned char		unmarshall;	/* unmarshalling phase */
1323bf0fb6fSDavid Howells 	unsigned char		addr_ix;	/* Address in ->alist */
133dde9f095SDavid Howells 	bool			drop_ref;	/* T if need to drop ref for incoming call */
13431143d5dSDavid Howells 	bool			send_pages;	/* T if data from mapping should be sent */
135d001648eSDavid Howells 	bool			need_attention;	/* T if RxRPC poked us */
13656ff9c83SDavid Howells 	bool			async;		/* T if asynchronous */
137a68f4a27SDavid Howells 	bool			upgrade;	/* T to request service upgrade */
1384571577fSDavid Howells 	bool			have_reply_time; /* T if have got reply_time */
13920b8391fSDavid Howells 	bool			intr;		/* T if interruptible */
14038355eecSDavid Howells 	bool			unmarshalling_error; /* T if an unmarshalling error occurred */
141bf99a53cSDavid Howells 	u16			service_id;	/* Actual service ID (after upgrade) */
142a25e21f0SDavid Howells 	unsigned int		debug_id;	/* Trace ID */
14350a2c953SDavid Howells 	u32			operation_ID;	/* operation ID for an incoming call */
14408e0e7c8SDavid Howells 	u32			count;		/* count for use in unmarshalling */
14512bdcf33SDavid Howells 	union {					/* place to extract temporary data */
14612bdcf33SDavid Howells 		struct {
14712bdcf33SDavid Howells 			__be32	tmp_u;
14812bdcf33SDavid Howells 			__be32	tmp;
14912bdcf33SDavid Howells 		} __attribute__((packed));
15012bdcf33SDavid Howells 		__be64		tmp64;
15112bdcf33SDavid Howells 	};
15212d8e95aSDavid Howells 	ktime_t			reply_time;	/* Time of first reply packet */
15308e0e7c8SDavid Howells };
15408e0e7c8SDavid Howells 
15508e0e7c8SDavid Howells struct afs_call_type {
15600d3b7a4SDavid Howells 	const char *name;
157025db80cSDavid Howells 	unsigned int op; /* Really enum afs_fs_operation */
15800d3b7a4SDavid Howells 
15908e0e7c8SDavid Howells 	/* deliver request or reply data to an call
16008e0e7c8SDavid Howells 	 * - returning an error will cause the call to be aborted
16108e0e7c8SDavid Howells 	 */
162d001648eSDavid Howells 	int (*deliver)(struct afs_call *call);
16308e0e7c8SDavid Howells 
16408e0e7c8SDavid Howells 	/* clean up a call */
16508e0e7c8SDavid Howells 	void (*destructor)(struct afs_call *call);
166341f741fSDavid Howells 
167341f741fSDavid Howells 	/* Work function */
168341f741fSDavid Howells 	void (*work)(struct work_struct *work);
1693bf0fb6fSDavid Howells 
1703bf0fb6fSDavid Howells 	/* Call done function (gets called immediately on success or failure) */
1713bf0fb6fSDavid Howells 	void (*done)(struct afs_call *call);
17208e0e7c8SDavid Howells };
17308e0e7c8SDavid Howells 
17408e0e7c8SDavid Howells /*
1754343d008SDavid Howells  * Key available for writeback on a file.
1764343d008SDavid Howells  */
1774343d008SDavid Howells struct afs_wb_key {
1784343d008SDavid Howells 	refcount_t		usage;
1794343d008SDavid Howells 	struct key		*key;
1804343d008SDavid Howells 	struct list_head	vnode_link;	/* Link in vnode->wb_keys */
1814343d008SDavid Howells };
1824343d008SDavid Howells 
1834343d008SDavid Howells /*
184215804a9SDavid Howells  * AFS open file information record.  Pointed to by file->private_data.
185215804a9SDavid Howells  */
186215804a9SDavid Howells struct afs_file {
187215804a9SDavid Howells 	struct key		*key;		/* The key this file was opened with */
1884343d008SDavid Howells 	struct afs_wb_key	*wb;		/* Writeback key record for this file */
189215804a9SDavid Howells };
190215804a9SDavid Howells 
191215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
192215804a9SDavid Howells {
193215804a9SDavid Howells 	struct afs_file *af = file->private_data;
194215804a9SDavid Howells 
195215804a9SDavid Howells 	return af->key;
196215804a9SDavid Howells }
197215804a9SDavid Howells 
198215804a9SDavid Howells /*
199196ee9cdSDavid Howells  * Record of an outstanding read operation on a vnode.
200196ee9cdSDavid Howells  */
201196ee9cdSDavid Howells struct afs_read {
202196ee9cdSDavid Howells 	loff_t			pos;		/* Where to start reading */
203e8e581a8SDavid Howells 	loff_t			len;		/* How much we're asking for */
204196ee9cdSDavid Howells 	loff_t			actual_len;	/* How much we're actually getting */
2056a0e3999SDavid Howells 	loff_t			remain;		/* Amount remaining */
206f3ddee8dSDavid Howells 	loff_t			file_size;	/* File size returned by server */
207*c69bf479SDavid Howells 	struct key		*key;		/* The key to use to reissue the read */
208f3ddee8dSDavid Howells 	afs_dataversion_t	data_version;	/* Version number returned by server */
209f3ddee8dSDavid Howells 	refcount_t		usage;
210196ee9cdSDavid Howells 	unsigned int		index;		/* Which page we're reading into */
211196ee9cdSDavid Howells 	unsigned int		nr_pages;
21212bdcf33SDavid Howells 	unsigned int		offset;		/* offset into current page */
213a58823acSDavid Howells 	struct afs_vnode	*vnode;
214a58823acSDavid Howells 	void (*page_done)(struct afs_read *);
215f3ddee8dSDavid Howells 	struct page		**pages;
216f3ddee8dSDavid Howells 	struct page		*array[];
217196ee9cdSDavid Howells };
218196ee9cdSDavid Howells 
219196ee9cdSDavid Howells /*
22008e0e7c8SDavid Howells  * AFS superblock private data
22108e0e7c8SDavid Howells  * - there's one superblock per volume
22208e0e7c8SDavid Howells  */
22308e0e7c8SDavid Howells struct afs_super_info {
2245b86d4ffSDavid Howells 	struct net		*net_ns;	/* Network namespace */
22549566f6fSDavid Howells 	struct afs_cell		*cell;		/* The cell in which the volume resides */
22608e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume record */
2276c6c1d63SDavid Howells 	enum afs_flock_mode	flock_mode:8;	/* File locking emulation mode */
2284d673da1SDavid Howells 	bool			dyn_root;	/* True if dynamic root */
22908e0e7c8SDavid Howells };
23008e0e7c8SDavid Howells 
23108e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
23208e0e7c8SDavid Howells {
23308e0e7c8SDavid Howells 	return sb->s_fs_info;
23408e0e7c8SDavid Howells }
23508e0e7c8SDavid Howells 
23608e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
23708e0e7c8SDavid Howells 
23808e0e7c8SDavid Howells /*
2396f8880d8SDavid Howells  * Set of substitutes for @sys.
2406f8880d8SDavid Howells  */
2416f8880d8SDavid Howells struct afs_sysnames {
2426f8880d8SDavid Howells #define AFS_NR_SYSNAME 16
2436f8880d8SDavid Howells 	char			*subs[AFS_NR_SYSNAME];
2446f8880d8SDavid Howells 	refcount_t		usage;
2456f8880d8SDavid Howells 	unsigned short		nr;
2466f8880d8SDavid Howells 	char			blank[1];
2476f8880d8SDavid Howells };
2486f8880d8SDavid Howells 
2496f8880d8SDavid Howells /*
250f044c884SDavid Howells  * AFS network namespace record.
251f044c884SDavid Howells  */
252f044c884SDavid Howells struct afs_net {
2535b86d4ffSDavid Howells 	struct net		*net;		/* Backpointer to the owning net namespace */
254f044c884SDavid Howells 	struct afs_uuid		uuid;
255f044c884SDavid Howells 	bool			live;		/* F if this namespace is being removed */
256f044c884SDavid Howells 
257f044c884SDavid Howells 	/* AF_RXRPC I/O stuff */
258f044c884SDavid Howells 	struct socket		*socket;
259f044c884SDavid Howells 	struct afs_call		*spare_incoming_call;
260f044c884SDavid Howells 	struct work_struct	charge_preallocation_work;
261f044c884SDavid Howells 	struct mutex		socket_mutex;
262f044c884SDavid Howells 	atomic_t		nr_outstanding_calls;
263f044c884SDavid Howells 	atomic_t		nr_superblocks;
264f044c884SDavid Howells 
265f044c884SDavid Howells 	/* Cell database */
266989782dcSDavid Howells 	struct rb_root		cells;
26792e3cc91SDavid Howells 	struct afs_cell		*ws_cell;
268989782dcSDavid Howells 	struct work_struct	cells_manager;
269989782dcSDavid Howells 	struct timer_list	cells_timer;
270989782dcSDavid Howells 	atomic_t		cells_outstanding;
27192e3cc91SDavid Howells 	struct rw_semaphore	cells_lock;
2728a070a96SDavid Howells 	struct mutex		cells_alias_lock;
273f044c884SDavid Howells 
2740da0b7fdSDavid Howells 	struct mutex		proc_cells_lock;
2756b3944e4SDavid Howells 	struct hlist_head	proc_cells;
276f044c884SDavid Howells 
277d2ddc776SDavid Howells 	/* Known servers.  Theoretically each fileserver can only be in one
278d2ddc776SDavid Howells 	 * cell, but in practice, people create aliases and subsets and there's
279d2ddc776SDavid Howells 	 * no easy way to distinguish them.
280d2ddc776SDavid Howells 	 */
281f6cbb368SDavid Howells 	seqlock_t		fs_lock;	/* For fs_servers, fs_probe_*, fs_proc */
282d2ddc776SDavid Howells 	struct rb_root		fs_servers;	/* afs_server (by server UUID or address) */
283f6cbb368SDavid Howells 	struct list_head	fs_probe_fast;	/* List of afs_server to probe at 30s intervals */
284f6cbb368SDavid Howells 	struct list_head	fs_probe_slow;	/* List of afs_server to probe at 5m intervals */
285d2ddc776SDavid Howells 	struct hlist_head	fs_proc;	/* procfs servers list */
286d2ddc776SDavid Howells 
287d2ddc776SDavid Howells 	struct hlist_head	fs_addresses4;	/* afs_server (by lowest IPv4 addr) */
288d2ddc776SDavid Howells 	struct hlist_head	fs_addresses6;	/* afs_server (by lowest IPv6 addr) */
289d2ddc776SDavid Howells 	seqlock_t		fs_addr_lock;	/* For fs_addresses[46] */
290d2ddc776SDavid Howells 
291d2ddc776SDavid Howells 	struct work_struct	fs_manager;
292d2ddc776SDavid Howells 	struct timer_list	fs_timer;
293f6cbb368SDavid Howells 
294f6cbb368SDavid Howells 	struct work_struct	fs_prober;
295f6cbb368SDavid Howells 	struct timer_list	fs_probe_timer;
296d2ddc776SDavid Howells 	atomic_t		servers_outstanding;
297f044c884SDavid Howells 
298f044c884SDavid Howells 	/* File locking renewal management */
299f044c884SDavid Howells 	struct mutex		lock_manager_mutex;
300f044c884SDavid Howells 
301f044c884SDavid Howells 	/* Misc */
3020da0b7fdSDavid Howells 	struct super_block	*dynroot_sb;	/* Dynamic root mount superblock */
303f044c884SDavid Howells 	struct proc_dir_entry	*proc_afs;	/* /proc/net/afs directory */
3046f8880d8SDavid Howells 	struct afs_sysnames	*sysnames;
3056f8880d8SDavid Howells 	rwlock_t		sysnames_lock;
306d55b4da4SDavid Howells 
307d55b4da4SDavid Howells 	/* Statistics counters */
308d55b4da4SDavid Howells 	atomic_t		n_lookup;	/* Number of lookups done */
309d55b4da4SDavid Howells 	atomic_t		n_reval;	/* Number of dentries needing revalidation */
310d55b4da4SDavid Howells 	atomic_t		n_inval;	/* Number of invalidations by the server */
311f3ddee8dSDavid Howells 	atomic_t		n_relpg;	/* Number of invalidations by releasepage */
312d55b4da4SDavid Howells 	atomic_t		n_read_dir;	/* Number of directory pages read */
31363a4681fSDavid Howells 	atomic_t		n_dir_cr;	/* Number of directory entry creation edits */
31463a4681fSDavid Howells 	atomic_t		n_dir_rm;	/* Number of directory entry removal edits */
31576a5cb6fSDavid Howells 	atomic_t		n_stores;	/* Number of store ops */
31676a5cb6fSDavid Howells 	atomic_long_t		n_store_bytes;	/* Number of bytes stored */
31776a5cb6fSDavid Howells 	atomic_long_t		n_fetch_bytes;	/* Number of bytes fetched */
31876a5cb6fSDavid Howells 	atomic_t		n_fetches;	/* Number of data fetch ops */
319f044c884SDavid Howells };
320f044c884SDavid Howells 
3216f8880d8SDavid Howells extern const char afs_init_sysname[];
322f044c884SDavid Howells 
323989782dcSDavid Howells enum afs_cell_state {
324989782dcSDavid Howells 	AFS_CELL_UNSET,
325989782dcSDavid Howells 	AFS_CELL_ACTIVATING,
326989782dcSDavid Howells 	AFS_CELL_ACTIVE,
327989782dcSDavid Howells 	AFS_CELL_DEACTIVATING,
328989782dcSDavid Howells 	AFS_CELL_INACTIVE,
329989782dcSDavid Howells 	AFS_CELL_FAILED,
3301d0e850aSDavid Howells 	AFS_CELL_REMOVED,
331989782dcSDavid Howells };
332989782dcSDavid Howells 
333f044c884SDavid Howells /*
334d2ddc776SDavid Howells  * AFS cell record.
335d2ddc776SDavid Howells  *
336d2ddc776SDavid Howells  * This is a tricky concept to get right as it is possible to create aliases
337d2ddc776SDavid Howells  * simply by pointing AFSDB/SRV records for two names at the same set of VL
338d2ddc776SDavid Howells  * servers; it is also possible to do things like setting up two sets of VL
339d2ddc776SDavid Howells  * servers, one of which provides a superset of the volumes provided by the
340d2ddc776SDavid Howells  * other (for internal/external division, for example).
341d2ddc776SDavid Howells  *
342d2ddc776SDavid Howells  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
343d2ddc776SDavid Howells  * servers and (b) a cell's name is used by the client to select the key to use
344d2ddc776SDavid Howells  * for authentication and encryption.  The cell name is not typically used in
345d2ddc776SDavid Howells  * the protocol.
346d2ddc776SDavid Howells  *
3478a070a96SDavid Howells  * Two cells are determined to be aliases if they have an explicit alias (YFS
3488a070a96SDavid Howells  * only), share any VL servers in common or have at least one volume in common.
3498a070a96SDavid Howells  * "In common" means that the address list of the VL servers or the fileservers
3508a070a96SDavid Howells  * share at least one endpoint.
35108e0e7c8SDavid Howells  */
35208e0e7c8SDavid Howells struct afs_cell {
353989782dcSDavid Howells 	union {
354989782dcSDavid Howells 		struct rcu_head	rcu;
355989782dcSDavid Howells 		struct rb_node	net_node;	/* Node in net->cells */
356989782dcSDavid Howells 	};
357989782dcSDavid Howells 	struct afs_net		*net;
3588a070a96SDavid Howells 	struct afs_cell		*alias_of;	/* The cell this is an alias of */
3598a070a96SDavid Howells 	struct afs_volume	*root_volume;	/* The root.cell volume if there is one */
36000d3b7a4SDavid Howells 	struct key		*anonymous_key;	/* anonymous user key for this cell */
361989782dcSDavid Howells 	struct work_struct	manager;	/* Manager for init/deinit/dns */
3626b3944e4SDavid Howells 	struct hlist_node	proc_link;	/* /proc cell list link */
3639b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
3649b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
3651da177e4SLinus Torvalds #endif
366989782dcSDavid Howells 	time64_t		dns_expiry;	/* Time AFSDB/SRV record expires */
367989782dcSDavid Howells 	time64_t		last_inactive;	/* Time of last drop of usage count */
36888c853c3SDavid Howells 	atomic_t		ref;		/* Struct refcount */
36988c853c3SDavid Howells 	atomic_t		active;		/* Active usage counter */
370989782dcSDavid Howells 	unsigned long		flags;
371d5c32c89SDavid Howells #define AFS_CELL_FL_NO_GC	0		/* The cell was added manually, don't auto-gc */
372d5c32c89SDavid Howells #define AFS_CELL_FL_DO_LOOKUP	1		/* DNS lookup requested */
3738a070a96SDavid Howells #define AFS_CELL_FL_CHECK_ALIAS	2		/* Need to check for aliases */
374989782dcSDavid Howells 	enum afs_cell_state	state;
375989782dcSDavid Howells 	short			error;
376d5c32c89SDavid Howells 	enum dns_record_source	dns_source:8;	/* Latest source of data from lookup */
377d5c32c89SDavid Howells 	enum dns_lookup_status	dns_status:8;	/* Latest status of data from lookup */
378d5c32c89SDavid Howells 	unsigned int		dns_lookup_count; /* Counter of DNS lookups */
379dca54a7bSDavid Howells 	unsigned int		debug_id;
380989782dcSDavid Howells 
38120325960SDavid Howells 	/* The volumes belonging to this cell */
38220325960SDavid Howells 	struct rb_root		volumes;	/* Tree of volumes on this server */
38320325960SDavid Howells 	struct hlist_head	proc_volumes;	/* procfs volume list */
38420325960SDavid Howells 	seqlock_t		volume_lock;	/* For volumes */
38520325960SDavid Howells 
386d2ddc776SDavid Howells 	/* Active fileserver interaction state. */
38720325960SDavid Howells 	struct rb_root		fs_servers;	/* afs_server (by server UUID) */
38820325960SDavid Howells 	seqlock_t		fs_lock;	/* For fs_servers  */
389989782dcSDavid Howells 
390d2ddc776SDavid Howells 	/* VL server list. */
3910a5143f2SDavid Howells 	rwlock_t		vl_servers_lock; /* Lock on vl_servers */
3920a5143f2SDavid Howells 	struct afs_vlserver_list __rcu *vl_servers;
3930a5143f2SDavid Howells 
394989782dcSDavid Howells 	u8			name_len;	/* Length of name */
395719fdd32SDavid Howells 	char			*name;		/* Cell name, case-flattened and NUL-padded */
39608e0e7c8SDavid Howells };
39708e0e7c8SDavid Howells 
39808e0e7c8SDavid Howells /*
3990a5143f2SDavid Howells  * Volume Location server record.
4000a5143f2SDavid Howells  */
4010a5143f2SDavid Howells struct afs_vlserver {
4020a5143f2SDavid Howells 	struct rcu_head		rcu;
4030a5143f2SDavid Howells 	struct afs_addr_list	__rcu *addresses; /* List of addresses for this VL server */
4040a5143f2SDavid Howells 	unsigned long		flags;
4050a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED	0		/* The VL server has been probed */
4060a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING	1		/* VL server is being probed */
4073bf0fb6fSDavid Howells #define AFS_VLSERVER_FL_IS_YFS	2		/* Server is YFS not AFS */
408b95b3094SDavid Howells #define AFS_VLSERVER_FL_RESPONDING 3		/* VL server is responding */
4090a5143f2SDavid Howells 	rwlock_t		lock;		/* Lock on addresses */
4100a5143f2SDavid Howells 	atomic_t		usage;
411b95b3094SDavid Howells 	unsigned int		rtt;		/* Server's current RTT in uS */
4123bf0fb6fSDavid Howells 
4133bf0fb6fSDavid Howells 	/* Probe state */
4143bf0fb6fSDavid Howells 	wait_queue_head_t	probe_wq;
4153bf0fb6fSDavid Howells 	atomic_t		probe_outstanding;
4163bf0fb6fSDavid Howells 	spinlock_t		probe_lock;
4173bf0fb6fSDavid Howells 	struct {
418b95b3094SDavid Howells 		unsigned int	rtt;		/* RTT in uS */
4193bf0fb6fSDavid Howells 		u32		abort_code;
4203bf0fb6fSDavid Howells 		short		error;
421fb72cd3dSDavid Howells 		unsigned short	flags;
422fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_RESPONDED		0x01 /* At least once response (may be abort) */
423fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_IS_YFS		0x02 /* The peer appears to be YFS */
424fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_NOT_YFS		0x04 /* The peer appears not to be YFS */
425fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_LOCAL_FAILURE	0x08 /* A local failure prevented a probe */
4263bf0fb6fSDavid Howells 	} probe;
4273bf0fb6fSDavid Howells 
4280a5143f2SDavid Howells 	u16			port;
4293bf0fb6fSDavid Howells 	u16			name_len;	/* Length of name */
4300a5143f2SDavid Howells 	char			name[];		/* Server name, case-flattened */
4310a5143f2SDavid Howells };
4320a5143f2SDavid Howells 
4330a5143f2SDavid Howells /*
4340a5143f2SDavid Howells  * Weighted list of Volume Location servers.
4350a5143f2SDavid Howells  */
4360a5143f2SDavid Howells struct afs_vlserver_entry {
4370a5143f2SDavid Howells 	u16			priority;	/* Preference (as SRV) */
4380a5143f2SDavid Howells 	u16			weight;		/* Weight (as SRV) */
4390a5143f2SDavid Howells 	enum dns_record_source	source:8;
4400a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4410a5143f2SDavid Howells 	struct afs_vlserver	*server;
4420a5143f2SDavid Howells };
4430a5143f2SDavid Howells 
4440a5143f2SDavid Howells struct afs_vlserver_list {
4450a5143f2SDavid Howells 	struct rcu_head		rcu;
4460a5143f2SDavid Howells 	atomic_t		usage;
4470a5143f2SDavid Howells 	u8			nr_servers;
4480a5143f2SDavid Howells 	u8			index;		/* Server currently in use */
4493bf0fb6fSDavid Howells 	u8			preferred;	/* Preferred server */
4500a5143f2SDavid Howells 	enum dns_record_source	source:8;
4510a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4520a5143f2SDavid Howells 	rwlock_t		lock;
4530a5143f2SDavid Howells 	struct afs_vlserver_entry servers[];
4540a5143f2SDavid Howells };
4550a5143f2SDavid Howells 
4560a5143f2SDavid Howells /*
457d2ddc776SDavid Howells  * Cached VLDB entry.
458d2ddc776SDavid Howells  *
459d2ddc776SDavid Howells  * This is pointed to by cell->vldb_entries, indexed by name.
46008e0e7c8SDavid Howells  */
461d2ddc776SDavid Howells struct afs_vldb_entry {
462d2ddc776SDavid Howells 	afs_volid_t		vid[3];		/* Volume IDs for R/W, R/O and Bak volumes */
46300d3b7a4SDavid Howells 
464d2ddc776SDavid Howells 	unsigned long		flags;
465d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW		0		/* - R/W volume exists */
466d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO		1		/* - R/O volume exists */
467d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK	2		/* - Backup volume exists */
468d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID	3		/* - Record is valid */
469d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR	4		/* - VL server returned error */
470d2ddc776SDavid Howells 
471d2ddc776SDavid Howells 	uuid_t			fs_server[AFS_NMAXNSERVERS];
47281006805SDavid Howells 	u32			addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
473d2ddc776SDavid Howells 	u8			fs_mask[AFS_NMAXNSERVERS];
47408e0e7c8SDavid Howells #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
47508e0e7c8SDavid Howells #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
47608e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
477d2ddc776SDavid Howells 	short			error;
478d2ddc776SDavid Howells 	u8			nr_servers;	/* Number of server records */
479d2ddc776SDavid Howells 	u8			name_len;
480d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
48108e0e7c8SDavid Howells };
48208e0e7c8SDavid Howells 
48308e0e7c8SDavid Howells /*
484d2ddc776SDavid Howells  * Record of fileserver with which we're actively communicating.
48508e0e7c8SDavid Howells  */
48608e0e7c8SDavid Howells struct afs_server {
487d2ddc776SDavid Howells 	struct rcu_head		rcu;
488d2ddc776SDavid Howells 	union {
489d2ddc776SDavid Howells 		uuid_t		uuid;		/* Server ID */
490d2ddc776SDavid Howells 		struct afs_uuid	_uuid;
491d2ddc776SDavid Howells 	};
492c435ee34SDavid Howells 
493d2ddc776SDavid Howells 	struct afs_addr_list	__rcu *addresses;
49420325960SDavid Howells 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
4953c4c4075SDavid Howells 	struct rb_node		uuid_rb;	/* Link in net->fs_servers */
4963c4c4075SDavid Howells 	struct afs_server __rcu	*uuid_next;	/* Next server with same UUID */
4973c4c4075SDavid Howells 	struct afs_server	*uuid_prev;	/* Previous server with same UUID */
498f6cbb368SDavid Howells 	struct list_head	probe_link;	/* Link in net->fs_probe_list */
499d2ddc776SDavid Howells 	struct hlist_node	addr4_link;	/* Link in net->fs_addresses4 */
500d2ddc776SDavid Howells 	struct hlist_node	addr6_link;	/* Link in net->fs_addresses6 */
501d2ddc776SDavid Howells 	struct hlist_node	proc_link;	/* Link in net->fs_proc */
502d2ddc776SDavid Howells 	struct afs_server	*gc_next;	/* Next server in manager's list */
503977e5f8eSDavid Howells 	time64_t		unuse_time;	/* Time at which last unused */
504c435ee34SDavid Howells 	unsigned long		flags;
505f3c130e6SDavid Howells #define AFS_SERVER_FL_RESPONDING 0		/* The server is responding */
50632275d3fSDavid Howells #define AFS_SERVER_FL_UPDATING	1
50732275d3fSDavid Howells #define AFS_SERVER_FL_NEEDS_UPDATE 2		/* Fileserver address list is out of date */
50832275d3fSDavid Howells #define AFS_SERVER_FL_NOT_READY	4		/* The record is not ready for use */
50932275d3fSDavid Howells #define AFS_SERVER_FL_NOT_FOUND	5		/* VL server says no such server */
51032275d3fSDavid Howells #define AFS_SERVER_FL_VL_FAIL	6		/* Failed to access VL server */
511f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8		/* May have callbacks on this fileserver */
51232275d3fSDavid Howells #define AFS_SERVER_FL_IS_YFS	16		/* Server is YFS not AFS */
51332275d3fSDavid Howells #define AFS_SERVER_FL_NO_IBULK	17		/* Fileserver doesn't support FS.InlineBulkStatus */
51432275d3fSDavid Howells #define AFS_SERVER_FL_NO_RM2	18		/* Fileserver doesn't support YFS.RemoveFile2 */
515977e5f8eSDavid Howells 	atomic_t		ref;		/* Object refcount */
516977e5f8eSDavid Howells 	atomic_t		active;		/* Active user count */
517d2ddc776SDavid Howells 	u32			addr_version;	/* Address list version */
518f3c130e6SDavid Howells 	unsigned int		rtt;		/* Server's current RTT in uS */
51945218193SDavid Howells 	unsigned int		debug_id;	/* Debugging ID for traces */
52008e0e7c8SDavid Howells 
52108e0e7c8SDavid Howells 	/* file service access */
522d2ddc776SDavid Howells 	rwlock_t		fs_lock;	/* access lock */
52308e0e7c8SDavid Howells 
52408e0e7c8SDavid Howells 	/* callback promise management */
525c435ee34SDavid Howells 	unsigned		cb_s_break;	/* Break-everything counter. */
5263bf0fb6fSDavid Howells 
5273bf0fb6fSDavid Howells 	/* Probe state */
528f6cbb368SDavid Howells 	unsigned long		probed_at;	/* Time last probe was dispatched (jiffies) */
5293bf0fb6fSDavid Howells 	wait_queue_head_t	probe_wq;
5303bf0fb6fSDavid Howells 	atomic_t		probe_outstanding;
5313bf0fb6fSDavid Howells 	spinlock_t		probe_lock;
5323bf0fb6fSDavid Howells 	struct {
533f3c130e6SDavid Howells 		unsigned int	rtt;		/* RTT in uS */
5343bf0fb6fSDavid Howells 		u32		abort_code;
5353bf0fb6fSDavid Howells 		short		error;
5363bf0fb6fSDavid Howells 		bool		responded:1;
5373bf0fb6fSDavid Howells 		bool		is_yfs:1;
5383bf0fb6fSDavid Howells 		bool		not_yfs:1;
5393bf0fb6fSDavid Howells 		bool		local_failure:1;
5403bf0fb6fSDavid Howells 	} probe;
541c435ee34SDavid Howells };
542c435ee34SDavid Howells 
543c435ee34SDavid Howells /*
544194d28cfSDavid Howells  * Replaceable volume server list.
54508e0e7c8SDavid Howells  */
546d2ddc776SDavid Howells struct afs_server_entry {
547d2ddc776SDavid Howells 	struct afs_server	*server;
548d2ddc776SDavid Howells };
549d2ddc776SDavid Howells 
550d2ddc776SDavid Howells struct afs_server_list {
551194d28cfSDavid Howells 	afs_volid_t		vids[AFS_MAXTYPES]; /* Volume IDs */
552d2ddc776SDavid Howells 	refcount_t		usage;
5533bf0fb6fSDavid Howells 	unsigned char		nr_servers;
5543bf0fb6fSDavid Howells 	unsigned char		preferred;	/* Preferred server */
555d2ddc776SDavid Howells 	unsigned short		vnovol_mask;	/* Servers to be skipped due to VNOVOL */
556d2ddc776SDavid Howells 	unsigned int		seq;		/* Set to ->servers_seq when installed */
557d4a96becSDavid Howells 	rwlock_t		lock;
558d2ddc776SDavid Howells 	struct afs_server_entry	servers[];
55908e0e7c8SDavid Howells };
56008e0e7c8SDavid Howells 
56108e0e7c8SDavid Howells /*
562d2ddc776SDavid Howells  * Live AFS volume management.
56308e0e7c8SDavid Howells  */
564d2ddc776SDavid Howells struct afs_volume {
56520325960SDavid Howells 	union {
56620325960SDavid Howells 		struct rcu_head	rcu;
567d2ddc776SDavid Howells 		afs_volid_t	vid;		/* volume ID */
56820325960SDavid Howells 	};
569d2ddc776SDavid Howells 	atomic_t		usage;
570d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update */
571d2ddc776SDavid Howells 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
57220325960SDavid Howells 	struct rb_node		cell_node;	/* Link in cell->volumes */
57320325960SDavid Howells 	struct hlist_node	proc_link;	/* Link in cell->proc_volumes */
57420325960SDavid Howells 	struct super_block __rcu *sb;		/* Superblock on which inodes reside */
575d2ddc776SDavid Howells 	unsigned long		flags;
576d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE	0	/* - T if an update needs performing */
577d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING	1	/* - T if an update is in progress */
578d2ddc776SDavid Howells #define AFS_VOLUME_WAIT		2	/* - T if users must wait for update */
579d2ddc776SDavid Howells #define AFS_VOLUME_DELETED	3	/* - T if volume appears deleted */
580d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE	4	/* - T if volume offline notice given */
581d2ddc776SDavid Howells #define AFS_VOLUME_BUSY		5	/* - T if volume busy notice given */
58220325960SDavid Howells #define AFS_VOLUME_MAYBE_NO_IBULK 6	/* - T if some servers don't have InlineBulkStatus */
583d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
584d2ddc776SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
585d2ddc776SDavid Howells #endif
5868a070a96SDavid Howells 	struct afs_server_list __rcu *servers;	/* List of servers on which volume resides */
587d2ddc776SDavid Howells 	rwlock_t		servers_lock;	/* Lock for ->servers */
588d2ddc776SDavid Howells 	unsigned int		servers_seq;	/* Incremented each time ->servers changes */
589d2ddc776SDavid Howells 
59068251f0aSDavid Howells 	unsigned		cb_v_break;	/* Break-everything counter. */
59190fa9b64SDavid Howells 	rwlock_t		cb_v_break_lock;
59268251f0aSDavid Howells 
593d2ddc776SDavid Howells 	afs_voltype_t		type;		/* type of volume */
594d2ddc776SDavid Howells 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
595d2ddc776SDavid Howells 	u8			name_len;
596d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
59708e0e7c8SDavid Howells };
59808e0e7c8SDavid Howells 
5990fafdc9fSDavid Howells enum afs_lock_state {
6000fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NONE,		/* The vnode has no lock on the server */
6010fafdc9fSDavid Howells 	AFS_VNODE_LOCK_WAITING_FOR_CB,	/* We're waiting for the server to break the callback */
6020fafdc9fSDavid Howells 	AFS_VNODE_LOCK_SETTING,		/* We're asking the server for a lock */
6030fafdc9fSDavid Howells 	AFS_VNODE_LOCK_GRANTED,		/* We have a lock on the server */
6040fafdc9fSDavid Howells 	AFS_VNODE_LOCK_EXTENDING,	/* We're extending a lock on the server */
6050fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NEED_UNLOCK,	/* We need to unlock on the server */
6060fafdc9fSDavid Howells 	AFS_VNODE_LOCK_UNLOCKING,	/* We're telling the server to unlock */
607cdfb26b4SDavid Howells 	AFS_VNODE_LOCK_DELETED,		/* The vnode has been deleted whilst we have a lock */
6080fafdc9fSDavid Howells };
6090fafdc9fSDavid Howells 
61008e0e7c8SDavid Howells /*
611f8de483eSDavid Howells  * AFS inode private data.
612f8de483eSDavid Howells  *
613f8de483eSDavid Howells  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
614f8de483eSDavid Howells  * leak from one inode to another.
61508e0e7c8SDavid Howells  */
61608e0e7c8SDavid Howells struct afs_vnode {
61708e0e7c8SDavid Howells 	struct inode		vfs_inode;	/* the VFS's inode record */
61808e0e7c8SDavid Howells 
61908e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume on which vnode resides */
62008e0e7c8SDavid Howells 	struct afs_fid		fid;		/* the file identifier for this inode */
62108e0e7c8SDavid Howells 	struct afs_file_status	status;		/* AFS status info for this file */
622a4ff7401SDavid Howells 	afs_dataversion_t	invalid_before;	/* Child dentries are invalid before this */
6239b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
6249b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
62508e0e7c8SDavid Howells #endif
626fe342cf7SDavid Howells 	struct afs_permits __rcu *permit_cache;	/* cache of permits so far obtained */
627d2ddc776SDavid Howells 	struct mutex		io_lock;	/* Lock for serialising I/O on this mutex */
628b61f7dcfSDavid Howells 	struct rw_semaphore	validate_lock;	/* lock for validating this vnode */
62979ddbfa5SDavid Howells 	struct rw_semaphore	rmdir_lock;	/* Lock for rmdir vs sillyrename */
63079ddbfa5SDavid Howells 	struct key		*silly_key;	/* Silly rename key */
6314343d008SDavid Howells 	spinlock_t		wb_lock;	/* lock for wb_keys */
63208e0e7c8SDavid Howells 	spinlock_t		lock;		/* waitqueue/flags lock */
63308e0e7c8SDavid Howells 	unsigned long		flags;
634c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED	0		/* Set if vnode has a callback promise */
635260a9803SDavid Howells #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
636f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID	2		/* Set if dir contents are valid */
63708e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
63808e0e7c8SDavid Howells #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
63908e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
6400fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL	6		/* set if Vnode is an auto mount point */
6410fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR	7 		/* set if Vnode is a pseudo directory */
6425a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT	8		/* Set if file has new content (create/trunc-0) */
643b6489a49SDavid Howells #define AFS_VNODE_SILLY_DELETED	9		/* Set if file has been silly-deleted */
64408e0e7c8SDavid Howells 
6454343d008SDavid Howells 	struct list_head	wb_keys;	/* List of keys available for writeback */
646e8d6c554SDavid Howells 	struct list_head	pending_locks;	/* locks waiting to be granted */
647e8d6c554SDavid Howells 	struct list_head	granted_locks;	/* locks granted on this file */
648e8d6c554SDavid Howells 	struct delayed_work	lock_work;	/* work to be done in locking */
6490fafdc9fSDavid Howells 	struct key		*lock_key;	/* Key to be used in lock ops */
650a690f60aSDavid Howells 	ktime_t			locked_at;	/* Time at which lock obtained */
6510fafdc9fSDavid Howells 	enum afs_lock_state	lock_state : 8;
6520fafdc9fSDavid Howells 	afs_lock_type_t		lock_type : 8;
65331143d5dSDavid Howells 
65408e0e7c8SDavid Howells 	/* outstanding callback notification on this file */
65520325960SDavid Howells 	void			*cb_server;	/* Server with callback/filelock */
656c435ee34SDavid Howells 	unsigned int		cb_s_break;	/* Mass break counter on ->server */
65768251f0aSDavid Howells 	unsigned int		cb_v_break;	/* Mass break counter on ->volume */
658c435ee34SDavid Howells 	unsigned int		cb_break;	/* Break counter on vnode */
65920325960SDavid Howells 	seqlock_t		cb_lock;	/* Lock for ->cb_server, ->status, ->cb_*break */
660c435ee34SDavid Howells 
661c435ee34SDavid Howells 	time64_t		cb_expires_at;	/* time at which callback expires */
66208e0e7c8SDavid Howells };
66308e0e7c8SDavid Howells 
66412bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
66512bdcf33SDavid Howells {
66612bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE
66712bdcf33SDavid Howells 	return vnode->cache;
66812bdcf33SDavid Howells #else
66912bdcf33SDavid Howells 	return NULL;
67012bdcf33SDavid Howells #endif
67112bdcf33SDavid Howells }
67212bdcf33SDavid Howells 
67300d3b7a4SDavid Howells /*
67400d3b7a4SDavid Howells  * cached security record for one user's attempt to access a vnode
67500d3b7a4SDavid Howells  */
67600d3b7a4SDavid Howells struct afs_permit {
67700d3b7a4SDavid Howells 	struct key		*key;		/* RxRPC ticket holding a security context */
678be080a6fSDavid Howells 	afs_access_t		access;		/* CallerAccess value for this key */
67900d3b7a4SDavid Howells };
68000d3b7a4SDavid Howells 
68100d3b7a4SDavid Howells /*
682be080a6fSDavid Howells  * Immutable cache of CallerAccess records from attempts to access vnodes.
683be080a6fSDavid Howells  * These may be shared between multiple vnodes.
68400d3b7a4SDavid Howells  */
68500d3b7a4SDavid Howells struct afs_permits {
686be080a6fSDavid Howells 	struct rcu_head		rcu;
687be080a6fSDavid Howells 	struct hlist_node	hash_node;	/* Link in hash */
688be080a6fSDavid Howells 	unsigned long		h;		/* Hash value for this permit list */
689be080a6fSDavid Howells 	refcount_t		usage;
690be080a6fSDavid Howells 	unsigned short		nr_permits;	/* Number of records */
691be080a6fSDavid Howells 	bool			invalidated;	/* Invalidated due to key change */
692be080a6fSDavid Howells 	struct afs_permit	permits[];	/* List of permits sorted by key pointer */
69300d3b7a4SDavid Howells };
69400d3b7a4SDavid Howells 
695b908fe6bSDavid Howells /*
6964584ae96SDavid Howells  * Error prioritisation and accumulation.
6974584ae96SDavid Howells  */
6984584ae96SDavid Howells struct afs_error {
6994584ae96SDavid Howells 	short	error;			/* Accumulated error */
7004584ae96SDavid Howells 	bool	responded;		/* T if server responded */
7014584ae96SDavid Howells };
7024584ae96SDavid Howells 
7034584ae96SDavid Howells /*
7048b2a464cSDavid Howells  * Cursor for iterating over a server's address list.
7058b2a464cSDavid Howells  */
7068b2a464cSDavid Howells struct afs_addr_cursor {
7078b2a464cSDavid Howells 	struct afs_addr_list	*alist;		/* Current address list (pins ref) */
7083bf0fb6fSDavid Howells 	unsigned long		tried;		/* Tried addresses */
7093bf0fb6fSDavid Howells 	signed char		index;		/* Current address */
7108b2a464cSDavid Howells 	bool			responded;	/* T if the current address responded */
711744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of address iterations */
7123bf0fb6fSDavid Howells 	short			error;
7133bf0fb6fSDavid Howells 	u32			abort_code;
7148b2a464cSDavid Howells };
7158b2a464cSDavid Howells 
7168b2a464cSDavid Howells /*
7170a5143f2SDavid Howells  * Cursor for iterating over a set of volume location servers.
7180a5143f2SDavid Howells  */
7190a5143f2SDavid Howells struct afs_vl_cursor {
7200a5143f2SDavid Howells 	struct afs_addr_cursor	ac;
7210a5143f2SDavid Howells 	struct afs_cell		*cell;		/* The cell we're querying */
7220a5143f2SDavid Howells 	struct afs_vlserver_list *server_list;	/* Current server list (pins ref) */
7233bf0fb6fSDavid Howells 	struct afs_vlserver	*server;	/* Server on which this resides */
7240a5143f2SDavid Howells 	struct key		*key;		/* Key for the server */
7253bf0fb6fSDavid Howells 	unsigned long		untried;	/* Bitmask of untried servers */
7263bf0fb6fSDavid Howells 	short			index;		/* Current server */
7270a5143f2SDavid Howells 	short			error;
7280a5143f2SDavid Howells 	unsigned short		flags;
7290a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP	0x0001		/* Set to cease iteration */
7300a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY	0x0002		/* Set to do a retry */
7310a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED	0x0004		/* Set if started a retry */
732744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
7330a5143f2SDavid Howells };
7340a5143f2SDavid Howells 
7350a5143f2SDavid Howells /*
736e49c7b2fSDavid Howells  * Fileserver operation methods.
737e49c7b2fSDavid Howells  */
738e49c7b2fSDavid Howells struct afs_operation_ops {
739e49c7b2fSDavid Howells 	void (*issue_afs_rpc)(struct afs_operation *op);
740e49c7b2fSDavid Howells 	void (*issue_yfs_rpc)(struct afs_operation *op);
741e49c7b2fSDavid Howells 	void (*success)(struct afs_operation *op);
742e49c7b2fSDavid Howells 	void (*aborted)(struct afs_operation *op);
743e49c7b2fSDavid Howells 	void (*edit_dir)(struct afs_operation *op);
744e49c7b2fSDavid Howells 	void (*put)(struct afs_operation *op);
745e49c7b2fSDavid Howells };
746e49c7b2fSDavid Howells 
747e49c7b2fSDavid Howells struct afs_vnode_param {
748e49c7b2fSDavid Howells 	struct afs_vnode	*vnode;
749e49c7b2fSDavid Howells 	struct afs_fid		fid;		/* Fid to access */
750e49c7b2fSDavid Howells 	struct afs_status_cb	scb;		/* Returned status and callback promise */
751e49c7b2fSDavid Howells 	afs_dataversion_t	dv_before;	/* Data version before the call */
752e49c7b2fSDavid Howells 	unsigned int		cb_break_before; /* cb_break + cb_s_break before the call */
753e49c7b2fSDavid Howells 	u8			dv_delta;	/* Expected change in data version */
754793fe82eSDavid Howells 	bool			put_vnode:1;	/* T if we have a ref on the vnode */
755793fe82eSDavid Howells 	bool			need_io_lock:1;	/* T if we need the I/O lock on this */
756793fe82eSDavid Howells 	bool			update_ctime:1;	/* Need to update the ctime */
757793fe82eSDavid Howells 	bool			set_size:1;	/* Must update i_size */
758b6489a49SDavid Howells 	bool			op_unlinked:1;	/* True if file was unlinked by op */
759a9e5c87cSDavid Howells 	bool			speculative:1;	/* T if speculative status fetch (no vnode lock) */
760e49c7b2fSDavid Howells };
761e49c7b2fSDavid Howells 
762e49c7b2fSDavid Howells /*
763e49c7b2fSDavid Howells  * Fileserver operation wrapper, handling server and address rotation
764e49c7b2fSDavid Howells  * asynchronously.  May make simultaneous calls to multiple servers.
7658b2a464cSDavid Howells  */
766a310082fSDavid Howells struct afs_operation {
767e49c7b2fSDavid Howells 	struct afs_net		*net;		/* Network namespace */
768e49c7b2fSDavid Howells 	struct key		*key;		/* Key for the cell */
769a58823acSDavid Howells 	const struct afs_call_type *type;	/* Type of call done */
770e49c7b2fSDavid Howells 	const struct afs_operation_ops *ops;
771e49c7b2fSDavid Howells 
772e49c7b2fSDavid Howells 	/* Parameters/results for the operation */
773e49c7b2fSDavid Howells 	struct afs_volume	*volume;	/* Volume being accessed */
774e49c7b2fSDavid Howells 	struct afs_vnode_param	file[2];
775e49c7b2fSDavid Howells 	struct afs_vnode_param	*more_files;
776e49c7b2fSDavid Howells 	struct afs_volsync	volsync;
777e49c7b2fSDavid Howells 	struct dentry		*dentry;	/* Dentry to be altered */
778e49c7b2fSDavid Howells 	struct dentry		*dentry_2;	/* Second dentry to be altered */
779e49c7b2fSDavid Howells 	struct timespec64	mtime;		/* Modification time to record */
780da8d0755SDavid Howells 	struct timespec64	ctime;		/* Change time to set */
781e49c7b2fSDavid Howells 	short			nr_files;	/* Number of entries in file[], more_files */
782e49c7b2fSDavid Howells 	short			error;
783e49c7b2fSDavid Howells 	unsigned int		debug_id;
784e49c7b2fSDavid Howells 
785e49c7b2fSDavid Howells 	unsigned int		cb_v_break;	/* Volume break counter before op */
786e49c7b2fSDavid Howells 	unsigned int		cb_s_break;	/* Server break counter before op */
787e49c7b2fSDavid Howells 
788e49c7b2fSDavid Howells 	union {
789e49c7b2fSDavid Howells 		struct {
790e49c7b2fSDavid Howells 			int	which;		/* Which ->file[] to fetch for */
791e49c7b2fSDavid Howells 		} fetch_status;
792e49c7b2fSDavid Howells 		struct {
793e49c7b2fSDavid Howells 			int	reason;		/* enum afs_edit_dir_reason */
794e49c7b2fSDavid Howells 			mode_t	mode;
795e49c7b2fSDavid Howells 			const char *symlink;
796e49c7b2fSDavid Howells 		} create;
797e49c7b2fSDavid Howells 		struct {
798e49c7b2fSDavid Howells 			bool	need_rehash;
799e49c7b2fSDavid Howells 		} unlink;
800e49c7b2fSDavid Howells 		struct {
801e49c7b2fSDavid Howells 			struct dentry *rehash;
802e49c7b2fSDavid Howells 			struct dentry *tmp;
803e49c7b2fSDavid Howells 			bool	new_negative;
804e49c7b2fSDavid Howells 		} rename;
805e49c7b2fSDavid Howells 		struct {
806e49c7b2fSDavid Howells 			struct afs_read *req;
807e49c7b2fSDavid Howells 		} fetch;
808e49c7b2fSDavid Howells 		struct {
809e49c7b2fSDavid Howells 			afs_lock_type_t type;
810e49c7b2fSDavid Howells 		} lock;
811e49c7b2fSDavid Howells 		struct {
812e49c7b2fSDavid Howells 			struct address_space *mapping;	/* Pages being written from */
813e49c7b2fSDavid Howells 			pgoff_t		first;		/* first page in mapping to deal with */
814e49c7b2fSDavid Howells 			pgoff_t		last;		/* last page in mapping to deal with */
815e49c7b2fSDavid Howells 			unsigned	first_offset;	/* offset into mapping[first] */
816e49c7b2fSDavid Howells 			unsigned	last_to;	/* amount of mapping[last] */
817d383e346SDavid Howells 			bool		laundering;	/* Laundering page, PG_writeback not set */
818e49c7b2fSDavid Howells 		} store;
819e49c7b2fSDavid Howells 		struct {
820e49c7b2fSDavid Howells 			struct iattr	*attr;
821ec0fa0b6SDavid Howells 			loff_t		old_i_size;
822e49c7b2fSDavid Howells 		} setattr;
823e49c7b2fSDavid Howells 		struct afs_acl	*acl;
824e49c7b2fSDavid Howells 		struct yfs_acl	*yacl;
825e49c7b2fSDavid Howells 		struct {
826e49c7b2fSDavid Howells 			struct afs_volume_status vs;
827e49c7b2fSDavid Howells 			struct kstatfs		*buf;
828e49c7b2fSDavid Howells 		} volstatus;
829e49c7b2fSDavid Howells 	};
830e49c7b2fSDavid Howells 
831e49c7b2fSDavid Howells 	/* Fileserver iteration state */
8328b2a464cSDavid Howells 	struct afs_addr_cursor	ac;
833d2ddc776SDavid Howells 	struct afs_server_list	*server_list;	/* Current server list (pins ref) */
83420325960SDavid Howells 	struct afs_server	*server;	/* Server we're using (ref pinned by server_list) */
835e49c7b2fSDavid Howells 	struct afs_call		*call;
8363bf0fb6fSDavid Howells 	unsigned long		untried;	/* Bitmask of untried servers */
8373bf0fb6fSDavid Howells 	short			index;		/* Current server */
838e49c7b2fSDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
839e49c7b2fSDavid Howells 
840e49c7b2fSDavid Howells 	unsigned int		flags;
841a310082fSDavid Howells #define AFS_OPERATION_STOP		0x0001	/* Set to cease iteration */
842a310082fSDavid Howells #define AFS_OPERATION_VBUSY		0x0002	/* Set if seen VBUSY */
843a310082fSDavid Howells #define AFS_OPERATION_VMOVED		0x0004	/* Set if seen VMOVED */
844a310082fSDavid Howells #define AFS_OPERATION_VNOVOL		0x0008	/* Set if seen VNOVOL */
845a310082fSDavid Howells #define AFS_OPERATION_CUR_ONLY		0x0010	/* Set if current server only (file lock held) */
846a310082fSDavid Howells #define AFS_OPERATION_NO_VSLEEP		0x0020	/* Set to prevent sleep on VBUSY, VOFFLINE, ... */
847e49c7b2fSDavid Howells #define AFS_OPERATION_UNINTR		0x0040	/* Set if op is uninterruptible */
848e49c7b2fSDavid Howells #define AFS_OPERATION_DOWNGRADE		0x0080	/* Set to retry with downgraded opcode */
849e49c7b2fSDavid Howells #define AFS_OPERATION_LOCK_0		0x0100	/* Set if have io_lock on file[0] */
850e49c7b2fSDavid Howells #define AFS_OPERATION_LOCK_1		0x0200	/* Set if have io_lock on file[1] */
8518409f67bSDavid Howells #define AFS_OPERATION_TRIED_ALL		0x0400	/* Set if we've tried all the fileservers */
8528409f67bSDavid Howells #define AFS_OPERATION_RETRY_SERVER	0x0800	/* Set if we should retry the current server */
853b6489a49SDavid Howells #define AFS_OPERATION_DIR_CONFLICT	0x1000	/* Set if we detected a 3rd-party dir change */
8548b2a464cSDavid Howells };
8558b2a464cSDavid Howells 
856402cb8ddSDavid Howells /*
857402cb8ddSDavid Howells  * Cache auxiliary data.
858402cb8ddSDavid Howells  */
859402cb8ddSDavid Howells struct afs_vnode_cache_aux {
860402cb8ddSDavid Howells 	u64			data_version;
861402cb8ddSDavid Howells } __packed;
862402cb8ddSDavid Howells 
863185f0c70SDavid Howells /*
864185f0c70SDavid Howells  * We use page->private to hold the amount of the page that we've written to,
865185f0c70SDavid Howells  * splitting the field into two parts.  However, we need to represent a range
8662d9900f2SDavid Howells  * 0...PAGE_SIZE, so we reduce the resolution if the size of the page
8672d9900f2SDavid Howells  * exceeds what we can encode.
868185f0c70SDavid Howells  */
86965dd2d60SDavid Howells #ifdef CONFIG_64BIT
870f86726a6SDavid Howells #define __AFS_PAGE_PRIV_MASK	0x7fffffffUL
871185f0c70SDavid Howells #define __AFS_PAGE_PRIV_SHIFT	32
872f86726a6SDavid Howells #define __AFS_PAGE_PRIV_MMAPPED	0x80000000UL
873185f0c70SDavid Howells #else
874f86726a6SDavid Howells #define __AFS_PAGE_PRIV_MASK	0x7fffUL
875185f0c70SDavid Howells #define __AFS_PAGE_PRIV_SHIFT	16
876f86726a6SDavid Howells #define __AFS_PAGE_PRIV_MMAPPED	0x8000UL
877185f0c70SDavid Howells #endif
878185f0c70SDavid Howells 
87967d78a6fSDavid Howells static inline unsigned int afs_page_dirty_resolution(struct page *page)
8802d9900f2SDavid Howells {
88167d78a6fSDavid Howells 	int shift = thp_order(page) + PAGE_SHIFT - (__AFS_PAGE_PRIV_SHIFT - 1);
8822d9900f2SDavid Howells 	return (shift > 0) ? shift : 0;
8832d9900f2SDavid Howells }
8842d9900f2SDavid Howells 
88567d78a6fSDavid Howells static inline size_t afs_page_dirty_from(struct page *page, unsigned long priv)
886185f0c70SDavid Howells {
8872d9900f2SDavid Howells 	unsigned long x = priv & __AFS_PAGE_PRIV_MASK;
8882d9900f2SDavid Howells 
8892d9900f2SDavid Howells 	/* The lower bound is inclusive */
89067d78a6fSDavid Howells 	return x << afs_page_dirty_resolution(page);
891185f0c70SDavid Howells }
892185f0c70SDavid Howells 
89367d78a6fSDavid Howells static inline size_t afs_page_dirty_to(struct page *page, unsigned long priv)
894185f0c70SDavid Howells {
8952d9900f2SDavid Howells 	unsigned long x = (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK;
8962d9900f2SDavid Howells 
8972d9900f2SDavid Howells 	/* The upper bound is immediately beyond the region */
89867d78a6fSDavid Howells 	return (x + 1) << afs_page_dirty_resolution(page);
899185f0c70SDavid Howells }
900185f0c70SDavid Howells 
90167d78a6fSDavid Howells static inline unsigned long afs_page_dirty(struct page *page, size_t from, size_t to)
902185f0c70SDavid Howells {
90367d78a6fSDavid Howells 	unsigned int res = afs_page_dirty_resolution(page);
9042d9900f2SDavid Howells 	from >>= res;
9052d9900f2SDavid Howells 	to = (to - 1) >> res;
9062d9900f2SDavid Howells 	return (to << __AFS_PAGE_PRIV_SHIFT) | from;
907185f0c70SDavid Howells }
908185f0c70SDavid Howells 
909f86726a6SDavid Howells static inline unsigned long afs_page_dirty_mmapped(unsigned long priv)
910f86726a6SDavid Howells {
911f86726a6SDavid Howells 	return priv | __AFS_PAGE_PRIV_MMAPPED;
912f86726a6SDavid Howells }
913f86726a6SDavid Howells 
914f86726a6SDavid Howells static inline bool afs_is_page_dirty_mmapped(unsigned long priv)
915f86726a6SDavid Howells {
916f86726a6SDavid Howells 	return priv & __AFS_PAGE_PRIV_MMAPPED;
917f86726a6SDavid Howells }
918f86726a6SDavid Howells 
91998bf40cdSDavid Howells #include <trace/events/afs.h>
92098bf40cdSDavid Howells 
92108e0e7c8SDavid Howells /*****************************************************************************/
92208e0e7c8SDavid Howells /*
9238b2a464cSDavid Howells  * addr_list.c
9248b2a464cSDavid Howells  */
9258b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
9268b2a464cSDavid Howells {
9278b2a464cSDavid Howells 	if (alist)
9288b2a464cSDavid Howells 		refcount_inc(&alist->usage);
9298b2a464cSDavid Howells 	return alist;
9308b2a464cSDavid Howells }
9318b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
9328b2a464cSDavid Howells 						unsigned short,
9338b2a464cSDavid Howells 						unsigned short);
9348b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *);
9350a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
9360a5143f2SDavid Howells 						      const char *, size_t, char,
9378b2a464cSDavid Howells 						      unsigned short, unsigned short);
9380a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
9398b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *);
9408b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *);
9418b2a464cSDavid Howells 
942bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
943bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
944d2ddc776SDavid Howells 
9458b2a464cSDavid Howells /*
9469b3f26c9SDavid Howells  * cache.c
9479b3f26c9SDavid Howells  */
9489b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
9499b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs;
9509b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def;
9519b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def;
9529b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def;
9539b3f26c9SDavid Howells #else
9549b3f26c9SDavid Howells #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
9559b3f26c9SDavid Howells #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
9569b3f26c9SDavid Howells #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
9579b3f26c9SDavid Howells #endif
9589b3f26c9SDavid Howells 
9599b3f26c9SDavid Howells /*
96008e0e7c8SDavid Howells  * callback.c
96108e0e7c8SDavid Howells  */
96208e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
963051d2525SDavid Howells extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
964051d2525SDavid Howells extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
9655cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
966c435ee34SDavid Howells 
96768251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
96868251f0aSDavid Howells {
969eeba1e9cSDavid Howells 	return vnode->cb_break + vnode->cb_v_break;
97068251f0aSDavid Howells }
97168251f0aSDavid Howells 
97218ac6185SDavid Howells static inline bool afs_cb_is_broken(unsigned int cb_break,
97320325960SDavid Howells 				    const struct afs_vnode *vnode)
97468251f0aSDavid Howells {
97520325960SDavid Howells 	return cb_break != (vnode->cb_break + vnode->volume->cb_v_break);
97668251f0aSDavid Howells }
97768251f0aSDavid Howells 
9781da177e4SLinus Torvalds /*
9791da177e4SLinus Torvalds  * cell.c
9801da177e4SLinus Torvalds  */
981989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
982dca54a7bSDavid Howells extern struct afs_cell *afs_find_cell(struct afs_net *, const char *, unsigned,
983dca54a7bSDavid Howells 				      enum afs_cell_trace);
984989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
985989782dcSDavid Howells 					const char *, bool);
986dca54a7bSDavid Howells extern struct afs_cell *afs_use_cell(struct afs_cell *, enum afs_cell_trace);
987dca54a7bSDavid Howells extern void afs_unuse_cell(struct afs_net *, struct afs_cell *, enum afs_cell_trace);
988dca54a7bSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *, enum afs_cell_trace);
989dca54a7bSDavid Howells extern void afs_see_cell(struct afs_cell *, enum afs_cell_trace);
990dca54a7bSDavid Howells extern void afs_put_cell(struct afs_cell *, enum afs_cell_trace);
991dca54a7bSDavid Howells extern void afs_queue_cell(struct afs_cell *, enum afs_cell_trace);
992989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
993989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
994f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
99508e0e7c8SDavid Howells 
99608e0e7c8SDavid Howells /*
99708e0e7c8SDavid Howells  * cmservice.c
99808e0e7c8SDavid Howells  */
99908e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
100008e0e7c8SDavid Howells 
10011da177e4SLinus Torvalds /*
10021da177e4SLinus Torvalds  * dir.c
10031da177e4SLinus Torvalds  */
10044b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
10054d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
1006f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops;
10074d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
10084d673da1SDavid Howells 
100966c7e1d3SDavid Howells extern void afs_d_release(struct dentry *);
1010728279a5SDavid Howells extern void afs_check_for_remote_deletion(struct afs_operation *);
101166c7e1d3SDavid Howells 
101266c7e1d3SDavid Howells /*
101363a4681fSDavid Howells  * dir_edit.c
101463a4681fSDavid Howells  */
101563a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
101663a4681fSDavid Howells 			     enum afs_edit_dir_reason);
101763a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
101863a4681fSDavid Howells 
101963a4681fSDavid Howells /*
102079ddbfa5SDavid Howells  * dir_silly.c
102179ddbfa5SDavid Howells  */
102279ddbfa5SDavid Howells extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
102379ddbfa5SDavid Howells 			   struct dentry *, struct key *);
102479ddbfa5SDavid Howells extern int afs_silly_iput(struct dentry *, struct inode *);
102579ddbfa5SDavid Howells 
102679ddbfa5SDavid Howells /*
102766c7e1d3SDavid Howells  * dynroot.c
102866c7e1d3SDavid Howells  */
102966c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
103066c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations;
103166c7e1d3SDavid Howells 
103266c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
10330da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
10340da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
10350da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *);
10360da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *);
10371da177e4SLinus Torvalds 
10381da177e4SLinus Torvalds /*
10391da177e4SLinus Torvalds  * file.c
10401da177e4SLinus Torvalds  */
1041f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops;
1042754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
104300d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
104400d3b7a4SDavid Howells 
10454343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
10464343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
104700d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
104800d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
1049*c69bf479SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct afs_read *);
1050f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *);
1051196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
10521da177e4SLinus Torvalds 
1053d4438a25SDavid Howells static inline struct afs_read *afs_get_read(struct afs_read *req)
1054d4438a25SDavid Howells {
1055d4438a25SDavid Howells 	refcount_inc(&req->usage);
1056d4438a25SDavid Howells 	return req;
1057d4438a25SDavid Howells }
1058d4438a25SDavid Howells 
10591da177e4SLinus Torvalds /*
1060e8d6c554SDavid Howells  * flock.c
1061e8d6c554SDavid Howells  */
1062f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
1063f044c884SDavid Howells 
1064a690f60aSDavid Howells extern void afs_lock_op_done(struct afs_call *);
1065e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
1066e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
1067e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
1068e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
1069e8d6c554SDavid Howells 
1070e8d6c554SDavid Howells /*
107108e0e7c8SDavid Howells  * fsclient.c
107208e0e7c8SDavid Howells  */
1073e49c7b2fSDavid Howells extern void afs_fs_fetch_status(struct afs_operation *);
1074e49c7b2fSDavid Howells extern void afs_fs_fetch_data(struct afs_operation *);
1075e49c7b2fSDavid Howells extern void afs_fs_create_file(struct afs_operation *);
1076e49c7b2fSDavid Howells extern void afs_fs_make_dir(struct afs_operation *);
1077e49c7b2fSDavid Howells extern void afs_fs_remove_file(struct afs_operation *);
1078e49c7b2fSDavid Howells extern void afs_fs_remove_dir(struct afs_operation *);
1079e49c7b2fSDavid Howells extern void afs_fs_link(struct afs_operation *);
1080e49c7b2fSDavid Howells extern void afs_fs_symlink(struct afs_operation *);
1081e49c7b2fSDavid Howells extern void afs_fs_rename(struct afs_operation *);
1082e49c7b2fSDavid Howells extern void afs_fs_store_data(struct afs_operation *);
1083e49c7b2fSDavid Howells extern void afs_fs_setattr(struct afs_operation *);
1084e49c7b2fSDavid Howells extern void afs_fs_get_volume_status(struct afs_operation *);
1085e49c7b2fSDavid Howells extern void afs_fs_set_lock(struct afs_operation *);
1086e49c7b2fSDavid Howells extern void afs_fs_extend_lock(struct afs_operation *);
1087e49c7b2fSDavid Howells extern void afs_fs_release_lock(struct afs_operation *);
1088d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
1089d2ddc776SDavid Howells 					struct afs_addr_cursor *, struct key *);
1090f6cbb368SDavid Howells extern bool afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
1091f6cbb368SDavid Howells 				    struct afs_addr_cursor *, struct key *);
1092e49c7b2fSDavid Howells extern void afs_fs_inline_bulk_status(struct afs_operation *);
109308e0e7c8SDavid Howells 
1094260f082bSDavid Howells struct afs_acl {
1095260f082bSDavid Howells 	u32	size;
1096260f082bSDavid Howells 	u8	data[];
1097260f082bSDavid Howells };
1098260f082bSDavid Howells 
1099e49c7b2fSDavid Howells extern void afs_fs_fetch_acl(struct afs_operation *);
1100e49c7b2fSDavid Howells extern void afs_fs_store_acl(struct afs_operation *);
1101e49c7b2fSDavid Howells 
1102e49c7b2fSDavid Howells /*
1103e49c7b2fSDavid Howells  * fs_operation.c
1104e49c7b2fSDavid Howells  */
1105e49c7b2fSDavid Howells extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
1106e49c7b2fSDavid Howells extern int afs_put_operation(struct afs_operation *);
1107e49c7b2fSDavid Howells extern bool afs_begin_vnode_operation(struct afs_operation *);
1108e49c7b2fSDavid Howells extern void afs_wait_for_operation(struct afs_operation *);
1109e49c7b2fSDavid Howells extern int afs_do_sync_operation(struct afs_operation *);
1110e49c7b2fSDavid Howells 
1111e49c7b2fSDavid Howells static inline void afs_op_nomem(struct afs_operation *op)
1112e49c7b2fSDavid Howells {
1113e49c7b2fSDavid Howells 	op->error = -ENOMEM;
1114e49c7b2fSDavid Howells }
1115e49c7b2fSDavid Howells 
1116e49c7b2fSDavid Howells static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
1117e49c7b2fSDavid Howells 				    struct afs_vnode *vnode)
1118e49c7b2fSDavid Howells {
1119e49c7b2fSDavid Howells 	op->file[n].vnode = vnode;
1120e49c7b2fSDavid Howells 	op->file[n].need_io_lock = true;
1121e49c7b2fSDavid Howells }
1122e49c7b2fSDavid Howells 
1123e49c7b2fSDavid Howells static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
1124e49c7b2fSDavid Howells 				  const struct afs_fid *fid)
1125e49c7b2fSDavid Howells {
1126e49c7b2fSDavid Howells 	op->file[n].fid = *fid;
1127e49c7b2fSDavid Howells }
1128260f082bSDavid Howells 
112908e0e7c8SDavid Howells /*
11303bf0fb6fSDavid Howells  * fs_probe.c
11313bf0fb6fSDavid Howells  */
11323bf0fb6fSDavid Howells extern void afs_fileserver_probe_result(struct afs_call *);
1133f6cbb368SDavid Howells extern void afs_fs_probe_fileserver(struct afs_net *, struct afs_server *, struct key *, bool);
11343bf0fb6fSDavid Howells extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long);
11358409f67bSDavid Howells extern void afs_probe_fileserver(struct afs_net *, struct afs_server *);
1136f6cbb368SDavid Howells extern void afs_fs_probe_dispatcher(struct work_struct *);
11378409f67bSDavid Howells extern int afs_wait_for_one_fs_probe(struct afs_server *, bool);
11385481fc6eSDavid Howells extern void afs_fs_probe_cleanup(struct afs_net *);
11393bf0fb6fSDavid Howells 
11403bf0fb6fSDavid Howells /*
11411da177e4SLinus Torvalds  * inode.c
11421da177e4SLinus Torvalds  */
1143b6489a49SDavid Howells extern const struct afs_operation_ops afs_fetch_status_operation;
1144b6489a49SDavid Howells 
1145e49c7b2fSDavid Howells extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
1146a58823acSDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1147e49c7b2fSDavid Howells extern int afs_ilookup5_test_by_fid(struct inode *, void *);
11484d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
1149e49c7b2fSDavid Howells extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
1150e49c7b2fSDavid Howells extern struct inode *afs_root_iget(struct super_block *, struct key *);
1151c925bd0aSDavid Howells extern bool afs_check_validity(struct afs_vnode *);
1152260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
1153549c7297SChristian Brauner extern int afs_getattr(struct user_namespace *mnt_userns, const struct path *,
1154549c7297SChristian Brauner 		       struct kstat *, u32, unsigned int);
1155549c7297SChristian Brauner extern int afs_setattr(struct user_namespace *mnt_userns, struct dentry *, struct iattr *);
1156b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
1157bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
11581da177e4SLinus Torvalds 
11591da177e4SLinus Torvalds /*
11601da177e4SLinus Torvalds  * main.c
11611da177e4SLinus Torvalds  */
11620ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
11635b86d4ffSDavid Howells extern int afs_net_id;
11645b86d4ffSDavid Howells 
11655b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net)
11665b86d4ffSDavid Howells {
11675b86d4ffSDavid Howells 	return net_generic(net, afs_net_id);
11685b86d4ffSDavid Howells }
11695b86d4ffSDavid Howells 
11705b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb)
11715b86d4ffSDavid Howells {
11725b86d4ffSDavid Howells 	return afs_net(AFS_FS_S(sb)->net_ns);
11735b86d4ffSDavid Howells }
1174f044c884SDavid Howells 
1175f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
1176f044c884SDavid Howells {
11775b86d4ffSDavid Howells 	return afs_sb2net(dentry->d_sb);
1178f044c884SDavid Howells }
1179f044c884SDavid Howells 
1180f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
1181f044c884SDavid Howells {
11825b86d4ffSDavid Howells 	return afs_sb2net(inode->i_sb);
1183f044c884SDavid Howells }
1184f044c884SDavid Howells 
1185f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1186f044c884SDavid Howells {
11875b86d4ffSDavid Howells 	return afs_i2net(&vnode->vfs_inode);
1188f044c884SDavid Howells }
1189f044c884SDavid Howells 
1190f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
1191f044c884SDavid Howells {
11925b86d4ffSDavid Howells 	return net_generic(sock_net(sk), afs_net_id);
1193f044c884SDavid Howells }
11941da177e4SLinus Torvalds 
1195d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s)
1196d55b4da4SDavid Howells {
1197d55b4da4SDavid Howells 	atomic_inc(s);
1198d55b4da4SDavid Howells }
1199d55b4da4SDavid Howells 
1200d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1201d55b4da4SDavid Howells 
12021da177e4SLinus Torvalds /*
120308e0e7c8SDavid Howells  * misc.c
120408e0e7c8SDavid Howells  */
120508e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
12064584ae96SDavid Howells extern void afs_prioritise_error(struct afs_error *, int, u32);
120708e0e7c8SDavid Howells 
120808e0e7c8SDavid Howells /*
12091da177e4SLinus Torvalds  * mntpt.c
12101da177e4SLinus Torvalds  */
1211754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
1212bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
12134b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
12141da177e4SLinus Torvalds 
1215d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
121608e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
12171da177e4SLinus Torvalds 
12181da177e4SLinus Torvalds /*
12191da177e4SLinus Torvalds  * proc.c
12201da177e4SLinus Torvalds  */
1221b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS
1222f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
1223f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
12245b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *);
12255b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *);
12266f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *);
1227b6cfbecaSDavid Howells #else
1228b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; }
1229b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {}
1230b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
1231b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
1232b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1233b6cfbecaSDavid Howells #endif
12341da177e4SLinus Torvalds 
123508e0e7c8SDavid Howells /*
1236d2ddc776SDavid Howells  * rotate.c
1237d2ddc776SDavid Howells  */
1238a310082fSDavid Howells extern bool afs_select_fileserver(struct afs_operation *);
1239e49c7b2fSDavid Howells extern void afs_dump_edestaddrreq(const struct afs_operation *);
1240d2ddc776SDavid Howells 
1241d2ddc776SDavid Howells /*
124208e0e7c8SDavid Howells  * rxrpc.c
124308e0e7c8SDavid Howells  */
1244f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
12458324f0bcSDavid Howells 
1246f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
1247f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
1248f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
1249341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
12500b9bf381SDavid Howells extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t);
12510b9bf381SDavid Howells extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
1252f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1253f044c884SDavid Howells 					    const struct afs_call_type *,
125408e0e7c8SDavid Howells 					    size_t, size_t);
125508e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
125608e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
1257b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
125812bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool);
12597126ead9SDavid Howells extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
126008e0e7c8SDavid Howells 
1261e49c7b2fSDavid Howells static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
1262e49c7b2fSDavid Howells 				    gfp_t gfp)
126320b8391fSDavid Howells {
1264e49c7b2fSDavid Howells 	op->call = call;
1265a310082fSDavid Howells 	op->type = call->type;
1266e49c7b2fSDavid Howells 	call->op = op;
1267e49c7b2fSDavid Howells 	call->key = op->key;
1268e49c7b2fSDavid Howells 	call->intr = !(op->flags & AFS_OPERATION_UNINTR);
1269e49c7b2fSDavid Howells 	afs_make_call(&op->ac, call, gfp);
127020b8391fSDavid Howells }
127120b8391fSDavid Howells 
127212bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
127312bdcf33SDavid Howells {
127412bdcf33SDavid Howells 	call->kvec[0].iov_base = buf;
127512bdcf33SDavid Howells 	call->kvec[0].iov_len = size;
1276fc276122SDavid Howells 	iov_iter_kvec(&call->def_iter, READ, call->kvec, 1, size);
127712bdcf33SDavid Howells }
127812bdcf33SDavid Howells 
127912bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call)
128012bdcf33SDavid Howells {
128112bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
128212bdcf33SDavid Howells }
128312bdcf33SDavid Howells 
128412bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call)
128512bdcf33SDavid Howells {
128612bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
128712bdcf33SDavid Howells }
128812bdcf33SDavid Howells 
128912bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size)
129012bdcf33SDavid Howells {
1291fc276122SDavid Howells 	iov_iter_discard(&call->def_iter, READ, size);
129212bdcf33SDavid Howells }
129312bdcf33SDavid Howells 
129412bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
129512bdcf33SDavid Howells {
129612bdcf33SDavid Howells 	afs_extract_begin(call, call->buffer, size);
129712bdcf33SDavid Howells }
129812bdcf33SDavid Howells 
1299d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
1300372ee163SDavid Howells {
130112bdcf33SDavid Howells 	return afs_extract_data(call, false);
1302372ee163SDavid Howells }
1303372ee163SDavid Howells 
130498bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
130598bf40cdSDavid Howells 					enum afs_call_state state)
130698bf40cdSDavid Howells {
130798bf40cdSDavid Howells 	return READ_ONCE(call->state) == state;
130898bf40cdSDavid Howells }
130998bf40cdSDavid Howells 
131098bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
131198bf40cdSDavid Howells 				      enum afs_call_state from,
131298bf40cdSDavid Howells 				      enum afs_call_state to)
131398bf40cdSDavid Howells {
131498bf40cdSDavid Howells 	bool ok = false;
131598bf40cdSDavid Howells 
131698bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
131798bf40cdSDavid Howells 	if (call->state == from) {
131898bf40cdSDavid Howells 		call->state = to;
131998bf40cdSDavid Howells 		trace_afs_call_state(call, from, to, 0, 0);
132098bf40cdSDavid Howells 		ok = true;
132198bf40cdSDavid Howells 	}
132298bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
132398bf40cdSDavid Howells 	return ok;
132498bf40cdSDavid Howells }
132598bf40cdSDavid Howells 
132698bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
132798bf40cdSDavid Howells 					 int error, u32 remote_abort)
132898bf40cdSDavid Howells {
132998bf40cdSDavid Howells 	enum afs_call_state state;
133098bf40cdSDavid Howells 	bool ok = false;
133198bf40cdSDavid Howells 
133298bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
133398bf40cdSDavid Howells 	state = call->state;
133498bf40cdSDavid Howells 	if (state != AFS_CALL_COMPLETE) {
133598bf40cdSDavid Howells 		call->abort_code = remote_abort;
133698bf40cdSDavid Howells 		call->error = error;
133798bf40cdSDavid Howells 		call->state = AFS_CALL_COMPLETE;
133898bf40cdSDavid Howells 		trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
133998bf40cdSDavid Howells 				     error, remote_abort);
134098bf40cdSDavid Howells 		ok = true;
134198bf40cdSDavid Howells 	}
134298bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
1343dde9f095SDavid Howells 	if (ok) {
134498bf40cdSDavid Howells 		trace_afs_call_done(call);
1345dde9f095SDavid Howells 
1346dde9f095SDavid Howells 		/* Asynchronous calls have two refs to release - one from the alloc and
1347dde9f095SDavid Howells 		 * one queued with the work item - and we can't just deallocate the
1348dde9f095SDavid Howells 		 * call because the work item may be queued again.
1349dde9f095SDavid Howells 		 */
1350dde9f095SDavid Howells 		if (call->drop_ref)
1351dde9f095SDavid Howells 			afs_put_call(call);
1352dde9f095SDavid Howells 	}
135398bf40cdSDavid Howells }
135498bf40cdSDavid Howells 
135508e0e7c8SDavid Howells /*
135600d3b7a4SDavid Howells  * security.c
135700d3b7a4SDavid Howells  */
1358be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
135900d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
1360a58823acSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1361a58823acSDavid Howells 			     struct afs_status_cb *);
1362416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *);
136300d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
13648b6a666aSDavid Howells extern struct key *afs_request_key_rcu(struct afs_cell *);
13650fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
1366549c7297SChristian Brauner extern int afs_permission(struct user_namespace *, struct inode *, int);
1367be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
136800d3b7a4SDavid Howells 
136900d3b7a4SDavid Howells /*
137008e0e7c8SDavid Howells  * server.c
137108e0e7c8SDavid Howells  */
137208e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
137308e0e7c8SDavid Howells 
1374f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
1375f044c884SDavid Howells 					  const struct sockaddr_rxrpc *);
1376d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
137781006805SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
137845218193SDavid Howells extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
1379977e5f8eSDavid Howells extern struct afs_server *afs_use_server(struct afs_server *, enum afs_server_trace);
1380977e5f8eSDavid Howells extern void afs_unuse_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1381977e5f8eSDavid Howells extern void afs_unuse_server_notime(struct afs_net *, struct afs_server *, enum afs_server_trace);
138245218193SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1383d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
1384d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
1385f6cbb368SDavid Howells extern void afs_fs_probe_timer(struct timer_list *);
1386f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
1387a310082fSDavid Howells extern bool afs_check_server_record(struct afs_operation *, struct afs_server *);
1388d2ddc776SDavid Howells 
1389f6cbb368SDavid Howells static inline void afs_inc_servers_outstanding(struct afs_net *net)
1390f6cbb368SDavid Howells {
1391f6cbb368SDavid Howells 	atomic_inc(&net->servers_outstanding);
1392f6cbb368SDavid Howells }
1393f6cbb368SDavid Howells 
1394f6cbb368SDavid Howells static inline void afs_dec_servers_outstanding(struct afs_net *net)
1395f6cbb368SDavid Howells {
1396f6cbb368SDavid Howells 	if (atomic_dec_and_test(&net->servers_outstanding))
1397f6cbb368SDavid Howells 		wake_up_var(&net->servers_outstanding);
1398f6cbb368SDavid Howells }
1399f6cbb368SDavid Howells 
1400f6cbb368SDavid Howells static inline bool afs_is_probing_server(struct afs_server *server)
1401f6cbb368SDavid Howells {
1402f6cbb368SDavid Howells 	return list_empty(&server->probe_link);
1403f6cbb368SDavid Howells }
1404f6cbb368SDavid Howells 
1405d2ddc776SDavid Howells /*
1406d2ddc776SDavid Howells  * server_list.c
1407d2ddc776SDavid Howells  */
1408d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1409d2ddc776SDavid Howells {
1410d2ddc776SDavid Howells 	refcount_inc(&slist->usage);
1411d2ddc776SDavid Howells 	return slist;
1412d2ddc776SDavid Howells }
1413d2ddc776SDavid Howells 
1414d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1415d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1416d2ddc776SDavid Howells 						     struct afs_vldb_entry *,
1417d2ddc776SDavid Howells 						     u8);
1418d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
141908e0e7c8SDavid Howells 
142008e0e7c8SDavid Howells /*
142100d3b7a4SDavid Howells  * super.c
142200d3b7a4SDavid Howells  */
1423f044c884SDavid Howells extern int __init afs_fs_init(void);
14245b86d4ffSDavid Howells extern void afs_fs_exit(void);
142500d3b7a4SDavid Howells 
142600d3b7a4SDavid Howells /*
142708e0e7c8SDavid Howells  * vlclient.c
142808e0e7c8SDavid Howells  */
14290a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
14300a5143f2SDavid Howells 							 const char *, int);
14310a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
14320b9bf381SDavid Howells extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *,
14330b9bf381SDavid Howells 						struct key *, struct afs_vlserver *, unsigned int);
14340a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
1435c3e9f888SDavid Howells extern char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *);
14360a5143f2SDavid Howells 
14370a5143f2SDavid Howells /*
14388a070a96SDavid Howells  * vl_alias.c
14398a070a96SDavid Howells  */
14408a070a96SDavid Howells extern int afs_cell_detect_alias(struct afs_cell *, struct key *);
14418a070a96SDavid Howells 
14428a070a96SDavid Howells /*
14433bf0fb6fSDavid Howells  * vl_probe.c
14443bf0fb6fSDavid Howells  */
14453bf0fb6fSDavid Howells extern void afs_vlserver_probe_result(struct afs_call *);
14463bf0fb6fSDavid Howells extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
14473bf0fb6fSDavid Howells extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
14483bf0fb6fSDavid Howells 
14493bf0fb6fSDavid Howells /*
14500a5143f2SDavid Howells  * vl_rotate.c
14510a5143f2SDavid Howells  */
14520a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
14530a5143f2SDavid Howells 					 struct afs_cell *, struct key *);
14540a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *);
14550a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
14560a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
14570a5143f2SDavid Howells 
14580a5143f2SDavid Howells /*
14590a5143f2SDavid Howells  * vlserver_list.c
14600a5143f2SDavid Howells  */
14610a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
14620a5143f2SDavid Howells {
14630a5143f2SDavid Howells 	atomic_inc(&vlserver->usage);
14640a5143f2SDavid Howells 	return vlserver;
14650a5143f2SDavid Howells }
14660a5143f2SDavid Howells 
14670a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
14680a5143f2SDavid Howells {
14690a5143f2SDavid Howells 	if (vllist)
14700a5143f2SDavid Howells 		atomic_inc(&vllist->usage);
14710a5143f2SDavid Howells 	return vllist;
14720a5143f2SDavid Howells }
14730a5143f2SDavid Howells 
14740a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
14750a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
14760a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
14770a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
14780a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
14790a5143f2SDavid Howells 							   const void *, size_t);
148008e0e7c8SDavid Howells 
148108e0e7c8SDavid Howells /*
148208e0e7c8SDavid Howells  * volume.c
148308e0e7c8SDavid Howells  */
148413fcc683SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1485d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *);
1486d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
1487cca37d45SDavid Howells extern struct afs_volume *afs_get_volume(struct afs_volume *, enum afs_volume_trace);
1488cca37d45SDavid Howells extern void afs_put_volume(struct afs_net *, struct afs_volume *, enum afs_volume_trace);
1489a310082fSDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
149008e0e7c8SDavid Howells 
149131143d5dSDavid Howells /*
149231143d5dSDavid Howells  * write.c
149331143d5dSDavid Howells  */
149431143d5dSDavid Howells extern int afs_set_page_dirty(struct page *);
149515b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
149615b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned flags,
149715b4650eSNick Piggin 			struct page **pagep, void **fsdata);
149815b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
149915b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned copied,
150015b4650eSNick Piggin 			struct page *page, void *fsdata);
150131143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
150231143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
150350b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
150402c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
15050722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
15064343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
15074343d008SDavid Howells extern int afs_launder_page(struct page *);
150831143d5dSDavid Howells 
1509d3e3b7eaSDavid Howells /*
1510d3e3b7eaSDavid Howells  * xattr.c
1511d3e3b7eaSDavid Howells  */
1512d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
151331143d5dSDavid Howells 
151430062bd1SDavid Howells /*
151530062bd1SDavid Howells  * yfsclient.c
151630062bd1SDavid Howells  */
1517e49c7b2fSDavid Howells extern void yfs_fs_fetch_data(struct afs_operation *);
1518e49c7b2fSDavid Howells extern void yfs_fs_create_file(struct afs_operation *);
1519e49c7b2fSDavid Howells extern void yfs_fs_make_dir(struct afs_operation *);
1520e49c7b2fSDavid Howells extern void yfs_fs_remove_file2(struct afs_operation *);
1521e49c7b2fSDavid Howells extern void yfs_fs_remove_file(struct afs_operation *);
1522e49c7b2fSDavid Howells extern void yfs_fs_remove_dir(struct afs_operation *);
1523e49c7b2fSDavid Howells extern void yfs_fs_link(struct afs_operation *);
1524e49c7b2fSDavid Howells extern void yfs_fs_symlink(struct afs_operation *);
1525e49c7b2fSDavid Howells extern void yfs_fs_rename(struct afs_operation *);
1526e49c7b2fSDavid Howells extern void yfs_fs_store_data(struct afs_operation *);
1527e49c7b2fSDavid Howells extern void yfs_fs_setattr(struct afs_operation *);
1528e49c7b2fSDavid Howells extern void yfs_fs_get_volume_status(struct afs_operation *);
1529e49c7b2fSDavid Howells extern void yfs_fs_set_lock(struct afs_operation *);
1530e49c7b2fSDavid Howells extern void yfs_fs_extend_lock(struct afs_operation *);
1531e49c7b2fSDavid Howells extern void yfs_fs_release_lock(struct afs_operation *);
1532e49c7b2fSDavid Howells extern void yfs_fs_fetch_status(struct afs_operation *);
1533e49c7b2fSDavid Howells extern void yfs_fs_inline_bulk_status(struct afs_operation *);
1534d2ddc776SDavid Howells 
1535ae46578bSDavid Howells struct yfs_acl {
1536ae46578bSDavid Howells 	struct afs_acl	*acl;		/* Dir/file/symlink ACL */
1537ae46578bSDavid Howells 	struct afs_acl	*vol_acl;	/* Whole volume ACL */
1538ae46578bSDavid Howells 	u32		inherit_flag;	/* True if ACL is inherited from parent dir */
1539ae46578bSDavid Howells 	u32		num_cleaned;	/* Number of ACEs removed due to subject removal */
1540ae46578bSDavid Howells 	unsigned int	flags;
1541ae46578bSDavid Howells #define YFS_ACL_WANT_ACL	0x01	/* Set if caller wants ->acl */
1542ae46578bSDavid Howells #define YFS_ACL_WANT_VOL_ACL	0x02	/* Set if caller wants ->vol_acl */
1543ae46578bSDavid Howells };
1544ae46578bSDavid Howells 
1545ae46578bSDavid Howells extern void yfs_free_opaque_acl(struct yfs_acl *);
1546e49c7b2fSDavid Howells extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
1547e49c7b2fSDavid Howells extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
1548ae46578bSDavid Howells 
1549d2ddc776SDavid Howells /*
1550d2ddc776SDavid Howells  * Miscellaneous inline functions.
1551d2ddc776SDavid Howells  */
1552d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1553d2ddc776SDavid Howells {
1554d2ddc776SDavid Howells 	return container_of(inode, struct afs_vnode, vfs_inode);
1555d2ddc776SDavid Howells }
1556d2ddc776SDavid Howells 
1557d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1558d2ddc776SDavid Howells {
1559d2ddc776SDavid Howells 	return &vnode->vfs_inode;
1560d2ddc776SDavid Howells }
1561d2ddc776SDavid Howells 
1562e49c7b2fSDavid Howells /*
1563e49c7b2fSDavid Howells  * Note that a dentry got changed.  We need to set d_fsdata to the data version
1564e49c7b2fSDavid Howells  * number derived from the result of the operation.  It doesn't matter if
1565e49c7b2fSDavid Howells  * d_fsdata goes backwards as we'll just revalidate.
1566e49c7b2fSDavid Howells  */
1567e49c7b2fSDavid Howells static inline void afs_update_dentry_version(struct afs_operation *op,
1568e49c7b2fSDavid Howells 					     struct afs_vnode_param *dir_vp,
1569e49c7b2fSDavid Howells 					     struct dentry *dentry)
1570e49c7b2fSDavid Howells {
1571e49c7b2fSDavid Howells 	if (!op->error)
1572e49c7b2fSDavid Howells 		dentry->d_fsdata =
1573e49c7b2fSDavid Howells 			(void *)(unsigned long)dir_vp->scb.status.data_version;
1574e49c7b2fSDavid Howells }
1575e49c7b2fSDavid Howells 
1576b6489a49SDavid Howells /*
1577b6489a49SDavid Howells  * Check for a conflicting operation on a directory that we just unlinked from.
1578b6489a49SDavid Howells  * If someone managed to sneak a link or an unlink in on the file we just
1579b6489a49SDavid Howells  * unlinked, we won't be able to trust nlink on an AFS file (but not YFS).
1580b6489a49SDavid Howells  */
1581b6489a49SDavid Howells static inline void afs_check_dir_conflict(struct afs_operation *op,
1582b6489a49SDavid Howells 					  struct afs_vnode_param *dvp)
1583b6489a49SDavid Howells {
1584b6489a49SDavid Howells 	if (dvp->dv_before + dvp->dv_delta != dvp->scb.status.data_version)
1585b6489a49SDavid Howells 		op->flags |= AFS_OPERATION_DIR_CONFLICT;
1586b6489a49SDavid Howells }
1587b6489a49SDavid Howells 
1588f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1589f51375cdSDavid Howells {
1590f51375cdSDavid Howells 	trace_afs_io_error(call->debug_id, -EIO, where);
1591f51375cdSDavid Howells 	return -EIO;
1592f51375cdSDavid Howells }
1593f51375cdSDavid Howells 
1594f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1595f51375cdSDavid Howells {
1596f51375cdSDavid Howells 	trace_afs_file_error(vnode, -EIO, where);
1597f51375cdSDavid Howells 	return -EIO;
1598f51375cdSDavid Howells }
1599d2ddc776SDavid Howells 
160008e0e7c8SDavid Howells /*****************************************************************************/
160108e0e7c8SDavid Howells /*
160208e0e7c8SDavid Howells  * debug tracing
160308e0e7c8SDavid Howells  */
160408e0e7c8SDavid Howells extern unsigned afs_debug;
160508e0e7c8SDavid Howells 
160608e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1607ad16df84SSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
160808e0e7c8SDavid Howells 
1609530b6412SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1610530b6412SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
161108e0e7c8SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
161208e0e7c8SDavid Howells 
161308e0e7c8SDavid Howells 
161408e0e7c8SDavid Howells #if defined(__KDEBUG)
161508e0e7c8SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
161608e0e7c8SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
161708e0e7c8SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
161808e0e7c8SDavid Howells 
161908e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
162008e0e7c8SDavid Howells #define AFS_DEBUG_KENTER	0x01
162108e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE	0x02
162208e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG	0x04
162308e0e7c8SDavid Howells 
162408e0e7c8SDavid Howells #define _enter(FMT,...)					\
162508e0e7c8SDavid Howells do {							\
162608e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
162708e0e7c8SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
162808e0e7c8SDavid Howells } while (0)
162908e0e7c8SDavid Howells 
163008e0e7c8SDavid Howells #define _leave(FMT,...)					\
163108e0e7c8SDavid Howells do {							\
163208e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
163308e0e7c8SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
163408e0e7c8SDavid Howells } while (0)
163508e0e7c8SDavid Howells 
163608e0e7c8SDavid Howells #define _debug(FMT,...)					\
163708e0e7c8SDavid Howells do {							\
163808e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
163908e0e7c8SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
164008e0e7c8SDavid Howells } while (0)
164108e0e7c8SDavid Howells 
164208e0e7c8SDavid Howells #else
164312fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
164412fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
164512fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
164608e0e7c8SDavid Howells #endif
164708e0e7c8SDavid Howells 
164808e0e7c8SDavid Howells /*
164908e0e7c8SDavid Howells  * debug assertion checking
165008e0e7c8SDavid Howells  */
165108e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
165208e0e7c8SDavid Howells 
165308e0e7c8SDavid Howells #define ASSERT(X)						\
165408e0e7c8SDavid Howells do {								\
165508e0e7c8SDavid Howells 	if (unlikely(!(X))) {					\
165608e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
165708e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
165808e0e7c8SDavid Howells 		BUG();						\
165908e0e7c8SDavid Howells 	}							\
166008e0e7c8SDavid Howells } while(0)
166108e0e7c8SDavid Howells 
166208e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)						\
166308e0e7c8SDavid Howells do {									\
166408e0e7c8SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
166508e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
166608e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
166708e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
166808e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
166908e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
167008e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
167108e0e7c8SDavid Howells 		BUG();							\
167208e0e7c8SDavid Howells 	}								\
167308e0e7c8SDavid Howells } while(0)
167408e0e7c8SDavid Howells 
1675416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)					\
1676416351f2SDavid Howells do {									\
1677416351f2SDavid Howells 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
1678416351f2SDavid Howells 		printk(KERN_ERR "\n");					\
1679416351f2SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1680416351f2SDavid Howells 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
1681416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1682416351f2SDavid Howells 		       (unsigned long)(H));				\
1683416351f2SDavid Howells 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1684416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1685416351f2SDavid Howells 		       (unsigned long)(H));				\
1686416351f2SDavid Howells 		BUG();							\
1687416351f2SDavid Howells 	}								\
1688416351f2SDavid Howells } while(0)
1689416351f2SDavid Howells 
169008e0e7c8SDavid Howells #define ASSERTIF(C, X)						\
169108e0e7c8SDavid Howells do {								\
169208e0e7c8SDavid Howells 	if (unlikely((C) && !(X))) {				\
169308e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
169408e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
169508e0e7c8SDavid Howells 		BUG();						\
169608e0e7c8SDavid Howells 	}							\
169708e0e7c8SDavid Howells } while(0)
169808e0e7c8SDavid Howells 
169908e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
170008e0e7c8SDavid Howells do {									\
170108e0e7c8SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
170208e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
170308e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
170408e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
170508e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
170608e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
170708e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
170808e0e7c8SDavid Howells 		BUG();							\
170908e0e7c8SDavid Howells 	}								\
171008e0e7c8SDavid Howells } while(0)
171108e0e7c8SDavid Howells 
171208e0e7c8SDavid Howells #else
171308e0e7c8SDavid Howells 
171408e0e7c8SDavid Howells #define ASSERT(X)				\
171508e0e7c8SDavid Howells do {						\
171608e0e7c8SDavid Howells } while(0)
171708e0e7c8SDavid Howells 
171808e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)			\
171908e0e7c8SDavid Howells do {						\
172008e0e7c8SDavid Howells } while(0)
172108e0e7c8SDavid Howells 
1722416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)		\
1723416351f2SDavid Howells do {						\
1724416351f2SDavid Howells } while(0)
1725416351f2SDavid Howells 
172608e0e7c8SDavid Howells #define ASSERTIF(C, X)				\
172708e0e7c8SDavid Howells do {						\
172808e0e7c8SDavid Howells } while(0)
172908e0e7c8SDavid Howells 
173008e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
173108e0e7c8SDavid Howells do {						\
173208e0e7c8SDavid Howells } while(0)
173308e0e7c8SDavid Howells 
173408e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1735