internal.h 42 KB

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