blob: 6aa6e9957c447437d4f4a748ff1c7e18c84343b2 [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 Howells31143d52007-05-09 02:33:46 -070092 struct address_space *mapping; /* page set */
93 struct afs_writeback *wb; /* writeback being performed */
David Howells08e0e7c2007-04-26 15:55:03 -070094 void *buffer; /* reply receive buffer */
David Howells97e30432017-11-02 15:27:48 +000095 void *reply[4]; /* Where to put the reply */
David Howells31143d52007-05-09 02:33:46 -070096 pgoff_t first; /* first page in mapping to deal with */
97 pgoff_t last; /* last page in mapping to deal with */
David Howellsd0016482016-08-30 20:42:14 +010098 size_t offset; /* offset into received data store */
David Howells341f7412017-01-05 10:38:36 +000099 atomic_t usage;
David Howells8e8d7f12017-01-05 10:38:34 +0000100 enum afs_call_state state;
David Howells08e0e7c2007-04-26 15:55:03 -0700101 int error; /* error code */
David Howellsd0016482016-08-30 20:42:14 +0100102 u32 abort_code; /* Remote abort ID or 0 */
David Howells08e0e7c2007-04-26 15:55:03 -0700103 unsigned request_size; /* size of request data */
104 unsigned reply_max; /* maximum size of reply */
David Howells31143d52007-05-09 02:33:46 -0700105 unsigned first_offset; /* offset into mapping[first] */
David Howellsc435ee32017-11-02 15:27:49 +0000106 unsigned int cb_break; /* cb_break + cb_s_break before the call */
Marc Dionnebcd89272017-03-16 16:27:44 +0000107 union {
108 unsigned last_to; /* amount of mapping[last] */
109 unsigned count2; /* count used in unmarshalling */
110 };
David Howells08e0e7c2007-04-26 15:55:03 -0700111 unsigned char unmarshall; /* unmarshalling phase */
112 bool incoming; /* T if incoming call */
David Howells31143d52007-05-09 02:33:46 -0700113 bool send_pages; /* T if data from mapping should be sent */
David Howellsd0016482016-08-30 20:42:14 +0100114 bool need_attention; /* T if RxRPC poked us */
David Howells56ff9c82017-01-05 10:38:36 +0000115 bool async; /* T if asynchronous */
David Howells33cd7f22017-11-02 15:27:48 +0000116 bool ret_reply0; /* T if should return reply[0] on success */
David Howellsa68f4a22017-10-18 11:36:39 +0100117 bool upgrade; /* T to request service upgrade */
David Howellsbf99a532017-11-02 15:27:51 +0000118 u16 service_id; /* Actual service ID (after upgrade) */
David Howells50a2c952016-10-13 08:27:10 +0100119 u32 operation_ID; /* operation ID for an incoming call */
David Howells08e0e7c2007-04-26 15:55:03 -0700120 u32 count; /* count for use in unmarshalling */
121 __be32 tmp; /* place to extract temporary data */
David Howells31143d52007-05-09 02:33:46 -0700122 afs_dataversion_t store_version; /* updated version expected from store */
David Howells08e0e7c2007-04-26 15:55:03 -0700123};
124
125struct afs_call_type {
David Howells00d3b7a2007-04-26 15:57:07 -0700126 const char *name;
David Howells025db802017-11-02 15:27:51 +0000127 unsigned int op; /* Really enum afs_fs_operation */
David Howells00d3b7a2007-04-26 15:57:07 -0700128
David Howells08e0e7c2007-04-26 15:55:03 -0700129 /* deliver request or reply data to an call
130 * - returning an error will cause the call to be aborted
131 */
David Howellsd0016482016-08-30 20:42:14 +0100132 int (*deliver)(struct afs_call *call);
David Howells08e0e7c2007-04-26 15:55:03 -0700133
David Howells08e0e7c2007-04-26 15:55:03 -0700134 /* clean up a call */
135 void (*destructor)(struct afs_call *call);
David Howells341f7412017-01-05 10:38:36 +0000136
137 /* Work function */
138 void (*work)(struct work_struct *work);
David Howells08e0e7c2007-04-26 15:55:03 -0700139};
140
141/*
David Howells196ee9c2017-01-05 10:38:34 +0000142 * Record of an outstanding read operation on a vnode.
143 */
144struct afs_read {
145 loff_t pos; /* Where to start reading */
David Howellse8e581a2017-03-16 16:27:44 +0000146 loff_t len; /* How much we're asking for */
David Howells196ee9c2017-01-05 10:38:34 +0000147 loff_t actual_len; /* How much we're actually getting */
David Howells6a0e3992017-03-16 16:27:46 +0000148 loff_t remain; /* Amount remaining */
David Howells196ee9c2017-01-05 10:38:34 +0000149 atomic_t usage;
David Howells196ee9c2017-01-05 10:38:34 +0000150 unsigned int index; /* Which page we're reading into */
David Howells196ee9c2017-01-05 10:38:34 +0000151 unsigned int nr_pages;
152 void (*page_done)(struct afs_call *, struct afs_read *);
153 struct page *pages[];
154};
155
156/*
David Howells31143d52007-05-09 02:33:46 -0700157 * record of an outstanding writeback on a vnode
158 */
159struct afs_writeback {
160 struct list_head link; /* link in vnode->writebacks */
161 struct work_struct writer; /* work item to perform the writeback */
162 struct afs_vnode *vnode; /* vnode to which this write applies */
163 struct key *key; /* owner of this write */
164 wait_queue_head_t waitq; /* completion and ready wait queue */
165 pgoff_t first; /* first page in batch */
166 pgoff_t point; /* last page in current store op */
167 pgoff_t last; /* last page in batch (inclusive) */
168 unsigned offset_first; /* offset into first page of start of write */
169 unsigned to_last; /* offset into last page of end of write */
170 int num_conflicts; /* count of conflicting writes in list */
171 int usage;
172 bool conflicts; /* T if has dependent conflicts */
173 enum {
174 AFS_WBACK_SYNCING, /* synchronisation being performed */
175 AFS_WBACK_PENDING, /* write pending */
176 AFS_WBACK_CONFLICTING, /* conflicting writes posted */
177 AFS_WBACK_WRITING, /* writing back */
178 AFS_WBACK_COMPLETE /* the writeback record has been unlinked */
179 } state __attribute__((packed));
180};
181
182/*
David Howells08e0e7c2007-04-26 15:55:03 -0700183 * AFS superblock private data
184 * - there's one superblock per volume
185 */
186struct afs_super_info {
David Howellsf044c882017-11-02 15:27:45 +0000187 struct afs_net *net; /* Network namespace */
David Howells49566f62017-11-02 15:27:46 +0000188 struct afs_cell *cell; /* The cell in which the volume resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700189 struct afs_volume *volume; /* volume record */
David Howells08e0e7c2007-04-26 15:55:03 -0700190};
191
192static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
193{
194 return sb->s_fs_info;
195}
196
197extern struct file_system_type afs_fs_type;
198
199/*
David Howellsf044c882017-11-02 15:27:45 +0000200 * AFS network namespace record.
201 */
202struct afs_net {
203 struct afs_uuid uuid;
204 bool live; /* F if this namespace is being removed */
205
206 /* AF_RXRPC I/O stuff */
207 struct socket *socket;
208 struct afs_call *spare_incoming_call;
209 struct work_struct charge_preallocation_work;
210 struct mutex socket_mutex;
211 atomic_t nr_outstanding_calls;
212 atomic_t nr_superblocks;
213
214 /* Cell database */
David Howells989782d2017-11-02 15:27:50 +0000215 struct rb_root cells;
David Howellsf044c882017-11-02 15:27:45 +0000216 struct afs_cell *ws_cell;
David Howells989782d2017-11-02 15:27:50 +0000217 struct work_struct cells_manager;
218 struct timer_list cells_timer;
219 atomic_t cells_outstanding;
220 seqlock_t cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000221
David Howells989782d2017-11-02 15:27:50 +0000222 spinlock_t proc_cells_lock;
David Howellsf044c882017-11-02 15:27:45 +0000223 struct list_head proc_cells;
224
David Howellsd2ddc772017-11-02 15:27:50 +0000225 /* Known servers. Theoretically each fileserver can only be in one
226 * cell, but in practice, people create aliases and subsets and there's
227 * no easy way to distinguish them.
228 */
229 seqlock_t fs_lock; /* For fs_servers */
230 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
231 struct list_head fs_updates; /* afs_server (by update_at) */
232 struct hlist_head fs_proc; /* procfs servers list */
233
234 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
235 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
236 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
237
238 struct work_struct fs_manager;
239 struct timer_list fs_timer;
240 atomic_t servers_outstanding;
David Howellsf044c882017-11-02 15:27:45 +0000241
242 /* File locking renewal management */
243 struct mutex lock_manager_mutex;
244
David Howellsf044c882017-11-02 15:27:45 +0000245 /* Misc */
246 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
247};
248
249extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
250
David Howells989782d2017-11-02 15:27:50 +0000251enum afs_cell_state {
252 AFS_CELL_UNSET,
253 AFS_CELL_ACTIVATING,
254 AFS_CELL_ACTIVE,
255 AFS_CELL_DEACTIVATING,
256 AFS_CELL_INACTIVE,
257 AFS_CELL_FAILED,
258};
259
David Howellsf044c882017-11-02 15:27:45 +0000260/*
David Howellsd2ddc772017-11-02 15:27:50 +0000261 * AFS cell record.
262 *
263 * This is a tricky concept to get right as it is possible to create aliases
264 * simply by pointing AFSDB/SRV records for two names at the same set of VL
265 * servers; it is also possible to do things like setting up two sets of VL
266 * servers, one of which provides a superset of the volumes provided by the
267 * other (for internal/external division, for example).
268 *
269 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
270 * servers and (b) a cell's name is used by the client to select the key to use
271 * for authentication and encryption. The cell name is not typically used in
272 * the protocol.
273 *
274 * There is no easy way to determine if two cells are aliases or one is a
275 * subset of another.
David Howells08e0e7c2007-04-26 15:55:03 -0700276 */
277struct afs_cell {
David Howells989782d2017-11-02 15:27:50 +0000278 union {
279 struct rcu_head rcu;
280 struct rb_node net_node; /* Node in net->cells */
281 };
282 struct afs_net *net;
David Howells00d3b7a2007-04-26 15:57:07 -0700283 struct key *anonymous_key; /* anonymous user key for this cell */
David Howells989782d2017-11-02 15:27:50 +0000284 struct work_struct manager; /* Manager for init/deinit/dns */
David Howells08e0e7c2007-04-26 15:55:03 -0700285 struct list_head proc_link; /* /proc cell list link */
David Howells9b3f26c2009-04-03 16:42:41 +0100286#ifdef CONFIG_AFS_FSCACHE
287 struct fscache_cookie *cache; /* caching cookie */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288#endif
David Howells989782d2017-11-02 15:27:50 +0000289 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
290 time64_t last_inactive; /* Time of last drop of usage count */
291 atomic_t usage;
292 unsigned long flags;
293#define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
294#define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
295#define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
296#define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
David Howells8b2a4642017-11-02 15:27:50 +0000297#define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
David Howells989782d2017-11-02 15:27:50 +0000298 enum afs_cell_state state;
299 short error;
300
David Howellsd2ddc772017-11-02 15:27:50 +0000301 /* Active fileserver interaction state. */
302 struct list_head proc_volumes; /* procfs volume list */
303 rwlock_t proc_lock;
David Howells989782d2017-11-02 15:27:50 +0000304
David Howellsd2ddc772017-11-02 15:27:50 +0000305 /* VL server list. */
David Howells8b2a4642017-11-02 15:27:50 +0000306 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
307 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
David Howells989782d2017-11-02 15:27:50 +0000308 u8 name_len; /* Length of name */
309 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
David Howells08e0e7c2007-04-26 15:55:03 -0700310};
311
312/*
David Howellsd2ddc772017-11-02 15:27:50 +0000313 * Cached VLDB entry.
314 *
315 * This is pointed to by cell->vldb_entries, indexed by name.
David Howells08e0e7c2007-04-26 15:55:03 -0700316 */
David Howellsd2ddc772017-11-02 15:27:50 +0000317struct afs_vldb_entry {
318 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
David Howells00d3b7a2007-04-26 15:57:07 -0700319
David Howellsd2ddc772017-11-02 15:27:50 +0000320 unsigned long flags;
321#define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
322#define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
323#define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
324#define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
325#define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
326
327 uuid_t fs_server[AFS_NMAXNSERVERS];
328 u8 fs_mask[AFS_NMAXNSERVERS];
David Howells08e0e7c2007-04-26 15:55:03 -0700329#define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
330#define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
331#define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
David Howellsd2ddc772017-11-02 15:27:50 +0000332 short error;
333 u8 nr_servers; /* Number of server records */
334 u8 name_len;
335 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700336};
337
338/*
David Howellsd2ddc772017-11-02 15:27:50 +0000339 * Record of fileserver with which we're actively communicating.
David Howells08e0e7c2007-04-26 15:55:03 -0700340 */
341struct afs_server {
David Howellsd2ddc772017-11-02 15:27:50 +0000342 struct rcu_head rcu;
343 union {
344 uuid_t uuid; /* Server ID */
345 struct afs_uuid _uuid;
346 };
David Howellsc435ee32017-11-02 15:27:49 +0000347
David Howellsd2ddc772017-11-02 15:27:50 +0000348 struct afs_addr_list __rcu *addresses;
349 struct rb_node uuid_rb; /* Link in net->servers */
350 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
351 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
352 struct hlist_node proc_link; /* Link in net->fs_proc */
353 struct afs_server *gc_next; /* Next server in manager's list */
354 time64_t put_time; /* Time at which last put */
355 time64_t update_at; /* Time at which to next update the record */
David Howellsc435ee32017-11-02 15:27:49 +0000356 unsigned long flags;
David Howellsd2ddc772017-11-02 15:27:50 +0000357#define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
358#define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
359#define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
360#define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
361#define AFS_SERVER_FL_UPDATING 4
362#define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
363#define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
364 atomic_t usage;
365 u32 addr_version; /* Address list version */
David Howells08e0e7c2007-04-26 15:55:03 -0700366
367 /* file service access */
David Howellsd2ddc772017-11-02 15:27:50 +0000368 rwlock_t fs_lock; /* access lock */
David Howells08e0e7c2007-04-26 15:55:03 -0700369
370 /* callback promise management */
David Howellsc435ee32017-11-02 15:27:49 +0000371 struct list_head cb_interests; /* List of superblocks using this server */
372 unsigned cb_s_break; /* Break-everything counter. */
373 rwlock_t cb_break_lock; /* Volume finding lock */
374};
375
376/*
377 * Interest by a superblock on a server.
378 */
379struct afs_cb_interest {
380 struct list_head cb_link; /* Link in server->cb_interests */
381 struct afs_server *server; /* Server on which this interest resides */
382 struct super_block *sb; /* Superblock on which inodes reside */
383 afs_volid_t vid; /* Volume ID to match */
384 refcount_t usage;
David Howells08e0e7c2007-04-26 15:55:03 -0700385};
386
387/*
David Howellsd2ddc772017-11-02 15:27:50 +0000388 * Replaceable server list.
David Howells08e0e7c2007-04-26 15:55:03 -0700389 */
David Howellsd2ddc772017-11-02 15:27:50 +0000390struct afs_server_entry {
391 struct afs_server *server;
392 struct afs_cb_interest *cb_interest;
393};
394
395struct afs_server_list {
396 refcount_t usage;
397 unsigned short nr_servers;
398 unsigned short index; /* Server currently in use */
399 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
400 unsigned int seq; /* Set to ->servers_seq when installed */
401 struct afs_server_entry servers[];
David Howells08e0e7c2007-04-26 15:55:03 -0700402};
403
404/*
David Howellsd2ddc772017-11-02 15:27:50 +0000405 * Live AFS volume management.
David Howells08e0e7c2007-04-26 15:55:03 -0700406 */
David Howellsd2ddc772017-11-02 15:27:50 +0000407struct afs_volume {
408 afs_volid_t vid; /* volume ID */
409 atomic_t usage;
410 time64_t update_at; /* Time at which to next update */
411 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
412 struct list_head proc_link; /* Link in cell->vl_proc */
413 unsigned long flags;
414#define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
415#define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
416#define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
417#define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
418#define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
419#define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
420#ifdef CONFIG_AFS_FSCACHE
421 struct fscache_cookie *cache; /* caching cookie */
422#endif
423 struct afs_server_list *servers; /* List of servers on which volume resides */
424 rwlock_t servers_lock; /* Lock for ->servers */
425 unsigned int servers_seq; /* Incremented each time ->servers changes */
426
427 afs_voltype_t type; /* type of volume */
428 short error;
429 char type_force; /* force volume type (suppress R/O -> R/W) */
430 u8 name_len;
431 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
David Howells08e0e7c2007-04-26 15:55:03 -0700432};
433
434/*
435 * AFS inode private data
436 */
437struct afs_vnode {
438 struct inode vfs_inode; /* the VFS's inode record */
439
440 struct afs_volume *volume; /* volume on which vnode resides */
David Howells08e0e7c2007-04-26 15:55:03 -0700441 struct afs_fid fid; /* the file identifier for this inode */
442 struct afs_file_status status; /* AFS status info for this file */
David Howells9b3f26c2009-04-03 16:42:41 +0100443#ifdef CONFIG_AFS_FSCACHE
444 struct fscache_cookie *cache; /* caching cookie */
David Howells08e0e7c2007-04-26 15:55:03 -0700445#endif
David Howellsbe080a62017-11-02 15:27:49 +0000446 struct afs_permits *permit_cache; /* cache of permits so far obtained */
David Howellsd2ddc772017-11-02 15:27:50 +0000447 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
David Howells260a9802007-04-26 15:59:35 -0700448 struct mutex validate_lock; /* lock for validating this vnode */
David Howells31143d52007-05-09 02:33:46 -0700449 spinlock_t writeback_lock; /* lock for writebacks */
David Howells08e0e7c2007-04-26 15:55:03 -0700450 spinlock_t lock; /* waitqueue/flags lock */
451 unsigned long flags;
David Howellsc435ee32017-11-02 15:27:49 +0000452#define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
David Howells260a9802007-04-26 15:59:35 -0700453#define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
David Howellsc435ee32017-11-02 15:27:49 +0000454#define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */
David Howells08e0e7c2007-04-26 15:55:03 -0700455#define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
456#define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
457#define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
David Howellse8d6c552007-07-15 23:40:12 -0700458#define AFS_VNODE_LOCKING 6 /* set if waiting for lock on vnode */
459#define AFS_VNODE_READLOCKED 7 /* set if vnode is read-locked on the server */
460#define AFS_VNODE_WRITELOCKED 8 /* set if vnode is write-locked on the server */
461#define AFS_VNODE_UNLOCKING 9 /* set if vnode is being unlocked on the server */
wangleibec5eb62010-08-11 09:38:04 +0100462#define AFS_VNODE_AUTOCELL 10 /* set if Vnode is an auto mount point */
463#define AFS_VNODE_PSEUDODIR 11 /* set if Vnode is a pseudo directory */
David Howells08e0e7c2007-04-26 15:55:03 -0700464
David Howells31143d52007-05-09 02:33:46 -0700465 struct list_head writebacks; /* alterations in pagecache that need writing */
David Howellse8d6c552007-07-15 23:40:12 -0700466 struct list_head pending_locks; /* locks waiting to be granted */
467 struct list_head granted_locks; /* locks granted on this file */
468 struct delayed_work lock_work; /* work to be done in locking */
469 struct key *unlock_key; /* key to be used in unlocking */
David Howells31143d52007-05-09 02:33:46 -0700470
David Howells08e0e7c2007-04-26 15:55:03 -0700471 /* outstanding callback notification on this file */
David Howellsc435ee32017-11-02 15:27:49 +0000472 struct afs_cb_interest *cb_interest; /* Server on which this resides */
473 unsigned int cb_s_break; /* Mass break counter on ->server */
474 unsigned int cb_break; /* Break counter on vnode */
475 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
476
477 time64_t cb_expires_at; /* time at which callback expires */
David Howells08e0e7c2007-04-26 15:55:03 -0700478 unsigned cb_version; /* callback version */
David Howells08e0e7c2007-04-26 15:55:03 -0700479 afs_callback_type_t cb_type; /* type of callback */
David Howells08e0e7c2007-04-26 15:55:03 -0700480};
481
David Howells00d3b7a2007-04-26 15:57:07 -0700482/*
483 * cached security record for one user's attempt to access a vnode
484 */
485struct afs_permit {
486 struct key *key; /* RxRPC ticket holding a security context */
David Howellsbe080a62017-11-02 15:27:49 +0000487 afs_access_t access; /* CallerAccess value for this key */
David Howells00d3b7a2007-04-26 15:57:07 -0700488};
489
490/*
David Howellsbe080a62017-11-02 15:27:49 +0000491 * Immutable cache of CallerAccess records from attempts to access vnodes.
492 * These may be shared between multiple vnodes.
David Howells00d3b7a2007-04-26 15:57:07 -0700493 */
494struct afs_permits {
David Howellsbe080a62017-11-02 15:27:49 +0000495 struct rcu_head rcu;
496 struct hlist_node hash_node; /* Link in hash */
497 unsigned long h; /* Hash value for this permit list */
498 refcount_t usage;
499 unsigned short nr_permits; /* Number of records */
500 bool invalidated; /* Invalidated due to key change */
501 struct afs_permit permits[]; /* List of permits sorted by key pointer */
David Howells00d3b7a2007-04-26 15:57:07 -0700502};
503
David Howellsb908fe62007-04-26 15:58:17 -0700504/*
505 * record of one of a system's set of network interfaces
506 */
507struct afs_interface {
David Howellsb908fe62007-04-26 15:58:17 -0700508 struct in_addr address; /* IPv4 address bound to interface */
509 struct in_addr netmask; /* netmask applied to address */
510 unsigned mtu; /* MTU of interface */
511};
512
David Howells8b2a4642017-11-02 15:27:50 +0000513/*
514 * Cursor for iterating over a server's address list.
515 */
516struct afs_addr_cursor {
517 struct afs_addr_list *alist; /* Current address list (pins ref) */
518 struct sockaddr_rxrpc *addr;
David Howellsd2ddc772017-11-02 15:27:50 +0000519 u32 abort_code;
David Howells8b2a4642017-11-02 15:27:50 +0000520 unsigned short start; /* Starting point in alist->addrs[] */
521 unsigned short index; /* Wrapping offset from start to current addr */
522 short error;
523 bool begun; /* T if we've begun iteration */
524 bool responded; /* T if the current address responded */
525};
526
527/*
528 * Cursor for iterating over a set of fileservers.
529 */
530struct afs_fs_cursor {
531 struct afs_addr_cursor ac;
David Howellsd2ddc772017-11-02 15:27:50 +0000532 struct afs_vnode *vnode;
533 struct afs_server_list *server_list; /* Current server list (pins ref) */
534 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
535 struct key *key; /* Key for the server */
536 unsigned int cb_break; /* cb_break + cb_s_break before the call */
537 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
538 unsigned char start; /* Initial index in server list */
539 unsigned char index; /* Number of servers tried beyond start */
540 unsigned short flags;
541#define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
542#define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
543#define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
544#define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
545#define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
546#define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
David Howells8b2a4642017-11-02 15:27:50 +0000547};
548
David Howells08e0e7c2007-04-26 15:55:03 -0700549/*****************************************************************************/
550/*
David Howells8b2a4642017-11-02 15:27:50 +0000551 * addr_list.c
552 */
553static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
554{
555 if (alist)
556 refcount_inc(&alist->usage);
557 return alist;
558}
559extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
560 unsigned short,
561 unsigned short);
562extern void afs_put_addrlist(struct afs_addr_list *);
563extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
564 unsigned short, unsigned short);
565extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
566extern bool afs_iterate_addresses(struct afs_addr_cursor *);
567extern int afs_end_cursor(struct afs_addr_cursor *);
568extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
569
David Howellsbf99a532017-11-02 15:27:51 +0000570extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
571extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
David Howellsd2ddc772017-11-02 15:27:50 +0000572
David Howells8b2a4642017-11-02 15:27:50 +0000573/*
David Howells9b3f26c2009-04-03 16:42:41 +0100574 * cache.c
575 */
576#ifdef CONFIG_AFS_FSCACHE
577extern struct fscache_netfs afs_cache_netfs;
578extern struct fscache_cookie_def afs_cell_cache_index_def;
David Howells9b3f26c2009-04-03 16:42:41 +0100579extern struct fscache_cookie_def afs_volume_cache_index_def;
580extern struct fscache_cookie_def afs_vnode_cache_index_def;
581#else
582#define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
David Howells9b3f26c2009-04-03 16:42:41 +0100583#define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
584#define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
585#endif
586
587/*
David Howells08e0e7c2007-04-26 15:55:03 -0700588 * callback.c
589 */
590extern void afs_init_callback_state(struct afs_server *);
David Howellsc435ee32017-11-02 15:27:49 +0000591extern void afs_break_callback(struct afs_vnode *);
592extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]);
593
David Howellsd2ddc772017-11-02 15:27:50 +0000594extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
David Howellsc435ee32017-11-02 15:27:49 +0000595extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
David Howellsd2ddc772017-11-02 15:27:50 +0000596extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
David Howellsc435ee32017-11-02 15:27:49 +0000597
598static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
599{
600 refcount_inc(&cbi->usage);
601 return cbi;
602}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604/*
605 * cell.c
606 */
David Howells989782d2017-11-02 15:27:50 +0000607extern int afs_cell_init(struct afs_net *, const char *);
608extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
609extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
610 const char *, bool);
David Howells8b2a4642017-11-02 15:27:50 +0000611extern struct afs_cell *afs_get_cell(struct afs_cell *);
David Howells9ed900b2017-11-02 15:27:46 +0000612extern void afs_put_cell(struct afs_net *, struct afs_cell *);
David Howells989782d2017-11-02 15:27:50 +0000613extern void afs_manage_cells(struct work_struct *);
614extern void afs_cells_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000615extern void __net_exit afs_cell_purge(struct afs_net *);
David Howells08e0e7c2007-04-26 15:55:03 -0700616
617/*
618 * cmservice.c
619 */
620extern bool afs_cm_incoming_call(struct afs_call *);
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622/*
623 * dir.c
624 */
David Howellsdab17c12017-11-02 15:27:52 +0000625extern bool afs_dir_check_page(struct inode *, struct page *);
Arjan van de Ven754661f2007-02-12 00:55:38 -0800626extern const struct inode_operations afs_dir_inode_operations;
Al Virod61dcce2011-01-12 20:04:20 -0500627extern const struct dentry_operations afs_fs_dentry_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800628extern const struct file_operations afs_dir_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630/*
631 * file.c
632 */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700633extern const struct address_space_operations afs_fs_aops;
Arjan van de Ven754661f2007-02-12 00:55:38 -0800634extern const struct inode_operations afs_file_inode_operations;
David Howells00d3b7a2007-04-26 15:57:07 -0700635extern const struct file_operations afs_file_operations;
636
637extern int afs_open(struct inode *, struct file *);
638extern int afs_release(struct inode *, struct file *);
David Howellsd2ddc772017-11-02 15:27:50 +0000639extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
Al Virof6d335c2010-05-21 15:27:09 +0100640extern int afs_page_filler(void *, struct page *);
David Howells196ee9c2017-01-05 10:38:34 +0000641extern void afs_put_read(struct afs_read *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643/*
David Howellse8d6c552007-07-15 23:40:12 -0700644 * flock.c
645 */
David Howellsf044c882017-11-02 15:27:45 +0000646extern struct workqueue_struct *afs_lock_manager;
647
David Howellse8d6c552007-07-15 23:40:12 -0700648extern void afs_lock_work(struct work_struct *);
649extern void afs_lock_may_be_available(struct afs_vnode *);
650extern int afs_lock(struct file *, int, struct file_lock *);
651extern int afs_flock(struct file *, int, struct file_lock *);
652
653/*
David Howells08e0e7c2007-04-26 15:55:03 -0700654 * fsclient.c
655 */
David Howellsd2ddc772017-11-02 15:27:50 +0000656extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
657extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
658extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
659extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
660 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
661extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
662extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
663extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
664 struct afs_fid *, struct afs_file_status *);
665extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
666 struct afs_vnode *, const char *);
David Howells8b2a4642017-11-02 15:27:50 +0000667extern int afs_fs_store_data(struct afs_fs_cursor *, struct afs_writeback *,
David Howellsd2ddc772017-11-02 15:27:50 +0000668 pgoff_t, pgoff_t, unsigned, unsigned);
669extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
670extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
671extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
672extern int afs_fs_extend_lock(struct afs_fs_cursor *);
673extern int afs_fs_release_lock(struct afs_fs_cursor *);
674extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
675 struct afs_addr_cursor *, struct key *);
676extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
677 struct afs_addr_cursor *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700678
679/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 * inode.c
681 */
David Howellsd2ddc772017-11-02 15:27:50 +0000682extern int afs_fetch_status(struct afs_vnode *, struct key *);
David Howellsc435ee32017-11-02 15:27:49 +0000683extern int afs_iget5_test(struct inode *, void *);
wangleibec5eb62010-08-11 09:38:04 +0100684extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
685 struct key *);
David Howells00d3b7a2007-04-26 15:57:07 -0700686extern struct inode *afs_iget(struct super_block *, struct key *,
David Howells260a9802007-04-26 15:59:35 -0700687 struct afs_fid *, struct afs_file_status *,
David Howellsd2ddc772017-11-02 15:27:50 +0000688 struct afs_callback *,
689 struct afs_cb_interest *);
David Howells416351f2007-05-09 02:33:45 -0700690extern void afs_zap_data(struct afs_vnode *);
David Howells260a9802007-04-26 15:59:35 -0700691extern int afs_validate(struct afs_vnode *, struct key *);
David Howellsa528d352017-01-31 16:46:22 +0000692extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
David Howells31143d52007-05-09 02:33:46 -0700693extern int afs_setattr(struct dentry *, struct iattr *);
Al Virob57922d2010-06-07 14:34:48 -0400694extern void afs_evict_inode(struct inode *);
wangleibec5eb62010-08-11 09:38:04 +0100695extern int afs_drop_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
697/*
698 * main.c
699 */
Tejun Heo0ad53ee2011-01-14 15:56:37 +0000700extern struct workqueue_struct *afs_wq;
David Howellsf044c882017-11-02 15:27:45 +0000701
702static inline struct afs_net *afs_d2net(struct dentry *dentry)
703{
704 return &__afs_net;
705}
706
707static inline struct afs_net *afs_i2net(struct inode *inode)
708{
709 return &__afs_net;
710}
711
712static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
713{
714 return &__afs_net;
715}
716
717static inline struct afs_net *afs_sock2net(struct sock *sk)
718{
719 return &__afs_net;
720}
721
722static inline struct afs_net *afs_get_net(struct afs_net *net)
723{
724 return net;
725}
726
727static inline void afs_put_net(struct afs_net *net)
728{
729}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731/*
David Howells08e0e7c2007-04-26 15:55:03 -0700732 * misc.c
733 */
734extern int afs_abort_to_error(u32);
735
736/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 * mntpt.c
738 */
Arjan van de Ven754661f2007-02-12 00:55:38 -0800739extern const struct inode_operations afs_mntpt_inode_operations;
wangleibec5eb62010-08-11 09:38:04 +0100740extern const struct inode_operations afs_autocell_inode_operations;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800741extern const struct file_operations afs_mntpt_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
David Howellsd18610b2011-01-14 19:04:05 +0000743extern struct vfsmount *afs_d_automount(struct path *);
David Howells08e0e7c2007-04-26 15:55:03 -0700744extern void afs_mntpt_kill_timer(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746/*
Arnd Bergmannb4db2b32017-02-10 16:34:07 +0000747 * netdevices.c
748 */
749extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
750
751/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 * proc.c
753 */
David Howellsf044c882017-11-02 15:27:45 +0000754extern int __net_init afs_proc_init(struct afs_net *);
755extern void __net_exit afs_proc_cleanup(struct afs_net *);
756extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
757extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
David Howells08e0e7c2007-04-26 15:55:03 -0700759/*
David Howellsd2ddc772017-11-02 15:27:50 +0000760 * rotate.c
761 */
762extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
763 struct key *);
764extern bool afs_select_fileserver(struct afs_fs_cursor *);
765extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
766extern int afs_end_vnode_operation(struct afs_fs_cursor *);
767
768/*
David Howells08e0e7c2007-04-26 15:55:03 -0700769 * rxrpc.c
770 */
David Howellsf044c882017-11-02 15:27:45 +0000771extern struct workqueue_struct *afs_async_calls;
David Howells8324f0b2016-08-30 09:49:29 +0100772
David Howellsf044c882017-11-02 15:27:45 +0000773extern int __net_init afs_open_socket(struct afs_net *);
774extern void __net_exit afs_close_socket(struct afs_net *);
775extern void afs_charge_preallocation(struct work_struct *);
David Howells341f7412017-01-05 10:38:36 +0000776extern void afs_put_call(struct afs_call *);
777extern int afs_queue_call_work(struct afs_call *);
David Howells8b2a4642017-11-02 15:27:50 +0000778extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
David Howellsf044c882017-11-02 15:27:45 +0000779extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
780 const struct afs_call_type *,
David Howells08e0e7c2007-04-26 15:55:03 -0700781 size_t, size_t);
782extern void afs_flat_call_destructor(struct afs_call *);
David Howells08e0e7c2007-04-26 15:55:03 -0700783extern void afs_send_empty_reply(struct afs_call *);
David Howellsb908fe62007-04-26 15:58:17 -0700784extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
David Howellsd0016482016-08-30 20:42:14 +0100785extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
David Howells08e0e7c2007-04-26 15:55:03 -0700786
David Howellsd0016482016-08-30 20:42:14 +0100787static inline int afs_transfer_reply(struct afs_call *call)
David Howells372ee162016-08-03 14:11:40 +0100788{
David Howellsd0016482016-08-30 20:42:14 +0100789 return afs_extract_data(call, call->buffer, call->reply_max, false);
David Howells372ee162016-08-03 14:11:40 +0100790}
791
David Howells08e0e7c2007-04-26 15:55:03 -0700792/*
David Howells00d3b7a2007-04-26 15:57:07 -0700793 * security.c
794 */
David Howellsbe080a62017-11-02 15:27:49 +0000795extern void afs_put_permits(struct afs_permits *);
David Howells00d3b7a2007-04-26 15:57:07 -0700796extern void afs_clear_permits(struct afs_vnode *);
David Howellsbe080a62017-11-02 15:27:49 +0000797extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
David Howells416351f2007-05-09 02:33:45 -0700798extern void afs_zap_permits(struct rcu_head *);
David Howells00d3b7a2007-04-26 15:57:07 -0700799extern struct key *afs_request_key(struct afs_cell *);
Al Viro10556cb2011-06-20 19:28:19 -0400800extern int afs_permission(struct inode *, int);
David Howellsbe080a62017-11-02 15:27:49 +0000801extern void __exit afs_clean_up_permit_cache(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700802
803/*
David Howells08e0e7c2007-04-26 15:55:03 -0700804 * server.c
805 */
806extern spinlock_t afs_server_peer_lock;
807
David Howellsc435ee32017-11-02 15:27:49 +0000808static inline struct afs_server *afs_get_server(struct afs_server *server)
809{
810 atomic_inc(&server->usage);
811 return server;
812}
David Howells08e0e7c2007-04-26 15:55:03 -0700813
David Howellsf044c882017-11-02 15:27:45 +0000814extern struct afs_server *afs_find_server(struct afs_net *,
815 const struct sockaddr_rxrpc *);
David Howellsd2ddc772017-11-02 15:27:50 +0000816extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
817extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
David Howells9ed900b2017-11-02 15:27:46 +0000818extern void afs_put_server(struct afs_net *, struct afs_server *);
David Howellsd2ddc772017-11-02 15:27:50 +0000819extern void afs_manage_servers(struct work_struct *);
820extern void afs_servers_timer(struct timer_list *);
David Howellsf044c882017-11-02 15:27:45 +0000821extern void __net_exit afs_purge_servers(struct afs_net *);
David Howellsd2ddc772017-11-02 15:27:50 +0000822extern bool afs_probe_fileserver(struct afs_fs_cursor *);
823extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
824
825/*
826 * server_list.c
827 */
828static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
829{
830 refcount_inc(&slist->usage);
831 return slist;
832}
833
834extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
835extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
836 struct afs_vldb_entry *,
837 u8);
838extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
David Howells08e0e7c2007-04-26 15:55:03 -0700839
840/*
David Howells00d3b7a2007-04-26 15:57:07 -0700841 * super.c
842 */
David Howellsf044c882017-11-02 15:27:45 +0000843extern int __init afs_fs_init(void);
844extern void __exit afs_fs_exit(void);
David Howells00d3b7a2007-04-26 15:57:07 -0700845
846/*
David Howells08e0e7c2007-04-26 15:55:03 -0700847 * vlclient.c
848 */
David Howellsd2ddc772017-11-02 15:27:50 +0000849extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
850 struct afs_addr_cursor *,
851 struct key *, const char *, int);
852extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
853 struct key *, const uuid_t *);
David Howellsbf99a532017-11-02 15:27:51 +0000854extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
855extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
856 struct key *, const uuid_t *);
David Howells08e0e7c2007-04-26 15:55:03 -0700857
858/*
859 * volume.c
860 */
David Howellsd2ddc772017-11-02 15:27:50 +0000861static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
David Howells49566f62017-11-02 15:27:46 +0000862{
863 if (volume)
864 atomic_inc(&volume->usage);
865 return volume;
866}
David Howells08e0e7c2007-04-26 15:55:03 -0700867
David Howellsd2ddc772017-11-02 15:27:50 +0000868extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
869extern void afs_activate_volume(struct afs_volume *);
870extern void afs_deactivate_volume(struct afs_volume *);
David Howells9ed900b2017-11-02 15:27:46 +0000871extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
David Howellsd2ddc772017-11-02 15:27:50 +0000872extern int afs_check_volume_status(struct afs_volume *, struct key *);
David Howells08e0e7c2007-04-26 15:55:03 -0700873
David Howells31143d52007-05-09 02:33:46 -0700874/*
875 * write.c
876 */
877extern int afs_set_page_dirty(struct page *);
878extern void afs_put_writeback(struct afs_writeback *);
Nick Piggin15b46502008-10-15 22:04:32 -0700879extern int afs_write_begin(struct file *file, struct address_space *mapping,
880 loff_t pos, unsigned len, unsigned flags,
881 struct page **pagep, void **fsdata);
882extern int afs_write_end(struct file *file, struct address_space *mapping,
883 loff_t pos, unsigned len, unsigned copied,
884 struct page *page, void *fsdata);
David Howells31143d52007-05-09 02:33:46 -0700885extern int afs_writepage(struct page *, struct writeback_control *);
886extern int afs_writepages(struct address_space *, struct writeback_control *);
David Howells31143d52007-05-09 02:33:46 -0700887extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
Al Viro50b55512014-04-03 14:13:46 -0400888extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
David Howells31143d52007-05-09 02:33:46 -0700889extern int afs_writeback_all(struct afs_vnode *);
David Howells58fed942017-03-16 16:27:45 +0000890extern int afs_flush(struct file *, fl_owner_t);
Josef Bacik02c24a82011-07-16 20:44:56 -0400891extern int afs_fsync(struct file *, loff_t, loff_t, int);
David Howells31143d52007-05-09 02:33:46 -0700892
David Howellsd3e3b7ea2017-07-06 15:50:27 +0100893/*
894 * xattr.c
895 */
896extern const struct xattr_handler *afs_xattr_handlers[];
897extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
David Howells31143d52007-05-09 02:33:46 -0700898
David Howellsd2ddc772017-11-02 15:27:50 +0000899
900/*
901 * Miscellaneous inline functions.
902 */
903static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
904{
905 return container_of(inode, struct afs_vnode, vfs_inode);
906}
907
908static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
909{
910 return &vnode->vfs_inode;
911}
912
913static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
914 struct afs_vnode *vnode,
915 unsigned int cb_break)
916{
917 if (fc->ac.error == 0)
918 afs_cache_permit(vnode, fc->key, cb_break);
919}
920
921static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
922 struct afs_vnode *vnode)
923{
924 if (fc->ac.error == -ENOENT) {
925 set_bit(AFS_VNODE_DELETED, &vnode->flags);
926 afs_break_callback(vnode);
927 }
928}
929
930
David Howells08e0e7c2007-04-26 15:55:03 -0700931/*****************************************************************************/
932/*
933 * debug tracing
934 */
David Howells8e8d7f12017-01-05 10:38:34 +0000935#include <trace/events/afs.h>
936
David Howells08e0e7c2007-04-26 15:55:03 -0700937extern unsigned afs_debug;
938
939#define dbgprintk(FMT,...) \
Sven Schnellead16df82008-04-03 10:44:01 +0100940 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -0700941
Harvey Harrison530b6412008-04-30 00:55:09 -0700942#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
943#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -0700944#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
945
946
947#if defined(__KDEBUG)
948#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
949#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
950#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
951
952#elif defined(CONFIG_AFS_DEBUG)
953#define AFS_DEBUG_KENTER 0x01
954#define AFS_DEBUG_KLEAVE 0x02
955#define AFS_DEBUG_KDEBUG 0x04
956
957#define _enter(FMT,...) \
958do { \
959 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
960 kenter(FMT,##__VA_ARGS__); \
961} while (0)
962
963#define _leave(FMT,...) \
964do { \
965 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
966 kleave(FMT,##__VA_ARGS__); \
967} while (0)
968
969#define _debug(FMT,...) \
970do { \
971 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
972 kdebug(FMT,##__VA_ARGS__); \
973} while (0)
974
975#else
David Howells12fdff32010-08-12 16:54:57 +0100976#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
977#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
978#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
David Howells08e0e7c2007-04-26 15:55:03 -0700979#endif
980
981/*
982 * debug assertion checking
983 */
984#if 1 // defined(__KDEBUGALL)
985
986#define ASSERT(X) \
987do { \
988 if (unlikely(!(X))) { \
989 printk(KERN_ERR "\n"); \
990 printk(KERN_ERR "AFS: Assertion failed\n"); \
991 BUG(); \
992 } \
993} while(0)
994
995#define ASSERTCMP(X, OP, Y) \
996do { \
997 if (unlikely(!((X) OP (Y)))) { \
998 printk(KERN_ERR "\n"); \
999 printk(KERN_ERR "AFS: Assertion failed\n"); \
1000 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1001 (unsigned long)(X), (unsigned long)(Y)); \
1002 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1003 (unsigned long)(X), (unsigned long)(Y)); \
1004 BUG(); \
1005 } \
1006} while(0)
1007
David Howells416351f2007-05-09 02:33:45 -07001008#define ASSERTRANGE(L, OP1, N, OP2, H) \
1009do { \
1010 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1011 printk(KERN_ERR "\n"); \
1012 printk(KERN_ERR "AFS: Assertion failed\n"); \
1013 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1014 (unsigned long)(L), (unsigned long)(N), \
1015 (unsigned long)(H)); \
1016 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1017 (unsigned long)(L), (unsigned long)(N), \
1018 (unsigned long)(H)); \
1019 BUG(); \
1020 } \
1021} while(0)
1022
David Howells08e0e7c2007-04-26 15:55:03 -07001023#define ASSERTIF(C, X) \
1024do { \
1025 if (unlikely((C) && !(X))) { \
1026 printk(KERN_ERR "\n"); \
1027 printk(KERN_ERR "AFS: Assertion failed\n"); \
1028 BUG(); \
1029 } \
1030} while(0)
1031
1032#define ASSERTIFCMP(C, X, OP, Y) \
1033do { \
1034 if (unlikely((C) && !((X) OP (Y)))) { \
1035 printk(KERN_ERR "\n"); \
1036 printk(KERN_ERR "AFS: Assertion failed\n"); \
1037 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1038 (unsigned long)(X), (unsigned long)(Y)); \
1039 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1040 (unsigned long)(X), (unsigned long)(Y)); \
1041 BUG(); \
1042 } \
1043} while(0)
1044
1045#else
1046
1047#define ASSERT(X) \
1048do { \
1049} while(0)
1050
1051#define ASSERTCMP(X, OP, Y) \
1052do { \
1053} while(0)
1054
David Howells416351f2007-05-09 02:33:45 -07001055#define ASSERTRANGE(L, OP1, N, OP2, H) \
1056do { \
1057} while(0)
1058
David Howells08e0e7c2007-04-26 15:55:03 -07001059#define ASSERTIF(C, X) \
1060do { \
1061} while(0)
1062
1063#define ASSERTIFCMP(C, X, OP, Y) \
1064do { \
1065} while(0)
1066
1067#endif /* __KDEBUGALL */