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