xref: /openbmc/linux/fs/afs/internal.h (revision e1e38ea1)
1 /* internal AFS stuff
2  *
3  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11 
12 #include <linux/compiler.h>
13 #include <linux/kernel.h>
14 #include <linux/ktime.h>
15 #include <linux/fs.h>
16 #include <linux/pagemap.h>
17 #include <linux/rxrpc.h>
18 #include <linux/key.h>
19 #include <linux/workqueue.h>
20 #include <linux/sched.h>
21 #include <linux/fscache.h>
22 #include <linux/backing-dev.h>
23 #include <linux/uuid.h>
24 #include <linux/mm_types.h>
25 #include <net/net_namespace.h>
26 #include <net/netns/generic.h>
27 #include <net/sock.h>
28 #include <net/af_rxrpc.h>
29 
30 #include "afs.h"
31 #include "afs_vl.h"
32 
33 #define AFS_CELL_MAX_ADDRS 15
34 
35 struct pagevec;
36 struct afs_call;
37 
38 struct afs_mount_params {
39 	bool			rwpath;		/* T if the parent should be considered R/W */
40 	bool			force;		/* T to force cell type */
41 	bool			autocell;	/* T if set auto mount operation */
42 	bool			dyn_root;	/* T if dynamic root */
43 	afs_voltype_t		type;		/* type of volume requested */
44 	int			volnamesz;	/* size of volume name */
45 	const char		*volname;	/* name of volume to mount */
46 	struct net		*net_ns;	/* Network namespace in effect */
47 	struct afs_net		*net;		/* the AFS net namespace stuff */
48 	struct afs_cell		*cell;		/* cell in which to find volume */
49 	struct afs_volume	*volume;	/* volume record */
50 	struct key		*key;		/* key to use for secure mounting */
51 };
52 
53 struct afs_iget_data {
54 	struct afs_fid		fid;
55 	struct afs_volume	*volume;	/* volume on which resides */
56 };
57 
58 enum afs_call_state {
59 	AFS_CALL_CL_REQUESTING,		/* Client: Request is being sent */
60 	AFS_CALL_CL_AWAIT_REPLY,	/* Client: Awaiting reply */
61 	AFS_CALL_CL_PROC_REPLY,		/* Client: rxrpc call complete; processing reply */
62 	AFS_CALL_SV_AWAIT_OP_ID,	/* Server: Awaiting op ID */
63 	AFS_CALL_SV_AWAIT_REQUEST,	/* Server: Awaiting request data */
64 	AFS_CALL_SV_REPLYING,		/* Server: Replying */
65 	AFS_CALL_SV_AWAIT_ACK,		/* Server: Awaiting final ACK */
66 	AFS_CALL_COMPLETE,		/* Completed or failed */
67 };
68 
69 /*
70  * List of server addresses.
71  */
72 struct afs_addr_list {
73 	struct rcu_head		rcu;		/* Must be first */
74 	refcount_t		usage;
75 	u32			version;	/* Version */
76 	unsigned short		nr_addrs;
77 	unsigned short		index;		/* Address currently in use */
78 	unsigned short		nr_ipv4;	/* Number of IPv4 addresses */
79 	unsigned long		probed;		/* Mask of servers that have been probed */
80 	unsigned long		yfs;		/* Mask of servers that are YFS */
81 	struct sockaddr_rxrpc	addrs[];
82 };
83 
84 /*
85  * a record of an in-progress RxRPC call
86  */
87 struct afs_call {
88 	const struct afs_call_type *type;	/* type of call */
89 	wait_queue_head_t	waitq;		/* processes awaiting completion */
90 	struct work_struct	async_work;	/* async I/O processor */
91 	struct work_struct	work;		/* actual work processor */
92 	struct rxrpc_call	*rxcall;	/* RxRPC call handle */
93 	struct key		*key;		/* security for this call */
94 	struct afs_net		*net;		/* The network namespace */
95 	struct afs_server	*cm_server;	/* Server affected by incoming CM call */
96 	struct afs_cb_interest	*cbi;		/* Callback interest for server used */
97 	void			*request;	/* request data (first part) */
98 	struct address_space	*mapping;	/* Pages being written from */
99 	void			*buffer;	/* reply receive buffer */
100 	void			*reply[4];	/* Where to put the reply */
101 	pgoff_t			first;		/* first page in mapping to deal with */
102 	pgoff_t			last;		/* last page in mapping to deal with */
103 	size_t			offset;		/* offset into received data store */
104 	atomic_t		usage;
105 	enum afs_call_state	state;
106 	spinlock_t		state_lock;
107 	int			error;		/* error code */
108 	u32			abort_code;	/* Remote abort ID or 0 */
109 	unsigned		request_size;	/* size of request data */
110 	unsigned		reply_max;	/* maximum size of reply */
111 	unsigned		first_offset;	/* offset into mapping[first] */
112 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
113 	union {
114 		unsigned	last_to;	/* amount of mapping[last] */
115 		unsigned	count2;		/* count used in unmarshalling */
116 	};
117 	unsigned char		unmarshall;	/* unmarshalling phase */
118 	bool			incoming;	/* T if incoming call */
119 	bool			send_pages;	/* T if data from mapping should be sent */
120 	bool			need_attention;	/* T if RxRPC poked us */
121 	bool			async;		/* T if asynchronous */
122 	bool			ret_reply0;	/* T if should return reply[0] on success */
123 	bool			upgrade;	/* T to request service upgrade */
124 	u16			service_id;	/* Actual service ID (after upgrade) */
125 	unsigned int		debug_id;	/* Trace ID */
126 	u32			operation_ID;	/* operation ID for an incoming call */
127 	u32			count;		/* count for use in unmarshalling */
128 	__be32			tmp;		/* place to extract temporary data */
129 	afs_dataversion_t	expected_version; /* Updated version expected from store */
130 	afs_dataversion_t	expected_version_2; /* 2nd updated version expected from store */
131 };
132 
133 struct afs_call_type {
134 	const char *name;
135 	unsigned int op; /* Really enum afs_fs_operation */
136 
137 	/* deliver request or reply data to an call
138 	 * - returning an error will cause the call to be aborted
139 	 */
140 	int (*deliver)(struct afs_call *call);
141 
142 	/* clean up a call */
143 	void (*destructor)(struct afs_call *call);
144 
145 	/* Work function */
146 	void (*work)(struct work_struct *work);
147 };
148 
149 /*
150  * Key available for writeback on a file.
151  */
152 struct afs_wb_key {
153 	refcount_t		usage;
154 	struct key		*key;
155 	struct list_head	vnode_link;	/* Link in vnode->wb_keys */
156 };
157 
158 /*
159  * AFS open file information record.  Pointed to by file->private_data.
160  */
161 struct afs_file {
162 	struct key		*key;		/* The key this file was opened with */
163 	struct afs_wb_key	*wb;		/* Writeback key record for this file */
164 };
165 
166 static inline struct key *afs_file_key(struct file *file)
167 {
168 	struct afs_file *af = file->private_data;
169 
170 	return af->key;
171 }
172 
173 /*
174  * Record of an outstanding read operation on a vnode.
175  */
176 struct afs_read {
177 	loff_t			pos;		/* Where to start reading */
178 	loff_t			len;		/* How much we're asking for */
179 	loff_t			actual_len;	/* How much we're actually getting */
180 	loff_t			remain;		/* Amount remaining */
181 	loff_t			file_size;	/* File size returned by server */
182 	afs_dataversion_t	data_version;	/* Version number returned by server */
183 	refcount_t		usage;
184 	unsigned int		index;		/* Which page we're reading into */
185 	unsigned int		nr_pages;
186 	void (*page_done)(struct afs_call *, struct afs_read *);
187 	struct page		**pages;
188 	struct page		*array[];
189 };
190 
191 /*
192  * AFS superblock private data
193  * - there's one superblock per volume
194  */
195 struct afs_super_info {
196 	struct net		*net_ns;	/* Network namespace */
197 	struct afs_cell		*cell;		/* The cell in which the volume resides */
198 	struct afs_volume	*volume;	/* volume record */
199 	bool			dyn_root;	/* True if dynamic root */
200 };
201 
202 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
203 {
204 	return sb->s_fs_info;
205 }
206 
207 extern struct file_system_type afs_fs_type;
208 
209 /*
210  * Set of substitutes for @sys.
211  */
212 struct afs_sysnames {
213 #define AFS_NR_SYSNAME 16
214 	char			*subs[AFS_NR_SYSNAME];
215 	refcount_t		usage;
216 	unsigned short		nr;
217 	char			blank[1];
218 };
219 
220 /*
221  * AFS network namespace record.
222  */
223 struct afs_net {
224 	struct net		*net;		/* Backpointer to the owning net namespace */
225 	struct afs_uuid		uuid;
226 	bool			live;		/* F if this namespace is being removed */
227 
228 	/* AF_RXRPC I/O stuff */
229 	struct socket		*socket;
230 	struct afs_call		*spare_incoming_call;
231 	struct work_struct	charge_preallocation_work;
232 	struct mutex		socket_mutex;
233 	atomic_t		nr_outstanding_calls;
234 	atomic_t		nr_superblocks;
235 
236 	/* Cell database */
237 	struct rb_root		cells;
238 	struct afs_cell __rcu	*ws_cell;
239 	struct work_struct	cells_manager;
240 	struct timer_list	cells_timer;
241 	atomic_t		cells_outstanding;
242 	seqlock_t		cells_lock;
243 
244 	struct mutex		proc_cells_lock;
245 	struct list_head	proc_cells;
246 
247 	/* Known servers.  Theoretically each fileserver can only be in one
248 	 * cell, but in practice, people create aliases and subsets and there's
249 	 * no easy way to distinguish them.
250 	 */
251 	seqlock_t		fs_lock;	/* For fs_servers */
252 	struct rb_root		fs_servers;	/* afs_server (by server UUID or address) */
253 	struct list_head	fs_updates;	/* afs_server (by update_at) */
254 	struct hlist_head	fs_proc;	/* procfs servers list */
255 
256 	struct hlist_head	fs_addresses4;	/* afs_server (by lowest IPv4 addr) */
257 	struct hlist_head	fs_addresses6;	/* afs_server (by lowest IPv6 addr) */
258 	seqlock_t		fs_addr_lock;	/* For fs_addresses[46] */
259 
260 	struct work_struct	fs_manager;
261 	struct timer_list	fs_timer;
262 	atomic_t		servers_outstanding;
263 
264 	/* File locking renewal management */
265 	struct mutex		lock_manager_mutex;
266 
267 	/* Misc */
268 	struct super_block	*dynroot_sb;	/* Dynamic root mount superblock */
269 	struct proc_dir_entry	*proc_afs;	/* /proc/net/afs directory */
270 	struct afs_sysnames	*sysnames;
271 	rwlock_t		sysnames_lock;
272 
273 	/* Statistics counters */
274 	atomic_t		n_lookup;	/* Number of lookups done */
275 	atomic_t		n_reval;	/* Number of dentries needing revalidation */
276 	atomic_t		n_inval;	/* Number of invalidations by the server */
277 	atomic_t		n_relpg;	/* Number of invalidations by releasepage */
278 	atomic_t		n_read_dir;	/* Number of directory pages read */
279 	atomic_t		n_dir_cr;	/* Number of directory entry creation edits */
280 	atomic_t		n_dir_rm;	/* Number of directory entry removal edits */
281 	atomic_t		n_stores;	/* Number of store ops */
282 	atomic_long_t		n_store_bytes;	/* Number of bytes stored */
283 	atomic_long_t		n_fetch_bytes;	/* Number of bytes fetched */
284 	atomic_t		n_fetches;	/* Number of data fetch ops */
285 };
286 
287 extern const char afs_init_sysname[];
288 
289 enum afs_cell_state {
290 	AFS_CELL_UNSET,
291 	AFS_CELL_ACTIVATING,
292 	AFS_CELL_ACTIVE,
293 	AFS_CELL_DEACTIVATING,
294 	AFS_CELL_INACTIVE,
295 	AFS_CELL_FAILED,
296 };
297 
298 /*
299  * AFS cell record.
300  *
301  * This is a tricky concept to get right as it is possible to create aliases
302  * simply by pointing AFSDB/SRV records for two names at the same set of VL
303  * servers; it is also possible to do things like setting up two sets of VL
304  * servers, one of which provides a superset of the volumes provided by the
305  * other (for internal/external division, for example).
306  *
307  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
308  * servers and (b) a cell's name is used by the client to select the key to use
309  * for authentication and encryption.  The cell name is not typically used in
310  * the protocol.
311  *
312  * There is no easy way to determine if two cells are aliases or one is a
313  * subset of another.
314  */
315 struct afs_cell {
316 	union {
317 		struct rcu_head	rcu;
318 		struct rb_node	net_node;	/* Node in net->cells */
319 	};
320 	struct afs_net		*net;
321 	struct key		*anonymous_key;	/* anonymous user key for this cell */
322 	struct work_struct	manager;	/* Manager for init/deinit/dns */
323 	struct list_head	proc_link;	/* /proc cell list link */
324 #ifdef CONFIG_AFS_FSCACHE
325 	struct fscache_cookie	*cache;		/* caching cookie */
326 #endif
327 	time64_t		dns_expiry;	/* Time AFSDB/SRV record expires */
328 	time64_t		last_inactive;	/* Time of last drop of usage count */
329 	atomic_t		usage;
330 	unsigned long		flags;
331 #define AFS_CELL_FL_NOT_READY	0		/* The cell record is not ready for use */
332 #define AFS_CELL_FL_NO_GC	1		/* The cell was added manually, don't auto-gc */
333 #define AFS_CELL_FL_NOT_FOUND	2		/* Permanent DNS error */
334 #define AFS_CELL_FL_DNS_FAIL	3		/* Failed to access DNS */
335 #define AFS_CELL_FL_NO_LOOKUP_YET 4		/* Not completed first DNS lookup yet */
336 	enum afs_cell_state	state;
337 	short			error;
338 
339 	/* Active fileserver interaction state. */
340 	struct list_head	proc_volumes;	/* procfs volume list */
341 	rwlock_t		proc_lock;
342 
343 	/* VL server list. */
344 	rwlock_t		vl_addrs_lock;	/* Lock on vl_addrs */
345 	struct afs_addr_list	__rcu *vl_addrs; /* List of VL servers */
346 	u8			name_len;	/* Length of name */
347 	char			name[64 + 1];	/* Cell name, case-flattened and NUL-padded */
348 };
349 
350 /*
351  * Cached VLDB entry.
352  *
353  * This is pointed to by cell->vldb_entries, indexed by name.
354  */
355 struct afs_vldb_entry {
356 	afs_volid_t		vid[3];		/* Volume IDs for R/W, R/O and Bak volumes */
357 
358 	unsigned long		flags;
359 #define AFS_VLDB_HAS_RW		0		/* - R/W volume exists */
360 #define AFS_VLDB_HAS_RO		1		/* - R/O volume exists */
361 #define AFS_VLDB_HAS_BAK	2		/* - Backup volume exists */
362 #define AFS_VLDB_QUERY_VALID	3		/* - Record is valid */
363 #define AFS_VLDB_QUERY_ERROR	4		/* - VL server returned error */
364 
365 	uuid_t			fs_server[AFS_NMAXNSERVERS];
366 	u8			fs_mask[AFS_NMAXNSERVERS];
367 #define AFS_VOL_VTM_RW	0x01 /* R/W version of the volume is available (on this server) */
368 #define AFS_VOL_VTM_RO	0x02 /* R/O version of the volume is available (on this server) */
369 #define AFS_VOL_VTM_BAK	0x04 /* backup version of the volume is available (on this server) */
370 	short			error;
371 	u8			nr_servers;	/* Number of server records */
372 	u8			name_len;
373 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
374 };
375 
376 /*
377  * Record of fileserver with which we're actively communicating.
378  */
379 struct afs_server {
380 	struct rcu_head		rcu;
381 	union {
382 		uuid_t		uuid;		/* Server ID */
383 		struct afs_uuid	_uuid;
384 	};
385 
386 	struct afs_addr_list	__rcu *addresses;
387 	struct rb_node		uuid_rb;	/* Link in net->servers */
388 	struct hlist_node	addr4_link;	/* Link in net->fs_addresses4 */
389 	struct hlist_node	addr6_link;	/* Link in net->fs_addresses6 */
390 	struct hlist_node	proc_link;	/* Link in net->fs_proc */
391 	struct afs_server	*gc_next;	/* Next server in manager's list */
392 	time64_t		put_time;	/* Time at which last put */
393 	time64_t		update_at;	/* Time at which to next update the record */
394 	unsigned long		flags;
395 #define AFS_SERVER_FL_NEW	0		/* New server, don't inc cb_s_break */
396 #define AFS_SERVER_FL_NOT_READY	1		/* The record is not ready for use */
397 #define AFS_SERVER_FL_NOT_FOUND	2		/* VL server says no such server */
398 #define AFS_SERVER_FL_VL_FAIL	3		/* Failed to access VL server */
399 #define AFS_SERVER_FL_UPDATING	4
400 #define AFS_SERVER_FL_PROBED	5		/* The fileserver has been probed */
401 #define AFS_SERVER_FL_PROBING	6		/* Fileserver is being probed */
402 #define AFS_SERVER_FL_NO_IBULK	7		/* Fileserver doesn't support FS.InlineBulkStatus */
403 #define AFS_SERVER_FL_MAY_HAVE_CB 8		/* May have callbacks on this fileserver */
404 	atomic_t		usage;
405 	u32			addr_version;	/* Address list version */
406 
407 	/* file service access */
408 	rwlock_t		fs_lock;	/* access lock */
409 
410 	/* callback promise management */
411 	struct hlist_head	cb_volumes;	/* List of volume interests on this server */
412 	unsigned		cb_s_break;	/* Break-everything counter. */
413 	rwlock_t		cb_break_lock;	/* Volume finding lock */
414 };
415 
416 /*
417  * Volume collation in the server's callback interest list.
418  */
419 struct afs_vol_interest {
420 	struct hlist_node	srv_link;	/* Link in server->cb_volumes */
421 	struct hlist_head	cb_interests;	/* List of callback interests on the server */
422 	afs_volid_t		vid;		/* Volume ID to match */
423 	unsigned int		usage;
424 };
425 
426 /*
427  * Interest by a superblock on a server.
428  */
429 struct afs_cb_interest {
430 	struct hlist_node	cb_vlink;	/* Link in vol_interest->cb_interests */
431 	struct afs_vol_interest	*vol_interest;
432 	struct afs_server	*server;	/* Server on which this interest resides */
433 	struct super_block	*sb;		/* Superblock on which inodes reside */
434 	afs_volid_t		vid;		/* Volume ID to match */
435 	refcount_t		usage;
436 };
437 
438 /*
439  * Replaceable server list.
440  */
441 struct afs_server_entry {
442 	struct afs_server	*server;
443 	struct afs_cb_interest	*cb_interest;
444 };
445 
446 struct afs_server_list {
447 	refcount_t		usage;
448 	unsigned short		nr_servers;
449 	unsigned short		index;		/* Server currently in use */
450 	unsigned short		vnovol_mask;	/* Servers to be skipped due to VNOVOL */
451 	unsigned int		seq;		/* Set to ->servers_seq when installed */
452 	rwlock_t		lock;
453 	struct afs_server_entry	servers[];
454 };
455 
456 /*
457  * Live AFS volume management.
458  */
459 struct afs_volume {
460 	afs_volid_t		vid;		/* volume ID */
461 	atomic_t		usage;
462 	time64_t		update_at;	/* Time at which to next update */
463 	struct afs_cell		*cell;		/* Cell to which belongs (pins ref) */
464 	struct list_head	proc_link;	/* Link in cell->vl_proc */
465 	unsigned long		flags;
466 #define AFS_VOLUME_NEEDS_UPDATE	0	/* - T if an update needs performing */
467 #define AFS_VOLUME_UPDATING	1	/* - T if an update is in progress */
468 #define AFS_VOLUME_WAIT		2	/* - T if users must wait for update */
469 #define AFS_VOLUME_DELETED	3	/* - T if volume appears deleted */
470 #define AFS_VOLUME_OFFLINE	4	/* - T if volume offline notice given */
471 #define AFS_VOLUME_BUSY		5	/* - T if volume busy notice given */
472 #ifdef CONFIG_AFS_FSCACHE
473 	struct fscache_cookie	*cache;		/* caching cookie */
474 #endif
475 	struct afs_server_list	*servers;	/* List of servers on which volume resides */
476 	rwlock_t		servers_lock;	/* Lock for ->servers */
477 	unsigned int		servers_seq;	/* Incremented each time ->servers changes */
478 
479 	unsigned		cb_v_break;	/* Break-everything counter. */
480 	rwlock_t		cb_break_lock;
481 
482 	afs_voltype_t		type;		/* type of volume */
483 	short			error;
484 	char			type_force;	/* force volume type (suppress R/O -> R/W) */
485 	u8			name_len;
486 	u8			name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
487 };
488 
489 enum afs_lock_state {
490 	AFS_VNODE_LOCK_NONE,		/* The vnode has no lock on the server */
491 	AFS_VNODE_LOCK_WAITING_FOR_CB,	/* We're waiting for the server to break the callback */
492 	AFS_VNODE_LOCK_SETTING,		/* We're asking the server for a lock */
493 	AFS_VNODE_LOCK_GRANTED,		/* We have a lock on the server */
494 	AFS_VNODE_LOCK_EXTENDING,	/* We're extending a lock on the server */
495 	AFS_VNODE_LOCK_NEED_UNLOCK,	/* We need to unlock on the server */
496 	AFS_VNODE_LOCK_UNLOCKING,	/* We're telling the server to unlock */
497 };
498 
499 /*
500  * AFS inode private data.
501  *
502  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
503  * leak from one inode to another.
504  */
505 struct afs_vnode {
506 	struct inode		vfs_inode;	/* the VFS's inode record */
507 
508 	struct afs_volume	*volume;	/* volume on which vnode resides */
509 	struct afs_fid		fid;		/* the file identifier for this inode */
510 	struct afs_file_status	status;		/* AFS status info for this file */
511 	afs_dataversion_t	invalid_before;	/* Child dentries are invalid before this */
512 #ifdef CONFIG_AFS_FSCACHE
513 	struct fscache_cookie	*cache;		/* caching cookie */
514 #endif
515 	struct afs_permits __rcu *permit_cache;	/* cache of permits so far obtained */
516 	struct mutex		io_lock;	/* Lock for serialising I/O on this mutex */
517 	struct rw_semaphore	validate_lock;	/* lock for validating this vnode */
518 	spinlock_t		wb_lock;	/* lock for wb_keys */
519 	spinlock_t		lock;		/* waitqueue/flags lock */
520 	unsigned long		flags;
521 #define AFS_VNODE_CB_PROMISED	0		/* Set if vnode has a callback promise */
522 #define AFS_VNODE_UNSET		1		/* set if vnode attributes not yet set */
523 #define AFS_VNODE_DIR_VALID	2		/* Set if dir contents are valid */
524 #define AFS_VNODE_ZAP_DATA	3		/* set if vnode's data should be invalidated */
525 #define AFS_VNODE_DELETED	4		/* set if vnode deleted on server */
526 #define AFS_VNODE_MOUNTPOINT	5		/* set if vnode is a mountpoint symlink */
527 #define AFS_VNODE_AUTOCELL	6		/* set if Vnode is an auto mount point */
528 #define AFS_VNODE_PSEUDODIR	7 		/* set if Vnode is a pseudo directory */
529 #define AFS_VNODE_NEW_CONTENT	8		/* Set if file has new content (create/trunc-0) */
530 
531 	struct list_head	wb_keys;	/* List of keys available for writeback */
532 	struct list_head	pending_locks;	/* locks waiting to be granted */
533 	struct list_head	granted_locks;	/* locks granted on this file */
534 	struct delayed_work	lock_work;	/* work to be done in locking */
535 	struct key		*lock_key;	/* Key to be used in lock ops */
536 	enum afs_lock_state	lock_state : 8;
537 	afs_lock_type_t		lock_type : 8;
538 
539 	/* outstanding callback notification on this file */
540 	struct afs_cb_interest	*cb_interest;	/* Server on which this resides */
541 	unsigned int		cb_s_break;	/* Mass break counter on ->server */
542 	unsigned int		cb_v_break;	/* Mass break counter on ->volume */
543 	unsigned int		cb_break;	/* Break counter on vnode */
544 	seqlock_t		cb_lock;	/* Lock for ->cb_interest, ->status, ->cb_*break */
545 
546 	time64_t		cb_expires_at;	/* time at which callback expires */
547 	unsigned		cb_version;	/* callback version */
548 	afs_callback_type_t	cb_type;	/* type of callback */
549 };
550 
551 /*
552  * cached security record for one user's attempt to access a vnode
553  */
554 struct afs_permit {
555 	struct key		*key;		/* RxRPC ticket holding a security context */
556 	afs_access_t		access;		/* CallerAccess value for this key */
557 };
558 
559 /*
560  * Immutable cache of CallerAccess records from attempts to access vnodes.
561  * These may be shared between multiple vnodes.
562  */
563 struct afs_permits {
564 	struct rcu_head		rcu;
565 	struct hlist_node	hash_node;	/* Link in hash */
566 	unsigned long		h;		/* Hash value for this permit list */
567 	refcount_t		usage;
568 	unsigned short		nr_permits;	/* Number of records */
569 	bool			invalidated;	/* Invalidated due to key change */
570 	struct afs_permit	permits[];	/* List of permits sorted by key pointer */
571 };
572 
573 /*
574  * record of one of a system's set of network interfaces
575  */
576 struct afs_interface {
577 	struct in_addr	address;	/* IPv4 address bound to interface */
578 	struct in_addr	netmask;	/* netmask applied to address */
579 	unsigned	mtu;		/* MTU of interface */
580 };
581 
582 /*
583  * Cursor for iterating over a server's address list.
584  */
585 struct afs_addr_cursor {
586 	struct afs_addr_list	*alist;		/* Current address list (pins ref) */
587 	struct sockaddr_rxrpc	*addr;
588 	u32			abort_code;
589 	unsigned short		start;		/* Starting point in alist->addrs[] */
590 	unsigned short		index;		/* Wrapping offset from start to current addr */
591 	short			error;
592 	bool			begun;		/* T if we've begun iteration */
593 	bool			responded;	/* T if the current address responded */
594 };
595 
596 /*
597  * Cursor for iterating over a set of fileservers.
598  */
599 struct afs_fs_cursor {
600 	struct afs_addr_cursor	ac;
601 	struct afs_vnode	*vnode;
602 	struct afs_server_list	*server_list;	/* Current server list (pins ref) */
603 	struct afs_cb_interest	*cbi;		/* Server on which this resides (pins ref) */
604 	struct key		*key;		/* Key for the server */
605 	unsigned int		cb_break;	/* cb_break + cb_s_break before the call */
606 	unsigned int		cb_break_2;	/* cb_break + cb_s_break (2nd vnode) */
607 	unsigned char		start;		/* Initial index in server list */
608 	unsigned char		index;		/* Number of servers tried beyond start */
609 	unsigned short		flags;
610 #define AFS_FS_CURSOR_STOP	0x0001		/* Set to cease iteration */
611 #define AFS_FS_CURSOR_VBUSY	0x0002		/* Set if seen VBUSY */
612 #define AFS_FS_CURSOR_VMOVED	0x0004		/* Set if seen VMOVED */
613 #define AFS_FS_CURSOR_VNOVOL	0x0008		/* Set if seen VNOVOL */
614 #define AFS_FS_CURSOR_CUR_ONLY	0x0010		/* Set if current server only (file lock held) */
615 #define AFS_FS_CURSOR_NO_VSLEEP	0x0020		/* Set to prevent sleep on VBUSY, VOFFLINE, ... */
616 };
617 
618 /*
619  * Cache auxiliary data.
620  */
621 struct afs_vnode_cache_aux {
622 	u64			data_version;
623 } __packed;
624 
625 #include <trace/events/afs.h>
626 
627 /*****************************************************************************/
628 /*
629  * addr_list.c
630  */
631 static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
632 {
633 	if (alist)
634 		refcount_inc(&alist->usage);
635 	return alist;
636 }
637 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
638 						unsigned short,
639 						unsigned short);
640 extern void afs_put_addrlist(struct afs_addr_list *);
641 extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
642 						  unsigned short, unsigned short);
643 extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
644 extern bool afs_iterate_addresses(struct afs_addr_cursor *);
645 extern int afs_end_cursor(struct afs_addr_cursor *);
646 extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
647 
648 extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
649 extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
650 
651 /*
652  * cache.c
653  */
654 #ifdef CONFIG_AFS_FSCACHE
655 extern struct fscache_netfs afs_cache_netfs;
656 extern struct fscache_cookie_def afs_cell_cache_index_def;
657 extern struct fscache_cookie_def afs_volume_cache_index_def;
658 extern struct fscache_cookie_def afs_vnode_cache_index_def;
659 #else
660 #define afs_cell_cache_index_def	(*(struct fscache_cookie_def *) NULL)
661 #define afs_volume_cache_index_def	(*(struct fscache_cookie_def *) NULL)
662 #define afs_vnode_cache_index_def	(*(struct fscache_cookie_def *) NULL)
663 #endif
664 
665 /*
666  * callback.c
667  */
668 extern void afs_init_callback_state(struct afs_server *);
669 extern void afs_break_callback(struct afs_vnode *);
670 extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
671 
672 extern int afs_register_server_cb_interest(struct afs_vnode *,
673 					   struct afs_server_list *, unsigned int);
674 extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
675 extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
676 
677 static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
678 {
679 	if (cbi)
680 		refcount_inc(&cbi->usage);
681 	return cbi;
682 }
683 
684 static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
685 {
686 	return vnode->cb_break + vnode->cb_s_break + vnode->cb_v_break;
687 }
688 
689 static inline unsigned int afs_cb_break_sum(struct afs_vnode *vnode,
690 					    struct afs_cb_interest *cbi)
691 {
692 	return vnode->cb_break + cbi->server->cb_s_break + vnode->volume->cb_v_break;
693 }
694 
695 /*
696  * cell.c
697  */
698 extern int afs_cell_init(struct afs_net *, const char *);
699 extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
700 extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
701 					const char *, bool);
702 extern struct afs_cell *afs_get_cell(struct afs_cell *);
703 extern void afs_put_cell(struct afs_net *, struct afs_cell *);
704 extern void afs_manage_cells(struct work_struct *);
705 extern void afs_cells_timer(struct timer_list *);
706 extern void __net_exit afs_cell_purge(struct afs_net *);
707 
708 /*
709  * cmservice.c
710  */
711 extern bool afs_cm_incoming_call(struct afs_call *);
712 
713 /*
714  * dir.c
715  */
716 extern const struct file_operations afs_dir_file_operations;
717 extern const struct inode_operations afs_dir_inode_operations;
718 extern const struct address_space_operations afs_dir_aops;
719 extern const struct dentry_operations afs_fs_dentry_operations;
720 
721 extern void afs_d_release(struct dentry *);
722 
723 /*
724  * dir_edit.c
725  */
726 extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
727 			     enum afs_edit_dir_reason);
728 extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
729 
730 /*
731  * dynroot.c
732  */
733 extern const struct file_operations afs_dynroot_file_operations;
734 extern const struct inode_operations afs_dynroot_inode_operations;
735 extern const struct dentry_operations afs_dynroot_dentry_operations;
736 
737 extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
738 extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
739 extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
740 extern int afs_dynroot_populate(struct super_block *);
741 extern void afs_dynroot_depopulate(struct super_block *);
742 
743 /*
744  * file.c
745  */
746 extern const struct address_space_operations afs_fs_aops;
747 extern const struct inode_operations afs_file_inode_operations;
748 extern const struct file_operations afs_file_operations;
749 
750 extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
751 extern void afs_put_wb_key(struct afs_wb_key *);
752 extern int afs_open(struct inode *, struct file *);
753 extern int afs_release(struct inode *, struct file *);
754 extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
755 extern int afs_page_filler(void *, struct page *);
756 extern void afs_put_read(struct afs_read *);
757 
758 /*
759  * flock.c
760  */
761 extern struct workqueue_struct *afs_lock_manager;
762 
763 extern void afs_lock_work(struct work_struct *);
764 extern void afs_lock_may_be_available(struct afs_vnode *);
765 extern int afs_lock(struct file *, int, struct file_lock *);
766 extern int afs_flock(struct file *, int, struct file_lock *);
767 
768 /*
769  * fsclient.c
770  */
771 #define AFS_VNODE_NOT_YET_SET	0x01
772 #define AFS_VNODE_META_CHANGED	0x02
773 #define AFS_VNODE_DATA_CHANGED	0x04
774 extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *,
775 					 const afs_dataversion_t *, u8);
776 
777 extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
778 extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
779 extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
780 extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, u64,
781 			 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
782 extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool, u64);
783 extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
784 extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
785 			  struct afs_fid *, struct afs_file_status *);
786 extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
787 			 struct afs_vnode *, const char *, u64, u64);
788 extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
789 			     pgoff_t, pgoff_t, unsigned, unsigned);
790 extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
791 extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
792 extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
793 extern int afs_fs_extend_lock(struct afs_fs_cursor *);
794 extern int afs_fs_release_lock(struct afs_fs_cursor *);
795 extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
796 					struct afs_addr_cursor *, struct key *);
797 extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
798 				   struct afs_addr_cursor *, struct key *);
799 extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
800 				     struct afs_fid *, struct afs_file_status *,
801 				     struct afs_callback *, unsigned int,
802 				     struct afs_volsync *);
803 extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
804 			       struct afs_fid *, struct afs_file_status *,
805 			       struct afs_callback *, struct afs_volsync *);
806 
807 /*
808  * inode.c
809  */
810 extern int afs_fetch_status(struct afs_vnode *, struct key *, bool);
811 extern int afs_iget5_test(struct inode *, void *);
812 extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
813 extern struct inode *afs_iget(struct super_block *, struct key *,
814 			      struct afs_fid *, struct afs_file_status *,
815 			      struct afs_callback *,
816 			      struct afs_cb_interest *);
817 extern void afs_zap_data(struct afs_vnode *);
818 extern int afs_validate(struct afs_vnode *, struct key *);
819 extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
820 extern int afs_setattr(struct dentry *, struct iattr *);
821 extern void afs_evict_inode(struct inode *);
822 extern int afs_drop_inode(struct inode *);
823 
824 /*
825  * main.c
826  */
827 extern struct workqueue_struct *afs_wq;
828 extern int afs_net_id;
829 
830 static inline struct afs_net *afs_net(struct net *net)
831 {
832 	return net_generic(net, afs_net_id);
833 }
834 
835 static inline struct afs_net *afs_sb2net(struct super_block *sb)
836 {
837 	return afs_net(AFS_FS_S(sb)->net_ns);
838 }
839 
840 static inline struct afs_net *afs_d2net(struct dentry *dentry)
841 {
842 	return afs_sb2net(dentry->d_sb);
843 }
844 
845 static inline struct afs_net *afs_i2net(struct inode *inode)
846 {
847 	return afs_sb2net(inode->i_sb);
848 }
849 
850 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
851 {
852 	return afs_i2net(&vnode->vfs_inode);
853 }
854 
855 static inline struct afs_net *afs_sock2net(struct sock *sk)
856 {
857 	return net_generic(sock_net(sk), afs_net_id);
858 }
859 
860 static inline void __afs_stat(atomic_t *s)
861 {
862 	atomic_inc(s);
863 }
864 
865 #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
866 
867 /*
868  * misc.c
869  */
870 extern int afs_abort_to_error(u32);
871 
872 /*
873  * mntpt.c
874  */
875 extern const struct inode_operations afs_mntpt_inode_operations;
876 extern const struct inode_operations afs_autocell_inode_operations;
877 extern const struct file_operations afs_mntpt_file_operations;
878 
879 extern struct vfsmount *afs_d_automount(struct path *);
880 extern void afs_mntpt_kill_timer(void);
881 
882 /*
883  * netdevices.c
884  */
885 extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *,
886 				   size_t, bool);
887 
888 /*
889  * proc.c
890  */
891 #ifdef CONFIG_PROC_FS
892 extern int __net_init afs_proc_init(struct afs_net *);
893 extern void __net_exit afs_proc_cleanup(struct afs_net *);
894 extern int afs_proc_cell_setup(struct afs_cell *);
895 extern void afs_proc_cell_remove(struct afs_cell *);
896 extern void afs_put_sysnames(struct afs_sysnames *);
897 #else
898 static inline int afs_proc_init(struct afs_net *net) { return 0; }
899 static inline void afs_proc_cleanup(struct afs_net *net) {}
900 static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
901 static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
902 static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
903 #endif
904 
905 /*
906  * rotate.c
907  */
908 extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
909 				      struct key *);
910 extern bool afs_select_fileserver(struct afs_fs_cursor *);
911 extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
912 extern int afs_end_vnode_operation(struct afs_fs_cursor *);
913 
914 /*
915  * rxrpc.c
916  */
917 extern struct workqueue_struct *afs_async_calls;
918 
919 extern int __net_init afs_open_socket(struct afs_net *);
920 extern void __net_exit afs_close_socket(struct afs_net *);
921 extern void afs_charge_preallocation(struct work_struct *);
922 extern void afs_put_call(struct afs_call *);
923 extern int afs_queue_call_work(struct afs_call *);
924 extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
925 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
926 					    const struct afs_call_type *,
927 					    size_t, size_t);
928 extern void afs_flat_call_destructor(struct afs_call *);
929 extern void afs_send_empty_reply(struct afs_call *);
930 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
931 extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
932 extern int afs_protocol_error(struct afs_call *, int);
933 
934 static inline int afs_transfer_reply(struct afs_call *call)
935 {
936 	return afs_extract_data(call, call->buffer, call->reply_max, false);
937 }
938 
939 static inline bool afs_check_call_state(struct afs_call *call,
940 					enum afs_call_state state)
941 {
942 	return READ_ONCE(call->state) == state;
943 }
944 
945 static inline bool afs_set_call_state(struct afs_call *call,
946 				      enum afs_call_state from,
947 				      enum afs_call_state to)
948 {
949 	bool ok = false;
950 
951 	spin_lock_bh(&call->state_lock);
952 	if (call->state == from) {
953 		call->state = to;
954 		trace_afs_call_state(call, from, to, 0, 0);
955 		ok = true;
956 	}
957 	spin_unlock_bh(&call->state_lock);
958 	return ok;
959 }
960 
961 static inline void afs_set_call_complete(struct afs_call *call,
962 					 int error, u32 remote_abort)
963 {
964 	enum afs_call_state state;
965 	bool ok = false;
966 
967 	spin_lock_bh(&call->state_lock);
968 	state = call->state;
969 	if (state != AFS_CALL_COMPLETE) {
970 		call->abort_code = remote_abort;
971 		call->error = error;
972 		call->state = AFS_CALL_COMPLETE;
973 		trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
974 				     error, remote_abort);
975 		ok = true;
976 	}
977 	spin_unlock_bh(&call->state_lock);
978 	if (ok)
979 		trace_afs_call_done(call);
980 }
981 
982 /*
983  * security.c
984  */
985 extern void afs_put_permits(struct afs_permits *);
986 extern void afs_clear_permits(struct afs_vnode *);
987 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
988 extern void afs_zap_permits(struct rcu_head *);
989 extern struct key *afs_request_key(struct afs_cell *);
990 extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
991 extern int afs_permission(struct inode *, int);
992 extern void __exit afs_clean_up_permit_cache(void);
993 
994 /*
995  * server.c
996  */
997 extern spinlock_t afs_server_peer_lock;
998 
999 static inline struct afs_server *afs_get_server(struct afs_server *server)
1000 {
1001 	atomic_inc(&server->usage);
1002 	return server;
1003 }
1004 
1005 extern struct afs_server *afs_find_server(struct afs_net *,
1006 					  const struct sockaddr_rxrpc *);
1007 extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
1008 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
1009 extern void afs_put_server(struct afs_net *, struct afs_server *);
1010 extern void afs_manage_servers(struct work_struct *);
1011 extern void afs_servers_timer(struct timer_list *);
1012 extern void __net_exit afs_purge_servers(struct afs_net *);
1013 extern bool afs_probe_fileserver(struct afs_fs_cursor *);
1014 extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
1015 
1016 /*
1017  * server_list.c
1018  */
1019 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1020 {
1021 	refcount_inc(&slist->usage);
1022 	return slist;
1023 }
1024 
1025 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1026 extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1027 						     struct afs_vldb_entry *,
1028 						     u8);
1029 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1030 
1031 /*
1032  * super.c
1033  */
1034 extern int __init afs_fs_init(void);
1035 extern void afs_fs_exit(void);
1036 
1037 /*
1038  * vlclient.c
1039  */
1040 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
1041 							 struct afs_addr_cursor *,
1042 							 struct key *, const char *, int);
1043 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
1044 						struct key *, const uuid_t *);
1045 extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
1046 extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
1047 						     struct key *, const uuid_t *);
1048 
1049 /*
1050  * volume.c
1051  */
1052 static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
1053 {
1054 	if (volume)
1055 		atomic_inc(&volume->usage);
1056 	return volume;
1057 }
1058 
1059 extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
1060 extern void afs_activate_volume(struct afs_volume *);
1061 extern void afs_deactivate_volume(struct afs_volume *);
1062 extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
1063 extern int afs_check_volume_status(struct afs_volume *, struct key *);
1064 
1065 /*
1066  * write.c
1067  */
1068 extern int afs_set_page_dirty(struct page *);
1069 extern int afs_write_begin(struct file *file, struct address_space *mapping,
1070 			loff_t pos, unsigned len, unsigned flags,
1071 			struct page **pagep, void **fsdata);
1072 extern int afs_write_end(struct file *file, struct address_space *mapping,
1073 			loff_t pos, unsigned len, unsigned copied,
1074 			struct page *page, void *fsdata);
1075 extern int afs_writepage(struct page *, struct writeback_control *);
1076 extern int afs_writepages(struct address_space *, struct writeback_control *);
1077 extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
1078 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
1079 extern int afs_fsync(struct file *, loff_t, loff_t, int);
1080 extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
1081 extern void afs_prune_wb_keys(struct afs_vnode *);
1082 extern int afs_launder_page(struct page *);
1083 
1084 /*
1085  * xattr.c
1086  */
1087 extern const struct xattr_handler *afs_xattr_handlers[];
1088 extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
1089 
1090 
1091 /*
1092  * Miscellaneous inline functions.
1093  */
1094 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1095 {
1096 	return container_of(inode, struct afs_vnode, vfs_inode);
1097 }
1098 
1099 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1100 {
1101 	return &vnode->vfs_inode;
1102 }
1103 
1104 static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
1105 					   struct afs_vnode *vnode,
1106 					   unsigned int cb_break)
1107 {
1108 	if (fc->ac.error == 0)
1109 		afs_cache_permit(vnode, fc->key, cb_break);
1110 }
1111 
1112 static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1113 						 struct afs_vnode *vnode)
1114 {
1115 	if (fc->ac.error == -ENOENT) {
1116 		set_bit(AFS_VNODE_DELETED, &vnode->flags);
1117 		afs_break_callback(vnode);
1118 	}
1119 }
1120 
1121 
1122 /*****************************************************************************/
1123 /*
1124  * debug tracing
1125  */
1126 extern unsigned afs_debug;
1127 
1128 #define dbgprintk(FMT,...) \
1129 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1130 
1131 #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1132 #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1133 #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
1134 
1135 
1136 #if defined(__KDEBUG)
1137 #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
1138 #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
1139 #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
1140 
1141 #elif defined(CONFIG_AFS_DEBUG)
1142 #define AFS_DEBUG_KENTER	0x01
1143 #define AFS_DEBUG_KLEAVE	0x02
1144 #define AFS_DEBUG_KDEBUG	0x04
1145 
1146 #define _enter(FMT,...)					\
1147 do {							\
1148 	if (unlikely(afs_debug & AFS_DEBUG_KENTER))	\
1149 		kenter(FMT,##__VA_ARGS__);		\
1150 } while (0)
1151 
1152 #define _leave(FMT,...)					\
1153 do {							\
1154 	if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))	\
1155 		kleave(FMT,##__VA_ARGS__);		\
1156 } while (0)
1157 
1158 #define _debug(FMT,...)					\
1159 do {							\
1160 	if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))	\
1161 		kdebug(FMT,##__VA_ARGS__);		\
1162 } while (0)
1163 
1164 #else
1165 #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1166 #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1167 #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
1168 #endif
1169 
1170 /*
1171  * debug assertion checking
1172  */
1173 #if 1 // defined(__KDEBUGALL)
1174 
1175 #define ASSERT(X)						\
1176 do {								\
1177 	if (unlikely(!(X))) {					\
1178 		printk(KERN_ERR "\n");				\
1179 		printk(KERN_ERR "AFS: Assertion failed\n");	\
1180 		BUG();						\
1181 	}							\
1182 } while(0)
1183 
1184 #define ASSERTCMP(X, OP, Y)						\
1185 do {									\
1186 	if (unlikely(!((X) OP (Y)))) {					\
1187 		printk(KERN_ERR "\n");					\
1188 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1189 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
1190 		       (unsigned long)(X), (unsigned long)(Y));		\
1191 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
1192 		       (unsigned long)(X), (unsigned long)(Y));		\
1193 		BUG();							\
1194 	}								\
1195 } while(0)
1196 
1197 #define ASSERTRANGE(L, OP1, N, OP2, H)					\
1198 do {									\
1199 	if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {		\
1200 		printk(KERN_ERR "\n");					\
1201 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1202 		printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n",	\
1203 		       (unsigned long)(L), (unsigned long)(N),		\
1204 		       (unsigned long)(H));				\
1205 		printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1206 		       (unsigned long)(L), (unsigned long)(N),		\
1207 		       (unsigned long)(H));				\
1208 		BUG();							\
1209 	}								\
1210 } while(0)
1211 
1212 #define ASSERTIF(C, X)						\
1213 do {								\
1214 	if (unlikely((C) && !(X))) {				\
1215 		printk(KERN_ERR "\n");				\
1216 		printk(KERN_ERR "AFS: Assertion failed\n");	\
1217 		BUG();						\
1218 	}							\
1219 } while(0)
1220 
1221 #define ASSERTIFCMP(C, X, OP, Y)					\
1222 do {									\
1223 	if (unlikely((C) && !((X) OP (Y)))) {				\
1224 		printk(KERN_ERR "\n");					\
1225 		printk(KERN_ERR "AFS: Assertion failed\n");		\
1226 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
1227 		       (unsigned long)(X), (unsigned long)(Y));		\
1228 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
1229 		       (unsigned long)(X), (unsigned long)(Y));		\
1230 		BUG();							\
1231 	}								\
1232 } while(0)
1233 
1234 #else
1235 
1236 #define ASSERT(X)				\
1237 do {						\
1238 } while(0)
1239 
1240 #define ASSERTCMP(X, OP, Y)			\
1241 do {						\
1242 } while(0)
1243 
1244 #define ASSERTRANGE(L, OP1, N, OP2, H)		\
1245 do {						\
1246 } while(0)
1247 
1248 #define ASSERTIF(C, X)				\
1249 do {						\
1250 } while(0)
1251 
1252 #define ASSERTIFCMP(C, X, OP, Y)		\
1253 do {						\
1254 } while(0)
1255 
1256 #endif /* __KDEBUGALL */
1257