]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/afs/internal.h
afs: Overhaul volume and server record caching and fileserver rotation
[mirror_ubuntu-bionic-kernel.git] / fs / afs / internal.h
1 /* internal AFS stuff
2 *
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
4 * 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
12 #include <linux/compiler.h>
13 #include <linux/kernel.h>
14 #include <linux/ktime.h>
15 #include <linux/fs.h>
16 #include <linux/pagemap.h>
17 #include <linux/rxrpc.h>
18 #include <linux/key.h>
19 #include <linux/workqueue.h>
20 #include <linux/sched.h>
21 #include <linux/fscache.h>
22 #include <linux/backing-dev.h>
23 #include <linux/uuid.h>
24 #include <net/net_namespace.h>
25 #include <net/af_rxrpc.h>
26
27 #include "afs.h"
28 #include "afs_vl.h"
29
30 #define AFS_CELL_MAX_ADDRS 15
31
32 struct pagevec;
33 struct afs_call;
34
35 struct afs_mount_params {
36 bool rwpath; /* T if the parent should be considered R/W */
37 bool force; /* T to force cell type */
38 bool autocell; /* T if set auto mount operation */
39 afs_voltype_t type; /* type of volume requested */
40 int volnamesz; /* size of volume name */
41 const char *volname; /* name of volume to mount */
42 struct afs_net *net; /* Network namespace in effect */
43 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
48 struct afs_iget_data {
49 struct afs_fid fid;
50 struct afs_volume *volume; /* volume on which resides */
51 };
52
53 enum 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 };
62
63 /*
64 * List of server addresses.
65 */
66 struct afs_addr_list {
67 struct rcu_head rcu; /* Must be first */
68 refcount_t usage;
69 u32 version; /* Version */
70 unsigned short nr_addrs;
71 unsigned short index; /* Address currently in use */
72 unsigned short nr_ipv4; /* Number of IPv4 addresses */
73 struct sockaddr_rxrpc addrs[];
74 };
75
76 /*
77 * a record of an in-progress RxRPC call
78 */
79 struct afs_call {
80 const struct afs_call_type *type; /* type of call */
81 wait_queue_head_t waitq; /* processes awaiting completion */
82 struct work_struct async_work; /* async I/O processor */
83 struct work_struct work; /* actual work processor */
84 struct rxrpc_call *rxcall; /* RxRPC call handle */
85 struct key *key; /* security for this call */
86 struct afs_net *net; /* The network namespace */
87 struct afs_server *cm_server; /* Server affected by incoming CM call */
88 struct afs_cb_interest *cbi; /* Callback interest for server used */
89 void *request; /* request data (first part) */
90 struct address_space *mapping; /* page set */
91 struct afs_writeback *wb; /* writeback being performed */
92 void *buffer; /* reply receive buffer */
93 void *reply[4]; /* Where to put the reply */
94 pgoff_t first; /* first page in mapping to deal with */
95 pgoff_t last; /* last page in mapping to deal with */
96 size_t offset; /* offset into received data store */
97 atomic_t usage;
98 enum afs_call_state state;
99 int error; /* error code */
100 u32 abort_code; /* Remote abort ID or 0 */
101 unsigned request_size; /* size of request data */
102 unsigned reply_max; /* maximum size of reply */
103 unsigned first_offset; /* offset into mapping[first] */
104 unsigned int cb_break; /* cb_break + cb_s_break before the call */
105 union {
106 unsigned last_to; /* amount of mapping[last] */
107 unsigned count2; /* count used in unmarshalling */
108 };
109 unsigned char unmarshall; /* unmarshalling phase */
110 bool incoming; /* T if incoming call */
111 bool send_pages; /* T if data from mapping should be sent */
112 bool need_attention; /* T if RxRPC poked us */
113 bool async; /* T if asynchronous */
114 bool ret_reply0; /* T if should return reply[0] on success */
115 bool upgrade; /* T to request service upgrade */
116 u16 service_id; /* RxRPC service ID to call */
117 u32 operation_ID; /* operation ID for an incoming call */
118 u32 count; /* count for use in unmarshalling */
119 __be32 tmp; /* place to extract temporary data */
120 afs_dataversion_t store_version; /* updated version expected from store */
121 };
122
123 struct afs_call_type {
124 const char *name;
125
126 /* deliver request or reply data to an call
127 * - returning an error will cause the call to be aborted
128 */
129 int (*deliver)(struct afs_call *call);
130
131 /* clean up a call */
132 void (*destructor)(struct afs_call *call);
133
134 /* Work function */
135 void (*work)(struct work_struct *work);
136 };
137
138 /*
139 * Record of an outstanding read operation on a vnode.
140 */
141 struct afs_read {
142 loff_t pos; /* Where to start reading */
143 loff_t len; /* How much we're asking for */
144 loff_t actual_len; /* How much we're actually getting */
145 loff_t remain; /* Amount remaining */
146 atomic_t usage;
147 unsigned int index; /* Which page we're reading into */
148 unsigned int nr_pages;
149 void (*page_done)(struct afs_call *, struct afs_read *);
150 struct page *pages[];
151 };
152
153 /*
154 * record of an outstanding writeback on a vnode
155 */
156 struct afs_writeback {
157 struct list_head link; /* link in vnode->writebacks */
158 struct work_struct writer; /* work item to perform the writeback */
159 struct afs_vnode *vnode; /* vnode to which this write applies */
160 struct key *key; /* owner of this write */
161 wait_queue_head_t waitq; /* completion and ready wait queue */
162 pgoff_t first; /* first page in batch */
163 pgoff_t point; /* last page in current store op */
164 pgoff_t last; /* last page in batch (inclusive) */
165 unsigned offset_first; /* offset into first page of start of write */
166 unsigned to_last; /* offset into last page of end of write */
167 int num_conflicts; /* count of conflicting writes in list */
168 int usage;
169 bool conflicts; /* T if has dependent conflicts */
170 enum {
171 AFS_WBACK_SYNCING, /* synchronisation being performed */
172 AFS_WBACK_PENDING, /* write pending */
173 AFS_WBACK_CONFLICTING, /* conflicting writes posted */
174 AFS_WBACK_WRITING, /* writing back */
175 AFS_WBACK_COMPLETE /* the writeback record has been unlinked */
176 } state __attribute__((packed));
177 };
178
179 /*
180 * AFS superblock private data
181 * - there's one superblock per volume
182 */
183 struct afs_super_info {
184 struct afs_net *net; /* Network namespace */
185 struct afs_cell *cell; /* The cell in which the volume resides */
186 struct afs_volume *volume; /* volume record */
187 };
188
189 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
190 {
191 return sb->s_fs_info;
192 }
193
194 extern struct file_system_type afs_fs_type;
195
196 /*
197 * AFS network namespace record.
198 */
199 struct 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 */
212 struct rb_root cells;
213 struct afs_cell *ws_cell;
214 struct work_struct cells_manager;
215 struct timer_list cells_timer;
216 atomic_t cells_outstanding;
217 seqlock_t cells_lock;
218
219 spinlock_t proc_cells_lock;
220 struct list_head proc_cells;
221
222 /* 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;
238
239 /* File locking renewal management */
240 struct mutex lock_manager_mutex;
241
242 /* Misc */
243 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
244 };
245
246 extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
247
248 enum 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
257 /*
258 * 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.
273 */
274 struct afs_cell {
275 union {
276 struct rcu_head rcu;
277 struct rb_node net_node; /* Node in net->cells */
278 };
279 struct afs_net *net;
280 struct key *anonymous_key; /* anonymous user key for this cell */
281 struct work_struct manager; /* Manager for init/deinit/dns */
282 struct list_head proc_link; /* /proc cell list link */
283 #ifdef CONFIG_AFS_FSCACHE
284 struct fscache_cookie *cache; /* caching cookie */
285 #endif
286 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 */
294 #define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
295 enum afs_cell_state state;
296 short error;
297
298 /* Active fileserver interaction state. */
299 struct list_head proc_volumes; /* procfs volume list */
300 rwlock_t proc_lock;
301
302 /* VL server list. */
303 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
304 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
305 u8 name_len; /* Length of name */
306 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
307 };
308
309 /*
310 * Cached VLDB entry.
311 *
312 * This is pointed to by cell->vldb_entries, indexed by name.
313 */
314 struct afs_vldb_entry {
315 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
316
317 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];
326 #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) */
329 short error;
330 u8 nr_servers; /* Number of server records */
331 u8 name_len;
332 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
333 };
334
335 /*
336 * Record of fileserver with which we're actively communicating.
337 */
338 struct afs_server {
339 struct rcu_head rcu;
340 union {
341 uuid_t uuid; /* Server ID */
342 struct afs_uuid _uuid;
343 };
344
345 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 */
353 unsigned long flags;
354 #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 */
363
364 /* file service access */
365 rwlock_t fs_lock; /* access lock */
366
367 /* callback promise management */
368 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 */
376 struct 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;
382 };
383
384 /*
385 * Replaceable server list.
386 */
387 struct afs_server_entry {
388 struct afs_server *server;
389 struct afs_cb_interest *cb_interest;
390 };
391
392 struct 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[];
399 };
400
401 /*
402 * Live AFS volume management.
403 */
404 struct 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 */
429 };
430
431 /*
432 * AFS inode private data
433 */
434 struct afs_vnode {
435 struct inode vfs_inode; /* the VFS's inode record */
436
437 struct afs_volume *volume; /* volume on which vnode resides */
438 struct afs_fid fid; /* the file identifier for this inode */
439 struct afs_file_status status; /* AFS status info for this file */
440 #ifdef CONFIG_AFS_FSCACHE
441 struct fscache_cookie *cache; /* caching cookie */
442 #endif
443 struct afs_permits *permit_cache; /* cache of permits so far obtained */
444 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
445 struct mutex validate_lock; /* lock for validating this vnode */
446 spinlock_t writeback_lock; /* lock for writebacks */
447 spinlock_t lock; /* waitqueue/flags lock */
448 unsigned long flags;
449 #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
450 #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
451 #define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */
452 #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 */
455 #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 */
459 #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 */
461
462 struct list_head writebacks; /* alterations in pagecache that need writing */
463 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 */
467
468 /* outstanding callback notification on this file */
469 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 */
475 unsigned cb_version; /* callback version */
476 afs_callback_type_t cb_type; /* type of callback */
477 };
478
479 /*
480 * cached security record for one user's attempt to access a vnode
481 */
482 struct afs_permit {
483 struct key *key; /* RxRPC ticket holding a security context */
484 afs_access_t access; /* CallerAccess value for this key */
485 };
486
487 /*
488 * Immutable cache of CallerAccess records from attempts to access vnodes.
489 * These may be shared between multiple vnodes.
490 */
491 struct afs_permits {
492 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 */
499 };
500
501 /*
502 * record of one of a system's set of network interfaces
503 */
504 struct afs_interface {
505 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
510 /*
511 * Cursor for iterating over a server's address list.
512 */
513 struct afs_addr_cursor {
514 struct afs_addr_list *alist; /* Current address list (pins ref) */
515 struct sockaddr_rxrpc *addr;
516 u32 abort_code;
517 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 */
527 struct afs_fs_cursor {
528 struct afs_addr_cursor ac;
529 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, ... */
544 };
545
546 /*****************************************************************************/
547 /*
548 * addr_list.c
549 */
550 static 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 }
556 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
557 unsigned short,
558 unsigned short);
559 extern void afs_put_addrlist(struct afs_addr_list *);
560 extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
561 unsigned short, unsigned short);
562 extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
563 extern bool afs_iterate_addresses(struct afs_addr_cursor *);
564 extern int afs_end_cursor(struct afs_addr_cursor *);
565 extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
566
567 extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32);
568
569 /*
570 * cache.c
571 */
572 #ifdef CONFIG_AFS_FSCACHE
573 extern struct fscache_netfs afs_cache_netfs;
574 extern struct fscache_cookie_def afs_cell_cache_index_def;
575 extern struct fscache_cookie_def afs_volume_cache_index_def;
576 extern struct fscache_cookie_def afs_vnode_cache_index_def;
577 #else
578 #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
579 #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
580 #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
581 #endif
582
583 /*
584 * callback.c
585 */
586 extern void afs_init_callback_state(struct afs_server *);
587 extern void afs_break_callback(struct afs_vnode *);
588 extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]);
589
590 extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *);
591 extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
592 extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
593
594 static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
595 {
596 refcount_inc(&cbi->usage);
597 return cbi;
598 }
599
600 /*
601 * cell.c
602 */
603 extern int afs_cell_init(struct afs_net *, const char *);
604 extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
605 extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
606 const char *, bool);
607 extern struct afs_cell *afs_get_cell(struct afs_cell *);
608 extern void afs_put_cell(struct afs_net *, struct afs_cell *);
609 extern void afs_manage_cells(struct work_struct *);
610 extern void afs_cells_timer(struct timer_list *);
611 extern void __net_exit afs_cell_purge(struct afs_net *);
612
613 /*
614 * cmservice.c
615 */
616 extern bool afs_cm_incoming_call(struct afs_call *);
617
618 /*
619 * dir.c
620 */
621 extern const struct inode_operations afs_dir_inode_operations;
622 extern const struct dentry_operations afs_fs_dentry_operations;
623 extern const struct file_operations afs_dir_file_operations;
624
625 /*
626 * file.c
627 */
628 extern const struct address_space_operations afs_fs_aops;
629 extern const struct inode_operations afs_file_inode_operations;
630 extern const struct file_operations afs_file_operations;
631
632 extern int afs_open(struct inode *, struct file *);
633 extern int afs_release(struct inode *, struct file *);
634 extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
635 extern int afs_page_filler(void *, struct page *);
636 extern void afs_put_read(struct afs_read *);
637
638 /*
639 * flock.c
640 */
641 extern struct workqueue_struct *afs_lock_manager;
642
643 extern void afs_lock_work(struct work_struct *);
644 extern void afs_lock_may_be_available(struct afs_vnode *);
645 extern int afs_lock(struct file *, int, struct file_lock *);
646 extern int afs_flock(struct file *, int, struct file_lock *);
647
648 /*
649 * fsclient.c
650 */
651 extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
652 extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
653 extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
654 extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
655 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
656 extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
657 extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
658 extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
659 struct afs_fid *, struct afs_file_status *);
660 extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
661 struct afs_vnode *, const char *);
662 extern int afs_fs_store_data(struct afs_fs_cursor *, struct afs_writeback *,
663 pgoff_t, pgoff_t, unsigned, unsigned);
664 extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
665 extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
666 extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
667 extern int afs_fs_extend_lock(struct afs_fs_cursor *);
668 extern int afs_fs_release_lock(struct afs_fs_cursor *);
669 extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
670 struct afs_addr_cursor *, struct key *);
671 extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
672 struct afs_addr_cursor *, struct key *);
673
674 /*
675 * inode.c
676 */
677 extern int afs_fetch_status(struct afs_vnode *, struct key *);
678 extern int afs_iget5_test(struct inode *, void *);
679 extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
680 struct key *);
681 extern struct inode *afs_iget(struct super_block *, struct key *,
682 struct afs_fid *, struct afs_file_status *,
683 struct afs_callback *,
684 struct afs_cb_interest *);
685 extern void afs_zap_data(struct afs_vnode *);
686 extern int afs_validate(struct afs_vnode *, struct key *);
687 extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
688 extern int afs_setattr(struct dentry *, struct iattr *);
689 extern void afs_evict_inode(struct inode *);
690 extern int afs_drop_inode(struct inode *);
691
692 /*
693 * main.c
694 */
695 extern struct workqueue_struct *afs_wq;
696
697 static inline struct afs_net *afs_d2net(struct dentry *dentry)
698 {
699 return &__afs_net;
700 }
701
702 static inline struct afs_net *afs_i2net(struct inode *inode)
703 {
704 return &__afs_net;
705 }
706
707 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
708 {
709 return &__afs_net;
710 }
711
712 static inline struct afs_net *afs_sock2net(struct sock *sk)
713 {
714 return &__afs_net;
715 }
716
717 static inline struct afs_net *afs_get_net(struct afs_net *net)
718 {
719 return net;
720 }
721
722 static inline void afs_put_net(struct afs_net *net)
723 {
724 }
725
726 /*
727 * misc.c
728 */
729 extern int afs_abort_to_error(u32);
730
731 /*
732 * mntpt.c
733 */
734 extern const struct inode_operations afs_mntpt_inode_operations;
735 extern const struct inode_operations afs_autocell_inode_operations;
736 extern const struct file_operations afs_mntpt_file_operations;
737
738 extern struct vfsmount *afs_d_automount(struct path *);
739 extern void afs_mntpt_kill_timer(void);
740
741 /*
742 * netdevices.c
743 */
744 extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
745
746 /*
747 * proc.c
748 */
749 extern int __net_init afs_proc_init(struct afs_net *);
750 extern void __net_exit afs_proc_cleanup(struct afs_net *);
751 extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
752 extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
753
754 /*
755 * rotate.c
756 */
757 extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
758 struct key *);
759 extern bool afs_select_fileserver(struct afs_fs_cursor *);
760 extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
761 extern int afs_end_vnode_operation(struct afs_fs_cursor *);
762
763 /*
764 * rxrpc.c
765 */
766 extern struct workqueue_struct *afs_async_calls;
767
768 extern int __net_init afs_open_socket(struct afs_net *);
769 extern void __net_exit afs_close_socket(struct afs_net *);
770 extern void afs_charge_preallocation(struct work_struct *);
771 extern void afs_put_call(struct afs_call *);
772 extern int afs_queue_call_work(struct afs_call *);
773 extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
774 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
775 const struct afs_call_type *,
776 size_t, size_t);
777 extern void afs_flat_call_destructor(struct afs_call *);
778 extern void afs_send_empty_reply(struct afs_call *);
779 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
780 extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
781
782 static inline int afs_transfer_reply(struct afs_call *call)
783 {
784 return afs_extract_data(call, call->buffer, call->reply_max, false);
785 }
786
787 /*
788 * security.c
789 */
790 extern void afs_put_permits(struct afs_permits *);
791 extern void afs_clear_permits(struct afs_vnode *);
792 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
793 extern void afs_zap_permits(struct rcu_head *);
794 extern struct key *afs_request_key(struct afs_cell *);
795 extern int afs_permission(struct inode *, int);
796 extern void __exit afs_clean_up_permit_cache(void);
797
798 /*
799 * server.c
800 */
801 extern spinlock_t afs_server_peer_lock;
802
803 static inline struct afs_server *afs_get_server(struct afs_server *server)
804 {
805 atomic_inc(&server->usage);
806 return server;
807 }
808
809 extern struct afs_server *afs_find_server(struct afs_net *,
810 const struct sockaddr_rxrpc *);
811 extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
812 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
813 extern void afs_put_server(struct afs_net *, struct afs_server *);
814 extern void afs_manage_servers(struct work_struct *);
815 extern void afs_servers_timer(struct timer_list *);
816 extern void __net_exit afs_purge_servers(struct afs_net *);
817 extern bool afs_probe_fileserver(struct afs_fs_cursor *);
818 extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
819
820 /*
821 * server_list.c
822 */
823 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
824 {
825 refcount_inc(&slist->usage);
826 return slist;
827 }
828
829 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
830 extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
831 struct afs_vldb_entry *,
832 u8);
833 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
834
835 /*
836 * super.c
837 */
838 extern int __init afs_fs_init(void);
839 extern void __exit afs_fs_exit(void);
840
841 /*
842 * vlclient.c
843 */
844 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
845 struct afs_addr_cursor *,
846 struct key *, const char *, int);
847 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
848 struct key *, const uuid_t *);
849
850 /*
851 * volume.c
852 */
853 static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
854 {
855 if (volume)
856 atomic_inc(&volume->usage);
857 return volume;
858 }
859
860 extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
861 extern void afs_activate_volume(struct afs_volume *);
862 extern void afs_deactivate_volume(struct afs_volume *);
863 extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
864 extern int afs_check_volume_status(struct afs_volume *, struct key *);
865
866 /*
867 * write.c
868 */
869 extern int afs_set_page_dirty(struct page *);
870 extern void afs_put_writeback(struct afs_writeback *);
871 extern int afs_write_begin(struct file *file, struct address_space *mapping,
872 loff_t pos, unsigned len, unsigned flags,
873 struct page **pagep, void **fsdata);
874 extern int afs_write_end(struct file *file, struct address_space *mapping,
875 loff_t pos, unsigned len, unsigned copied,
876 struct page *page, void *fsdata);
877 extern int afs_writepage(struct page *, struct writeback_control *);
878 extern int afs_writepages(struct address_space *, struct writeback_control *);
879 extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
880 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
881 extern int afs_writeback_all(struct afs_vnode *);
882 extern int afs_flush(struct file *, fl_owner_t);
883 extern int afs_fsync(struct file *, loff_t, loff_t, int);
884
885 /*
886 * xattr.c
887 */
888 extern const struct xattr_handler *afs_xattr_handlers[];
889 extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
890
891
892 /*
893 * Miscellaneous inline functions.
894 */
895 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
896 {
897 return container_of(inode, struct afs_vnode, vfs_inode);
898 }
899
900 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
901 {
902 return &vnode->vfs_inode;
903 }
904
905 static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
906 struct afs_vnode *vnode,
907 unsigned int cb_break)
908 {
909 if (fc->ac.error == 0)
910 afs_cache_permit(vnode, fc->key, cb_break);
911 }
912
913 static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
914 struct afs_vnode *vnode)
915 {
916 if (fc->ac.error == -ENOENT) {
917 set_bit(AFS_VNODE_DELETED, &vnode->flags);
918 afs_break_callback(vnode);
919 }
920 }
921
922
923 /*****************************************************************************/
924 /*
925 * debug tracing
926 */
927 #include <trace/events/afs.h>
928
929 extern unsigned afs_debug;
930
931 #define dbgprintk(FMT,...) \
932 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
933
934 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
935 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
936 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
937
938
939 #if defined(__KDEBUG)
940 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
941 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
942 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
943
944 #elif defined(CONFIG_AFS_DEBUG)
945 #define AFS_DEBUG_KENTER 0x01
946 #define AFS_DEBUG_KLEAVE 0x02
947 #define AFS_DEBUG_KDEBUG 0x04
948
949 #define _enter(FMT,...) \
950 do { \
951 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
952 kenter(FMT,##__VA_ARGS__); \
953 } while (0)
954
955 #define _leave(FMT,...) \
956 do { \
957 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
958 kleave(FMT,##__VA_ARGS__); \
959 } while (0)
960
961 #define _debug(FMT,...) \
962 do { \
963 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
964 kdebug(FMT,##__VA_ARGS__); \
965 } while (0)
966
967 #else
968 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
969 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
970 #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
971 #endif
972
973 /*
974 * debug assertion checking
975 */
976 #if 1 // defined(__KDEBUGALL)
977
978 #define ASSERT(X) \
979 do { \
980 if (unlikely(!(X))) { \
981 printk(KERN_ERR "\n"); \
982 printk(KERN_ERR "AFS: Assertion failed\n"); \
983 BUG(); \
984 } \
985 } while(0)
986
987 #define ASSERTCMP(X, OP, Y) \
988 do { \
989 if (unlikely(!((X) OP (Y)))) { \
990 printk(KERN_ERR "\n"); \
991 printk(KERN_ERR "AFS: Assertion failed\n"); \
992 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
993 (unsigned long)(X), (unsigned long)(Y)); \
994 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
995 (unsigned long)(X), (unsigned long)(Y)); \
996 BUG(); \
997 } \
998 } while(0)
999
1000 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1001 do { \
1002 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1003 printk(KERN_ERR "\n"); \
1004 printk(KERN_ERR "AFS: Assertion failed\n"); \
1005 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1006 (unsigned long)(L), (unsigned long)(N), \
1007 (unsigned long)(H)); \
1008 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1009 (unsigned long)(L), (unsigned long)(N), \
1010 (unsigned long)(H)); \
1011 BUG(); \
1012 } \
1013 } while(0)
1014
1015 #define ASSERTIF(C, X) \
1016 do { \
1017 if (unlikely((C) && !(X))) { \
1018 printk(KERN_ERR "\n"); \
1019 printk(KERN_ERR "AFS: Assertion failed\n"); \
1020 BUG(); \
1021 } \
1022 } while(0)
1023
1024 #define ASSERTIFCMP(C, X, OP, Y) \
1025 do { \
1026 if (unlikely((C) && !((X) OP (Y)))) { \
1027 printk(KERN_ERR "\n"); \
1028 printk(KERN_ERR "AFS: Assertion failed\n"); \
1029 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1030 (unsigned long)(X), (unsigned long)(Y)); \
1031 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1032 (unsigned long)(X), (unsigned long)(Y)); \
1033 BUG(); \
1034 } \
1035 } while(0)
1036
1037 #else
1038
1039 #define ASSERT(X) \
1040 do { \
1041 } while(0)
1042
1043 #define ASSERTCMP(X, OP, Y) \
1044 do { \
1045 } while(0)
1046
1047 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1048 do { \
1049 } while(0)
1050
1051 #define ASSERTIF(C, X) \
1052 do { \
1053 } while(0)
1054
1055 #define ASSERTIFCMP(C, X, OP, Y) \
1056 do { \
1057 } while(0)
1058
1059 #endif /* __KDEBUGALL */