xref: /linux/fs/afs/internal.h (revision c925bd0ac4741badb567f594c41c8cba5e9e9732)
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 
396c6c1d63SDavid Howells /*
406c6c1d63SDavid Howells  * Partial file-locking emulation mode.  (The problem being that AFS3 only
416c6c1d63SDavid Howells  * allows whole-file locks and no upgrading/downgrading).
426c6c1d63SDavid Howells  */
436c6c1d63SDavid Howells enum afs_flock_mode {
446c6c1d63SDavid Howells 	afs_flock_mode_unset,
456c6c1d63SDavid Howells 	afs_flock_mode_local,	/* Local locking only */
466c6c1d63SDavid Howells 	afs_flock_mode_openafs,	/* Don't get server lock for a partial lock */
476c6c1d63SDavid Howells 	afs_flock_mode_strict,	/* Always get a server lock for a partial lock */
486c6c1d63SDavid Howells 	afs_flock_mode_write,	/* Get an exclusive server lock for a partial lock */
496c6c1d63SDavid Howells };
506c6c1d63SDavid Howells 
5113fcc683SDavid Howells struct afs_fs_context {
5200d3b7a4SDavid Howells 	bool			force;		/* T to force cell type */
53bec5eb61Swanglei 	bool			autocell;	/* T if set auto mount operation */
544d673da1SDavid Howells 	bool			dyn_root;	/* T if dynamic root */
5513fcc683SDavid Howells 	bool			no_cell;	/* T if the source is "none" (for dynroot) */
566c6c1d63SDavid Howells 	enum afs_flock_mode	flock_mode;	/* Partial file-locking emulation mode */
5700d3b7a4SDavid Howells 	afs_voltype_t		type;		/* type of volume requested */
5813fcc683SDavid Howells 	unsigned int		volnamesz;	/* size of volume name */
5900d3b7a4SDavid Howells 	const char		*volname;	/* name of volume to mount */
605b86d4ffSDavid Howells 	struct afs_net		*net;		/* the AFS net namespace stuff */
6100d3b7a4SDavid Howells 	struct afs_cell		*cell;		/* cell in which to find volume */
6200d3b7a4SDavid Howells 	struct afs_volume	*volume;	/* volume record */
6300d3b7a4SDavid Howells 	struct key		*key;		/* key to use for secure mounting */
6400d3b7a4SDavid Howells };
6500d3b7a4SDavid Howells 
66c435ee34SDavid Howells struct afs_iget_data {
67c435ee34SDavid Howells 	struct afs_fid		fid;
68c435ee34SDavid Howells 	struct afs_volume	*volume;	/* volume on which resides */
69c435ee34SDavid Howells };
70c435ee34SDavid Howells 
718e8d7f13SDavid Howells enum afs_call_state {
7298bf40cdSDavid Howells 	AFS_CALL_CL_REQUESTING,		/* Client: Request is being sent */
7398bf40cdSDavid Howells 	AFS_CALL_CL_AWAIT_REPLY,	/* Client: Awaiting reply */
7498bf40cdSDavid Howells 	AFS_CALL_CL_PROC_REPLY,		/* Client: rxrpc call complete; processing reply */
7598bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_OP_ID,	/* Server: Awaiting op ID */
7698bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_REQUEST,	/* Server: Awaiting request data */
7798bf40cdSDavid Howells 	AFS_CALL_SV_REPLYING,		/* Server: Replying */
7898bf40cdSDavid Howells 	AFS_CALL_SV_AWAIT_ACK,		/* Server: Awaiting final ACK */
798e8d7f13SDavid Howells 	AFS_CALL_COMPLETE,		/* Completed or failed */
808e8d7f13SDavid Howells };
81f044c884SDavid Howells 
8208e0e7c8SDavid Howells /*
838b2a464cSDavid Howells  * List of server addresses.
848b2a464cSDavid Howells  */
858b2a464cSDavid Howells struct afs_addr_list {
868b2a464cSDavid Howells 	struct rcu_head		rcu;		/* Must be first */
878b2a464cSDavid Howells 	refcount_t		usage;
88d2ddc776SDavid Howells 	u32			version;	/* Version */
8968eb64c3SDavid Howells 	unsigned char		max_addrs;
9068eb64c3SDavid Howells 	unsigned char		nr_addrs;
913bf0fb6fSDavid Howells 	unsigned char		preferred;	/* Preferred address */
9268eb64c3SDavid Howells 	unsigned char		nr_ipv4;	/* Number of IPv4 addresses */
930a5143f2SDavid Howells 	enum dns_record_source	source:8;
940a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
95bf99a53cSDavid Howells 	unsigned long		probed;		/* Mask of servers that have been probed */
963bf0fb6fSDavid Howells 	unsigned long		failed;		/* Mask of addrs that failed locally/ICMP */
973bf0fb6fSDavid Howells 	unsigned long		responded;	/* Mask of addrs that responded */
988b2a464cSDavid Howells 	struct sockaddr_rxrpc	addrs[];
9968eb64c3SDavid Howells #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
1008b2a464cSDavid Howells };
1018b2a464cSDavid Howells 
1028b2a464cSDavid Howells /*
10308e0e7c8SDavid Howells  * a record of an in-progress RxRPC call
10408e0e7c8SDavid Howells  */
10508e0e7c8SDavid Howells struct afs_call {
10608e0e7c8SDavid Howells 	const struct afs_call_type *type;	/* type of call */
1073bf0fb6fSDavid Howells 	struct afs_addr_list	*alist;		/* Address is alist[addr_ix] */
10808e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* processes awaiting completion */
109341f741fSDavid Howells 	struct work_struct	async_work;	/* async I/O processor */
11008e0e7c8SDavid Howells 	struct work_struct	work;		/* actual work processor */
11108e0e7c8SDavid Howells 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
11208e0e7c8SDavid Howells 	struct key		*key;		/* security for this call */
113f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
114ffba718eSDavid Howells 	union {
115ffba718eSDavid Howells 		struct afs_server	*server;
116ffba718eSDavid Howells 		struct afs_vlserver	*vlserver;
117ffba718eSDavid Howells 	};
118d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Callback interest for server used */
119a58823acSDavid Howells 	struct afs_vnode	*lvnode;	/* vnode being locked */
12008e0e7c8SDavid Howells 	void			*request;	/* request data (first part) */
1214343d008SDavid Howells 	struct address_space	*mapping;	/* Pages being written from */
12212bdcf33SDavid Howells 	struct iov_iter		iter;		/* Buffer iterator */
12312bdcf33SDavid Howells 	struct iov_iter		*_iter;		/* Iterator currently in use */
12412bdcf33SDavid Howells 	union {	/* Convenience for ->iter */
12512bdcf33SDavid Howells 		struct kvec	kvec[1];
12612bdcf33SDavid Howells 		struct bio_vec	bvec[1];
12712bdcf33SDavid Howells 	};
12808e0e7c8SDavid Howells 	void			*buffer;	/* reply receive buffer */
129ffba718eSDavid Howells 	union {
130ffba718eSDavid Howells 		long			ret0;	/* Value to reply with instead of 0 */
131ffba718eSDavid Howells 		struct afs_addr_list	*ret_alist;
132ffba718eSDavid Howells 		struct afs_vldb_entry	*ret_vldb;
133ffba718eSDavid Howells 		struct afs_acl		*ret_acl;
134ffba718eSDavid Howells 	};
135ffba718eSDavid Howells 	struct afs_fid		*out_fid;
136a58823acSDavid Howells 	struct afs_status_cb	*out_dir_scb;
13787182759SDavid Howells 	struct afs_status_cb	*out_scb;
138ffba718eSDavid Howells 	struct yfs_acl		*out_yacl;
139ffba718eSDavid Howells 	struct afs_volsync	*out_volsync;
140ffba718eSDavid Howells 	struct afs_volume_status *out_volstatus;
141ffba718eSDavid Howells 	struct afs_read		*read_request;
142ffba718eSDavid Howells 	unsigned int		server_index;
14331143d5dSDavid Howells 	pgoff_t			first;		/* first page in mapping to deal with */
14431143d5dSDavid Howells 	pgoff_t			last;		/* last page in mapping to deal with */
145341f741fSDavid Howells 	atomic_t		usage;
1468e8d7f13SDavid Howells 	enum afs_call_state	state;
14798bf40cdSDavid Howells 	spinlock_t		state_lock;
14808e0e7c8SDavid Howells 	int			error;		/* error code */
149d001648eSDavid Howells 	u32			abort_code;	/* Remote abort ID or 0 */
1503bf0fb6fSDavid Howells 	u32			epoch;
15194f699c9SDavid Howells 	unsigned int		max_lifespan;	/* Maximum lifespan to set if not 0 */
15208e0e7c8SDavid Howells 	unsigned		request_size;	/* size of request data */
15308e0e7c8SDavid Howells 	unsigned		reply_max;	/* maximum size of reply */
15431143d5dSDavid Howells 	unsigned		first_offset;	/* offset into mapping[first] */
155bcd89270SMarc Dionne 	union {
15631143d5dSDavid Howells 		unsigned	last_to;	/* amount of mapping[last] */
157bcd89270SMarc Dionne 		unsigned	count2;		/* count used in unmarshalling */
158bcd89270SMarc Dionne 	};
15908e0e7c8SDavid Howells 	unsigned char		unmarshall;	/* unmarshalling phase */
1603bf0fb6fSDavid Howells 	unsigned char		addr_ix;	/* Address in ->alist */
16108e0e7c8SDavid Howells 	bool			incoming;	/* T if incoming call */
16231143d5dSDavid Howells 	bool			send_pages;	/* T if data from mapping should be sent */
163d001648eSDavid Howells 	bool			need_attention;	/* T if RxRPC poked us */
16456ff9c83SDavid Howells 	bool			async;		/* T if asynchronous */
165a68f4a27SDavid Howells 	bool			upgrade;	/* T to request service upgrade */
1664571577fSDavid Howells 	bool			have_reply_time; /* T if have got reply_time */
16720b8391fSDavid Howells 	bool			intr;		/* T if interruptible */
168bf99a53cSDavid Howells 	u16			service_id;	/* Actual service ID (after upgrade) */
169a25e21f0SDavid Howells 	unsigned int		debug_id;	/* Trace ID */
17050a2c953SDavid Howells 	u32			operation_ID;	/* operation ID for an incoming call */
17108e0e7c8SDavid Howells 	u32			count;		/* count for use in unmarshalling */
17212bdcf33SDavid Howells 	union {					/* place to extract temporary data */
17312bdcf33SDavid Howells 		struct {
17412bdcf33SDavid Howells 			__be32	tmp_u;
17512bdcf33SDavid Howells 			__be32	tmp;
17612bdcf33SDavid Howells 		} __attribute__((packed));
17712bdcf33SDavid Howells 		__be64		tmp64;
17812bdcf33SDavid Howells 	};
17912d8e95aSDavid Howells 	ktime_t			reply_time;	/* Time of first reply packet */
18008e0e7c8SDavid Howells };
18108e0e7c8SDavid Howells 
18208e0e7c8SDavid Howells struct afs_call_type {
18300d3b7a4SDavid Howells 	const char *name;
184025db80cSDavid Howells 	unsigned int op; /* Really enum afs_fs_operation */
18500d3b7a4SDavid Howells 
18608e0e7c8SDavid Howells 	/* deliver request or reply data to an call
18708e0e7c8SDavid Howells 	 * - returning an error will cause the call to be aborted
18808e0e7c8SDavid Howells 	 */
189d001648eSDavid Howells 	int (*deliver)(struct afs_call *call);
19008e0e7c8SDavid Howells 
19108e0e7c8SDavid Howells 	/* clean up a call */
19208e0e7c8SDavid Howells 	void (*destructor)(struct afs_call *call);
193341f741fSDavid Howells 
194341f741fSDavid Howells 	/* Work function */
195341f741fSDavid Howells 	void (*work)(struct work_struct *work);
1963bf0fb6fSDavid Howells 
1973bf0fb6fSDavid Howells 	/* Call done function (gets called immediately on success or failure) */
1983bf0fb6fSDavid Howells 	void (*done)(struct afs_call *call);
19908e0e7c8SDavid Howells };
20008e0e7c8SDavid Howells 
20108e0e7c8SDavid Howells /*
2024343d008SDavid Howells  * Key available for writeback on a file.
2034343d008SDavid Howells  */
2044343d008SDavid Howells struct afs_wb_key {
2054343d008SDavid Howells 	refcount_t		usage;
2064343d008SDavid Howells 	struct key		*key;
2074343d008SDavid Howells 	struct list_head	vnode_link;	/* Link in vnode->wb_keys */
2084343d008SDavid Howells };
2094343d008SDavid Howells 
2104343d008SDavid Howells /*
211215804a9SDavid Howells  * AFS open file information record.  Pointed to by file->private_data.
212215804a9SDavid Howells  */
213215804a9SDavid Howells struct afs_file {
214215804a9SDavid Howells 	struct key		*key;		/* The key this file was opened with */
2154343d008SDavid Howells 	struct afs_wb_key	*wb;		/* Writeback key record for this file */
216215804a9SDavid Howells };
217215804a9SDavid Howells 
218215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
219215804a9SDavid Howells {
220215804a9SDavid Howells 	struct afs_file *af = file->private_data;
221215804a9SDavid Howells 
222215804a9SDavid Howells 	return af->key;
223215804a9SDavid Howells }
224215804a9SDavid Howells 
225215804a9SDavid Howells /*
226196ee9cdSDavid Howells  * Record of an outstanding read operation on a vnode.
227196ee9cdSDavid Howells  */
228196ee9cdSDavid Howells struct afs_read {
229196ee9cdSDavid Howells 	loff_t			pos;		/* Where to start reading */
230e8e581a8SDavid Howells 	loff_t			len;		/* How much we're asking for */
231196ee9cdSDavid Howells 	loff_t			actual_len;	/* How much we're actually getting */
2326a0e3999SDavid Howells 	loff_t			remain;		/* Amount remaining */
233f3ddee8dSDavid Howells 	loff_t			file_size;	/* File size returned by server */
234f3ddee8dSDavid Howells 	afs_dataversion_t	data_version;	/* Version number returned by server */
235f3ddee8dSDavid Howells 	refcount_t		usage;
236196ee9cdSDavid Howells 	unsigned int		index;		/* Which page we're reading into */
237196ee9cdSDavid Howells 	unsigned int		nr_pages;
23812bdcf33SDavid Howells 	unsigned int		offset;		/* offset into current page */
239a58823acSDavid Howells 	struct afs_vnode	*vnode;
240a58823acSDavid Howells 	void (*page_done)(struct afs_read *);
241f3ddee8dSDavid Howells 	struct page		**pages;
242f3ddee8dSDavid Howells 	struct page		*array[];
243196ee9cdSDavid Howells };
244196ee9cdSDavid Howells 
245196ee9cdSDavid Howells /*
24608e0e7c8SDavid Howells  * AFS superblock private data
24708e0e7c8SDavid Howells  * - there's one superblock per volume
24808e0e7c8SDavid Howells  */
24908e0e7c8SDavid Howells struct afs_super_info {
2505b86d4ffSDavid Howells 	struct net		*net_ns;	/* Network namespace */
25149566f6fSDavid Howells 	struct afs_cell		*cell;		/* The cell in which the volume resides */
25208e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume record */
2536c6c1d63SDavid Howells 	enum afs_flock_mode	flock_mode:8;	/* File locking emulation mode */
2544d673da1SDavid Howells 	bool			dyn_root;	/* True if dynamic root */
25508e0e7c8SDavid Howells };
25608e0e7c8SDavid Howells 
25708e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
25808e0e7c8SDavid Howells {
25908e0e7c8SDavid Howells 	return sb->s_fs_info;
26008e0e7c8SDavid Howells }
26108e0e7c8SDavid Howells 
26208e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
26308e0e7c8SDavid Howells 
26408e0e7c8SDavid Howells /*
2656f8880d8SDavid Howells  * Set of substitutes for @sys.
2666f8880d8SDavid Howells  */
2676f8880d8SDavid Howells struct afs_sysnames {
2686f8880d8SDavid Howells #define AFS_NR_SYSNAME 16
2696f8880d8SDavid Howells 	char			*subs[AFS_NR_SYSNAME];
2706f8880d8SDavid Howells 	refcount_t		usage;
2716f8880d8SDavid Howells 	unsigned short		nr;
2726f8880d8SDavid Howells 	char			blank[1];
2736f8880d8SDavid Howells };
2746f8880d8SDavid Howells 
2756f8880d8SDavid Howells /*
276f044c884SDavid Howells  * AFS network namespace record.
277f044c884SDavid Howells  */
278f044c884SDavid Howells struct afs_net {
2795b86d4ffSDavid Howells 	struct net		*net;		/* Backpointer to the owning net namespace */
280f044c884SDavid Howells 	struct afs_uuid		uuid;
281f044c884SDavid Howells 	bool			live;		/* F if this namespace is being removed */
282f044c884SDavid Howells 
283f044c884SDavid Howells 	/* AF_RXRPC I/O stuff */
284f044c884SDavid Howells 	struct socket		*socket;
285f044c884SDavid Howells 	struct afs_call		*spare_incoming_call;
286f044c884SDavid Howells 	struct work_struct	charge_preallocation_work;
287f044c884SDavid Howells 	struct mutex		socket_mutex;
288f044c884SDavid Howells 	atomic_t		nr_outstanding_calls;
289f044c884SDavid Howells 	atomic_t		nr_superblocks;
290f044c884SDavid Howells 
291f044c884SDavid Howells 	/* Cell database */
292989782dcSDavid Howells 	struct rb_root		cells;
2931588def9SDavid Howells 	struct afs_cell __rcu	*ws_cell;
294989782dcSDavid Howells 	struct work_struct	cells_manager;
295989782dcSDavid Howells 	struct timer_list	cells_timer;
296989782dcSDavid Howells 	atomic_t		cells_outstanding;
297989782dcSDavid Howells 	seqlock_t		cells_lock;
298f044c884SDavid Howells 
2990da0b7fdSDavid Howells 	struct mutex		proc_cells_lock;
3006b3944e4SDavid Howells 	struct hlist_head	proc_cells;
301f044c884SDavid Howells 
302d2ddc776SDavid Howells 	/* Known servers.  Theoretically each fileserver can only be in one
303d2ddc776SDavid Howells 	 * cell, but in practice, people create aliases and subsets and there's
304d2ddc776SDavid Howells 	 * no easy way to distinguish them.
305d2ddc776SDavid Howells 	 */
306d2ddc776SDavid Howells 	seqlock_t		fs_lock;	/* For fs_servers */
307d2ddc776SDavid Howells 	struct rb_root		fs_servers;	/* afs_server (by server UUID or address) */
308d2ddc776SDavid Howells 	struct list_head	fs_updates;	/* afs_server (by update_at) */
309d2ddc776SDavid Howells 	struct hlist_head	fs_proc;	/* procfs servers list */
310d2ddc776SDavid Howells 
311d2ddc776SDavid Howells 	struct hlist_head	fs_addresses4;	/* afs_server (by lowest IPv4 addr) */
312d2ddc776SDavid Howells 	struct hlist_head	fs_addresses6;	/* afs_server (by lowest IPv6 addr) */
313d2ddc776SDavid Howells 	seqlock_t		fs_addr_lock;	/* For fs_addresses[46] */
314d2ddc776SDavid Howells 
315d2ddc776SDavid Howells 	struct work_struct	fs_manager;
316d2ddc776SDavid Howells 	struct timer_list	fs_timer;
317d2ddc776SDavid Howells 	atomic_t		servers_outstanding;
318f044c884SDavid Howells 
319f044c884SDavid Howells 	/* File locking renewal management */
320f044c884SDavid Howells 	struct mutex		lock_manager_mutex;
321f044c884SDavid Howells 
322f044c884SDavid Howells 	/* Misc */
3230da0b7fdSDavid Howells 	struct super_block	*dynroot_sb;	/* Dynamic root mount superblock */
324f044c884SDavid Howells 	struct proc_dir_entry	*proc_afs;	/* /proc/net/afs directory */
3256f8880d8SDavid Howells 	struct afs_sysnames	*sysnames;
3266f8880d8SDavid Howells 	rwlock_t		sysnames_lock;
327d55b4da4SDavid Howells 
328d55b4da4SDavid Howells 	/* Statistics counters */
329d55b4da4SDavid Howells 	atomic_t		n_lookup;	/* Number of lookups done */
330d55b4da4SDavid Howells 	atomic_t		n_reval;	/* Number of dentries needing revalidation */
331d55b4da4SDavid Howells 	atomic_t		n_inval;	/* Number of invalidations by the server */
332f3ddee8dSDavid Howells 	atomic_t		n_relpg;	/* Number of invalidations by releasepage */
333d55b4da4SDavid Howells 	atomic_t		n_read_dir;	/* Number of directory pages read */
33463a4681fSDavid Howells 	atomic_t		n_dir_cr;	/* Number of directory entry creation edits */
33563a4681fSDavid Howells 	atomic_t		n_dir_rm;	/* Number of directory entry removal edits */
33676a5cb6fSDavid Howells 	atomic_t		n_stores;	/* Number of store ops */
33776a5cb6fSDavid Howells 	atomic_long_t		n_store_bytes;	/* Number of bytes stored */
33876a5cb6fSDavid Howells 	atomic_long_t		n_fetch_bytes;	/* Number of bytes fetched */
33976a5cb6fSDavid Howells 	atomic_t		n_fetches;	/* Number of data fetch ops */
340f044c884SDavid Howells };
341f044c884SDavid Howells 
3426f8880d8SDavid Howells extern const char afs_init_sysname[];
343f044c884SDavid Howells 
344989782dcSDavid Howells enum afs_cell_state {
345989782dcSDavid Howells 	AFS_CELL_UNSET,
346989782dcSDavid Howells 	AFS_CELL_ACTIVATING,
347989782dcSDavid Howells 	AFS_CELL_ACTIVE,
348989782dcSDavid Howells 	AFS_CELL_DEACTIVATING,
349989782dcSDavid Howells 	AFS_CELL_INACTIVE,
350989782dcSDavid Howells 	AFS_CELL_FAILED,
351989782dcSDavid Howells };
352989782dcSDavid Howells 
353f044c884SDavid Howells /*
354d2ddc776SDavid Howells  * AFS cell record.
355d2ddc776SDavid Howells  *
356d2ddc776SDavid Howells  * This is a tricky concept to get right as it is possible to create aliases
357d2ddc776SDavid Howells  * simply by pointing AFSDB/SRV records for two names at the same set of VL
358d2ddc776SDavid Howells  * servers; it is also possible to do things like setting up two sets of VL
359d2ddc776SDavid Howells  * servers, one of which provides a superset of the volumes provided by the
360d2ddc776SDavid Howells  * other (for internal/external division, for example).
361d2ddc776SDavid Howells  *
362d2ddc776SDavid Howells  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
363d2ddc776SDavid Howells  * servers and (b) a cell's name is used by the client to select the key to use
364d2ddc776SDavid Howells  * for authentication and encryption.  The cell name is not typically used in
365d2ddc776SDavid Howells  * the protocol.
366d2ddc776SDavid Howells  *
367d2ddc776SDavid Howells  * There is no easy way to determine if two cells are aliases or one is a
368d2ddc776SDavid Howells  * subset of another.
36908e0e7c8SDavid Howells  */
37008e0e7c8SDavid Howells struct afs_cell {
371989782dcSDavid Howells 	union {
372989782dcSDavid Howells 		struct rcu_head	rcu;
373989782dcSDavid Howells 		struct rb_node	net_node;	/* Node in net->cells */
374989782dcSDavid Howells 	};
375989782dcSDavid Howells 	struct afs_net		*net;
37600d3b7a4SDavid Howells 	struct key		*anonymous_key;	/* anonymous user key for this cell */
377989782dcSDavid Howells 	struct work_struct	manager;	/* Manager for init/deinit/dns */
3786b3944e4SDavid Howells 	struct hlist_node	proc_link;	/* /proc cell list link */
3799b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
3809b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
3811da177e4SLinus Torvalds #endif
382989782dcSDavid Howells 	time64_t		dns_expiry;	/* Time AFSDB/SRV record expires */
383989782dcSDavid Howells 	time64_t		last_inactive;	/* Time of last drop of usage count */
384989782dcSDavid Howells 	atomic_t		usage;
385989782dcSDavid Howells 	unsigned long		flags;
386d5c32c89SDavid Howells #define AFS_CELL_FL_NO_GC	0		/* The cell was added manually, don't auto-gc */
387d5c32c89SDavid Howells #define AFS_CELL_FL_DO_LOOKUP	1		/* DNS lookup requested */
388989782dcSDavid Howells 	enum afs_cell_state	state;
389989782dcSDavid Howells 	short			error;
390d5c32c89SDavid Howells 	enum dns_record_source	dns_source:8;	/* Latest source of data from lookup */
391d5c32c89SDavid Howells 	enum dns_lookup_status	dns_status:8;	/* Latest status of data from lookup */
392d5c32c89SDavid Howells 	unsigned int		dns_lookup_count; /* Counter of DNS lookups */
393989782dcSDavid Howells 
394d2ddc776SDavid Howells 	/* Active fileserver interaction state. */
395d2ddc776SDavid Howells 	struct list_head	proc_volumes;	/* procfs volume list */
396d2ddc776SDavid Howells 	rwlock_t		proc_lock;
397989782dcSDavid Howells 
398d2ddc776SDavid Howells 	/* VL server list. */
3990a5143f2SDavid Howells 	rwlock_t		vl_servers_lock; /* Lock on vl_servers */
4000a5143f2SDavid Howells 	struct afs_vlserver_list __rcu *vl_servers;
4010a5143f2SDavid Howells 
402989782dcSDavid Howells 	u8			name_len;	/* Length of name */
403989782dcSDavid Howells 	char			name[64 + 1];	/* Cell name, case-flattened and NUL-padded */
40408e0e7c8SDavid Howells };
40508e0e7c8SDavid Howells 
40608e0e7c8SDavid Howells /*
4070a5143f2SDavid Howells  * Volume Location server record.
4080a5143f2SDavid Howells  */
4090a5143f2SDavid Howells struct afs_vlserver {
4100a5143f2SDavid Howells 	struct rcu_head		rcu;
4110a5143f2SDavid Howells 	struct afs_addr_list	__rcu *addresses; /* List of addresses for this VL server */
4120a5143f2SDavid Howells 	unsigned long		flags;
4130a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED	0		/* The VL server has been probed */
4140a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING	1		/* VL server is being probed */
4153bf0fb6fSDavid Howells #define AFS_VLSERVER_FL_IS_YFS	2		/* Server is YFS not AFS */
4160a5143f2SDavid Howells 	rwlock_t		lock;		/* Lock on addresses */
4170a5143f2SDavid Howells 	atomic_t		usage;
4183bf0fb6fSDavid Howells 
4193bf0fb6fSDavid Howells 	/* Probe state */
4203bf0fb6fSDavid Howells 	wait_queue_head_t	probe_wq;
4213bf0fb6fSDavid Howells 	atomic_t		probe_outstanding;
4223bf0fb6fSDavid Howells 	spinlock_t		probe_lock;
4233bf0fb6fSDavid Howells 	struct {
4243bf0fb6fSDavid Howells 		unsigned int	rtt;		/* RTT as ktime/64 */
4253bf0fb6fSDavid Howells 		u32		abort_code;
4263bf0fb6fSDavid Howells 		short		error;
4273bf0fb6fSDavid Howells 		bool		have_result;
4283bf0fb6fSDavid Howells 		bool		responded:1;
4293bf0fb6fSDavid Howells 		bool		is_yfs:1;
4303bf0fb6fSDavid Howells 		bool		not_yfs:1;
4313bf0fb6fSDavid Howells 		bool		local_failure:1;
4323bf0fb6fSDavid Howells 	} probe;
4333bf0fb6fSDavid Howells 
4340a5143f2SDavid Howells 	u16			port;
4353bf0fb6fSDavid Howells 	u16			name_len;	/* Length of name */
4360a5143f2SDavid Howells 	char			name[];		/* Server name, case-flattened */
4370a5143f2SDavid Howells };
4380a5143f2SDavid Howells 
4390a5143f2SDavid Howells /*
4400a5143f2SDavid Howells  * Weighted list of Volume Location servers.
4410a5143f2SDavid Howells  */
4420a5143f2SDavid Howells struct afs_vlserver_entry {
4430a5143f2SDavid Howells 	u16			priority;	/* Preference (as SRV) */
4440a5143f2SDavid Howells 	u16			weight;		/* Weight (as SRV) */
4450a5143f2SDavid Howells 	enum dns_record_source	source:8;
4460a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4470a5143f2SDavid Howells 	struct afs_vlserver	*server;
4480a5143f2SDavid Howells };
4490a5143f2SDavid Howells 
4500a5143f2SDavid Howells struct afs_vlserver_list {
4510a5143f2SDavid Howells 	struct rcu_head		rcu;
4520a5143f2SDavid Howells 	atomic_t		usage;
4530a5143f2SDavid Howells 	u8			nr_servers;
4540a5143f2SDavid Howells 	u8			index;		/* Server currently in use */
4553bf0fb6fSDavid Howells 	u8			preferred;	/* Preferred server */
4560a5143f2SDavid Howells 	enum dns_record_source	source:8;
4570a5143f2SDavid Howells 	enum dns_lookup_status	status:8;
4580a5143f2SDavid Howells 	rwlock_t		lock;
4590a5143f2SDavid Howells 	struct afs_vlserver_entry servers[];
4600a5143f2SDavid Howells };
4610a5143f2SDavid Howells 
4620a5143f2SDavid Howells /*
463d2ddc776SDavid Howells  * Cached VLDB entry.
464d2ddc776SDavid Howells  *
465d2ddc776SDavid Howells  * This is pointed to by cell->vldb_entries, indexed by name.
46608e0e7c8SDavid Howells  */
467d2ddc776SDavid Howells struct afs_vldb_entry {
468d2ddc776SDavid Howells 	afs_volid_t		vid[3];		/* Volume IDs for R/W, R/O and Bak volumes */
46900d3b7a4SDavid Howells 
470d2ddc776SDavid Howells 	unsigned long		flags;
471d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW		0		/* - R/W volume exists */
472d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO		1		/* - R/O volume exists */
473d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK	2		/* - Backup volume exists */
474d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID	3		/* - Record is valid */
475d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR	4		/* - VL server returned error */
476d2ddc776SDavid Howells 
477d2ddc776SDavid Howells 	uuid_t			fs_server[AFS_NMAXNSERVERS];
478d2ddc776SDavid Howells 	u8			fs_mask[AFS_NMAXNSERVERS];
47908e0e7c8SDavid Howells #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
48008e0e7c8SDavid Howells #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
48108e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
482d2ddc776SDavid Howells 	short			error;
483d2ddc776SDavid Howells 	u8			nr_servers;	/* Number of server records */
484d2ddc776SDavid Howells 	u8			name_len;
485d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
48608e0e7c8SDavid Howells };
48708e0e7c8SDavid Howells 
48808e0e7c8SDavid Howells /*
489d2ddc776SDavid Howells  * Record of fileserver with which we're actively communicating.
49008e0e7c8SDavid Howells  */
49108e0e7c8SDavid Howells struct afs_server {
492d2ddc776SDavid Howells 	struct rcu_head		rcu;
493d2ddc776SDavid Howells 	union {
494d2ddc776SDavid Howells 		uuid_t		uuid;		/* Server ID */
495d2ddc776SDavid Howells 		struct afs_uuid	_uuid;
496d2ddc776SDavid Howells 	};
497c435ee34SDavid Howells 
498d2ddc776SDavid Howells 	struct afs_addr_list	__rcu *addresses;
499d2ddc776SDavid Howells 	struct rb_node		uuid_rb;	/* Link in net->servers */
500d2ddc776SDavid Howells 	struct hlist_node	addr4_link;	/* Link in net->fs_addresses4 */
501d2ddc776SDavid Howells 	struct hlist_node	addr6_link;	/* Link in net->fs_addresses6 */
502d2ddc776SDavid Howells 	struct hlist_node	proc_link;	/* Link in net->fs_proc */
503d2ddc776SDavid Howells 	struct afs_server	*gc_next;	/* Next server in manager's list */
504d2ddc776SDavid Howells 	time64_t		put_time;	/* Time at which last put */
505d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update the record */
506c435ee34SDavid Howells 	unsigned long		flags;
507d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_READY	1		/* The record is not ready for use */
508d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_FOUND	2		/* VL server says no such server */
509d2ddc776SDavid Howells #define AFS_SERVER_FL_VL_FAIL	3		/* Failed to access VL server */
510d2ddc776SDavid Howells #define AFS_SERVER_FL_UPDATING	4
511d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBED	5		/* The fileserver has been probed */
512d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBING	6		/* Fileserver is being probed */
5135cf9dd55SDavid Howells #define AFS_SERVER_FL_NO_IBULK	7		/* Fileserver doesn't support FS.InlineBulkStatus */
514f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8		/* May have callbacks on this fileserver */
51530062bd1SDavid Howells #define AFS_SERVER_FL_IS_YFS	9		/* Server is YFS not AFS */
51630062bd1SDavid Howells #define AFS_SERVER_FL_NO_RM2	10		/* Fileserver doesn't support YFS.RemoveFile2 */
5173bf0fb6fSDavid Howells #define AFS_SERVER_FL_HAVE_EPOCH 11		/* ->epoch is valid */
518d2ddc776SDavid Howells 	atomic_t		usage;
519d2ddc776SDavid Howells 	u32			addr_version;	/* Address list version */
5203bf0fb6fSDavid Howells 	u32			cm_epoch;	/* Server RxRPC epoch */
52108e0e7c8SDavid Howells 
52208e0e7c8SDavid Howells 	/* file service access */
523d2ddc776SDavid Howells 	rwlock_t		fs_lock;	/* access lock */
52408e0e7c8SDavid Howells 
52508e0e7c8SDavid Howells 	/* callback promise management */
52647ea0f2eSDavid Howells 	struct hlist_head	cb_volumes;	/* List of volume interests on this server */
527c435ee34SDavid Howells 	unsigned		cb_s_break;	/* Break-everything counter. */
528c435ee34SDavid Howells 	rwlock_t		cb_break_lock;	/* Volume finding lock */
5293bf0fb6fSDavid Howells 
5303bf0fb6fSDavid Howells 	/* Probe state */
5313bf0fb6fSDavid Howells 	wait_queue_head_t	probe_wq;
5323bf0fb6fSDavid Howells 	atomic_t		probe_outstanding;
5333bf0fb6fSDavid Howells 	spinlock_t		probe_lock;
5343bf0fb6fSDavid Howells 	struct {
5353bf0fb6fSDavid Howells 		unsigned int	rtt;		/* RTT as ktime/64 */
5363bf0fb6fSDavid Howells 		u32		abort_code;
5373bf0fb6fSDavid Howells 		u32		cm_epoch;
5383bf0fb6fSDavid Howells 		short		error;
5393bf0fb6fSDavid Howells 		bool		have_result;
5403bf0fb6fSDavid Howells 		bool		responded:1;
5413bf0fb6fSDavid Howells 		bool		is_yfs:1;
5423bf0fb6fSDavid Howells 		bool		not_yfs:1;
5433bf0fb6fSDavid Howells 		bool		local_failure:1;
5443bf0fb6fSDavid Howells 		bool		no_epoch:1;
5453bf0fb6fSDavid Howells 		bool		cm_probed:1;
5463bf0fb6fSDavid Howells 		bool		said_rebooted:1;
5473bf0fb6fSDavid Howells 		bool		said_inconsistent:1;
5483bf0fb6fSDavid Howells 	} probe;
549c435ee34SDavid Howells };
550c435ee34SDavid Howells 
551c435ee34SDavid Howells /*
55247ea0f2eSDavid Howells  * Volume collation in the server's callback interest list.
55347ea0f2eSDavid Howells  */
55447ea0f2eSDavid Howells struct afs_vol_interest {
55547ea0f2eSDavid Howells 	struct hlist_node	srv_link;	/* Link in server->cb_volumes */
55647ea0f2eSDavid Howells 	struct hlist_head	cb_interests;	/* List of callback interests on the server */
55747ea0f2eSDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
55847ea0f2eSDavid Howells 	unsigned int		usage;
55947ea0f2eSDavid Howells };
56047ea0f2eSDavid Howells 
56147ea0f2eSDavid Howells /*
562c435ee34SDavid Howells  * Interest by a superblock on a server.
563c435ee34SDavid Howells  */
564c435ee34SDavid Howells struct afs_cb_interest {
56547ea0f2eSDavid Howells 	struct hlist_node	cb_vlink;	/* Link in vol_interest->cb_interests */
56647ea0f2eSDavid Howells 	struct afs_vol_interest	*vol_interest;
567c435ee34SDavid Howells 	struct afs_server	*server;	/* Server on which this interest resides */
568c435ee34SDavid Howells 	struct super_block	*sb;		/* Superblock on which inodes reside */
569c435ee34SDavid Howells 	afs_volid_t		vid;		/* Volume ID to match */
570c435ee34SDavid Howells 	refcount_t		usage;
57108e0e7c8SDavid Howells };
57208e0e7c8SDavid Howells 
57308e0e7c8SDavid Howells /*
574d2ddc776SDavid Howells  * Replaceable server list.
57508e0e7c8SDavid Howells  */
576d2ddc776SDavid Howells struct afs_server_entry {
577d2ddc776SDavid Howells 	struct afs_server	*server;
578d2ddc776SDavid Howells 	struct afs_cb_interest	*cb_interest;
579d2ddc776SDavid Howells };
580d2ddc776SDavid Howells 
581d2ddc776SDavid Howells struct afs_server_list {
582d2ddc776SDavid Howells 	refcount_t		usage;
5833bf0fb6fSDavid Howells 	unsigned char		nr_servers;
5843bf0fb6fSDavid Howells 	unsigned char		preferred;	/* Preferred server */
585d2ddc776SDavid Howells 	unsigned short		vnovol_mask;	/* Servers to be skipped due to VNOVOL */
586d2ddc776SDavid Howells 	unsigned int		seq;		/* Set to ->servers_seq when installed */
587d4a96becSDavid Howells 	rwlock_t		lock;
588d2ddc776SDavid Howells 	struct afs_server_entry	servers[];
58908e0e7c8SDavid Howells };
59008e0e7c8SDavid Howells 
59108e0e7c8SDavid Howells /*
592d2ddc776SDavid Howells  * Live AFS volume management.
59308e0e7c8SDavid Howells  */
594d2ddc776SDavid Howells struct afs_volume {
595d2ddc776SDavid Howells 	afs_volid_t		vid;		/* volume ID */
596d2ddc776SDavid Howells 	atomic_t		usage;
597d2ddc776SDavid Howells 	time64_t		update_at;	/* Time at which to next update */
598d2ddc776SDavid Howells 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
599d2ddc776SDavid Howells 	struct list_head	proc_link;	/* Link in cell->vl_proc */
600d2ddc776SDavid Howells 	unsigned long		flags;
601d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE	0	/* - T if an update needs performing */
602d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING	1	/* - T if an update is in progress */
603d2ddc776SDavid Howells #define AFS_VOLUME_WAIT		2	/* - T if users must wait for update */
604d2ddc776SDavid Howells #define AFS_VOLUME_DELETED	3	/* - T if volume appears deleted */
605d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE	4	/* - T if volume offline notice given */
606d2ddc776SDavid Howells #define AFS_VOLUME_BUSY		5	/* - T if volume busy notice given */
607d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
608d2ddc776SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
609d2ddc776SDavid Howells #endif
610d2ddc776SDavid Howells 	struct afs_server_list	*servers;	/* List of servers on which volume resides */
611d2ddc776SDavid Howells 	rwlock_t		servers_lock;	/* Lock for ->servers */
612d2ddc776SDavid Howells 	unsigned int		servers_seq;	/* Incremented each time ->servers changes */
613d2ddc776SDavid Howells 
61468251f0aSDavid Howells 	unsigned		cb_v_break;	/* Break-everything counter. */
61568251f0aSDavid Howells 	rwlock_t		cb_break_lock;
61668251f0aSDavid Howells 
617d2ddc776SDavid Howells 	afs_voltype_t		type;		/* type of volume */
618d2ddc776SDavid Howells 	short			error;
619d2ddc776SDavid Howells 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
620d2ddc776SDavid Howells 	u8			name_len;
621d2ddc776SDavid Howells 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
62208e0e7c8SDavid Howells };
62308e0e7c8SDavid Howells 
6240fafdc9fSDavid Howells enum afs_lock_state {
6250fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NONE,		/* The vnode has no lock on the server */
6260fafdc9fSDavid Howells 	AFS_VNODE_LOCK_WAITING_FOR_CB,	/* We're waiting for the server to break the callback */
6270fafdc9fSDavid Howells 	AFS_VNODE_LOCK_SETTING,		/* We're asking the server for a lock */
6280fafdc9fSDavid Howells 	AFS_VNODE_LOCK_GRANTED,		/* We have a lock on the server */
6290fafdc9fSDavid Howells 	AFS_VNODE_LOCK_EXTENDING,	/* We're extending a lock on the server */
6300fafdc9fSDavid Howells 	AFS_VNODE_LOCK_NEED_UNLOCK,	/* We need to unlock on the server */
6310fafdc9fSDavid Howells 	AFS_VNODE_LOCK_UNLOCKING,	/* We're telling the server to unlock */
632cdfb26b4SDavid Howells 	AFS_VNODE_LOCK_DELETED,		/* The vnode has been deleted whilst we have a lock */
6330fafdc9fSDavid Howells };
6340fafdc9fSDavid Howells 
63508e0e7c8SDavid Howells /*
636f8de483eSDavid Howells  * AFS inode private data.
637f8de483eSDavid Howells  *
638f8de483eSDavid Howells  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
639f8de483eSDavid Howells  * leak from one inode to another.
64008e0e7c8SDavid Howells  */
64108e0e7c8SDavid Howells struct afs_vnode {
64208e0e7c8SDavid Howells 	struct inode		vfs_inode;	/* the VFS's inode record */
64308e0e7c8SDavid Howells 
64408e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume on which vnode resides */
64508e0e7c8SDavid Howells 	struct afs_fid		fid;		/* the file identifier for this inode */
64608e0e7c8SDavid Howells 	struct afs_file_status	status;		/* AFS status info for this file */
647a4ff7401SDavid Howells 	afs_dataversion_t	invalid_before;	/* Child dentries are invalid before this */
6489b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
6499b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
65008e0e7c8SDavid Howells #endif
651fe342cf7SDavid Howells 	struct afs_permits __rcu *permit_cache;	/* cache of permits so far obtained */
652d2ddc776SDavid Howells 	struct mutex		io_lock;	/* Lock for serialising I/O on this mutex */
653b61f7dcfSDavid Howells 	struct rw_semaphore	validate_lock;	/* lock for validating this vnode */
65479ddbfa5SDavid Howells 	struct rw_semaphore	rmdir_lock;	/* Lock for rmdir vs sillyrename */
65579ddbfa5SDavid Howells 	struct key		*silly_key;	/* Silly rename key */
6564343d008SDavid Howells 	spinlock_t		wb_lock;	/* lock for wb_keys */
65708e0e7c8SDavid Howells 	spinlock_t		lock;		/* waitqueue/flags lock */
65808e0e7c8SDavid Howells 	unsigned long		flags;
659c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED	0		/* Set if vnode has a callback promise */
660260a9803SDavid Howells #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
661f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID	2		/* Set if dir contents are valid */
66208e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
66308e0e7c8SDavid Howells #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
66408e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
6650fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL	6		/* set if Vnode is an auto mount point */
6660fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR	7 		/* set if Vnode is a pseudo directory */
6675a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT	8		/* Set if file has new content (create/trunc-0) */
66808e0e7c8SDavid Howells 
6694343d008SDavid Howells 	struct list_head	wb_keys;	/* List of keys available for writeback */
670e8d6c554SDavid Howells 	struct list_head	pending_locks;	/* locks waiting to be granted */
671e8d6c554SDavid Howells 	struct list_head	granted_locks;	/* locks granted on this file */
672e8d6c554SDavid Howells 	struct delayed_work	lock_work;	/* work to be done in locking */
6730fafdc9fSDavid Howells 	struct key		*lock_key;	/* Key to be used in lock ops */
674a690f60aSDavid Howells 	ktime_t			locked_at;	/* Time at which lock obtained */
6750fafdc9fSDavid Howells 	enum afs_lock_state	lock_state : 8;
6760fafdc9fSDavid Howells 	afs_lock_type_t		lock_type : 8;
67731143d5dSDavid Howells 
67808e0e7c8SDavid Howells 	/* outstanding callback notification on this file */
679c435ee34SDavid Howells 	struct afs_cb_interest	*cb_interest;	/* Server on which this resides */
680c435ee34SDavid Howells 	unsigned int		cb_s_break;	/* Mass break counter on ->server */
68168251f0aSDavid Howells 	unsigned int		cb_v_break;	/* Mass break counter on ->volume */
682c435ee34SDavid Howells 	unsigned int		cb_break;	/* Break counter on vnode */
683c435ee34SDavid Howells 	seqlock_t		cb_lock;	/* Lock for ->cb_interest, ->status, ->cb_*break */
684c435ee34SDavid Howells 
685c435ee34SDavid Howells 	time64_t		cb_expires_at;	/* time at which callback expires */
68608e0e7c8SDavid Howells };
68708e0e7c8SDavid Howells 
68812bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
68912bdcf33SDavid Howells {
69012bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE
69112bdcf33SDavid Howells 	return vnode->cache;
69212bdcf33SDavid Howells #else
69312bdcf33SDavid Howells 	return NULL;
69412bdcf33SDavid Howells #endif
69512bdcf33SDavid Howells }
69612bdcf33SDavid Howells 
69700d3b7a4SDavid Howells /*
69800d3b7a4SDavid Howells  * cached security record for one user's attempt to access a vnode
69900d3b7a4SDavid Howells  */
70000d3b7a4SDavid Howells struct afs_permit {
70100d3b7a4SDavid Howells 	struct key		*key;		/* RxRPC ticket holding a security context */
702be080a6fSDavid Howells 	afs_access_t		access;		/* CallerAccess value for this key */
70300d3b7a4SDavid Howells };
70400d3b7a4SDavid Howells 
70500d3b7a4SDavid Howells /*
706be080a6fSDavid Howells  * Immutable cache of CallerAccess records from attempts to access vnodes.
707be080a6fSDavid Howells  * These may be shared between multiple vnodes.
70800d3b7a4SDavid Howells  */
70900d3b7a4SDavid Howells struct afs_permits {
710be080a6fSDavid Howells 	struct rcu_head		rcu;
711be080a6fSDavid Howells 	struct hlist_node	hash_node;	/* Link in hash */
712be080a6fSDavid Howells 	unsigned long		h;		/* Hash value for this permit list */
713be080a6fSDavid Howells 	refcount_t		usage;
714be080a6fSDavid Howells 	unsigned short		nr_permits;	/* Number of records */
715be080a6fSDavid Howells 	bool			invalidated;	/* Invalidated due to key change */
716be080a6fSDavid Howells 	struct afs_permit	permits[];	/* List of permits sorted by key pointer */
71700d3b7a4SDavid Howells };
71800d3b7a4SDavid Howells 
719b908fe6bSDavid Howells /*
720b908fe6bSDavid Howells  * record of one of a system's set of network interfaces
721b908fe6bSDavid Howells  */
722b908fe6bSDavid Howells struct afs_interface {
723b908fe6bSDavid Howells 	struct in_addr	address;	/* IPv4 address bound to interface */
724b908fe6bSDavid Howells 	struct in_addr	netmask;	/* netmask applied to address */
725b908fe6bSDavid Howells 	unsigned	mtu;		/* MTU of interface */
726b908fe6bSDavid Howells };
727b908fe6bSDavid Howells 
7288b2a464cSDavid Howells /*
7294584ae96SDavid Howells  * Error prioritisation and accumulation.
7304584ae96SDavid Howells  */
7314584ae96SDavid Howells struct afs_error {
7324584ae96SDavid Howells 	short	error;			/* Accumulated error */
7334584ae96SDavid Howells 	bool	responded;		/* T if server responded */
7344584ae96SDavid Howells };
7354584ae96SDavid Howells 
7364584ae96SDavid Howells /*
7378b2a464cSDavid Howells  * Cursor for iterating over a server's address list.
7388b2a464cSDavid Howells  */
7398b2a464cSDavid Howells struct afs_addr_cursor {
7408b2a464cSDavid Howells 	struct afs_addr_list	*alist;		/* Current address list (pins ref) */
7413bf0fb6fSDavid Howells 	unsigned long		tried;		/* Tried addresses */
7423bf0fb6fSDavid Howells 	signed char		index;		/* Current address */
7438b2a464cSDavid Howells 	bool			responded;	/* T if the current address responded */
744744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of address iterations */
7453bf0fb6fSDavid Howells 	short			error;
7463bf0fb6fSDavid Howells 	u32			abort_code;
7478b2a464cSDavid Howells };
7488b2a464cSDavid Howells 
7498b2a464cSDavid Howells /*
7500a5143f2SDavid Howells  * Cursor for iterating over a set of volume location servers.
7510a5143f2SDavid Howells  */
7520a5143f2SDavid Howells struct afs_vl_cursor {
7530a5143f2SDavid Howells 	struct afs_addr_cursor	ac;
7540a5143f2SDavid Howells 	struct afs_cell		*cell;		/* The cell we're querying */
7550a5143f2SDavid Howells 	struct afs_vlserver_list *server_list;	/* Current server list (pins ref) */
7563bf0fb6fSDavid Howells 	struct afs_vlserver	*server;	/* Server on which this resides */
7570a5143f2SDavid Howells 	struct key		*key;		/* Key for the server */
7583bf0fb6fSDavid Howells 	unsigned long		untried;	/* Bitmask of untried servers */
7593bf0fb6fSDavid Howells 	short			index;		/* Current server */
7600a5143f2SDavid Howells 	short			error;
7610a5143f2SDavid Howells 	unsigned short		flags;
7620a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP	0x0001		/* Set to cease iteration */
7630a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY	0x0002		/* Set to do a retry */
7640a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED	0x0004		/* Set if started a retry */
765744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
7660a5143f2SDavid Howells };
7670a5143f2SDavid Howells 
7680a5143f2SDavid Howells /*
7698b2a464cSDavid Howells  * Cursor for iterating over a set of fileservers.
7708b2a464cSDavid Howells  */
7718b2a464cSDavid Howells struct afs_fs_cursor {
772a58823acSDavid Howells 	const struct afs_call_type *type;	/* Type of call done */
7738b2a464cSDavid Howells 	struct afs_addr_cursor	ac;
774d2ddc776SDavid Howells 	struct afs_vnode	*vnode;
775d2ddc776SDavid Howells 	struct afs_server_list	*server_list;	/* Current server list (pins ref) */
776d2ddc776SDavid Howells 	struct afs_cb_interest	*cbi;		/* Server on which this resides (pins ref) */
777d2ddc776SDavid Howells 	struct key		*key;		/* Key for the server */
7783bf0fb6fSDavid Howells 	unsigned long		untried;	/* Bitmask of untried servers */
779d2ddc776SDavid Howells 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
780d2ddc776SDavid Howells 	unsigned int		cb_break_2;	/* cb_break + cb_s_break (2nd vnode) */
7813bf0fb6fSDavid Howells 	short			index;		/* Current server */
782e7f680f4SDavid Howells 	short			error;
783d2ddc776SDavid Howells 	unsigned short		flags;
784d2ddc776SDavid Howells #define AFS_FS_CURSOR_STOP	0x0001		/* Set to cease iteration */
785d2ddc776SDavid Howells #define AFS_FS_CURSOR_VBUSY	0x0002		/* Set if seen VBUSY */
786d2ddc776SDavid Howells #define AFS_FS_CURSOR_VMOVED	0x0004		/* Set if seen VMOVED */
787d2ddc776SDavid Howells #define AFS_FS_CURSOR_VNOVOL	0x0008		/* Set if seen VNOVOL */
788d2ddc776SDavid Howells #define AFS_FS_CURSOR_CUR_ONLY	0x0010		/* Set if current server only (file lock held) */
789d2ddc776SDavid Howells #define AFS_FS_CURSOR_NO_VSLEEP	0x0020		/* Set to prevent sleep on VBUSY, VOFFLINE, ... */
79020b8391fSDavid Howells #define AFS_FS_CURSOR_INTR	0x0040		/* Set if op is interruptible */
791744bcd71SDavid Howells 	unsigned short		nr_iterations;	/* Number of server iterations */
7928b2a464cSDavid Howells };
7938b2a464cSDavid Howells 
794402cb8ddSDavid Howells /*
795402cb8ddSDavid Howells  * Cache auxiliary data.
796402cb8ddSDavid Howells  */
797402cb8ddSDavid Howells struct afs_vnode_cache_aux {
798402cb8ddSDavid Howells 	u64			data_version;
799402cb8ddSDavid Howells } __packed;
800402cb8ddSDavid Howells 
80198bf40cdSDavid Howells #include <trace/events/afs.h>
80298bf40cdSDavid Howells 
80308e0e7c8SDavid Howells /*****************************************************************************/
80408e0e7c8SDavid Howells /*
8058b2a464cSDavid Howells  * addr_list.c
8068b2a464cSDavid Howells  */
8078b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
8088b2a464cSDavid Howells {
8098b2a464cSDavid Howells 	if (alist)
8108b2a464cSDavid Howells 		refcount_inc(&alist->usage);
8118b2a464cSDavid Howells 	return alist;
8128b2a464cSDavid Howells }
8138b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
8148b2a464cSDavid Howells 						unsigned short,
8158b2a464cSDavid Howells 						unsigned short);
8168b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *);
8170a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
8180a5143f2SDavid Howells 						      const char *, size_t, char,
8198b2a464cSDavid Howells 						      unsigned short, unsigned short);
8200a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
8218b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *);
8228b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *);
8238b2a464cSDavid Howells 
824bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
825bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
826d2ddc776SDavid Howells 
8278b2a464cSDavid Howells /*
8289b3f26c9SDavid Howells  * cache.c
8299b3f26c9SDavid Howells  */
8309b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
8319b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs;
8329b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def;
8339b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def;
8349b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def;
8359b3f26c9SDavid Howells #else
8369b3f26c9SDavid Howells #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
8379b3f26c9SDavid Howells #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
8389b3f26c9SDavid Howells #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
8399b3f26c9SDavid Howells #endif
8409b3f26c9SDavid Howells 
8419b3f26c9SDavid Howells /*
84208e0e7c8SDavid Howells  * callback.c
84308e0e7c8SDavid Howells  */
84408e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
84530062bd1SDavid Howells extern void __afs_break_callback(struct afs_vnode *);
846c435ee34SDavid Howells extern void afs_break_callback(struct afs_vnode *);
8475cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
848c435ee34SDavid Howells 
849d4a96becSDavid Howells extern int afs_register_server_cb_interest(struct afs_vnode *,
850d4a96becSDavid Howells 					   struct afs_server_list *, unsigned int);
851c435ee34SDavid Howells extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
852d2ddc776SDavid Howells extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
853c435ee34SDavid Howells 
854c435ee34SDavid Howells static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
855c435ee34SDavid Howells {
856d4a96becSDavid Howells 	if (cbi)
857c435ee34SDavid Howells 		refcount_inc(&cbi->usage);
858c435ee34SDavid Howells 	return cbi;
859c435ee34SDavid Howells }
8601da177e4SLinus Torvalds 
86168251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
86268251f0aSDavid Howells {
863eeba1e9cSDavid Howells 	return vnode->cb_break + vnode->cb_v_break;
86468251f0aSDavid Howells }
86568251f0aSDavid Howells 
86618ac6185SDavid Howells static inline bool afs_cb_is_broken(unsigned int cb_break,
86718ac6185SDavid Howells 				    const struct afs_vnode *vnode,
86818ac6185SDavid Howells 				    const struct afs_cb_interest *cbi)
86968251f0aSDavid Howells {
87018ac6185SDavid Howells 	return !cbi || cb_break != (vnode->cb_break +
87118ac6185SDavid Howells 				    vnode->volume->cb_v_break);
87268251f0aSDavid Howells }
87368251f0aSDavid Howells 
8741da177e4SLinus Torvalds /*
8751da177e4SLinus Torvalds  * cell.c
8761da177e4SLinus Torvalds  */
877989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
878989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
879989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
880989782dcSDavid Howells 					const char *, bool);
8818b2a464cSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *);
8829ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *);
883989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
884989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
885f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
88608e0e7c8SDavid Howells 
88708e0e7c8SDavid Howells /*
88808e0e7c8SDavid Howells  * cmservice.c
88908e0e7c8SDavid Howells  */
89008e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
89108e0e7c8SDavid Howells 
8921da177e4SLinus Torvalds /*
8931da177e4SLinus Torvalds  * dir.c
8941da177e4SLinus Torvalds  */
8954b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
8964d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
897f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops;
8984d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
8994d673da1SDavid Howells 
90066c7e1d3SDavid Howells extern void afs_d_release(struct dentry *);
90179ddbfa5SDavid Howells extern int afs_dir_remove_link(struct dentry *, struct key *, unsigned long, unsigned long);
90266c7e1d3SDavid Howells 
90366c7e1d3SDavid Howells /*
90463a4681fSDavid Howells  * dir_edit.c
90563a4681fSDavid Howells  */
90663a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
90763a4681fSDavid Howells 			     enum afs_edit_dir_reason);
90863a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
90963a4681fSDavid Howells 
91063a4681fSDavid Howells /*
91179ddbfa5SDavid Howells  * dir_silly.c
91279ddbfa5SDavid Howells  */
91379ddbfa5SDavid Howells extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
91479ddbfa5SDavid Howells 			   struct dentry *, struct key *);
91579ddbfa5SDavid Howells extern int afs_silly_iput(struct dentry *, struct inode *);
91679ddbfa5SDavid Howells 
91779ddbfa5SDavid Howells /*
91866c7e1d3SDavid Howells  * dynroot.c
91966c7e1d3SDavid Howells  */
92066c7e1d3SDavid Howells extern const struct file_operations afs_dynroot_file_operations;
92166c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
92266c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations;
92366c7e1d3SDavid Howells 
92466c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
9250da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
9260da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
9270da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *);
9280da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *);
9291da177e4SLinus Torvalds 
9301da177e4SLinus Torvalds /*
9311da177e4SLinus Torvalds  * file.c
9321da177e4SLinus Torvalds  */
933f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops;
934754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
93500d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
93600d3b7a4SDavid Howells 
9374343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
9384343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
93900d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
94000d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
941d2ddc776SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
942f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *);
943196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
9441da177e4SLinus Torvalds 
9451da177e4SLinus Torvalds /*
946e8d6c554SDavid Howells  * flock.c
947e8d6c554SDavid Howells  */
948f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
949f044c884SDavid Howells 
950a690f60aSDavid Howells extern void afs_lock_op_done(struct afs_call *);
951e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
952e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
953e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
954e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
955e8d6c554SDavid Howells 
956e8d6c554SDavid Howells /*
95708e0e7c8SDavid Howells  * fsclient.c
95808e0e7c8SDavid Howells  */
959a58823acSDavid Howells extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_status_cb *,
960a58823acSDavid Howells 				    struct afs_volsync *);
961d2ddc776SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
962a58823acSDavid Howells extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_status_cb *, struct afs_read *);
963a58823acSDavid Howells extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
964a58823acSDavid Howells 			 struct afs_status_cb *, struct afs_fid *, struct afs_status_cb *);
965a58823acSDavid Howells extern int afs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool,
966a58823acSDavid Howells 			 struct afs_status_cb *);
967a58823acSDavid Howells extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *,
968a58823acSDavid Howells 		       struct afs_status_cb *, struct afs_status_cb *);
969a58823acSDavid Howells extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
970a58823acSDavid Howells 			  struct afs_status_cb *, struct afs_fid *, struct afs_status_cb *);
971d2ddc776SDavid Howells extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
972a58823acSDavid Howells 			 struct afs_vnode *, const char *,
973a58823acSDavid Howells 			 struct afs_status_cb *, struct afs_status_cb *);
9744343d008SDavid Howells extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
975a58823acSDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned, struct afs_status_cb *);
976a58823acSDavid Howells extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *, struct afs_status_cb *);
977d2ddc776SDavid Howells extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
978a58823acSDavid Howells extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t, struct afs_status_cb *);
979a58823acSDavid Howells extern int afs_fs_extend_lock(struct afs_fs_cursor *, struct afs_status_cb *);
980a58823acSDavid Howells extern int afs_fs_release_lock(struct afs_fs_cursor *, struct afs_status_cb *);
981d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
982d2ddc776SDavid Howells 					struct afs_addr_cursor *, struct key *);
9830b9bf381SDavid Howells extern struct afs_call *afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
9840b9bf381SDavid Howells 						struct afs_addr_cursor *, struct key *,
9850b9bf381SDavid Howells 						unsigned int);
9865cf9dd55SDavid Howells extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
98787182759SDavid Howells 				     struct afs_fid *, struct afs_status_cb *,
98887182759SDavid Howells 				     unsigned int, struct afs_volsync *);
9895cf9dd55SDavid Howells extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
990a58823acSDavid Howells 			       struct afs_fid *, struct afs_status_cb *,
991a58823acSDavid Howells 			       struct afs_volsync *);
99208e0e7c8SDavid Howells 
993260f082bSDavid Howells struct afs_acl {
994260f082bSDavid Howells 	u32	size;
995260f082bSDavid Howells 	u8	data[];
996260f082bSDavid Howells };
997260f082bSDavid Howells 
998a58823acSDavid Howells extern struct afs_acl *afs_fs_fetch_acl(struct afs_fs_cursor *, struct afs_status_cb *);
999a58823acSDavid Howells extern int afs_fs_store_acl(struct afs_fs_cursor *, const struct afs_acl *,
1000a58823acSDavid Howells 			    struct afs_status_cb *);
1001260f082bSDavid Howells 
100208e0e7c8SDavid Howells /*
10033bf0fb6fSDavid Howells  * fs_probe.c
10043bf0fb6fSDavid Howells  */
10053bf0fb6fSDavid Howells extern void afs_fileserver_probe_result(struct afs_call *);
10063bf0fb6fSDavid Howells extern int afs_probe_fileservers(struct afs_net *, struct key *, struct afs_server_list *);
10073bf0fb6fSDavid Howells extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long);
10083bf0fb6fSDavid Howells 
10093bf0fb6fSDavid Howells /*
10101da177e4SLinus Torvalds  * inode.c
10111da177e4SLinus Torvalds  */
1012a58823acSDavid Howells extern void afs_vnode_commit_status(struct afs_fs_cursor *,
1013a58823acSDavid Howells 				    struct afs_vnode *,
1014a58823acSDavid Howells 				    unsigned int,
1015a58823acSDavid Howells 				    const afs_dataversion_t *,
1016a58823acSDavid Howells 				    struct afs_status_cb *);
1017a58823acSDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1018c435ee34SDavid Howells extern int afs_iget5_test(struct inode *, void *);
10194d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
102000d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *,
1021a58823acSDavid Howells 			      struct afs_fid *, struct afs_status_cb *,
1022b134d687SDavid Howells 			      struct afs_cb_interest *,
1023b134d687SDavid Howells 			      struct afs_vnode *);
1024416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *);
1025*c925bd0aSDavid Howells extern bool afs_check_validity(struct afs_vnode *);
1026260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
1027a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
102831143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *);
1029b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
1030bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
10311da177e4SLinus Torvalds 
10321da177e4SLinus Torvalds /*
10331da177e4SLinus Torvalds  * main.c
10341da177e4SLinus Torvalds  */
10350ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
10365b86d4ffSDavid Howells extern int afs_net_id;
10375b86d4ffSDavid Howells 
10385b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net)
10395b86d4ffSDavid Howells {
10405b86d4ffSDavid Howells 	return net_generic(net, afs_net_id);
10415b86d4ffSDavid Howells }
10425b86d4ffSDavid Howells 
10435b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb)
10445b86d4ffSDavid Howells {
10455b86d4ffSDavid Howells 	return afs_net(AFS_FS_S(sb)->net_ns);
10465b86d4ffSDavid Howells }
1047f044c884SDavid Howells 
1048f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
1049f044c884SDavid Howells {
10505b86d4ffSDavid Howells 	return afs_sb2net(dentry->d_sb);
1051f044c884SDavid Howells }
1052f044c884SDavid Howells 
1053f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
1054f044c884SDavid Howells {
10555b86d4ffSDavid Howells 	return afs_sb2net(inode->i_sb);
1056f044c884SDavid Howells }
1057f044c884SDavid Howells 
1058f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1059f044c884SDavid Howells {
10605b86d4ffSDavid Howells 	return afs_i2net(&vnode->vfs_inode);
1061f044c884SDavid Howells }
1062f044c884SDavid Howells 
1063f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
1064f044c884SDavid Howells {
10655b86d4ffSDavid Howells 	return net_generic(sock_net(sk), afs_net_id);
1066f044c884SDavid Howells }
10671da177e4SLinus Torvalds 
1068d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s)
1069d55b4da4SDavid Howells {
1070d55b4da4SDavid Howells 	atomic_inc(s);
1071d55b4da4SDavid Howells }
1072d55b4da4SDavid Howells 
1073d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1074d55b4da4SDavid Howells 
10751da177e4SLinus Torvalds /*
107608e0e7c8SDavid Howells  * misc.c
107708e0e7c8SDavid Howells  */
107808e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
10794584ae96SDavid Howells extern void afs_prioritise_error(struct afs_error *, int, u32);
108008e0e7c8SDavid Howells 
108108e0e7c8SDavid Howells /*
10821da177e4SLinus Torvalds  * mntpt.c
10831da177e4SLinus Torvalds  */
1084754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
1085bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
10864b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
10871da177e4SLinus Torvalds 
1088d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
108908e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
10901da177e4SLinus Torvalds 
10911da177e4SLinus Torvalds /*
1092b4db2b35SArnd Bergmann  * netdevices.c
1093b4db2b35SArnd Bergmann  */
10945b86d4ffSDavid Howells extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *,
10955b86d4ffSDavid Howells 				   size_t, bool);
1096b4db2b35SArnd Bergmann 
1097b4db2b35SArnd Bergmann /*
10981da177e4SLinus Torvalds  * proc.c
10991da177e4SLinus Torvalds  */
1100b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS
1101f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
1102f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
11035b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *);
11045b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *);
11056f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *);
1106b6cfbecaSDavid Howells #else
1107b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; }
1108b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {}
1109b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
1110b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
1111b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1112b6cfbecaSDavid Howells #endif
11131da177e4SLinus Torvalds 
111408e0e7c8SDavid Howells /*
1115d2ddc776SDavid Howells  * rotate.c
1116d2ddc776SDavid Howells  */
1117d2ddc776SDavid Howells extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
111820b8391fSDavid Howells 				      struct key *, bool);
1119d2ddc776SDavid Howells extern bool afs_select_fileserver(struct afs_fs_cursor *);
1120d2ddc776SDavid Howells extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
1121d2ddc776SDavid Howells extern int afs_end_vnode_operation(struct afs_fs_cursor *);
1122d2ddc776SDavid Howells 
1123d2ddc776SDavid Howells /*
112408e0e7c8SDavid Howells  * rxrpc.c
112508e0e7c8SDavid Howells  */
1126f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
11278324f0bcSDavid Howells 
1128f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
1129f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
1130f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
1131341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
11320b9bf381SDavid Howells extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t);
11330b9bf381SDavid Howells extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
1134f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1135f044c884SDavid Howells 					    const struct afs_call_type *,
113608e0e7c8SDavid Howells 					    size_t, size_t);
113708e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
113808e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
1139b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
114012bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool);
1141160cb957SDavid Howells extern int afs_protocol_error(struct afs_call *, int, enum afs_eproto_cause);
114208e0e7c8SDavid Howells 
114320b8391fSDavid Howells static inline void afs_set_fc_call(struct afs_call *call, struct afs_fs_cursor *fc)
114420b8391fSDavid Howells {
114520b8391fSDavid Howells 	call->intr = fc->flags & AFS_FS_CURSOR_INTR;
1146a58823acSDavid Howells 	fc->type = call->type;
114720b8391fSDavid Howells }
114820b8391fSDavid Howells 
114912bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
115012bdcf33SDavid Howells {
115112bdcf33SDavid Howells 	call->kvec[0].iov_base = buf;
115212bdcf33SDavid Howells 	call->kvec[0].iov_len = size;
115312bdcf33SDavid Howells 	iov_iter_kvec(&call->iter, READ, call->kvec, 1, size);
115412bdcf33SDavid Howells }
115512bdcf33SDavid Howells 
115612bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call)
115712bdcf33SDavid Howells {
115812bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
115912bdcf33SDavid Howells }
116012bdcf33SDavid Howells 
116112bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call)
116212bdcf33SDavid Howells {
116312bdcf33SDavid Howells 	afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
116412bdcf33SDavid Howells }
116512bdcf33SDavid Howells 
116612bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size)
116712bdcf33SDavid Howells {
116812bdcf33SDavid Howells 	iov_iter_discard(&call->iter, READ, size);
116912bdcf33SDavid Howells }
117012bdcf33SDavid Howells 
117112bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
117212bdcf33SDavid Howells {
117312bdcf33SDavid Howells 	afs_extract_begin(call, call->buffer, size);
117412bdcf33SDavid Howells }
117512bdcf33SDavid Howells 
1176d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
1177372ee163SDavid Howells {
117812bdcf33SDavid Howells 	return afs_extract_data(call, false);
1179372ee163SDavid Howells }
1180372ee163SDavid Howells 
118198bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
118298bf40cdSDavid Howells 					enum afs_call_state state)
118398bf40cdSDavid Howells {
118498bf40cdSDavid Howells 	return READ_ONCE(call->state) == state;
118598bf40cdSDavid Howells }
118698bf40cdSDavid Howells 
118798bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
118898bf40cdSDavid Howells 				      enum afs_call_state from,
118998bf40cdSDavid Howells 				      enum afs_call_state to)
119098bf40cdSDavid Howells {
119198bf40cdSDavid Howells 	bool ok = false;
119298bf40cdSDavid Howells 
119398bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
119498bf40cdSDavid Howells 	if (call->state == from) {
119598bf40cdSDavid Howells 		call->state = to;
119698bf40cdSDavid Howells 		trace_afs_call_state(call, from, to, 0, 0);
119798bf40cdSDavid Howells 		ok = true;
119898bf40cdSDavid Howells 	}
119998bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
120098bf40cdSDavid Howells 	return ok;
120198bf40cdSDavid Howells }
120298bf40cdSDavid Howells 
120398bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
120498bf40cdSDavid Howells 					 int error, u32 remote_abort)
120598bf40cdSDavid Howells {
120698bf40cdSDavid Howells 	enum afs_call_state state;
120798bf40cdSDavid Howells 	bool ok = false;
120898bf40cdSDavid Howells 
120998bf40cdSDavid Howells 	spin_lock_bh(&call->state_lock);
121098bf40cdSDavid Howells 	state = call->state;
121198bf40cdSDavid Howells 	if (state != AFS_CALL_COMPLETE) {
121298bf40cdSDavid Howells 		call->abort_code = remote_abort;
121398bf40cdSDavid Howells 		call->error = error;
121498bf40cdSDavid Howells 		call->state = AFS_CALL_COMPLETE;
121598bf40cdSDavid Howells 		trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
121698bf40cdSDavid Howells 				     error, remote_abort);
121798bf40cdSDavid Howells 		ok = true;
121898bf40cdSDavid Howells 	}
121998bf40cdSDavid Howells 	spin_unlock_bh(&call->state_lock);
122098bf40cdSDavid Howells 	if (ok)
122198bf40cdSDavid Howells 		trace_afs_call_done(call);
122298bf40cdSDavid Howells }
122398bf40cdSDavid Howells 
122408e0e7c8SDavid Howells /*
122500d3b7a4SDavid Howells  * security.c
122600d3b7a4SDavid Howells  */
1227be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
122800d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
1229a58823acSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1230a58823acSDavid Howells 			     struct afs_status_cb *);
1231416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *);
123200d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
12330fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
123410556cb2SAl Viro extern int afs_permission(struct inode *, int);
1235be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
123600d3b7a4SDavid Howells 
123700d3b7a4SDavid Howells /*
123808e0e7c8SDavid Howells  * server.c
123908e0e7c8SDavid Howells  */
124008e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
124108e0e7c8SDavid Howells 
1242c435ee34SDavid Howells static inline struct afs_server *afs_get_server(struct afs_server *server)
1243c435ee34SDavid Howells {
1244c435ee34SDavid Howells 	atomic_inc(&server->usage);
1245c435ee34SDavid Howells 	return server;
1246c435ee34SDavid Howells }
124708e0e7c8SDavid Howells 
1248f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
1249f044c884SDavid Howells 					  const struct sockaddr_rxrpc *);
1250d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
1251d2ddc776SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
12529ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *);
1253d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
1254d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
1255f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
1256d2ddc776SDavid Howells extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
1257d2ddc776SDavid Howells 
1258d2ddc776SDavid Howells /*
1259d2ddc776SDavid Howells  * server_list.c
1260d2ddc776SDavid Howells  */
1261d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1262d2ddc776SDavid Howells {
1263d2ddc776SDavid Howells 	refcount_inc(&slist->usage);
1264d2ddc776SDavid Howells 	return slist;
1265d2ddc776SDavid Howells }
1266d2ddc776SDavid Howells 
1267d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1268d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1269d2ddc776SDavid Howells 						     struct afs_vldb_entry *,
1270d2ddc776SDavid Howells 						     u8);
1271d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
127208e0e7c8SDavid Howells 
127308e0e7c8SDavid Howells /*
127400d3b7a4SDavid Howells  * super.c
127500d3b7a4SDavid Howells  */
1276f044c884SDavid Howells extern int __init afs_fs_init(void);
12775b86d4ffSDavid Howells extern void afs_fs_exit(void);
127800d3b7a4SDavid Howells 
127900d3b7a4SDavid Howells /*
128008e0e7c8SDavid Howells  * vlclient.c
128108e0e7c8SDavid Howells  */
12820a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
12830a5143f2SDavid Howells 							 const char *, int);
12840a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
12850b9bf381SDavid Howells extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *,
12860b9bf381SDavid Howells 						struct key *, struct afs_vlserver *, unsigned int);
12870a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
12880a5143f2SDavid Howells 
12890a5143f2SDavid Howells /*
12903bf0fb6fSDavid Howells  * vl_probe.c
12913bf0fb6fSDavid Howells  */
12923bf0fb6fSDavid Howells extern void afs_vlserver_probe_result(struct afs_call *);
12933bf0fb6fSDavid Howells extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
12943bf0fb6fSDavid Howells extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
12953bf0fb6fSDavid Howells 
12963bf0fb6fSDavid Howells /*
12970a5143f2SDavid Howells  * vl_rotate.c
12980a5143f2SDavid Howells  */
12990a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
13000a5143f2SDavid Howells 					 struct afs_cell *, struct key *);
13010a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *);
13020a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
13030a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
13040a5143f2SDavid Howells 
13050a5143f2SDavid Howells /*
13060a5143f2SDavid Howells  * vlserver_list.c
13070a5143f2SDavid Howells  */
13080a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
13090a5143f2SDavid Howells {
13100a5143f2SDavid Howells 	atomic_inc(&vlserver->usage);
13110a5143f2SDavid Howells 	return vlserver;
13120a5143f2SDavid Howells }
13130a5143f2SDavid Howells 
13140a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
13150a5143f2SDavid Howells {
13160a5143f2SDavid Howells 	if (vllist)
13170a5143f2SDavid Howells 		atomic_inc(&vllist->usage);
13180a5143f2SDavid Howells 	return vllist;
13190a5143f2SDavid Howells }
13200a5143f2SDavid Howells 
13210a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
13220a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
13230a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
13240a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
13250a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
13260a5143f2SDavid Howells 							   const void *, size_t);
132708e0e7c8SDavid Howells 
132808e0e7c8SDavid Howells /*
132908e0e7c8SDavid Howells  * volume.c
133008e0e7c8SDavid Howells  */
1331d2ddc776SDavid Howells static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
133249566f6fSDavid Howells {
133349566f6fSDavid Howells 	if (volume)
133449566f6fSDavid Howells 		atomic_inc(&volume->usage);
133549566f6fSDavid Howells 	return volume;
133649566f6fSDavid Howells }
133708e0e7c8SDavid Howells 
133813fcc683SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1339d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *);
1340d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
13419ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
1342d2ddc776SDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct key *);
134308e0e7c8SDavid Howells 
134431143d5dSDavid Howells /*
134531143d5dSDavid Howells  * write.c
134631143d5dSDavid Howells  */
134731143d5dSDavid Howells extern int afs_set_page_dirty(struct page *);
134815b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
134915b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned flags,
135015b4650eSNick Piggin 			struct page **pagep, void **fsdata);
135115b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
135215b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned copied,
135315b4650eSNick Piggin 			struct page *page, void *fsdata);
135431143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
135531143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
135650b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
135702c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
13580722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
13594343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
13604343d008SDavid Howells extern int afs_launder_page(struct page *);
136131143d5dSDavid Howells 
1362d3e3b7eaSDavid Howells /*
1363d3e3b7eaSDavid Howells  * xattr.c
1364d3e3b7eaSDavid Howells  */
1365d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
1366d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
136731143d5dSDavid Howells 
136830062bd1SDavid Howells /*
136930062bd1SDavid Howells  * yfsclient.c
137030062bd1SDavid Howells  */
1371a58823acSDavid Howells extern int yfs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_status_cb *,
1372a58823acSDavid Howells 				    struct afs_volsync *);
1373a58823acSDavid Howells extern int yfs_fs_fetch_data(struct afs_fs_cursor *, struct afs_status_cb *, struct afs_read *);
1374a58823acSDavid Howells extern int yfs_fs_create_file(struct afs_fs_cursor *, const char *, umode_t, struct afs_status_cb *,
1375a58823acSDavid Howells 			      struct afs_fid *, struct afs_status_cb *);
1376a58823acSDavid Howells extern int yfs_fs_make_dir(struct afs_fs_cursor *, const char *, umode_t, struct afs_status_cb *,
1377a58823acSDavid Howells 			   struct afs_fid *, struct afs_status_cb *);
1378a58823acSDavid Howells extern int yfs_fs_remove_file2(struct afs_fs_cursor *, struct afs_vnode *, const char *,
1379a58823acSDavid Howells 			       struct afs_status_cb *, struct afs_status_cb *);
1380a58823acSDavid Howells extern int yfs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool,
1381a58823acSDavid Howells 			 struct afs_status_cb *);
1382a58823acSDavid Howells extern int yfs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *,
1383a58823acSDavid Howells 		       struct afs_status_cb *, struct afs_status_cb *);
1384a58823acSDavid Howells extern int yfs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
1385a58823acSDavid Howells 			  struct afs_status_cb *, struct afs_fid *, struct afs_status_cb *);
1386a58823acSDavid Howells extern int yfs_fs_rename(struct afs_fs_cursor *, const char *, struct afs_vnode *, const char *,
1387a58823acSDavid Howells 			 struct afs_status_cb *, struct afs_status_cb *);
138830062bd1SDavid Howells extern int yfs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
1389a58823acSDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned, struct afs_status_cb *);
1390a58823acSDavid Howells extern int yfs_fs_setattr(struct afs_fs_cursor *, struct iattr *, struct afs_status_cb *);
139130062bd1SDavid Howells extern int yfs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
1392a58823acSDavid Howells extern int yfs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t, struct afs_status_cb *);
1393a58823acSDavid Howells extern int yfs_fs_extend_lock(struct afs_fs_cursor *, struct afs_status_cb *);
1394a58823acSDavid Howells extern int yfs_fs_release_lock(struct afs_fs_cursor *, struct afs_status_cb *);
139530062bd1SDavid Howells extern int yfs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
1396a58823acSDavid Howells 			       struct afs_fid *, struct afs_status_cb *,
1397a58823acSDavid Howells 			       struct afs_volsync *);
139830062bd1SDavid Howells extern int yfs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
139987182759SDavid Howells 				     struct afs_fid *, struct afs_status_cb *,
140087182759SDavid Howells 				     unsigned int, struct afs_volsync *);
1401d2ddc776SDavid Howells 
1402ae46578bSDavid Howells struct yfs_acl {
1403ae46578bSDavid Howells 	struct afs_acl	*acl;		/* Dir/file/symlink ACL */
1404ae46578bSDavid Howells 	struct afs_acl	*vol_acl;	/* Whole volume ACL */
1405ae46578bSDavid Howells 	u32		inherit_flag;	/* True if ACL is inherited from parent dir */
1406ae46578bSDavid Howells 	u32		num_cleaned;	/* Number of ACEs removed due to subject removal */
1407ae46578bSDavid Howells 	unsigned int	flags;
1408ae46578bSDavid Howells #define YFS_ACL_WANT_ACL	0x01	/* Set if caller wants ->acl */
1409ae46578bSDavid Howells #define YFS_ACL_WANT_VOL_ACL	0x02	/* Set if caller wants ->vol_acl */
1410ae46578bSDavid Howells };
1411ae46578bSDavid Howells 
1412ae46578bSDavid Howells extern void yfs_free_opaque_acl(struct yfs_acl *);
1413a58823acSDavid Howells extern struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *, struct yfs_acl *,
1414a58823acSDavid Howells 					       struct afs_status_cb *);
1415a58823acSDavid Howells extern int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *, const struct afs_acl *,
1416a58823acSDavid Howells 				    struct afs_status_cb *);
1417ae46578bSDavid Howells 
1418d2ddc776SDavid Howells /*
1419d2ddc776SDavid Howells  * Miscellaneous inline functions.
1420d2ddc776SDavid Howells  */
1421d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1422d2ddc776SDavid Howells {
1423d2ddc776SDavid Howells 	return container_of(inode, struct afs_vnode, vfs_inode);
1424d2ddc776SDavid Howells }
1425d2ddc776SDavid Howells 
1426d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1427d2ddc776SDavid Howells {
1428d2ddc776SDavid Howells 	return &vnode->vfs_inode;
1429d2ddc776SDavid Howells }
1430d2ddc776SDavid Howells 
1431d2ddc776SDavid Howells static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1432d2ddc776SDavid Howells 						 struct afs_vnode *vnode)
1433d2ddc776SDavid Howells {
1434d2ddc776SDavid Howells 	if (fc->ac.error == -ENOENT) {
1435d2ddc776SDavid Howells 		set_bit(AFS_VNODE_DELETED, &vnode->flags);
1436d2ddc776SDavid Howells 		afs_break_callback(vnode);
1437d2ddc776SDavid Howells 	}
1438d2ddc776SDavid Howells }
1439d2ddc776SDavid Howells 
1440f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1441f51375cdSDavid Howells {
1442f51375cdSDavid Howells 	trace_afs_io_error(call->debug_id, -EIO, where);
1443f51375cdSDavid Howells 	return -EIO;
1444f51375cdSDavid Howells }
1445f51375cdSDavid Howells 
1446f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1447f51375cdSDavid Howells {
1448f51375cdSDavid Howells 	trace_afs_file_error(vnode, -EIO, where);
1449f51375cdSDavid Howells 	return -EIO;
1450f51375cdSDavid Howells }
1451d2ddc776SDavid Howells 
145208e0e7c8SDavid Howells /*****************************************************************************/
145308e0e7c8SDavid Howells /*
145408e0e7c8SDavid Howells  * debug tracing
145508e0e7c8SDavid Howells  */
145608e0e7c8SDavid Howells extern unsigned afs_debug;
145708e0e7c8SDavid Howells 
145808e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1459ad16df84SSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
146008e0e7c8SDavid Howells 
1461530b6412SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1462530b6412SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
146308e0e7c8SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
146408e0e7c8SDavid Howells 
146508e0e7c8SDavid Howells 
146608e0e7c8SDavid Howells #if defined(__KDEBUG)
146708e0e7c8SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
146808e0e7c8SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
146908e0e7c8SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
147008e0e7c8SDavid Howells 
147108e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
147208e0e7c8SDavid Howells #define AFS_DEBUG_KENTER	0x01
147308e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE	0x02
147408e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG	0x04
147508e0e7c8SDavid Howells 
147608e0e7c8SDavid Howells #define _enter(FMT,...)					\
147708e0e7c8SDavid Howells do {							\
147808e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
147908e0e7c8SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
148008e0e7c8SDavid Howells } while (0)
148108e0e7c8SDavid Howells 
148208e0e7c8SDavid Howells #define _leave(FMT,...)					\
148308e0e7c8SDavid Howells do {							\
148408e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
148508e0e7c8SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
148608e0e7c8SDavid Howells } while (0)
148708e0e7c8SDavid Howells 
148808e0e7c8SDavid Howells #define _debug(FMT,...)					\
148908e0e7c8SDavid Howells do {							\
149008e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
149108e0e7c8SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
149208e0e7c8SDavid Howells } while (0)
149308e0e7c8SDavid Howells 
149408e0e7c8SDavid Howells #else
149512fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
149612fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
149712fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
149808e0e7c8SDavid Howells #endif
149908e0e7c8SDavid Howells 
150008e0e7c8SDavid Howells /*
150108e0e7c8SDavid Howells  * debug assertion checking
150208e0e7c8SDavid Howells  */
150308e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
150408e0e7c8SDavid Howells 
150508e0e7c8SDavid Howells #define ASSERT(X)						\
150608e0e7c8SDavid Howells do {								\
150708e0e7c8SDavid Howells 	if (unlikely(!(X))) {					\
150808e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
150908e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
151008e0e7c8SDavid Howells 		BUG();						\
151108e0e7c8SDavid Howells 	}							\
151208e0e7c8SDavid Howells } while(0)
151308e0e7c8SDavid Howells 
151408e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)						\
151508e0e7c8SDavid Howells do {									\
151608e0e7c8SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
151708e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
151808e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
151908e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
152008e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
152108e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
152208e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
152308e0e7c8SDavid Howells 		BUG();							\
152408e0e7c8SDavid Howells 	}								\
152508e0e7c8SDavid Howells } while(0)
152608e0e7c8SDavid Howells 
1527416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)					\
1528416351f2SDavid Howells do {									\
1529416351f2SDavid Howells 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
1530416351f2SDavid Howells 		printk(KERN_ERR "\n");					\
1531416351f2SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1532416351f2SDavid Howells 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
1533416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1534416351f2SDavid Howells 		       (unsigned long)(H));				\
1535416351f2SDavid Howells 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1536416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
1537416351f2SDavid Howells 		       (unsigned long)(H));				\
1538416351f2SDavid Howells 		BUG();							\
1539416351f2SDavid Howells 	}								\
1540416351f2SDavid Howells } while(0)
1541416351f2SDavid Howells 
154208e0e7c8SDavid Howells #define ASSERTIF(C, X)						\
154308e0e7c8SDavid Howells do {								\
154408e0e7c8SDavid Howells 	if (unlikely((C) && !(X))) {				\
154508e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
154608e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
154708e0e7c8SDavid Howells 		BUG();						\
154808e0e7c8SDavid Howells 	}							\
154908e0e7c8SDavid Howells } while(0)
155008e0e7c8SDavid Howells 
155108e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
155208e0e7c8SDavid Howells do {									\
155308e0e7c8SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
155408e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
155508e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
155608e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
155708e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
155808e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
155908e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
156008e0e7c8SDavid Howells 		BUG();							\
156108e0e7c8SDavid Howells 	}								\
156208e0e7c8SDavid Howells } while(0)
156308e0e7c8SDavid Howells 
156408e0e7c8SDavid Howells #else
156508e0e7c8SDavid Howells 
156608e0e7c8SDavid Howells #define ASSERT(X)				\
156708e0e7c8SDavid Howells do {						\
156808e0e7c8SDavid Howells } while(0)
156908e0e7c8SDavid Howells 
157008e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)			\
157108e0e7c8SDavid Howells do {						\
157208e0e7c8SDavid Howells } while(0)
157308e0e7c8SDavid Howells 
1574416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)		\
1575416351f2SDavid Howells do {						\
1576416351f2SDavid Howells } while(0)
1577416351f2SDavid Howells 
157808e0e7c8SDavid Howells #define ASSERTIF(C, X)				\
157908e0e7c8SDavid Howells do {						\
158008e0e7c8SDavid Howells } while(0)
158108e0e7c8SDavid Howells 
158208e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
158308e0e7c8SDavid Howells do {						\
158408e0e7c8SDavid Howells } while(0)
158508e0e7c8SDavid Howells 
158608e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1587