internal.h 31 KB

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