GNU Linux-libre 4.9.330-gnu1
[releases.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 <net/af_rxrpc.h>
24
25 #include "afs.h"
26 #include "afs_vl.h"
27
28 #define AFS_CELL_MAX_ADDRS 15
29
30 struct pagevec;
31 struct afs_call;
32
33 typedef enum {
34         AFS_VL_NEW,                     /* new, uninitialised record */
35         AFS_VL_CREATING,                /* creating record */
36         AFS_VL_VALID,                   /* record is pending */
37         AFS_VL_NO_VOLUME,               /* no such volume available */
38         AFS_VL_UPDATING,                /* update in progress */
39         AFS_VL_VOLUME_DELETED,          /* volume was deleted */
40         AFS_VL_UNCERTAIN,               /* uncertain state (update failed) */
41 } __attribute__((packed)) afs_vlocation_state_t;
42
43 struct afs_mount_params {
44         bool                    rwpath;         /* T if the parent should be considered R/W */
45         bool                    force;          /* T to force cell type */
46         bool                    autocell;       /* T if set auto mount operation */
47         afs_voltype_t           type;           /* type of volume requested */
48         int                     volnamesz;      /* size of volume name */
49         const char              *volname;       /* name of volume to mount */
50         struct afs_cell         *cell;          /* cell in which to find volume */
51         struct afs_volume       *volume;        /* volume record */
52         struct key              *key;           /* key to use for secure mounting */
53 };
54
55 /*
56  * definition of how to wait for the completion of an operation
57  */
58 struct afs_wait_mode {
59         /* RxRPC received message notification */
60         rxrpc_notify_rx_t notify_rx;
61
62         /* synchronous call waiter and call dispatched notification */
63         int (*wait)(struct afs_call *call);
64
65         /* asynchronous call completion */
66         void (*async_complete)(void *reply, int error);
67 };
68
69 extern const struct afs_wait_mode afs_sync_call;
70 extern const struct afs_wait_mode afs_async_call;
71
72 /*
73  * a record of an in-progress RxRPC call
74  */
75 struct afs_call {
76         const struct afs_call_type *type;       /* type of call */
77         const struct afs_wait_mode *wait_mode;  /* completion wait mode */
78         wait_queue_head_t       waitq;          /* processes awaiting completion */
79         struct work_struct      async_work;     /* asynchronous work processor */
80         struct work_struct      work;           /* actual work processor */
81         struct rxrpc_call       *rxcall;        /* RxRPC call handle */
82         struct key              *key;           /* security for this call */
83         struct afs_server       *server;        /* server affected by incoming CM call */
84         void                    *request;       /* request data (first part) */
85         struct address_space    *mapping;       /* page set */
86         struct afs_writeback    *wb;            /* writeback being performed */
87         void                    *buffer;        /* reply receive buffer */
88         void                    *reply;         /* reply buffer (first part) */
89         void                    *reply2;        /* reply buffer (second part) */
90         void                    *reply3;        /* reply buffer (third part) */
91         void                    *reply4;        /* reply buffer (fourth part) */
92         pgoff_t                 first;          /* first page in mapping to deal with */
93         pgoff_t                 last;           /* last page in mapping to deal with */
94         size_t                  offset;         /* offset into received data store */
95         enum {                                  /* call state */
96                 AFS_CALL_REQUESTING,    /* request is being sent for outgoing call */
97                 AFS_CALL_AWAIT_REPLY,   /* awaiting reply to outgoing call */
98                 AFS_CALL_AWAIT_OP_ID,   /* awaiting op ID on incoming call */
99                 AFS_CALL_AWAIT_REQUEST, /* awaiting request data on incoming call */
100                 AFS_CALL_REPLYING,      /* replying to incoming call */
101                 AFS_CALL_AWAIT_ACK,     /* awaiting final ACK of incoming call */
102                 AFS_CALL_COMPLETE,      /* Completed or failed */
103         }                       state;
104         int                     error;          /* error code */
105         u32                     abort_code;     /* Remote abort ID or 0 */
106         unsigned                request_size;   /* size of request data */
107         unsigned                reply_max;      /* maximum size of reply */
108         unsigned                first_offset;   /* offset into mapping[first] */
109         union {
110                 unsigned        last_to;        /* amount of mapping[last] */
111                 unsigned        count2;         /* count used in unmarshalling */
112         };
113         unsigned char           unmarshall;     /* unmarshalling phase */
114         bool                    incoming;       /* T if incoming call */
115         bool                    send_pages;     /* T if data from mapping should be sent */
116         bool                    need_attention; /* T if RxRPC poked us */
117         u16                     service_id;     /* RxRPC service ID to call */
118         __be16                  port;           /* target UDP port */
119         u32                     operation_ID;   /* operation ID for an incoming call */
120         u32                     count;          /* count for use in unmarshalling */
121         __be32                  tmp;            /* place to extract temporary data */
122         afs_dataversion_t       store_version;  /* updated version expected from store */
123 };
124
125 struct afs_call_type {
126         const char *name;
127
128         /* deliver request or reply data to an call
129          * - returning an error will cause the call to be aborted
130          */
131         int (*deliver)(struct afs_call *call);
132
133         /* map an abort code to an error number */
134         int (*abort_to_error)(u32 abort_code);
135
136         /* clean up a call */
137         void (*destructor)(struct afs_call *call);
138 };
139
140 /*
141  * record of an outstanding writeback on a vnode
142  */
143 struct afs_writeback {
144         struct list_head        link;           /* link in vnode->writebacks */
145         struct work_struct      writer;         /* work item to perform the writeback */
146         struct afs_vnode        *vnode;         /* vnode to which this write applies */
147         struct key              *key;           /* owner of this write */
148         wait_queue_head_t       waitq;          /* completion and ready wait queue */
149         pgoff_t                 first;          /* first page in batch */
150         pgoff_t                 point;          /* last page in current store op */
151         pgoff_t                 last;           /* last page in batch (inclusive) */
152         unsigned                offset_first;   /* offset into first page of start of write */
153         unsigned                to_last;        /* offset into last page of end of write */
154         int                     num_conflicts;  /* count of conflicting writes in list */
155         int                     usage;
156         bool                    conflicts;      /* T if has dependent conflicts */
157         enum {
158                 AFS_WBACK_SYNCING,              /* synchronisation being performed */
159                 AFS_WBACK_PENDING,              /* write pending */
160                 AFS_WBACK_CONFLICTING,          /* conflicting writes posted */
161                 AFS_WBACK_WRITING,              /* writing back */
162                 AFS_WBACK_COMPLETE              /* the writeback record has been unlinked */
163         } state __attribute__((packed));
164 };
165
166 /*
167  * AFS superblock private data
168  * - there's one superblock per volume
169  */
170 struct afs_super_info {
171         struct afs_volume       *volume;        /* volume record */
172         char                    rwparent;       /* T if parent is R/W AFS volume */
173 };
174
175 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
176 {
177         return sb->s_fs_info;
178 }
179
180 extern struct file_system_type afs_fs_type;
181
182 /*
183  * entry in the cached cell catalogue
184  */
185 struct afs_cache_cell {
186         char            name[AFS_MAXCELLNAME];  /* cell name (padded with NULs) */
187         struct in_addr  vl_servers[15];         /* cached cell VL servers */
188 };
189
190 /*
191  * AFS cell record
192  */
193 struct afs_cell {
194         atomic_t                usage;
195         struct list_head        link;           /* main cell list link */
196         struct key              *anonymous_key; /* anonymous user key for this cell */
197         struct list_head        proc_link;      /* /proc cell list link */
198 #ifdef CONFIG_AFS_FSCACHE
199         struct fscache_cookie   *cache;         /* caching cookie */
200 #endif
201
202         /* server record management */
203         rwlock_t                servers_lock;   /* active server list lock */
204         struct list_head        servers;        /* active server list */
205
206         /* volume location record management */
207         struct rw_semaphore     vl_sem;         /* volume management serialisation semaphore */
208         struct list_head        vl_list;        /* cell's active VL record list */
209         spinlock_t              vl_lock;        /* vl_list lock */
210         unsigned short          vl_naddrs;      /* number of VL servers in addr list */
211         unsigned short          vl_curr_svix;   /* current server index */
212         struct in_addr          vl_addrs[AFS_CELL_MAX_ADDRS];   /* cell VL server addresses */
213
214         char                    name[0];        /* cell name - must go last */
215 };
216
217 /*
218  * entry in the cached volume location catalogue
219  */
220 struct afs_cache_vlocation {
221         /* volume name (lowercase, padded with NULs) */
222         uint8_t                 name[AFS_MAXVOLNAME + 1];
223
224         uint8_t                 nservers;       /* number of entries used in servers[] */
225         uint8_t                 vidmask;        /* voltype mask for vid[] */
226         uint8_t                 srvtmask[8];    /* voltype masks for servers[] */
227 #define AFS_VOL_VTM_RW  0x01 /* R/W version of the volume is available (on this server) */
228 #define AFS_VOL_VTM_RO  0x02 /* R/O version of the volume is available (on this server) */
229 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
230
231         afs_volid_t             vid[3];         /* volume IDs for R/W, R/O and Bak volumes */
232         struct in_addr          servers[8];     /* fileserver addresses */
233         time_t                  rtime;          /* last retrieval time */
234 };
235
236 /*
237  * volume -> vnode hash table entry
238  */
239 struct afs_cache_vhash {
240         afs_voltype_t           vtype;          /* which volume variation */
241         uint8_t                 hash_bucket;    /* which hash bucket this represents */
242 } __attribute__((packed));
243
244 /*
245  * AFS volume location record
246  */
247 struct afs_vlocation {
248         atomic_t                usage;
249         time64_t                time_of_death;  /* time at which put reduced usage to 0 */
250         struct list_head        link;           /* link in cell volume location list */
251         struct list_head        grave;          /* link in master graveyard list */
252         struct list_head        update;         /* link in master update list */
253         struct afs_cell         *cell;          /* cell to which volume belongs */
254 #ifdef CONFIG_AFS_FSCACHE
255         struct fscache_cookie   *cache;         /* caching cookie */
256 #endif
257         struct afs_cache_vlocation vldb;        /* volume information DB record */
258         struct afs_volume       *vols[3];       /* volume access record pointer (index by type) */
259         wait_queue_head_t       waitq;          /* status change waitqueue */
260         time64_t                update_at;      /* time at which record should be updated */
261         spinlock_t              lock;           /* access lock */
262         afs_vlocation_state_t   state;          /* volume location state */
263         unsigned short          upd_rej_cnt;    /* ENOMEDIUM count during update */
264         unsigned short          upd_busy_cnt;   /* EBUSY count during update */
265         bool                    valid;          /* T if valid */
266 };
267
268 /*
269  * AFS fileserver record
270  */
271 struct afs_server {
272         atomic_t                usage;
273         time64_t                time_of_death;  /* time at which put reduced usage to 0 */
274         struct in_addr          addr;           /* server address */
275         struct afs_cell         *cell;          /* cell in which server resides */
276         struct list_head        link;           /* link in cell's server list */
277         struct list_head        grave;          /* link in master graveyard list */
278         struct rb_node          master_rb;      /* link in master by-addr tree */
279         struct rw_semaphore     sem;            /* access lock */
280
281         /* file service access */
282         struct rb_root          fs_vnodes;      /* vnodes backed by this server (ordered by FID) */
283         unsigned long           fs_act_jif;     /* time at which last activity occurred */
284         unsigned long           fs_dead_jif;    /* time at which no longer to be considered dead */
285         spinlock_t              fs_lock;        /* access lock */
286         int                     fs_state;       /* 0 or reason FS currently marked dead (-errno) */
287
288         /* callback promise management */
289         struct rb_root          cb_promises;    /* vnode expiration list (ordered earliest first) */
290         struct delayed_work     cb_updater;     /* callback updater */
291         struct delayed_work     cb_break_work;  /* collected break dispatcher */
292         wait_queue_head_t       cb_break_waitq; /* space available in cb_break waitqueue */
293         spinlock_t              cb_lock;        /* access lock */
294         struct afs_callback     cb_break[64];   /* ring of callbacks awaiting breaking */
295         atomic_t                cb_break_n;     /* number of pending breaks */
296         u8                      cb_break_head;  /* head of callback breaking ring */
297         u8                      cb_break_tail;  /* tail of callback breaking ring */
298 };
299
300 /*
301  * AFS volume access record
302  */
303 struct afs_volume {
304         atomic_t                usage;
305         struct afs_cell         *cell;          /* cell to which belongs (unrefd ptr) */
306         struct afs_vlocation    *vlocation;     /* volume location */
307 #ifdef CONFIG_AFS_FSCACHE
308         struct fscache_cookie   *cache;         /* caching cookie */
309 #endif
310         afs_volid_t             vid;            /* volume ID */
311         afs_voltype_t           type;           /* type of volume */
312         char                    type_force;     /* force volume type (suppress R/O -> R/W) */
313         unsigned short          nservers;       /* number of server slots filled */
314         unsigned short          rjservers;      /* number of servers discarded due to -ENOMEDIUM */
315         struct afs_server       *servers[8];    /* servers on which volume resides (ordered) */
316         struct rw_semaphore     server_sem;     /* lock for accessing current server */
317         struct backing_dev_info bdi;
318 };
319
320 /*
321  * vnode catalogue entry
322  */
323 struct afs_cache_vnode {
324         afs_vnodeid_t           vnode_id;       /* vnode ID */
325         unsigned                vnode_unique;   /* vnode ID uniquifier */
326         afs_dataversion_t       data_version;   /* data version */
327 };
328
329 /*
330  * AFS inode private data
331  */
332 struct afs_vnode {
333         struct inode            vfs_inode;      /* the VFS's inode record */
334
335         struct afs_volume       *volume;        /* volume on which vnode resides */
336         struct afs_server       *server;        /* server currently supplying this file */
337         struct afs_fid          fid;            /* the file identifier for this inode */
338         struct afs_file_status  status;         /* AFS status info for this file */
339 #ifdef CONFIG_AFS_FSCACHE
340         struct fscache_cookie   *cache;         /* caching cookie */
341 #endif
342         struct afs_permits      *permits;       /* cache of permits so far obtained */
343         struct mutex            permits_lock;   /* lock for altering permits list */
344         struct mutex            validate_lock;  /* lock for validating this vnode */
345         wait_queue_head_t       update_waitq;   /* status fetch waitqueue */
346         int                     update_cnt;     /* number of outstanding ops that will update the
347                                                  * status */
348         spinlock_t              writeback_lock; /* lock for writebacks */
349         spinlock_t              lock;           /* waitqueue/flags lock */
350         unsigned long           flags;
351 #define AFS_VNODE_CB_BROKEN     0               /* set if vnode's callback was broken */
352 #define AFS_VNODE_UNSET         1               /* set if vnode attributes not yet set */
353 #define AFS_VNODE_MODIFIED      2               /* set if vnode's data modified */
354 #define AFS_VNODE_ZAP_DATA      3               /* set if vnode's data should be invalidated */
355 #define AFS_VNODE_DELETED       4               /* set if vnode deleted on server */
356 #define AFS_VNODE_MOUNTPOINT    5               /* set if vnode is a mountpoint symlink */
357 #define AFS_VNODE_LOCKING       6               /* set if waiting for lock on vnode */
358 #define AFS_VNODE_READLOCKED    7               /* set if vnode is read-locked on the server */
359 #define AFS_VNODE_WRITELOCKED   8               /* set if vnode is write-locked on the server */
360 #define AFS_VNODE_UNLOCKING     9               /* set if vnode is being unlocked on the server */
361 #define AFS_VNODE_AUTOCELL      10              /* set if Vnode is an auto mount point */
362 #define AFS_VNODE_PSEUDODIR     11              /* set if Vnode is a pseudo directory */
363
364         long                    acl_order;      /* ACL check count (callback break count) */
365
366         struct list_head        writebacks;     /* alterations in pagecache that need writing */
367         struct list_head        pending_locks;  /* locks waiting to be granted */
368         struct list_head        granted_locks;  /* locks granted on this file */
369         struct delayed_work     lock_work;      /* work to be done in locking */
370         struct key              *unlock_key;    /* key to be used in unlocking */
371
372         /* outstanding callback notification on this file */
373         struct rb_node          server_rb;      /* link in server->fs_vnodes */
374         struct rb_node          cb_promise;     /* link in server->cb_promises */
375         struct work_struct      cb_broken_work; /* work to be done on callback break */
376         time64_t                cb_expires;     /* time at which callback expires */
377         time64_t                cb_expires_at;  /* time used to order cb_promise */
378         unsigned                cb_version;     /* callback version */
379         unsigned                cb_expiry;      /* callback expiry time */
380         afs_callback_type_t     cb_type;        /* type of callback */
381         bool                    cb_promised;    /* true if promise still holds */
382 };
383
384 /*
385  * cached security record for one user's attempt to access a vnode
386  */
387 struct afs_permit {
388         struct key              *key;           /* RxRPC ticket holding a security context */
389         afs_access_t            access_mask;    /* access mask for this key */
390 };
391
392 /*
393  * cache of security records from attempts to access a vnode
394  */
395 struct afs_permits {
396         struct rcu_head         rcu;            /* disposal procedure */
397         int                     count;          /* number of records */
398         struct afs_permit       permits[0];     /* the permits so far examined */
399 };
400
401 /*
402  * record of one of a system's set of network interfaces
403  */
404 struct afs_interface {
405         struct in_addr  address;        /* IPv4 address bound to interface */
406         struct in_addr  netmask;        /* netmask applied to address */
407         unsigned        mtu;            /* MTU of interface */
408 };
409
410 /*
411  * UUID definition [internet draft]
412  * - the timestamp is a 60-bit value, split 32/16/12, and goes in 100ns
413  *   increments since midnight 15th October 1582
414  *   - add AFS_UUID_TO_UNIX_TIME to convert unix time in 100ns units to UUID
415  *     time
416  * - the clock sequence is a 14-bit counter to avoid duplicate times
417  */
418 struct afs_uuid {
419         u32             time_low;                       /* low part of timestamp */
420         u16             time_mid;                       /* mid part of timestamp */
421         u16             time_hi_and_version;            /* high part of timestamp and version  */
422 #define AFS_UUID_TO_UNIX_TIME   0x01b21dd213814000ULL
423 #define AFS_UUID_TIMEHI_MASK    0x0fff
424 #define AFS_UUID_VERSION_TIME   0x1000  /* time-based UUID */
425 #define AFS_UUID_VERSION_NAME   0x3000  /* name-based UUID */
426 #define AFS_UUID_VERSION_RANDOM 0x4000  /* (pseudo-)random generated UUID */
427         u8              clock_seq_hi_and_reserved;      /* clock seq hi and variant */
428 #define AFS_UUID_CLOCKHI_MASK   0x3f
429 #define AFS_UUID_VARIANT_STD    0x80
430         u8              clock_seq_low;                  /* clock seq low */
431         u8              node[6];                        /* spatially unique node ID (MAC addr) */
432 };
433
434 /*****************************************************************************/
435 /*
436  * cache.c
437  */
438 #ifdef CONFIG_AFS_FSCACHE
439 extern struct fscache_netfs afs_cache_netfs;
440 extern struct fscache_cookie_def afs_cell_cache_index_def;
441 extern struct fscache_cookie_def afs_vlocation_cache_index_def;
442 extern struct fscache_cookie_def afs_volume_cache_index_def;
443 extern struct fscache_cookie_def afs_vnode_cache_index_def;
444 #else
445 #define afs_cell_cache_index_def        (*(struct fscache_cookie_def *) NULL)
446 #define afs_vlocation_cache_index_def   (*(struct fscache_cookie_def *) NULL)
447 #define afs_volume_cache_index_def      (*(struct fscache_cookie_def *) NULL)
448 #define afs_vnode_cache_index_def       (*(struct fscache_cookie_def *) NULL)
449 #endif
450
451 /*
452  * callback.c
453  */
454 extern void afs_init_callback_state(struct afs_server *);
455 extern void afs_broken_callback_work(struct work_struct *);
456 extern void afs_break_callbacks(struct afs_server *, size_t,
457                                 struct afs_callback[]);
458 extern void afs_discard_callback_on_delete(struct afs_vnode *);
459 extern void afs_give_up_callback(struct afs_vnode *);
460 extern void afs_dispatch_give_up_callbacks(struct work_struct *);
461 extern void afs_flush_callback_breaks(struct afs_server *);
462 extern int __init afs_callback_update_init(void);
463 extern void afs_callback_update_kill(void);
464
465 /*
466  * cell.c
467  */
468 extern struct rw_semaphore afs_proc_cells_sem;
469 extern struct list_head afs_proc_cells;
470
471 #define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0)
472 extern int afs_cell_init(char *);
473 extern struct afs_cell *afs_cell_create(const char *, unsigned, char *, bool);
474 extern struct afs_cell *afs_cell_lookup(const char *, unsigned, bool);
475 extern struct afs_cell *afs_grab_cell(struct afs_cell *);
476 extern void afs_put_cell(struct afs_cell *);
477 extern void afs_cell_purge(void);
478
479 /*
480  * cmservice.c
481  */
482 extern bool afs_cm_incoming_call(struct afs_call *);
483
484 /*
485  * dir.c
486  */
487 extern const struct inode_operations afs_dir_inode_operations;
488 extern const struct dentry_operations afs_fs_dentry_operations;
489 extern const struct file_operations afs_dir_file_operations;
490
491 /*
492  * file.c
493  */
494 extern const struct address_space_operations afs_fs_aops;
495 extern const struct inode_operations afs_file_inode_operations;
496 extern const struct file_operations afs_file_operations;
497
498 extern int afs_open(struct inode *, struct file *);
499 extern int afs_release(struct inode *, struct file *);
500 extern int afs_page_filler(void *, struct page *);
501
502 /*
503  * flock.c
504  */
505 extern void __exit afs_kill_lock_manager(void);
506 extern void afs_lock_work(struct work_struct *);
507 extern void afs_lock_may_be_available(struct afs_vnode *);
508 extern int afs_lock(struct file *, int, struct file_lock *);
509 extern int afs_flock(struct file *, int, struct file_lock *);
510
511 /*
512  * fsclient.c
513  */
514 extern int afs_fs_fetch_file_status(struct afs_server *, struct key *,
515                                     struct afs_vnode *, struct afs_volsync *,
516                                     const struct afs_wait_mode *);
517 extern int afs_fs_give_up_callbacks(struct afs_server *,
518                                     const struct afs_wait_mode *);
519 extern int afs_fs_fetch_data(struct afs_server *, struct key *,
520                              struct afs_vnode *, off_t, size_t, struct page *,
521                              const struct afs_wait_mode *);
522 extern int afs_fs_create(struct afs_server *, struct key *,
523                          struct afs_vnode *, const char *, umode_t,
524                          struct afs_fid *, struct afs_file_status *,
525                          struct afs_callback *,
526                          const struct afs_wait_mode *);
527 extern int afs_fs_remove(struct afs_server *, struct key *,
528                          struct afs_vnode *, const char *, bool,
529                          const struct afs_wait_mode *);
530 extern int afs_fs_link(struct afs_server *, struct key *, struct afs_vnode *,
531                        struct afs_vnode *, const char *,
532                        const struct afs_wait_mode *);
533 extern int afs_fs_symlink(struct afs_server *, struct key *,
534                           struct afs_vnode *, const char *, const char *,
535                           struct afs_fid *, struct afs_file_status *,
536                           const struct afs_wait_mode *);
537 extern int afs_fs_rename(struct afs_server *, struct key *,
538                          struct afs_vnode *, const char *,
539                          struct afs_vnode *, const char *,
540                          const struct afs_wait_mode *);
541 extern int afs_fs_store_data(struct afs_server *, struct afs_writeback *,
542                              pgoff_t, pgoff_t, unsigned, unsigned,
543                              const struct afs_wait_mode *);
544 extern int afs_fs_setattr(struct afs_server *, struct key *,
545                           struct afs_vnode *, struct iattr *,
546                           const struct afs_wait_mode *);
547 extern int afs_fs_get_volume_status(struct afs_server *, struct key *,
548                                     struct afs_vnode *,
549                                     struct afs_volume_status *,
550                                     const struct afs_wait_mode *);
551 extern int afs_fs_set_lock(struct afs_server *, struct key *,
552                            struct afs_vnode *, afs_lock_type_t,
553                            const struct afs_wait_mode *);
554 extern int afs_fs_extend_lock(struct afs_server *, struct key *,
555                               struct afs_vnode *,
556                               const struct afs_wait_mode *);
557 extern int afs_fs_release_lock(struct afs_server *, struct key *,
558                                struct afs_vnode *,
559                                const struct afs_wait_mode *);
560
561 /*
562  * inode.c
563  */
564 extern struct inode *afs_iget_autocell(struct inode *, const char *, int,
565                                        struct key *);
566 extern struct inode *afs_iget(struct super_block *, struct key *,
567                               struct afs_fid *, struct afs_file_status *,
568                               struct afs_callback *);
569 extern void afs_zap_data(struct afs_vnode *);
570 extern int afs_validate(struct afs_vnode *, struct key *);
571 extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
572 extern int afs_setattr(struct dentry *, struct iattr *);
573 extern void afs_evict_inode(struct inode *);
574 extern int afs_drop_inode(struct inode *);
575
576 /*
577  * main.c
578  */
579 extern struct workqueue_struct *afs_wq;
580 extern struct afs_uuid afs_uuid;
581
582 /*
583  * misc.c
584  */
585 extern int afs_abort_to_error(u32);
586
587 /*
588  * mntpt.c
589  */
590 extern const struct inode_operations afs_mntpt_inode_operations;
591 extern const struct inode_operations afs_autocell_inode_operations;
592 extern const struct file_operations afs_mntpt_file_operations;
593
594 extern struct vfsmount *afs_d_automount(struct path *);
595 extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *);
596 extern void afs_mntpt_kill_timer(void);
597
598 /*
599  * proc.c
600  */
601 extern int afs_proc_init(void);
602 extern void afs_proc_cleanup(void);
603 extern int afs_proc_cell_setup(struct afs_cell *);
604 extern void afs_proc_cell_remove(struct afs_cell *);
605
606 /*
607  * rxrpc.c
608  */
609 extern struct socket *afs_socket;
610
611 extern int afs_open_socket(void);
612 extern void afs_close_socket(void);
613 extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t,
614                          const struct afs_wait_mode *);
615 extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *,
616                                             size_t, size_t);
617 extern void afs_flat_call_destructor(struct afs_call *);
618 extern void afs_send_empty_reply(struct afs_call *);
619 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
620 extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
621
622 static inline int afs_transfer_reply(struct afs_call *call)
623 {
624         return afs_extract_data(call, call->buffer, call->reply_max, false);
625 }
626
627 /*
628  * security.c
629  */
630 extern void afs_clear_permits(struct afs_vnode *);
631 extern void afs_cache_permit(struct afs_vnode *, struct key *, long);
632 extern void afs_zap_permits(struct rcu_head *);
633 extern struct key *afs_request_key(struct afs_cell *);
634 extern int afs_permission(struct inode *, int);
635
636 /*
637  * server.c
638  */
639 extern spinlock_t afs_server_peer_lock;
640
641 #define afs_get_server(S)                                       \
642 do {                                                            \
643         _debug("GET SERVER %d", atomic_read(&(S)->usage));      \
644         atomic_inc(&(S)->usage);                                \
645 } while(0)
646
647 extern struct afs_server *afs_lookup_server(struct afs_cell *,
648                                             const struct in_addr *);
649 extern struct afs_server *afs_find_server(const struct sockaddr_rxrpc *);
650 extern void afs_put_server(struct afs_server *);
651 extern void __exit afs_purge_servers(void);
652
653 /*
654  * super.c
655  */
656 extern int afs_fs_init(void);
657 extern void afs_fs_exit(void);
658
659 /*
660  * use-rtnetlink.c
661  */
662 extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
663 extern int afs_get_MAC_address(u8 *, size_t);
664
665 /*
666  * vlclient.c
667  */
668 extern int afs_vl_get_entry_by_name(struct in_addr *, struct key *,
669                                     const char *, struct afs_cache_vlocation *,
670                                     const struct afs_wait_mode *);
671 extern int afs_vl_get_entry_by_id(struct in_addr *, struct key *,
672                                   afs_volid_t, afs_voltype_t,
673                                   struct afs_cache_vlocation *,
674                                   const struct afs_wait_mode *);
675
676 /*
677  * vlocation.c
678  */
679 #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
680
681 extern int __init afs_vlocation_update_init(void);
682 extern struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *,
683                                                   struct key *,
684                                                   const char *, size_t);
685 extern void afs_put_vlocation(struct afs_vlocation *);
686 extern void afs_vlocation_purge(void);
687
688 /*
689  * vnode.c
690  */
691 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
692 {
693         return container_of(inode, struct afs_vnode, vfs_inode);
694 }
695
696 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
697 {
698         return &vnode->vfs_inode;
699 }
700
701 extern void afs_vnode_finalise_status_update(struct afs_vnode *,
702                                              struct afs_server *);
703 extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *,
704                                   struct key *);
705 extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *,
706                                 off_t, size_t, struct page *);
707 extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *,
708                             umode_t, struct afs_fid *, struct afs_file_status *,
709                             struct afs_callback *, struct afs_server **);
710 extern int afs_vnode_remove(struct afs_vnode *, struct key *, const char *,
711                             bool);
712 extern int afs_vnode_link(struct afs_vnode *, struct afs_vnode *, struct key *,
713                           const char *);
714 extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *,
715                              const char *, struct afs_fid *,
716                              struct afs_file_status *, struct afs_server **);
717 extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *,
718                             struct key *, const char *, const char *);
719 extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t,
720                                 unsigned, unsigned);
721 extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *);
722 extern int afs_vnode_get_volume_status(struct afs_vnode *, struct key *,
723                                        struct afs_volume_status *);
724 extern int afs_vnode_set_lock(struct afs_vnode *, struct key *,
725                               afs_lock_type_t);
726 extern int afs_vnode_extend_lock(struct afs_vnode *, struct key *);
727 extern int afs_vnode_release_lock(struct afs_vnode *, struct key *);
728
729 /*
730  * volume.c
731  */
732 #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
733
734 extern void afs_put_volume(struct afs_volume *);
735 extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *);
736 extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *);
737 extern int afs_volume_release_fileserver(struct afs_vnode *,
738                                          struct afs_server *, int);
739
740 /*
741  * write.c
742  */
743 extern int afs_set_page_dirty(struct page *);
744 extern void afs_put_writeback(struct afs_writeback *);
745 extern int afs_write_begin(struct file *file, struct address_space *mapping,
746                         loff_t pos, unsigned len, unsigned flags,
747                         struct page **pagep, void **fsdata);
748 extern int afs_write_end(struct file *file, struct address_space *mapping,
749                         loff_t pos, unsigned len, unsigned copied,
750                         struct page *page, void *fsdata);
751 extern int afs_writepage(struct page *, struct writeback_control *);
752 extern int afs_writepages(struct address_space *, struct writeback_control *);
753 extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
754 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
755 extern int afs_writeback_all(struct afs_vnode *);
756 extern int afs_flush(struct file *, fl_owner_t);
757 extern int afs_fsync(struct file *, loff_t, loff_t, int);
758
759
760 /*****************************************************************************/
761 /*
762  * debug tracing
763  */
764 extern unsigned afs_debug;
765
766 #define dbgprintk(FMT,...) \
767         printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
768
769 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
770 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
771 #define kdebug(FMT,...) dbgprintk("    "FMT ,##__VA_ARGS__)
772
773
774 #if defined(__KDEBUG)
775 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
776 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
777 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
778
779 #elif defined(CONFIG_AFS_DEBUG)
780 #define AFS_DEBUG_KENTER        0x01
781 #define AFS_DEBUG_KLEAVE        0x02
782 #define AFS_DEBUG_KDEBUG        0x04
783
784 #define _enter(FMT,...)                                 \
785 do {                                                    \
786         if (unlikely(afs_debug & AFS_DEBUG_KENTER))     \
787                 kenter(FMT,##__VA_ARGS__);              \
788 } while (0)
789
790 #define _leave(FMT,...)                                 \
791 do {                                                    \
792         if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))     \
793                 kleave(FMT,##__VA_ARGS__);              \
794 } while (0)
795
796 #define _debug(FMT,...)                                 \
797 do {                                                    \
798         if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))     \
799                 kdebug(FMT,##__VA_ARGS__);              \
800 } while (0)
801
802 #else
803 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
804 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
805 #define _debug(FMT,...) no_printk("    "FMT ,##__VA_ARGS__)
806 #endif
807
808 /*
809  * debug assertion checking
810  */
811 #if 1 // defined(__KDEBUGALL)
812
813 #define ASSERT(X)                                               \
814 do {                                                            \
815         if (unlikely(!(X))) {                                   \
816                 printk(KERN_ERR "\n");                          \
817                 printk(KERN_ERR "AFS: Assertion failed\n");     \
818                 BUG();                                          \
819         }                                                       \
820 } while(0)
821
822 #define ASSERTCMP(X, OP, Y)                                             \
823 do {                                                                    \
824         if (unlikely(!((X) OP (Y)))) {                                  \
825                 printk(KERN_ERR "\n");                                  \
826                 printk(KERN_ERR "AFS: Assertion failed\n");             \
827                 printk(KERN_ERR "%lu " #OP " %lu is false\n",           \
828                        (unsigned long)(X), (unsigned long)(Y));         \
829                 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",       \
830                        (unsigned long)(X), (unsigned long)(Y));         \
831                 BUG();                                                  \
832         }                                                               \
833 } while(0)
834
835 #define ASSERTRANGE(L, OP1, N, OP2, H)                                  \
836 do {                                                                    \
837         if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {               \
838                 printk(KERN_ERR "\n");                                  \
839                 printk(KERN_ERR "AFS: Assertion failed\n");             \
840                 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
841                        (unsigned long)(L), (unsigned long)(N),          \
842                        (unsigned long)(H));                             \
843                 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
844                        (unsigned long)(L), (unsigned long)(N),          \
845                        (unsigned long)(H));                             \
846                 BUG();                                                  \
847         }                                                               \
848 } while(0)
849
850 #define ASSERTIF(C, X)                                          \
851 do {                                                            \
852         if (unlikely((C) && !(X))) {                            \
853                 printk(KERN_ERR "\n");                          \
854                 printk(KERN_ERR "AFS: Assertion failed\n");     \
855                 BUG();                                          \
856         }                                                       \
857 } while(0)
858
859 #define ASSERTIFCMP(C, X, OP, Y)                                        \
860 do {                                                                    \
861         if (unlikely((C) && !((X) OP (Y)))) {                           \
862                 printk(KERN_ERR "\n");                                  \
863                 printk(KERN_ERR "AFS: Assertion failed\n");             \
864                 printk(KERN_ERR "%lu " #OP " %lu is false\n",           \
865                        (unsigned long)(X), (unsigned long)(Y));         \
866                 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",       \
867                        (unsigned long)(X), (unsigned long)(Y));         \
868                 BUG();                                                  \
869         }                                                               \
870 } while(0)
871
872 #else
873
874 #define ASSERT(X)                               \
875 do {                                            \
876 } while(0)
877
878 #define ASSERTCMP(X, OP, Y)                     \
879 do {                                            \
880 } while(0)
881
882 #define ASSERTRANGE(L, OP1, N, OP2, H)          \
883 do {                                            \
884 } while(0)
885
886 #define ASSERTIF(C, X)                          \
887 do {                                            \
888 } while(0)
889
890 #define ASSERTIFCMP(C, X, OP, Y)                \
891 do {                                            \
892 } while(0)
893
894 #endif /* __KDEBUGALL */