1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/compiler.h>
9 #include <linux/kernel.h>
10 #include <linux/ktime.h>
12 #include <linux/pagemap.h>
13 #include <linux/rxrpc.h>
14 #include <linux/key.h>
15 #include <linux/workqueue.h>
16 #include <linux/sched.h>
17 #include <linux/fscache.h>
18 #include <linux/backing-dev.h>
19 #include <linux/uuid.h>
20 #include <linux/mm_types.h>
21 #include <linux/dns_resolver.h>
22 #include <net/net_namespace.h>
23 #include <net/netns/generic.h>
25 #include <net/af_rxrpc.h>
30 #define AFS_CELL_MAX_ADDRS 15
36 * Partial file-locking emulation mode. (The problem being that AFS3 only
37 * allows whole-file locks and no upgrading/downgrading).
41 afs_flock_mode_local, /* Local locking only */
42 afs_flock_mode_openafs, /* Don't get server lock for a partial lock */
43 afs_flock_mode_strict, /* Always get a server lock for a partial lock */
44 afs_flock_mode_write, /* Get an exclusive server lock for a partial lock */
47 struct afs_fs_context {
48 bool force; /* T to force cell type */
49 bool autocell; /* T if set auto mount operation */
50 bool dyn_root; /* T if dynamic root */
51 bool no_cell; /* T if the source is "none" (for dynroot) */
52 enum afs_flock_mode flock_mode; /* Partial file-locking emulation mode */
53 afs_voltype_t type; /* type of volume requested */
54 unsigned int volnamesz; /* size of volume name */
55 const char *volname; /* name of volume to mount */
56 struct afs_net *net; /* the AFS net namespace stuff */
57 struct afs_cell *cell; /* cell in which to find volume */
58 struct afs_volume *volume; /* volume record */
59 struct key *key; /* key to use for secure mounting */
63 AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
64 AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
65 AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
66 AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
67 AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
68 AFS_CALL_SV_REPLYING, /* Server: Replying */
69 AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
70 AFS_CALL_COMPLETE, /* Completed or failed */
74 * List of server addresses.
76 struct afs_addr_list {
79 u32 version; /* Version */
80 unsigned char max_addrs;
81 unsigned char nr_addrs;
82 unsigned char preferred; /* Preferred address */
83 unsigned char nr_ipv4; /* Number of IPv4 addresses */
84 enum dns_record_source source:8;
85 enum dns_lookup_status status:8;
86 unsigned long failed; /* Mask of addrs that failed locally/ICMP */
87 unsigned long responded; /* Mask of addrs that responded */
88 struct sockaddr_rxrpc addrs[];
89 #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
93 * a record of an in-progress RxRPC call
96 const struct afs_call_type *type; /* type of call */
97 struct afs_addr_list *alist; /* Address is alist[addr_ix] */
98 wait_queue_head_t waitq; /* processes awaiting completion */
99 struct work_struct async_work; /* async I/O processor */
100 struct work_struct work; /* actual work processor */
101 struct rxrpc_call *rxcall; /* RxRPC call handle */
102 struct key *key; /* security for this call */
103 struct afs_net *net; /* The network namespace */
104 struct afs_server *server; /* The fileserver record if fs op (pins ref) */
105 struct afs_vlserver *vlserver; /* The vlserver record if vl op */
106 struct afs_cb_interest *cbi; /* Callback interest for server used */
107 void *request; /* request data (first part) */
108 struct iov_iter def_iter; /* Default buffer/data iterator */
109 struct iov_iter *iter; /* Iterator currently in use */
110 union { /* Convenience for ->def_iter */
112 struct bio_vec bvec[1];
114 void *buffer; /* reply receive buffer */
116 long ret0; /* Value to reply with instead of 0 */
117 struct afs_addr_list *ret_alist;
118 struct afs_vldb_entry *ret_vldb;
120 struct afs_operation *op;
121 unsigned int server_index;
123 enum afs_call_state state;
124 spinlock_t state_lock;
125 int error; /* error code */
126 u32 abort_code; /* Remote abort ID or 0 */
128 unsigned int max_lifespan; /* Maximum lifespan to set if not 0 */
129 unsigned request_size; /* size of request data */
130 unsigned reply_max; /* maximum size of reply */
131 unsigned count2; /* count used in unmarshalling */
132 unsigned char unmarshall; /* unmarshalling phase */
133 unsigned char addr_ix; /* Address in ->alist */
134 bool drop_ref; /* T if need to drop ref for incoming call */
135 bool send_pages; /* T if data from mapping should be sent */
136 bool need_attention; /* T if RxRPC poked us */
137 bool async; /* T if asynchronous */
138 bool upgrade; /* T to request service upgrade */
139 bool have_reply_time; /* T if have got reply_time */
140 bool intr; /* T if interruptible */
141 bool unmarshalling_error; /* T if an unmarshalling error occurred */
142 u16 service_id; /* Actual service ID (after upgrade) */
143 unsigned int debug_id; /* Trace ID */
144 u32 operation_ID; /* operation ID for an incoming call */
145 u32 count; /* count for use in unmarshalling */
146 union { /* place to extract temporary data */
150 } __attribute__((packed));
153 ktime_t reply_time; /* Time of first reply packet */
156 struct afs_call_type {
158 unsigned int op; /* Really enum afs_fs_operation */
160 /* deliver request or reply data to an call
161 * - returning an error will cause the call to be aborted
163 int (*deliver)(struct afs_call *call);
165 /* clean up a call */
166 void (*destructor)(struct afs_call *call);
169 void (*work)(struct work_struct *work);
171 /* Call done function (gets called immediately on success or failure) */
172 void (*done)(struct afs_call *call);
176 * Key available for writeback on a file.
181 struct list_head vnode_link; /* Link in vnode->wb_keys */
185 * AFS open file information record. Pointed to by file->private_data.
188 struct key *key; /* The key this file was opened with */
189 struct afs_wb_key *wb; /* Writeback key record for this file */
192 static inline struct key *afs_file_key(struct file *file)
194 struct afs_file *af = file->private_data;
200 * Record of an outstanding read operation on a vnode.
203 loff_t pos; /* Where to start reading */
204 loff_t len; /* How much we're asking for */
205 loff_t actual_len; /* How much we're actually getting */
206 loff_t remain; /* Amount remaining */
207 loff_t file_size; /* File size returned by server */
208 afs_dataversion_t data_version; /* Version number returned by server */
210 unsigned int index; /* Which page we're reading into */
211 unsigned int nr_pages;
212 unsigned int offset; /* offset into current page */
213 struct afs_vnode *vnode;
214 void (*page_done)(struct afs_read *);
216 struct page *array[];
220 * AFS superblock private data
221 * - there's one superblock per volume
223 struct afs_super_info {
224 struct net *net_ns; /* Network namespace */
225 struct afs_cell *cell; /* The cell in which the volume resides */
226 struct afs_volume *volume; /* volume record */
227 enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
228 bool dyn_root; /* True if dynamic root */
231 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
233 return sb->s_fs_info;
236 extern struct file_system_type afs_fs_type;
239 * Set of substitutes for @sys.
241 struct afs_sysnames {
242 #define AFS_NR_SYSNAME 16
243 char *subs[AFS_NR_SYSNAME];
250 * AFS network namespace record.
253 struct net *net; /* Backpointer to the owning net namespace */
254 struct afs_uuid uuid;
255 bool live; /* F if this namespace is being removed */
257 /* AF_RXRPC I/O stuff */
258 struct socket *socket;
259 struct afs_call *spare_incoming_call;
260 struct work_struct charge_preallocation_work;
261 struct mutex socket_mutex;
262 atomic_t nr_outstanding_calls;
263 atomic_t nr_superblocks;
266 struct rb_root cells;
267 struct afs_cell __rcu *ws_cell;
268 struct work_struct cells_manager;
269 struct timer_list cells_timer;
270 atomic_t cells_outstanding;
271 seqlock_t cells_lock;
273 struct mutex proc_cells_lock;
274 struct hlist_head proc_cells;
276 /* Known servers. Theoretically each fileserver can only be in one
277 * cell, but in practice, people create aliases and subsets and there's
278 * no easy way to distinguish them.
280 seqlock_t fs_lock; /* For fs_servers, fs_probe_*, fs_proc */
281 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
282 struct list_head fs_probe_fast; /* List of afs_server to probe at 30s intervals */
283 struct list_head fs_probe_slow; /* List of afs_server to probe at 5m intervals */
284 struct hlist_head fs_proc; /* procfs servers list */
286 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
287 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
288 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
290 struct work_struct fs_manager;
291 struct timer_list fs_timer;
293 struct work_struct fs_prober;
294 struct timer_list fs_probe_timer;
295 atomic_t servers_outstanding;
297 /* File locking renewal management */
298 struct mutex lock_manager_mutex;
301 struct super_block *dynroot_sb; /* Dynamic root mount superblock */
302 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
303 struct afs_sysnames *sysnames;
304 rwlock_t sysnames_lock;
306 /* Statistics counters */
307 atomic_t n_lookup; /* Number of lookups done */
308 atomic_t n_reval; /* Number of dentries needing revalidation */
309 atomic_t n_inval; /* Number of invalidations by the server */
310 atomic_t n_relpg; /* Number of invalidations by releasepage */
311 atomic_t n_read_dir; /* Number of directory pages read */
312 atomic_t n_dir_cr; /* Number of directory entry creation edits */
313 atomic_t n_dir_rm; /* Number of directory entry removal edits */
314 atomic_t n_stores; /* Number of store ops */
315 atomic_long_t n_store_bytes; /* Number of bytes stored */
316 atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
317 atomic_t n_fetches; /* Number of data fetch ops */
320 extern const char afs_init_sysname[];
322 enum afs_cell_state {
326 AFS_CELL_DEACTIVATING,
334 * This is a tricky concept to get right as it is possible to create aliases
335 * simply by pointing AFSDB/SRV records for two names at the same set of VL
336 * servers; it is also possible to do things like setting up two sets of VL
337 * servers, one of which provides a superset of the volumes provided by the
338 * other (for internal/external division, for example).
340 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
341 * servers and (b) a cell's name is used by the client to select the key to use
342 * for authentication and encryption. The cell name is not typically used in
345 * There is no easy way to determine if two cells are aliases or one is a
351 struct rb_node net_node; /* Node in net->cells */
354 struct key *anonymous_key; /* anonymous user key for this cell */
355 struct work_struct manager; /* Manager for init/deinit/dns */
356 struct hlist_node proc_link; /* /proc cell list link */
357 #ifdef CONFIG_AFS_FSCACHE
358 struct fscache_cookie *cache; /* caching cookie */
360 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
361 time64_t last_inactive; /* Time of last drop of usage count */
364 #define AFS_CELL_FL_NO_GC 0 /* The cell was added manually, don't auto-gc */
365 #define AFS_CELL_FL_DO_LOOKUP 1 /* DNS lookup requested */
366 enum afs_cell_state state;
368 enum dns_record_source dns_source:8; /* Latest source of data from lookup */
369 enum dns_lookup_status dns_status:8; /* Latest status of data from lookup */
370 unsigned int dns_lookup_count; /* Counter of DNS lookups */
372 /* Active fileserver interaction state. */
373 struct list_head proc_volumes; /* procfs volume list */
376 /* VL server list. */
377 rwlock_t vl_servers_lock; /* Lock on vl_servers */
378 struct afs_vlserver_list __rcu *vl_servers;
380 u8 name_len; /* Length of name */
381 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
385 * Volume Location server record.
387 struct afs_vlserver {
389 struct afs_addr_list __rcu *addresses; /* List of addresses for this VL server */
391 #define AFS_VLSERVER_FL_PROBED 0 /* The VL server has been probed */
392 #define AFS_VLSERVER_FL_PROBING 1 /* VL server is being probed */
393 #define AFS_VLSERVER_FL_IS_YFS 2 /* Server is YFS not AFS */
394 rwlock_t lock; /* Lock on addresses */
398 wait_queue_head_t probe_wq;
399 atomic_t probe_outstanding;
400 spinlock_t probe_lock;
402 unsigned int rtt; /* RTT as ktime/64 */
409 bool local_failure:1;
413 u16 name_len; /* Length of name */
414 char name[]; /* Server name, case-flattened */
418 * Weighted list of Volume Location servers.
420 struct afs_vlserver_entry {
421 u16 priority; /* Preference (as SRV) */
422 u16 weight; /* Weight (as SRV) */
423 enum dns_record_source source:8;
424 enum dns_lookup_status status:8;
425 struct afs_vlserver *server;
428 struct afs_vlserver_list {
432 u8 index; /* Server currently in use */
433 u8 preferred; /* Preferred server */
434 enum dns_record_source source:8;
435 enum dns_lookup_status status:8;
437 struct afs_vlserver_entry servers[];
443 * This is pointed to by cell->vldb_entries, indexed by name.
445 struct afs_vldb_entry {
446 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
449 #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
450 #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
451 #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
452 #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
453 #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
455 uuid_t fs_server[AFS_NMAXNSERVERS];
456 u32 addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
457 u8 fs_mask[AFS_NMAXNSERVERS];
458 #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
459 #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
460 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
462 u8 nr_servers; /* Number of server records */
464 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
468 * Record of fileserver with which we're actively communicating.
473 uuid_t uuid; /* Server ID */
474 struct afs_uuid _uuid;
477 struct afs_addr_list __rcu *addresses;
478 struct rb_node uuid_rb; /* Link in net->fs_servers */
479 struct list_head probe_link; /* Link in net->fs_probe_list */
480 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
481 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
482 struct hlist_node proc_link; /* Link in net->fs_proc */
483 struct afs_server *gc_next; /* Next server in manager's list */
484 time64_t unuse_time; /* Time at which last unused */
486 #define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
487 #define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
488 #define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
489 #define AFS_SERVER_FL_UPDATING 4
490 #define AFS_SERVER_FL_NO_IBULK 7 /* Fileserver doesn't support FS.InlineBulkStatus */
491 #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
492 #define AFS_SERVER_FL_IS_YFS 9 /* Server is YFS not AFS */
493 #define AFS_SERVER_FL_NO_RM2 10 /* Fileserver doesn't support YFS.RemoveFile2 */
494 #define AFS_SERVER_FL_HAVE_EPOCH 11 /* ->epoch is valid */
495 #define AFS_SERVER_FL_NEEDS_UPDATE 12 /* Fileserver address list is out of date */
496 atomic_t ref; /* Object refcount */
497 atomic_t active; /* Active user count */
498 u32 addr_version; /* Address list version */
499 u32 cm_epoch; /* Server RxRPC epoch */
500 unsigned int debug_id; /* Debugging ID for traces */
502 /* file service access */
503 rwlock_t fs_lock; /* access lock */
505 /* callback promise management */
506 struct rb_root cb_volumes; /* List of volume interests on this server */
507 unsigned cb_s_break; /* Break-everything counter. */
508 seqlock_t cb_break_lock; /* Volume finding lock */
511 unsigned long probed_at; /* Time last probe was dispatched (jiffies) */
512 wait_queue_head_t probe_wq;
513 atomic_t probe_outstanding;
514 spinlock_t probe_lock;
516 unsigned int rtt; /* RTT as ktime/64 */
523 bool local_failure:1;
525 bool said_rebooted:1;
526 bool said_inconsistent:1;
531 * Volume collation in the server's callback interest list.
533 struct afs_vol_interest {
534 struct rb_node srv_node; /* Link in server->cb_volumes */
535 struct hlist_head cb_interests; /* List of callback interests on the server */
538 afs_volid_t vid; /* Volume ID to match */
544 * Interest by a superblock on a server.
546 struct afs_cb_interest {
547 struct hlist_node cb_vlink; /* Link in vol_interest->cb_interests */
548 struct afs_vol_interest *vol_interest;
549 struct afs_server *server; /* Server on which this interest resides */
550 struct super_block *sb; /* Superblock on which inodes reside */
556 * Replaceable server list.
558 struct afs_server_entry {
559 struct afs_server *server;
560 struct afs_cb_interest *cb_interest;
563 struct afs_server_list {
565 unsigned char nr_servers;
566 unsigned char preferred; /* Preferred server */
567 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
568 unsigned int seq; /* Set to ->servers_seq when installed */
570 struct afs_server_entry servers[];
574 * Live AFS volume management.
577 afs_volid_t vid; /* volume ID */
579 time64_t update_at; /* Time at which to next update */
580 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
581 struct list_head proc_link; /* Link in cell->vl_proc */
583 #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
584 #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
585 #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
586 #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
587 #define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
588 #define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
589 #ifdef CONFIG_AFS_FSCACHE
590 struct fscache_cookie *cache; /* caching cookie */
592 struct afs_server_list *servers; /* List of servers on which volume resides */
593 rwlock_t servers_lock; /* Lock for ->servers */
594 unsigned int servers_seq; /* Incremented each time ->servers changes */
596 unsigned cb_v_break; /* Break-everything counter. */
597 rwlock_t cb_v_break_lock;
599 afs_voltype_t type; /* type of volume */
601 char type_force; /* force volume type (suppress R/O -> R/W) */
603 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
606 enum afs_lock_state {
607 AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
608 AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
609 AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
610 AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
611 AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
612 AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
613 AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
614 AFS_VNODE_LOCK_DELETED, /* The vnode has been deleted whilst we have a lock */
618 * AFS inode private data.
620 * Note that afs_alloc_inode() *must* reset anything that could incorrectly
621 * leak from one inode to another.
624 struct inode vfs_inode; /* the VFS's inode record */
626 struct afs_volume *volume; /* volume on which vnode resides */
627 struct afs_fid fid; /* the file identifier for this inode */
628 struct afs_file_status status; /* AFS status info for this file */
629 afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
630 #ifdef CONFIG_AFS_FSCACHE
631 struct fscache_cookie *cache; /* caching cookie */
633 struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
634 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
635 struct rw_semaphore validate_lock; /* lock for validating this vnode */
636 struct rw_semaphore rmdir_lock; /* Lock for rmdir vs sillyrename */
637 struct key *silly_key; /* Silly rename key */
638 spinlock_t wb_lock; /* lock for wb_keys */
639 spinlock_t lock; /* waitqueue/flags lock */
641 #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
642 #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
643 #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
644 #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
645 #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
646 #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
647 #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
648 #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
649 #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
651 struct list_head wb_keys; /* List of keys available for writeback */
652 struct list_head pending_locks; /* locks waiting to be granted */
653 struct list_head granted_locks; /* locks granted on this file */
654 struct delayed_work lock_work; /* work to be done in locking */
655 struct key *lock_key; /* Key to be used in lock ops */
656 ktime_t locked_at; /* Time at which lock obtained */
657 enum afs_lock_state lock_state : 8;
658 afs_lock_type_t lock_type : 8;
660 /* outstanding callback notification on this file */
661 struct afs_cb_interest __rcu *cb_interest; /* Server on which this resides */
662 unsigned int cb_s_break; /* Mass break counter on ->server */
663 unsigned int cb_v_break; /* Mass break counter on ->volume */
664 unsigned int cb_break; /* Break counter on vnode */
665 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
667 time64_t cb_expires_at; /* time at which callback expires */
670 static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
672 #ifdef CONFIG_AFS_FSCACHE
680 * cached security record for one user's attempt to access a vnode
683 struct key *key; /* RxRPC ticket holding a security context */
684 afs_access_t access; /* CallerAccess value for this key */
688 * Immutable cache of CallerAccess records from attempts to access vnodes.
689 * These may be shared between multiple vnodes.
693 struct hlist_node hash_node; /* Link in hash */
694 unsigned long h; /* Hash value for this permit list */
696 unsigned short nr_permits; /* Number of records */
697 bool invalidated; /* Invalidated due to key change */
698 struct afs_permit permits[]; /* List of permits sorted by key pointer */
702 * Error prioritisation and accumulation.
705 short error; /* Accumulated error */
706 bool responded; /* T if server responded */
710 * Cursor for iterating over a server's address list.
712 struct afs_addr_cursor {
713 struct afs_addr_list *alist; /* Current address list (pins ref) */
714 unsigned long tried; /* Tried addresses */
715 signed char index; /* Current address */
716 bool responded; /* T if the current address responded */
717 unsigned short nr_iterations; /* Number of address iterations */
723 * Cursor for iterating over a set of volume location servers.
725 struct afs_vl_cursor {
726 struct afs_addr_cursor ac;
727 struct afs_cell *cell; /* The cell we're querying */
728 struct afs_vlserver_list *server_list; /* Current server list (pins ref) */
729 struct afs_vlserver *server; /* Server on which this resides */
730 struct key *key; /* Key for the server */
731 unsigned long untried; /* Bitmask of untried servers */
732 short index; /* Current server */
734 unsigned short flags;
735 #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */
736 #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */
737 #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */
738 unsigned short nr_iterations; /* Number of server iterations */
742 * Fileserver operation methods.
744 struct afs_operation_ops {
745 void (*issue_afs_rpc)(struct afs_operation *op);
746 void (*issue_yfs_rpc)(struct afs_operation *op);
747 void (*success)(struct afs_operation *op);
748 void (*aborted)(struct afs_operation *op);
749 void (*edit_dir)(struct afs_operation *op);
750 void (*put)(struct afs_operation *op);
753 struct afs_vnode_param {
754 struct afs_vnode *vnode;
755 struct afs_fid fid; /* Fid to access */
756 struct afs_status_cb scb; /* Returned status and callback promise */
757 afs_dataversion_t dv_before; /* Data version before the call */
758 unsigned int cb_break_before; /* cb_break + cb_s_break before the call */
759 u8 dv_delta; /* Expected change in data version */
760 bool put_vnode; /* T if we have a ref on the vnode */
761 bool need_io_lock; /* T if we need the I/O lock on this */
765 * Fileserver operation wrapper, handling server and address rotation
766 * asynchronously. May make simultaneous calls to multiple servers.
768 struct afs_operation {
769 struct afs_net *net; /* Network namespace */
770 struct key *key; /* Key for the cell */
771 const struct afs_call_type *type; /* Type of call done */
772 const struct afs_operation_ops *ops;
774 /* Parameters/results for the operation */
775 struct afs_volume *volume; /* Volume being accessed */
776 struct afs_vnode_param file[2];
777 struct afs_vnode_param *more_files;
778 struct afs_volsync volsync;
779 struct dentry *dentry; /* Dentry to be altered */
780 struct dentry *dentry_2; /* Second dentry to be altered */
781 struct timespec64 mtime; /* Modification time to record */
782 short nr_files; /* Number of entries in file[], more_files */
784 unsigned int abort_code;
785 unsigned int debug_id;
787 unsigned int cb_v_break; /* Volume break counter before op */
788 unsigned int cb_s_break; /* Server break counter before op */
792 int which; /* Which ->file[] to fetch for */
795 int reason; /* enum afs_edit_dir_reason */
803 struct dentry *rehash;
808 struct afs_read *req;
811 struct afs_vnode *lvnode; /* vnode being locked */
812 afs_lock_type_t type;
815 struct address_space *mapping; /* Pages being written from */
816 pgoff_t first; /* first page in mapping to deal with */
817 pgoff_t last; /* last page in mapping to deal with */
818 unsigned first_offset; /* offset into mapping[first] */
819 unsigned last_to; /* amount of mapping[last] */
825 struct yfs_acl *yacl;
827 struct afs_volume_status vs;
832 /* Fileserver iteration state */
833 struct afs_addr_cursor ac;
834 struct afs_server_list *server_list; /* Current server list (pins ref) */
835 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
836 struct afs_call *call;
837 unsigned long untried; /* Bitmask of untried servers */
838 short index; /* Current server */
839 unsigned short nr_iterations; /* Number of server iterations */
842 #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */
843 #define AFS_OPERATION_VBUSY 0x0002 /* Set if seen VBUSY */
844 #define AFS_OPERATION_VMOVED 0x0004 /* Set if seen VMOVED */
845 #define AFS_OPERATION_VNOVOL 0x0008 /* Set if seen VNOVOL */
846 #define AFS_OPERATION_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
847 #define AFS_OPERATION_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
848 #define AFS_OPERATION_UNINTR 0x0040 /* Set if op is uninterruptible */
849 #define AFS_OPERATION_DOWNGRADE 0x0080 /* Set to retry with downgraded opcode */
850 #define AFS_OPERATION_LOCK_0 0x0100 /* Set if have io_lock on file[0] */
851 #define AFS_OPERATION_LOCK_1 0x0200 /* Set if have io_lock on file[1] */
855 * Cache auxiliary data.
857 struct afs_vnode_cache_aux {
861 #include <trace/events/afs.h>
863 /*****************************************************************************/
867 static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
870 refcount_inc(&alist->usage);
873 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
876 extern void afs_put_addrlist(struct afs_addr_list *);
877 extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
878 const char *, size_t, char,
879 unsigned short, unsigned short);
880 extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
881 extern bool afs_iterate_addresses(struct afs_addr_cursor *);
882 extern int afs_end_cursor(struct afs_addr_cursor *);
884 extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
885 extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
890 #ifdef CONFIG_AFS_FSCACHE
891 extern struct fscache_netfs afs_cache_netfs;
892 extern struct fscache_cookie_def afs_cell_cache_index_def;
893 extern struct fscache_cookie_def afs_volume_cache_index_def;
894 extern struct fscache_cookie_def afs_vnode_cache_index_def;
896 #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
897 #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
898 #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
904 extern void afs_init_callback_state(struct afs_server *);
905 extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
906 extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
907 extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
909 extern int afs_register_server_cb_interest(struct afs_vnode *,
910 struct afs_server_list *, unsigned int);
911 extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
912 extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
914 static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
917 refcount_inc(&cbi->usage);
921 static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
923 return vnode->cb_break + vnode->cb_v_break;
926 static inline bool afs_cb_is_broken(unsigned int cb_break,
927 const struct afs_vnode *vnode,
928 const struct afs_cb_interest *cbi)
930 return !cbi || cb_break != (vnode->cb_break +
931 vnode->volume->cb_v_break);
937 extern int afs_cell_init(struct afs_net *, const char *);
938 extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
939 extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
941 extern struct afs_cell *afs_get_cell(struct afs_cell *);
942 extern void afs_put_cell(struct afs_net *, struct afs_cell *);
943 extern void afs_manage_cells(struct work_struct *);
944 extern void afs_cells_timer(struct timer_list *);
945 extern void __net_exit afs_cell_purge(struct afs_net *);
950 extern bool afs_cm_incoming_call(struct afs_call *);
955 extern const struct file_operations afs_dir_file_operations;
956 extern const struct inode_operations afs_dir_inode_operations;
957 extern const struct address_space_operations afs_dir_aops;
958 extern const struct dentry_operations afs_fs_dentry_operations;
960 extern void afs_d_release(struct dentry *);
965 extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
966 enum afs_edit_dir_reason);
967 extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
972 extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
973 struct dentry *, struct key *);
974 extern int afs_silly_iput(struct dentry *, struct inode *);
979 extern const struct inode_operations afs_dynroot_inode_operations;
980 extern const struct dentry_operations afs_dynroot_dentry_operations;
982 extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
983 extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
984 extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
985 extern int afs_dynroot_populate(struct super_block *);
986 extern void afs_dynroot_depopulate(struct super_block *);
991 extern const struct address_space_operations afs_fs_aops;
992 extern const struct inode_operations afs_file_inode_operations;
993 extern const struct file_operations afs_file_operations;
995 extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
996 extern void afs_put_wb_key(struct afs_wb_key *);
997 extern int afs_open(struct inode *, struct file *);
998 extern int afs_release(struct inode *, struct file *);
999 extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
1000 extern int afs_page_filler(void *, struct page *);
1001 extern void afs_put_read(struct afs_read *);
1003 static inline struct afs_read *afs_get_read(struct afs_read *req)
1005 refcount_inc(&req->usage);
1012 extern struct workqueue_struct *afs_lock_manager;
1014 extern void afs_lock_op_done(struct afs_call *);
1015 extern void afs_lock_work(struct work_struct *);
1016 extern void afs_lock_may_be_available(struct afs_vnode *);
1017 extern int afs_lock(struct file *, int, struct file_lock *);
1018 extern int afs_flock(struct file *, int, struct file_lock *);
1023 extern void afs_fs_fetch_status(struct afs_operation *);
1024 extern void afs_fs_fetch_data(struct afs_operation *);
1025 extern void afs_fs_create_file(struct afs_operation *);
1026 extern void afs_fs_make_dir(struct afs_operation *);
1027 extern void afs_fs_remove_file(struct afs_operation *);
1028 extern void afs_fs_remove_dir(struct afs_operation *);
1029 extern void afs_fs_link(struct afs_operation *);
1030 extern void afs_fs_symlink(struct afs_operation *);
1031 extern void afs_fs_rename(struct afs_operation *);
1032 extern void afs_fs_store_data(struct afs_operation *);
1033 extern void afs_fs_setattr(struct afs_operation *);
1034 extern void afs_fs_get_volume_status(struct afs_operation *);
1035 extern void afs_fs_set_lock(struct afs_operation *);
1036 extern void afs_fs_extend_lock(struct afs_operation *);
1037 extern void afs_fs_release_lock(struct afs_operation *);
1038 extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
1039 struct afs_addr_cursor *, struct key *);
1040 extern bool afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
1041 struct afs_addr_cursor *, struct key *);
1042 extern void afs_fs_inline_bulk_status(struct afs_operation *);
1049 extern void afs_fs_fetch_acl(struct afs_operation *);
1050 extern void afs_fs_store_acl(struct afs_operation *);
1055 extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
1056 extern int afs_put_operation(struct afs_operation *);
1057 extern bool afs_begin_vnode_operation(struct afs_operation *);
1058 extern void afs_wait_for_operation(struct afs_operation *);
1059 extern int afs_do_sync_operation(struct afs_operation *);
1061 static inline void afs_op_nomem(struct afs_operation *op)
1063 op->error = -ENOMEM;
1066 static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
1067 struct afs_vnode *vnode)
1069 op->file[n].vnode = vnode;
1070 op->file[n].need_io_lock = true;
1073 static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
1074 const struct afs_fid *fid)
1076 op->file[n].fid = *fid;
1082 extern void afs_fileserver_probe_result(struct afs_call *);
1083 extern void afs_fs_probe_fileserver(struct afs_net *, struct afs_server *, struct key *, bool);
1084 extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long);
1085 extern void afs_fs_probe_dispatcher(struct work_struct *);
1090 extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
1091 extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1092 extern int afs_ilookup5_test_by_fid(struct inode *, void *);
1093 extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
1094 extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
1095 extern struct inode *afs_root_iget(struct super_block *, struct key *);
1096 extern void afs_zap_data(struct afs_vnode *);
1097 extern bool afs_check_validity(struct afs_vnode *);
1098 extern int afs_validate(struct afs_vnode *, struct key *);
1099 extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
1100 extern int afs_setattr(struct dentry *, struct iattr *);
1101 extern void afs_evict_inode(struct inode *);
1102 extern int afs_drop_inode(struct inode *);
1107 extern struct workqueue_struct *afs_wq;
1108 extern int afs_net_id;
1110 static inline struct afs_net *afs_net(struct net *net)
1112 return net_generic(net, afs_net_id);
1115 static inline struct afs_net *afs_sb2net(struct super_block *sb)
1117 return afs_net(AFS_FS_S(sb)->net_ns);
1120 static inline struct afs_net *afs_d2net(struct dentry *dentry)
1122 return afs_sb2net(dentry->d_sb);
1125 static inline struct afs_net *afs_i2net(struct inode *inode)
1127 return afs_sb2net(inode->i_sb);
1130 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1132 return afs_i2net(&vnode->vfs_inode);
1135 static inline struct afs_net *afs_sock2net(struct sock *sk)
1137 return net_generic(sock_net(sk), afs_net_id);
1140 static inline void __afs_stat(atomic_t *s)
1145 #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1150 extern int afs_abort_to_error(u32);
1151 extern void afs_prioritise_error(struct afs_error *, int, u32);
1156 extern const struct inode_operations afs_mntpt_inode_operations;
1157 extern const struct inode_operations afs_autocell_inode_operations;
1158 extern const struct file_operations afs_mntpt_file_operations;
1160 extern struct vfsmount *afs_d_automount(struct path *);
1161 extern void afs_mntpt_kill_timer(void);
1166 #ifdef CONFIG_PROC_FS
1167 extern int __net_init afs_proc_init(struct afs_net *);
1168 extern void __net_exit afs_proc_cleanup(struct afs_net *);
1169 extern int afs_proc_cell_setup(struct afs_cell *);
1170 extern void afs_proc_cell_remove(struct afs_cell *);
1171 extern void afs_put_sysnames(struct afs_sysnames *);
1173 static inline int afs_proc_init(struct afs_net *net) { return 0; }
1174 static inline void afs_proc_cleanup(struct afs_net *net) {}
1175 static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
1176 static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
1177 static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1183 extern bool afs_select_fileserver(struct afs_operation *);
1184 extern bool afs_select_current_fileserver(struct afs_operation *);
1185 extern void afs_dump_edestaddrreq(const struct afs_operation *);
1190 extern struct workqueue_struct *afs_async_calls;
1192 extern int __net_init afs_open_socket(struct afs_net *);
1193 extern void __net_exit afs_close_socket(struct afs_net *);
1194 extern void afs_charge_preallocation(struct work_struct *);
1195 extern void afs_put_call(struct afs_call *);
1196 extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t);
1197 extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
1198 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1199 const struct afs_call_type *,
1201 extern void afs_flat_call_destructor(struct afs_call *);
1202 extern void afs_send_empty_reply(struct afs_call *);
1203 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
1204 extern int afs_extract_data(struct afs_call *, bool);
1205 extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
1207 static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
1211 op->type = call->type;
1213 call->key = op->key;
1214 call->cbi = afs_get_cb_interest(op->cbi);
1215 call->intr = !(op->flags & AFS_OPERATION_UNINTR);
1216 afs_make_call(&op->ac, call, gfp);
1219 static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
1221 call->kvec[0].iov_base = buf;
1222 call->kvec[0].iov_len = size;
1223 iov_iter_kvec(&call->def_iter, READ, call->kvec, 1, size);
1226 static inline void afs_extract_to_tmp(struct afs_call *call)
1228 afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
1231 static inline void afs_extract_to_tmp64(struct afs_call *call)
1233 afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
1236 static inline void afs_extract_discard(struct afs_call *call, size_t size)
1238 iov_iter_discard(&call->def_iter, READ, size);
1241 static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
1243 afs_extract_begin(call, call->buffer, size);
1246 static inline int afs_transfer_reply(struct afs_call *call)
1248 return afs_extract_data(call, false);
1251 static inline bool afs_check_call_state(struct afs_call *call,
1252 enum afs_call_state state)
1254 return READ_ONCE(call->state) == state;
1257 static inline bool afs_set_call_state(struct afs_call *call,
1258 enum afs_call_state from,
1259 enum afs_call_state to)
1263 spin_lock_bh(&call->state_lock);
1264 if (call->state == from) {
1266 trace_afs_call_state(call, from, to, 0, 0);
1269 spin_unlock_bh(&call->state_lock);
1273 static inline void afs_set_call_complete(struct afs_call *call,
1274 int error, u32 remote_abort)
1276 enum afs_call_state state;
1279 spin_lock_bh(&call->state_lock);
1280 state = call->state;
1281 if (state != AFS_CALL_COMPLETE) {
1282 call->abort_code = remote_abort;
1283 call->error = error;
1284 call->state = AFS_CALL_COMPLETE;
1285 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
1286 error, remote_abort);
1289 spin_unlock_bh(&call->state_lock);
1291 trace_afs_call_done(call);
1293 /* Asynchronous calls have two refs to release - one from the alloc and
1294 * one queued with the work item - and we can't just deallocate the
1295 * call because the work item may be queued again.
1305 extern void afs_put_permits(struct afs_permits *);
1306 extern void afs_clear_permits(struct afs_vnode *);
1307 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1308 struct afs_status_cb *);
1309 extern void afs_zap_permits(struct rcu_head *);
1310 extern struct key *afs_request_key(struct afs_cell *);
1311 extern struct key *afs_request_key_rcu(struct afs_cell *);
1312 extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
1313 extern int afs_permission(struct inode *, int);
1314 extern void __exit afs_clean_up_permit_cache(void);
1319 extern spinlock_t afs_server_peer_lock;
1321 extern struct afs_server *afs_find_server(struct afs_net *,
1322 const struct sockaddr_rxrpc *);
1323 extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
1324 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
1325 extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
1326 extern struct afs_server *afs_use_server(struct afs_server *, enum afs_server_trace);
1327 extern void afs_unuse_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1328 extern void afs_unuse_server_notime(struct afs_net *, struct afs_server *, enum afs_server_trace);
1329 extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1330 extern void afs_manage_servers(struct work_struct *);
1331 extern void afs_servers_timer(struct timer_list *);
1332 extern void afs_fs_probe_timer(struct timer_list *);
1333 extern void __net_exit afs_purge_servers(struct afs_net *);
1334 extern bool afs_check_server_record(struct afs_operation *, struct afs_server *);
1336 static inline void afs_inc_servers_outstanding(struct afs_net *net)
1338 atomic_inc(&net->servers_outstanding);
1341 static inline void afs_dec_servers_outstanding(struct afs_net *net)
1343 if (atomic_dec_and_test(&net->servers_outstanding))
1344 wake_up_var(&net->servers_outstanding);
1347 static inline bool afs_is_probing_server(struct afs_server *server)
1349 return list_empty(&server->probe_link);
1355 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1357 refcount_inc(&slist->usage);
1361 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1362 extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1363 struct afs_vldb_entry *,
1365 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1370 extern int __init afs_fs_init(void);
1371 extern void afs_fs_exit(void);
1376 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
1378 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
1379 extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *,
1380 struct key *, struct afs_vlserver *, unsigned int);
1381 extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
1386 extern void afs_vlserver_probe_result(struct afs_call *);
1387 extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
1388 extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
1393 extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
1394 struct afs_cell *, struct key *);
1395 extern bool afs_select_vlserver(struct afs_vl_cursor *);
1396 extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
1397 extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
1402 static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
1404 atomic_inc(&vlserver->usage);
1408 static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
1411 atomic_inc(&vllist->usage);
1415 extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
1416 extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
1417 extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
1418 extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
1419 extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
1420 const void *, size_t);
1425 static inline struct afs_volume *afs_get_volume(struct afs_volume *volume)
1428 atomic_inc(&volume->usage);
1432 extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1433 extern void afs_activate_volume(struct afs_volume *);
1434 extern void afs_deactivate_volume(struct afs_volume *);
1435 extern void afs_put_volume(struct afs_net *, struct afs_volume *);
1436 extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
1441 extern int afs_set_page_dirty(struct page *);
1442 extern int afs_write_begin(struct file *file, struct address_space *mapping,
1443 loff_t pos, unsigned len, unsigned flags,
1444 struct page **pagep, void **fsdata);
1445 extern int afs_write_end(struct file *file, struct address_space *mapping,
1446 loff_t pos, unsigned len, unsigned copied,
1447 struct page *page, void *fsdata);
1448 extern int afs_writepage(struct page *, struct writeback_control *);
1449 extern int afs_writepages(struct address_space *, struct writeback_control *);
1450 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
1451 extern int afs_fsync(struct file *, loff_t, loff_t, int);
1452 extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
1453 extern void afs_prune_wb_keys(struct afs_vnode *);
1454 extern int afs_launder_page(struct page *);
1459 extern const struct xattr_handler *afs_xattr_handlers[];
1460 extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
1465 extern void yfs_fs_fetch_file_status(struct afs_operation *);
1466 extern void yfs_fs_fetch_data(struct afs_operation *);
1467 extern void yfs_fs_create_file(struct afs_operation *);
1468 extern void yfs_fs_make_dir(struct afs_operation *);
1469 extern void yfs_fs_remove_file2(struct afs_operation *);
1470 extern void yfs_fs_remove_file(struct afs_operation *);
1471 extern void yfs_fs_remove_dir(struct afs_operation *);
1472 extern void yfs_fs_link(struct afs_operation *);
1473 extern void yfs_fs_symlink(struct afs_operation *);
1474 extern void yfs_fs_rename(struct afs_operation *);
1475 extern void yfs_fs_store_data(struct afs_operation *);
1476 extern void yfs_fs_setattr(struct afs_operation *);
1477 extern void yfs_fs_get_volume_status(struct afs_operation *);
1478 extern void yfs_fs_set_lock(struct afs_operation *);
1479 extern void yfs_fs_extend_lock(struct afs_operation *);
1480 extern void yfs_fs_release_lock(struct afs_operation *);
1481 extern void yfs_fs_fetch_status(struct afs_operation *);
1482 extern void yfs_fs_inline_bulk_status(struct afs_operation *);
1485 struct afs_acl *acl; /* Dir/file/symlink ACL */
1486 struct afs_acl *vol_acl; /* Whole volume ACL */
1487 u32 inherit_flag; /* True if ACL is inherited from parent dir */
1488 u32 num_cleaned; /* Number of ACEs removed due to subject removal */
1490 #define YFS_ACL_WANT_ACL 0x01 /* Set if caller wants ->acl */
1491 #define YFS_ACL_WANT_VOL_ACL 0x02 /* Set if caller wants ->vol_acl */
1494 extern void yfs_free_opaque_acl(struct yfs_acl *);
1495 extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
1496 extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
1499 * Miscellaneous inline functions.
1501 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1503 return container_of(inode, struct afs_vnode, vfs_inode);
1506 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1508 return &vnode->vfs_inode;
1511 static inline void afs_check_for_remote_deletion(struct afs_operation *op,
1512 struct afs_vnode *vnode)
1514 if (op->error == -ENOENT) {
1515 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1516 afs_break_callback(vnode, afs_cb_break_for_deleted);
1521 * Note that a dentry got changed. We need to set d_fsdata to the data version
1522 * number derived from the result of the operation. It doesn't matter if
1523 * d_fsdata goes backwards as we'll just revalidate.
1525 static inline void afs_update_dentry_version(struct afs_operation *op,
1526 struct afs_vnode_param *dir_vp,
1527 struct dentry *dentry)
1531 (void *)(unsigned long)dir_vp->scb.status.data_version;
1534 static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1536 trace_afs_io_error(call->debug_id, -EIO, where);
1540 static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1542 trace_afs_file_error(vnode, -EIO, where);
1546 /*****************************************************************************/
1550 extern unsigned afs_debug;
1552 #define dbgprintk(FMT,...) \
1553 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1555 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1556 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1557 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1560 #if defined(__KDEBUG)
1561 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1562 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1563 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1565 #elif defined(CONFIG_AFS_DEBUG)
1566 #define AFS_DEBUG_KENTER 0x01
1567 #define AFS_DEBUG_KLEAVE 0x02
1568 #define AFS_DEBUG_KDEBUG 0x04
1570 #define _enter(FMT,...) \
1572 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
1573 kenter(FMT,##__VA_ARGS__); \
1576 #define _leave(FMT,...) \
1578 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
1579 kleave(FMT,##__VA_ARGS__); \
1582 #define _debug(FMT,...) \
1584 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
1585 kdebug(FMT,##__VA_ARGS__); \
1589 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1590 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1591 #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
1595 * debug assertion checking
1597 #if 1 // defined(__KDEBUGALL)
1601 if (unlikely(!(X))) { \
1602 printk(KERN_ERR "\n"); \
1603 printk(KERN_ERR "AFS: Assertion failed\n"); \
1608 #define ASSERTCMP(X, OP, Y) \
1610 if (unlikely(!((X) OP (Y)))) { \
1611 printk(KERN_ERR "\n"); \
1612 printk(KERN_ERR "AFS: Assertion failed\n"); \
1613 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1614 (unsigned long)(X), (unsigned long)(Y)); \
1615 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1616 (unsigned long)(X), (unsigned long)(Y)); \
1621 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1623 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1624 printk(KERN_ERR "\n"); \
1625 printk(KERN_ERR "AFS: Assertion failed\n"); \
1626 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1627 (unsigned long)(L), (unsigned long)(N), \
1628 (unsigned long)(H)); \
1629 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1630 (unsigned long)(L), (unsigned long)(N), \
1631 (unsigned long)(H)); \
1636 #define ASSERTIF(C, X) \
1638 if (unlikely((C) && !(X))) { \
1639 printk(KERN_ERR "\n"); \
1640 printk(KERN_ERR "AFS: Assertion failed\n"); \
1645 #define ASSERTIFCMP(C, X, OP, Y) \
1647 if (unlikely((C) && !((X) OP (Y)))) { \
1648 printk(KERN_ERR "\n"); \
1649 printk(KERN_ERR "AFS: Assertion failed\n"); \
1650 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1651 (unsigned long)(X), (unsigned long)(Y)); \
1652 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1653 (unsigned long)(X), (unsigned long)(Y)); \
1664 #define ASSERTCMP(X, OP, Y) \
1668 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1672 #define ASSERTIF(C, X) \
1676 #define ASSERTIFCMP(C, X, OP, Y) \
1680 #endif /* __KDEBUGALL */