internal.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  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/net_namespace.h>
  24. #include <net/netns/generic.h>
  25. #include <net/sock.h>
  26. #include <net/af_rxrpc.h>
  27. #include "afs.h"
  28. #include "afs_vl.h"
  29. #define AFS_CELL_MAX_ADDRS 15
  30. struct pagevec;
  31. struct afs_call;
  32. struct afs_mount_params {
  33. bool rwpath; /* T if the parent should be considered R/W */
  34. bool force; /* T to force cell type */
  35. bool autocell; /* T if set auto mount operation */
  36. bool dyn_root; /* T if dynamic root */
  37. afs_voltype_t type; /* type of volume requested */
  38. int volnamesz; /* size of volume name */
  39. const char *volname; /* name of volume to mount */
  40. struct net *net_ns; /* Network namespace in effect */
  41. struct afs_net *net; /* the AFS net namespace stuff */
  42. struct afs_cell *cell; /* cell in which to find volume */
  43. struct afs_volume *volume; /* volume record */
  44. struct key *key; /* key to use for secure mounting */
  45. };
  46. struct afs_iget_data {
  47. struct afs_fid fid;
  48. struct afs_volume *volume; /* volume on which resides */
  49. };
  50. enum afs_call_state {
  51. AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
  52. AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
  53. AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
  54. AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
  55. AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
  56. AFS_CALL_SV_REPLYING, /* Server: Replying */
  57. AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
  58. AFS_CALL_COMPLETE, /* Completed or failed */
  59. };
  60. /*
  61. * List of server addresses.
  62. */
  63. struct afs_addr_list {
  64. struct rcu_head rcu; /* Must be first */
  65. refcount_t usage;
  66. u32 version; /* Version */
  67. unsigned short nr_addrs;
  68. unsigned short index; /* Address currently in use */
  69. unsigned short nr_ipv4; /* Number of IPv4 addresses */
  70. unsigned long probed; /* Mask of servers that have been probed */
  71. unsigned long yfs; /* Mask of servers that are YFS */
  72. struct sockaddr_rxrpc addrs[];
  73. };
  74. /*
  75. * a record of an in-progress RxRPC call
  76. */
  77. struct afs_call {
  78. const struct afs_call_type *type; /* type of call */
  79. wait_queue_head_t waitq; /* processes awaiting completion */
  80. struct work_struct async_work; /* async I/O processor */
  81. struct work_struct work; /* actual work processor */
  82. struct rxrpc_call *rxcall; /* RxRPC call handle */
  83. struct key *key; /* security for this call */
  84. struct afs_net *net; /* The network namespace */
  85. struct afs_server *cm_server; /* Server affected by incoming CM call */
  86. struct afs_cb_interest *cbi; /* Callback interest for server used */
  87. void *request; /* request data (first part) */
  88. struct address_space *mapping; /* Pages being written from */
  89. void *buffer; /* reply receive buffer */
  90. void *reply[4]; /* Where to put the reply */
  91. pgoff_t first; /* first page in mapping to deal with */
  92. pgoff_t last; /* last page in mapping to deal with */
  93. size_t offset; /* offset into received data store */
  94. atomic_t usage;
  95. enum afs_call_state state;
  96. spinlock_t state_lock;
  97. int error; /* error code */
  98. u32 abort_code; /* Remote abort ID or 0 */
  99. unsigned request_size; /* size of request data */
  100. unsigned reply_max; /* maximum size of reply */
  101. unsigned first_offset; /* offset into mapping[first] */
  102. unsigned int cb_break; /* cb_break + cb_s_break before the call */
  103. union {
  104. unsigned last_to; /* amount of mapping[last] */
  105. unsigned count2; /* count used in unmarshalling */
  106. };
  107. unsigned char unmarshall; /* unmarshalling phase */
  108. bool incoming; /* T if incoming call */
  109. bool send_pages; /* T if data from mapping should be sent */
  110. bool need_attention; /* T if RxRPC poked us */
  111. bool async; /* T if asynchronous */
  112. bool ret_reply0; /* T if should return reply[0] on success */
  113. bool upgrade; /* T to request service upgrade */
  114. u16 service_id; /* Actual service ID (after upgrade) */
  115. unsigned int debug_id; /* Trace ID */
  116. u32 operation_ID; /* operation ID for an incoming call */
  117. u32 count; /* count for use in unmarshalling */
  118. __be32 tmp; /* place to extract temporary data */
  119. afs_dataversion_t expected_version; /* Updated version expected from store */
  120. afs_dataversion_t expected_version_2; /* 2nd updated version expected from store */
  121. };
  122. struct afs_call_type {
  123. const char *name;
  124. unsigned int op; /* Really enum afs_fs_operation */
  125. /* deliver request or reply data to an call
  126. * - returning an error will cause the call to be aborted
  127. */
  128. int (*deliver)(struct afs_call *call);
  129. /* clean up a call */
  130. void (*destructor)(struct afs_call *call);
  131. /* Work function */
  132. void (*work)(struct work_struct *work);
  133. };
  134. /*
  135. * Key available for writeback on a file.
  136. */
  137. struct afs_wb_key {
  138. refcount_t usage;
  139. struct key *key;
  140. struct list_head vnode_link; /* Link in vnode->wb_keys */
  141. };
  142. /*
  143. * AFS open file information record. Pointed to by file->private_data.
  144. */
  145. struct afs_file {
  146. struct key *key; /* The key this file was opened with */
  147. struct afs_wb_key *wb; /* Writeback key record for this file */
  148. };
  149. static inline struct key *afs_file_key(struct file *file)
  150. {
  151. struct afs_file *af = file->private_data;
  152. return af->key;
  153. }
  154. /*
  155. * Record of an outstanding read operation on a vnode.
  156. */
  157. struct afs_read {
  158. loff_t pos; /* Where to start reading */
  159. loff_t len; /* How much we're asking for */
  160. loff_t actual_len; /* How much we're actually getting */
  161. loff_t remain; /* Amount remaining */
  162. loff_t file_size; /* File size returned by server */
  163. afs_dataversion_t data_version; /* Version number returned by server */
  164. refcount_t usage;
  165. unsigned int index; /* Which page we're reading into */
  166. unsigned int nr_pages;
  167. void (*page_done)(struct afs_call *, struct afs_read *);
  168. struct page **pages;
  169. struct page *array[];
  170. };
  171. /*
  172. * AFS superblock private data
  173. * - there's one superblock per volume
  174. */
  175. struct afs_super_info {
  176. struct net *net_ns; /* Network namespace */
  177. struct afs_cell *cell; /* The cell in which the volume resides */
  178. struct afs_volume *volume; /* volume record */
  179. bool dyn_root; /* True if dynamic root */
  180. };
  181. static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
  182. {
  183. return sb->s_fs_info;
  184. }
  185. extern struct file_system_type afs_fs_type;
  186. /*
  187. * Set of substitutes for @sys.
  188. */
  189. struct afs_sysnames {
  190. #define AFS_NR_SYSNAME 16
  191. char *subs[AFS_NR_SYSNAME];
  192. refcount_t usage;
  193. unsigned short nr;
  194. char blank[1];
  195. };
  196. /*
  197. * AFS network namespace record.
  198. */
  199. struct afs_net {
  200. struct net *net; /* Backpointer to the owning net namespace */
  201. struct afs_uuid uuid;
  202. bool live; /* F if this namespace is being removed */
  203. /* AF_RXRPC I/O stuff */
  204. struct socket *socket;
  205. struct afs_call *spare_incoming_call;
  206. struct work_struct charge_preallocation_work;
  207. struct mutex socket_mutex;
  208. atomic_t nr_outstanding_calls;
  209. atomic_t nr_superblocks;
  210. /* Cell database */
  211. struct rb_root cells;
  212. struct afs_cell __rcu *ws_cell;
  213. struct work_struct cells_manager;
  214. struct timer_list cells_timer;
  215. atomic_t cells_outstanding;
  216. seqlock_t cells_lock;
  217. struct mutex proc_cells_lock;
  218. struct list_head proc_cells;
  219. /* Known servers. Theoretically each fileserver can only be in one
  220. * cell, but in practice, people create aliases and subsets and there's
  221. * no easy way to distinguish them.
  222. */
  223. seqlock_t fs_lock; /* For fs_servers */
  224. struct rb_root fs_servers; /* afs_server (by server UUID or address) */
  225. struct list_head fs_updates; /* afs_server (by update_at) */
  226. struct hlist_head fs_proc; /* procfs servers list */
  227. struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */
  228. struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */
  229. seqlock_t fs_addr_lock; /* For fs_addresses[46] */
  230. struct work_struct fs_manager;
  231. struct timer_list fs_timer;
  232. atomic_t servers_outstanding;
  233. /* File locking renewal management */
  234. struct mutex lock_manager_mutex;
  235. /* Misc */
  236. struct super_block *dynroot_sb; /* Dynamic root mount superblock */
  237. struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
  238. struct afs_sysnames *sysnames;
  239. rwlock_t sysnames_lock;
  240. /* Statistics counters */
  241. atomic_t n_lookup; /* Number of lookups done */
  242. atomic_t n_reval; /* Number of dentries needing revalidation */
  243. atomic_t n_inval; /* Number of invalidations by the server */
  244. atomic_t n_relpg; /* Number of invalidations by releasepage */
  245. atomic_t n_read_dir; /* Number of directory pages read */
  246. atomic_t n_dir_cr; /* Number of directory entry creation edits */
  247. atomic_t n_dir_rm; /* Number of directory entry removal edits */
  248. atomic_t n_stores; /* Number of store ops */
  249. atomic_long_t n_store_bytes; /* Number of bytes stored */
  250. atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
  251. atomic_t n_fetches; /* Number of data fetch ops */
  252. };
  253. extern const char afs_init_sysname[];
  254. enum afs_cell_state {
  255. AFS_CELL_UNSET,
  256. AFS_CELL_ACTIVATING,
  257. AFS_CELL_ACTIVE,
  258. AFS_CELL_DEACTIVATING,
  259. AFS_CELL_INACTIVE,
  260. AFS_CELL_FAILED,
  261. };
  262. /*
  263. * AFS cell record.
  264. *
  265. * This is a tricky concept to get right as it is possible to create aliases
  266. * simply by pointing AFSDB/SRV records for two names at the same set of VL
  267. * servers; it is also possible to do things like setting up two sets of VL
  268. * servers, one of which provides a superset of the volumes provided by the
  269. * other (for internal/external division, for example).
  270. *
  271. * Cells only exist in the sense that (a) a cell's name maps to a set of VL
  272. * servers and (b) a cell's name is used by the client to select the key to use
  273. * for authentication and encryption. The cell name is not typically used in
  274. * the protocol.
  275. *
  276. * There is no easy way to determine if two cells are aliases or one is a
  277. * subset of another.
  278. */
  279. struct afs_cell {
  280. union {
  281. struct rcu_head rcu;
  282. struct rb_node net_node; /* Node in net->cells */
  283. };
  284. struct afs_net *net;
  285. struct key *anonymous_key; /* anonymous user key for this cell */
  286. struct work_struct manager; /* Manager for init/deinit/dns */
  287. struct list_head proc_link; /* /proc cell list link */
  288. #ifdef CONFIG_AFS_FSCACHE
  289. struct fscache_cookie *cache; /* caching cookie */
  290. #endif
  291. time64_t dns_expiry; /* Time AFSDB/SRV record expires */
  292. time64_t last_inactive; /* Time of last drop of usage count */
  293. atomic_t usage;
  294. unsigned long flags;
  295. #define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */
  296. #define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */
  297. #define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */
  298. #define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */
  299. #define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */
  300. enum afs_cell_state state;
  301. short error;
  302. /* Active fileserver interaction state. */
  303. struct list_head proc_volumes; /* procfs volume list */
  304. rwlock_t proc_lock;
  305. /* VL server list. */
  306. rwlock_t vl_addrs_lock; /* Lock on vl_addrs */
  307. struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */
  308. u8 name_len; /* Length of name */
  309. char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */
  310. };
  311. /*
  312. * Cached VLDB entry.
  313. *
  314. * This is pointed to by cell->vldb_entries, indexed by name.
  315. */
  316. struct afs_vldb_entry {
  317. afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
  318. unsigned long flags;
  319. #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
  320. #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
  321. #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
  322. #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
  323. #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
  324. uuid_t fs_server[AFS_NMAXNSERVERS];
  325. u8 fs_mask[AFS_NMAXNSERVERS];
  326. #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
  327. #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
  328. #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
  329. short error;
  330. u8 nr_servers; /* Number of server records */
  331. u8 name_len;
  332. u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
  333. };
  334. /*
  335. * Record of fileserver with which we're actively communicating.
  336. */
  337. struct afs_server {
  338. struct rcu_head rcu;
  339. union {
  340. uuid_t uuid; /* Server ID */
  341. struct afs_uuid _uuid;
  342. };
  343. struct afs_addr_list __rcu *addresses;
  344. struct rb_node uuid_rb; /* Link in net->servers */
  345. struct hlist_node addr4_link; /* Link in net->fs_addresses4 */
  346. struct hlist_node addr6_link; /* Link in net->fs_addresses6 */
  347. struct hlist_node proc_link; /* Link in net->fs_proc */
  348. struct afs_server *gc_next; /* Next server in manager's list */
  349. time64_t put_time; /* Time at which last put */
  350. time64_t update_at; /* Time at which to next update the record */
  351. unsigned long flags;
  352. #define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */
  353. #define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */
  354. #define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */
  355. #define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */
  356. #define AFS_SERVER_FL_UPDATING 4
  357. #define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */
  358. #define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */
  359. #define AFS_SERVER_FL_NO_IBULK 7 /* Fileserver doesn't support FS.InlineBulkStatus */
  360. #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
  361. atomic_t usage;
  362. u32 addr_version; /* Address list version */
  363. /* file service access */
  364. rwlock_t fs_lock; /* access lock */
  365. /* callback promise management */
  366. struct hlist_head cb_volumes; /* List of volume interests on this server */
  367. unsigned cb_s_break; /* Break-everything counter. */
  368. rwlock_t cb_break_lock; /* Volume finding lock */
  369. };
  370. /*
  371. * Volume collation in the server's callback interest list.
  372. */
  373. struct afs_vol_interest {
  374. struct hlist_node srv_link; /* Link in server->cb_volumes */
  375. struct hlist_head cb_interests; /* List of callback interests on the server */
  376. afs_volid_t vid; /* Volume ID to match */
  377. unsigned int usage;
  378. };
  379. /*
  380. * Interest by a superblock on a server.
  381. */
  382. struct afs_cb_interest {
  383. struct hlist_node cb_vlink; /* Link in vol_interest->cb_interests */
  384. struct afs_vol_interest *vol_interest;
  385. struct afs_server *server; /* Server on which this interest resides */
  386. struct super_block *sb; /* Superblock on which inodes reside */
  387. afs_volid_t vid; /* Volume ID to match */
  388. refcount_t usage;
  389. };
  390. /*
  391. * Replaceable server list.
  392. */
  393. struct afs_server_entry {
  394. struct afs_server *server;
  395. struct afs_cb_interest *cb_interest;
  396. };
  397. struct afs_server_list {
  398. refcount_t usage;
  399. unsigned short nr_servers;
  400. unsigned short index; /* Server currently in use */
  401. unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
  402. unsigned int seq; /* Set to ->servers_seq when installed */
  403. rwlock_t lock;
  404. struct afs_server_entry servers[];
  405. };
  406. /*
  407. * Live AFS volume management.
  408. */
  409. struct afs_volume {
  410. afs_volid_t vid; /* volume ID */
  411. atomic_t usage;
  412. time64_t update_at; /* Time at which to next update */
  413. struct afs_cell *cell; /* Cell to which belongs (pins ref) */
  414. struct list_head proc_link; /* Link in cell->vl_proc */
  415. unsigned long flags;
  416. #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
  417. #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
  418. #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
  419. #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
  420. #define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */
  421. #define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */
  422. #ifdef CONFIG_AFS_FSCACHE
  423. struct fscache_cookie *cache; /* caching cookie */
  424. #endif
  425. struct afs_server_list *servers; /* List of servers on which volume resides */
  426. rwlock_t servers_lock; /* Lock for ->servers */
  427. unsigned int servers_seq; /* Incremented each time ->servers changes */
  428. unsigned cb_v_break; /* Break-everything counter. */
  429. rwlock_t cb_break_lock;
  430. afs_voltype_t type; /* type of volume */
  431. short error;
  432. char type_force; /* force volume type (suppress R/O -> R/W) */
  433. u8 name_len;
  434. u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
  435. };
  436. enum afs_lock_state {
  437. AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
  438. AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
  439. AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
  440. AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
  441. AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
  442. AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
  443. AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
  444. };
  445. /*
  446. * AFS inode private data.
  447. *
  448. * Note that afs_alloc_inode() *must* reset anything that could incorrectly
  449. * leak from one inode to another.
  450. */
  451. struct afs_vnode {
  452. struct inode vfs_inode; /* the VFS's inode record */
  453. struct afs_volume *volume; /* volume on which vnode resides */
  454. struct afs_fid fid; /* the file identifier for this inode */
  455. struct afs_file_status status; /* AFS status info for this file */
  456. afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
  457. #ifdef CONFIG_AFS_FSCACHE
  458. struct fscache_cookie *cache; /* caching cookie */
  459. #endif
  460. struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
  461. struct mutex io_lock; /* Lock for serialising I/O on this mutex */
  462. struct rw_semaphore validate_lock; /* lock for validating this vnode */
  463. spinlock_t wb_lock; /* lock for wb_keys */
  464. spinlock_t lock; /* waitqueue/flags lock */
  465. unsigned long flags;
  466. #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */
  467. #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
  468. #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
  469. #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
  470. #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
  471. #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
  472. #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
  473. #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
  474. #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
  475. struct list_head wb_keys; /* List of keys available for writeback */
  476. struct list_head pending_locks; /* locks waiting to be granted */
  477. struct list_head granted_locks; /* locks granted on this file */
  478. struct delayed_work lock_work; /* work to be done in locking */
  479. struct key *lock_key; /* Key to be used in lock ops */
  480. enum afs_lock_state lock_state : 8;
  481. afs_lock_type_t lock_type : 8;
  482. /* outstanding callback notification on this file */
  483. struct afs_cb_interest *cb_interest; /* Server on which this resides */
  484. unsigned int cb_s_break; /* Mass break counter on ->server */
  485. unsigned int cb_v_break; /* Mass break counter on ->volume */
  486. unsigned int cb_break; /* Break counter on vnode */
  487. seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */
  488. time64_t cb_expires_at; /* time at which callback expires */
  489. unsigned cb_version; /* callback version */
  490. afs_callback_type_t cb_type; /* type of callback */
  491. };
  492. /*
  493. * cached security record for one user's attempt to access a vnode
  494. */
  495. struct afs_permit {
  496. struct key *key; /* RxRPC ticket holding a security context */
  497. afs_access_t access; /* CallerAccess value for this key */
  498. };
  499. /*
  500. * Immutable cache of CallerAccess records from attempts to access vnodes.
  501. * These may be shared between multiple vnodes.
  502. */
  503. struct afs_permits {
  504. struct rcu_head rcu;
  505. struct hlist_node hash_node; /* Link in hash */
  506. unsigned long h; /* Hash value for this permit list */
  507. refcount_t usage;
  508. unsigned short nr_permits; /* Number of records */
  509. bool invalidated; /* Invalidated due to key change */
  510. struct afs_permit permits[]; /* List of permits sorted by key pointer */
  511. };
  512. /*
  513. * record of one of a system's set of network interfaces
  514. */
  515. struct afs_interface {
  516. struct in_addr address; /* IPv4 address bound to interface */
  517. struct in_addr netmask; /* netmask applied to address */
  518. unsigned mtu; /* MTU of interface */
  519. };
  520. /*
  521. * Cursor for iterating over a server's address list.
  522. */
  523. struct afs_addr_cursor {
  524. struct afs_addr_list *alist; /* Current address list (pins ref) */
  525. struct sockaddr_rxrpc *addr;
  526. u32 abort_code;
  527. unsigned short start; /* Starting point in alist->addrs[] */
  528. unsigned short index; /* Wrapping offset from start to current addr */
  529. short error;
  530. bool begun; /* T if we've begun iteration */
  531. bool responded; /* T if the current address responded */
  532. };
  533. /*
  534. * Cursor for iterating over a set of fileservers.
  535. */
  536. struct afs_fs_cursor {
  537. struct afs_addr_cursor ac;
  538. struct afs_vnode *vnode;
  539. struct afs_server_list *server_list; /* Current server list (pins ref) */
  540. struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */
  541. struct key *key; /* Key for the server */
  542. unsigned int cb_break; /* cb_break + cb_s_break before the call */
  543. unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */
  544. unsigned char start; /* Initial index in server list */
  545. unsigned char index; /* Number of servers tried beyond start */
  546. unsigned short flags;
  547. #define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */
  548. #define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */
  549. #define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */
  550. #define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */
  551. #define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
  552. #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
  553. };
  554. /*
  555. * Cache auxiliary data.
  556. */
  557. struct afs_vnode_cache_aux {
  558. u64 data_version;
  559. } __packed;
  560. #include <trace/events/afs.h>
  561. /*****************************************************************************/
  562. /*
  563. * addr_list.c
  564. */
  565. static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist)
  566. {
  567. if (alist)
  568. refcount_inc(&alist->usage);
  569. return alist;
  570. }
  571. extern struct afs_addr_list *afs_alloc_addrlist(unsigned int,
  572. unsigned short,
  573. unsigned short);
  574. extern void afs_put_addrlist(struct afs_addr_list *);
  575. extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char,
  576. unsigned short, unsigned short);
  577. extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *);
  578. extern bool afs_iterate_addresses(struct afs_addr_cursor *);
  579. extern int afs_end_cursor(struct afs_addr_cursor *);
  580. extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *);
  581. extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16);
  582. extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16);
  583. /*
  584. * cache.c
  585. */
  586. #ifdef CONFIG_AFS_FSCACHE
  587. extern struct fscache_netfs afs_cache_netfs;
  588. extern struct fscache_cookie_def afs_cell_cache_index_def;
  589. extern struct fscache_cookie_def afs_volume_cache_index_def;
  590. extern struct fscache_cookie_def afs_vnode_cache_index_def;
  591. #else
  592. #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL)
  593. #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL)
  594. #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL)
  595. #endif
  596. /*
  597. * callback.c
  598. */
  599. extern void afs_init_callback_state(struct afs_server *);
  600. extern void afs_break_callback(struct afs_vnode *);
  601. extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*);
  602. extern int afs_register_server_cb_interest(struct afs_vnode *,
  603. struct afs_server_list *, unsigned int);
  604. extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *);
  605. extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *);
  606. static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi)
  607. {
  608. if (cbi)
  609. refcount_inc(&cbi->usage);
  610. return cbi;
  611. }
  612. static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
  613. {
  614. return vnode->cb_break + vnode->cb_s_break + vnode->cb_v_break;
  615. }
  616. static inline unsigned int afs_cb_break_sum(struct afs_vnode *vnode,
  617. struct afs_cb_interest *cbi)
  618. {
  619. return vnode->cb_break + cbi->server->cb_s_break + vnode->volume->cb_v_break;
  620. }
  621. /*
  622. * cell.c
  623. */
  624. extern int afs_cell_init(struct afs_net *, const char *);
  625. extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned);
  626. extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
  627. const char *, bool);
  628. extern struct afs_cell *afs_get_cell(struct afs_cell *);
  629. extern void afs_put_cell(struct afs_net *, struct afs_cell *);
  630. extern void afs_manage_cells(struct work_struct *);
  631. extern void afs_cells_timer(struct timer_list *);
  632. extern void __net_exit afs_cell_purge(struct afs_net *);
  633. /*
  634. * cmservice.c
  635. */
  636. extern bool afs_cm_incoming_call(struct afs_call *);
  637. /*
  638. * dir.c
  639. */
  640. extern const struct file_operations afs_dir_file_operations;
  641. extern const struct inode_operations afs_dir_inode_operations;
  642. extern const struct address_space_operations afs_dir_aops;
  643. extern const struct dentry_operations afs_fs_dentry_operations;
  644. extern void afs_d_release(struct dentry *);
  645. /*
  646. * dir_edit.c
  647. */
  648. extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
  649. enum afs_edit_dir_reason);
  650. extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
  651. /*
  652. * dynroot.c
  653. */
  654. extern const struct file_operations afs_dynroot_file_operations;
  655. extern const struct inode_operations afs_dynroot_inode_operations;
  656. extern const struct dentry_operations afs_dynroot_dentry_operations;
  657. extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
  658. extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
  659. extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
  660. extern int afs_dynroot_populate(struct super_block *);
  661. extern void afs_dynroot_depopulate(struct super_block *);
  662. /*
  663. * file.c
  664. */
  665. extern const struct address_space_operations afs_fs_aops;
  666. extern const struct inode_operations afs_file_inode_operations;
  667. extern const struct file_operations afs_file_operations;
  668. extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
  669. extern void afs_put_wb_key(struct afs_wb_key *);
  670. extern int afs_open(struct inode *, struct file *);
  671. extern int afs_release(struct inode *, struct file *);
  672. extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *);
  673. extern int afs_page_filler(void *, struct page *);
  674. extern void afs_put_read(struct afs_read *);
  675. /*
  676. * flock.c
  677. */
  678. extern struct workqueue_struct *afs_lock_manager;
  679. extern void afs_lock_work(struct work_struct *);
  680. extern void afs_lock_may_be_available(struct afs_vnode *);
  681. extern int afs_lock(struct file *, int, struct file_lock *);
  682. extern int afs_flock(struct file *, int, struct file_lock *);
  683. /*
  684. * fsclient.c
  685. */
  686. #define AFS_VNODE_NOT_YET_SET 0x01
  687. #define AFS_VNODE_META_CHANGED 0x02
  688. #define AFS_VNODE_DATA_CHANGED 0x04
  689. extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *,
  690. const afs_dataversion_t *, u8);
  691. extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool);
  692. extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *);
  693. extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *);
  694. extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, u64,
  695. struct afs_fid *, struct afs_file_status *, struct afs_callback *);
  696. extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool, u64);
  697. extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64);
  698. extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64,
  699. struct afs_fid *, struct afs_file_status *);
  700. extern int afs_fs_rename(struct afs_fs_cursor *, const char *,
  701. struct afs_vnode *, const char *, u64, u64);
  702. extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *,
  703. pgoff_t, pgoff_t, unsigned, unsigned);
  704. extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *);
  705. extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *);
  706. extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t);
  707. extern int afs_fs_extend_lock(struct afs_fs_cursor *);
  708. extern int afs_fs_release_lock(struct afs_fs_cursor *);
  709. extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *,
  710. struct afs_addr_cursor *, struct key *);
  711. extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *,
  712. struct afs_addr_cursor *, struct key *);
  713. extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *,
  714. struct afs_fid *, struct afs_file_status *,
  715. struct afs_callback *, unsigned int,
  716. struct afs_volsync *);
  717. extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *,
  718. struct afs_fid *, struct afs_file_status *,
  719. struct afs_callback *, struct afs_volsync *);
  720. /*
  721. * inode.c
  722. */
  723. extern int afs_fetch_status(struct afs_vnode *, struct key *, bool);
  724. extern int afs_iget5_test(struct inode *, void *);
  725. extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
  726. extern struct inode *afs_iget(struct super_block *, struct key *,
  727. struct afs_fid *, struct afs_file_status *,
  728. struct afs_callback *,
  729. struct afs_cb_interest *);
  730. extern void afs_zap_data(struct afs_vnode *);
  731. extern int afs_validate(struct afs_vnode *, struct key *);
  732. extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int);
  733. extern int afs_setattr(struct dentry *, struct iattr *);
  734. extern void afs_evict_inode(struct inode *);
  735. extern int afs_drop_inode(struct inode *);
  736. /*
  737. * main.c
  738. */
  739. extern struct workqueue_struct *afs_wq;
  740. extern int afs_net_id;
  741. static inline struct afs_net *afs_net(struct net *net)
  742. {
  743. return net_generic(net, afs_net_id);
  744. }
  745. static inline struct afs_net *afs_sb2net(struct super_block *sb)
  746. {
  747. return afs_net(AFS_FS_S(sb)->net_ns);
  748. }
  749. static inline struct afs_net *afs_d2net(struct dentry *dentry)
  750. {
  751. return afs_sb2net(dentry->d_sb);
  752. }
  753. static inline struct afs_net *afs_i2net(struct inode *inode)
  754. {
  755. return afs_sb2net(inode->i_sb);
  756. }
  757. static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
  758. {
  759. return afs_i2net(&vnode->vfs_inode);
  760. }
  761. static inline struct afs_net *afs_sock2net(struct sock *sk)
  762. {
  763. return net_generic(sock_net(sk), afs_net_id);
  764. }
  765. static inline void __afs_stat(atomic_t *s)
  766. {
  767. atomic_inc(s);
  768. }
  769. #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
  770. /*
  771. * misc.c
  772. */
  773. extern int afs_abort_to_error(u32);
  774. /*
  775. * mntpt.c
  776. */
  777. extern const struct inode_operations afs_mntpt_inode_operations;
  778. extern const struct inode_operations afs_autocell_inode_operations;
  779. extern const struct file_operations afs_mntpt_file_operations;
  780. extern struct vfsmount *afs_d_automount(struct path *);
  781. extern void afs_mntpt_kill_timer(void);
  782. /*
  783. * netdevices.c
  784. */
  785. extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *,
  786. size_t, bool);
  787. /*
  788. * proc.c
  789. */
  790. #ifdef CONFIG_PROC_FS
  791. extern int __net_init afs_proc_init(struct afs_net *);
  792. extern void __net_exit afs_proc_cleanup(struct afs_net *);
  793. extern int afs_proc_cell_setup(struct afs_cell *);
  794. extern void afs_proc_cell_remove(struct afs_cell *);
  795. extern void afs_put_sysnames(struct afs_sysnames *);
  796. #else
  797. static inline int afs_proc_init(struct afs_net *net) { return 0; }
  798. static inline void afs_proc_cleanup(struct afs_net *net) {}
  799. static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
  800. static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
  801. static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
  802. #endif
  803. /*
  804. * rotate.c
  805. */
  806. extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *,
  807. struct key *);
  808. extern bool afs_select_fileserver(struct afs_fs_cursor *);
  809. extern bool afs_select_current_fileserver(struct afs_fs_cursor *);
  810. extern int afs_end_vnode_operation(struct afs_fs_cursor *);
  811. /*
  812. * rxrpc.c
  813. */
  814. extern struct workqueue_struct *afs_async_calls;
  815. extern int __net_init afs_open_socket(struct afs_net *);
  816. extern void __net_exit afs_close_socket(struct afs_net *);
  817. extern void afs_charge_preallocation(struct work_struct *);
  818. extern void afs_put_call(struct afs_call *);
  819. extern int afs_queue_call_work(struct afs_call *);
  820. extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool);
  821. extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
  822. const struct afs_call_type *,
  823. size_t, size_t);
  824. extern void afs_flat_call_destructor(struct afs_call *);
  825. extern void afs_send_empty_reply(struct afs_call *);
  826. extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
  827. extern int afs_extract_data(struct afs_call *, void *, size_t, bool);
  828. extern int afs_protocol_error(struct afs_call *, int);
  829. static inline int afs_transfer_reply(struct afs_call *call)
  830. {
  831. return afs_extract_data(call, call->buffer, call->reply_max, false);
  832. }
  833. static inline bool afs_check_call_state(struct afs_call *call,
  834. enum afs_call_state state)
  835. {
  836. return READ_ONCE(call->state) == state;
  837. }
  838. static inline bool afs_set_call_state(struct afs_call *call,
  839. enum afs_call_state from,
  840. enum afs_call_state to)
  841. {
  842. bool ok = false;
  843. spin_lock_bh(&call->state_lock);
  844. if (call->state == from) {
  845. call->state = to;
  846. trace_afs_call_state(call, from, to, 0, 0);
  847. ok = true;
  848. }
  849. spin_unlock_bh(&call->state_lock);
  850. return ok;
  851. }
  852. static inline void afs_set_call_complete(struct afs_call *call,
  853. int error, u32 remote_abort)
  854. {
  855. enum afs_call_state state;
  856. bool ok = false;
  857. spin_lock_bh(&call->state_lock);
  858. state = call->state;
  859. if (state != AFS_CALL_COMPLETE) {
  860. call->abort_code = remote_abort;
  861. call->error = error;
  862. call->state = AFS_CALL_COMPLETE;
  863. trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
  864. error, remote_abort);
  865. ok = true;
  866. }
  867. spin_unlock_bh(&call->state_lock);
  868. if (ok)
  869. trace_afs_call_done(call);
  870. }
  871. /*
  872. * security.c
  873. */
  874. extern void afs_put_permits(struct afs_permits *);
  875. extern void afs_clear_permits(struct afs_vnode *);
  876. extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int);
  877. extern void afs_zap_permits(struct rcu_head *);
  878. extern struct key *afs_request_key(struct afs_cell *);
  879. extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
  880. extern int afs_permission(struct inode *, int);
  881. extern void __exit afs_clean_up_permit_cache(void);
  882. /*
  883. * server.c
  884. */
  885. extern spinlock_t afs_server_peer_lock;
  886. static inline struct afs_server *afs_get_server(struct afs_server *server)
  887. {
  888. atomic_inc(&server->usage);
  889. return server;
  890. }
  891. extern struct afs_server *afs_find_server(struct afs_net *,
  892. const struct sockaddr_rxrpc *);
  893. extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
  894. extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *);
  895. extern void afs_put_server(struct afs_net *, struct afs_server *);
  896. extern void afs_manage_servers(struct work_struct *);
  897. extern void afs_servers_timer(struct timer_list *);
  898. extern void __net_exit afs_purge_servers(struct afs_net *);
  899. extern bool afs_probe_fileserver(struct afs_fs_cursor *);
  900. extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *);
  901. /*
  902. * server_list.c
  903. */
  904. static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
  905. {
  906. refcount_inc(&slist->usage);
  907. return slist;
  908. }
  909. extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
  910. extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *,
  911. struct afs_vldb_entry *,
  912. u8);
  913. extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
  914. /*
  915. * super.c
  916. */
  917. extern int __init afs_fs_init(void);
  918. extern void afs_fs_exit(void);
  919. /*
  920. * vlclient.c
  921. */
  922. extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *,
  923. struct afs_addr_cursor *,
  924. struct key *, const char *, int);
  925. extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *,
  926. struct key *, const uuid_t *);
  927. extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *);
  928. extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *,
  929. struct key *, const uuid_t *);
  930. /*
  931. * volume.c
  932. */
  933. static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)
  934. {
  935. if (volume)
  936. atomic_inc(&volume->usage);
  937. return volume;
  938. }
  939. extern struct afs_volume *afs_create_volume(struct afs_mount_params *);
  940. extern void afs_activate_volume(struct afs_volume *);
  941. extern void afs_deactivate_volume(struct afs_volume *);
  942. extern void afs_put_volume(struct afs_cell *, struct afs_volume *);
  943. extern int afs_check_volume_status(struct afs_volume *, struct key *);
  944. /*
  945. * write.c
  946. */
  947. extern int afs_set_page_dirty(struct page *);
  948. extern int afs_write_begin(struct file *file, struct address_space *mapping,
  949. loff_t pos, unsigned len, unsigned flags,
  950. struct page **pagep, void **fsdata);
  951. extern int afs_write_end(struct file *file, struct address_space *mapping,
  952. loff_t pos, unsigned len, unsigned copied,
  953. struct page *page, void *fsdata);
  954. extern int afs_writepage(struct page *, struct writeback_control *);
  955. extern int afs_writepages(struct address_space *, struct writeback_control *);
  956. extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
  957. extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
  958. extern int afs_fsync(struct file *, loff_t, loff_t, int);
  959. extern int afs_page_mkwrite(struct vm_fault *);
  960. extern void afs_prune_wb_keys(struct afs_vnode *);
  961. extern int afs_launder_page(struct page *);
  962. /*
  963. * xattr.c
  964. */
  965. extern const struct xattr_handler *afs_xattr_handlers[];
  966. extern ssize_t afs_listxattr(struct dentry *, char *, size_t);
  967. /*
  968. * Miscellaneous inline functions.
  969. */
  970. static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
  971. {
  972. return container_of(inode, struct afs_vnode, vfs_inode);
  973. }
  974. static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
  975. {
  976. return &vnode->vfs_inode;
  977. }
  978. static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc,
  979. struct afs_vnode *vnode,
  980. unsigned int cb_break)
  981. {
  982. if (fc->ac.error == 0)
  983. afs_cache_permit(vnode, fc->key, cb_break);
  984. }
  985. static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc,
  986. struct afs_vnode *vnode)
  987. {
  988. if (fc->ac.error == -ENOENT) {
  989. set_bit(AFS_VNODE_DELETED, &vnode->flags);
  990. afs_break_callback(vnode);
  991. }
  992. }
  993. /*****************************************************************************/
  994. /*
  995. * debug tracing
  996. */
  997. extern unsigned afs_debug;
  998. #define dbgprintk(FMT,...) \
  999. printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
  1000. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1001. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1002. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  1003. #if defined(__KDEBUG)
  1004. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  1005. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  1006. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  1007. #elif defined(CONFIG_AFS_DEBUG)
  1008. #define AFS_DEBUG_KENTER 0x01
  1009. #define AFS_DEBUG_KLEAVE 0x02
  1010. #define AFS_DEBUG_KDEBUG 0x04
  1011. #define _enter(FMT,...) \
  1012. do { \
  1013. if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
  1014. kenter(FMT,##__VA_ARGS__); \
  1015. } while (0)
  1016. #define _leave(FMT,...) \
  1017. do { \
  1018. if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
  1019. kleave(FMT,##__VA_ARGS__); \
  1020. } while (0)
  1021. #define _debug(FMT,...) \
  1022. do { \
  1023. if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
  1024. kdebug(FMT,##__VA_ARGS__); \
  1025. } while (0)
  1026. #else
  1027. #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1028. #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1029. #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
  1030. #endif
  1031. /*
  1032. * debug assertion checking
  1033. */
  1034. #if 1 // defined(__KDEBUGALL)
  1035. #define ASSERT(X) \
  1036. do { \
  1037. if (unlikely(!(X))) { \
  1038. printk(KERN_ERR "\n"); \
  1039. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1040. BUG(); \
  1041. } \
  1042. } while(0)
  1043. #define ASSERTCMP(X, OP, Y) \
  1044. do { \
  1045. if (unlikely(!((X) OP (Y)))) { \
  1046. printk(KERN_ERR "\n"); \
  1047. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1048. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  1049. (unsigned long)(X), (unsigned long)(Y)); \
  1050. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  1051. (unsigned long)(X), (unsigned long)(Y)); \
  1052. BUG(); \
  1053. } \
  1054. } while(0)
  1055. #define ASSERTRANGE(L, OP1, N, OP2, H) \
  1056. do { \
  1057. if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
  1058. printk(KERN_ERR "\n"); \
  1059. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1060. printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
  1061. (unsigned long)(L), (unsigned long)(N), \
  1062. (unsigned long)(H)); \
  1063. printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
  1064. (unsigned long)(L), (unsigned long)(N), \
  1065. (unsigned long)(H)); \
  1066. BUG(); \
  1067. } \
  1068. } while(0)
  1069. #define ASSERTIF(C, X) \
  1070. do { \
  1071. if (unlikely((C) && !(X))) { \
  1072. printk(KERN_ERR "\n"); \
  1073. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1074. BUG(); \
  1075. } \
  1076. } while(0)
  1077. #define ASSERTIFCMP(C, X, OP, Y) \
  1078. do { \
  1079. if (unlikely((C) && !((X) OP (Y)))) { \
  1080. printk(KERN_ERR "\n"); \
  1081. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1082. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  1083. (unsigned long)(X), (unsigned long)(Y)); \
  1084. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  1085. (unsigned long)(X), (unsigned long)(Y)); \
  1086. BUG(); \
  1087. } \
  1088. } while(0)
  1089. #else
  1090. #define ASSERT(X) \
  1091. do { \
  1092. } while(0)
  1093. #define ASSERTCMP(X, OP, Y) \
  1094. do { \
  1095. } while(0)
  1096. #define ASSERTRANGE(L, OP1, N, OP2, H) \
  1097. do { \
  1098. } while(0)
  1099. #define ASSERTIF(C, X) \
  1100. do { \
  1101. } while(0)
  1102. #define ASSERTIFCMP(C, X, OP, Y) \
  1103. do { \
  1104. } while(0)
  1105. #endif /* __KDEBUGALL */