]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/afs/internal.h
s390/crypto: Fix return code checking in cbc_paes_crypt()
[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_CL_REQUESTING, /* Client: Request is being sent */
55 AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
56 AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
57 AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
58 AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
59 AFS_CALL_SV_REPLYING, /* Server: Replying */
60 AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
61 AFS_CALL_COMPLETE, /* Completed or failed */
62 };
63
64 /*
65 * List of server addresses.
66 */
67 struct afs_addr_list {
68 struct rcu_head rcu; /* Must be first */
69 refcount_t usage;
70 u32 version; /* Version */
71 unsigned short nr_addrs;
72 unsigned short index; /* Address currently in use */
73 unsigned short nr_ipv4; /* Number of IPv4 addresses */
74 unsigned long probed; /* Mask of servers that have been probed */
75 unsigned long yfs; /* Mask of servers that are YFS */
76 struct sockaddr_rxrpc addrs[];
77 };
78
79 /*
80 * a record of an in-progress RxRPC call
81 */
82 struct afs_call {
83 const struct afs_call_type *type; /* type of call */
84 wait_queue_head_t waitq; /* processes awaiting completion */
85 struct work_struct async_work; /* async I/O processor */
86 struct work_struct work; /* actual work processor */
87 struct rxrpc_call *rxcall; /* RxRPC call handle */
88 struct key *key; /* security for this call */
89 struct afs_net *net; /* The network namespace */
90 struct afs_server *cm_server; /* Server affected by incoming CM call */
91 struct afs_cb_interest *cbi; /* Callback interest for server used */
92 void *request; /* request data (first part) */
93 struct address_space *mapping; /* Pages being written from */
94 void *buffer; /* reply receive buffer */
95 void *reply[4]; /* Where to put the reply */
96 pgoff_t first; /* first page in mapping to deal with */
97 pgoff_t last; /* last page in mapping to deal with */
98 size_t offset; /* offset into received data store */
99 atomic_t usage;
100 enum afs_call_state state;
101 spinlock_t state_lock;
102 int error; /* error code */
103 u32 abort_code; /* Remote abort ID or 0 */
104 unsigned request_size; /* size of request data */
105 unsigned reply_max; /* maximum size of reply */
106 unsigned first_offset; /* offset into mapping[first] */
107 unsigned int cb_break; /* cb_break + cb_s_break before the call */
108 union {
109 unsigned last_to; /* amount of mapping[last] */
110 unsigned count2; /* count used in unmarshalling */
111 };
112 unsigned char unmarshall; /* unmarshalling phase */
113 bool incoming; /* T if incoming call */
114 bool send_pages; /* T if data from mapping should be sent */
115 bool need_attention; /* T if RxRPC poked us */
116 bool async; /* T if asynchronous */
117 bool ret_reply0; /* T if should return reply[0] on success */
118 bool upgrade; /* T to request service upgrade */
119 u16 service_id; /* Actual service ID (after upgrade) */
120 u32 operation_ID; /* operation ID for an incoming call */
121 u32 count; /* count for use in unmarshalling */
122 __be32 tmp; /* place to extract temporary data */
123 afs_dataversion_t store_version; /* updated version expected from store */
124 };
125
126 struct afs_call_type {
127 const char *name;
128 unsigned int op; /* Really enum afs_fs_operation */
129
130 /* deliver request or reply data to an call
131 * - returning an error will cause the call to be aborted
132 */
133 int (*deliver)(struct afs_call *call);
134
135 /* clean up a call */
136 void (*destructor)(struct afs_call *call);
137
138 /* Work function */
139 void (*work)(struct work_struct *work);
140 };
141
142 /*
143 * Key available for writeback on a file.
144 */
145 struct afs_wb_key {
146 refcount_t usage;
147 struct key *key;
148 struct list_head vnode_link; /* Link in vnode->wb_keys */
149 };
150
151 /*
152 * AFS open file information record. Pointed to by file->private_data.
153 */
154 struct afs_file {
155 struct key *key; /* The key this file was opened with */
156 struct afs_wb_key *wb; /* Writeback key record for this file */
157 };
158
159 static inline struct key *afs_file_key(struct file *file)
160 {
161 struct afs_file *af = file->private_data;
162
163 return af->key;
164 }
165
166 /*
167 * Record of an outstanding read operation on a vnode.
168 */
169 struct afs_read {
170 loff_t pos; /* Where to start reading */
171 loff_t len; /* How much we're asking for */
172 loff_t actual_len; /* How much we're actually getting */
173 loff_t remain; /* Amount remaining */
174 atomic_t usage;
175 unsigned int index; /* Which page we're reading into */
176 unsigned int nr_pages;
177 void (*page_done)(struct afs_call *, struct afs_read *);
178 struct page *pages[];
179 };
180
181 /*
182 * AFS superblock private data
183 * - there's one superblock per volume
184 */
185 struct afs_super_info {
186 struct afs_net *net; /* Network namespace */
187 struct afs_cell *cell; /* The cell in which the volume resides */
188 struct afs_volume *volume; /* volume record */
189 };
190
191 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
192 {
193 return sb->s_fs_info;
194 }
195
196 extern struct file_system_type afs_fs_type;
197
198 /*
199 * AFS network namespace record.
200 */
201 struct afs_net {
202 struct afs_uuid uuid;
203 bool live; /* F if this namespace is being removed */
204
205 /* AF_RXRPC I/O stuff */
206 struct socket *socket;
207 struct afs_call *spare_incoming_call;
208 struct work_struct charge_preallocation_work;
209 struct mutex socket_mutex;
210 atomic_t nr_outstanding_calls;
211 atomic_t nr_superblocks;
212
213 /* Cell database */
214 struct rb_root cells;
215 struct afs_cell *ws_cell;
216 struct work_struct cells_manager;
217 struct timer_list cells_timer;
218 atomic_t cells_outstanding;
219 seqlock_t cells_lock;
220
221 spinlock_t proc_cells_lock;
222 struct list_head proc_cells;
223
224 /* Known servers. Theoretically each fileserver can only be in one
225 * cell, but in practice, people create aliases and subsets and there's
226 * no easy way to distinguish them.
227 */
228 seqlock_t fs_lock; /* For fs_servers */
229 struct rb_root fs_servers; /* afs_server (by server UUID or address) */
230 struct list_head fs_updates; /* afs_server (by update_at) */
231 struct hlist_head fs_proc; /* procfs servers list */
232
233 struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
234 struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
235 seqlock_t fs_addr_lock; /* For fs_addresses[46] */
236
237 struct work_struct fs_manager;
238 struct timer_list fs_timer;
239 atomic_t servers_outstanding;
240
241 /* File locking renewal management */
242 struct mutex lock_manager_mutex;
243
244 /* Misc */
245 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
246 };
247
248 extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns
249
250 enum afs_cell_state {
251 AFS_CELL_UNSET,
252 AFS_CELL_ACTIVATING,
253 AFS_CELL_ACTIVE,
254 AFS_CELL_DEACTIVATING,
255 AFS_CELL_INACTIVE,
256 AFS_CELL_FAILED,
257 };
258
259 /*
260 * AFS cell record.
261 *
262 * This is a tricky concept to get right as it is possible to create aliases
263 * simply by pointing AFSDB/SRV records for two names at the same set of VL
264 * servers; it is also possible to do things like setting up two sets of VL
265 * servers, one of which provides a superset of the volumes provided by the
266 * other (for internal/external division, for example).
267 *
268 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
269 * servers and (b) a cell's name is used by the client to select the key to use
270 * for authentication and encryption. The cell name is not typically used in
271 * the protocol.
272 *
273 * There is no easy way to determine if two cells are aliases or one is a
274 * subset of another.
275 */
276 struct afs_cell {
277 union {
278 struct rcu_head rcu;
279 struct rb_node net_node; /* Node in net->cells */
280 };
281 struct afs_net *net;
282 struct key *anonymous_key; /* anonymous user key for this cell */
283 struct work_struct manager; /* Manager for init/deinit/dns */
284 struct list_head proc_link; /* /proc cell list link */
285 #ifdef CONFIG_AFS_FSCACHE
286 struct fscache_cookie *cache; /* caching cookie */
287 #endif
288 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
289 time64_t last_inactive; /* Time of last drop of usage count */
290 atomic_t usage;
291 unsigned long flags;
292 #define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
293 #define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
294 #define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
295 #define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
296 #define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
297 enum afs_cell_state state;
298 short error;
299
300 /* Active fileserver interaction state. */
301 struct list_head proc_volumes; /* procfs volume list */
302 rwlock_t proc_lock;
303
304 /* VL server list. */
305 rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
306 struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
307 u8 name_len; /* Length of name */
308 char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
309 };
310
311 /*
312 * Cached VLDB entry.
313 *
314 * This is pointed to by cell->vldb_entries, indexed by name.
315 */
316 struct afs_vldb_entry {
317 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
318
319 unsigned long flags;
320 #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
321 #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
322 #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
323 #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
324 #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
325
326 uuid_t fs_server[AFS_NMAXNSERVERS];
327 u8 fs_mask[AFS_NMAXNSERVERS];
328 #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
329 #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
330 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
331 short error;
332 u8 nr_servers; /* Number of server records */
333 u8 name_len;
334 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
335 };
336
337 /*
338 * Record of fileserver with which we're actively communicating.
339 */
340 struct afs_server {
341 struct rcu_head rcu;
342 union {
343 uuid_t uuid; /* Server ID */
344 struct afs_uuid _uuid;
345 };
346
347 struct afs_addr_list __rcu *addresses;
348 struct rb_node uuid_rb; /* Link in net->servers */
349 struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
350 struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
351 struct hlist_node proc_link; /* Link in net->fs_proc */
352 struct afs_server *gc_next; /* Next server in manager's list */
353 time64_t put_time; /* Time at which last put */
354 time64_t update_at; /* Time at which to next update the record */
355 unsigned long flags;
356 #define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
357 #define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
358 #define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
359 #define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
360 #define AFS_SERVER_FL_UPDATING 4
361 #define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
362 #define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
363 atomic_t usage;
364 u32 addr_version; /* Address list version */
365
366 /* file service access */
367 rwlock_t fs_lock; /* access lock */
368
369 /* callback promise management */
370 struct list_head cb_interests; /* List of superblocks using this server */
371 unsigned cb_s_break; /* Break-everything counter. */
372 rwlock_t cb_break_lock; /* Volume finding lock */
373 };
374
375 /*
376 * Interest by a superblock on a server.
377 */
378 struct afs_cb_interest {
379 struct list_head cb_link; /* Link in server->cb_interests */
380 struct afs_server *server; /* Server on which this interest resides */
381 struct super_block *sb; /* Superblock on which inodes reside */
382 afs_volid_t vid; /* Volume ID to match */
383 refcount_t usage;
384 };
385
386 /*
387 * Replaceable server list.
388 */
389 struct afs_server_entry {
390 struct afs_server *server;
391 struct afs_cb_interest *cb_interest;
392 };
393
394 struct afs_server_list {
395 refcount_t usage;
396 unsigned short nr_servers;
397 unsigned short index; /* Server currently in use */
398 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
399 unsigned int seq; /* Set to ->servers_seq when installed */
400 rwlock_t lock;
401 struct afs_server_entry servers[];
402 };
403
404 /*
405 * Live AFS volume management.
406 */
407 struct 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 */
432 };
433
434 enum afs_lock_state {
435 AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
436 AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
437 AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
438 AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
439 AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
440 AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
441 AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
442 };
443
444 /*
445 * AFS inode private data.
446 *
447 * Note that afs_alloc_inode() *must* reset anything that could incorrectly
448 * leak from one inode to another.
449 */
450 struct afs_vnode {
451 struct inode vfs_inode; /* the VFS's inode record */
452
453 struct afs_volume *volume; /* volume on which vnode resides */
454 struct afs_fid fid; /* the file identifier for this inode */
455 struct afs_file_status status; /* AFS status info for this file */
456 #ifdef CONFIG_AFS_FSCACHE
457 struct fscache_cookie *cache; /* caching cookie */
458 #endif
459 struct afs_permits *permit_cache; /* cache of permits so far obtained */
460 struct mutex io_lock; /* Lock for serialising I/O on this mutex */
461 struct mutex validate_lock; /* lock for validating this vnode */
462 spinlock_t wb_lock; /* lock for wb_keys */
463 spinlock_t lock; /* waitqueue/flags lock */
464 unsigned long flags;
465 #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
466 #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
467 #define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */
468 #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
469 #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
470 #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
471 #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
472 #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
473
474 struct list_head wb_keys; /* List of keys available for writeback */
475 struct list_head pending_locks; /* locks waiting to be granted */
476 struct list_head granted_locks; /* locks granted on this file */
477 struct delayed_work lock_work; /* work to be done in locking */
478 struct key *lock_key; /* Key to be used in lock ops */
479 enum afs_lock_state lock_state : 8;
480 afs_lock_type_t lock_type : 8;
481
482 /* outstanding callback notification on this file */
483 struct afs_cb_interest *cb_interest; /* Server on which this resides */
484 unsigned int cb_s_break; /* Mass break counter on ->server */
485 unsigned int cb_break; /* Break counter on vnode */
486 seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
487
488 time64_t cb_expires_at; /* time at which callback expires */
489 unsigned cb_version; /* callback version */
490 afs_callback_type_t cb_type; /* type of callback */
491 };
492
493 /*
494 * cached security record for one user's attempt to access a vnode
495 */
496 struct afs_permit {
497 struct key *key; /* RxRPC ticket holding a security context */
498 afs_access_t access; /* CallerAccess value for this key */
499 };
500
501 /*
502 * Immutable cache of CallerAccess records from attempts to access vnodes.
503 * These may be shared between multiple vnodes.
504 */
505 struct afs_permits {
506 struct rcu_head rcu;
507 struct hlist_node hash_node; /* Link in hash */
508 unsigned long h; /* Hash value for this permit list */
509 refcount_t usage;
510 unsigned short nr_permits; /* Number of records */
511 bool invalidated; /* Invalidated due to key change */
512 struct afs_permit permits[]; /* List of permits sorted by key pointer */
513 };
514
515 /*
516 * record of one of a system's set of network interfaces
517 */
518 struct afs_interface {
519 struct in_addr address; /* IPv4 address bound to interface */
520 struct in_addr netmask; /* netmask applied to address */
521 unsigned mtu; /* MTU of interface */
522 };
523
524 /*
525 * Cursor for iterating over a server's address list.
526 */
527 struct afs_addr_cursor {
528 struct afs_addr_list *alist; /* Current address list (pins ref) */
529 struct sockaddr_rxrpc *addr;
530 u32 abort_code;
531 unsigned short start; /* Starting point in alist->addrs[] */
532 unsigned short index; /* Wrapping offset from start to current addr */
533 short error;
534 bool begun; /* T if we've begun iteration */
535 bool responded; /* T if the current address responded */
536 };
537
538 /*
539 * Cursor for iterating over a set of fileservers.
540 */
541 struct afs_fs_cursor {
542 struct afs_addr_cursor ac;
543 struct afs_vnode *vnode;
544 struct afs_server_list *server_list; /* Current server list (pins ref) */
545 struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
546 struct key *key; /* Key for the server */
547 unsigned int cb_break; /* cb_break + cb_s_break before the call */
548 unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
549 unsigned char start; /* Initial index in server list */
550 unsigned char index; /* Number of servers tried beyond start */
551 unsigned short flags;
552 #define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
553 #define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
554 #define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
555 #define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
556 #define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
557 #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
558 };
559
560 #include <trace/events/afs.h>
561
562 /*****************************************************************************/
563 /*
564 * addr_list.c
565 */
566 static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
567 {
568 if (alist)
569 refcount_inc(&alist->usage);
570 return alist;
571 }
572 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
573 unsigned short,
574 unsigned short);
575 extern void afs_put_addrlist(struct afs_addr_list *);
576 extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
577 unsigned short, unsigned short);
578 extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
579 extern bool afs_iterate_addresses(struct afs_addr_cursor *);
580 extern int afs_end_cursor(struct afs_addr_cursor *);
581 extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
582
583 extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
584 extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
585
586 /*
587 * cache.c
588 */
589 #ifdef CONFIG_AFS_FSCACHE
590 extern struct fscache_netfs afs_cache_netfs;
591 extern struct fscache_cookie_def afs_cell_cache_index_def;
592 extern struct fscache_cookie_def afs_volume_cache_index_def;
593 extern struct fscache_cookie_def afs_vnode_cache_index_def;
594 #else
595 #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
596 #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
597 #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
598 #endif
599
600 /*
601 * callback.c
602 */
603 extern void afs_init_callback_state(struct afs_server *);
604 extern void afs_break_callback(struct afs_vnode *);
605 extern void afs_break_callbacks(struct afs_server *, size_t,struct afs_callback[]);
606
607 extern int afs_register_server_cb_interest(struct afs_vnode *,
608 struct afs_server_list *, unsigned int);
609 extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
610 extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
611
612 static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
613 {
614 if (cbi)
615 refcount_inc(&cbi->usage);
616 return cbi;
617 }
618
619 /*
620 * cell.c
621 */
622 extern int afs_cell_init(struct afs_net *, const char *);
623 extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
624 extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
625 const char *, bool);
626 extern struct afs_cell *afs_get_cell(struct afs_cell *);
627 extern void afs_put_cell(struct afs_net *, struct afs_cell *);
628 extern void afs_manage_cells(struct work_struct *);
629 extern void afs_cells_timer(struct timer_list *);
630 extern void __net_exit afs_cell_purge(struct afs_net *);
631
632 /*
633 * cmservice.c
634 */
635 extern bool afs_cm_incoming_call(struct afs_call *);
636
637 /*
638 * dir.c
639 */
640 extern bool afs_dir_check_page(struct inode *, struct page *);
641 extern const struct inode_operations afs_dir_inode_operations;
642 extern const struct dentry_operations afs_fs_dentry_operations;
643 extern const struct file_operations afs_dir_file_operations;
644
645 /*
646 * file.c
647 */
648 extern const struct address_space_operations afs_fs_aops;
649 extern const struct inode_operations afs_file_inode_operations;
650 extern const struct file_operations afs_file_operations;
651
652 extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
653 extern void afs_put_wb_key(struct afs_wb_key *);
654 extern int afs_open(struct inode *, struct file *);
655 extern int afs_release(struct inode *, struct file *);
656 extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
657 extern int afs_page_filler(void *, struct page *);
658 extern void afs_put_read(struct afs_read *);
659
660 /*
661 * flock.c
662 */
663 extern struct workqueue_struct *afs_lock_manager;
664
665 extern void afs_lock_work(struct work_struct *);
666 extern void afs_lock_may_be_available(struct afs_vnode *);
667 extern int afs_lock(struct file *, int, struct file_lock *);
668 extern int afs_flock(struct file *, int, struct file_lock *);
669
670 /*
671 * fsclient.c
672 */
673 extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *);
674 extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
675 extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
676 extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t,
677 struct afs_fid *, struct afs_file_status *, struct afs_callback *);
678 extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool);
679 extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *);
680 extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *,
681 struct afs_fid *, struct afs_file_status *);
682 extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
683 struct afs_vnode *, const char *);
684 extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
685 pgoff_t, pgoff_t, unsigned, unsigned);
686 extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
687 extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
688 extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
689 extern int afs_fs_extend_lock(struct afs_fs_cursor *);
690 extern int afs_fs_release_lock(struct afs_fs_cursor *);
691 extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
692 struct afs_addr_cursor *, struct key *);
693 extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
694 struct afs_addr_cursor *, struct key *);
695
696 /*
697 * inode.c
698 */
699 extern int afs_fetch_status(struct afs_vnode *, struct key *);
700 extern int afs_iget5_test(struct inode *, void *);
701 extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
702 struct key *);
703 extern struct inode *afs_iget(struct super_block *, struct key *,
704 struct afs_fid *, struct afs_file_status *,
705 struct afs_callback *,
706 struct afs_cb_interest *);
707 extern void afs_zap_data(struct afs_vnode *);
708 extern int afs_validate(struct afs_vnode *, struct key *);
709 extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
710 extern int afs_setattr(struct dentry *, struct iattr *);
711 extern void afs_evict_inode(struct inode *);
712 extern int afs_drop_inode(struct inode *);
713
714 /*
715 * main.c
716 */
717 extern struct workqueue_struct *afs_wq;
718
719 static inline struct afs_net *afs_d2net(struct dentry *dentry)
720 {
721 return &__afs_net;
722 }
723
724 static inline struct afs_net *afs_i2net(struct inode *inode)
725 {
726 return &__afs_net;
727 }
728
729 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
730 {
731 return &__afs_net;
732 }
733
734 static inline struct afs_net *afs_sock2net(struct sock *sk)
735 {
736 return &__afs_net;
737 }
738
739 static inline struct afs_net *afs_get_net(struct afs_net *net)
740 {
741 return net;
742 }
743
744 static inline void afs_put_net(struct afs_net *net)
745 {
746 }
747
748 /*
749 * misc.c
750 */
751 extern int afs_abort_to_error(u32);
752
753 /*
754 * mntpt.c
755 */
756 extern const struct inode_operations afs_mntpt_inode_operations;
757 extern const struct inode_operations afs_autocell_inode_operations;
758 extern const struct file_operations afs_mntpt_file_operations;
759
760 extern struct vfsmount *afs_d_automount(struct path *);
761 extern void afs_mntpt_kill_timer(void);
762
763 /*
764 * netdevices.c
765 */
766 extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
767
768 /*
769 * proc.c
770 */
771 extern int __net_init afs_proc_init(struct afs_net *);
772 extern void __net_exit afs_proc_cleanup(struct afs_net *);
773 extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *);
774 extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *);
775
776 /*
777 * rotate.c
778 */
779 extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
780 struct key *);
781 extern bool afs_select_fileserver(struct afs_fs_cursor *);
782 extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
783 extern int afs_end_vnode_operation(struct afs_fs_cursor *);
784
785 /*
786 * rxrpc.c
787 */
788 extern struct workqueue_struct *afs_async_calls;
789
790 extern int __net_init afs_open_socket(struct afs_net *);
791 extern void __net_exit afs_close_socket(struct afs_net *);
792 extern void afs_charge_preallocation(struct work_struct *);
793 extern void afs_put_call(struct afs_call *);
794 extern int afs_queue_call_work(struct afs_call *);
795 extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
796 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
797 const struct afs_call_type *,
798 size_t, size_t);
799 extern void afs_flat_call_destructor(struct afs_call *);
800 extern void afs_send_empty_reply(struct afs_call *);
801 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
802 extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
803
804 static inline int afs_transfer_reply(struct afs_call *call)
805 {
806 return afs_extract_data(call, call->buffer, call->reply_max, false);
807 }
808
809 static inline bool afs_check_call_state(struct afs_call *call,
810 enum afs_call_state state)
811 {
812 return READ_ONCE(call->state) == state;
813 }
814
815 static inline bool afs_set_call_state(struct afs_call *call,
816 enum afs_call_state from,
817 enum afs_call_state to)
818 {
819 bool ok = false;
820
821 spin_lock_bh(&call->state_lock);
822 if (call->state == from) {
823 call->state = to;
824 trace_afs_call_state(call, from, to, 0, 0);
825 ok = true;
826 }
827 spin_unlock_bh(&call->state_lock);
828 return ok;
829 }
830
831 static inline void afs_set_call_complete(struct afs_call *call,
832 int error, u32 remote_abort)
833 {
834 enum afs_call_state state;
835 bool ok = false;
836
837 spin_lock_bh(&call->state_lock);
838 state = call->state;
839 if (state != AFS_CALL_COMPLETE) {
840 call->abort_code = remote_abort;
841 call->error = error;
842 call->state = AFS_CALL_COMPLETE;
843 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
844 error, remote_abort);
845 ok = true;
846 }
847 spin_unlock_bh(&call->state_lock);
848 if (ok)
849 trace_afs_call_done(call);
850 }
851
852 /*
853 * security.c
854 */
855 extern void afs_put_permits(struct afs_permits *);
856 extern void afs_clear_permits(struct afs_vnode *);
857 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
858 extern void afs_zap_permits(struct rcu_head *);
859 extern struct key *afs_request_key(struct afs_cell *);
860 extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
861 extern int afs_permission(struct inode *, int);
862 extern void __exit afs_clean_up_permit_cache(void);
863
864 /*
865 * server.c
866 */
867 extern spinlock_t afs_server_peer_lock;
868
869 static inline struct afs_server *afs_get_server(struct afs_server *server)
870 {
871 atomic_inc(&server->usage);
872 return server;
873 }
874
875 extern struct afs_server *afs_find_server(struct afs_net *,
876 const struct sockaddr_rxrpc *);
877 extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
878 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
879 extern void afs_put_server(struct afs_net *, struct afs_server *);
880 extern void afs_manage_servers(struct work_struct *);
881 extern void afs_servers_timer(struct timer_list *);
882 extern void __net_exit afs_purge_servers(struct afs_net *);
883 extern bool afs_probe_fileserver(struct afs_fs_cursor *);
884 extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
885
886 /*
887 * server_list.c
888 */
889 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
890 {
891 refcount_inc(&slist->usage);
892 return slist;
893 }
894
895 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
896 extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
897 struct afs_vldb_entry *,
898 u8);
899 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
900
901 /*
902 * super.c
903 */
904 extern int __init afs_fs_init(void);
905 extern void __exit afs_fs_exit(void);
906
907 /*
908 * vlclient.c
909 */
910 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
911 struct afs_addr_cursor *,
912 struct key *, const char *, int);
913 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
914 struct key *, const uuid_t *);
915 extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
916 extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
917 struct key *, const uuid_t *);
918
919 /*
920 * volume.c
921 */
922 static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
923 {
924 if (volume)
925 atomic_inc(&volume->usage);
926 return volume;
927 }
928
929 extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
930 extern void afs_activate_volume(struct afs_volume *);
931 extern void afs_deactivate_volume(struct afs_volume *);
932 extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
933 extern int afs_check_volume_status(struct afs_volume *, struct key *);
934
935 /*
936 * write.c
937 */
938 extern int afs_set_page_dirty(struct page *);
939 extern int afs_write_begin(struct file *file, struct address_space *mapping,
940 loff_t pos, unsigned len, unsigned flags,
941 struct page **pagep, void **fsdata);
942 extern int afs_write_end(struct file *file, struct address_space *mapping,
943 loff_t pos, unsigned len, unsigned copied,
944 struct page *page, void *fsdata);
945 extern int afs_writepage(struct page *, struct writeback_control *);
946 extern int afs_writepages(struct address_space *, struct writeback_control *);
947 extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
948 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
949 extern int afs_flush(struct file *, fl_owner_t);
950 extern int afs_fsync(struct file *, loff_t, loff_t, int);
951 extern int afs_page_mkwrite(struct vm_fault *);
952 extern void afs_prune_wb_keys(struct afs_vnode *);
953 extern int afs_launder_page(struct page *);
954
955 /*
956 * xattr.c
957 */
958 extern const struct xattr_handler *afs_xattr_handlers[];
959 extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
960
961
962 /*
963 * Miscellaneous inline functions.
964 */
965 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
966 {
967 return container_of(inode, struct afs_vnode, vfs_inode);
968 }
969
970 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
971 {
972 return &vnode->vfs_inode;
973 }
974
975 static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
976 struct afs_vnode *vnode,
977 unsigned int cb_break)
978 {
979 if (fc->ac.error == 0)
980 afs_cache_permit(vnode, fc->key, cb_break);
981 }
982
983 static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
984 struct afs_vnode *vnode)
985 {
986 if (fc->ac.error == -ENOENT) {
987 set_bit(AFS_VNODE_DELETED, &vnode->flags);
988 afs_break_callback(vnode);
989 }
990 }
991
992
993 /*****************************************************************************/
994 /*
995 * debug tracing
996 */
997 extern unsigned afs_debug;
998
999 #define dbgprintk(FMT,...) \
1000 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1001
1002 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1003 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1004 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1005
1006
1007 #if defined(__KDEBUG)
1008 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1009 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1010 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1011
1012 #elif defined(CONFIG_AFS_DEBUG)
1013 #define AFS_DEBUG_KENTER 0x01
1014 #define AFS_DEBUG_KLEAVE 0x02
1015 #define AFS_DEBUG_KDEBUG 0x04
1016
1017 #define _enter(FMT,...) \
1018 do { \
1019 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
1020 kenter(FMT,##__VA_ARGS__); \
1021 } while (0)
1022
1023 #define _leave(FMT,...) \
1024 do { \
1025 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
1026 kleave(FMT,##__VA_ARGS__); \
1027 } while (0)
1028
1029 #define _debug(FMT,...) \
1030 do { \
1031 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
1032 kdebug(FMT,##__VA_ARGS__); \
1033 } while (0)
1034
1035 #else
1036 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1037 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1038 #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
1039 #endif
1040
1041 /*
1042 * debug assertion checking
1043 */
1044 #if 1 // defined(__KDEBUGALL)
1045
1046 #define ASSERT(X) \
1047 do { \
1048 if (unlikely(!(X))) { \
1049 printk(KERN_ERR "\n"); \
1050 printk(KERN_ERR "AFS: Assertion failed\n"); \
1051 BUG(); \
1052 } \
1053 } while(0)
1054
1055 #define ASSERTCMP(X, OP, Y) \
1056 do { \
1057 if (unlikely(!((X) OP (Y)))) { \
1058 printk(KERN_ERR "\n"); \
1059 printk(KERN_ERR "AFS: Assertion failed\n"); \
1060 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1061 (unsigned long)(X), (unsigned long)(Y)); \
1062 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1063 (unsigned long)(X), (unsigned long)(Y)); \
1064 BUG(); \
1065 } \
1066 } while(0)
1067
1068 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1069 do { \
1070 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1071 printk(KERN_ERR "\n"); \
1072 printk(KERN_ERR "AFS: Assertion failed\n"); \
1073 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1074 (unsigned long)(L), (unsigned long)(N), \
1075 (unsigned long)(H)); \
1076 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1077 (unsigned long)(L), (unsigned long)(N), \
1078 (unsigned long)(H)); \
1079 BUG(); \
1080 } \
1081 } while(0)
1082
1083 #define ASSERTIF(C, X) \
1084 do { \
1085 if (unlikely((C) && !(X))) { \
1086 printk(KERN_ERR "\n"); \
1087 printk(KERN_ERR "AFS: Assertion failed\n"); \
1088 BUG(); \
1089 } \
1090 } while(0)
1091
1092 #define ASSERTIFCMP(C, X, OP, Y) \
1093 do { \
1094 if (unlikely((C) && !((X) OP (Y)))) { \
1095 printk(KERN_ERR "\n"); \
1096 printk(KERN_ERR "AFS: Assertion failed\n"); \
1097 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1098 (unsigned long)(X), (unsigned long)(Y)); \
1099 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1100 (unsigned long)(X), (unsigned long)(Y)); \
1101 BUG(); \
1102 } \
1103 } while(0)
1104
1105 #else
1106
1107 #define ASSERT(X) \
1108 do { \
1109 } while(0)
1110
1111 #define ASSERTCMP(X, OP, Y) \
1112 do { \
1113 } while(0)
1114
1115 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1116 do { \
1117 } while(0)
1118
1119 #define ASSERTIF(C, X) \
1120 do { \
1121 } while(0)
1122
1123 #define ASSERTIFCMP(C, X, OP, Y) \
1124 do { \
1125 } while(0)
1126
1127 #endif /* __KDEBUGALL */