12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2ec26815aSDavid Howells /* internal AFS stuff
31da177e4SLinus Torvalds *
408e0e7c8SDavid Howells * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
51da177e4SLinus Torvalds * Written by David Howells (dhowells@redhat.com)
61da177e4SLinus Torvalds */
71da177e4SLinus Torvalds
81da177e4SLinus Torvalds #include <linux/compiler.h>
91da177e4SLinus Torvalds #include <linux/kernel.h>
108a79790bSTina Ruchandani #include <linux/ktime.h>
111da177e4SLinus Torvalds #include <linux/fs.h>
125970e15dSJeff Layton #include <linux/filelock.h>
131da177e4SLinus Torvalds #include <linux/pagemap.h>
1408e0e7c8SDavid Howells #include <linux/rxrpc.h>
1500d3b7a4SDavid Howells #include <linux/key.h>
16e8edc6e0SAlexey Dobriyan #include <linux/workqueue.h>
1700c541eaSAndrew Morton #include <linux/sched.h>
1880e50be4SChristoph Hellwig #include <linux/fscache.h>
19e1da0222SJens Axboe #include <linux/backing-dev.h>
20ff548773SDavid Howells #include <linux/uuid.h>
210722f186SSouptick Joarder #include <linux/mm_types.h>
220a5143f2SDavid Howells #include <linux/dns_resolver.h>
23f044c884SDavid Howells #include <net/net_namespace.h>
245b86d4ffSDavid Howells #include <net/netns/generic.h>
255b86d4ffSDavid Howells #include <net/sock.h>
268324f0bcSDavid Howells #include <net/af_rxrpc.h>
2700c541eaSAndrew Morton
2808e0e7c8SDavid Howells #include "afs.h"
2908e0e7c8SDavid Howells #include "afs_vl.h"
3008e0e7c8SDavid Howells
3108e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15
3208e0e7c8SDavid Howells
3331143d5dSDavid Howells struct pagevec;
3408e0e7c8SDavid Howells struct afs_call;
35c4508464SDavid Howells struct afs_vnode;
3608e0e7c8SDavid Howells
376c6c1d63SDavid Howells /*
386c6c1d63SDavid Howells * Partial file-locking emulation mode. (The problem being that AFS3 only
396c6c1d63SDavid Howells * allows whole-file locks and no upgrading/downgrading).
406c6c1d63SDavid Howells */
416c6c1d63SDavid Howells enum afs_flock_mode {
426c6c1d63SDavid Howells afs_flock_mode_unset,
436c6c1d63SDavid Howells afs_flock_mode_local, /* Local locking only */
446c6c1d63SDavid Howells afs_flock_mode_openafs, /* Don't get server lock for a partial lock */
456c6c1d63SDavid Howells afs_flock_mode_strict, /* Always get a server lock for a partial lock */
466c6c1d63SDavid Howells afs_flock_mode_write, /* Get an exclusive server lock for a partial lock */
476c6c1d63SDavid Howells };
486c6c1d63SDavid Howells
4913fcc683SDavid Howells struct afs_fs_context {
5000d3b7a4SDavid Howells bool force; /* T to force cell type */
51bec5eb61Swanglei bool autocell; /* T if set auto mount operation */
524d673da1SDavid Howells bool dyn_root; /* T if dynamic root */
5313fcc683SDavid Howells bool no_cell; /* T if the source is "none" (for dynroot) */
546c6c1d63SDavid Howells enum afs_flock_mode flock_mode; /* Partial file-locking emulation mode */
5500d3b7a4SDavid Howells afs_voltype_t type; /* type of volume requested */
5613fcc683SDavid Howells unsigned int volnamesz; /* size of volume name */
5700d3b7a4SDavid Howells const char *volname; /* name of volume to mount */
585b86d4ffSDavid Howells struct afs_net *net; /* the AFS net namespace stuff */
5900d3b7a4SDavid Howells struct afs_cell *cell; /* cell in which to find volume */
6000d3b7a4SDavid Howells struct afs_volume *volume; /* volume record */
6100d3b7a4SDavid Howells struct key *key; /* key to use for secure mounting */
6200d3b7a4SDavid Howells };
6300d3b7a4SDavid Howells
648e8d7f13SDavid Howells enum afs_call_state {
6598bf40cdSDavid Howells AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
6698bf40cdSDavid Howells AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
6798bf40cdSDavid Howells AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
6898bf40cdSDavid Howells AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
6998bf40cdSDavid Howells AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
7098bf40cdSDavid Howells AFS_CALL_SV_REPLYING, /* Server: Replying */
7198bf40cdSDavid Howells AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
728e8d7f13SDavid Howells AFS_CALL_COMPLETE, /* Completed or failed */
738e8d7f13SDavid Howells };
74f044c884SDavid Howells
7508e0e7c8SDavid Howells /*
768b2a464cSDavid Howells * List of server addresses.
778b2a464cSDavid Howells */
788b2a464cSDavid Howells struct afs_addr_list {
79ddd2b85fSJann Horn struct rcu_head rcu;
808b2a464cSDavid Howells refcount_t usage;
81d2ddc776SDavid Howells u32 version; /* Version */
8268eb64c3SDavid Howells unsigned char max_addrs;
8368eb64c3SDavid Howells unsigned char nr_addrs;
843bf0fb6fSDavid Howells unsigned char preferred; /* Preferred address */
8568eb64c3SDavid Howells unsigned char nr_ipv4; /* Number of IPv4 addresses */
860a5143f2SDavid Howells enum dns_record_source source:8;
870a5143f2SDavid Howells enum dns_lookup_status status:8;
883bf0fb6fSDavid Howells unsigned long failed; /* Mask of addrs that failed locally/ICMP */
893bf0fb6fSDavid Howells unsigned long responded; /* Mask of addrs that responded */
908b2a464cSDavid Howells struct sockaddr_rxrpc addrs[];
9168eb64c3SDavid Howells #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
928b2a464cSDavid Howells };
938b2a464cSDavid Howells
948b2a464cSDavid Howells /*
9508e0e7c8SDavid Howells * a record of an in-progress RxRPC call
9608e0e7c8SDavid Howells */
9708e0e7c8SDavid Howells struct afs_call {
9808e0e7c8SDavid Howells const struct afs_call_type *type; /* type of call */
993bf0fb6fSDavid Howells struct afs_addr_list *alist; /* Address is alist[addr_ix] */
10008e0e7c8SDavid Howells wait_queue_head_t waitq; /* processes awaiting completion */
101341f741fSDavid Howells struct work_struct async_work; /* async I/O processor */
10208e0e7c8SDavid Howells struct work_struct work; /* actual work processor */
10308e0e7c8SDavid Howells struct rxrpc_call *rxcall; /* RxRPC call handle */
10408e0e7c8SDavid Howells struct key *key; /* security for this call */
105f044c884SDavid Howells struct afs_net *net; /* The network namespace */
106a6853b9cSDavid Howells struct afs_server *server; /* The fileserver record if fs op (pins ref) */
107a6853b9cSDavid Howells struct afs_vlserver *vlserver; /* The vlserver record if vl op */
10808e0e7c8SDavid Howells void *request; /* request data (first part) */
109f105da1aSDavid Howells size_t iov_len; /* Size of *iter to be used */
110fc276122SDavid Howells struct iov_iter def_iter; /* Default buffer/data iterator */
111bd80d8a8SDavid Howells struct iov_iter *write_iter; /* Iterator defining write to be made */
112fc276122SDavid Howells struct iov_iter *iter; /* Iterator currently in use */
113fc276122SDavid Howells union { /* Convenience for ->def_iter */
11412bdcf33SDavid Howells struct kvec kvec[1];
11512bdcf33SDavid Howells struct bio_vec bvec[1];
11612bdcf33SDavid Howells };
11708e0e7c8SDavid Howells void *buffer; /* reply receive buffer */
118ffba718eSDavid Howells union {
119ffba718eSDavid Howells long ret0; /* Value to reply with instead of 0 */
120ffba718eSDavid Howells struct afs_addr_list *ret_alist;
121ffba718eSDavid Howells struct afs_vldb_entry *ret_vldb;
122c3e9f888SDavid Howells char *ret_str;
123ffba718eSDavid Howells };
124e49c7b2fSDavid Howells struct afs_operation *op;
125ffba718eSDavid Howells unsigned int server_index;
126c56f9ec8SDavid Howells refcount_t ref;
1278e8d7f13SDavid Howells enum afs_call_state state;
12898bf40cdSDavid Howells spinlock_t state_lock;
12908e0e7c8SDavid Howells int error; /* error code */
130d001648eSDavid Howells u32 abort_code; /* Remote abort ID or 0 */
131db099c62SDavid Howells unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
13208e0e7c8SDavid Howells unsigned request_size; /* size of request data */
13308e0e7c8SDavid Howells unsigned reply_max; /* maximum size of reply */
134bcd89270SMarc Dionne unsigned count2; /* count used in unmarshalling */
13508e0e7c8SDavid Howells unsigned char unmarshall; /* unmarshalling phase */
1363bf0fb6fSDavid Howells unsigned char addr_ix; /* Address in ->alist */
137dde9f095SDavid Howells bool drop_ref; /* T if need to drop ref for incoming call */
138d001648eSDavid Howells bool need_attention; /* T if RxRPC poked us */
13956ff9c83SDavid Howells bool async; /* T if asynchronous */
140a68f4a27SDavid Howells bool upgrade; /* T to request service upgrade */
14120b8391fSDavid Howells bool intr; /* T if interruptible */
14238355eecSDavid Howells bool unmarshalling_error; /* T if an unmarshalling error occurred */
143bf99a53cSDavid Howells u16 service_id; /* Actual service ID (after upgrade) */
144a25e21f0SDavid Howells unsigned int debug_id; /* Trace ID */
14550a2c953SDavid Howells u32 operation_ID; /* operation ID for an incoming call */
14608e0e7c8SDavid Howells u32 count; /* count for use in unmarshalling */
14712bdcf33SDavid Howells union { /* place to extract temporary data */
14812bdcf33SDavid Howells struct {
14912bdcf33SDavid Howells __be32 tmp_u;
15012bdcf33SDavid Howells __be32 tmp;
15112bdcf33SDavid Howells } __attribute__((packed));
15212bdcf33SDavid Howells __be64 tmp64;
15312bdcf33SDavid Howells };
1547903192cSDavid Howells ktime_t issue_time; /* Time of issue of operation */
15508e0e7c8SDavid Howells };
15608e0e7c8SDavid Howells
15708e0e7c8SDavid Howells struct afs_call_type {
15800d3b7a4SDavid Howells const char *name;
159025db80cSDavid Howells unsigned int op; /* Really enum afs_fs_operation */
16000d3b7a4SDavid Howells
16108e0e7c8SDavid Howells /* deliver request or reply data to an call
16208e0e7c8SDavid Howells * - returning an error will cause the call to be aborted
16308e0e7c8SDavid Howells */
164d001648eSDavid Howells int (*deliver)(struct afs_call *call);
16508e0e7c8SDavid Howells
16608e0e7c8SDavid Howells /* clean up a call */
16708e0e7c8SDavid Howells void (*destructor)(struct afs_call *call);
168341f741fSDavid Howells
169341f741fSDavid Howells /* Work function */
170341f741fSDavid Howells void (*work)(struct work_struct *work);
1713bf0fb6fSDavid Howells
1723bf0fb6fSDavid Howells /* Call done function (gets called immediately on success or failure) */
1733bf0fb6fSDavid Howells void (*done)(struct afs_call *call);
17408e0e7c8SDavid Howells };
17508e0e7c8SDavid Howells
17608e0e7c8SDavid Howells /*
1774343d008SDavid Howells * Key available for writeback on a file.
1784343d008SDavid Howells */
1794343d008SDavid Howells struct afs_wb_key {
1804343d008SDavid Howells refcount_t usage;
1814343d008SDavid Howells struct key *key;
1824343d008SDavid Howells struct list_head vnode_link; /* Link in vnode->wb_keys */
1834343d008SDavid Howells };
1844343d008SDavid Howells
1854343d008SDavid Howells /*
186215804a9SDavid Howells * AFS open file information record. Pointed to by file->private_data.
187215804a9SDavid Howells */
188215804a9SDavid Howells struct afs_file {
189215804a9SDavid Howells struct key *key; /* The key this file was opened with */
1904343d008SDavid Howells struct afs_wb_key *wb; /* Writeback key record for this file */
191215804a9SDavid Howells };
192215804a9SDavid Howells
afs_file_key(struct file * file)193215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
194215804a9SDavid Howells {
195215804a9SDavid Howells struct afs_file *af = file->private_data;
196215804a9SDavid Howells
197215804a9SDavid Howells return af->key;
198215804a9SDavid Howells }
199215804a9SDavid Howells
200215804a9SDavid Howells /*
201196ee9cdSDavid Howells * Record of an outstanding read operation on a vnode.
202196ee9cdSDavid Howells */
203196ee9cdSDavid Howells struct afs_read {
204196ee9cdSDavid Howells loff_t pos; /* Where to start reading */
205e8e581a8SDavid Howells loff_t len; /* How much we're asking for */
206196ee9cdSDavid Howells loff_t actual_len; /* How much we're actually getting */
207f3ddee8dSDavid Howells loff_t file_size; /* File size returned by server */
208c69bf479SDavid Howells struct key *key; /* The key to use to reissue the read */
209c4508464SDavid Howells struct afs_vnode *vnode; /* The file being read into. */
2106a19114bSDavid Howells struct netfs_io_subrequest *subreq; /* Fscache helper read request this belongs to */
211f3ddee8dSDavid Howells afs_dataversion_t data_version; /* Version number returned by server */
212f3ddee8dSDavid Howells refcount_t usage;
213c4508464SDavid Howells unsigned int call_debug_id;
214196ee9cdSDavid Howells unsigned int nr_pages;
215c4508464SDavid Howells int error;
216c4508464SDavid Howells void (*done)(struct afs_read *);
217c4508464SDavid Howells void (*cleanup)(struct afs_read *);
218c4508464SDavid Howells struct iov_iter *iter; /* Iterator representing the buffer */
219c4508464SDavid Howells struct iov_iter def_iter; /* Default iterator */
220196ee9cdSDavid Howells };
221196ee9cdSDavid Howells
222196ee9cdSDavid Howells /*
22308e0e7c8SDavid Howells * AFS superblock private data
22408e0e7c8SDavid Howells * - there's one superblock per volume
22508e0e7c8SDavid Howells */
22608e0e7c8SDavid Howells struct afs_super_info {
2275b86d4ffSDavid Howells struct net *net_ns; /* Network namespace */
22849566f6fSDavid Howells struct afs_cell *cell; /* The cell in which the volume resides */
22908e0e7c8SDavid Howells struct afs_volume *volume; /* volume record */
2306c6c1d63SDavid Howells enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
2314d673da1SDavid Howells bool dyn_root; /* True if dynamic root */
23208e0e7c8SDavid Howells };
23308e0e7c8SDavid Howells
AFS_FS_S(struct super_block * sb)23408e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
23508e0e7c8SDavid Howells {
23608e0e7c8SDavid Howells return sb->s_fs_info;
23708e0e7c8SDavid Howells }
23808e0e7c8SDavid Howells
23908e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
24008e0e7c8SDavid Howells
24108e0e7c8SDavid Howells /*
2426f8880d8SDavid Howells * Set of substitutes for @sys.
2436f8880d8SDavid Howells */
2446f8880d8SDavid Howells struct afs_sysnames {
2456f8880d8SDavid Howells #define AFS_NR_SYSNAME 16
2466f8880d8SDavid Howells char *subs[AFS_NR_SYSNAME];
2476f8880d8SDavid Howells refcount_t usage;
2486f8880d8SDavid Howells unsigned short nr;
2496f8880d8SDavid Howells char blank[1];
2506f8880d8SDavid Howells };
2516f8880d8SDavid Howells
2526f8880d8SDavid Howells /*
253f044c884SDavid Howells * AFS network namespace record.
254f044c884SDavid Howells */
255f044c884SDavid Howells struct afs_net {
2565b86d4ffSDavid Howells struct net *net; /* Backpointer to the owning net namespace */
257f044c884SDavid Howells struct afs_uuid uuid;
258f044c884SDavid Howells bool live; /* F if this namespace is being removed */
259f044c884SDavid Howells
260f044c884SDavid Howells /* AF_RXRPC I/O stuff */
261f044c884SDavid Howells struct socket *socket;
262f044c884SDavid Howells struct afs_call *spare_incoming_call;
263f044c884SDavid Howells struct work_struct charge_preallocation_work;
264f044c884SDavid Howells struct mutex socket_mutex;
265f044c884SDavid Howells atomic_t nr_outstanding_calls;
266f044c884SDavid Howells atomic_t nr_superblocks;
267f044c884SDavid Howells
268f044c884SDavid Howells /* Cell database */
269989782dcSDavid Howells struct rb_root cells;
27092e3cc91SDavid Howells struct afs_cell *ws_cell;
271989782dcSDavid Howells struct work_struct cells_manager;
272989782dcSDavid Howells struct timer_list cells_timer;
273989782dcSDavid Howells atomic_t cells_outstanding;
27492e3cc91SDavid Howells struct rw_semaphore cells_lock;
2758a070a96SDavid Howells struct mutex cells_alias_lock;
276f044c884SDavid Howells
2770da0b7fdSDavid Howells struct mutex proc_cells_lock;
2786b3944e4SDavid Howells struct hlist_head proc_cells;
279f044c884SDavid Howells
280d2ddc776SDavid Howells /* Known servers. Theoretically each fileserver can only be in one
281d2ddc776SDavid Howells * cell, but in practice, people create aliases and subsets and there's
282d2ddc776SDavid Howells * no easy way to distinguish them.
283d2ddc776SDavid Howells */
284f6cbb368SDavid Howells seqlock_t fs_lock; /* For fs_servers, fs_probe_*, fs_proc */
285d2ddc776SDavid Howells struct rb_root fs_servers; /* afs_server (by server UUID or address) */
286f6cbb368SDavid Howells struct list_head fs_probe_fast; /* List of afs_server to probe at 30s intervals */
287f6cbb368SDavid Howells struct list_head fs_probe_slow; /* List of afs_server to probe at 5m intervals */
288d2ddc776SDavid Howells struct hlist_head fs_proc; /* procfs servers list */
289d2ddc776SDavid Howells
290d2ddc776SDavid Howells struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
291d2ddc776SDavid Howells struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
292d2ddc776SDavid Howells seqlock_t fs_addr_lock; /* For fs_addresses[46] */
293d2ddc776SDavid Howells
294d2ddc776SDavid Howells struct work_struct fs_manager;
295d2ddc776SDavid Howells struct timer_list fs_timer;
296f6cbb368SDavid Howells
297f6cbb368SDavid Howells struct work_struct fs_prober;
298f6cbb368SDavid Howells struct timer_list fs_probe_timer;
299d2ddc776SDavid Howells atomic_t servers_outstanding;
300f044c884SDavid Howells
301f044c884SDavid Howells /* File locking renewal management */
302f044c884SDavid Howells struct mutex lock_manager_mutex;
303f044c884SDavid Howells
304f044c884SDavid Howells /* Misc */
3050da0b7fdSDavid Howells struct super_block *dynroot_sb; /* Dynamic root mount superblock */
306f044c884SDavid Howells struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
3076f8880d8SDavid Howells struct afs_sysnames *sysnames;
3086f8880d8SDavid Howells rwlock_t sysnames_lock;
309d55b4da4SDavid Howells
310d55b4da4SDavid Howells /* Statistics counters */
311d55b4da4SDavid Howells atomic_t n_lookup; /* Number of lookups done */
312d55b4da4SDavid Howells atomic_t n_reval; /* Number of dentries needing revalidation */
313d55b4da4SDavid Howells atomic_t n_inval; /* Number of invalidations by the server */
314508cae68SMatthew Wilcox (Oracle) atomic_t n_relpg; /* Number of invalidations by release_folio */
315d55b4da4SDavid Howells atomic_t n_read_dir; /* Number of directory pages read */
31663a4681fSDavid Howells atomic_t n_dir_cr; /* Number of directory entry creation edits */
31763a4681fSDavid Howells atomic_t n_dir_rm; /* Number of directory entry removal edits */
31876a5cb6fSDavid Howells atomic_t n_stores; /* Number of store ops */
31976a5cb6fSDavid Howells atomic_long_t n_store_bytes; /* Number of bytes stored */
32076a5cb6fSDavid Howells atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
32176a5cb6fSDavid Howells atomic_t n_fetches; /* Number of data fetch ops */
322f044c884SDavid Howells };
323f044c884SDavid Howells
3246f8880d8SDavid Howells extern const char afs_init_sysname[];
325f044c884SDavid Howells
326989782dcSDavid Howells enum afs_cell_state {
327989782dcSDavid Howells AFS_CELL_UNSET,
328989782dcSDavid Howells AFS_CELL_ACTIVATING,
329989782dcSDavid Howells AFS_CELL_ACTIVE,
330989782dcSDavid Howells AFS_CELL_DEACTIVATING,
331989782dcSDavid Howells AFS_CELL_INACTIVE,
332989782dcSDavid Howells AFS_CELL_FAILED,
3331d0e850aSDavid Howells AFS_CELL_REMOVED,
334989782dcSDavid Howells };
335989782dcSDavid Howells
336f044c884SDavid Howells /*
337d2ddc776SDavid Howells * AFS cell record.
338d2ddc776SDavid Howells *
339d2ddc776SDavid Howells * This is a tricky concept to get right as it is possible to create aliases
340d2ddc776SDavid Howells * simply by pointing AFSDB/SRV records for two names at the same set of VL
341d2ddc776SDavid Howells * servers; it is also possible to do things like setting up two sets of VL
342d2ddc776SDavid Howells * servers, one of which provides a superset of the volumes provided by the
343d2ddc776SDavid Howells * other (for internal/external division, for example).
344d2ddc776SDavid Howells *
345d2ddc776SDavid Howells * Cells only exist in the sense that (a) a cell's name maps to a set of VL
346d2ddc776SDavid Howells * servers and (b) a cell's name is used by the client to select the key to use
347d2ddc776SDavid Howells * for authentication and encryption. The cell name is not typically used in
348d2ddc776SDavid Howells * the protocol.
349d2ddc776SDavid Howells *
3508a070a96SDavid Howells * Two cells are determined to be aliases if they have an explicit alias (YFS
3518a070a96SDavid Howells * only), share any VL servers in common or have at least one volume in common.
3528a070a96SDavid Howells * "In common" means that the address list of the VL servers or the fileservers
3538a070a96SDavid Howells * share at least one endpoint.
35408e0e7c8SDavid Howells */
35508e0e7c8SDavid Howells struct afs_cell {
356989782dcSDavid Howells union {
357989782dcSDavid Howells struct rcu_head rcu;
358989782dcSDavid Howells struct rb_node net_node; /* Node in net->cells */
359989782dcSDavid Howells };
360989782dcSDavid Howells struct afs_net *net;
3618a070a96SDavid Howells struct afs_cell *alias_of; /* The cell this is an alias of */
3628a070a96SDavid Howells struct afs_volume *root_volume; /* The root.cell volume if there is one */
36300d3b7a4SDavid Howells struct key *anonymous_key; /* anonymous user key for this cell */
364989782dcSDavid Howells struct work_struct manager; /* Manager for init/deinit/dns */
3656b3944e4SDavid Howells struct hlist_node proc_link; /* /proc cell list link */
366989782dcSDavid Howells time64_t dns_expiry; /* Time AFSDB/SRV record expires */
367989782dcSDavid Howells time64_t last_inactive; /* Time of last drop of usage count */
368c56f9ec8SDavid Howells refcount_t ref; /* Struct refcount */
36988c853c3SDavid Howells atomic_t active; /* Active usage counter */
370989782dcSDavid Howells unsigned long flags;
371d5c32c89SDavid Howells #define AFS_CELL_FL_NO_GC 0 /* The cell was added manually, don't auto-gc */
372d5c32c89SDavid Howells #define AFS_CELL_FL_DO_LOOKUP 1 /* DNS lookup requested */
3738a070a96SDavid Howells #define AFS_CELL_FL_CHECK_ALIAS 2 /* Need to check for aliases */
374989782dcSDavid Howells enum afs_cell_state state;
375989782dcSDavid Howells short error;
376d5c32c89SDavid Howells enum dns_record_source dns_source:8; /* Latest source of data from lookup */
377d5c32c89SDavid Howells enum dns_lookup_status dns_status:8; /* Latest status of data from lookup */
378d5c32c89SDavid Howells unsigned int dns_lookup_count; /* Counter of DNS lookups */
379dca54a7bSDavid Howells unsigned int debug_id;
380989782dcSDavid Howells
38120325960SDavid Howells /* The volumes belonging to this cell */
382*0b2bf6fbSDavid Howells spinlock_t vs_lock; /* Lock for server->volumes */
38320325960SDavid Howells struct rb_root volumes; /* Tree of volumes on this server */
38420325960SDavid Howells struct hlist_head proc_volumes; /* procfs volume list */
38520325960SDavid Howells seqlock_t volume_lock; /* For volumes */
38620325960SDavid Howells
387d2ddc776SDavid Howells /* Active fileserver interaction state. */
38820325960SDavid Howells struct rb_root fs_servers; /* afs_server (by server UUID) */
38920325960SDavid Howells seqlock_t fs_lock; /* For fs_servers */
3906e0e99d5SDavid Howells struct rw_semaphore fs_open_mmaps_lock;
3916e0e99d5SDavid Howells struct list_head fs_open_mmaps; /* List of vnodes that are mmapped */
3924fe6a946SDavid Howells atomic_t fs_s_break; /* Counter of CB.InitCallBackState messages */
393989782dcSDavid Howells
394d2ddc776SDavid Howells /* VL server list. */
3950a5143f2SDavid Howells rwlock_t vl_servers_lock; /* Lock on vl_servers */
3960a5143f2SDavid Howells struct afs_vlserver_list __rcu *vl_servers;
3970a5143f2SDavid Howells
398989782dcSDavid Howells u8 name_len; /* Length of name */
399719fdd32SDavid Howells char *name; /* Cell name, case-flattened and NUL-padded */
40008e0e7c8SDavid Howells };
40108e0e7c8SDavid Howells
40208e0e7c8SDavid Howells /*
4030a5143f2SDavid Howells * Volume Location server record.
4040a5143f2SDavid Howells */
4050a5143f2SDavid Howells struct afs_vlserver {
4060a5143f2SDavid Howells struct rcu_head rcu;
4070a5143f2SDavid Howells struct afs_addr_list __rcu *addresses; /* List of addresses for this VL server */
4080a5143f2SDavid Howells unsigned long flags;
4090a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED 0 /* The VL server has been probed */
4100a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING 1 /* VL server is being probed */
4113bf0fb6fSDavid Howells #define AFS_VLSERVER_FL_IS_YFS 2 /* Server is YFS not AFS */
412b95b3094SDavid Howells #define AFS_VLSERVER_FL_RESPONDING 3 /* VL server is responding */
4130a5143f2SDavid Howells rwlock_t lock; /* Lock on addresses */
414c56f9ec8SDavid Howells refcount_t ref;
415b95b3094SDavid Howells unsigned int rtt; /* Server's current RTT in uS */
4163bf0fb6fSDavid Howells
4173bf0fb6fSDavid Howells /* Probe state */
4183bf0fb6fSDavid Howells wait_queue_head_t probe_wq;
4193bf0fb6fSDavid Howells atomic_t probe_outstanding;
4203bf0fb6fSDavid Howells spinlock_t probe_lock;
4213bf0fb6fSDavid Howells struct {
422b95b3094SDavid Howells unsigned int rtt; /* RTT in uS */
4233bf0fb6fSDavid Howells u32 abort_code;
4243bf0fb6fSDavid Howells short error;
425fb72cd3dSDavid Howells unsigned short flags;
426fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_RESPONDED 0x01 /* At least once response (may be abort) */
427fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_IS_YFS 0x02 /* The peer appears to be YFS */
428fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_NOT_YFS 0x04 /* The peer appears not to be YFS */
429fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_LOCAL_FAILURE 0x08 /* A local failure prevented a probe */
4303bf0fb6fSDavid Howells } probe;
4313bf0fb6fSDavid Howells
4320a5143f2SDavid Howells u16 port;
4333bf0fb6fSDavid Howells u16 name_len; /* Length of name */
4340a5143f2SDavid Howells char name[]; /* Server name, case-flattened */
4350a5143f2SDavid Howells };
4360a5143f2SDavid Howells
4370a5143f2SDavid Howells /*
4380a5143f2SDavid Howells * Weighted list of Volume Location servers.
4390a5143f2SDavid Howells */
4400a5143f2SDavid Howells struct afs_vlserver_entry {
4410a5143f2SDavid Howells u16 priority; /* Preference (as SRV) */
4420a5143f2SDavid Howells u16 weight; /* Weight (as SRV) */
4430a5143f2SDavid Howells enum dns_record_source source:8;
4440a5143f2SDavid Howells enum dns_lookup_status status:8;
4450a5143f2SDavid Howells struct afs_vlserver *server;
4460a5143f2SDavid Howells };
4470a5143f2SDavid Howells
4480a5143f2SDavid Howells struct afs_vlserver_list {
4490a5143f2SDavid Howells struct rcu_head rcu;
450c56f9ec8SDavid Howells refcount_t ref;
4510a5143f2SDavid Howells u8 nr_servers;
4520a5143f2SDavid Howells u8 index; /* Server currently in use */
4533bf0fb6fSDavid Howells u8 preferred; /* Preferred server */
4540a5143f2SDavid Howells enum dns_record_source source:8;
4550a5143f2SDavid Howells enum dns_lookup_status status:8;
4560a5143f2SDavid Howells rwlock_t lock;
4570a5143f2SDavid Howells struct afs_vlserver_entry servers[];
4580a5143f2SDavid Howells };
4590a5143f2SDavid Howells
4600a5143f2SDavid Howells /*
461d2ddc776SDavid Howells * Cached VLDB entry.
462d2ddc776SDavid Howells *
463d2ddc776SDavid Howells * This is pointed to by cell->vldb_entries, indexed by name.
46408e0e7c8SDavid Howells */
465d2ddc776SDavid Howells struct afs_vldb_entry {
466d2ddc776SDavid Howells afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
46700d3b7a4SDavid Howells
468d2ddc776SDavid Howells unsigned long flags;
469d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
470d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
471d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
472d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
473d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
474d2ddc776SDavid Howells
475d2ddc776SDavid Howells uuid_t fs_server[AFS_NMAXNSERVERS];
47681006805SDavid Howells u32 addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
477d2ddc776SDavid Howells u8 fs_mask[AFS_NMAXNSERVERS];
47808e0e7c8SDavid Howells #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
47908e0e7c8SDavid Howells #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
48008e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
481d2ddc776SDavid Howells short error;
482d2ddc776SDavid Howells u8 nr_servers; /* Number of server records */
483d2ddc776SDavid Howells u8 name_len;
484d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
48508e0e7c8SDavid Howells };
48608e0e7c8SDavid Howells
48708e0e7c8SDavid Howells /*
488d2ddc776SDavid Howells * Record of fileserver with which we're actively communicating.
48908e0e7c8SDavid Howells */
49008e0e7c8SDavid Howells struct afs_server {
491d2ddc776SDavid Howells struct rcu_head rcu;
492d2ddc776SDavid Howells union {
493d2ddc776SDavid Howells uuid_t uuid; /* Server ID */
494d2ddc776SDavid Howells struct afs_uuid _uuid;
495d2ddc776SDavid Howells };
496c435ee34SDavid Howells
497d2ddc776SDavid Howells struct afs_addr_list __rcu *addresses;
49820325960SDavid Howells struct afs_cell *cell; /* Cell to which belongs (pins ref) */
4993c4c4075SDavid Howells struct rb_node uuid_rb; /* Link in net->fs_servers */
5003c4c4075SDavid Howells struct afs_server __rcu *uuid_next; /* Next server with same UUID */
5013c4c4075SDavid Howells struct afs_server *uuid_prev; /* Previous server with same UUID */
502f6cbb368SDavid Howells struct list_head probe_link; /* Link in net->fs_probe_list */
503d2ddc776SDavid Howells struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
504d2ddc776SDavid Howells struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
505d2ddc776SDavid Howells struct hlist_node proc_link; /* Link in net->fs_proc */
506*0b2bf6fbSDavid Howells struct list_head volumes; /* RCU list of afs_server_entry objects */
5076e0e99d5SDavid Howells struct work_struct initcb_work; /* Work for CB.InitCallBackState* */
508d2ddc776SDavid Howells struct afs_server *gc_next; /* Next server in manager's list */
509977e5f8eSDavid Howells time64_t unuse_time; /* Time at which last unused */
510c435ee34SDavid Howells unsigned long flags;
511f3c130e6SDavid Howells #define AFS_SERVER_FL_RESPONDING 0 /* The server is responding */
51232275d3fSDavid Howells #define AFS_SERVER_FL_UPDATING 1
51332275d3fSDavid Howells #define AFS_SERVER_FL_NEEDS_UPDATE 2 /* Fileserver address list is out of date */
51432275d3fSDavid Howells #define AFS_SERVER_FL_NOT_READY 4 /* The record is not ready for use */
51532275d3fSDavid Howells #define AFS_SERVER_FL_NOT_FOUND 5 /* VL server says no such server */
51632275d3fSDavid Howells #define AFS_SERVER_FL_VL_FAIL 6 /* Failed to access VL server */
517f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
51832275d3fSDavid Howells #define AFS_SERVER_FL_IS_YFS 16 /* Server is YFS not AFS */
51932275d3fSDavid Howells #define AFS_SERVER_FL_NO_IBULK 17 /* Fileserver doesn't support FS.InlineBulkStatus */
52032275d3fSDavid Howells #define AFS_SERVER_FL_NO_RM2 18 /* Fileserver doesn't support YFS.RemoveFile2 */
521b537a3c2SDavid Howells #define AFS_SERVER_FL_HAS_FS64 19 /* Fileserver supports FS.{Fetch,Store}Data64 */
522c56f9ec8SDavid Howells refcount_t ref; /* Object refcount */
523977e5f8eSDavid Howells atomic_t active; /* Active user count */
524d2ddc776SDavid Howells u32 addr_version; /* Address list version */
525f3c130e6SDavid Howells unsigned int rtt; /* Server's current RTT in uS */
52645218193SDavid Howells unsigned int debug_id; /* Debugging ID for traces */
52708e0e7c8SDavid Howells
52808e0e7c8SDavid Howells /* file service access */
529d2ddc776SDavid Howells rwlock_t fs_lock; /* access lock */
53008e0e7c8SDavid Howells
53108e0e7c8SDavid Howells /* callback promise management */
532c435ee34SDavid Howells unsigned cb_s_break; /* Break-everything counter. */
5333bf0fb6fSDavid Howells
5343bf0fb6fSDavid Howells /* Probe state */
535f6cbb368SDavid Howells unsigned long probed_at; /* Time last probe was dispatched (jiffies) */
5363bf0fb6fSDavid Howells wait_queue_head_t probe_wq;
5373bf0fb6fSDavid Howells atomic_t probe_outstanding;
5383bf0fb6fSDavid Howells spinlock_t probe_lock;
5393bf0fb6fSDavid Howells struct {
540f3c130e6SDavid Howells unsigned int rtt; /* RTT in uS */
5413bf0fb6fSDavid Howells u32 abort_code;
5423bf0fb6fSDavid Howells short error;
5433bf0fb6fSDavid Howells bool responded:1;
5443bf0fb6fSDavid Howells bool is_yfs:1;
5453bf0fb6fSDavid Howells bool not_yfs:1;
5463bf0fb6fSDavid Howells bool local_failure:1;
5473bf0fb6fSDavid Howells } probe;
548c435ee34SDavid Howells };
549c435ee34SDavid Howells
550c435ee34SDavid Howells /*
551194d28cfSDavid Howells * Replaceable volume server list.
55208e0e7c8SDavid Howells */
553d2ddc776SDavid Howells struct afs_server_entry {
554d2ddc776SDavid Howells struct afs_server *server;
555*0b2bf6fbSDavid Howells struct afs_volume *volume;
556*0b2bf6fbSDavid Howells struct list_head slink; /* Link in server->volumes */
557d2ddc776SDavid Howells };
558d2ddc776SDavid Howells
559d2ddc776SDavid Howells struct afs_server_list {
5603a4ef515SDavid Howells struct rcu_head rcu;
561d2ddc776SDavid Howells refcount_t usage;
562*0b2bf6fbSDavid Howells bool attached; /* T if attached to servers */
5633bf0fb6fSDavid Howells unsigned char nr_servers;
5643bf0fb6fSDavid Howells unsigned char preferred; /* Preferred server */
565d2ddc776SDavid Howells unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
566d2ddc776SDavid Howells unsigned int seq; /* Set to ->servers_seq when installed */
567d4a96becSDavid Howells rwlock_t lock;
568d2ddc776SDavid Howells struct afs_server_entry servers[];
56908e0e7c8SDavid Howells };
57008e0e7c8SDavid Howells
57108e0e7c8SDavid Howells /*
572d2ddc776SDavid Howells * Live AFS volume management.
57308e0e7c8SDavid Howells */
574d2ddc776SDavid Howells struct afs_volume {
57520325960SDavid Howells struct rcu_head rcu;
576*0b2bf6fbSDavid Howells afs_volid_t vid; /* The volume ID of this volume */
577*0b2bf6fbSDavid Howells afs_volid_t vids[AFS_MAXTYPES]; /* All associated volume IDs */
578c56f9ec8SDavid Howells refcount_t ref;
579d2ddc776SDavid Howells time64_t update_at; /* Time at which to next update */
580d2ddc776SDavid Howells struct afs_cell *cell; /* Cell to which belongs (pins ref) */
58120325960SDavid Howells struct rb_node cell_node; /* Link in cell->volumes */
58220325960SDavid Howells struct hlist_node proc_link; /* Link in cell->proc_volumes */
58320325960SDavid Howells struct super_block __rcu *sb; /* Superblock on which inodes reside */
584d2ddc776SDavid Howells unsigned long flags;
585d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
586d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
587d2ddc776SDavid Howells #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
588d2ddc776SDavid Howells #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
589d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
590d2ddc776SDavid Howells #define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
59120325960SDavid Howells #define AFS_VOLUME_MAYBE_NO_IBULK 6 /* - T if some servers don't have InlineBulkStatus */
592c3215484SDavid Howells #define AFS_VOLUME_RM_TREE 7 /* - Set if volume removed from cell->volumes */
593d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
594523d27cdSDavid Howells struct fscache_volume *cache; /* Caching cookie */
595d2ddc776SDavid Howells #endif
5968a070a96SDavid Howells struct afs_server_list __rcu *servers; /* List of servers on which volume resides */
597d2ddc776SDavid Howells rwlock_t servers_lock; /* Lock for ->servers */
598d2ddc776SDavid Howells unsigned int servers_seq; /* Incremented each time ->servers changes */
599d2ddc776SDavid Howells
60068251f0aSDavid Howells unsigned cb_v_break; /* Break-everything counter. */
60190fa9b64SDavid Howells rwlock_t cb_v_break_lock;
60268251f0aSDavid Howells
603d2ddc776SDavid Howells afs_voltype_t type; /* type of volume */
604d2ddc776SDavid Howells char type_force; /* force volume type (suppress R/O -> R/W) */
605d2ddc776SDavid Howells u8 name_len;
606d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
60708e0e7c8SDavid Howells };
60808e0e7c8SDavid Howells
6090fafdc9fSDavid Howells enum afs_lock_state {
6100fafdc9fSDavid Howells AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
6110fafdc9fSDavid Howells AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
6120fafdc9fSDavid Howells AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
6130fafdc9fSDavid Howells AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
6140fafdc9fSDavid Howells AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
6150fafdc9fSDavid Howells AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
6160fafdc9fSDavid Howells AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
617cdfb26b4SDavid Howells AFS_VNODE_LOCK_DELETED, /* The vnode has been deleted whilst we have a lock */
6180fafdc9fSDavid Howells };
6190fafdc9fSDavid Howells
62008e0e7c8SDavid Howells /*
621f8de483eSDavid Howells * AFS inode private data.
622f8de483eSDavid Howells *
623f8de483eSDavid Howells * Note that afs_alloc_inode() *must* reset anything that could incorrectly
624f8de483eSDavid Howells * leak from one inode to another.
62508e0e7c8SDavid Howells */
62608e0e7c8SDavid Howells struct afs_vnode {
627874c8ca1SDavid Howells struct netfs_inode netfs; /* Netfslib context and vfs inode */
62808e0e7c8SDavid Howells struct afs_volume *volume; /* volume on which vnode resides */
62908e0e7c8SDavid Howells struct afs_fid fid; /* the file identifier for this inode */
63008e0e7c8SDavid Howells struct afs_file_status status; /* AFS status info for this file */
631a4ff7401SDavid Howells afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
632fe342cf7SDavid Howells struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
633d2ddc776SDavid Howells struct mutex io_lock; /* Lock for serialising I/O on this mutex */
634b61f7dcfSDavid Howells struct rw_semaphore validate_lock; /* lock for validating this vnode */
63579ddbfa5SDavid Howells struct rw_semaphore rmdir_lock; /* Lock for rmdir vs sillyrename */
63679ddbfa5SDavid Howells struct key *silly_key; /* Silly rename key */
6374343d008SDavid Howells spinlock_t wb_lock; /* lock for wb_keys */
63808e0e7c8SDavid Howells spinlock_t lock; /* waitqueue/flags lock */
63908e0e7c8SDavid Howells unsigned long flags;
640c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
641260a9803SDavid Howells #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
642f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
64308e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
64408e0e7c8SDavid Howells #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
64508e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
6460fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
6470fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
6485a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
649b6489a49SDavid Howells #define AFS_VNODE_SILLY_DELETED 9 /* Set if file has been silly-deleted */
65022650f14SDavid Howells #define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
65108e0e7c8SDavid Howells
6524343d008SDavid Howells struct list_head wb_keys; /* List of keys available for writeback */
653e8d6c554SDavid Howells struct list_head pending_locks; /* locks waiting to be granted */
654e8d6c554SDavid Howells struct list_head granted_locks; /* locks granted on this file */
655e8d6c554SDavid Howells struct delayed_work lock_work; /* work to be done in locking */
6560fafdc9fSDavid Howells struct key *lock_key; /* Key to be used in lock ops */
657a690f60aSDavid Howells ktime_t locked_at; /* Time at which lock obtained */
6580fafdc9fSDavid Howells enum afs_lock_state lock_state : 8;
6590fafdc9fSDavid Howells afs_lock_type_t lock_type : 8;
66031143d5dSDavid Howells
66108e0e7c8SDavid Howells /* outstanding callback notification on this file */
6626e0e99d5SDavid Howells struct work_struct cb_work; /* Work for mmap'd files */
6636e0e99d5SDavid Howells struct list_head cb_mmap_link; /* Link in cell->fs_open_mmaps */
66420325960SDavid Howells void *cb_server; /* Server with callback/filelock */
6656e0e99d5SDavid Howells atomic_t cb_nr_mmap; /* Number of mmaps */
6664fe6a946SDavid Howells unsigned int cb_fs_s_break; /* Mass server break counter (cell->fs_s_break) */
667c435ee34SDavid Howells unsigned int cb_s_break; /* Mass break counter on ->server */
66868251f0aSDavid Howells unsigned int cb_v_break; /* Mass break counter on ->volume */
669c435ee34SDavid Howells unsigned int cb_break; /* Break counter on vnode */
67020325960SDavid Howells seqlock_t cb_lock; /* Lock for ->cb_server, ->status, ->cb_*break */
671c435ee34SDavid Howells
672c435ee34SDavid Howells time64_t cb_expires_at; /* time at which callback expires */
67308e0e7c8SDavid Howells };
67408e0e7c8SDavid Howells
afs_vnode_cache(struct afs_vnode * vnode)67512bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
67612bdcf33SDavid Howells {
67712bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE
678e81fb419SLinus Torvalds return netfs_i_cookie(&vnode->netfs);
67912bdcf33SDavid Howells #else
68012bdcf33SDavid Howells return NULL;
68112bdcf33SDavid Howells #endif
68212bdcf33SDavid Howells }
68312bdcf33SDavid Howells
afs_vnode_set_cache(struct afs_vnode * vnode,struct fscache_cookie * cookie)684bc899ee1SDavid Howells static inline void afs_vnode_set_cache(struct afs_vnode *vnode,
685bc899ee1SDavid Howells struct fscache_cookie *cookie)
686bc899ee1SDavid Howells {
687bc899ee1SDavid Howells #ifdef CONFIG_AFS_FSCACHE
688874c8ca1SDavid Howells vnode->netfs.cache = cookie;
689b4fa966fSDavid Howells if (cookie)
690b4fa966fSDavid Howells mapping_set_release_always(vnode->netfs.inode.i_mapping);
691bc899ee1SDavid Howells #endif
692bc899ee1SDavid Howells }
693bc899ee1SDavid Howells
69400d3b7a4SDavid Howells /*
69500d3b7a4SDavid Howells * cached security record for one user's attempt to access a vnode
69600d3b7a4SDavid Howells */
69700d3b7a4SDavid Howells struct afs_permit {
69800d3b7a4SDavid Howells struct key *key; /* RxRPC ticket holding a security context */
699be080a6fSDavid Howells afs_access_t access; /* CallerAccess value for this key */
70000d3b7a4SDavid Howells };
70100d3b7a4SDavid Howells
70200d3b7a4SDavid Howells /*
703be080a6fSDavid Howells * Immutable cache of CallerAccess records from attempts to access vnodes.
704be080a6fSDavid Howells * These may be shared between multiple vnodes.
70500d3b7a4SDavid Howells */
70600d3b7a4SDavid Howells struct afs_permits {
707be080a6fSDavid Howells struct rcu_head rcu;
708be080a6fSDavid Howells struct hlist_node hash_node; /* Link in hash */
709be080a6fSDavid Howells unsigned long h; /* Hash value for this permit list */
710be080a6fSDavid Howells refcount_t usage;
711be080a6fSDavid Howells unsigned short nr_permits; /* Number of records */
712be080a6fSDavid Howells bool invalidated; /* Invalidated due to key change */
713be080a6fSDavid Howells struct afs_permit permits[]; /* List of permits sorted by key pointer */
71400d3b7a4SDavid Howells };
71500d3b7a4SDavid Howells
716b908fe6bSDavid Howells /*
7174584ae96SDavid Howells * Error prioritisation and accumulation.
7184584ae96SDavid Howells */
7194584ae96SDavid Howells struct afs_error {
7204584ae96SDavid Howells short error; /* Accumulated error */
7214584ae96SDavid Howells bool responded; /* T if server responded */
7224584ae96SDavid Howells };
7234584ae96SDavid Howells
7244584ae96SDavid Howells /*
7258b2a464cSDavid Howells * Cursor for iterating over a server's address list.
7268b2a464cSDavid Howells */
7278b2a464cSDavid Howells struct afs_addr_cursor {
7288b2a464cSDavid Howells struct afs_addr_list *alist; /* Current address list (pins ref) */
7293bf0fb6fSDavid Howells unsigned long tried; /* Tried addresses */
7303bf0fb6fSDavid Howells signed char index; /* Current address */
7318b2a464cSDavid Howells bool responded; /* T if the current address responded */
732744bcd71SDavid Howells unsigned short nr_iterations; /* Number of address iterations */
7333bf0fb6fSDavid Howells short error;
7343bf0fb6fSDavid Howells u32 abort_code;
7358b2a464cSDavid Howells };
7368b2a464cSDavid Howells
7378b2a464cSDavid Howells /*
7380a5143f2SDavid Howells * Cursor for iterating over a set of volume location servers.
7390a5143f2SDavid Howells */
7400a5143f2SDavid Howells struct afs_vl_cursor {
7410a5143f2SDavid Howells struct afs_addr_cursor ac;
7420a5143f2SDavid Howells struct afs_cell *cell; /* The cell we're querying */
7430a5143f2SDavid Howells struct afs_vlserver_list *server_list; /* Current server list (pins ref) */
7443bf0fb6fSDavid Howells struct afs_vlserver *server; /* Server on which this resides */
7450a5143f2SDavid Howells struct key *key; /* Key for the server */
7463bf0fb6fSDavid Howells unsigned long untried; /* Bitmask of untried servers */
7473bf0fb6fSDavid Howells short index; /* Current server */
7480a5143f2SDavid Howells short error;
7490a5143f2SDavid Howells unsigned short flags;
7500a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */
7510a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */
7520a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */
753744bcd71SDavid Howells unsigned short nr_iterations; /* Number of server iterations */
7540a5143f2SDavid Howells };
7550a5143f2SDavid Howells
7560a5143f2SDavid Howells /*
757e49c7b2fSDavid Howells * Fileserver operation methods.
758e49c7b2fSDavid Howells */
759e49c7b2fSDavid Howells struct afs_operation_ops {
760e49c7b2fSDavid Howells void (*issue_afs_rpc)(struct afs_operation *op);
761e49c7b2fSDavid Howells void (*issue_yfs_rpc)(struct afs_operation *op);
762e49c7b2fSDavid Howells void (*success)(struct afs_operation *op);
763e49c7b2fSDavid Howells void (*aborted)(struct afs_operation *op);
764dc419184SDavid Howells void (*failed)(struct afs_operation *op);
765e49c7b2fSDavid Howells void (*edit_dir)(struct afs_operation *op);
766e49c7b2fSDavid Howells void (*put)(struct afs_operation *op);
767e49c7b2fSDavid Howells };
768e49c7b2fSDavid Howells
769e49c7b2fSDavid Howells struct afs_vnode_param {
770e49c7b2fSDavid Howells struct afs_vnode *vnode;
771e49c7b2fSDavid Howells struct afs_fid fid; /* Fid to access */
772e49c7b2fSDavid Howells struct afs_status_cb scb; /* Returned status and callback promise */
773e49c7b2fSDavid Howells afs_dataversion_t dv_before; /* Data version before the call */
774e49c7b2fSDavid Howells unsigned int cb_break_before; /* cb_break + cb_s_break before the call */
775e49c7b2fSDavid Howells u8 dv_delta; /* Expected change in data version */
776793fe82eSDavid Howells bool put_vnode:1; /* T if we have a ref on the vnode */
777793fe82eSDavid Howells bool need_io_lock:1; /* T if we need the I/O lock on this */
778793fe82eSDavid Howells bool update_ctime:1; /* Need to update the ctime */
779793fe82eSDavid Howells bool set_size:1; /* Must update i_size */
780b6489a49SDavid Howells bool op_unlinked:1; /* True if file was unlinked by op */
781a9e5c87cSDavid Howells bool speculative:1; /* T if speculative status fetch (no vnode lock) */
78222650f14SDavid Howells bool modification:1; /* Set if the content gets modified */
783e49c7b2fSDavid Howells };
784e49c7b2fSDavid Howells
785e49c7b2fSDavid Howells /*
786e49c7b2fSDavid Howells * Fileserver operation wrapper, handling server and address rotation
787e49c7b2fSDavid Howells * asynchronously. May make simultaneous calls to multiple servers.
7888b2a464cSDavid Howells */
789a310082fSDavid Howells struct afs_operation {
790e49c7b2fSDavid Howells struct afs_net *net; /* Network namespace */
791e49c7b2fSDavid Howells struct key *key; /* Key for the cell */
792a58823acSDavid Howells const struct afs_call_type *type; /* Type of call done */
793e49c7b2fSDavid Howells const struct afs_operation_ops *ops;
794e49c7b2fSDavid Howells
795e49c7b2fSDavid Howells /* Parameters/results for the operation */
796e49c7b2fSDavid Howells struct afs_volume *volume; /* Volume being accessed */
797e49c7b2fSDavid Howells struct afs_vnode_param file[2];
798e49c7b2fSDavid Howells struct afs_vnode_param *more_files;
799e49c7b2fSDavid Howells struct afs_volsync volsync;
800e49c7b2fSDavid Howells struct dentry *dentry; /* Dentry to be altered */
801e49c7b2fSDavid Howells struct dentry *dentry_2; /* Second dentry to be altered */
802e49c7b2fSDavid Howells struct timespec64 mtime; /* Modification time to record */
803da8d0755SDavid Howells struct timespec64 ctime; /* Change time to set */
804e49c7b2fSDavid Howells short nr_files; /* Number of entries in file[], more_files */
805e49c7b2fSDavid Howells short error;
806e49c7b2fSDavid Howells unsigned int debug_id;
807e49c7b2fSDavid Howells
808e49c7b2fSDavid Howells unsigned int cb_v_break; /* Volume break counter before op */
809e49c7b2fSDavid Howells unsigned int cb_s_break; /* Server break counter before op */
810e49c7b2fSDavid Howells
811e49c7b2fSDavid Howells union {
812e49c7b2fSDavid Howells struct {
813e49c7b2fSDavid Howells int which; /* Which ->file[] to fetch for */
814e49c7b2fSDavid Howells } fetch_status;
815e49c7b2fSDavid Howells struct {
816e49c7b2fSDavid Howells int reason; /* enum afs_edit_dir_reason */
817e49c7b2fSDavid Howells mode_t mode;
818e49c7b2fSDavid Howells const char *symlink;
819e49c7b2fSDavid Howells } create;
820e49c7b2fSDavid Howells struct {
821e49c7b2fSDavid Howells bool need_rehash;
822e49c7b2fSDavid Howells } unlink;
823e49c7b2fSDavid Howells struct {
824e49c7b2fSDavid Howells struct dentry *rehash;
825e49c7b2fSDavid Howells struct dentry *tmp;
826e49c7b2fSDavid Howells bool new_negative;
827e49c7b2fSDavid Howells } rename;
828e49c7b2fSDavid Howells struct {
829e49c7b2fSDavid Howells struct afs_read *req;
830e49c7b2fSDavid Howells } fetch;
831e49c7b2fSDavid Howells struct {
832e49c7b2fSDavid Howells afs_lock_type_t type;
833e49c7b2fSDavid Howells } lock;
834e49c7b2fSDavid Howells struct {
835bd80d8a8SDavid Howells struct iov_iter *write_iter;
836bd80d8a8SDavid Howells loff_t pos;
837bd80d8a8SDavid Howells loff_t size;
838bd80d8a8SDavid Howells loff_t i_size;
839d383e346SDavid Howells bool laundering; /* Laundering page, PG_writeback not set */
840e49c7b2fSDavid Howells } store;
841e49c7b2fSDavid Howells struct {
842e49c7b2fSDavid Howells struct iattr *attr;
843ec0fa0b6SDavid Howells loff_t old_i_size;
844e49c7b2fSDavid Howells } setattr;
845e49c7b2fSDavid Howells struct afs_acl *acl;
846e49c7b2fSDavid Howells struct yfs_acl *yacl;
847e49c7b2fSDavid Howells struct {
848e49c7b2fSDavid Howells struct afs_volume_status vs;
849e49c7b2fSDavid Howells struct kstatfs *buf;
850e49c7b2fSDavid Howells } volstatus;
851e49c7b2fSDavid Howells };
852e49c7b2fSDavid Howells
853e49c7b2fSDavid Howells /* Fileserver iteration state */
8548b2a464cSDavid Howells struct afs_addr_cursor ac;
855d2ddc776SDavid Howells struct afs_server_list *server_list; /* Current server list (pins ref) */
85620325960SDavid Howells struct afs_server *server; /* Server we're using (ref pinned by server_list) */
857e49c7b2fSDavid Howells struct afs_call *call;
8583bf0fb6fSDavid Howells unsigned long untried; /* Bitmask of untried servers */
8593bf0fb6fSDavid Howells short index; /* Current server */
860e49c7b2fSDavid Howells unsigned short nr_iterations; /* Number of server iterations */
861e49c7b2fSDavid Howells
862e49c7b2fSDavid Howells unsigned int flags;
863a310082fSDavid Howells #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */
864a310082fSDavid Howells #define AFS_OPERATION_VBUSY 0x0002 /* Set if seen VBUSY */
865a310082fSDavid Howells #define AFS_OPERATION_VMOVED 0x0004 /* Set if seen VMOVED */
866a310082fSDavid Howells #define AFS_OPERATION_VNOVOL 0x0008 /* Set if seen VNOVOL */
867a310082fSDavid Howells #define AFS_OPERATION_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
868a310082fSDavid Howells #define AFS_OPERATION_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
869e49c7b2fSDavid Howells #define AFS_OPERATION_UNINTR 0x0040 /* Set if op is uninterruptible */
870e49c7b2fSDavid Howells #define AFS_OPERATION_DOWNGRADE 0x0080 /* Set to retry with downgraded opcode */
871e49c7b2fSDavid Howells #define AFS_OPERATION_LOCK_0 0x0100 /* Set if have io_lock on file[0] */
872e49c7b2fSDavid Howells #define AFS_OPERATION_LOCK_1 0x0200 /* Set if have io_lock on file[1] */
8738409f67bSDavid Howells #define AFS_OPERATION_TRIED_ALL 0x0400 /* Set if we've tried all the fileservers */
8748409f67bSDavid Howells #define AFS_OPERATION_RETRY_SERVER 0x0800 /* Set if we should retry the current server */
875b6489a49SDavid Howells #define AFS_OPERATION_DIR_CONFLICT 0x1000 /* Set if we detected a 3rd-party dir change */
8768b2a464cSDavid Howells };
8778b2a464cSDavid Howells
878402cb8ddSDavid Howells /*
879402cb8ddSDavid Howells * Cache auxiliary data.
880402cb8ddSDavid Howells */
881402cb8ddSDavid Howells struct afs_vnode_cache_aux {
882523d27cdSDavid Howells __be64 data_version;
883402cb8ddSDavid Howells } __packed;
884402cb8ddSDavid Howells
afs_set_cache_aux(struct afs_vnode * vnode,struct afs_vnode_cache_aux * aux)885523d27cdSDavid Howells static inline void afs_set_cache_aux(struct afs_vnode *vnode,
886523d27cdSDavid Howells struct afs_vnode_cache_aux *aux)
887523d27cdSDavid Howells {
888523d27cdSDavid Howells aux->data_version = cpu_to_be64(vnode->status.data_version);
889523d27cdSDavid Howells }
890523d27cdSDavid Howells
afs_invalidate_cache(struct afs_vnode * vnode,unsigned int flags)891523d27cdSDavid Howells static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int flags)
892523d27cdSDavid Howells {
893523d27cdSDavid Howells struct afs_vnode_cache_aux aux;
894523d27cdSDavid Howells
895523d27cdSDavid Howells afs_set_cache_aux(vnode, &aux);
896523d27cdSDavid Howells fscache_invalidate(afs_vnode_cache(vnode), &aux,
897874c8ca1SDavid Howells i_size_read(&vnode->netfs.inode), flags);
898523d27cdSDavid Howells }
899523d27cdSDavid Howells
900185f0c70SDavid Howells /*
90178525c74SDavid Howells * We use folio->private to hold the amount of the folio that we've written to,
902185f0c70SDavid Howells * splitting the field into two parts. However, we need to represent a range
90378525c74SDavid Howells * 0...FOLIO_SIZE, so we reduce the resolution if the size of the folio
9042d9900f2SDavid Howells * exceeds what we can encode.
905185f0c70SDavid Howells */
90665dd2d60SDavid Howells #ifdef CONFIG_64BIT
90778525c74SDavid Howells #define __AFS_FOLIO_PRIV_MASK 0x7fffffffUL
90878525c74SDavid Howells #define __AFS_FOLIO_PRIV_SHIFT 32
90978525c74SDavid Howells #define __AFS_FOLIO_PRIV_MMAPPED 0x80000000UL
910185f0c70SDavid Howells #else
91178525c74SDavid Howells #define __AFS_FOLIO_PRIV_MASK 0x7fffUL
91278525c74SDavid Howells #define __AFS_FOLIO_PRIV_SHIFT 16
91378525c74SDavid Howells #define __AFS_FOLIO_PRIV_MMAPPED 0x8000UL
914185f0c70SDavid Howells #endif
915185f0c70SDavid Howells
afs_folio_dirty_resolution(struct folio * folio)91678525c74SDavid Howells static inline unsigned int afs_folio_dirty_resolution(struct folio *folio)
9172d9900f2SDavid Howells {
91878525c74SDavid Howells int shift = folio_shift(folio) - (__AFS_FOLIO_PRIV_SHIFT - 1);
9192d9900f2SDavid Howells return (shift > 0) ? shift : 0;
9202d9900f2SDavid Howells }
9212d9900f2SDavid Howells
afs_folio_dirty_from(struct folio * folio,unsigned long priv)92278525c74SDavid Howells static inline size_t afs_folio_dirty_from(struct folio *folio, unsigned long priv)
923185f0c70SDavid Howells {
92478525c74SDavid Howells unsigned long x = priv & __AFS_FOLIO_PRIV_MASK;
9252d9900f2SDavid Howells
9262d9900f2SDavid Howells /* The lower bound is inclusive */
92778525c74SDavid Howells return x << afs_folio_dirty_resolution(folio);
928185f0c70SDavid Howells }
929185f0c70SDavid Howells
afs_folio_dirty_to(struct folio * folio,unsigned long priv)93078525c74SDavid Howells static inline size_t afs_folio_dirty_to(struct folio *folio, unsigned long priv)
931185f0c70SDavid Howells {
93278525c74SDavid Howells unsigned long x = (priv >> __AFS_FOLIO_PRIV_SHIFT) & __AFS_FOLIO_PRIV_MASK;
9332d9900f2SDavid Howells
9342d9900f2SDavid Howells /* The upper bound is immediately beyond the region */
93578525c74SDavid Howells return (x + 1) << afs_folio_dirty_resolution(folio);
936185f0c70SDavid Howells }
937185f0c70SDavid Howells
afs_folio_dirty(struct folio * folio,size_t from,size_t to)93878525c74SDavid Howells static inline unsigned long afs_folio_dirty(struct folio *folio, size_t from, size_t to)
939185f0c70SDavid Howells {
94078525c74SDavid Howells unsigned int res = afs_folio_dirty_resolution(folio);
9412d9900f2SDavid Howells from >>= res;
9422d9900f2SDavid Howells to = (to - 1) >> res;
94378525c74SDavid Howells return (to << __AFS_FOLIO_PRIV_SHIFT) | from;
944185f0c70SDavid Howells }
945185f0c70SDavid Howells
afs_folio_dirty_mmapped(unsigned long priv)94678525c74SDavid Howells static inline unsigned long afs_folio_dirty_mmapped(unsigned long priv)
947f86726a6SDavid Howells {
94878525c74SDavid Howells return priv | __AFS_FOLIO_PRIV_MMAPPED;
949f86726a6SDavid Howells }
950f86726a6SDavid Howells
afs_is_folio_dirty_mmapped(unsigned long priv)95178525c74SDavid Howells static inline bool afs_is_folio_dirty_mmapped(unsigned long priv)
952f86726a6SDavid Howells {
95378525c74SDavid Howells return priv & __AFS_FOLIO_PRIV_MMAPPED;
954f86726a6SDavid Howells }
955f86726a6SDavid Howells
95698bf40cdSDavid Howells #include <trace/events/afs.h>
95798bf40cdSDavid Howells
95808e0e7c8SDavid Howells /*****************************************************************************/
95908e0e7c8SDavid Howells /*
9608b2a464cSDavid Howells * addr_list.c
9618b2a464cSDavid Howells */
afs_get_addrlist(struct afs_addr_list * alist)9628b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
9638b2a464cSDavid Howells {
9648b2a464cSDavid Howells if (alist)
9658b2a464cSDavid Howells refcount_inc(&alist->usage);
9668b2a464cSDavid Howells return alist;
9678b2a464cSDavid Howells }
9688b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
9698b2a464cSDavid Howells unsigned short,
9708b2a464cSDavid Howells unsigned short);
9718b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *);
9720a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
9730a5143f2SDavid Howells const char *, size_t, char,
9748b2a464cSDavid Howells unsigned short, unsigned short);
9750a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
9768b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *);
9778b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *);
9788b2a464cSDavid Howells
979bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
980bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
981d2ddc776SDavid Howells
9828b2a464cSDavid Howells /*
98308e0e7c8SDavid Howells * callback.c
98408e0e7c8SDavid Howells */
9856e0e99d5SDavid Howells extern void afs_invalidate_mmap_work(struct work_struct *);
9866e0e99d5SDavid Howells extern void afs_server_init_callback_work(struct work_struct *work);
98708e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
988051d2525SDavid Howells extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
989051d2525SDavid Howells extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
9905cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
991c435ee34SDavid Howells
afs_calc_vnode_cb_break(struct afs_vnode * vnode)99268251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
99368251f0aSDavid Howells {
994eeba1e9cSDavid Howells return vnode->cb_break + vnode->cb_v_break;
99568251f0aSDavid Howells }
99668251f0aSDavid Howells
afs_cb_is_broken(unsigned int cb_break,const struct afs_vnode * vnode)99718ac6185SDavid Howells static inline bool afs_cb_is_broken(unsigned int cb_break,
99820325960SDavid Howells const struct afs_vnode *vnode)
99968251f0aSDavid Howells {
100020325960SDavid Howells return cb_break != (vnode->cb_break + vnode->volume->cb_v_break);
100168251f0aSDavid Howells }
100268251f0aSDavid Howells
10031da177e4SLinus Torvalds /*
10041da177e4SLinus Torvalds * cell.c
10051da177e4SLinus Torvalds */
1006989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
1007dca54a7bSDavid Howells extern struct afs_cell *afs_find_cell(struct afs_net *, const char *, unsigned,
1008dca54a7bSDavid Howells enum afs_cell_trace);
1009989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
1010989782dcSDavid Howells const char *, bool);
1011dca54a7bSDavid Howells extern struct afs_cell *afs_use_cell(struct afs_cell *, enum afs_cell_trace);
1012dca54a7bSDavid Howells extern void afs_unuse_cell(struct afs_net *, struct afs_cell *, enum afs_cell_trace);
1013dca54a7bSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *, enum afs_cell_trace);
1014dca54a7bSDavid Howells extern void afs_see_cell(struct afs_cell *, enum afs_cell_trace);
1015dca54a7bSDavid Howells extern void afs_put_cell(struct afs_cell *, enum afs_cell_trace);
1016dca54a7bSDavid Howells extern void afs_queue_cell(struct afs_cell *, enum afs_cell_trace);
1017989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
1018989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
1019f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
102008e0e7c8SDavid Howells
102108e0e7c8SDavid Howells /*
102208e0e7c8SDavid Howells * cmservice.c
102308e0e7c8SDavid Howells */
102408e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
102508e0e7c8SDavid Howells
10261da177e4SLinus Torvalds /*
10271da177e4SLinus Torvalds * dir.c
10281da177e4SLinus Torvalds */
10294b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
10304d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
1031f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops;
10324d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
10334d673da1SDavid Howells
103466c7e1d3SDavid Howells extern void afs_d_release(struct dentry *);
1035728279a5SDavid Howells extern void afs_check_for_remote_deletion(struct afs_operation *);
103666c7e1d3SDavid Howells
103766c7e1d3SDavid Howells /*
103863a4681fSDavid Howells * dir_edit.c
103963a4681fSDavid Howells */
104063a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
104163a4681fSDavid Howells enum afs_edit_dir_reason);
104263a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
1043790dc90bSDavid Howells void afs_edit_dir_update_dotdot(struct afs_vnode *vnode, struct afs_vnode *new_dvnode,
1044790dc90bSDavid Howells enum afs_edit_dir_reason why);
104563a4681fSDavid Howells
104663a4681fSDavid Howells /*
104779ddbfa5SDavid Howells * dir_silly.c
104879ddbfa5SDavid Howells */
104979ddbfa5SDavid Howells extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
105079ddbfa5SDavid Howells struct dentry *, struct key *);
105179ddbfa5SDavid Howells extern int afs_silly_iput(struct dentry *, struct inode *);
105279ddbfa5SDavid Howells
105379ddbfa5SDavid Howells /*
105466c7e1d3SDavid Howells * dynroot.c
105566c7e1d3SDavid Howells */
105666c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
105766c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations;
105866c7e1d3SDavid Howells
105966c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
10600da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
10610da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
10620da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *);
10630da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *);
10641da177e4SLinus Torvalds
10651da177e4SLinus Torvalds /*
10661da177e4SLinus Torvalds * file.c
10671da177e4SLinus Torvalds */
106875bd228dSDavid Howells extern const struct address_space_operations afs_file_aops;
106975bd228dSDavid Howells extern const struct address_space_operations afs_symlink_aops;
1070754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
107100d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
10726a19114bSDavid Howells extern const struct netfs_request_ops afs_req_ops;
107300d3b7a4SDavid Howells
10744343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
10754343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
107600d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
107700d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
1078c69bf479SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct afs_read *);
10795cbf0398SDavid Howells extern struct afs_read *afs_alloc_read(gfp_t);
1080196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
1081c7f75ef3SDavid Howells extern int afs_write_inode(struct inode *, struct writeback_control *);
10821da177e4SLinus Torvalds
afs_get_read(struct afs_read * req)1083d4438a25SDavid Howells static inline struct afs_read *afs_get_read(struct afs_read *req)
1084d4438a25SDavid Howells {
1085d4438a25SDavid Howells refcount_inc(&req->usage);
1086d4438a25SDavid Howells return req;
1087d4438a25SDavid Howells }
1088d4438a25SDavid Howells
10891da177e4SLinus Torvalds /*
1090e8d6c554SDavid Howells * flock.c
1091e8d6c554SDavid Howells */
1092f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
1093f044c884SDavid Howells
1094a690f60aSDavid Howells extern void afs_lock_op_done(struct afs_call *);
1095e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
1096e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
1097e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
1098e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
1099e8d6c554SDavid Howells
1100e8d6c554SDavid Howells /*
110108e0e7c8SDavid Howells * fsclient.c
110208e0e7c8SDavid Howells */
1103e49c7b2fSDavid Howells extern void afs_fs_fetch_status(struct afs_operation *);
1104e49c7b2fSDavid Howells extern void afs_fs_fetch_data(struct afs_operation *);
1105e49c7b2fSDavid Howells extern void afs_fs_create_file(struct afs_operation *);
1106e49c7b2fSDavid Howells extern void afs_fs_make_dir(struct afs_operation *);
1107e49c7b2fSDavid Howells extern void afs_fs_remove_file(struct afs_operation *);
1108e49c7b2fSDavid Howells extern void afs_fs_remove_dir(struct afs_operation *);
1109e49c7b2fSDavid Howells extern void afs_fs_link(struct afs_operation *);
1110e49c7b2fSDavid Howells extern void afs_fs_symlink(struct afs_operation *);
1111e49c7b2fSDavid Howells extern void afs_fs_rename(struct afs_operation *);
1112e49c7b2fSDavid Howells extern void afs_fs_store_data(struct afs_operation *);
1113e49c7b2fSDavid Howells extern void afs_fs_setattr(struct afs_operation *);
1114e49c7b2fSDavid Howells extern void afs_fs_get_volume_status(struct afs_operation *);
1115e49c7b2fSDavid Howells extern void afs_fs_set_lock(struct afs_operation *);
1116e49c7b2fSDavid Howells extern void afs_fs_extend_lock(struct afs_operation *);
1117e49c7b2fSDavid Howells extern void afs_fs_release_lock(struct afs_operation *);
1118d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
1119d2ddc776SDavid Howells struct afs_addr_cursor *, struct key *);
1120f6cbb368SDavid Howells extern bool afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
1121f6cbb368SDavid Howells struct afs_addr_cursor *, struct key *);
1122e49c7b2fSDavid Howells extern void afs_fs_inline_bulk_status(struct afs_operation *);
112308e0e7c8SDavid Howells
1124260f082bSDavid Howells struct afs_acl {
1125260f082bSDavid Howells u32 size;
1126260f082bSDavid Howells u8 data[];
1127260f082bSDavid Howells };
1128260f082bSDavid Howells
1129e49c7b2fSDavid Howells extern void afs_fs_fetch_acl(struct afs_operation *);
1130e49c7b2fSDavid Howells extern void afs_fs_store_acl(struct afs_operation *);
1131e49c7b2fSDavid Howells
1132e49c7b2fSDavid Howells /*
1133e49c7b2fSDavid Howells * fs_operation.c
1134e49c7b2fSDavid Howells */
1135e49c7b2fSDavid Howells extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
1136e49c7b2fSDavid Howells extern int afs_put_operation(struct afs_operation *);
1137e49c7b2fSDavid Howells extern bool afs_begin_vnode_operation(struct afs_operation *);
1138e49c7b2fSDavid Howells extern void afs_wait_for_operation(struct afs_operation *);
1139e49c7b2fSDavid Howells extern int afs_do_sync_operation(struct afs_operation *);
1140e49c7b2fSDavid Howells
afs_op_nomem(struct afs_operation * op)1141e49c7b2fSDavid Howells static inline void afs_op_nomem(struct afs_operation *op)
1142e49c7b2fSDavid Howells {
1143e49c7b2fSDavid Howells op->error = -ENOMEM;
1144e49c7b2fSDavid Howells }
1145e49c7b2fSDavid Howells
afs_op_set_vnode(struct afs_operation * op,unsigned int n,struct afs_vnode * vnode)1146e49c7b2fSDavid Howells static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
1147e49c7b2fSDavid Howells struct afs_vnode *vnode)
1148e49c7b2fSDavid Howells {
1149e49c7b2fSDavid Howells op->file[n].vnode = vnode;
1150e49c7b2fSDavid Howells op->file[n].need_io_lock = true;
1151e49c7b2fSDavid Howells }
1152e49c7b2fSDavid Howells
afs_op_set_fid(struct afs_operation * op,unsigned int n,const struct afs_fid * fid)1153e49c7b2fSDavid Howells static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
1154e49c7b2fSDavid Howells const struct afs_fid *fid)
1155e49c7b2fSDavid Howells {
1156e49c7b2fSDavid Howells op->file[n].fid = *fid;
1157e49c7b2fSDavid Howells }
1158260f082bSDavid Howells
115908e0e7c8SDavid Howells /*
11603bf0fb6fSDavid Howells * fs_probe.c
11613bf0fb6fSDavid Howells */
11623bf0fb6fSDavid Howells extern void afs_fileserver_probe_result(struct afs_call *);
1163f6cbb368SDavid Howells extern void afs_fs_probe_fileserver(struct afs_net *, struct afs_server *, struct key *, bool);
11643bf0fb6fSDavid Howells extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long);
11658409f67bSDavid Howells extern void afs_probe_fileserver(struct afs_net *, struct afs_server *);
1166f6cbb368SDavid Howells extern void afs_fs_probe_dispatcher(struct work_struct *);
11678409f67bSDavid Howells extern int afs_wait_for_one_fs_probe(struct afs_server *, bool);
11685481fc6eSDavid Howells extern void afs_fs_probe_cleanup(struct afs_net *);
11693bf0fb6fSDavid Howells
11703bf0fb6fSDavid Howells /*
11711da177e4SLinus Torvalds * inode.c
11721da177e4SLinus Torvalds */
1173b6489a49SDavid Howells extern const struct afs_operation_ops afs_fetch_status_operation;
1174b6489a49SDavid Howells
1175e49c7b2fSDavid Howells extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
1176a58823acSDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1177e49c7b2fSDavid Howells extern int afs_ilookup5_test_by_fid(struct inode *, void *);
11784d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
1179e49c7b2fSDavid Howells extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
1180e49c7b2fSDavid Howells extern struct inode *afs_root_iget(struct super_block *, struct key *);
1181c925bd0aSDavid Howells extern bool afs_check_validity(struct afs_vnode *);
1182260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *);
11830050d7f5SMatthew Wilcox (Oracle) bool afs_pagecache_valid(struct afs_vnode *);
1184b74d24f7SChristian Brauner extern int afs_getattr(struct mnt_idmap *idmap, const struct path *,
1185549c7297SChristian Brauner struct kstat *, u32, unsigned int);
1186c1632a0fSChristian Brauner extern int afs_setattr(struct mnt_idmap *idmap, struct dentry *, struct iattr *);
1187b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
1188bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
11891da177e4SLinus Torvalds
11901da177e4SLinus Torvalds /*
11911da177e4SLinus Torvalds * main.c
11921da177e4SLinus Torvalds */
11930ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
11945b86d4ffSDavid Howells extern int afs_net_id;
11955b86d4ffSDavid Howells
afs_net(struct net * net)11965b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net)
11975b86d4ffSDavid Howells {
11985b86d4ffSDavid Howells return net_generic(net, afs_net_id);
11995b86d4ffSDavid Howells }
12005b86d4ffSDavid Howells
afs_sb2net(struct super_block * sb)12015b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb)
12025b86d4ffSDavid Howells {
12035b86d4ffSDavid Howells return afs_net(AFS_FS_S(sb)->net_ns);
12045b86d4ffSDavid Howells }
1205f044c884SDavid Howells
afs_d2net(struct dentry * dentry)1206f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
1207f044c884SDavid Howells {
12085b86d4ffSDavid Howells return afs_sb2net(dentry->d_sb);
1209f044c884SDavid Howells }
1210f044c884SDavid Howells
afs_i2net(struct inode * inode)1211f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
1212f044c884SDavid Howells {
12135b86d4ffSDavid Howells return afs_sb2net(inode->i_sb);
1214f044c884SDavid Howells }
1215f044c884SDavid Howells
afs_v2net(struct afs_vnode * vnode)1216f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1217f044c884SDavid Howells {
1218874c8ca1SDavid Howells return afs_i2net(&vnode->netfs.inode);
1219f044c884SDavid Howells }
1220f044c884SDavid Howells
afs_sock2net(struct sock * sk)1221f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
1222f044c884SDavid Howells {
12235b86d4ffSDavid Howells return net_generic(sock_net(sk), afs_net_id);
1224f044c884SDavid Howells }
12251da177e4SLinus Torvalds
__afs_stat(atomic_t * s)1226d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s)
1227d55b4da4SDavid Howells {
1228d55b4da4SDavid Howells atomic_inc(s);
1229d55b4da4SDavid Howells }
1230d55b4da4SDavid Howells
1231d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1232d55b4da4SDavid Howells
12331da177e4SLinus Torvalds /*
123408e0e7c8SDavid Howells * misc.c
123508e0e7c8SDavid Howells */
123608e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
12374584ae96SDavid Howells extern void afs_prioritise_error(struct afs_error *, int, u32);
123808e0e7c8SDavid Howells
123908e0e7c8SDavid Howells /*
12401da177e4SLinus Torvalds * mntpt.c
12411da177e4SLinus Torvalds */
1242754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
1243bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
12444b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
12451da177e4SLinus Torvalds
1246d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
124708e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
12481da177e4SLinus Torvalds
12491da177e4SLinus Torvalds /*
12501da177e4SLinus Torvalds * proc.c
12511da177e4SLinus Torvalds */
1252b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS
1253f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
1254f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
12555b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *);
12565b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *);
12576f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *);
1258b6cfbecaSDavid Howells #else
afs_proc_init(struct afs_net * net)1259b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; }
afs_proc_cleanup(struct afs_net * net)1260b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {}
afs_proc_cell_setup(struct afs_cell * cell)1261b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
afs_proc_cell_remove(struct afs_cell * cell)1262b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
afs_put_sysnames(struct afs_sysnames * sysnames)1263b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1264b6cfbecaSDavid Howells #endif
12651da177e4SLinus Torvalds
126608e0e7c8SDavid Howells /*
1267d2ddc776SDavid Howells * rotate.c
1268d2ddc776SDavid Howells */
1269a310082fSDavid Howells extern bool afs_select_fileserver(struct afs_operation *);
1270e49c7b2fSDavid Howells extern void afs_dump_edestaddrreq(const struct afs_operation *);
1271d2ddc776SDavid Howells
1272d2ddc776SDavid Howells /*
127308e0e7c8SDavid Howells * rxrpc.c
127408e0e7c8SDavid Howells */
1275f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
12768324f0bcSDavid Howells
1277f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
1278f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
1279f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
1280341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
12810b9bf381SDavid Howells extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t);
12820b9bf381SDavid Howells extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
1283f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1284f044c884SDavid Howells const struct afs_call_type *,
128508e0e7c8SDavid Howells size_t, size_t);
128608e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
128708e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
1288b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
128912bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool);
12907126ead9SDavid Howells extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
129108e0e7c8SDavid Howells
afs_see_call(struct afs_call * call,enum afs_call_trace why)1292a5e15707SDavid Howells static inline void afs_see_call(struct afs_call *call, enum afs_call_trace why)
1293a5e15707SDavid Howells {
1294a5e15707SDavid Howells int r = refcount_read(&call->ref);
1295a5e15707SDavid Howells
1296a5e15707SDavid Howells trace_afs_call(call->debug_id, why, r,
1297a5e15707SDavid Howells atomic_read(&call->net->nr_outstanding_calls),
1298a5e15707SDavid Howells __builtin_return_address(0));
1299a5e15707SDavid Howells }
1300a5e15707SDavid Howells
afs_make_op_call(struct afs_operation * op,struct afs_call * call,gfp_t gfp)1301e49c7b2fSDavid Howells static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
1302e49c7b2fSDavid Howells gfp_t gfp)
130320b8391fSDavid Howells {
1304e49c7b2fSDavid Howells op->call = call;
1305a310082fSDavid Howells op->type = call->type;
1306e49c7b2fSDavid Howells call->op = op;
1307e49c7b2fSDavid Howells call->key = op->key;
1308e49c7b2fSDavid Howells call->intr = !(op->flags & AFS_OPERATION_UNINTR);
1309e49c7b2fSDavid Howells afs_make_call(&op->ac, call, gfp);
131020b8391fSDavid Howells }
131120b8391fSDavid Howells
afs_extract_begin(struct afs_call * call,void * buf,size_t size)131212bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
131312bdcf33SDavid Howells {
1314f105da1aSDavid Howells call->iov_len = size;
131512bdcf33SDavid Howells call->kvec[0].iov_base = buf;
131612bdcf33SDavid Howells call->kvec[0].iov_len = size;
1317de4eda9dSAl Viro iov_iter_kvec(&call->def_iter, ITER_DEST, call->kvec, 1, size);
131812bdcf33SDavid Howells }
131912bdcf33SDavid Howells
afs_extract_to_tmp(struct afs_call * call)132012bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call)
132112bdcf33SDavid Howells {
1322f105da1aSDavid Howells call->iov_len = sizeof(call->tmp);
132312bdcf33SDavid Howells afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
132412bdcf33SDavid Howells }
132512bdcf33SDavid Howells
afs_extract_to_tmp64(struct afs_call * call)132612bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call)
132712bdcf33SDavid Howells {
1328f105da1aSDavid Howells call->iov_len = sizeof(call->tmp64);
132912bdcf33SDavid Howells afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
133012bdcf33SDavid Howells }
133112bdcf33SDavid Howells
afs_extract_discard(struct afs_call * call,size_t size)133212bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size)
133312bdcf33SDavid Howells {
1334f105da1aSDavid Howells call->iov_len = size;
1335de4eda9dSAl Viro iov_iter_discard(&call->def_iter, ITER_DEST, size);
133612bdcf33SDavid Howells }
133712bdcf33SDavid Howells
afs_extract_to_buf(struct afs_call * call,size_t size)133812bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
133912bdcf33SDavid Howells {
1340f105da1aSDavid Howells call->iov_len = size;
134112bdcf33SDavid Howells afs_extract_begin(call, call->buffer, size);
134212bdcf33SDavid Howells }
134312bdcf33SDavid Howells
afs_transfer_reply(struct afs_call * call)1344d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
1345372ee163SDavid Howells {
134612bdcf33SDavid Howells return afs_extract_data(call, false);
1347372ee163SDavid Howells }
1348372ee163SDavid Howells
afs_check_call_state(struct afs_call * call,enum afs_call_state state)134998bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
135098bf40cdSDavid Howells enum afs_call_state state)
135198bf40cdSDavid Howells {
135298bf40cdSDavid Howells return READ_ONCE(call->state) == state;
135398bf40cdSDavid Howells }
135498bf40cdSDavid Howells
afs_set_call_state(struct afs_call * call,enum afs_call_state from,enum afs_call_state to)135598bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
135698bf40cdSDavid Howells enum afs_call_state from,
135798bf40cdSDavid Howells enum afs_call_state to)
135898bf40cdSDavid Howells {
135998bf40cdSDavid Howells bool ok = false;
136098bf40cdSDavid Howells
136198bf40cdSDavid Howells spin_lock_bh(&call->state_lock);
136298bf40cdSDavid Howells if (call->state == from) {
136398bf40cdSDavid Howells call->state = to;
136498bf40cdSDavid Howells trace_afs_call_state(call, from, to, 0, 0);
136598bf40cdSDavid Howells ok = true;
136698bf40cdSDavid Howells }
136798bf40cdSDavid Howells spin_unlock_bh(&call->state_lock);
136898bf40cdSDavid Howells return ok;
136998bf40cdSDavid Howells }
137098bf40cdSDavid Howells
afs_set_call_complete(struct afs_call * call,int error,u32 remote_abort)137198bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
137298bf40cdSDavid Howells int error, u32 remote_abort)
137398bf40cdSDavid Howells {
137498bf40cdSDavid Howells enum afs_call_state state;
137598bf40cdSDavid Howells bool ok = false;
137698bf40cdSDavid Howells
137798bf40cdSDavid Howells spin_lock_bh(&call->state_lock);
137898bf40cdSDavid Howells state = call->state;
137998bf40cdSDavid Howells if (state != AFS_CALL_COMPLETE) {
138098bf40cdSDavid Howells call->abort_code = remote_abort;
138198bf40cdSDavid Howells call->error = error;
138298bf40cdSDavid Howells call->state = AFS_CALL_COMPLETE;
138398bf40cdSDavid Howells trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
138498bf40cdSDavid Howells error, remote_abort);
138598bf40cdSDavid Howells ok = true;
138698bf40cdSDavid Howells }
138798bf40cdSDavid Howells spin_unlock_bh(&call->state_lock);
1388dde9f095SDavid Howells if (ok) {
138998bf40cdSDavid Howells trace_afs_call_done(call);
1390dde9f095SDavid Howells
1391dde9f095SDavid Howells /* Asynchronous calls have two refs to release - one from the alloc and
1392dde9f095SDavid Howells * one queued with the work item - and we can't just deallocate the
1393dde9f095SDavid Howells * call because the work item may be queued again.
1394dde9f095SDavid Howells */
1395dde9f095SDavid Howells if (call->drop_ref)
1396dde9f095SDavid Howells afs_put_call(call);
1397dde9f095SDavid Howells }
139898bf40cdSDavid Howells }
139998bf40cdSDavid Howells
140008e0e7c8SDavid Howells /*
140100d3b7a4SDavid Howells * security.c
140200d3b7a4SDavid Howells */
1403be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
140400d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
1405a58823acSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1406a58823acSDavid Howells struct afs_status_cb *);
140700d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
14088b6a666aSDavid Howells extern struct key *afs_request_key_rcu(struct afs_cell *);
14090fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
14104609e1f1SChristian Brauner extern int afs_permission(struct mnt_idmap *, struct inode *, int);
1411be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
141200d3b7a4SDavid Howells
141300d3b7a4SDavid Howells /*
141408e0e7c8SDavid Howells * server.c
141508e0e7c8SDavid Howells */
141608e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
141708e0e7c8SDavid Howells
1418f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *,
1419f044c884SDavid Howells const struct sockaddr_rxrpc *);
1420d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
142181006805SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
142245218193SDavid Howells extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
1423977e5f8eSDavid Howells extern struct afs_server *afs_use_server(struct afs_server *, enum afs_server_trace);
1424977e5f8eSDavid Howells extern void afs_unuse_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1425977e5f8eSDavid Howells extern void afs_unuse_server_notime(struct afs_net *, struct afs_server *, enum afs_server_trace);
142645218193SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1427d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
1428d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
1429f6cbb368SDavid Howells extern void afs_fs_probe_timer(struct timer_list *);
1430f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
1431a310082fSDavid Howells extern bool afs_check_server_record(struct afs_operation *, struct afs_server *);
1432d2ddc776SDavid Howells
afs_inc_servers_outstanding(struct afs_net * net)1433f6cbb368SDavid Howells static inline void afs_inc_servers_outstanding(struct afs_net *net)
1434f6cbb368SDavid Howells {
1435f6cbb368SDavid Howells atomic_inc(&net->servers_outstanding);
1436f6cbb368SDavid Howells }
1437f6cbb368SDavid Howells
afs_dec_servers_outstanding(struct afs_net * net)1438f6cbb368SDavid Howells static inline void afs_dec_servers_outstanding(struct afs_net *net)
1439f6cbb368SDavid Howells {
1440f6cbb368SDavid Howells if (atomic_dec_and_test(&net->servers_outstanding))
1441f6cbb368SDavid Howells wake_up_var(&net->servers_outstanding);
1442f6cbb368SDavid Howells }
1443f6cbb368SDavid Howells
afs_is_probing_server(struct afs_server * server)1444f6cbb368SDavid Howells static inline bool afs_is_probing_server(struct afs_server *server)
1445f6cbb368SDavid Howells {
1446f6cbb368SDavid Howells return list_empty(&server->probe_link);
1447f6cbb368SDavid Howells }
1448f6cbb368SDavid Howells
1449d2ddc776SDavid Howells /*
1450d2ddc776SDavid Howells * server_list.c
1451d2ddc776SDavid Howells */
afs_get_serverlist(struct afs_server_list * slist)1452d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1453d2ddc776SDavid Howells {
1454d2ddc776SDavid Howells refcount_inc(&slist->usage);
1455d2ddc776SDavid Howells return slist;
1456d2ddc776SDavid Howells }
1457d2ddc776SDavid Howells
1458d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1459*0b2bf6fbSDavid Howells struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,
1460*0b2bf6fbSDavid Howells struct key *key,
1461*0b2bf6fbSDavid Howells struct afs_vldb_entry *vldb);
1462d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1463*0b2bf6fbSDavid Howells void afs_attach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist);
1464*0b2bf6fbSDavid Howells void afs_reattach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist,
1465*0b2bf6fbSDavid Howells struct afs_server_list *old);
1466*0b2bf6fbSDavid Howells void afs_detach_volume_from_servers(struct afs_volume *volume, struct afs_server_list *slist);
146708e0e7c8SDavid Howells
146808e0e7c8SDavid Howells /*
146900d3b7a4SDavid Howells * super.c
147000d3b7a4SDavid Howells */
1471f044c884SDavid Howells extern int __init afs_fs_init(void);
14725b86d4ffSDavid Howells extern void afs_fs_exit(void);
147300d3b7a4SDavid Howells
147400d3b7a4SDavid Howells /*
147508e0e7c8SDavid Howells * vlclient.c
147608e0e7c8SDavid Howells */
14770a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
14780a5143f2SDavid Howells const char *, int);
14790a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
14800b9bf381SDavid Howells extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *,
14810b9bf381SDavid Howells struct key *, struct afs_vlserver *, unsigned int);
14820a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
1483c3e9f888SDavid Howells extern char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *);
14840a5143f2SDavid Howells
14850a5143f2SDavid Howells /*
14868a070a96SDavid Howells * vl_alias.c
14878a070a96SDavid Howells */
14888a070a96SDavid Howells extern int afs_cell_detect_alias(struct afs_cell *, struct key *);
14898a070a96SDavid Howells
14908a070a96SDavid Howells /*
14913bf0fb6fSDavid Howells * vl_probe.c
14923bf0fb6fSDavid Howells */
14933bf0fb6fSDavid Howells extern void afs_vlserver_probe_result(struct afs_call *);
14943bf0fb6fSDavid Howells extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
14953bf0fb6fSDavid Howells extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
14963bf0fb6fSDavid Howells
14973bf0fb6fSDavid Howells /*
14980a5143f2SDavid Howells * vl_rotate.c
14990a5143f2SDavid Howells */
15000a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
15010a5143f2SDavid Howells struct afs_cell *, struct key *);
15020a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *);
15030a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
15040a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
15050a5143f2SDavid Howells
15060a5143f2SDavid Howells /*
15070a5143f2SDavid Howells * vlserver_list.c
15080a5143f2SDavid Howells */
afs_get_vlserver(struct afs_vlserver * vlserver)15090a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
15100a5143f2SDavid Howells {
1511c56f9ec8SDavid Howells refcount_inc(&vlserver->ref);
15120a5143f2SDavid Howells return vlserver;
15130a5143f2SDavid Howells }
15140a5143f2SDavid Howells
afs_get_vlserverlist(struct afs_vlserver_list * vllist)15150a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
15160a5143f2SDavid Howells {
15170a5143f2SDavid Howells if (vllist)
1518c56f9ec8SDavid Howells refcount_inc(&vllist->ref);
15190a5143f2SDavid Howells return vllist;
15200a5143f2SDavid Howells }
15210a5143f2SDavid Howells
15220a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
15230a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
15240a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
15250a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
15260a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
15270a5143f2SDavid Howells const void *, size_t);
152808e0e7c8SDavid Howells
152908e0e7c8SDavid Howells /*
153008e0e7c8SDavid Howells * volume.c
153108e0e7c8SDavid Howells */
153213fcc683SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1533523d27cdSDavid Howells extern int afs_activate_volume(struct afs_volume *);
1534d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
1535c3215484SDavid Howells bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace reason);
1536cca37d45SDavid Howells extern struct afs_volume *afs_get_volume(struct afs_volume *, enum afs_volume_trace);
1537cca37d45SDavid Howells extern void afs_put_volume(struct afs_net *, struct afs_volume *, enum afs_volume_trace);
1538a310082fSDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
153908e0e7c8SDavid Howells
154031143d5dSDavid Howells /*
154131143d5dSDavid Howells * write.c
154231143d5dSDavid Howells */
1543c7f75ef3SDavid Howells #ifdef CONFIG_AFS_FSCACHE
15448fb72b4aSMatthew Wilcox (Oracle) bool afs_dirty_folio(struct address_space *, struct folio *);
1545c7f75ef3SDavid Howells #else
15468fb72b4aSMatthew Wilcox (Oracle) #define afs_dirty_folio filemap_dirty_folio
1547c7f75ef3SDavid Howells #endif
154815b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping,
15499d6b0cd7SMatthew Wilcox (Oracle) loff_t pos, unsigned len,
155015b4650eSNick Piggin struct page **pagep, void **fsdata);
155115b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping,
155215b4650eSNick Piggin loff_t pos, unsigned len, unsigned copied,
155315b4650eSNick Piggin struct page *page, void *fsdata);
155431143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *);
155531143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
155650b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
155702c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
15580722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
15594343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
1560a42442ddSMatthew Wilcox (Oracle) int afs_launder_folio(struct folio *);
156131143d5dSDavid Howells
1562d3e3b7eaSDavid Howells /*
1563d3e3b7eaSDavid Howells * xattr.c
1564d3e3b7eaSDavid Howells */
1565d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[];
156631143d5dSDavid Howells
156730062bd1SDavid Howells /*
156830062bd1SDavid Howells * yfsclient.c
156930062bd1SDavid Howells */
1570e49c7b2fSDavid Howells extern void yfs_fs_fetch_data(struct afs_operation *);
1571e49c7b2fSDavid Howells extern void yfs_fs_create_file(struct afs_operation *);
1572e49c7b2fSDavid Howells extern void yfs_fs_make_dir(struct afs_operation *);
1573e49c7b2fSDavid Howells extern void yfs_fs_remove_file2(struct afs_operation *);
1574e49c7b2fSDavid Howells extern void yfs_fs_remove_file(struct afs_operation *);
1575e49c7b2fSDavid Howells extern void yfs_fs_remove_dir(struct afs_operation *);
1576e49c7b2fSDavid Howells extern void yfs_fs_link(struct afs_operation *);
1577e49c7b2fSDavid Howells extern void yfs_fs_symlink(struct afs_operation *);
1578e49c7b2fSDavid Howells extern void yfs_fs_rename(struct afs_operation *);
1579e49c7b2fSDavid Howells extern void yfs_fs_store_data(struct afs_operation *);
1580e49c7b2fSDavid Howells extern void yfs_fs_setattr(struct afs_operation *);
1581e49c7b2fSDavid Howells extern void yfs_fs_get_volume_status(struct afs_operation *);
1582e49c7b2fSDavid Howells extern void yfs_fs_set_lock(struct afs_operation *);
1583e49c7b2fSDavid Howells extern void yfs_fs_extend_lock(struct afs_operation *);
1584e49c7b2fSDavid Howells extern void yfs_fs_release_lock(struct afs_operation *);
1585e49c7b2fSDavid Howells extern void yfs_fs_fetch_status(struct afs_operation *);
1586e49c7b2fSDavid Howells extern void yfs_fs_inline_bulk_status(struct afs_operation *);
1587d2ddc776SDavid Howells
1588ae46578bSDavid Howells struct yfs_acl {
1589ae46578bSDavid Howells struct afs_acl *acl; /* Dir/file/symlink ACL */
1590ae46578bSDavid Howells struct afs_acl *vol_acl; /* Whole volume ACL */
1591ae46578bSDavid Howells u32 inherit_flag; /* True if ACL is inherited from parent dir */
1592ae46578bSDavid Howells u32 num_cleaned; /* Number of ACEs removed due to subject removal */
1593ae46578bSDavid Howells unsigned int flags;
1594ae46578bSDavid Howells #define YFS_ACL_WANT_ACL 0x01 /* Set if caller wants ->acl */
1595ae46578bSDavid Howells #define YFS_ACL_WANT_VOL_ACL 0x02 /* Set if caller wants ->vol_acl */
1596ae46578bSDavid Howells };
1597ae46578bSDavid Howells
1598ae46578bSDavid Howells extern void yfs_free_opaque_acl(struct yfs_acl *);
1599e49c7b2fSDavid Howells extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
1600e49c7b2fSDavid Howells extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
1601ae46578bSDavid Howells
1602d2ddc776SDavid Howells /*
1603d2ddc776SDavid Howells * Miscellaneous inline functions.
1604d2ddc776SDavid Howells */
AFS_FS_I(struct inode * inode)1605d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1606d2ddc776SDavid Howells {
1607874c8ca1SDavid Howells return container_of(inode, struct afs_vnode, netfs.inode);
1608d2ddc776SDavid Howells }
1609d2ddc776SDavid Howells
AFS_VNODE_TO_I(struct afs_vnode * vnode)1610d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1611d2ddc776SDavid Howells {
1612874c8ca1SDavid Howells return &vnode->netfs.inode;
1613d2ddc776SDavid Howells }
1614d2ddc776SDavid Howells
1615e49c7b2fSDavid Howells /*
1616e49c7b2fSDavid Howells * Note that a dentry got changed. We need to set d_fsdata to the data version
1617e49c7b2fSDavid Howells * number derived from the result of the operation. It doesn't matter if
1618e49c7b2fSDavid Howells * d_fsdata goes backwards as we'll just revalidate.
1619e49c7b2fSDavid Howells */
afs_update_dentry_version(struct afs_operation * op,struct afs_vnode_param * dir_vp,struct dentry * dentry)1620e49c7b2fSDavid Howells static inline void afs_update_dentry_version(struct afs_operation *op,
1621e49c7b2fSDavid Howells struct afs_vnode_param *dir_vp,
1622e49c7b2fSDavid Howells struct dentry *dentry)
1623e49c7b2fSDavid Howells {
1624e49c7b2fSDavid Howells if (!op->error)
1625e49c7b2fSDavid Howells dentry->d_fsdata =
1626e49c7b2fSDavid Howells (void *)(unsigned long)dir_vp->scb.status.data_version;
1627e49c7b2fSDavid Howells }
1628e49c7b2fSDavid Howells
1629b6489a49SDavid Howells /*
16309d37e1caSDavid Howells * Set the file size and block count. Estimate the number of 512 bytes blocks
16319d37e1caSDavid Howells * used, rounded up to nearest 1K for consistency with other AFS clients.
16329d37e1caSDavid Howells */
afs_set_i_size(struct afs_vnode * vnode,u64 size)16339d37e1caSDavid Howells static inline void afs_set_i_size(struct afs_vnode *vnode, u64 size)
16349d37e1caSDavid Howells {
1635874c8ca1SDavid Howells i_size_write(&vnode->netfs.inode, size);
1636874c8ca1SDavid Howells vnode->netfs.inode.i_blocks = ((size + 1023) >> 10) << 1;
16379d37e1caSDavid Howells }
16389d37e1caSDavid Howells
16399d37e1caSDavid Howells /*
1640b6489a49SDavid Howells * Check for a conflicting operation on a directory that we just unlinked from.
1641b6489a49SDavid Howells * If someone managed to sneak a link or an unlink in on the file we just
1642b6489a49SDavid Howells * unlinked, we won't be able to trust nlink on an AFS file (but not YFS).
1643b6489a49SDavid Howells */
afs_check_dir_conflict(struct afs_operation * op,struct afs_vnode_param * dvp)1644b6489a49SDavid Howells static inline void afs_check_dir_conflict(struct afs_operation *op,
1645b6489a49SDavid Howells struct afs_vnode_param *dvp)
1646b6489a49SDavid Howells {
1647b6489a49SDavid Howells if (dvp->dv_before + dvp->dv_delta != dvp->scb.status.data_version)
1648b6489a49SDavid Howells op->flags |= AFS_OPERATION_DIR_CONFLICT;
1649b6489a49SDavid Howells }
1650b6489a49SDavid Howells
afs_io_error(struct afs_call * call,enum afs_io_error where)1651f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1652f51375cdSDavid Howells {
1653f51375cdSDavid Howells trace_afs_io_error(call->debug_id, -EIO, where);
1654f51375cdSDavid Howells return -EIO;
1655f51375cdSDavid Howells }
1656f51375cdSDavid Howells
afs_bad(struct afs_vnode * vnode,enum afs_file_error where)1657f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1658f51375cdSDavid Howells {
1659f51375cdSDavid Howells trace_afs_file_error(vnode, -EIO, where);
1660f51375cdSDavid Howells return -EIO;
1661f51375cdSDavid Howells }
1662d2ddc776SDavid Howells
166308e0e7c8SDavid Howells /*****************************************************************************/
166408e0e7c8SDavid Howells /*
166508e0e7c8SDavid Howells * debug tracing
166608e0e7c8SDavid Howells */
166708e0e7c8SDavid Howells extern unsigned afs_debug;
166808e0e7c8SDavid Howells
166908e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1670ad16df84SSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
167108e0e7c8SDavid Howells
1672530b6412SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1673530b6412SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
167408e0e7c8SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
167508e0e7c8SDavid Howells
167608e0e7c8SDavid Howells
167708e0e7c8SDavid Howells #if defined(__KDEBUG)
167808e0e7c8SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
167908e0e7c8SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
168008e0e7c8SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
168108e0e7c8SDavid Howells
168208e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
168308e0e7c8SDavid Howells #define AFS_DEBUG_KENTER 0x01
168408e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE 0x02
168508e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG 0x04
168608e0e7c8SDavid Howells
168708e0e7c8SDavid Howells #define _enter(FMT,...) \
168808e0e7c8SDavid Howells do { \
168908e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
169008e0e7c8SDavid Howells kenter(FMT,##__VA_ARGS__); \
169108e0e7c8SDavid Howells } while (0)
169208e0e7c8SDavid Howells
169308e0e7c8SDavid Howells #define _leave(FMT,...) \
169408e0e7c8SDavid Howells do { \
169508e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
169608e0e7c8SDavid Howells kleave(FMT,##__VA_ARGS__); \
169708e0e7c8SDavid Howells } while (0)
169808e0e7c8SDavid Howells
169908e0e7c8SDavid Howells #define _debug(FMT,...) \
170008e0e7c8SDavid Howells do { \
170108e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
170208e0e7c8SDavid Howells kdebug(FMT,##__VA_ARGS__); \
170308e0e7c8SDavid Howells } while (0)
170408e0e7c8SDavid Howells
170508e0e7c8SDavid Howells #else
170612fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
170712fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
170812fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
170908e0e7c8SDavid Howells #endif
171008e0e7c8SDavid Howells
171108e0e7c8SDavid Howells /*
171208e0e7c8SDavid Howells * debug assertion checking
171308e0e7c8SDavid Howells */
171408e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
171508e0e7c8SDavid Howells
171608e0e7c8SDavid Howells #define ASSERT(X) \
171708e0e7c8SDavid Howells do { \
171808e0e7c8SDavid Howells if (unlikely(!(X))) { \
171908e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
172008e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
172108e0e7c8SDavid Howells BUG(); \
172208e0e7c8SDavid Howells } \
172308e0e7c8SDavid Howells } while(0)
172408e0e7c8SDavid Howells
172508e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \
172608e0e7c8SDavid Howells do { \
172708e0e7c8SDavid Howells if (unlikely(!((X) OP (Y)))) { \
172808e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
172908e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
173008e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \
173108e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
173208e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
173308e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
173408e0e7c8SDavid Howells BUG(); \
173508e0e7c8SDavid Howells } \
173608e0e7c8SDavid Howells } while(0)
173708e0e7c8SDavid Howells
1738416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \
1739416351f2SDavid Howells do { \
1740416351f2SDavid Howells if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1741416351f2SDavid Howells printk(KERN_ERR "\n"); \
1742416351f2SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
1743416351f2SDavid Howells printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1744416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \
1745416351f2SDavid Howells (unsigned long)(H)); \
1746416351f2SDavid Howells printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1747416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \
1748416351f2SDavid Howells (unsigned long)(H)); \
1749416351f2SDavid Howells BUG(); \
1750416351f2SDavid Howells } \
1751416351f2SDavid Howells } while(0)
1752416351f2SDavid Howells
175308e0e7c8SDavid Howells #define ASSERTIF(C, X) \
175408e0e7c8SDavid Howells do { \
175508e0e7c8SDavid Howells if (unlikely((C) && !(X))) { \
175608e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
175708e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
175808e0e7c8SDavid Howells BUG(); \
175908e0e7c8SDavid Howells } \
176008e0e7c8SDavid Howells } while(0)
176108e0e7c8SDavid Howells
176208e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \
176308e0e7c8SDavid Howells do { \
176408e0e7c8SDavid Howells if (unlikely((C) && !((X) OP (Y)))) { \
176508e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
176608e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
176708e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \
176808e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
176908e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
177008e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
177108e0e7c8SDavid Howells BUG(); \
177208e0e7c8SDavid Howells } \
177308e0e7c8SDavid Howells } while(0)
177408e0e7c8SDavid Howells
177508e0e7c8SDavid Howells #else
177608e0e7c8SDavid Howells
177708e0e7c8SDavid Howells #define ASSERT(X) \
177808e0e7c8SDavid Howells do { \
177908e0e7c8SDavid Howells } while(0)
178008e0e7c8SDavid Howells
178108e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \
178208e0e7c8SDavid Howells do { \
178308e0e7c8SDavid Howells } while(0)
178408e0e7c8SDavid Howells
1785416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \
1786416351f2SDavid Howells do { \
1787416351f2SDavid Howells } while(0)
1788416351f2SDavid Howells
178908e0e7c8SDavid Howells #define ASSERTIF(C, X) \
179008e0e7c8SDavid Howells do { \
179108e0e7c8SDavid Howells } while(0)
179208e0e7c8SDavid Howells
179308e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \
179408e0e7c8SDavid Howells do { \
179508e0e7c8SDavid Howells } while(0)
179608e0e7c8SDavid Howells
179708e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1798