internal.h 20 KB

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