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