xref: /openbmc/linux/fs/afs/internal.h (revision 79ddbfa5)
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 
3913fcc683SDavid Howells struct afs_fs_context {
4000d3b7a4SDavid Howells 	bool			force;		/* T to force cell type */
41bec5eb61Swanglei 	bool			autocell;	/* T if set auto mount operation */
424d673da1SDavid Howells 	bool			dyn_root;	/* T if dynamic root */
4313fcc683SDavid Howells 	bool			no_cell;	/* T if the source is "none" (for dynroot) */
4400d3b7a4SDavid Howells 	afs_voltype_t		type;		/* type of volume requested */
4513fcc683SDavid Howells 	unsigned int		volnamesz;	/* size of volume name */
4600d3b7a4SDavid Howells 	const char		*volname;	/* name of volume to mount */
475b86d4ffSDavid Howells 	struct afs_net		*net;		/* the AFS net namespace stuff */
4800d3b7a4SDavid Howells 	struct afs_cell		*cell;		/* cell in which to find volume */
4900d3b7a4SDavid Howells 	struct afs_volume	*volume;	/* volume record */
5000d3b7a4SDavid Howells 	struct key		*key;		/* key to use for secure mounting */
5100d3b7a4SDavid Howells };
5200d3b7a4SDavid Howells 
53c435ee34SDavid Howells struct afs_iget_data {
54c435ee34SDavid Howells 	struct afs_fid		fid;
55c435ee34SDavid Howells 	struct afs_volume	*volume;	/* volume on which resides */
56c435ee34SDavid Howells };
57c435ee34SDavid Howells 
588e8d7f13SDavid Howells enum afs_call_state {
5998bf40cdSDavid Howells 	AFS_CALL_CL_REQUESTING,		/* Client: Request is being sent */
6098bf40cdSDavid Howells 	AFS_CALL_CL_AWAIT_REPLY,	/* Client: Awaiting reply */
6198bf40cdSDavid Howells 	AFS_CALL_CL_PROC_REPLY,		/* Client: rxrpc call complete; processing reply */
6298bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_OP_ID,	/* Server: Awaiting op ID */
6398bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_REQUEST,	/* Server: Awaiting request data */
6498bf40cdSDavid Howells 	AFS_CALL_SV_REPLYING,		/* Server: Replying */
6598bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_ACK,		/* Server: Awaiting final ACK */
668e8d7f13SDavid Howells 	AFS_CALL_COMPLETE,		/* Completed or failed */
678e8d7f13SDavid Howells };
68f044c884SDavid Howells 
6908e0e7c8SDavid Howells /*
708b2a464cSDavid Howells  * List of server addresses.
718b2a464cSDavid Howells  */
728b2a464cSDavid Howells struct afs_addr_list {
738b2a464cSDavid Howells 	struct rcu_head		rcu;		/* Must be first */
748b2a464cSDavid Howells 	refcount_t		usage;
75d2ddc776SDavid Howells 	u32			version;	/* Version */
7668eb64c3SDavid Howells 	unsigned char		max_addrs;
7768eb64c3SDavid Howells 	unsigned char		nr_addrs;
783bf0fb6fSDavid Howells 	unsigned char		preferred;	/* Preferred address */
7968eb64c3SDavid Howells 	unsigned char		nr_ipv4;	/* Number of IPv4 addresses */
800a5143f2SDavid Howells 	enum dns_record_source	source:8;
810a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
82bf99a53cSDavid Howells 	unsigned long		probed;		/* Mask of servers that have been probed */
833bf0fb6fSDavid Howells 	unsigned long		failed;		/* Mask of addrs that failed locally/ICMP */
843bf0fb6fSDavid Howells 	unsigned long		responded;	/* Mask of addrs that responded */
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 */
943bf0fb6fSDavid Howells 	struct afs_addr_list	*alist;		/* Address is alist[addr_ix] */
9508e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* processes awaiting completion */
96341f741fSDavid Howells 	struct work_struct	async_work;	/* async I/O processor */
9708e0e7c8SDavid Howells 	struct work_struct	work;		/* actual work processor */
9808e0e7c8SDavid Howells 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
9908e0e7c8SDavid Howells 	struct key		*key;		/* security for this call */
100f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
101d0676a16SDavid Howells 	struct afs_server	*cm_server;	/* Server affected by incoming CM call */
102d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Callback interest for server used */
10308e0e7c8SDavid Howells 	void			*request;	/* request data (first part) */
1044343d008SDavid Howells 	struct address_space	*mapping;	/* Pages being written from */
10512bdcf33SDavid Howells 	struct iov_iter		iter;		/* Buffer iterator */
10612bdcf33SDavid Howells 	struct iov_iter		*_iter;		/* Iterator currently in use */
10712bdcf33SDavid Howells 	union {	/* Convenience for ->iter */
10812bdcf33SDavid Howells 		struct kvec	kvec[1];
10912bdcf33SDavid Howells 		struct bio_vec	bvec[1];
11012bdcf33SDavid Howells 	};
11108e0e7c8SDavid Howells 	void			*buffer;	/* reply receive buffer */
11297e3043aSDavid Howells 	void			*reply[4];	/* Where to put the reply */
11331143d5dSDavid Howells 	pgoff_t			first;		/* first page in mapping to deal with */
11431143d5dSDavid Howells 	pgoff_t			last;		/* last page in mapping to deal with */
115341f741fSDavid Howells 	atomic_t		usage;
1168e8d7f13SDavid Howells 	enum afs_call_state	state;
11798bf40cdSDavid Howells 	spinlock_t		state_lock;
11808e0e7c8SDavid Howells 	int			error;		/* error code */
119d001648eSDavid Howells 	u32			abort_code;	/* Remote abort ID or 0 */
1203bf0fb6fSDavid Howells 	u32			epoch;
12108e0e7c8SDavid Howells 	unsigned		request_size;	/* size of request data */
12208e0e7c8SDavid Howells 	unsigned		reply_max;	/* maximum size of reply */
12331143d5dSDavid Howells 	unsigned		first_offset;	/* offset into mapping[first] */
124c435ee34SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
125bcd89270SMarc Dionne 	union {
12631143d5dSDavid Howells 		unsigned	last_to;	/* amount of mapping[last] */
127bcd89270SMarc Dionne 		unsigned	count2;		/* count used in unmarshalling */
128bcd89270SMarc Dionne 	};
12908e0e7c8SDavid Howells 	unsigned char		unmarshall;	/* unmarshalling phase */
1303bf0fb6fSDavid Howells 	unsigned char		addr_ix;	/* Address in ->alist */
13108e0e7c8SDavid Howells 	bool			incoming;	/* T if incoming call */
13231143d5dSDavid Howells 	bool			send_pages;	/* T if data from mapping should be sent */
133d001648eSDavid Howells 	bool			need_attention;	/* T if RxRPC poked us */
13456ff9c83SDavid Howells 	bool			async;		/* T if asynchronous */
13533cd7f2bSDavid Howells 	bool			ret_reply0;	/* T if should return reply[0] on success */
136a68f4a27SDavid Howells 	bool			upgrade;	/* T to request service upgrade */
13712d8e95aSDavid Howells 	bool			want_reply_time; /* T if want reply_time */
138bf99a53cSDavid Howells 	u16			service_id;	/* Actual service ID (after upgrade) */
139a25e21f0SDavid Howells 	unsigned int		debug_id;	/* Trace ID */
14050a2c953SDavid Howells 	u32			operation_ID;	/* operation ID for an incoming call */
14108e0e7c8SDavid Howells 	u32			count;		/* count for use in unmarshalling */
14212bdcf33SDavid Howells 	union {					/* place to extract temporary data */
14312bdcf33SDavid Howells 		struct {
14412bdcf33SDavid Howells 			__be32	tmp_u;
14512bdcf33SDavid Howells 			__be32	tmp;
14612bdcf33SDavid Howells 		} __attribute__((packed));
14712bdcf33SDavid Howells 		__be64		tmp64;
14812bdcf33SDavid Howells 	};
1490c3a5ac2SDavid Howells 	afs_dataversion_t	expected_version; /* Updated version expected from store */
1500c3a5ac2SDavid Howells 	afs_dataversion_t	expected_version_2; /* 2nd updated version expected from store */
15112d8e95aSDavid Howells 	ktime_t			reply_time;	/* Time of first reply packet */
15208e0e7c8SDavid Howells };
15308e0e7c8SDavid Howells 
15408e0e7c8SDavid Howells struct afs_call_type {
15500d3b7a4SDavid Howells 	const char *name;
156025db80cSDavid Howells 	unsigned int op; /* Really enum afs_fs_operation */
15700d3b7a4SDavid Howells 
15808e0e7c8SDavid Howells 	/* deliver request or reply data to an call
15908e0e7c8SDavid Howells 	 * - returning an error will cause the call to be aborted
16008e0e7c8SDavid Howells 	 */
161d001648eSDavid Howells 	int (*deliver)(struct afs_call *call);
16208e0e7c8SDavid Howells 
16308e0e7c8SDavid Howells 	/* clean up a call */
16408e0e7c8SDavid Howells 	void (*destructor)(struct afs_call *call);
165341f741fSDavid Howells 
166341f741fSDavid Howells 	/* Work function */
167341f741fSDavid Howells 	void (*work)(struct work_struct *work);
1683bf0fb6fSDavid Howells 
1693bf0fb6fSDavid Howells 	/* Call done function (gets called immediately on success or failure) */
1703bf0fb6fSDavid Howells 	void (*done)(struct afs_call *call);
17108e0e7c8SDavid Howells };
17208e0e7c8SDavid Howells 
17308e0e7c8SDavid Howells /*
1744343d008SDavid Howells  * Key available for writeback on a file.
1754343d008SDavid Howells  */
1764343d008SDavid Howells struct afs_wb_key {
1774343d008SDavid Howells 	refcount_t		usage;
1784343d008SDavid Howells 	struct key		*key;
1794343d008SDavid Howells 	struct list_head	vnode_link;	/* Link in vnode->wb_keys */
1804343d008SDavid Howells };
1814343d008SDavid Howells 
1824343d008SDavid Howells /*
183215804a9SDavid Howells  * AFS open file information record.  Pointed to by file->private_data.
184215804a9SDavid Howells  */
185215804a9SDavid Howells struct afs_file {
186215804a9SDavid Howells 	struct key		*key;		/* The key this file was opened with */
1874343d008SDavid Howells 	struct afs_wb_key	*wb;		/* Writeback key record for this file */
188215804a9SDavid Howells };
189215804a9SDavid Howells 
190215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
191215804a9SDavid Howells {
192215804a9SDavid Howells 	struct afs_file *af = file->private_data;
193215804a9SDavid Howells 
194215804a9SDavid Howells 	return af->key;
195215804a9SDavid Howells }
196215804a9SDavid Howells 
197215804a9SDavid Howells /*
198196ee9cdSDavid Howells  * Record of an outstanding read operation on a vnode.
199196ee9cdSDavid Howells  */
200196ee9cdSDavid Howells struct afs_read {
201196ee9cdSDavid Howells 	loff_t			pos;		/* Where to start reading */
202e8e581a8SDavid Howells 	loff_t			len;		/* How much we're asking for */
203196ee9cdSDavid Howells 	loff_t			actual_len;	/* How much we're actually getting */
2046a0e3999SDavid Howells 	loff_t			remain;		/* Amount remaining */
205f3ddee8dSDavid Howells 	loff_t			file_size;	/* File size returned by server */
206f3ddee8dSDavid Howells 	afs_dataversion_t	data_version;	/* Version number returned by server */
207f3ddee8dSDavid Howells 	refcount_t		usage;
208196ee9cdSDavid Howells 	unsigned int		index;		/* Which page we're reading into */
209196ee9cdSDavid Howells 	unsigned int		nr_pages;
21012bdcf33SDavid Howells 	unsigned int		offset;		/* offset into current page */
211196ee9cdSDavid Howells 	void (*page_done)(struct afs_call *, struct afs_read *);
212f3ddee8dSDavid Howells 	struct page		**pages;
213f3ddee8dSDavid Howells 	struct page		*array[];
214196ee9cdSDavid Howells };
215196ee9cdSDavid Howells 
216196ee9cdSDavid Howells /*
21708e0e7c8SDavid Howells  * AFS superblock private data
21808e0e7c8SDavid Howells  * - there's one superblock per volume
21908e0e7c8SDavid Howells  */
22008e0e7c8SDavid Howells struct afs_super_info {
2215b86d4ffSDavid Howells 	struct net		*net_ns;	/* Network namespace */
22249566f6fSDavid Howells 	struct afs_cell		*cell;		/* The cell in which the volume resides */
22308e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume record */
2244d673da1SDavid Howells 	bool			dyn_root;	/* True if dynamic root */
22508e0e7c8SDavid Howells };
22608e0e7c8SDavid Howells 
22708e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
22808e0e7c8SDavid Howells {
22908e0e7c8SDavid Howells 	return sb->s_fs_info;
23008e0e7c8SDavid Howells }
23108e0e7c8SDavid Howells 
23208e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
23308e0e7c8SDavid Howells 
23408e0e7c8SDavid Howells /*
2356f8880d8SDavid Howells  * Set of substitutes for @sys.
2366f8880d8SDavid Howells  */
2376f8880d8SDavid Howells struct afs_sysnames {
2386f8880d8SDavid Howells #define AFS_NR_SYSNAME 16
2396f8880d8SDavid Howells 	char			*subs[AFS_NR_SYSNAME];
2406f8880d8SDavid Howells 	refcount_t		usage;
2416f8880d8SDavid Howells 	unsigned short		nr;
2426f8880d8SDavid Howells 	char			blank[1];
2436f8880d8SDavid Howells };
2446f8880d8SDavid Howells 
2456f8880d8SDavid Howells /*
246f044c884SDavid Howells  * AFS network namespace record.
247f044c884SDavid Howells  */
248f044c884SDavid Howells struct afs_net {
2495b86d4ffSDavid Howells 	struct net		*net;		/* Backpointer to the owning net namespace */
250f044c884SDavid Howells 	struct afs_uuid		uuid;
251f044c884SDavid Howells 	bool			live;		/* F if this namespace is being removed */
252f044c884SDavid Howells 
253f044c884SDavid Howells 	/* AF_RXRPC I/O stuff */
254f044c884SDavid Howells 	struct socket		*socket;
255f044c884SDavid Howells 	struct afs_call		*spare_incoming_call;
256f044c884SDavid Howells 	struct work_struct	charge_preallocation_work;
257f044c884SDavid Howells 	struct mutex		socket_mutex;
258f044c884SDavid Howells 	atomic_t		nr_outstanding_calls;
259f044c884SDavid Howells 	atomic_t		nr_superblocks;
260f044c884SDavid Howells 
261f044c884SDavid Howells 	/* Cell database */
262989782dcSDavid Howells 	struct rb_root		cells;
2631588def9SDavid Howells 	struct afs_cell __rcu	*ws_cell;
264989782dcSDavid Howells 	struct work_struct	cells_manager;
265989782dcSDavid Howells 	struct timer_list	cells_timer;
266989782dcSDavid Howells 	atomic_t		cells_outstanding;
267989782dcSDavid Howells 	seqlock_t		cells_lock;
268f044c884SDavid Howells 
2690da0b7fdSDavid Howells 	struct mutex		proc_cells_lock;
2706b3944e4SDavid Howells 	struct hlist_head	proc_cells;
271f044c884SDavid Howells 
272d2ddc776SDavid Howells 	/* Known servers.  Theoretically each fileserver can only be in one
273d2ddc776SDavid Howells 	 * cell, but in practice, people create aliases and subsets and there's
274d2ddc776SDavid Howells 	 * no easy way to distinguish them.
275d2ddc776SDavid Howells 	 */
276d2ddc776SDavid Howells 	seqlock_t		fs_lock;	/* For fs_servers */
277d2ddc776SDavid Howells 	struct rb_root		fs_servers;	/* afs_server (by server UUID or address) */
278d2ddc776SDavid Howells 	struct list_head	fs_updates;	/* afs_server (by update_at) */
279d2ddc776SDavid Howells 	struct hlist_head	fs_proc;	/* procfs servers list */
280d2ddc776SDavid Howells 
281d2ddc776SDavid Howells 	struct hlist_head	fs_addresses4;	/* afs_server (by lowest IPv4 addr) */
282d2ddc776SDavid Howells 	struct hlist_head	fs_addresses6;	/* afs_server (by lowest IPv6 addr) */
283d2ddc776SDavid Howells 	seqlock_t		fs_addr_lock;	/* For fs_addresses[46] */
284d2ddc776SDavid Howells 
285d2ddc776SDavid Howells 	struct work_struct	fs_manager;
286d2ddc776SDavid Howells 	struct timer_list	fs_timer;
287d2ddc776SDavid Howells 	atomic_t		servers_outstanding;
288f044c884SDavid Howells 
289f044c884SDavid Howells 	/* File locking renewal management */
290f044c884SDavid Howells 	struct mutex		lock_manager_mutex;
291f044c884SDavid Howells 
292f044c884SDavid Howells 	/* Misc */
2930da0b7fdSDavid Howells 	struct super_block	*dynroot_sb;	/* Dynamic root mount superblock */
294f044c884SDavid Howells 	struct proc_dir_entry	*proc_afs;	/* /proc/net/afs directory */
2956f8880d8SDavid Howells 	struct afs_sysnames	*sysnames;
2966f8880d8SDavid Howells 	rwlock_t		sysnames_lock;
297d55b4da4SDavid Howells 
298d55b4da4SDavid Howells 	/* Statistics counters */
299d55b4da4SDavid Howells 	atomic_t		n_lookup;	/* Number of lookups done */
300d55b4da4SDavid Howells 	atomic_t		n_reval;	/* Number of dentries needing revalidation */
301d55b4da4SDavid Howells 	atomic_t		n_inval;	/* Number of invalidations by the server */
302f3ddee8dSDavid Howells 	atomic_t		n_relpg;	/* Number of invalidations by releasepage */
303d55b4da4SDavid Howells 	atomic_t		n_read_dir;	/* Number of directory pages read */
30463a4681fSDavid Howells 	atomic_t		n_dir_cr;	/* Number of directory entry creation edits */
30563a4681fSDavid Howells 	atomic_t		n_dir_rm;	/* Number of directory entry removal edits */
30676a5cb6fSDavid Howells 	atomic_t		n_stores;	/* Number of store ops */
30776a5cb6fSDavid Howells 	atomic_long_t		n_store_bytes;	/* Number of bytes stored */
30876a5cb6fSDavid Howells 	atomic_long_t		n_fetch_bytes;	/* Number of bytes fetched */
30976a5cb6fSDavid Howells 	atomic_t		n_fetches;	/* Number of data fetch ops */
310f044c884SDavid Howells };
311f044c884SDavid Howells 
3126f8880d8SDavid Howells extern const char afs_init_sysname[];
313f044c884SDavid Howells 
314989782dcSDavid Howells enum afs_cell_state {
315989782dcSDavid Howells 	AFS_CELL_UNSET,
316989782dcSDavid Howells 	AFS_CELL_ACTIVATING,
317989782dcSDavid Howells 	AFS_CELL_ACTIVE,
318989782dcSDavid Howells 	AFS_CELL_DEACTIVATING,
319989782dcSDavid Howells 	AFS_CELL_INACTIVE,
320989782dcSDavid Howells 	AFS_CELL_FAILED,
321989782dcSDavid Howells };
322989782dcSDavid Howells 
323f044c884SDavid Howells /*
324d2ddc776SDavid Howells  * AFS cell record.
325d2ddc776SDavid Howells  *
326d2ddc776SDavid Howells  * This is a tricky concept to get right as it is possible to create aliases
327d2ddc776SDavid Howells  * simply by pointing AFSDB/SRV records for two names at the same set of VL
328d2ddc776SDavid Howells  * servers; it is also possible to do things like setting up two sets of VL
329d2ddc776SDavid Howells  * servers, one of which provides a superset of the volumes provided by the
330d2ddc776SDavid Howells  * other (for internal/external division, for example).
331d2ddc776SDavid Howells  *
332d2ddc776SDavid Howells  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
333d2ddc776SDavid Howells  * servers and (b) a cell's name is used by the client to select the key to use
334d2ddc776SDavid Howells  * for authentication and encryption.  The cell name is not typically used in
335d2ddc776SDavid Howells  * the protocol.
336d2ddc776SDavid Howells  *
337d2ddc776SDavid Howells  * There is no easy way to determine if two cells are aliases or one is a
338d2ddc776SDavid Howells  * subset of another.
33908e0e7c8SDavid Howells  */
34008e0e7c8SDavid Howells struct afs_cell {
341989782dcSDavid Howells 	union {
342989782dcSDavid Howells 		struct rcu_head	rcu;
343989782dcSDavid Howells 		struct rb_node	net_node;	/* Node in net->cells */
344989782dcSDavid Howells 	};
345989782dcSDavid Howells 	struct afs_net		*net;
34600d3b7a4SDavid Howells 	struct key		*anonymous_key;	/* anonymous user key for this cell */
347989782dcSDavid Howells 	struct work_struct	manager;	/* Manager for init/deinit/dns */
3486b3944e4SDavid Howells 	struct hlist_node	proc_link;	/* /proc cell list link */
3499b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
3509b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
3511da177e4SLinus Torvalds #endif
352989782dcSDavid Howells 	time64_t		dns_expiry;	/* Time AFSDB/SRV record expires */
353989782dcSDavid Howells 	time64_t		last_inactive;	/* Time of last drop of usage count */
354989782dcSDavid Howells 	atomic_t		usage;
355989782dcSDavid Howells 	unsigned long		flags;
356989782dcSDavid Howells #define AFS_CELL_FL_NOT_READY	0		/* The cell record is not ready for use */
357989782dcSDavid Howells #define AFS_CELL_FL_NO_GC	1		/* The cell was added manually, don't auto-gc */
358989782dcSDavid Howells #define AFS_CELL_FL_NOT_FOUND	2		/* Permanent DNS error */
359989782dcSDavid Howells #define AFS_CELL_FL_DNS_FAIL	3		/* Failed to access DNS */
3608b2a464cSDavid Howells #define AFS_CELL_FL_NO_LOOKUP_YET 4		/* Not completed first DNS lookup yet */
361989782dcSDavid Howells 	enum afs_cell_state	state;
362989782dcSDavid Howells 	short			error;
363989782dcSDavid Howells 
364d2ddc776SDavid Howells 	/* Active fileserver interaction state. */
365d2ddc776SDavid Howells 	struct list_head	proc_volumes;	/* procfs volume list */
366d2ddc776SDavid Howells 	rwlock_t		proc_lock;
367989782dcSDavid Howells 
368d2ddc776SDavid Howells 	/* VL server list. */
3690a5143f2SDavid Howells 	rwlock_t		vl_servers_lock; /* Lock on vl_servers */
3700a5143f2SDavid Howells 	struct afs_vlserver_list __rcu *vl_servers;
3710a5143f2SDavid Howells 
372989782dcSDavid Howells 	u8			name_len;	/* Length of name */
373989782dcSDavid Howells 	char			name[64 + 1];	/* Cell name, case-flattened and NUL-padded */
37408e0e7c8SDavid Howells };
37508e0e7c8SDavid Howells 
37608e0e7c8SDavid Howells /*
3770a5143f2SDavid Howells  * Volume Location server record.
3780a5143f2SDavid Howells  */
3790a5143f2SDavid Howells struct afs_vlserver {
3800a5143f2SDavid Howells 	struct rcu_head		rcu;
3810a5143f2SDavid Howells 	struct afs_addr_list	__rcu *addresses; /* List of addresses for this VL server */
3820a5143f2SDavid Howells 	unsigned long		flags;
3830a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED	0		/* The VL server has been probed */
3840a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING	1		/* VL server is being probed */
3853bf0fb6fSDavid Howells #define AFS_VLSERVER_FL_IS_YFS	2		/* Server is YFS not AFS */
3860a5143f2SDavid Howells 	rwlock_t		lock;		/* Lock on addresses */
3870a5143f2SDavid Howells 	atomic_t		usage;
3883bf0fb6fSDavid Howells 
3893bf0fb6fSDavid Howells 	/* Probe state */
3903bf0fb6fSDavid Howells 	wait_queue_head_t	probe_wq;
3913bf0fb6fSDavid Howells 	atomic_t		probe_outstanding;
3923bf0fb6fSDavid Howells 	spinlock_t		probe_lock;
3933bf0fb6fSDavid Howells 	struct {
3943bf0fb6fSDavid Howells 		unsigned int	rtt;		/* RTT as ktime/64 */
3953bf0fb6fSDavid Howells 		u32		abort_code;
3963bf0fb6fSDavid Howells 		short		error;
3973bf0fb6fSDavid Howells 		bool		have_result;
3983bf0fb6fSDavid Howells 		bool		responded:1;
3993bf0fb6fSDavid Howells 		bool		is_yfs:1;
4003bf0fb6fSDavid Howells 		bool		not_yfs:1;
4013bf0fb6fSDavid Howells 		bool		local_failure:1;
4023bf0fb6fSDavid Howells 	} probe;
4033bf0fb6fSDavid Howells 
4040a5143f2SDavid Howells 	u16			port;
4053bf0fb6fSDavid Howells 	u16			name_len;	/* Length of name */
4060a5143f2SDavid Howells 	char			name[];		/* Server name, case-flattened */
4070a5143f2SDavid Howells };
4080a5143f2SDavid Howells 
4090a5143f2SDavid Howells /*
4100a5143f2SDavid Howells  * Weighted list of Volume Location servers.
4110a5143f2SDavid Howells  */
4120a5143f2SDavid Howells struct afs_vlserver_entry {
4130a5143f2SDavid Howells 	u16			priority;	/* Preference (as SRV) */
4140a5143f2SDavid Howells 	u16			weight;		/* Weight (as SRV) */
4150a5143f2SDavid Howells 	enum dns_record_source	source:8;
4160a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4170a5143f2SDavid Howells 	struct afs_vlserver	*server;
4180a5143f2SDavid Howells };
4190a5143f2SDavid Howells 
4200a5143f2SDavid Howells struct afs_vlserver_list {
4210a5143f2SDavid Howells 	struct rcu_head		rcu;
4220a5143f2SDavid Howells 	atomic_t		usage;
4230a5143f2SDavid Howells 	u8			nr_servers;
4240a5143f2SDavid Howells 	u8			index;		/* Server currently in use */
4253bf0fb6fSDavid Howells 	u8			preferred;	/* Preferred server */
4260a5143f2SDavid Howells 	enum dns_record_source	source:8;
4270a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4280a5143f2SDavid Howells 	rwlock_t		lock;
4290a5143f2SDavid Howells 	struct afs_vlserver_entry servers[];
4300a5143f2SDavid Howells };
4310a5143f2SDavid Howells 
4320a5143f2SDavid Howells /*
433d2ddc776SDavid Howells  * Cached VLDB entry.
434d2ddc776SDavid Howells  *
435d2ddc776SDavid Howells  * This is pointed to by cell->vldb_entries, indexed by name.
43608e0e7c8SDavid Howells  */
437d2ddc776SDavid Howells struct afs_vldb_entry {
438d2ddc776SDavid Howells 	afs_volid_t		vid[3];		/* Volume IDs for R/W, R/O and Bak volumes */
43900d3b7a4SDavid Howells 
440d2ddc776SDavid Howells 	unsigned long		flags;
441d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW		0		/* - R/W volume exists */
442d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO		1		/* - R/O volume exists */
443d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK	2		/* - Backup volume exists */
444d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID	3		/* - Record is valid */
445d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR	4		/* - VL server returned error */
446d2ddc776SDavid Howells 
447d2ddc776SDavid Howells 	uuid_t			fs_server[AFS_NMAXNSERVERS];
448d2ddc776SDavid Howells 	u8			fs_mask[AFS_NMAXNSERVERS];
44908e0e7c8SDavid Howells #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
45008e0e7c8SDavid Howells #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
45108e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
452d2ddc776SDavid Howells 	short			error;
453d2ddc776SDavid Howells 	u8			nr_servers;	/* Number of server records */
454d2ddc776SDavid Howells 	u8			name_len;
455d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
45608e0e7c8SDavid Howells };
45708e0e7c8SDavid Howells 
45808e0e7c8SDavid Howells /*
459d2ddc776SDavid Howells  * Record of fileserver with which we're actively communicating.
46008e0e7c8SDavid Howells  */
46108e0e7c8SDavid Howells struct afs_server {
462d2ddc776SDavid Howells 	struct rcu_head		rcu;
463d2ddc776SDavid Howells 	union {
464d2ddc776SDavid Howells 		uuid_t		uuid;		/* Server ID */
465d2ddc776SDavid Howells 		struct afs_uuid	_uuid;
466d2ddc776SDavid Howells 	};
467c435ee34SDavid Howells 
468d2ddc776SDavid Howells 	struct afs_addr_list	__rcu *addresses;
469d2ddc776SDavid Howells 	struct rb_node		uuid_rb;	/* Link in net->servers */
470d2ddc776SDavid Howells 	struct hlist_node	addr4_link;	/* Link in net->fs_addresses4 */
471d2ddc776SDavid Howells 	struct hlist_node	addr6_link;	/* Link in net->fs_addresses6 */
472d2ddc776SDavid Howells 	struct hlist_node	proc_link;	/* Link in net->fs_proc */
473d2ddc776SDavid Howells 	struct afs_server	*gc_next;	/* Next server in manager's list */
474d2ddc776SDavid Howells 	time64_t		put_time;	/* Time at which last put */
475d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update the record */
476c435ee34SDavid Howells 	unsigned long		flags;
477d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_READY	1		/* The record is not ready for use */
478d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_FOUND	2		/* VL server says no such server */
479d2ddc776SDavid Howells #define AFS_SERVER_FL_VL_FAIL	3		/* Failed to access VL server */
480d2ddc776SDavid Howells #define AFS_SERVER_FL_UPDATING	4
481d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBED	5		/* The fileserver has been probed */
482d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBING	6		/* Fileserver is being probed */
4835cf9dd55SDavid Howells #define AFS_SERVER_FL_NO_IBULK	7		/* Fileserver doesn't support FS.InlineBulkStatus */
484f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8		/* May have callbacks on this fileserver */
48530062bd1SDavid Howells #define AFS_SERVER_FL_IS_YFS	9		/* Server is YFS not AFS */
48630062bd1SDavid Howells #define AFS_SERVER_FL_NO_RM2	10		/* Fileserver doesn't support YFS.RemoveFile2 */
4873bf0fb6fSDavid Howells #define AFS_SERVER_FL_HAVE_EPOCH 11		/* ->epoch is valid */
488d2ddc776SDavid Howells 	atomic_t		usage;
489d2ddc776SDavid Howells 	u32			addr_version;	/* Address list version */
4903bf0fb6fSDavid Howells 	u32			cm_epoch;	/* Server RxRPC epoch */
49108e0e7c8SDavid Howells 
49208e0e7c8SDavid Howells 	/* file service access */
493d2ddc776SDavid Howells 	rwlock_t		fs_lock;	/* access lock */
49408e0e7c8SDavid Howells 
49508e0e7c8SDavid Howells 	/* callback promise management */
49647ea0f2eSDavid Howells 	struct hlist_head	cb_volumes;	/* List of volume interests on this server */
497c435ee34SDavid Howells 	unsigned		cb_s_break;	/* Break-everything counter. */
498c435ee34SDavid Howells 	rwlock_t		cb_break_lock;	/* Volume finding lock */
4993bf0fb6fSDavid Howells 
5003bf0fb6fSDavid Howells 	/* Probe state */
5013bf0fb6fSDavid Howells 	wait_queue_head_t	probe_wq;
5023bf0fb6fSDavid Howells 	atomic_t		probe_outstanding;
5033bf0fb6fSDavid Howells 	spinlock_t		probe_lock;
5043bf0fb6fSDavid Howells 	struct {
5053bf0fb6fSDavid Howells 		unsigned int	rtt;		/* RTT as ktime/64 */
5063bf0fb6fSDavid Howells 		u32		abort_code;
5073bf0fb6fSDavid Howells 		u32		cm_epoch;
5083bf0fb6fSDavid Howells 		short		error;
5093bf0fb6fSDavid Howells 		bool		have_result;
5103bf0fb6fSDavid Howells 		bool		responded:1;
5113bf0fb6fSDavid Howells 		bool		is_yfs:1;
5123bf0fb6fSDavid Howells 		bool		not_yfs:1;
5133bf0fb6fSDavid Howells 		bool		local_failure:1;
5143bf0fb6fSDavid Howells 		bool		no_epoch:1;
5153bf0fb6fSDavid Howells 		bool		cm_probed:1;
5163bf0fb6fSDavid Howells 		bool		said_rebooted:1;
5173bf0fb6fSDavid Howells 		bool		said_inconsistent:1;
5183bf0fb6fSDavid Howells 	} probe;
519c435ee34SDavid Howells };
520c435ee34SDavid Howells 
521c435ee34SDavid Howells /*
52247ea0f2eSDavid Howells  * Volume collation in the server's callback interest list.
52347ea0f2eSDavid Howells  */
52447ea0f2eSDavid Howells struct afs_vol_interest {
52547ea0f2eSDavid Howells 	struct hlist_node	srv_link;	/* Link in server->cb_volumes */
52647ea0f2eSDavid Howells 	struct hlist_head	cb_interests;	/* List of callback interests on the server */
52747ea0f2eSDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
52847ea0f2eSDavid Howells 	unsigned int		usage;
52947ea0f2eSDavid Howells };
53047ea0f2eSDavid Howells 
53147ea0f2eSDavid Howells /*
532c435ee34SDavid Howells  * Interest by a superblock on a server.
533c435ee34SDavid Howells  */
534c435ee34SDavid Howells struct afs_cb_interest {
53547ea0f2eSDavid Howells 	struct hlist_node	cb_vlink;	/* Link in vol_interest->cb_interests */
53647ea0f2eSDavid Howells 	struct afs_vol_interest	*vol_interest;
537c435ee34SDavid Howells 	struct afs_server	*server;	/* Server on which this interest resides */
538c435ee34SDavid Howells 	struct super_block	*sb;		/* Superblock on which inodes reside */
539c435ee34SDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
540c435ee34SDavid Howells 	refcount_t		usage;
54108e0e7c8SDavid Howells };
54208e0e7c8SDavid Howells 
54308e0e7c8SDavid Howells /*
544d2ddc776SDavid Howells  * Replaceable server list.
54508e0e7c8SDavid Howells  */
546d2ddc776SDavid Howells struct afs_server_entry {
547d2ddc776SDavid Howells 	struct afs_server	*server;
548d2ddc776SDavid Howells 	struct afs_cb_interest	*cb_interest;
549d2ddc776SDavid Howells };
550d2ddc776SDavid Howells 
551d2ddc776SDavid Howells struct afs_server_list {
552d2ddc776SDavid Howells 	refcount_t		usage;
5533bf0fb6fSDavid Howells 	unsigned char		nr_servers;
5543bf0fb6fSDavid Howells 	unsigned char		preferred;	/* Preferred server */
555d2ddc776SDavid Howells 	unsigned short		vnovol_mask;	/* Servers to be skipped due to VNOVOL */
556d2ddc776SDavid Howells 	unsigned int		seq;		/* Set to ->servers_seq when installed */
557d4a96becSDavid Howells 	rwlock_t		lock;
558d2ddc776SDavid Howells 	struct afs_server_entry	servers[];
55908e0e7c8SDavid Howells };
56008e0e7c8SDavid Howells 
56108e0e7c8SDavid Howells /*
562d2ddc776SDavid Howells  * Live AFS volume management.
56308e0e7c8SDavid Howells  */
564d2ddc776SDavid Howells struct afs_volume {
565d2ddc776SDavid Howells 	afs_volid_t		vid;		/* volume ID */
566d2ddc776SDavid Howells 	atomic_t		usage;
567d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update */
568d2ddc776SDavid Howells 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
569d2ddc776SDavid Howells 	struct list_head	proc_link;	/* Link in cell->vl_proc */
570d2ddc776SDavid Howells 	unsigned long		flags;
571d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE	0	/* - T if an update needs performing */
572d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING	1	/* - T if an update is in progress */
573d2ddc776SDavid Howells #define AFS_VOLUME_WAIT		2	/* - T if users must wait for update */
574d2ddc776SDavid Howells #define AFS_VOLUME_DELETED	3	/* - T if volume appears deleted */
575d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE	4	/* - T if volume offline notice given */
576d2ddc776SDavid Howells #define AFS_VOLUME_BUSY		5	/* - T if volume busy notice given */
577d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
578d2ddc776SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
579d2ddc776SDavid Howells #endif
580d2ddc776SDavid Howells 	struct afs_server_list	*servers;	/* List of servers on which volume resides */
581d2ddc776SDavid Howells 	rwlock_t		servers_lock;	/* Lock for ->servers */
582d2ddc776SDavid Howells 	unsigned int		servers_seq;	/* Incremented each time ->servers changes */
583d2ddc776SDavid Howells 
58468251f0aSDavid Howells 	unsigned		cb_v_break;	/* Break-everything counter. */
58568251f0aSDavid Howells 	rwlock_t		cb_break_lock;
58668251f0aSDavid Howells 
587d2ddc776SDavid Howells 	afs_voltype_t		type;		/* type of volume */
588d2ddc776SDavid Howells 	short			error;
589d2ddc776SDavid Howells 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
590d2ddc776SDavid Howells 	u8			name_len;
591d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
59208e0e7c8SDavid Howells };
59308e0e7c8SDavid Howells 
5940fafdc9fSDavid Howells enum afs_lock_state {
5950fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NONE,		/* The vnode has no lock on the server */
5960fafdc9fSDavid Howells 	AFS_VNODE_LOCK_WAITING_FOR_CB,	/* We're waiting for the server to break the callback */
5970fafdc9fSDavid Howells 	AFS_VNODE_LOCK_SETTING,		/* We're asking the server for a lock */
5980fafdc9fSDavid Howells 	AFS_VNODE_LOCK_GRANTED,		/* We have a lock on the server */
5990fafdc9fSDavid Howells 	AFS_VNODE_LOCK_EXTENDING,	/* We're extending a lock on the server */
6000fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NEED_UNLOCK,	/* We need to unlock on the server */
6010fafdc9fSDavid Howells 	AFS_VNODE_LOCK_UNLOCKING,	/* We're telling the server to unlock */
602cdfb26b4SDavid Howells 	AFS_VNODE_LOCK_DELETED,		/* The vnode has been deleted whilst we have a lock */
6030fafdc9fSDavid Howells };
6040fafdc9fSDavid Howells 
60508e0e7c8SDavid Howells /*
606f8de483eSDavid Howells  * AFS inode private data.
607f8de483eSDavid Howells  *
608f8de483eSDavid Howells  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
609f8de483eSDavid Howells  * leak from one inode to another.
61008e0e7c8SDavid Howells  */
61108e0e7c8SDavid Howells struct afs_vnode {
61208e0e7c8SDavid Howells 	struct inode		vfs_inode;	/* the VFS's inode record */
61308e0e7c8SDavid Howells 
61408e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume on which vnode resides */
61508e0e7c8SDavid Howells 	struct afs_fid		fid;		/* the file identifier for this inode */
61608e0e7c8SDavid Howells 	struct afs_file_status	status;		/* AFS status info for this file */
617a4ff7401SDavid Howells 	afs_dataversion_t	invalid_before;	/* Child dentries are invalid before this */
6189b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
6199b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
62008e0e7c8SDavid Howells #endif
621fe342cf7SDavid Howells 	struct afs_permits __rcu *permit_cache;	/* cache of permits so far obtained */
622d2ddc776SDavid Howells 	struct mutex		io_lock;	/* Lock for serialising I/O on this mutex */
623b61f7dcfSDavid Howells 	struct rw_semaphore	validate_lock;	/* lock for validating this vnode */
62479ddbfa5SDavid Howells 	struct rw_semaphore	rmdir_lock;	/* Lock for rmdir vs sillyrename */
62579ddbfa5SDavid Howells 	struct key		*silly_key;	/* Silly rename key */
6264343d008SDavid Howells 	spinlock_t		wb_lock;	/* lock for wb_keys */
62708e0e7c8SDavid Howells 	spinlock_t		lock;		/* waitqueue/flags lock */
62808e0e7c8SDavid Howells 	unsigned long		flags;
629c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED	0		/* Set if vnode has a callback promise */
630260a9803SDavid Howells #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
631f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID	2		/* Set if dir contents are valid */
63208e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
63308e0e7c8SDavid Howells #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
63408e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
6350fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL	6		/* set if Vnode is an auto mount point */
6360fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR	7 		/* set if Vnode is a pseudo directory */
6375a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT	8		/* Set if file has new content (create/trunc-0) */
63808e0e7c8SDavid Howells 
6394343d008SDavid Howells 	struct list_head	wb_keys;	/* List of keys available for writeback */
640e8d6c554SDavid Howells 	struct list_head	pending_locks;	/* locks waiting to be granted */
641e8d6c554SDavid Howells 	struct list_head	granted_locks;	/* locks granted on this file */
642e8d6c554SDavid Howells 	struct delayed_work	lock_work;	/* work to be done in locking */
6430fafdc9fSDavid Howells 	struct key		*lock_key;	/* Key to be used in lock ops */
644a690f60aSDavid Howells 	ktime_t			locked_at;	/* Time at which lock obtained */
6450fafdc9fSDavid Howells 	enum afs_lock_state	lock_state : 8;
6460fafdc9fSDavid Howells 	afs_lock_type_t		lock_type : 8;
64731143d5dSDavid Howells 
64808e0e7c8SDavid Howells 	/* outstanding callback notification on this file */
649c435ee34SDavid Howells 	struct afs_cb_interest	*cb_interest;	/* Server on which this resides */
650c435ee34SDavid Howells 	unsigned int		cb_s_break;	/* Mass break counter on ->server */
65168251f0aSDavid Howells 	unsigned int		cb_v_break;	/* Mass break counter on ->volume */
652c435ee34SDavid Howells 	unsigned int		cb_break;	/* Break counter on vnode */
653c435ee34SDavid Howells 	seqlock_t		cb_lock;	/* Lock for ->cb_interest, ->status, ->cb_*break */
654c435ee34SDavid Howells 
655c435ee34SDavid Howells 	time64_t		cb_expires_at;	/* time at which callback expires */
65608e0e7c8SDavid Howells 	unsigned		cb_version;	/* callback version */
65708e0e7c8SDavid Howells 	afs_callback_type_t	cb_type;	/* type of callback */
65808e0e7c8SDavid Howells };
65908e0e7c8SDavid Howells 
66012bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
66112bdcf33SDavid Howells {
66212bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE
66312bdcf33SDavid Howells 	return vnode->cache;
66412bdcf33SDavid Howells #else
66512bdcf33SDavid Howells 	return NULL;
66612bdcf33SDavid Howells #endif
66712bdcf33SDavid Howells }
66812bdcf33SDavid Howells 
66900d3b7a4SDavid Howells /*
67000d3b7a4SDavid Howells  * cached security record for one user's attempt to access a vnode
67100d3b7a4SDavid Howells  */
67200d3b7a4SDavid Howells struct afs_permit {
67300d3b7a4SDavid Howells 	struct key		*key;		/* RxRPC ticket holding a security context */
674be080a6fSDavid Howells 	afs_access_t		access;		/* CallerAccess value for this key */
67500d3b7a4SDavid Howells };
67600d3b7a4SDavid Howells 
67700d3b7a4SDavid Howells /*
678be080a6fSDavid Howells  * Immutable cache of CallerAccess records from attempts to access vnodes.
679be080a6fSDavid Howells  * These may be shared between multiple vnodes.
68000d3b7a4SDavid Howells  */
68100d3b7a4SDavid Howells struct afs_permits {
682be080a6fSDavid Howells 	struct rcu_head		rcu;
683be080a6fSDavid Howells 	struct hlist_node	hash_node;	/* Link in hash */
684be080a6fSDavid Howells 	unsigned long		h;		/* Hash value for this permit list */
685be080a6fSDavid Howells 	refcount_t		usage;
686be080a6fSDavid Howells 	unsigned short		nr_permits;	/* Number of records */
687be080a6fSDavid Howells 	bool			invalidated;	/* Invalidated due to key change */
688be080a6fSDavid Howells 	struct afs_permit	permits[];	/* List of permits sorted by key pointer */
68900d3b7a4SDavid Howells };
69000d3b7a4SDavid Howells 
691b908fe6bSDavid Howells /*
692b908fe6bSDavid Howells  * record of one of a system's set of network interfaces
693b908fe6bSDavid Howells  */
694b908fe6bSDavid Howells struct afs_interface {
695b908fe6bSDavid Howells 	struct in_addr	address;	/* IPv4 address bound to interface */
696b908fe6bSDavid Howells 	struct in_addr	netmask;	/* netmask applied to address */
697b908fe6bSDavid Howells 	unsigned	mtu;		/* MTU of interface */
698b908fe6bSDavid Howells };
699b908fe6bSDavid Howells 
7008b2a464cSDavid Howells /*
7014584ae96SDavid Howells  * Error prioritisation and accumulation.
7024584ae96SDavid Howells  */
7034584ae96SDavid Howells struct afs_error {
7044584ae96SDavid Howells 	short	error;			/* Accumulated error */
7054584ae96SDavid Howells 	bool	responded;		/* T if server responded */
7064584ae96SDavid Howells };
7074584ae96SDavid Howells 
7084584ae96SDavid Howells /*
7098b2a464cSDavid Howells  * Cursor for iterating over a server's address list.
7108b2a464cSDavid Howells  */
7118b2a464cSDavid Howells struct afs_addr_cursor {
7128b2a464cSDavid Howells 	struct afs_addr_list	*alist;		/* Current address list (pins ref) */
7133bf0fb6fSDavid Howells 	unsigned long		tried;		/* Tried addresses */
7143bf0fb6fSDavid Howells 	signed char		index;		/* Current address */
7158b2a464cSDavid Howells 	bool			responded;	/* T if the current address responded */
716744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of address iterations */
7173bf0fb6fSDavid Howells 	short			error;
7183bf0fb6fSDavid Howells 	u32			abort_code;
7198b2a464cSDavid Howells };
7208b2a464cSDavid Howells 
7218b2a464cSDavid Howells /*
7220a5143f2SDavid Howells  * Cursor for iterating over a set of volume location servers.
7230a5143f2SDavid Howells  */
7240a5143f2SDavid Howells struct afs_vl_cursor {
7250a5143f2SDavid Howells 	struct afs_addr_cursor	ac;
7260a5143f2SDavid Howells 	struct afs_cell		*cell;		/* The cell we're querying */
7270a5143f2SDavid Howells 	struct afs_vlserver_list *server_list;	/* Current server list (pins ref) */
7283bf0fb6fSDavid Howells 	struct afs_vlserver	*server;	/* Server on which this resides */
7290a5143f2SDavid Howells 	struct key		*key;		/* Key for the server */
7303bf0fb6fSDavid Howells 	unsigned long		untried;	/* Bitmask of untried servers */
7313bf0fb6fSDavid Howells 	short			index;		/* Current server */
7320a5143f2SDavid Howells 	short			error;
7330a5143f2SDavid Howells 	unsigned short		flags;
7340a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP	0x0001		/* Set to cease iteration */
7350a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY	0x0002		/* Set to do a retry */
7360a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED	0x0004		/* Set if started a retry */
737744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
7380a5143f2SDavid Howells };
7390a5143f2SDavid Howells 
7400a5143f2SDavid Howells /*
7418b2a464cSDavid Howells  * Cursor for iterating over a set of fileservers.
7428b2a464cSDavid Howells  */
7438b2a464cSDavid Howells struct afs_fs_cursor {
7448b2a464cSDavid Howells 	struct afs_addr_cursor	ac;
745d2ddc776SDavid Howells 	struct afs_vnode	*vnode;
746d2ddc776SDavid Howells 	struct afs_server_list	*server_list;	/* Current server list (pins ref) */
747d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Server on which this resides (pins ref) */
748d2ddc776SDavid Howells 	struct key		*key;		/* Key for the server */
7493bf0fb6fSDavid Howells 	unsigned long		untried;	/* Bitmask of untried servers */
750d2ddc776SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
751d2ddc776SDavid Howells 	unsigned int		cb_break_2;	/* cb_break + cb_s_break (2nd vnode) */
7523bf0fb6fSDavid Howells 	short			index;		/* Current server */
753e7f680f4SDavid Howells 	short			error;
754d2ddc776SDavid Howells 	unsigned short		flags;
755d2ddc776SDavid Howells #define AFS_FS_CURSOR_STOP	0x0001		/* Set to cease iteration */
756d2ddc776SDavid Howells #define AFS_FS_CURSOR_VBUSY	0x0002		/* Set if seen VBUSY */
757d2ddc776SDavid Howells #define AFS_FS_CURSOR_VMOVED	0x0004		/* Set if seen VMOVED */
758d2ddc776SDavid Howells #define AFS_FS_CURSOR_VNOVOL	0x0008		/* Set if seen VNOVOL */
759d2ddc776SDavid Howells #define AFS_FS_CURSOR_CUR_ONLY	0x0010		/* Set if current server only (file lock held) */
760d2ddc776SDavid Howells #define AFS_FS_CURSOR_NO_VSLEEP	0x0020		/* Set to prevent sleep on VBUSY, VOFFLINE, ... */
761744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
7628b2a464cSDavid Howells };
7638b2a464cSDavid Howells 
764402cb8ddSDavid Howells /*
765402cb8ddSDavid Howells  * Cache auxiliary data.
766402cb8ddSDavid Howells  */
767402cb8ddSDavid Howells struct afs_vnode_cache_aux {
768402cb8ddSDavid Howells 	u64			data_version;
769402cb8ddSDavid Howells } __packed;
770402cb8ddSDavid Howells 
77198bf40cdSDavid Howells #include <trace/events/afs.h>
77298bf40cdSDavid Howells 
77308e0e7c8SDavid Howells /*****************************************************************************/
77408e0e7c8SDavid Howells /*
7758b2a464cSDavid Howells  * addr_list.c
7768b2a464cSDavid Howells  */
7778b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
7788b2a464cSDavid Howells {
7798b2a464cSDavid Howells 	if (alist)
7808b2a464cSDavid Howells 		refcount_inc(&alist->usage);
7818b2a464cSDavid Howells 	return alist;
7828b2a464cSDavid Howells }
7838b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
7848b2a464cSDavid Howells 						unsigned short,
7858b2a464cSDavid Howells 						unsigned short);
7868b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *);
7870a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
7880a5143f2SDavid Howells 						      const char *, size_t, char,
7898b2a464cSDavid Howells 						      unsigned short, unsigned short);
7900a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
7918b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *);
7928b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *);
7938b2a464cSDavid Howells 
794bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
795bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
796d2ddc776SDavid Howells 
7978b2a464cSDavid Howells /*
7989b3f26c9SDavid Howells  * cache.c
7999b3f26c9SDavid Howells  */
8009b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
8019b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs;
8029b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def;
8039b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def;
8049b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def;
8059b3f26c9SDavid Howells #else
8069b3f26c9SDavid Howells #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
8079b3f26c9SDavid Howells #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
8089b3f26c9SDavid Howells #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
8099b3f26c9SDavid Howells #endif
8109b3f26c9SDavid Howells 
8119b3f26c9SDavid Howells /*
81208e0e7c8SDavid Howells  * callback.c
81308e0e7c8SDavid Howells  */
81408e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
81530062bd1SDavid Howells extern void __afs_break_callback(struct afs_vnode *);
816c435ee34SDavid Howells extern void afs_break_callback(struct afs_vnode *);
8175cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
818c435ee34SDavid Howells 
819d4a96becSDavid Howells extern int afs_register_server_cb_interest(struct afs_vnode *,
820d4a96becSDavid Howells 					   struct afs_server_list *, unsigned int);
821c435ee34SDavid Howells extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
822d2ddc776SDavid Howells extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
823c435ee34SDavid Howells 
824c435ee34SDavid Howells static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
825c435ee34SDavid Howells {
826d4a96becSDavid Howells 	if (cbi)
827c435ee34SDavid Howells 		refcount_inc(&cbi->usage);
828c435ee34SDavid Howells 	return cbi;
829c435ee34SDavid Howells }
8301da177e4SLinus Torvalds 
83168251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
83268251f0aSDavid Howells {
833eeba1e9cSDavid Howells 	return vnode->cb_break + vnode->cb_v_break;
83468251f0aSDavid Howells }
83568251f0aSDavid Howells 
83618ac6185SDavid Howells static inline bool afs_cb_is_broken(unsigned int cb_break,
83718ac6185SDavid Howells 				    const struct afs_vnode *vnode,
83818ac6185SDavid Howells 				    const struct afs_cb_interest *cbi)
83968251f0aSDavid Howells {
84018ac6185SDavid Howells 	return !cbi || cb_break != (vnode->cb_break +
84118ac6185SDavid Howells 				    vnode->volume->cb_v_break);
84268251f0aSDavid Howells }
84368251f0aSDavid Howells 
8441da177e4SLinus Torvalds /*
8451da177e4SLinus Torvalds  * cell.c
8461da177e4SLinus Torvalds  */
847989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
848989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
849989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
850989782dcSDavid Howells 					const char *, bool);
8518b2a464cSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *);
8529ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *);
853989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
854989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
855f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
85608e0e7c8SDavid Howells 
85708e0e7c8SDavid Howells /*
85808e0e7c8SDavid Howells  * cmservice.c
85908e0e7c8SDavid Howells  */
86008e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
86108e0e7c8SDavid Howells 
8621da177e4SLinus Torvalds /*
8631da177e4SLinus Torvalds  * dir.c
8641da177e4SLinus Torvalds  */
8654b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
8664d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
867f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops;
8684d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
8694d673da1SDavid Howells 
87066c7e1d3SDavid Howells extern void afs_d_release(struct dentry *);
87179ddbfa5SDavid Howells extern int afs_dir_remove_link(struct dentry *, struct key *, unsigned long, unsigned long);
87266c7e1d3SDavid Howells 
87366c7e1d3SDavid Howells /*
87463a4681fSDavid Howells  * dir_edit.c
87563a4681fSDavid Howells  */
87663a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
87763a4681fSDavid Howells 			     enum afs_edit_dir_reason);
87863a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
87963a4681fSDavid Howells 
88063a4681fSDavid Howells /*
88179ddbfa5SDavid Howells  * dir_silly.c
88279ddbfa5SDavid Howells  */
88379ddbfa5SDavid Howells extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
88479ddbfa5SDavid Howells 			   struct dentry *, struct key *);
88579ddbfa5SDavid Howells extern int afs_silly_iput(struct dentry *, struct inode *);
88679ddbfa5SDavid Howells 
88779ddbfa5SDavid Howells /*
88866c7e1d3SDavid Howells  * dynroot.c
88966c7e1d3SDavid Howells  */
89066c7e1d3SDavid Howells extern const struct file_operations afs_dynroot_file_operations;
89166c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
89266c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations;
89366c7e1d3SDavid Howells 
89466c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
8950da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
8960da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
8970da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *);
8980da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *);
8991da177e4SLinus Torvalds 
9001da177e4SLinus Torvalds /*
9011da177e4SLinus Torvalds  * file.c
9021da177e4SLinus Torvalds  */
903f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops;
904754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
90500d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
90600d3b7a4SDavid Howells 
9074343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
9084343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
90900d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
91000d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
911d2ddc776SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
912f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *);
913196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
9141da177e4SLinus Torvalds 
9151da177e4SLinus Torvalds /*
916e8d6c554SDavid Howells  * flock.c
917e8d6c554SDavid Howells  */
918f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
919f044c884SDavid Howells 
920a690f60aSDavid Howells extern void afs_lock_op_done(struct afs_call *);
921e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
922e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
923e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
924e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
925e8d6c554SDavid Howells 
926e8d6c554SDavid Howells /*
92708e0e7c8SDavid Howells  * fsclient.c
92808e0e7c8SDavid Howells  */
929dd9fbcb8SDavid Howells #define AFS_VNODE_NOT_YET_SET	0x01
930dd9fbcb8SDavid Howells #define AFS_VNODE_META_CHANGED	0x02
931dd9fbcb8SDavid Howells #define AFS_VNODE_DATA_CHANGED	0x04
932dd9fbcb8SDavid Howells extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *,
933dd9fbcb8SDavid Howells 					 const afs_dataversion_t *, u8);
934dd9fbcb8SDavid Howells 
9350c3a5ac2SDavid Howells extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
936d2ddc776SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
937d2ddc776SDavid Howells extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
93863a4681fSDavid Howells extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, u64,
939d2ddc776SDavid Howells 			 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
94030062bd1SDavid Howells extern int afs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool, u64);
94163a4681fSDavid Howells extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
94263a4681fSDavid Howells extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
943d2ddc776SDavid Howells 			  struct afs_fid *, struct afs_file_status *);
944d2ddc776SDavid Howells extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
94563a4681fSDavid Howells 			 struct afs_vnode *, const char *, u64, u64);
9464343d008SDavid Howells extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
947d2ddc776SDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned);
948d2ddc776SDavid Howells extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
949d2ddc776SDavid Howells extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
950d2ddc776SDavid Howells extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
951d2ddc776SDavid Howells extern int afs_fs_extend_lock(struct afs_fs_cursor *);
952d2ddc776SDavid Howells extern int afs_fs_release_lock(struct afs_fs_cursor *);
953d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
954d2ddc776SDavid Howells 					struct afs_addr_cursor *, struct key *);
9550b9bf381SDavid Howells extern struct afs_call *afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
9560b9bf381SDavid Howells 						struct afs_addr_cursor *, struct key *,
9570b9bf381SDavid Howells 						unsigned int);
9585cf9dd55SDavid Howells extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
9595cf9dd55SDavid Howells 				     struct afs_fid *, struct afs_file_status *,
9605cf9dd55SDavid Howells 				     struct afs_callback *, unsigned int,
9615cf9dd55SDavid Howells 				     struct afs_volsync *);
9625cf9dd55SDavid Howells extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
9635cf9dd55SDavid Howells 			       struct afs_fid *, struct afs_file_status *,
9645cf9dd55SDavid Howells 			       struct afs_callback *, struct afs_volsync *);
96508e0e7c8SDavid Howells 
96608e0e7c8SDavid Howells /*
9673bf0fb6fSDavid Howells  * fs_probe.c
9683bf0fb6fSDavid Howells  */
9693bf0fb6fSDavid Howells extern void afs_fileserver_probe_result(struct afs_call *);
9703bf0fb6fSDavid Howells extern int afs_probe_fileservers(struct afs_net *, struct key *, struct afs_server_list *);
9713bf0fb6fSDavid Howells extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long);
9723bf0fb6fSDavid Howells 
9733bf0fb6fSDavid Howells /*
9741da177e4SLinus Torvalds  * inode.c
9751da177e4SLinus Torvalds  */
9760c3a5ac2SDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool);
977c435ee34SDavid Howells extern int afs_iget5_test(struct inode *, void *);
9784d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
97900d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *,
980260a9803SDavid Howells 			      struct afs_fid *, struct afs_file_status *,
981d2ddc776SDavid Howells 			      struct afs_callback *,
982d2ddc776SDavid Howells 			      struct afs_cb_interest *);
983416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *);
984260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
985a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
98631143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *);
987b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
988bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
9891da177e4SLinus Torvalds 
9901da177e4SLinus Torvalds /*
9911da177e4SLinus Torvalds  * main.c
9921da177e4SLinus Torvalds  */
9930ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
9945b86d4ffSDavid Howells extern int afs_net_id;
9955b86d4ffSDavid Howells 
9965b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net)
9975b86d4ffSDavid Howells {
9985b86d4ffSDavid Howells 	return net_generic(net, afs_net_id);
9995b86d4ffSDavid Howells }
10005b86d4ffSDavid Howells 
10015b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb)
10025b86d4ffSDavid Howells {
10035b86d4ffSDavid Howells 	return afs_net(AFS_FS_S(sb)->net_ns);
10045b86d4ffSDavid Howells }
1005f044c884SDavid Howells 
1006f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
1007f044c884SDavid Howells {
10085b86d4ffSDavid Howells 	return afs_sb2net(dentry->d_sb);
1009f044c884SDavid Howells }
1010f044c884SDavid Howells 
1011f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
1012f044c884SDavid Howells {
10135b86d4ffSDavid Howells 	return afs_sb2net(inode->i_sb);
1014f044c884SDavid Howells }
1015f044c884SDavid Howells 
1016f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1017f044c884SDavid Howells {
10185b86d4ffSDavid Howells 	return afs_i2net(&vnode->vfs_inode);
1019f044c884SDavid Howells }
1020f044c884SDavid Howells 
1021f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
1022f044c884SDavid Howells {
10235b86d4ffSDavid Howells 	return net_generic(sock_net(sk), afs_net_id);
1024f044c884SDavid Howells }
10251da177e4SLinus Torvalds 
1026d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s)
1027d55b4da4SDavid Howells {
1028d55b4da4SDavid Howells 	atomic_inc(s);
1029d55b4da4SDavid Howells }
1030d55b4da4SDavid Howells 
1031d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1032d55b4da4SDavid Howells 
10331da177e4SLinus Torvalds /*
103408e0e7c8SDavid Howells  * misc.c
103508e0e7c8SDavid Howells  */
103608e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
10374584ae96SDavid Howells extern void afs_prioritise_error(struct afs_error *, int, u32);
103808e0e7c8SDavid Howells 
103908e0e7c8SDavid Howells /*
10401da177e4SLinus Torvalds  * mntpt.c
10411da177e4SLinus Torvalds  */
1042754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
1043bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
10444b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
10451da177e4SLinus Torvalds 
1046d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
104708e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
10481da177e4SLinus Torvalds 
10491da177e4SLinus Torvalds /*
1050b4db2b35SArnd Bergmann  * netdevices.c
1051b4db2b35SArnd Bergmann  */
10525b86d4ffSDavid Howells extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *,
10535b86d4ffSDavid Howells 				   size_t, bool);
1054b4db2b35SArnd Bergmann 
1055b4db2b35SArnd Bergmann /*
10561da177e4SLinus Torvalds  * proc.c
10571da177e4SLinus Torvalds  */
1058b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS
1059f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
1060f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
10615b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *);
10625b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *);
10636f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *);
1064b6cfbecaSDavid Howells #else
1065b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; }
1066b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {}
1067b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
1068b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
1069b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1070b6cfbecaSDavid Howells #endif
10711da177e4SLinus Torvalds 
107208e0e7c8SDavid Howells /*
1073d2ddc776SDavid Howells  * rotate.c
1074d2ddc776SDavid Howells  */
1075d2ddc776SDavid Howells extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
1076d2ddc776SDavid Howells 				      struct key *);
1077d2ddc776SDavid Howells extern bool afs_select_fileserver(struct afs_fs_cursor *);
1078d2ddc776SDavid Howells extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
1079d2ddc776SDavid Howells extern int afs_end_vnode_operation(struct afs_fs_cursor *);
1080d2ddc776SDavid Howells 
1081d2ddc776SDavid Howells /*
108208e0e7c8SDavid Howells  * rxrpc.c
108308e0e7c8SDavid Howells  */
1084f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
10858324f0bcSDavid Howells 
1086f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
1087f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
1088f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
1089341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
10900b9bf381SDavid Howells extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t);
10910b9bf381SDavid Howells extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
1092f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1093f044c884SDavid Howells 					    const struct afs_call_type *,
109408e0e7c8SDavid Howells 					    size_t, size_t);
109508e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
109608e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
1097b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
109812bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool);
1099160cb957SDavid Howells extern int afs_protocol_error(struct afs_call *, int, enum afs_eproto_cause);
110008e0e7c8SDavid Howells 
110112bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
110212bdcf33SDavid Howells {
110312bdcf33SDavid Howells 	call->kvec[0].iov_base = buf;
110412bdcf33SDavid Howells 	call->kvec[0].iov_len = size;
110512bdcf33SDavid Howells 	iov_iter_kvec(&call->iter, READ, call->kvec, 1, size);
110612bdcf33SDavid Howells }
110712bdcf33SDavid Howells 
110812bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call)
110912bdcf33SDavid Howells {
111012bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
111112bdcf33SDavid Howells }
111212bdcf33SDavid Howells 
111312bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call)
111412bdcf33SDavid Howells {
111512bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
111612bdcf33SDavid Howells }
111712bdcf33SDavid Howells 
111812bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size)
111912bdcf33SDavid Howells {
112012bdcf33SDavid Howells 	iov_iter_discard(&call->iter, READ, size);
112112bdcf33SDavid Howells }
112212bdcf33SDavid Howells 
112312bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
112412bdcf33SDavid Howells {
112512bdcf33SDavid Howells 	afs_extract_begin(call, call->buffer, size);
112612bdcf33SDavid Howells }
112712bdcf33SDavid Howells 
1128d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
1129372ee163SDavid Howells {
113012bdcf33SDavid Howells 	return afs_extract_data(call, false);
1131372ee163SDavid Howells }
1132372ee163SDavid Howells 
113398bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
113498bf40cdSDavid Howells 					enum afs_call_state state)
113598bf40cdSDavid Howells {
113698bf40cdSDavid Howells 	return READ_ONCE(call->state) == state;
113798bf40cdSDavid Howells }
113898bf40cdSDavid Howells 
113998bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
114098bf40cdSDavid Howells 				      enum afs_call_state from,
114198bf40cdSDavid Howells 				      enum afs_call_state to)
114298bf40cdSDavid Howells {
114398bf40cdSDavid Howells 	bool ok = false;
114498bf40cdSDavid Howells 
114598bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
114698bf40cdSDavid Howells 	if (call->state == from) {
114798bf40cdSDavid Howells 		call->state = to;
114898bf40cdSDavid Howells 		trace_afs_call_state(call, from, to, 0, 0);
114998bf40cdSDavid Howells 		ok = true;
115098bf40cdSDavid Howells 	}
115198bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
115298bf40cdSDavid Howells 	return ok;
115398bf40cdSDavid Howells }
115498bf40cdSDavid Howells 
115598bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
115698bf40cdSDavid Howells 					 int error, u32 remote_abort)
115798bf40cdSDavid Howells {
115898bf40cdSDavid Howells 	enum afs_call_state state;
115998bf40cdSDavid Howells 	bool ok = false;
116098bf40cdSDavid Howells 
116198bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
116298bf40cdSDavid Howells 	state = call->state;
116398bf40cdSDavid Howells 	if (state != AFS_CALL_COMPLETE) {
116498bf40cdSDavid Howells 		call->abort_code = remote_abort;
116598bf40cdSDavid Howells 		call->error = error;
116698bf40cdSDavid Howells 		call->state = AFS_CALL_COMPLETE;
116798bf40cdSDavid Howells 		trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
116898bf40cdSDavid Howells 				     error, remote_abort);
116998bf40cdSDavid Howells 		ok = true;
117098bf40cdSDavid Howells 	}
117198bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
117298bf40cdSDavid Howells 	if (ok)
117398bf40cdSDavid Howells 		trace_afs_call_done(call);
117498bf40cdSDavid Howells }
117598bf40cdSDavid Howells 
117608e0e7c8SDavid Howells /*
117700d3b7a4SDavid Howells  * security.c
117800d3b7a4SDavid Howells  */
1179be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
118000d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
1181be080a6fSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
1182416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *);
118300d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
11840fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
118510556cb2SAl Viro extern int afs_permission(struct inode *, int);
1186be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
118700d3b7a4SDavid Howells 
118800d3b7a4SDavid Howells /*
118908e0e7c8SDavid Howells  * server.c
119008e0e7c8SDavid Howells  */
119108e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
119208e0e7c8SDavid Howells 
1193c435ee34SDavid Howells static inline struct afs_server *afs_get_server(struct afs_server *server)
1194c435ee34SDavid Howells {
1195c435ee34SDavid Howells 	atomic_inc(&server->usage);
1196c435ee34SDavid Howells 	return server;
1197c435ee34SDavid Howells }
119808e0e7c8SDavid Howells 
1199f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
1200f044c884SDavid Howells 					  const struct sockaddr_rxrpc *);
1201d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
1202d2ddc776SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
12039ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *);
1204d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
1205d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
1206f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
1207d2ddc776SDavid Howells extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
1208d2ddc776SDavid Howells 
1209d2ddc776SDavid Howells /*
1210d2ddc776SDavid Howells  * server_list.c
1211d2ddc776SDavid Howells  */
1212d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1213d2ddc776SDavid Howells {
1214d2ddc776SDavid Howells 	refcount_inc(&slist->usage);
1215d2ddc776SDavid Howells 	return slist;
1216d2ddc776SDavid Howells }
1217d2ddc776SDavid Howells 
1218d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1219d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1220d2ddc776SDavid Howells 						     struct afs_vldb_entry *,
1221d2ddc776SDavid Howells 						     u8);
1222d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
122308e0e7c8SDavid Howells 
122408e0e7c8SDavid Howells /*
122500d3b7a4SDavid Howells  * super.c
122600d3b7a4SDavid Howells  */
1227f044c884SDavid Howells extern int __init afs_fs_init(void);
12285b86d4ffSDavid Howells extern void afs_fs_exit(void);
122900d3b7a4SDavid Howells 
123000d3b7a4SDavid Howells /*
123108e0e7c8SDavid Howells  * vlclient.c
123208e0e7c8SDavid Howells  */
12330a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
12340a5143f2SDavid Howells 							 const char *, int);
12350a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
12360b9bf381SDavid Howells extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *,
12370b9bf381SDavid Howells 						struct key *, struct afs_vlserver *, unsigned int);
12380a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
12390a5143f2SDavid Howells 
12400a5143f2SDavid Howells /*
12413bf0fb6fSDavid Howells  * vl_probe.c
12423bf0fb6fSDavid Howells  */
12433bf0fb6fSDavid Howells extern void afs_vlserver_probe_result(struct afs_call *);
12443bf0fb6fSDavid Howells extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
12453bf0fb6fSDavid Howells extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
12463bf0fb6fSDavid Howells 
12473bf0fb6fSDavid Howells /*
12480a5143f2SDavid Howells  * vl_rotate.c
12490a5143f2SDavid Howells  */
12500a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
12510a5143f2SDavid Howells 					 struct afs_cell *, struct key *);
12520a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *);
12530a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
12540a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
12550a5143f2SDavid Howells 
12560a5143f2SDavid Howells /*
12570a5143f2SDavid Howells  * vlserver_list.c
12580a5143f2SDavid Howells  */
12590a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
12600a5143f2SDavid Howells {
12610a5143f2SDavid Howells 	atomic_inc(&vlserver->usage);
12620a5143f2SDavid Howells 	return vlserver;
12630a5143f2SDavid Howells }
12640a5143f2SDavid Howells 
12650a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
12660a5143f2SDavid Howells {
12670a5143f2SDavid Howells 	if (vllist)
12680a5143f2SDavid Howells 		atomic_inc(&vllist->usage);
12690a5143f2SDavid Howells 	return vllist;
12700a5143f2SDavid Howells }
12710a5143f2SDavid Howells 
12720a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
12730a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
12740a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
12750a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
12760a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
12770a5143f2SDavid Howells 							   const void *, size_t);
127808e0e7c8SDavid Howells 
127908e0e7c8SDavid Howells /*
128008e0e7c8SDavid Howells  * volume.c
128108e0e7c8SDavid Howells  */
1282d2ddc776SDavid Howells static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
128349566f6fSDavid Howells {
128449566f6fSDavid Howells 	if (volume)
128549566f6fSDavid Howells 		atomic_inc(&volume->usage);
128649566f6fSDavid Howells 	return volume;
128749566f6fSDavid Howells }
128808e0e7c8SDavid Howells 
128913fcc683SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1290d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *);
1291d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
12929ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
1293d2ddc776SDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct key *);
129408e0e7c8SDavid Howells 
129531143d5dSDavid Howells /*
129631143d5dSDavid Howells  * write.c
129731143d5dSDavid Howells  */
129831143d5dSDavid Howells extern int afs_set_page_dirty(struct page *);
129915b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
130015b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned flags,
130115b4650eSNick Piggin 			struct page **pagep, void **fsdata);
130215b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
130315b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned copied,
130415b4650eSNick Piggin 			struct page *page, void *fsdata);
130531143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
130631143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
130731143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
130850b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
130902c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
13100722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
13114343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
13124343d008SDavid Howells extern int afs_launder_page(struct page *);
131331143d5dSDavid Howells 
1314d3e3b7eaSDavid Howells /*
1315d3e3b7eaSDavid Howells  * xattr.c
1316d3e3b7eaSDavid Howells  */
1317d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
1318d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
131931143d5dSDavid Howells 
132030062bd1SDavid Howells /*
132130062bd1SDavid Howells  * yfsclient.c
132230062bd1SDavid Howells  */
132330062bd1SDavid Howells extern int yfs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
132430062bd1SDavid Howells extern int yfs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
132530062bd1SDavid Howells extern int yfs_fs_create_file(struct afs_fs_cursor *, const char *, umode_t, u64,
132630062bd1SDavid Howells 			      struct afs_fid *, struct afs_file_status *, struct afs_callback *);
132730062bd1SDavid Howells extern int yfs_fs_make_dir(struct afs_fs_cursor *, const char *, umode_t, u64,
132830062bd1SDavid Howells 			 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
132930062bd1SDavid Howells extern int yfs_fs_remove_file2(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
133030062bd1SDavid Howells extern int yfs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool, u64);
133130062bd1SDavid Howells extern int yfs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
133230062bd1SDavid Howells extern int yfs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
133330062bd1SDavid Howells 			  struct afs_fid *, struct afs_file_status *);
133430062bd1SDavid Howells extern int yfs_fs_rename(struct afs_fs_cursor *, const char *,
133530062bd1SDavid Howells 			 struct afs_vnode *, const char *, u64, u64);
133630062bd1SDavid Howells extern int yfs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
133730062bd1SDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned);
133830062bd1SDavid Howells extern int yfs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
133930062bd1SDavid Howells extern int yfs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
134030062bd1SDavid Howells extern int yfs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
134130062bd1SDavid Howells extern int yfs_fs_extend_lock(struct afs_fs_cursor *);
134230062bd1SDavid Howells extern int yfs_fs_release_lock(struct afs_fs_cursor *);
134330062bd1SDavid Howells extern int yfs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
134430062bd1SDavid Howells 			       struct afs_fid *, struct afs_file_status *,
134530062bd1SDavid Howells 			       struct afs_callback *, struct afs_volsync *);
134630062bd1SDavid Howells extern int yfs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
134730062bd1SDavid Howells 				     struct afs_fid *, struct afs_file_status *,
134830062bd1SDavid Howells 				     struct afs_callback *, unsigned int,
134930062bd1SDavid Howells 				     struct afs_volsync *);
1350d2ddc776SDavid Howells 
1351d2ddc776SDavid Howells /*
1352d2ddc776SDavid Howells  * Miscellaneous inline functions.
1353d2ddc776SDavid Howells  */
1354d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1355d2ddc776SDavid Howells {
1356d2ddc776SDavid Howells 	return container_of(inode, struct afs_vnode, vfs_inode);
1357d2ddc776SDavid Howells }
1358d2ddc776SDavid Howells 
1359d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1360d2ddc776SDavid Howells {
1361d2ddc776SDavid Howells 	return &vnode->vfs_inode;
1362d2ddc776SDavid Howells }
1363d2ddc776SDavid Howells 
1364d2ddc776SDavid Howells static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
1365d2ddc776SDavid Howells 					   struct afs_vnode *vnode,
1366d2ddc776SDavid Howells 					   unsigned int cb_break)
1367d2ddc776SDavid Howells {
1368d2ddc776SDavid Howells 	if (fc->ac.error == 0)
1369d2ddc776SDavid Howells 		afs_cache_permit(vnode, fc->key, cb_break);
1370d2ddc776SDavid Howells }
1371d2ddc776SDavid Howells 
1372d2ddc776SDavid Howells static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1373d2ddc776SDavid Howells 						 struct afs_vnode *vnode)
1374d2ddc776SDavid Howells {
1375d2ddc776SDavid Howells 	if (fc->ac.error == -ENOENT) {
1376d2ddc776SDavid Howells 		set_bit(AFS_VNODE_DELETED, &vnode->flags);
1377d2ddc776SDavid Howells 		afs_break_callback(vnode);
1378d2ddc776SDavid Howells 	}
1379d2ddc776SDavid Howells }
1380d2ddc776SDavid Howells 
1381f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1382f51375cdSDavid Howells {
1383f51375cdSDavid Howells 	trace_afs_io_error(call->debug_id, -EIO, where);
1384f51375cdSDavid Howells 	return -EIO;
1385f51375cdSDavid Howells }
1386f51375cdSDavid Howells 
1387f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1388f51375cdSDavid Howells {
1389f51375cdSDavid Howells 	trace_afs_file_error(vnode, -EIO, where);
1390f51375cdSDavid Howells 	return -EIO;
1391f51375cdSDavid Howells }
1392d2ddc776SDavid Howells 
139308e0e7c8SDavid Howells /*****************************************************************************/
139408e0e7c8SDavid Howells /*
139508e0e7c8SDavid Howells  * debug tracing
139608e0e7c8SDavid Howells  */
139708e0e7c8SDavid Howells extern unsigned afs_debug;
139808e0e7c8SDavid Howells 
139908e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1400ad16df84SSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
140108e0e7c8SDavid Howells 
1402530b6412SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1403530b6412SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
140408e0e7c8SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
140508e0e7c8SDavid Howells 
140608e0e7c8SDavid Howells 
140708e0e7c8SDavid Howells #if defined(__KDEBUG)
140808e0e7c8SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
140908e0e7c8SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
141008e0e7c8SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
141108e0e7c8SDavid Howells 
141208e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
141308e0e7c8SDavid Howells #define AFS_DEBUG_KENTER	0x01
141408e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE	0x02
141508e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG	0x04
141608e0e7c8SDavid Howells 
141708e0e7c8SDavid Howells #define _enter(FMT,...)					\
141808e0e7c8SDavid Howells do {							\
141908e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
142008e0e7c8SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
142108e0e7c8SDavid Howells } while (0)
142208e0e7c8SDavid Howells 
142308e0e7c8SDavid Howells #define _leave(FMT,...)					\
142408e0e7c8SDavid Howells do {							\
142508e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
142608e0e7c8SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
142708e0e7c8SDavid Howells } while (0)
142808e0e7c8SDavid Howells 
142908e0e7c8SDavid Howells #define _debug(FMT,...)					\
143008e0e7c8SDavid Howells do {							\
143108e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
143208e0e7c8SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
143308e0e7c8SDavid Howells } while (0)
143408e0e7c8SDavid Howells 
143508e0e7c8SDavid Howells #else
143612fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
143712fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
143812fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
143908e0e7c8SDavid Howells #endif
144008e0e7c8SDavid Howells 
144108e0e7c8SDavid Howells /*
144208e0e7c8SDavid Howells  * debug assertion checking
144308e0e7c8SDavid Howells  */
144408e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
144508e0e7c8SDavid Howells 
144608e0e7c8SDavid Howells #define ASSERT(X)						\
144708e0e7c8SDavid Howells do {								\
144808e0e7c8SDavid Howells 	if (unlikely(!(X))) {					\
144908e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
145008e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
145108e0e7c8SDavid Howells 		BUG();						\
145208e0e7c8SDavid Howells 	}							\
145308e0e7c8SDavid Howells } while(0)
145408e0e7c8SDavid Howells 
145508e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)						\
145608e0e7c8SDavid Howells do {									\
145708e0e7c8SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
145808e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
145908e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
146008e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
146108e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
146208e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
146308e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
146408e0e7c8SDavid Howells 		BUG();							\
146508e0e7c8SDavid Howells 	}								\
146608e0e7c8SDavid Howells } while(0)
146708e0e7c8SDavid Howells 
1468416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)					\
1469416351f2SDavid Howells do {									\
1470416351f2SDavid Howells 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
1471416351f2SDavid Howells 		printk(KERN_ERR "\n");					\
1472416351f2SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1473416351f2SDavid Howells 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
1474416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1475416351f2SDavid Howells 		       (unsigned long)(H));				\
1476416351f2SDavid Howells 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1477416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1478416351f2SDavid Howells 		       (unsigned long)(H));				\
1479416351f2SDavid Howells 		BUG();							\
1480416351f2SDavid Howells 	}								\
1481416351f2SDavid Howells } while(0)
1482416351f2SDavid Howells 
148308e0e7c8SDavid Howells #define ASSERTIF(C, X)						\
148408e0e7c8SDavid Howells do {								\
148508e0e7c8SDavid Howells 	if (unlikely((C) && !(X))) {				\
148608e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
148708e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
148808e0e7c8SDavid Howells 		BUG();						\
148908e0e7c8SDavid Howells 	}							\
149008e0e7c8SDavid Howells } while(0)
149108e0e7c8SDavid Howells 
149208e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
149308e0e7c8SDavid Howells do {									\
149408e0e7c8SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
149508e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
149608e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
149708e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
149808e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
149908e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
150008e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
150108e0e7c8SDavid Howells 		BUG();							\
150208e0e7c8SDavid Howells 	}								\
150308e0e7c8SDavid Howells } while(0)
150408e0e7c8SDavid Howells 
150508e0e7c8SDavid Howells #else
150608e0e7c8SDavid Howells 
150708e0e7c8SDavid Howells #define ASSERT(X)				\
150808e0e7c8SDavid Howells do {						\
150908e0e7c8SDavid Howells } while(0)
151008e0e7c8SDavid Howells 
151108e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)			\
151208e0e7c8SDavid Howells do {						\
151308e0e7c8SDavid Howells } while(0)
151408e0e7c8SDavid Howells 
1515416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)		\
1516416351f2SDavid Howells do {						\
1517416351f2SDavid Howells } while(0)
1518416351f2SDavid Howells 
151908e0e7c8SDavid Howells #define ASSERTIF(C, X)				\
152008e0e7c8SDavid Howells do {						\
152108e0e7c8SDavid Howells } while(0)
152208e0e7c8SDavid Howells 
152308e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
152408e0e7c8SDavid Howells do {						\
152508e0e7c8SDavid Howells } while(0)
152608e0e7c8SDavid Howells 
152708e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1528