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