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;
36f49b594dSDavid Howells struct afs_server_probe;
3708e0e7c8SDavid Howells
386c6c1d63SDavid Howells /*
396c6c1d63SDavid Howells * Partial file-locking emulation mode. (The problem being that AFS3 only
406c6c1d63SDavid Howells * allows whole-file locks and no upgrading/downgrading).
416c6c1d63SDavid Howells */
426c6c1d63SDavid Howells enum afs_flock_mode {
436c6c1d63SDavid Howells afs_flock_mode_unset,
446c6c1d63SDavid Howells afs_flock_mode_local, /* Local locking only */
456c6c1d63SDavid Howells afs_flock_mode_openafs, /* Don't get server lock for a partial lock */
466c6c1d63SDavid Howells afs_flock_mode_strict, /* Always get a server lock for a partial lock */
476c6c1d63SDavid Howells afs_flock_mode_write, /* Get an exclusive server lock for a partial lock */
486c6c1d63SDavid Howells };
496c6c1d63SDavid Howells
5013fcc683SDavid Howells struct afs_fs_context {
5100d3b7a4SDavid Howells bool force; /* T to force cell type */
52bec5eb61Swanglei bool autocell; /* T if set auto mount operation */
534d673da1SDavid Howells bool dyn_root; /* T if dynamic root */
5413fcc683SDavid Howells bool no_cell; /* T if the source is "none" (for dynroot) */
556c6c1d63SDavid Howells enum afs_flock_mode flock_mode; /* Partial file-locking emulation mode */
5600d3b7a4SDavid Howells afs_voltype_t type; /* type of volume requested */
5713fcc683SDavid Howells unsigned int volnamesz; /* size of volume name */
5800d3b7a4SDavid Howells const char *volname; /* name of volume to mount */
595b86d4ffSDavid Howells struct afs_net *net; /* the AFS net namespace stuff */
6000d3b7a4SDavid Howells struct afs_cell *cell; /* cell in which to find volume */
6100d3b7a4SDavid Howells struct afs_volume *volume; /* volume record */
6200d3b7a4SDavid Howells struct key *key; /* key to use for secure mounting */
6300d3b7a4SDavid Howells };
6400d3b7a4SDavid Howells
658e8d7f13SDavid Howells enum afs_call_state {
6698bf40cdSDavid Howells AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
6798bf40cdSDavid Howells AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
6898bf40cdSDavid Howells AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
6998bf40cdSDavid Howells AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
7098bf40cdSDavid Howells AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
7198bf40cdSDavid Howells AFS_CALL_SV_REPLYING, /* Server: Replying */
7298bf40cdSDavid Howells AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
738e8d7f13SDavid Howells AFS_CALL_COMPLETE, /* Completed or failed */
748e8d7f13SDavid Howells };
75f044c884SDavid Howells
76f94f70d3SDavid Howells /*
77f94f70d3SDavid Howells * Address preferences.
78f94f70d3SDavid Howells */
79f94f70d3SDavid Howells struct afs_addr_preference {
80f94f70d3SDavid Howells union {
81f94f70d3SDavid Howells struct in_addr ipv4_addr; /* AF_INET address to compare against */
82f94f70d3SDavid Howells struct in6_addr ipv6_addr; /* AF_INET6 address to compare against */
83f94f70d3SDavid Howells };
84f94f70d3SDavid Howells sa_family_t family; /* Which address to use */
85f94f70d3SDavid Howells u16 prio; /* Priority */
86f94f70d3SDavid Howells u8 subnet_mask; /* How many bits to compare */
87f94f70d3SDavid Howells };
88f94f70d3SDavid Howells
89f94f70d3SDavid Howells struct afs_addr_preference_list {
90f94f70d3SDavid Howells struct rcu_head rcu;
91f94f70d3SDavid Howells u16 version; /* Incremented when prefs list changes */
92f94f70d3SDavid Howells u8 ipv6_off; /* Offset of IPv6 addresses */
93f94f70d3SDavid Howells u8 nr; /* Number of addresses in total */
94f94f70d3SDavid Howells u8 max_prefs; /* Number of prefs allocated */
95f94f70d3SDavid Howells struct afs_addr_preference prefs[] __counted_by(max_prefs);
96f94f70d3SDavid Howells };
97f94f70d3SDavid Howells
9872904d7bSDavid Howells struct afs_address {
9972904d7bSDavid Howells struct rxrpc_peer *peer;
100aa453becSDavid Howells short last_error; /* Last error from this address */
101d14cf8edSDavid Howells u16 prio; /* Address priority */
10272904d7bSDavid Howells };
10372904d7bSDavid Howells
10408e0e7c8SDavid Howells /*
1058b2a464cSDavid Howells * List of server addresses.
1068b2a464cSDavid Howells */
1078b2a464cSDavid Howells struct afs_addr_list {
108ddd2b85fSJann Horn struct rcu_head rcu;
1098b2a464cSDavid Howells refcount_t usage;
110d2ddc776SDavid Howells u32 version; /* Version */
1111e5d8493SDavid Howells unsigned int debug_id;
112d14cf8edSDavid Howells unsigned int addr_pref_version; /* Version of address preference list */
11368eb64c3SDavid Howells unsigned char max_addrs;
11468eb64c3SDavid Howells unsigned char nr_addrs;
1153bf0fb6fSDavid Howells unsigned char preferred; /* Preferred address */
11668eb64c3SDavid Howells unsigned char nr_ipv4; /* Number of IPv4 addresses */
1170a5143f2SDavid Howells enum dns_record_source source:8;
1180a5143f2SDavid Howells enum dns_lookup_status status:8;
119aa4917d6SDavid Howells unsigned long probe_failed; /* Mask of addrs that failed locally/ICMP */
1203bf0fb6fSDavid Howells unsigned long responded; /* Mask of addrs that responded */
12172904d7bSDavid Howells struct afs_address addrs[] __counted_by(max_addrs);
12268eb64c3SDavid Howells #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
1238b2a464cSDavid Howells };
1248b2a464cSDavid Howells
1258b2a464cSDavid Howells /*
12608e0e7c8SDavid Howells * a record of an in-progress RxRPC call
12708e0e7c8SDavid Howells */
12808e0e7c8SDavid Howells struct afs_call {
12908e0e7c8SDavid Howells const struct afs_call_type *type; /* type of call */
13008e0e7c8SDavid Howells wait_queue_head_t waitq; /* processes awaiting completion */
131341f741fSDavid Howells struct work_struct async_work; /* async I/O processor */
13208e0e7c8SDavid Howells struct work_struct work; /* actual work processor */
13308e0e7c8SDavid Howells struct rxrpc_call *rxcall; /* RxRPC call handle */
134e38f299eSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */
13508e0e7c8SDavid Howells struct key *key; /* security for this call */
136f044c884SDavid Howells struct afs_net *net; /* The network namespace */
137a6853b9cSDavid Howells struct afs_server *server; /* The fileserver record if fs op (pins ref) */
138a6853b9cSDavid Howells struct afs_vlserver *vlserver; /* The vlserver record if vl op */
13908e0e7c8SDavid Howells void *request; /* request data (first part) */
140f105da1aSDavid Howells size_t iov_len; /* Size of *iter to be used */
141fc276122SDavid Howells struct iov_iter def_iter; /* Default buffer/data iterator */
142bd80d8a8SDavid Howells struct iov_iter *write_iter; /* Iterator defining write to be made */
143fc276122SDavid Howells struct iov_iter *iter; /* Iterator currently in use */
144fc276122SDavid Howells union { /* Convenience for ->def_iter */
14512bdcf33SDavid Howells struct kvec kvec[1];
14612bdcf33SDavid Howells struct bio_vec bvec[1];
14712bdcf33SDavid Howells };
14808e0e7c8SDavid Howells void *buffer; /* reply receive buffer */
149ffba718eSDavid Howells union {
150f49b594dSDavid Howells struct afs_endpoint_state *probe;
151f49b594dSDavid Howells struct afs_addr_list *vl_probe;
152ffba718eSDavid Howells struct afs_addr_list *ret_alist;
153ffba718eSDavid Howells struct afs_vldb_entry *ret_vldb;
154c3e9f888SDavid Howells char *ret_str;
155ffba718eSDavid Howells };
156abcbd3bfSDavid Howells struct afs_fid fid; /* Primary vnode ID (or all zeroes) */
157f49b594dSDavid Howells unsigned char probe_index; /* Address in ->probe_alist */
158e49c7b2fSDavid Howells struct afs_operation *op;
159ffba718eSDavid Howells unsigned int server_index;
160c56f9ec8SDavid Howells refcount_t ref;
1618e8d7f13SDavid Howells enum afs_call_state state;
16298bf40cdSDavid Howells spinlock_t state_lock;
16308e0e7c8SDavid Howells int error; /* error code */
164d001648eSDavid Howells u32 abort_code; /* Remote abort ID or 0 */
165db099c62SDavid Howells unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
16608e0e7c8SDavid Howells unsigned request_size; /* size of request data */
16708e0e7c8SDavid Howells unsigned reply_max; /* maximum size of reply */
168bcd89270SMarc Dionne unsigned count2; /* count used in unmarshalling */
16908e0e7c8SDavid Howells unsigned char unmarshall; /* unmarshalling phase */
170dde9f095SDavid Howells bool drop_ref; /* T if need to drop ref for incoming call */
171d001648eSDavid Howells bool need_attention; /* T if RxRPC poked us */
17256ff9c83SDavid Howells bool async; /* T if asynchronous */
173a68f4a27SDavid Howells bool upgrade; /* T to request service upgrade */
17420b8391fSDavid Howells bool intr; /* T if interruptible */
17538355eecSDavid Howells bool unmarshalling_error; /* T if an unmarshalling error occurred */
176aa453becSDavid Howells bool responded; /* Got a response from the call (may be abort) */
177bf99a53cSDavid Howells u16 service_id; /* Actual service ID (after upgrade) */
178a25e21f0SDavid Howells unsigned int debug_id; /* Trace ID */
17950a2c953SDavid Howells u32 operation_ID; /* operation ID for an incoming call */
18008e0e7c8SDavid Howells u32 count; /* count for use in unmarshalling */
18112bdcf33SDavid Howells union { /* place to extract temporary data */
18212bdcf33SDavid Howells struct {
18312bdcf33SDavid Howells __be32 tmp_u;
18412bdcf33SDavid Howells __be32 tmp;
18512bdcf33SDavid Howells } __attribute__((packed));
18612bdcf33SDavid Howells __be64 tmp64;
18712bdcf33SDavid Howells };
1887903192cSDavid Howells ktime_t issue_time; /* Time of issue of operation */
18908e0e7c8SDavid Howells };
19008e0e7c8SDavid Howells
19108e0e7c8SDavid Howells struct afs_call_type {
19200d3b7a4SDavid Howells const char *name;
193025db80cSDavid Howells unsigned int op; /* Really enum afs_fs_operation */
19400d3b7a4SDavid Howells
19508e0e7c8SDavid Howells /* deliver request or reply data to an call
19608e0e7c8SDavid Howells * - returning an error will cause the call to be aborted
19708e0e7c8SDavid Howells */
198d001648eSDavid Howells int (*deliver)(struct afs_call *call);
19908e0e7c8SDavid Howells
20008e0e7c8SDavid Howells /* clean up a call */
20108e0e7c8SDavid Howells void (*destructor)(struct afs_call *call);
202341f741fSDavid Howells
203341f741fSDavid Howells /* Work function */
204341f741fSDavid Howells void (*work)(struct work_struct *work);
2053bf0fb6fSDavid Howells
2063bf0fb6fSDavid Howells /* Call done function (gets called immediately on success or failure) */
2073bf0fb6fSDavid Howells void (*done)(struct afs_call *call);
20808e0e7c8SDavid Howells };
20908e0e7c8SDavid Howells
21008e0e7c8SDavid Howells /*
2114343d008SDavid Howells * Key available for writeback on a file.
2124343d008SDavid Howells */
2134343d008SDavid Howells struct afs_wb_key {
2144343d008SDavid Howells refcount_t usage;
2154343d008SDavid Howells struct key *key;
2164343d008SDavid Howells struct list_head vnode_link; /* Link in vnode->wb_keys */
2174343d008SDavid Howells };
2184343d008SDavid Howells
2194343d008SDavid Howells /*
220215804a9SDavid Howells * AFS open file information record. Pointed to by file->private_data.
221215804a9SDavid Howells */
222215804a9SDavid Howells struct afs_file {
223215804a9SDavid Howells struct key *key; /* The key this file was opened with */
2244343d008SDavid Howells struct afs_wb_key *wb; /* Writeback key record for this file */
225215804a9SDavid Howells };
226215804a9SDavid Howells
afs_file_key(struct file * file)227215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file)
228215804a9SDavid Howells {
229215804a9SDavid Howells struct afs_file *af = file->private_data;
230215804a9SDavid Howells
231215804a9SDavid Howells return af->key;
232215804a9SDavid Howells }
233215804a9SDavid Howells
234215804a9SDavid Howells /*
235196ee9cdSDavid Howells * Record of an outstanding read operation on a vnode.
236196ee9cdSDavid Howells */
237196ee9cdSDavid Howells struct afs_read {
238196ee9cdSDavid Howells loff_t pos; /* Where to start reading */
239e8e581a8SDavid Howells loff_t len; /* How much we're asking for */
240196ee9cdSDavid Howells loff_t actual_len; /* How much we're actually getting */
241f3ddee8dSDavid Howells loff_t file_size; /* File size returned by server */
242c69bf479SDavid Howells struct key *key; /* The key to use to reissue the read */
243c4508464SDavid Howells struct afs_vnode *vnode; /* The file being read into. */
2446a19114bSDavid Howells struct netfs_io_subrequest *subreq; /* Fscache helper read request this belongs to */
245f3ddee8dSDavid Howells afs_dataversion_t data_version; /* Version number returned by server */
246f3ddee8dSDavid Howells refcount_t usage;
247c4508464SDavid Howells unsigned int call_debug_id;
248196ee9cdSDavid Howells unsigned int nr_pages;
249c4508464SDavid Howells int error;
250c4508464SDavid Howells void (*done)(struct afs_read *);
251c4508464SDavid Howells void (*cleanup)(struct afs_read *);
252c4508464SDavid Howells struct iov_iter *iter; /* Iterator representing the buffer */
253c4508464SDavid Howells struct iov_iter def_iter; /* Default iterator */
254196ee9cdSDavid Howells };
255196ee9cdSDavid Howells
256196ee9cdSDavid Howells /*
25708e0e7c8SDavid Howells * AFS superblock private data
25808e0e7c8SDavid Howells * - there's one superblock per volume
25908e0e7c8SDavid Howells */
26008e0e7c8SDavid Howells struct afs_super_info {
2615b86d4ffSDavid Howells struct net *net_ns; /* Network namespace */
26249566f6fSDavid Howells struct afs_cell *cell; /* The cell in which the volume resides */
26308e0e7c8SDavid Howells struct afs_volume *volume; /* volume record */
2646c6c1d63SDavid Howells enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
2654d673da1SDavid Howells bool dyn_root; /* True if dynamic root */
26608e0e7c8SDavid Howells };
26708e0e7c8SDavid Howells
AFS_FS_S(struct super_block * sb)26808e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
26908e0e7c8SDavid Howells {
27008e0e7c8SDavid Howells return sb->s_fs_info;
27108e0e7c8SDavid Howells }
27208e0e7c8SDavid Howells
27308e0e7c8SDavid Howells extern struct file_system_type afs_fs_type;
27408e0e7c8SDavid Howells
27508e0e7c8SDavid Howells /*
2766f8880d8SDavid Howells * Set of substitutes for @sys.
2776f8880d8SDavid Howells */
2786f8880d8SDavid Howells struct afs_sysnames {
2796f8880d8SDavid Howells #define AFS_NR_SYSNAME 16
2806f8880d8SDavid Howells char *subs[AFS_NR_SYSNAME];
2816f8880d8SDavid Howells refcount_t usage;
2826f8880d8SDavid Howells unsigned short nr;
2836f8880d8SDavid Howells char blank[1];
2846f8880d8SDavid Howells };
2856f8880d8SDavid Howells
2866f8880d8SDavid Howells /*
287f044c884SDavid Howells * AFS network namespace record.
288f044c884SDavid Howells */
289f044c884SDavid Howells struct afs_net {
2905b86d4ffSDavid Howells struct net *net; /* Backpointer to the owning net namespace */
291f044c884SDavid Howells struct afs_uuid uuid;
292f044c884SDavid Howells bool live; /* F if this namespace is being removed */
293f044c884SDavid Howells
294f044c884SDavid Howells /* AF_RXRPC I/O stuff */
295f044c884SDavid Howells struct socket *socket;
296f044c884SDavid Howells struct afs_call *spare_incoming_call;
297f044c884SDavid Howells struct work_struct charge_preallocation_work;
298f044c884SDavid Howells struct mutex socket_mutex;
299f044c884SDavid Howells atomic_t nr_outstanding_calls;
300f044c884SDavid Howells atomic_t nr_superblocks;
301f044c884SDavid Howells
302f044c884SDavid Howells /* Cell database */
303989782dcSDavid Howells struct rb_root cells;
30492e3cc91SDavid Howells struct afs_cell *ws_cell;
305989782dcSDavid Howells struct work_struct cells_manager;
306989782dcSDavid Howells struct timer_list cells_timer;
307989782dcSDavid Howells atomic_t cells_outstanding;
30892e3cc91SDavid Howells struct rw_semaphore cells_lock;
3098a070a96SDavid Howells struct mutex cells_alias_lock;
310f044c884SDavid Howells
3110da0b7fdSDavid Howells struct mutex proc_cells_lock;
3126b3944e4SDavid Howells struct hlist_head proc_cells;
313f044c884SDavid Howells
314d2ddc776SDavid Howells /* Known servers. Theoretically each fileserver can only be in one
315d2ddc776SDavid Howells * cell, but in practice, people create aliases and subsets and there's
316d2ddc776SDavid Howells * no easy way to distinguish them.
317d2ddc776SDavid Howells */
318f6cbb368SDavid Howells seqlock_t fs_lock; /* For fs_servers, fs_probe_*, fs_proc */
319d2ddc776SDavid Howells struct rb_root fs_servers; /* afs_server (by server UUID or address) */
320f6cbb368SDavid Howells struct list_head fs_probe_fast; /* List of afs_server to probe at 30s intervals */
321f6cbb368SDavid Howells struct list_head fs_probe_slow; /* List of afs_server to probe at 5m intervals */
322d2ddc776SDavid Howells struct hlist_head fs_proc; /* procfs servers list */
323d2ddc776SDavid Howells
324bfacaf71SMarc Dionne struct hlist_head fs_addresses; /* afs_server (by lowest IPv6 addr) */
325d2ddc776SDavid Howells seqlock_t fs_addr_lock; /* For fs_addresses[46] */
326d2ddc776SDavid Howells
327d2ddc776SDavid Howells struct work_struct fs_manager;
328d2ddc776SDavid Howells struct timer_list fs_timer;
329f6cbb368SDavid Howells
330f6cbb368SDavid Howells struct work_struct fs_prober;
331f6cbb368SDavid Howells struct timer_list fs_probe_timer;
332d2ddc776SDavid Howells atomic_t servers_outstanding;
333f044c884SDavid Howells
334f044c884SDavid Howells /* File locking renewal management */
335f044c884SDavid Howells struct mutex lock_manager_mutex;
336f044c884SDavid Howells
337f044c884SDavid Howells /* Misc */
3380da0b7fdSDavid Howells struct super_block *dynroot_sb; /* Dynamic root mount superblock */
339f044c884SDavid Howells struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
3406f8880d8SDavid Howells struct afs_sysnames *sysnames;
3416f8880d8SDavid Howells rwlock_t sysnames_lock;
342f94f70d3SDavid Howells struct afs_addr_preference_list __rcu *address_prefs;
343f94f70d3SDavid Howells u16 address_pref_version;
344d55b4da4SDavid Howells
345d55b4da4SDavid Howells /* Statistics counters */
346d55b4da4SDavid Howells atomic_t n_lookup; /* Number of lookups done */
347d55b4da4SDavid Howells atomic_t n_reval; /* Number of dentries needing revalidation */
348d55b4da4SDavid Howells atomic_t n_inval; /* Number of invalidations by the server */
349508cae68SMatthew Wilcox (Oracle) atomic_t n_relpg; /* Number of invalidations by release_folio */
350d55b4da4SDavid Howells atomic_t n_read_dir; /* Number of directory pages read */
35163a4681fSDavid Howells atomic_t n_dir_cr; /* Number of directory entry creation edits */
35263a4681fSDavid Howells atomic_t n_dir_rm; /* Number of directory entry removal edits */
35376a5cb6fSDavid Howells atomic_t n_stores; /* Number of store ops */
35476a5cb6fSDavid Howells atomic_long_t n_store_bytes; /* Number of bytes stored */
35576a5cb6fSDavid Howells atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
35676a5cb6fSDavid Howells atomic_t n_fetches; /* Number of data fetch ops */
357f044c884SDavid Howells };
358f044c884SDavid Howells
3596f8880d8SDavid Howells extern const char afs_init_sysname[];
360f044c884SDavid Howells
361989782dcSDavid Howells enum afs_cell_state {
362989782dcSDavid Howells AFS_CELL_UNSET,
363989782dcSDavid Howells AFS_CELL_ACTIVATING,
364989782dcSDavid Howells AFS_CELL_ACTIVE,
365989782dcSDavid Howells AFS_CELL_DEACTIVATING,
366989782dcSDavid Howells AFS_CELL_INACTIVE,
367989782dcSDavid Howells AFS_CELL_FAILED,
3681d0e850aSDavid Howells AFS_CELL_REMOVED,
369989782dcSDavid Howells };
370989782dcSDavid Howells
371f044c884SDavid Howells /*
372d2ddc776SDavid Howells * AFS cell record.
373d2ddc776SDavid Howells *
374d2ddc776SDavid Howells * This is a tricky concept to get right as it is possible to create aliases
375d2ddc776SDavid Howells * simply by pointing AFSDB/SRV records for two names at the same set of VL
376d2ddc776SDavid Howells * servers; it is also possible to do things like setting up two sets of VL
377d2ddc776SDavid Howells * servers, one of which provides a superset of the volumes provided by the
378d2ddc776SDavid Howells * other (for internal/external division, for example).
379d2ddc776SDavid Howells *
380d2ddc776SDavid Howells * Cells only exist in the sense that (a) a cell's name maps to a set of VL
381d2ddc776SDavid Howells * servers and (b) a cell's name is used by the client to select the key to use
382d2ddc776SDavid Howells * for authentication and encryption. The cell name is not typically used in
383d2ddc776SDavid Howells * the protocol.
384d2ddc776SDavid Howells *
3858a070a96SDavid Howells * Two cells are determined to be aliases if they have an explicit alias (YFS
3868a070a96SDavid Howells * only), share any VL servers in common or have at least one volume in common.
3878a070a96SDavid Howells * "In common" means that the address list of the VL servers or the fileservers
3888a070a96SDavid Howells * share at least one endpoint.
38908e0e7c8SDavid Howells */
39008e0e7c8SDavid Howells struct afs_cell {
391989782dcSDavid Howells union {
392989782dcSDavid Howells struct rcu_head rcu;
393989782dcSDavid Howells struct rb_node net_node; /* Node in net->cells */
394989782dcSDavid Howells };
395989782dcSDavid Howells struct afs_net *net;
3968a070a96SDavid Howells struct afs_cell *alias_of; /* The cell this is an alias of */
3978a070a96SDavid Howells struct afs_volume *root_volume; /* The root.cell volume if there is one */
39800d3b7a4SDavid Howells struct key *anonymous_key; /* anonymous user key for this cell */
399989782dcSDavid Howells struct work_struct manager; /* Manager for init/deinit/dns */
4006b3944e4SDavid Howells struct hlist_node proc_link; /* /proc cell list link */
401989782dcSDavid Howells time64_t dns_expiry; /* Time AFSDB/SRV record expires */
402989782dcSDavid Howells time64_t last_inactive; /* Time of last drop of usage count */
403c56f9ec8SDavid Howells refcount_t ref; /* Struct refcount */
40488c853c3SDavid Howells atomic_t active; /* Active usage counter */
405989782dcSDavid Howells unsigned long flags;
406d5c32c89SDavid Howells #define AFS_CELL_FL_NO_GC 0 /* The cell was added manually, don't auto-gc */
407d5c32c89SDavid Howells #define AFS_CELL_FL_DO_LOOKUP 1 /* DNS lookup requested */
4088a070a96SDavid Howells #define AFS_CELL_FL_CHECK_ALIAS 2 /* Need to check for aliases */
409989782dcSDavid Howells enum afs_cell_state state;
410989782dcSDavid Howells short error;
411d5c32c89SDavid Howells enum dns_record_source dns_source:8; /* Latest source of data from lookup */
412d5c32c89SDavid Howells enum dns_lookup_status dns_status:8; /* Latest status of data from lookup */
413d5c32c89SDavid Howells unsigned int dns_lookup_count; /* Counter of DNS lookups */
414dca54a7bSDavid Howells unsigned int debug_id;
415989782dcSDavid Howells
41620325960SDavid Howells /* The volumes belonging to this cell */
41732222f09SDavid Howells struct rw_semaphore vs_lock; /* Lock for server->volumes */
41820325960SDavid Howells struct rb_root volumes; /* Tree of volumes on this server */
41920325960SDavid Howells struct hlist_head proc_volumes; /* procfs volume list */
42020325960SDavid Howells seqlock_t volume_lock; /* For volumes */
42120325960SDavid Howells
422d2ddc776SDavid Howells /* Active fileserver interaction state. */
42320325960SDavid Howells struct rb_root fs_servers; /* afs_server (by server UUID) */
42420325960SDavid Howells seqlock_t fs_lock; /* For fs_servers */
425989782dcSDavid Howells
426d2ddc776SDavid Howells /* VL server list. */
4270a5143f2SDavid Howells rwlock_t vl_servers_lock; /* Lock on vl_servers */
4280a5143f2SDavid Howells struct afs_vlserver_list __rcu *vl_servers;
4290a5143f2SDavid Howells
430989782dcSDavid Howells u8 name_len; /* Length of name */
431719fdd32SDavid Howells char *name; /* Cell name, case-flattened and NUL-padded */
43208e0e7c8SDavid Howells };
43308e0e7c8SDavid Howells
43408e0e7c8SDavid Howells /*
4350a5143f2SDavid Howells * Volume Location server record.
4360a5143f2SDavid Howells */
4370a5143f2SDavid Howells struct afs_vlserver {
4380a5143f2SDavid Howells struct rcu_head rcu;
4390a5143f2SDavid Howells struct afs_addr_list __rcu *addresses; /* List of addresses for this VL server */
4400a5143f2SDavid Howells unsigned long flags;
4410a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED 0 /* The VL server has been probed */
4420a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING 1 /* VL server is being probed */
4433bf0fb6fSDavid Howells #define AFS_VLSERVER_FL_IS_YFS 2 /* Server is YFS not AFS */
444b95b3094SDavid Howells #define AFS_VLSERVER_FL_RESPONDING 3 /* VL server is responding */
4450a5143f2SDavid Howells rwlock_t lock; /* Lock on addresses */
446c56f9ec8SDavid Howells refcount_t ref;
447b95b3094SDavid Howells unsigned int rtt; /* Server's current RTT in uS */
448e6a7d7f7SDavid Howells unsigned int debug_id;
4493bf0fb6fSDavid Howells
4503bf0fb6fSDavid Howells /* Probe state */
4513bf0fb6fSDavid Howells wait_queue_head_t probe_wq;
4523bf0fb6fSDavid Howells atomic_t probe_outstanding;
4533bf0fb6fSDavid Howells spinlock_t probe_lock;
4543bf0fb6fSDavid Howells struct {
45572904d7bSDavid Howells unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */
4563bf0fb6fSDavid Howells u32 abort_code;
4573bf0fb6fSDavid Howells short error;
458fb72cd3dSDavid Howells unsigned short flags;
459fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_RESPONDED 0x01 /* At least once response (may be abort) */
460fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_IS_YFS 0x02 /* The peer appears to be YFS */
461fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_NOT_YFS 0x04 /* The peer appears not to be YFS */
462fb72cd3dSDavid Howells #define AFS_VLSERVER_PROBE_LOCAL_FAILURE 0x08 /* A local failure prevented a probe */
4633bf0fb6fSDavid Howells } probe;
4643bf0fb6fSDavid Howells
465e38f299eSDavid Howells u16 service_id; /* Service ID we're using */
4660a5143f2SDavid Howells u16 port;
4673bf0fb6fSDavid Howells u16 name_len; /* Length of name */
4680a5143f2SDavid Howells char name[]; /* Server name, case-flattened */
4690a5143f2SDavid Howells };
4700a5143f2SDavid Howells
4710a5143f2SDavid Howells /*
4720a5143f2SDavid Howells * Weighted list of Volume Location servers.
4730a5143f2SDavid Howells */
4740a5143f2SDavid Howells struct afs_vlserver_entry {
4750a5143f2SDavid Howells u16 priority; /* Preference (as SRV) */
4760a5143f2SDavid Howells u16 weight; /* Weight (as SRV) */
4770a5143f2SDavid Howells enum dns_record_source source:8;
4780a5143f2SDavid Howells enum dns_lookup_status status:8;
4790a5143f2SDavid Howells struct afs_vlserver *server;
4800a5143f2SDavid Howells };
4810a5143f2SDavid Howells
4820a5143f2SDavid Howells struct afs_vlserver_list {
4830a5143f2SDavid Howells struct rcu_head rcu;
484c56f9ec8SDavid Howells refcount_t ref;
4850a5143f2SDavid Howells u8 nr_servers;
4860a5143f2SDavid Howells u8 index; /* Server currently in use */
4873bf0fb6fSDavid Howells u8 preferred; /* Preferred server */
4880a5143f2SDavid Howells enum dns_record_source source:8;
4890a5143f2SDavid Howells enum dns_lookup_status status:8;
4900a5143f2SDavid Howells rwlock_t lock;
4910a5143f2SDavid Howells struct afs_vlserver_entry servers[];
4920a5143f2SDavid Howells };
4930a5143f2SDavid Howells
4940a5143f2SDavid Howells /*
495d2ddc776SDavid Howells * Cached VLDB entry.
496d2ddc776SDavid Howells *
497d2ddc776SDavid Howells * This is pointed to by cell->vldb_entries, indexed by name.
49808e0e7c8SDavid Howells */
499d2ddc776SDavid Howells struct afs_vldb_entry {
500d2ddc776SDavid Howells afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
50100d3b7a4SDavid Howells
502d2ddc776SDavid Howells unsigned long flags;
503d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
504d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
505d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
506d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
507d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
508d2ddc776SDavid Howells
509d2ddc776SDavid Howells uuid_t fs_server[AFS_NMAXNSERVERS];
51081006805SDavid Howells u32 addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
511d2ddc776SDavid Howells u8 fs_mask[AFS_NMAXNSERVERS];
51208e0e7c8SDavid Howells #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
51308e0e7c8SDavid Howells #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
51408e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
515d3acd81eSDavid Howells u8 vlsf_flags[AFS_NMAXNSERVERS];
516d2ddc776SDavid Howells short error;
517d2ddc776SDavid Howells u8 nr_servers; /* Number of server records */
518d2ddc776SDavid Howells u8 name_len;
519d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
52008e0e7c8SDavid Howells };
52108e0e7c8SDavid Howells
52208e0e7c8SDavid Howells /*
523f49b594dSDavid Howells * Fileserver endpoint state. The records the addresses of a fileserver's
524f49b594dSDavid Howells * endpoints and the state and result of a round of probing on them. This
525f49b594dSDavid Howells * allows the rotation algorithm to access those results without them being
526f49b594dSDavid Howells * erased by a subsequent round of probing.
527f49b594dSDavid Howells */
528f49b594dSDavid Howells struct afs_endpoint_state {
529f49b594dSDavid Howells struct rcu_head rcu;
530f49b594dSDavid Howells struct afs_addr_list *addresses; /* The addresses being probed */
531f49b594dSDavid Howells unsigned long responsive_set; /* Bitset of responsive endpoints */
532f49b594dSDavid Howells unsigned long failed_set; /* Bitset of endpoints we failed to probe */
533f49b594dSDavid Howells refcount_t ref;
534f49b594dSDavid Howells unsigned int server_id; /* Debug ID of server */
535f49b594dSDavid Howells unsigned int probe_seq; /* Probe sequence (from server::probe_counter) */
536f49b594dSDavid Howells atomic_t nr_probing; /* Number of outstanding probes */
537f49b594dSDavid Howells unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */
538f49b594dSDavid Howells s32 abort_code;
539f49b594dSDavid Howells short error;
54021c1f410SDavid Howells unsigned long flags;
54121c1f410SDavid Howells #define AFS_ESTATE_RESPONDED 0 /* Set if the server responded */
54221c1f410SDavid Howells #define AFS_ESTATE_SUPERSEDED 1 /* Set if this record has been superseded */
54321c1f410SDavid Howells #define AFS_ESTATE_IS_YFS 2 /* Set if probe upgraded to YFS */
54421c1f410SDavid Howells #define AFS_ESTATE_NOT_YFS 3 /* Set if probe didn't upgrade to YFS */
54521c1f410SDavid Howells #define AFS_ESTATE_LOCAL_FAILURE 4 /* Set if there was a local failure (eg. ENOMEM) */
546f49b594dSDavid Howells };
547f49b594dSDavid Howells
548f49b594dSDavid Howells /*
549d2ddc776SDavid Howells * Record of fileserver with which we're actively communicating.
55008e0e7c8SDavid Howells */
55108e0e7c8SDavid Howells struct afs_server {
552d2ddc776SDavid Howells struct rcu_head rcu;
553d2ddc776SDavid Howells union {
554d2ddc776SDavid Howells uuid_t uuid; /* Server ID */
555d2ddc776SDavid Howells struct afs_uuid _uuid;
556d2ddc776SDavid Howells };
557c435ee34SDavid Howells
55820325960SDavid Howells struct afs_cell *cell; /* Cell to which belongs (pins ref) */
5593c4c4075SDavid Howells struct rb_node uuid_rb; /* Link in net->fs_servers */
5603c4c4075SDavid Howells struct afs_server __rcu *uuid_next; /* Next server with same UUID */
5613c4c4075SDavid Howells struct afs_server *uuid_prev; /* Previous server with same UUID */
562f6cbb368SDavid Howells struct list_head probe_link; /* Link in net->fs_probe_list */
563bfacaf71SMarc Dionne struct hlist_node addr_link; /* Link in net->fs_addresses6 */
564d2ddc776SDavid Howells struct hlist_node proc_link; /* Link in net->fs_proc */
565ca0e79a4SDavid Howells struct list_head volumes; /* RCU list of afs_server_entry objects */
566d2ddc776SDavid Howells struct afs_server *gc_next; /* Next server in manager's list */
567977e5f8eSDavid Howells time64_t unuse_time; /* Time at which last unused */
568c435ee34SDavid Howells unsigned long flags;
569f3c130e6SDavid Howells #define AFS_SERVER_FL_RESPONDING 0 /* The server is responding */
57032275d3fSDavid Howells #define AFS_SERVER_FL_UPDATING 1
57132275d3fSDavid Howells #define AFS_SERVER_FL_NEEDS_UPDATE 2 /* Fileserver address list is out of date */
57232275d3fSDavid Howells #define AFS_SERVER_FL_NOT_READY 4 /* The record is not ready for use */
57332275d3fSDavid Howells #define AFS_SERVER_FL_NOT_FOUND 5 /* VL server says no such server */
57432275d3fSDavid Howells #define AFS_SERVER_FL_VL_FAIL 6 /* Failed to access VL server */
575f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
57632275d3fSDavid Howells #define AFS_SERVER_FL_IS_YFS 16 /* Server is YFS not AFS */
57732275d3fSDavid Howells #define AFS_SERVER_FL_NO_IBULK 17 /* Fileserver doesn't support FS.InlineBulkStatus */
57832275d3fSDavid Howells #define AFS_SERVER_FL_NO_RM2 18 /* Fileserver doesn't support YFS.RemoveFile2 */
579b537a3c2SDavid Howells #define AFS_SERVER_FL_HAS_FS64 19 /* Fileserver supports FS.{Fetch,Store}Data64 */
580c56f9ec8SDavid Howells refcount_t ref; /* Object refcount */
581977e5f8eSDavid Howells atomic_t active; /* Active user count */
582d2ddc776SDavid Howells u32 addr_version; /* Address list version */
583e38f299eSDavid Howells u16 service_id; /* Service ID we're using. */
584f3c130e6SDavid Howells unsigned int rtt; /* Server's current RTT in uS */
58545218193SDavid Howells unsigned int debug_id; /* Debugging ID for traces */
58608e0e7c8SDavid Howells
58708e0e7c8SDavid Howells /* file service access */
588d2ddc776SDavid Howells rwlock_t fs_lock; /* access lock */
58908e0e7c8SDavid Howells
5903bf0fb6fSDavid Howells /* Probe state */
591f49b594dSDavid Howells struct afs_endpoint_state __rcu *endpoint_state; /* Latest endpoint/probe state */
592f6cbb368SDavid Howells unsigned long probed_at; /* Time last probe was dispatched (jiffies) */
5933bf0fb6fSDavid Howells wait_queue_head_t probe_wq;
594f49b594dSDavid Howells unsigned int probe_counter; /* Number of probes issued */
5953bf0fb6fSDavid Howells spinlock_t probe_lock;
596c435ee34SDavid Howells };
597c435ee34SDavid Howells
598d3acd81eSDavid Howells enum afs_ro_replicating {
599d3acd81eSDavid Howells AFS_RO_NOT_REPLICATING, /* Not doing replication */
600d3acd81eSDavid Howells AFS_RO_REPLICATING_USE_OLD, /* Replicating; use old version */
601d3acd81eSDavid Howells AFS_RO_REPLICATING_USE_NEW, /* Replicating; switch to new version */
602d3acd81eSDavid Howells } __mode(byte);
603d3acd81eSDavid Howells
604c435ee34SDavid Howells /*
605194d28cfSDavid Howells * Replaceable volume server list.
60608e0e7c8SDavid Howells */
607d2ddc776SDavid Howells struct afs_server_entry {
608d2ddc776SDavid Howells struct afs_server *server;
609ca0e79a4SDavid Howells struct afs_volume *volume;
610ca0e79a4SDavid Howells struct list_head slink; /* Link in server->volumes */
611453924deSDavid Howells time64_t cb_expires_at; /* Time at which volume-level callback expires */
612d3acd81eSDavid Howells unsigned long flags;
613d3acd81eSDavid Howells #define AFS_SE_EXCLUDED 0 /* Set if server is to be excluded in rotation */
61428f4c580SDavid Howells #define AFS_SE_VOLUME_OFFLINE 1 /* Set if volume offline notice given */
61528f4c580SDavid Howells #define AFS_SE_VOLUME_BUSY 2 /* Set if volume busy notice given */
616d2ddc776SDavid Howells };
617d2ddc776SDavid Howells
618d2ddc776SDavid Howells struct afs_server_list {
619e6bace73SDavid Howells struct rcu_head rcu;
620d2ddc776SDavid Howells refcount_t usage;
621ca0e79a4SDavid Howells bool attached; /* T if attached to servers */
622d3acd81eSDavid Howells enum afs_ro_replicating ro_replicating; /* RW->RO update (probably) in progress */
6233bf0fb6fSDavid Howells unsigned char nr_servers;
624d2ddc776SDavid Howells unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
625d2ddc776SDavid Howells unsigned int seq; /* Set to ->servers_seq when installed */
626d4a96becSDavid Howells rwlock_t lock;
627d2ddc776SDavid Howells struct afs_server_entry servers[];
62808e0e7c8SDavid Howells };
62908e0e7c8SDavid Howells
63008e0e7c8SDavid Howells /*
631d2ddc776SDavid Howells * Live AFS volume management.
63208e0e7c8SDavid Howells */
633d2ddc776SDavid Howells struct afs_volume {
63420325960SDavid Howells struct rcu_head rcu;
635ca0e79a4SDavid Howells afs_volid_t vid; /* The volume ID of this volume */
636ca0e79a4SDavid Howells afs_volid_t vids[AFS_MAXTYPES]; /* All associated volume IDs */
637c56f9ec8SDavid Howells refcount_t ref;
638d2ddc776SDavid Howells time64_t update_at; /* Time at which to next update */
639d2ddc776SDavid Howells struct afs_cell *cell; /* Cell to which belongs (pins ref) */
64020325960SDavid Howells struct rb_node cell_node; /* Link in cell->volumes */
64120325960SDavid Howells struct hlist_node proc_link; /* Link in cell->proc_volumes */
64220325960SDavid Howells struct super_block __rcu *sb; /* Superblock on which inodes reside */
643445f9b69SDavid Howells struct work_struct destructor; /* Deferred destructor */
644d2ddc776SDavid Howells unsigned long flags;
645d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
646d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
647d2ddc776SDavid Howells #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
648d2ddc776SDavid Howells #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
64928f4c580SDavid Howells #define AFS_VOLUME_MAYBE_NO_IBULK 4 /* - T if some servers don't have InlineBulkStatus */
65028f4c580SDavid Howells #define AFS_VOLUME_RM_TREE 5 /* - Set if volume removed from cell->volumes */
651d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE
652523d27cdSDavid Howells struct fscache_volume *cache; /* Caching cookie */
653d2ddc776SDavid Howells #endif
6548a070a96SDavid Howells struct afs_server_list __rcu *servers; /* List of servers on which volume resides */
655d2ddc776SDavid Howells rwlock_t servers_lock; /* Lock for ->servers */
656d2ddc776SDavid Howells unsigned int servers_seq; /* Incremented each time ->servers changes */
657d2ddc776SDavid Howells
65816069e13SDavid Howells /* RO release tracking */
65916069e13SDavid Howells struct mutex volsync_lock; /* Time/state evaluation lock */
66016069e13SDavid Howells time64_t creation_time; /* Volume creation time (or TIME64_MIN) */
66116069e13SDavid Howells time64_t update_time; /* Volume update time (or TIME64_MIN) */
66216069e13SDavid Howells
66316069e13SDavid Howells /* Callback management */
664453924deSDavid Howells struct mutex cb_check_lock; /* Lock to control race to check after v_break */
665453924deSDavid Howells time64_t cb_expires_at; /* Earliest volume callback expiry time */
66616069e13SDavid Howells atomic_t cb_ro_snapshot; /* RO volume update-from-snapshot counter */
66716069e13SDavid Howells atomic_t cb_v_break; /* Volume-break event counter. */
668453924deSDavid Howells atomic_t cb_v_check; /* Volume-break has-been-checked counter. */
66916069e13SDavid Howells atomic_t cb_scrub; /* Scrub-all-data event counter. */
67090fa9b64SDavid Howells rwlock_t cb_v_break_lock;
671453924deSDavid Howells struct rw_semaphore open_mmaps_lock;
672453924deSDavid Howells struct list_head open_mmaps; /* List of vnodes that are mmapped */
67368251f0aSDavid Howells
674d2ddc776SDavid Howells afs_voltype_t type; /* type of volume */
675d2ddc776SDavid Howells char type_force; /* force volume type (suppress R/O -> R/W) */
676d2ddc776SDavid Howells u8 name_len;
677d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
67808e0e7c8SDavid Howells };
67908e0e7c8SDavid Howells
6800fafdc9fSDavid Howells enum afs_lock_state {
6810fafdc9fSDavid Howells AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
6820fafdc9fSDavid Howells AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
6830fafdc9fSDavid Howells AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
6840fafdc9fSDavid Howells AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
6850fafdc9fSDavid Howells AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
6860fafdc9fSDavid Howells AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
6870fafdc9fSDavid Howells AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
688cdfb26b4SDavid Howells AFS_VNODE_LOCK_DELETED, /* The vnode has been deleted whilst we have a lock */
6890fafdc9fSDavid Howells };
6900fafdc9fSDavid Howells
69108e0e7c8SDavid Howells /*
692f8de483eSDavid Howells * AFS inode private data.
693f8de483eSDavid Howells *
694f8de483eSDavid Howells * Note that afs_alloc_inode() *must* reset anything that could incorrectly
695f8de483eSDavid Howells * leak from one inode to another.
69608e0e7c8SDavid Howells */
69708e0e7c8SDavid Howells struct afs_vnode {
698874c8ca1SDavid Howells struct netfs_inode netfs; /* Netfslib context and vfs inode */
69908e0e7c8SDavid Howells struct afs_volume *volume; /* volume on which vnode resides */
70008e0e7c8SDavid Howells struct afs_fid fid; /* the file identifier for this inode */
70108e0e7c8SDavid Howells struct afs_file_status status; /* AFS status info for this file */
702a4ff7401SDavid Howells afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
703fe342cf7SDavid Howells struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
704d2ddc776SDavid Howells struct mutex io_lock; /* Lock for serialising I/O on this mutex */
705b61f7dcfSDavid Howells struct rw_semaphore validate_lock; /* lock for validating this vnode */
70679ddbfa5SDavid Howells struct rw_semaphore rmdir_lock; /* Lock for rmdir vs sillyrename */
70779ddbfa5SDavid Howells struct key *silly_key; /* Silly rename key */
7084343d008SDavid Howells spinlock_t wb_lock; /* lock for wb_keys */
70908e0e7c8SDavid Howells spinlock_t lock; /* waitqueue/flags lock */
71008e0e7c8SDavid Howells unsigned long flags;
711260a9803SDavid Howells #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
712f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
71308e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
71408e0e7c8SDavid Howells #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
71508e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
7160fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
7170fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
7185a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
719b6489a49SDavid Howells #define AFS_VNODE_SILLY_DELETED 9 /* Set if file has been silly-deleted */
72022650f14SDavid Howells #define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
72108e0e7c8SDavid Howells
7224343d008SDavid Howells struct list_head wb_keys; /* List of keys available for writeback */
723e8d6c554SDavid Howells struct list_head pending_locks; /* locks waiting to be granted */
724e8d6c554SDavid Howells struct list_head granted_locks; /* locks granted on this file */
725e8d6c554SDavid Howells struct delayed_work lock_work; /* work to be done in locking */
7260fafdc9fSDavid Howells struct key *lock_key; /* Key to be used in lock ops */
727a690f60aSDavid Howells ktime_t locked_at; /* Time at which lock obtained */
7280fafdc9fSDavid Howells enum afs_lock_state lock_state : 8;
7290fafdc9fSDavid Howells afs_lock_type_t lock_type : 8;
73031143d5dSDavid Howells
73108e0e7c8SDavid Howells /* outstanding callback notification on this file */
7326e0e99d5SDavid Howells struct work_struct cb_work; /* Work for mmap'd files */
7336e0e99d5SDavid Howells struct list_head cb_mmap_link; /* Link in cell->fs_open_mmaps */
73420325960SDavid Howells void *cb_server; /* Server with callback/filelock */
7356e0e99d5SDavid Howells atomic_t cb_nr_mmap; /* Number of mmaps */
736453924deSDavid Howells unsigned int cb_ro_snapshot; /* RO volume release counter on ->volume */
737453924deSDavid Howells unsigned int cb_scrub; /* Scrub counter on ->volume */
738c435ee34SDavid Howells unsigned int cb_break; /* Break counter on vnode */
739453924deSDavid Howells unsigned int cb_v_check; /* Break check counter on ->volume */
74020325960SDavid Howells seqlock_t cb_lock; /* Lock for ->cb_server, ->status, ->cb_*break */
741c435ee34SDavid Howells
742453924deSDavid Howells atomic64_t cb_expires_at; /* time at which callback expires */
743453924deSDavid Howells #define AFS_NO_CB_PROMISE TIME64_MIN
74408e0e7c8SDavid Howells };
74508e0e7c8SDavid Howells
afs_vnode_cache(struct afs_vnode * vnode)74612bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
74712bdcf33SDavid Howells {
74812bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE
749e81fb419SLinus Torvalds return netfs_i_cookie(&vnode->netfs);
75012bdcf33SDavid Howells #else
75112bdcf33SDavid Howells return NULL;
75212bdcf33SDavid Howells #endif
75312bdcf33SDavid Howells }
75412bdcf33SDavid Howells
afs_vnode_set_cache(struct afs_vnode * vnode,struct fscache_cookie * cookie)755bc899ee1SDavid Howells static inline void afs_vnode_set_cache(struct afs_vnode *vnode,
756bc899ee1SDavid Howells struct fscache_cookie *cookie)
757bc899ee1SDavid Howells {
758bc899ee1SDavid Howells #ifdef CONFIG_AFS_FSCACHE
759874c8ca1SDavid Howells vnode->netfs.cache = cookie;
760b4fa966fSDavid Howells if (cookie)
761b4fa966fSDavid Howells mapping_set_release_always(vnode->netfs.inode.i_mapping);
762bc899ee1SDavid Howells #endif
763bc899ee1SDavid Howells }
764bc899ee1SDavid Howells
76500d3b7a4SDavid Howells /*
76600d3b7a4SDavid Howells * cached security record for one user's attempt to access a vnode
76700d3b7a4SDavid Howells */
76800d3b7a4SDavid Howells struct afs_permit {
76900d3b7a4SDavid Howells struct key *key; /* RxRPC ticket holding a security context */
770be080a6fSDavid Howells afs_access_t access; /* CallerAccess value for this key */
77100d3b7a4SDavid Howells };
77200d3b7a4SDavid Howells
77300d3b7a4SDavid Howells /*
774be080a6fSDavid Howells * Immutable cache of CallerAccess records from attempts to access vnodes.
775be080a6fSDavid Howells * These may be shared between multiple vnodes.
77600d3b7a4SDavid Howells */
77700d3b7a4SDavid Howells struct afs_permits {
778be080a6fSDavid Howells struct rcu_head rcu;
779be080a6fSDavid Howells struct hlist_node hash_node; /* Link in hash */
780be080a6fSDavid Howells unsigned long h; /* Hash value for this permit list */
781be080a6fSDavid Howells refcount_t usage;
782be080a6fSDavid Howells unsigned short nr_permits; /* Number of records */
783be080a6fSDavid Howells bool invalidated; /* Invalidated due to key change */
784aade1533SKees Cook struct afs_permit permits[] __counted_by(nr_permits); /* List of permits sorted by key pointer */
78500d3b7a4SDavid Howells };
78600d3b7a4SDavid Howells
787b908fe6bSDavid Howells /*
7884584ae96SDavid Howells * Error prioritisation and accumulation.
7894584ae96SDavid Howells */
7904584ae96SDavid Howells struct afs_error {
791aa453becSDavid Howells s32 abort_code; /* Cumulative abort code */
792aa453becSDavid Howells short error; /* Cumulative error */
7934584ae96SDavid Howells bool responded; /* T if server responded */
794aa453becSDavid Howells bool aborted; /* T if ->error is from an abort */
7954584ae96SDavid Howells };
7964584ae96SDavid Howells
7974584ae96SDavid Howells /*
7980a5143f2SDavid Howells * Cursor for iterating over a set of volume location servers.
7990a5143f2SDavid Howells */
8000a5143f2SDavid Howells struct afs_vl_cursor {
8010a5143f2SDavid Howells struct afs_cell *cell; /* The cell we're querying */
8020a5143f2SDavid Howells struct afs_vlserver_list *server_list; /* Current server list (pins ref) */
8033bf0fb6fSDavid Howells struct afs_vlserver *server; /* Server on which this resides */
80498f9fda2SDavid Howells struct afs_addr_list *alist; /* Current address list (pins ref) */
8050a5143f2SDavid Howells struct key *key; /* Key for the server */
806905b8615SDavid Howells unsigned long untried_servers; /* Bitmask of untried servers */
80798f9fda2SDavid Howells unsigned long addr_tried; /* Tried addresses */
808aa453becSDavid Howells struct afs_error cumul_error; /* Cumulative error */
80998f9fda2SDavid Howells unsigned int debug_id;
810aa453becSDavid Howells s32 call_abort_code;
811aa453becSDavid Howells short call_error; /* Error from single call */
812905b8615SDavid Howells short server_index; /* Current server */
81398f9fda2SDavid Howells signed char addr_index; /* Current address */
8140a5143f2SDavid Howells unsigned short flags;
8150a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */
8160a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */
8170a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */
818aa453becSDavid Howells short nr_iterations; /* Number of server iterations */
819aa453becSDavid Howells bool call_responded; /* T if the current address responded */
8200a5143f2SDavid Howells };
8210a5143f2SDavid Howells
8220a5143f2SDavid Howells /*
823495f2ae9SDavid Howells * Fileserver state tracking for an operation. An array of these is kept,
824495f2ae9SDavid Howells * indexed by server index.
825495f2ae9SDavid Howells */
826495f2ae9SDavid Howells struct afs_server_state {
827495f2ae9SDavid Howells /* Tracking of fileserver probe state. Other operations may interfere
828495f2ae9SDavid Howells * by probing a fileserver when accessing other volumes.
829495f2ae9SDavid Howells */
830495f2ae9SDavid Howells unsigned int probe_seq;
831495f2ae9SDavid Howells unsigned long untried_addrs; /* Addresses we haven't tried yet */
832495f2ae9SDavid Howells struct wait_queue_entry probe_waiter;
833495f2ae9SDavid Howells struct afs_endpoint_state *endpoint_state; /* Endpoint state being monitored */
834495f2ae9SDavid Howells };
835495f2ae9SDavid Howells
836495f2ae9SDavid Howells /*
837e49c7b2fSDavid Howells * Fileserver operation methods.
838e49c7b2fSDavid Howells */
839e49c7b2fSDavid Howells struct afs_operation_ops {
840e49c7b2fSDavid Howells void (*issue_afs_rpc)(struct afs_operation *op);
841e49c7b2fSDavid Howells void (*issue_yfs_rpc)(struct afs_operation *op);
842e49c7b2fSDavid Howells void (*success)(struct afs_operation *op);
843e49c7b2fSDavid Howells void (*aborted)(struct afs_operation *op);
844dc419184SDavid Howells void (*failed)(struct afs_operation *op);
845e49c7b2fSDavid Howells void (*edit_dir)(struct afs_operation *op);
846e49c7b2fSDavid Howells void (*put)(struct afs_operation *op);
847e49c7b2fSDavid Howells };
848e49c7b2fSDavid Howells
849e49c7b2fSDavid Howells struct afs_vnode_param {
850e49c7b2fSDavid Howells struct afs_vnode *vnode;
851e49c7b2fSDavid Howells struct afs_fid fid; /* Fid to access */
852e49c7b2fSDavid Howells struct afs_status_cb scb; /* Returned status and callback promise */
853e49c7b2fSDavid Howells afs_dataversion_t dv_before; /* Data version before the call */
854453924deSDavid Howells unsigned int cb_break_before; /* cb_break before the call */
855e49c7b2fSDavid Howells u8 dv_delta; /* Expected change in data version */
856793fe82eSDavid Howells bool put_vnode:1; /* T if we have a ref on the vnode */
857793fe82eSDavid Howells bool need_io_lock:1; /* T if we need the I/O lock on this */
858793fe82eSDavid Howells bool update_ctime:1; /* Need to update the ctime */
859793fe82eSDavid Howells bool set_size:1; /* Must update i_size */
860b6489a49SDavid Howells bool op_unlinked:1; /* True if file was unlinked by op */
861a9e5c87cSDavid Howells bool speculative:1; /* T if speculative status fetch (no vnode lock) */
86222650f14SDavid Howells bool modification:1; /* Set if the content gets modified */
863e49c7b2fSDavid Howells };
864e49c7b2fSDavid Howells
865e49c7b2fSDavid Howells /*
866e49c7b2fSDavid Howells * Fileserver operation wrapper, handling server and address rotation
867e49c7b2fSDavid Howells * asynchronously. May make simultaneous calls to multiple servers.
8688b2a464cSDavid Howells */
869a310082fSDavid Howells struct afs_operation {
870e49c7b2fSDavid Howells struct afs_net *net; /* Network namespace */
871e49c7b2fSDavid Howells struct key *key; /* Key for the cell */
872a58823acSDavid Howells const struct afs_call_type *type; /* Type of call done */
873e49c7b2fSDavid Howells const struct afs_operation_ops *ops;
874e49c7b2fSDavid Howells
875e49c7b2fSDavid Howells /* Parameters/results for the operation */
876e49c7b2fSDavid Howells struct afs_volume *volume; /* Volume being accessed */
877e49c7b2fSDavid Howells struct afs_vnode_param file[2];
878e49c7b2fSDavid Howells struct afs_vnode_param *more_files;
87916069e13SDavid Howells struct afs_volsync pre_volsync; /* Volsync before op */
88016069e13SDavid Howells struct afs_volsync volsync; /* Volsync returned by op */
881e49c7b2fSDavid Howells struct dentry *dentry; /* Dentry to be altered */
882e49c7b2fSDavid Howells struct dentry *dentry_2; /* Second dentry to be altered */
883e49c7b2fSDavid Howells struct timespec64 mtime; /* Modification time to record */
884da8d0755SDavid Howells struct timespec64 ctime; /* Change time to set */
885aa453becSDavid Howells struct afs_error cumul_error; /* Cumulative error */
886e49c7b2fSDavid Howells short nr_files; /* Number of entries in file[], more_files */
887e49c7b2fSDavid Howells unsigned int debug_id;
888e49c7b2fSDavid Howells
889e49c7b2fSDavid Howells unsigned int cb_v_break; /* Volume break counter before op */
890e49c7b2fSDavid Howells
891e49c7b2fSDavid Howells union {
892e49c7b2fSDavid Howells struct {
893e49c7b2fSDavid Howells int which; /* Which ->file[] to fetch for */
894e49c7b2fSDavid Howells } fetch_status;
895e49c7b2fSDavid Howells struct {
896e49c7b2fSDavid Howells int reason; /* enum afs_edit_dir_reason */
897e49c7b2fSDavid Howells mode_t mode;
898e49c7b2fSDavid Howells const char *symlink;
899e49c7b2fSDavid Howells } create;
900e49c7b2fSDavid Howells struct {
901e49c7b2fSDavid Howells bool need_rehash;
902e49c7b2fSDavid Howells } unlink;
903e49c7b2fSDavid Howells struct {
904e49c7b2fSDavid Howells struct dentry *rehash;
905e49c7b2fSDavid Howells struct dentry *tmp;
906e49c7b2fSDavid Howells bool new_negative;
907e49c7b2fSDavid Howells } rename;
908e49c7b2fSDavid Howells struct {
909e49c7b2fSDavid Howells struct afs_read *req;
910e49c7b2fSDavid Howells } fetch;
911e49c7b2fSDavid Howells struct {
912e49c7b2fSDavid Howells afs_lock_type_t type;
913e49c7b2fSDavid Howells } lock;
914e49c7b2fSDavid Howells struct {
915bd80d8a8SDavid Howells struct iov_iter *write_iter;
916bd80d8a8SDavid Howells loff_t pos;
917bd80d8a8SDavid Howells loff_t size;
918bd80d8a8SDavid Howells loff_t i_size;
919e49c7b2fSDavid Howells } store;
920e49c7b2fSDavid Howells struct {
921e49c7b2fSDavid Howells struct iattr *attr;
922ec0fa0b6SDavid Howells loff_t old_i_size;
923e49c7b2fSDavid Howells } setattr;
924e49c7b2fSDavid Howells struct afs_acl *acl;
925e49c7b2fSDavid Howells struct yfs_acl *yacl;
926e49c7b2fSDavid Howells struct {
927e49c7b2fSDavid Howells struct afs_volume_status vs;
928e49c7b2fSDavid Howells struct kstatfs *buf;
929e49c7b2fSDavid Howells } volstatus;
930e49c7b2fSDavid Howells };
931e49c7b2fSDavid Howells
932e49c7b2fSDavid Howells /* Fileserver iteration state */
933d2ddc776SDavid Howells struct afs_server_list *server_list; /* Current server list (pins ref) */
93420325960SDavid Howells struct afs_server *server; /* Server we're using (ref pinned by server_list) */
935495f2ae9SDavid Howells struct afs_endpoint_state *estate; /* Current endpoint state (doesn't pin ref) */
936495f2ae9SDavid Howells struct afs_server_state *server_states; /* States of the servers involved */
937e49c7b2fSDavid Howells struct afs_call *call;
938905b8615SDavid Howells unsigned long untried_servers; /* Bitmask of untried servers */
93998f9fda2SDavid Howells unsigned long addr_tried; /* Tried addresses */
94098f9fda2SDavid Howells s32 call_abort_code; /* Abort code from single call */
94198f9fda2SDavid Howells short call_error; /* Error from single call */
942905b8615SDavid Howells short server_index; /* Current server */
943075171fdSDavid Howells short nr_iterations; /* Number of server iterations */
94498f9fda2SDavid Howells signed char addr_index; /* Current address */
945aa453becSDavid Howells bool call_responded; /* T if the current address responded */
946aa453becSDavid Howells
947e49c7b2fSDavid Howells unsigned int flags;
948a310082fSDavid Howells #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */
949a310082fSDavid Howells #define AFS_OPERATION_VBUSY 0x0002 /* Set if seen VBUSY */
950a310082fSDavid Howells #define AFS_OPERATION_VMOVED 0x0004 /* Set if seen VMOVED */
951a310082fSDavid Howells #define AFS_OPERATION_VNOVOL 0x0008 /* Set if seen VNOVOL */
952a310082fSDavid Howells #define AFS_OPERATION_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
953a310082fSDavid Howells #define AFS_OPERATION_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
954e49c7b2fSDavid Howells #define AFS_OPERATION_UNINTR 0x0040 /* Set if op is uninterruptible */
955e49c7b2fSDavid Howells #define AFS_OPERATION_DOWNGRADE 0x0080 /* Set to retry with downgraded opcode */
956e49c7b2fSDavid Howells #define AFS_OPERATION_LOCK_0 0x0100 /* Set if have io_lock on file[0] */
957e49c7b2fSDavid Howells #define AFS_OPERATION_LOCK_1 0x0200 /* Set if have io_lock on file[1] */
9588409f67bSDavid Howells #define AFS_OPERATION_TRIED_ALL 0x0400 /* Set if we've tried all the fileservers */
9598409f67bSDavid Howells #define AFS_OPERATION_RETRY_SERVER 0x0800 /* Set if we should retry the current server */
960b6489a49SDavid Howells #define AFS_OPERATION_DIR_CONFLICT 0x1000 /* Set if we detected a 3rd-party dir change */
9618b2a464cSDavid Howells };
9628b2a464cSDavid Howells
963402cb8ddSDavid Howells /*
964402cb8ddSDavid Howells * Cache auxiliary data.
965402cb8ddSDavid Howells */
966402cb8ddSDavid Howells struct afs_vnode_cache_aux {
967523d27cdSDavid Howells __be64 data_version;
968402cb8ddSDavid Howells } __packed;
969402cb8ddSDavid Howells
afs_set_cache_aux(struct afs_vnode * vnode,struct afs_vnode_cache_aux * aux)970523d27cdSDavid Howells static inline void afs_set_cache_aux(struct afs_vnode *vnode,
971523d27cdSDavid Howells struct afs_vnode_cache_aux *aux)
972523d27cdSDavid Howells {
973523d27cdSDavid Howells aux->data_version = cpu_to_be64(vnode->status.data_version);
974523d27cdSDavid Howells }
975523d27cdSDavid Howells
afs_invalidate_cache(struct afs_vnode * vnode,unsigned int flags)976523d27cdSDavid Howells static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int flags)
977523d27cdSDavid Howells {
978523d27cdSDavid Howells struct afs_vnode_cache_aux aux;
979523d27cdSDavid Howells
980523d27cdSDavid Howells afs_set_cache_aux(vnode, &aux);
981523d27cdSDavid Howells fscache_invalidate(afs_vnode_cache(vnode), &aux,
982874c8ca1SDavid Howells i_size_read(&vnode->netfs.inode), flags);
983523d27cdSDavid Howells }
984523d27cdSDavid Howells
98598bf40cdSDavid Howells #include <trace/events/afs.h>
98698bf40cdSDavid Howells
98708e0e7c8SDavid Howells /*****************************************************************************/
98808e0e7c8SDavid Howells /*
9898b2a464cSDavid Howells * addr_list.c
9908b2a464cSDavid Howells */
9911e5d8493SDavid Howells struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
992e38f299eSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr);
9931e5d8493SDavid Howells extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
9940a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
9950a5143f2SDavid Howells const char *, size_t, char,
9968b2a464cSDavid Howells unsigned short, unsigned short);
99707f3502bSDavid Howells bool afs_addr_list_same(const struct afs_addr_list *a,
99807f3502bSDavid Howells const struct afs_addr_list *b);
9990a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
10008b2a464cSDavid Howells
100172904d7bSDavid Howells extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *addr,
100272904d7bSDavid Howells __be32 xdr, u16 port);
100372904d7bSDavid Howells extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *addr,
100472904d7bSDavid Howells __be32 *xdr, u16 port);
1005d2ddc776SDavid Howells
10068b2a464cSDavid Howells /*
1007f94f70d3SDavid Howells * addr_prefs.c
1008f94f70d3SDavid Howells */
1009f94f70d3SDavid Howells int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size);
1010d14cf8edSDavid Howells void afs_get_address_preferences_rcu(struct afs_net *net, struct afs_addr_list *alist);
1011d14cf8edSDavid Howells void afs_get_address_preferences(struct afs_net *net, struct afs_addr_list *alist);
1012f94f70d3SDavid Howells
1013f94f70d3SDavid Howells /*
101408e0e7c8SDavid Howells * callback.c
101508e0e7c8SDavid Howells */
10166e0e99d5SDavid Howells extern void afs_invalidate_mmap_work(struct work_struct *);
101708e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *);
1018051d2525SDavid Howells extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
1019051d2525SDavid Howells extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
10205cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
1021c435ee34SDavid Howells
afs_calc_vnode_cb_break(struct afs_vnode * vnode)102268251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
102368251f0aSDavid Howells {
1024453924deSDavid Howells return vnode->cb_break + vnode->cb_ro_snapshot + vnode->cb_scrub;
102568251f0aSDavid Howells }
102668251f0aSDavid Howells
afs_cb_is_broken(unsigned int cb_break,const struct afs_vnode * vnode)102718ac6185SDavid Howells static inline bool afs_cb_is_broken(unsigned int cb_break,
102820325960SDavid Howells const struct afs_vnode *vnode)
102968251f0aSDavid Howells {
1030453924deSDavid Howells return cb_break != (vnode->cb_break +
1031453924deSDavid Howells atomic_read(&vnode->volume->cb_ro_snapshot) +
1032453924deSDavid Howells atomic_read(&vnode->volume->cb_scrub));
103368251f0aSDavid Howells }
103468251f0aSDavid Howells
10351da177e4SLinus Torvalds /*
10361da177e4SLinus Torvalds * cell.c
10371da177e4SLinus Torvalds */
1038989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *);
1039dca54a7bSDavid Howells extern struct afs_cell *afs_find_cell(struct afs_net *, const char *, unsigned,
1040dca54a7bSDavid Howells enum afs_cell_trace);
1041989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
1042989782dcSDavid Howells const char *, bool);
1043dca54a7bSDavid Howells extern struct afs_cell *afs_use_cell(struct afs_cell *, enum afs_cell_trace);
1044dca54a7bSDavid Howells extern void afs_unuse_cell(struct afs_net *, struct afs_cell *, enum afs_cell_trace);
1045dca54a7bSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *, enum afs_cell_trace);
1046dca54a7bSDavid Howells extern void afs_see_cell(struct afs_cell *, enum afs_cell_trace);
1047dca54a7bSDavid Howells extern void afs_put_cell(struct afs_cell *, enum afs_cell_trace);
1048dca54a7bSDavid Howells extern void afs_queue_cell(struct afs_cell *, enum afs_cell_trace);
1049989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *);
1050989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *);
1051f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *);
105208e0e7c8SDavid Howells
105308e0e7c8SDavid Howells /*
105408e0e7c8SDavid Howells * cmservice.c
105508e0e7c8SDavid Howells */
105608e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *);
105708e0e7c8SDavid Howells
10581da177e4SLinus Torvalds /*
10591da177e4SLinus Torvalds * dir.c
10601da177e4SLinus Torvalds */
10614b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations;
10624d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations;
1063f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops;
10644d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations;
10654d673da1SDavid Howells
106666c7e1d3SDavid Howells extern void afs_d_release(struct dentry *);
1067728279a5SDavid Howells extern void afs_check_for_remote_deletion(struct afs_operation *);
106866c7e1d3SDavid Howells
106966c7e1d3SDavid Howells /*
107063a4681fSDavid Howells * dir_edit.c
107163a4681fSDavid Howells */
107263a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
107363a4681fSDavid Howells enum afs_edit_dir_reason);
107463a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
107563a4681fSDavid Howells
107663a4681fSDavid Howells /*
107779ddbfa5SDavid Howells * dir_silly.c
107879ddbfa5SDavid Howells */
107979ddbfa5SDavid Howells extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
108079ddbfa5SDavid Howells struct dentry *, struct key *);
108179ddbfa5SDavid Howells extern int afs_silly_iput(struct dentry *, struct inode *);
108279ddbfa5SDavid Howells
108379ddbfa5SDavid Howells /*
108466c7e1d3SDavid Howells * dynroot.c
108566c7e1d3SDavid Howells */
108666c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations;
108766c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations;
108866c7e1d3SDavid Howells
108966c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
10900da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
10910da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
10920da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *);
10930da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *);
10941da177e4SLinus Torvalds
10951da177e4SLinus Torvalds /*
10961da177e4SLinus Torvalds * file.c
10971da177e4SLinus Torvalds */
109875bd228dSDavid Howells extern const struct address_space_operations afs_file_aops;
109975bd228dSDavid Howells extern const struct address_space_operations afs_symlink_aops;
1100754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations;
110100d3b7a4SDavid Howells extern const struct file_operations afs_file_operations;
11026a19114bSDavid Howells extern const struct netfs_request_ops afs_req_ops;
110300d3b7a4SDavid Howells
11044343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
11054343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *);
110600d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *);
110700d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *);
1108c69bf479SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct afs_read *);
11095cbf0398SDavid Howells extern struct afs_read *afs_alloc_read(gfp_t);
1110196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *);
11111da177e4SLinus Torvalds
afs_get_read(struct afs_read * req)1112d4438a25SDavid Howells static inline struct afs_read *afs_get_read(struct afs_read *req)
1113d4438a25SDavid Howells {
1114d4438a25SDavid Howells refcount_inc(&req->usage);
1115d4438a25SDavid Howells return req;
1116d4438a25SDavid Howells }
1117d4438a25SDavid Howells
11181da177e4SLinus Torvalds /*
1119e8d6c554SDavid Howells * flock.c
1120e8d6c554SDavid Howells */
1121f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager;
1122f044c884SDavid Howells
1123a690f60aSDavid Howells extern void afs_lock_op_done(struct afs_call *);
1124e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *);
1125e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *);
1126e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *);
1127e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *);
1128e8d6c554SDavid Howells
1129e8d6c554SDavid Howells /*
113008e0e7c8SDavid Howells * fsclient.c
113108e0e7c8SDavid Howells */
1132e49c7b2fSDavid Howells extern void afs_fs_fetch_status(struct afs_operation *);
1133e49c7b2fSDavid Howells extern void afs_fs_fetch_data(struct afs_operation *);
1134e49c7b2fSDavid Howells extern void afs_fs_create_file(struct afs_operation *);
1135e49c7b2fSDavid Howells extern void afs_fs_make_dir(struct afs_operation *);
1136e49c7b2fSDavid Howells extern void afs_fs_remove_file(struct afs_operation *);
1137e49c7b2fSDavid Howells extern void afs_fs_remove_dir(struct afs_operation *);
1138e49c7b2fSDavid Howells extern void afs_fs_link(struct afs_operation *);
1139e49c7b2fSDavid Howells extern void afs_fs_symlink(struct afs_operation *);
1140e49c7b2fSDavid Howells extern void afs_fs_rename(struct afs_operation *);
1141e49c7b2fSDavid Howells extern void afs_fs_store_data(struct afs_operation *);
1142e49c7b2fSDavid Howells extern void afs_fs_setattr(struct afs_operation *);
1143e49c7b2fSDavid Howells extern void afs_fs_get_volume_status(struct afs_operation *);
1144e49c7b2fSDavid Howells extern void afs_fs_set_lock(struct afs_operation *);
1145e49c7b2fSDavid Howells extern void afs_fs_extend_lock(struct afs_operation *);
1146e49c7b2fSDavid Howells extern void afs_fs_release_lock(struct afs_operation *);
114798f9fda2SDavid Howells int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
114898f9fda2SDavid Howells struct afs_address *addr, struct key *key);
114998f9fda2SDavid Howells bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1150f49b594dSDavid Howells struct afs_endpoint_state *estate, unsigned int addr_index,
115198f9fda2SDavid Howells struct key *key);
1152e49c7b2fSDavid Howells extern void afs_fs_inline_bulk_status(struct afs_operation *);
115308e0e7c8SDavid Howells
1154260f082bSDavid Howells struct afs_acl {
1155260f082bSDavid Howells u32 size;
115644642564SGustavo A. R. Silva u8 data[] __counted_by(size);
1157260f082bSDavid Howells };
1158260f082bSDavid Howells
1159e49c7b2fSDavid Howells extern void afs_fs_fetch_acl(struct afs_operation *);
1160e49c7b2fSDavid Howells extern void afs_fs_store_acl(struct afs_operation *);
1161e49c7b2fSDavid Howells
1162e49c7b2fSDavid Howells /*
1163e49c7b2fSDavid Howells * fs_operation.c
1164e49c7b2fSDavid Howells */
1165e49c7b2fSDavid Howells extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
1166e49c7b2fSDavid Howells extern int afs_put_operation(struct afs_operation *);
1167e49c7b2fSDavid Howells extern bool afs_begin_vnode_operation(struct afs_operation *);
1168e49c7b2fSDavid Howells extern void afs_wait_for_operation(struct afs_operation *);
1169e49c7b2fSDavid Howells extern int afs_do_sync_operation(struct afs_operation *);
1170e49c7b2fSDavid Howells
afs_op_set_vnode(struct afs_operation * op,unsigned int n,struct afs_vnode * vnode)1171e49c7b2fSDavid Howells static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
1172e49c7b2fSDavid Howells struct afs_vnode *vnode)
1173e49c7b2fSDavid Howells {
1174e49c7b2fSDavid Howells op->file[n].vnode = vnode;
1175e49c7b2fSDavid Howells op->file[n].need_io_lock = true;
1176e49c7b2fSDavid Howells }
1177e49c7b2fSDavid Howells
afs_op_set_fid(struct afs_operation * op,unsigned int n,const struct afs_fid * fid)1178e49c7b2fSDavid Howells static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
1179e49c7b2fSDavid Howells const struct afs_fid *fid)
1180e49c7b2fSDavid Howells {
1181e49c7b2fSDavid Howells op->file[n].fid = *fid;
1182e49c7b2fSDavid Howells }
1183260f082bSDavid Howells
118408e0e7c8SDavid Howells /*
11853bf0fb6fSDavid Howells * fs_probe.c
11863bf0fb6fSDavid Howells */
1187f49b594dSDavid Howells struct afs_endpoint_state *afs_get_endpoint_state(struct afs_endpoint_state *estate,
1188f49b594dSDavid Howells enum afs_estate_trace where);
1189f49b594dSDavid Howells void afs_put_endpoint_state(struct afs_endpoint_state *estate, enum afs_estate_trace where);
11903bf0fb6fSDavid Howells extern void afs_fileserver_probe_result(struct afs_call *);
1191f49b594dSDavid Howells void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
1192f49b594dSDavid Howells struct afs_addr_list *new_addrs, struct key *key);
1193495f2ae9SDavid Howells int afs_wait_for_fs_probes(struct afs_operation *op, struct afs_server_state *states, bool intr);
11948409f67bSDavid Howells extern void afs_probe_fileserver(struct afs_net *, struct afs_server *);
1195f6cbb368SDavid Howells extern void afs_fs_probe_dispatcher(struct work_struct *);
1196f49b594dSDavid Howells int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoint_state *estate,
1197495f2ae9SDavid Howells unsigned long exclude, bool is_intr);
11985481fc6eSDavid Howells extern void afs_fs_probe_cleanup(struct afs_net *);
11993bf0fb6fSDavid Howells
12003bf0fb6fSDavid Howells /*
12011da177e4SLinus Torvalds * inode.c
12021da177e4SLinus Torvalds */
1203b6489a49SDavid Howells extern const struct afs_operation_ops afs_fetch_status_operation;
1204b6489a49SDavid Howells
1205e49c7b2fSDavid Howells extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
1206a58823acSDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1207e49c7b2fSDavid Howells extern int afs_ilookup5_test_by_fid(struct inode *, void *);
12084d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
1209e49c7b2fSDavid Howells extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
1210e49c7b2fSDavid Howells extern struct inode *afs_root_iget(struct super_block *, struct key *);
1211b74d24f7SChristian Brauner extern int afs_getattr(struct mnt_idmap *idmap, const struct path *,
1212549c7297SChristian Brauner struct kstat *, u32, unsigned int);
1213c1632a0fSChristian Brauner extern int afs_setattr(struct mnt_idmap *idmap, struct dentry *, struct iattr *);
1214b57922d9SAl Viro extern void afs_evict_inode(struct inode *);
1215bec5eb61Swanglei extern int afs_drop_inode(struct inode *);
12161da177e4SLinus Torvalds
12171da177e4SLinus Torvalds /*
12181da177e4SLinus Torvalds * main.c
12191da177e4SLinus Torvalds */
12200ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq;
12215b86d4ffSDavid Howells extern int afs_net_id;
12225b86d4ffSDavid Howells
afs_net(struct net * net)12235b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net)
12245b86d4ffSDavid Howells {
12255b86d4ffSDavid Howells return net_generic(net, afs_net_id);
12265b86d4ffSDavid Howells }
12275b86d4ffSDavid Howells
afs_sb2net(struct super_block * sb)12285b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb)
12295b86d4ffSDavid Howells {
12305b86d4ffSDavid Howells return afs_net(AFS_FS_S(sb)->net_ns);
12315b86d4ffSDavid Howells }
1232f044c884SDavid Howells
afs_d2net(struct dentry * dentry)1233f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry)
1234f044c884SDavid Howells {
12355b86d4ffSDavid Howells return afs_sb2net(dentry->d_sb);
1236f044c884SDavid Howells }
1237f044c884SDavid Howells
afs_i2net(struct inode * inode)1238f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode)
1239f044c884SDavid Howells {
12405b86d4ffSDavid Howells return afs_sb2net(inode->i_sb);
1241f044c884SDavid Howells }
1242f044c884SDavid Howells
afs_v2net(struct afs_vnode * vnode)1243f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1244f044c884SDavid Howells {
1245874c8ca1SDavid Howells return afs_i2net(&vnode->netfs.inode);
1246f044c884SDavid Howells }
1247f044c884SDavid Howells
afs_sock2net(struct sock * sk)1248f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk)
1249f044c884SDavid Howells {
12505b86d4ffSDavid Howells return net_generic(sock_net(sk), afs_net_id);
1251f044c884SDavid Howells }
12521da177e4SLinus Torvalds
__afs_stat(atomic_t * s)1253d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s)
1254d55b4da4SDavid Howells {
1255d55b4da4SDavid Howells atomic_inc(s);
1256d55b4da4SDavid Howells }
1257d55b4da4SDavid Howells
1258d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1259d55b4da4SDavid Howells
12601da177e4SLinus Torvalds /*
126108e0e7c8SDavid Howells * misc.c
126208e0e7c8SDavid Howells */
126308e0e7c8SDavid Howells extern int afs_abort_to_error(u32);
12644584ae96SDavid Howells extern void afs_prioritise_error(struct afs_error *, int, u32);
126508e0e7c8SDavid Howells
afs_op_nomem(struct afs_operation * op)12662de5599fSDavid Howells static inline void afs_op_nomem(struct afs_operation *op)
12672de5599fSDavid Howells {
1268aa453becSDavid Howells op->cumul_error.error = -ENOMEM;
12692de5599fSDavid Howells }
12702de5599fSDavid Howells
afs_op_error(const struct afs_operation * op)12712de5599fSDavid Howells static inline int afs_op_error(const struct afs_operation *op)
12722de5599fSDavid Howells {
1273aa453becSDavid Howells return op->cumul_error.error;
1274aa453becSDavid Howells }
1275aa453becSDavid Howells
afs_op_abort_code(const struct afs_operation * op)1276aa453becSDavid Howells static inline s32 afs_op_abort_code(const struct afs_operation *op)
1277aa453becSDavid Howells {
1278aa453becSDavid Howells return op->cumul_error.abort_code;
12792de5599fSDavid Howells }
12802de5599fSDavid Howells
afs_op_set_error(struct afs_operation * op,int error)12812de5599fSDavid Howells static inline int afs_op_set_error(struct afs_operation *op, int error)
12822de5599fSDavid Howells {
1283aa453becSDavid Howells return op->cumul_error.error = error;
1284aa453becSDavid Howells }
1285aa453becSDavid Howells
afs_op_accumulate_error(struct afs_operation * op,int error,s32 abort_code)1286aa453becSDavid Howells static inline void afs_op_accumulate_error(struct afs_operation *op, int error, s32 abort_code)
1287aa453becSDavid Howells {
1288aa453becSDavid Howells afs_prioritise_error(&op->cumul_error, error, abort_code);
12892de5599fSDavid Howells }
12902de5599fSDavid Howells
129108e0e7c8SDavid Howells /*
12921da177e4SLinus Torvalds * mntpt.c
12931da177e4SLinus Torvalds */
1294754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations;
1295bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations;
12964b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations;
12971da177e4SLinus Torvalds
1298d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *);
129908e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void);
13001da177e4SLinus Torvalds
13011da177e4SLinus Torvalds /*
13021da177e4SLinus Torvalds * proc.c
13031da177e4SLinus Torvalds */
1304b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS
1305f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *);
1306f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *);
13075b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *);
13085b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *);
13096f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *);
1310b6cfbecaSDavid Howells #else
afs_proc_init(struct afs_net * net)1311b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; }
afs_proc_cleanup(struct afs_net * net)1312b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {}
afs_proc_cell_setup(struct afs_cell * cell)1313b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
afs_proc_cell_remove(struct afs_cell * cell)1314b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
afs_put_sysnames(struct afs_sysnames * sysnames)1315b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1316b6cfbecaSDavid Howells #endif
13171da177e4SLinus Torvalds
131808e0e7c8SDavid Howells /*
1319d2ddc776SDavid Howells * rotate.c
1320d2ddc776SDavid Howells */
1321495f2ae9SDavid Howells void afs_clear_server_states(struct afs_operation *op);
1322a310082fSDavid Howells extern bool afs_select_fileserver(struct afs_operation *);
1323e49c7b2fSDavid Howells extern void afs_dump_edestaddrreq(const struct afs_operation *);
1324d2ddc776SDavid Howells
1325d2ddc776SDavid Howells /*
132608e0e7c8SDavid Howells * rxrpc.c
132708e0e7c8SDavid Howells */
1328f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls;
13298324f0bcSDavid Howells
1330f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *);
1331f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *);
1332f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *);
1333341f741fSDavid Howells extern void afs_put_call(struct afs_call *);
133498f9fda2SDavid Howells void afs_make_call(struct afs_call *call, gfp_t gfp);
133598f9fda2SDavid Howells void afs_wait_for_call_to_complete(struct afs_call *call);
1336f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1337f044c884SDavid Howells const struct afs_call_type *,
133808e0e7c8SDavid Howells size_t, size_t);
133908e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *);
134008e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *);
1341b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
134212bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool);
13437126ead9SDavid Howells extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
134408e0e7c8SDavid Howells
afs_make_op_call(struct afs_operation * op,struct afs_call * call,gfp_t gfp)1345e49c7b2fSDavid Howells static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
1346e49c7b2fSDavid Howells gfp_t gfp)
134720b8391fSDavid Howells {
1348f49b594dSDavid Howells struct afs_addr_list *alist = op->estate->addresses;
1349f49b594dSDavid Howells
1350e49c7b2fSDavid Howells op->call = call;
1351a310082fSDavid Howells op->type = call->type;
1352e49c7b2fSDavid Howells call->op = op;
1353e49c7b2fSDavid Howells call->key = op->key;
1354e49c7b2fSDavid Howells call->intr = !(op->flags & AFS_OPERATION_UNINTR);
1355f49b594dSDavid Howells call->peer = rxrpc_kernel_get_peer(alist->addrs[op->addr_index].peer);
1356e38f299eSDavid Howells call->service_id = op->server->service_id;
135798f9fda2SDavid Howells afs_make_call(call, gfp);
135820b8391fSDavid Howells }
135920b8391fSDavid Howells
afs_extract_begin(struct afs_call * call,void * buf,size_t size)136012bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
136112bdcf33SDavid Howells {
1362f105da1aSDavid Howells call->iov_len = size;
136312bdcf33SDavid Howells call->kvec[0].iov_base = buf;
136412bdcf33SDavid Howells call->kvec[0].iov_len = size;
1365de4eda9dSAl Viro iov_iter_kvec(&call->def_iter, ITER_DEST, call->kvec, 1, size);
136612bdcf33SDavid Howells }
136712bdcf33SDavid Howells
afs_extract_to_tmp(struct afs_call * call)136812bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call)
136912bdcf33SDavid Howells {
1370f105da1aSDavid Howells call->iov_len = sizeof(call->tmp);
137112bdcf33SDavid Howells afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
137212bdcf33SDavid Howells }
137312bdcf33SDavid Howells
afs_extract_to_tmp64(struct afs_call * call)137412bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call)
137512bdcf33SDavid Howells {
1376f105da1aSDavid Howells call->iov_len = sizeof(call->tmp64);
137712bdcf33SDavid Howells afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
137812bdcf33SDavid Howells }
137912bdcf33SDavid Howells
afs_extract_discard(struct afs_call * call,size_t size)138012bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size)
138112bdcf33SDavid Howells {
1382f105da1aSDavid Howells call->iov_len = size;
1383de4eda9dSAl Viro iov_iter_discard(&call->def_iter, ITER_DEST, size);
138412bdcf33SDavid Howells }
138512bdcf33SDavid Howells
afs_extract_to_buf(struct afs_call * call,size_t size)138612bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
138712bdcf33SDavid Howells {
1388f105da1aSDavid Howells call->iov_len = size;
138912bdcf33SDavid Howells afs_extract_begin(call, call->buffer, size);
139012bdcf33SDavid Howells }
139112bdcf33SDavid Howells
afs_transfer_reply(struct afs_call * call)1392d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call)
1393372ee163SDavid Howells {
139412bdcf33SDavid Howells return afs_extract_data(call, false);
1395372ee163SDavid Howells }
1396372ee163SDavid Howells
afs_check_call_state(struct afs_call * call,enum afs_call_state state)139798bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call,
139898bf40cdSDavid Howells enum afs_call_state state)
139998bf40cdSDavid Howells {
140098bf40cdSDavid Howells return READ_ONCE(call->state) == state;
140198bf40cdSDavid Howells }
140298bf40cdSDavid Howells
afs_set_call_state(struct afs_call * call,enum afs_call_state from,enum afs_call_state to)140398bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call,
140498bf40cdSDavid Howells enum afs_call_state from,
140598bf40cdSDavid Howells enum afs_call_state to)
140698bf40cdSDavid Howells {
140798bf40cdSDavid Howells bool ok = false;
140898bf40cdSDavid Howells
140998bf40cdSDavid Howells spin_lock_bh(&call->state_lock);
141098bf40cdSDavid Howells if (call->state == from) {
141198bf40cdSDavid Howells call->state = to;
141298bf40cdSDavid Howells trace_afs_call_state(call, from, to, 0, 0);
141398bf40cdSDavid Howells ok = true;
141498bf40cdSDavid Howells }
141598bf40cdSDavid Howells spin_unlock_bh(&call->state_lock);
141698bf40cdSDavid Howells return ok;
141798bf40cdSDavid Howells }
141898bf40cdSDavid Howells
afs_set_call_complete(struct afs_call * call,int error,u32 remote_abort)141998bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call,
142098bf40cdSDavid Howells int error, u32 remote_abort)
142198bf40cdSDavid Howells {
142298bf40cdSDavid Howells enum afs_call_state state;
142398bf40cdSDavid Howells bool ok = false;
142498bf40cdSDavid Howells
142598bf40cdSDavid Howells spin_lock_bh(&call->state_lock);
142698bf40cdSDavid Howells state = call->state;
142798bf40cdSDavid Howells if (state != AFS_CALL_COMPLETE) {
142898bf40cdSDavid Howells call->abort_code = remote_abort;
142998bf40cdSDavid Howells call->error = error;
143098bf40cdSDavid Howells call->state = AFS_CALL_COMPLETE;
143198bf40cdSDavid Howells trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
143298bf40cdSDavid Howells error, remote_abort);
143398bf40cdSDavid Howells ok = true;
143498bf40cdSDavid Howells }
143598bf40cdSDavid Howells spin_unlock_bh(&call->state_lock);
1436dde9f095SDavid Howells if (ok) {
143798bf40cdSDavid Howells trace_afs_call_done(call);
1438dde9f095SDavid Howells
1439dde9f095SDavid Howells /* Asynchronous calls have two refs to release - one from the alloc and
1440dde9f095SDavid Howells * one queued with the work item - and we can't just deallocate the
1441dde9f095SDavid Howells * call because the work item may be queued again.
1442dde9f095SDavid Howells */
1443dde9f095SDavid Howells if (call->drop_ref)
1444dde9f095SDavid Howells afs_put_call(call);
1445dde9f095SDavid Howells }
144698bf40cdSDavid Howells }
144798bf40cdSDavid Howells
144808e0e7c8SDavid Howells /*
144900d3b7a4SDavid Howells * security.c
145000d3b7a4SDavid Howells */
1451be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *);
145200d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *);
1453a58823acSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1454a58823acSDavid Howells struct afs_status_cb *);
145500d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *);
14568b6a666aSDavid Howells extern struct key *afs_request_key_rcu(struct afs_cell *);
14570fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
14584609e1f1SChristian Brauner extern int afs_permission(struct mnt_idmap *, struct inode *, int);
1459be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void);
146000d3b7a4SDavid Howells
146100d3b7a4SDavid Howells /*
146208e0e7c8SDavid Howells * server.c
146308e0e7c8SDavid Howells */
146408e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock;
146508e0e7c8SDavid Howells
146672904d7bSDavid Howells extern struct afs_server *afs_find_server(struct afs_net *, const struct rxrpc_peer *);
1467d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
146881006805SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
146945218193SDavid Howells extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
1470977e5f8eSDavid Howells extern struct afs_server *afs_use_server(struct afs_server *, enum afs_server_trace);
1471977e5f8eSDavid Howells extern void afs_unuse_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1472977e5f8eSDavid Howells extern void afs_unuse_server_notime(struct afs_net *, struct afs_server *, enum afs_server_trace);
147345218193SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1474d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *);
1475d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *);
1476f6cbb368SDavid Howells extern void afs_fs_probe_timer(struct timer_list *);
1477f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *);
1478f49b594dSDavid Howells bool afs_check_server_record(struct afs_operation *op, struct afs_server *server, struct key *key);
1479d2ddc776SDavid Howells
afs_inc_servers_outstanding(struct afs_net * net)1480f6cbb368SDavid Howells static inline void afs_inc_servers_outstanding(struct afs_net *net)
1481f6cbb368SDavid Howells {
1482f6cbb368SDavid Howells atomic_inc(&net->servers_outstanding);
1483f6cbb368SDavid Howells }
1484f6cbb368SDavid Howells
afs_dec_servers_outstanding(struct afs_net * net)1485f6cbb368SDavid Howells static inline void afs_dec_servers_outstanding(struct afs_net *net)
1486f6cbb368SDavid Howells {
1487f6cbb368SDavid Howells if (atomic_dec_and_test(&net->servers_outstanding))
1488f6cbb368SDavid Howells wake_up_var(&net->servers_outstanding);
1489f6cbb368SDavid Howells }
1490f6cbb368SDavid Howells
afs_is_probing_server(struct afs_server * server)1491f6cbb368SDavid Howells static inline bool afs_is_probing_server(struct afs_server *server)
1492f6cbb368SDavid Howells {
1493f6cbb368SDavid Howells return list_empty(&server->probe_link);
1494f6cbb368SDavid Howells }
1495f6cbb368SDavid Howells
1496d2ddc776SDavid Howells /*
1497d2ddc776SDavid Howells * server_list.c
1498d2ddc776SDavid Howells */
afs_get_serverlist(struct afs_server_list * slist)1499d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1500d2ddc776SDavid Howells {
1501d2ddc776SDavid Howells refcount_inc(&slist->usage);
1502d2ddc776SDavid Howells return slist;
1503d2ddc776SDavid Howells }
1504d2ddc776SDavid Howells
1505d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1506ca0e79a4SDavid Howells struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,
1507ca0e79a4SDavid Howells struct key *key,
1508ca0e79a4SDavid Howells struct afs_vldb_entry *vldb);
1509d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1510ca0e79a4SDavid Howells void afs_attach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist);
1511ca0e79a4SDavid Howells void afs_reattach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist,
1512ca0e79a4SDavid Howells struct afs_server_list *old);
1513ca0e79a4SDavid Howells void afs_detach_volume_from_servers(struct afs_volume *volume, struct afs_server_list *slist);
151408e0e7c8SDavid Howells
151508e0e7c8SDavid Howells /*
151600d3b7a4SDavid Howells * super.c
151700d3b7a4SDavid Howells */
1518f044c884SDavid Howells extern int __init afs_fs_init(void);
15195b86d4ffSDavid Howells extern void afs_fs_exit(void);
152000d3b7a4SDavid Howells
152100d3b7a4SDavid Howells /*
1522dfa0a449SDavid Howells * validation.c
1523dfa0a449SDavid Howells */
1524453924deSDavid Howells bool afs_check_validity(const struct afs_vnode *vnode);
152516069e13SDavid Howells int afs_update_volume_state(struct afs_operation *op);
1526dfa0a449SDavid Howells int afs_validate(struct afs_vnode *vnode, struct key *key);
1527dfa0a449SDavid Howells
1528dfa0a449SDavid Howells /*
152908e0e7c8SDavid Howells * vlclient.c
153008e0e7c8SDavid Howells */
15310a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
15320a5143f2SDavid Howells const char *, int);
15330a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
153498f9fda2SDavid Howells struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
153598f9fda2SDavid Howells struct afs_addr_list *alist,
153698f9fda2SDavid Howells unsigned int addr_index,
153798f9fda2SDavid Howells struct key *key,
153898f9fda2SDavid Howells struct afs_vlserver *server,
153998f9fda2SDavid Howells unsigned int server_index);
15400a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
1541c3e9f888SDavid Howells extern char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *);
15420a5143f2SDavid Howells
15430a5143f2SDavid Howells /*
15448a070a96SDavid Howells * vl_alias.c
15458a070a96SDavid Howells */
15468a070a96SDavid Howells extern int afs_cell_detect_alias(struct afs_cell *, struct key *);
15478a070a96SDavid Howells
15488a070a96SDavid Howells /*
15493bf0fb6fSDavid Howells * vl_probe.c
15503bf0fb6fSDavid Howells */
15513bf0fb6fSDavid Howells extern void afs_vlserver_probe_result(struct afs_call *);
15523bf0fb6fSDavid Howells extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
15533bf0fb6fSDavid Howells extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
15543bf0fb6fSDavid Howells
15553bf0fb6fSDavid Howells /*
15560a5143f2SDavid Howells * vl_rotate.c
15570a5143f2SDavid Howells */
15580a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
15590a5143f2SDavid Howells struct afs_cell *, struct key *);
15600a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *);
15610a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
15620a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
15630a5143f2SDavid Howells
15640a5143f2SDavid Howells /*
15650a5143f2SDavid Howells * vlserver_list.c
15660a5143f2SDavid Howells */
afs_get_vlserver(struct afs_vlserver * vlserver)15670a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
15680a5143f2SDavid Howells {
1569c56f9ec8SDavid Howells refcount_inc(&vlserver->ref);
15700a5143f2SDavid Howells return vlserver;
15710a5143f2SDavid Howells }
15720a5143f2SDavid Howells
afs_get_vlserverlist(struct afs_vlserver_list * vllist)15730a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
15740a5143f2SDavid Howells {
15750a5143f2SDavid Howells if (vllist)
1576c56f9ec8SDavid Howells refcount_inc(&vllist->ref);
15770a5143f2SDavid Howells return vllist;
15780a5143f2SDavid Howells }
15790a5143f2SDavid Howells
15800a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
15810a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
15820a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
15830a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
15840a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
15850a5143f2SDavid Howells const void *, size_t);
158608e0e7c8SDavid Howells
158708e0e7c8SDavid Howells /*
158808e0e7c8SDavid Howells * volume.c
158908e0e7c8SDavid Howells */
159013fcc683SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1591523d27cdSDavid Howells extern int afs_activate_volume(struct afs_volume *);
1592d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *);
15939a6b294aSDavid Howells bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace reason);
1594cca37d45SDavid Howells extern struct afs_volume *afs_get_volume(struct afs_volume *, enum afs_volume_trace);
1595445f9b69SDavid Howells void afs_put_volume(struct afs_volume *volume, enum afs_volume_trace reason);
1596a310082fSDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
159708e0e7c8SDavid Howells
159831143d5dSDavid Howells /*
159931143d5dSDavid Howells * write.c
160031143d5dSDavid Howells */
1601ed22e1dbSDavid Howells void afs_prepare_write(struct netfs_io_subrequest *subreq);
1602ed22e1dbSDavid Howells void afs_issue_write(struct netfs_io_subrequest *subreq);
1603ed22e1dbSDavid Howells void afs_begin_writeback(struct netfs_io_request *wreq);
1604*1ecb146fSDavid Howells void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream);
160531143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *);
160602c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int);
16070722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
16084343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *);
160931143d5dSDavid Howells
1610d3e3b7eaSDavid Howells /*
1611d3e3b7eaSDavid Howells * xattr.c
1612d3e3b7eaSDavid Howells */
1613f710c2e4SWedson Almeida Filho extern const struct xattr_handler * const afs_xattr_handlers[];
161431143d5dSDavid Howells
161530062bd1SDavid Howells /*
161630062bd1SDavid Howells * yfsclient.c
161730062bd1SDavid Howells */
1618e49c7b2fSDavid Howells extern void yfs_fs_fetch_data(struct afs_operation *);
1619e49c7b2fSDavid Howells extern void yfs_fs_create_file(struct afs_operation *);
1620e49c7b2fSDavid Howells extern void yfs_fs_make_dir(struct afs_operation *);
1621e49c7b2fSDavid Howells extern void yfs_fs_remove_file2(struct afs_operation *);
1622e49c7b2fSDavid Howells extern void yfs_fs_remove_file(struct afs_operation *);
1623e49c7b2fSDavid Howells extern void yfs_fs_remove_dir(struct afs_operation *);
1624e49c7b2fSDavid Howells extern void yfs_fs_link(struct afs_operation *);
1625e49c7b2fSDavid Howells extern void yfs_fs_symlink(struct afs_operation *);
1626e49c7b2fSDavid Howells extern void yfs_fs_rename(struct afs_operation *);
1627e49c7b2fSDavid Howells extern void yfs_fs_store_data(struct afs_operation *);
1628e49c7b2fSDavid Howells extern void yfs_fs_setattr(struct afs_operation *);
1629e49c7b2fSDavid Howells extern void yfs_fs_get_volume_status(struct afs_operation *);
1630e49c7b2fSDavid Howells extern void yfs_fs_set_lock(struct afs_operation *);
1631e49c7b2fSDavid Howells extern void yfs_fs_extend_lock(struct afs_operation *);
1632e49c7b2fSDavid Howells extern void yfs_fs_release_lock(struct afs_operation *);
1633e49c7b2fSDavid Howells extern void yfs_fs_fetch_status(struct afs_operation *);
1634e49c7b2fSDavid Howells extern void yfs_fs_inline_bulk_status(struct afs_operation *);
1635d2ddc776SDavid Howells
1636ae46578bSDavid Howells struct yfs_acl {
1637ae46578bSDavid Howells struct afs_acl *acl; /* Dir/file/symlink ACL */
1638ae46578bSDavid Howells struct afs_acl *vol_acl; /* Whole volume ACL */
1639ae46578bSDavid Howells u32 inherit_flag; /* True if ACL is inherited from parent dir */
1640ae46578bSDavid Howells u32 num_cleaned; /* Number of ACEs removed due to subject removal */
1641ae46578bSDavid Howells unsigned int flags;
1642ae46578bSDavid Howells #define YFS_ACL_WANT_ACL 0x01 /* Set if caller wants ->acl */
1643ae46578bSDavid Howells #define YFS_ACL_WANT_VOL_ACL 0x02 /* Set if caller wants ->vol_acl */
1644ae46578bSDavid Howells };
1645ae46578bSDavid Howells
1646ae46578bSDavid Howells extern void yfs_free_opaque_acl(struct yfs_acl *);
1647e49c7b2fSDavid Howells extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
1648e49c7b2fSDavid Howells extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
1649ae46578bSDavid Howells
1650d2ddc776SDavid Howells /*
1651d2ddc776SDavid Howells * Miscellaneous inline functions.
1652d2ddc776SDavid Howells */
AFS_FS_I(struct inode * inode)1653d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1654d2ddc776SDavid Howells {
1655874c8ca1SDavid Howells return container_of(inode, struct afs_vnode, netfs.inode);
1656d2ddc776SDavid Howells }
1657d2ddc776SDavid Howells
AFS_VNODE_TO_I(struct afs_vnode * vnode)1658d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1659d2ddc776SDavid Howells {
1660874c8ca1SDavid Howells return &vnode->netfs.inode;
1661d2ddc776SDavid Howells }
1662d2ddc776SDavid Howells
1663e49c7b2fSDavid Howells /*
1664e49c7b2fSDavid Howells * Note that a dentry got changed. We need to set d_fsdata to the data version
1665e49c7b2fSDavid Howells * number derived from the result of the operation. It doesn't matter if
1666e49c7b2fSDavid Howells * d_fsdata goes backwards as we'll just revalidate.
1667e49c7b2fSDavid Howells */
afs_update_dentry_version(struct afs_operation * op,struct afs_vnode_param * dir_vp,struct dentry * dentry)1668e49c7b2fSDavid Howells static inline void afs_update_dentry_version(struct afs_operation *op,
1669e49c7b2fSDavid Howells struct afs_vnode_param *dir_vp,
1670e49c7b2fSDavid Howells struct dentry *dentry)
1671e49c7b2fSDavid Howells {
1672aa453becSDavid Howells if (!op->cumul_error.error)
1673e49c7b2fSDavid Howells dentry->d_fsdata =
1674e49c7b2fSDavid Howells (void *)(unsigned long)dir_vp->scb.status.data_version;
1675e49c7b2fSDavid Howells }
1676e49c7b2fSDavid Howells
1677b6489a49SDavid Howells /*
16789d37e1caSDavid Howells * Set the file size and block count. Estimate the number of 512 bytes blocks
16799d37e1caSDavid Howells * used, rounded up to nearest 1K for consistency with other AFS clients.
16809d37e1caSDavid Howells */
afs_set_i_size(struct afs_vnode * vnode,u64 size)16819d37e1caSDavid Howells static inline void afs_set_i_size(struct afs_vnode *vnode, u64 size)
16829d37e1caSDavid Howells {
1683874c8ca1SDavid Howells i_size_write(&vnode->netfs.inode, size);
1684874c8ca1SDavid Howells vnode->netfs.inode.i_blocks = ((size + 1023) >> 10) << 1;
16859d37e1caSDavid Howells }
16869d37e1caSDavid Howells
16879d37e1caSDavid Howells /*
1688b6489a49SDavid Howells * Check for a conflicting operation on a directory that we just unlinked from.
1689b6489a49SDavid Howells * If someone managed to sneak a link or an unlink in on the file we just
1690b6489a49SDavid Howells * unlinked, we won't be able to trust nlink on an AFS file (but not YFS).
1691b6489a49SDavid Howells */
afs_check_dir_conflict(struct afs_operation * op,struct afs_vnode_param * dvp)1692b6489a49SDavid Howells static inline void afs_check_dir_conflict(struct afs_operation *op,
1693b6489a49SDavid Howells struct afs_vnode_param *dvp)
1694b6489a49SDavid Howells {
1695b6489a49SDavid Howells if (dvp->dv_before + dvp->dv_delta != dvp->scb.status.data_version)
1696b6489a49SDavid Howells op->flags |= AFS_OPERATION_DIR_CONFLICT;
1697b6489a49SDavid Howells }
1698b6489a49SDavid Howells
afs_io_error(struct afs_call * call,enum afs_io_error where)1699f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1700f51375cdSDavid Howells {
1701f51375cdSDavid Howells trace_afs_io_error(call->debug_id, -EIO, where);
1702f51375cdSDavid Howells return -EIO;
1703f51375cdSDavid Howells }
1704f51375cdSDavid Howells
afs_bad(struct afs_vnode * vnode,enum afs_file_error where)1705f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1706f51375cdSDavid Howells {
1707f51375cdSDavid Howells trace_afs_file_error(vnode, -EIO, where);
1708f51375cdSDavid Howells return -EIO;
1709f51375cdSDavid Howells }
1710d2ddc776SDavid Howells
171108e0e7c8SDavid Howells /*****************************************************************************/
171208e0e7c8SDavid Howells /*
171308e0e7c8SDavid Howells * debug tracing
171408e0e7c8SDavid Howells */
171508e0e7c8SDavid Howells extern unsigned afs_debug;
171608e0e7c8SDavid Howells
171708e0e7c8SDavid Howells #define dbgprintk(FMT,...) \
1718ad16df84SSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
171908e0e7c8SDavid Howells
1720530b6412SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1721530b6412SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
172208e0e7c8SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
172308e0e7c8SDavid Howells
172408e0e7c8SDavid Howells
172508e0e7c8SDavid Howells #if defined(__KDEBUG)
172608e0e7c8SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
172708e0e7c8SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
172808e0e7c8SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
172908e0e7c8SDavid Howells
173008e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG)
173108e0e7c8SDavid Howells #define AFS_DEBUG_KENTER 0x01
173208e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE 0x02
173308e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG 0x04
173408e0e7c8SDavid Howells
173508e0e7c8SDavid Howells #define _enter(FMT,...) \
173608e0e7c8SDavid Howells do { \
173708e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
173808e0e7c8SDavid Howells kenter(FMT,##__VA_ARGS__); \
173908e0e7c8SDavid Howells } while (0)
174008e0e7c8SDavid Howells
174108e0e7c8SDavid Howells #define _leave(FMT,...) \
174208e0e7c8SDavid Howells do { \
174308e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
174408e0e7c8SDavid Howells kleave(FMT,##__VA_ARGS__); \
174508e0e7c8SDavid Howells } while (0)
174608e0e7c8SDavid Howells
174708e0e7c8SDavid Howells #define _debug(FMT,...) \
174808e0e7c8SDavid Howells do { \
174908e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
175008e0e7c8SDavid Howells kdebug(FMT,##__VA_ARGS__); \
175108e0e7c8SDavid Howells } while (0)
175208e0e7c8SDavid Howells
175308e0e7c8SDavid Howells #else
175412fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
175512fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
175612fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
175708e0e7c8SDavid Howells #endif
175808e0e7c8SDavid Howells
175908e0e7c8SDavid Howells /*
176008e0e7c8SDavid Howells * debug assertion checking
176108e0e7c8SDavid Howells */
176208e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL)
176308e0e7c8SDavid Howells
176408e0e7c8SDavid Howells #define ASSERT(X) \
176508e0e7c8SDavid Howells do { \
176608e0e7c8SDavid Howells if (unlikely(!(X))) { \
176708e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
176808e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
176908e0e7c8SDavid Howells BUG(); \
177008e0e7c8SDavid Howells } \
177108e0e7c8SDavid Howells } while(0)
177208e0e7c8SDavid Howells
177308e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \
177408e0e7c8SDavid Howells do { \
177508e0e7c8SDavid Howells if (unlikely(!((X) OP (Y)))) { \
177608e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
177708e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
177808e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \
177908e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
178008e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
178108e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
178208e0e7c8SDavid Howells BUG(); \
178308e0e7c8SDavid Howells } \
178408e0e7c8SDavid Howells } while(0)
178508e0e7c8SDavid Howells
1786416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \
1787416351f2SDavid Howells do { \
1788416351f2SDavid Howells if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1789416351f2SDavid Howells printk(KERN_ERR "\n"); \
1790416351f2SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
1791416351f2SDavid Howells printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1792416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \
1793416351f2SDavid Howells (unsigned long)(H)); \
1794416351f2SDavid Howells printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1795416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \
1796416351f2SDavid Howells (unsigned long)(H)); \
1797416351f2SDavid Howells BUG(); \
1798416351f2SDavid Howells } \
1799416351f2SDavid Howells } while(0)
1800416351f2SDavid Howells
180108e0e7c8SDavid Howells #define ASSERTIF(C, X) \
180208e0e7c8SDavid Howells do { \
180308e0e7c8SDavid Howells if (unlikely((C) && !(X))) { \
180408e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
180508e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
180608e0e7c8SDavid Howells BUG(); \
180708e0e7c8SDavid Howells } \
180808e0e7c8SDavid Howells } while(0)
180908e0e7c8SDavid Howells
181008e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \
181108e0e7c8SDavid Howells do { \
181208e0e7c8SDavid Howells if (unlikely((C) && !((X) OP (Y)))) { \
181308e0e7c8SDavid Howells printk(KERN_ERR "\n"); \
181408e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \
181508e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \
181608e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
181708e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
181808e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \
181908e0e7c8SDavid Howells BUG(); \
182008e0e7c8SDavid Howells } \
182108e0e7c8SDavid Howells } while(0)
182208e0e7c8SDavid Howells
182308e0e7c8SDavid Howells #else
182408e0e7c8SDavid Howells
182508e0e7c8SDavid Howells #define ASSERT(X) \
182608e0e7c8SDavid Howells do { \
182708e0e7c8SDavid Howells } while(0)
182808e0e7c8SDavid Howells
182908e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \
183008e0e7c8SDavid Howells do { \
183108e0e7c8SDavid Howells } while(0)
183208e0e7c8SDavid Howells
1833416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \
1834416351f2SDavid Howells do { \
1835416351f2SDavid Howells } while(0)
1836416351f2SDavid Howells
183708e0e7c8SDavid Howells #define ASSERTIF(C, X) \
183808e0e7c8SDavid Howells do { \
183908e0e7c8SDavid Howells } while(0)
184008e0e7c8SDavid Howells
184108e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \
184208e0e7c8SDavid Howells do { \
184308e0e7c8SDavid Howells } while(0)
184408e0e7c8SDavid Howells
184508e0e7c8SDavid Howells #endif /* __KDEBUGALL */
1846