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