xref: /openbmc/linux/fs/afs/internal.h (revision 744bcd71)
1ec26815aSDavid Howells /* internal AFS stuff
21da177e4SLinus Torvalds  *
308e0e7c8SDavid Howells  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
41da177e4SLinus Torvalds  * Written by David Howells (dhowells@redhat.com)
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
71da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License
81da177e4SLinus Torvalds  * as published by the Free Software Foundation; either version
91da177e4SLinus Torvalds  * 2 of the License, or (at your option) any later version.
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <linux/compiler.h>
131da177e4SLinus Torvalds #include <linux/kernel.h>
148a79790bSTina Ruchandani #include <linux/ktime.h>
151da177e4SLinus Torvalds #include <linux/fs.h>
161da177e4SLinus Torvalds #include <linux/pagemap.h>
1708e0e7c8SDavid Howells #include <linux/rxrpc.h>
1800d3b7a4SDavid Howells #include <linux/key.h>
19e8edc6e0SAlexey Dobriyan #include <linux/workqueue.h>
2000c541eaSAndrew Morton #include <linux/sched.h>
2180e50be4SChristoph Hellwig #include <linux/fscache.h>
22e1da0222SJens Axboe #include <linux/backing-dev.h>
23ff548773SDavid Howells #include <linux/uuid.h>
240722f186SSouptick Joarder #include <linux/mm_types.h>
250a5143f2SDavid Howells #include <linux/dns_resolver.h>
26f044c884SDavid Howells #include <net/net_namespace.h>
275b86d4ffSDavid Howells #include <net/netns/generic.h>
285b86d4ffSDavid Howells #include <net/sock.h>
298324f0bcSDavid Howells #include <net/af_rxrpc.h>
3000c541eaSAndrew Morton 
3108e0e7c8SDavid Howells #include "afs.h"
3208e0e7c8SDavid Howells #include "afs_vl.h"
3308e0e7c8SDavid Howells 
3408e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15
3508e0e7c8SDavid Howells 
3631143d5dSDavid Howells struct pagevec;
3708e0e7c8SDavid Howells struct afs_call;
3808e0e7c8SDavid Howells 
3900d3b7a4SDavid Howells struct afs_mount_params {
4000d3b7a4SDavid Howells 	bool			rwpath;		/* T if the parent should be considered R/W */
4100d3b7a4SDavid Howells 	bool			force;		/* T to force cell type */
42bec5eb61Swanglei 	bool			autocell;	/* T if set auto mount operation */
434d673da1SDavid Howells 	bool			dyn_root;	/* T if dynamic root */
4400d3b7a4SDavid Howells 	afs_voltype_t		type;		/* type of volume requested */
4500d3b7a4SDavid Howells 	int			volnamesz;	/* size of volume name */
4600d3b7a4SDavid Howells 	const char		*volname;	/* name of volume to mount */
475b86d4ffSDavid Howells 	struct net		*net_ns;	/* Network namespace in effect */
485b86d4ffSDavid Howells 	struct afs_net		*net;		/* the AFS net namespace stuff */
4900d3b7a4SDavid Howells 	struct afs_cell		*cell;		/* cell in which to find volume */
5000d3b7a4SDavid Howells 	struct afs_volume	*volume;	/* volume record */
5100d3b7a4SDavid Howells 	struct key		*key;		/* key to use for secure mounting */
5200d3b7a4SDavid Howells };
5300d3b7a4SDavid Howells 
54c435ee34SDavid Howells struct afs_iget_data {
55c435ee34SDavid Howells 	struct afs_fid		fid;
56c435ee34SDavid Howells 	struct afs_volume	*volume;	/* volume on which resides */
57c435ee34SDavid Howells };
58c435ee34SDavid Howells 
598e8d7f13SDavid Howells enum afs_call_state {
6098bf40cdSDavid Howells 	AFS_CALL_CL_REQUESTING,		/* Client: Request is being sent */
6198bf40cdSDavid Howells 	AFS_CALL_CL_AWAIT_REPLY,	/* Client: Awaiting reply */
6298bf40cdSDavid Howells 	AFS_CALL_CL_PROC_REPLY,		/* Client: rxrpc call complete; processing reply */
6398bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_OP_ID,	/* Server: Awaiting op ID */
6498bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_REQUEST,	/* Server: Awaiting request data */
6598bf40cdSDavid Howells 	AFS_CALL_SV_REPLYING,		/* Server: Replying */
6698bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_ACK,		/* Server: Awaiting final ACK */
678e8d7f13SDavid Howells 	AFS_CALL_COMPLETE,		/* Completed or failed */
688e8d7f13SDavid Howells };
69f044c884SDavid Howells 
7008e0e7c8SDavid Howells /*
718b2a464cSDavid Howells  * List of server addresses.
728b2a464cSDavid Howells  */
738b2a464cSDavid Howells struct afs_addr_list {
748b2a464cSDavid Howells 	struct rcu_head		rcu;		/* Must be first */
758b2a464cSDavid Howells 	refcount_t		usage;
76d2ddc776SDavid Howells 	u32			version;	/* Version */
7768eb64c3SDavid Howells 	unsigned char		max_addrs;
7868eb64c3SDavid Howells 	unsigned char		nr_addrs;
7968eb64c3SDavid Howells 	unsigned char		index;		/* Address currently in use */
8068eb64c3SDavid Howells 	unsigned char		nr_ipv4;	/* Number of IPv4 addresses */
810a5143f2SDavid Howells 	enum dns_record_source	source:8;
820a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
83bf99a53cSDavid Howells 	unsigned long		probed;		/* Mask of servers that have been probed */
84bf99a53cSDavid Howells 	unsigned long		yfs;		/* Mask of servers that are YFS */
858b2a464cSDavid Howells 	struct sockaddr_rxrpc	addrs[];
8668eb64c3SDavid Howells #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
878b2a464cSDavid Howells };
888b2a464cSDavid Howells 
898b2a464cSDavid Howells /*
9008e0e7c8SDavid Howells  * a record of an in-progress RxRPC call
9108e0e7c8SDavid Howells  */
9208e0e7c8SDavid Howells struct afs_call {
9308e0e7c8SDavid Howells 	const struct afs_call_type *type;	/* type of call */
9408e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* processes awaiting completion */
95341f741fSDavid Howells 	struct work_struct	async_work;	/* async I/O processor */
9608e0e7c8SDavid Howells 	struct work_struct	work;		/* actual work processor */
9708e0e7c8SDavid Howells 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
9808e0e7c8SDavid Howells 	struct key		*key;		/* security for this call */
99f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
100d0676a16SDavid Howells 	struct afs_server	*cm_server;	/* Server affected by incoming CM call */
101d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Callback interest for server used */
10208e0e7c8SDavid Howells 	void			*request;	/* request data (first part) */
1034343d008SDavid Howells 	struct address_space	*mapping;	/* Pages being written from */
10412bdcf33SDavid Howells 	struct iov_iter		iter;		/* Buffer iterator */
10512bdcf33SDavid Howells 	struct iov_iter		*_iter;		/* Iterator currently in use */
10612bdcf33SDavid Howells 	union {	/* Convenience for ->iter */
10712bdcf33SDavid Howells 		struct kvec	kvec[1];
10812bdcf33SDavid Howells 		struct bio_vec	bvec[1];
10912bdcf33SDavid Howells 	};
11008e0e7c8SDavid Howells 	void			*buffer;	/* reply receive buffer */
11197e3043aSDavid Howells 	void			*reply[4];	/* Where to put the reply */
11231143d5dSDavid Howells 	pgoff_t			first;		/* first page in mapping to deal with */
11331143d5dSDavid Howells 	pgoff_t			last;		/* last page in mapping to deal with */
114341f741fSDavid Howells 	atomic_t		usage;
1158e8d7f13SDavid Howells 	enum afs_call_state	state;
11698bf40cdSDavid Howells 	spinlock_t		state_lock;
11708e0e7c8SDavid Howells 	int			error;		/* error code */
118d001648eSDavid Howells 	u32			abort_code;	/* Remote abort ID or 0 */
11908e0e7c8SDavid Howells 	unsigned		request_size;	/* size of request data */
12008e0e7c8SDavid Howells 	unsigned		reply_max;	/* maximum size of reply */
12131143d5dSDavid Howells 	unsigned		first_offset;	/* offset into mapping[first] */
122c435ee34SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
123bcd89270SMarc Dionne 	union {
12431143d5dSDavid Howells 		unsigned	last_to;	/* amount of mapping[last] */
125bcd89270SMarc Dionne 		unsigned	count2;		/* count used in unmarshalling */
126bcd89270SMarc Dionne 	};
12708e0e7c8SDavid Howells 	unsigned char		unmarshall;	/* unmarshalling phase */
12808e0e7c8SDavid Howells 	bool			incoming;	/* T if incoming call */
12931143d5dSDavid Howells 	bool			send_pages;	/* T if data from mapping should be sent */
130d001648eSDavid Howells 	bool			need_attention;	/* T if RxRPC poked us */
13156ff9c83SDavid Howells 	bool			async;		/* T if asynchronous */
13233cd7f2bSDavid Howells 	bool			ret_reply0;	/* T if should return reply[0] on success */
133a68f4a27SDavid Howells 	bool			upgrade;	/* T to request service upgrade */
13412d8e95aSDavid Howells 	bool			want_reply_time;	/* T if want reply_time */
135bf99a53cSDavid Howells 	u16			service_id;	/* Actual service ID (after upgrade) */
136a25e21f0SDavid Howells 	unsigned int		debug_id;	/* Trace ID */
13750a2c953SDavid Howells 	u32			operation_ID;	/* operation ID for an incoming call */
13808e0e7c8SDavid Howells 	u32			count;		/* count for use in unmarshalling */
13912bdcf33SDavid Howells 	union {					/* place to extract temporary data */
14012bdcf33SDavid Howells 		struct {
14112bdcf33SDavid Howells 			__be32	tmp_u;
14212bdcf33SDavid Howells 			__be32	tmp;
14312bdcf33SDavid Howells 		} __attribute__((packed));
14412bdcf33SDavid Howells 		__be64		tmp64;
14512bdcf33SDavid Howells 	};
1460c3a5ac2SDavid Howells 	afs_dataversion_t	expected_version; /* Updated version expected from store */
1470c3a5ac2SDavid Howells 	afs_dataversion_t	expected_version_2; /* 2nd updated version expected from store */
14812d8e95aSDavid Howells 	ktime_t			reply_time;	/* Time of first reply packet */
14908e0e7c8SDavid Howells };
15008e0e7c8SDavid Howells 
15108e0e7c8SDavid Howells struct afs_call_type {
15200d3b7a4SDavid Howells 	const char *name;
153025db80cSDavid Howells 	unsigned int op; /* Really enum afs_fs_operation */
15400d3b7a4SDavid Howells 
15508e0e7c8SDavid Howells 	/* deliver request or reply data to an call
15608e0e7c8SDavid Howells 	 * - returning an error will cause the call to be aborted
15708e0e7c8SDavid Howells 	 */
158d001648eSDavid Howells 	int (*deliver)(struct afs_call *call);
15908e0e7c8SDavid Howells 
16008e0e7c8SDavid Howells 	/* clean up a call */
16108e0e7c8SDavid Howells 	void (*destructor)(struct afs_call *call);
162341f741fSDavid Howells 
163341f741fSDavid Howells 	/* Work function */
164341f741fSDavid Howells 	void (*work)(struct work_struct *work);
16508e0e7c8SDavid Howells };
16608e0e7c8SDavid Howells 
16708e0e7c8SDavid Howells /*
1684343d008SDavid Howells  * Key available for writeback on a file.
1694343d008SDavid Howells  */
1704343d008SDavid Howells struct afs_wb_key {
1714343d008SDavid Howells 	refcount_t		usage;
1724343d008SDavid Howells 	struct key		*key;
1734343d008SDavid Howells 	struct list_head	vnode_link;	/* Link in vnode->wb_keys */
1744343d008SDavid Howells };
1754343d008SDavid Howells 
1764343d008SDavid Howells /*
177215804a9SDavid Howells  * AFS open file information record.  Pointed to by file->private_data.
178215804a9SDavid Howells  */
179215804a9SDavid Howells struct afs_file {
180215804a9SDavid Howells 	struct key		*key;		/* The key this file was opened with */
1814343d008SDavid Howells 	struct afs_wb_key	*wb;		/* Writeback key record for this file */
182215804a9SDavid Howells };
183215804a9SDavid Howells 
184215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
185215804a9SDavid Howells {
186215804a9SDavid Howells 	struct afs_file *af = file->private_data;
187215804a9SDavid Howells 
188215804a9SDavid Howells 	return af->key;
189215804a9SDavid Howells }
190215804a9SDavid Howells 
191215804a9SDavid Howells /*
192196ee9cdSDavid Howells  * Record of an outstanding read operation on a vnode.
193196ee9cdSDavid Howells  */
194196ee9cdSDavid Howells struct afs_read {
195196ee9cdSDavid Howells 	loff_t			pos;		/* Where to start reading */
196e8e581a8SDavid Howells 	loff_t			len;		/* How much we're asking for */
197196ee9cdSDavid Howells 	loff_t			actual_len;	/* How much we're actually getting */
1986a0e3999SDavid Howells 	loff_t			remain;		/* Amount remaining */
199f3ddee8dSDavid Howells 	loff_t			file_size;	/* File size returned by server */
200f3ddee8dSDavid Howells 	afs_dataversion_t	data_version;	/* Version number returned by server */
201f3ddee8dSDavid Howells 	refcount_t		usage;
202196ee9cdSDavid Howells 	unsigned int		index;		/* Which page we're reading into */
203196ee9cdSDavid Howells 	unsigned int		nr_pages;
20412bdcf33SDavid Howells 	unsigned int		offset;		/* offset into current page */
205196ee9cdSDavid Howells 	void (*page_done)(struct afs_call *, struct afs_read *);
206f3ddee8dSDavid Howells 	struct page		**pages;
207f3ddee8dSDavid Howells 	struct page		*array[];
208196ee9cdSDavid Howells };
209196ee9cdSDavid Howells 
210196ee9cdSDavid Howells /*
21108e0e7c8SDavid Howells  * AFS superblock private data
21208e0e7c8SDavid Howells  * - there's one superblock per volume
21308e0e7c8SDavid Howells  */
21408e0e7c8SDavid Howells struct afs_super_info {
2155b86d4ffSDavid Howells 	struct net		*net_ns;	/* Network namespace */
21649566f6fSDavid Howells 	struct afs_cell		*cell;		/* The cell in which the volume resides */
21708e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume record */
2184d673da1SDavid Howells 	bool			dyn_root;	/* True if dynamic root */
21908e0e7c8SDavid Howells };
22008e0e7c8SDavid Howells 
22108e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
22208e0e7c8SDavid Howells {
22308e0e7c8SDavid Howells 	return sb->s_fs_info;
22408e0e7c8SDavid Howells }
22508e0e7c8SDavid Howells 
22608e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
22708e0e7c8SDavid Howells 
22808e0e7c8SDavid Howells /*
2296f8880d8SDavid Howells  * Set of substitutes for @sys.
2306f8880d8SDavid Howells  */
2316f8880d8SDavid Howells struct afs_sysnames {
2326f8880d8SDavid Howells #define AFS_NR_SYSNAME 16
2336f8880d8SDavid Howells 	char			*subs[AFS_NR_SYSNAME];
2346f8880d8SDavid Howells 	refcount_t		usage;
2356f8880d8SDavid Howells 	unsigned short		nr;
2366f8880d8SDavid Howells 	char			blank[1];
2376f8880d8SDavid Howells };
2386f8880d8SDavid Howells 
2396f8880d8SDavid Howells /*
240f044c884SDavid Howells  * AFS network namespace record.
241f044c884SDavid Howells  */
242f044c884SDavid Howells struct afs_net {
2435b86d4ffSDavid Howells 	struct net		*net;		/* Backpointer to the owning net namespace */
244f044c884SDavid Howells 	struct afs_uuid		uuid;
245f044c884SDavid Howells 	bool			live;		/* F if this namespace is being removed */
246f044c884SDavid Howells 
247f044c884SDavid Howells 	/* AF_RXRPC I/O stuff */
248f044c884SDavid Howells 	struct socket		*socket;
249f044c884SDavid Howells 	struct afs_call		*spare_incoming_call;
250f044c884SDavid Howells 	struct work_struct	charge_preallocation_work;
251f044c884SDavid Howells 	struct mutex		socket_mutex;
252f044c884SDavid Howells 	atomic_t		nr_outstanding_calls;
253f044c884SDavid Howells 	atomic_t		nr_superblocks;
254f044c884SDavid Howells 
255f044c884SDavid Howells 	/* Cell database */
256989782dcSDavid Howells 	struct rb_root		cells;
2571588def9SDavid Howells 	struct afs_cell __rcu	*ws_cell;
258989782dcSDavid Howells 	struct work_struct	cells_manager;
259989782dcSDavid Howells 	struct timer_list	cells_timer;
260989782dcSDavid Howells 	atomic_t		cells_outstanding;
261989782dcSDavid Howells 	seqlock_t		cells_lock;
262f044c884SDavid Howells 
2630da0b7fdSDavid Howells 	struct mutex		proc_cells_lock;
2646b3944e4SDavid Howells 	struct hlist_head	proc_cells;
265f044c884SDavid Howells 
266d2ddc776SDavid Howells 	/* Known servers.  Theoretically each fileserver can only be in one
267d2ddc776SDavid Howells 	 * cell, but in practice, people create aliases and subsets and there's
268d2ddc776SDavid Howells 	 * no easy way to distinguish them.
269d2ddc776SDavid Howells 	 */
270d2ddc776SDavid Howells 	seqlock_t		fs_lock;	/* For fs_servers */
271d2ddc776SDavid Howells 	struct rb_root		fs_servers;	/* afs_server (by server UUID or address) */
272d2ddc776SDavid Howells 	struct list_head	fs_updates;	/* afs_server (by update_at) */
273d2ddc776SDavid Howells 	struct hlist_head	fs_proc;	/* procfs servers list */
274d2ddc776SDavid Howells 
275d2ddc776SDavid Howells 	struct hlist_head	fs_addresses4;	/* afs_server (by lowest IPv4 addr) */
276d2ddc776SDavid Howells 	struct hlist_head	fs_addresses6;	/* afs_server (by lowest IPv6 addr) */
277d2ddc776SDavid Howells 	seqlock_t		fs_addr_lock;	/* For fs_addresses[46] */
278d2ddc776SDavid Howells 
279d2ddc776SDavid Howells 	struct work_struct	fs_manager;
280d2ddc776SDavid Howells 	struct timer_list	fs_timer;
281d2ddc776SDavid Howells 	atomic_t		servers_outstanding;
282f044c884SDavid Howells 
283f044c884SDavid Howells 	/* File locking renewal management */
284f044c884SDavid Howells 	struct mutex		lock_manager_mutex;
285f044c884SDavid Howells 
286f044c884SDavid Howells 	/* Misc */
2870da0b7fdSDavid Howells 	struct super_block	*dynroot_sb;	/* Dynamic root mount superblock */
288f044c884SDavid Howells 	struct proc_dir_entry	*proc_afs;	/* /proc/net/afs directory */
2896f8880d8SDavid Howells 	struct afs_sysnames	*sysnames;
2906f8880d8SDavid Howells 	rwlock_t		sysnames_lock;
291d55b4da4SDavid Howells 
292d55b4da4SDavid Howells 	/* Statistics counters */
293d55b4da4SDavid Howells 	atomic_t		n_lookup;	/* Number of lookups done */
294d55b4da4SDavid Howells 	atomic_t		n_reval;	/* Number of dentries needing revalidation */
295d55b4da4SDavid Howells 	atomic_t		n_inval;	/* Number of invalidations by the server */
296f3ddee8dSDavid Howells 	atomic_t		n_relpg;	/* Number of invalidations by releasepage */
297d55b4da4SDavid Howells 	atomic_t		n_read_dir;	/* Number of directory pages read */
29863a4681fSDavid Howells 	atomic_t		n_dir_cr;	/* Number of directory entry creation edits */
29963a4681fSDavid Howells 	atomic_t		n_dir_rm;	/* Number of directory entry removal edits */
30076a5cb6fSDavid Howells 	atomic_t		n_stores;	/* Number of store ops */
30176a5cb6fSDavid Howells 	atomic_long_t		n_store_bytes;	/* Number of bytes stored */
30276a5cb6fSDavid Howells 	atomic_long_t		n_fetch_bytes;	/* Number of bytes fetched */
30376a5cb6fSDavid Howells 	atomic_t		n_fetches;	/* Number of data fetch ops */
304f044c884SDavid Howells };
305f044c884SDavid Howells 
3066f8880d8SDavid Howells extern const char afs_init_sysname[];
307f044c884SDavid Howells 
308989782dcSDavid Howells enum afs_cell_state {
309989782dcSDavid Howells 	AFS_CELL_UNSET,
310989782dcSDavid Howells 	AFS_CELL_ACTIVATING,
311989782dcSDavid Howells 	AFS_CELL_ACTIVE,
312989782dcSDavid Howells 	AFS_CELL_DEACTIVATING,
313989782dcSDavid Howells 	AFS_CELL_INACTIVE,
314989782dcSDavid Howells 	AFS_CELL_FAILED,
315989782dcSDavid Howells };
316989782dcSDavid Howells 
317f044c884SDavid Howells /*
318d2ddc776SDavid Howells  * AFS cell record.
319d2ddc776SDavid Howells  *
320d2ddc776SDavid Howells  * This is a tricky concept to get right as it is possible to create aliases
321d2ddc776SDavid Howells  * simply by pointing AFSDB/SRV records for two names at the same set of VL
322d2ddc776SDavid Howells  * servers; it is also possible to do things like setting up two sets of VL
323d2ddc776SDavid Howells  * servers, one of which provides a superset of the volumes provided by the
324d2ddc776SDavid Howells  * other (for internal/external division, for example).
325d2ddc776SDavid Howells  *
326d2ddc776SDavid Howells  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
327d2ddc776SDavid Howells  * servers and (b) a cell's name is used by the client to select the key to use
328d2ddc776SDavid Howells  * for authentication and encryption.  The cell name is not typically used in
329d2ddc776SDavid Howells  * the protocol.
330d2ddc776SDavid Howells  *
331d2ddc776SDavid Howells  * There is no easy way to determine if two cells are aliases or one is a
332d2ddc776SDavid Howells  * subset of another.
33308e0e7c8SDavid Howells  */
33408e0e7c8SDavid Howells struct afs_cell {
335989782dcSDavid Howells 	union {
336989782dcSDavid Howells 		struct rcu_head	rcu;
337989782dcSDavid Howells 		struct rb_node	net_node;	/* Node in net->cells */
338989782dcSDavid Howells 	};
339989782dcSDavid Howells 	struct afs_net		*net;
34000d3b7a4SDavid Howells 	struct key		*anonymous_key;	/* anonymous user key for this cell */
341989782dcSDavid Howells 	struct work_struct	manager;	/* Manager for init/deinit/dns */
3426b3944e4SDavid Howells 	struct hlist_node	proc_link;	/* /proc cell list link */
3439b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
3449b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
3451da177e4SLinus Torvalds #endif
346989782dcSDavid Howells 	time64_t		dns_expiry;	/* Time AFSDB/SRV record expires */
347989782dcSDavid Howells 	time64_t		last_inactive;	/* Time of last drop of usage count */
348989782dcSDavid Howells 	atomic_t		usage;
349989782dcSDavid Howells 	unsigned long		flags;
350989782dcSDavid Howells #define AFS_CELL_FL_NOT_READY	0		/* The cell record is not ready for use */
351989782dcSDavid Howells #define AFS_CELL_FL_NO_GC	1		/* The cell was added manually, don't auto-gc */
352989782dcSDavid Howells #define AFS_CELL_FL_NOT_FOUND	2		/* Permanent DNS error */
353989782dcSDavid Howells #define AFS_CELL_FL_DNS_FAIL	3		/* Failed to access DNS */
3548b2a464cSDavid Howells #define AFS_CELL_FL_NO_LOOKUP_YET 4		/* Not completed first DNS lookup yet */
355989782dcSDavid Howells 	enum afs_cell_state	state;
356989782dcSDavid Howells 	short			error;
357989782dcSDavid Howells 
358d2ddc776SDavid Howells 	/* Active fileserver interaction state. */
359d2ddc776SDavid Howells 	struct list_head	proc_volumes;	/* procfs volume list */
360d2ddc776SDavid Howells 	rwlock_t		proc_lock;
361989782dcSDavid Howells 
362d2ddc776SDavid Howells 	/* VL server list. */
3630a5143f2SDavid Howells 	rwlock_t		vl_servers_lock; /* Lock on vl_servers */
3640a5143f2SDavid Howells 	struct afs_vlserver_list __rcu *vl_servers;
3650a5143f2SDavid Howells 
366989782dcSDavid Howells 	u8			name_len;	/* Length of name */
367989782dcSDavid Howells 	char			name[64 + 1];	/* Cell name, case-flattened and NUL-padded */
36808e0e7c8SDavid Howells };
36908e0e7c8SDavid Howells 
37008e0e7c8SDavid Howells /*
3710a5143f2SDavid Howells  * Volume Location server record.
3720a5143f2SDavid Howells  */
3730a5143f2SDavid Howells struct afs_vlserver {
3740a5143f2SDavid Howells 	struct rcu_head		rcu;
3750a5143f2SDavid Howells 	struct afs_addr_list	__rcu *addresses; /* List of addresses for this VL server */
3760a5143f2SDavid Howells 	unsigned long		flags;
3770a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED	0		/* The VL server has been probed */
3780a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING	1		/* VL server is being probed */
3790a5143f2SDavid Howells 	rwlock_t		lock;		/* Lock on addresses */
3800a5143f2SDavid Howells 	atomic_t		usage;
3810a5143f2SDavid Howells 	u16			name_len;	/* Length of name */
3820a5143f2SDavid Howells 	u16			port;
3830a5143f2SDavid Howells 	char			name[];		/* Server name, case-flattened */
3840a5143f2SDavid Howells };
3850a5143f2SDavid Howells 
3860a5143f2SDavid Howells /*
3870a5143f2SDavid Howells  * Weighted list of Volume Location servers.
3880a5143f2SDavid Howells  */
3890a5143f2SDavid Howells struct afs_vlserver_entry {
3900a5143f2SDavid Howells 	u16			priority;	/* Preference (as SRV) */
3910a5143f2SDavid Howells 	u16			weight;		/* Weight (as SRV) */
3920a5143f2SDavid Howells 	enum dns_record_source	source:8;
3930a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
3940a5143f2SDavid Howells 	struct afs_vlserver	*server;
3950a5143f2SDavid Howells };
3960a5143f2SDavid Howells 
3970a5143f2SDavid Howells struct afs_vlserver_list {
3980a5143f2SDavid Howells 	struct rcu_head		rcu;
3990a5143f2SDavid Howells 	atomic_t		usage;
4000a5143f2SDavid Howells 	u8			nr_servers;
4010a5143f2SDavid Howells 	u8			index;		/* Server currently in use */
4020a5143f2SDavid Howells 	enum dns_record_source	source:8;
4030a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4040a5143f2SDavid Howells 	rwlock_t		lock;
4050a5143f2SDavid Howells 	struct afs_vlserver_entry servers[];
4060a5143f2SDavid Howells };
4070a5143f2SDavid Howells 
4080a5143f2SDavid Howells /*
409d2ddc776SDavid Howells  * Cached VLDB entry.
410d2ddc776SDavid Howells  *
411d2ddc776SDavid Howells  * This is pointed to by cell->vldb_entries, indexed by name.
41208e0e7c8SDavid Howells  */
413d2ddc776SDavid Howells struct afs_vldb_entry {
414d2ddc776SDavid Howells 	afs_volid_t		vid[3];		/* Volume IDs for R/W, R/O and Bak volumes */
41500d3b7a4SDavid Howells 
416d2ddc776SDavid Howells 	unsigned long		flags;
417d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW		0		/* - R/W volume exists */
418d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO		1		/* - R/O volume exists */
419d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK	2		/* - Backup volume exists */
420d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID	3		/* - Record is valid */
421d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR	4		/* - VL server returned error */
422d2ddc776SDavid Howells 
423d2ddc776SDavid Howells 	uuid_t			fs_server[AFS_NMAXNSERVERS];
424d2ddc776SDavid Howells 	u8			fs_mask[AFS_NMAXNSERVERS];
42508e0e7c8SDavid Howells #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
42608e0e7c8SDavid Howells #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
42708e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
428d2ddc776SDavid Howells 	short			error;
429d2ddc776SDavid Howells 	u8			nr_servers;	/* Number of server records */
430d2ddc776SDavid Howells 	u8			name_len;
431d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
43208e0e7c8SDavid Howells };
43308e0e7c8SDavid Howells 
43408e0e7c8SDavid Howells /*
435d2ddc776SDavid Howells  * Record of fileserver with which we're actively communicating.
43608e0e7c8SDavid Howells  */
43708e0e7c8SDavid Howells struct afs_server {
438d2ddc776SDavid Howells 	struct rcu_head		rcu;
439d2ddc776SDavid Howells 	union {
440d2ddc776SDavid Howells 		uuid_t		uuid;		/* Server ID */
441d2ddc776SDavid Howells 		struct afs_uuid	_uuid;
442d2ddc776SDavid Howells 	};
443c435ee34SDavid Howells 
444d2ddc776SDavid Howells 	struct afs_addr_list	__rcu *addresses;
445d2ddc776SDavid Howells 	struct rb_node		uuid_rb;	/* Link in net->servers */
446d2ddc776SDavid Howells 	struct hlist_node	addr4_link;	/* Link in net->fs_addresses4 */
447d2ddc776SDavid Howells 	struct hlist_node	addr6_link;	/* Link in net->fs_addresses6 */
448d2ddc776SDavid Howells 	struct hlist_node	proc_link;	/* Link in net->fs_proc */
449d2ddc776SDavid Howells 	struct afs_server	*gc_next;	/* Next server in manager's list */
450d2ddc776SDavid Howells 	time64_t		put_time;	/* Time at which last put */
451d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update the record */
452c435ee34SDavid Howells 	unsigned long		flags;
453d2ddc776SDavid Howells #define AFS_SERVER_FL_NEW	0		/* New server, don't inc cb_s_break */
454d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_READY	1		/* The record is not ready for use */
455d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_FOUND	2		/* VL server says no such server */
456d2ddc776SDavid Howells #define AFS_SERVER_FL_VL_FAIL	3		/* Failed to access VL server */
457d2ddc776SDavid Howells #define AFS_SERVER_FL_UPDATING	4
458d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBED	5		/* The fileserver has been probed */
459d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBING	6		/* Fileserver is being probed */
4605cf9dd55SDavid Howells #define AFS_SERVER_FL_NO_IBULK	7		/* Fileserver doesn't support FS.InlineBulkStatus */
461f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8		/* May have callbacks on this fileserver */
46230062bd1SDavid Howells #define AFS_SERVER_FL_IS_YFS	9		/* Server is YFS not AFS */
46330062bd1SDavid Howells #define AFS_SERVER_FL_NO_RM2	10		/* Fileserver doesn't support YFS.RemoveFile2 */
464d2ddc776SDavid Howells 	atomic_t		usage;
465d2ddc776SDavid Howells 	u32			addr_version;	/* Address list version */
46608e0e7c8SDavid Howells 
46708e0e7c8SDavid Howells 	/* file service access */
468d2ddc776SDavid Howells 	rwlock_t		fs_lock;	/* access lock */
46908e0e7c8SDavid Howells 
47008e0e7c8SDavid Howells 	/* callback promise management */
47147ea0f2eSDavid Howells 	struct hlist_head	cb_volumes;	/* List of volume interests on this server */
472c435ee34SDavid Howells 	unsigned		cb_s_break;	/* Break-everything counter. */
473c435ee34SDavid Howells 	rwlock_t		cb_break_lock;	/* Volume finding lock */
474c435ee34SDavid Howells };
475c435ee34SDavid Howells 
476c435ee34SDavid Howells /*
47747ea0f2eSDavid Howells  * Volume collation in the server's callback interest list.
47847ea0f2eSDavid Howells  */
47947ea0f2eSDavid Howells struct afs_vol_interest {
48047ea0f2eSDavid Howells 	struct hlist_node	srv_link;	/* Link in server->cb_volumes */
48147ea0f2eSDavid Howells 	struct hlist_head	cb_interests;	/* List of callback interests on the server */
48247ea0f2eSDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
48347ea0f2eSDavid Howells 	unsigned int		usage;
48447ea0f2eSDavid Howells };
48547ea0f2eSDavid Howells 
48647ea0f2eSDavid Howells /*
487c435ee34SDavid Howells  * Interest by a superblock on a server.
488c435ee34SDavid Howells  */
489c435ee34SDavid Howells struct afs_cb_interest {
49047ea0f2eSDavid Howells 	struct hlist_node	cb_vlink;	/* Link in vol_interest->cb_interests */
49147ea0f2eSDavid Howells 	struct afs_vol_interest	*vol_interest;
492c435ee34SDavid Howells 	struct afs_server	*server;	/* Server on which this interest resides */
493c435ee34SDavid Howells 	struct super_block	*sb;		/* Superblock on which inodes reside */
494c435ee34SDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
495c435ee34SDavid Howells 	refcount_t		usage;
49608e0e7c8SDavid Howells };
49708e0e7c8SDavid Howells 
49808e0e7c8SDavid Howells /*
499d2ddc776SDavid Howells  * Replaceable server list.
50008e0e7c8SDavid Howells  */
501d2ddc776SDavid Howells struct afs_server_entry {
502d2ddc776SDavid Howells 	struct afs_server	*server;
503d2ddc776SDavid Howells 	struct afs_cb_interest	*cb_interest;
504d2ddc776SDavid Howells };
505d2ddc776SDavid Howells 
506d2ddc776SDavid Howells struct afs_server_list {
507d2ddc776SDavid Howells 	refcount_t		usage;
508d2ddc776SDavid Howells 	unsigned short		nr_servers;
509d2ddc776SDavid Howells 	unsigned short		index;		/* Server currently in use */
510d2ddc776SDavid Howells 	unsigned short		vnovol_mask;	/* Servers to be skipped due to VNOVOL */
511d2ddc776SDavid Howells 	unsigned int		seq;		/* Set to ->servers_seq when installed */
512d4a96becSDavid Howells 	rwlock_t		lock;
513d2ddc776SDavid Howells 	struct afs_server_entry	servers[];
51408e0e7c8SDavid Howells };
51508e0e7c8SDavid Howells 
51608e0e7c8SDavid Howells /*
517d2ddc776SDavid Howells  * Live AFS volume management.
51808e0e7c8SDavid Howells  */
519d2ddc776SDavid Howells struct afs_volume {
520d2ddc776SDavid Howells 	afs_volid_t		vid;		/* volume ID */
521d2ddc776SDavid Howells 	atomic_t		usage;
522d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update */
523d2ddc776SDavid Howells 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
524d2ddc776SDavid Howells 	struct list_head	proc_link;	/* Link in cell->vl_proc */
525d2ddc776SDavid Howells 	unsigned long		flags;
526d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE	0	/* - T if an update needs performing */
527d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING	1	/* - T if an update is in progress */
528d2ddc776SDavid Howells #define AFS_VOLUME_WAIT		2	/* - T if users must wait for update */
529d2ddc776SDavid Howells #define AFS_VOLUME_DELETED	3	/* - T if volume appears deleted */
530d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE	4	/* - T if volume offline notice given */
531d2ddc776SDavid Howells #define AFS_VOLUME_BUSY		5	/* - T if volume busy notice given */
532d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
533d2ddc776SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
534d2ddc776SDavid Howells #endif
535d2ddc776SDavid Howells 	struct afs_server_list	*servers;	/* List of servers on which volume resides */
536d2ddc776SDavid Howells 	rwlock_t		servers_lock;	/* Lock for ->servers */
537d2ddc776SDavid Howells 	unsigned int		servers_seq;	/* Incremented each time ->servers changes */
538d2ddc776SDavid Howells 
53968251f0aSDavid Howells 	unsigned		cb_v_break;	/* Break-everything counter. */
54068251f0aSDavid Howells 	rwlock_t		cb_break_lock;
54168251f0aSDavid Howells 
542d2ddc776SDavid Howells 	afs_voltype_t		type;		/* type of volume */
543d2ddc776SDavid Howells 	short			error;
544d2ddc776SDavid Howells 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
545d2ddc776SDavid Howells 	u8			name_len;
546d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
54708e0e7c8SDavid Howells };
54808e0e7c8SDavid Howells 
5490fafdc9fSDavid Howells enum afs_lock_state {
5500fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NONE,		/* The vnode has no lock on the server */
5510fafdc9fSDavid Howells 	AFS_VNODE_LOCK_WAITING_FOR_CB,	/* We're waiting for the server to break the callback */
5520fafdc9fSDavid Howells 	AFS_VNODE_LOCK_SETTING,		/* We're asking the server for a lock */
5530fafdc9fSDavid Howells 	AFS_VNODE_LOCK_GRANTED,		/* We have a lock on the server */
5540fafdc9fSDavid Howells 	AFS_VNODE_LOCK_EXTENDING,	/* We're extending a lock on the server */
5550fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NEED_UNLOCK,	/* We need to unlock on the server */
5560fafdc9fSDavid Howells 	AFS_VNODE_LOCK_UNLOCKING,	/* We're telling the server to unlock */
5570fafdc9fSDavid Howells };
5580fafdc9fSDavid Howells 
55908e0e7c8SDavid Howells /*
560f8de483eSDavid Howells  * AFS inode private data.
561f8de483eSDavid Howells  *
562f8de483eSDavid Howells  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
563f8de483eSDavid Howells  * leak from one inode to another.
56408e0e7c8SDavid Howells  */
56508e0e7c8SDavid Howells struct afs_vnode {
56608e0e7c8SDavid Howells 	struct inode		vfs_inode;	/* the VFS's inode record */
56708e0e7c8SDavid Howells 
56808e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume on which vnode resides */
56908e0e7c8SDavid Howells 	struct afs_fid		fid;		/* the file identifier for this inode */
57008e0e7c8SDavid Howells 	struct afs_file_status	status;		/* AFS status info for this file */
571a4ff7401SDavid Howells 	afs_dataversion_t	invalid_before;	/* Child dentries are invalid before this */
5729b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
5739b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
57408e0e7c8SDavid Howells #endif
575fe342cf7SDavid Howells 	struct afs_permits __rcu *permit_cache;	/* cache of permits so far obtained */
576d2ddc776SDavid Howells 	struct mutex		io_lock;	/* Lock for serialising I/O on this mutex */
577b61f7dcfSDavid Howells 	struct rw_semaphore	validate_lock;	/* lock for validating this vnode */
5784343d008SDavid Howells 	spinlock_t		wb_lock;	/* lock for wb_keys */
57908e0e7c8SDavid Howells 	spinlock_t		lock;		/* waitqueue/flags lock */
58008e0e7c8SDavid Howells 	unsigned long		flags;
581c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED	0		/* Set if vnode has a callback promise */
582260a9803SDavid Howells #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
583f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID	2		/* Set if dir contents are valid */
58408e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
58508e0e7c8SDavid Howells #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
58608e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
5870fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL	6		/* set if Vnode is an auto mount point */
5880fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR	7 		/* set if Vnode is a pseudo directory */
5895a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT	8		/* Set if file has new content (create/trunc-0) */
59008e0e7c8SDavid Howells 
5914343d008SDavid Howells 	struct list_head	wb_keys;	/* List of keys available for writeback */
592e8d6c554SDavid Howells 	struct list_head	pending_locks;	/* locks waiting to be granted */
593e8d6c554SDavid Howells 	struct list_head	granted_locks;	/* locks granted on this file */
594e8d6c554SDavid Howells 	struct delayed_work	lock_work;	/* work to be done in locking */
5950fafdc9fSDavid Howells 	struct key		*lock_key;	/* Key to be used in lock ops */
5960fafdc9fSDavid Howells 	enum afs_lock_state	lock_state : 8;
5970fafdc9fSDavid Howells 	afs_lock_type_t		lock_type : 8;
59831143d5dSDavid Howells 
59908e0e7c8SDavid Howells 	/* outstanding callback notification on this file */
600c435ee34SDavid Howells 	struct afs_cb_interest	*cb_interest;	/* Server on which this resides */
601c435ee34SDavid Howells 	unsigned int		cb_s_break;	/* Mass break counter on ->server */
60268251f0aSDavid Howells 	unsigned int		cb_v_break;	/* Mass break counter on ->volume */
603c435ee34SDavid Howells 	unsigned int		cb_break;	/* Break counter on vnode */
604c435ee34SDavid Howells 	seqlock_t		cb_lock;	/* Lock for ->cb_interest, ->status, ->cb_*break */
605c435ee34SDavid Howells 
606c435ee34SDavid Howells 	time64_t		cb_expires_at;	/* time at which callback expires */
60708e0e7c8SDavid Howells 	unsigned		cb_version;	/* callback version */
60808e0e7c8SDavid Howells 	afs_callback_type_t	cb_type;	/* type of callback */
60908e0e7c8SDavid Howells };
61008e0e7c8SDavid Howells 
61112bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
61212bdcf33SDavid Howells {
61312bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE
61412bdcf33SDavid Howells 	return vnode->cache;
61512bdcf33SDavid Howells #else
61612bdcf33SDavid Howells 	return NULL;
61712bdcf33SDavid Howells #endif
61812bdcf33SDavid Howells }
61912bdcf33SDavid Howells 
62000d3b7a4SDavid Howells /*
62100d3b7a4SDavid Howells  * cached security record for one user's attempt to access a vnode
62200d3b7a4SDavid Howells  */
62300d3b7a4SDavid Howells struct afs_permit {
62400d3b7a4SDavid Howells 	struct key		*key;		/* RxRPC ticket holding a security context */
625be080a6fSDavid Howells 	afs_access_t		access;		/* CallerAccess value for this key */
62600d3b7a4SDavid Howells };
62700d3b7a4SDavid Howells 
62800d3b7a4SDavid Howells /*
629be080a6fSDavid Howells  * Immutable cache of CallerAccess records from attempts to access vnodes.
630be080a6fSDavid Howells  * These may be shared between multiple vnodes.
63100d3b7a4SDavid Howells  */
63200d3b7a4SDavid Howells struct afs_permits {
633be080a6fSDavid Howells 	struct rcu_head		rcu;
634be080a6fSDavid Howells 	struct hlist_node	hash_node;	/* Link in hash */
635be080a6fSDavid Howells 	unsigned long		h;		/* Hash value for this permit list */
636be080a6fSDavid Howells 	refcount_t		usage;
637be080a6fSDavid Howells 	unsigned short		nr_permits;	/* Number of records */
638be080a6fSDavid Howells 	bool			invalidated;	/* Invalidated due to key change */
639be080a6fSDavid Howells 	struct afs_permit	permits[];	/* List of permits sorted by key pointer */
64000d3b7a4SDavid Howells };
64100d3b7a4SDavid Howells 
642b908fe6bSDavid Howells /*
643b908fe6bSDavid Howells  * record of one of a system's set of network interfaces
644b908fe6bSDavid Howells  */
645b908fe6bSDavid Howells struct afs_interface {
646b908fe6bSDavid Howells 	struct in_addr	address;	/* IPv4 address bound to interface */
647b908fe6bSDavid Howells 	struct in_addr	netmask;	/* netmask applied to address */
648b908fe6bSDavid Howells 	unsigned	mtu;		/* MTU of interface */
649b908fe6bSDavid Howells };
650b908fe6bSDavid Howells 
6518b2a464cSDavid Howells /*
6528b2a464cSDavid Howells  * Cursor for iterating over a server's address list.
6538b2a464cSDavid Howells  */
6548b2a464cSDavid Howells struct afs_addr_cursor {
6558b2a464cSDavid Howells 	struct afs_addr_list	*alist;		/* Current address list (pins ref) */
6568b2a464cSDavid Howells 	struct sockaddr_rxrpc	*addr;
657d2ddc776SDavid Howells 	u32			abort_code;
6588b2a464cSDavid Howells 	unsigned short		start;		/* Starting point in alist->addrs[] */
6598b2a464cSDavid Howells 	unsigned short		index;		/* Wrapping offset from start to current addr */
6608b2a464cSDavid Howells 	short			error;
6618b2a464cSDavid Howells 	bool			begun;		/* T if we've begun iteration */
6628b2a464cSDavid Howells 	bool			responded;	/* T if the current address responded */
663744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of address iterations */
6648b2a464cSDavid Howells };
6658b2a464cSDavid Howells 
6668b2a464cSDavid Howells /*
6670a5143f2SDavid Howells  * Cursor for iterating over a set of volume location servers.
6680a5143f2SDavid Howells  */
6690a5143f2SDavid Howells struct afs_vl_cursor {
6700a5143f2SDavid Howells 	struct afs_addr_cursor	ac;
6710a5143f2SDavid Howells 	struct afs_cell		*cell;		/* The cell we're querying */
6720a5143f2SDavid Howells 	struct afs_vlserver_list *server_list;	/* Current server list (pins ref) */
6730a5143f2SDavid Howells 	struct key		*key;		/* Key for the server */
6740a5143f2SDavid Howells 	unsigned char		start;		/* Initial index in server list */
6750a5143f2SDavid Howells 	unsigned char		index;		/* Number of servers tried beyond start */
6760a5143f2SDavid Howells 	short			error;
6770a5143f2SDavid Howells 	unsigned short		flags;
6780a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP	0x0001		/* Set to cease iteration */
6790a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY	0x0002		/* Set to do a retry */
6800a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED	0x0004		/* Set if started a retry */
681744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
6820a5143f2SDavid Howells };
6830a5143f2SDavid Howells 
6840a5143f2SDavid Howells /*
6858b2a464cSDavid Howells  * Cursor for iterating over a set of fileservers.
6868b2a464cSDavid Howells  */
6878b2a464cSDavid Howells struct afs_fs_cursor {
6888b2a464cSDavid Howells 	struct afs_addr_cursor	ac;
689d2ddc776SDavid Howells 	struct afs_vnode	*vnode;
690d2ddc776SDavid Howells 	struct afs_server_list	*server_list;	/* Current server list (pins ref) */
691d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Server on which this resides (pins ref) */
692d2ddc776SDavid Howells 	struct key		*key;		/* Key for the server */
693d2ddc776SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
694d2ddc776SDavid Howells 	unsigned int		cb_break_2;	/* cb_break + cb_s_break (2nd vnode) */
695d2ddc776SDavid Howells 	unsigned char		start;		/* Initial index in server list */
696d2ddc776SDavid Howells 	unsigned char		index;		/* Number of servers tried beyond start */
697e7f680f4SDavid Howells 	short			error;
698d2ddc776SDavid Howells 	unsigned short		flags;
699d2ddc776SDavid Howells #define AFS_FS_CURSOR_STOP	0x0001		/* Set to cease iteration */
700d2ddc776SDavid Howells #define AFS_FS_CURSOR_VBUSY	0x0002		/* Set if seen VBUSY */
701d2ddc776SDavid Howells #define AFS_FS_CURSOR_VMOVED	0x0004		/* Set if seen VMOVED */
702d2ddc776SDavid Howells #define AFS_FS_CURSOR_VNOVOL	0x0008		/* Set if seen VNOVOL */
703d2ddc776SDavid Howells #define AFS_FS_CURSOR_CUR_ONLY	0x0010		/* Set if current server only (file lock held) */
704d2ddc776SDavid Howells #define AFS_FS_CURSOR_NO_VSLEEP	0x0020		/* Set to prevent sleep on VBUSY, VOFFLINE, ... */
705744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
7068b2a464cSDavid Howells };
7078b2a464cSDavid Howells 
708402cb8ddSDavid Howells /*
709402cb8ddSDavid Howells  * Cache auxiliary data.
710402cb8ddSDavid Howells  */
711402cb8ddSDavid Howells struct afs_vnode_cache_aux {
712402cb8ddSDavid Howells 	u64			data_version;
713402cb8ddSDavid Howells } __packed;
714402cb8ddSDavid Howells 
71598bf40cdSDavid Howells #include <trace/events/afs.h>
71698bf40cdSDavid Howells 
71708e0e7c8SDavid Howells /*****************************************************************************/
71808e0e7c8SDavid Howells /*
7198b2a464cSDavid Howells  * addr_list.c
7208b2a464cSDavid Howells  */
7218b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
7228b2a464cSDavid Howells {
7238b2a464cSDavid Howells 	if (alist)
7248b2a464cSDavid Howells 		refcount_inc(&alist->usage);
7258b2a464cSDavid Howells 	return alist;
7268b2a464cSDavid Howells }
7278b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
7288b2a464cSDavid Howells 						unsigned short,
7298b2a464cSDavid Howells 						unsigned short);
7308b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *);
7310a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
7320a5143f2SDavid Howells 						      const char *, size_t, char,
7338b2a464cSDavid Howells 						      unsigned short, unsigned short);
7340a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
7358b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *);
7368b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *);
7378b2a464cSDavid Howells 
738bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
739bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
740d2ddc776SDavid Howells 
7418b2a464cSDavid Howells /*
7429b3f26c9SDavid Howells  * cache.c
7439b3f26c9SDavid Howells  */
7449b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
7459b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs;
7469b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def;
7479b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def;
7489b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def;
7499b3f26c9SDavid Howells #else
7509b3f26c9SDavid Howells #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
7519b3f26c9SDavid Howells #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
7529b3f26c9SDavid Howells #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
7539b3f26c9SDavid Howells #endif
7549b3f26c9SDavid Howells 
7559b3f26c9SDavid Howells /*
75608e0e7c8SDavid Howells  * callback.c
75708e0e7c8SDavid Howells  */
75808e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
75930062bd1SDavid Howells extern void __afs_break_callback(struct afs_vnode *);
760c435ee34SDavid Howells extern void afs_break_callback(struct afs_vnode *);
7615cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
762c435ee34SDavid Howells 
763d4a96becSDavid Howells extern int afs_register_server_cb_interest(struct afs_vnode *,
764d4a96becSDavid Howells 					   struct afs_server_list *, unsigned int);
765c435ee34SDavid Howells extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
766d2ddc776SDavid Howells extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
767c435ee34SDavid Howells 
768c435ee34SDavid Howells static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
769c435ee34SDavid Howells {
770d4a96becSDavid Howells 	if (cbi)
771c435ee34SDavid Howells 		refcount_inc(&cbi->usage);
772c435ee34SDavid Howells 	return cbi;
773c435ee34SDavid Howells }
7741da177e4SLinus Torvalds 
77568251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
77668251f0aSDavid Howells {
77768251f0aSDavid Howells 	return vnode->cb_break + vnode->cb_s_break + vnode->cb_v_break;
77868251f0aSDavid Howells }
77968251f0aSDavid Howells 
78068251f0aSDavid Howells static inline unsigned int afs_cb_break_sum(struct afs_vnode *vnode,
78168251f0aSDavid Howells 					    struct afs_cb_interest *cbi)
78268251f0aSDavid Howells {
78368251f0aSDavid Howells 	return vnode->cb_break + cbi->server->cb_s_break + vnode->volume->cb_v_break;
78468251f0aSDavid Howells }
78568251f0aSDavid Howells 
7861da177e4SLinus Torvalds /*
7871da177e4SLinus Torvalds  * cell.c
7881da177e4SLinus Torvalds  */
789989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
790989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
791989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
792989782dcSDavid Howells 					const char *, bool);
7938b2a464cSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *);
7949ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *);
795989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
796989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
797f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
79808e0e7c8SDavid Howells 
79908e0e7c8SDavid Howells /*
80008e0e7c8SDavid Howells  * cmservice.c
80108e0e7c8SDavid Howells  */
80208e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
80308e0e7c8SDavid Howells 
8041da177e4SLinus Torvalds /*
8051da177e4SLinus Torvalds  * dir.c
8061da177e4SLinus Torvalds  */
8074b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
8084d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
809f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops;
8104d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
8114d673da1SDavid Howells 
81266c7e1d3SDavid Howells extern void afs_d_release(struct dentry *);
81366c7e1d3SDavid Howells 
81466c7e1d3SDavid Howells /*
81563a4681fSDavid Howells  * dir_edit.c
81663a4681fSDavid Howells  */
81763a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
81863a4681fSDavid Howells 			     enum afs_edit_dir_reason);
81963a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
82063a4681fSDavid Howells 
82163a4681fSDavid Howells /*
82266c7e1d3SDavid Howells  * dynroot.c
82366c7e1d3SDavid Howells  */
82466c7e1d3SDavid Howells extern const struct file_operations afs_dynroot_file_operations;
82566c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
82666c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations;
82766c7e1d3SDavid Howells 
82866c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
8290da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
8300da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
8310da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *);
8320da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *);
8331da177e4SLinus Torvalds 
8341da177e4SLinus Torvalds /*
8351da177e4SLinus Torvalds  * file.c
8361da177e4SLinus Torvalds  */
837f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops;
838754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
83900d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
84000d3b7a4SDavid Howells 
8414343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
8424343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
84300d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
84400d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
845d2ddc776SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
846f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *);
847196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
8481da177e4SLinus Torvalds 
8491da177e4SLinus Torvalds /*
850e8d6c554SDavid Howells  * flock.c
851e8d6c554SDavid Howells  */
852f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
853f044c884SDavid Howells 
854e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
855e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
856e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
857e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
858e8d6c554SDavid Howells 
859e8d6c554SDavid Howells /*
86008e0e7c8SDavid Howells  * fsclient.c
86108e0e7c8SDavid Howells  */
862dd9fbcb8SDavid Howells #define AFS_VNODE_NOT_YET_SET	0x01
863dd9fbcb8SDavid Howells #define AFS_VNODE_META_CHANGED	0x02
864dd9fbcb8SDavid Howells #define AFS_VNODE_DATA_CHANGED	0x04
865dd9fbcb8SDavid Howells extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *,
866dd9fbcb8SDavid Howells 					 const afs_dataversion_t *, u8);
867dd9fbcb8SDavid Howells 
8680c3a5ac2SDavid Howells extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
869d2ddc776SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
870d2ddc776SDavid Howells extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
87163a4681fSDavid Howells extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, u64,
872d2ddc776SDavid Howells 			 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
87330062bd1SDavid Howells extern int afs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool, u64);
87463a4681fSDavid Howells extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
87563a4681fSDavid Howells extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
876d2ddc776SDavid Howells 			  struct afs_fid *, struct afs_file_status *);
877d2ddc776SDavid Howells extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
87863a4681fSDavid Howells 			 struct afs_vnode *, const char *, u64, u64);
8794343d008SDavid Howells extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
880d2ddc776SDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned);
881d2ddc776SDavid Howells extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
882d2ddc776SDavid Howells extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
883d2ddc776SDavid Howells extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
884d2ddc776SDavid Howells extern int afs_fs_extend_lock(struct afs_fs_cursor *);
885d2ddc776SDavid Howells extern int afs_fs_release_lock(struct afs_fs_cursor *);
886d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
887d2ddc776SDavid Howells 					struct afs_addr_cursor *, struct key *);
888d2ddc776SDavid Howells extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
889d2ddc776SDavid Howells 				   struct afs_addr_cursor *, struct key *);
8905cf9dd55SDavid Howells extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
8915cf9dd55SDavid Howells 				     struct afs_fid *, struct afs_file_status *,
8925cf9dd55SDavid Howells 				     struct afs_callback *, unsigned int,
8935cf9dd55SDavid Howells 				     struct afs_volsync *);
8945cf9dd55SDavid Howells extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
8955cf9dd55SDavid Howells 			       struct afs_fid *, struct afs_file_status *,
8965cf9dd55SDavid Howells 			       struct afs_callback *, struct afs_volsync *);
89708e0e7c8SDavid Howells 
89808e0e7c8SDavid Howells /*
8991da177e4SLinus Torvalds  * inode.c
9001da177e4SLinus Torvalds  */
9010c3a5ac2SDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool);
902c435ee34SDavid Howells extern int afs_iget5_test(struct inode *, void *);
9034d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
90400d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *,
905260a9803SDavid Howells 			      struct afs_fid *, struct afs_file_status *,
906d2ddc776SDavid Howells 			      struct afs_callback *,
907d2ddc776SDavid Howells 			      struct afs_cb_interest *);
908416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *);
909260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
910a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
91131143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *);
912b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
913bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
9141da177e4SLinus Torvalds 
9151da177e4SLinus Torvalds /*
9161da177e4SLinus Torvalds  * main.c
9171da177e4SLinus Torvalds  */
9180ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
9195b86d4ffSDavid Howells extern int afs_net_id;
9205b86d4ffSDavid Howells 
9215b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net)
9225b86d4ffSDavid Howells {
9235b86d4ffSDavid Howells 	return net_generic(net, afs_net_id);
9245b86d4ffSDavid Howells }
9255b86d4ffSDavid Howells 
9265b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb)
9275b86d4ffSDavid Howells {
9285b86d4ffSDavid Howells 	return afs_net(AFS_FS_S(sb)->net_ns);
9295b86d4ffSDavid Howells }
930f044c884SDavid Howells 
931f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
932f044c884SDavid Howells {
9335b86d4ffSDavid Howells 	return afs_sb2net(dentry->d_sb);
934f044c884SDavid Howells }
935f044c884SDavid Howells 
936f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
937f044c884SDavid Howells {
9385b86d4ffSDavid Howells 	return afs_sb2net(inode->i_sb);
939f044c884SDavid Howells }
940f044c884SDavid Howells 
941f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
942f044c884SDavid Howells {
9435b86d4ffSDavid Howells 	return afs_i2net(&vnode->vfs_inode);
944f044c884SDavid Howells }
945f044c884SDavid Howells 
946f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
947f044c884SDavid Howells {
9485b86d4ffSDavid Howells 	return net_generic(sock_net(sk), afs_net_id);
949f044c884SDavid Howells }
9501da177e4SLinus Torvalds 
951d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s)
952d55b4da4SDavid Howells {
953d55b4da4SDavid Howells 	atomic_inc(s);
954d55b4da4SDavid Howells }
955d55b4da4SDavid Howells 
956d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
957d55b4da4SDavid Howells 
9581da177e4SLinus Torvalds /*
95908e0e7c8SDavid Howells  * misc.c
96008e0e7c8SDavid Howells  */
96108e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
96208e0e7c8SDavid Howells 
96308e0e7c8SDavid Howells /*
9641da177e4SLinus Torvalds  * mntpt.c
9651da177e4SLinus Torvalds  */
966754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
967bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
9684b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
9691da177e4SLinus Torvalds 
970d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
97108e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
9721da177e4SLinus Torvalds 
9731da177e4SLinus Torvalds /*
974b4db2b35SArnd Bergmann  * netdevices.c
975b4db2b35SArnd Bergmann  */
9765b86d4ffSDavid Howells extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *,
9775b86d4ffSDavid Howells 				   size_t, bool);
978b4db2b35SArnd Bergmann 
979b4db2b35SArnd Bergmann /*
9801da177e4SLinus Torvalds  * proc.c
9811da177e4SLinus Torvalds  */
982b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS
983f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
984f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
9855b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *);
9865b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *);
9876f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *);
988b6cfbecaSDavid Howells #else
989b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; }
990b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {}
991b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
992b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
993b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
994b6cfbecaSDavid Howells #endif
9951da177e4SLinus Torvalds 
99608e0e7c8SDavid Howells /*
997d2ddc776SDavid Howells  * rotate.c
998d2ddc776SDavid Howells  */
999d2ddc776SDavid Howells extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
1000d2ddc776SDavid Howells 				      struct key *);
1001d2ddc776SDavid Howells extern bool afs_select_fileserver(struct afs_fs_cursor *);
1002d2ddc776SDavid Howells extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
1003d2ddc776SDavid Howells extern int afs_end_vnode_operation(struct afs_fs_cursor *);
1004d2ddc776SDavid Howells 
1005d2ddc776SDavid Howells /*
100608e0e7c8SDavid Howells  * rxrpc.c
100708e0e7c8SDavid Howells  */
1008f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
10098324f0bcSDavid Howells 
1010f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
1011f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
1012f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
1013341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
1014341f741fSDavid Howells extern int afs_queue_call_work(struct afs_call *);
10158b2a464cSDavid Howells extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
1016f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1017f044c884SDavid Howells 					    const struct afs_call_type *,
101808e0e7c8SDavid Howells 					    size_t, size_t);
101908e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
102008e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
1021b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
102212bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool);
1023160cb957SDavid Howells extern int afs_protocol_error(struct afs_call *, int, enum afs_eproto_cause);
102408e0e7c8SDavid Howells 
102512bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
102612bdcf33SDavid Howells {
102712bdcf33SDavid Howells 	call->kvec[0].iov_base = buf;
102812bdcf33SDavid Howells 	call->kvec[0].iov_len = size;
102912bdcf33SDavid Howells 	iov_iter_kvec(&call->iter, READ, call->kvec, 1, size);
103012bdcf33SDavid Howells }
103112bdcf33SDavid Howells 
103212bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call)
103312bdcf33SDavid Howells {
103412bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
103512bdcf33SDavid Howells }
103612bdcf33SDavid Howells 
103712bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call)
103812bdcf33SDavid Howells {
103912bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
104012bdcf33SDavid Howells }
104112bdcf33SDavid Howells 
104212bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size)
104312bdcf33SDavid Howells {
104412bdcf33SDavid Howells 	iov_iter_discard(&call->iter, READ, size);
104512bdcf33SDavid Howells }
104612bdcf33SDavid Howells 
104712bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
104812bdcf33SDavid Howells {
104912bdcf33SDavid Howells 	afs_extract_begin(call, call->buffer, size);
105012bdcf33SDavid Howells }
105112bdcf33SDavid Howells 
1052d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
1053372ee163SDavid Howells {
105412bdcf33SDavid Howells 	return afs_extract_data(call, false);
1055372ee163SDavid Howells }
1056372ee163SDavid Howells 
105798bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
105898bf40cdSDavid Howells 					enum afs_call_state state)
105998bf40cdSDavid Howells {
106098bf40cdSDavid Howells 	return READ_ONCE(call->state) == state;
106198bf40cdSDavid Howells }
106298bf40cdSDavid Howells 
106398bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
106498bf40cdSDavid Howells 				      enum afs_call_state from,
106598bf40cdSDavid Howells 				      enum afs_call_state to)
106698bf40cdSDavid Howells {
106798bf40cdSDavid Howells 	bool ok = false;
106898bf40cdSDavid Howells 
106998bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
107098bf40cdSDavid Howells 	if (call->state == from) {
107198bf40cdSDavid Howells 		call->state = to;
107298bf40cdSDavid Howells 		trace_afs_call_state(call, from, to, 0, 0);
107398bf40cdSDavid Howells 		ok = true;
107498bf40cdSDavid Howells 	}
107598bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
107698bf40cdSDavid Howells 	return ok;
107798bf40cdSDavid Howells }
107898bf40cdSDavid Howells 
107998bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
108098bf40cdSDavid Howells 					 int error, u32 remote_abort)
108198bf40cdSDavid Howells {
108298bf40cdSDavid Howells 	enum afs_call_state state;
108398bf40cdSDavid Howells 	bool ok = false;
108498bf40cdSDavid Howells 
108598bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
108698bf40cdSDavid Howells 	state = call->state;
108798bf40cdSDavid Howells 	if (state != AFS_CALL_COMPLETE) {
108898bf40cdSDavid Howells 		call->abort_code = remote_abort;
108998bf40cdSDavid Howells 		call->error = error;
109098bf40cdSDavid Howells 		call->state = AFS_CALL_COMPLETE;
109198bf40cdSDavid Howells 		trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
109298bf40cdSDavid Howells 				     error, remote_abort);
109398bf40cdSDavid Howells 		ok = true;
109498bf40cdSDavid Howells 	}
109598bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
109698bf40cdSDavid Howells 	if (ok)
109798bf40cdSDavid Howells 		trace_afs_call_done(call);
109898bf40cdSDavid Howells }
109998bf40cdSDavid Howells 
110008e0e7c8SDavid Howells /*
110100d3b7a4SDavid Howells  * security.c
110200d3b7a4SDavid Howells  */
1103be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
110400d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
1105be080a6fSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
1106416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *);
110700d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
11080fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
110910556cb2SAl Viro extern int afs_permission(struct inode *, int);
1110be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
111100d3b7a4SDavid Howells 
111200d3b7a4SDavid Howells /*
111308e0e7c8SDavid Howells  * server.c
111408e0e7c8SDavid Howells  */
111508e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
111608e0e7c8SDavid Howells 
1117c435ee34SDavid Howells static inline struct afs_server *afs_get_server(struct afs_server *server)
1118c435ee34SDavid Howells {
1119c435ee34SDavid Howells 	atomic_inc(&server->usage);
1120c435ee34SDavid Howells 	return server;
1121c435ee34SDavid Howells }
112208e0e7c8SDavid Howells 
1123f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
1124f044c884SDavid Howells 					  const struct sockaddr_rxrpc *);
1125d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
1126d2ddc776SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
11279ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *);
1128d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
1129d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
1130f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
1131d2ddc776SDavid Howells extern bool afs_probe_fileserver(struct afs_fs_cursor *);
1132d2ddc776SDavid Howells extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
1133d2ddc776SDavid Howells 
1134d2ddc776SDavid Howells /*
1135d2ddc776SDavid Howells  * server_list.c
1136d2ddc776SDavid Howells  */
1137d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1138d2ddc776SDavid Howells {
1139d2ddc776SDavid Howells 	refcount_inc(&slist->usage);
1140d2ddc776SDavid Howells 	return slist;
1141d2ddc776SDavid Howells }
1142d2ddc776SDavid Howells 
1143d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1144d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1145d2ddc776SDavid Howells 						     struct afs_vldb_entry *,
1146d2ddc776SDavid Howells 						     u8);
1147d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
114808e0e7c8SDavid Howells 
114908e0e7c8SDavid Howells /*
115000d3b7a4SDavid Howells  * super.c
115100d3b7a4SDavid Howells  */
1152f044c884SDavid Howells extern int __init afs_fs_init(void);
11535b86d4ffSDavid Howells extern void afs_fs_exit(void);
115400d3b7a4SDavid Howells 
115500d3b7a4SDavid Howells /*
115608e0e7c8SDavid Howells  * vlclient.c
115708e0e7c8SDavid Howells  */
11580a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
11590a5143f2SDavid Howells 							 const char *, int);
11600a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
1161bf99a53cSDavid Howells extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
11620a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
11630a5143f2SDavid Howells 
11640a5143f2SDavid Howells /*
11650a5143f2SDavid Howells  * vl_rotate.c
11660a5143f2SDavid Howells  */
11670a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
11680a5143f2SDavid Howells 					 struct afs_cell *, struct key *);
11690a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *);
11700a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
11710a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
11720a5143f2SDavid Howells 
11730a5143f2SDavid Howells /*
11740a5143f2SDavid Howells  * vlserver_list.c
11750a5143f2SDavid Howells  */
11760a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
11770a5143f2SDavid Howells {
11780a5143f2SDavid Howells 	atomic_inc(&vlserver->usage);
11790a5143f2SDavid Howells 	return vlserver;
11800a5143f2SDavid Howells }
11810a5143f2SDavid Howells 
11820a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
11830a5143f2SDavid Howells {
11840a5143f2SDavid Howells 	if (vllist)
11850a5143f2SDavid Howells 		atomic_inc(&vllist->usage);
11860a5143f2SDavid Howells 	return vllist;
11870a5143f2SDavid Howells }
11880a5143f2SDavid Howells 
11890a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
11900a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
11910a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
11920a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
11930a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
11940a5143f2SDavid Howells 							   const void *, size_t);
119508e0e7c8SDavid Howells 
119608e0e7c8SDavid Howells /*
119708e0e7c8SDavid Howells  * volume.c
119808e0e7c8SDavid Howells  */
1199d2ddc776SDavid Howells static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
120049566f6fSDavid Howells {
120149566f6fSDavid Howells 	if (volume)
120249566f6fSDavid Howells 		atomic_inc(&volume->usage);
120349566f6fSDavid Howells 	return volume;
120449566f6fSDavid Howells }
120508e0e7c8SDavid Howells 
1206d2ddc776SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
1207d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *);
1208d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
12099ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
1210d2ddc776SDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct key *);
121108e0e7c8SDavid Howells 
121231143d5dSDavid Howells /*
121331143d5dSDavid Howells  * write.c
121431143d5dSDavid Howells  */
121531143d5dSDavid Howells extern int afs_set_page_dirty(struct page *);
121615b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
121715b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned flags,
121815b4650eSNick Piggin 			struct page **pagep, void **fsdata);
121915b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
122015b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned copied,
122115b4650eSNick Piggin 			struct page *page, void *fsdata);
122231143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
122331143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
122431143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
122550b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
122602c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
12270722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
12284343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
12294343d008SDavid Howells extern int afs_launder_page(struct page *);
123031143d5dSDavid Howells 
1231d3e3b7eaSDavid Howells /*
1232d3e3b7eaSDavid Howells  * xattr.c
1233d3e3b7eaSDavid Howells  */
1234d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
1235d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
123631143d5dSDavid Howells 
123730062bd1SDavid Howells /*
123830062bd1SDavid Howells  * yfsclient.c
123930062bd1SDavid Howells  */
124030062bd1SDavid Howells extern int yfs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
124130062bd1SDavid Howells extern int yfs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
124230062bd1SDavid Howells extern int yfs_fs_create_file(struct afs_fs_cursor *, const char *, umode_t, u64,
124330062bd1SDavid Howells 			      struct afs_fid *, struct afs_file_status *, struct afs_callback *);
124430062bd1SDavid Howells extern int yfs_fs_make_dir(struct afs_fs_cursor *, const char *, umode_t, u64,
124530062bd1SDavid Howells 			 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
124630062bd1SDavid Howells extern int yfs_fs_remove_file2(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
124730062bd1SDavid Howells extern int yfs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool, u64);
124830062bd1SDavid Howells extern int yfs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
124930062bd1SDavid Howells extern int yfs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
125030062bd1SDavid Howells 			  struct afs_fid *, struct afs_file_status *);
125130062bd1SDavid Howells extern int yfs_fs_rename(struct afs_fs_cursor *, const char *,
125230062bd1SDavid Howells 			 struct afs_vnode *, const char *, u64, u64);
125330062bd1SDavid Howells extern int yfs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
125430062bd1SDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned);
125530062bd1SDavid Howells extern int yfs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
125630062bd1SDavid Howells extern int yfs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
125730062bd1SDavid Howells extern int yfs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
125830062bd1SDavid Howells extern int yfs_fs_extend_lock(struct afs_fs_cursor *);
125930062bd1SDavid Howells extern int yfs_fs_release_lock(struct afs_fs_cursor *);
126030062bd1SDavid Howells extern int yfs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
126130062bd1SDavid Howells 			       struct afs_fid *, struct afs_file_status *,
126230062bd1SDavid Howells 			       struct afs_callback *, struct afs_volsync *);
126330062bd1SDavid Howells extern int yfs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
126430062bd1SDavid Howells 				     struct afs_fid *, struct afs_file_status *,
126530062bd1SDavid Howells 				     struct afs_callback *, unsigned int,
126630062bd1SDavid Howells 				     struct afs_volsync *);
1267d2ddc776SDavid Howells 
1268d2ddc776SDavid Howells /*
1269d2ddc776SDavid Howells  * Miscellaneous inline functions.
1270d2ddc776SDavid Howells  */
1271d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1272d2ddc776SDavid Howells {
1273d2ddc776SDavid Howells 	return container_of(inode, struct afs_vnode, vfs_inode);
1274d2ddc776SDavid Howells }
1275d2ddc776SDavid Howells 
1276d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1277d2ddc776SDavid Howells {
1278d2ddc776SDavid Howells 	return &vnode->vfs_inode;
1279d2ddc776SDavid Howells }
1280d2ddc776SDavid Howells 
1281d2ddc776SDavid Howells static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
1282d2ddc776SDavid Howells 					   struct afs_vnode *vnode,
1283d2ddc776SDavid Howells 					   unsigned int cb_break)
1284d2ddc776SDavid Howells {
1285d2ddc776SDavid Howells 	if (fc->ac.error == 0)
1286d2ddc776SDavid Howells 		afs_cache_permit(vnode, fc->key, cb_break);
1287d2ddc776SDavid Howells }
1288d2ddc776SDavid Howells 
1289d2ddc776SDavid Howells static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1290d2ddc776SDavid Howells 						 struct afs_vnode *vnode)
1291d2ddc776SDavid Howells {
1292d2ddc776SDavid Howells 	if (fc->ac.error == -ENOENT) {
1293d2ddc776SDavid Howells 		set_bit(AFS_VNODE_DELETED, &vnode->flags);
1294d2ddc776SDavid Howells 		afs_break_callback(vnode);
1295d2ddc776SDavid Howells 	}
1296d2ddc776SDavid Howells }
1297d2ddc776SDavid Howells 
1298f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1299f51375cdSDavid Howells {
1300f51375cdSDavid Howells 	trace_afs_io_error(call->debug_id, -EIO, where);
1301f51375cdSDavid Howells 	return -EIO;
1302f51375cdSDavid Howells }
1303f51375cdSDavid Howells 
1304f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1305f51375cdSDavid Howells {
1306f51375cdSDavid Howells 	trace_afs_file_error(vnode, -EIO, where);
1307f51375cdSDavid Howells 	return -EIO;
1308f51375cdSDavid Howells }
1309d2ddc776SDavid Howells 
131008e0e7c8SDavid Howells /*****************************************************************************/
131108e0e7c8SDavid Howells /*
131208e0e7c8SDavid Howells  * debug tracing
131308e0e7c8SDavid Howells  */
131408e0e7c8SDavid Howells extern unsigned afs_debug;
131508e0e7c8SDavid Howells 
131608e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1317ad16df84SSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
131808e0e7c8SDavid Howells 
1319530b6412SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1320530b6412SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
132108e0e7c8SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
132208e0e7c8SDavid Howells 
132308e0e7c8SDavid Howells 
132408e0e7c8SDavid Howells #if defined(__KDEBUG)
132508e0e7c8SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
132608e0e7c8SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
132708e0e7c8SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
132808e0e7c8SDavid Howells 
132908e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
133008e0e7c8SDavid Howells #define AFS_DEBUG_KENTER	0x01
133108e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE	0x02
133208e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG	0x04
133308e0e7c8SDavid Howells 
133408e0e7c8SDavid Howells #define _enter(FMT,...)					\
133508e0e7c8SDavid Howells do {							\
133608e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
133708e0e7c8SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
133808e0e7c8SDavid Howells } while (0)
133908e0e7c8SDavid Howells 
134008e0e7c8SDavid Howells #define _leave(FMT,...)					\
134108e0e7c8SDavid Howells do {							\
134208e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
134308e0e7c8SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
134408e0e7c8SDavid Howells } while (0)
134508e0e7c8SDavid Howells 
134608e0e7c8SDavid Howells #define _debug(FMT,...)					\
134708e0e7c8SDavid Howells do {							\
134808e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
134908e0e7c8SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
135008e0e7c8SDavid Howells } while (0)
135108e0e7c8SDavid Howells 
135208e0e7c8SDavid Howells #else
135312fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
135412fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
135512fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
135608e0e7c8SDavid Howells #endif
135708e0e7c8SDavid Howells 
135808e0e7c8SDavid Howells /*
135908e0e7c8SDavid Howells  * debug assertion checking
136008e0e7c8SDavid Howells  */
136108e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
136208e0e7c8SDavid Howells 
136308e0e7c8SDavid Howells #define ASSERT(X)						\
136408e0e7c8SDavid Howells do {								\
136508e0e7c8SDavid Howells 	if (unlikely(!(X))) {					\
136608e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
136708e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
136808e0e7c8SDavid Howells 		BUG();						\
136908e0e7c8SDavid Howells 	}							\
137008e0e7c8SDavid Howells } while(0)
137108e0e7c8SDavid Howells 
137208e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)						\
137308e0e7c8SDavid Howells do {									\
137408e0e7c8SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
137508e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
137608e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
137708e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
137808e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
137908e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
138008e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
138108e0e7c8SDavid Howells 		BUG();							\
138208e0e7c8SDavid Howells 	}								\
138308e0e7c8SDavid Howells } while(0)
138408e0e7c8SDavid Howells 
1385416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)					\
1386416351f2SDavid Howells do {									\
1387416351f2SDavid Howells 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
1388416351f2SDavid Howells 		printk(KERN_ERR "\n");					\
1389416351f2SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1390416351f2SDavid Howells 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
1391416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1392416351f2SDavid Howells 		       (unsigned long)(H));				\
1393416351f2SDavid Howells 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1394416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1395416351f2SDavid Howells 		       (unsigned long)(H));				\
1396416351f2SDavid Howells 		BUG();							\
1397416351f2SDavid Howells 	}								\
1398416351f2SDavid Howells } while(0)
1399416351f2SDavid Howells 
140008e0e7c8SDavid Howells #define ASSERTIF(C, X)						\
140108e0e7c8SDavid Howells do {								\
140208e0e7c8SDavid Howells 	if (unlikely((C) && !(X))) {				\
140308e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
140408e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
140508e0e7c8SDavid Howells 		BUG();						\
140608e0e7c8SDavid Howells 	}							\
140708e0e7c8SDavid Howells } while(0)
140808e0e7c8SDavid Howells 
140908e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
141008e0e7c8SDavid Howells do {									\
141108e0e7c8SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
141208e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
141308e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
141408e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
141508e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
141608e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
141708e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
141808e0e7c8SDavid Howells 		BUG();							\
141908e0e7c8SDavid Howells 	}								\
142008e0e7c8SDavid Howells } while(0)
142108e0e7c8SDavid Howells 
142208e0e7c8SDavid Howells #else
142308e0e7c8SDavid Howells 
142408e0e7c8SDavid Howells #define ASSERT(X)				\
142508e0e7c8SDavid Howells do {						\
142608e0e7c8SDavid Howells } while(0)
142708e0e7c8SDavid Howells 
142808e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)			\
142908e0e7c8SDavid Howells do {						\
143008e0e7c8SDavid Howells } while(0)
143108e0e7c8SDavid Howells 
1432416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)		\
1433416351f2SDavid Howells do {						\
1434416351f2SDavid Howells } while(0)
1435416351f2SDavid Howells 
143608e0e7c8SDavid Howells #define ASSERTIF(C, X)				\
143708e0e7c8SDavid Howells do {						\
143808e0e7c8SDavid Howells } while(0)
143908e0e7c8SDavid Howells 
144008e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
144108e0e7c8SDavid Howells do {						\
144208e0e7c8SDavid Howells } while(0)
144308e0e7c8SDavid Howells 
144408e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1445