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