xref: /openbmc/linux/fs/afs/internal.h (revision 5cf9dd55)
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>
24f044c884SDavid Howells #include <net/net_namespace.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 
3500d3b7a4SDavid Howells struct afs_mount_params {
3600d3b7a4SDavid Howells 	bool			rwpath;		/* T if the parent should be considered R/W */
3700d3b7a4SDavid Howells 	bool			force;		/* T to force cell type */
38bec5eb61Swanglei 	bool			autocell;	/* T if set auto mount operation */
394d673da1SDavid Howells 	bool			dyn_root;	/* T if dynamic root */
4000d3b7a4SDavid Howells 	afs_voltype_t		type;		/* type of volume requested */
4100d3b7a4SDavid Howells 	int			volnamesz;	/* size of volume name */
4200d3b7a4SDavid Howells 	const char		*volname;	/* name of volume to mount */
43f044c884SDavid Howells 	struct afs_net		*net;		/* Network namespace in effect */
4400d3b7a4SDavid Howells 	struct afs_cell		*cell;		/* cell in which to find volume */
4500d3b7a4SDavid Howells 	struct afs_volume	*volume;	/* volume record */
4600d3b7a4SDavid Howells 	struct key		*key;		/* key to use for secure mounting */
4700d3b7a4SDavid Howells };
4800d3b7a4SDavid Howells 
49c435ee34SDavid Howells struct afs_iget_data {
50c435ee34SDavid Howells 	struct afs_fid		fid;
51c435ee34SDavid Howells 	struct afs_volume	*volume;	/* volume on which resides */
52c435ee34SDavid Howells };
53c435ee34SDavid Howells 
548e8d7f13SDavid Howells enum afs_call_state {
5598bf40cdSDavid Howells 	AFS_CALL_CL_REQUESTING,		/* Client: Request is being sent */
5698bf40cdSDavid Howells 	AFS_CALL_CL_AWAIT_REPLY,	/* Client: Awaiting reply */
5798bf40cdSDavid Howells 	AFS_CALL_CL_PROC_REPLY,		/* Client: rxrpc call complete; processing reply */
5898bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_OP_ID,	/* Server: Awaiting op ID */
5998bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_REQUEST,	/* Server: Awaiting request data */
6098bf40cdSDavid Howells 	AFS_CALL_SV_REPLYING,		/* Server: Replying */
6198bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_ACK,		/* Server: Awaiting final ACK */
628e8d7f13SDavid Howells 	AFS_CALL_COMPLETE,		/* Completed or failed */
638e8d7f13SDavid Howells };
64f044c884SDavid Howells 
6508e0e7c8SDavid Howells /*
668b2a464cSDavid Howells  * List of server addresses.
678b2a464cSDavid Howells  */
688b2a464cSDavid Howells struct afs_addr_list {
698b2a464cSDavid Howells 	struct rcu_head		rcu;		/* Must be first */
708b2a464cSDavid Howells 	refcount_t		usage;
71d2ddc776SDavid Howells 	u32			version;	/* Version */
728b2a464cSDavid Howells 	unsigned short		nr_addrs;
738b2a464cSDavid Howells 	unsigned short		index;		/* Address currently in use */
74d2ddc776SDavid Howells 	unsigned short		nr_ipv4;	/* Number of IPv4 addresses */
75bf99a53cSDavid Howells 	unsigned long		probed;		/* Mask of servers that have been probed */
76bf99a53cSDavid Howells 	unsigned long		yfs;		/* Mask of servers that are YFS */
778b2a464cSDavid Howells 	struct sockaddr_rxrpc	addrs[];
788b2a464cSDavid Howells };
798b2a464cSDavid Howells 
808b2a464cSDavid Howells /*
8108e0e7c8SDavid Howells  * a record of an in-progress RxRPC call
8208e0e7c8SDavid Howells  */
8308e0e7c8SDavid Howells struct afs_call {
8408e0e7c8SDavid Howells 	const struct afs_call_type *type;	/* type of call */
8508e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* processes awaiting completion */
86341f741fSDavid Howells 	struct work_struct	async_work;	/* async I/O processor */
8708e0e7c8SDavid Howells 	struct work_struct	work;		/* actual work processor */
8808e0e7c8SDavid Howells 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
8908e0e7c8SDavid Howells 	struct key		*key;		/* security for this call */
90f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
91d0676a16SDavid Howells 	struct afs_server	*cm_server;	/* Server affected by incoming CM call */
92d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Callback interest for server used */
9308e0e7c8SDavid Howells 	void			*request;	/* request data (first part) */
944343d008SDavid Howells 	struct address_space	*mapping;	/* Pages being written from */
9508e0e7c8SDavid Howells 	void			*buffer;	/* reply receive buffer */
9697e3043aSDavid Howells 	void			*reply[4];	/* Where to put the reply */
9731143d5dSDavid Howells 	pgoff_t			first;		/* first page in mapping to deal with */
9831143d5dSDavid Howells 	pgoff_t			last;		/* last page in mapping to deal with */
99d001648eSDavid Howells 	size_t			offset;		/* offset into received data store */
100341f741fSDavid Howells 	atomic_t		usage;
1018e8d7f13SDavid Howells 	enum afs_call_state	state;
10298bf40cdSDavid Howells 	spinlock_t		state_lock;
10308e0e7c8SDavid Howells 	int			error;		/* error code */
104d001648eSDavid Howells 	u32			abort_code;	/* Remote abort ID or 0 */
10508e0e7c8SDavid Howells 	unsigned		request_size;	/* size of request data */
10608e0e7c8SDavid Howells 	unsigned		reply_max;	/* maximum size of reply */
10731143d5dSDavid Howells 	unsigned		first_offset;	/* offset into mapping[first] */
108c435ee34SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
109bcd89270SMarc Dionne 	union {
11031143d5dSDavid Howells 		unsigned	last_to;	/* amount of mapping[last] */
111bcd89270SMarc Dionne 		unsigned	count2;		/* count used in unmarshalling */
112bcd89270SMarc Dionne 	};
11308e0e7c8SDavid Howells 	unsigned char		unmarshall;	/* unmarshalling phase */
11408e0e7c8SDavid Howells 	bool			incoming;	/* T if incoming call */
11531143d5dSDavid Howells 	bool			send_pages;	/* T if data from mapping should be sent */
116d001648eSDavid Howells 	bool			need_attention;	/* T if RxRPC poked us */
11756ff9c83SDavid Howells 	bool			async;		/* T if asynchronous */
11833cd7f2bSDavid Howells 	bool			ret_reply0;	/* T if should return reply[0] on success */
119a68f4a27SDavid Howells 	bool			upgrade;	/* T to request service upgrade */
120bf99a53cSDavid Howells 	u16			service_id;	/* Actual service ID (after upgrade) */
121a25e21f0SDavid Howells 	unsigned int		debug_id;	/* Trace ID */
12250a2c953SDavid Howells 	u32			operation_ID;	/* operation ID for an incoming call */
12308e0e7c8SDavid Howells 	u32			count;		/* count for use in unmarshalling */
12408e0e7c8SDavid Howells 	__be32			tmp;		/* place to extract temporary data */
12531143d5dSDavid Howells 	afs_dataversion_t	store_version;	/* updated version expected from store */
12608e0e7c8SDavid Howells };
12708e0e7c8SDavid Howells 
12808e0e7c8SDavid Howells struct afs_call_type {
12900d3b7a4SDavid Howells 	const char *name;
130025db80cSDavid Howells 	unsigned int op; /* Really enum afs_fs_operation */
13100d3b7a4SDavid Howells 
13208e0e7c8SDavid Howells 	/* deliver request or reply data to an call
13308e0e7c8SDavid Howells 	 * - returning an error will cause the call to be aborted
13408e0e7c8SDavid Howells 	 */
135d001648eSDavid Howells 	int (*deliver)(struct afs_call *call);
13608e0e7c8SDavid Howells 
13708e0e7c8SDavid Howells 	/* clean up a call */
13808e0e7c8SDavid Howells 	void (*destructor)(struct afs_call *call);
139341f741fSDavid Howells 
140341f741fSDavid Howells 	/* Work function */
141341f741fSDavid Howells 	void (*work)(struct work_struct *work);
14208e0e7c8SDavid Howells };
14308e0e7c8SDavid Howells 
14408e0e7c8SDavid Howells /*
1454343d008SDavid Howells  * Key available for writeback on a file.
1464343d008SDavid Howells  */
1474343d008SDavid Howells struct afs_wb_key {
1484343d008SDavid Howells 	refcount_t		usage;
1494343d008SDavid Howells 	struct key		*key;
1504343d008SDavid Howells 	struct list_head	vnode_link;	/* Link in vnode->wb_keys */
1514343d008SDavid Howells };
1524343d008SDavid Howells 
1534343d008SDavid Howells /*
154215804a9SDavid Howells  * AFS open file information record.  Pointed to by file->private_data.
155215804a9SDavid Howells  */
156215804a9SDavid Howells struct afs_file {
157215804a9SDavid Howells 	struct key		*key;		/* The key this file was opened with */
1584343d008SDavid Howells 	struct afs_wb_key	*wb;		/* Writeback key record for this file */
159215804a9SDavid Howells };
160215804a9SDavid Howells 
161215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
162215804a9SDavid Howells {
163215804a9SDavid Howells 	struct afs_file *af = file->private_data;
164215804a9SDavid Howells 
165215804a9SDavid Howells 	return af->key;
166215804a9SDavid Howells }
167215804a9SDavid Howells 
168215804a9SDavid Howells /*
169196ee9cdSDavid Howells  * Record of an outstanding read operation on a vnode.
170196ee9cdSDavid Howells  */
171196ee9cdSDavid Howells struct afs_read {
172196ee9cdSDavid Howells 	loff_t			pos;		/* Where to start reading */
173e8e581a8SDavid Howells 	loff_t			len;		/* How much we're asking for */
174196ee9cdSDavid Howells 	loff_t			actual_len;	/* How much we're actually getting */
1756a0e3999SDavid Howells 	loff_t			remain;		/* Amount remaining */
176196ee9cdSDavid Howells 	atomic_t		usage;
177196ee9cdSDavid Howells 	unsigned int		index;		/* Which page we're reading into */
178196ee9cdSDavid Howells 	unsigned int		nr_pages;
179196ee9cdSDavid Howells 	void (*page_done)(struct afs_call *, struct afs_read *);
180196ee9cdSDavid Howells 	struct page		*pages[];
181196ee9cdSDavid Howells };
182196ee9cdSDavid Howells 
183196ee9cdSDavid Howells /*
18408e0e7c8SDavid Howells  * AFS superblock private data
18508e0e7c8SDavid Howells  * - there's one superblock per volume
18608e0e7c8SDavid Howells  */
18708e0e7c8SDavid Howells struct afs_super_info {
188f044c884SDavid Howells 	struct afs_net		*net;		/* Network namespace */
18949566f6fSDavid Howells 	struct afs_cell		*cell;		/* The cell in which the volume resides */
19008e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume record */
1914d673da1SDavid Howells 	bool			dyn_root;	/* True if dynamic root */
19208e0e7c8SDavid Howells };
19308e0e7c8SDavid Howells 
19408e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
19508e0e7c8SDavid Howells {
19608e0e7c8SDavid Howells 	return sb->s_fs_info;
19708e0e7c8SDavid Howells }
19808e0e7c8SDavid Howells 
19908e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
20008e0e7c8SDavid Howells 
20108e0e7c8SDavid Howells /*
202f044c884SDavid Howells  * AFS network namespace record.
203f044c884SDavid Howells  */
204f044c884SDavid Howells struct afs_net {
205f044c884SDavid Howells 	struct afs_uuid		uuid;
206f044c884SDavid Howells 	bool			live;		/* F if this namespace is being removed */
207f044c884SDavid Howells 
208f044c884SDavid Howells 	/* AF_RXRPC I/O stuff */
209f044c884SDavid Howells 	struct socket		*socket;
210f044c884SDavid Howells 	struct afs_call		*spare_incoming_call;
211f044c884SDavid Howells 	struct work_struct	charge_preallocation_work;
212f044c884SDavid Howells 	struct mutex		socket_mutex;
213f044c884SDavid Howells 	atomic_t		nr_outstanding_calls;
214f044c884SDavid Howells 	atomic_t		nr_superblocks;
215f044c884SDavid Howells 
216f044c884SDavid Howells 	/* Cell database */
217989782dcSDavid Howells 	struct rb_root		cells;
218f044c884SDavid Howells 	struct afs_cell		*ws_cell;
219989782dcSDavid Howells 	struct work_struct	cells_manager;
220989782dcSDavid Howells 	struct timer_list	cells_timer;
221989782dcSDavid Howells 	atomic_t		cells_outstanding;
222989782dcSDavid Howells 	seqlock_t		cells_lock;
223f044c884SDavid Howells 
224989782dcSDavid Howells 	spinlock_t		proc_cells_lock;
225f044c884SDavid Howells 	struct list_head	proc_cells;
226f044c884SDavid Howells 
227d2ddc776SDavid Howells 	/* Known servers.  Theoretically each fileserver can only be in one
228d2ddc776SDavid Howells 	 * cell, but in practice, people create aliases and subsets and there's
229d2ddc776SDavid Howells 	 * no easy way to distinguish them.
230d2ddc776SDavid Howells 	 */
231d2ddc776SDavid Howells 	seqlock_t		fs_lock;	/* For fs_servers */
232d2ddc776SDavid Howells 	struct rb_root		fs_servers;	/* afs_server (by server UUID or address) */
233d2ddc776SDavid Howells 	struct list_head	fs_updates;	/* afs_server (by update_at) */
234d2ddc776SDavid Howells 	struct hlist_head	fs_proc;	/* procfs servers list */
235d2ddc776SDavid Howells 
236d2ddc776SDavid Howells 	struct hlist_head	fs_addresses4;	/* afs_server (by lowest IPv4 addr) */
237d2ddc776SDavid Howells 	struct hlist_head	fs_addresses6;	/* afs_server (by lowest IPv6 addr) */
238d2ddc776SDavid Howells 	seqlock_t		fs_addr_lock;	/* For fs_addresses[46] */
239d2ddc776SDavid Howells 
240d2ddc776SDavid Howells 	struct work_struct	fs_manager;
241d2ddc776SDavid Howells 	struct timer_list	fs_timer;
242d2ddc776SDavid Howells 	atomic_t		servers_outstanding;
243f044c884SDavid Howells 
244f044c884SDavid Howells 	/* File locking renewal management */
245f044c884SDavid Howells 	struct mutex		lock_manager_mutex;
246f044c884SDavid Howells 
247f044c884SDavid Howells 	/* Misc */
248f044c884SDavid Howells 	struct proc_dir_entry	*proc_afs;		/* /proc/net/afs directory */
249f044c884SDavid Howells };
250f044c884SDavid Howells 
251f044c884SDavid Howells extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
252f044c884SDavid Howells 
253989782dcSDavid Howells enum afs_cell_state {
254989782dcSDavid Howells 	AFS_CELL_UNSET,
255989782dcSDavid Howells 	AFS_CELL_ACTIVATING,
256989782dcSDavid Howells 	AFS_CELL_ACTIVE,
257989782dcSDavid Howells 	AFS_CELL_DEACTIVATING,
258989782dcSDavid Howells 	AFS_CELL_INACTIVE,
259989782dcSDavid Howells 	AFS_CELL_FAILED,
260989782dcSDavid Howells };
261989782dcSDavid Howells 
262f044c884SDavid Howells /*
263d2ddc776SDavid Howells  * AFS cell record.
264d2ddc776SDavid Howells  *
265d2ddc776SDavid Howells  * This is a tricky concept to get right as it is possible to create aliases
266d2ddc776SDavid Howells  * simply by pointing AFSDB/SRV records for two names at the same set of VL
267d2ddc776SDavid Howells  * servers; it is also possible to do things like setting up two sets of VL
268d2ddc776SDavid Howells  * servers, one of which provides a superset of the volumes provided by the
269d2ddc776SDavid Howells  * other (for internal/external division, for example).
270d2ddc776SDavid Howells  *
271d2ddc776SDavid Howells  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
272d2ddc776SDavid Howells  * servers and (b) a cell's name is used by the client to select the key to use
273d2ddc776SDavid Howells  * for authentication and encryption.  The cell name is not typically used in
274d2ddc776SDavid Howells  * the protocol.
275d2ddc776SDavid Howells  *
276d2ddc776SDavid Howells  * There is no easy way to determine if two cells are aliases or one is a
277d2ddc776SDavid Howells  * subset of another.
27808e0e7c8SDavid Howells  */
27908e0e7c8SDavid Howells struct afs_cell {
280989782dcSDavid Howells 	union {
281989782dcSDavid Howells 		struct rcu_head	rcu;
282989782dcSDavid Howells 		struct rb_node	net_node;	/* Node in net->cells */
283989782dcSDavid Howells 	};
284989782dcSDavid Howells 	struct afs_net		*net;
28500d3b7a4SDavid Howells 	struct key		*anonymous_key;	/* anonymous user key for this cell */
286989782dcSDavid Howells 	struct work_struct	manager;	/* Manager for init/deinit/dns */
28708e0e7c8SDavid Howells 	struct list_head	proc_link;	/* /proc cell list link */
2889b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
2899b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
2901da177e4SLinus Torvalds #endif
291989782dcSDavid Howells 	time64_t		dns_expiry;	/* Time AFSDB/SRV record expires */
292989782dcSDavid Howells 	time64_t		last_inactive;	/* Time of last drop of usage count */
293989782dcSDavid Howells 	atomic_t		usage;
294989782dcSDavid Howells 	unsigned long		flags;
295989782dcSDavid Howells #define AFS_CELL_FL_NOT_READY	0		/* The cell record is not ready for use */
296989782dcSDavid Howells #define AFS_CELL_FL_NO_GC	1		/* The cell was added manually, don't auto-gc */
297989782dcSDavid Howells #define AFS_CELL_FL_NOT_FOUND	2		/* Permanent DNS error */
298989782dcSDavid Howells #define AFS_CELL_FL_DNS_FAIL	3		/* Failed to access DNS */
2998b2a464cSDavid Howells #define AFS_CELL_FL_NO_LOOKUP_YET 4		/* Not completed first DNS lookup yet */
300989782dcSDavid Howells 	enum afs_cell_state	state;
301989782dcSDavid Howells 	short			error;
302989782dcSDavid Howells 
303d2ddc776SDavid Howells 	/* Active fileserver interaction state. */
304d2ddc776SDavid Howells 	struct list_head	proc_volumes;	/* procfs volume list */
305d2ddc776SDavid Howells 	rwlock_t		proc_lock;
306989782dcSDavid Howells 
307d2ddc776SDavid Howells 	/* VL server list. */
3088b2a464cSDavid Howells 	rwlock_t		vl_addrs_lock;	/* Lock on vl_addrs */
3098b2a464cSDavid Howells 	struct afs_addr_list	__rcu *vl_addrs; /* List of VL servers */
310989782dcSDavid Howells 	u8			name_len;	/* Length of name */
311989782dcSDavid Howells 	char			name[64 + 1];	/* Cell name, case-flattened and NUL-padded */
31208e0e7c8SDavid Howells };
31308e0e7c8SDavid Howells 
31408e0e7c8SDavid Howells /*
315d2ddc776SDavid Howells  * Cached VLDB entry.
316d2ddc776SDavid Howells  *
317d2ddc776SDavid Howells  * This is pointed to by cell->vldb_entries, indexed by name.
31808e0e7c8SDavid Howells  */
319d2ddc776SDavid Howells struct afs_vldb_entry {
320d2ddc776SDavid Howells 	afs_volid_t		vid[3];		/* Volume IDs for R/W, R/O and Bak volumes */
32100d3b7a4SDavid Howells 
322d2ddc776SDavid Howells 	unsigned long		flags;
323d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW		0		/* - R/W volume exists */
324d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO		1		/* - R/O volume exists */
325d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK	2		/* - Backup volume exists */
326d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID	3		/* - Record is valid */
327d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR	4		/* - VL server returned error */
328d2ddc776SDavid Howells 
329d2ddc776SDavid Howells 	uuid_t			fs_server[AFS_NMAXNSERVERS];
330d2ddc776SDavid Howells 	u8			fs_mask[AFS_NMAXNSERVERS];
33108e0e7c8SDavid Howells #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
33208e0e7c8SDavid Howells #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
33308e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
334d2ddc776SDavid Howells 	short			error;
335d2ddc776SDavid Howells 	u8			nr_servers;	/* Number of server records */
336d2ddc776SDavid Howells 	u8			name_len;
337d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
33808e0e7c8SDavid Howells };
33908e0e7c8SDavid Howells 
34008e0e7c8SDavid Howells /*
341d2ddc776SDavid Howells  * Record of fileserver with which we're actively communicating.
34208e0e7c8SDavid Howells  */
34308e0e7c8SDavid Howells struct afs_server {
344d2ddc776SDavid Howells 	struct rcu_head		rcu;
345d2ddc776SDavid Howells 	union {
346d2ddc776SDavid Howells 		uuid_t		uuid;		/* Server ID */
347d2ddc776SDavid Howells 		struct afs_uuid	_uuid;
348d2ddc776SDavid Howells 	};
349c435ee34SDavid Howells 
350d2ddc776SDavid Howells 	struct afs_addr_list	__rcu *addresses;
351d2ddc776SDavid Howells 	struct rb_node		uuid_rb;	/* Link in net->servers */
352d2ddc776SDavid Howells 	struct hlist_node	addr4_link;	/* Link in net->fs_addresses4 */
353d2ddc776SDavid Howells 	struct hlist_node	addr6_link;	/* Link in net->fs_addresses6 */
354d2ddc776SDavid Howells 	struct hlist_node	proc_link;	/* Link in net->fs_proc */
355d2ddc776SDavid Howells 	struct afs_server	*gc_next;	/* Next server in manager's list */
356d2ddc776SDavid Howells 	time64_t		put_time;	/* Time at which last put */
357d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update the record */
358c435ee34SDavid Howells 	unsigned long		flags;
359d2ddc776SDavid Howells #define AFS_SERVER_FL_NEW	0		/* New server, don't inc cb_s_break */
360d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_READY	1		/* The record is not ready for use */
361d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_FOUND	2		/* VL server says no such server */
362d2ddc776SDavid Howells #define AFS_SERVER_FL_VL_FAIL	3		/* Failed to access VL server */
363d2ddc776SDavid Howells #define AFS_SERVER_FL_UPDATING	4
364d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBED	5		/* The fileserver has been probed */
365d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBING	6		/* Fileserver is being probed */
3665cf9dd55SDavid Howells #define AFS_SERVER_FL_NO_IBULK	7		/* Fileserver doesn't support FS.InlineBulkStatus */
367d2ddc776SDavid Howells 	atomic_t		usage;
368d2ddc776SDavid Howells 	u32			addr_version;	/* Address list version */
36908e0e7c8SDavid Howells 
37008e0e7c8SDavid Howells 	/* file service access */
371d2ddc776SDavid Howells 	rwlock_t		fs_lock;	/* access lock */
37208e0e7c8SDavid Howells 
37308e0e7c8SDavid Howells 	/* callback promise management */
374c435ee34SDavid Howells 	struct list_head	cb_interests;	/* List of superblocks using this server */
375c435ee34SDavid Howells 	unsigned		cb_s_break;	/* Break-everything counter. */
376c435ee34SDavid Howells 	rwlock_t		cb_break_lock;	/* Volume finding lock */
377c435ee34SDavid Howells };
378c435ee34SDavid Howells 
379c435ee34SDavid Howells /*
380c435ee34SDavid Howells  * Interest by a superblock on a server.
381c435ee34SDavid Howells  */
382c435ee34SDavid Howells struct afs_cb_interest {
383c435ee34SDavid Howells 	struct list_head	cb_link;	/* Link in server->cb_interests */
384c435ee34SDavid Howells 	struct afs_server	*server;	/* Server on which this interest resides */
385c435ee34SDavid Howells 	struct super_block	*sb;		/* Superblock on which inodes reside */
386c435ee34SDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
387c435ee34SDavid Howells 	refcount_t		usage;
38808e0e7c8SDavid Howells };
38908e0e7c8SDavid Howells 
39008e0e7c8SDavid Howells /*
391d2ddc776SDavid Howells  * Replaceable server list.
39208e0e7c8SDavid Howells  */
393d2ddc776SDavid Howells struct afs_server_entry {
394d2ddc776SDavid Howells 	struct afs_server	*server;
395d2ddc776SDavid Howells 	struct afs_cb_interest	*cb_interest;
396d2ddc776SDavid Howells };
397d2ddc776SDavid Howells 
398d2ddc776SDavid Howells struct afs_server_list {
399d2ddc776SDavid Howells 	refcount_t		usage;
400d2ddc776SDavid Howells 	unsigned short		nr_servers;
401d2ddc776SDavid Howells 	unsigned short		index;		/* Server currently in use */
402d2ddc776SDavid Howells 	unsigned short		vnovol_mask;	/* Servers to be skipped due to VNOVOL */
403d2ddc776SDavid Howells 	unsigned int		seq;		/* Set to ->servers_seq when installed */
404d2ddc776SDavid Howells 	struct afs_server_entry	servers[];
40508e0e7c8SDavid Howells };
40608e0e7c8SDavid Howells 
40708e0e7c8SDavid Howells /*
408d2ddc776SDavid Howells  * Live AFS volume management.
40908e0e7c8SDavid Howells  */
410d2ddc776SDavid Howells struct afs_volume {
411d2ddc776SDavid Howells 	afs_volid_t		vid;		/* volume ID */
412d2ddc776SDavid Howells 	atomic_t		usage;
413d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update */
414d2ddc776SDavid Howells 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
415d2ddc776SDavid Howells 	struct list_head	proc_link;	/* Link in cell->vl_proc */
416d2ddc776SDavid Howells 	unsigned long		flags;
417d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE	0	/* - T if an update needs performing */
418d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING	1	/* - T if an update is in progress */
419d2ddc776SDavid Howells #define AFS_VOLUME_WAIT		2	/* - T if users must wait for update */
420d2ddc776SDavid Howells #define AFS_VOLUME_DELETED	3	/* - T if volume appears deleted */
421d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE	4	/* - T if volume offline notice given */
422d2ddc776SDavid Howells #define AFS_VOLUME_BUSY		5	/* - T if volume busy notice given */
423d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
424d2ddc776SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
425d2ddc776SDavid Howells #endif
426d2ddc776SDavid Howells 	struct afs_server_list	*servers;	/* List of servers on which volume resides */
427d2ddc776SDavid Howells 	rwlock_t		servers_lock;	/* Lock for ->servers */
428d2ddc776SDavid Howells 	unsigned int		servers_seq;	/* Incremented each time ->servers changes */
429d2ddc776SDavid Howells 
430d2ddc776SDavid Howells 	afs_voltype_t		type;		/* type of volume */
431d2ddc776SDavid Howells 	short			error;
432d2ddc776SDavid Howells 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
433d2ddc776SDavid Howells 	u8			name_len;
434d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
43508e0e7c8SDavid Howells };
43608e0e7c8SDavid Howells 
4370fafdc9fSDavid Howells enum afs_lock_state {
4380fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NONE,		/* The vnode has no lock on the server */
4390fafdc9fSDavid Howells 	AFS_VNODE_LOCK_WAITING_FOR_CB,	/* We're waiting for the server to break the callback */
4400fafdc9fSDavid Howells 	AFS_VNODE_LOCK_SETTING,		/* We're asking the server for a lock */
4410fafdc9fSDavid Howells 	AFS_VNODE_LOCK_GRANTED,		/* We have a lock on the server */
4420fafdc9fSDavid Howells 	AFS_VNODE_LOCK_EXTENDING,	/* We're extending a lock on the server */
4430fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NEED_UNLOCK,	/* We need to unlock on the server */
4440fafdc9fSDavid Howells 	AFS_VNODE_LOCK_UNLOCKING,	/* We're telling the server to unlock */
4450fafdc9fSDavid Howells };
4460fafdc9fSDavid Howells 
44708e0e7c8SDavid Howells /*
448f8de483eSDavid Howells  * AFS inode private data.
449f8de483eSDavid Howells  *
450f8de483eSDavid Howells  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
451f8de483eSDavid Howells  * leak from one inode to another.
45208e0e7c8SDavid Howells  */
45308e0e7c8SDavid Howells struct afs_vnode {
45408e0e7c8SDavid Howells 	struct inode		vfs_inode;	/* the VFS's inode record */
45508e0e7c8SDavid Howells 
45608e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume on which vnode resides */
45708e0e7c8SDavid Howells 	struct afs_fid		fid;		/* the file identifier for this inode */
45808e0e7c8SDavid Howells 	struct afs_file_status	status;		/* AFS status info for this file */
4599b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
4609b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
46108e0e7c8SDavid Howells #endif
462fe342cf7SDavid Howells 	struct afs_permits __rcu *permit_cache;	/* cache of permits so far obtained */
463d2ddc776SDavid Howells 	struct mutex		io_lock;	/* Lock for serialising I/O on this mutex */
464260a9803SDavid Howells 	struct mutex		validate_lock;	/* lock for validating this vnode */
4654343d008SDavid Howells 	spinlock_t		wb_lock;	/* lock for wb_keys */
46608e0e7c8SDavid Howells 	spinlock_t		lock;		/* waitqueue/flags lock */
46708e0e7c8SDavid Howells 	unsigned long		flags;
468c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED	0		/* Set if vnode has a callback promise */
469260a9803SDavid Howells #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
470c435ee34SDavid Howells #define AFS_VNODE_DIR_MODIFIED	2		/* set if dir vnode's data modified */
47108e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
47208e0e7c8SDavid Howells #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
47308e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
4740fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL	6		/* set if Vnode is an auto mount point */
4750fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR	7 		/* set if Vnode is a pseudo directory */
47608e0e7c8SDavid Howells 
4774343d008SDavid Howells 	struct list_head	wb_keys;	/* List of keys available for writeback */
478e8d6c554SDavid Howells 	struct list_head	pending_locks;	/* locks waiting to be granted */
479e8d6c554SDavid Howells 	struct list_head	granted_locks;	/* locks granted on this file */
480e8d6c554SDavid Howells 	struct delayed_work	lock_work;	/* work to be done in locking */
4810fafdc9fSDavid Howells 	struct key		*lock_key;	/* Key to be used in lock ops */
4820fafdc9fSDavid Howells 	enum afs_lock_state	lock_state : 8;
4830fafdc9fSDavid Howells 	afs_lock_type_t		lock_type : 8;
48431143d5dSDavid Howells 
48508e0e7c8SDavid Howells 	/* outstanding callback notification on this file */
486c435ee34SDavid Howells 	struct afs_cb_interest	*cb_interest;	/* Server on which this resides */
487c435ee34SDavid Howells 	unsigned int		cb_s_break;	/* Mass break counter on ->server */
488c435ee34SDavid Howells 	unsigned int		cb_break;	/* Break counter on vnode */
489c435ee34SDavid Howells 	seqlock_t		cb_lock;	/* Lock for ->cb_interest, ->status, ->cb_*break */
490c435ee34SDavid Howells 
491c435ee34SDavid Howells 	time64_t		cb_expires_at;	/* time at which callback expires */
49208e0e7c8SDavid Howells 	unsigned		cb_version;	/* callback version */
49308e0e7c8SDavid Howells 	afs_callback_type_t	cb_type;	/* type of callback */
49408e0e7c8SDavid Howells };
49508e0e7c8SDavid Howells 
49600d3b7a4SDavid Howells /*
49700d3b7a4SDavid Howells  * cached security record for one user's attempt to access a vnode
49800d3b7a4SDavid Howells  */
49900d3b7a4SDavid Howells struct afs_permit {
50000d3b7a4SDavid Howells 	struct key		*key;		/* RxRPC ticket holding a security context */
501be080a6fSDavid Howells 	afs_access_t		access;		/* CallerAccess value for this key */
50200d3b7a4SDavid Howells };
50300d3b7a4SDavid Howells 
50400d3b7a4SDavid Howells /*
505be080a6fSDavid Howells  * Immutable cache of CallerAccess records from attempts to access vnodes.
506be080a6fSDavid Howells  * These may be shared between multiple vnodes.
50700d3b7a4SDavid Howells  */
50800d3b7a4SDavid Howells struct afs_permits {
509be080a6fSDavid Howells 	struct rcu_head		rcu;
510be080a6fSDavid Howells 	struct hlist_node	hash_node;	/* Link in hash */
511be080a6fSDavid Howells 	unsigned long		h;		/* Hash value for this permit list */
512be080a6fSDavid Howells 	refcount_t		usage;
513be080a6fSDavid Howells 	unsigned short		nr_permits;	/* Number of records */
514be080a6fSDavid Howells 	bool			invalidated;	/* Invalidated due to key change */
515be080a6fSDavid Howells 	struct afs_permit	permits[];	/* List of permits sorted by key pointer */
51600d3b7a4SDavid Howells };
51700d3b7a4SDavid Howells 
518b908fe6bSDavid Howells /*
519b908fe6bSDavid Howells  * record of one of a system's set of network interfaces
520b908fe6bSDavid Howells  */
521b908fe6bSDavid Howells struct afs_interface {
522b908fe6bSDavid Howells 	struct in_addr	address;	/* IPv4 address bound to interface */
523b908fe6bSDavid Howells 	struct in_addr	netmask;	/* netmask applied to address */
524b908fe6bSDavid Howells 	unsigned	mtu;		/* MTU of interface */
525b908fe6bSDavid Howells };
526b908fe6bSDavid Howells 
5278b2a464cSDavid Howells /*
5288b2a464cSDavid Howells  * Cursor for iterating over a server's address list.
5298b2a464cSDavid Howells  */
5308b2a464cSDavid Howells struct afs_addr_cursor {
5318b2a464cSDavid Howells 	struct afs_addr_list	*alist;		/* Current address list (pins ref) */
5328b2a464cSDavid Howells 	struct sockaddr_rxrpc	*addr;
533d2ddc776SDavid Howells 	u32			abort_code;
5348b2a464cSDavid Howells 	unsigned short		start;		/* Starting point in alist->addrs[] */
5358b2a464cSDavid Howells 	unsigned short		index;		/* Wrapping offset from start to current addr */
5368b2a464cSDavid Howells 	short			error;
5378b2a464cSDavid Howells 	bool			begun;		/* T if we've begun iteration */
5388b2a464cSDavid Howells 	bool			responded;	/* T if the current address responded */
5398b2a464cSDavid Howells };
5408b2a464cSDavid Howells 
5418b2a464cSDavid Howells /*
5428b2a464cSDavid Howells  * Cursor for iterating over a set of fileservers.
5438b2a464cSDavid Howells  */
5448b2a464cSDavid Howells struct afs_fs_cursor {
5458b2a464cSDavid Howells 	struct afs_addr_cursor	ac;
546d2ddc776SDavid Howells 	struct afs_vnode	*vnode;
547d2ddc776SDavid Howells 	struct afs_server_list	*server_list;	/* Current server list (pins ref) */
548d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Server on which this resides (pins ref) */
549d2ddc776SDavid Howells 	struct key		*key;		/* Key for the server */
550d2ddc776SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
551d2ddc776SDavid Howells 	unsigned int		cb_break_2;	/* cb_break + cb_s_break (2nd vnode) */
552d2ddc776SDavid Howells 	unsigned char		start;		/* Initial index in server list */
553d2ddc776SDavid Howells 	unsigned char		index;		/* Number of servers tried beyond start */
554d2ddc776SDavid Howells 	unsigned short		flags;
555d2ddc776SDavid Howells #define AFS_FS_CURSOR_STOP	0x0001		/* Set to cease iteration */
556d2ddc776SDavid Howells #define AFS_FS_CURSOR_VBUSY	0x0002		/* Set if seen VBUSY */
557d2ddc776SDavid Howells #define AFS_FS_CURSOR_VMOVED	0x0004		/* Set if seen VMOVED */
558d2ddc776SDavid Howells #define AFS_FS_CURSOR_VNOVOL	0x0008		/* Set if seen VNOVOL */
559d2ddc776SDavid Howells #define AFS_FS_CURSOR_CUR_ONLY	0x0010		/* Set if current server only (file lock held) */
560d2ddc776SDavid Howells #define AFS_FS_CURSOR_NO_VSLEEP	0x0020		/* Set to prevent sleep on VBUSY, VOFFLINE, ... */
5618b2a464cSDavid Howells };
5628b2a464cSDavid Howells 
563402cb8ddSDavid Howells /*
564402cb8ddSDavid Howells  * Cache auxiliary data.
565402cb8ddSDavid Howells  */
566402cb8ddSDavid Howells struct afs_vnode_cache_aux {
567402cb8ddSDavid Howells 	u64			data_version;
568402cb8ddSDavid Howells } __packed;
569402cb8ddSDavid Howells 
57098bf40cdSDavid Howells #include <trace/events/afs.h>
57198bf40cdSDavid Howells 
57208e0e7c8SDavid Howells /*****************************************************************************/
57308e0e7c8SDavid Howells /*
5748b2a464cSDavid Howells  * addr_list.c
5758b2a464cSDavid Howells  */
5768b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
5778b2a464cSDavid Howells {
5788b2a464cSDavid Howells 	if (alist)
5798b2a464cSDavid Howells 		refcount_inc(&alist->usage);
5808b2a464cSDavid Howells 	return alist;
5818b2a464cSDavid Howells }
5828b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
5838b2a464cSDavid Howells 						unsigned short,
5848b2a464cSDavid Howells 						unsigned short);
5858b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *);
5868b2a464cSDavid Howells extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
5878b2a464cSDavid Howells 						  unsigned short, unsigned short);
5888b2a464cSDavid Howells extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
5898b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *);
5908b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *);
5918b2a464cSDavid Howells extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
5928b2a464cSDavid Howells 
593bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
594bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
595d2ddc776SDavid Howells 
5968b2a464cSDavid Howells /*
5979b3f26c9SDavid Howells  * cache.c
5989b3f26c9SDavid Howells  */
5999b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
6009b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs;
6019b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def;
6029b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def;
6039b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def;
6049b3f26c9SDavid Howells #else
6059b3f26c9SDavid Howells #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
6069b3f26c9SDavid Howells #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
6079b3f26c9SDavid Howells #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
6089b3f26c9SDavid Howells #endif
6099b3f26c9SDavid Howells 
6109b3f26c9SDavid Howells /*
61108e0e7c8SDavid Howells  * callback.c
61208e0e7c8SDavid Howells  */
61308e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
614c435ee34SDavid Howells extern void afs_break_callback(struct afs_vnode *);
6155cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
616c435ee34SDavid Howells 
617d2ddc776SDavid Howells extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
618c435ee34SDavid Howells extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
619d2ddc776SDavid Howells extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
620c435ee34SDavid Howells 
621c435ee34SDavid Howells static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
622c435ee34SDavid Howells {
623c435ee34SDavid Howells 	refcount_inc(&cbi->usage);
624c435ee34SDavid Howells 	return cbi;
625c435ee34SDavid Howells }
6261da177e4SLinus Torvalds 
6271da177e4SLinus Torvalds /*
6281da177e4SLinus Torvalds  * cell.c
6291da177e4SLinus Torvalds  */
630989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
631989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
632989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
633989782dcSDavid Howells 					const char *, bool);
6348b2a464cSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *);
6359ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *);
636989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
637989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
638f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
63908e0e7c8SDavid Howells 
64008e0e7c8SDavid Howells /*
64108e0e7c8SDavid Howells  * cmservice.c
64208e0e7c8SDavid Howells  */
64308e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
64408e0e7c8SDavid Howells 
6451da177e4SLinus Torvalds /*
6461da177e4SLinus Torvalds  * dir.c
6471da177e4SLinus Torvalds  */
6484b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
6494d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
6504d673da1SDavid Howells extern const struct file_operations afs_dynroot_file_operations;
6514d673da1SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
6524d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
6534d673da1SDavid Howells 
6544d673da1SDavid Howells extern bool afs_dir_check_page(struct inode *, struct page *);
6551da177e4SLinus Torvalds 
6561da177e4SLinus Torvalds /*
6571da177e4SLinus Torvalds  * file.c
6581da177e4SLinus Torvalds  */
659f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops;
660754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
66100d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
66200d3b7a4SDavid Howells 
6634343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
6644343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
66500d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
66600d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
667d2ddc776SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
668f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *);
669196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
6701da177e4SLinus Torvalds 
6711da177e4SLinus Torvalds /*
672e8d6c554SDavid Howells  * flock.c
673e8d6c554SDavid Howells  */
674f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
675f044c884SDavid Howells 
676e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
677e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
678e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
679e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
680e8d6c554SDavid Howells 
681e8d6c554SDavid Howells /*
68208e0e7c8SDavid Howells  * fsclient.c
68308e0e7c8SDavid Howells  */
684d2ddc776SDavid Howells extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
685d2ddc776SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
686d2ddc776SDavid Howells extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
687d2ddc776SDavid Howells extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
688d2ddc776SDavid Howells 			 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
689d2ddc776SDavid Howells extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
690d2ddc776SDavid Howells extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
691d2ddc776SDavid Howells extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
692d2ddc776SDavid Howells 			  struct afs_fid *, struct afs_file_status *);
693d2ddc776SDavid Howells extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
694d2ddc776SDavid Howells 			 struct afs_vnode *, const char *);
6954343d008SDavid Howells extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
696d2ddc776SDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned);
697d2ddc776SDavid Howells extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
698d2ddc776SDavid Howells extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
699d2ddc776SDavid Howells extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
700d2ddc776SDavid Howells extern int afs_fs_extend_lock(struct afs_fs_cursor *);
701d2ddc776SDavid Howells extern int afs_fs_release_lock(struct afs_fs_cursor *);
702d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
703d2ddc776SDavid Howells 					struct afs_addr_cursor *, struct key *);
704d2ddc776SDavid Howells extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
705d2ddc776SDavid Howells 				   struct afs_addr_cursor *, struct key *);
7065cf9dd55SDavid Howells extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
7075cf9dd55SDavid Howells 				     struct afs_fid *, struct afs_file_status *,
7085cf9dd55SDavid Howells 				     struct afs_callback *, unsigned int,
7095cf9dd55SDavid Howells 				     struct afs_volsync *);
7105cf9dd55SDavid Howells extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
7115cf9dd55SDavid Howells 			       struct afs_fid *, struct afs_file_status *,
7125cf9dd55SDavid Howells 			       struct afs_callback *, struct afs_volsync *);
71308e0e7c8SDavid Howells 
71408e0e7c8SDavid Howells /*
7151da177e4SLinus Torvalds  * inode.c
7161da177e4SLinus Torvalds  */
717d2ddc776SDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *);
718c435ee34SDavid Howells extern int afs_iget5_test(struct inode *, void *);
7194d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
72000d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *,
721260a9803SDavid Howells 			      struct afs_fid *, struct afs_file_status *,
722d2ddc776SDavid Howells 			      struct afs_callback *,
723d2ddc776SDavid Howells 			      struct afs_cb_interest *);
724416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *);
725260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
726a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
72731143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *);
728b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
729bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
7301da177e4SLinus Torvalds 
7311da177e4SLinus Torvalds /*
7321da177e4SLinus Torvalds  * main.c
7331da177e4SLinus Torvalds  */
7340ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
735f044c884SDavid Howells 
736f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
737f044c884SDavid Howells {
738f044c884SDavid Howells 	return &__afs_net;
739f044c884SDavid Howells }
740f044c884SDavid Howells 
741f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
742f044c884SDavid Howells {
743f044c884SDavid Howells 	return &__afs_net;
744f044c884SDavid Howells }
745f044c884SDavid Howells 
746f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
747f044c884SDavid Howells {
748f044c884SDavid Howells 	return &__afs_net;
749f044c884SDavid Howells }
750f044c884SDavid Howells 
751f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
752f044c884SDavid Howells {
753f044c884SDavid Howells 	return &__afs_net;
754f044c884SDavid Howells }
755f044c884SDavid Howells 
756f044c884SDavid Howells static inline struct afs_net *afs_get_net(struct afs_net *net)
757f044c884SDavid Howells {
758f044c884SDavid Howells 	return net;
759f044c884SDavid Howells }
760f044c884SDavid Howells 
761f044c884SDavid Howells static inline void afs_put_net(struct afs_net *net)
762f044c884SDavid Howells {
763f044c884SDavid Howells }
7641da177e4SLinus Torvalds 
7651da177e4SLinus Torvalds /*
76608e0e7c8SDavid Howells  * misc.c
76708e0e7c8SDavid Howells  */
76808e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
76908e0e7c8SDavid Howells 
77008e0e7c8SDavid Howells /*
7711da177e4SLinus Torvalds  * mntpt.c
7721da177e4SLinus Torvalds  */
773754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
774bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
7754b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
7761da177e4SLinus Torvalds 
777d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
77808e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
7791da177e4SLinus Torvalds 
7801da177e4SLinus Torvalds /*
781b4db2b35SArnd Bergmann  * netdevices.c
782b4db2b35SArnd Bergmann  */
783b4db2b35SArnd Bergmann extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
784b4db2b35SArnd Bergmann 
785b4db2b35SArnd Bergmann /*
7861da177e4SLinus Torvalds  * proc.c
7871da177e4SLinus Torvalds  */
788f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
789f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
790f044c884SDavid Howells extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
791f044c884SDavid Howells extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
7921da177e4SLinus Torvalds 
79308e0e7c8SDavid Howells /*
794d2ddc776SDavid Howells  * rotate.c
795d2ddc776SDavid Howells  */
796d2ddc776SDavid Howells extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
797d2ddc776SDavid Howells 				      struct key *);
798d2ddc776SDavid Howells extern bool afs_select_fileserver(struct afs_fs_cursor *);
799d2ddc776SDavid Howells extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
800d2ddc776SDavid Howells extern int afs_end_vnode_operation(struct afs_fs_cursor *);
801d2ddc776SDavid Howells 
802d2ddc776SDavid Howells /*
80308e0e7c8SDavid Howells  * rxrpc.c
80408e0e7c8SDavid Howells  */
805f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
8068324f0bcSDavid Howells 
807f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
808f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
809f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
810341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
811341f741fSDavid Howells extern int afs_queue_call_work(struct afs_call *);
8128b2a464cSDavid Howells extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
813f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
814f044c884SDavid Howells 					    const struct afs_call_type *,
81508e0e7c8SDavid Howells 					    size_t, size_t);
81608e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
81708e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
818b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
819d001648eSDavid Howells extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
82008e0e7c8SDavid Howells 
821d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
822372ee163SDavid Howells {
823d001648eSDavid Howells 	return afs_extract_data(call, call->buffer, call->reply_max, false);
824372ee163SDavid Howells }
825372ee163SDavid Howells 
82698bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
82798bf40cdSDavid Howells 					enum afs_call_state state)
82898bf40cdSDavid Howells {
82998bf40cdSDavid Howells 	return READ_ONCE(call->state) == state;
83098bf40cdSDavid Howells }
83198bf40cdSDavid Howells 
83298bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
83398bf40cdSDavid Howells 				      enum afs_call_state from,
83498bf40cdSDavid Howells 				      enum afs_call_state to)
83598bf40cdSDavid Howells {
83698bf40cdSDavid Howells 	bool ok = false;
83798bf40cdSDavid Howells 
83898bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
83998bf40cdSDavid Howells 	if (call->state == from) {
84098bf40cdSDavid Howells 		call->state = to;
84198bf40cdSDavid Howells 		trace_afs_call_state(call, from, to, 0, 0);
84298bf40cdSDavid Howells 		ok = true;
84398bf40cdSDavid Howells 	}
84498bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
84598bf40cdSDavid Howells 	return ok;
84698bf40cdSDavid Howells }
84798bf40cdSDavid Howells 
84898bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
84998bf40cdSDavid Howells 					 int error, u32 remote_abort)
85098bf40cdSDavid Howells {
85198bf40cdSDavid Howells 	enum afs_call_state state;
85298bf40cdSDavid Howells 	bool ok = false;
85398bf40cdSDavid Howells 
85498bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
85598bf40cdSDavid Howells 	state = call->state;
85698bf40cdSDavid Howells 	if (state != AFS_CALL_COMPLETE) {
85798bf40cdSDavid Howells 		call->abort_code = remote_abort;
85898bf40cdSDavid Howells 		call->error = error;
85998bf40cdSDavid Howells 		call->state = AFS_CALL_COMPLETE;
86098bf40cdSDavid Howells 		trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
86198bf40cdSDavid Howells 				     error, remote_abort);
86298bf40cdSDavid Howells 		ok = true;
86398bf40cdSDavid Howells 	}
86498bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
86598bf40cdSDavid Howells 	if (ok)
86698bf40cdSDavid Howells 		trace_afs_call_done(call);
86798bf40cdSDavid Howells }
86898bf40cdSDavid Howells 
86908e0e7c8SDavid Howells /*
87000d3b7a4SDavid Howells  * security.c
87100d3b7a4SDavid Howells  */
872be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
87300d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
874be080a6fSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
875416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *);
87600d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
8770fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
87810556cb2SAl Viro extern int afs_permission(struct inode *, int);
879be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
88000d3b7a4SDavid Howells 
88100d3b7a4SDavid Howells /*
88208e0e7c8SDavid Howells  * server.c
88308e0e7c8SDavid Howells  */
88408e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
88508e0e7c8SDavid Howells 
886c435ee34SDavid Howells static inline struct afs_server *afs_get_server(struct afs_server *server)
887c435ee34SDavid Howells {
888c435ee34SDavid Howells 	atomic_inc(&server->usage);
889c435ee34SDavid Howells 	return server;
890c435ee34SDavid Howells }
89108e0e7c8SDavid Howells 
892f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
893f044c884SDavid Howells 					  const struct sockaddr_rxrpc *);
894d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
895d2ddc776SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
8969ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *);
897d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
898d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
899f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
900d2ddc776SDavid Howells extern bool afs_probe_fileserver(struct afs_fs_cursor *);
901d2ddc776SDavid Howells extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
902d2ddc776SDavid Howells 
903d2ddc776SDavid Howells /*
904d2ddc776SDavid Howells  * server_list.c
905d2ddc776SDavid Howells  */
906d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
907d2ddc776SDavid Howells {
908d2ddc776SDavid Howells 	refcount_inc(&slist->usage);
909d2ddc776SDavid Howells 	return slist;
910d2ddc776SDavid Howells }
911d2ddc776SDavid Howells 
912d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
913d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
914d2ddc776SDavid Howells 						     struct afs_vldb_entry *,
915d2ddc776SDavid Howells 						     u8);
916d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
91708e0e7c8SDavid Howells 
91808e0e7c8SDavid Howells /*
91900d3b7a4SDavid Howells  * super.c
92000d3b7a4SDavid Howells  */
921f044c884SDavid Howells extern int __init afs_fs_init(void);
922f044c884SDavid Howells extern void __exit afs_fs_exit(void);
92300d3b7a4SDavid Howells 
92400d3b7a4SDavid Howells /*
92508e0e7c8SDavid Howells  * vlclient.c
92608e0e7c8SDavid Howells  */
927d2ddc776SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
928d2ddc776SDavid Howells 							 struct afs_addr_cursor *,
929d2ddc776SDavid Howells 							 struct key *, const char *, int);
930d2ddc776SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
931d2ddc776SDavid Howells 						struct key *, const uuid_t *);
932bf99a53cSDavid Howells extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
933bf99a53cSDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
934bf99a53cSDavid Howells 						     struct key *, const uuid_t *);
93508e0e7c8SDavid Howells 
93608e0e7c8SDavid Howells /*
93708e0e7c8SDavid Howells  * volume.c
93808e0e7c8SDavid Howells  */
939d2ddc776SDavid Howells static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
94049566f6fSDavid Howells {
94149566f6fSDavid Howells 	if (volume)
94249566f6fSDavid Howells 		atomic_inc(&volume->usage);
94349566f6fSDavid Howells 	return volume;
94449566f6fSDavid Howells }
94508e0e7c8SDavid Howells 
946d2ddc776SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
947d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *);
948d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
9499ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
950d2ddc776SDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct key *);
95108e0e7c8SDavid Howells 
95231143d5dSDavid Howells /*
95331143d5dSDavid Howells  * write.c
95431143d5dSDavid Howells  */
95531143d5dSDavid Howells extern int afs_set_page_dirty(struct page *);
95615b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
95715b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned flags,
95815b4650eSNick Piggin 			struct page **pagep, void **fsdata);
95915b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
96015b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned copied,
96115b4650eSNick Piggin 			struct page *page, void *fsdata);
96231143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
96331143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
96431143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
96550b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
96658fed94dSDavid Howells extern int afs_flush(struct file *, fl_owner_t);
96702c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
9681cf7a151SDavid Howells extern int afs_page_mkwrite(struct vm_fault *);
9694343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
9704343d008SDavid Howells extern int afs_launder_page(struct page *);
97131143d5dSDavid Howells 
972d3e3b7eaSDavid Howells /*
973d3e3b7eaSDavid Howells  * xattr.c
974d3e3b7eaSDavid Howells  */
975d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
976d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
97731143d5dSDavid Howells 
978d2ddc776SDavid Howells 
979d2ddc776SDavid Howells /*
980d2ddc776SDavid Howells  * Miscellaneous inline functions.
981d2ddc776SDavid Howells  */
982d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
983d2ddc776SDavid Howells {
984d2ddc776SDavid Howells 	return container_of(inode, struct afs_vnode, vfs_inode);
985d2ddc776SDavid Howells }
986d2ddc776SDavid Howells 
987d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
988d2ddc776SDavid Howells {
989d2ddc776SDavid Howells 	return &vnode->vfs_inode;
990d2ddc776SDavid Howells }
991d2ddc776SDavid Howells 
992d2ddc776SDavid Howells static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
993d2ddc776SDavid Howells 					   struct afs_vnode *vnode,
994d2ddc776SDavid Howells 					   unsigned int cb_break)
995d2ddc776SDavid Howells {
996d2ddc776SDavid Howells 	if (fc->ac.error == 0)
997d2ddc776SDavid Howells 		afs_cache_permit(vnode, fc->key, cb_break);
998d2ddc776SDavid Howells }
999d2ddc776SDavid Howells 
1000d2ddc776SDavid Howells static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1001d2ddc776SDavid Howells 						 struct afs_vnode *vnode)
1002d2ddc776SDavid Howells {
1003d2ddc776SDavid Howells 	if (fc->ac.error == -ENOENT) {
1004d2ddc776SDavid Howells 		set_bit(AFS_VNODE_DELETED, &vnode->flags);
1005d2ddc776SDavid Howells 		afs_break_callback(vnode);
1006d2ddc776SDavid Howells 	}
1007d2ddc776SDavid Howells }
1008d2ddc776SDavid Howells 
1009d2ddc776SDavid Howells 
101008e0e7c8SDavid Howells /*****************************************************************************/
101108e0e7c8SDavid Howells /*
101208e0e7c8SDavid Howells  * debug tracing
101308e0e7c8SDavid Howells  */
101408e0e7c8SDavid Howells extern unsigned afs_debug;
101508e0e7c8SDavid Howells 
101608e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1017ad16df84SSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
101808e0e7c8SDavid Howells 
1019530b6412SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1020530b6412SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
102108e0e7c8SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
102208e0e7c8SDavid Howells 
102308e0e7c8SDavid Howells 
102408e0e7c8SDavid Howells #if defined(__KDEBUG)
102508e0e7c8SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
102608e0e7c8SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
102708e0e7c8SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
102808e0e7c8SDavid Howells 
102908e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
103008e0e7c8SDavid Howells #define AFS_DEBUG_KENTER	0x01
103108e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE	0x02
103208e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG	0x04
103308e0e7c8SDavid Howells 
103408e0e7c8SDavid Howells #define _enter(FMT,...)					\
103508e0e7c8SDavid Howells do {							\
103608e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
103708e0e7c8SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
103808e0e7c8SDavid Howells } while (0)
103908e0e7c8SDavid Howells 
104008e0e7c8SDavid Howells #define _leave(FMT,...)					\
104108e0e7c8SDavid Howells do {							\
104208e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
104308e0e7c8SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
104408e0e7c8SDavid Howells } while (0)
104508e0e7c8SDavid Howells 
104608e0e7c8SDavid Howells #define _debug(FMT,...)					\
104708e0e7c8SDavid Howells do {							\
104808e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
104908e0e7c8SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
105008e0e7c8SDavid Howells } while (0)
105108e0e7c8SDavid Howells 
105208e0e7c8SDavid Howells #else
105312fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
105412fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
105512fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
105608e0e7c8SDavid Howells #endif
105708e0e7c8SDavid Howells 
105808e0e7c8SDavid Howells /*
105908e0e7c8SDavid Howells  * debug assertion checking
106008e0e7c8SDavid Howells  */
106108e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
106208e0e7c8SDavid Howells 
106308e0e7c8SDavid Howells #define ASSERT(X)						\
106408e0e7c8SDavid Howells do {								\
106508e0e7c8SDavid Howells 	if (unlikely(!(X))) {					\
106608e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
106708e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
106808e0e7c8SDavid Howells 		BUG();						\
106908e0e7c8SDavid Howells 	}							\
107008e0e7c8SDavid Howells } while(0)
107108e0e7c8SDavid Howells 
107208e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)						\
107308e0e7c8SDavid Howells do {									\
107408e0e7c8SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
107508e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
107608e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
107708e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
107808e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
107908e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
108008e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
108108e0e7c8SDavid Howells 		BUG();							\
108208e0e7c8SDavid Howells 	}								\
108308e0e7c8SDavid Howells } while(0)
108408e0e7c8SDavid Howells 
1085416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)					\
1086416351f2SDavid Howells do {									\
1087416351f2SDavid Howells 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
1088416351f2SDavid Howells 		printk(KERN_ERR "\n");					\
1089416351f2SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1090416351f2SDavid Howells 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
1091416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1092416351f2SDavid Howells 		       (unsigned long)(H));				\
1093416351f2SDavid Howells 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1094416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1095416351f2SDavid Howells 		       (unsigned long)(H));				\
1096416351f2SDavid Howells 		BUG();							\
1097416351f2SDavid Howells 	}								\
1098416351f2SDavid Howells } while(0)
1099416351f2SDavid Howells 
110008e0e7c8SDavid Howells #define ASSERTIF(C, X)						\
110108e0e7c8SDavid Howells do {								\
110208e0e7c8SDavid Howells 	if (unlikely((C) && !(X))) {				\
110308e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
110408e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
110508e0e7c8SDavid Howells 		BUG();						\
110608e0e7c8SDavid Howells 	}							\
110708e0e7c8SDavid Howells } while(0)
110808e0e7c8SDavid Howells 
110908e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
111008e0e7c8SDavid Howells do {									\
111108e0e7c8SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
111208e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
111308e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
111408e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
111508e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
111608e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
111708e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
111808e0e7c8SDavid Howells 		BUG();							\
111908e0e7c8SDavid Howells 	}								\
112008e0e7c8SDavid Howells } while(0)
112108e0e7c8SDavid Howells 
112208e0e7c8SDavid Howells #else
112308e0e7c8SDavid Howells 
112408e0e7c8SDavid Howells #define ASSERT(X)				\
112508e0e7c8SDavid Howells do {						\
112608e0e7c8SDavid Howells } while(0)
112708e0e7c8SDavid Howells 
112808e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)			\
112908e0e7c8SDavid Howells do {						\
113008e0e7c8SDavid Howells } while(0)
113108e0e7c8SDavid Howells 
1132416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)		\
1133416351f2SDavid Howells do {						\
1134416351f2SDavid Howells } while(0)
1135416351f2SDavid Howells 
113608e0e7c8SDavid Howells #define ASSERTIF(C, X)				\
113708e0e7c8SDavid Howells do {						\
113808e0e7c8SDavid Howells } while(0)
113908e0e7c8SDavid Howells 
114008e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
114108e0e7c8SDavid Howells do {						\
114208e0e7c8SDavid Howells } while(0)
114308e0e7c8SDavid Howells 
114408e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1145