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