blob: b6ec46ae03c3dbfea532ba83baeddf56de1be65d [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* internal AFS stuff
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/compiler.h>
13#include <linux/kernel.h>
Tina Ruchandani8a797902017-03-16 16:27:46 +000014#include <linux/ktime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/fs.h>
16#include <linux/pagemap.h>
David Howells08e0e7c2007-04-26 15:55:03 -070017#include <linux/rxrpc.h>
David Howells00d3b7a2007-04-26 15:57:07 -070018#include <linux/key.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040019#include <linux/workqueue.h>
Andrew Morton00c541e2007-05-31 00:40:52 -070020#include <linux/sched.h>
Christoph Hellwig80e50be2009-10-01 15:44:27 -070021#include <linux/fscache.h>
Jens Axboee1da0222010-04-22 11:58:18 +020022#include <linux/backing-dev.h>
David Howellsff548772017-02-10 16:34:07 +000023#include <linux/uuid.h>
David Howellsf044c882017-11-02 15:27:45 +000024#include <net/net_namespace.h>
David Howells8324f0b2016-08-30 09:49:29 +010025#include <net/af_rxrpc.h>
Andrew Morton00c541e2007-05-31 00:40:52 -070026
David Howells08e0e7c2007-04-26 15:55:03 -070027#include "afs.h"
28#include "afs_vl.h"
29
30#define AFS_CELL_MAX_ADDRS 15
31
David Howells31143d52007-05-09 02:33:46 -070032struct pagevec;
David Howells08e0e7c2007-04-26 15:55:03 -070033struct afs_call;
34
David Howells00d3b7a2007-04-26 15:57:07 -070035struct afs_mount_params {
36 bool rwpath; /* T if the parent should be considered R/W */
37 bool force; /* T to force cell type */
wangleibec5eb62010-08-11 09:38:04 +010038 bool autocell; /* T if set auto mount operation */
David Howells4d673da2018-02-06 06:26:30 +000039 bool dyn_root; /* T if dynamic root */
David Howells00d3b7a2007-04-26 15:57:07 -070040 afs_voltype_t type; /* type of volume requested */
41 int volnamesz; /* size of volume name */
42 const char *volname; /* name of volume to mount */
David Howellsf044c882017-11-02 15:27:45 +000043 struct afs_net *net; /* Network namespace in effect */
David Howells00d3b7a2007-04-26 15:57:07 -070044 struct afs_cell *cell; /* cell in which to find volume */
45 struct afs_volume *volume; /* volume record */
46 struct key *key; /* key to use for secure mounting */
47};
48
David Howellsc435ee32017-11-02 15:27:49 +000049struct afs_iget_data {
50 struct afs_fid fid;
51 struct afs_volume *volume; /* volume on which resides */
52};
53
David Howells8e8d7f12017-01-05 10:38:34 +000054enum afs_call_state {
David Howells98bf40c2017-11-02 15:27:53 +000055 AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
56 AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
57 AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
58 AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
59 AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
60 AFS_CALL_SV_REPLYING, /* Server: Replying */
61 AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
62 AFS_CALL_COMPLETE, /* Completed or failed */
David Howells8e8d7f12017-01-05 10:38:34 +000063};
David Howellsf044c882017-11-02 15:27:45 +000064
David Howells08e0e7c2007-04-26 15:55:03 -070065/*
David Howells8b2a4642017-11-02 15:27:50 +000066 * List of server addresses.
67 */
68struct afs_addr_list {
69 struct rcu_head rcu; /* Must be first */
70 refcount_t usage;
David Howellsd2ddc772017-11-02 15:27:50 +000071 u32 version; /* Version */
David Howells8b2a4642017-11-02 15:27:50 +000072 unsigned short nr_addrs;
73 unsigned short index; /* Address currently in use */
David Howellsd2ddc772017-11-02 15:27:50 +000074 unsigned short nr_ipv4; /* Number of IPv4 addresses */
David Howellsbf99a532017-11-02 15:27:51 +000075 unsigned long probed; /* Mask of servers that have been probed */
76 unsigned long yfs; /* Mask of servers that are YFS */
David Howells8b2a4642017-11-02 15:27:50 +000077 struct sockaddr_rxrpc addrs[];
78};
79
80/*
David Howells08e0e7c2007-04-26 15:55:03 -070081 * a record of an in-progress RxRPC call
82 */
83struct afs_call {
84 const struct afs_call_type *type; /* type of call */
David Howells08e0e7c2007-04-26 15:55:03 -070085 wait_queue_head_t waitq; /* processes awaiting completion */
David Howells341f7412017-01-05 10:38:36 +000086 struct work_struct async_work; /* async I/O processor */
David Howells08e0e7c2007-04-26 15:55:03 -070087 struct work_struct work; /* actual work processor */
David Howells08e0e7c2007-04-26 15:55:03 -070088 struct rxrpc_call *rxcall; /* RxRPC call handle */
89 struct key *key; /* security for this call */
David Howellsf044c882017-11-02 15:27:45 +000090 struct afs_net *net; /* The network namespace */
David Howellsd0676a12017-11-02 15:27:49 +000091 struct afs_server *cm_server; /* Server affected by incoming CM call */
David Howellsd2ddc772017-11-02 15:27:50 +000092 struct afs_cb_interest *cbi; /* Callback interest for server used */
David Howells08e0e7c2007-04-26 15:55:03 -070093 void *request; /* request data (first part) */
David Howells4343d002017-11-02 15:27:52 +000094 struct address_space *mapping; /* Pages being written from */
David Howells08e0e7c2007-04-26 15:55:03 -070095 void *buffer; /* reply receive buffer */
David Howells97e30432017-11-02 15:27:48 +000096 void *reply[4]; /* Where to put the reply */
David Howells31143d52007-05-09 02:33:46 -070097 pgoff_t first; /* first page in mapping to deal with */
98 pgoff_t last; /* last page in mapping to deal with */
David Howellsd0016482016-08-30 20:42:14 +010099 size_t offset; /* offset into received data store */
David Howells341f7412017-01-05 10:38:36 +0000100 atomic_t usage;
David Howells8e8d7f12017-01-05 10:38:34 +0000101 enum afs_call_state state;
David Howells98bf40c2017-11-02 15:27:53 +0000102 spinlock_t state_lock;
David Howells08e0e7c2007-04-26 15:55:03 -0700103 int error; /* error code */
David Howellsd0016482016-08-30 20:42:14 +0100104 u32 abort_code; /* Remote abort ID or 0 */
David Howells08e0e7c2007-04-26 15:55:03 -0700105 unsigned request_size; /* size of request data */
106 unsigned reply_max; /* maximum size of reply */
David Howells31143d52007-05-09 02:33:46 -0700107 unsigned first_offset; /* offset into mapping[first] */
David Howellsc435ee32017-11-02 15:27:49 +0000108 unsigned int cb_break; /* cb_break + cb_s_break before the call */
Marc Dionnebcd89272017-03-16 16:27:44 +0000109 union {
110 unsigned last_to; /* amount of mapping[last] */
111 unsigned count2; /* count used in unmarshalling */
112 };
David Howells08e0e7c2007-04-26 15:55:03 -0700113 unsigned char unmarshall; /* unmarshalling phase */
114 bool incoming; /* T if incoming call */
David Howells31143d52007-05-09 02:33:46 -0700115 bool send_pages; /* T if data from mapping should be sent */
David Howellsd0016482016-08-30 20:42:14 +0100116 bool need_attention; /* T if RxRPC poked us */
David Howells56ff9c82017-01-05 10:38:36 +0000117 bool async; /* T if asynchronous */
David Howells33cd7f22017-11-02 15:27:48 +0000118 bool ret_reply0; /* T if should return reply[0] on success */
David Howellsa68f4a22017-10-18 11:36:39 +0100119 bool upgrade; /* T to request service upgrade */
David Howellsbf99a532017-11-02 15:27:51 +0000120 u16 service_id; /* Actual service ID (after upgrade) */
David Howellsa25e21f2018-03-27 23:03:00 +0100121 unsigned int debug_id; /* Trace ID */
David Howells50a2c952016-10-13 08:27:10 +0100122 u32 operation_ID; /* operation ID for an incoming call */
David Howells08e0e7c2007-04-26 15:55:03 -0700123 u32 count; /* count for use in unmarshalling */
124 __be32 tmp; /* place to extract temporary data */
David Howells0c3a5ac2018-04-06 14:17:24 +0100125 afs_dataversion_t expected_version; /* Updated version expected from store */
126 afs_dataversion_t expected_version_2; /* 2nd updated version expected from store */
David Howells08e0e7c2007-04-26 15:55:03 -0700127};
128
129struct afs_call_type {
David Howells00d3b7a2007-04-26 15:57:07 -0700130 const char *name;
David Howells025db802017-11-02 15:27:51 +0000131 unsigned int op; /* Really enum afs_fs_operation */
David Howells00d3b7a2007-04-26 15:57:07 -0700132
David Howells08e0e7c2007-04-26 15:55:03 -0700133 /* deliver request or reply data to an call
134 * - returning an error will cause the call to be aborted
135 */
David Howellsd0016482016-08-30 20:42:14 +0100136 int (*deliver)(struct afs_call *call);
David Howells08e0e7c2007-04-26 15:55:03 -0700137
David Howells08e0e7c2007-04-26 15:55:03 -0700138 /* clean up a call */
139 void (*destructor)(struct afs_call *call);
David Howells341f7412017-01-05 10:38:36 +0000140
141 /* Work function */
142 void (*work)(struct work_struct *work);
David Howells08e0e7c2007-04-26 15:55:03 -0700143};
144
145/*
David Howells4343d002017-11-02 15:27:52 +0000146 * Key available for writeback on a file.
147 */
148struct afs_wb_key {
149 refcount_t usage;
150 struct key *key;
151 struct list_head vnode_link; /* Link in vnode->wb_keys */
152};
153
154/*
David Howells215804a2017-11-02 15:27:52 +0000155 * AFS open file information record. Pointed to by file->private_data.
156 */
157struct afs_file {
158 struct key *key; /* The key this file was opened with */
David Howells4343d002017-11-02 15:27:52 +0000159 struct afs_wb_key *wb; /* Writeback key record for this file */
David Howells215804a2017-11-02 15:27:52 +0000160};
161
162static inline struct key *afs_file_key(struct file *file)
163{
164 struct afs_file *af = file->private_data;
165
166 return af->key;
167}
168
169/*
David Howells196ee9c2017-01-05 10:38:34 +0000170 * Record of an outstanding read operation on a vnode.
171 */
172struct afs_read {
173 loff_t pos; /* Where to start reading */
David Howellse8e581a2017-03-16 16:27:44 +0000174 loff_t len; /* How much we're asking for */
David Howells196ee9c2017-01-05 10:38:34 +0000175 loff_t actual_len; /* How much we're actually getting */
David Howells6a0e3992017-03-16 16:27:46 +0000176 loff_t remain; /* Amount remaining */
David Howells0c3a5ac2018-04-06 14:17:24 +0100177 afs_dataversion_t new_version; /* Version number returned by server */
David Howells196ee9c2017-01-05 10:38:34 +0000178 atomic_t usage;
David Howells196ee9c2017-01-05 10:38:34 +0000179 unsigned int index; /* Which page we're reading into */
David Howells196ee9c2017-01-05 10:38:34 +0000180 unsigned int nr_pages;
181 void (*page_done)(struct afs_call *, struct afs_read *);
182 struct page *pages[];
183};
184
185/*
David Howells08e0e7c2007-04-26 15:55:03 -0700186 * AFS superblock private data
187 * - there's one superblock per volume
188 */
189struct afs_super_info {
David Howellsf044c882017-11-02 15:27:45 +0000190 struct afs_net *net; /* Network namespace */
David Howells49566f62017-11-02 15:27:46 +0000191 struct afs_cell *cell; /* The cell in which the volume resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700192 struct afs_volume *volume; /* volume record */
David Howells4d673da2018-02-06 06:26:30 +0000193 bool dyn_root; /* True if dynamic root */
David Howells08e0e7c2007-04-26 15:55:03 -0700194};
195
196static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
197{
198 return sb->s_fs_info;
199}
200
201extern struct file_system_type afs_fs_type;
202
203/*
David Howells6f8880d2018-04-09 21:12:31 +0100204 * Set of substitutes for @sys.
205 */
206struct afs_sysnames {
207#define AFS_NR_SYSNAME 16
208 char *subs[AFS_NR_SYSNAME];
209 refcount_t usage;
210 unsigned short nr;
211 short error;
212 char blank[1];
213};
214
215/*
David Howellsf044c882017-11-02 15:27:45 +0000216 * AFS network namespace record.
217 */
218struct afs_net {
219 struct afs_uuid uuid;
220 bool live; /* F if this namespace is being removed */
221
222 /* AF_RXRPC I/O stuff */
223 struct socket *socket;
224 struct afs_call *spare_incoming_call;
225 struct work_struct charge_preallocation_work;
226 struct mutex socket_mutex;
227 atomic_t nr_outstanding_calls;
228 atomic_t nr_superblocks;
229
230 /* Cell database */
David Howells989782d2017-11-02 15:27:50 +0000231 struct rb_root cells;
David Howellsf044c882017-11-02 15:27:45 +0000232 struct afs_cell *ws_cell;
David Howells989782d2017-11-02 15:27:50 +0000233 struct work_struct cells_manager;
234 struct timer_list cells_timer;
235 atomic_t cells_outstanding;
236 seqlock_t cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000237
David Howells989782d2017-11-02 15:27:50 +0000238 spinlock_t proc_cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000239 struct list_head proc_cells;
240
David Howellsd2ddc772017-11-02 15:27:50 +0000241 /* Known servers. Theoretically each fileserver can only be in one
242 * cell, but in practice, people create aliases and subsets and there's
243 * no easy way to distinguish them.
244 */
245 seqlock_t fs_lock; /* For fs_servers */
246 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
247 struct list_head fs_updates; /* afs_server (by update_at) */
248 struct hlist_head fs_proc; /* procfs servers list */
249
250 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
251 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
252 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
253
254 struct work_struct fs_manager;
255 struct timer_list fs_timer;
256 atomic_t servers_outstanding;
David Howellsf044c882017-11-02 15:27:45 +0000257
258 /* File locking renewal management */
259 struct mutex lock_manager_mutex;
260
David Howellsf044c882017-11-02 15:27:45 +0000261 /* Misc */
David Howellsd55b4da2018-04-06 14:17:24 +0100262 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
David Howells6f8880d2018-04-09 21:12:31 +0100263 struct afs_sysnames *sysnames;
264 rwlock_t sysnames_lock;
David Howellsd55b4da2018-04-06 14:17:24 +0100265
266 /* Statistics counters */
267 atomic_t n_lookup; /* Number of lookups done */
268 atomic_t n_reval; /* Number of dentries needing revalidation */
269 atomic_t n_inval; /* Number of invalidations by the server */
270 atomic_t n_read_dir; /* Number of directory pages read */
David Howellsf044c882017-11-02 15:27:45 +0000271};
272
David Howells6f8880d2018-04-09 21:12:31 +0100273extern const char afs_init_sysname[];
David Howellsf044c882017-11-02 15:27:45 +0000274extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
275
David Howells989782d2017-11-02 15:27:50 +0000276enum afs_cell_state {
277 AFS_CELL_UNSET,
278 AFS_CELL_ACTIVATING,
279 AFS_CELL_ACTIVE,
280 AFS_CELL_DEACTIVATING,
281 AFS_CELL_INACTIVE,
282 AFS_CELL_FAILED,
283};
284
David Howellsf044c882017-11-02 15:27:45 +0000285/*
David Howellsd2ddc772017-11-02 15:27:50 +0000286 * AFS cell record.
287 *
288 * This is a tricky concept to get right as it is possible to create aliases
289 * simply by pointing AFSDB/SRV records for two names at the same set of VL
290 * servers; it is also possible to do things like setting up two sets of VL
291 * servers, one of which provides a superset of the volumes provided by the
292 * other (for internal/external division, for example).
293 *
294 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
295 * servers and (b) a cell's name is used by the client to select the key to use
296 * for authentication and encryption. The cell name is not typically used in
297 * the protocol.
298 *
299 * There is no easy way to determine if two cells are aliases or one is a
300 * subset of another.
David Howells08e0e7c2007-04-26 15:55:03 -0700301 */
302struct afs_cell {
David Howells989782d2017-11-02 15:27:50 +0000303 union {
304 struct rcu_head rcu;
305 struct rb_node net_node; /* Node in net->cells */
306 };
307 struct afs_net *net;
David Howells00d3b7a2007-04-26 15:57:07 -0700308 struct key *anonymous_key; /* anonymous user key for this cell */
David Howells989782d2017-11-02 15:27:50 +0000309 struct work_struct manager; /* Manager for init/deinit/dns */
David Howells08e0e7c2007-04-26 15:55:03 -0700310 struct list_head proc_link; /* /proc cell list link */
David Howells9b3f26c2009-04-03 16:42:41 +0100311#ifdef CONFIG_AFS_FSCACHE
312 struct fscache_cookie *cache; /* caching cookie */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#endif
David Howells989782d2017-11-02 15:27:50 +0000314 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
315 time64_t last_inactive; /* Time of last drop of usage count */
316 atomic_t usage;
317 unsigned long flags;
318#define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
319#define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
320#define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
321#define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
David Howells8b2a4642017-11-02 15:27:50 +0000322#define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
David Howells989782d2017-11-02 15:27:50 +0000323 enum afs_cell_state state;
324 short error;
325
David Howellsd2ddc772017-11-02 15:27:50 +0000326 /* Active fileserver interaction state. */
327 struct list_head proc_volumes; /* procfs volume list */
328 rwlock_t proc_lock;
David Howells989782d2017-11-02 15:27:50 +0000329
David Howellsd2ddc772017-11-02 15:27:50 +0000330 /* VL server list. */
David Howells8b2a4642017-11-02 15:27:50 +0000331 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
332 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
David Howells989782d2017-11-02 15:27:50 +0000333 u8 name_len; /* Length of name */
334 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
David Howells08e0e7c2007-04-26 15:55:03 -0700335};
336
337/*
David Howellsd2ddc772017-11-02 15:27:50 +0000338 * Cached VLDB entry.
339 *
340 * This is pointed to by cell->vldb_entries, indexed by name.
David Howells08e0e7c2007-04-26 15:55:03 -0700341 */
David Howellsd2ddc772017-11-02 15:27:50 +0000342struct afs_vldb_entry {
343 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
David Howells00d3b7a2007-04-26 15:57:07 -0700344
David Howellsd2ddc772017-11-02 15:27:50 +0000345 unsigned long flags;
346#define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
347#define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
348#define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
349#define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
350#define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
351
352 uuid_t fs_server[AFS_NMAXNSERVERS];
353 u8 fs_mask[AFS_NMAXNSERVERS];
David Howells08e0e7c2007-04-26 15:55:03 -0700354#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
355#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
356#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
David Howellsd2ddc772017-11-02 15:27:50 +0000357 short error;
358 u8 nr_servers; /* Number of server records */
359 u8 name_len;
360 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700361};
362
363/*
David Howellsd2ddc772017-11-02 15:27:50 +0000364 * Record of fileserver with which we're actively communicating.
David Howells08e0e7c2007-04-26 15:55:03 -0700365 */
366struct afs_server {
David Howellsd2ddc772017-11-02 15:27:50 +0000367 struct rcu_head rcu;
368 union {
369 uuid_t uuid; /* Server ID */
370 struct afs_uuid _uuid;
371 };
David Howellsc435ee32017-11-02 15:27:49 +0000372
David Howellsd2ddc772017-11-02 15:27:50 +0000373 struct afs_addr_list __rcu *addresses;
374 struct rb_node uuid_rb; /* Link in net->servers */
375 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
376 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
377 struct hlist_node proc_link; /* Link in net->fs_proc */
378 struct afs_server *gc_next; /* Next server in manager's list */
379 time64_t put_time; /* Time at which last put */
380 time64_t update_at; /* Time at which to next update the record */
David Howellsc435ee32017-11-02 15:27:49 +0000381 unsigned long flags;
David Howellsd2ddc772017-11-02 15:27:50 +0000382#define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
383#define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
384#define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
385#define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
386#define AFS_SERVER_FL_UPDATING 4
387#define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
388#define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
David Howells5cf9dd52018-04-09 21:12:31 +0100389#define AFS_SERVER_FL_NO_IBULK 7 /* Fileserver doesn't support FS.InlineBulkStatus */
David Howellsd2ddc772017-11-02 15:27:50 +0000390 atomic_t usage;
391 u32 addr_version; /* Address list version */
David Howells08e0e7c2007-04-26 15:55:03 -0700392
393 /* file service access */
David Howellsd2ddc772017-11-02 15:27:50 +0000394 rwlock_t fs_lock; /* access lock */
David Howells08e0e7c2007-04-26 15:55:03 -0700395
396 /* callback promise management */
David Howellsc435ee32017-11-02 15:27:49 +0000397 struct list_head cb_interests; /* List of superblocks using this server */
398 unsigned cb_s_break; /* Break-everything counter. */
399 rwlock_t cb_break_lock; /* Volume finding lock */
400};
401
402/*
403 * Interest by a superblock on a server.
404 */
405struct afs_cb_interest {
406 struct list_head cb_link; /* Link in server->cb_interests */
407 struct afs_server *server; /* Server on which this interest resides */
408 struct super_block *sb; /* Superblock on which inodes reside */
409 afs_volid_t vid; /* Volume ID to match */
410 refcount_t usage;
David Howells08e0e7c2007-04-26 15:55:03 -0700411};
412
413/*
David Howellsd2ddc772017-11-02 15:27:50 +0000414 * Replaceable server list.
David Howells08e0e7c2007-04-26 15:55:03 -0700415 */
David Howellsd2ddc772017-11-02 15:27:50 +0000416struct afs_server_entry {
417 struct afs_server *server;
418 struct afs_cb_interest *cb_interest;
419};
420
421struct afs_server_list {
422 refcount_t usage;
423 unsigned short nr_servers;
424 unsigned short index; /* Server currently in use */
425 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
426 unsigned int seq; /* Set to ->servers_seq when installed */
427 struct afs_server_entry servers[];
David Howells08e0e7c2007-04-26 15:55:03 -0700428};
429
430/*
David Howellsd2ddc772017-11-02 15:27:50 +0000431 * Live AFS volume management.
David Howells08e0e7c2007-04-26 15:55:03 -0700432 */
David Howellsd2ddc772017-11-02 15:27:50 +0000433struct afs_volume {
434 afs_volid_t vid; /* volume ID */
435 atomic_t usage;
436 time64_t update_at; /* Time at which to next update */
437 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
438 struct list_head proc_link; /* Link in cell->vl_proc */
439 unsigned long flags;
440#define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
441#define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
442#define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
443#define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
444#define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
445#define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
446#ifdef CONFIG_AFS_FSCACHE
447 struct fscache_cookie *cache; /* caching cookie */
448#endif
449 struct afs_server_list *servers; /* List of servers on which volume resides */
450 rwlock_t servers_lock; /* Lock for ->servers */
451 unsigned int servers_seq; /* Incremented each time ->servers changes */
452
453 afs_voltype_t type; /* type of volume */
454 short error;
455 char type_force; /* force volume type (suppress R/O -> R/W) */
456 u8 name_len;
457 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700458};
459
David Howells0fafdc92017-11-13 16:59:50 +0000460enum afs_lock_state {
461 AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
462 AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
463 AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
464 AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
465 AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
466 AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
467 AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
468};
469
David Howells08e0e7c2007-04-26 15:55:03 -0700470/*
David Howellsf8de4832017-12-01 11:40:43 +0000471 * AFS inode private data.
472 *
473 * Note that afs_alloc_inode() *must* reset anything that could incorrectly
474 * leak from one inode to another.
David Howells08e0e7c2007-04-26 15:55:03 -0700475 */
476struct afs_vnode {
477 struct inode vfs_inode; /* the VFS's inode record */
478
479 struct afs_volume *volume; /* volume on which vnode resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700480 struct afs_fid fid; /* the file identifier for this inode */
481 struct afs_file_status status; /* AFS status info for this file */
David Howellsa4ff7402018-04-06 14:17:24 +0100482 afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
David Howells9b3f26c2009-04-03 16:42:41 +0100483#ifdef CONFIG_AFS_FSCACHE
484 struct fscache_cookie *cache; /* caching cookie */
David Howells08e0e7c2007-04-26 15:55:03 -0700485#endif
David Howellsfe342cf2018-04-09 21:12:31 +0100486 struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
David Howellsd2ddc772017-11-02 15:27:50 +0000487 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
David Howells260a9802007-04-26 15:59:35 -0700488 struct mutex validate_lock; /* lock for validating this vnode */
David Howells4343d002017-11-02 15:27:52 +0000489 spinlock_t wb_lock; /* lock for wb_keys */
David Howells08e0e7c2007-04-26 15:55:03 -0700490 spinlock_t lock; /* waitqueue/flags lock */
491 unsigned long flags;
David Howellsc435ee32017-11-02 15:27:49 +0000492#define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
David Howells260a9802007-04-26 15:59:35 -0700493#define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
David Howellsc435ee32017-11-02 15:27:49 +0000494#define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */
David Howells08e0e7c2007-04-26 15:55:03 -0700495#define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
496#define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
497#define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
David Howells0fafdc92017-11-13 16:59:50 +0000498#define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
499#define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
David Howells08e0e7c2007-04-26 15:55:03 -0700500
David Howells4343d002017-11-02 15:27:52 +0000501 struct list_head wb_keys; /* List of keys available for writeback */
David Howellse8d6c552007-07-15 23:40:12 -0700502 struct list_head pending_locks; /* locks waiting to be granted */
503 struct list_head granted_locks; /* locks granted on this file */
504 struct delayed_work lock_work; /* work to be done in locking */
David Howells0fafdc92017-11-13 16:59:50 +0000505 struct key *lock_key; /* Key to be used in lock ops */
506 enum afs_lock_state lock_state : 8;
507 afs_lock_type_t lock_type : 8;
David Howells31143d52007-05-09 02:33:46 -0700508
David Howells08e0e7c2007-04-26 15:55:03 -0700509 /* outstanding callback notification on this file */
David Howellsc435ee32017-11-02 15:27:49 +0000510 struct afs_cb_interest *cb_interest; /* Server on which this resides */
511 unsigned int cb_s_break; /* Mass break counter on ->server */
512 unsigned int cb_break; /* Break counter on vnode */
513 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
514
515 time64_t cb_expires_at; /* time at which callback expires */
David Howells08e0e7c2007-04-26 15:55:03 -0700516 unsigned cb_version; /* callback version */
David Howells08e0e7c2007-04-26 15:55:03 -0700517 afs_callback_type_t cb_type; /* type of callback */
David Howells08e0e7c2007-04-26 15:55:03 -0700518};
519
David Howells00d3b7a2007-04-26 15:57:07 -0700520/*
521 * cached security record for one user's attempt to access a vnode
522 */
523struct afs_permit {
524 struct key *key; /* RxRPC ticket holding a security context */
David Howellsbe080a62017-11-02 15:27:49 +0000525 afs_access_t access; /* CallerAccess value for this key */
David Howells00d3b7a2007-04-26 15:57:07 -0700526};
527
528/*
David Howellsbe080a62017-11-02 15:27:49 +0000529 * Immutable cache of CallerAccess records from attempts to access vnodes.
530 * These may be shared between multiple vnodes.
David Howells00d3b7a2007-04-26 15:57:07 -0700531 */
532struct afs_permits {
David Howellsbe080a62017-11-02 15:27:49 +0000533 struct rcu_head rcu;
534 struct hlist_node hash_node; /* Link in hash */
535 unsigned long h; /* Hash value for this permit list */
536 refcount_t usage;
537 unsigned short nr_permits; /* Number of records */
538 bool invalidated; /* Invalidated due to key change */
539 struct afs_permit permits[]; /* List of permits sorted by key pointer */
David Howells00d3b7a2007-04-26 15:57:07 -0700540};
541
David Howellsb908fe62007-04-26 15:58:17 -0700542/*
543 * record of one of a system's set of network interfaces
544 */
545struct afs_interface {
David Howellsb908fe62007-04-26 15:58:17 -0700546 struct in_addr address; /* IPv4 address bound to interface */
547 struct in_addr netmask; /* netmask applied to address */
548 unsigned mtu; /* MTU of interface */
549};
550
David Howells8b2a4642017-11-02 15:27:50 +0000551/*
552 * Cursor for iterating over a server's address list.
553 */
554struct afs_addr_cursor {
555 struct afs_addr_list *alist; /* Current address list (pins ref) */
556 struct sockaddr_rxrpc *addr;
David Howellsd2ddc772017-11-02 15:27:50 +0000557 u32 abort_code;
David Howells8b2a4642017-11-02 15:27:50 +0000558 unsigned short start; /* Starting point in alist->addrs[] */
559 unsigned short index; /* Wrapping offset from start to current addr */
560 short error;
561 bool begun; /* T if we've begun iteration */
562 bool responded; /* T if the current address responded */
563};
564
565/*
566 * Cursor for iterating over a set of fileservers.
567 */
568struct afs_fs_cursor {
569 struct afs_addr_cursor ac;
David Howellsd2ddc772017-11-02 15:27:50 +0000570 struct afs_vnode *vnode;
571 struct afs_server_list *server_list; /* Current server list (pins ref) */
572 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
573 struct key *key; /* Key for the server */
574 unsigned int cb_break; /* cb_break + cb_s_break before the call */
575 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
576 unsigned char start; /* Initial index in server list */
577 unsigned char index; /* Number of servers tried beyond start */
578 unsigned short flags;
579#define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
580#define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
581#define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
582#define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
583#define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
584#define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
David Howells8b2a4642017-11-02 15:27:50 +0000585};
586
David Howells402cb8d2018-04-04 13:41:28 +0100587/*
588 * Cache auxiliary data.
589 */
590struct afs_vnode_cache_aux {
591 u64 data_version;
592} __packed;
593
David Howells98bf40c2017-11-02 15:27:53 +0000594#include <trace/events/afs.h>
595
David Howells08e0e7c2007-04-26 15:55:03 -0700596/*****************************************************************************/
597/*
David Howells8b2a4642017-11-02 15:27:50 +0000598 * addr_list.c
599 */
600static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
601{
602 if (alist)
603 refcount_inc(&alist->usage);
604 return alist;
605}
606extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
607 unsigned short,
608 unsigned short);
609extern void afs_put_addrlist(struct afs_addr_list *);
610extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
611 unsigned short, unsigned short);
612extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
613extern bool afs_iterate_addresses(struct afs_addr_cursor *);
614extern int afs_end_cursor(struct afs_addr_cursor *);
615extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
616
David Howellsbf99a532017-11-02 15:27:51 +0000617extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
618extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
David Howellsd2ddc772017-11-02 15:27:50 +0000619
David Howells8b2a4642017-11-02 15:27:50 +0000620/*
David Howells9b3f26c2009-04-03 16:42:41 +0100621 * cache.c
622 */
623#ifdef CONFIG_AFS_FSCACHE
624extern struct fscache_netfs afs_cache_netfs;
625extern struct fscache_cookie_def afs_cell_cache_index_def;
David Howells9b3f26c2009-04-03 16:42:41 +0100626extern struct fscache_cookie_def afs_volume_cache_index_def;
627extern struct fscache_cookie_def afs_vnode_cache_index_def;
628#else
629#define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
David Howells9b3f26c2009-04-03 16:42:41 +0100630#define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
631#define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
632#endif
633
634/*
David Howells08e0e7c2007-04-26 15:55:03 -0700635 * callback.c
636 */
637extern void afs_init_callback_state(struct afs_server *);
David Howellsc435ee32017-11-02 15:27:49 +0000638extern void afs_break_callback(struct afs_vnode *);
David Howells5cf9dd52018-04-09 21:12:31 +0100639extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
David Howellsc435ee32017-11-02 15:27:49 +0000640
David Howellsd2ddc772017-11-02 15:27:50 +0000641extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
David Howellsc435ee32017-11-02 15:27:49 +0000642extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
David Howellsd2ddc772017-11-02 15:27:50 +0000643extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
David Howellsc435ee32017-11-02 15:27:49 +0000644
645static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
646{
647 refcount_inc(&cbi->usage);
648 return cbi;
649}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651/*
652 * cell.c
653 */
David Howells989782d2017-11-02 15:27:50 +0000654extern int afs_cell_init(struct afs_net *, const char *);
655extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
656extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
657 const char *, bool);
David Howells8b2a4642017-11-02 15:27:50 +0000658extern struct afs_cell *afs_get_cell(struct afs_cell *);
David Howells9ed900b2017-11-02 15:27:46 +0000659extern void afs_put_cell(struct afs_net *, struct afs_cell *);
David Howells989782d2017-11-02 15:27:50 +0000660extern void afs_manage_cells(struct work_struct *);
661extern void afs_cells_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000662extern void __net_exit afs_cell_purge(struct afs_net *);
David Howells08e0e7c2007-04-26 15:55:03 -0700663
664/*
665 * cmservice.c
666 */
667extern bool afs_cm_incoming_call(struct afs_call *);
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669/*
670 * dir.c
671 */
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800672extern const struct file_operations afs_dir_file_operations;
David Howells4d673da2018-02-06 06:26:30 +0000673extern const struct inode_operations afs_dir_inode_operations;
David Howells4d673da2018-02-06 06:26:30 +0000674extern const struct dentry_operations afs_fs_dentry_operations;
675
676extern bool afs_dir_check_page(struct inode *, struct page *);
David Howells66c7e1d2018-04-06 14:17:25 +0100677extern void afs_d_release(struct dentry *);
678
679/*
680 * dynroot.c
681 */
682extern const struct file_operations afs_dynroot_file_operations;
683extern const struct inode_operations afs_dynroot_inode_operations;
684extern const struct dentry_operations afs_dynroot_dentry_operations;
685
686extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688/*
689 * file.c
690 */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700691extern const struct address_space_operations afs_fs_aops;
Arjan van de Ven754661f2007-02-12 00:55:38 -0800692extern const struct inode_operations afs_file_inode_operations;
David Howells00d3b7a2007-04-26 15:57:07 -0700693extern const struct file_operations afs_file_operations;
694
David Howells4343d002017-11-02 15:27:52 +0000695extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
696extern void afs_put_wb_key(struct afs_wb_key *);
David Howells00d3b7a2007-04-26 15:57:07 -0700697extern int afs_open(struct inode *, struct file *);
698extern int afs_release(struct inode *, struct file *);
David Howellsd2ddc772017-11-02 15:27:50 +0000699extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
Al Virof6d335c2010-05-21 15:27:09 +0100700extern int afs_page_filler(void *, struct page *);
David Howells196ee9c2017-01-05 10:38:34 +0000701extern void afs_put_read(struct afs_read *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703/*
David Howellse8d6c552007-07-15 23:40:12 -0700704 * flock.c
705 */
David Howellsf044c882017-11-02 15:27:45 +0000706extern struct workqueue_struct *afs_lock_manager;
707
David Howellse8d6c552007-07-15 23:40:12 -0700708extern void afs_lock_work(struct work_struct *);
709extern void afs_lock_may_be_available(struct afs_vnode *);
710extern int afs_lock(struct file *, int, struct file_lock *);
711extern int afs_flock(struct file *, int, struct file_lock *);
712
713/*
David Howells08e0e7c2007-04-26 15:55:03 -0700714 * fsclient.c
715 */
David Howellsdd9fbcb2018-04-06 14:17:24 +0100716#define AFS_VNODE_NOT_YET_SET 0x01
717#define AFS_VNODE_META_CHANGED 0x02
718#define AFS_VNODE_DATA_CHANGED 0x04
719extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *,
720 const afs_dataversion_t *, u8);
721
David Howells0c3a5ac2018-04-06 14:17:24 +0100722extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
David Howellsd2ddc772017-11-02 15:27:50 +0000723extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
724extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
725extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
726 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
727extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
728extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
729extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
730 struct afs_fid *, struct afs_file_status *);
731extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
732 struct afs_vnode *, const char *);
David Howells4343d002017-11-02 15:27:52 +0000733extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
David Howellsd2ddc772017-11-02 15:27:50 +0000734 pgoff_t, pgoff_t, unsigned, unsigned);
735extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
736extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
737extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
738extern int afs_fs_extend_lock(struct afs_fs_cursor *);
739extern int afs_fs_release_lock(struct afs_fs_cursor *);
740extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
741 struct afs_addr_cursor *, struct key *);
742extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
743 struct afs_addr_cursor *, struct key *);
David Howells5cf9dd52018-04-09 21:12:31 +0100744extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
745 struct afs_fid *, struct afs_file_status *,
746 struct afs_callback *, unsigned int,
747 struct afs_volsync *);
748extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
749 struct afs_fid *, struct afs_file_status *,
750 struct afs_callback *, struct afs_volsync *);
David Howells08e0e7c2007-04-26 15:55:03 -0700751
752/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 * inode.c
754 */
David Howells0c3a5ac2018-04-06 14:17:24 +0100755extern int afs_fetch_status(struct afs_vnode *, struct key *, bool);
David Howellsc435ee32017-11-02 15:27:49 +0000756extern int afs_iget5_test(struct inode *, void *);
David Howells4d673da2018-02-06 06:26:30 +0000757extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
David Howells00d3b7a2007-04-26 15:57:07 -0700758extern struct inode *afs_iget(struct super_block *, struct key *,
David Howells260a9802007-04-26 15:59:35 -0700759 struct afs_fid *, struct afs_file_status *,
David Howellsd2ddc772017-11-02 15:27:50 +0000760 struct afs_callback *,
761 struct afs_cb_interest *);
David Howells416351f2007-05-09 02:33:45 -0700762extern void afs_zap_data(struct afs_vnode *);
David Howells260a9802007-04-26 15:59:35 -0700763extern int afs_validate(struct afs_vnode *, struct key *);
David Howellsa528d352017-01-31 16:46:22 +0000764extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
David Howells31143d52007-05-09 02:33:46 -0700765extern int afs_setattr(struct dentry *, struct iattr *);
Al Virob57922d2010-06-07 14:34:48 -0400766extern void afs_evict_inode(struct inode *);
wangleibec5eb62010-08-11 09:38:04 +0100767extern int afs_drop_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769/*
770 * main.c
771 */
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000772extern struct workqueue_struct *afs_wq;
David Howellsf044c882017-11-02 15:27:45 +0000773
774static inline struct afs_net *afs_d2net(struct dentry *dentry)
775{
776 return &__afs_net;
777}
778
779static inline struct afs_net *afs_i2net(struct inode *inode)
780{
781 return &__afs_net;
782}
783
784static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
785{
786 return &__afs_net;
787}
788
789static inline struct afs_net *afs_sock2net(struct sock *sk)
790{
791 return &__afs_net;
792}
793
794static inline struct afs_net *afs_get_net(struct afs_net *net)
795{
796 return net;
797}
798
799static inline void afs_put_net(struct afs_net *net)
800{
801}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
David Howellsd55b4da2018-04-06 14:17:24 +0100803static inline void __afs_stat(atomic_t *s)
804{
805 atomic_inc(s);
806}
807
808#define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810/*
David Howells08e0e7c2007-04-26 15:55:03 -0700811 * misc.c
812 */
813extern int afs_abort_to_error(u32);
814
815/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 * mntpt.c
817 */
Arjan van de Ven754661f2007-02-12 00:55:38 -0800818extern const struct inode_operations afs_mntpt_inode_operations;
wangleibec5eb62010-08-11 09:38:04 +0100819extern const struct inode_operations afs_autocell_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800820extern const struct file_operations afs_mntpt_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
David Howellsd18610b2011-01-14 19:04:05 +0000822extern struct vfsmount *afs_d_automount(struct path *);
David Howells08e0e7c2007-04-26 15:55:03 -0700823extern void afs_mntpt_kill_timer(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825/*
Arnd Bergmannb4db2b32017-02-10 16:34:07 +0000826 * netdevices.c
827 */
828extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
829
830/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 * proc.c
832 */
David Howellsf044c882017-11-02 15:27:45 +0000833extern int __net_init afs_proc_init(struct afs_net *);
834extern void __net_exit afs_proc_cleanup(struct afs_net *);
835extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
836extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
David Howells6f8880d2018-04-09 21:12:31 +0100837extern void afs_put_sysnames(struct afs_sysnames *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
David Howells08e0e7c2007-04-26 15:55:03 -0700839/*
David Howellsd2ddc772017-11-02 15:27:50 +0000840 * rotate.c
841 */
842extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
843 struct key *);
844extern bool afs_select_fileserver(struct afs_fs_cursor *);
845extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
846extern int afs_end_vnode_operation(struct afs_fs_cursor *);
847
848/*
David Howells08e0e7c2007-04-26 15:55:03 -0700849 * rxrpc.c
850 */
David Howellsf044c882017-11-02 15:27:45 +0000851extern struct workqueue_struct *afs_async_calls;
David Howells8324f0b2016-08-30 09:49:29 +0100852
David Howellsf044c882017-11-02 15:27:45 +0000853extern int __net_init afs_open_socket(struct afs_net *);
854extern void __net_exit afs_close_socket(struct afs_net *);
855extern void afs_charge_preallocation(struct work_struct *);
David Howells341f7412017-01-05 10:38:36 +0000856extern void afs_put_call(struct afs_call *);
857extern int afs_queue_call_work(struct afs_call *);
David Howells8b2a4642017-11-02 15:27:50 +0000858extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
David Howellsf044c882017-11-02 15:27:45 +0000859extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
860 const struct afs_call_type *,
David Howells08e0e7c2007-04-26 15:55:03 -0700861 size_t, size_t);
862extern void afs_flat_call_destructor(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -0700863extern void afs_send_empty_reply(struct afs_call *);
David Howellsb908fe62007-04-26 15:58:17 -0700864extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
David Howellsd0016482016-08-30 20:42:14 +0100865extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
David Howells08e0e7c2007-04-26 15:55:03 -0700866
David Howellsd0016482016-08-30 20:42:14 +0100867static inline int afs_transfer_reply(struct afs_call *call)
David Howells372ee162016-08-03 14:11:40 +0100868{
David Howellsd0016482016-08-30 20:42:14 +0100869 return afs_extract_data(call, call->buffer, call->reply_max, false);
David Howells372ee162016-08-03 14:11:40 +0100870}
871
David Howells98bf40c2017-11-02 15:27:53 +0000872static inline bool afs_check_call_state(struct afs_call *call,
873 enum afs_call_state state)
874{
875 return READ_ONCE(call->state) == state;
876}
877
878static inline bool afs_set_call_state(struct afs_call *call,
879 enum afs_call_state from,
880 enum afs_call_state to)
881{
882 bool ok = false;
883
884 spin_lock_bh(&call->state_lock);
885 if (call->state == from) {
886 call->state = to;
887 trace_afs_call_state(call, from, to, 0, 0);
888 ok = true;
889 }
890 spin_unlock_bh(&call->state_lock);
891 return ok;
892}
893
894static inline void afs_set_call_complete(struct afs_call *call,
895 int error, u32 remote_abort)
896{
897 enum afs_call_state state;
898 bool ok = false;
899
900 spin_lock_bh(&call->state_lock);
901 state = call->state;
902 if (state != AFS_CALL_COMPLETE) {
903 call->abort_code = remote_abort;
904 call->error = error;
905 call->state = AFS_CALL_COMPLETE;
906 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
907 error, remote_abort);
908 ok = true;
909 }
910 spin_unlock_bh(&call->state_lock);
911 if (ok)
912 trace_afs_call_done(call);
913}
914
David Howells08e0e7c2007-04-26 15:55:03 -0700915/*
David Howells00d3b7a2007-04-26 15:57:07 -0700916 * security.c
917 */
David Howellsbe080a62017-11-02 15:27:49 +0000918extern void afs_put_permits(struct afs_permits *);
David Howells00d3b7a2007-04-26 15:57:07 -0700919extern void afs_clear_permits(struct afs_vnode *);
David Howellsbe080a62017-11-02 15:27:49 +0000920extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
David Howells416351f2007-05-09 02:33:45 -0700921extern void afs_zap_permits(struct rcu_head *);
David Howells00d3b7a2007-04-26 15:57:07 -0700922extern struct key *afs_request_key(struct afs_cell *);
David Howells0fafdc92017-11-13 16:59:50 +0000923extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
Al Viro10556cb22011-06-20 19:28:19 -0400924extern int afs_permission(struct inode *, int);
David Howellsbe080a62017-11-02 15:27:49 +0000925extern void __exit afs_clean_up_permit_cache(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700926
927/*
David Howells08e0e7c2007-04-26 15:55:03 -0700928 * server.c
929 */
930extern spinlock_t afs_server_peer_lock;
931
David Howellsc435ee32017-11-02 15:27:49 +0000932static inline struct afs_server *afs_get_server(struct afs_server *server)
933{
934 atomic_inc(&server->usage);
935 return server;
936}
David Howells08e0e7c2007-04-26 15:55:03 -0700937
David Howellsf044c882017-11-02 15:27:45 +0000938extern struct afs_server *afs_find_server(struct afs_net *,
939 const struct sockaddr_rxrpc *);
David Howellsd2ddc772017-11-02 15:27:50 +0000940extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
941extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
David Howells9ed900b2017-11-02 15:27:46 +0000942extern void afs_put_server(struct afs_net *, struct afs_server *);
David Howellsd2ddc772017-11-02 15:27:50 +0000943extern void afs_manage_servers(struct work_struct *);
944extern void afs_servers_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000945extern void __net_exit afs_purge_servers(struct afs_net *);
David Howellsd2ddc772017-11-02 15:27:50 +0000946extern bool afs_probe_fileserver(struct afs_fs_cursor *);
947extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
948
949/*
950 * server_list.c
951 */
952static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
953{
954 refcount_inc(&slist->usage);
955 return slist;
956}
957
958extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
959extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
960 struct afs_vldb_entry *,
961 u8);
962extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
David Howells08e0e7c2007-04-26 15:55:03 -0700963
964/*
David Howells00d3b7a2007-04-26 15:57:07 -0700965 * super.c
966 */
David Howellsf044c882017-11-02 15:27:45 +0000967extern int __init afs_fs_init(void);
968extern void __exit afs_fs_exit(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700969
970/*
David Howells08e0e7c2007-04-26 15:55:03 -0700971 * vlclient.c
972 */
David Howellsd2ddc772017-11-02 15:27:50 +0000973extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
974 struct afs_addr_cursor *,
975 struct key *, const char *, int);
976extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
977 struct key *, const uuid_t *);
David Howellsbf99a532017-11-02 15:27:51 +0000978extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
979extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
980 struct key *, const uuid_t *);
David Howells08e0e7c2007-04-26 15:55:03 -0700981
982/*
983 * volume.c
984 */
David Howellsd2ddc772017-11-02 15:27:50 +0000985static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
David Howells49566f62017-11-02 15:27:46 +0000986{
987 if (volume)
988 atomic_inc(&volume->usage);
989 return volume;
990}
David Howells08e0e7c2007-04-26 15:55:03 -0700991
David Howellsd2ddc772017-11-02 15:27:50 +0000992extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
993extern void afs_activate_volume(struct afs_volume *);
994extern void afs_deactivate_volume(struct afs_volume *);
David Howells9ed900b2017-11-02 15:27:46 +0000995extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
David Howellsd2ddc772017-11-02 15:27:50 +0000996extern int afs_check_volume_status(struct afs_volume *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700997
David Howells31143d52007-05-09 02:33:46 -0700998/*
999 * write.c
1000 */
1001extern int afs_set_page_dirty(struct page *);
Nick Piggin15b46502008-10-15 22:04:32 -07001002extern int afs_write_begin(struct file *file, struct address_space *mapping,
1003 loff_t pos, unsigned len, unsigned flags,
1004 struct page **pagep, void **fsdata);
1005extern int afs_write_end(struct file *file, struct address_space *mapping,
1006 loff_t pos, unsigned len, unsigned copied,
1007 struct page *page, void *fsdata);
David Howells31143d52007-05-09 02:33:46 -07001008extern int afs_writepage(struct page *, struct writeback_control *);
1009extern int afs_writepages(struct address_space *, struct writeback_control *);
David Howells31143d52007-05-09 02:33:46 -07001010extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
Al Viro50b55512014-04-03 14:13:46 -04001011extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
David Howells58fed942017-03-16 16:27:45 +00001012extern int afs_flush(struct file *, fl_owner_t);
Josef Bacik02c24a82011-07-16 20:44:56 -04001013extern int afs_fsync(struct file *, loff_t, loff_t, int);
David Howells1cf7a152017-11-02 15:27:52 +00001014extern int afs_page_mkwrite(struct vm_fault *);
David Howells4343d002017-11-02 15:27:52 +00001015extern void afs_prune_wb_keys(struct afs_vnode *);
1016extern int afs_launder_page(struct page *);
David Howells31143d52007-05-09 02:33:46 -07001017
David Howellsd3e3b7ea2017-07-06 15:50:27 +01001018/*
1019 * xattr.c
1020 */
1021extern const struct xattr_handler *afs_xattr_handlers[];
1022extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
David Howells31143d52007-05-09 02:33:46 -07001023
David Howellsd2ddc772017-11-02 15:27:50 +00001024
1025/*
1026 * Miscellaneous inline functions.
1027 */
1028static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1029{
1030 return container_of(inode, struct afs_vnode, vfs_inode);
1031}
1032
1033static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1034{
1035 return &vnode->vfs_inode;
1036}
1037
1038static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
1039 struct afs_vnode *vnode,
1040 unsigned int cb_break)
1041{
1042 if (fc->ac.error == 0)
1043 afs_cache_permit(vnode, fc->key, cb_break);
1044}
1045
1046static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
1047 struct afs_vnode *vnode)
1048{
1049 if (fc->ac.error == -ENOENT) {
1050 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1051 afs_break_callback(vnode);
1052 }
1053}
1054
1055
David Howells08e0e7c2007-04-26 15:55:03 -07001056/*****************************************************************************/
1057/*
1058 * debug tracing
1059 */
1060extern unsigned afs_debug;
1061
1062#define dbgprintk(FMT,...) \
Sven Schnellead16df82008-04-03 10:44:01 +01001063 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -07001064
Harvey Harrison530b6412008-04-30 00:55:09 -07001065#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1066#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -07001067#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1068
1069
1070#if defined(__KDEBUG)
1071#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1072#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1073#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1074
1075#elif defined(CONFIG_AFS_DEBUG)
1076#define AFS_DEBUG_KENTER 0x01
1077#define AFS_DEBUG_KLEAVE 0x02
1078#define AFS_DEBUG_KDEBUG 0x04
1079
1080#define _enter(FMT,...) \
1081do { \
1082 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
1083 kenter(FMT,##__VA_ARGS__); \
1084} while (0)
1085
1086#define _leave(FMT,...) \
1087do { \
1088 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
1089 kleave(FMT,##__VA_ARGS__); \
1090} while (0)
1091
1092#define _debug(FMT,...) \
1093do { \
1094 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
1095 kdebug(FMT,##__VA_ARGS__); \
1096} while (0)
1097
1098#else
David Howells12fdff32010-08-12 16:54:57 +01001099#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1100#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1101#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -07001102#endif
1103
1104/*
1105 * debug assertion checking
1106 */
1107#if 1 // defined(__KDEBUGALL)
1108
1109#define ASSERT(X) \
1110do { \
1111 if (unlikely(!(X))) { \
1112 printk(KERN_ERR "\n"); \
1113 printk(KERN_ERR "AFS: Assertion failed\n"); \
1114 BUG(); \
1115 } \
1116} while(0)
1117
1118#define ASSERTCMP(X, OP, Y) \
1119do { \
1120 if (unlikely(!((X) OP (Y)))) { \
1121 printk(KERN_ERR "\n"); \
1122 printk(KERN_ERR "AFS: Assertion failed\n"); \
1123 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1124 (unsigned long)(X), (unsigned long)(Y)); \
1125 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1126 (unsigned long)(X), (unsigned long)(Y)); \
1127 BUG(); \
1128 } \
1129} while(0)
1130
David Howells416351f2007-05-09 02:33:45 -07001131#define ASSERTRANGE(L, OP1, N, OP2, H) \
1132do { \
1133 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1134 printk(KERN_ERR "\n"); \
1135 printk(KERN_ERR "AFS: Assertion failed\n"); \
1136 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1137 (unsigned long)(L), (unsigned long)(N), \
1138 (unsigned long)(H)); \
1139 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1140 (unsigned long)(L), (unsigned long)(N), \
1141 (unsigned long)(H)); \
1142 BUG(); \
1143 } \
1144} while(0)
1145
David Howells08e0e7c2007-04-26 15:55:03 -07001146#define ASSERTIF(C, X) \
1147do { \
1148 if (unlikely((C) && !(X))) { \
1149 printk(KERN_ERR "\n"); \
1150 printk(KERN_ERR "AFS: Assertion failed\n"); \
1151 BUG(); \
1152 } \
1153} while(0)
1154
1155#define ASSERTIFCMP(C, X, OP, Y) \
1156do { \
1157 if (unlikely((C) && !((X) OP (Y)))) { \
1158 printk(KERN_ERR "\n"); \
1159 printk(KERN_ERR "AFS: Assertion failed\n"); \
1160 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1161 (unsigned long)(X), (unsigned long)(Y)); \
1162 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1163 (unsigned long)(X), (unsigned long)(Y)); \
1164 BUG(); \
1165 } \
1166} while(0)
1167
1168#else
1169
1170#define ASSERT(X) \
1171do { \
1172} while(0)
1173
1174#define ASSERTCMP(X, OP, Y) \
1175do { \
1176} while(0)
1177
David Howells416351f2007-05-09 02:33:45 -07001178#define ASSERTRANGE(L, OP1, N, OP2, H) \
1179do { \
1180} while(0)
1181
David Howells08e0e7c2007-04-26 15:55:03 -07001182#define ASSERTIF(C, X) \
1183do { \
1184} while(0)
1185
1186#define ASSERTIFCMP(C, X, OP, Y) \
1187do { \
1188} while(0)
1189
1190#endif /* __KDEBUGALL */