internal.h 22 KB

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