[AFS]: Add security support.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / afs / internal.h
1 /* internal AFS stuff
2 *
3 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
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
12 #include <linux/compiler.h>
13 #include <linux/kernel.h>
14 #include <linux/fs.h>
15 #include <linux/pagemap.h>
16 #include <linux/skbuff.h>
17 #include <linux/rxrpc.h>
18 #include <linux/key.h>
19 #include "afs.h"
20 #include "afs_vl.h"
21
22 #define AFS_CELL_MAX_ADDRS 15
23
24 struct afs_call;
25
26 typedef enum {
27 AFS_VL_NEW, /* new, uninitialised record */
28 AFS_VL_CREATING, /* creating record */
29 AFS_VL_VALID, /* record is pending */
30 AFS_VL_NO_VOLUME, /* no such volume available */
31 AFS_VL_UPDATING, /* update in progress */
32 AFS_VL_VOLUME_DELETED, /* volume was deleted */
33 AFS_VL_UNCERTAIN, /* uncertain state (update failed) */
34 } __attribute__((packed)) afs_vlocation_state_t;
35
36 struct afs_mount_params {
37 bool rwpath; /* T if the parent should be considered R/W */
38 bool force; /* T to force cell type */
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 */
42 struct afs_cell *cell; /* cell in which to find volume */
43 struct afs_volume *volume; /* volume record */
44 struct key *key; /* key to use for secure mounting */
45 };
46
47 /*
48 * definition of how to wait for the completion of an operation
49 */
50 struct afs_wait_mode {
51 /* RxRPC received message notification */
52 void (*rx_wakeup)(struct afs_call *call);
53
54 /* synchronous call waiter and call dispatched notification */
55 int (*wait)(struct afs_call *call);
56
57 /* asynchronous call completion */
58 void (*async_complete)(void *reply, int error);
59 };
60
61 extern const struct afs_wait_mode afs_sync_call;
62 extern const struct afs_wait_mode afs_async_call;
63
64 /*
65 * a record of an in-progress RxRPC call
66 */
67 struct afs_call {
68 const struct afs_call_type *type; /* type of call */
69 const struct afs_wait_mode *wait_mode; /* completion wait mode */
70 wait_queue_head_t waitq; /* processes awaiting completion */
71 struct work_struct async_work; /* asynchronous work processor */
72 struct work_struct work; /* actual work processor */
73 struct sk_buff_head rx_queue; /* received packets */
74 struct rxrpc_call *rxcall; /* RxRPC call handle */
75 struct key *key; /* security for this call */
76 struct afs_server *server; /* server affected by incoming CM call */
77 void *request; /* request data (first part) */
78 void *request2; /* request data (second part) */
79 void *buffer; /* reply receive buffer */
80 void *reply; /* reply buffer (first part) */
81 void *reply2; /* reply buffer (second part) */
82 void *reply3; /* reply buffer (third part) */
83 enum { /* call state */
84 AFS_CALL_REQUESTING, /* request is being sent for outgoing call */
85 AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */
86 AFS_CALL_AWAIT_OP_ID, /* awaiting op ID on incoming call */
87 AFS_CALL_AWAIT_REQUEST, /* awaiting request data on incoming call */
88 AFS_CALL_REPLYING, /* replying to incoming call */
89 AFS_CALL_AWAIT_ACK, /* awaiting final ACK of incoming call */
90 AFS_CALL_COMPLETE, /* successfully completed */
91 AFS_CALL_BUSY, /* server was busy */
92 AFS_CALL_ABORTED, /* call was aborted */
93 AFS_CALL_ERROR, /* call failed due to error */
94 } state;
95 int error; /* error code */
96 unsigned request_size; /* size of request data */
97 unsigned reply_max; /* maximum size of reply */
98 unsigned reply_size; /* current size of reply */
99 unsigned short offset; /* offset into received data store */
100 unsigned char unmarshall; /* unmarshalling phase */
101 bool incoming; /* T if incoming call */
102 u16 service_id; /* RxRPC service ID to call */
103 __be16 port; /* target UDP port */
104 __be32 operation_ID; /* operation ID for an incoming call */
105 u32 count; /* count for use in unmarshalling */
106 __be32 tmp; /* place to extract temporary data */
107 };
108
109 struct afs_call_type {
110 const char *name;
111
112 /* deliver request or reply data to an call
113 * - returning an error will cause the call to be aborted
114 */
115 int (*deliver)(struct afs_call *call, struct sk_buff *skb,
116 bool last);
117
118 /* map an abort code to an error number */
119 int (*abort_to_error)(u32 abort_code);
120
121 /* clean up a call */
122 void (*destructor)(struct afs_call *call);
123 };
124
125 /*
126 * AFS superblock private data
127 * - there's one superblock per volume
128 */
129 struct afs_super_info {
130 struct afs_volume *volume; /* volume record */
131 char rwparent; /* T if parent is R/W AFS volume */
132 };
133
134 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
135 {
136 return sb->s_fs_info;
137 }
138
139 extern struct file_system_type afs_fs_type;
140
141 /*
142 * entry in the cached cell catalogue
143 */
144 struct afs_cache_cell {
145 char name[AFS_MAXCELLNAME]; /* cell name (padded with NULs) */
146 struct in_addr vl_servers[15]; /* cached cell VL servers */
147 };
148
149 /*
150 * AFS cell record
151 */
152 struct afs_cell {
153 atomic_t usage;
154 struct list_head link; /* main cell list link */
155 struct key *anonymous_key; /* anonymous user key for this cell */
156 struct list_head proc_link; /* /proc cell list link */
157 struct proc_dir_entry *proc_dir; /* /proc dir for this cell */
158 #ifdef AFS_CACHING_SUPPORT
159 struct cachefs_cookie *cache; /* caching cookie */
160 #endif
161
162 /* server record management */
163 rwlock_t servers_lock; /* active server list lock */
164 struct list_head servers; /* active server list */
165
166 /* volume location record management */
167 struct rw_semaphore vl_sem; /* volume management serialisation semaphore */
168 struct list_head vl_list; /* cell's active VL record list */
169 spinlock_t vl_lock; /* vl_list lock */
170 unsigned short vl_naddrs; /* number of VL servers in addr list */
171 unsigned short vl_curr_svix; /* current server index */
172 struct in_addr vl_addrs[AFS_CELL_MAX_ADDRS]; /* cell VL server addresses */
173
174 char name[0]; /* cell name - must go last */
175 };
176
177 /*
178 * entry in the cached volume location catalogue
179 */
180 struct afs_cache_vlocation {
181 /* volume name (lowercase, padded with NULs) */
182 uint8_t name[AFS_MAXVOLNAME + 1];
183
184 uint8_t nservers; /* number of entries used in servers[] */
185 uint8_t vidmask; /* voltype mask for vid[] */
186 uint8_t srvtmask[8]; /* voltype masks for servers[] */
187 #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
188 #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
189 #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
190
191 afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */
192 struct in_addr servers[8]; /* fileserver addresses */
193 time_t rtime; /* last retrieval time */
194 };
195
196 /*
197 * volume -> vnode hash table entry
198 */
199 struct afs_cache_vhash {
200 afs_voltype_t vtype; /* which volume variation */
201 uint8_t hash_bucket; /* which hash bucket this represents */
202 } __attribute__((packed));
203
204 /*
205 * AFS volume location record
206 */
207 struct afs_vlocation {
208 atomic_t usage;
209 time_t time_of_death; /* time at which put reduced usage to 0 */
210 struct list_head link; /* link in cell volume location list */
211 struct list_head grave; /* link in master graveyard list */
212 struct list_head update; /* link in master update list */
213 struct afs_cell *cell; /* cell to which volume belongs */
214 #ifdef AFS_CACHING_SUPPORT
215 struct cachefs_cookie *cache; /* caching cookie */
216 #endif
217 struct afs_cache_vlocation vldb; /* volume information DB record */
218 struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
219 wait_queue_head_t waitq; /* status change waitqueue */
220 time_t update_at; /* time at which record should be updated */
221 rwlock_t lock; /* access lock */
222 afs_vlocation_state_t state; /* volume location state */
223 unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */
224 unsigned short upd_busy_cnt; /* EBUSY count during update */
225 bool valid; /* T if valid */
226 };
227
228 /*
229 * AFS fileserver record
230 */
231 struct afs_server {
232 atomic_t usage;
233 time_t time_of_death; /* time at which put reduced usage to 0 */
234 struct in_addr addr; /* server address */
235 struct afs_cell *cell; /* cell in which server resides */
236 struct list_head link; /* link in cell's server list */
237 struct list_head grave; /* link in master graveyard list */
238 struct rb_node master_rb; /* link in master by-addr tree */
239 struct rw_semaphore sem; /* access lock */
240
241 /* file service access */
242 struct rb_root fs_vnodes; /* vnodes backed by this server (ordered by FID) */
243 unsigned long fs_act_jif; /* time at which last activity occurred */
244 unsigned long fs_dead_jif; /* time at which no longer to be considered dead */
245 spinlock_t fs_lock; /* access lock */
246 int fs_state; /* 0 or reason FS currently marked dead (-errno) */
247
248 /* callback promise management */
249 struct rb_root cb_promises; /* vnode expiration list (ordered earliest first) */
250 struct delayed_work cb_updater; /* callback updater */
251 struct delayed_work cb_break_work; /* collected break dispatcher */
252 wait_queue_head_t cb_break_waitq; /* space available in cb_break waitqueue */
253 spinlock_t cb_lock; /* access lock */
254 struct afs_callback cb_break[64]; /* ring of callbacks awaiting breaking */
255 atomic_t cb_break_n; /* number of pending breaks */
256 u8 cb_break_head; /* head of callback breaking ring */
257 u8 cb_break_tail; /* tail of callback breaking ring */
258 };
259
260 /*
261 * AFS volume access record
262 */
263 struct afs_volume {
264 atomic_t usage;
265 struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */
266 struct afs_vlocation *vlocation; /* volume location */
267 #ifdef AFS_CACHING_SUPPORT
268 struct cachefs_cookie *cache; /* caching cookie */
269 #endif
270 afs_volid_t vid; /* volume ID */
271 afs_voltype_t type; /* type of volume */
272 char type_force; /* force volume type (suppress R/O -> R/W) */
273 unsigned short nservers; /* number of server slots filled */
274 unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */
275 struct afs_server *servers[8]; /* servers on which volume resides (ordered) */
276 struct rw_semaphore server_sem; /* lock for accessing current server */
277 };
278
279 /*
280 * vnode catalogue entry
281 */
282 struct afs_cache_vnode {
283 afs_vnodeid_t vnode_id; /* vnode ID */
284 unsigned vnode_unique; /* vnode ID uniquifier */
285 afs_dataversion_t data_version; /* data version */
286 };
287
288 /*
289 * AFS inode private data
290 */
291 struct afs_vnode {
292 struct inode vfs_inode; /* the VFS's inode record */
293
294 struct afs_volume *volume; /* volume on which vnode resides */
295 struct afs_server *server; /* server currently supplying this file */
296 struct afs_fid fid; /* the file identifier for this inode */
297 struct afs_file_status status; /* AFS status info for this file */
298 #ifdef AFS_CACHING_SUPPORT
299 struct cachefs_cookie *cache; /* caching cookie */
300 #endif
301 struct afs_permits *permits; /* cache of permits so far obtained */
302 struct mutex permits_lock; /* lock for altering permits list */
303 wait_queue_head_t update_waitq; /* status fetch waitqueue */
304 unsigned update_cnt; /* number of outstanding ops that will update the
305 * status */
306 spinlock_t lock; /* waitqueue/flags lock */
307 unsigned long flags;
308 #define AFS_VNODE_CB_BROKEN 0 /* set if vnode's callback was broken */
309 #define AFS_VNODE_CHANGED 1 /* set if vnode's metadata changed */
310 #define AFS_VNODE_MODIFIED 2 /* set if vnode's data modified */
311 #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
312 #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
313 #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
314 #define AFS_VNODE_DIR_CHANGED 6 /* set if vnode's parent dir metadata changed */
315 #define AFS_VNODE_DIR_MODIFIED 7 /* set if vnode's parent dir data modified */
316
317 long acl_order; /* ACL check count (callback break count) */
318
319 /* outstanding callback notification on this file */
320 struct rb_node server_rb; /* link in server->fs_vnodes */
321 struct rb_node cb_promise; /* link in server->cb_promises */
322 struct work_struct cb_broken_work; /* work to be done on callback break */
323 struct mutex cb_broken_lock; /* lock against multiple attempts to fix break */
324 time_t cb_expires; /* time at which callback expires */
325 time_t cb_expires_at; /* time used to order cb_promise */
326 unsigned cb_version; /* callback version */
327 unsigned cb_expiry; /* callback expiry time */
328 afs_callback_type_t cb_type; /* type of callback */
329 bool cb_promised; /* true if promise still holds */
330 };
331
332 /*
333 * cached security record for one user's attempt to access a vnode
334 */
335 struct afs_permit {
336 struct key *key; /* RxRPC ticket holding a security context */
337 afs_access_t access_mask; /* access mask for this key */
338 };
339
340 /*
341 * cache of security records from attempts to access a vnode
342 */
343 struct afs_permits {
344 struct rcu_head rcu; /* disposal procedure */
345 int count; /* number of records */
346 struct afs_permit permits[0]; /* the permits so far examined */
347 };
348
349 /*****************************************************************************/
350 /*
351 * callback.c
352 */
353 extern void afs_init_callback_state(struct afs_server *);
354 extern void afs_broken_callback_work(struct work_struct *);
355 extern void afs_break_callbacks(struct afs_server *, size_t,
356 struct afs_callback[]);
357 extern void afs_give_up_callback(struct afs_vnode *);
358 extern void afs_dispatch_give_up_callbacks(struct work_struct *);
359 extern void afs_flush_callback_breaks(struct afs_server *);
360 extern int __init afs_callback_update_init(void);
361 extern void __exit afs_callback_update_kill(void);
362
363 /*
364 * cell.c
365 */
366 extern struct rw_semaphore afs_proc_cells_sem;
367 extern struct list_head afs_proc_cells;
368 #ifdef AFS_CACHING_SUPPORT
369 extern struct cachefs_index_def afs_cache_cell_index_def;
370 #endif
371
372 #define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0)
373 extern int afs_cell_init(char *);
374 extern struct afs_cell *afs_cell_create(const char *, char *);
375 extern struct afs_cell *afs_cell_lookup(const char *, unsigned);
376 extern struct afs_cell *afs_grab_cell(struct afs_cell *);
377 extern void afs_put_cell(struct afs_cell *);
378 extern void afs_cell_purge(void);
379
380 /*
381 * cmservice.c
382 */
383 extern bool afs_cm_incoming_call(struct afs_call *);
384
385 /*
386 * dir.c
387 */
388 extern const struct inode_operations afs_dir_inode_operations;
389 extern const struct file_operations afs_dir_file_operations;
390
391 extern int afs_permission(struct inode *, int, struct nameidata *);
392
393 /*
394 * file.c
395 */
396 extern const struct address_space_operations afs_fs_aops;
397 extern const struct inode_operations afs_file_inode_operations;
398 extern const struct file_operations afs_file_operations;
399
400 extern int afs_open(struct inode *, struct file *);
401 extern int afs_release(struct inode *, struct file *);
402
403 #ifdef AFS_CACHING_SUPPORT
404 extern int afs_cache_get_page_cookie(struct page *, struct cachefs_page **);
405 #endif
406
407 /*
408 * fsclient.c
409 */
410 extern int afs_fs_fetch_file_status(struct afs_server *, struct key *,
411 struct afs_vnode *, struct afs_volsync *,
412 const struct afs_wait_mode *);
413 extern int afs_fs_give_up_callbacks(struct afs_server *,
414 const struct afs_wait_mode *);
415 extern int afs_fs_fetch_data(struct afs_server *, struct key *,
416 struct afs_vnode *, off_t, size_t, struct page *,
417 struct afs_volsync *,
418 const struct afs_wait_mode *);
419
420 /*
421 * inode.c
422 */
423 extern struct inode *afs_iget(struct super_block *, struct key *,
424 struct afs_fid *);
425 extern int afs_inode_getattr(struct vfsmount *, struct dentry *,
426 struct kstat *);
427 extern void afs_zap_permits(struct rcu_head *);
428 extern void afs_clear_inode(struct inode *);
429
430 /*
431 * main.c
432 */
433 #ifdef AFS_CACHING_SUPPORT
434 extern struct cachefs_netfs afs_cache_netfs;
435 #endif
436
437 /*
438 * misc.c
439 */
440 extern int afs_abort_to_error(u32);
441
442 /*
443 * mntpt.c
444 */
445 extern const struct inode_operations afs_mntpt_inode_operations;
446 extern const struct file_operations afs_mntpt_file_operations;
447 extern unsigned long afs_mntpt_expiry_timeout;
448
449 extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *);
450 extern void afs_mntpt_kill_timer(void);
451 extern void afs_umount_begin(struct vfsmount *, int);
452
453 /*
454 * proc.c
455 */
456 extern int afs_proc_init(void);
457 extern void afs_proc_cleanup(void);
458 extern int afs_proc_cell_setup(struct afs_cell *);
459 extern void afs_proc_cell_remove(struct afs_cell *);
460
461 /*
462 * rxrpc.c
463 */
464 extern int afs_open_socket(void);
465 extern void afs_close_socket(void);
466 extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t,
467 const struct afs_wait_mode *);
468 extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *,
469 size_t, size_t);
470 extern void afs_flat_call_destructor(struct afs_call *);
471 extern void afs_transfer_reply(struct afs_call *, struct sk_buff *);
472 extern void afs_send_empty_reply(struct afs_call *);
473 extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *,
474 size_t);
475
476 /*
477 * security.c
478 */
479 extern void afs_clear_permits(struct afs_vnode *);
480 extern void afs_cache_permit(struct afs_vnode *, struct key *, long);
481 extern struct key *afs_request_key(struct afs_cell *);
482 extern int afs_permission(struct inode *, int, struct nameidata *);
483
484 /*
485 * server.c
486 */
487 extern spinlock_t afs_server_peer_lock;
488
489 #define afs_get_server(S) do { atomic_inc(&(S)->usage); } while(0)
490
491 extern struct afs_server *afs_lookup_server(struct afs_cell *,
492 const struct in_addr *);
493 extern struct afs_server *afs_find_server(const struct in_addr *);
494 extern void afs_put_server(struct afs_server *);
495 extern void __exit afs_purge_servers(void);
496
497 /*
498 * super.c
499 */
500 extern int afs_fs_init(void);
501 extern void afs_fs_exit(void);
502
503 /*
504 * vlclient.c
505 */
506 #ifdef AFS_CACHING_SUPPORT
507 extern struct cachefs_index_def afs_vlocation_cache_index_def;
508 #endif
509
510 extern int afs_vl_get_entry_by_name(struct in_addr *, struct key *,
511 const char *, struct afs_cache_vlocation *,
512 const struct afs_wait_mode *);
513 extern int afs_vl_get_entry_by_id(struct in_addr *, struct key *,
514 afs_volid_t, afs_voltype_t,
515 struct afs_cache_vlocation *,
516 const struct afs_wait_mode *);
517
518 /*
519 * vlocation.c
520 */
521 #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
522
523 extern int __init afs_vlocation_update_init(void);
524 extern struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *,
525 struct key *,
526 const char *, size_t);
527 extern void afs_put_vlocation(struct afs_vlocation *);
528 extern void __exit afs_vlocation_purge(void);
529
530 /*
531 * vnode.c
532 */
533 #ifdef AFS_CACHING_SUPPORT
534 extern struct cachefs_index_def afs_vnode_cache_index_def;
535 #endif
536
537 extern struct afs_timer_ops afs_vnode_cb_timed_out_ops;
538
539 static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
540 {
541 return container_of(inode, struct afs_vnode, vfs_inode);
542 }
543
544 static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
545 {
546 return &vnode->vfs_inode;
547 }
548
549 extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *,
550 struct key *);
551 extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *,
552 off_t, size_t, struct page *);
553
554 /*
555 * volume.c
556 */
557 #ifdef AFS_CACHING_SUPPORT
558 extern struct cachefs_index_def afs_volume_cache_index_def;
559 #endif
560
561 #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
562
563 extern void afs_put_volume(struct afs_volume *);
564 extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *);
565 extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *);
566 extern int afs_volume_release_fileserver(struct afs_vnode *,
567 struct afs_server *, int);
568
569 /*****************************************************************************/
570 /*
571 * debug tracing
572 */
573 extern unsigned afs_debug;
574
575 #define dbgprintk(FMT,...) \
576 printk("[%x%-6.6s] "FMT"\n", smp_processor_id(), current->comm ,##__VA_ARGS__)
577
578 /* make sure we maintain the format strings, even when debugging is disabled */
579 static inline __attribute__((format(printf,1,2)))
580 void _dbprintk(const char *fmt, ...)
581 {
582 }
583
584 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
585 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
586 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
587
588
589 #if defined(__KDEBUG)
590 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
591 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
592 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
593
594 #elif defined(CONFIG_AFS_DEBUG)
595 #define AFS_DEBUG_KENTER 0x01
596 #define AFS_DEBUG_KLEAVE 0x02
597 #define AFS_DEBUG_KDEBUG 0x04
598
599 #define _enter(FMT,...) \
600 do { \
601 if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
602 kenter(FMT,##__VA_ARGS__); \
603 } while (0)
604
605 #define _leave(FMT,...) \
606 do { \
607 if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
608 kleave(FMT,##__VA_ARGS__); \
609 } while (0)
610
611 #define _debug(FMT,...) \
612 do { \
613 if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
614 kdebug(FMT,##__VA_ARGS__); \
615 } while (0)
616
617 #else
618 #define _enter(FMT,...) _dbprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
619 #define _leave(FMT,...) _dbprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
620 #define _debug(FMT,...) _dbprintk(" "FMT ,##__VA_ARGS__)
621 #endif
622
623 /*
624 * debug assertion checking
625 */
626 #if 1 // defined(__KDEBUGALL)
627
628 #define ASSERT(X) \
629 do { \
630 if (unlikely(!(X))) { \
631 printk(KERN_ERR "\n"); \
632 printk(KERN_ERR "AFS: Assertion failed\n"); \
633 BUG(); \
634 } \
635 } while(0)
636
637 #define ASSERTCMP(X, OP, Y) \
638 do { \
639 if (unlikely(!((X) OP (Y)))) { \
640 printk(KERN_ERR "\n"); \
641 printk(KERN_ERR "AFS: Assertion failed\n"); \
642 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
643 (unsigned long)(X), (unsigned long)(Y)); \
644 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
645 (unsigned long)(X), (unsigned long)(Y)); \
646 BUG(); \
647 } \
648 } while(0)
649
650 #define ASSERTIF(C, X) \
651 do { \
652 if (unlikely((C) && !(X))) { \
653 printk(KERN_ERR "\n"); \
654 printk(KERN_ERR "AFS: Assertion failed\n"); \
655 BUG(); \
656 } \
657 } while(0)
658
659 #define ASSERTIFCMP(C, X, OP, Y) \
660 do { \
661 if (unlikely((C) && !((X) OP (Y)))) { \
662 printk(KERN_ERR "\n"); \
663 printk(KERN_ERR "AFS: Assertion failed\n"); \
664 printk(KERN_ERR "%lu " #OP " %lu is false\n", \
665 (unsigned long)(X), (unsigned long)(Y)); \
666 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
667 (unsigned long)(X), (unsigned long)(Y)); \
668 BUG(); \
669 } \
670 } while(0)
671
672 #else
673
674 #define ASSERT(X) \
675 do { \
676 } while(0)
677
678 #define ASSERTCMP(X, OP, Y) \
679 do { \
680 } while(0)
681
682 #define ASSERTIF(C, X) \
683 do { \
684 } while(0)
685
686 #define ASSERTIFCMP(C, X, OP, Y) \
687 do { \
688 } while(0)
689
690 #endif /* __KDEBUGALL */