OSDN Git Service

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