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