internal.h 30 KB

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