blob: 688562ae3bf826850cef231dbac39586af641cf1 [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 Howells00d3b7a2007-04-26 15:57:07 -070039 afs_voltype_t type; /* type of volume requested */
40 int volnamesz; /* size of volume name */
41 const char *volname; /* name of volume to mount */
David Howellsf044c882017-11-02 15:27:45 +000042 struct afs_net *net; /* Network namespace in effect */
David Howells00d3b7a2007-04-26 15:57:07 -070043 struct afs_cell *cell; /* cell in which to find volume */
44 struct afs_volume *volume; /* volume record */
45 struct key *key; /* key to use for secure mounting */
46};
47
David Howellsc435ee32017-11-02 15:27:49 +000048struct afs_iget_data {
49 struct afs_fid fid;
50 struct afs_volume *volume; /* volume on which resides */
51};
52
David Howells8e8d7f12017-01-05 10:38:34 +000053enum afs_call_state {
54 AFS_CALL_REQUESTING, /* request is being sent for outgoing call */
55 AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */
56 AFS_CALL_AWAIT_OP_ID, /* awaiting op ID on incoming call */
57 AFS_CALL_AWAIT_REQUEST, /* awaiting request data on incoming call */
58 AFS_CALL_REPLYING, /* replying to incoming call */
59 AFS_CALL_AWAIT_ACK, /* awaiting final ACK of incoming call */
60 AFS_CALL_COMPLETE, /* Completed or failed */
61};
David Howellsf044c882017-11-02 15:27:45 +000062
David Howells08e0e7c2007-04-26 15:55:03 -070063/*
David Howells8b2a4642017-11-02 15:27:50 +000064 * List of server addresses.
65 */
66struct afs_addr_list {
67 struct rcu_head rcu; /* Must be first */
68 refcount_t usage;
David Howellsd2ddc772017-11-02 15:27:50 +000069 u32 version; /* Version */
David Howells8b2a4642017-11-02 15:27:50 +000070 unsigned short nr_addrs;
71 unsigned short index; /* Address currently in use */
David Howellsd2ddc772017-11-02 15:27:50 +000072 unsigned short nr_ipv4; /* Number of IPv4 addresses */
David Howellsbf99a532017-11-02 15:27:51 +000073 unsigned long probed; /* Mask of servers that have been probed */
74 unsigned long yfs; /* Mask of servers that are YFS */
David Howells8b2a4642017-11-02 15:27:50 +000075 struct sockaddr_rxrpc addrs[];
76};
77
78/*
David Howells08e0e7c2007-04-26 15:55:03 -070079 * a record of an in-progress RxRPC call
80 */
81struct afs_call {
82 const struct afs_call_type *type; /* type of call */
David Howells08e0e7c2007-04-26 15:55:03 -070083 wait_queue_head_t waitq; /* processes awaiting completion */
David Howells341f7412017-01-05 10:38:36 +000084 struct work_struct async_work; /* async I/O processor */
David Howells08e0e7c2007-04-26 15:55:03 -070085 struct work_struct work; /* actual work processor */
David Howells08e0e7c2007-04-26 15:55:03 -070086 struct rxrpc_call *rxcall; /* RxRPC call handle */
87 struct key *key; /* security for this call */
David Howellsf044c882017-11-02 15:27:45 +000088 struct afs_net *net; /* The network namespace */
David Howellsd0676a12017-11-02 15:27:49 +000089 struct afs_server *cm_server; /* Server affected by incoming CM call */
David Howellsd2ddc772017-11-02 15:27:50 +000090 struct afs_cb_interest *cbi; /* Callback interest for server used */
David Howells08e0e7c2007-04-26 15:55:03 -070091 void *request; /* request data (first part) */
David Howells4343d002017-11-02 15:27:52 +000092 struct address_space *mapping; /* Pages being written from */
David Howells08e0e7c2007-04-26 15:55:03 -070093 void *buffer; /* reply receive buffer */
David Howells97e30432017-11-02 15:27:48 +000094 void *reply[4]; /* Where to put the reply */
David Howells31143d52007-05-09 02:33:46 -070095 pgoff_t first; /* first page in mapping to deal with */
96 pgoff_t last; /* last page in mapping to deal with */
David Howellsd0016482016-08-30 20:42:14 +010097 size_t offset; /* offset into received data store */
David Howells341f7412017-01-05 10:38:36 +000098 atomic_t usage;
David Howells8e8d7f12017-01-05 10:38:34 +000099 enum afs_call_state state;
David Howells08e0e7c2007-04-26 15:55:03 -0700100 int error; /* error code */
David Howellsd0016482016-08-30 20:42:14 +0100101 u32 abort_code; /* Remote abort ID or 0 */
David Howells08e0e7c2007-04-26 15:55:03 -0700102 unsigned request_size; /* size of request data */
103 unsigned reply_max; /* maximum size of reply */
David Howells31143d52007-05-09 02:33:46 -0700104 unsigned first_offset; /* offset into mapping[first] */
David Howellsc435ee32017-11-02 15:27:49 +0000105 unsigned int cb_break; /* cb_break + cb_s_break before the call */
Marc Dionnebcd89272017-03-16 16:27:44 +0000106 union {
107 unsigned last_to; /* amount of mapping[last] */
108 unsigned count2; /* count used in unmarshalling */
109 };
David Howells08e0e7c2007-04-26 15:55:03 -0700110 unsigned char unmarshall; /* unmarshalling phase */
111 bool incoming; /* T if incoming call */
David Howells31143d52007-05-09 02:33:46 -0700112 bool send_pages; /* T if data from mapping should be sent */
David Howellsd0016482016-08-30 20:42:14 +0100113 bool need_attention; /* T if RxRPC poked us */
David Howells56ff9c82017-01-05 10:38:36 +0000114 bool async; /* T if asynchronous */
David Howells33cd7f22017-11-02 15:27:48 +0000115 bool ret_reply0; /* T if should return reply[0] on success */
David Howellsa68f4a22017-10-18 11:36:39 +0100116 bool upgrade; /* T to request service upgrade */
David Howellsbf99a532017-11-02 15:27:51 +0000117 u16 service_id; /* Actual service ID (after upgrade) */
David Howells50a2c952016-10-13 08:27:10 +0100118 u32 operation_ID; /* operation ID for an incoming call */
David Howells08e0e7c2007-04-26 15:55:03 -0700119 u32 count; /* count for use in unmarshalling */
120 __be32 tmp; /* place to extract temporary data */
David Howells31143d52007-05-09 02:33:46 -0700121 afs_dataversion_t store_version; /* updated version expected from store */
David Howells08e0e7c2007-04-26 15:55:03 -0700122};
123
124struct afs_call_type {
David Howells00d3b7a2007-04-26 15:57:07 -0700125 const char *name;
David Howells025db802017-11-02 15:27:51 +0000126 unsigned int op; /* Really enum afs_fs_operation */
David Howells00d3b7a2007-04-26 15:57:07 -0700127
David Howells08e0e7c2007-04-26 15:55:03 -0700128 /* deliver request or reply data to an call
129 * - returning an error will cause the call to be aborted
130 */
David Howellsd0016482016-08-30 20:42:14 +0100131 int (*deliver)(struct afs_call *call);
David Howells08e0e7c2007-04-26 15:55:03 -0700132
David Howells08e0e7c2007-04-26 15:55:03 -0700133 /* clean up a call */
134 void (*destructor)(struct afs_call *call);
David Howells341f7412017-01-05 10:38:36 +0000135
136 /* Work function */
137 void (*work)(struct work_struct *work);
David Howells08e0e7c2007-04-26 15:55:03 -0700138};
139
140/*
David Howells4343d002017-11-02 15:27:52 +0000141 * Key available for writeback on a file.
142 */
143struct afs_wb_key {
144 refcount_t usage;
145 struct key *key;
146 struct list_head vnode_link; /* Link in vnode->wb_keys */
147};
148
149/*
David Howells215804a2017-11-02 15:27:52 +0000150 * AFS open file information record. Pointed to by file->private_data.
151 */
152struct afs_file {
153 struct key *key; /* The key this file was opened with */
David Howells4343d002017-11-02 15:27:52 +0000154 struct afs_wb_key *wb; /* Writeback key record for this file */
David Howells215804a2017-11-02 15:27:52 +0000155};
156
157static inline struct key *afs_file_key(struct file *file)
158{
159 struct afs_file *af = file->private_data;
160
161 return af->key;
162}
163
164/*
David Howells196ee9c2017-01-05 10:38:34 +0000165 * Record of an outstanding read operation on a vnode.
166 */
167struct afs_read {
168 loff_t pos; /* Where to start reading */
David Howellse8e581a2017-03-16 16:27:44 +0000169 loff_t len; /* How much we're asking for */
David Howells196ee9c2017-01-05 10:38:34 +0000170 loff_t actual_len; /* How much we're actually getting */
David Howells6a0e3992017-03-16 16:27:46 +0000171 loff_t remain; /* Amount remaining */
David Howells196ee9c2017-01-05 10:38:34 +0000172 atomic_t usage;
David Howells196ee9c2017-01-05 10:38:34 +0000173 unsigned int index; /* Which page we're reading into */
David Howells196ee9c2017-01-05 10:38:34 +0000174 unsigned int nr_pages;
175 void (*page_done)(struct afs_call *, struct afs_read *);
176 struct page *pages[];
177};
178
179/*
David Howells08e0e7c2007-04-26 15:55:03 -0700180 * AFS superblock private data
181 * - there's one superblock per volume
182 */
183struct afs_super_info {
David Howellsf044c882017-11-02 15:27:45 +0000184 struct afs_net *net; /* Network namespace */
David Howells49566f62017-11-02 15:27:46 +0000185 struct afs_cell *cell; /* The cell in which the volume resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700186 struct afs_volume *volume; /* volume record */
David Howells08e0e7c2007-04-26 15:55:03 -0700187};
188
189static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
190{
191 return sb->s_fs_info;
192}
193
194extern struct file_system_type afs_fs_type;
195
196/*
David Howellsf044c882017-11-02 15:27:45 +0000197 * AFS network namespace record.
198 */
199struct afs_net {
200 struct afs_uuid uuid;
201 bool live; /* F if this namespace is being removed */
202
203 /* AF_RXRPC I/O stuff */
204 struct socket *socket;
205 struct afs_call *spare_incoming_call;
206 struct work_struct charge_preallocation_work;
207 struct mutex socket_mutex;
208 atomic_t nr_outstanding_calls;
209 atomic_t nr_superblocks;
210
211 /* Cell database */
David Howells989782d2017-11-02 15:27:50 +0000212 struct rb_root cells;
David Howellsf044c882017-11-02 15:27:45 +0000213 struct afs_cell *ws_cell;
David Howells989782d2017-11-02 15:27:50 +0000214 struct work_struct cells_manager;
215 struct timer_list cells_timer;
216 atomic_t cells_outstanding;
217 seqlock_t cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000218
David Howells989782d2017-11-02 15:27:50 +0000219 spinlock_t proc_cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000220 struct list_head proc_cells;
221
David Howellsd2ddc772017-11-02 15:27:50 +0000222 /* Known servers. Theoretically each fileserver can only be in one
223 * cell, but in practice, people create aliases and subsets and there's
224 * no easy way to distinguish them.
225 */
226 seqlock_t fs_lock; /* For fs_servers */
227 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
228 struct list_head fs_updates; /* afs_server (by update_at) */
229 struct hlist_head fs_proc; /* procfs servers list */
230
231 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
232 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
233 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
234
235 struct work_struct fs_manager;
236 struct timer_list fs_timer;
237 atomic_t servers_outstanding;
David Howellsf044c882017-11-02 15:27:45 +0000238
239 /* File locking renewal management */
240 struct mutex lock_manager_mutex;
241
David Howellsf044c882017-11-02 15:27:45 +0000242 /* Misc */
243 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
244};
245
246extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
247
David Howells989782d2017-11-02 15:27:50 +0000248enum afs_cell_state {
249 AFS_CELL_UNSET,
250 AFS_CELL_ACTIVATING,
251 AFS_CELL_ACTIVE,
252 AFS_CELL_DEACTIVATING,
253 AFS_CELL_INACTIVE,
254 AFS_CELL_FAILED,
255};
256
David Howellsf044c882017-11-02 15:27:45 +0000257/*
David Howellsd2ddc772017-11-02 15:27:50 +0000258 * AFS cell record.
259 *
260 * This is a tricky concept to get right as it is possible to create aliases
261 * simply by pointing AFSDB/SRV records for two names at the same set of VL
262 * servers; it is also possible to do things like setting up two sets of VL
263 * servers, one of which provides a superset of the volumes provided by the
264 * other (for internal/external division, for example).
265 *
266 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
267 * servers and (b) a cell's name is used by the client to select the key to use
268 * for authentication and encryption. The cell name is not typically used in
269 * the protocol.
270 *
271 * There is no easy way to determine if two cells are aliases or one is a
272 * subset of another.
David Howells08e0e7c2007-04-26 15:55:03 -0700273 */
274struct afs_cell {
David Howells989782d2017-11-02 15:27:50 +0000275 union {
276 struct rcu_head rcu;
277 struct rb_node net_node; /* Node in net->cells */
278 };
279 struct afs_net *net;
David Howells00d3b7a2007-04-26 15:57:07 -0700280 struct key *anonymous_key; /* anonymous user key for this cell */
David Howells989782d2017-11-02 15:27:50 +0000281 struct work_struct manager; /* Manager for init/deinit/dns */
David Howells08e0e7c2007-04-26 15:55:03 -0700282 struct list_head proc_link; /* /proc cell list link */
David Howells9b3f26c2009-04-03 16:42:41 +0100283#ifdef CONFIG_AFS_FSCACHE
284 struct fscache_cookie *cache; /* caching cookie */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#endif
David Howells989782d2017-11-02 15:27:50 +0000286 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
287 time64_t last_inactive; /* Time of last drop of usage count */
288 atomic_t usage;
289 unsigned long flags;
290#define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
291#define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
292#define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
293#define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
David Howells8b2a4642017-11-02 15:27:50 +0000294#define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
David Howells989782d2017-11-02 15:27:50 +0000295 enum afs_cell_state state;
296 short error;
297
David Howellsd2ddc772017-11-02 15:27:50 +0000298 /* Active fileserver interaction state. */
299 struct list_head proc_volumes; /* procfs volume list */
300 rwlock_t proc_lock;
David Howells989782d2017-11-02 15:27:50 +0000301
David Howellsd2ddc772017-11-02 15:27:50 +0000302 /* VL server list. */
David Howells8b2a4642017-11-02 15:27:50 +0000303 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
304 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
David Howells989782d2017-11-02 15:27:50 +0000305 u8 name_len; /* Length of name */
306 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
David Howells08e0e7c2007-04-26 15:55:03 -0700307};
308
309/*
David Howellsd2ddc772017-11-02 15:27:50 +0000310 * Cached VLDB entry.
311 *
312 * This is pointed to by cell->vldb_entries, indexed by name.
David Howells08e0e7c2007-04-26 15:55:03 -0700313 */
David Howellsd2ddc772017-11-02 15:27:50 +0000314struct afs_vldb_entry {
315 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
David Howells00d3b7a2007-04-26 15:57:07 -0700316
David Howellsd2ddc772017-11-02 15:27:50 +0000317 unsigned long flags;
318#define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
319#define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
320#define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
321#define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
322#define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
323
324 uuid_t fs_server[AFS_NMAXNSERVERS];
325 u8 fs_mask[AFS_NMAXNSERVERS];
David Howells08e0e7c2007-04-26 15:55:03 -0700326#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
327#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
328#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
David Howellsd2ddc772017-11-02 15:27:50 +0000329 short error;
330 u8 nr_servers; /* Number of server records */
331 u8 name_len;
332 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700333};
334
335/*
David Howellsd2ddc772017-11-02 15:27:50 +0000336 * Record of fileserver with which we're actively communicating.
David Howells08e0e7c2007-04-26 15:55:03 -0700337 */
338struct afs_server {
David Howellsd2ddc772017-11-02 15:27:50 +0000339 struct rcu_head rcu;
340 union {
341 uuid_t uuid; /* Server ID */
342 struct afs_uuid _uuid;
343 };
David Howellsc435ee32017-11-02 15:27:49 +0000344
David Howellsd2ddc772017-11-02 15:27:50 +0000345 struct afs_addr_list __rcu *addresses;
346 struct rb_node uuid_rb; /* Link in net->servers */
347 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
348 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
349 struct hlist_node proc_link; /* Link in net->fs_proc */
350 struct afs_server *gc_next; /* Next server in manager's list */
351 time64_t put_time; /* Time at which last put */
352 time64_t update_at; /* Time at which to next update the record */
David Howellsc435ee32017-11-02 15:27:49 +0000353 unsigned long flags;
David Howellsd2ddc772017-11-02 15:27:50 +0000354#define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
355#define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
356#define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
357#define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
358#define AFS_SERVER_FL_UPDATING 4
359#define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
360#define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
361 atomic_t usage;
362 u32 addr_version; /* Address list version */
David Howells08e0e7c2007-04-26 15:55:03 -0700363
364 /* file service access */
David Howellsd2ddc772017-11-02 15:27:50 +0000365 rwlock_t fs_lock; /* access lock */
David Howells08e0e7c2007-04-26 15:55:03 -0700366
367 /* callback promise management */
David Howellsc435ee32017-11-02 15:27:49 +0000368 struct list_head cb_interests; /* List of superblocks using this server */
369 unsigned cb_s_break; /* Break-everything counter. */
370 rwlock_t cb_break_lock; /* Volume finding lock */
371};
372
373/*
374 * Interest by a superblock on a server.
375 */
376struct afs_cb_interest {
377 struct list_head cb_link; /* Link in server->cb_interests */
378 struct afs_server *server; /* Server on which this interest resides */
379 struct super_block *sb; /* Superblock on which inodes reside */
380 afs_volid_t vid; /* Volume ID to match */
381 refcount_t usage;
David Howells08e0e7c2007-04-26 15:55:03 -0700382};
383
384/*
David Howellsd2ddc772017-11-02 15:27:50 +0000385 * Replaceable server list.
David Howells08e0e7c2007-04-26 15:55:03 -0700386 */
David Howellsd2ddc772017-11-02 15:27:50 +0000387struct afs_server_entry {
388 struct afs_server *server;
389 struct afs_cb_interest *cb_interest;
390};
391
392struct afs_server_list {
393 refcount_t usage;
394 unsigned short nr_servers;
395 unsigned short index; /* Server currently in use */
396 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
397 unsigned int seq; /* Set to ->servers_seq when installed */
398 struct afs_server_entry servers[];
David Howells08e0e7c2007-04-26 15:55:03 -0700399};
400
401/*
David Howellsd2ddc772017-11-02 15:27:50 +0000402 * Live AFS volume management.
David Howells08e0e7c2007-04-26 15:55:03 -0700403 */
David Howellsd2ddc772017-11-02 15:27:50 +0000404struct afs_volume {
405 afs_volid_t vid; /* volume ID */
406 atomic_t usage;
407 time64_t update_at; /* Time at which to next update */
408 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
409 struct list_head proc_link; /* Link in cell->vl_proc */
410 unsigned long flags;
411#define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
412#define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
413#define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
414#define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
415#define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
416#define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
417#ifdef CONFIG_AFS_FSCACHE
418 struct fscache_cookie *cache; /* caching cookie */
419#endif
420 struct afs_server_list *servers; /* List of servers on which volume resides */
421 rwlock_t servers_lock; /* Lock for ->servers */
422 unsigned int servers_seq; /* Incremented each time ->servers changes */
423
424 afs_voltype_t type; /* type of volume */
425 short error;
426 char type_force; /* force volume type (suppress R/O -> R/W) */
427 u8 name_len;
428 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700429};
430
431/*
432 * AFS inode private data
433 */
434struct afs_vnode {
435 struct inode vfs_inode; /* the VFS's inode record */
436
437 struct afs_volume *volume; /* volume on which vnode resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700438 struct afs_fid fid; /* the file identifier for this inode */
439 struct afs_file_status status; /* AFS status info for this file */
David Howells9b3f26c2009-04-03 16:42:41 +0100440#ifdef CONFIG_AFS_FSCACHE
441 struct fscache_cookie *cache; /* caching cookie */
David Howells08e0e7c2007-04-26 15:55:03 -0700442#endif
David Howellsbe080a62017-11-02 15:27:49 +0000443 struct afs_permits *permit_cache; /* cache of permits so far obtained */
David Howellsd2ddc772017-11-02 15:27:50 +0000444 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
David Howells260a9802007-04-26 15:59:35 -0700445 struct mutex validate_lock; /* lock for validating this vnode */
David Howells4343d002017-11-02 15:27:52 +0000446 spinlock_t wb_lock; /* lock for wb_keys */
David Howells08e0e7c2007-04-26 15:55:03 -0700447 spinlock_t lock; /* waitqueue/flags lock */
448 unsigned long flags;
David Howellsc435ee32017-11-02 15:27:49 +0000449#define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
David Howells260a9802007-04-26 15:59:35 -0700450#define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
David Howellsc435ee32017-11-02 15:27:49 +0000451#define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */
David Howells08e0e7c2007-04-26 15:55:03 -0700452#define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
453#define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
454#define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
David Howellse8d6c552007-07-15 23:40:12 -0700455#define AFS_VNODE_LOCKING 6 /* set if waiting for lock on vnode */
456#define AFS_VNODE_READLOCKED 7 /* set if vnode is read-locked on the server */
457#define AFS_VNODE_WRITELOCKED 8 /* set if vnode is write-locked on the server */
458#define AFS_VNODE_UNLOCKING 9 /* set if vnode is being unlocked on the server */
wangleibec5eb62010-08-11 09:38:04 +0100459#define AFS_VNODE_AUTOCELL 10 /* set if Vnode is an auto mount point */
460#define AFS_VNODE_PSEUDODIR 11 /* set if Vnode is a pseudo directory */
David Howells08e0e7c2007-04-26 15:55:03 -0700461
David Howells4343d002017-11-02 15:27:52 +0000462 struct list_head wb_keys; /* List of keys available for writeback */
David Howellse8d6c552007-07-15 23:40:12 -0700463 struct list_head pending_locks; /* locks waiting to be granted */
464 struct list_head granted_locks; /* locks granted on this file */
465 struct delayed_work lock_work; /* work to be done in locking */
466 struct key *unlock_key; /* key to be used in unlocking */
David Howells31143d52007-05-09 02:33:46 -0700467
David Howells08e0e7c2007-04-26 15:55:03 -0700468 /* outstanding callback notification on this file */
David Howellsc435ee32017-11-02 15:27:49 +0000469 struct afs_cb_interest *cb_interest; /* Server on which this resides */
470 unsigned int cb_s_break; /* Mass break counter on ->server */
471 unsigned int cb_break; /* Break counter on vnode */
472 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
473
474 time64_t cb_expires_at; /* time at which callback expires */
David Howells08e0e7c2007-04-26 15:55:03 -0700475 unsigned cb_version; /* callback version */
David Howells08e0e7c2007-04-26 15:55:03 -0700476 afs_callback_type_t cb_type; /* type of callback */
David Howells08e0e7c2007-04-26 15:55:03 -0700477};
478
David Howells00d3b7a2007-04-26 15:57:07 -0700479/*
480 * cached security record for one user's attempt to access a vnode
481 */
482struct afs_permit {
483 struct key *key; /* RxRPC ticket holding a security context */
David Howellsbe080a62017-11-02 15:27:49 +0000484 afs_access_t access; /* CallerAccess value for this key */
David Howells00d3b7a2007-04-26 15:57:07 -0700485};
486
487/*
David Howellsbe080a62017-11-02 15:27:49 +0000488 * Immutable cache of CallerAccess records from attempts to access vnodes.
489 * These may be shared between multiple vnodes.
David Howells00d3b7a2007-04-26 15:57:07 -0700490 */
491struct afs_permits {
David Howellsbe080a62017-11-02 15:27:49 +0000492 struct rcu_head rcu;
493 struct hlist_node hash_node; /* Link in hash */
494 unsigned long h; /* Hash value for this permit list */
495 refcount_t usage;
496 unsigned short nr_permits; /* Number of records */
497 bool invalidated; /* Invalidated due to key change */
498 struct afs_permit permits[]; /* List of permits sorted by key pointer */
David Howells00d3b7a2007-04-26 15:57:07 -0700499};
500
David Howellsb908fe62007-04-26 15:58:17 -0700501/*
502 * record of one of a system's set of network interfaces
503 */
504struct afs_interface {
David Howellsb908fe62007-04-26 15:58:17 -0700505 struct in_addr address; /* IPv4 address bound to interface */
506 struct in_addr netmask; /* netmask applied to address */
507 unsigned mtu; /* MTU of interface */
508};
509
David Howells8b2a4642017-11-02 15:27:50 +0000510/*
511 * Cursor for iterating over a server's address list.
512 */
513struct afs_addr_cursor {
514 struct afs_addr_list *alist; /* Current address list (pins ref) */
515 struct sockaddr_rxrpc *addr;
David Howellsd2ddc772017-11-02 15:27:50 +0000516 u32 abort_code;
David Howells8b2a4642017-11-02 15:27:50 +0000517 unsigned short start; /* Starting point in alist->addrs[] */
518 unsigned short index; /* Wrapping offset from start to current addr */
519 short error;
520 bool begun; /* T if we've begun iteration */
521 bool responded; /* T if the current address responded */
522};
523
524/*
525 * Cursor for iterating over a set of fileservers.
526 */
527struct afs_fs_cursor {
528 struct afs_addr_cursor ac;
David Howellsd2ddc772017-11-02 15:27:50 +0000529 struct afs_vnode *vnode;
530 struct afs_server_list *server_list; /* Current server list (pins ref) */
531 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
532 struct key *key; /* Key for the server */
533 unsigned int cb_break; /* cb_break + cb_s_break before the call */
534 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
535 unsigned char start; /* Initial index in server list */
536 unsigned char index; /* Number of servers tried beyond start */
537 unsigned short flags;
538#define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
539#define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
540#define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
541#define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
542#define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
543#define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
David Howells8b2a4642017-11-02 15:27:50 +0000544};
545
David Howells08e0e7c2007-04-26 15:55:03 -0700546/*****************************************************************************/
547/*
David Howells8b2a4642017-11-02 15:27:50 +0000548 * addr_list.c
549 */
550static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
551{
552 if (alist)
553 refcount_inc(&alist->usage);
554 return alist;
555}
556extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
557 unsigned short,
558 unsigned short);
559extern void afs_put_addrlist(struct afs_addr_list *);
560extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
561 unsigned short, unsigned short);
562extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
563extern bool afs_iterate_addresses(struct afs_addr_cursor *);
564extern int afs_end_cursor(struct afs_addr_cursor *);
565extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
566
David Howellsbf99a532017-11-02 15:27:51 +0000567extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
568extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
David Howellsd2ddc772017-11-02 15:27:50 +0000569
David Howells8b2a4642017-11-02 15:27:50 +0000570/*
David Howells9b3f26c2009-04-03 16:42:41 +0100571 * cache.c
572 */
573#ifdef CONFIG_AFS_FSCACHE
574extern struct fscache_netfs afs_cache_netfs;
575extern struct fscache_cookie_def afs_cell_cache_index_def;
David Howells9b3f26c2009-04-03 16:42:41 +0100576extern struct fscache_cookie_def afs_volume_cache_index_def;
577extern struct fscache_cookie_def afs_vnode_cache_index_def;
578#else
579#define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
David Howells9b3f26c2009-04-03 16:42:41 +0100580#define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
581#define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
582#endif
583
584/*
David Howells08e0e7c2007-04-26 15:55:03 -0700585 * callback.c
586 */
587extern void afs_init_callback_state(struct afs_server *);
David Howellsc435ee32017-11-02 15:27:49 +0000588extern void afs_break_callback(struct afs_vnode *);
589extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]);
590
David Howellsd2ddc772017-11-02 15:27:50 +0000591extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
David Howellsc435ee32017-11-02 15:27:49 +0000592extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
David Howellsd2ddc772017-11-02 15:27:50 +0000593extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
David Howellsc435ee32017-11-02 15:27:49 +0000594
595static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
596{
597 refcount_inc(&cbi->usage);
598 return cbi;
599}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601/*
602 * cell.c
603 */
David Howells989782d2017-11-02 15:27:50 +0000604extern int afs_cell_init(struct afs_net *, const char *);
605extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
606extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
607 const char *, bool);
David Howells8b2a4642017-11-02 15:27:50 +0000608extern struct afs_cell *afs_get_cell(struct afs_cell *);
David Howells9ed900b2017-11-02 15:27:46 +0000609extern void afs_put_cell(struct afs_net *, struct afs_cell *);
David Howells989782d2017-11-02 15:27:50 +0000610extern void afs_manage_cells(struct work_struct *);
611extern void afs_cells_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000612extern void __net_exit afs_cell_purge(struct afs_net *);
David Howells08e0e7c2007-04-26 15:55:03 -0700613
614/*
615 * cmservice.c
616 */
617extern bool afs_cm_incoming_call(struct afs_call *);
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619/*
620 * dir.c
621 */
David Howellsdab17c12017-11-02 15:27:52 +0000622extern bool afs_dir_check_page(struct inode *, struct page *);
Arjan van de Ven754661f2007-02-12 00:55:38 -0800623extern const struct inode_operations afs_dir_inode_operations;
Al Virod61dcce2011-01-12 20:04:20 -0500624extern const struct dentry_operations afs_fs_dentry_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800625extern const struct file_operations afs_dir_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627/*
628 * file.c
629 */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700630extern const struct address_space_operations afs_fs_aops;
Arjan van de Ven754661f2007-02-12 00:55:38 -0800631extern const struct inode_operations afs_file_inode_operations;
David Howells00d3b7a2007-04-26 15:57:07 -0700632extern const struct file_operations afs_file_operations;
633
David Howells4343d002017-11-02 15:27:52 +0000634extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
635extern void afs_put_wb_key(struct afs_wb_key *);
David Howells00d3b7a2007-04-26 15:57:07 -0700636extern int afs_open(struct inode *, struct file *);
637extern int afs_release(struct inode *, struct file *);
David Howellsd2ddc772017-11-02 15:27:50 +0000638extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
Al Virof6d335c2010-05-21 15:27:09 +0100639extern int afs_page_filler(void *, struct page *);
David Howells196ee9c2017-01-05 10:38:34 +0000640extern void afs_put_read(struct afs_read *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642/*
David Howellse8d6c552007-07-15 23:40:12 -0700643 * flock.c
644 */
David Howellsf044c882017-11-02 15:27:45 +0000645extern struct workqueue_struct *afs_lock_manager;
646
David Howellse8d6c552007-07-15 23:40:12 -0700647extern void afs_lock_work(struct work_struct *);
648extern void afs_lock_may_be_available(struct afs_vnode *);
649extern int afs_lock(struct file *, int, struct file_lock *);
650extern int afs_flock(struct file *, int, struct file_lock *);
651
652/*
David Howells08e0e7c2007-04-26 15:55:03 -0700653 * fsclient.c
654 */
David Howellsd2ddc772017-11-02 15:27:50 +0000655extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
656extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
657extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
658extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
659 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
660extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
661extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
662extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
663 struct afs_fid *, struct afs_file_status *);
664extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
665 struct afs_vnode *, const char *);
David Howells4343d002017-11-02 15:27:52 +0000666extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
David Howellsd2ddc772017-11-02 15:27:50 +0000667 pgoff_t, pgoff_t, unsigned, unsigned);
668extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
669extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
670extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
671extern int afs_fs_extend_lock(struct afs_fs_cursor *);
672extern int afs_fs_release_lock(struct afs_fs_cursor *);
673extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
674 struct afs_addr_cursor *, struct key *);
675extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
676 struct afs_addr_cursor *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700677
678/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 * inode.c
680 */
David Howellsd2ddc772017-11-02 15:27:50 +0000681extern int afs_fetch_status(struct afs_vnode *, struct key *);
David Howellsc435ee32017-11-02 15:27:49 +0000682extern int afs_iget5_test(struct inode *, void *);
wangleibec5eb62010-08-11 09:38:04 +0100683extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
684 struct key *);
David Howells00d3b7a2007-04-26 15:57:07 -0700685extern struct inode *afs_iget(struct super_block *, struct key *,
David Howells260a9802007-04-26 15:59:35 -0700686 struct afs_fid *, struct afs_file_status *,
David Howellsd2ddc772017-11-02 15:27:50 +0000687 struct afs_callback *,
688 struct afs_cb_interest *);
David Howells416351f2007-05-09 02:33:45 -0700689extern void afs_zap_data(struct afs_vnode *);
David Howells260a9802007-04-26 15:59:35 -0700690extern int afs_validate(struct afs_vnode *, struct key *);
David Howellsa528d352017-01-31 16:46:22 +0000691extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
David Howells31143d52007-05-09 02:33:46 -0700692extern int afs_setattr(struct dentry *, struct iattr *);
Al Virob57922d2010-06-07 14:34:48 -0400693extern void afs_evict_inode(struct inode *);
wangleibec5eb62010-08-11 09:38:04 +0100694extern int afs_drop_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696/*
697 * main.c
698 */
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000699extern struct workqueue_struct *afs_wq;
David Howellsf044c882017-11-02 15:27:45 +0000700
701static inline struct afs_net *afs_d2net(struct dentry *dentry)
702{
703 return &__afs_net;
704}
705
706static inline struct afs_net *afs_i2net(struct inode *inode)
707{
708 return &__afs_net;
709}
710
711static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
712{
713 return &__afs_net;
714}
715
716static inline struct afs_net *afs_sock2net(struct sock *sk)
717{
718 return &__afs_net;
719}
720
721static inline struct afs_net *afs_get_net(struct afs_net *net)
722{
723 return net;
724}
725
726static inline void afs_put_net(struct afs_net *net)
727{
728}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730/*
David Howells08e0e7c2007-04-26 15:55:03 -0700731 * misc.c
732 */
733extern int afs_abort_to_error(u32);
734
735/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 * mntpt.c
737 */
Arjan van de Ven754661f2007-02-12 00:55:38 -0800738extern const struct inode_operations afs_mntpt_inode_operations;
wangleibec5eb62010-08-11 09:38:04 +0100739extern const struct inode_operations afs_autocell_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800740extern const struct file_operations afs_mntpt_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
David Howellsd18610b2011-01-14 19:04:05 +0000742extern struct vfsmount *afs_d_automount(struct path *);
David Howells08e0e7c2007-04-26 15:55:03 -0700743extern void afs_mntpt_kill_timer(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745/*
Arnd Bergmannb4db2b32017-02-10 16:34:07 +0000746 * netdevices.c
747 */
748extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
749
750/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 * proc.c
752 */
David Howellsf044c882017-11-02 15:27:45 +0000753extern int __net_init afs_proc_init(struct afs_net *);
754extern void __net_exit afs_proc_cleanup(struct afs_net *);
755extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
756extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
David Howells08e0e7c2007-04-26 15:55:03 -0700758/*
David Howellsd2ddc772017-11-02 15:27:50 +0000759 * rotate.c
760 */
761extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
762 struct key *);
763extern bool afs_select_fileserver(struct afs_fs_cursor *);
764extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
765extern int afs_end_vnode_operation(struct afs_fs_cursor *);
766
767/*
David Howells08e0e7c2007-04-26 15:55:03 -0700768 * rxrpc.c
769 */
David Howellsf044c882017-11-02 15:27:45 +0000770extern struct workqueue_struct *afs_async_calls;
David Howells8324f0b2016-08-30 09:49:29 +0100771
David Howellsf044c882017-11-02 15:27:45 +0000772extern int __net_init afs_open_socket(struct afs_net *);
773extern void __net_exit afs_close_socket(struct afs_net *);
774extern void afs_charge_preallocation(struct work_struct *);
David Howells341f7412017-01-05 10:38:36 +0000775extern void afs_put_call(struct afs_call *);
776extern int afs_queue_call_work(struct afs_call *);
David Howells8b2a4642017-11-02 15:27:50 +0000777extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
David Howellsf044c882017-11-02 15:27:45 +0000778extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
779 const struct afs_call_type *,
David Howells08e0e7c2007-04-26 15:55:03 -0700780 size_t, size_t);
781extern void afs_flat_call_destructor(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -0700782extern void afs_send_empty_reply(struct afs_call *);
David Howellsb908fe62007-04-26 15:58:17 -0700783extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
David Howellsd0016482016-08-30 20:42:14 +0100784extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
David Howells08e0e7c2007-04-26 15:55:03 -0700785
David Howellsd0016482016-08-30 20:42:14 +0100786static inline int afs_transfer_reply(struct afs_call *call)
David Howells372ee162016-08-03 14:11:40 +0100787{
David Howellsd0016482016-08-30 20:42:14 +0100788 return afs_extract_data(call, call->buffer, call->reply_max, false);
David Howells372ee162016-08-03 14:11:40 +0100789}
790
David Howells08e0e7c2007-04-26 15:55:03 -0700791/*
David Howells00d3b7a2007-04-26 15:57:07 -0700792 * security.c
793 */
David Howellsbe080a62017-11-02 15:27:49 +0000794extern void afs_put_permits(struct afs_permits *);
David Howells00d3b7a2007-04-26 15:57:07 -0700795extern void afs_clear_permits(struct afs_vnode *);
David Howellsbe080a62017-11-02 15:27:49 +0000796extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
David Howells416351f2007-05-09 02:33:45 -0700797extern void afs_zap_permits(struct rcu_head *);
David Howells00d3b7a2007-04-26 15:57:07 -0700798extern struct key *afs_request_key(struct afs_cell *);
Al Viro10556cb2011-06-20 19:28:19 -0400799extern int afs_permission(struct inode *, int);
David Howellsbe080a62017-11-02 15:27:49 +0000800extern void __exit afs_clean_up_permit_cache(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700801
802/*
David Howells08e0e7c2007-04-26 15:55:03 -0700803 * server.c
804 */
805extern spinlock_t afs_server_peer_lock;
806
David Howellsc435ee32017-11-02 15:27:49 +0000807static inline struct afs_server *afs_get_server(struct afs_server *server)
808{
809 atomic_inc(&server->usage);
810 return server;
811}
David Howells08e0e7c2007-04-26 15:55:03 -0700812
David Howellsf044c882017-11-02 15:27:45 +0000813extern struct afs_server *afs_find_server(struct afs_net *,
814 const struct sockaddr_rxrpc *);
David Howellsd2ddc772017-11-02 15:27:50 +0000815extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
816extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
David Howells9ed900b2017-11-02 15:27:46 +0000817extern void afs_put_server(struct afs_net *, struct afs_server *);
David Howellsd2ddc772017-11-02 15:27:50 +0000818extern void afs_manage_servers(struct work_struct *);
819extern void afs_servers_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000820extern void __net_exit afs_purge_servers(struct afs_net *);
David Howellsd2ddc772017-11-02 15:27:50 +0000821extern bool afs_probe_fileserver(struct afs_fs_cursor *);
822extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
823
824/*
825 * server_list.c
826 */
827static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
828{
829 refcount_inc(&slist->usage);
830 return slist;
831}
832
833extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
834extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
835 struct afs_vldb_entry *,
836 u8);
837extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
David Howells08e0e7c2007-04-26 15:55:03 -0700838
839/*
David Howells00d3b7a2007-04-26 15:57:07 -0700840 * super.c
841 */
David Howellsf044c882017-11-02 15:27:45 +0000842extern int __init afs_fs_init(void);
843extern void __exit afs_fs_exit(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700844
845/*
David Howells08e0e7c2007-04-26 15:55:03 -0700846 * vlclient.c
847 */
David Howellsd2ddc772017-11-02 15:27:50 +0000848extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
849 struct afs_addr_cursor *,
850 struct key *, const char *, int);
851extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
852 struct key *, const uuid_t *);
David Howellsbf99a532017-11-02 15:27:51 +0000853extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
854extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
855 struct key *, const uuid_t *);
David Howells08e0e7c2007-04-26 15:55:03 -0700856
857/*
858 * volume.c
859 */
David Howellsd2ddc772017-11-02 15:27:50 +0000860static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
David Howells49566f62017-11-02 15:27:46 +0000861{
862 if (volume)
863 atomic_inc(&volume->usage);
864 return volume;
865}
David Howells08e0e7c2007-04-26 15:55:03 -0700866
David Howellsd2ddc772017-11-02 15:27:50 +0000867extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
868extern void afs_activate_volume(struct afs_volume *);
869extern void afs_deactivate_volume(struct afs_volume *);
David Howells9ed900b2017-11-02 15:27:46 +0000870extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
David Howellsd2ddc772017-11-02 15:27:50 +0000871extern int afs_check_volume_status(struct afs_volume *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700872
David Howells31143d52007-05-09 02:33:46 -0700873/*
874 * write.c
875 */
876extern int afs_set_page_dirty(struct page *);
Nick Piggin15b46502008-10-15 22:04:32 -0700877extern int afs_write_begin(struct file *file, struct address_space *mapping,
878 loff_t pos, unsigned len, unsigned flags,
879 struct page **pagep, void **fsdata);
880extern int afs_write_end(struct file *file, struct address_space *mapping,
881 loff_t pos, unsigned len, unsigned copied,
882 struct page *page, void *fsdata);
David Howells31143d52007-05-09 02:33:46 -0700883extern int afs_writepage(struct page *, struct writeback_control *);
884extern int afs_writepages(struct address_space *, struct writeback_control *);
David Howells31143d52007-05-09 02:33:46 -0700885extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
Al Viro50b55512014-04-03 14:13:46 -0400886extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
David Howells58fed942017-03-16 16:27:45 +0000887extern int afs_flush(struct file *, fl_owner_t);
Josef Bacik02c24a82011-07-16 20:44:56 -0400888extern int afs_fsync(struct file *, loff_t, loff_t, int);
David Howells4343d002017-11-02 15:27:52 +0000889extern void afs_prune_wb_keys(struct afs_vnode *);
890extern int afs_launder_page(struct page *);
David Howells31143d52007-05-09 02:33:46 -0700891
David Howellsd3e3b7ea2017-07-06 15:50:27 +0100892/*
893 * xattr.c
894 */
895extern const struct xattr_handler *afs_xattr_handlers[];
896extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
David Howells31143d52007-05-09 02:33:46 -0700897
David Howellsd2ddc772017-11-02 15:27:50 +0000898
899/*
900 * Miscellaneous inline functions.
901 */
902static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
903{
904 return container_of(inode, struct afs_vnode, vfs_inode);
905}
906
907static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
908{
909 return &vnode->vfs_inode;
910}
911
912static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
913 struct afs_vnode *vnode,
914 unsigned int cb_break)
915{
916 if (fc->ac.error == 0)
917 afs_cache_permit(vnode, fc->key, cb_break);
918}
919
920static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
921 struct afs_vnode *vnode)
922{
923 if (fc->ac.error == -ENOENT) {
924 set_bit(AFS_VNODE_DELETED, &vnode->flags);
925 afs_break_callback(vnode);
926 }
927}
928
929
David Howells08e0e7c2007-04-26 15:55:03 -0700930/*****************************************************************************/
931/*
932 * debug tracing
933 */
David Howells8e8d7f12017-01-05 10:38:34 +0000934#include <trace/events/afs.h>
935
David Howells08e0e7c2007-04-26 15:55:03 -0700936extern unsigned afs_debug;
937
938#define dbgprintk(FMT,...) \
Sven Schnellead16df82008-04-03 10:44:01 +0100939 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -0700940
Harvey Harrison530b6412008-04-30 00:55:09 -0700941#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
942#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -0700943#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
944
945
946#if defined(__KDEBUG)
947#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
948#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
949#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
950
951#elif defined(CONFIG_AFS_DEBUG)
952#define AFS_DEBUG_KENTER 0x01
953#define AFS_DEBUG_KLEAVE 0x02
954#define AFS_DEBUG_KDEBUG 0x04
955
956#define _enter(FMT,...) \
957do { \
958 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
959 kenter(FMT,##__VA_ARGS__); \
960} while (0)
961
962#define _leave(FMT,...) \
963do { \
964 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
965 kleave(FMT,##__VA_ARGS__); \
966} while (0)
967
968#define _debug(FMT,...) \
969do { \
970 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
971 kdebug(FMT,##__VA_ARGS__); \
972} while (0)
973
974#else
David Howells12fdff32010-08-12 16:54:57 +0100975#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
976#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
977#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -0700978#endif
979
980/*
981 * debug assertion checking
982 */
983#if 1 // defined(__KDEBUGALL)
984
985#define ASSERT(X) \
986do { \
987 if (unlikely(!(X))) { \
988 printk(KERN_ERR "\n"); \
989 printk(KERN_ERR "AFS: Assertion failed\n"); \
990 BUG(); \
991 } \
992} while(0)
993
994#define ASSERTCMP(X, OP, Y) \
995do { \
996 if (unlikely(!((X) OP (Y)))) { \
997 printk(KERN_ERR "\n"); \
998 printk(KERN_ERR "AFS: Assertion failed\n"); \
999 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1000 (unsigned long)(X), (unsigned long)(Y)); \
1001 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1002 (unsigned long)(X), (unsigned long)(Y)); \
1003 BUG(); \
1004 } \
1005} while(0)
1006
David Howells416351f2007-05-09 02:33:45 -07001007#define ASSERTRANGE(L, OP1, N, OP2, H) \
1008do { \
1009 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1010 printk(KERN_ERR "\n"); \
1011 printk(KERN_ERR "AFS: Assertion failed\n"); \
1012 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1013 (unsigned long)(L), (unsigned long)(N), \
1014 (unsigned long)(H)); \
1015 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1016 (unsigned long)(L), (unsigned long)(N), \
1017 (unsigned long)(H)); \
1018 BUG(); \
1019 } \
1020} while(0)
1021
David Howells08e0e7c2007-04-26 15:55:03 -07001022#define ASSERTIF(C, X) \
1023do { \
1024 if (unlikely((C) && !(X))) { \
1025 printk(KERN_ERR "\n"); \
1026 printk(KERN_ERR "AFS: Assertion failed\n"); \
1027 BUG(); \
1028 } \
1029} while(0)
1030
1031#define ASSERTIFCMP(C, X, OP, Y) \
1032do { \
1033 if (unlikely((C) && !((X) OP (Y)))) { \
1034 printk(KERN_ERR "\n"); \
1035 printk(KERN_ERR "AFS: Assertion failed\n"); \
1036 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1037 (unsigned long)(X), (unsigned long)(Y)); \
1038 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1039 (unsigned long)(X), (unsigned long)(Y)); \
1040 BUG(); \
1041 } \
1042} while(0)
1043
1044#else
1045
1046#define ASSERT(X) \
1047do { \
1048} while(0)
1049
1050#define ASSERTCMP(X, OP, Y) \
1051do { \
1052} while(0)
1053
David Howells416351f2007-05-09 02:33:45 -07001054#define ASSERTRANGE(L, OP1, N, OP2, H) \
1055do { \
1056} while(0)
1057
David Howells08e0e7c2007-04-26 15:55:03 -07001058#define ASSERTIF(C, X) \
1059do { \
1060} while(0)
1061
1062#define ASSERTIFCMP(C, X, OP, Y) \
1063do { \
1064} while(0)
1065
1066#endif /* __KDEBUGALL */