internal.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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 <linux/workqueue.h>
  19. #include <linux/sched.h>
  20. #include "afs.h"
  21. #include "afs_vl.h"
  22. #define AFS_CELL_MAX_ADDRS 15
  23. struct pagevec;
  24. struct afs_call;
  25. typedef enum {
  26. AFS_VL_NEW, /* new, uninitialised record */
  27. AFS_VL_CREATING, /* creating record */
  28. AFS_VL_VALID, /* record is pending */
  29. AFS_VL_NO_VOLUME, /* no such volume available */
  30. AFS_VL_UPDATING, /* update in progress */
  31. AFS_VL_VOLUME_DELETED, /* volume was deleted */
  32. AFS_VL_UNCERTAIN, /* uncertain state (update failed) */
  33. } __attribute__((packed)) afs_vlocation_state_t;
  34. struct afs_mount_params {
  35. bool rwpath; /* T if the parent should be considered R/W */
  36. bool force; /* T to force cell type */
  37. afs_voltype_t type; /* type of volume requested */
  38. int volnamesz; /* size of volume name */
  39. const char *volname; /* name of volume to mount */
  40. struct afs_cell *cell; /* cell in which to find volume */
  41. struct afs_volume *volume; /* volume record */
  42. struct key *key; /* key to use for secure mounting */
  43. };
  44. /*
  45. * definition of how to wait for the completion of an operation
  46. */
  47. struct afs_wait_mode {
  48. /* RxRPC received message notification */
  49. void (*rx_wakeup)(struct afs_call *call);
  50. /* synchronous call waiter and call dispatched notification */
  51. int (*wait)(struct afs_call *call);
  52. /* asynchronous call completion */
  53. void (*async_complete)(void *reply, int error);
  54. };
  55. extern const struct afs_wait_mode afs_sync_call;
  56. extern const struct afs_wait_mode afs_async_call;
  57. /*
  58. * a record of an in-progress RxRPC call
  59. */
  60. struct afs_call {
  61. const struct afs_call_type *type; /* type of call */
  62. const struct afs_wait_mode *wait_mode; /* completion wait mode */
  63. wait_queue_head_t waitq; /* processes awaiting completion */
  64. struct work_struct async_work; /* asynchronous work processor */
  65. struct work_struct work; /* actual work processor */
  66. struct sk_buff_head rx_queue; /* received packets */
  67. struct rxrpc_call *rxcall; /* RxRPC call handle */
  68. struct key *key; /* security for this call */
  69. struct afs_server *server; /* server affected by incoming CM call */
  70. void *request; /* request data (first part) */
  71. struct address_space *mapping; /* page set */
  72. struct afs_writeback *wb; /* writeback being performed */
  73. void *buffer; /* reply receive buffer */
  74. void *reply; /* reply buffer (first part) */
  75. void *reply2; /* reply buffer (second part) */
  76. void *reply3; /* reply buffer (third part) */
  77. void *reply4; /* reply buffer (fourth part) */
  78. pgoff_t first; /* first page in mapping to deal with */
  79. pgoff_t last; /* last page in mapping to deal with */
  80. enum { /* call state */
  81. AFS_CALL_REQUESTING, /* request is being sent for outgoing call */
  82. AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */
  83. AFS_CALL_AWAIT_OP_ID, /* awaiting op ID on incoming call */
  84. AFS_CALL_AWAIT_REQUEST, /* awaiting request data on incoming call */
  85. AFS_CALL_REPLYING, /* replying to incoming call */
  86. AFS_CALL_AWAIT_ACK, /* awaiting final ACK of incoming call */
  87. AFS_CALL_COMPLETE, /* successfully completed */
  88. AFS_CALL_BUSY, /* server was busy */
  89. AFS_CALL_ABORTED, /* call was aborted */
  90. AFS_CALL_ERROR, /* call failed due to error */
  91. } state;
  92. int error; /* error code */
  93. unsigned request_size; /* size of request data */
  94. unsigned reply_max; /* maximum size of reply */
  95. unsigned reply_size; /* current size of reply */
  96. unsigned first_offset; /* offset into mapping[first] */
  97. unsigned last_to; /* amount of mapping[last] */
  98. unsigned short offset; /* offset into received data store */
  99. unsigned char unmarshall; /* unmarshalling phase */
  100. bool incoming; /* T if incoming call */
  101. bool send_pages; /* T if data from mapping should be sent */
  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. afs_dataversion_t store_version; /* updated version expected from store */
  108. };
  109. struct afs_call_type {
  110. const char *name;
  111. /* deliver request or reply data to an call
  112. * - returning an error will cause the call to be aborted
  113. */
  114. int (*deliver)(struct afs_call *call, struct sk_buff *skb,
  115. bool last);
  116. /* map an abort code to an error number */
  117. int (*abort_to_error)(u32 abort_code);
  118. /* clean up a call */
  119. void (*destructor)(struct afs_call *call);
  120. };
  121. /*
  122. * record of an outstanding writeback on a vnode
  123. */
  124. struct afs_writeback {
  125. struct list_head link; /* link in vnode->writebacks */
  126. struct work_struct writer; /* work item to perform the writeback */
  127. struct afs_vnode *vnode; /* vnode to which this write applies */
  128. struct key *key; /* owner of this write */
  129. wait_queue_head_t waitq; /* completion and ready wait queue */
  130. pgoff_t first; /* first page in batch */
  131. pgoff_t point; /* last page in current store op */
  132. pgoff_t last; /* last page in batch (inclusive) */
  133. unsigned offset_first; /* offset into first page of start of write */
  134. unsigned to_last; /* offset into last page of end of write */
  135. int num_conflicts; /* count of conflicting writes in list */
  136. int usage;
  137. bool conflicts; /* T if has dependent conflicts */
  138. enum {
  139. AFS_WBACK_SYNCING, /* synchronisation being performed */
  140. AFS_WBACK_PENDING, /* write pending */
  141. AFS_WBACK_CONFLICTING, /* conflicting writes posted */
  142. AFS_WBACK_WRITING, /* writing back */
  143. AFS_WBACK_COMPLETE /* the writeback record has been unlinked */
  144. } state __attribute__((packed));
  145. };
  146. /*
  147. * AFS superblock private data
  148. * - there's one superblock per volume
  149. */
  150. struct afs_super_info {
  151. struct afs_volume *volume; /* volume record */
  152. char rwparent; /* T if parent is R/W AFS volume */
  153. };
  154. static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
  155. {
  156. return sb->s_fs_info;
  157. }
  158. extern struct file_system_type afs_fs_type;
  159. /*
  160. * entry in the cached cell catalogue
  161. */
  162. struct afs_cache_cell {
  163. char name[AFS_MAXCELLNAME]; /* cell name (padded with NULs) */
  164. struct in_addr vl_servers[15]; /* cached cell VL servers */
  165. };
  166. /*
  167. * AFS cell record
  168. */
  169. struct afs_cell {
  170. atomic_t usage;
  171. struct list_head link; /* main cell list link */
  172. struct key *anonymous_key; /* anonymous user key for this cell */
  173. struct list_head proc_link; /* /proc cell list link */
  174. struct proc_dir_entry *proc_dir; /* /proc dir for this cell */
  175. #ifdef AFS_CACHING_SUPPORT
  176. struct cachefs_cookie *cache; /* caching cookie */
  177. #endif
  178. /* server record management */
  179. rwlock_t servers_lock; /* active server list lock */
  180. struct list_head servers; /* active server list */
  181. /* volume location record management */
  182. struct rw_semaphore vl_sem; /* volume management serialisation semaphore */
  183. struct list_head vl_list; /* cell's active VL record list */
  184. spinlock_t vl_lock; /* vl_list lock */
  185. unsigned short vl_naddrs; /* number of VL servers in addr list */
  186. unsigned short vl_curr_svix; /* current server index */
  187. struct in_addr vl_addrs[AFS_CELL_MAX_ADDRS]; /* cell VL server addresses */
  188. char name[0]; /* cell name - must go last */
  189. };
  190. /*
  191. * entry in the cached volume location catalogue
  192. */
  193. struct afs_cache_vlocation {
  194. /* volume name (lowercase, padded with NULs) */
  195. uint8_t name[AFS_MAXVOLNAME + 1];
  196. uint8_t nservers; /* number of entries used in servers[] */
  197. uint8_t vidmask; /* voltype mask for vid[] */
  198. uint8_t srvtmask[8]; /* voltype masks for servers[] */
  199. #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
  200. #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
  201. #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
  202. afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */
  203. struct in_addr servers[8]; /* fileserver addresses */
  204. time_t rtime; /* last retrieval time */
  205. };
  206. /*
  207. * volume -> vnode hash table entry
  208. */
  209. struct afs_cache_vhash {
  210. afs_voltype_t vtype; /* which volume variation */
  211. uint8_t hash_bucket; /* which hash bucket this represents */
  212. } __attribute__((packed));
  213. /*
  214. * AFS volume location record
  215. */
  216. struct afs_vlocation {
  217. atomic_t usage;
  218. time_t time_of_death; /* time at which put reduced usage to 0 */
  219. struct list_head link; /* link in cell volume location list */
  220. struct list_head grave; /* link in master graveyard list */
  221. struct list_head update; /* link in master update list */
  222. struct afs_cell *cell; /* cell to which volume belongs */
  223. #ifdef AFS_CACHING_SUPPORT
  224. struct cachefs_cookie *cache; /* caching cookie */
  225. #endif
  226. struct afs_cache_vlocation vldb; /* volume information DB record */
  227. struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
  228. wait_queue_head_t waitq; /* status change waitqueue */
  229. time_t update_at; /* time at which record should be updated */
  230. spinlock_t lock; /* access lock */
  231. afs_vlocation_state_t state; /* volume location state */
  232. unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */
  233. unsigned short upd_busy_cnt; /* EBUSY count during update */
  234. bool valid; /* T if valid */
  235. };
  236. /*
  237. * AFS fileserver record
  238. */
  239. struct afs_server {
  240. atomic_t usage;
  241. time_t time_of_death; /* time at which put reduced usage to 0 */
  242. struct in_addr addr; /* server address */
  243. struct afs_cell *cell; /* cell in which server resides */
  244. struct list_head link; /* link in cell's server list */
  245. struct list_head grave; /* link in master graveyard list */
  246. struct rb_node master_rb; /* link in master by-addr tree */
  247. struct rw_semaphore sem; /* access lock */
  248. /* file service access */
  249. struct rb_root fs_vnodes; /* vnodes backed by this server (ordered by FID) */
  250. unsigned long fs_act_jif; /* time at which last activity occurred */
  251. unsigned long fs_dead_jif; /* time at which no longer to be considered dead */
  252. spinlock_t fs_lock; /* access lock */
  253. int fs_state; /* 0 or reason FS currently marked dead (-errno) */
  254. /* callback promise management */
  255. struct rb_root cb_promises; /* vnode expiration list (ordered earliest first) */
  256. struct delayed_work cb_updater; /* callback updater */
  257. struct delayed_work cb_break_work; /* collected break dispatcher */
  258. wait_queue_head_t cb_break_waitq; /* space available in cb_break waitqueue */
  259. spinlock_t cb_lock; /* access lock */
  260. struct afs_callback cb_break[64]; /* ring of callbacks awaiting breaking */
  261. atomic_t cb_break_n; /* number of pending breaks */
  262. u8 cb_break_head; /* head of callback breaking ring */
  263. u8 cb_break_tail; /* tail of callback breaking ring */
  264. };
  265. /*
  266. * AFS volume access record
  267. */
  268. struct afs_volume {
  269. atomic_t usage;
  270. struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */
  271. struct afs_vlocation *vlocation; /* volume location */
  272. #ifdef AFS_CACHING_SUPPORT
  273. struct cachefs_cookie *cache; /* caching cookie */
  274. #endif
  275. afs_volid_t vid; /* volume ID */
  276. afs_voltype_t type; /* type of volume */
  277. char type_force; /* force volume type (suppress R/O -> R/W) */
  278. unsigned short nservers; /* number of server slots filled */
  279. unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */
  280. struct afs_server *servers[8]; /* servers on which volume resides (ordered) */
  281. struct rw_semaphore server_sem; /* lock for accessing current server */
  282. };
  283. /*
  284. * vnode catalogue entry
  285. */
  286. struct afs_cache_vnode {
  287. afs_vnodeid_t vnode_id; /* vnode ID */
  288. unsigned vnode_unique; /* vnode ID uniquifier */
  289. afs_dataversion_t data_version; /* data version */
  290. };
  291. /*
  292. * AFS inode private data
  293. */
  294. struct afs_vnode {
  295. struct inode vfs_inode; /* the VFS's inode record */
  296. struct afs_volume *volume; /* volume on which vnode resides */
  297. struct afs_server *server; /* server currently supplying this file */
  298. struct afs_fid fid; /* the file identifier for this inode */
  299. struct afs_file_status status; /* AFS status info for this file */
  300. #ifdef AFS_CACHING_SUPPORT
  301. struct cachefs_cookie *cache; /* caching cookie */
  302. #endif
  303. struct afs_permits *permits; /* cache of permits so far obtained */
  304. struct mutex permits_lock; /* lock for altering permits list */
  305. struct mutex validate_lock; /* lock for validating this vnode */
  306. wait_queue_head_t update_waitq; /* status fetch waitqueue */
  307. int update_cnt; /* number of outstanding ops that will update the
  308. * status */
  309. spinlock_t writeback_lock; /* lock for writebacks */
  310. spinlock_t lock; /* waitqueue/flags lock */
  311. unsigned long flags;
  312. #define AFS_VNODE_CB_BROKEN 0 /* set if vnode's callback was broken */
  313. #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
  314. #define AFS_VNODE_MODIFIED 2 /* set if vnode's data modified */
  315. #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
  316. #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
  317. #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
  318. long acl_order; /* ACL check count (callback break count) */
  319. struct list_head writebacks; /* alterations in pagecache that need writing */
  320. /* outstanding callback notification on this file */
  321. struct rb_node server_rb; /* link in server->fs_vnodes */
  322. struct rb_node cb_promise; /* link in server->cb_promises */
  323. struct work_struct cb_broken_work; /* work to be done on callback 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. * cached security record for one user's attempt to access a vnode
  333. */
  334. struct afs_permit {
  335. struct key *key; /* RxRPC ticket holding a security context */
  336. afs_access_t access_mask; /* access mask for this key */
  337. };
  338. /*
  339. * cache of security records from attempts to access a vnode
  340. */
  341. struct afs_permits {
  342. struct rcu_head rcu; /* disposal procedure */
  343. int count; /* number of records */
  344. struct afs_permit permits[0]; /* the permits so far examined */
  345. };
  346. /*
  347. * record of one of a system's set of network interfaces
  348. */
  349. struct afs_interface {
  350. struct in_addr address; /* IPv4 address bound to interface */
  351. struct in_addr netmask; /* netmask applied to address */
  352. unsigned mtu; /* MTU of interface */
  353. };
  354. /*
  355. * UUID definition [internet draft]
  356. * - the timestamp is a 60-bit value, split 32/16/12, and goes in 100ns
  357. * increments since midnight 15th October 1582
  358. * - add AFS_UUID_TO_UNIX_TIME to convert unix time in 100ns units to UUID
  359. * time
  360. * - the clock sequence is a 14-bit counter to avoid duplicate times
  361. */
  362. struct afs_uuid {
  363. u32 time_low; /* low part of timestamp */
  364. u16 time_mid; /* mid part of timestamp */
  365. u16 time_hi_and_version; /* high part of timestamp and version */
  366. #define AFS_UUID_TO_UNIX_TIME 0x01b21dd213814000ULL
  367. #define AFS_UUID_TIMEHI_MASK 0x0fff
  368. #define AFS_UUID_VERSION_TIME 0x1000 /* time-based UUID */
  369. #define AFS_UUID_VERSION_NAME 0x3000 /* name-based UUID */
  370. #define AFS_UUID_VERSION_RANDOM 0x4000 /* (pseudo-)random generated UUID */
  371. u8 clock_seq_hi_and_reserved; /* clock seq hi and variant */
  372. #define AFS_UUID_CLOCKHI_MASK 0x3f
  373. #define AFS_UUID_VARIANT_STD 0x80
  374. u8 clock_seq_low; /* clock seq low */
  375. u8 node[6]; /* spatially unique node ID (MAC addr) */
  376. };
  377. /*****************************************************************************/
  378. /*
  379. * callback.c
  380. */
  381. extern void afs_init_callback_state(struct afs_server *);
  382. extern void afs_broken_callback_work(struct work_struct *);
  383. extern void afs_break_callbacks(struct afs_server *, size_t,
  384. struct afs_callback[]);
  385. extern void afs_discard_callback_on_delete(struct afs_vnode *);
  386. extern void afs_give_up_callback(struct afs_vnode *);
  387. extern void afs_dispatch_give_up_callbacks(struct work_struct *);
  388. extern void afs_flush_callback_breaks(struct afs_server *);
  389. extern int __init afs_callback_update_init(void);
  390. extern void afs_callback_update_kill(void);
  391. /*
  392. * cell.c
  393. */
  394. extern struct rw_semaphore afs_proc_cells_sem;
  395. extern struct list_head afs_proc_cells;
  396. #ifdef AFS_CACHING_SUPPORT
  397. extern struct cachefs_index_def afs_cache_cell_index_def;
  398. #endif
  399. #define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0)
  400. extern int afs_cell_init(char *);
  401. extern struct afs_cell *afs_cell_create(const char *, char *);
  402. extern struct afs_cell *afs_cell_lookup(const char *, unsigned);
  403. extern struct afs_cell *afs_grab_cell(struct afs_cell *);
  404. extern void afs_put_cell(struct afs_cell *);
  405. extern void afs_cell_purge(void);
  406. /*
  407. * cmservice.c
  408. */
  409. extern bool afs_cm_incoming_call(struct afs_call *);
  410. /*
  411. * dir.c
  412. */
  413. extern const struct inode_operations afs_dir_inode_operations;
  414. extern const struct file_operations afs_dir_file_operations;
  415. extern int afs_permission(struct inode *, int, struct nameidata *);
  416. /*
  417. * file.c
  418. */
  419. extern const struct address_space_operations afs_fs_aops;
  420. extern const struct inode_operations afs_file_inode_operations;
  421. extern const struct file_operations afs_file_operations;
  422. extern int afs_open(struct inode *, struct file *);
  423. extern int afs_release(struct inode *, struct file *);
  424. /*
  425. * fsclient.c
  426. */
  427. extern int afs_fs_fetch_file_status(struct afs_server *, struct key *,
  428. struct afs_vnode *, struct afs_volsync *,
  429. const struct afs_wait_mode *);
  430. extern int afs_fs_give_up_callbacks(struct afs_server *,
  431. const struct afs_wait_mode *);
  432. extern int afs_fs_fetch_data(struct afs_server *, struct key *,
  433. struct afs_vnode *, off_t, size_t, struct page *,
  434. const struct afs_wait_mode *);
  435. extern int afs_fs_create(struct afs_server *, struct key *,
  436. struct afs_vnode *, const char *, umode_t,
  437. struct afs_fid *, struct afs_file_status *,
  438. struct afs_callback *,
  439. const struct afs_wait_mode *);
  440. extern int afs_fs_remove(struct afs_server *, struct key *,
  441. struct afs_vnode *, const char *, bool,
  442. const struct afs_wait_mode *);
  443. extern int afs_fs_link(struct afs_server *, struct key *, struct afs_vnode *,
  444. struct afs_vnode *, const char *,
  445. const struct afs_wait_mode *);
  446. extern int afs_fs_symlink(struct afs_server *, struct key *,
  447. struct afs_vnode *, const char *, const char *,
  448. struct afs_fid *, struct afs_file_status *,
  449. const struct afs_wait_mode *);
  450. extern int afs_fs_rename(struct afs_server *, struct key *,
  451. struct afs_vnode *, const char *,
  452. struct afs_vnode *, const char *,
  453. const struct afs_wait_mode *);
  454. extern int afs_fs_store_data(struct afs_server *, struct afs_writeback *,
  455. pgoff_t, pgoff_t, unsigned, unsigned,
  456. const struct afs_wait_mode *);
  457. extern int afs_fs_setattr(struct afs_server *, struct key *,
  458. struct afs_vnode *, struct iattr *,
  459. const struct afs_wait_mode *);
  460. extern int afs_fs_get_volume_status(struct afs_server *, struct key *,
  461. struct afs_vnode *,
  462. struct afs_volume_status *,
  463. const struct afs_wait_mode *);
  464. /*
  465. * inode.c
  466. */
  467. extern struct inode *afs_iget(struct super_block *, struct key *,
  468. struct afs_fid *, struct afs_file_status *,
  469. struct afs_callback *);
  470. extern void afs_zap_data(struct afs_vnode *);
  471. extern int afs_validate(struct afs_vnode *, struct key *);
  472. extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  473. extern int afs_setattr(struct dentry *, struct iattr *);
  474. extern void afs_clear_inode(struct inode *);
  475. /*
  476. * main.c
  477. */
  478. extern struct afs_uuid afs_uuid;
  479. #ifdef AFS_CACHING_SUPPORT
  480. extern struct cachefs_netfs afs_cache_netfs;
  481. #endif
  482. /*
  483. * misc.c
  484. */
  485. extern int afs_abort_to_error(u32);
  486. /*
  487. * mntpt.c
  488. */
  489. extern const struct inode_operations afs_mntpt_inode_operations;
  490. extern const struct file_operations afs_mntpt_file_operations;
  491. extern unsigned long afs_mntpt_expiry_timeout;
  492. extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *);
  493. extern void afs_mntpt_kill_timer(void);
  494. extern void afs_umount_begin(struct vfsmount *, int);
  495. /*
  496. * proc.c
  497. */
  498. extern int afs_proc_init(void);
  499. extern void afs_proc_cleanup(void);
  500. extern int afs_proc_cell_setup(struct afs_cell *);
  501. extern void afs_proc_cell_remove(struct afs_cell *);
  502. /*
  503. * rxrpc.c
  504. */
  505. extern int afs_open_socket(void);
  506. extern void afs_close_socket(void);
  507. extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t,
  508. const struct afs_wait_mode *);
  509. extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *,
  510. size_t, size_t);
  511. extern void afs_flat_call_destructor(struct afs_call *);
  512. extern void afs_transfer_reply(struct afs_call *, struct sk_buff *);
  513. extern void afs_send_empty_reply(struct afs_call *);
  514. extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
  515. extern int afs_extract_data(struct afs_call *, struct sk_buff *, bool, void *,
  516. size_t);
  517. /*
  518. * security.c
  519. */
  520. extern void afs_clear_permits(struct afs_vnode *);
  521. extern void afs_cache_permit(struct afs_vnode *, struct key *, long);
  522. extern void afs_zap_permits(struct rcu_head *);
  523. extern struct key *afs_request_key(struct afs_cell *);
  524. extern int afs_permission(struct inode *, int, struct nameidata *);
  525. /*
  526. * server.c
  527. */
  528. extern spinlock_t afs_server_peer_lock;
  529. #define afs_get_server(S) \
  530. do { \
  531. _debug("GET SERVER %d", atomic_read(&(S)->usage)); \
  532. atomic_inc(&(S)->usage); \
  533. } while(0)
  534. extern struct afs_server *afs_lookup_server(struct afs_cell *,
  535. const struct in_addr *);
  536. extern struct afs_server *afs_find_server(const struct in_addr *);
  537. extern void afs_put_server(struct afs_server *);
  538. extern void __exit afs_purge_servers(void);
  539. /*
  540. * super.c
  541. */
  542. extern int afs_fs_init(void);
  543. extern void afs_fs_exit(void);
  544. /*
  545. * use-rtnetlink.c
  546. */
  547. extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
  548. extern int afs_get_MAC_address(u8 *, size_t);
  549. /*
  550. * vlclient.c
  551. */
  552. #ifdef AFS_CACHING_SUPPORT
  553. extern struct cachefs_index_def afs_vlocation_cache_index_def;
  554. #endif
  555. extern int afs_vl_get_entry_by_name(struct in_addr *, struct key *,
  556. const char *, struct afs_cache_vlocation *,
  557. const struct afs_wait_mode *);
  558. extern int afs_vl_get_entry_by_id(struct in_addr *, struct key *,
  559. afs_volid_t, afs_voltype_t,
  560. struct afs_cache_vlocation *,
  561. const struct afs_wait_mode *);
  562. /*
  563. * vlocation.c
  564. */
  565. #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
  566. extern int __init afs_vlocation_update_init(void);
  567. extern struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *,
  568. struct key *,
  569. const char *, size_t);
  570. extern void afs_put_vlocation(struct afs_vlocation *);
  571. extern void afs_vlocation_purge(void);
  572. /*
  573. * vnode.c
  574. */
  575. #ifdef AFS_CACHING_SUPPORT
  576. extern struct cachefs_index_def afs_vnode_cache_index_def;
  577. #endif
  578. extern struct afs_timer_ops afs_vnode_cb_timed_out_ops;
  579. static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
  580. {
  581. return container_of(inode, struct afs_vnode, vfs_inode);
  582. }
  583. static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
  584. {
  585. return &vnode->vfs_inode;
  586. }
  587. extern void afs_vnode_finalise_status_update(struct afs_vnode *,
  588. struct afs_server *);
  589. extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *,
  590. struct key *);
  591. extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *,
  592. off_t, size_t, struct page *);
  593. extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *,
  594. umode_t, struct afs_fid *, struct afs_file_status *,
  595. struct afs_callback *, struct afs_server **);
  596. extern int afs_vnode_remove(struct afs_vnode *, struct key *, const char *,
  597. bool);
  598. extern int afs_vnode_link(struct afs_vnode *, struct afs_vnode *, struct key *,
  599. const char *);
  600. extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *,
  601. const char *, struct afs_fid *,
  602. struct afs_file_status *, struct afs_server **);
  603. extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *,
  604. struct key *, const char *, const char *);
  605. extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t,
  606. unsigned, unsigned);
  607. extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *);
  608. extern int afs_vnode_get_volume_status(struct afs_vnode *, struct key *,
  609. struct afs_volume_status *);
  610. /*
  611. * volume.c
  612. */
  613. #ifdef AFS_CACHING_SUPPORT
  614. extern struct cachefs_index_def afs_volume_cache_index_def;
  615. #endif
  616. #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
  617. extern void afs_put_volume(struct afs_volume *);
  618. extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *);
  619. extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *);
  620. extern int afs_volume_release_fileserver(struct afs_vnode *,
  621. struct afs_server *, int);
  622. /*
  623. * write.c
  624. */
  625. extern int afs_set_page_dirty(struct page *);
  626. extern void afs_put_writeback(struct afs_writeback *);
  627. extern int afs_prepare_write(struct file *, struct page *, unsigned, unsigned);
  628. extern int afs_commit_write(struct file *, struct page *, unsigned, unsigned);
  629. extern int afs_writepage(struct page *, struct writeback_control *);
  630. extern int afs_writepages(struct address_space *, struct writeback_control *);
  631. extern int afs_write_inode(struct inode *, int);
  632. extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
  633. extern ssize_t afs_file_write(struct kiocb *, const struct iovec *,
  634. unsigned long, loff_t);
  635. extern int afs_writeback_all(struct afs_vnode *);
  636. extern int afs_fsync(struct file *, struct dentry *, int);
  637. /*****************************************************************************/
  638. /*
  639. * debug tracing
  640. */
  641. extern unsigned afs_debug;
  642. #define dbgprintk(FMT,...) \
  643. printk("[%x%-6.6s] "FMT"\n", smp_processor_id(), current->comm ,##__VA_ARGS__)
  644. /* make sure we maintain the format strings, even when debugging is disabled */
  645. static inline __attribute__((format(printf,1,2)))
  646. void _dbprintk(const char *fmt, ...)
  647. {
  648. }
  649. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
  650. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
  651. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  652. #if defined(__KDEBUG)
  653. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  654. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  655. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  656. #elif defined(CONFIG_AFS_DEBUG)
  657. #define AFS_DEBUG_KENTER 0x01
  658. #define AFS_DEBUG_KLEAVE 0x02
  659. #define AFS_DEBUG_KDEBUG 0x04
  660. #define _enter(FMT,...) \
  661. do { \
  662. if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
  663. kenter(FMT,##__VA_ARGS__); \
  664. } while (0)
  665. #define _leave(FMT,...) \
  666. do { \
  667. if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
  668. kleave(FMT,##__VA_ARGS__); \
  669. } while (0)
  670. #define _debug(FMT,...) \
  671. do { \
  672. if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
  673. kdebug(FMT,##__VA_ARGS__); \
  674. } while (0)
  675. #else
  676. #define _enter(FMT,...) _dbprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
  677. #define _leave(FMT,...) _dbprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
  678. #define _debug(FMT,...) _dbprintk(" "FMT ,##__VA_ARGS__)
  679. #endif
  680. /*
  681. * debug assertion checking
  682. */
  683. #if 1 // defined(__KDEBUGALL)
  684. #define ASSERT(X) \
  685. do { \
  686. if (unlikely(!(X))) { \
  687. printk(KERN_ERR "\n"); \
  688. printk(KERN_ERR "AFS: Assertion failed\n"); \
  689. BUG(); \
  690. } \
  691. } while(0)
  692. #define ASSERTCMP(X, OP, Y) \
  693. do { \
  694. if (unlikely(!((X) OP (Y)))) { \
  695. printk(KERN_ERR "\n"); \
  696. printk(KERN_ERR "AFS: Assertion failed\n"); \
  697. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  698. (unsigned long)(X), (unsigned long)(Y)); \
  699. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  700. (unsigned long)(X), (unsigned long)(Y)); \
  701. BUG(); \
  702. } \
  703. } while(0)
  704. #define ASSERTRANGE(L, OP1, N, OP2, H) \
  705. do { \
  706. if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
  707. printk(KERN_ERR "\n"); \
  708. printk(KERN_ERR "AFS: Assertion failed\n"); \
  709. printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
  710. (unsigned long)(L), (unsigned long)(N), \
  711. (unsigned long)(H)); \
  712. printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
  713. (unsigned long)(L), (unsigned long)(N), \
  714. (unsigned long)(H)); \
  715. BUG(); \
  716. } \
  717. } while(0)
  718. #define ASSERTIF(C, X) \
  719. do { \
  720. if (unlikely((C) && !(X))) { \
  721. printk(KERN_ERR "\n"); \
  722. printk(KERN_ERR "AFS: Assertion failed\n"); \
  723. BUG(); \
  724. } \
  725. } while(0)
  726. #define ASSERTIFCMP(C, X, OP, Y) \
  727. do { \
  728. if (unlikely((C) && !((X) OP (Y)))) { \
  729. printk(KERN_ERR "\n"); \
  730. printk(KERN_ERR "AFS: Assertion failed\n"); \
  731. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  732. (unsigned long)(X), (unsigned long)(Y)); \
  733. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  734. (unsigned long)(X), (unsigned long)(Y)); \
  735. BUG(); \
  736. } \
  737. } while(0)
  738. #else
  739. #define ASSERT(X) \
  740. do { \
  741. } while(0)
  742. #define ASSERTCMP(X, OP, Y) \
  743. do { \
  744. } while(0)
  745. #define ASSERTRANGE(L, OP1, N, OP2, H) \
  746. do { \
  747. } while(0)
  748. #define ASSERTIF(C, X) \
  749. do { \
  750. } while(0)
  751. #define ASSERTIFCMP(C, X, OP, Y) \
  752. do { \
  753. } while(0)
  754. #endif /* __KDEBUGALL */