1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* internal AFS stuff
3 *
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8 #include <linux/compiler.h>
9 #include <linux/kernel.h>
10 #include <linux/ktime.h>
11 #include <linux/fs.h>
12 #include <linux/filelock.h>
13 #include <linux/pagemap.h>
14 #include <linux/rxrpc.h>
15 #include <linux/key.h>
16 #include <linux/workqueue.h>
17 #include <linux/sched.h>
18 #include <linux/fscache.h>
19 #include <linux/backing-dev.h>
20 #include <linux/uuid.h>
21 #include <linux/mm_types.h>
22 #include <linux/dns_resolver.h>
23 #include <crypto/krb5.h>
24 #include <net/net_namespace.h>
25 #include <net/netns/generic.h>
26 #include <net/sock.h>
27 #include <net/af_rxrpc.h>
28
29 #include "afs.h"
30 #include "afs_vl.h"
31
32 #define AFS_CELL_MAX_ADDRS 15
33
34 struct afs_call;
35 struct afs_vnode;
36 struct afs_server_probe;
37
38 /*
39 * Partial file-locking emulation mode. (The problem being that AFS3 only
40 * allows whole-file locks and no upgrading/downgrading).
41 */
42 enum afs_flock_mode {
43 afs_flock_mode_unset,
44 afs_flock_mode_local, /* Local locking only */
45 afs_flock_mode_openafs, /* Don't get server lock for a partial lock */
46 afs_flock_mode_strict, /* Always get a server lock for a partial lock */
47 afs_flock_mode_write, /* Get an exclusive server lock for a partial lock */
48 };
49
50 struct afs_fs_context {
51 bool force; /* T to force cell type */
52 bool autocell; /* T if set auto mount operation */
53 bool dyn_root; /* T if dynamic root */
54 bool no_cell; /* T if the source is "none" (for dynroot) */
55 enum afs_flock_mode flock_mode; /* Partial file-locking emulation mode */
56 afs_voltype_t type; /* type of volume requested */
57 unsigned int volnamesz; /* size of volume name */
58 const char *volname; /* name of volume to mount */
59 struct afs_net *net; /* the AFS net namespace stuff */
60 struct afs_cell *cell; /* cell in which to find volume */
61 struct afs_volume *volume; /* volume record */
62 struct key *key; /* key to use for secure mounting */
63 };
64
65 enum afs_call_state {
66 AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
67 AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
68 AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
69 AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
70 AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
71 AFS_CALL_SV_REPLYING, /* Server: Replying */
72 AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
73 AFS_CALL_COMPLETE, /* Completed or failed */
74 };
75
76 /*
77 * Address preferences.
78 */
79 struct afs_addr_preference {
80 union {
81 struct in_addr ipv4_addr; /* AF_INET address to compare against */
82 struct in6_addr ipv6_addr; /* AF_INET6 address to compare against */
83 };
84 sa_family_t family; /* Which address to use */
85 u16 prio; /* Priority */
86 u8 subnet_mask; /* How many bits to compare */
87 };
88
89 struct afs_addr_preference_list {
90 struct rcu_head rcu;
91 u16 version; /* Incremented when prefs list changes */
92 u8 ipv6_off; /* Offset of IPv6 addresses */
93 u8 nr; /* Number of addresses in total */
94 u8 max_prefs; /* Number of prefs allocated */
95 struct afs_addr_preference prefs[] __counted_by(max_prefs);
96 };
97
98 struct afs_address {
99 struct rxrpc_peer *peer;
100 short last_error; /* Last error from this address */
101 u16 prio; /* Address priority */
102 };
103
104 /*
105 * List of server addresses.
106 */
107 struct afs_addr_list {
108 struct rcu_head rcu;
109 refcount_t usage;
110 u32 version; /* Version */
111 unsigned int debug_id;
112 unsigned int addr_pref_version; /* Version of address preference list */
113 unsigned char max_addrs;
114 unsigned char nr_addrs;
115 unsigned char preferred; /* Preferred address */
116 unsigned char nr_ipv4; /* Number of IPv4 addresses */
117 enum dns_record_source source:8;
118 enum dns_lookup_status status:8;
119 unsigned long probe_failed; /* Mask of addrs that failed locally/ICMP */
120 unsigned long responded; /* Mask of addrs that responded */
121 struct afs_address addrs[] __counted_by(max_addrs);
122 #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
123 };
124
125 /*
126 * a record of an in-progress RxRPC call
127 */
128 struct afs_call {
129 const struct afs_call_type *type; /* type of call */
130 wait_queue_head_t waitq; /* processes awaiting completion */
131 struct work_struct async_work; /* async I/O processor */
132 struct work_struct work; /* actual work processor */
133 struct work_struct free_work; /* Deferred free processor */
134 struct rxrpc_call *rxcall; /* RxRPC call handle */
135 struct rxrpc_peer *peer; /* Remote endpoint */
136 struct key *key; /* security for this call */
137 struct afs_net *net; /* The network namespace */
138 struct afs_server *server; /* The fileserver record if fs op (pins ref) */
139 struct afs_vlserver *vlserver; /* The vlserver record if vl op */
140 void *request; /* request data (first part) */
141 size_t iov_len; /* Size of *iter to be used */
142 struct iov_iter def_iter; /* Default buffer/data iterator */
143 struct iov_iter *write_iter; /* Iterator defining write to be made */
144 struct iov_iter *iter; /* Iterator currently in use */
145 union { /* Convenience for ->def_iter */
146 struct kvec kvec[1];
147 struct bio_vec bvec[1];
148 };
149 void *buffer; /* reply receive buffer */
150 union {
151 struct afs_endpoint_state *probe;
152 struct afs_addr_list *vl_probe;
153 struct afs_addr_list *ret_alist;
154 struct afs_vldb_entry *ret_vldb;
155 char *ret_str;
156 };
157 struct afs_fid fid; /* Primary vnode ID (or all zeroes) */
158 unsigned char probe_index; /* Address in ->probe_alist */
159 struct afs_operation *op;
160 unsigned int server_index;
161 refcount_t ref;
162 enum afs_call_state state;
163 spinlock_t state_lock;
164 int error; /* error code */
165 u32 abort_code; /* Remote abort ID or 0 */
166 unsigned long long remaining; /* How much is left to receive */
167 unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
168 unsigned request_size; /* size of request data */
169 unsigned reply_max; /* maximum size of reply */
170 unsigned count2; /* count used in unmarshalling */
171 unsigned char unmarshall; /* unmarshalling phase */
172 bool drop_ref; /* T if need to drop ref for incoming call */
173 bool need_attention; /* T if RxRPC poked us */
174 bool async; /* T if asynchronous */
175 bool upgrade; /* T to request service upgrade */
176 bool intr; /* T if interruptible */
177 bool unmarshalling_error; /* T if an unmarshalling error occurred */
178 bool responded; /* Got a response from the call (may be abort) */
179 u8 security_ix; /* Security class */
180 u16 service_id; /* Actual service ID (after upgrade) */
181 unsigned int debug_id; /* Trace ID */
182 u32 enctype; /* Security encoding type */
183 u32 operation_ID; /* operation ID for an incoming call */
184 u32 count; /* count for use in unmarshalling */
185 union { /* place to extract temporary data */
186 struct {
187 __be32 tmp_u;
188 __be32 tmp;
189 } __attribute__((packed));
190 __be64 tmp64;
191 };
192 ktime_t issue_time; /* Time of issue of operation */
193 };
194
195 struct afs_call_type {
196 const char *name;
197 unsigned int op; /* Really enum afs_fs_operation */
198
199 /* deliver request or reply data to an call
200 * - returning an error will cause the call to be aborted
201 */
202 int (*deliver)(struct afs_call *call);
203
204 /* clean up a call */
205 void (*destructor)(struct afs_call *call);
206
207 /* Async receive processing function */
208 void (*async_rx)(struct work_struct *work);
209
210 /* Work function */
211 void (*work)(struct work_struct *work);
212
213 /* Call done function (gets called immediately on success or failure) */
214 void (*done)(struct afs_call *call);
215
216 /* Handle a call being immediately cancelled. */
217 void (*immediate_cancel)(struct afs_call *call);
218 };
219
220 /*
221 * Key available for writeback on a file.
222 */
223 struct afs_wb_key {
224 refcount_t usage;
225 struct key *key;
226 struct list_head vnode_link; /* Link in vnode->wb_keys */
227 };
228
229 /*
230 * AFS open file information record. Pointed to by file->private_data.
231 */
232 struct afs_file {
233 struct key *key; /* The key this file was opened with */
234 struct afs_wb_key *wb; /* Writeback key record for this file */
235 };
236
afs_file_key(struct file * file)237 static inline struct key *afs_file_key(struct file *file)
238 {
239 struct afs_file *af = file->private_data;
240
241 return af->key;
242 }
243
244 /*
245 * AFS superblock private data
246 * - there's one superblock per volume
247 */
248 struct afs_super_info {
249 struct net *net_ns; /* Network namespace */
250 struct afs_cell *cell; /* The cell in which the volume resides */
251 struct afs_volume *volume; /* volume record */
252 enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
253 bool dyn_root; /* True if dynamic root */
254 };
255
AFS_FS_S(struct super_block * sb)256 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
257 {
258 return sb->s_fs_info;
259 }
260
261 extern struct file_system_type afs_fs_type;
262
263 /*
264 * Set of substitutes for @sys.
265 */
266 struct afs_sysnames {
267 #define AFS_NR_SYSNAME 16
268 char *subs[AFS_NR_SYSNAME];
269 refcount_t usage;
270 unsigned short nr;
271 char blank[1];
272 };
273
274 /*
275 * AFS network namespace record.
276 */
277 struct afs_net {
278 struct net *net; /* Backpointer to the owning net namespace */
279 struct afs_uuid uuid;
280 bool live; /* F if this namespace is being removed */
281
282 /* AF_RXRPC I/O stuff */
283 struct socket *socket;
284 struct afs_call *spare_incoming_call;
285 struct work_struct charge_preallocation_work;
286 struct work_struct rx_oob_work;
287 struct mutex socket_mutex;
288 atomic_t nr_outstanding_calls;
289 atomic_t nr_superblocks;
290
291 /* Cell database */
292 struct rb_root cells;
293 struct idr cells_dyn_ino; /* cell->dynroot_ino mapping */
294 struct afs_cell __rcu *ws_cell;
295 atomic_t cells_outstanding;
296 struct rw_semaphore cells_lock;
297 struct mutex cells_alias_lock;
298
299 struct mutex proc_cells_lock;
300 struct hlist_head proc_cells;
301
302 /* Known servers. Theoretically each fileserver can only be in one
303 * cell, but in practice, people create aliases and subsets and there's
304 * no easy way to distinguish them.
305 */
306 seqlock_t fs_lock; /* For fs_probe_*, fs_proc */
307 struct list_head fs_probe_fast; /* List of afs_server to probe at 30s intervals */
308 struct list_head fs_probe_slow; /* List of afs_server to probe at 5m intervals */
309 struct hlist_head fs_proc; /* procfs servers list */
310
311 struct key *fs_cm_token_key; /* Key for creating CM tokens */
312 struct work_struct fs_prober;
313 struct timer_list fs_probe_timer;
314 atomic_t servers_outstanding;
315
316 /* File locking renewal management */
317 struct mutex lock_manager_mutex;
318
319 /* Misc */
320 struct super_block *dynroot_sb; /* Dynamic root mount superblock */
321 struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
322 struct afs_sysnames *sysnames;
323 rwlock_t sysnames_lock;
324 struct afs_addr_preference_list __rcu *address_prefs;
325 u16 address_pref_version;
326
327 /* Statistics counters */
328 atomic_t n_lookup; /* Number of lookups done */
329 atomic_t n_reval; /* Number of dentries needing revalidation */
330 atomic_t n_inval; /* Number of invalidations by the server */
331 atomic_t n_relpg; /* Number of invalidations by release_folio */
332 atomic_t n_read_dir; /* Number of directory pages read */
333 atomic_t n_dir_cr; /* Number of directory entry creation edits */
334 atomic_t n_dir_rm; /* Number of directory entry removal edits */
335 atomic_t n_stores; /* Number of store ops */
336 atomic_long_t n_store_bytes; /* Number of bytes stored */
337 atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
338 atomic_t n_fetches; /* Number of data fetch ops */
339 };
340
341 extern const char afs_init_sysname[];
342
343 enum afs_cell_state {
344 AFS_CELL_SETTING_UP,
345 AFS_CELL_UNLOOKED,
346 AFS_CELL_ACTIVE,
347 AFS_CELL_REMOVING,
348 AFS_CELL_DEAD,
349 };
350
351 /*
352 * AFS cell record.
353 *
354 * This is a tricky concept to get right as it is possible to create aliases
355 * simply by pointing AFSDB/SRV records for two names at the same set of VL
356 * servers; it is also possible to do things like setting up two sets of VL
357 * servers, one of which provides a superset of the volumes provided by the
358 * other (for internal/external division, for example).
359 *
360 * Cells only exist in the sense that (a) a cell's name maps to a set of VL
361 * servers and (b) a cell's name is used by the client to select the key to use
362 * for authentication and encryption. The cell name is not typically used in
363 * the protocol.
364 *
365 * Two cells are determined to be aliases if they have an explicit alias (YFS
366 * only), share any VL servers in common or have at least one volume in common.
367 * "In common" means that the address list of the VL servers or the fileservers
368 * share at least one endpoint.
369 */
370 struct afs_cell {
371 union {
372 struct rcu_head rcu;
373 struct rb_node net_node; /* Node in net->cells */
374 };
375 struct afs_net *net;
376 struct afs_cell *alias_of; /* The cell this is an alias of */
377 struct afs_volume *root_volume; /* The root.cell volume if there is one */
378 struct key *anonymous_key; /* anonymous user key for this cell */
379 struct work_struct destroyer; /* Destroyer for cell */
380 struct work_struct manager; /* Manager for init/deinit/dns */
381 struct timer_list management_timer; /* General management timer */
382 struct hlist_node proc_link; /* /proc cell list link */
383 time64_t dns_expiry; /* Time AFSDB/SRV record expires */
384 time64_t last_inactive; /* Time of last drop of usage count */
385 refcount_t ref; /* Struct refcount */
386 atomic_t active; /* Active usage counter */
387 unsigned long flags;
388 #define AFS_CELL_FL_NO_GC 0 /* The cell was added manually, don't auto-gc */
389 #define AFS_CELL_FL_DO_LOOKUP 1 /* DNS lookup requested */
390 #define AFS_CELL_FL_CHECK_ALIAS 2 /* Need to check for aliases */
391 enum afs_cell_state state;
392 short error;
393 enum dns_record_source dns_source:8; /* Latest source of data from lookup */
394 enum dns_lookup_status dns_status:8; /* Latest status of data from lookup */
395 unsigned int dns_lookup_count; /* Counter of DNS lookups */
396 unsigned int debug_id;
397 unsigned int dynroot_ino; /* Inode numbers for dynroot (a pair) */
398
399 /* The volumes belonging to this cell */
400 struct rw_semaphore vs_lock; /* Lock for server->volumes */
401 struct rb_root volumes; /* Tree of volumes on this server */
402 struct hlist_head proc_volumes; /* procfs volume list */
403 seqlock_t volume_lock; /* For volumes */
404
405 /* Active fileserver interaction state. */
406 struct rb_root fs_servers; /* afs_server (by server UUID) */
407 struct rw_semaphore fs_lock; /* For fs_servers */
408
409 /* VL server list. */
410 rwlock_t vl_servers_lock; /* Lock on vl_servers */
411 struct afs_vlserver_list __rcu *vl_servers;
412
413 u8 name_len; /* Length of name */
414 char *name; /* Cell name, case-flattened and NUL-padded */
415 char *key_desc; /* Authentication key description */
416 };
417
418 /*
419 * Volume Location server record.
420 */
421 struct afs_vlserver {
422 struct rcu_head rcu;
423 struct afs_addr_list __rcu *addresses; /* List of addresses for this VL server */
424 unsigned long flags;
425 #define AFS_VLSERVER_FL_PROBED 0 /* The VL server has been probed */
426 #define AFS_VLSERVER_FL_PROBING 1 /* VL server is being probed */
427 #define AFS_VLSERVER_FL_IS_YFS 2 /* Server is YFS not AFS */
428 #define AFS_VLSERVER_FL_RESPONDING 3 /* VL server is responding */
429 rwlock_t lock; /* Lock on addresses */
430 refcount_t ref;
431 unsigned int rtt; /* Server's current RTT in uS */
432 unsigned int debug_id;
433
434 /* Probe state */
435 wait_queue_head_t probe_wq;
436 atomic_t probe_outstanding;
437 spinlock_t probe_lock;
438 struct {
439 unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */
440 u32 abort_code;
441 short error;
442 unsigned short flags;
443 #define AFS_VLSERVER_PROBE_RESPONDED 0x01 /* At least once response (may be abort) */
444 #define AFS_VLSERVER_PROBE_IS_YFS 0x02 /* The peer appears to be YFS */
445 #define AFS_VLSERVER_PROBE_NOT_YFS 0x04 /* The peer appears not to be YFS */
446 #define AFS_VLSERVER_PROBE_LOCAL_FAILURE 0x08 /* A local failure prevented a probe */
447 } probe;
448
449 u16 service_id; /* Service ID we're using */
450 u16 port;
451 u16 name_len; /* Length of name */
452 char name[]; /* Server name, case-flattened */
453 };
454
455 /*
456 * Weighted list of Volume Location servers.
457 */
458 struct afs_vlserver_entry {
459 u16 priority; /* Preference (as SRV) */
460 u16 weight; /* Weight (as SRV) */
461 enum dns_record_source source:8;
462 enum dns_lookup_status status:8;
463 struct afs_vlserver *server;
464 };
465
466 struct afs_vlserver_list {
467 struct rcu_head rcu;
468 refcount_t ref;
469 u8 nr_servers;
470 u8 index; /* Server currently in use */
471 u8 preferred; /* Preferred server */
472 enum dns_record_source source:8;
473 enum dns_lookup_status status:8;
474 rwlock_t lock;
475 struct afs_vlserver_entry servers[];
476 };
477
478 /*
479 * Cached VLDB entry.
480 *
481 * This is pointed to by cell->vldb_entries, indexed by name.
482 */
483 struct afs_vldb_entry {
484 afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
485
486 unsigned long flags;
487 #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
488 #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
489 #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
490 #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
491 #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
492
493 uuid_t fs_server[AFS_NMAXNSERVERS];
494 u32 addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
495 u8 fs_mask[AFS_NMAXNSERVERS];
496 #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
497 #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
498 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
499 u8 vlsf_flags[AFS_NMAXNSERVERS];
500 short error;
501 u8 nr_servers; /* Number of server records */
502 u8 name_len;
503 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
504 };
505
506 /*
507 * Fileserver endpoint state. The records the addresses of a fileserver's
508 * endpoints and the state and result of a round of probing on them. This
509 * allows the rotation algorithm to access those results without them being
510 * erased by a subsequent round of probing.
511 */
512 struct afs_endpoint_state {
513 struct rcu_head rcu;
514 struct afs_addr_list *addresses; /* The addresses being probed */
515 unsigned long responsive_set; /* Bitset of responsive endpoints */
516 unsigned long failed_set; /* Bitset of endpoints we failed to probe */
517 refcount_t ref;
518 unsigned int server_id; /* Debug ID of server */
519 unsigned int probe_seq; /* Probe sequence (from server::probe_counter) */
520 atomic_t nr_probing; /* Number of outstanding probes */
521 unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */
522 s32 abort_code;
523 short error;
524 unsigned long flags;
525 #define AFS_ESTATE_RESPONDED 0 /* Set if the server responded */
526 #define AFS_ESTATE_SUPERSEDED 1 /* Set if this record has been superseded */
527 #define AFS_ESTATE_IS_YFS 2 /* Set if probe upgraded to YFS */
528 #define AFS_ESTATE_NOT_YFS 3 /* Set if probe didn't upgrade to YFS */
529 #define AFS_ESTATE_LOCAL_FAILURE 4 /* Set if there was a local failure (eg. ENOMEM) */
530 };
531
532 /*
533 * Record of fileserver with which we're actively communicating.
534 */
535 struct afs_server {
536 struct rcu_head rcu;
537 union {
538 uuid_t uuid; /* Server ID */
539 struct afs_uuid _uuid;
540 };
541
542 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
543 struct rb_node uuid_rb; /* Link in cell->fs_servers */
544 struct list_head probe_link; /* Link in net->fs_probe_* */
545 struct hlist_node proc_link; /* Link in net->fs_proc */
546 struct list_head volumes; /* RCU list of afs_server_entry objects */
547 struct work_struct destroyer; /* Work item to try and destroy a server */
548 struct timer_list timer; /* Management timer */
549 struct mutex cm_token_lock; /* Lock governing creation of appdata */
550 struct krb5_buffer cm_rxgk_appdata; /* Appdata to be included in RESPONSE packet */
551 time64_t unuse_time; /* Time at which last unused */
552 unsigned long flags;
553 #define AFS_SERVER_FL_RESPONDING 0 /* The server is responding */
554 #define AFS_SERVER_FL_UPDATING 1
555 #define AFS_SERVER_FL_NEEDS_UPDATE 2 /* Fileserver address list is out of date */
556 #define AFS_SERVER_FL_UNCREATED 3 /* The record needs creating */
557 #define AFS_SERVER_FL_CREATING 4 /* The record is being created */
558 #define AFS_SERVER_FL_EXPIRED 5 /* The record has expired */
559 #define AFS_SERVER_FL_NOT_FOUND 6 /* VL server says no such server */
560 #define AFS_SERVER_FL_VL_FAIL 7 /* Failed to access VL server */
561 #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
562 #define AFS_SERVER_FL_IS_YFS 16 /* Server is YFS not AFS */
563 #define AFS_SERVER_FL_NO_IBULK 17 /* Fileserver doesn't support FS.InlineBulkStatus */
564 #define AFS_SERVER_FL_NO_RM2 18 /* Fileserver doesn't support YFS.RemoveFile2 */
565 #define AFS_SERVER_FL_HAS_FS64 19 /* Fileserver supports FS.{Fetch,Store}Data64 */
566 #define AFS_SERVER_FL_NO_RENAME2 20 /* YFS Fileserver doesn't support enhanced rename */
567 refcount_t ref; /* Object refcount */
568 atomic_t active; /* Active user count */
569 u32 addr_version; /* Address list version */
570 u16 service_id; /* Service ID we're using. */
571 short create_error; /* Creation error */
572 unsigned int rtt; /* Server's current RTT in uS */
573 unsigned int debug_id; /* Debugging ID for traces */
574
575 /* file service access */
576 rwlock_t fs_lock; /* access lock */
577
578 /* Probe state */
579 struct afs_endpoint_state __rcu *endpoint_state; /* Latest endpoint/probe state */
580 unsigned long probed_at; /* Time last probe was dispatched (jiffies) */
581 wait_queue_head_t probe_wq;
582 unsigned int probe_counter; /* Number of probes issued */
583 spinlock_t probe_lock;
584 };
585
586 enum afs_ro_replicating {
587 AFS_RO_NOT_REPLICATING, /* Not doing replication */
588 AFS_RO_REPLICATING_USE_OLD, /* Replicating; use old version */
589 AFS_RO_REPLICATING_USE_NEW, /* Replicating; switch to new version */
590 } __mode(byte);
591
592 /*
593 * Replaceable volume server list.
594 */
595 struct afs_server_entry {
596 struct afs_server *server;
597 struct afs_volume *volume;
598 struct list_head slink; /* Link in server->volumes */
599 time64_t cb_expires_at; /* Time at which volume-level callback expires */
600 unsigned long flags;
601 #define AFS_SE_EXCLUDED 0 /* Set if server is to be excluded in rotation */
602 #define AFS_SE_VOLUME_OFFLINE 1 /* Set if volume offline notice given */
603 #define AFS_SE_VOLUME_BUSY 2 /* Set if volume busy notice given */
604 };
605
606 struct afs_server_list {
607 struct rcu_head rcu;
608 refcount_t usage;
609 bool attached; /* T if attached to servers */
610 enum afs_ro_replicating ro_replicating; /* RW->RO update (probably) in progress */
611 unsigned char nr_servers;
612 unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
613 unsigned int seq; /* Set to ->servers_seq when installed */
614 rwlock_t lock;
615 struct afs_server_entry servers[];
616 };
617
618 /*
619 * Live AFS volume management.
620 */
621 struct afs_volume {
622 struct rcu_head rcu;
623 afs_volid_t vid; /* The volume ID of this volume */
624 afs_volid_t vids[AFS_MAXTYPES]; /* All associated volume IDs */
625 refcount_t ref;
626 unsigned int debug_id; /* Debugging ID for traces */
627 time64_t update_at; /* Time at which to next update */
628 struct afs_cell *cell; /* Cell to which belongs (pins ref) */
629 struct rb_node cell_node; /* Link in cell->volumes */
630 struct hlist_node proc_link; /* Link in cell->proc_volumes */
631 struct super_block __rcu *sb; /* Superblock on which inodes reside */
632 struct work_struct destructor; /* Deferred destructor */
633 unsigned long flags;
634 #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
635 #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
636 #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
637 #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
638 #define AFS_VOLUME_MAYBE_NO_IBULK 4 /* - T if some servers don't have InlineBulkStatus */
639 #define AFS_VOLUME_RM_TREE 5 /* - Set if volume removed from cell->volumes */
640 #ifdef CONFIG_AFS_FSCACHE
641 struct fscache_volume *cache; /* Caching cookie */
642 #endif
643 struct afs_server_list __rcu *servers; /* List of servers on which volume resides */
644 rwlock_t servers_lock; /* Lock for ->servers */
645 unsigned int servers_seq; /* Incremented each time ->servers changes */
646
647 /* RO release tracking */
648 struct mutex volsync_lock; /* Time/state evaluation lock */
649 time64_t creation_time; /* Volume creation time (or TIME64_MIN) */
650 time64_t update_time; /* Volume update time (or TIME64_MIN) */
651
652 /* Callback management */
653 struct mutex cb_check_lock; /* Lock to control race to check after v_break */
654 time64_t cb_expires_at; /* Earliest volume callback expiry time */
655 atomic_t cb_ro_snapshot; /* RO volume update-from-snapshot counter */
656 atomic_t cb_v_break; /* Volume-break event counter. */
657 atomic_t cb_v_check; /* Volume-break has-been-checked counter. */
658 atomic_t cb_scrub; /* Scrub-all-data event counter. */
659 rwlock_t cb_v_break_lock;
660 struct rw_semaphore open_mmaps_lock;
661 struct list_head open_mmaps; /* List of vnodes that are mmapped */
662
663 afs_voltype_t type; /* type of volume */
664 char type_force; /* force volume type (suppress R/O -> R/W) */
665 u8 name_len;
666 u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
667 };
668
669 enum afs_lock_state {
670 AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
671 AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
672 AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
673 AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
674 AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
675 AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
676 AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
677 AFS_VNODE_LOCK_DELETED, /* The vnode has been deleted whilst we have a lock */
678 };
679
680 /*
681 * AFS inode private data.
682 *
683 * Note that afs_alloc_inode() *must* reset anything that could incorrectly
684 * leak from one inode to another.
685 */
686 struct afs_vnode {
687 struct netfs_inode netfs; /* Netfslib context and vfs inode */
688 struct afs_volume *volume; /* volume on which vnode resides */
689 struct afs_fid fid; /* the file identifier for this inode */
690 struct afs_file_status status; /* AFS status info for this file */
691 afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
692 struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
693 struct list_head io_lock_waiters; /* Threads waiting for the I/O lock */
694 struct rw_semaphore validate_lock; /* lock for validating this vnode */
695 struct rw_semaphore rmdir_lock; /* Lock for rmdir vs sillyrename */
696 struct key *silly_key; /* Silly rename key */
697 spinlock_t wb_lock; /* lock for wb_keys */
698 spinlock_t lock; /* waitqueue/flags lock */
699 unsigned long flags;
700 #define AFS_VNODE_IO_LOCK 0 /* Set if the I/O serialisation lock is held */
701 #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
702 #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
703 #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
704 #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
705 #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
706 #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
707 #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
708 #define AFS_VNODE_SILLY_DELETED 9 /* Set if file has been silly-deleted */
709 #define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
710 #define AFS_VNODE_DIR_READ 11 /* Set if we've read a dir's contents */
711
712 struct folio_queue *directory; /* Directory contents */
713 struct afs_symlink __rcu *symlink; /* Symlink content */
714 struct list_head wb_keys; /* List of keys available for writeback */
715 struct list_head pending_locks; /* locks waiting to be granted */
716 struct list_head granted_locks; /* locks granted on this file */
717 struct delayed_work lock_work; /* work to be done in locking */
718 struct key *lock_key; /* Key to be used in lock ops */
719 ktime_t locked_at; /* Time at which lock obtained */
720 enum afs_lock_state lock_state : 8;
721 afs_lock_type_t lock_type : 8;
722 unsigned int directory_size; /* Amount of space in ->directory */
723
724 /* outstanding callback notification on this file */
725 struct work_struct cb_work; /* Work for mmap'd files */
726 struct list_head cb_mmap_link; /* Link in cell->fs_open_mmaps */
727 void *cb_server; /* Server with callback/filelock */
728 atomic_t cb_nr_mmap; /* Number of mmaps */
729 unsigned int cb_ro_snapshot; /* RO volume release counter on ->volume */
730 unsigned int cb_scrub; /* Scrub counter on ->volume */
731 unsigned int cb_break; /* Break counter on vnode */
732 unsigned int cb_v_check; /* Break check counter on ->volume */
733 seqlock_t cb_lock; /* Lock for ->cb_server, ->status, ->cb_*break */
734
735 atomic64_t cb_expires_at; /* time at which callback expires */
736 #define AFS_NO_CB_PROMISE TIME64_MIN
737 };
738
afs_vnode_cache(struct afs_vnode * vnode)739 static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
740 {
741 #ifdef CONFIG_AFS_FSCACHE
742 return netfs_i_cookie(&vnode->netfs);
743 #else
744 return NULL;
745 #endif
746 }
747
afs_vnode_set_cache(struct afs_vnode * vnode,struct fscache_cookie * cookie)748 static inline void afs_vnode_set_cache(struct afs_vnode *vnode,
749 struct fscache_cookie *cookie)
750 {
751 #ifdef CONFIG_AFS_FSCACHE
752 vnode->netfs.cache = cookie;
753 if (cookie)
754 mapping_set_release_always(vnode->netfs.inode.i_mapping);
755 #endif
756 }
757
758 /*
759 * cached security record for one user's attempt to access a vnode
760 */
761 struct afs_permit {
762 struct key *key; /* RxRPC ticket holding a security context */
763 afs_access_t access; /* CallerAccess value for this key */
764 };
765
766 /*
767 * Immutable cache of CallerAccess records from attempts to access vnodes.
768 * These may be shared between multiple vnodes.
769 */
770 struct afs_permits {
771 struct rcu_head rcu;
772 struct hlist_node hash_node; /* Link in hash */
773 unsigned long h; /* Hash value for this permit list */
774 refcount_t usage;
775 unsigned short nr_permits; /* Number of records */
776 bool invalidated; /* Invalidated due to key change */
777 struct afs_permit permits[] __counted_by(nr_permits); /* List of permits sorted by key pointer */
778 };
779
780 /*
781 * Copy of symlink content for normal use.
782 */
783 struct afs_symlink {
784 struct rcu_head rcu;
785 refcount_t ref;
786 char content[];
787 };
788
789 /*
790 * Error prioritisation and accumulation.
791 */
792 struct afs_error {
793 s32 abort_code; /* Cumulative abort code */
794 short error; /* Cumulative error */
795 bool responded; /* T if server responded */
796 bool aborted; /* T if ->error is from an abort */
797 };
798
799 /*
800 * Cursor for iterating over a set of volume location servers.
801 */
802 struct afs_vl_cursor {
803 struct afs_cell *cell; /* The cell we're querying */
804 struct afs_vlserver_list *server_list; /* Current server list (pins ref) */
805 struct afs_vlserver *server; /* Server on which this resides */
806 struct afs_addr_list *alist; /* Current address list (pins ref) */
807 struct key *key; /* Key for the server */
808 unsigned long untried_servers; /* Bitmask of untried servers */
809 unsigned long addr_tried; /* Tried addresses */
810 struct afs_error cumul_error; /* Cumulative error */
811 unsigned int debug_id;
812 s32 call_abort_code;
813 short call_error; /* Error from single call */
814 short server_index; /* Current server */
815 signed char addr_index; /* Current address */
816 unsigned short flags;
817 #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */
818 #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */
819 #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */
820 short nr_iterations; /* Number of server iterations */
821 bool call_responded; /* T if the current address responded */
822 };
823
824 /*
825 * Fileserver state tracking for an operation. An array of these is kept,
826 * indexed by server index.
827 */
828 struct afs_server_state {
829 /* Tracking of fileserver probe state. Other operations may interfere
830 * by probing a fileserver when accessing other volumes.
831 */
832 unsigned int probe_seq;
833 unsigned long untried_addrs; /* Addresses we haven't tried yet */
834 struct wait_queue_entry probe_waiter;
835 struct afs_endpoint_state *endpoint_state; /* Endpoint state being monitored */
836 };
837
838 /*
839 * Fileserver operation methods.
840 */
841 struct afs_operation_ops {
842 void (*issue_afs_rpc)(struct afs_operation *op);
843 void (*issue_yfs_rpc)(struct afs_operation *op);
844 void (*success)(struct afs_operation *op);
845 void (*aborted)(struct afs_operation *op);
846 void (*failed)(struct afs_operation *op);
847 void (*edit_dir)(struct afs_operation *op);
848 void (*put)(struct afs_operation *op);
849 };
850
851 struct afs_vnode_param {
852 struct afs_vnode *vnode;
853 struct afs_fid fid; /* Fid to access */
854 struct afs_status_cb scb; /* Returned status and callback promise */
855 afs_dataversion_t dv_before; /* Data version before the call */
856 unsigned int cb_break_before; /* cb_break before the call */
857 u8 dv_delta; /* Expected change in data version */
858 bool put_vnode:1; /* T if we have a ref on the vnode */
859 bool need_io_lock:1; /* T if we need the I/O lock on this */
860 bool update_ctime:1; /* Need to update the ctime */
861 bool set_size:1; /* Must update i_size */
862 bool op_unlinked:1; /* True if file was unlinked by op */
863 bool speculative:1; /* T if speculative status fetch (no vnode lock) */
864 bool modification:1; /* Set if the content gets modified */
865 };
866
867 /*
868 * Fileserver operation wrapper, handling server and address rotation
869 * asynchronously. May make simultaneous calls to multiple servers.
870 */
871 struct afs_operation {
872 struct afs_net *net; /* Network namespace */
873 struct key *key; /* Key for the cell */
874 const struct afs_call_type *type; /* Type of call done */
875 const struct afs_operation_ops *ops;
876
877 /* Parameters/results for the operation */
878 struct afs_volume *volume; /* Volume being accessed */
879 struct afs_vnode_param file[2];
880 struct afs_vnode_param *more_files;
881 struct afs_volsync pre_volsync; /* Volsync before op */
882 struct afs_volsync volsync; /* Volsync returned by op */
883 struct dentry *dentry; /* Dentry to be altered */
884 struct dentry *dentry_2; /* Second dentry to be altered */
885 struct timespec64 mtime; /* Modification time to record */
886 struct timespec64 ctime; /* Change time to set */
887 struct afs_error cumul_error; /* Cumulative error */
888 short nr_files; /* Number of entries in file[], more_files */
889 unsigned int debug_id;
890
891 unsigned int cb_v_break; /* Volume break counter before op */
892
893 union {
894 struct {
895 int which; /* Which ->file[] to fetch for */
896 } fetch_status;
897 struct {
898 int reason; /* enum afs_edit_dir_reason */
899 mode_t mode;
900 struct afs_symlink *symlink;
901 } create;
902 struct {
903 bool need_rehash;
904 } unlink;
905 struct {
906 struct dentry *rehash;
907 struct dentry *tmp;
908 unsigned int rename_flags;
909 bool new_negative;
910 } rename;
911 struct {
912 struct netfs_io_subrequest *subreq;
913 } fetch;
914 struct {
915 afs_lock_type_t type;
916 } lock;
917 struct {
918 struct iov_iter *write_iter;
919 loff_t pos;
920 loff_t size;
921 loff_t i_size;
922 } store;
923 struct {
924 struct iattr *attr;
925 loff_t old_i_size;
926 } setattr;
927 struct afs_acl *acl;
928 struct yfs_acl *yacl;
929 struct {
930 struct afs_volume_status vs;
931 struct kstatfs *buf;
932 } volstatus;
933 };
934
935 /* Fileserver iteration state */
936 struct afs_server_list *server_list; /* Current server list (pins ref) */
937 struct afs_server *server; /* Server we're using (ref pinned by server_list) */
938 struct afs_endpoint_state *estate; /* Current endpoint state (doesn't pin ref) */
939 struct afs_server_state *server_states; /* States of the servers involved */
940 struct afs_call *call;
941 unsigned long untried_servers; /* Bitmask of untried servers */
942 unsigned long addr_tried; /* Tried addresses */
943 s32 call_abort_code; /* Abort code from single call */
944 short call_error; /* Error from single call */
945 short server_index; /* Current server */
946 short nr_iterations; /* Number of server iterations */
947 signed char addr_index; /* Current address */
948 bool call_responded; /* T if the current address responded */
949
950 unsigned int flags;
951 #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */
952 #define AFS_OPERATION_VBUSY 0x0002 /* Set if seen VBUSY */
953 #define AFS_OPERATION_VMOVED 0x0004 /* Set if seen VMOVED */
954 #define AFS_OPERATION_VNOVOL 0x0008 /* Set if seen VNOVOL */
955 #define AFS_OPERATION_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
956 #define AFS_OPERATION_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
957 #define AFS_OPERATION_UNINTR 0x0040 /* Set if op is uninterruptible */
958 #define AFS_OPERATION_DOWNGRADE 0x0080 /* Set to retry with downgraded opcode */
959 #define AFS_OPERATION_LOCK_0 0x0100 /* Set if have io_lock on file[0] */
960 #define AFS_OPERATION_LOCK_1 0x0200 /* Set if have io_lock on file[1] */
961 #define AFS_OPERATION_TRIED_ALL 0x0400 /* Set if we've tried all the fileservers */
962 #define AFS_OPERATION_RETRY_SERVER 0x0800 /* Set if we should retry the current server */
963 #define AFS_OPERATION_DIR_CONFLICT 0x1000 /* Set if we detected a 3rd-party dir change */
964 #define AFS_OPERATION_ASYNC 0x2000 /* Set if should run asynchronously */
965 };
966
967 /*
968 * Cache auxiliary data.
969 */
970 struct afs_vnode_cache_aux {
971 __be64 data_version;
972 } __packed;
973
afs_set_cache_aux(struct afs_vnode * vnode,struct afs_vnode_cache_aux * aux)974 static inline void afs_set_cache_aux(struct afs_vnode *vnode,
975 struct afs_vnode_cache_aux *aux)
976 {
977 aux->data_version = cpu_to_be64(vnode->status.data_version);
978 }
979
afs_invalidate_cache(struct afs_vnode * vnode,unsigned int flags)980 static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int flags)
981 {
982 struct afs_vnode_cache_aux aux;
983
984 afs_set_cache_aux(vnode, &aux);
985 fscache_invalidate(afs_vnode_cache(vnode), &aux,
986 i_size_read(&vnode->netfs.inode), flags);
987 }
988
989 /*
990 * Directory iteration management.
991 */
992 struct afs_dir_iter {
993 struct afs_vnode *dvnode;
994 union afs_xdr_dir_block *block;
995 struct folio_queue *fq;
996 unsigned int fpos;
997 int fq_slot;
998 unsigned int loop_check;
999 u8 nr_slots;
1000 u8 bucket;
1001 unsigned int prev_entry;
1002 };
1003
1004 #include <trace/events/afs.h>
1005
1006 /*****************************************************************************/
1007 /*
1008 * addr_list.c
1009 */
1010 struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
1011 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr);
1012 extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
1013 extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
1014 const char *, size_t, char,
1015 unsigned short, unsigned short);
1016 bool afs_addr_list_same(const struct afs_addr_list *a,
1017 const struct afs_addr_list *b);
1018 extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
1019
1020 extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *addr,
1021 __be32 xdr, u16 port);
1022 extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *addr,
1023 __be32 *xdr, u16 port);
1024 void afs_set_peer_appdata(struct afs_server *server,
1025 struct afs_addr_list *old_alist,
1026 struct afs_addr_list *new_alist);
1027
1028 /*
1029 * addr_prefs.c
1030 */
1031 int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size);
1032 void afs_get_address_preferences_rcu(struct afs_net *net, struct afs_addr_list *alist);
1033 void afs_get_address_preferences(struct afs_net *net, struct afs_addr_list *alist);
1034
1035 /*
1036 * callback.c
1037 */
1038 extern void afs_invalidate_mmap_work(struct work_struct *);
1039 extern void afs_init_callback_state(struct afs_server *);
1040 extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
1041 extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
1042 extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
1043
afs_calc_vnode_cb_break(struct afs_vnode * vnode)1044 static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
1045 {
1046 return vnode->cb_break + vnode->cb_ro_snapshot + vnode->cb_scrub;
1047 }
1048
afs_cb_is_broken(unsigned int cb_break,const struct afs_vnode * vnode)1049 static inline bool afs_cb_is_broken(unsigned int cb_break,
1050 const struct afs_vnode *vnode)
1051 {
1052 return cb_break != (vnode->cb_break +
1053 atomic_read(&vnode->volume->cb_ro_snapshot) +
1054 atomic_read(&vnode->volume->cb_scrub));
1055 }
1056
1057 /*
1058 * cell.c
1059 */
1060 extern int afs_cell_init(struct afs_net *, const char *);
1061 extern struct afs_cell *afs_find_cell(struct afs_net *, const char *, unsigned,
1062 enum afs_cell_trace);
1063 enum afs_lookup_cell_for {
1064 AFS_LOOKUP_CELL_DYNROOT,
1065 AFS_LOOKUP_CELL_MOUNTPOINT,
1066 AFS_LOOKUP_CELL_DIRECT_MOUNT,
1067 AFS_LOOKUP_CELL_PRELOAD,
1068 AFS_LOOKUP_CELL_ROOTCELL,
1069 AFS_LOOKUP_CELL_ALIAS_CHECK,
1070 };
1071 struct afs_cell *afs_lookup_cell(struct afs_net *net,
1072 const char *name, unsigned int namesz,
1073 const char *vllist,
1074 enum afs_lookup_cell_for reason,
1075 enum afs_cell_trace trace);
1076 extern struct afs_cell *afs_use_cell(struct afs_cell *, enum afs_cell_trace);
1077 void afs_unuse_cell(struct afs_cell *cell, enum afs_cell_trace reason);
1078 extern struct afs_cell *afs_get_cell(struct afs_cell *, enum afs_cell_trace);
1079 extern void afs_see_cell(struct afs_cell *, enum afs_cell_trace);
1080 extern void afs_put_cell(struct afs_cell *, enum afs_cell_trace);
1081 extern void afs_queue_cell(struct afs_cell *, enum afs_cell_trace);
1082 void afs_set_cell_timer(struct afs_cell *cell, unsigned int delay_secs);
1083 extern void __net_exit afs_cell_purge(struct afs_net *);
1084
1085 /*
1086 * cmservice.c
1087 */
1088 extern bool afs_cm_incoming_call(struct afs_call *);
1089
1090 /*
1091 * cm_security.c
1092 */
1093 void afs_process_oob_queue(struct work_struct *work);
1094 #ifdef CONFIG_RXGK
1095 int afs_create_token_key(struct afs_net *net, struct socket *socket);
1096 #else
afs_create_token_key(struct afs_net * net,struct socket * socket)1097 static inline int afs_create_token_key(struct afs_net *net, struct socket *socket)
1098 {
1099 return 0;
1100 }
1101 #endif
1102
1103 /*
1104 * dir.c
1105 */
1106 extern const struct file_operations afs_dir_file_operations;
1107 extern const struct inode_operations afs_dir_inode_operations;
1108 extern const struct address_space_operations afs_dir_aops;
1109 extern const struct dentry_operations afs_fs_dentry_operations;
1110
1111 ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
1112 __acquires(&dvnode->validate_lock);
1113 extern void afs_d_release(struct dentry *);
1114 extern void afs_check_for_remote_deletion(struct afs_operation *);
1115
1116 /*
1117 * dir_edit.c
1118 */
1119 extern void afs_edit_dir_add(struct afs_vnode *, const struct qstr *, struct afs_fid *,
1120 enum afs_edit_dir_reason);
1121 extern void afs_edit_dir_remove(struct afs_vnode *, const struct qstr *, enum afs_edit_dir_reason);
1122 void afs_edit_dir_update(struct afs_vnode *vnode, const struct qstr *name,
1123 struct afs_vnode *new_dvnode, enum afs_edit_dir_reason why);
1124 void afs_mkdir_init_dir(struct afs_vnode *dvnode, struct afs_vnode *parent_vnode);
1125
1126 /*
1127 * dir_search.c
1128 */
1129 unsigned int afs_dir_hash_name(const struct qstr *name);
1130 bool afs_dir_init_iter(struct afs_dir_iter *iter, const struct qstr *name);
1131 union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t block);
1132 int afs_dir_search_bucket(struct afs_dir_iter *iter, const struct qstr *name,
1133 struct afs_fid *_fid);
1134 int afs_dir_search(struct afs_vnode *dvnode, const struct qstr *name,
1135 struct afs_fid *_fid, afs_dataversion_t *_dir_version);
1136
1137 /*
1138 * dir_silly.c
1139 */
1140 extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
1141 struct dentry *, struct key *);
1142 extern int afs_silly_iput(struct dentry *, struct inode *);
1143
1144 /*
1145 * dynroot.c
1146 */
1147 extern const struct inode_operations afs_dynroot_inode_operations;
1148 extern const struct dentry_operations afs_dynroot_dentry_operations;
1149
1150 struct inode *afs_dynroot_iget_root(struct super_block *sb);
1151
1152 /*
1153 * file.c
1154 */
1155 extern const struct address_space_operations afs_file_aops;
1156 extern const struct inode_operations afs_file_inode_operations;
1157 extern const struct file_operations afs_file_operations;
1158 extern const struct afs_operation_ops afs_fetch_data_operation;
1159 extern const struct netfs_request_ops afs_req_ops;
1160
1161 extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
1162 extern void afs_put_wb_key(struct afs_wb_key *);
1163 extern int afs_open(struct inode *, struct file *);
1164 extern int afs_release(struct inode *, struct file *);
1165 void afs_fetch_data_async_rx(struct work_struct *work);
1166 void afs_fetch_data_immediate_cancel(struct afs_call *call);
1167 void afs_set_i_size(struct afs_vnode *vnode, loff_t new_i_size);
1168
1169 /*
1170 * flock.c
1171 */
1172 extern struct workqueue_struct *afs_lock_manager;
1173
1174 extern void afs_lock_op_done(struct afs_call *);
1175 extern void afs_lock_work(struct work_struct *);
1176 extern void afs_lock_may_be_available(struct afs_vnode *);
1177 extern int afs_lock(struct file *, int, struct file_lock *);
1178 extern int afs_flock(struct file *, int, struct file_lock *);
1179
1180 /*
1181 * fsclient.c
1182 */
1183 extern void afs_fs_fetch_status(struct afs_operation *);
1184 extern void afs_fs_fetch_data(struct afs_operation *);
1185 extern void afs_fs_create_file(struct afs_operation *);
1186 extern void afs_fs_make_dir(struct afs_operation *);
1187 extern void afs_fs_remove_file(struct afs_operation *);
1188 extern void afs_fs_remove_dir(struct afs_operation *);
1189 extern void afs_fs_link(struct afs_operation *);
1190 extern void afs_fs_symlink(struct afs_operation *);
1191 extern void afs_fs_rename(struct afs_operation *);
1192 extern void afs_fs_store_data(struct afs_operation *);
1193 extern void afs_fs_setattr(struct afs_operation *);
1194 extern void afs_fs_get_volume_status(struct afs_operation *);
1195 extern void afs_fs_set_lock(struct afs_operation *);
1196 extern void afs_fs_extend_lock(struct afs_operation *);
1197 extern void afs_fs_release_lock(struct afs_operation *);
1198 int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
1199 struct afs_address *addr, struct key *key);
1200 bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
1201 struct afs_endpoint_state *estate, unsigned int addr_index,
1202 struct key *key);
1203 extern void afs_fs_inline_bulk_status(struct afs_operation *);
1204
1205 struct afs_acl {
1206 u32 size;
1207 u8 data[] __counted_by(size);
1208 };
1209
1210 extern void afs_fs_fetch_acl(struct afs_operation *);
1211 extern void afs_fs_store_acl(struct afs_operation *);
1212
1213 /*
1214 * fs_operation.c
1215 */
1216 extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
1217 extern int afs_put_operation(struct afs_operation *);
1218 extern bool afs_begin_vnode_operation(struct afs_operation *);
1219 extern void afs_end_vnode_operation(struct afs_operation *op);
1220 extern void afs_wait_for_operation(struct afs_operation *);
1221 extern int afs_do_sync_operation(struct afs_operation *);
1222
afs_op_set_vnode(struct afs_operation * op,unsigned int n,struct afs_vnode * vnode)1223 static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
1224 struct afs_vnode *vnode)
1225 {
1226 op->file[n].vnode = vnode;
1227 op->file[n].need_io_lock = true;
1228 }
1229
afs_op_set_fid(struct afs_operation * op,unsigned int n,const struct afs_fid * fid)1230 static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
1231 const struct afs_fid *fid)
1232 {
1233 op->file[n].fid = *fid;
1234 }
1235
1236 /*
1237 * fs_probe.c
1238 */
1239 struct afs_endpoint_state *afs_get_endpoint_state(struct afs_endpoint_state *estate,
1240 enum afs_estate_trace where);
1241 void afs_put_endpoint_state(struct afs_endpoint_state *estate, enum afs_estate_trace where);
1242 extern void afs_fileserver_probe_result(struct afs_call *);
1243 int afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
1244 struct afs_addr_list *new_alist, struct key *key);
1245 int afs_wait_for_fs_probes(struct afs_operation *op, struct afs_server_state *states, bool intr);
1246 extern void afs_probe_fileserver(struct afs_net *, struct afs_server *);
1247 extern void afs_fs_probe_dispatcher(struct work_struct *);
1248 int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoint_state *estate,
1249 unsigned long exclude, bool is_intr);
1250 extern void afs_fs_probe_cleanup(struct afs_net *);
1251
1252 /*
1253 * inode.c
1254 */
1255 extern const struct afs_operation_ops afs_fetch_status_operation;
1256
1257 extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
1258 extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1259 extern int afs_ilookup5_test_by_fid(struct inode *, void *);
1260 extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
1261 extern struct inode *afs_root_iget(struct super_block *, struct key *);
1262 extern int afs_getattr(struct mnt_idmap *idmap, const struct path *,
1263 struct kstat *, u32, unsigned int);
1264 extern int afs_setattr(struct mnt_idmap *idmap, struct dentry *, struct iattr *);
1265 extern void afs_evict_inode(struct inode *);
1266 extern int afs_drop_inode(struct inode *);
1267
1268 /*
1269 * main.c
1270 */
1271 extern struct workqueue_struct *afs_wq;
1272 extern int afs_net_id;
1273
afs_net(struct net * net)1274 static inline struct afs_net *afs_net(struct net *net)
1275 {
1276 return net_generic(net, afs_net_id);
1277 }
1278
afs_sb2net(struct super_block * sb)1279 static inline struct afs_net *afs_sb2net(struct super_block *sb)
1280 {
1281 return afs_net(AFS_FS_S(sb)->net_ns);
1282 }
1283
afs_d2net(struct dentry * dentry)1284 static inline struct afs_net *afs_d2net(struct dentry *dentry)
1285 {
1286 return afs_sb2net(dentry->d_sb);
1287 }
1288
afs_i2net(struct inode * inode)1289 static inline struct afs_net *afs_i2net(struct inode *inode)
1290 {
1291 return afs_sb2net(inode->i_sb);
1292 }
1293
afs_v2net(struct afs_vnode * vnode)1294 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1295 {
1296 return afs_i2net(&vnode->netfs.inode);
1297 }
1298
afs_sock2net(struct sock * sk)1299 static inline struct afs_net *afs_sock2net(struct sock *sk)
1300 {
1301 return net_generic(sock_net(sk), afs_net_id);
1302 }
1303
__afs_stat(atomic_t * s)1304 static inline void __afs_stat(atomic_t *s)
1305 {
1306 atomic_inc(s);
1307 }
1308
1309 #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1310
1311 /*
1312 * misc.c
1313 */
1314 extern int afs_abort_to_error(u32);
1315 extern void afs_prioritise_error(struct afs_error *, int, u32);
1316
afs_op_nomem(struct afs_operation * op)1317 static inline void afs_op_nomem(struct afs_operation *op)
1318 {
1319 op->cumul_error.error = -ENOMEM;
1320 }
1321
afs_op_error(const struct afs_operation * op)1322 static inline int afs_op_error(const struct afs_operation *op)
1323 {
1324 return op->cumul_error.error;
1325 }
1326
afs_op_abort_code(const struct afs_operation * op)1327 static inline s32 afs_op_abort_code(const struct afs_operation *op)
1328 {
1329 return op->cumul_error.abort_code;
1330 }
1331
afs_op_set_error(struct afs_operation * op,int error)1332 static inline int afs_op_set_error(struct afs_operation *op, int error)
1333 {
1334 return op->cumul_error.error = error;
1335 }
1336
afs_op_accumulate_error(struct afs_operation * op,int error,s32 abort_code)1337 static inline void afs_op_accumulate_error(struct afs_operation *op, int error, s32 abort_code)
1338 {
1339 afs_prioritise_error(&op->cumul_error, error, abort_code);
1340 }
1341
1342 /*
1343 * mntpt.c
1344 */
1345 extern const struct inode_operations afs_mntpt_inode_operations;
1346 extern const struct inode_operations afs_autocell_inode_operations;
1347 extern const struct file_operations afs_mntpt_file_operations;
1348
1349 extern struct vfsmount *afs_d_automount(struct path *);
1350 extern void afs_mntpt_kill_timer(void);
1351
1352 /*
1353 * proc.c
1354 */
1355 #ifdef CONFIG_PROC_FS
1356 extern int __net_init afs_proc_init(struct afs_net *);
1357 extern void __net_exit afs_proc_cleanup(struct afs_net *);
1358 extern int afs_proc_cell_setup(struct afs_cell *);
1359 extern void afs_proc_cell_remove(struct afs_cell *);
1360 extern void afs_put_sysnames(struct afs_sysnames *);
1361 #else
afs_proc_init(struct afs_net * net)1362 static inline int afs_proc_init(struct afs_net *net) { return 0; }
afs_proc_cleanup(struct afs_net * net)1363 static inline void afs_proc_cleanup(struct afs_net *net) {}
afs_proc_cell_setup(struct afs_cell * cell)1364 static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
afs_proc_cell_remove(struct afs_cell * cell)1365 static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
afs_put_sysnames(struct afs_sysnames * sysnames)1366 static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1367 #endif
1368
1369 /*
1370 * rotate.c
1371 */
1372 void afs_clear_server_states(struct afs_operation *op);
1373 extern bool afs_select_fileserver(struct afs_operation *);
1374 extern void afs_dump_edestaddrreq(const struct afs_operation *);
1375
1376 /*
1377 * rxrpc.c
1378 */
1379 extern struct workqueue_struct *afs_async_calls;
1380
1381 extern int __net_init afs_open_socket(struct afs_net *);
1382 extern void __net_exit afs_close_socket(struct afs_net *);
1383 extern void afs_charge_preallocation(struct work_struct *);
1384 extern void afs_put_call(struct afs_call *);
1385 void afs_deferred_put_call(struct afs_call *call);
1386 void afs_make_call(struct afs_call *call, gfp_t gfp);
1387 void afs_deliver_to_call(struct afs_call *call);
1388 void afs_wait_for_call_to_complete(struct afs_call *call);
1389 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1390 const struct afs_call_type *,
1391 size_t, size_t);
1392 extern void afs_flat_call_destructor(struct afs_call *);
1393 extern void afs_send_empty_reply(struct afs_call *);
1394 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
1395 extern int afs_extract_data(struct afs_call *, bool);
1396 extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
1397
afs_get_call(struct afs_call * call,enum afs_call_trace why)1398 static inline struct afs_call *afs_get_call(struct afs_call *call,
1399 enum afs_call_trace why)
1400 {
1401 int r;
1402
1403 __refcount_inc(&call->ref, &r);
1404
1405 trace_afs_call(call->debug_id, why, r + 1,
1406 atomic_read(&call->net->nr_outstanding_calls),
1407 __builtin_return_address(0));
1408 return call;
1409 }
1410
afs_see_call(struct afs_call * call,enum afs_call_trace why)1411 static inline void afs_see_call(struct afs_call *call, enum afs_call_trace why)
1412 {
1413 int r = refcount_read(&call->ref);
1414
1415 trace_afs_call(call->debug_id, why, r,
1416 atomic_read(&call->net->nr_outstanding_calls),
1417 __builtin_return_address(0));
1418 }
1419
afs_make_op_call(struct afs_operation * op,struct afs_call * call,gfp_t gfp)1420 static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
1421 gfp_t gfp)
1422 {
1423 struct afs_addr_list *alist = op->estate->addresses;
1424
1425 op->call = call;
1426 op->type = call->type;
1427 call->op = op;
1428 call->key = op->key;
1429 call->intr = !(op->flags & AFS_OPERATION_UNINTR);
1430 call->peer = rxrpc_kernel_get_peer(alist->addrs[op->addr_index].peer);
1431 call->service_id = op->server->service_id;
1432 afs_make_call(call, gfp);
1433 }
1434
afs_extract_begin(struct afs_call * call,void * buf,size_t size)1435 static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
1436 {
1437 call->iov_len = size;
1438 call->kvec[0].iov_base = buf;
1439 call->kvec[0].iov_len = size;
1440 iov_iter_kvec(&call->def_iter, ITER_DEST, call->kvec, 1, size);
1441 }
1442
afs_extract_to_tmp(struct afs_call * call)1443 static inline void afs_extract_to_tmp(struct afs_call *call)
1444 {
1445 call->iov_len = sizeof(call->tmp);
1446 afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
1447 }
1448
afs_extract_to_tmp64(struct afs_call * call)1449 static inline void afs_extract_to_tmp64(struct afs_call *call)
1450 {
1451 call->iov_len = sizeof(call->tmp64);
1452 afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
1453 }
1454
afs_extract_discard(struct afs_call * call,size_t size)1455 static inline void afs_extract_discard(struct afs_call *call, size_t size)
1456 {
1457 call->iov_len = size;
1458 iov_iter_discard(&call->def_iter, ITER_DEST, size);
1459 }
1460
afs_extract_to_buf(struct afs_call * call,size_t size)1461 static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
1462 {
1463 call->iov_len = size;
1464 afs_extract_begin(call, call->buffer, size);
1465 }
1466
afs_transfer_reply(struct afs_call * call)1467 static inline int afs_transfer_reply(struct afs_call *call)
1468 {
1469 return afs_extract_data(call, false);
1470 }
1471
afs_check_call_state(struct afs_call * call,enum afs_call_state state)1472 static inline bool afs_check_call_state(struct afs_call *call,
1473 enum afs_call_state state)
1474 {
1475 return READ_ONCE(call->state) == state;
1476 }
1477
afs_set_call_state(struct afs_call * call,enum afs_call_state from,enum afs_call_state to)1478 static inline bool afs_set_call_state(struct afs_call *call,
1479 enum afs_call_state from,
1480 enum afs_call_state to)
1481 {
1482 bool ok = false;
1483
1484 spin_lock_bh(&call->state_lock);
1485 if (call->state == from) {
1486 call->state = to;
1487 trace_afs_call_state(call, from, to, 0, 0);
1488 ok = true;
1489 }
1490 spin_unlock_bh(&call->state_lock);
1491 return ok;
1492 }
1493
afs_set_call_complete(struct afs_call * call,int error,u32 remote_abort)1494 static inline void afs_set_call_complete(struct afs_call *call,
1495 int error, u32 remote_abort)
1496 {
1497 enum afs_call_state state;
1498 bool ok = false;
1499
1500 spin_lock_bh(&call->state_lock);
1501 state = call->state;
1502 if (state != AFS_CALL_COMPLETE) {
1503 call->abort_code = remote_abort;
1504 call->error = error;
1505 call->state = AFS_CALL_COMPLETE;
1506 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
1507 error, remote_abort);
1508 ok = true;
1509 }
1510 spin_unlock_bh(&call->state_lock);
1511 if (ok) {
1512 trace_afs_call_done(call);
1513
1514 /* Asynchronous calls have two refs to release - one from the alloc and
1515 * one queued with the work item - and we can't just deallocate the
1516 * call because the work item may be queued again.
1517 */
1518 if (call->drop_ref)
1519 afs_put_call(call);
1520 }
1521 }
1522
1523 /*
1524 * security.c
1525 */
1526 extern void afs_put_permits(struct afs_permits *);
1527 extern void afs_clear_permits(struct afs_vnode *);
1528 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1529 struct afs_status_cb *);
1530 extern struct key *afs_request_key(struct afs_cell *);
1531 extern struct key *afs_request_key_rcu(struct afs_cell *);
1532 extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
1533 extern int afs_permission(struct mnt_idmap *, struct inode *, int);
1534 extern void __exit afs_clean_up_permit_cache(void);
1535
1536 /*
1537 * server.c
1538 */
1539 extern spinlock_t afs_server_peer_lock;
1540
1541 struct afs_server *afs_find_server(const struct rxrpc_peer *peer);
1542 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
1543 extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
1544 struct afs_server *afs_use_server(struct afs_server *server, bool activate,
1545 enum afs_server_trace reason);
1546 void afs_unuse_server(struct afs_net *net, struct afs_server *server,
1547 enum afs_server_trace reason);
1548 void afs_unuse_server_notime(struct afs_net *net, struct afs_server *server,
1549 enum afs_server_trace reason);
1550 extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1551 void afs_purge_servers(struct afs_cell *cell);
1552 extern void afs_fs_probe_timer(struct timer_list *);
1553 void __net_exit afs_wait_for_servers(struct afs_net *net);
1554 bool afs_check_server_record(struct afs_operation *op, struct afs_server *server, struct key *key);
1555
afs_see_server(struct afs_server * server,enum afs_server_trace trace)1556 static inline void afs_see_server(struct afs_server *server, enum afs_server_trace trace)
1557 {
1558 int r = refcount_read(&server->ref);
1559 int a = atomic_read(&server->active);
1560
1561 trace_afs_server(server->debug_id, r, a, trace);
1562
1563 }
1564
afs_inc_servers_outstanding(struct afs_net * net)1565 static inline void afs_inc_servers_outstanding(struct afs_net *net)
1566 {
1567 atomic_inc(&net->servers_outstanding);
1568 }
1569
afs_dec_servers_outstanding(struct afs_net * net)1570 static inline void afs_dec_servers_outstanding(struct afs_net *net)
1571 {
1572 if (atomic_dec_and_test(&net->servers_outstanding))
1573 wake_up_var(&net->servers_outstanding);
1574 }
1575
afs_is_probing_server(struct afs_server * server)1576 static inline bool afs_is_probing_server(struct afs_server *server)
1577 {
1578 return list_empty(&server->probe_link);
1579 }
1580
1581 /*
1582 * server_list.c
1583 */
afs_get_serverlist(struct afs_server_list * slist)1584 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1585 {
1586 refcount_inc(&slist->usage);
1587 return slist;
1588 }
1589
1590 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1591 struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,
1592 struct key *key,
1593 struct afs_vldb_entry *vldb);
1594 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1595 void afs_attach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist);
1596 void afs_reattach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist,
1597 struct afs_server_list *old);
1598 void afs_detach_volume_from_servers(struct afs_volume *volume, struct afs_server_list *slist);
1599
1600 /*
1601 * super.c
1602 */
1603 extern int __init afs_fs_init(void);
1604 extern void afs_fs_exit(void);
1605
1606 /*
1607 * symlink.c
1608 */
1609 extern const struct inode_operations afs_symlink_inode_operations;
1610 extern const struct address_space_operations afs_symlink_aops;
1611
1612 void afs_invalidate_symlink(struct afs_vnode *vnode);
1613 void afs_evict_symlink(struct afs_vnode *vnode);
1614 void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op);
1615 const char *afs_get_link(struct dentry *dentry, struct inode *inode,
1616 struct delayed_call *callback);
1617 int afs_readlink(struct dentry *dentry, char __user *buffer, int buflen);
1618 int afs_symlink_writepages(struct address_space *mapping,
1619 struct writeback_control *wbc);
1620
1621 /*
1622 * validation.c
1623 */
1624 bool afs_check_validity(const struct afs_vnode *vnode);
1625 int afs_update_volume_state(struct afs_operation *op);
1626 int afs_validate(struct afs_vnode *vnode, struct key *key);
1627
1628 /*
1629 * vlclient.c
1630 */
1631 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
1632 const char *, int);
1633 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
1634 struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
1635 struct afs_addr_list *alist,
1636 unsigned int addr_index,
1637 struct key *key,
1638 struct afs_vlserver *server,
1639 unsigned int server_index);
1640 extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
1641 extern char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *);
1642
1643 /*
1644 * vl_alias.c
1645 */
1646 extern int afs_cell_detect_alias(struct afs_cell *, struct key *);
1647
1648 /*
1649 * vl_probe.c
1650 */
1651 extern void afs_vlserver_probe_result(struct afs_call *);
1652 extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
1653 extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
1654
1655 /*
1656 * vl_rotate.c
1657 */
1658 extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
1659 struct afs_cell *, struct key *);
1660 extern bool afs_select_vlserver(struct afs_vl_cursor *);
1661 extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
1662 extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
1663
1664 /*
1665 * vlserver_list.c
1666 */
afs_get_vlserver(struct afs_vlserver * vlserver)1667 static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
1668 {
1669 refcount_inc(&vlserver->ref);
1670 return vlserver;
1671 }
1672
afs_get_vlserverlist(struct afs_vlserver_list * vllist)1673 static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
1674 {
1675 if (vllist)
1676 refcount_inc(&vllist->ref);
1677 return vllist;
1678 }
1679
1680 extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
1681 extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
1682 extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
1683 extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
1684 extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
1685 const void *, size_t);
1686
1687 /*
1688 * volume.c
1689 */
1690 extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1691 extern int afs_activate_volume(struct afs_volume *);
1692 extern void afs_deactivate_volume(struct afs_volume *);
1693 bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace reason);
1694 extern struct afs_volume *afs_get_volume(struct afs_volume *, enum afs_volume_trace);
1695 void afs_put_volume(struct afs_volume *volume, enum afs_volume_trace reason);
1696 extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
1697
1698 /*
1699 * write.c
1700 */
1701 void afs_prepare_write(struct netfs_io_subrequest *subreq);
1702 void afs_issue_write(struct netfs_io_subrequest *subreq);
1703 void afs_begin_writeback(struct netfs_io_request *wreq);
1704 void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream);
1705 extern int afs_writepages(struct address_space *, struct writeback_control *);
1706 extern int afs_fsync(struct file *, loff_t, loff_t, int);
1707 extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
1708 extern void afs_prune_wb_keys(struct afs_vnode *);
1709
1710 /*
1711 * xattr.c
1712 */
1713 extern const struct xattr_handler * const afs_xattr_handlers[];
1714
1715 /*
1716 * yfsclient.c
1717 */
1718 extern void yfs_fs_fetch_data(struct afs_operation *);
1719 extern void yfs_fs_create_file(struct afs_operation *);
1720 extern void yfs_fs_make_dir(struct afs_operation *);
1721 extern void yfs_fs_remove_file2(struct afs_operation *);
1722 extern void yfs_fs_remove_file(struct afs_operation *);
1723 extern void yfs_fs_remove_dir(struct afs_operation *);
1724 extern void yfs_fs_link(struct afs_operation *);
1725 extern void yfs_fs_symlink(struct afs_operation *);
1726 extern void yfs_fs_rename(struct afs_operation *);
1727 void yfs_fs_rename_replace(struct afs_operation *op);
1728 void yfs_fs_rename_noreplace(struct afs_operation *op);
1729 void yfs_fs_rename_exchange(struct afs_operation *op);
1730 extern void yfs_fs_store_data(struct afs_operation *);
1731 extern void yfs_fs_setattr(struct afs_operation *);
1732 extern void yfs_fs_get_volume_status(struct afs_operation *);
1733 extern void yfs_fs_set_lock(struct afs_operation *);
1734 extern void yfs_fs_extend_lock(struct afs_operation *);
1735 extern void yfs_fs_release_lock(struct afs_operation *);
1736 extern void yfs_fs_fetch_status(struct afs_operation *);
1737 extern void yfs_fs_inline_bulk_status(struct afs_operation *);
1738
1739 struct yfs_acl {
1740 struct afs_acl *acl; /* Dir/file/symlink ACL */
1741 struct afs_acl *vol_acl; /* Whole volume ACL */
1742 u32 inherit_flag; /* True if ACL is inherited from parent dir */
1743 u32 num_cleaned; /* Number of ACEs removed due to subject removal */
1744 unsigned int flags;
1745 #define YFS_ACL_WANT_ACL 0x01 /* Set if caller wants ->acl */
1746 #define YFS_ACL_WANT_VOL_ACL 0x02 /* Set if caller wants ->vol_acl */
1747 };
1748
1749 extern void yfs_free_opaque_acl(struct yfs_acl *);
1750 extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
1751 extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
1752
1753 /*
1754 * Miscellaneous inline functions.
1755 */
AFS_FS_I(struct inode * inode)1756 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1757 {
1758 return container_of(inode, struct afs_vnode, netfs.inode);
1759 }
1760
AFS_VNODE_TO_I(struct afs_vnode * vnode)1761 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1762 {
1763 return &vnode->netfs.inode;
1764 }
1765
1766 /*
1767 * Note that a dentry got changed. We need to set d_fsdata to the data version
1768 * number derived from the result of the operation. It doesn't matter if
1769 * d_fsdata goes backwards as we'll just revalidate.
1770 */
afs_update_dentry_version(struct afs_operation * op,struct afs_vnode_param * dir_vp,struct dentry * dentry)1771 static inline void afs_update_dentry_version(struct afs_operation *op,
1772 struct afs_vnode_param *dir_vp,
1773 struct dentry *dentry)
1774 {
1775 if (!op->cumul_error.error)
1776 dentry->d_fsdata =
1777 (void *)(unsigned long)dir_vp->scb.status.data_version;
1778 }
1779
1780 /*
1781 * Check for a conflicting operation on a directory that we just unlinked from.
1782 * If someone managed to sneak a link or an unlink in on the file we just
1783 * unlinked, we won't be able to trust nlink on an AFS file (but not YFS).
1784 */
afs_check_dir_conflict(struct afs_operation * op,struct afs_vnode_param * dvp)1785 static inline void afs_check_dir_conflict(struct afs_operation *op,
1786 struct afs_vnode_param *dvp)
1787 {
1788 if (dvp->dv_before + dvp->dv_delta != dvp->scb.status.data_version)
1789 op->flags |= AFS_OPERATION_DIR_CONFLICT;
1790 }
1791
afs_io_error(struct afs_call * call,enum afs_io_error where)1792 static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1793 {
1794 trace_afs_io_error(call->debug_id, -EIO, where);
1795 return -EIO;
1796 }
1797
afs_bad(struct afs_vnode * vnode,enum afs_file_error where)1798 static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1799 {
1800 trace_afs_file_error(vnode, -EIO, where);
1801 return -EIO;
1802 }
1803
1804 /*
1805 * Set the callback promise on a vnode.
1806 */
afs_set_cb_promise(struct afs_vnode * vnode,time64_t expires_at,enum afs_cb_promise_trace trace)1807 static inline void afs_set_cb_promise(struct afs_vnode *vnode, time64_t expires_at,
1808 enum afs_cb_promise_trace trace)
1809 {
1810 atomic64_set(&vnode->cb_expires_at, expires_at);
1811 trace_afs_cb_promise(vnode, trace);
1812 }
1813
1814 /*
1815 * Clear the callback promise on a vnode, returning true if it was promised.
1816 */
afs_clear_cb_promise(struct afs_vnode * vnode,enum afs_cb_promise_trace trace)1817 static inline bool afs_clear_cb_promise(struct afs_vnode *vnode,
1818 enum afs_cb_promise_trace trace)
1819 {
1820 trace_afs_cb_promise(vnode, trace);
1821 return atomic64_xchg(&vnode->cb_expires_at, AFS_NO_CB_PROMISE) != AFS_NO_CB_PROMISE;
1822 }
1823
1824 /*
1825 * Mark a directory as being invalid.
1826 */
afs_invalidate_dir(struct afs_vnode * dvnode,enum afs_dir_invalid_trace trace)1827 static inline void afs_invalidate_dir(struct afs_vnode *dvnode,
1828 enum afs_dir_invalid_trace trace)
1829 {
1830 if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
1831 trace_afs_dir_invalid(dvnode, trace);
1832 afs_stat_v(dvnode, n_inval);
1833 }
1834 }
1835
1836 /*****************************************************************************/
1837 /*
1838 * debug tracing
1839 */
1840 extern unsigned afs_debug;
1841
1842 #define dbgprintk(FMT,...) \
1843 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1844
1845 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1846 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1847 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1848
1849
1850 #if defined(__KDEBUG)
1851 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1852 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1853 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1854
1855 #elif defined(CONFIG_AFS_DEBUG)
1856 #define AFS_DEBUG_KENTER 0x01
1857 #define AFS_DEBUG_KLEAVE 0x02
1858 #define AFS_DEBUG_KDEBUG 0x04
1859
1860 #define _enter(FMT,...) \
1861 do { \
1862 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
1863 kenter(FMT,##__VA_ARGS__); \
1864 } while (0)
1865
1866 #define _leave(FMT,...) \
1867 do { \
1868 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
1869 kleave(FMT,##__VA_ARGS__); \
1870 } while (0)
1871
1872 #define _debug(FMT,...) \
1873 do { \
1874 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
1875 kdebug(FMT,##__VA_ARGS__); \
1876 } while (0)
1877
1878 #else
1879 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1880 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1881 #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
1882 #endif
1883
1884 /*
1885 * debug assertion checking
1886 */
1887 #if 1 // defined(__KDEBUGALL)
1888
1889 #define ASSERT(X) \
1890 do { \
1891 if (unlikely(!(X))) { \
1892 printk(KERN_ERR "\n"); \
1893 printk(KERN_ERR "AFS: Assertion failed\n"); \
1894 BUG(); \
1895 } \
1896 } while(0)
1897
1898 #define ASSERTCMP(X, OP, Y) \
1899 do { \
1900 if (unlikely(!((X) OP (Y)))) { \
1901 printk(KERN_ERR "\n"); \
1902 printk(KERN_ERR "AFS: Assertion failed\n"); \
1903 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1904 (unsigned long)(X), (unsigned long)(Y)); \
1905 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1906 (unsigned long)(X), (unsigned long)(Y)); \
1907 BUG(); \
1908 } \
1909 } while(0)
1910
1911 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1912 do { \
1913 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
1914 printk(KERN_ERR "\n"); \
1915 printk(KERN_ERR "AFS: Assertion failed\n"); \
1916 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1917 (unsigned long)(L), (unsigned long)(N), \
1918 (unsigned long)(H)); \
1919 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1920 (unsigned long)(L), (unsigned long)(N), \
1921 (unsigned long)(H)); \
1922 BUG(); \
1923 } \
1924 } while(0)
1925
1926 #define ASSERTIF(C, X) \
1927 do { \
1928 if (unlikely((C) && !(X))) { \
1929 printk(KERN_ERR "\n"); \
1930 printk(KERN_ERR "AFS: Assertion failed\n"); \
1931 BUG(); \
1932 } \
1933 } while(0)
1934
1935 #define ASSERTIFCMP(C, X, OP, Y) \
1936 do { \
1937 if (unlikely((C) && !((X) OP (Y)))) { \
1938 printk(KERN_ERR "\n"); \
1939 printk(KERN_ERR "AFS: Assertion failed\n"); \
1940 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
1941 (unsigned long)(X), (unsigned long)(Y)); \
1942 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
1943 (unsigned long)(X), (unsigned long)(Y)); \
1944 BUG(); \
1945 } \
1946 } while(0)
1947
1948 #else
1949
1950 #define ASSERT(X) \
1951 do { \
1952 } while(0)
1953
1954 #define ASSERTCMP(X, OP, Y) \
1955 do { \
1956 } while(0)
1957
1958 #define ASSERTRANGE(L, OP1, N, OP2, H) \
1959 do { \
1960 } while(0)
1961
1962 #define ASSERTIF(C, X) \
1963 do { \
1964 } while(0)
1965
1966 #define ASSERTIFCMP(C, X, OP, Y) \
1967 do { \
1968 } while(0)
1969
1970 #endif /* __KDEBUGALL */
1971