xref: /openbmc/linux/fs/afs/internal.h (revision 4d9df986)
1ec26815aSDavid Howells /* internal AFS stuff
21da177e4SLinus Torvalds  *
308e0e7c8SDavid Howells  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
41da177e4SLinus Torvalds  * Written by David Howells (dhowells@redhat.com)
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or
71da177e4SLinus Torvalds  * modify it under the terms of the GNU General Public License
81da177e4SLinus Torvalds  * as published by the Free Software Foundation; either version
91da177e4SLinus Torvalds  * 2 of the License, or (at your option) any later version.
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
121da177e4SLinus Torvalds #include <linux/compiler.h>
131da177e4SLinus Torvalds #include <linux/kernel.h>
148a79790bSTina Ruchandani #include <linux/ktime.h>
151da177e4SLinus Torvalds #include <linux/fs.h>
161da177e4SLinus Torvalds #include <linux/pagemap.h>
1708e0e7c8SDavid Howells #include <linux/rxrpc.h>
1800d3b7a4SDavid Howells #include <linux/key.h>
19e8edc6e0SAlexey Dobriyan #include <linux/workqueue.h>
2000c541eaSAndrew Morton #include <linux/sched.h>
2180e50be4SChristoph Hellwig #include <linux/fscache.h>
22e1da0222SJens Axboe #include <linux/backing-dev.h>
23ff548773SDavid Howells #include <linux/uuid.h>
24f044c884SDavid Howells #include <net/net_namespace.h>
258324f0bcSDavid Howells #include <net/af_rxrpc.h>
2600c541eaSAndrew Morton 
2708e0e7c8SDavid Howells #include "afs.h"
2808e0e7c8SDavid Howells #include "afs_vl.h"
2908e0e7c8SDavid Howells 
3008e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15
3108e0e7c8SDavid Howells 
3231143d5dSDavid Howells struct pagevec;
3308e0e7c8SDavid Howells struct afs_call;
3408e0e7c8SDavid Howells 
3508e0e7c8SDavid Howells typedef enum {
3608e0e7c8SDavid Howells 	AFS_VL_NEW,			/* new, uninitialised record */
3708e0e7c8SDavid Howells 	AFS_VL_CREATING,		/* creating record */
3808e0e7c8SDavid Howells 	AFS_VL_VALID,			/* record is pending */
3908e0e7c8SDavid Howells 	AFS_VL_NO_VOLUME,		/* no such volume available */
4008e0e7c8SDavid Howells 	AFS_VL_UPDATING,		/* update in progress */
4108e0e7c8SDavid Howells 	AFS_VL_VOLUME_DELETED,		/* volume was deleted */
4208e0e7c8SDavid Howells 	AFS_VL_UNCERTAIN,		/* uncertain state (update failed) */
4308e0e7c8SDavid Howells } __attribute__((packed)) afs_vlocation_state_t;
441da177e4SLinus Torvalds 
4500d3b7a4SDavid Howells struct afs_mount_params {
4600d3b7a4SDavid Howells 	bool			rwpath;		/* T if the parent should be considered R/W */
4700d3b7a4SDavid Howells 	bool			force;		/* T to force cell type */
48bec5eb61Swanglei 	bool			autocell;	/* T if set auto mount operation */
4900d3b7a4SDavid Howells 	afs_voltype_t		type;		/* type of volume requested */
5000d3b7a4SDavid Howells 	int			volnamesz;	/* size of volume name */
5100d3b7a4SDavid Howells 	const char		*volname;	/* name of volume to mount */
52f044c884SDavid Howells 	struct afs_net		*net;		/* Network namespace in effect */
5300d3b7a4SDavid Howells 	struct afs_cell		*cell;		/* cell in which to find volume */
5400d3b7a4SDavid Howells 	struct afs_volume	*volume;	/* volume record */
5500d3b7a4SDavid Howells 	struct key		*key;		/* key to use for secure mounting */
5600d3b7a4SDavid Howells };
5700d3b7a4SDavid Howells 
588e8d7f13SDavid Howells enum afs_call_state {
598e8d7f13SDavid Howells 	AFS_CALL_REQUESTING,	/* request is being sent for outgoing call */
608e8d7f13SDavid Howells 	AFS_CALL_AWAIT_REPLY,	/* awaiting reply to outgoing call */
618e8d7f13SDavid Howells 	AFS_CALL_AWAIT_OP_ID,	/* awaiting op ID on incoming call */
628e8d7f13SDavid Howells 	AFS_CALL_AWAIT_REQUEST,	/* awaiting request data on incoming call */
638e8d7f13SDavid Howells 	AFS_CALL_REPLYING,	/* replying to incoming call */
648e8d7f13SDavid Howells 	AFS_CALL_AWAIT_ACK,	/* awaiting final ACK of incoming call */
658e8d7f13SDavid Howells 	AFS_CALL_COMPLETE,	/* Completed or failed */
668e8d7f13SDavid Howells };
67f044c884SDavid Howells 
6808e0e7c8SDavid Howells /*
6908e0e7c8SDavid Howells  * a record of an in-progress RxRPC call
7008e0e7c8SDavid Howells  */
7108e0e7c8SDavid Howells struct afs_call {
7208e0e7c8SDavid Howells 	const struct afs_call_type *type;	/* type of call */
7308e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* processes awaiting completion */
74341f741fSDavid Howells 	struct work_struct	async_work;	/* async I/O processor */
7508e0e7c8SDavid Howells 	struct work_struct	work;		/* actual work processor */
7608e0e7c8SDavid Howells 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
7708e0e7c8SDavid Howells 	struct key		*key;		/* security for this call */
78f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
7908e0e7c8SDavid Howells 	struct afs_server	*server;	/* server affected by incoming CM call */
8008e0e7c8SDavid Howells 	void			*request;	/* request data (first part) */
8131143d5dSDavid Howells 	struct address_space	*mapping;	/* page set */
8231143d5dSDavid Howells 	struct afs_writeback	*wb;		/* writeback being performed */
8308e0e7c8SDavid Howells 	void			*buffer;	/* reply receive buffer */
8408e0e7c8SDavid Howells 	void			*reply;		/* reply buffer (first part) */
8508e0e7c8SDavid Howells 	void			*reply2;	/* reply buffer (second part) */
8608e0e7c8SDavid Howells 	void			*reply3;	/* reply buffer (third part) */
87260a9803SDavid Howells 	void			*reply4;	/* reply buffer (fourth part) */
8831143d5dSDavid Howells 	pgoff_t			first;		/* first page in mapping to deal with */
8931143d5dSDavid Howells 	pgoff_t			last;		/* last page in mapping to deal with */
90d001648eSDavid Howells 	size_t			offset;		/* offset into received data store */
91341f741fSDavid Howells 	atomic_t		usage;
928e8d7f13SDavid Howells 	enum afs_call_state	state;
9308e0e7c8SDavid Howells 	int			error;		/* error code */
94d001648eSDavid Howells 	u32			abort_code;	/* Remote abort ID or 0 */
9508e0e7c8SDavid Howells 	unsigned		request_size;	/* size of request data */
9608e0e7c8SDavid Howells 	unsigned		reply_max;	/* maximum size of reply */
9731143d5dSDavid Howells 	unsigned		first_offset;	/* offset into mapping[first] */
98bcd89270SMarc Dionne 	union {
9931143d5dSDavid Howells 		unsigned	last_to;	/* amount of mapping[last] */
100bcd89270SMarc Dionne 		unsigned	count2;		/* count used in unmarshalling */
101bcd89270SMarc Dionne 	};
10208e0e7c8SDavid Howells 	unsigned char		unmarshall;	/* unmarshalling phase */
10308e0e7c8SDavid Howells 	bool			incoming;	/* T if incoming call */
10431143d5dSDavid Howells 	bool			send_pages;	/* T if data from mapping should be sent */
105d001648eSDavid Howells 	bool			need_attention;	/* T if RxRPC poked us */
10656ff9c83SDavid Howells 	bool			async;		/* T if asynchronous */
107a68f4a27SDavid Howells 	bool			upgrade;	/* T to request service upgrade */
10808e0e7c8SDavid Howells 	u16			service_id;	/* RxRPC service ID to call */
10950a2c953SDavid Howells 	u32			operation_ID;	/* operation ID for an incoming call */
11008e0e7c8SDavid Howells 	u32			count;		/* count for use in unmarshalling */
11108e0e7c8SDavid Howells 	__be32			tmp;		/* place to extract temporary data */
11231143d5dSDavid Howells 	afs_dataversion_t	store_version;	/* updated version expected from store */
11308e0e7c8SDavid Howells };
11408e0e7c8SDavid Howells 
11508e0e7c8SDavid Howells struct afs_call_type {
11600d3b7a4SDavid Howells 	const char *name;
11700d3b7a4SDavid Howells 
11808e0e7c8SDavid Howells 	/* deliver request or reply data to an call
11908e0e7c8SDavid Howells 	 * - returning an error will cause the call to be aborted
12008e0e7c8SDavid Howells 	 */
121d001648eSDavid Howells 	int (*deliver)(struct afs_call *call);
12208e0e7c8SDavid Howells 
12308e0e7c8SDavid Howells 	/* map an abort code to an error number */
12408e0e7c8SDavid Howells 	int (*abort_to_error)(u32 abort_code);
12508e0e7c8SDavid Howells 
12608e0e7c8SDavid Howells 	/* clean up a call */
12708e0e7c8SDavid Howells 	void (*destructor)(struct afs_call *call);
128341f741fSDavid Howells 
129341f741fSDavid Howells 	/* Work function */
130341f741fSDavid Howells 	void (*work)(struct work_struct *work);
13108e0e7c8SDavid Howells };
13208e0e7c8SDavid Howells 
13308e0e7c8SDavid Howells /*
134196ee9cdSDavid Howells  * Record of an outstanding read operation on a vnode.
135196ee9cdSDavid Howells  */
136196ee9cdSDavid Howells struct afs_read {
137196ee9cdSDavid Howells 	loff_t			pos;		/* Where to start reading */
138e8e581a8SDavid Howells 	loff_t			len;		/* How much we're asking for */
139196ee9cdSDavid Howells 	loff_t			actual_len;	/* How much we're actually getting */
1406a0e3999SDavid Howells 	loff_t			remain;		/* Amount remaining */
141196ee9cdSDavid Howells 	atomic_t		usage;
142196ee9cdSDavid Howells 	unsigned int		index;		/* Which page we're reading into */
143196ee9cdSDavid Howells 	unsigned int		nr_pages;
144196ee9cdSDavid Howells 	void (*page_done)(struct afs_call *, struct afs_read *);
145196ee9cdSDavid Howells 	struct page		*pages[];
146196ee9cdSDavid Howells };
147196ee9cdSDavid Howells 
148196ee9cdSDavid Howells /*
14931143d5dSDavid Howells  * record of an outstanding writeback on a vnode
15031143d5dSDavid Howells  */
15131143d5dSDavid Howells struct afs_writeback {
15231143d5dSDavid Howells 	struct list_head	link;		/* link in vnode->writebacks */
15331143d5dSDavid Howells 	struct work_struct	writer;		/* work item to perform the writeback */
15431143d5dSDavid Howells 	struct afs_vnode	*vnode;		/* vnode to which this write applies */
15531143d5dSDavid Howells 	struct key		*key;		/* owner of this write */
15631143d5dSDavid Howells 	wait_queue_head_t	waitq;		/* completion and ready wait queue */
15731143d5dSDavid Howells 	pgoff_t			first;		/* first page in batch */
15831143d5dSDavid Howells 	pgoff_t			point;		/* last page in current store op */
15931143d5dSDavid Howells 	pgoff_t			last;		/* last page in batch (inclusive) */
16031143d5dSDavid Howells 	unsigned		offset_first;	/* offset into first page of start of write */
16131143d5dSDavid Howells 	unsigned		to_last;	/* offset into last page of end of write */
16231143d5dSDavid Howells 	int			num_conflicts;	/* count of conflicting writes in list */
16331143d5dSDavid Howells 	int			usage;
16431143d5dSDavid Howells 	bool			conflicts;	/* T if has dependent conflicts */
16531143d5dSDavid Howells 	enum {
16631143d5dSDavid Howells 		AFS_WBACK_SYNCING,		/* synchronisation being performed */
16731143d5dSDavid Howells 		AFS_WBACK_PENDING,		/* write pending */
16831143d5dSDavid Howells 		AFS_WBACK_CONFLICTING,		/* conflicting writes posted */
16931143d5dSDavid Howells 		AFS_WBACK_WRITING,		/* writing back */
17031143d5dSDavid Howells 		AFS_WBACK_COMPLETE		/* the writeback record has been unlinked */
17131143d5dSDavid Howells 	} state __attribute__((packed));
17231143d5dSDavid Howells };
17331143d5dSDavid Howells 
17431143d5dSDavid Howells /*
17508e0e7c8SDavid Howells  * AFS superblock private data
17608e0e7c8SDavid Howells  * - there's one superblock per volume
17708e0e7c8SDavid Howells  */
17808e0e7c8SDavid Howells struct afs_super_info {
179f044c884SDavid Howells 	struct afs_net		*net;		/* Network namespace */
18049566f6fSDavid Howells 	struct afs_cell		*cell;		/* The cell in which the volume resides */
18108e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume record */
18208e0e7c8SDavid Howells 	char			rwparent;	/* T if parent is R/W AFS volume */
18308e0e7c8SDavid Howells };
18408e0e7c8SDavid Howells 
18508e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
18608e0e7c8SDavid Howells {
18708e0e7c8SDavid Howells 	return sb->s_fs_info;
18808e0e7c8SDavid Howells }
18908e0e7c8SDavid Howells 
19008e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
19108e0e7c8SDavid Howells 
19208e0e7c8SDavid Howells /*
193f044c884SDavid Howells  * AFS network namespace record.
194f044c884SDavid Howells  */
195f044c884SDavid Howells struct afs_net {
196f044c884SDavid Howells 	struct afs_uuid		uuid;
197f044c884SDavid Howells 	bool			live;		/* F if this namespace is being removed */
198f044c884SDavid Howells 
199f044c884SDavid Howells 	/* AF_RXRPC I/O stuff */
200f044c884SDavid Howells 	struct socket		*socket;
201f044c884SDavid Howells 	struct afs_call		*spare_incoming_call;
202f044c884SDavid Howells 	struct work_struct	charge_preallocation_work;
203f044c884SDavid Howells 	struct mutex		socket_mutex;
204f044c884SDavid Howells 	atomic_t		nr_outstanding_calls;
205f044c884SDavid Howells 	atomic_t		nr_superblocks;
206f044c884SDavid Howells 
207f044c884SDavid Howells 	/* Cell database */
208f044c884SDavid Howells 	struct list_head	cells;
209f044c884SDavid Howells 	struct afs_cell		*ws_cell;
210f044c884SDavid Howells 	rwlock_t		cells_lock;
211f044c884SDavid Howells 	struct rw_semaphore	cells_sem;
212f044c884SDavid Howells 	wait_queue_head_t	cells_freeable_wq;
213f044c884SDavid Howells 
214f044c884SDavid Howells 	struct rw_semaphore	proc_cells_sem;
215f044c884SDavid Howells 	struct list_head	proc_cells;
216f044c884SDavid Howells 
217f044c884SDavid Howells 	/* Volume location database */
218f044c884SDavid Howells 	struct list_head	vl_updates;		/* VL records in need-update order */
219f044c884SDavid Howells 	struct list_head	vl_graveyard;		/* Inactive VL records */
220f044c884SDavid Howells 	struct delayed_work	vl_reaper;
221f044c884SDavid Howells 	struct delayed_work	vl_updater;
222f044c884SDavid Howells 	spinlock_t		vl_updates_lock;
223f044c884SDavid Howells 	spinlock_t		vl_graveyard_lock;
224f044c884SDavid Howells 
225f044c884SDavid Howells 	/* File locking renewal management */
226f044c884SDavid Howells 	struct mutex		lock_manager_mutex;
227f044c884SDavid Howells 
228f044c884SDavid Howells 	/* Server database */
229f044c884SDavid Howells 	struct rb_root		servers;		/* Active servers */
230f044c884SDavid Howells 	rwlock_t		servers_lock;
231f044c884SDavid Howells 	struct list_head	server_graveyard;	/* Inactive server LRU list */
232f044c884SDavid Howells 	spinlock_t		server_graveyard_lock;
23359fa1c4aSDavid Howells 	struct timer_list	server_timer;
23459fa1c4aSDavid Howells 	struct work_struct	server_reaper;
23559fa1c4aSDavid Howells 	atomic_t		servers_outstanding;
236f044c884SDavid Howells 
237f044c884SDavid Howells 	/* Misc */
238f044c884SDavid Howells 	struct proc_dir_entry	*proc_afs;		/* /proc/net/afs directory */
239f044c884SDavid Howells };
240f044c884SDavid Howells 
241f044c884SDavid Howells extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
242f044c884SDavid Howells 
243f044c884SDavid Howells /*
24408e0e7c8SDavid Howells  * AFS cell record
24508e0e7c8SDavid Howells  */
24608e0e7c8SDavid Howells struct afs_cell {
24708e0e7c8SDavid Howells 	atomic_t		usage;
24808e0e7c8SDavid Howells 	struct list_head	link;		/* main cell list link */
249f044c884SDavid Howells 	struct afs_net		*net;		/* The network namespace */
25000d3b7a4SDavid Howells 	struct key		*anonymous_key;	/* anonymous user key for this cell */
25108e0e7c8SDavid Howells 	struct list_head	proc_link;	/* /proc cell list link */
2529b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
2539b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
2541da177e4SLinus Torvalds #endif
2551da177e4SLinus Torvalds 
25608e0e7c8SDavid Howells 	/* server record management */
25708e0e7c8SDavid Howells 	rwlock_t		servers_lock;	/* active server list lock */
25808e0e7c8SDavid Howells 	struct list_head	servers;	/* active server list */
2591da177e4SLinus Torvalds 
26008e0e7c8SDavid Howells 	/* volume location record management */
26108e0e7c8SDavid Howells 	struct rw_semaphore	vl_sem;		/* volume management serialisation semaphore */
26208e0e7c8SDavid Howells 	struct list_head	vl_list;	/* cell's active VL record list */
26308e0e7c8SDavid Howells 	spinlock_t		vl_lock;	/* vl_list lock */
26408e0e7c8SDavid Howells 	unsigned short		vl_naddrs;	/* number of VL servers in addr list */
26508e0e7c8SDavid Howells 	unsigned short		vl_curr_svix;	/* current server index */
2664d9df986SDavid Howells 	struct sockaddr_rxrpc	vl_addrs[AFS_CELL_MAX_ADDRS];	/* cell VL server addresses */
26708e0e7c8SDavid Howells 
26808e0e7c8SDavid Howells 	char			name[0];	/* cell name - must go last */
26908e0e7c8SDavid Howells };
27008e0e7c8SDavid Howells 
27108e0e7c8SDavid Howells /*
27208e0e7c8SDavid Howells  * entry in the cached volume location catalogue
27308e0e7c8SDavid Howells  */
27408e0e7c8SDavid Howells struct afs_cache_vlocation {
27500d3b7a4SDavid Howells 	/* volume name (lowercase, padded with NULs) */
27600d3b7a4SDavid Howells 	uint8_t			name[AFS_MAXVOLNAME + 1];
27700d3b7a4SDavid Howells 
27808e0e7c8SDavid Howells 	uint8_t			nservers;	/* number of entries used in servers[] */
27908e0e7c8SDavid Howells 	uint8_t			vidmask;	/* voltype mask for vid[] */
28008e0e7c8SDavid Howells 	uint8_t			srvtmask[8];	/* voltype masks for servers[] */
28108e0e7c8SDavid Howells #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
28208e0e7c8SDavid Howells #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
28308e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
28408e0e7c8SDavid Howells 
28508e0e7c8SDavid Howells 	afs_volid_t		vid[3];		/* volume IDs for R/W, R/O and Bak volumes */
2864d9df986SDavid Howells 	struct sockaddr_rxrpc	servers[8];	/* fileserver addresses */
28708e0e7c8SDavid Howells 	time_t			rtime;		/* last retrieval time */
28808e0e7c8SDavid Howells };
28908e0e7c8SDavid Howells 
29008e0e7c8SDavid Howells /*
29108e0e7c8SDavid Howells  * AFS volume location record
29208e0e7c8SDavid Howells  */
29308e0e7c8SDavid Howells struct afs_vlocation {
29408e0e7c8SDavid Howells 	atomic_t		usage;
2958a79790bSTina Ruchandani 	time64_t		time_of_death;	/* time at which put reduced usage to 0 */
29608e0e7c8SDavid Howells 	struct list_head	link;		/* link in cell volume location list */
29708e0e7c8SDavid Howells 	struct list_head	grave;		/* link in master graveyard list */
29808e0e7c8SDavid Howells 	struct list_head	update;		/* link in master update list */
29908e0e7c8SDavid Howells 	struct afs_cell		*cell;		/* cell to which volume belongs */
30008e0e7c8SDavid Howells 	struct afs_cache_vlocation vldb;	/* volume information DB record */
30108e0e7c8SDavid Howells 	struct afs_volume	*vols[3];	/* volume access record pointer (index by type) */
30208e0e7c8SDavid Howells 	wait_queue_head_t	waitq;		/* status change waitqueue */
3038a79790bSTina Ruchandani 	time64_t		update_at;	/* time at which record should be updated */
30439bf0949SDavid S. Miller 	spinlock_t		lock;		/* access lock */
30508e0e7c8SDavid Howells 	afs_vlocation_state_t	state;		/* volume location state */
30608e0e7c8SDavid Howells 	unsigned short		upd_rej_cnt;	/* ENOMEDIUM count during update */
30708e0e7c8SDavid Howells 	unsigned short		upd_busy_cnt;	/* EBUSY count during update */
30808e0e7c8SDavid Howells 	bool			valid;		/* T if valid */
30908e0e7c8SDavid Howells };
31008e0e7c8SDavid Howells 
31108e0e7c8SDavid Howells /*
31208e0e7c8SDavid Howells  * AFS fileserver record
31308e0e7c8SDavid Howells  */
31408e0e7c8SDavid Howells struct afs_server {
31508e0e7c8SDavid Howells 	atomic_t		usage;
3168a79790bSTina Ruchandani 	time64_t		time_of_death;	/* time at which put reduced usage to 0 */
3174d9df986SDavid Howells 	struct sockaddr_rxrpc	addr;		/* server address */
3189ed900b1SDavid Howells 	struct afs_net		*net;		/* Network namespace in which the server resides */
31908e0e7c8SDavid Howells 	struct afs_cell		*cell;		/* cell in which server resides */
32008e0e7c8SDavid Howells 	struct list_head	link;		/* link in cell's server list */
32108e0e7c8SDavid Howells 	struct list_head	grave;		/* link in master graveyard list */
32208e0e7c8SDavid Howells 	struct rb_node		master_rb;	/* link in master by-addr tree */
32308e0e7c8SDavid Howells 	struct rw_semaphore	sem;		/* access lock */
32408e0e7c8SDavid Howells 
32508e0e7c8SDavid Howells 	/* file service access */
32608e0e7c8SDavid Howells 	struct rb_root		fs_vnodes;	/* vnodes backed by this server (ordered by FID) */
32708e0e7c8SDavid Howells 	unsigned long		fs_act_jif;	/* time at which last activity occurred */
32808e0e7c8SDavid Howells 	unsigned long		fs_dead_jif;	/* time at which no longer to be considered dead */
32908e0e7c8SDavid Howells 	spinlock_t		fs_lock;	/* access lock */
33008e0e7c8SDavid Howells 	int			fs_state;      	/* 0 or reason FS currently marked dead (-errno) */
33108e0e7c8SDavid Howells 
33208e0e7c8SDavid Howells 	/* callback promise management */
33308e0e7c8SDavid Howells 	struct rb_root		cb_promises;	/* vnode expiration list (ordered earliest first) */
33408e0e7c8SDavid Howells 	struct delayed_work	cb_updater;	/* callback updater */
33508e0e7c8SDavid Howells 	struct delayed_work	cb_break_work;	/* collected break dispatcher */
33608e0e7c8SDavid Howells 	wait_queue_head_t	cb_break_waitq;	/* space available in cb_break waitqueue */
33708e0e7c8SDavid Howells 	spinlock_t		cb_lock;	/* access lock */
33808e0e7c8SDavid Howells 	struct afs_callback	cb_break[64];	/* ring of callbacks awaiting breaking */
33908e0e7c8SDavid Howells 	atomic_t		cb_break_n;	/* number of pending breaks */
34008e0e7c8SDavid Howells 	u8			cb_break_head;	/* head of callback breaking ring */
34108e0e7c8SDavid Howells 	u8			cb_break_tail;	/* tail of callback breaking ring */
34208e0e7c8SDavid Howells };
34308e0e7c8SDavid Howells 
34408e0e7c8SDavid Howells /*
34508e0e7c8SDavid Howells  * AFS volume access record
34608e0e7c8SDavid Howells  */
34708e0e7c8SDavid Howells struct afs_volume {
34808e0e7c8SDavid Howells 	atomic_t		usage;
34908e0e7c8SDavid Howells 	struct afs_cell		*cell;		/* cell to which belongs (unrefd ptr) */
35008e0e7c8SDavid Howells 	struct afs_vlocation	*vlocation;	/* volume location */
3519b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
3529b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
35308e0e7c8SDavid Howells #endif
35408e0e7c8SDavid Howells 	afs_volid_t		vid;		/* volume ID */
35508e0e7c8SDavid Howells 	afs_voltype_t		type;		/* type of volume */
35608e0e7c8SDavid Howells 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
35708e0e7c8SDavid Howells 	unsigned short		nservers;	/* number of server slots filled */
35808e0e7c8SDavid Howells 	unsigned short		rjservers;	/* number of servers discarded due to -ENOMEDIUM */
35908e0e7c8SDavid Howells 	struct afs_server	*servers[8];	/* servers on which volume resides (ordered) */
36008e0e7c8SDavid Howells 	struct rw_semaphore	server_sem;	/* lock for accessing current server */
36108e0e7c8SDavid Howells };
36208e0e7c8SDavid Howells 
36308e0e7c8SDavid Howells /*
36408e0e7c8SDavid Howells  * vnode catalogue entry
36508e0e7c8SDavid Howells  */
36608e0e7c8SDavid Howells struct afs_cache_vnode {
36708e0e7c8SDavid Howells 	afs_vnodeid_t		vnode_id;	/* vnode ID */
36808e0e7c8SDavid Howells 	unsigned		vnode_unique;	/* vnode ID uniquifier */
36908e0e7c8SDavid Howells 	afs_dataversion_t	data_version;	/* data version */
37008e0e7c8SDavid Howells };
37108e0e7c8SDavid Howells 
37208e0e7c8SDavid Howells /*
37308e0e7c8SDavid Howells  * AFS inode private data
37408e0e7c8SDavid Howells  */
37508e0e7c8SDavid Howells struct afs_vnode {
37608e0e7c8SDavid Howells 	struct inode		vfs_inode;	/* the VFS's inode record */
37708e0e7c8SDavid Howells 
37808e0e7c8SDavid Howells 	struct afs_volume	*volume;	/* volume on which vnode resides */
37908e0e7c8SDavid Howells 	struct afs_server	*server;	/* server currently supplying this file */
38008e0e7c8SDavid Howells 	struct afs_fid		fid;		/* the file identifier for this inode */
38108e0e7c8SDavid Howells 	struct afs_file_status	status;		/* AFS status info for this file */
3829b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
3839b3f26c9SDavid Howells 	struct fscache_cookie	*cache;		/* caching cookie */
38408e0e7c8SDavid Howells #endif
38500d3b7a4SDavid Howells 	struct afs_permits	*permits;	/* cache of permits so far obtained */
38600d3b7a4SDavid Howells 	struct mutex		permits_lock;	/* lock for altering permits list */
387260a9803SDavid Howells 	struct mutex		validate_lock;	/* lock for validating this vnode */
38808e0e7c8SDavid Howells 	wait_queue_head_t	update_waitq;	/* status fetch waitqueue */
389260a9803SDavid Howells 	int			update_cnt;	/* number of outstanding ops that will update the
39008e0e7c8SDavid Howells 						 * status */
39131143d5dSDavid Howells 	spinlock_t		writeback_lock;	/* lock for writebacks */
39208e0e7c8SDavid Howells 	spinlock_t		lock;		/* waitqueue/flags lock */
39308e0e7c8SDavid Howells 	unsigned long		flags;
39408e0e7c8SDavid Howells #define AFS_VNODE_CB_BROKEN	0		/* set if vnode's callback was broken */
395260a9803SDavid Howells #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
39608e0e7c8SDavid Howells #define AFS_VNODE_MODIFIED	2		/* set if vnode's data modified */
39708e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
39808e0e7c8SDavid Howells #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
39908e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
400e8d6c554SDavid Howells #define AFS_VNODE_LOCKING	6		/* set if waiting for lock on vnode */
401e8d6c554SDavid Howells #define AFS_VNODE_READLOCKED	7		/* set if vnode is read-locked on the server */
402e8d6c554SDavid Howells #define AFS_VNODE_WRITELOCKED	8		/* set if vnode is write-locked on the server */
403e8d6c554SDavid Howells #define AFS_VNODE_UNLOCKING	9		/* set if vnode is being unlocked on the server */
404bec5eb61Swanglei #define AFS_VNODE_AUTOCELL	10		/* set if Vnode is an auto mount point */
405bec5eb61Swanglei #define AFS_VNODE_PSEUDODIR	11		/* set if Vnode is a pseudo directory */
40608e0e7c8SDavid Howells 
40700d3b7a4SDavid Howells 	long			acl_order;	/* ACL check count (callback break count) */
40800d3b7a4SDavid Howells 
40931143d5dSDavid Howells 	struct list_head	writebacks;	/* alterations in pagecache that need writing */
410e8d6c554SDavid Howells 	struct list_head	pending_locks;	/* locks waiting to be granted */
411e8d6c554SDavid Howells 	struct list_head	granted_locks;	/* locks granted on this file */
412e8d6c554SDavid Howells 	struct delayed_work	lock_work;	/* work to be done in locking */
413e8d6c554SDavid Howells 	struct key		*unlock_key;	/* key to be used in unlocking */
41431143d5dSDavid Howells 
41508e0e7c8SDavid Howells 	/* outstanding callback notification on this file */
41608e0e7c8SDavid Howells 	struct rb_node		server_rb;	/* link in server->fs_vnodes */
41708e0e7c8SDavid Howells 	struct rb_node		cb_promise;	/* link in server->cb_promises */
41808e0e7c8SDavid Howells 	struct work_struct	cb_broken_work;	/* work to be done on callback break */
41956e71431STina Ruchandani 	time64_t		cb_expires;	/* time at which callback expires */
42056e71431STina Ruchandani 	time64_t		cb_expires_at;	/* time used to order cb_promise */
42108e0e7c8SDavid Howells 	unsigned		cb_version;	/* callback version */
42208e0e7c8SDavid Howells 	unsigned		cb_expiry;	/* callback expiry time */
42308e0e7c8SDavid Howells 	afs_callback_type_t	cb_type;	/* type of callback */
42408e0e7c8SDavid Howells 	bool			cb_promised;	/* true if promise still holds */
42508e0e7c8SDavid Howells };
42608e0e7c8SDavid Howells 
42700d3b7a4SDavid Howells /*
42800d3b7a4SDavid Howells  * cached security record for one user's attempt to access a vnode
42900d3b7a4SDavid Howells  */
43000d3b7a4SDavid Howells struct afs_permit {
43100d3b7a4SDavid Howells 	struct key		*key;		/* RxRPC ticket holding a security context */
43200d3b7a4SDavid Howells 	afs_access_t		access_mask;	/* access mask for this key */
43300d3b7a4SDavid Howells };
43400d3b7a4SDavid Howells 
43500d3b7a4SDavid Howells /*
43600d3b7a4SDavid Howells  * cache of security records from attempts to access a vnode
43700d3b7a4SDavid Howells  */
43800d3b7a4SDavid Howells struct afs_permits {
43900d3b7a4SDavid Howells 	struct rcu_head		rcu;		/* disposal procedure */
44000d3b7a4SDavid Howells 	int			count;		/* number of records */
44100d3b7a4SDavid Howells 	struct afs_permit	permits[0];	/* the permits so far examined */
44200d3b7a4SDavid Howells };
44300d3b7a4SDavid Howells 
444b908fe6bSDavid Howells /*
445b908fe6bSDavid Howells  * record of one of a system's set of network interfaces
446b908fe6bSDavid Howells  */
447b908fe6bSDavid Howells struct afs_interface {
448b908fe6bSDavid Howells 	struct in_addr	address;	/* IPv4 address bound to interface */
449b908fe6bSDavid Howells 	struct in_addr	netmask;	/* netmask applied to address */
450b908fe6bSDavid Howells 	unsigned	mtu;		/* MTU of interface */
451b908fe6bSDavid Howells };
452b908fe6bSDavid Howells 
45308e0e7c8SDavid Howells /*****************************************************************************/
45408e0e7c8SDavid Howells /*
4559b3f26c9SDavid Howells  * cache.c
4569b3f26c9SDavid Howells  */
4579b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE
4589b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs;
4599b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def;
4609b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def;
4619b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def;
4629b3f26c9SDavid Howells #else
4639b3f26c9SDavid Howells #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
4649b3f26c9SDavid Howells #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
4659b3f26c9SDavid Howells #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
4669b3f26c9SDavid Howells #endif
4679b3f26c9SDavid Howells 
4689b3f26c9SDavid Howells /*
46908e0e7c8SDavid Howells  * callback.c
47008e0e7c8SDavid Howells  */
471f044c884SDavid Howells extern struct workqueue_struct *afs_callback_update_worker;
472f044c884SDavid Howells 
47308e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
47408e0e7c8SDavid Howells extern void afs_broken_callback_work(struct work_struct *);
47508e0e7c8SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t,
47608e0e7c8SDavid Howells 				struct afs_callback[]);
477260a9803SDavid Howells extern void afs_discard_callback_on_delete(struct afs_vnode *);
47808e0e7c8SDavid Howells extern void afs_give_up_callback(struct afs_vnode *);
47908e0e7c8SDavid Howells extern void afs_dispatch_give_up_callbacks(struct work_struct *);
48008e0e7c8SDavid Howells extern void afs_flush_callback_breaks(struct afs_server *);
4811da177e4SLinus Torvalds 
4821da177e4SLinus Torvalds /*
4831da177e4SLinus Torvalds  * cell.c
4841da177e4SLinus Torvalds  */
48549566f6fSDavid Howells static inline struct afs_cell *afs_get_cell(struct afs_cell *cell)
48649566f6fSDavid Howells {
48749566f6fSDavid Howells 	if (cell)
48849566f6fSDavid Howells 		atomic_inc(&cell->usage);
48949566f6fSDavid Howells 	return cell;
49049566f6fSDavid Howells }
491f044c884SDavid Howells extern int afs_cell_init(struct afs_net *, char *);
492f044c884SDavid Howells extern struct afs_cell *afs_cell_create(struct afs_net *, const char *, unsigned, char *, bool);
493f044c884SDavid Howells extern struct afs_cell *afs_cell_lookup(struct afs_net *, const char *, unsigned, bool);
49408e0e7c8SDavid Howells extern struct afs_cell *afs_grab_cell(struct afs_cell *);
4959ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *);
496f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
49708e0e7c8SDavid Howells 
49808e0e7c8SDavid Howells /*
49908e0e7c8SDavid Howells  * cmservice.c
50008e0e7c8SDavid Howells  */
50108e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
50208e0e7c8SDavid Howells 
5031da177e4SLinus Torvalds /*
5041da177e4SLinus Torvalds  * dir.c
5051da177e4SLinus Torvalds  */
506754661f1SArjan van de Ven extern const struct inode_operations afs_dir_inode_operations;
507d61dcce2SAl Viro extern const struct dentry_operations afs_fs_dentry_operations;
5084b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
5091da177e4SLinus Torvalds 
5101da177e4SLinus Torvalds /*
5111da177e4SLinus Torvalds  * file.c
5121da177e4SLinus Torvalds  */
513f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops;
514754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
51500d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
51600d3b7a4SDavid Howells 
51700d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
51800d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
519f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *);
520196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
5211da177e4SLinus Torvalds 
5221da177e4SLinus Torvalds /*
523e8d6c554SDavid Howells  * flock.c
524e8d6c554SDavid Howells  */
525f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
526f044c884SDavid Howells 
527e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
528e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
529e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
530e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
531e8d6c554SDavid Howells 
532e8d6c554SDavid Howells /*
53308e0e7c8SDavid Howells  * fsclient.c
53408e0e7c8SDavid Howells  */
53500d3b7a4SDavid Howells extern int afs_fs_fetch_file_status(struct afs_server *, struct key *,
53600d3b7a4SDavid Howells 				    struct afs_vnode *, struct afs_volsync *,
53756ff9c83SDavid Howells 				    bool);
538f044c884SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *, bool);
53900d3b7a4SDavid Howells extern int afs_fs_fetch_data(struct afs_server *, struct key *,
54056ff9c83SDavid Howells 			     struct afs_vnode *, struct afs_read *, bool);
541260a9803SDavid Howells extern int afs_fs_create(struct afs_server *, struct key *,
542260a9803SDavid Howells 			 struct afs_vnode *, const char *, umode_t,
543260a9803SDavid Howells 			 struct afs_fid *, struct afs_file_status *,
54456ff9c83SDavid Howells 			 struct afs_callback *, bool);
545260a9803SDavid Howells extern int afs_fs_remove(struct afs_server *, struct key *,
54656ff9c83SDavid Howells 			 struct afs_vnode *, const char *, bool, bool);
547260a9803SDavid Howells extern int afs_fs_link(struct afs_server *, struct key *, struct afs_vnode *,
54856ff9c83SDavid Howells 		       struct afs_vnode *, const char *, bool);
549260a9803SDavid Howells extern int afs_fs_symlink(struct afs_server *, struct key *,
550260a9803SDavid Howells 			  struct afs_vnode *, const char *, const char *,
55156ff9c83SDavid Howells 			  struct afs_fid *, struct afs_file_status *, bool);
552260a9803SDavid Howells extern int afs_fs_rename(struct afs_server *, struct key *,
553260a9803SDavid Howells 			 struct afs_vnode *, const char *,
55456ff9c83SDavid Howells 			 struct afs_vnode *, const char *, bool);
55531143d5dSDavid Howells extern int afs_fs_store_data(struct afs_server *, struct afs_writeback *,
55656ff9c83SDavid Howells 			     pgoff_t, pgoff_t, unsigned, unsigned, bool);
55731143d5dSDavid Howells extern int afs_fs_setattr(struct afs_server *, struct key *,
55856ff9c83SDavid Howells 			  struct afs_vnode *, struct iattr *, bool);
55945222b9eSDavid Howells extern int afs_fs_get_volume_status(struct afs_server *, struct key *,
56045222b9eSDavid Howells 				    struct afs_vnode *,
56156ff9c83SDavid Howells 				    struct afs_volume_status *, bool);
562e8d6c554SDavid Howells extern int afs_fs_set_lock(struct afs_server *, struct key *,
56356ff9c83SDavid Howells 			   struct afs_vnode *, afs_lock_type_t, bool);
564e8d6c554SDavid Howells extern int afs_fs_extend_lock(struct afs_server *, struct key *,
56556ff9c83SDavid Howells 			      struct afs_vnode *, bool);
566e8d6c554SDavid Howells extern int afs_fs_release_lock(struct afs_server *, struct key *,
56756ff9c83SDavid Howells 			       struct afs_vnode *, bool);
56808e0e7c8SDavid Howells 
56908e0e7c8SDavid Howells /*
5701da177e4SLinus Torvalds  * inode.c
5711da177e4SLinus Torvalds  */
572bec5eb61Swanglei extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
573bec5eb61Swanglei 				       struct key *);
57400d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *,
575260a9803SDavid Howells 			      struct afs_fid *, struct afs_file_status *,
576260a9803SDavid Howells 			      struct afs_callback *);
577416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *);
578260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
579a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
58031143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *);
581b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
582bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds /*
5851da177e4SLinus Torvalds  * main.c
5861da177e4SLinus Torvalds  */
5870ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
588f044c884SDavid Howells 
589f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
590f044c884SDavid Howells {
591f044c884SDavid Howells 	return &__afs_net;
592f044c884SDavid Howells }
593f044c884SDavid Howells 
594f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
595f044c884SDavid Howells {
596f044c884SDavid Howells 	return &__afs_net;
597f044c884SDavid Howells }
598f044c884SDavid Howells 
599f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
600f044c884SDavid Howells {
601f044c884SDavid Howells 	return &__afs_net;
602f044c884SDavid Howells }
603f044c884SDavid Howells 
604f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
605f044c884SDavid Howells {
606f044c884SDavid Howells 	return &__afs_net;
607f044c884SDavid Howells }
608f044c884SDavid Howells 
609f044c884SDavid Howells static inline struct afs_net *afs_get_net(struct afs_net *net)
610f044c884SDavid Howells {
611f044c884SDavid Howells 	return net;
612f044c884SDavid Howells }
613f044c884SDavid Howells 
614f044c884SDavid Howells static inline void afs_put_net(struct afs_net *net)
615f044c884SDavid Howells {
616f044c884SDavid Howells }
6171da177e4SLinus Torvalds 
6181da177e4SLinus Torvalds /*
61908e0e7c8SDavid Howells  * misc.c
62008e0e7c8SDavid Howells  */
62108e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
62208e0e7c8SDavid Howells 
62308e0e7c8SDavid Howells /*
6241da177e4SLinus Torvalds  * mntpt.c
6251da177e4SLinus Torvalds  */
626754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
627bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
6284b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
6291da177e4SLinus Torvalds 
630d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
63108e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
6321da177e4SLinus Torvalds 
6331da177e4SLinus Torvalds /*
634b4db2b35SArnd Bergmann  * netdevices.c
635b4db2b35SArnd Bergmann  */
636b4db2b35SArnd Bergmann extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
637b4db2b35SArnd Bergmann 
638b4db2b35SArnd Bergmann /*
6391da177e4SLinus Torvalds  * proc.c
6401da177e4SLinus Torvalds  */
641f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
642f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
643f044c884SDavid Howells extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
644f044c884SDavid Howells extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
6451da177e4SLinus Torvalds 
64608e0e7c8SDavid Howells /*
64708e0e7c8SDavid Howells  * rxrpc.c
64808e0e7c8SDavid Howells  */
649f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
6508324f0bcSDavid Howells 
651f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
652f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
653f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
654341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
655341f741fSDavid Howells extern int afs_queue_call_work(struct afs_call *);
6564d9df986SDavid Howells extern int afs_make_call(struct sockaddr_rxrpc *, struct afs_call *, gfp_t, bool);
657f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
658f044c884SDavid Howells 					    const struct afs_call_type *,
65908e0e7c8SDavid Howells 					    size_t, size_t);
66008e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
66108e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
662b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
663d001648eSDavid Howells extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
66408e0e7c8SDavid Howells 
665d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
666372ee163SDavid Howells {
667d001648eSDavid Howells 	return afs_extract_data(call, call->buffer, call->reply_max, false);
668372ee163SDavid Howells }
669372ee163SDavid Howells 
67008e0e7c8SDavid Howells /*
67100d3b7a4SDavid Howells  * security.c
67200d3b7a4SDavid Howells  */
67300d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
67400d3b7a4SDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, long);
675416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *);
67600d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
67710556cb2SAl Viro extern int afs_permission(struct inode *, int);
67800d3b7a4SDavid Howells 
67900d3b7a4SDavid Howells /*
68008e0e7c8SDavid Howells  * server.c
68108e0e7c8SDavid Howells  */
68208e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
68308e0e7c8SDavid Howells 
684260a9803SDavid Howells #define afs_get_server(S)					\
685260a9803SDavid Howells do {								\
686260a9803SDavid Howells 	_debug("GET SERVER %d", atomic_read(&(S)->usage));	\
687260a9803SDavid Howells 	atomic_inc(&(S)->usage);				\
688260a9803SDavid Howells } while(0)
68908e0e7c8SDavid Howells 
69059fa1c4aSDavid Howells extern void afs_server_timer(struct timer_list *);
69108e0e7c8SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *,
6924d9df986SDavid Howells 					    struct sockaddr_rxrpc *);
693f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
694f044c884SDavid Howells 					  const struct sockaddr_rxrpc *);
6959ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *);
696f044c884SDavid Howells extern void afs_reap_server(struct work_struct *);
697f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
69808e0e7c8SDavid Howells 
69908e0e7c8SDavid Howells /*
70000d3b7a4SDavid Howells  * super.c
70100d3b7a4SDavid Howells  */
702f044c884SDavid Howells extern int __init afs_fs_init(void);
703f044c884SDavid Howells extern void __exit afs_fs_exit(void);
70400d3b7a4SDavid Howells 
70500d3b7a4SDavid Howells /*
70608e0e7c8SDavid Howells  * vlclient.c
70708e0e7c8SDavid Howells  */
708f044c884SDavid Howells extern int afs_vl_get_entry_by_name(struct afs_net *,
7094d9df986SDavid Howells 				    struct sockaddr_rxrpc *, struct key *,
71000d3b7a4SDavid Howells 				    const char *, struct afs_cache_vlocation *,
71156ff9c83SDavid Howells 				    bool);
712f044c884SDavid Howells extern int afs_vl_get_entry_by_id(struct afs_net *,
7134d9df986SDavid Howells 				  struct sockaddr_rxrpc *, struct key *,
71400d3b7a4SDavid Howells 				  afs_volid_t, afs_voltype_t,
71556ff9c83SDavid Howells 				  struct afs_cache_vlocation *, bool);
71608e0e7c8SDavid Howells 
71708e0e7c8SDavid Howells /*
71808e0e7c8SDavid Howells  * vlocation.c
71908e0e7c8SDavid Howells  */
720f044c884SDavid Howells extern struct workqueue_struct *afs_vlocation_update_worker;
721f044c884SDavid Howells 
72208e0e7c8SDavid Howells #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
72308e0e7c8SDavid Howells 
724f044c884SDavid Howells extern struct afs_vlocation *afs_vlocation_lookup(struct afs_net *,
725f044c884SDavid Howells 						  struct afs_cell *,
72600d3b7a4SDavid Howells 						  struct key *,
72708e0e7c8SDavid Howells 						  const char *, size_t);
728f044c884SDavid Howells extern void afs_put_vlocation(struct afs_net *, struct afs_vlocation *);
729f044c884SDavid Howells extern void afs_vlocation_updater(struct work_struct *);
730f044c884SDavid Howells extern void afs_vlocation_reaper(struct work_struct *);
731f044c884SDavid Howells extern void __net_exit afs_vlocation_purge(struct afs_net *);
73208e0e7c8SDavid Howells 
73308e0e7c8SDavid Howells /*
73408e0e7c8SDavid Howells  * vnode.c
73508e0e7c8SDavid Howells  */
73608e0e7c8SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
73708e0e7c8SDavid Howells {
73808e0e7c8SDavid Howells 	return container_of(inode, struct afs_vnode, vfs_inode);
73908e0e7c8SDavid Howells }
74008e0e7c8SDavid Howells 
74108e0e7c8SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
74208e0e7c8SDavid Howells {
74308e0e7c8SDavid Howells 	return &vnode->vfs_inode;
74408e0e7c8SDavid Howells }
74508e0e7c8SDavid Howells 
746260a9803SDavid Howells extern void afs_vnode_finalise_status_update(struct afs_vnode *,
747260a9803SDavid Howells 					     struct afs_server *);
74800d3b7a4SDavid Howells extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *,
74900d3b7a4SDavid Howells 				  struct key *);
75000d3b7a4SDavid Howells extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *,
751196ee9cdSDavid Howells 				struct afs_read *);
752260a9803SDavid Howells extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *,
753260a9803SDavid Howells 			    umode_t, struct afs_fid *, struct afs_file_status *,
754260a9803SDavid Howells 			    struct afs_callback *, struct afs_server **);
755260a9803SDavid Howells extern int afs_vnode_remove(struct afs_vnode *, struct key *, const char *,
756260a9803SDavid Howells 			    bool);
757260a9803SDavid Howells extern int afs_vnode_link(struct afs_vnode *, struct afs_vnode *, struct key *,
758260a9803SDavid Howells 			  const char *);
759260a9803SDavid Howells extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *,
760260a9803SDavid Howells 			     const char *, struct afs_fid *,
761260a9803SDavid Howells 			     struct afs_file_status *, struct afs_server **);
762260a9803SDavid Howells extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *,
763260a9803SDavid Howells 			    struct key *, const char *, const char *);
76431143d5dSDavid Howells extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t,
76531143d5dSDavid Howells 				unsigned, unsigned);
76631143d5dSDavid Howells extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *);
76745222b9eSDavid Howells extern int afs_vnode_get_volume_status(struct afs_vnode *, struct key *,
76845222b9eSDavid Howells 				       struct afs_volume_status *);
769e8d6c554SDavid Howells extern int afs_vnode_set_lock(struct afs_vnode *, struct key *,
770e8d6c554SDavid Howells 			      afs_lock_type_t);
771e8d6c554SDavid Howells extern int afs_vnode_extend_lock(struct afs_vnode *, struct key *);
772e8d6c554SDavid Howells extern int afs_vnode_release_lock(struct afs_vnode *, struct key *);
77308e0e7c8SDavid Howells 
77408e0e7c8SDavid Howells /*
77508e0e7c8SDavid Howells  * volume.c
77608e0e7c8SDavid Howells  */
77749566f6fSDavid Howells static inline struct afs_volume *afs_get_volume(struct afs_volume *volume)
77849566f6fSDavid Howells {
77949566f6fSDavid Howells 	if (volume)
78049566f6fSDavid Howells 		atomic_inc(&volume->usage);
78149566f6fSDavid Howells 	return volume;
78249566f6fSDavid Howells }
78308e0e7c8SDavid Howells 
7849ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
78500d3b7a4SDavid Howells extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *);
78608e0e7c8SDavid Howells extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *);
78708e0e7c8SDavid Howells extern int afs_volume_release_fileserver(struct afs_vnode *,
78808e0e7c8SDavid Howells 					 struct afs_server *, int);
78908e0e7c8SDavid Howells 
79031143d5dSDavid Howells /*
79131143d5dSDavid Howells  * write.c
79231143d5dSDavid Howells  */
79331143d5dSDavid Howells extern int afs_set_page_dirty(struct page *);
79431143d5dSDavid Howells extern void afs_put_writeback(struct afs_writeback *);
79515b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
79615b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned flags,
79715b4650eSNick Piggin 			struct page **pagep, void **fsdata);
79815b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
79915b4650eSNick Piggin 			loff_t pos, unsigned len, unsigned copied,
80015b4650eSNick Piggin 			struct page *page, void *fsdata);
80131143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
80231143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
80331143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
80450b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
80531143d5dSDavid Howells extern int afs_writeback_all(struct afs_vnode *);
80658fed94dSDavid Howells extern int afs_flush(struct file *, fl_owner_t);
80702c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
80831143d5dSDavid Howells 
809d3e3b7eaSDavid Howells /*
810d3e3b7eaSDavid Howells  * xattr.c
811d3e3b7eaSDavid Howells  */
812d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
813d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
81431143d5dSDavid Howells 
81508e0e7c8SDavid Howells /*****************************************************************************/
81608e0e7c8SDavid Howells /*
81708e0e7c8SDavid Howells  * debug tracing
81808e0e7c8SDavid Howells  */
8198e8d7f13SDavid Howells #include <trace/events/afs.h>
8208e8d7f13SDavid Howells 
82108e0e7c8SDavid Howells extern unsigned afs_debug;
82208e0e7c8SDavid Howells 
82308e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
824ad16df84SSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
82508e0e7c8SDavid Howells 
826530b6412SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
827530b6412SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
82808e0e7c8SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
82908e0e7c8SDavid Howells 
83008e0e7c8SDavid Howells 
83108e0e7c8SDavid Howells #if defined(__KDEBUG)
83208e0e7c8SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
83308e0e7c8SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
83408e0e7c8SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
83508e0e7c8SDavid Howells 
83608e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
83708e0e7c8SDavid Howells #define AFS_DEBUG_KENTER	0x01
83808e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE	0x02
83908e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG	0x04
84008e0e7c8SDavid Howells 
84108e0e7c8SDavid Howells #define _enter(FMT,...)					\
84208e0e7c8SDavid Howells do {							\
84308e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
84408e0e7c8SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
84508e0e7c8SDavid Howells } while (0)
84608e0e7c8SDavid Howells 
84708e0e7c8SDavid Howells #define _leave(FMT,...)					\
84808e0e7c8SDavid Howells do {							\
84908e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
85008e0e7c8SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
85108e0e7c8SDavid Howells } while (0)
85208e0e7c8SDavid Howells 
85308e0e7c8SDavid Howells #define _debug(FMT,...)					\
85408e0e7c8SDavid Howells do {							\
85508e0e7c8SDavid Howells 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
85608e0e7c8SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
85708e0e7c8SDavid Howells } while (0)
85808e0e7c8SDavid Howells 
85908e0e7c8SDavid Howells #else
86012fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
86112fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
86212fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
86308e0e7c8SDavid Howells #endif
86408e0e7c8SDavid Howells 
86508e0e7c8SDavid Howells /*
86608e0e7c8SDavid Howells  * debug assertion checking
86708e0e7c8SDavid Howells  */
86808e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
86908e0e7c8SDavid Howells 
87008e0e7c8SDavid Howells #define ASSERT(X)						\
87108e0e7c8SDavid Howells do {								\
87208e0e7c8SDavid Howells 	if (unlikely(!(X))) {					\
87308e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
87408e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
87508e0e7c8SDavid Howells 		BUG();						\
87608e0e7c8SDavid Howells 	}							\
87708e0e7c8SDavid Howells } while(0)
87808e0e7c8SDavid Howells 
87908e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)						\
88008e0e7c8SDavid Howells do {									\
88108e0e7c8SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
88208e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
88308e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
88408e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
88508e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
88608e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
88708e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
88808e0e7c8SDavid Howells 		BUG();							\
88908e0e7c8SDavid Howells 	}								\
89008e0e7c8SDavid Howells } while(0)
89108e0e7c8SDavid Howells 
892416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)					\
893416351f2SDavid Howells do {									\
894416351f2SDavid Howells 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
895416351f2SDavid Howells 		printk(KERN_ERR "\n");					\
896416351f2SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
897416351f2SDavid Howells 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
898416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
899416351f2SDavid Howells 		       (unsigned long)(H));				\
900416351f2SDavid Howells 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
901416351f2SDavid Howells 		       (unsigned long)(L), (unsigned long)(N),		\
902416351f2SDavid Howells 		       (unsigned long)(H));				\
903416351f2SDavid Howells 		BUG();							\
904416351f2SDavid Howells 	}								\
905416351f2SDavid Howells } while(0)
906416351f2SDavid Howells 
90708e0e7c8SDavid Howells #define ASSERTIF(C, X)						\
90808e0e7c8SDavid Howells do {								\
90908e0e7c8SDavid Howells 	if (unlikely((C) && !(X))) {				\
91008e0e7c8SDavid Howells 		printk(KERN_ERR "\n");				\
91108e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");	\
91208e0e7c8SDavid Howells 		BUG();						\
91308e0e7c8SDavid Howells 	}							\
91408e0e7c8SDavid Howells } while(0)
91508e0e7c8SDavid Howells 
91608e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
91708e0e7c8SDavid Howells do {									\
91808e0e7c8SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
91908e0e7c8SDavid Howells 		printk(KERN_ERR "\n");					\
92008e0e7c8SDavid Howells 		printk(KERN_ERR "AFS: Assertion failed\n");		\
92108e0e7c8SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
92208e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
92308e0e7c8SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
92408e0e7c8SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
92508e0e7c8SDavid Howells 		BUG();							\
92608e0e7c8SDavid Howells 	}								\
92708e0e7c8SDavid Howells } while(0)
92808e0e7c8SDavid Howells 
92908e0e7c8SDavid Howells #else
93008e0e7c8SDavid Howells 
93108e0e7c8SDavid Howells #define ASSERT(X)				\
93208e0e7c8SDavid Howells do {						\
93308e0e7c8SDavid Howells } while(0)
93408e0e7c8SDavid Howells 
93508e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y)			\
93608e0e7c8SDavid Howells do {						\
93708e0e7c8SDavid Howells } while(0)
93808e0e7c8SDavid Howells 
939416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H)		\
940416351f2SDavid Howells do {						\
941416351f2SDavid Howells } while(0)
942416351f2SDavid Howells 
94308e0e7c8SDavid Howells #define ASSERTIF(C, X)				\
94408e0e7c8SDavid Howells do {						\
94508e0e7c8SDavid Howells } while(0)
94608e0e7c8SDavid Howells 
94708e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
94808e0e7c8SDavid Howells do {						\
94908e0e7c8SDavid Howells } while(0)
95008e0e7c8SDavid Howells 
95108e0e7c8SDavid Howells #endif /* __KDEBUGALL */
952