internal.h 31 KB

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