blob: a6a1d75eee4148f95966d9a8c4d9b7b9b207582b [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 Howells31143d52007-05-09 02:33:46 -0700125 afs_dataversion_t store_version; /* updated version expected from store */
David Howells08e0e7c2007-04-26 15:55:03 -0700126};
127
128struct afs_call_type {
David Howells00d3b7a2007-04-26 15:57:07 -0700129 const char *name;
David Howells025db802017-11-02 15:27:51 +0000130 unsigned int op; /* Really enum afs_fs_operation */
David Howells00d3b7a2007-04-26 15:57:07 -0700131
David Howells08e0e7c2007-04-26 15:55:03 -0700132 /* deliver request or reply data to an call
133 * - returning an error will cause the call to be aborted
134 */
David Howellsd0016482016-08-30 20:42:14 +0100135 int (*deliver)(struct afs_call *call);
David Howells08e0e7c2007-04-26 15:55:03 -0700136
David Howells08e0e7c2007-04-26 15:55:03 -0700137 /* clean up a call */
138 void (*destructor)(struct afs_call *call);
David Howells341f7412017-01-05 10:38:36 +0000139
140 /* Work function */
141 void (*work)(struct work_struct *work);
David Howells08e0e7c2007-04-26 15:55:03 -0700142};
143
144/*
David Howells4343d002017-11-02 15:27:52 +0000145 * Key available for writeback on a file.
146 */
147struct afs_wb_key {
148 refcount_t usage;
149 struct key *key;
150 struct list_head vnode_link; /* Link in vnode->wb_keys */
151};
152
153/*
David Howells215804a2017-11-02 15:27:52 +0000154 * AFS open file information record. Pointed to by file->private_data.
155 */
156struct afs_file {
157 struct key *key; /* The key this file was opened with */
David Howells4343d002017-11-02 15:27:52 +0000158 struct afs_wb_key *wb; /* Writeback key record for this file */
David Howells215804a2017-11-02 15:27:52 +0000159};
160
161static inline struct key *afs_file_key(struct file *file)
162{
163 struct afs_file *af = file->private_data;
164
165 return af->key;
166}
167
168/*
David Howells196ee9c2017-01-05 10:38:34 +0000169 * Record of an outstanding read operation on a vnode.
170 */
171struct afs_read {
172 loff_t pos; /* Where to start reading */
David Howellse8e581a2017-03-16 16:27:44 +0000173 loff_t len; /* How much we're asking for */
David Howells196ee9c2017-01-05 10:38:34 +0000174 loff_t actual_len; /* How much we're actually getting */
David Howells6a0e3992017-03-16 16:27:46 +0000175 loff_t remain; /* Amount remaining */
David Howells196ee9c2017-01-05 10:38:34 +0000176 atomic_t usage;
David Howells196ee9c2017-01-05 10:38:34 +0000177 unsigned int index; /* Which page we're reading into */
David Howells196ee9c2017-01-05 10:38:34 +0000178 unsigned int nr_pages;
179 void (*page_done)(struct afs_call *, struct afs_read *);
180 struct page *pages[];
181};
182
183/*
David Howells08e0e7c2007-04-26 15:55:03 -0700184 * AFS superblock private data
185 * - there's one superblock per volume
186 */
187struct afs_super_info {
David Howellsf044c882017-11-02 15:27:45 +0000188 struct afs_net *net; /* Network namespace */
David Howells49566f62017-11-02 15:27:46 +0000189 struct afs_cell *cell; /* The cell in which the volume resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700190 struct afs_volume *volume; /* volume record */
David Howells4d673da2018-02-06 06:26:30 +0000191 bool dyn_root; /* True if dynamic root */
David Howells08e0e7c2007-04-26 15:55:03 -0700192};
193
194static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
195{
196 return sb->s_fs_info;
197}
198
199extern struct file_system_type afs_fs_type;
200
201/*
David Howellsf044c882017-11-02 15:27:45 +0000202 * AFS network namespace record.
203 */
204struct afs_net {
205 struct afs_uuid uuid;
206 bool live; /* F if this namespace is being removed */
207
208 /* AF_RXRPC I/O stuff */
209 struct socket *socket;
210 struct afs_call *spare_incoming_call;
211 struct work_struct charge_preallocation_work;
212 struct mutex socket_mutex;
213 atomic_t nr_outstanding_calls;
214 atomic_t nr_superblocks;
215
216 /* Cell database */
David Howells989782d2017-11-02 15:27:50 +0000217 struct rb_root cells;
David Howellsf044c882017-11-02 15:27:45 +0000218 struct afs_cell *ws_cell;
David Howells989782d2017-11-02 15:27:50 +0000219 struct work_struct cells_manager;
220 struct timer_list cells_timer;
221 atomic_t cells_outstanding;
222 seqlock_t cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000223
David Howells989782d2017-11-02 15:27:50 +0000224 spinlock_t proc_cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000225 struct list_head proc_cells;
226
David Howellsd2ddc772017-11-02 15:27:50 +0000227 /* Known servers. Theoretically each fileserver can only be in one
228 * cell, but in practice, people create aliases and subsets and there's
229 * no easy way to distinguish them.
230 */
231 seqlock_t fs_lock; /* For fs_servers */
232 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
233 struct list_head fs_updates; /* afs_server (by update_at) */
234 struct hlist_head fs_proc; /* procfs servers list */
235
236 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
237 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
238 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
239
240 struct work_struct fs_manager;
241 struct timer_list fs_timer;
242 atomic_t servers_outstanding;
David Howellsf044c882017-11-02 15:27:45 +0000243
244 /* File locking renewal management */
245 struct mutex lock_manager_mutex;
246
David Howellsf044c882017-11-02 15:27:45 +0000247 /* Misc */
248 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
249};
250
251extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
252
David Howells989782d2017-11-02 15:27:50 +0000253enum afs_cell_state {
254 AFS_CELL_UNSET,
255 AFS_CELL_ACTIVATING,
256 AFS_CELL_ACTIVE,
257 AFS_CELL_DEACTIVATING,
258 AFS_CELL_INACTIVE,
259 AFS_CELL_FAILED,
260};
261
David Howellsf044c882017-11-02 15:27:45 +0000262/*
David Howellsd2ddc772017-11-02 15:27:50 +0000263 * AFS cell record.
264 *
265 * This is a tricky concept to get right as it is possible to create aliases
266 * simply by pointing AFSDB/SRV records for two names at the same set of VL
267 * servers; it is also possible to do things like setting up two sets of VL
268 * servers, one of which provides a superset of the volumes provided by the
269 * other (for internal/external division, for example).
270 *
271 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
272 * servers and (b) a cell's name is used by the client to select the key to use
273 * for authentication and encryption. The cell name is not typically used in
274 * the protocol.
275 *
276 * There is no easy way to determine if two cells are aliases or one is a
277 * subset of another.
David Howells08e0e7c2007-04-26 15:55:03 -0700278 */
279struct afs_cell {
David Howells989782d2017-11-02 15:27:50 +0000280 union {
281 struct rcu_head rcu;
282 struct rb_node net_node; /* Node in net->cells */
283 };
284 struct afs_net *net;
David Howells00d3b7a2007-04-26 15:57:07 -0700285 struct key *anonymous_key; /* anonymous user key for this cell */
David Howells989782d2017-11-02 15:27:50 +0000286 struct work_struct manager; /* Manager for init/deinit/dns */
David Howells08e0e7c2007-04-26 15:55:03 -0700287 struct list_head proc_link; /* /proc cell list link */
David Howells9b3f26c2009-04-03 16:42:41 +0100288#ifdef CONFIG_AFS_FSCACHE
289 struct fscache_cookie *cache; /* caching cookie */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290#endif
David Howells989782d2017-11-02 15:27:50 +0000291 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
292 time64_t last_inactive; /* Time of last drop of usage count */
293 atomic_t usage;
294 unsigned long flags;
295#define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
296#define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
297#define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
298#define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
David Howells8b2a4642017-11-02 15:27:50 +0000299#define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
David Howells989782d2017-11-02 15:27:50 +0000300 enum afs_cell_state state;
301 short error;
302
David Howellsd2ddc772017-11-02 15:27:50 +0000303 /* Active fileserver interaction state. */
304 struct list_head proc_volumes; /* procfs volume list */
305 rwlock_t proc_lock;
David Howells989782d2017-11-02 15:27:50 +0000306
David Howellsd2ddc772017-11-02 15:27:50 +0000307 /* VL server list. */
David Howells8b2a4642017-11-02 15:27:50 +0000308 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
309 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
David Howells989782d2017-11-02 15:27:50 +0000310 u8 name_len; /* Length of name */
311 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
David Howells08e0e7c2007-04-26 15:55:03 -0700312};
313
314/*
David Howellsd2ddc772017-11-02 15:27:50 +0000315 * Cached VLDB entry.
316 *
317 * This is pointed to by cell->vldb_entries, indexed by name.
David Howells08e0e7c2007-04-26 15:55:03 -0700318 */
David Howellsd2ddc772017-11-02 15:27:50 +0000319struct afs_vldb_entry {
320 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
David Howells00d3b7a2007-04-26 15:57:07 -0700321
David Howellsd2ddc772017-11-02 15:27:50 +0000322 unsigned long flags;
323#define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
324#define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
325#define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
326#define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
327#define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
328
329 uuid_t fs_server[AFS_NMAXNSERVERS];
330 u8 fs_mask[AFS_NMAXNSERVERS];
David Howells08e0e7c2007-04-26 15:55:03 -0700331#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
332#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
333#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
David Howellsd2ddc772017-11-02 15:27:50 +0000334 short error;
335 u8 nr_servers; /* Number of server records */
336 u8 name_len;
337 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700338};
339
340/*
David Howellsd2ddc772017-11-02 15:27:50 +0000341 * Record of fileserver with which we're actively communicating.
David Howells08e0e7c2007-04-26 15:55:03 -0700342 */
343struct afs_server {
David Howellsd2ddc772017-11-02 15:27:50 +0000344 struct rcu_head rcu;
345 union {
346 uuid_t uuid; /* Server ID */
347 struct afs_uuid _uuid;
348 };
David Howellsc435ee32017-11-02 15:27:49 +0000349
David Howellsd2ddc772017-11-02 15:27:50 +0000350 struct afs_addr_list __rcu *addresses;
351 struct rb_node uuid_rb; /* Link in net->servers */
352 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
353 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
354 struct hlist_node proc_link; /* Link in net->fs_proc */
355 struct afs_server *gc_next; /* Next server in manager's list */
356 time64_t put_time; /* Time at which last put */
357 time64_t update_at; /* Time at which to next update the record */
David Howellsc435ee32017-11-02 15:27:49 +0000358 unsigned long flags;
David Howellsd2ddc772017-11-02 15:27:50 +0000359#define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
360#define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
361#define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
362#define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
363#define AFS_SERVER_FL_UPDATING 4
364#define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
365#define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
366 atomic_t usage;
367 u32 addr_version; /* Address list version */
David Howells08e0e7c2007-04-26 15:55:03 -0700368
369 /* file service access */
David Howellsd2ddc772017-11-02 15:27:50 +0000370 rwlock_t fs_lock; /* access lock */
David Howells08e0e7c2007-04-26 15:55:03 -0700371
372 /* callback promise management */
David Howellsc435ee32017-11-02 15:27:49 +0000373 struct list_head cb_interests; /* List of superblocks using this server */
374 unsigned cb_s_break; /* Break-everything counter. */
375 rwlock_t cb_break_lock; /* Volume finding lock */
376};
377
378/*
379 * Interest by a superblock on a server.
380 */
381struct afs_cb_interest {
382 struct list_head cb_link; /* Link in server->cb_interests */
383 struct afs_server *server; /* Server on which this interest resides */
384 struct super_block *sb; /* Superblock on which inodes reside */
385 afs_volid_t vid; /* Volume ID to match */
386 refcount_t usage;
David Howells08e0e7c2007-04-26 15:55:03 -0700387};
388
389/*
David Howellsd2ddc772017-11-02 15:27:50 +0000390 * Replaceable server list.
David Howells08e0e7c2007-04-26 15:55:03 -0700391 */
David Howellsd2ddc772017-11-02 15:27:50 +0000392struct afs_server_entry {
393 struct afs_server *server;
394 struct afs_cb_interest *cb_interest;
395};
396
397struct afs_server_list {
398 refcount_t usage;
399 unsigned short nr_servers;
400 unsigned short index; /* Server currently in use */
401 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
402 unsigned int seq; /* Set to ->servers_seq when installed */
403 struct afs_server_entry servers[];
David Howells08e0e7c2007-04-26 15:55:03 -0700404};
405
406/*
David Howellsd2ddc772017-11-02 15:27:50 +0000407 * Live AFS volume management.
David Howells08e0e7c2007-04-26 15:55:03 -0700408 */
David Howellsd2ddc772017-11-02 15:27:50 +0000409struct afs_volume {
410 afs_volid_t vid; /* volume ID */
411 atomic_t usage;
412 time64_t update_at; /* Time at which to next update */
413 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
414 struct list_head proc_link; /* Link in cell->vl_proc */
415 unsigned long flags;
416#define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
417#define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
418#define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
419#define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
420#define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
421#define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
422#ifdef CONFIG_AFS_FSCACHE
423 struct fscache_cookie *cache; /* caching cookie */
424#endif
425 struct afs_server_list *servers; /* List of servers on which volume resides */
426 rwlock_t servers_lock; /* Lock for ->servers */
427 unsigned int servers_seq; /* Incremented each time ->servers changes */
428
429 afs_voltype_t type; /* type of volume */
430 short error;
431 char type_force; /* force volume type (suppress R/O -> R/W) */
432 u8 name_len;
433 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700434};
435
David Howells0fafdc92017-11-13 16:59:50 +0000436enum afs_lock_state {
437 AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
438 AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
439 AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
440 AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
441 AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
442 AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
443 AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
444};
445
David Howells08e0e7c2007-04-26 15:55:03 -0700446/*
David Howellsf8de4832017-12-01 11:40:43 +0000447 * AFS inode private data.
448 *
449 * Note that afs_alloc_inode() *must* reset anything that could incorrectly
450 * leak from one inode to another.
David Howells08e0e7c2007-04-26 15:55:03 -0700451 */
452struct afs_vnode {
453 struct inode vfs_inode; /* the VFS's inode record */
454
455 struct afs_volume *volume; /* volume on which vnode resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700456 struct afs_fid fid; /* the file identifier for this inode */
457 struct afs_file_status status; /* AFS status info for this file */
David Howells9b3f26c2009-04-03 16:42:41 +0100458#ifdef CONFIG_AFS_FSCACHE
459 struct fscache_cookie *cache; /* caching cookie */
David Howells08e0e7c2007-04-26 15:55:03 -0700460#endif
David Howellsbe080a62017-11-02 15:27:49 +0000461 struct afs_permits *permit_cache; /* cache of permits so far obtained */
David Howellsd2ddc772017-11-02 15:27:50 +0000462 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
David Howells260a9802007-04-26 15:59:35 -0700463 struct mutex validate_lock; /* lock for validating this vnode */
David Howells4343d002017-11-02 15:27:52 +0000464 spinlock_t wb_lock; /* lock for wb_keys */
David Howells08e0e7c2007-04-26 15:55:03 -0700465 spinlock_t lock; /* waitqueue/flags lock */
466 unsigned long flags;
David Howellsc435ee32017-11-02 15:27:49 +0000467#define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
David Howells260a9802007-04-26 15:59:35 -0700468#define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
David Howellsc435ee32017-11-02 15:27:49 +0000469#define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */
David Howells08e0e7c2007-04-26 15:55:03 -0700470#define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
471#define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
472#define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
David Howells0fafdc92017-11-13 16:59:50 +0000473#define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
474#define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
David Howells08e0e7c2007-04-26 15:55:03 -0700475
David Howells4343d002017-11-02 15:27:52 +0000476 struct list_head wb_keys; /* List of keys available for writeback */
David Howellse8d6c552007-07-15 23:40:12 -0700477 struct list_head pending_locks; /* locks waiting to be granted */
478 struct list_head granted_locks; /* locks granted on this file */
479 struct delayed_work lock_work; /* work to be done in locking */
David Howells0fafdc92017-11-13 16:59:50 +0000480 struct key *lock_key; /* Key to be used in lock ops */
481 enum afs_lock_state lock_state : 8;
482 afs_lock_type_t lock_type : 8;
David Howells31143d52007-05-09 02:33:46 -0700483
David Howells08e0e7c2007-04-26 15:55:03 -0700484 /* outstanding callback notification on this file */
David Howellsc435ee32017-11-02 15:27:49 +0000485 struct afs_cb_interest *cb_interest; /* Server on which this resides */
486 unsigned int cb_s_break; /* Mass break counter on ->server */
487 unsigned int cb_break; /* Break counter on vnode */
488 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
489
490 time64_t cb_expires_at; /* time at which callback expires */
David Howells08e0e7c2007-04-26 15:55:03 -0700491 unsigned cb_version; /* callback version */
David Howells08e0e7c2007-04-26 15:55:03 -0700492 afs_callback_type_t cb_type; /* type of callback */
David Howells08e0e7c2007-04-26 15:55:03 -0700493};
494
David Howells00d3b7a2007-04-26 15:57:07 -0700495/*
496 * cached security record for one user's attempt to access a vnode
497 */
498struct afs_permit {
499 struct key *key; /* RxRPC ticket holding a security context */
David Howellsbe080a62017-11-02 15:27:49 +0000500 afs_access_t access; /* CallerAccess value for this key */
David Howells00d3b7a2007-04-26 15:57:07 -0700501};
502
503/*
David Howellsbe080a62017-11-02 15:27:49 +0000504 * Immutable cache of CallerAccess records from attempts to access vnodes.
505 * These may be shared between multiple vnodes.
David Howells00d3b7a2007-04-26 15:57:07 -0700506 */
507struct afs_permits {
David Howellsbe080a62017-11-02 15:27:49 +0000508 struct rcu_head rcu;
509 struct hlist_node hash_node; /* Link in hash */
510 unsigned long h; /* Hash value for this permit list */
511 refcount_t usage;
512 unsigned short nr_permits; /* Number of records */
513 bool invalidated; /* Invalidated due to key change */
514 struct afs_permit permits[]; /* List of permits sorted by key pointer */
David Howells00d3b7a2007-04-26 15:57:07 -0700515};
516
David Howellsb908fe62007-04-26 15:58:17 -0700517/*
518 * record of one of a system's set of network interfaces
519 */
520struct afs_interface {
David Howellsb908fe62007-04-26 15:58:17 -0700521 struct in_addr address; /* IPv4 address bound to interface */
522 struct in_addr netmask; /* netmask applied to address */
523 unsigned mtu; /* MTU of interface */
524};
525
David Howells8b2a4642017-11-02 15:27:50 +0000526/*
527 * Cursor for iterating over a server's address list.
528 */
529struct afs_addr_cursor {
530 struct afs_addr_list *alist; /* Current address list (pins ref) */
531 struct sockaddr_rxrpc *addr;
David Howellsd2ddc772017-11-02 15:27:50 +0000532 u32 abort_code;
David Howells8b2a4642017-11-02 15:27:50 +0000533 unsigned short start; /* Starting point in alist->addrs[] */
534 unsigned short index; /* Wrapping offset from start to current addr */
535 short error;
536 bool begun; /* T if we've begun iteration */
537 bool responded; /* T if the current address responded */
538};
539
540/*
541 * Cursor for iterating over a set of fileservers.
542 */
543struct afs_fs_cursor {
544 struct afs_addr_cursor ac;
David Howellsd2ddc772017-11-02 15:27:50 +0000545 struct afs_vnode *vnode;
546 struct afs_server_list *server_list; /* Current server list (pins ref) */
547 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
548 struct key *key; /* Key for the server */
549 unsigned int cb_break; /* cb_break + cb_s_break before the call */
550 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
551 unsigned char start; /* Initial index in server list */
552 unsigned char index; /* Number of servers tried beyond start */
553 unsigned short flags;
554#define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
555#define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
556#define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
557#define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
558#define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
559#define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
David Howells8b2a4642017-11-02 15:27:50 +0000560};
561
David Howells402cb8d2018-04-04 13:41:28 +0100562/*
563 * Cache auxiliary data.
564 */
565struct afs_vnode_cache_aux {
566 u64 data_version;
567} __packed;
568
David Howells98bf40c2017-11-02 15:27:53 +0000569#include <trace/events/afs.h>
570
David Howells08e0e7c2007-04-26 15:55:03 -0700571/*****************************************************************************/
572/*
David Howells8b2a4642017-11-02 15:27:50 +0000573 * addr_list.c
574 */
575static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
576{
577 if (alist)
578 refcount_inc(&alist->usage);
579 return alist;
580}
581extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
582 unsigned short,
583 unsigned short);
584extern void afs_put_addrlist(struct afs_addr_list *);
585extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
586 unsigned short, unsigned short);
587extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
588extern bool afs_iterate_addresses(struct afs_addr_cursor *);
589extern int afs_end_cursor(struct afs_addr_cursor *);
590extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
591
David Howellsbf99a532017-11-02 15:27:51 +0000592extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
593extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
David Howellsd2ddc772017-11-02 15:27:50 +0000594
David Howells8b2a4642017-11-02 15:27:50 +0000595/*
David Howells9b3f26c2009-04-03 16:42:41 +0100596 * cache.c
597 */
598#ifdef CONFIG_AFS_FSCACHE
599extern struct fscache_netfs afs_cache_netfs;
600extern struct fscache_cookie_def afs_cell_cache_index_def;
David Howells9b3f26c2009-04-03 16:42:41 +0100601extern struct fscache_cookie_def afs_volume_cache_index_def;
602extern struct fscache_cookie_def afs_vnode_cache_index_def;
603#else
604#define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
David Howells9b3f26c2009-04-03 16:42:41 +0100605#define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
606#define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
607#endif
608
609/*
David Howells08e0e7c2007-04-26 15:55:03 -0700610 * callback.c
611 */
612extern void afs_init_callback_state(struct afs_server *);
David Howellsc435ee32017-11-02 15:27:49 +0000613extern void afs_break_callback(struct afs_vnode *);
614extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]);
615
David Howellsd2ddc772017-11-02 15:27:50 +0000616extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
David Howellsc435ee32017-11-02 15:27:49 +0000617extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
David Howellsd2ddc772017-11-02 15:27:50 +0000618extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
David Howellsc435ee32017-11-02 15:27:49 +0000619
620static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
621{
622 refcount_inc(&cbi->usage);
623 return cbi;
624}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626/*
627 * cell.c
628 */
David Howells989782d2017-11-02 15:27:50 +0000629extern int afs_cell_init(struct afs_net *, const char *);
630extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
631extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
632 const char *, bool);
David Howells8b2a4642017-11-02 15:27:50 +0000633extern struct afs_cell *afs_get_cell(struct afs_cell *);
David Howells9ed900b2017-11-02 15:27:46 +0000634extern void afs_put_cell(struct afs_net *, struct afs_cell *);
David Howells989782d2017-11-02 15:27:50 +0000635extern void afs_manage_cells(struct work_struct *);
636extern void afs_cells_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000637extern void __net_exit afs_cell_purge(struct afs_net *);
David Howells08e0e7c2007-04-26 15:55:03 -0700638
639/*
640 * cmservice.c
641 */
642extern bool afs_cm_incoming_call(struct afs_call *);
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644/*
645 * dir.c
646 */
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800647extern const struct file_operations afs_dir_file_operations;
David Howells4d673da2018-02-06 06:26:30 +0000648extern const struct inode_operations afs_dir_inode_operations;
649extern const struct file_operations afs_dynroot_file_operations;
650extern const struct inode_operations afs_dynroot_inode_operations;
651extern const struct dentry_operations afs_fs_dentry_operations;
652
653extern bool afs_dir_check_page(struct inode *, struct page *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655/*
656 * file.c
657 */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700658extern const struct address_space_operations afs_fs_aops;
Arjan van de Ven754661f2007-02-12 00:55:38 -0800659extern const struct inode_operations afs_file_inode_operations;
David Howells00d3b7a2007-04-26 15:57:07 -0700660extern const struct file_operations afs_file_operations;
661
David Howells4343d002017-11-02 15:27:52 +0000662extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
663extern void afs_put_wb_key(struct afs_wb_key *);
David Howells00d3b7a2007-04-26 15:57:07 -0700664extern int afs_open(struct inode *, struct file *);
665extern int afs_release(struct inode *, struct file *);
David Howellsd2ddc772017-11-02 15:27:50 +0000666extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
Al Virof6d335c2010-05-21 15:27:09 +0100667extern int afs_page_filler(void *, struct page *);
David Howells196ee9c2017-01-05 10:38:34 +0000668extern void afs_put_read(struct afs_read *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/*
David Howellse8d6c552007-07-15 23:40:12 -0700671 * flock.c
672 */
David Howellsf044c882017-11-02 15:27:45 +0000673extern struct workqueue_struct *afs_lock_manager;
674
David Howellse8d6c552007-07-15 23:40:12 -0700675extern void afs_lock_work(struct work_struct *);
676extern void afs_lock_may_be_available(struct afs_vnode *);
677extern int afs_lock(struct file *, int, struct file_lock *);
678extern int afs_flock(struct file *, int, struct file_lock *);
679
680/*
David Howells08e0e7c2007-04-26 15:55:03 -0700681 * fsclient.c
682 */
David Howellsd2ddc772017-11-02 15:27:50 +0000683extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
684extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
685extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
686extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
687 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
688extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
689extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
690extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
691 struct afs_fid *, struct afs_file_status *);
692extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
693 struct afs_vnode *, const char *);
David Howells4343d002017-11-02 15:27:52 +0000694extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
David Howellsd2ddc772017-11-02 15:27:50 +0000695 pgoff_t, pgoff_t, unsigned, unsigned);
696extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
697extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
698extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
699extern int afs_fs_extend_lock(struct afs_fs_cursor *);
700extern int afs_fs_release_lock(struct afs_fs_cursor *);
701extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
702 struct afs_addr_cursor *, struct key *);
703extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
704 struct afs_addr_cursor *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700705
706/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 * inode.c
708 */
David Howellsd2ddc772017-11-02 15:27:50 +0000709extern int afs_fetch_status(struct afs_vnode *, struct key *);
David Howellsc435ee32017-11-02 15:27:49 +0000710extern int afs_iget5_test(struct inode *, void *);
David Howells4d673da2018-02-06 06:26:30 +0000711extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
David Howells00d3b7a2007-04-26 15:57:07 -0700712extern struct inode *afs_iget(struct super_block *, struct key *,
David Howells260a9802007-04-26 15:59:35 -0700713 struct afs_fid *, struct afs_file_status *,
David Howellsd2ddc772017-11-02 15:27:50 +0000714 struct afs_callback *,
715 struct afs_cb_interest *);
David Howells416351f2007-05-09 02:33:45 -0700716extern void afs_zap_data(struct afs_vnode *);
David Howells260a9802007-04-26 15:59:35 -0700717extern int afs_validate(struct afs_vnode *, struct key *);
David Howellsa528d352017-01-31 16:46:22 +0000718extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
David Howells31143d52007-05-09 02:33:46 -0700719extern int afs_setattr(struct dentry *, struct iattr *);
Al Virob57922d2010-06-07 14:34:48 -0400720extern void afs_evict_inode(struct inode *);
wangleibec5eb62010-08-11 09:38:04 +0100721extern int afs_drop_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723/*
724 * main.c
725 */
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000726extern struct workqueue_struct *afs_wq;
David Howellsf044c882017-11-02 15:27:45 +0000727
728static inline struct afs_net *afs_d2net(struct dentry *dentry)
729{
730 return &__afs_net;
731}
732
733static inline struct afs_net *afs_i2net(struct inode *inode)
734{
735 return &__afs_net;
736}
737
738static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
739{
740 return &__afs_net;
741}
742
743static inline struct afs_net *afs_sock2net(struct sock *sk)
744{
745 return &__afs_net;
746}
747
748static inline struct afs_net *afs_get_net(struct afs_net *net)
749{
750 return net;
751}
752
753static inline void afs_put_net(struct afs_net *net)
754{
755}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757/*
David Howells08e0e7c2007-04-26 15:55:03 -0700758 * misc.c
759 */
760extern int afs_abort_to_error(u32);
761
762/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 * mntpt.c
764 */
Arjan van de Ven754661f2007-02-12 00:55:38 -0800765extern const struct inode_operations afs_mntpt_inode_operations;
wangleibec5eb62010-08-11 09:38:04 +0100766extern const struct inode_operations afs_autocell_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800767extern const struct file_operations afs_mntpt_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
David Howellsd18610b2011-01-14 19:04:05 +0000769extern struct vfsmount *afs_d_automount(struct path *);
David Howells08e0e7c2007-04-26 15:55:03 -0700770extern void afs_mntpt_kill_timer(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772/*
Arnd Bergmannb4db2b32017-02-10 16:34:07 +0000773 * netdevices.c
774 */
775extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
776
777/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 * proc.c
779 */
David Howellsf044c882017-11-02 15:27:45 +0000780extern int __net_init afs_proc_init(struct afs_net *);
781extern void __net_exit afs_proc_cleanup(struct afs_net *);
782extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
783extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
David Howells08e0e7c2007-04-26 15:55:03 -0700785/*
David Howellsd2ddc772017-11-02 15:27:50 +0000786 * rotate.c
787 */
788extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
789 struct key *);
790extern bool afs_select_fileserver(struct afs_fs_cursor *);
791extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
792extern int afs_end_vnode_operation(struct afs_fs_cursor *);
793
794/*
David Howells08e0e7c2007-04-26 15:55:03 -0700795 * rxrpc.c
796 */
David Howellsf044c882017-11-02 15:27:45 +0000797extern struct workqueue_struct *afs_async_calls;
David Howells8324f0b2016-08-30 09:49:29 +0100798
David Howellsf044c882017-11-02 15:27:45 +0000799extern int __net_init afs_open_socket(struct afs_net *);
800extern void __net_exit afs_close_socket(struct afs_net *);
801extern void afs_charge_preallocation(struct work_struct *);
David Howells341f7412017-01-05 10:38:36 +0000802extern void afs_put_call(struct afs_call *);
803extern int afs_queue_call_work(struct afs_call *);
David Howells8b2a4642017-11-02 15:27:50 +0000804extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
David Howellsf044c882017-11-02 15:27:45 +0000805extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
806 const struct afs_call_type *,
David Howells08e0e7c2007-04-26 15:55:03 -0700807 size_t, size_t);
808extern void afs_flat_call_destructor(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -0700809extern void afs_send_empty_reply(struct afs_call *);
David Howellsb908fe62007-04-26 15:58:17 -0700810extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
David Howellsd0016482016-08-30 20:42:14 +0100811extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
David Howells08e0e7c2007-04-26 15:55:03 -0700812
David Howellsd0016482016-08-30 20:42:14 +0100813static inline int afs_transfer_reply(struct afs_call *call)
David Howells372ee162016-08-03 14:11:40 +0100814{
David Howellsd0016482016-08-30 20:42:14 +0100815 return afs_extract_data(call, call->buffer, call->reply_max, false);
David Howells372ee162016-08-03 14:11:40 +0100816}
817
David Howells98bf40c2017-11-02 15:27:53 +0000818static inline bool afs_check_call_state(struct afs_call *call,
819 enum afs_call_state state)
820{
821 return READ_ONCE(call->state) == state;
822}
823
824static inline bool afs_set_call_state(struct afs_call *call,
825 enum afs_call_state from,
826 enum afs_call_state to)
827{
828 bool ok = false;
829
830 spin_lock_bh(&call->state_lock);
831 if (call->state == from) {
832 call->state = to;
833 trace_afs_call_state(call, from, to, 0, 0);
834 ok = true;
835 }
836 spin_unlock_bh(&call->state_lock);
837 return ok;
838}
839
840static inline void afs_set_call_complete(struct afs_call *call,
841 int error, u32 remote_abort)
842{
843 enum afs_call_state state;
844 bool ok = false;
845
846 spin_lock_bh(&call->state_lock);
847 state = call->state;
848 if (state != AFS_CALL_COMPLETE) {
849 call->abort_code = remote_abort;
850 call->error = error;
851 call->state = AFS_CALL_COMPLETE;
852 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
853 error, remote_abort);
854 ok = true;
855 }
856 spin_unlock_bh(&call->state_lock);
857 if (ok)
858 trace_afs_call_done(call);
859}
860
David Howells08e0e7c2007-04-26 15:55:03 -0700861/*
David Howells00d3b7a2007-04-26 15:57:07 -0700862 * security.c
863 */
David Howellsbe080a62017-11-02 15:27:49 +0000864extern void afs_put_permits(struct afs_permits *);
David Howells00d3b7a2007-04-26 15:57:07 -0700865extern void afs_clear_permits(struct afs_vnode *);
David Howellsbe080a62017-11-02 15:27:49 +0000866extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
David Howells416351f2007-05-09 02:33:45 -0700867extern void afs_zap_permits(struct rcu_head *);
David Howells00d3b7a2007-04-26 15:57:07 -0700868extern struct key *afs_request_key(struct afs_cell *);
David Howells0fafdc92017-11-13 16:59:50 +0000869extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
Al Viro10556cb2011-06-20 19:28:19 -0400870extern int afs_permission(struct inode *, int);
David Howellsbe080a62017-11-02 15:27:49 +0000871extern void __exit afs_clean_up_permit_cache(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700872
873/*
David Howells08e0e7c2007-04-26 15:55:03 -0700874 * server.c
875 */
876extern spinlock_t afs_server_peer_lock;
877
David Howellsc435ee32017-11-02 15:27:49 +0000878static inline struct afs_server *afs_get_server(struct afs_server *server)
879{
880 atomic_inc(&server->usage);
881 return server;
882}
David Howells08e0e7c2007-04-26 15:55:03 -0700883
David Howellsf044c882017-11-02 15:27:45 +0000884extern struct afs_server *afs_find_server(struct afs_net *,
885 const struct sockaddr_rxrpc *);
David Howellsd2ddc772017-11-02 15:27:50 +0000886extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
887extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
David Howells9ed900b2017-11-02 15:27:46 +0000888extern void afs_put_server(struct afs_net *, struct afs_server *);
David Howellsd2ddc772017-11-02 15:27:50 +0000889extern void afs_manage_servers(struct work_struct *);
890extern void afs_servers_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000891extern void __net_exit afs_purge_servers(struct afs_net *);
David Howellsd2ddc772017-11-02 15:27:50 +0000892extern bool afs_probe_fileserver(struct afs_fs_cursor *);
893extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
894
895/*
896 * server_list.c
897 */
898static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
899{
900 refcount_inc(&slist->usage);
901 return slist;
902}
903
904extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
905extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
906 struct afs_vldb_entry *,
907 u8);
908extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
David Howells08e0e7c2007-04-26 15:55:03 -0700909
910/*
David Howells00d3b7a2007-04-26 15:57:07 -0700911 * super.c
912 */
David Howellsf044c882017-11-02 15:27:45 +0000913extern int __init afs_fs_init(void);
914extern void __exit afs_fs_exit(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700915
916/*
David Howells08e0e7c2007-04-26 15:55:03 -0700917 * vlclient.c
918 */
David Howellsd2ddc772017-11-02 15:27:50 +0000919extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
920 struct afs_addr_cursor *,
921 struct key *, const char *, int);
922extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
923 struct key *, const uuid_t *);
David Howellsbf99a532017-11-02 15:27:51 +0000924extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
925extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
926 struct key *, const uuid_t *);
David Howells08e0e7c2007-04-26 15:55:03 -0700927
928/*
929 * volume.c
930 */
David Howellsd2ddc772017-11-02 15:27:50 +0000931static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
David Howells49566f62017-11-02 15:27:46 +0000932{
933 if (volume)
934 atomic_inc(&volume->usage);
935 return volume;
936}
David Howells08e0e7c2007-04-26 15:55:03 -0700937
David Howellsd2ddc772017-11-02 15:27:50 +0000938extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
939extern void afs_activate_volume(struct afs_volume *);
940extern void afs_deactivate_volume(struct afs_volume *);
David Howells9ed900b2017-11-02 15:27:46 +0000941extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
David Howellsd2ddc772017-11-02 15:27:50 +0000942extern int afs_check_volume_status(struct afs_volume *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700943
David Howells31143d52007-05-09 02:33:46 -0700944/*
945 * write.c
946 */
947extern int afs_set_page_dirty(struct page *);
Nick Piggin15b46502008-10-15 22:04:32 -0700948extern int afs_write_begin(struct file *file, struct address_space *mapping,
949 loff_t pos, unsigned len, unsigned flags,
950 struct page **pagep, void **fsdata);
951extern int afs_write_end(struct file *file, struct address_space *mapping,
952 loff_t pos, unsigned len, unsigned copied,
953 struct page *page, void *fsdata);
David Howells31143d52007-05-09 02:33:46 -0700954extern int afs_writepage(struct page *, struct writeback_control *);
955extern int afs_writepages(struct address_space *, struct writeback_control *);
David Howells31143d52007-05-09 02:33:46 -0700956extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
Al Viro50b55512014-04-03 14:13:46 -0400957extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
David Howells58fed942017-03-16 16:27:45 +0000958extern int afs_flush(struct file *, fl_owner_t);
Josef Bacik02c24a82011-07-16 20:44:56 -0400959extern int afs_fsync(struct file *, loff_t, loff_t, int);
David Howells1cf7a152017-11-02 15:27:52 +0000960extern int afs_page_mkwrite(struct vm_fault *);
David Howells4343d002017-11-02 15:27:52 +0000961extern void afs_prune_wb_keys(struct afs_vnode *);
962extern int afs_launder_page(struct page *);
David Howells31143d52007-05-09 02:33:46 -0700963
David Howellsd3e3b7ea2017-07-06 15:50:27 +0100964/*
965 * xattr.c
966 */
967extern const struct xattr_handler *afs_xattr_handlers[];
968extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
David Howells31143d52007-05-09 02:33:46 -0700969
David Howellsd2ddc772017-11-02 15:27:50 +0000970
971/*
972 * Miscellaneous inline functions.
973 */
974static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
975{
976 return container_of(inode, struct afs_vnode, vfs_inode);
977}
978
979static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
980{
981 return &vnode->vfs_inode;
982}
983
984static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
985 struct afs_vnode *vnode,
986 unsigned int cb_break)
987{
988 if (fc->ac.error == 0)
989 afs_cache_permit(vnode, fc->key, cb_break);
990}
991
992static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
993 struct afs_vnode *vnode)
994{
995 if (fc->ac.error == -ENOENT) {
996 set_bit(AFS_VNODE_DELETED, &vnode->flags);
997 afs_break_callback(vnode);
998 }
999}
1000
1001
David Howells08e0e7c2007-04-26 15:55:03 -07001002/*****************************************************************************/
1003/*
1004 * debug tracing
1005 */
1006extern unsigned afs_debug;
1007
1008#define dbgprintk(FMT,...) \
Sven Schnellead16df82008-04-03 10:44:01 +01001009 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -07001010
Harvey Harrison530b6412008-04-30 00:55:09 -07001011#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1012#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -07001013#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1014
1015
1016#if defined(__KDEBUG)
1017#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1018#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1019#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1020
1021#elif defined(CONFIG_AFS_DEBUG)
1022#define AFS_DEBUG_KENTER 0x01
1023#define AFS_DEBUG_KLEAVE 0x02
1024#define AFS_DEBUG_KDEBUG 0x04
1025
1026#define _enter(FMT,...) \
1027do { \
1028 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
1029 kenter(FMT,##__VA_ARGS__); \
1030} while (0)
1031
1032#define _leave(FMT,...) \
1033do { \
1034 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
1035 kleave(FMT,##__VA_ARGS__); \
1036} while (0)
1037
1038#define _debug(FMT,...) \
1039do { \
1040 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
1041 kdebug(FMT,##__VA_ARGS__); \
1042} while (0)
1043
1044#else
David Howells12fdff32010-08-12 16:54:57 +01001045#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1046#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1047#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -07001048#endif
1049
1050/*
1051 * debug assertion checking
1052 */
1053#if 1 // defined(__KDEBUGALL)
1054
1055#define ASSERT(X) \
1056do { \
1057 if (unlikely(!(X))) { \
1058 printk(KERN_ERR "\n"); \
1059 printk(KERN_ERR "AFS: Assertion failed\n"); \
1060 BUG(); \
1061 } \
1062} while(0)
1063
1064#define ASSERTCMP(X, OP, Y) \
1065do { \
1066 if (unlikely(!((X) OP (Y)))) { \
1067 printk(KERN_ERR "\n"); \
1068 printk(KERN_ERR "AFS: Assertion failed\n"); \
1069 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1070 (unsigned long)(X), (unsigned long)(Y)); \
1071 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1072 (unsigned long)(X), (unsigned long)(Y)); \
1073 BUG(); \
1074 } \
1075} while(0)
1076
David Howells416351f2007-05-09 02:33:45 -07001077#define ASSERTRANGE(L, OP1, N, OP2, H) \
1078do { \
1079 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1080 printk(KERN_ERR "\n"); \
1081 printk(KERN_ERR "AFS: Assertion failed\n"); \
1082 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1083 (unsigned long)(L), (unsigned long)(N), \
1084 (unsigned long)(H)); \
1085 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1086 (unsigned long)(L), (unsigned long)(N), \
1087 (unsigned long)(H)); \
1088 BUG(); \
1089 } \
1090} while(0)
1091
David Howells08e0e7c2007-04-26 15:55:03 -07001092#define ASSERTIF(C, X) \
1093do { \
1094 if (unlikely((C) && !(X))) { \
1095 printk(KERN_ERR "\n"); \
1096 printk(KERN_ERR "AFS: Assertion failed\n"); \
1097 BUG(); \
1098 } \
1099} while(0)
1100
1101#define ASSERTIFCMP(C, X, OP, Y) \
1102do { \
1103 if (unlikely((C) && !((X) OP (Y)))) { \
1104 printk(KERN_ERR "\n"); \
1105 printk(KERN_ERR "AFS: Assertion failed\n"); \
1106 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1107 (unsigned long)(X), (unsigned long)(Y)); \
1108 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1109 (unsigned long)(X), (unsigned long)(Y)); \
1110 BUG(); \
1111 } \
1112} while(0)
1113
1114#else
1115
1116#define ASSERT(X) \
1117do { \
1118} while(0)
1119
1120#define ASSERTCMP(X, OP, Y) \
1121do { \
1122} while(0)
1123
David Howells416351f2007-05-09 02:33:45 -07001124#define ASSERTRANGE(L, OP1, N, OP2, H) \
1125do { \
1126} while(0)
1127
David Howells08e0e7c2007-04-26 15:55:03 -07001128#define ASSERTIF(C, X) \
1129do { \
1130} while(0)
1131
1132#define ASSERTIFCMP(C, X, OP, Y) \
1133do { \
1134} while(0)
1135
1136#endif /* __KDEBUGALL */