3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/compiler.h>
13 #include <linux/kernel.h>
14 #include <linux/ktime.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 <net/net_namespace.h>
25 #include <net/netns/generic.h>
27 #include <net/af_rxrpc.h>
32 #define AFS_CELL_MAX_ADDRS 15
37 struct afs_mount_params {
38 bool rwpath; /* T if the parent should be considered R/W */
39 bool force; /* T to force cell type */
40 bool autocell; /* T if set auto mount operation */
41 bool dyn_root; /* T if dynamic root */
42 afs_voltype_t type; /* type of volume requested */
43 int volnamesz; /* size of volume name */
44 const char *volname; /* name of volume to mount */
45 struct net *net_ns; /* Network namespace in effect */
46 struct afs_net *net; /* the AFS net namespace stuff */
47 struct afs_cell *cell; /* cell in which to find volume */
48 struct afs_volume *volume; /* volume record */
49 struct key *key; /* key to use for secure mounting */
52 struct afs_iget_data {
54 struct afs_volume *volume; /* volume on which resides */
58 AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
59 AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
60 AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
61 AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
62 AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
63 AFS_CALL_SV_REPLYING, /* Server: Replying */
64 AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
65 AFS_CALL_COMPLETE, /* Completed or failed */
69 * List of server addresses.
71 struct afs_addr_list {
72 struct rcu_head rcu; /* Must be first */
74 u32 version; /* Version */
75 unsigned short nr_addrs;
76 unsigned short index; /* Address currently in use */
77 unsigned short nr_ipv4; /* Number of IPv4 addresses */
78 unsigned long probed; /* Mask of servers that have been probed */
79 unsigned long yfs; /* Mask of servers that are YFS */
80 struct sockaddr_rxrpc addrs[];
84 * a record of an in-progress RxRPC call
87 const struct afs_call_type *type; /* type of call */
88 wait_queue_head_t waitq; /* processes awaiting completion */
89 struct work_struct async_work; /* async I/O processor */
90 struct work_struct work; /* actual work processor */
91 struct rxrpc_call *rxcall; /* RxRPC call handle */
92 struct key *key; /* security for this call */
93 struct afs_net *net; /* The network namespace */
94 struct afs_server *cm_server; /* Server affected by incoming CM call */
95 struct afs_cb_interest *cbi; /* Callback interest for server used */
96 void *request; /* request data (first part) */
97 struct address_space *mapping; /* Pages being written from */
98 void *buffer; /* reply receive buffer */
99 void *reply[4]; /* Where to put the reply */
100 pgoff_t first; /* first page in mapping to deal with */
101 pgoff_t last; /* last page in mapping to deal with */
102 size_t offset; /* offset into received data store */
104 enum afs_call_state state;
105 spinlock_t state_lock;
106 int error; /* error code */
107 u32 abort_code; /* Remote abort ID or 0 */
108 unsigned request_size; /* size of request data */
109 unsigned reply_max; /* maximum size of reply */
110 unsigned first_offset; /* offset into mapping[first] */
111 unsigned int cb_break; /* cb_break + cb_s_break before the call */
113 unsigned last_to; /* amount of mapping[last] */
114 unsigned count2; /* count used in unmarshalling */
116 unsigned char unmarshall; /* unmarshalling phase */
117 bool incoming; /* T if incoming call */
118 bool send_pages; /* T if data from mapping should be sent */
119 bool need_attention; /* T if RxRPC poked us */
120 bool async; /* T if asynchronous */
121 bool ret_reply0; /* T if should return reply[0] on success */
122 bool upgrade; /* T to request service upgrade */
123 u16 service_id; /* Actual service ID (after upgrade) */
124 unsigned int debug_id; /* Trace ID */
125 u32 operation_ID; /* operation ID for an incoming call */
126 u32 count; /* count for use in unmarshalling */
127 __be32 tmp; /* place to extract temporary data */
128 afs_dataversion_t expected_version; /* Updated version expected from store */
129 afs_dataversion_t expected_version_2; /* 2nd updated version expected from store */
132 struct afs_call_type {
134 unsigned int op; /* Really enum afs_fs_operation */
136 /* deliver request or reply data to an call
137 * - returning an error will cause the call to be aborted
139 int (*deliver)(struct afs_call *call);
141 /* clean up a call */
142 void (*destructor)(struct afs_call *call);
145 void (*work)(struct work_struct *work);
149 * Key available for writeback on a file.
154 struct list_head vnode_link; /* Link in vnode->wb_keys */
158 * AFS open file information record. Pointed to by file->private_data.
161 struct key *key; /* The key this file was opened with */
162 struct afs_wb_key *wb; /* Writeback key record for this file */
165 static inline struct key *afs_file_key(struct file *file)
167 struct afs_file *af = file->private_data;
173 * Record of an outstanding read operation on a vnode.
176 loff_t pos; /* Where to start reading */
177 loff_t len; /* How much we're asking for */
178 loff_t actual_len; /* How much we're actually getting */
179 loff_t remain; /* Amount remaining */
180 loff_t file_size; /* File size returned by server */
181 afs_dataversion_t data_version; /* Version number returned by server */
183 unsigned int index; /* Which page we're reading into */
184 unsigned int nr_pages;
185 void (*page_done)(struct afs_call *, struct afs_read *);
187 struct page *array[];
191 * AFS superblock private data
192 * - there's one superblock per volume
194 struct afs_super_info {
195 struct net *net_ns; /* Network namespace */
196 struct afs_cell *cell; /* The cell in which the volume resides */
197 struct afs_volume *volume; /* volume record */
198 bool dyn_root; /* True if dynamic root */
201 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
203 return sb->s_fs_info;
206 extern struct file_system_type afs_fs_type;
209 * Set of substitutes for @sys.
211 struct afs_sysnames {
212 #define AFS_NR_SYSNAME 16
213 char *subs[AFS_NR_SYSNAME];
220 * AFS network namespace record.
223 struct net *net; /* Backpointer to the owning net namespace */
224 struct afs_uuid uuid;
225 bool live; /* F if this namespace is being removed */
227 /* AF_RXRPC I/O stuff */
228 struct socket *socket;
229 struct afs_call *spare_incoming_call;
230 struct work_struct charge_preallocation_work;
231 struct mutex socket_mutex;
232 atomic_t nr_outstanding_calls;
233 atomic_t nr_superblocks;
236 struct rb_root cells;
237 struct afs_cell __rcu *ws_cell;
238 struct work_struct cells_manager;
239 struct timer_list cells_timer;
240 atomic_t cells_outstanding;
241 seqlock_t cells_lock;
243 spinlock_t proc_cells_lock;
244 struct list_head proc_cells;
246 /* Known servers. Theoretically each fileserver can only be in one
247 * cell, but in practice, people create aliases and subsets and there's
248 * no easy way to distinguish them.
250 seqlock_t fs_lock; /* For fs_servers */
251 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
252 struct list_head fs_updates; /* afs_server (by update_at) */
253 struct hlist_head fs_proc; /* procfs servers list */
255 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
256 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
257 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
259 struct work_struct fs_manager;
260 struct timer_list fs_timer;
261 atomic_t servers_outstanding;
263 /* File locking renewal management */
264 struct mutex lock_manager_mutex;
267 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
268 struct afs_sysnames *sysnames;
269 rwlock_t sysnames_lock;
271 /* Statistics counters */
272 atomic_t n_lookup; /* Number of lookups done */
273 atomic_t n_reval; /* Number of dentries needing revalidation */
274 atomic_t n_inval; /* Number of invalidations by the server */
275 atomic_t n_relpg; /* Number of invalidations by releasepage */
276 atomic_t n_read_dir; /* Number of directory pages read */
277 atomic_t n_dir_cr; /* Number of directory entry creation edits */
278 atomic_t n_dir_rm; /* Number of directory entry removal edits */
279 atomic_t n_stores; /* Number of store ops */
280 atomic_long_t n_store_bytes; /* Number of bytes stored */
281 atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
282 atomic_t n_fetches; /* Number of data fetch ops */
285 extern const char afs_init_sysname[];
287 enum afs_cell_state {
291 AFS_CELL_DEACTIVATING,
299 * This is a tricky concept to get right as it is possible to create aliases
300 * simply by pointing AFSDB/SRV records for two names at the same set of VL
301 * servers; it is also possible to do things like setting up two sets of VL
302 * servers, one of which provides a superset of the volumes provided by the
303 * other (for internal/external division, for example).
305 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
306 * servers and (b) a cell's name is used by the client to select the key to use
307 * for authentication and encryption. The cell name is not typically used in
310 * There is no easy way to determine if two cells are aliases or one is a
316 struct rb_node net_node; /* Node in net->cells */
319 struct key *anonymous_key; /* anonymous user key for this cell */
320 struct work_struct manager; /* Manager for init/deinit/dns */
321 struct list_head proc_link; /* /proc cell list link */
322 #ifdef CONFIG_AFS_FSCACHE
323 struct fscache_cookie *cache; /* caching cookie */
325 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
326 time64_t last_inactive; /* Time of last drop of usage count */
329 #define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
330 #define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
331 #define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
332 #define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
333 #define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
334 enum afs_cell_state state;
337 /* Active fileserver interaction state. */
338 struct list_head proc_volumes; /* procfs volume list */
341 /* VL server list. */
342 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
343 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
344 u8 name_len; /* Length of name */
345 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
351 * This is pointed to by cell->vldb_entries, indexed by name.
353 struct afs_vldb_entry {
354 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
357 #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
358 #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
359 #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
360 #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
361 #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
363 uuid_t fs_server[AFS_NMAXNSERVERS];
364 u8 fs_mask[AFS_NMAXNSERVERS];
365 #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
366 #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
367 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
369 u8 nr_servers; /* Number of server records */
371 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
375 * Record of fileserver with which we're actively communicating.
380 uuid_t uuid; /* Server ID */
381 struct afs_uuid _uuid;
384 struct afs_addr_list __rcu *addresses;
385 struct rb_node uuid_rb; /* Link in net->servers */
386 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
387 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
388 struct hlist_node proc_link; /* Link in net->fs_proc */
389 struct afs_server *gc_next; /* Next server in manager's list */
390 time64_t put_time; /* Time at which last put */
391 time64_t update_at; /* Time at which to next update the record */
393 #define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
394 #define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
395 #define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
396 #define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
397 #define AFS_SERVER_FL_UPDATING 4
398 #define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
399 #define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
400 #define AFS_SERVER_FL_NO_IBULK 7 /* Fileserver doesn't support FS.InlineBulkStatus */
401 #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
403 u32 addr_version; /* Address list version */
405 /* file service access */
406 rwlock_t fs_lock; /* access lock */
408 /* callback promise management */
409 struct list_head cb_interests; /* List of superblocks using this server */
410 unsigned cb_s_break; /* Break-everything counter. */
411 rwlock_t cb_break_lock; /* Volume finding lock */
415 * Interest by a superblock on a server.
417 struct afs_cb_interest {
418 struct list_head cb_link; /* Link in server->cb_interests */
419 struct afs_server *server; /* Server on which this interest resides */
420 struct super_block *sb; /* Superblock on which inodes reside */
421 afs_volid_t vid; /* Volume ID to match */
426 * Replaceable server list.
428 struct afs_server_entry {
429 struct afs_server *server;
430 struct afs_cb_interest *cb_interest;
433 struct afs_server_list {
435 unsigned short nr_servers;
436 unsigned short index; /* Server currently in use */
437 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
438 unsigned int seq; /* Set to ->servers_seq when installed */
440 struct afs_server_entry servers[];
444 * Live AFS volume management.
447 afs_volid_t vid; /* volume ID */
449 time64_t update_at; /* Time at which to next update */
450 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
451 struct list_head proc_link; /* Link in cell->vl_proc */
453 #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
454 #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
455 #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
456 #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
457 #define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
458 #define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
459 #ifdef CONFIG_AFS_FSCACHE
460 struct fscache_cookie *cache; /* caching cookie */
462 struct afs_server_list *servers; /* List of servers on which volume resides */
463 rwlock_t servers_lock; /* Lock for ->servers */
464 unsigned int servers_seq; /* Incremented each time ->servers changes */
466 unsigned cb_v_break; /* Break-everything counter. */
467 rwlock_t cb_break_lock;
469 afs_voltype_t type; /* type of volume */
471 char type_force; /* force volume type (suppress R/O -> R/W) */
473 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
476 enum afs_lock_state {
477 AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
478 AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
479 AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
480 AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
481 AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
482 AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
483 AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
487 * AFS inode private data.
489 * Note that afs_alloc_inode() *must* reset anything that could incorrectly
490 * leak from one inode to another.
493 struct inode vfs_inode; /* the VFS's inode record */
495 struct afs_volume *volume; /* volume on which vnode resides */
496 struct afs_fid fid; /* the file identifier for this inode */
497 struct afs_file_status status; /* AFS status info for this file */
498 afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
499 #ifdef CONFIG_AFS_FSCACHE
500 struct fscache_cookie *cache; /* caching cookie */
502 struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
503 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
504 struct rw_semaphore validate_lock; /* lock for validating this vnode */
505 spinlock_t wb_lock; /* lock for wb_keys */
506 spinlock_t lock; /* waitqueue/flags lock */
508 #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
509 #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
510 #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
511 #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
512 #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
513 #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
514 #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
515 #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
516 #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
518 struct list_head wb_keys; /* List of keys available for writeback */
519 struct list_head pending_locks; /* locks waiting to be granted */
520 struct list_head granted_locks; /* locks granted on this file */
521 struct delayed_work lock_work; /* work to be done in locking */
522 struct key *lock_key; /* Key to be used in lock ops */
523 enum afs_lock_state lock_state : 8;
524 afs_lock_type_t lock_type : 8;
526 /* outstanding callback notification on this file */
527 struct afs_cb_interest *cb_interest; /* Server on which this resides */
528 unsigned int cb_s_break; /* Mass break counter on ->server */
529 unsigned int cb_v_break; /* Mass break counter on ->volume */
530 unsigned int cb_break; /* Break counter on vnode */
531 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
533 time64_t cb_expires_at; /* time at which callback expires */
534 unsigned cb_version; /* callback version */
535 afs_callback_type_t cb_type; /* type of callback */
539 * cached security record for one user's attempt to access a vnode
542 struct key *key; /* RxRPC ticket holding a security context */
543 afs_access_t access; /* CallerAccess value for this key */
547 * Immutable cache of CallerAccess records from attempts to access vnodes.
548 * These may be shared between multiple vnodes.
552 struct hlist_node hash_node; /* Link in hash */
553 unsigned long h; /* Hash value for this permit list */
555 unsigned short nr_permits; /* Number of records */
556 bool invalidated; /* Invalidated due to key change */
557 struct afs_permit permits[]; /* List of permits sorted by key pointer */
561 * record of one of a system's set of network interfaces
563 struct afs_interface {
564 struct in_addr address; /* IPv4 address bound to interface */
565 struct in_addr netmask; /* netmask applied to address */
566 unsigned mtu; /* MTU of interface */
570 * Cursor for iterating over a server's address list.
572 struct afs_addr_cursor {
573 struct afs_addr_list *alist; /* Current address list (pins ref) */
574 struct sockaddr_rxrpc *addr;
576 unsigned short start; /* Starting point in alist->addrs[] */
577 unsigned short index; /* Wrapping offset from start to current addr */
579 bool begun; /* T if we've begun iteration */
580 bool responded; /* T if the current address responded */
584 * Cursor for iterating over a set of fileservers.
586 struct afs_fs_cursor {
587 struct afs_addr_cursor ac;
588 struct afs_vnode *vnode;
589 struct afs_server_list *server_list; /* Current server list (pins ref) */
590 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
591 struct key *key; /* Key for the server */
592 unsigned int cb_break; /* cb_break + cb_s_break before the call */
593 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
594 unsigned char start; /* Initial index in server list */
595 unsigned char index; /* Number of servers tried beyond start */
596 unsigned short flags;
597 #define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
598 #define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
599 #define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
600 #define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
601 #define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
602 #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
606 * Cache auxiliary data.
608 struct afs_vnode_cache_aux {
612 #include <trace/events/afs.h>
614 /*****************************************************************************/
618 static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
621 refcount_inc(&alist->usage);
624 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
627 extern void afs_put_addrlist(struct afs_addr_list *);
628 extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
629 unsigned short, unsigned short);
630 extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
631 extern bool afs_iterate_addresses(struct afs_addr_cursor *);
632 extern int afs_end_cursor(struct afs_addr_cursor *);
633 extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
635 extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
636 extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
641 #ifdef CONFIG_AFS_FSCACHE
642 extern struct fscache_netfs afs_cache_netfs;
643 extern struct fscache_cookie_def afs_cell_cache_index_def;
644 extern struct fscache_cookie_def afs_volume_cache_index_def;
645 extern struct fscache_cookie_def afs_vnode_cache_index_def;
647 #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
648 #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
649 #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
655 extern void afs_init_callback_state(struct afs_server *);
656 extern void afs_break_callback(struct afs_vnode *);
657 extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
659 extern int afs_register_server_cb_interest(struct afs_vnode *,
660 struct afs_server_list *, unsigned int);
661 extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
662 extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
664 static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
667 refcount_inc(&cbi->usage);
671 static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
673 return vnode->cb_break + vnode->cb_s_break + vnode->cb_v_break;
676 static inline unsigned int afs_cb_break_sum(struct afs_vnode *vnode,
677 struct afs_cb_interest *cbi)
679 return vnode->cb_break + cbi->server->cb_s_break + vnode->volume->cb_v_break;
685 extern int afs_cell_init(struct afs_net *, const char *);
686 extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
687 extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
689 extern struct afs_cell *afs_get_cell(struct afs_cell *);
690 extern void afs_put_cell(struct afs_net *, struct afs_cell *);
691 extern void afs_manage_cells(struct work_struct *);
692 extern void afs_cells_timer(struct timer_list *);
693 extern void __net_exit afs_cell_purge(struct afs_net *);
698 extern bool afs_cm_incoming_call(struct afs_call *);
703 extern const struct file_operations afs_dir_file_operations;
704 extern const struct inode_operations afs_dir_inode_operations;
705 extern const struct address_space_operations afs_dir_aops;
706 extern const struct dentry_operations afs_fs_dentry_operations;
708 extern void afs_d_release(struct dentry *);
713 extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
714 enum afs_edit_dir_reason);
715 extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
720 extern const struct file_operations afs_dynroot_file_operations;
721 extern const struct inode_operations afs_dynroot_inode_operations;
722 extern const struct dentry_operations afs_dynroot_dentry_operations;
724 extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
729 extern const struct address_space_operations afs_fs_aops;
730 extern const struct inode_operations afs_file_inode_operations;
731 extern const struct file_operations afs_file_operations;
733 extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
734 extern void afs_put_wb_key(struct afs_wb_key *);
735 extern int afs_open(struct inode *, struct file *);
736 extern int afs_release(struct inode *, struct file *);
737 extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
738 extern int afs_page_filler(void *, struct page *);
739 extern void afs_put_read(struct afs_read *);
744 extern struct workqueue_struct *afs_lock_manager;
746 extern void afs_lock_work(struct work_struct *);
747 extern void afs_lock_may_be_available(struct afs_vnode *);
748 extern int afs_lock(struct file *, int, struct file_lock *);
749 extern int afs_flock(struct file *, int, struct file_lock *);
754 #define AFS_VNODE_NOT_YET_SET 0x01
755 #define AFS_VNODE_META_CHANGED 0x02
756 #define AFS_VNODE_DATA_CHANGED 0x04
757 extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *,
758 const afs_dataversion_t *, u8);
760 extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
761 extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
762 extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
763 extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, u64,
764 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
765 extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool, u64);
766 extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
767 extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
768 struct afs_fid *, struct afs_file_status *);
769 extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
770 struct afs_vnode *, const char *, u64, u64);
771 extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
772 pgoff_t, pgoff_t, unsigned, unsigned);
773 extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
774 extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
775 extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
776 extern int afs_fs_extend_lock(struct afs_fs_cursor *);
777 extern int afs_fs_release_lock(struct afs_fs_cursor *);
778 extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
779 struct afs_addr_cursor *, struct key *);
780 extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
781 struct afs_addr_cursor *, struct key *);
782 extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
783 struct afs_fid *, struct afs_file_status *,
784 struct afs_callback *, unsigned int,
785 struct afs_volsync *);
786 extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
787 struct afs_fid *, struct afs_file_status *,
788 struct afs_callback *, struct afs_volsync *);
793 extern int afs_fetch_status(struct afs_vnode *, struct key *, bool);
794 extern int afs_iget5_test(struct inode *, void *);
795 extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
796 extern struct inode *afs_iget(struct super_block *, struct key *,
797 struct afs_fid *, struct afs_file_status *,
798 struct afs_callback *,
799 struct afs_cb_interest *);
800 extern void afs_zap_data(struct afs_vnode *);
801 extern int afs_validate(struct afs_vnode *, struct key *);
802 extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
803 extern int afs_setattr(struct dentry *, struct iattr *);
804 extern void afs_evict_inode(struct inode *);
805 extern int afs_drop_inode(struct inode *);
810 extern struct workqueue_struct *afs_wq;
811 extern int afs_net_id;
813 static inline struct afs_net *afs_net(struct net *net)
815 return net_generic(net, afs_net_id);
818 static inline struct afs_net *afs_sb2net(struct super_block *sb)
820 return afs_net(AFS_FS_S(sb)->net_ns);
823 static inline struct afs_net *afs_d2net(struct dentry *dentry)
825 return afs_sb2net(dentry->d_sb);
828 static inline struct afs_net *afs_i2net(struct inode *inode)
830 return afs_sb2net(inode->i_sb);
833 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
835 return afs_i2net(&vnode->vfs_inode);
838 static inline struct afs_net *afs_sock2net(struct sock *sk)
840 return net_generic(sock_net(sk), afs_net_id);
843 static inline void __afs_stat(atomic_t *s)
848 #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
853 extern int afs_abort_to_error(u32);
858 extern const struct inode_operations afs_mntpt_inode_operations;
859 extern const struct inode_operations afs_autocell_inode_operations;
860 extern const struct file_operations afs_mntpt_file_operations;
862 extern struct vfsmount *afs_d_automount(struct path *);
863 extern void afs_mntpt_kill_timer(void);
868 extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *,
874 #ifdef CONFIG_PROC_FS
875 extern int __net_init afs_proc_init(struct afs_net *);
876 extern void __net_exit afs_proc_cleanup(struct afs_net *);
877 extern int afs_proc_cell_setup(struct afs_cell *);
878 extern void afs_proc_cell_remove(struct afs_cell *);
879 extern void afs_put_sysnames(struct afs_sysnames *);
881 static inline int afs_proc_init(struct afs_net *net) { return 0; }
882 static inline void afs_proc_cleanup(struct afs_net *net) {}
883 static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
884 static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
885 static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
891 extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
893 extern bool afs_select_fileserver(struct afs_fs_cursor *);
894 extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
895 extern int afs_end_vnode_operation(struct afs_fs_cursor *);
900 extern struct workqueue_struct *afs_async_calls;
902 extern int __net_init afs_open_socket(struct afs_net *);
903 extern void __net_exit afs_close_socket(struct afs_net *);
904 extern void afs_charge_preallocation(struct work_struct *);
905 extern void afs_put_call(struct afs_call *);
906 extern int afs_queue_call_work(struct afs_call *);
907 extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
908 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
909 const struct afs_call_type *,
911 extern void afs_flat_call_destructor(struct afs_call *);
912 extern void afs_send_empty_reply(struct afs_call *);
913 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
914 extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
915 extern int afs_protocol_error(struct afs_call *, int);
917 static inline int afs_transfer_reply(struct afs_call *call)
919 return afs_extract_data(call, call->buffer, call->reply_max, false);
922 static inline bool afs_check_call_state(struct afs_call *call,
923 enum afs_call_state state)
925 return READ_ONCE(call->state) == state;
928 static inline bool afs_set_call_state(struct afs_call *call,
929 enum afs_call_state from,
930 enum afs_call_state to)
934 spin_lock_bh(&call->state_lock);
935 if (call->state == from) {
937 trace_afs_call_state(call, from, to, 0, 0);
940 spin_unlock_bh(&call->state_lock);
944 static inline void afs_set_call_complete(struct afs_call *call,
945 int error, u32 remote_abort)
947 enum afs_call_state state;
950 spin_lock_bh(&call->state_lock);
952 if (state != AFS_CALL_COMPLETE) {
953 call->abort_code = remote_abort;
955 call->state = AFS_CALL_COMPLETE;
956 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
957 error, remote_abort);
960 spin_unlock_bh(&call->state_lock);
962 trace_afs_call_done(call);
968 extern void afs_put_permits(struct afs_permits *);
969 extern void afs_clear_permits(struct afs_vnode *);
970 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
971 extern void afs_zap_permits(struct rcu_head *);
972 extern struct key *afs_request_key(struct afs_cell *);
973 extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
974 extern int afs_permission(struct inode *, int);
975 extern void __exit afs_clean_up_permit_cache(void);
980 extern spinlock_t afs_server_peer_lock;
982 static inline struct afs_server *afs_get_server(struct afs_server *server)
984 atomic_inc(&server->usage);
988 extern struct afs_server *afs_find_server(struct afs_net *,
989 const struct sockaddr_rxrpc *);
990 extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
991 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
992 extern void afs_put_server(struct afs_net *, struct afs_server *);
993 extern void afs_manage_servers(struct work_struct *);
994 extern void afs_servers_timer(struct timer_list *);
995 extern void __net_exit afs_purge_servers(struct afs_net *);
996 extern bool afs_probe_fileserver(struct afs_fs_cursor *);
997 extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
1002 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1004 refcount_inc(&slist->usage);
1008 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1009 extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1010 struct afs_vldb_entry *,
1012 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1017 extern int __init afs_fs_init(void);
1018 extern void afs_fs_exit(void);
1023 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
1024 struct afs_addr_cursor *,
1025 struct key *, const char *, int);
1026 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
1027 struct key *, const uuid_t *);
1028 extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
1029 extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
1030 struct key *, const uuid_t *);
1035 static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
1038 atomic_inc(&volume->usage);
1042 extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
1043 extern void afs_activate_volume(struct afs_volume *);
1044 extern void afs_deactivate_volume(struct afs_volume *);
1045 extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
1046 extern int afs_check_volume_status(struct afs_volume *, struct key *);
1051 extern int afs_set_page_dirty(struct page *);
1052 extern int afs_write_begin(struct file *file, struct address_space *mapping,
1053 loff_t pos, unsigned len, unsigned flags,
1054 struct page **pagep, void **fsdata);
1055 extern int afs_write_end(struct file *file, struct address_space *mapping,
1056 loff_t pos, unsigned len, unsigned copied,
1057 struct page *page, void *fsdata);
1058 extern int afs_writepage(struct page *, struct writeback_control *);
1059 extern int afs_writepages(struct address_space *, struct writeback_control *);
1060 extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
1061 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
1062 extern int afs_fsync(struct file *, loff_t, loff_t, int);
1063 extern int afs_page_mkwrite(struct vm_fault *);
1064 extern void afs_prune_wb_keys(struct afs_vnode *);
1065 extern int afs_launder_page(struct page *);
1070 extern const struct xattr_handler *afs_xattr_handlers[];
1071 extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
1075 * Miscellaneous inline functions.
1077 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1079 return container_of(inode, struct afs_vnode, vfs_inode);
1082 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1084 return &vnode->vfs_inode;
1087 static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
1088 struct afs_vnode *vnode,
1089 unsigned int cb_break)
1091 if (fc->ac.error == 0)
1092 afs_cache_permit(vnode, fc->key, cb_break);
1095 static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1096 struct afs_vnode *vnode)
1098 if (fc->ac.error == -ENOENT) {
1099 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1100 afs_break_callback(vnode);
1105 /*****************************************************************************/
1109 extern unsigned afs_debug;
1111 #define dbgprintk(FMT,...) \
1112 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1114 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1115 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1116 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1119 #if defined(__KDEBUG)
1120 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1121 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1122 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1124 #elif defined(CONFIG_AFS_DEBUG)
1125 #define AFS_DEBUG_KENTER 0x01
1126 #define AFS_DEBUG_KLEAVE 0x02
1127 #define AFS_DEBUG_KDEBUG 0x04
1129 #define _enter(FMT,...) \
1131 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
1132 kenter(FMT,##__VA_ARGS__); \
1135 #define _leave(FMT,...) \
1137 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
1138 kleave(FMT,##__VA_ARGS__); \
1141 #define _debug(FMT,...) \
1143 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
1144 kdebug(FMT,##__VA_ARGS__); \
1148 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1149 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1150 #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
1154 * debug assertion checking
1156 #if 1 // defined(__KDEBUGALL)
1160 if (unlikely(!(X))) { \
1161 printk(KERN_ERR "\n"); \
1162 printk(KERN_ERR "AFS: Assertion failed\n"); \
1167 #define ASSERTCMP(X, OP, Y) \
1169 if (unlikely(!((X) OP (Y)))) { \
1170 printk(KERN_ERR "\n"); \
1171 printk(KERN_ERR "AFS: Assertion failed\n"); \
1172 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1173 (unsigned long)(X), (unsigned long)(Y)); \
1174 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1175 (unsigned long)(X), (unsigned long)(Y)); \
1180 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1182 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1183 printk(KERN_ERR "\n"); \
1184 printk(KERN_ERR "AFS: Assertion failed\n"); \
1185 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1186 (unsigned long)(L), (unsigned long)(N), \
1187 (unsigned long)(H)); \
1188 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1189 (unsigned long)(L), (unsigned long)(N), \
1190 (unsigned long)(H)); \
1195 #define ASSERTIF(C, X) \
1197 if (unlikely((C) && !(X))) { \
1198 printk(KERN_ERR "\n"); \
1199 printk(KERN_ERR "AFS: Assertion failed\n"); \
1204 #define ASSERTIFCMP(C, X, OP, Y) \
1206 if (unlikely((C) && !((X) OP (Y)))) { \
1207 printk(KERN_ERR "\n"); \
1208 printk(KERN_ERR "AFS: Assertion failed\n"); \
1209 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1210 (unsigned long)(X), (unsigned long)(Y)); \
1211 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1212 (unsigned long)(X), (unsigned long)(Y)); \
1223 #define ASSERTCMP(X, OP, Y) \
1227 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1231 #define ASSERTIF(C, X) \
1235 #define ASSERTIFCMP(C, X, OP, Y) \
1239 #endif /* __KDEBUGALL */