OSDN Git Service

afs: Build an abstraction around an "operation" concept
[tomoyo/tomoyo-test1.git] / fs / afs / internal.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* internal AFS stuff
3  *
4  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
7
8 #include <linux/compiler.h>
9 #include <linux/kernel.h>
10 #include <linux/ktime.h>
11 #include <linux/fs.h>
12 #include <linux/pagemap.h>
13 #include <linux/rxrpc.h>
14 #include <linux/key.h>
15 #include <linux/workqueue.h>
16 #include <linux/sched.h>
17 #include <linux/fscache.h>
18 #include <linux/backing-dev.h>
19 #include <linux/uuid.h>
20 #include <linux/mm_types.h>
21 #include <linux/dns_resolver.h>
22 #include <net/net_namespace.h>
23 #include <net/netns/generic.h>
24 #include <net/sock.h>
25 #include <net/af_rxrpc.h>
26
27 #include "afs.h"
28 #include "afs_vl.h"
29
30 #define AFS_CELL_MAX_ADDRS 15
31
32 struct pagevec;
33 struct afs_call;
34
35 /*
36  * Partial file-locking emulation mode.  (The problem being that AFS3 only
37  * allows whole-file locks and no upgrading/downgrading).
38  */
39 enum afs_flock_mode {
40         afs_flock_mode_unset,
41         afs_flock_mode_local,   /* Local locking only */
42         afs_flock_mode_openafs, /* Don't get server lock for a partial lock */
43         afs_flock_mode_strict,  /* Always get a server lock for a partial lock */
44         afs_flock_mode_write,   /* Get an exclusive server lock for a partial lock */
45 };
46
47 struct afs_fs_context {
48         bool                    force;          /* T to force cell type */
49         bool                    autocell;       /* T if set auto mount operation */
50         bool                    dyn_root;       /* T if dynamic root */
51         bool                    no_cell;        /* T if the source is "none" (for dynroot) */
52         enum afs_flock_mode     flock_mode;     /* Partial file-locking emulation mode */
53         afs_voltype_t           type;           /* type of volume requested */
54         unsigned int            volnamesz;      /* size of volume name */
55         const char              *volname;       /* name of volume to mount */
56         struct afs_net          *net;           /* the AFS net namespace stuff */
57         struct afs_cell         *cell;          /* cell in which to find volume */
58         struct afs_volume       *volume;        /* volume record */
59         struct key              *key;           /* key to use for secure mounting */
60 };
61
62 enum afs_call_state {
63         AFS_CALL_CL_REQUESTING,         /* Client: Request is being sent */
64         AFS_CALL_CL_AWAIT_REPLY,        /* Client: Awaiting reply */
65         AFS_CALL_CL_PROC_REPLY,         /* Client: rxrpc call complete; processing reply */
66         AFS_CALL_SV_AWAIT_OP_ID,        /* Server: Awaiting op ID */
67         AFS_CALL_SV_AWAIT_REQUEST,      /* Server: Awaiting request data */
68         AFS_CALL_SV_REPLYING,           /* Server: Replying */
69         AFS_CALL_SV_AWAIT_ACK,          /* Server: Awaiting final ACK */
70         AFS_CALL_COMPLETE,              /* Completed or failed */
71 };
72
73 /*
74  * List of server addresses.
75  */
76 struct afs_addr_list {
77         struct rcu_head         rcu;
78         refcount_t              usage;
79         u32                     version;        /* Version */
80         unsigned char           max_addrs;
81         unsigned char           nr_addrs;
82         unsigned char           preferred;      /* Preferred address */
83         unsigned char           nr_ipv4;        /* Number of IPv4 addresses */
84         enum dns_record_source  source:8;
85         enum dns_lookup_status  status:8;
86         unsigned long           failed;         /* Mask of addrs that failed locally/ICMP */
87         unsigned long           responded;      /* Mask of addrs that responded */
88         struct sockaddr_rxrpc   addrs[];
89 #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
90 };
91
92 /*
93  * a record of an in-progress RxRPC call
94  */
95 struct afs_call {
96         const struct afs_call_type *type;       /* type of call */
97         struct afs_addr_list    *alist;         /* Address is alist[addr_ix] */
98         wait_queue_head_t       waitq;          /* processes awaiting completion */
99         struct work_struct      async_work;     /* async I/O processor */
100         struct work_struct      work;           /* actual work processor */
101         struct rxrpc_call       *rxcall;        /* RxRPC call handle */
102         struct key              *key;           /* security for this call */
103         struct afs_net          *net;           /* The network namespace */
104         struct afs_server       *server;        /* The fileserver record if fs op (pins ref) */
105         struct afs_vlserver     *vlserver;      /* The vlserver record if vl op */
106         struct afs_cb_interest  *cbi;           /* Callback interest for server used */
107         void                    *request;       /* request data (first part) */
108         struct iov_iter         def_iter;       /* Default buffer/data iterator */
109         struct iov_iter         *iter;          /* Iterator currently in use */
110         union { /* Convenience for ->def_iter */
111                 struct kvec     kvec[1];
112                 struct bio_vec  bvec[1];
113         };
114         void                    *buffer;        /* reply receive buffer */
115         union {
116                 long                    ret0;   /* Value to reply with instead of 0 */
117                 struct afs_addr_list    *ret_alist;
118                 struct afs_vldb_entry   *ret_vldb;
119         };
120         struct afs_operation    *op;
121         unsigned int            server_index;
122         atomic_t                usage;
123         enum afs_call_state     state;
124         spinlock_t              state_lock;
125         int                     error;          /* error code */
126         u32                     abort_code;     /* Remote abort ID or 0 */
127         u32                     epoch;
128         unsigned int            max_lifespan;   /* Maximum lifespan to set if not 0 */
129         unsigned                request_size;   /* size of request data */
130         unsigned                reply_max;      /* maximum size of reply */
131         unsigned                count2;         /* count used in unmarshalling */
132         unsigned char           unmarshall;     /* unmarshalling phase */
133         unsigned char           addr_ix;        /* Address in ->alist */
134         bool                    drop_ref;       /* T if need to drop ref for incoming call */
135         bool                    send_pages;     /* T if data from mapping should be sent */
136         bool                    need_attention; /* T if RxRPC poked us */
137         bool                    async;          /* T if asynchronous */
138         bool                    upgrade;        /* T to request service upgrade */
139         bool                    have_reply_time; /* T if have got reply_time */
140         bool                    intr;           /* T if interruptible */
141         bool                    unmarshalling_error; /* T if an unmarshalling error occurred */
142         u16                     service_id;     /* Actual service ID (after upgrade) */
143         unsigned int            debug_id;       /* Trace ID */
144         u32                     operation_ID;   /* operation ID for an incoming call */
145         u32                     count;          /* count for use in unmarshalling */
146         union {                                 /* place to extract temporary data */
147                 struct {
148                         __be32  tmp_u;
149                         __be32  tmp;
150                 } __attribute__((packed));
151                 __be64          tmp64;
152         };
153         ktime_t                 reply_time;     /* Time of first reply packet */
154 };
155
156 struct afs_call_type {
157         const char *name;
158         unsigned int op; /* Really enum afs_fs_operation */
159
160         /* deliver request or reply data to an call
161          * - returning an error will cause the call to be aborted
162          */
163         int (*deliver)(struct afs_call *call);
164
165         /* clean up a call */
166         void (*destructor)(struct afs_call *call);
167
168         /* Work function */
169         void (*work)(struct work_struct *work);
170
171         /* Call done function (gets called immediately on success or failure) */
172         void (*done)(struct afs_call *call);
173 };
174
175 /*
176  * Key available for writeback on a file.
177  */
178 struct afs_wb_key {
179         refcount_t              usage;
180         struct key              *key;
181         struct list_head        vnode_link;     /* Link in vnode->wb_keys */
182 };
183
184 /*
185  * AFS open file information record.  Pointed to by file->private_data.
186  */
187 struct afs_file {
188         struct key              *key;           /* The key this file was opened with */
189         struct afs_wb_key       *wb;            /* Writeback key record for this file */
190 };
191
192 static inline struct key *afs_file_key(struct file *file)
193 {
194         struct afs_file *af = file->private_data;
195
196         return af->key;
197 }
198
199 /*
200  * Record of an outstanding read operation on a vnode.
201  */
202 struct afs_read {
203         loff_t                  pos;            /* Where to start reading */
204         loff_t                  len;            /* How much we're asking for */
205         loff_t                  actual_len;     /* How much we're actually getting */
206         loff_t                  remain;         /* Amount remaining */
207         loff_t                  file_size;      /* File size returned by server */
208         afs_dataversion_t       data_version;   /* Version number returned by server */
209         refcount_t              usage;
210         unsigned int            index;          /* Which page we're reading into */
211         unsigned int            nr_pages;
212         unsigned int            offset;         /* offset into current page */
213         struct afs_vnode        *vnode;
214         void (*page_done)(struct afs_read *);
215         struct page             **pages;
216         struct page             *array[];
217 };
218
219 /*
220  * AFS superblock private data
221  * - there's one superblock per volume
222  */
223 struct afs_super_info {
224         struct net              *net_ns;        /* Network namespace */
225         struct afs_cell         *cell;          /* The cell in which the volume resides */
226         struct afs_volume       *volume;        /* volume record */
227         enum afs_flock_mode     flock_mode:8;   /* File locking emulation mode */
228         bool                    dyn_root;       /* True if dynamic root */
229 };
230
231 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
232 {
233         return sb->s_fs_info;
234 }
235
236 extern struct file_system_type afs_fs_type;
237
238 /*
239  * Set of substitutes for @sys.
240  */
241 struct afs_sysnames {
242 #define AFS_NR_SYSNAME 16
243         char                    *subs[AFS_NR_SYSNAME];
244         refcount_t              usage;
245         unsigned short          nr;
246         char                    blank[1];
247 };
248
249 /*
250  * AFS network namespace record.
251  */
252 struct afs_net {
253         struct net              *net;           /* Backpointer to the owning net namespace */
254         struct afs_uuid         uuid;
255         bool                    live;           /* F if this namespace is being removed */
256
257         /* AF_RXRPC I/O stuff */
258         struct socket           *socket;
259         struct afs_call         *spare_incoming_call;
260         struct work_struct      charge_preallocation_work;
261         struct mutex            socket_mutex;
262         atomic_t                nr_outstanding_calls;
263         atomic_t                nr_superblocks;
264
265         /* Cell database */
266         struct rb_root          cells;
267         struct afs_cell __rcu   *ws_cell;
268         struct work_struct      cells_manager;
269         struct timer_list       cells_timer;
270         atomic_t                cells_outstanding;
271         seqlock_t               cells_lock;
272
273         struct mutex            proc_cells_lock;
274         struct hlist_head       proc_cells;
275
276         /* Known servers.  Theoretically each fileserver can only be in one
277          * cell, but in practice, people create aliases and subsets and there's
278          * no easy way to distinguish them.
279          */
280         seqlock_t               fs_lock;        /* For fs_servers, fs_probe_*, fs_proc */
281         struct rb_root          fs_servers;     /* afs_server (by server UUID or address) */
282         struct list_head        fs_probe_fast;  /* List of afs_server to probe at 30s intervals */
283         struct list_head        fs_probe_slow;  /* List of afs_server to probe at 5m intervals */
284         struct hlist_head       fs_proc;        /* procfs servers list */
285
286         struct hlist_head       fs_addresses4;  /* afs_server (by lowest IPv4 addr) */
287         struct hlist_head       fs_addresses6;  /* afs_server (by lowest IPv6 addr) */
288         seqlock_t               fs_addr_lock;   /* For fs_addresses[46] */
289
290         struct work_struct      fs_manager;
291         struct timer_list       fs_timer;
292
293         struct work_struct      fs_prober;
294         struct timer_list       fs_probe_timer;
295         atomic_t                servers_outstanding;
296
297         /* File locking renewal management */
298         struct mutex            lock_manager_mutex;
299
300         /* Misc */
301         struct super_block      *dynroot_sb;    /* Dynamic root mount superblock */
302         struct proc_dir_entry   *proc_afs;      /* /proc/net/afs directory */
303         struct afs_sysnames     *sysnames;
304         rwlock_t                sysnames_lock;
305
306         /* Statistics counters */
307         atomic_t                n_lookup;       /* Number of lookups done */
308         atomic_t                n_reval;        /* Number of dentries needing revalidation */
309         atomic_t                n_inval;        /* Number of invalidations by the server */
310         atomic_t                n_relpg;        /* Number of invalidations by releasepage */
311         atomic_t                n_read_dir;     /* Number of directory pages read */
312         atomic_t                n_dir_cr;       /* Number of directory entry creation edits */
313         atomic_t                n_dir_rm;       /* Number of directory entry removal edits */
314         atomic_t                n_stores;       /* Number of store ops */
315         atomic_long_t           n_store_bytes;  /* Number of bytes stored */
316         atomic_long_t           n_fetch_bytes;  /* Number of bytes fetched */
317         atomic_t                n_fetches;      /* Number of data fetch ops */
318 };
319
320 extern const char afs_init_sysname[];
321
322 enum afs_cell_state {
323         AFS_CELL_UNSET,
324         AFS_CELL_ACTIVATING,
325         AFS_CELL_ACTIVE,
326         AFS_CELL_DEACTIVATING,
327         AFS_CELL_INACTIVE,
328         AFS_CELL_FAILED,
329 };
330
331 /*
332  * AFS cell record.
333  *
334  * This is a tricky concept to get right as it is possible to create aliases
335  * simply by pointing AFSDB/SRV records for two names at the same set of VL
336  * servers; it is also possible to do things like setting up two sets of VL
337  * servers, one of which provides a superset of the volumes provided by the
338  * other (for internal/external division, for example).
339  *
340  * Cells only exist in the sense that (a) a cell's name maps to a set of VL
341  * servers and (b) a cell's name is used by the client to select the key to use
342  * for authentication and encryption.  The cell name is not typically used in
343  * the protocol.
344  *
345  * There is no easy way to determine if two cells are aliases or one is a
346  * subset of another.
347  */
348 struct afs_cell {
349         union {
350                 struct rcu_head rcu;
351                 struct rb_node  net_node;       /* Node in net->cells */
352         };
353         struct afs_net          *net;
354         struct key              *anonymous_key; /* anonymous user key for this cell */
355         struct work_struct      manager;        /* Manager for init/deinit/dns */
356         struct hlist_node       proc_link;      /* /proc cell list link */
357 #ifdef CONFIG_AFS_FSCACHE
358         struct fscache_cookie   *cache;         /* caching cookie */
359 #endif
360         time64_t                dns_expiry;     /* Time AFSDB/SRV record expires */
361         time64_t                last_inactive;  /* Time of last drop of usage count */
362         atomic_t                usage;
363         unsigned long           flags;
364 #define AFS_CELL_FL_NO_GC       0               /* The cell was added manually, don't auto-gc */
365 #define AFS_CELL_FL_DO_LOOKUP   1               /* DNS lookup requested */
366         enum afs_cell_state     state;
367         short                   error;
368         enum dns_record_source  dns_source:8;   /* Latest source of data from lookup */
369         enum dns_lookup_status  dns_status:8;   /* Latest status of data from lookup */
370         unsigned int            dns_lookup_count; /* Counter of DNS lookups */
371
372         /* Active fileserver interaction state. */
373         struct list_head        proc_volumes;   /* procfs volume list */
374         rwlock_t                proc_lock;
375
376         /* VL server list. */
377         rwlock_t                vl_servers_lock; /* Lock on vl_servers */
378         struct afs_vlserver_list __rcu *vl_servers;
379
380         u8                      name_len;       /* Length of name */
381         char                    name[64 + 1];   /* Cell name, case-flattened and NUL-padded */
382 };
383
384 /*
385  * Volume Location server record.
386  */
387 struct afs_vlserver {
388         struct rcu_head         rcu;
389         struct afs_addr_list    __rcu *addresses; /* List of addresses for this VL server */
390         unsigned long           flags;
391 #define AFS_VLSERVER_FL_PROBED  0               /* The VL server has been probed */
392 #define AFS_VLSERVER_FL_PROBING 1               /* VL server is being probed */
393 #define AFS_VLSERVER_FL_IS_YFS  2               /* Server is YFS not AFS */
394         rwlock_t                lock;           /* Lock on addresses */
395         atomic_t                usage;
396
397         /* Probe state */
398         wait_queue_head_t       probe_wq;
399         atomic_t                probe_outstanding;
400         spinlock_t              probe_lock;
401         struct {
402                 unsigned int    rtt;            /* RTT as ktime/64 */
403                 u32             abort_code;
404                 short           error;
405                 bool            have_result;
406                 bool            responded:1;
407                 bool            is_yfs:1;
408                 bool            not_yfs:1;
409                 bool            local_failure:1;
410         } probe;
411
412         u16                     port;
413         u16                     name_len;       /* Length of name */
414         char                    name[];         /* Server name, case-flattened */
415 };
416
417 /*
418  * Weighted list of Volume Location servers.
419  */
420 struct afs_vlserver_entry {
421         u16                     priority;       /* Preference (as SRV) */
422         u16                     weight;         /* Weight (as SRV) */
423         enum dns_record_source  source:8;
424         enum dns_lookup_status  status:8;
425         struct afs_vlserver     *server;
426 };
427
428 struct afs_vlserver_list {
429         struct rcu_head         rcu;
430         atomic_t                usage;
431         u8                      nr_servers;
432         u8                      index;          /* Server currently in use */
433         u8                      preferred;      /* Preferred server */
434         enum dns_record_source  source:8;
435         enum dns_lookup_status  status:8;
436         rwlock_t                lock;
437         struct afs_vlserver_entry servers[];
438 };
439
440 /*
441  * Cached VLDB entry.
442  *
443  * This is pointed to by cell->vldb_entries, indexed by name.
444  */
445 struct afs_vldb_entry {
446         afs_volid_t             vid[3];         /* Volume IDs for R/W, R/O and Bak volumes */
447
448         unsigned long           flags;
449 #define AFS_VLDB_HAS_RW         0               /* - R/W volume exists */
450 #define AFS_VLDB_HAS_RO         1               /* - R/O volume exists */
451 #define AFS_VLDB_HAS_BAK        2               /* - Backup volume exists */
452 #define AFS_VLDB_QUERY_VALID    3               /* - Record is valid */
453 #define AFS_VLDB_QUERY_ERROR    4               /* - VL server returned error */
454
455         uuid_t                  fs_server[AFS_NMAXNSERVERS];
456         u32                     addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
457         u8                      fs_mask[AFS_NMAXNSERVERS];
458 #define AFS_VOL_VTM_RW  0x01 /* R/W version of the volume is available (on this server) */
459 #define AFS_VOL_VTM_RO  0x02 /* R/O version of the volume is available (on this server) */
460 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
461         short                   error;
462         u8                      nr_servers;     /* Number of server records */
463         u8                      name_len;
464         u8                      name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
465 };
466
467 /*
468  * Record of fileserver with which we're actively communicating.
469  */
470 struct afs_server {
471         struct rcu_head         rcu;
472         union {
473                 uuid_t          uuid;           /* Server ID */
474                 struct afs_uuid _uuid;
475         };
476
477         struct afs_addr_list    __rcu *addresses;
478         struct rb_node          uuid_rb;        /* Link in net->fs_servers */
479         struct list_head        probe_link;     /* Link in net->fs_probe_list */
480         struct hlist_node       addr4_link;     /* Link in net->fs_addresses4 */
481         struct hlist_node       addr6_link;     /* Link in net->fs_addresses6 */
482         struct hlist_node       proc_link;      /* Link in net->fs_proc */
483         struct afs_server       *gc_next;       /* Next server in manager's list */
484         time64_t                unuse_time;     /* Time at which last unused */
485         unsigned long           flags;
486 #define AFS_SERVER_FL_NOT_READY 1               /* The record is not ready for use */
487 #define AFS_SERVER_FL_NOT_FOUND 2               /* VL server says no such server */
488 #define AFS_SERVER_FL_VL_FAIL   3               /* Failed to access VL server */
489 #define AFS_SERVER_FL_UPDATING  4
490 #define AFS_SERVER_FL_NO_IBULK  7               /* Fileserver doesn't support FS.InlineBulkStatus */
491 #define AFS_SERVER_FL_MAY_HAVE_CB 8             /* May have callbacks on this fileserver */
492 #define AFS_SERVER_FL_IS_YFS    9               /* Server is YFS not AFS */
493 #define AFS_SERVER_FL_NO_RM2    10              /* Fileserver doesn't support YFS.RemoveFile2 */
494 #define AFS_SERVER_FL_HAVE_EPOCH 11             /* ->epoch is valid */
495 #define AFS_SERVER_FL_NEEDS_UPDATE 12           /* Fileserver address list is out of date */
496         atomic_t                ref;            /* Object refcount */
497         atomic_t                active;         /* Active user count */
498         u32                     addr_version;   /* Address list version */
499         u32                     cm_epoch;       /* Server RxRPC epoch */
500         unsigned int            debug_id;       /* Debugging ID for traces */
501
502         /* file service access */
503         rwlock_t                fs_lock;        /* access lock */
504
505         /* callback promise management */
506         struct rb_root          cb_volumes;     /* List of volume interests on this server */
507         unsigned                cb_s_break;     /* Break-everything counter. */
508         seqlock_t               cb_break_lock;  /* Volume finding lock */
509
510         /* Probe state */
511         unsigned long           probed_at;      /* Time last probe was dispatched (jiffies) */
512         wait_queue_head_t       probe_wq;
513         atomic_t                probe_outstanding;
514         spinlock_t              probe_lock;
515         struct {
516                 unsigned int    rtt;            /* RTT as ktime/64 */
517                 u32             abort_code;
518                 u32             cm_epoch;
519                 short           error;
520                 bool            responded:1;
521                 bool            is_yfs:1;
522                 bool            not_yfs:1;
523                 bool            local_failure:1;
524                 bool            cm_probed:1;
525                 bool            said_rebooted:1;
526                 bool            said_inconsistent:1;
527         } probe;
528 };
529
530 /*
531  * Volume collation in the server's callback interest list.
532  */
533 struct afs_vol_interest {
534         struct rb_node          srv_node;       /* Link in server->cb_volumes */
535         struct hlist_head       cb_interests;   /* List of callback interests on the server */
536         union {
537                 struct rcu_head rcu;
538                 afs_volid_t     vid;            /* Volume ID to match */
539         };
540         unsigned int            usage;
541 };
542
543 /*
544  * Interest by a superblock on a server.
545  */
546 struct afs_cb_interest {
547         struct hlist_node       cb_vlink;       /* Link in vol_interest->cb_interests */
548         struct afs_vol_interest *vol_interest;
549         struct afs_server       *server;        /* Server on which this interest resides */
550         struct super_block      *sb;            /* Superblock on which inodes reside */
551         struct rcu_head         rcu;
552         refcount_t              usage;
553 };
554
555 /*
556  * Replaceable server list.
557  */
558 struct afs_server_entry {
559         struct afs_server       *server;
560         struct afs_cb_interest  *cb_interest;
561 };
562
563 struct afs_server_list {
564         refcount_t              usage;
565         unsigned char           nr_servers;
566         unsigned char           preferred;      /* Preferred server */
567         unsigned short          vnovol_mask;    /* Servers to be skipped due to VNOVOL */
568         unsigned int            seq;            /* Set to ->servers_seq when installed */
569         rwlock_t                lock;
570         struct afs_server_entry servers[];
571 };
572
573 /*
574  * Live AFS volume management.
575  */
576 struct afs_volume {
577         afs_volid_t             vid;            /* volume ID */
578         atomic_t                usage;
579         time64_t                update_at;      /* Time at which to next update */
580         struct afs_cell         *cell;          /* Cell to which belongs (pins ref) */
581         struct list_head        proc_link;      /* Link in cell->vl_proc */
582         unsigned long           flags;
583 #define AFS_VOLUME_NEEDS_UPDATE 0       /* - T if an update needs performing */
584 #define AFS_VOLUME_UPDATING     1       /* - T if an update is in progress */
585 #define AFS_VOLUME_WAIT         2       /* - T if users must wait for update */
586 #define AFS_VOLUME_DELETED      3       /* - T if volume appears deleted */
587 #define AFS_VOLUME_OFFLINE      4       /* - T if volume offline notice given */
588 #define AFS_VOLUME_BUSY         5       /* - T if volume busy notice given */
589 #ifdef CONFIG_AFS_FSCACHE
590         struct fscache_cookie   *cache;         /* caching cookie */
591 #endif
592         struct afs_server_list  *servers;       /* List of servers on which volume resides */
593         rwlock_t                servers_lock;   /* Lock for ->servers */
594         unsigned int            servers_seq;    /* Incremented each time ->servers changes */
595
596         unsigned                cb_v_break;     /* Break-everything counter. */
597         rwlock_t                cb_v_break_lock;
598
599         afs_voltype_t           type;           /* type of volume */
600         short                   error;
601         char                    type_force;     /* force volume type (suppress R/O -> R/W) */
602         u8                      name_len;
603         u8                      name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
604 };
605
606 enum afs_lock_state {
607         AFS_VNODE_LOCK_NONE,            /* The vnode has no lock on the server */
608         AFS_VNODE_LOCK_WAITING_FOR_CB,  /* We're waiting for the server to break the callback */
609         AFS_VNODE_LOCK_SETTING,         /* We're asking the server for a lock */
610         AFS_VNODE_LOCK_GRANTED,         /* We have a lock on the server */
611         AFS_VNODE_LOCK_EXTENDING,       /* We're extending a lock on the server */
612         AFS_VNODE_LOCK_NEED_UNLOCK,     /* We need to unlock on the server */
613         AFS_VNODE_LOCK_UNLOCKING,       /* We're telling the server to unlock */
614         AFS_VNODE_LOCK_DELETED,         /* The vnode has been deleted whilst we have a lock */
615 };
616
617 /*
618  * AFS inode private data.
619  *
620  * Note that afs_alloc_inode() *must* reset anything that could incorrectly
621  * leak from one inode to another.
622  */
623 struct afs_vnode {
624         struct inode            vfs_inode;      /* the VFS's inode record */
625
626         struct afs_volume       *volume;        /* volume on which vnode resides */
627         struct afs_fid          fid;            /* the file identifier for this inode */
628         struct afs_file_status  status;         /* AFS status info for this file */
629         afs_dataversion_t       invalid_before; /* Child dentries are invalid before this */
630 #ifdef CONFIG_AFS_FSCACHE
631         struct fscache_cookie   *cache;         /* caching cookie */
632 #endif
633         struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
634         struct mutex            io_lock;        /* Lock for serialising I/O on this mutex */
635         struct rw_semaphore     validate_lock;  /* lock for validating this vnode */
636         struct rw_semaphore     rmdir_lock;     /* Lock for rmdir vs sillyrename */
637         struct key              *silly_key;     /* Silly rename key */
638         spinlock_t              wb_lock;        /* lock for wb_keys */
639         spinlock_t              lock;           /* waitqueue/flags lock */
640         unsigned long           flags;
641 #define AFS_VNODE_CB_PROMISED   0               /* Set if vnode has a callback promise */
642 #define AFS_VNODE_UNSET         1               /* set if vnode attributes not yet set */
643 #define AFS_VNODE_DIR_VALID     2               /* Set if dir contents are valid */
644 #define AFS_VNODE_ZAP_DATA      3               /* set if vnode's data should be invalidated */
645 #define AFS_VNODE_DELETED       4               /* set if vnode deleted on server */
646 #define AFS_VNODE_MOUNTPOINT    5               /* set if vnode is a mountpoint symlink */
647 #define AFS_VNODE_AUTOCELL      6               /* set if Vnode is an auto mount point */
648 #define AFS_VNODE_PSEUDODIR     7               /* set if Vnode is a pseudo directory */
649 #define AFS_VNODE_NEW_CONTENT   8               /* Set if file has new content (create/trunc-0) */
650
651         struct list_head        wb_keys;        /* List of keys available for writeback */
652         struct list_head        pending_locks;  /* locks waiting to be granted */
653         struct list_head        granted_locks;  /* locks granted on this file */
654         struct delayed_work     lock_work;      /* work to be done in locking */
655         struct key              *lock_key;      /* Key to be used in lock ops */
656         ktime_t                 locked_at;      /* Time at which lock obtained */
657         enum afs_lock_state     lock_state : 8;
658         afs_lock_type_t         lock_type : 8;
659
660         /* outstanding callback notification on this file */
661         struct afs_cb_interest __rcu *cb_interest; /* Server on which this resides */
662         unsigned int            cb_s_break;     /* Mass break counter on ->server */
663         unsigned int            cb_v_break;     /* Mass break counter on ->volume */
664         unsigned int            cb_break;       /* Break counter on vnode */
665         seqlock_t               cb_lock;        /* Lock for ->cb_interest, ->status, ->cb_*break */
666
667         time64_t                cb_expires_at;  /* time at which callback expires */
668 };
669
670 static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
671 {
672 #ifdef CONFIG_AFS_FSCACHE
673         return vnode->cache;
674 #else
675         return NULL;
676 #endif
677 }
678
679 /*
680  * cached security record for one user's attempt to access a vnode
681  */
682 struct afs_permit {
683         struct key              *key;           /* RxRPC ticket holding a security context */
684         afs_access_t            access;         /* CallerAccess value for this key */
685 };
686
687 /*
688  * Immutable cache of CallerAccess records from attempts to access vnodes.
689  * These may be shared between multiple vnodes.
690  */
691 struct afs_permits {
692         struct rcu_head         rcu;
693         struct hlist_node       hash_node;      /* Link in hash */
694         unsigned long           h;              /* Hash value for this permit list */
695         refcount_t              usage;
696         unsigned short          nr_permits;     /* Number of records */
697         bool                    invalidated;    /* Invalidated due to key change */
698         struct afs_permit       permits[];      /* List of permits sorted by key pointer */
699 };
700
701 /*
702  * Error prioritisation and accumulation.
703  */
704 struct afs_error {
705         short   error;                  /* Accumulated error */
706         bool    responded;              /* T if server responded */
707 };
708
709 /*
710  * Cursor for iterating over a server's address list.
711  */
712 struct afs_addr_cursor {
713         struct afs_addr_list    *alist;         /* Current address list (pins ref) */
714         unsigned long           tried;          /* Tried addresses */
715         signed char             index;          /* Current address */
716         bool                    responded;      /* T if the current address responded */
717         unsigned short          nr_iterations;  /* Number of address iterations */
718         short                   error;
719         u32                     abort_code;
720 };
721
722 /*
723  * Cursor for iterating over a set of volume location servers.
724  */
725 struct afs_vl_cursor {
726         struct afs_addr_cursor  ac;
727         struct afs_cell         *cell;          /* The cell we're querying */
728         struct afs_vlserver_list *server_list;  /* Current server list (pins ref) */
729         struct afs_vlserver     *server;        /* Server on which this resides */
730         struct key              *key;           /* Key for the server */
731         unsigned long           untried;        /* Bitmask of untried servers */
732         short                   index;          /* Current server */
733         short                   error;
734         unsigned short          flags;
735 #define AFS_VL_CURSOR_STOP      0x0001          /* Set to cease iteration */
736 #define AFS_VL_CURSOR_RETRY     0x0002          /* Set to do a retry */
737 #define AFS_VL_CURSOR_RETRIED   0x0004          /* Set if started a retry */
738         unsigned short          nr_iterations;  /* Number of server iterations */
739 };
740
741 /*
742  * Fileserver operation methods.
743  */
744 struct afs_operation_ops {
745         void (*issue_afs_rpc)(struct afs_operation *op);
746         void (*issue_yfs_rpc)(struct afs_operation *op);
747         void (*success)(struct afs_operation *op);
748         void (*aborted)(struct afs_operation *op);
749         void (*edit_dir)(struct afs_operation *op);
750         void (*put)(struct afs_operation *op);
751 };
752
753 struct afs_vnode_param {
754         struct afs_vnode        *vnode;
755         struct afs_fid          fid;            /* Fid to access */
756         struct afs_status_cb    scb;            /* Returned status and callback promise */
757         afs_dataversion_t       dv_before;      /* Data version before the call */
758         unsigned int            cb_break_before; /* cb_break + cb_s_break before the call */
759         u8                      dv_delta;       /* Expected change in data version */
760         bool                    put_vnode;      /* T if we have a ref on the vnode */
761         bool                    need_io_lock;   /* T if we need the I/O lock on this */
762 };
763
764 /*
765  * Fileserver operation wrapper, handling server and address rotation
766  * asynchronously.  May make simultaneous calls to multiple servers.
767  */
768 struct afs_operation {
769         struct afs_net          *net;           /* Network namespace */
770         struct key              *key;           /* Key for the cell */
771         const struct afs_call_type *type;       /* Type of call done */
772         const struct afs_operation_ops *ops;
773
774         /* Parameters/results for the operation */
775         struct afs_volume       *volume;        /* Volume being accessed */
776         struct afs_vnode_param  file[2];
777         struct afs_vnode_param  *more_files;
778         struct afs_volsync      volsync;
779         struct dentry           *dentry;        /* Dentry to be altered */
780         struct dentry           *dentry_2;      /* Second dentry to be altered */
781         struct timespec64       mtime;          /* Modification time to record */
782         short                   nr_files;       /* Number of entries in file[], more_files */
783         short                   error;
784         unsigned int            abort_code;
785         unsigned int            debug_id;
786
787         unsigned int            cb_v_break;     /* Volume break counter before op */
788         unsigned int            cb_s_break;     /* Server break counter before op */
789
790         union {
791                 struct {
792                         int     which;          /* Which ->file[] to fetch for */
793                 } fetch_status;
794                 struct {
795                         int     reason;         /* enum afs_edit_dir_reason */
796                         mode_t  mode;
797                         const char *symlink;
798                 } create;
799                 struct {
800                         bool    need_rehash;
801                 } unlink;
802                 struct {
803                         struct dentry *rehash;
804                         struct dentry *tmp;
805                         bool    new_negative;
806                 } rename;
807                 struct {
808                         struct afs_read *req;
809                 } fetch;
810                 struct {
811                         struct afs_vnode *lvnode;       /* vnode being locked */
812                         afs_lock_type_t type;
813                 } lock;
814                 struct {
815                         struct address_space *mapping;  /* Pages being written from */
816                         pgoff_t         first;          /* first page in mapping to deal with */
817                         pgoff_t         last;           /* last page in mapping to deal with */
818                         unsigned        first_offset;   /* offset into mapping[first] */
819                         unsigned        last_to;        /* amount of mapping[last] */
820                 } store;
821                 struct {
822                         struct iattr    *attr;
823                 } setattr;
824                 struct afs_acl  *acl;
825                 struct yfs_acl  *yacl;
826                 struct {
827                         struct afs_volume_status vs;
828                         struct kstatfs          *buf;
829                 } volstatus;
830         };
831
832         /* Fileserver iteration state */
833         struct afs_addr_cursor  ac;
834         struct afs_server_list  *server_list;   /* Current server list (pins ref) */
835         struct afs_cb_interest  *cbi;           /* Server on which this resides (pins ref) */
836         struct afs_call         *call;
837         unsigned long           untried;        /* Bitmask of untried servers */
838         short                   index;          /* Current server */
839         unsigned short          nr_iterations;  /* Number of server iterations */
840
841         unsigned int            flags;
842 #define AFS_OPERATION_STOP      0x0001          /* Set to cease iteration */
843 #define AFS_OPERATION_VBUSY     0x0002          /* Set if seen VBUSY */
844 #define AFS_OPERATION_VMOVED    0x0004          /* Set if seen VMOVED */
845 #define AFS_OPERATION_VNOVOL    0x0008          /* Set if seen VNOVOL */
846 #define AFS_OPERATION_CUR_ONLY  0x0010          /* Set if current server only (file lock held) */
847 #define AFS_OPERATION_NO_VSLEEP 0x0020          /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
848 #define AFS_OPERATION_UNINTR    0x0040          /* Set if op is uninterruptible */
849 #define AFS_OPERATION_DOWNGRADE 0x0080          /* Set to retry with downgraded opcode */
850 #define AFS_OPERATION_LOCK_0    0x0100          /* Set if have io_lock on file[0] */
851 #define AFS_OPERATION_LOCK_1    0x0200          /* Set if have io_lock on file[1] */
852 };
853
854 /*
855  * Cache auxiliary data.
856  */
857 struct afs_vnode_cache_aux {
858         u64                     data_version;
859 } __packed;
860
861 #include <trace/events/afs.h>
862
863 /*****************************************************************************/
864 /*
865  * addr_list.c
866  */
867 static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
868 {
869         if (alist)
870                 refcount_inc(&alist->usage);
871         return alist;
872 }
873 extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
874                                                 unsigned short,
875                                                 unsigned short);
876 extern void afs_put_addrlist(struct afs_addr_list *);
877 extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
878                                                       const char *, size_t, char,
879                                                       unsigned short, unsigned short);
880 extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
881 extern bool afs_iterate_addresses(struct afs_addr_cursor *);
882 extern int afs_end_cursor(struct afs_addr_cursor *);
883
884 extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
885 extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
886
887 /*
888  * cache.c
889  */
890 #ifdef CONFIG_AFS_FSCACHE
891 extern struct fscache_netfs afs_cache_netfs;
892 extern struct fscache_cookie_def afs_cell_cache_index_def;
893 extern struct fscache_cookie_def afs_volume_cache_index_def;
894 extern struct fscache_cookie_def afs_vnode_cache_index_def;
895 #else
896 #define afs_cell_cache_index_def        (*(struct fscache_cookie_def *) NULL)
897 #define afs_volume_cache_index_def      (*(struct fscache_cookie_def *) NULL)
898 #define afs_vnode_cache_index_def       (*(struct fscache_cookie_def *) NULL)
899 #endif
900
901 /*
902  * callback.c
903  */
904 extern void afs_init_callback_state(struct afs_server *);
905 extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
906 extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
907 extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
908
909 extern int afs_register_server_cb_interest(struct afs_vnode *,
910                                            struct afs_server_list *, unsigned int);
911 extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
912 extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
913
914 static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
915 {
916         if (cbi)
917                 refcount_inc(&cbi->usage);
918         return cbi;
919 }
920
921 static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
922 {
923         return vnode->cb_break + vnode->cb_v_break;
924 }
925
926 static inline bool afs_cb_is_broken(unsigned int cb_break,
927                                     const struct afs_vnode *vnode,
928                                     const struct afs_cb_interest *cbi)
929 {
930         return !cbi || cb_break != (vnode->cb_break +
931                                     vnode->volume->cb_v_break);
932 }
933
934 /*
935  * cell.c
936  */
937 extern int afs_cell_init(struct afs_net *, const char *);
938 extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
939 extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
940                                         const char *, bool);
941 extern struct afs_cell *afs_get_cell(struct afs_cell *);
942 extern void afs_put_cell(struct afs_net *, struct afs_cell *);
943 extern void afs_manage_cells(struct work_struct *);
944 extern void afs_cells_timer(struct timer_list *);
945 extern void __net_exit afs_cell_purge(struct afs_net *);
946
947 /*
948  * cmservice.c
949  */
950 extern bool afs_cm_incoming_call(struct afs_call *);
951
952 /*
953  * dir.c
954  */
955 extern const struct file_operations afs_dir_file_operations;
956 extern const struct inode_operations afs_dir_inode_operations;
957 extern const struct address_space_operations afs_dir_aops;
958 extern const struct dentry_operations afs_fs_dentry_operations;
959
960 extern void afs_d_release(struct dentry *);
961
962 /*
963  * dir_edit.c
964  */
965 extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
966                              enum afs_edit_dir_reason);
967 extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
968
969 /*
970  * dir_silly.c
971  */
972 extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
973                            struct dentry *, struct key *);
974 extern int afs_silly_iput(struct dentry *, struct inode *);
975
976 /*
977  * dynroot.c
978  */
979 extern const struct inode_operations afs_dynroot_inode_operations;
980 extern const struct dentry_operations afs_dynroot_dentry_operations;
981
982 extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
983 extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
984 extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
985 extern int afs_dynroot_populate(struct super_block *);
986 extern void afs_dynroot_depopulate(struct super_block *);
987
988 /*
989  * file.c
990  */
991 extern const struct address_space_operations afs_fs_aops;
992 extern const struct inode_operations afs_file_inode_operations;
993 extern const struct file_operations afs_file_operations;
994
995 extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
996 extern void afs_put_wb_key(struct afs_wb_key *);
997 extern int afs_open(struct inode *, struct file *);
998 extern int afs_release(struct inode *, struct file *);
999 extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
1000 extern int afs_page_filler(void *, struct page *);
1001 extern void afs_put_read(struct afs_read *);
1002
1003 static inline struct afs_read *afs_get_read(struct afs_read *req)
1004 {
1005         refcount_inc(&req->usage);
1006         return req;
1007 }
1008
1009 /*
1010  * flock.c
1011  */
1012 extern struct workqueue_struct *afs_lock_manager;
1013
1014 extern void afs_lock_op_done(struct afs_call *);
1015 extern void afs_lock_work(struct work_struct *);
1016 extern void afs_lock_may_be_available(struct afs_vnode *);
1017 extern int afs_lock(struct file *, int, struct file_lock *);
1018 extern int afs_flock(struct file *, int, struct file_lock *);
1019
1020 /*
1021  * fsclient.c
1022  */
1023 extern void afs_fs_fetch_status(struct afs_operation *);
1024 extern void afs_fs_fetch_data(struct afs_operation *);
1025 extern void afs_fs_create_file(struct afs_operation *);
1026 extern void afs_fs_make_dir(struct afs_operation *);
1027 extern void afs_fs_remove_file(struct afs_operation *);
1028 extern void afs_fs_remove_dir(struct afs_operation *);
1029 extern void afs_fs_link(struct afs_operation *);
1030 extern void afs_fs_symlink(struct afs_operation *);
1031 extern void afs_fs_rename(struct afs_operation *);
1032 extern void afs_fs_store_data(struct afs_operation *);
1033 extern void afs_fs_setattr(struct afs_operation *);
1034 extern void afs_fs_get_volume_status(struct afs_operation *);
1035 extern void afs_fs_set_lock(struct afs_operation *);
1036 extern void afs_fs_extend_lock(struct afs_operation *);
1037 extern void afs_fs_release_lock(struct afs_operation *);
1038 extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
1039                                         struct afs_addr_cursor *, struct key *);
1040 extern bool afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
1041                                     struct afs_addr_cursor *, struct key *);
1042 extern void afs_fs_inline_bulk_status(struct afs_operation *);
1043
1044 struct afs_acl {
1045         u32     size;
1046         u8      data[];
1047 };
1048
1049 extern void afs_fs_fetch_acl(struct afs_operation *);
1050 extern void afs_fs_store_acl(struct afs_operation *);
1051
1052 /*
1053  * fs_operation.c
1054  */
1055 extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
1056 extern int afs_put_operation(struct afs_operation *);
1057 extern bool afs_begin_vnode_operation(struct afs_operation *);
1058 extern void afs_wait_for_operation(struct afs_operation *);
1059 extern int afs_do_sync_operation(struct afs_operation *);
1060
1061 static inline void afs_op_nomem(struct afs_operation *op)
1062 {
1063         op->error = -ENOMEM;
1064 }
1065
1066 static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
1067                                     struct afs_vnode *vnode)
1068 {
1069         op->file[n].vnode = vnode;
1070         op->file[n].need_io_lock = true;
1071 }
1072
1073 static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
1074                                   const struct afs_fid *fid)
1075 {
1076         op->file[n].fid = *fid;
1077 }
1078
1079 /*
1080  * fs_probe.c
1081  */
1082 extern void afs_fileserver_probe_result(struct afs_call *);
1083 extern void afs_fs_probe_fileserver(struct afs_net *, struct afs_server *, struct key *, bool);
1084 extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long);
1085 extern void afs_fs_probe_dispatcher(struct work_struct *);
1086
1087 /*
1088  * inode.c
1089  */
1090 extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
1091 extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
1092 extern int afs_ilookup5_test_by_fid(struct inode *, void *);
1093 extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
1094 extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
1095 extern struct inode *afs_root_iget(struct super_block *, struct key *);
1096 extern void afs_zap_data(struct afs_vnode *);
1097 extern bool afs_check_validity(struct afs_vnode *);
1098 extern int afs_validate(struct afs_vnode *, struct key *);
1099 extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
1100 extern int afs_setattr(struct dentry *, struct iattr *);
1101 extern void afs_evict_inode(struct inode *);
1102 extern int afs_drop_inode(struct inode *);
1103
1104 /*
1105  * main.c
1106  */
1107 extern struct workqueue_struct *afs_wq;
1108 extern int afs_net_id;
1109
1110 static inline struct afs_net *afs_net(struct net *net)
1111 {
1112         return net_generic(net, afs_net_id);
1113 }
1114
1115 static inline struct afs_net *afs_sb2net(struct super_block *sb)
1116 {
1117         return afs_net(AFS_FS_S(sb)->net_ns);
1118 }
1119
1120 static inline struct afs_net *afs_d2net(struct dentry *dentry)
1121 {
1122         return afs_sb2net(dentry->d_sb);
1123 }
1124
1125 static inline struct afs_net *afs_i2net(struct inode *inode)
1126 {
1127         return afs_sb2net(inode->i_sb);
1128 }
1129
1130 static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
1131 {
1132         return afs_i2net(&vnode->vfs_inode);
1133 }
1134
1135 static inline struct afs_net *afs_sock2net(struct sock *sk)
1136 {
1137         return net_generic(sock_net(sk), afs_net_id);
1138 }
1139
1140 static inline void __afs_stat(atomic_t *s)
1141 {
1142         atomic_inc(s);
1143 }
1144
1145 #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
1146
1147 /*
1148  * misc.c
1149  */
1150 extern int afs_abort_to_error(u32);
1151 extern void afs_prioritise_error(struct afs_error *, int, u32);
1152
1153 /*
1154  * mntpt.c
1155  */
1156 extern const struct inode_operations afs_mntpt_inode_operations;
1157 extern const struct inode_operations afs_autocell_inode_operations;
1158 extern const struct file_operations afs_mntpt_file_operations;
1159
1160 extern struct vfsmount *afs_d_automount(struct path *);
1161 extern void afs_mntpt_kill_timer(void);
1162
1163 /*
1164  * proc.c
1165  */
1166 #ifdef CONFIG_PROC_FS
1167 extern int __net_init afs_proc_init(struct afs_net *);
1168 extern void __net_exit afs_proc_cleanup(struct afs_net *);
1169 extern int afs_proc_cell_setup(struct afs_cell *);
1170 extern void afs_proc_cell_remove(struct afs_cell *);
1171 extern void afs_put_sysnames(struct afs_sysnames *);
1172 #else
1173 static inline int afs_proc_init(struct afs_net *net) { return 0; }
1174 static inline void afs_proc_cleanup(struct afs_net *net) {}
1175 static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
1176 static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
1177 static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
1178 #endif
1179
1180 /*
1181  * rotate.c
1182  */
1183 extern bool afs_select_fileserver(struct afs_operation *);
1184 extern bool afs_select_current_fileserver(struct afs_operation *);
1185 extern void afs_dump_edestaddrreq(const struct afs_operation *);
1186
1187 /*
1188  * rxrpc.c
1189  */
1190 extern struct workqueue_struct *afs_async_calls;
1191
1192 extern int __net_init afs_open_socket(struct afs_net *);
1193 extern void __net_exit afs_close_socket(struct afs_net *);
1194 extern void afs_charge_preallocation(struct work_struct *);
1195 extern void afs_put_call(struct afs_call *);
1196 extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t);
1197 extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *);
1198 extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
1199                                             const struct afs_call_type *,
1200                                             size_t, size_t);
1201 extern void afs_flat_call_destructor(struct afs_call *);
1202 extern void afs_send_empty_reply(struct afs_call *);
1203 extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
1204 extern int afs_extract_data(struct afs_call *, bool);
1205 extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
1206
1207 static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
1208                                     gfp_t gfp)
1209 {
1210         op->call = call;
1211         op->type = call->type;
1212         call->op = op;
1213         call->key = op->key;
1214         call->cbi = afs_get_cb_interest(op->cbi);
1215         call->intr = !(op->flags & AFS_OPERATION_UNINTR);
1216         afs_make_call(&op->ac, call, gfp);
1217 }
1218
1219 static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
1220 {
1221         call->kvec[0].iov_base = buf;
1222         call->kvec[0].iov_len = size;
1223         iov_iter_kvec(&call->def_iter, READ, call->kvec, 1, size);
1224 }
1225
1226 static inline void afs_extract_to_tmp(struct afs_call *call)
1227 {
1228         afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
1229 }
1230
1231 static inline void afs_extract_to_tmp64(struct afs_call *call)
1232 {
1233         afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
1234 }
1235
1236 static inline void afs_extract_discard(struct afs_call *call, size_t size)
1237 {
1238         iov_iter_discard(&call->def_iter, READ, size);
1239 }
1240
1241 static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
1242 {
1243         afs_extract_begin(call, call->buffer, size);
1244 }
1245
1246 static inline int afs_transfer_reply(struct afs_call *call)
1247 {
1248         return afs_extract_data(call, false);
1249 }
1250
1251 static inline bool afs_check_call_state(struct afs_call *call,
1252                                         enum afs_call_state state)
1253 {
1254         return READ_ONCE(call->state) == state;
1255 }
1256
1257 static inline bool afs_set_call_state(struct afs_call *call,
1258                                       enum afs_call_state from,
1259                                       enum afs_call_state to)
1260 {
1261         bool ok = false;
1262
1263         spin_lock_bh(&call->state_lock);
1264         if (call->state == from) {
1265                 call->state = to;
1266                 trace_afs_call_state(call, from, to, 0, 0);
1267                 ok = true;
1268         }
1269         spin_unlock_bh(&call->state_lock);
1270         return ok;
1271 }
1272
1273 static inline void afs_set_call_complete(struct afs_call *call,
1274                                          int error, u32 remote_abort)
1275 {
1276         enum afs_call_state state;
1277         bool ok = false;
1278
1279         spin_lock_bh(&call->state_lock);
1280         state = call->state;
1281         if (state != AFS_CALL_COMPLETE) {
1282                 call->abort_code = remote_abort;
1283                 call->error = error;
1284                 call->state = AFS_CALL_COMPLETE;
1285                 trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
1286                                      error, remote_abort);
1287                 ok = true;
1288         }
1289         spin_unlock_bh(&call->state_lock);
1290         if (ok) {
1291                 trace_afs_call_done(call);
1292
1293                 /* Asynchronous calls have two refs to release - one from the alloc and
1294                  * one queued with the work item - and we can't just deallocate the
1295                  * call because the work item may be queued again.
1296                  */
1297                 if (call->drop_ref)
1298                         afs_put_call(call);
1299         }
1300 }
1301
1302 /*
1303  * security.c
1304  */
1305 extern void afs_put_permits(struct afs_permits *);
1306 extern void afs_clear_permits(struct afs_vnode *);
1307 extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
1308                              struct afs_status_cb *);
1309 extern void afs_zap_permits(struct rcu_head *);
1310 extern struct key *afs_request_key(struct afs_cell *);
1311 extern struct key *afs_request_key_rcu(struct afs_cell *);
1312 extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
1313 extern int afs_permission(struct inode *, int);
1314 extern void __exit afs_clean_up_permit_cache(void);
1315
1316 /*
1317  * server.c
1318  */
1319 extern spinlock_t afs_server_peer_lock;
1320
1321 extern struct afs_server *afs_find_server(struct afs_net *,
1322                                           const struct sockaddr_rxrpc *);
1323 extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
1324 extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
1325 extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
1326 extern struct afs_server *afs_use_server(struct afs_server *, enum afs_server_trace);
1327 extern void afs_unuse_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1328 extern void afs_unuse_server_notime(struct afs_net *, struct afs_server *, enum afs_server_trace);
1329 extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
1330 extern void afs_manage_servers(struct work_struct *);
1331 extern void afs_servers_timer(struct timer_list *);
1332 extern void afs_fs_probe_timer(struct timer_list *);
1333 extern void __net_exit afs_purge_servers(struct afs_net *);
1334 extern bool afs_check_server_record(struct afs_operation *, struct afs_server *);
1335
1336 static inline void afs_inc_servers_outstanding(struct afs_net *net)
1337 {
1338         atomic_inc(&net->servers_outstanding);
1339 }
1340
1341 static inline void afs_dec_servers_outstanding(struct afs_net *net)
1342 {
1343         if (atomic_dec_and_test(&net->servers_outstanding))
1344                 wake_up_var(&net->servers_outstanding);
1345 }
1346
1347 static inline bool afs_is_probing_server(struct afs_server *server)
1348 {
1349         return list_empty(&server->probe_link);
1350 }
1351
1352 /*
1353  * server_list.c
1354  */
1355 static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
1356 {
1357         refcount_inc(&slist->usage);
1358         return slist;
1359 }
1360
1361 extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
1362 extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
1363                                                      struct afs_vldb_entry *,
1364                                                      u8);
1365 extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
1366
1367 /*
1368  * super.c
1369  */
1370 extern int __init afs_fs_init(void);
1371 extern void afs_fs_exit(void);
1372
1373 /*
1374  * vlclient.c
1375  */
1376 extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
1377                                                          const char *, int);
1378 extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
1379 extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *,
1380                                                 struct key *, struct afs_vlserver *, unsigned int);
1381 extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
1382
1383 /*
1384  * vl_probe.c
1385  */
1386 extern void afs_vlserver_probe_result(struct afs_call *);
1387 extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
1388 extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
1389
1390 /*
1391  * vl_rotate.c
1392  */
1393 extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
1394                                          struct afs_cell *, struct key *);
1395 extern bool afs_select_vlserver(struct afs_vl_cursor *);
1396 extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
1397 extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
1398
1399 /*
1400  * vlserver_list.c
1401  */
1402 static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
1403 {
1404         atomic_inc(&vlserver->usage);
1405         return vlserver;
1406 }
1407
1408 static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
1409 {
1410         if (vllist)
1411                 atomic_inc(&vllist->usage);
1412         return vllist;
1413 }
1414
1415 extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
1416 extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
1417 extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
1418 extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
1419 extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
1420                                                            const void *, size_t);
1421
1422 /*
1423  * volume.c
1424  */
1425 static inline struct afs_volume *afs_get_volume(struct afs_volume *volume)
1426 {
1427         if (volume)
1428                 atomic_inc(&volume->usage);
1429         return volume;
1430 }
1431
1432 extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
1433 extern void afs_activate_volume(struct afs_volume *);
1434 extern void afs_deactivate_volume(struct afs_volume *);
1435 extern void afs_put_volume(struct afs_net *, struct afs_volume *);
1436 extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
1437
1438 /*
1439  * write.c
1440  */
1441 extern int afs_set_page_dirty(struct page *);
1442 extern int afs_write_begin(struct file *file, struct address_space *mapping,
1443                         loff_t pos, unsigned len, unsigned flags,
1444                         struct page **pagep, void **fsdata);
1445 extern int afs_write_end(struct file *file, struct address_space *mapping,
1446                         loff_t pos, unsigned len, unsigned copied,
1447                         struct page *page, void *fsdata);
1448 extern int afs_writepage(struct page *, struct writeback_control *);
1449 extern int afs_writepages(struct address_space *, struct writeback_control *);
1450 extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
1451 extern int afs_fsync(struct file *, loff_t, loff_t, int);
1452 extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
1453 extern void afs_prune_wb_keys(struct afs_vnode *);
1454 extern int afs_launder_page(struct page *);
1455
1456 /*
1457  * xattr.c
1458  */
1459 extern const struct xattr_handler *afs_xattr_handlers[];
1460 extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
1461
1462 /*
1463  * yfsclient.c
1464  */
1465 extern void yfs_fs_fetch_file_status(struct afs_operation *);
1466 extern void yfs_fs_fetch_data(struct afs_operation *);
1467 extern void yfs_fs_create_file(struct afs_operation *);
1468 extern void yfs_fs_make_dir(struct afs_operation *);
1469 extern void yfs_fs_remove_file2(struct afs_operation *);
1470 extern void yfs_fs_remove_file(struct afs_operation *);
1471 extern void yfs_fs_remove_dir(struct afs_operation *);
1472 extern void yfs_fs_link(struct afs_operation *);
1473 extern void yfs_fs_symlink(struct afs_operation *);
1474 extern void yfs_fs_rename(struct afs_operation *);
1475 extern void yfs_fs_store_data(struct afs_operation *);
1476 extern void yfs_fs_setattr(struct afs_operation *);
1477 extern void yfs_fs_get_volume_status(struct afs_operation *);
1478 extern void yfs_fs_set_lock(struct afs_operation *);
1479 extern void yfs_fs_extend_lock(struct afs_operation *);
1480 extern void yfs_fs_release_lock(struct afs_operation *);
1481 extern void yfs_fs_fetch_status(struct afs_operation *);
1482 extern void yfs_fs_inline_bulk_status(struct afs_operation *);
1483
1484 struct yfs_acl {
1485         struct afs_acl  *acl;           /* Dir/file/symlink ACL */
1486         struct afs_acl  *vol_acl;       /* Whole volume ACL */
1487         u32             inherit_flag;   /* True if ACL is inherited from parent dir */
1488         u32             num_cleaned;    /* Number of ACEs removed due to subject removal */
1489         unsigned int    flags;
1490 #define YFS_ACL_WANT_ACL        0x01    /* Set if caller wants ->acl */
1491 #define YFS_ACL_WANT_VOL_ACL    0x02    /* Set if caller wants ->vol_acl */
1492 };
1493
1494 extern void yfs_free_opaque_acl(struct yfs_acl *);
1495 extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
1496 extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
1497
1498 /*
1499  * Miscellaneous inline functions.
1500  */
1501 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
1502 {
1503         return container_of(inode, struct afs_vnode, vfs_inode);
1504 }
1505
1506 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
1507 {
1508         return &vnode->vfs_inode;
1509 }
1510
1511 static inline void afs_check_for_remote_deletion(struct afs_operation *op,
1512                                                  struct afs_vnode *vnode)
1513 {
1514         if (op->error == -ENOENT) {
1515                 set_bit(AFS_VNODE_DELETED, &vnode->flags);
1516                 afs_break_callback(vnode, afs_cb_break_for_deleted);
1517         }
1518 }
1519
1520 /*
1521  * Note that a dentry got changed.  We need to set d_fsdata to the data version
1522  * number derived from the result of the operation.  It doesn't matter if
1523  * d_fsdata goes backwards as we'll just revalidate.
1524  */
1525 static inline void afs_update_dentry_version(struct afs_operation *op,
1526                                              struct afs_vnode_param *dir_vp,
1527                                              struct dentry *dentry)
1528 {
1529         if (!op->error)
1530                 dentry->d_fsdata =
1531                         (void *)(unsigned long)dir_vp->scb.status.data_version;
1532 }
1533
1534 static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
1535 {
1536         trace_afs_io_error(call->debug_id, -EIO, where);
1537         return -EIO;
1538 }
1539
1540 static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
1541 {
1542         trace_afs_file_error(vnode, -EIO, where);
1543         return -EIO;
1544 }
1545
1546 /*****************************************************************************/
1547 /*
1548  * debug tracing
1549  */
1550 extern unsigned afs_debug;
1551
1552 #define dbgprintk(FMT,...) \
1553         printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1554
1555 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1556 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1557 #define kdebug(FMT,...) dbgprintk("    "FMT ,##__VA_ARGS__)
1558
1559
1560 #if defined(__KDEBUG)
1561 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1562 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1563 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1564
1565 #elif defined(CONFIG_AFS_DEBUG)
1566 #define AFS_DEBUG_KENTER        0x01
1567 #define AFS_DEBUG_KLEAVE        0x02
1568 #define AFS_DEBUG_KDEBUG        0x04
1569
1570 #define _enter(FMT,...)                                 \
1571 do {                                                    \
1572         if (unlikely(afs_debug & AFS_DEBUG_KENTER))     \
1573                 kenter(FMT,##__VA_ARGS__);              \
1574 } while (0)
1575
1576 #define _leave(FMT,...)                                 \
1577 do {                                                    \
1578         if (unlikely(afs_debug & AFS_DEBUG_KLEAVE))     \
1579                 kleave(FMT,##__VA_ARGS__);              \
1580 } while (0)
1581
1582 #define _debug(FMT,...)                                 \
1583 do {                                                    \
1584         if (unlikely(afs_debug & AFS_DEBUG_KDEBUG))     \
1585                 kdebug(FMT,##__VA_ARGS__);              \
1586 } while (0)
1587
1588 #else
1589 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1590 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1591 #define _debug(FMT,...) no_printk("    "FMT ,##__VA_ARGS__)
1592 #endif
1593
1594 /*
1595  * debug assertion checking
1596  */
1597 #if 1 // defined(__KDEBUGALL)
1598
1599 #define ASSERT(X)                                               \
1600 do {                                                            \
1601         if (unlikely(!(X))) {                                   \
1602                 printk(KERN_ERR "\n");                          \
1603                 printk(KERN_ERR "AFS: Assertion failed\n");     \
1604                 BUG();                                          \
1605         }                                                       \
1606 } while(0)
1607
1608 #define ASSERTCMP(X, OP, Y)                                             \
1609 do {                                                                    \
1610         if (unlikely(!((X) OP (Y)))) {                                  \
1611                 printk(KERN_ERR "\n");                                  \
1612                 printk(KERN_ERR "AFS: Assertion failed\n");             \
1613                 printk(KERN_ERR "%lu " #OP " %lu is false\n",           \
1614                        (unsigned long)(X), (unsigned long)(Y));         \
1615                 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",       \
1616                        (unsigned long)(X), (unsigned long)(Y));         \
1617                 BUG();                                                  \
1618         }                                                               \
1619 } while(0)
1620
1621 #define ASSERTRANGE(L, OP1, N, OP2, H)                                  \
1622 do {                                                                    \
1623         if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) {               \
1624                 printk(KERN_ERR "\n");                                  \
1625                 printk(KERN_ERR "AFS: Assertion failed\n");             \
1626                 printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
1627                        (unsigned long)(L), (unsigned long)(N),          \
1628                        (unsigned long)(H));                             \
1629                 printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
1630                        (unsigned long)(L), (unsigned long)(N),          \
1631                        (unsigned long)(H));                             \
1632                 BUG();                                                  \
1633         }                                                               \
1634 } while(0)
1635
1636 #define ASSERTIF(C, X)                                          \
1637 do {                                                            \
1638         if (unlikely((C) && !(X))) {                            \
1639                 printk(KERN_ERR "\n");                          \
1640                 printk(KERN_ERR "AFS: Assertion failed\n");     \
1641                 BUG();                                          \
1642         }                                                       \
1643 } while(0)
1644
1645 #define ASSERTIFCMP(C, X, OP, Y)                                        \
1646 do {                                                                    \
1647         if (unlikely((C) && !((X) OP (Y)))) {                           \
1648                 printk(KERN_ERR "\n");                                  \
1649                 printk(KERN_ERR "AFS: Assertion failed\n");             \
1650                 printk(KERN_ERR "%lu " #OP " %lu is false\n",           \
1651                        (unsigned long)(X), (unsigned long)(Y));         \
1652                 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",       \
1653                        (unsigned long)(X), (unsigned long)(Y));         \
1654                 BUG();                                                  \
1655         }                                                               \
1656 } while(0)
1657
1658 #else
1659
1660 #define ASSERT(X)                               \
1661 do {                                            \
1662 } while(0)
1663
1664 #define ASSERTCMP(X, OP, Y)                     \
1665 do {                                            \
1666 } while(0)
1667
1668 #define ASSERTRANGE(L, OP1, N, OP2, H)          \
1669 do {                                            \
1670 } while(0)
1671
1672 #define ASSERTIF(C, X)                          \
1673 do {                                            \
1674 } while(0)
1675
1676 #define ASSERTIFCMP(C, X, OP, Y)                \
1677 do {                                            \
1678 } while(0)
1679
1680 #endif /* __KDEBUGALL */