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