internal.h 50 KB

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