internal.h 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* internal AFS stuff
  3. *
  4. * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include <linux/compiler.h>
  8. #include <linux/kernel.h>
  9. #include <linux/ktime.h>
  10. #include <linux/fs.h>
  11. #include <linux/filelock.h>
  12. #include <linux/pagemap.h>
  13. #include <linux/rxrpc.h>
  14. #include <linux/key.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/sched.h>
  17. #include <linux/fscache.h>
  18. #include <linux/backing-dev.h>
  19. #include <linux/uuid.h>
  20. #include <linux/mm_types.h>
  21. #include <linux/dns_resolver.h>
  22. #include <net/net_namespace.h>
  23. #include <net/netns/generic.h>
  24. #include <net/sock.h>
  25. #include <net/af_rxrpc.h>
  26. #include "afs.h"
  27. #include "afs_vl.h"
  28. #define AFS_CELL_MAX_ADDRS 15
  29. struct pagevec;
  30. struct afs_call;
  31. struct afs_vnode;
  32. struct afs_server_probe;
  33. /*
  34. * Partial file-locking emulation mode. (The problem being that AFS3 only
  35. * allows whole-file locks and no upgrading/downgrading).
  36. */
  37. enum afs_flock_mode {
  38. afs_flock_mode_unset,
  39. afs_flock_mode_local, /* Local locking only */
  40. afs_flock_mode_openafs, /* Don't get server lock for a partial lock */
  41. afs_flock_mode_strict, /* Always get a server lock for a partial lock */
  42. afs_flock_mode_write, /* Get an exclusive server lock for a partial lock */
  43. };
  44. struct afs_fs_context {
  45. bool force; /* T to force cell type */
  46. bool autocell; /* T if set auto mount operation */
  47. bool dyn_root; /* T if dynamic root */
  48. bool no_cell; /* T if the source is "none" (for dynroot) */
  49. enum afs_flock_mode flock_mode; /* Partial file-locking emulation mode */
  50. afs_voltype_t type; /* type of volume requested */
  51. unsigned int volnamesz; /* size of volume name */
  52. const char *volname; /* name of volume to mount */
  53. struct afs_net *net; /* the AFS net namespace stuff */
  54. struct afs_cell *cell; /* cell in which to find volume */
  55. struct afs_volume *volume; /* volume record */
  56. struct key *key; /* key to use for secure mounting */
  57. };
  58. enum afs_call_state {
  59. AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */
  60. AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */
  61. AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */
  62. AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */
  63. AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */
  64. AFS_CALL_SV_REPLYING, /* Server: Replying */
  65. AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */
  66. AFS_CALL_COMPLETE, /* Completed or failed */
  67. };
  68. /*
  69. * Address preferences.
  70. */
  71. struct afs_addr_preference {
  72. union {
  73. struct in_addr ipv4_addr; /* AF_INET address to compare against */
  74. struct in6_addr ipv6_addr; /* AF_INET6 address to compare against */
  75. };
  76. sa_family_t family; /* Which address to use */
  77. u16 prio; /* Priority */
  78. u8 subnet_mask; /* How many bits to compare */
  79. };
  80. struct afs_addr_preference_list {
  81. struct rcu_head rcu;
  82. u16 version; /* Incremented when prefs list changes */
  83. u8 ipv6_off; /* Offset of IPv6 addresses */
  84. u8 nr; /* Number of addresses in total */
  85. u8 max_prefs; /* Number of prefs allocated */
  86. struct afs_addr_preference prefs[] __counted_by(max_prefs);
  87. };
  88. struct afs_address {
  89. struct rxrpc_peer *peer;
  90. short last_error; /* Last error from this address */
  91. u16 prio; /* Address priority */
  92. };
  93. /*
  94. * List of server addresses.
  95. */
  96. struct afs_addr_list {
  97. struct rcu_head rcu;
  98. refcount_t usage;
  99. u32 version; /* Version */
  100. unsigned int debug_id;
  101. unsigned int addr_pref_version; /* Version of address preference list */
  102. unsigned char max_addrs;
  103. unsigned char nr_addrs;
  104. unsigned char preferred; /* Preferred address */
  105. unsigned char nr_ipv4; /* Number of IPv4 addresses */
  106. enum dns_record_source source:8;
  107. enum dns_lookup_status status:8;
  108. unsigned long probe_failed; /* Mask of addrs that failed locally/ICMP */
  109. unsigned long responded; /* Mask of addrs that responded */
  110. struct afs_address addrs[] __counted_by(max_addrs);
  111. #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
  112. };
  113. /*
  114. * a record of an in-progress RxRPC call
  115. */
  116. struct afs_call {
  117. const struct afs_call_type *type; /* type of call */
  118. wait_queue_head_t waitq; /* processes awaiting completion */
  119. struct work_struct async_work; /* async I/O processor */
  120. struct work_struct work; /* actual work processor */
  121. struct work_struct free_work; /* Deferred free processor */
  122. struct rxrpc_call *rxcall; /* RxRPC call handle */
  123. struct rxrpc_peer *peer; /* Remote endpoint */
  124. struct key *key; /* security for this call */
  125. struct afs_net *net; /* The network namespace */
  126. struct afs_server *server; /* The fileserver record if fs op (pins ref) */
  127. struct afs_vlserver *vlserver; /* The vlserver record if vl op */
  128. void *request; /* request data (first part) */
  129. size_t iov_len; /* Size of *iter to be used */
  130. struct iov_iter def_iter; /* Default buffer/data iterator */
  131. struct iov_iter *write_iter; /* Iterator defining write to be made */
  132. struct iov_iter *iter; /* Iterator currently in use */
  133. union { /* Convenience for ->def_iter */
  134. struct kvec kvec[1];
  135. struct bio_vec bvec[1];
  136. };
  137. void *buffer; /* reply receive buffer */
  138. union {
  139. struct afs_endpoint_state *probe;
  140. struct afs_addr_list *vl_probe;
  141. struct afs_addr_list *ret_alist;
  142. struct afs_vldb_entry *ret_vldb;
  143. char *ret_str;
  144. };
  145. struct afs_fid fid; /* Primary vnode ID (or all zeroes) */
  146. unsigned char probe_index; /* Address in ->probe_alist */
  147. struct afs_operation *op;
  148. unsigned int server_index;
  149. refcount_t ref;
  150. enum afs_call_state state;
  151. spinlock_t state_lock;
  152. int error; /* error code */
  153. u32 abort_code; /* Remote abort ID or 0 */
  154. unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
  155. unsigned request_size; /* size of request data */
  156. unsigned reply_max; /* maximum size of reply */
  157. unsigned count2; /* count used in unmarshalling */
  158. unsigned char unmarshall; /* unmarshalling phase */
  159. bool drop_ref; /* T if need to drop ref for incoming call */
  160. bool need_attention; /* T if RxRPC poked us */
  161. bool async; /* T if asynchronous */
  162. bool upgrade; /* T to request service upgrade */
  163. bool intr; /* T if interruptible */
  164. bool unmarshalling_error; /* T if an unmarshalling error occurred */
  165. bool responded; /* Got a response from the call (may be abort) */
  166. u16 service_id; /* Actual service ID (after upgrade) */
  167. unsigned int debug_id; /* Trace ID */
  168. u32 operation_ID; /* operation ID for an incoming call */
  169. u32 count; /* count for use in unmarshalling */
  170. union { /* place to extract temporary data */
  171. struct {
  172. __be32 tmp_u;
  173. __be32 tmp;
  174. } __attribute__((packed));
  175. __be64 tmp64;
  176. };
  177. ktime_t issue_time; /* Time of issue of operation */
  178. };
  179. struct afs_call_type {
  180. const char *name;
  181. unsigned int op; /* Really enum afs_fs_operation */
  182. /* deliver request or reply data to an call
  183. * - returning an error will cause the call to be aborted
  184. */
  185. int (*deliver)(struct afs_call *call);
  186. /* clean up a call */
  187. void (*destructor)(struct afs_call *call);
  188. /* Work function */
  189. void (*work)(struct work_struct *work);
  190. /* Call done function (gets called immediately on success or failure) */
  191. void (*done)(struct afs_call *call);
  192. };
  193. /*
  194. * Key available for writeback on a file.
  195. */
  196. struct afs_wb_key {
  197. refcount_t usage;
  198. struct key *key;
  199. struct list_head vnode_link; /* Link in vnode->wb_keys */
  200. };
  201. /*
  202. * AFS open file information record. Pointed to by file->private_data.
  203. */
  204. struct afs_file {
  205. struct key *key; /* The key this file was opened with */
  206. struct afs_wb_key *wb; /* Writeback key record for this file */
  207. };
  208. static inline struct key *afs_file_key(struct file *file)
  209. {
  210. struct afs_file *af = file->private_data;
  211. return af->key;
  212. }
  213. /*
  214. * Record of an outstanding read operation on a vnode.
  215. */
  216. struct afs_read {
  217. loff_t pos; /* Where to start reading */
  218. loff_t len; /* How much we're asking for */
  219. loff_t actual_len; /* How much we're actually getting */
  220. loff_t file_size; /* File size returned by server */
  221. struct key *key; /* The key to use to reissue the read */
  222. struct afs_vnode *vnode; /* The file being read into. */
  223. struct netfs_io_subrequest *subreq; /* Fscache helper read request this belongs to */
  224. afs_dataversion_t data_version; /* Version number returned by server */
  225. refcount_t usage;
  226. unsigned int call_debug_id;
  227. unsigned int nr_pages;
  228. int error;
  229. void (*done)(struct afs_read *);
  230. void (*cleanup)(struct afs_read *);
  231. struct iov_iter *iter; /* Iterator representing the buffer */
  232. struct iov_iter def_iter; /* Default iterator */
  233. };
  234. /*
  235. * AFS superblock private data
  236. * - there's one superblock per volume
  237. */
  238. struct afs_super_info {
  239. struct net *net_ns; /* Network namespace */
  240. struct afs_cell *cell; /* The cell in which the volume resides */
  241. struct afs_volume *volume; /* volume record */
  242. enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
  243. bool dyn_root; /* True if dynamic root */
  244. };
  245. static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
  246. {
  247. return sb->s_fs_info;
  248. }
  249. extern struct file_system_type afs_fs_type;
  250. /*
  251. * Set of substitutes for @sys.
  252. */
  253. struct afs_sysnames {
  254. #define AFS_NR_SYSNAME 16
  255. char *subs[AFS_NR_SYSNAME];
  256. refcount_t usage;
  257. unsigned short nr;
  258. char blank[1];
  259. };
  260. /*
  261. * AFS network namespace record.
  262. */
  263. struct afs_net {
  264. struct net *net; /* Backpointer to the owning net namespace */
  265. struct afs_uuid uuid;
  266. bool live; /* F if this namespace is being removed */
  267. /* AF_RXRPC I/O stuff */
  268. struct socket *socket;
  269. struct afs_call *spare_incoming_call;
  270. struct work_struct charge_preallocation_work;
  271. struct mutex socket_mutex;
  272. atomic_t nr_outstanding_calls;
  273. atomic_t nr_superblocks;
  274. /* Cell database */
  275. struct rb_root cells;
  276. struct afs_cell *ws_cell;
  277. struct work_struct cells_manager;
  278. struct timer_list cells_timer;
  279. atomic_t cells_outstanding;
  280. struct rw_semaphore cells_lock;
  281. struct mutex cells_alias_lock;
  282. struct mutex proc_cells_lock;
  283. struct hlist_head proc_cells;
  284. /* Known servers. Theoretically each fileserver can only be in one
  285. * cell, but in practice, people create aliases and subsets and there's
  286. * no easy way to distinguish them.
  287. */
  288. seqlock_t fs_lock; /* For fs_servers, fs_probe_*, fs_proc */
  289. struct rb_root fs_servers; /* afs_server (by server UUID or address) */
  290. struct list_head fs_probe_fast; /* List of afs_server to probe at 30s intervals */
  291. struct list_head fs_probe_slow; /* List of afs_server to probe at 5m intervals */
  292. struct hlist_head fs_proc; /* procfs servers list */
  293. struct hlist_head fs_addresses; /* afs_server (by lowest IPv6 addr) */
  294. seqlock_t fs_addr_lock; /* For fs_addresses[46] */
  295. struct work_struct fs_manager;
  296. struct timer_list fs_timer;
  297. struct work_struct fs_prober;
  298. struct timer_list fs_probe_timer;
  299. atomic_t servers_outstanding;
  300. /* File locking renewal management */
  301. struct mutex lock_manager_mutex;
  302. /* Misc */
  303. struct super_block *dynroot_sb; /* Dynamic root mount superblock */
  304. struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */
  305. struct afs_sysnames *sysnames;
  306. rwlock_t sysnames_lock;
  307. struct afs_addr_preference_list __rcu *address_prefs;
  308. u16 address_pref_version;
  309. /* Statistics counters */
  310. atomic_t n_lookup; /* Number of lookups done */
  311. atomic_t n_reval; /* Number of dentries needing revalidation */
  312. atomic_t n_inval; /* Number of invalidations by the server */
  313. atomic_t n_relpg; /* Number of invalidations by release_folio */
  314. atomic_t n_read_dir; /* Number of directory pages read */
  315. atomic_t n_dir_cr; /* Number of directory entry creation edits */
  316. atomic_t n_dir_rm; /* Number of directory entry removal edits */
  317. atomic_t n_stores; /* Number of store ops */
  318. atomic_long_t n_store_bytes; /* Number of bytes stored */
  319. atomic_long_t n_fetch_bytes; /* Number of bytes fetched */
  320. atomic_t n_fetches; /* Number of data fetch ops */
  321. };
  322. extern const char afs_init_sysname[];
  323. enum afs_cell_state {
  324. AFS_CELL_UNSET,
  325. AFS_CELL_ACTIVATING,
  326. AFS_CELL_ACTIVE,
  327. AFS_CELL_DEACTIVATING,
  328. AFS_CELL_INACTIVE,
  329. AFS_CELL_FAILED,
  330. AFS_CELL_REMOVED,
  331. };
  332. /*
  333. * AFS cell record.
  334. *
  335. * This is a tricky concept to get right as it is possible to create aliases
  336. * simply by pointing AFSDB/SRV records for two names at the same set of VL
  337. * servers; it is also possible to do things like setting up two sets of VL
  338. * servers, one of which provides a superset of the volumes provided by the
  339. * other (for internal/external division, for example).
  340. *
  341. * Cells only exist in the sense that (a) a cell's name maps to a set of VL
  342. * servers and (b) a cell's name is used by the client to select the key to use
  343. * for authentication and encryption. The cell name is not typically used in
  344. * the protocol.
  345. *
  346. * Two cells are determined to be aliases if they have an explicit alias (YFS
  347. * only), share any VL servers in common or have at least one volume in common.
  348. * "In common" means that the address list of the VL servers or the fileservers
  349. * share at least one endpoint.
  350. */
  351. struct afs_cell {
  352. union {
  353. struct rcu_head rcu;
  354. struct rb_node net_node; /* Node in net->cells */
  355. };
  356. struct afs_net *net;
  357. struct afs_cell *alias_of; /* The cell this is an alias of */
  358. struct afs_volume *root_volume; /* The root.cell volume if there is one */
  359. struct key *anonymous_key; /* anonymous user key for this cell */
  360. struct work_struct manager; /* Manager for init/deinit/dns */
  361. struct hlist_node proc_link; /* /proc cell list link */
  362. time64_t dns_expiry; /* Time AFSDB/SRV record expires */
  363. time64_t last_inactive; /* Time of last drop of usage count */
  364. refcount_t ref; /* Struct refcount */
  365. atomic_t active; /* Active usage counter */
  366. unsigned long flags;
  367. #define AFS_CELL_FL_NO_GC 0 /* The cell was added manually, don't auto-gc */
  368. #define AFS_CELL_FL_DO_LOOKUP 1 /* DNS lookup requested */
  369. #define AFS_CELL_FL_CHECK_ALIAS 2 /* Need to check for aliases */
  370. enum afs_cell_state state;
  371. short error;
  372. enum dns_record_source dns_source:8; /* Latest source of data from lookup */
  373. enum dns_lookup_status dns_status:8; /* Latest status of data from lookup */
  374. unsigned int dns_lookup_count; /* Counter of DNS lookups */
  375. unsigned int debug_id;
  376. /* The volumes belonging to this cell */
  377. struct rw_semaphore vs_lock; /* Lock for server->volumes */
  378. struct rb_root volumes; /* Tree of volumes on this server */
  379. struct hlist_head proc_volumes; /* procfs volume list */
  380. seqlock_t volume_lock; /* For volumes */
  381. /* Active fileserver interaction state. */
  382. struct rb_root fs_servers; /* afs_server (by server UUID) */
  383. seqlock_t fs_lock; /* For fs_servers */
  384. /* VL server list. */
  385. rwlock_t vl_servers_lock; /* Lock on vl_servers */
  386. struct afs_vlserver_list __rcu *vl_servers;
  387. u8 name_len; /* Length of name */
  388. char *name; /* Cell name, case-flattened and NUL-padded */
  389. };
  390. /*
  391. * Volume Location server record.
  392. */
  393. struct afs_vlserver {
  394. struct rcu_head rcu;
  395. struct afs_addr_list __rcu *addresses; /* List of addresses for this VL server */
  396. unsigned long flags;
  397. #define AFS_VLSERVER_FL_PROBED 0 /* The VL server has been probed */
  398. #define AFS_VLSERVER_FL_PROBING 1 /* VL server is being probed */
  399. #define AFS_VLSERVER_FL_IS_YFS 2 /* Server is YFS not AFS */
  400. #define AFS_VLSERVER_FL_RESPONDING 3 /* VL server is responding */
  401. rwlock_t lock; /* Lock on addresses */
  402. refcount_t ref;
  403. unsigned int rtt; /* Server's current RTT in uS */
  404. unsigned int debug_id;
  405. /* Probe state */
  406. wait_queue_head_t probe_wq;
  407. atomic_t probe_outstanding;
  408. spinlock_t probe_lock;
  409. struct {
  410. unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */
  411. u32 abort_code;
  412. short error;
  413. unsigned short flags;
  414. #define AFS_VLSERVER_PROBE_RESPONDED 0x01 /* At least once response (may be abort) */
  415. #define AFS_VLSERVER_PROBE_IS_YFS 0x02 /* The peer appears to be YFS */
  416. #define AFS_VLSERVER_PROBE_NOT_YFS 0x04 /* The peer appears not to be YFS */
  417. #define AFS_VLSERVER_PROBE_LOCAL_FAILURE 0x08 /* A local failure prevented a probe */
  418. } probe;
  419. u16 service_id; /* Service ID we're using */
  420. u16 port;
  421. u16 name_len; /* Length of name */
  422. char name[]; /* Server name, case-flattened */
  423. };
  424. /*
  425. * Weighted list of Volume Location servers.
  426. */
  427. struct afs_vlserver_entry {
  428. u16 priority; /* Preference (as SRV) */
  429. u16 weight; /* Weight (as SRV) */
  430. enum dns_record_source source:8;
  431. enum dns_lookup_status status:8;
  432. struct afs_vlserver *server;
  433. };
  434. struct afs_vlserver_list {
  435. struct rcu_head rcu;
  436. refcount_t ref;
  437. u8 nr_servers;
  438. u8 index; /* Server currently in use */
  439. u8 preferred; /* Preferred server */
  440. enum dns_record_source source:8;
  441. enum dns_lookup_status status:8;
  442. rwlock_t lock;
  443. struct afs_vlserver_entry servers[];
  444. };
  445. /*
  446. * Cached VLDB entry.
  447. *
  448. * This is pointed to by cell->vldb_entries, indexed by name.
  449. */
  450. struct afs_vldb_entry {
  451. afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */
  452. unsigned long flags;
  453. #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */
  454. #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */
  455. #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */
  456. #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */
  457. #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */
  458. uuid_t fs_server[AFS_NMAXNSERVERS];
  459. u32 addr_version[AFS_NMAXNSERVERS]; /* Registration change counters */
  460. u8 fs_mask[AFS_NMAXNSERVERS];
  461. #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
  462. #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
  463. #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
  464. u8 vlsf_flags[AFS_NMAXNSERVERS];
  465. short error;
  466. u8 nr_servers; /* Number of server records */
  467. u8 name_len;
  468. u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
  469. };
  470. /*
  471. * Fileserver endpoint state. The records the addresses of a fileserver's
  472. * endpoints and the state and result of a round of probing on them. This
  473. * allows the rotation algorithm to access those results without them being
  474. * erased by a subsequent round of probing.
  475. */
  476. struct afs_endpoint_state {
  477. struct rcu_head rcu;
  478. struct afs_addr_list *addresses; /* The addresses being probed */
  479. unsigned long responsive_set; /* Bitset of responsive endpoints */
  480. unsigned long failed_set; /* Bitset of endpoints we failed to probe */
  481. refcount_t ref;
  482. unsigned int server_id; /* Debug ID of server */
  483. unsigned int probe_seq; /* Probe sequence (from server::probe_counter) */
  484. atomic_t nr_probing; /* Number of outstanding probes */
  485. unsigned int rtt; /* Best RTT in uS (or UINT_MAX) */
  486. s32 abort_code;
  487. short error;
  488. unsigned long flags;
  489. #define AFS_ESTATE_RESPONDED 0 /* Set if the server responded */
  490. #define AFS_ESTATE_SUPERSEDED 1 /* Set if this record has been superseded */
  491. #define AFS_ESTATE_IS_YFS 2 /* Set if probe upgraded to YFS */
  492. #define AFS_ESTATE_NOT_YFS 3 /* Set if probe didn't upgrade to YFS */
  493. #define AFS_ESTATE_LOCAL_FAILURE 4 /* Set if there was a local failure (eg. ENOMEM) */
  494. };
  495. /*
  496. * Record of fileserver with which we're actively communicating.
  497. */
  498. struct afs_server {
  499. struct rcu_head rcu;
  500. union {
  501. uuid_t uuid; /* Server ID */
  502. struct afs_uuid _uuid;
  503. };
  504. struct afs_cell *cell; /* Cell to which belongs (pins ref) */
  505. struct rb_node uuid_rb; /* Link in net->fs_servers */
  506. struct afs_server __rcu *uuid_next; /* Next server with same UUID */
  507. struct afs_server *uuid_prev; /* Previous server with same UUID */
  508. struct list_head probe_link; /* Link in net->fs_probe_list */
  509. struct hlist_node addr_link; /* Link in net->fs_addresses6 */
  510. struct hlist_node proc_link; /* Link in net->fs_proc */
  511. struct list_head volumes; /* RCU list of afs_server_entry objects */
  512. struct afs_server *gc_next; /* Next server in manager's list */
  513. time64_t unuse_time; /* Time at which last unused */
  514. unsigned long flags;
  515. #define AFS_SERVER_FL_RESPONDING 0 /* The server is responding */
  516. #define AFS_SERVER_FL_UPDATING 1
  517. #define AFS_SERVER_FL_NEEDS_UPDATE 2 /* Fileserver address list is out of date */
  518. #define AFS_SERVER_FL_NOT_READY 4 /* The record is not ready for use */
  519. #define AFS_SERVER_FL_NOT_FOUND 5 /* VL server says no such server */
  520. #define AFS_SERVER_FL_VL_FAIL 6 /* Failed to access VL server */
  521. #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */
  522. #define AFS_SERVER_FL_IS_YFS 16 /* Server is YFS not AFS */
  523. #define AFS_SERVER_FL_NO_IBULK 17 /* Fileserver doesn't support FS.InlineBulkStatus */
  524. #define AFS_SERVER_FL_NO_RM2 18 /* Fileserver doesn't support YFS.RemoveFile2 */
  525. #define AFS_SERVER_FL_HAS_FS64 19 /* Fileserver supports FS.{Fetch,Store}Data64 */
  526. refcount_t ref; /* Object refcount */
  527. atomic_t active; /* Active user count */
  528. u32 addr_version; /* Address list version */
  529. u16 service_id; /* Service ID we're using. */
  530. unsigned int rtt; /* Server's current RTT in uS */
  531. unsigned int debug_id; /* Debugging ID for traces */
  532. /* file service access */
  533. rwlock_t fs_lock; /* access lock */
  534. /* Probe state */
  535. struct afs_endpoint_state __rcu *endpoint_state; /* Latest endpoint/probe state */
  536. unsigned long probed_at; /* Time last probe was dispatched (jiffies) */
  537. wait_queue_head_t probe_wq;
  538. unsigned int probe_counter; /* Number of probes issued */
  539. spinlock_t probe_lock;
  540. };
  541. enum afs_ro_replicating {
  542. AFS_RO_NOT_REPLICATING, /* Not doing replication */
  543. AFS_RO_REPLICATING_USE_OLD, /* Replicating; use old version */
  544. AFS_RO_REPLICATING_USE_NEW, /* Replicating; switch to new version */
  545. } __mode(byte);
  546. /*
  547. * Replaceable volume server list.
  548. */
  549. struct afs_server_entry {
  550. struct afs_server *server;
  551. struct afs_volume *volume;
  552. struct list_head slink; /* Link in server->volumes */
  553. time64_t cb_expires_at; /* Time at which volume-level callback expires */
  554. unsigned long flags;
  555. #define AFS_SE_EXCLUDED 0 /* Set if server is to be excluded in rotation */
  556. #define AFS_SE_VOLUME_OFFLINE 1 /* Set if volume offline notice given */
  557. #define AFS_SE_VOLUME_BUSY 2 /* Set if volume busy notice given */
  558. };
  559. struct afs_server_list {
  560. struct rcu_head rcu;
  561. refcount_t usage;
  562. bool attached; /* T if attached to servers */
  563. enum afs_ro_replicating ro_replicating; /* RW->RO update (probably) in progress */
  564. unsigned char nr_servers;
  565. unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */
  566. unsigned int seq; /* Set to ->servers_seq when installed */
  567. rwlock_t lock;
  568. struct afs_server_entry servers[];
  569. };
  570. /*
  571. * Live AFS volume management.
  572. */
  573. struct afs_volume {
  574. struct rcu_head rcu;
  575. afs_volid_t vid; /* The volume ID of this volume */
  576. afs_volid_t vids[AFS_MAXTYPES]; /* All associated volume IDs */
  577. refcount_t ref;
  578. time64_t update_at; /* Time at which to next update */
  579. struct afs_cell *cell; /* Cell to which belongs (pins ref) */
  580. struct rb_node cell_node; /* Link in cell->volumes */
  581. struct hlist_node proc_link; /* Link in cell->proc_volumes */
  582. struct super_block __rcu *sb; /* Superblock on which inodes reside */
  583. struct work_struct destructor; /* Deferred destructor */
  584. unsigned long flags;
  585. #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */
  586. #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */
  587. #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */
  588. #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */
  589. #define AFS_VOLUME_MAYBE_NO_IBULK 4 /* - T if some servers don't have InlineBulkStatus */
  590. #define AFS_VOLUME_RM_TREE 5 /* - Set if volume removed from cell->volumes */
  591. #ifdef CONFIG_AFS_FSCACHE
  592. struct fscache_volume *cache; /* Caching cookie */
  593. #endif
  594. struct afs_server_list __rcu *servers; /* List of servers on which volume resides */
  595. rwlock_t servers_lock; /* Lock for ->servers */
  596. unsigned int servers_seq; /* Incremented each time ->servers changes */
  597. /* RO release tracking */
  598. struct mutex volsync_lock; /* Time/state evaluation lock */
  599. time64_t creation_time; /* Volume creation time (or TIME64_MIN) */
  600. time64_t update_time; /* Volume update time (or TIME64_MIN) */
  601. /* Callback management */
  602. struct mutex cb_check_lock; /* Lock to control race to check after v_break */
  603. time64_t cb_expires_at; /* Earliest volume callback expiry time */
  604. atomic_t cb_ro_snapshot; /* RO volume update-from-snapshot counter */
  605. atomic_t cb_v_break; /* Volume-break event counter. */
  606. atomic_t cb_v_check; /* Volume-break has-been-checked counter. */
  607. atomic_t cb_scrub; /* Scrub-all-data event counter. */
  608. rwlock_t cb_v_break_lock;
  609. struct rw_semaphore open_mmaps_lock;
  610. struct list_head open_mmaps; /* List of vnodes that are mmapped */
  611. afs_voltype_t type; /* type of volume */
  612. char type_force; /* force volume type (suppress R/O -> R/W) */
  613. u8 name_len;
  614. u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */
  615. };
  616. enum afs_lock_state {
  617. AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */
  618. AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */
  619. AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */
  620. AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */
  621. AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */
  622. AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */
  623. AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */
  624. AFS_VNODE_LOCK_DELETED, /* The vnode has been deleted whilst we have a lock */
  625. };
  626. /*
  627. * AFS inode private data.
  628. *
  629. * Note that afs_alloc_inode() *must* reset anything that could incorrectly
  630. * leak from one inode to another.
  631. */
  632. struct afs_vnode {
  633. struct netfs_inode netfs; /* Netfslib context and vfs inode */
  634. struct afs_volume *volume; /* volume on which vnode resides */
  635. struct afs_fid fid; /* the file identifier for this inode */
  636. struct afs_file_status status; /* AFS status info for this file */
  637. afs_dataversion_t invalid_before; /* Child dentries are invalid before this */
  638. struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */
  639. struct mutex io_lock; /* Lock for serialising I/O on this mutex */
  640. struct rw_semaphore validate_lock; /* lock for validating this vnode */
  641. struct rw_semaphore rmdir_lock; /* Lock for rmdir vs sillyrename */
  642. struct key *silly_key; /* Silly rename key */
  643. spinlock_t wb_lock; /* lock for wb_keys */
  644. spinlock_t lock; /* waitqueue/flags lock */
  645. unsigned long flags;
  646. #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */
  647. #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */
  648. #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */
  649. #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */
  650. #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
  651. #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
  652. #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
  653. #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
  654. #define AFS_VNODE_SILLY_DELETED 9 /* Set if file has been silly-deleted */
  655. #define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
  656. struct list_head wb_keys; /* List of keys available for writeback */
  657. struct list_head pending_locks; /* locks waiting to be granted */
  658. struct list_head granted_locks; /* locks granted on this file */
  659. struct delayed_work lock_work; /* work to be done in locking */
  660. struct key *lock_key; /* Key to be used in lock ops */
  661. ktime_t locked_at; /* Time at which lock obtained */
  662. enum afs_lock_state lock_state : 8;
  663. afs_lock_type_t lock_type : 8;
  664. /* outstanding callback notification on this file */
  665. struct work_struct cb_work; /* Work for mmap'd files */
  666. struct list_head cb_mmap_link; /* Link in cell->fs_open_mmaps */
  667. void *cb_server; /* Server with callback/filelock */
  668. atomic_t cb_nr_mmap; /* Number of mmaps */
  669. unsigned int cb_ro_snapshot; /* RO volume release counter on ->volume */
  670. unsigned int cb_scrub; /* Scrub counter on ->volume */
  671. unsigned int cb_break; /* Break counter on vnode */
  672. unsigned int cb_v_check; /* Break check counter on ->volume */
  673. seqlock_t cb_lock; /* Lock for ->cb_server, ->status, ->cb_*break */
  674. atomic64_t cb_expires_at; /* time at which callback expires */
  675. #define AFS_NO_CB_PROMISE TIME64_MIN
  676. };
  677. static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode)
  678. {
  679. #ifdef CONFIG_AFS_FSCACHE
  680. return netfs_i_cookie(&vnode->netfs);
  681. #else
  682. return NULL;
  683. #endif
  684. }
  685. static inline void afs_vnode_set_cache(struct afs_vnode *vnode,
  686. struct fscache_cookie *cookie)
  687. {
  688. #ifdef CONFIG_AFS_FSCACHE
  689. vnode->netfs.cache = cookie;
  690. if (cookie)
  691. mapping_set_release_always(vnode->netfs.inode.i_mapping);
  692. #endif
  693. }
  694. /*
  695. * cached security record for one user's attempt to access a vnode
  696. */
  697. struct afs_permit {
  698. struct key *key; /* RxRPC ticket holding a security context */
  699. afs_access_t access; /* CallerAccess value for this key */
  700. };
  701. /*
  702. * Immutable cache of CallerAccess records from attempts to access vnodes.
  703. * These may be shared between multiple vnodes.
  704. */
  705. struct afs_permits {
  706. struct rcu_head rcu;
  707. struct hlist_node hash_node; /* Link in hash */
  708. unsigned long h; /* Hash value for this permit list */
  709. refcount_t usage;
  710. unsigned short nr_permits; /* Number of records */
  711. bool invalidated; /* Invalidated due to key change */
  712. struct afs_permit permits[] __counted_by(nr_permits); /* List of permits sorted by key pointer */
  713. };
  714. /*
  715. * Error prioritisation and accumulation.
  716. */
  717. struct afs_error {
  718. s32 abort_code; /* Cumulative abort code */
  719. short error; /* Cumulative error */
  720. bool responded; /* T if server responded */
  721. bool aborted; /* T if ->error is from an abort */
  722. };
  723. /*
  724. * Cursor for iterating over a set of volume location servers.
  725. */
  726. struct afs_vl_cursor {
  727. struct afs_cell *cell; /* The cell we're querying */
  728. struct afs_vlserver_list *server_list; /* Current server list (pins ref) */
  729. struct afs_vlserver *server; /* Server on which this resides */
  730. struct afs_addr_list *alist; /* Current address list (pins ref) */
  731. struct key *key; /* Key for the server */
  732. unsigned long untried_servers; /* Bitmask of untried servers */
  733. unsigned long addr_tried; /* Tried addresses */
  734. struct afs_error cumul_error; /* Cumulative error */
  735. unsigned int debug_id;
  736. s32 call_abort_code;
  737. short call_error; /* Error from single call */
  738. short server_index; /* Current server */
  739. signed char addr_index; /* Current address */
  740. unsigned short flags;
  741. #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */
  742. #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */
  743. #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */
  744. short nr_iterations; /* Number of server iterations */
  745. bool call_responded; /* T if the current address responded */
  746. };
  747. /*
  748. * Fileserver state tracking for an operation. An array of these is kept,
  749. * indexed by server index.
  750. */
  751. struct afs_server_state {
  752. /* Tracking of fileserver probe state. Other operations may interfere
  753. * by probing a fileserver when accessing other volumes.
  754. */
  755. unsigned int probe_seq;
  756. unsigned long untried_addrs; /* Addresses we haven't tried yet */
  757. struct wait_queue_entry probe_waiter;
  758. struct afs_endpoint_state *endpoint_state; /* Endpoint state being monitored */
  759. };
  760. /*
  761. * Fileserver operation methods.
  762. */
  763. struct afs_operation_ops {
  764. void (*issue_afs_rpc)(struct afs_operation *op);
  765. void (*issue_yfs_rpc)(struct afs_operation *op);
  766. void (*success)(struct afs_operation *op);
  767. void (*aborted)(struct afs_operation *op);
  768. void (*failed)(struct afs_operation *op);
  769. void (*edit_dir)(struct afs_operation *op);
  770. void (*put)(struct afs_operation *op);
  771. };
  772. struct afs_vnode_param {
  773. struct afs_vnode *vnode;
  774. struct afs_fid fid; /* Fid to access */
  775. struct afs_status_cb scb; /* Returned status and callback promise */
  776. afs_dataversion_t dv_before; /* Data version before the call */
  777. unsigned int cb_break_before; /* cb_break before the call */
  778. u8 dv_delta; /* Expected change in data version */
  779. bool put_vnode:1; /* T if we have a ref on the vnode */
  780. bool need_io_lock:1; /* T if we need the I/O lock on this */
  781. bool update_ctime:1; /* Need to update the ctime */
  782. bool set_size:1; /* Must update i_size */
  783. bool op_unlinked:1; /* True if file was unlinked by op */
  784. bool speculative:1; /* T if speculative status fetch (no vnode lock) */
  785. bool modification:1; /* Set if the content gets modified */
  786. };
  787. /*
  788. * Fileserver operation wrapper, handling server and address rotation
  789. * asynchronously. May make simultaneous calls to multiple servers.
  790. */
  791. struct afs_operation {
  792. struct afs_net *net; /* Network namespace */
  793. struct key *key; /* Key for the cell */
  794. const struct afs_call_type *type; /* Type of call done */
  795. const struct afs_operation_ops *ops;
  796. /* Parameters/results for the operation */
  797. struct afs_volume *volume; /* Volume being accessed */
  798. struct afs_vnode_param file[2];
  799. struct afs_vnode_param *more_files;
  800. struct afs_volsync pre_volsync; /* Volsync before op */
  801. struct afs_volsync volsync; /* Volsync returned by op */
  802. struct dentry *dentry; /* Dentry to be altered */
  803. struct dentry *dentry_2; /* Second dentry to be altered */
  804. struct timespec64 mtime; /* Modification time to record */
  805. struct timespec64 ctime; /* Change time to set */
  806. struct afs_error cumul_error; /* Cumulative error */
  807. short nr_files; /* Number of entries in file[], more_files */
  808. unsigned int debug_id;
  809. unsigned int cb_v_break; /* Volume break counter before op */
  810. union {
  811. struct {
  812. int which; /* Which ->file[] to fetch for */
  813. } fetch_status;
  814. struct {
  815. int reason; /* enum afs_edit_dir_reason */
  816. mode_t mode;
  817. const char *symlink;
  818. } create;
  819. struct {
  820. bool need_rehash;
  821. } unlink;
  822. struct {
  823. struct dentry *rehash;
  824. struct dentry *tmp;
  825. bool new_negative;
  826. } rename;
  827. struct {
  828. struct afs_read *req;
  829. } fetch;
  830. struct {
  831. afs_lock_type_t type;
  832. } lock;
  833. struct {
  834. struct iov_iter *write_iter;
  835. loff_t pos;
  836. loff_t size;
  837. loff_t i_size;
  838. } store;
  839. struct {
  840. struct iattr *attr;
  841. loff_t old_i_size;
  842. } setattr;
  843. struct afs_acl *acl;
  844. struct yfs_acl *yacl;
  845. struct {
  846. struct afs_volume_status vs;
  847. struct kstatfs *buf;
  848. } volstatus;
  849. };
  850. /* Fileserver iteration state */
  851. struct afs_server_list *server_list; /* Current server list (pins ref) */
  852. struct afs_server *server; /* Server we're using (ref pinned by server_list) */
  853. struct afs_endpoint_state *estate; /* Current endpoint state (doesn't pin ref) */
  854. struct afs_server_state *server_states; /* States of the servers involved */
  855. struct afs_call *call;
  856. unsigned long untried_servers; /* Bitmask of untried servers */
  857. unsigned long addr_tried; /* Tried addresses */
  858. s32 call_abort_code; /* Abort code from single call */
  859. short call_error; /* Error from single call */
  860. short server_index; /* Current server */
  861. short nr_iterations; /* Number of server iterations */
  862. signed char addr_index; /* Current address */
  863. bool call_responded; /* T if the current address responded */
  864. unsigned int flags;
  865. #define AFS_OPERATION_STOP 0x0001 /* Set to cease iteration */
  866. #define AFS_OPERATION_VBUSY 0x0002 /* Set if seen VBUSY */
  867. #define AFS_OPERATION_VMOVED 0x0004 /* Set if seen VMOVED */
  868. #define AFS_OPERATION_VNOVOL 0x0008 /* Set if seen VNOVOL */
  869. #define AFS_OPERATION_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */
  870. #define AFS_OPERATION_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */
  871. #define AFS_OPERATION_UNINTR 0x0040 /* Set if op is uninterruptible */
  872. #define AFS_OPERATION_DOWNGRADE 0x0080 /* Set to retry with downgraded opcode */
  873. #define AFS_OPERATION_LOCK_0 0x0100 /* Set if have io_lock on file[0] */
  874. #define AFS_OPERATION_LOCK_1 0x0200 /* Set if have io_lock on file[1] */
  875. #define AFS_OPERATION_TRIED_ALL 0x0400 /* Set if we've tried all the fileservers */
  876. #define AFS_OPERATION_RETRY_SERVER 0x0800 /* Set if we should retry the current server */
  877. #define AFS_OPERATION_DIR_CONFLICT 0x1000 /* Set if we detected a 3rd-party dir change */
  878. };
  879. /*
  880. * Cache auxiliary data.
  881. */
  882. struct afs_vnode_cache_aux {
  883. __be64 data_version;
  884. } __packed;
  885. static inline void afs_set_cache_aux(struct afs_vnode *vnode,
  886. struct afs_vnode_cache_aux *aux)
  887. {
  888. aux->data_version = cpu_to_be64(vnode->status.data_version);
  889. }
  890. static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int flags)
  891. {
  892. struct afs_vnode_cache_aux aux;
  893. afs_set_cache_aux(vnode, &aux);
  894. fscache_invalidate(afs_vnode_cache(vnode), &aux,
  895. i_size_read(&vnode->netfs.inode), flags);
  896. }
  897. #include <trace/events/afs.h>
  898. /*****************************************************************************/
  899. /*
  900. * addr_list.c
  901. */
  902. struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
  903. extern struct afs_addr_list *afs_alloc_addrlist(unsigned int nr);
  904. extern void afs_put_addrlist(struct afs_addr_list *alist, enum afs_alist_trace reason);
  905. extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *,
  906. const char *, size_t, char,
  907. unsigned short, unsigned short);
  908. bool afs_addr_list_same(const struct afs_addr_list *a,
  909. const struct afs_addr_list *b);
  910. extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *);
  911. extern int afs_merge_fs_addr4(struct afs_net *net, struct afs_addr_list *addr,
  912. __be32 xdr, u16 port);
  913. extern int afs_merge_fs_addr6(struct afs_net *net, struct afs_addr_list *addr,
  914. __be32 *xdr, u16 port);
  915. /*
  916. * addr_prefs.c
  917. */
  918. int afs_proc_addr_prefs_write(struct file *file, char *buf, size_t size);
  919. void afs_get_address_preferences_rcu(struct afs_net *net, struct afs_addr_list *alist);
  920. void afs_get_address_preferences(struct afs_net *net, struct afs_addr_list *alist);
  921. /*
  922. * callback.c
  923. */
  924. extern void afs_invalidate_mmap_work(struct work_struct *);
  925. extern void afs_init_callback_state(struct afs_server *);
  926. extern void __afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
  927. extern void afs_break_callback(struct afs_vnode *, enum afs_cb_break_reason);
  928. extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break *);
  929. static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode)
  930. {
  931. return vnode->cb_break + vnode->cb_ro_snapshot + vnode->cb_scrub;
  932. }
  933. static inline bool afs_cb_is_broken(unsigned int cb_break,
  934. const struct afs_vnode *vnode)
  935. {
  936. return cb_break != (vnode->cb_break +
  937. atomic_read(&vnode->volume->cb_ro_snapshot) +
  938. atomic_read(&vnode->volume->cb_scrub));
  939. }
  940. /*
  941. * cell.c
  942. */
  943. extern int afs_cell_init(struct afs_net *, const char *);
  944. extern struct afs_cell *afs_find_cell(struct afs_net *, const char *, unsigned,
  945. enum afs_cell_trace);
  946. extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned,
  947. const char *, bool);
  948. extern struct afs_cell *afs_use_cell(struct afs_cell *, enum afs_cell_trace);
  949. extern void afs_unuse_cell(struct afs_net *, struct afs_cell *, enum afs_cell_trace);
  950. extern struct afs_cell *afs_get_cell(struct afs_cell *, enum afs_cell_trace);
  951. extern void afs_see_cell(struct afs_cell *, enum afs_cell_trace);
  952. extern void afs_put_cell(struct afs_cell *, enum afs_cell_trace);
  953. extern void afs_queue_cell(struct afs_cell *, enum afs_cell_trace);
  954. extern void afs_manage_cells(struct work_struct *);
  955. extern void afs_cells_timer(struct timer_list *);
  956. extern void __net_exit afs_cell_purge(struct afs_net *);
  957. /*
  958. * cmservice.c
  959. */
  960. extern bool afs_cm_incoming_call(struct afs_call *);
  961. /*
  962. * dir.c
  963. */
  964. extern const struct file_operations afs_dir_file_operations;
  965. extern const struct inode_operations afs_dir_inode_operations;
  966. extern const struct address_space_operations afs_dir_aops;
  967. extern const struct dentry_operations afs_fs_dentry_operations;
  968. extern void afs_d_release(struct dentry *);
  969. extern void afs_check_for_remote_deletion(struct afs_operation *);
  970. /*
  971. * dir_edit.c
  972. */
  973. extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *,
  974. enum afs_edit_dir_reason);
  975. extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason);
  976. void afs_edit_dir_update_dotdot(struct afs_vnode *vnode, struct afs_vnode *new_dvnode,
  977. enum afs_edit_dir_reason why);
  978. /*
  979. * dir_silly.c
  980. */
  981. extern int afs_sillyrename(struct afs_vnode *, struct afs_vnode *,
  982. struct dentry *, struct key *);
  983. extern int afs_silly_iput(struct dentry *, struct inode *);
  984. /*
  985. * dynroot.c
  986. */
  987. extern const struct inode_operations afs_dynroot_inode_operations;
  988. extern const struct dentry_operations afs_dynroot_dentry_operations;
  989. extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *);
  990. extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *);
  991. extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *);
  992. extern int afs_dynroot_populate(struct super_block *);
  993. extern void afs_dynroot_depopulate(struct super_block *);
  994. /*
  995. * file.c
  996. */
  997. extern const struct address_space_operations afs_file_aops;
  998. extern const struct address_space_operations afs_symlink_aops;
  999. extern const struct inode_operations afs_file_inode_operations;
  1000. extern const struct file_operations afs_file_operations;
  1001. extern const struct netfs_request_ops afs_req_ops;
  1002. extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);
  1003. extern void afs_put_wb_key(struct afs_wb_key *);
  1004. extern int afs_open(struct inode *, struct file *);
  1005. extern int afs_release(struct inode *, struct file *);
  1006. extern int afs_fetch_data(struct afs_vnode *, struct afs_read *);
  1007. extern struct afs_read *afs_alloc_read(gfp_t);
  1008. extern void afs_put_read(struct afs_read *);
  1009. static inline struct afs_read *afs_get_read(struct afs_read *req)
  1010. {
  1011. refcount_inc(&req->usage);
  1012. return req;
  1013. }
  1014. /*
  1015. * flock.c
  1016. */
  1017. extern struct workqueue_struct *afs_lock_manager;
  1018. extern void afs_lock_op_done(struct afs_call *);
  1019. extern void afs_lock_work(struct work_struct *);
  1020. extern void afs_lock_may_be_available(struct afs_vnode *);
  1021. extern int afs_lock(struct file *, int, struct file_lock *);
  1022. extern int afs_flock(struct file *, int, struct file_lock *);
  1023. /*
  1024. * fsclient.c
  1025. */
  1026. extern void afs_fs_fetch_status(struct afs_operation *);
  1027. extern void afs_fs_fetch_data(struct afs_operation *);
  1028. extern void afs_fs_create_file(struct afs_operation *);
  1029. extern void afs_fs_make_dir(struct afs_operation *);
  1030. extern void afs_fs_remove_file(struct afs_operation *);
  1031. extern void afs_fs_remove_dir(struct afs_operation *);
  1032. extern void afs_fs_link(struct afs_operation *);
  1033. extern void afs_fs_symlink(struct afs_operation *);
  1034. extern void afs_fs_rename(struct afs_operation *);
  1035. extern void afs_fs_store_data(struct afs_operation *);
  1036. extern void afs_fs_setattr(struct afs_operation *);
  1037. extern void afs_fs_get_volume_status(struct afs_operation *);
  1038. extern void afs_fs_set_lock(struct afs_operation *);
  1039. extern void afs_fs_extend_lock(struct afs_operation *);
  1040. extern void afs_fs_release_lock(struct afs_operation *);
  1041. int afs_fs_give_up_all_callbacks(struct afs_net *net, struct afs_server *server,
  1042. struct afs_address *addr, struct key *key);
  1043. bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
  1044. struct afs_endpoint_state *estate, unsigned int addr_index,
  1045. struct key *key);
  1046. extern void afs_fs_inline_bulk_status(struct afs_operation *);
  1047. struct afs_acl {
  1048. u32 size;
  1049. u8 data[] __counted_by(size);
  1050. };
  1051. extern void afs_fs_fetch_acl(struct afs_operation *);
  1052. extern void afs_fs_store_acl(struct afs_operation *);
  1053. /*
  1054. * fs_operation.c
  1055. */
  1056. extern struct afs_operation *afs_alloc_operation(struct key *, struct afs_volume *);
  1057. extern int afs_put_operation(struct afs_operation *);
  1058. extern bool afs_begin_vnode_operation(struct afs_operation *);
  1059. extern void afs_wait_for_operation(struct afs_operation *);
  1060. extern int afs_do_sync_operation(struct afs_operation *);
  1061. static inline void afs_op_set_vnode(struct afs_operation *op, unsigned int n,
  1062. struct afs_vnode *vnode)
  1063. {
  1064. op->file[n].vnode = vnode;
  1065. op->file[n].need_io_lock = true;
  1066. }
  1067. static inline void afs_op_set_fid(struct afs_operation *op, unsigned int n,
  1068. const struct afs_fid *fid)
  1069. {
  1070. op->file[n].fid = *fid;
  1071. }
  1072. /*
  1073. * fs_probe.c
  1074. */
  1075. struct afs_endpoint_state *afs_get_endpoint_state(struct afs_endpoint_state *estate,
  1076. enum afs_estate_trace where);
  1077. void afs_put_endpoint_state(struct afs_endpoint_state *estate, enum afs_estate_trace where);
  1078. extern void afs_fileserver_probe_result(struct afs_call *);
  1079. void afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
  1080. struct afs_addr_list *new_addrs, struct key *key);
  1081. int afs_wait_for_fs_probes(struct afs_operation *op, struct afs_server_state *states, bool intr);
  1082. extern void afs_probe_fileserver(struct afs_net *, struct afs_server *);
  1083. extern void afs_fs_probe_dispatcher(struct work_struct *);
  1084. int afs_wait_for_one_fs_probe(struct afs_server *server, struct afs_endpoint_state *estate,
  1085. unsigned long exclude, bool is_intr);
  1086. extern void afs_fs_probe_cleanup(struct afs_net *);
  1087. /*
  1088. * inode.c
  1089. */
  1090. extern const struct afs_operation_ops afs_fetch_status_operation;
  1091. extern void afs_vnode_commit_status(struct afs_operation *, struct afs_vnode_param *);
  1092. extern int afs_fetch_status(struct afs_vnode *, struct key *, bool, afs_access_t *);
  1093. extern int afs_ilookup5_test_by_fid(struct inode *, void *);
  1094. extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool);
  1095. extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);
  1096. extern struct inode *afs_root_iget(struct super_block *, struct key *);
  1097. extern int afs_getattr(struct mnt_idmap *idmap, const struct path *,
  1098. struct kstat *, u32, unsigned int);
  1099. extern int afs_setattr(struct mnt_idmap *idmap, struct dentry *, struct iattr *);
  1100. extern void afs_evict_inode(struct inode *);
  1101. extern int afs_drop_inode(struct inode *);
  1102. /*
  1103. * main.c
  1104. */
  1105. extern struct workqueue_struct *afs_wq;
  1106. extern int afs_net_id;
  1107. static inline struct afs_net *afs_net(struct net *net)
  1108. {
  1109. return net_generic(net, afs_net_id);
  1110. }
  1111. static inline struct afs_net *afs_sb2net(struct super_block *sb)
  1112. {
  1113. return afs_net(AFS_FS_S(sb)->net_ns);
  1114. }
  1115. static inline struct afs_net *afs_d2net(struct dentry *dentry)
  1116. {
  1117. return afs_sb2net(dentry->d_sb);
  1118. }
  1119. static inline struct afs_net *afs_i2net(struct inode *inode)
  1120. {
  1121. return afs_sb2net(inode->i_sb);
  1122. }
  1123. static inline struct afs_net *afs_v2net(struct afs_vnode *vnode)
  1124. {
  1125. return afs_i2net(&vnode->netfs.inode);
  1126. }
  1127. static inline struct afs_net *afs_sock2net(struct sock *sk)
  1128. {
  1129. return net_generic(sock_net(sk), afs_net_id);
  1130. }
  1131. static inline void __afs_stat(atomic_t *s)
  1132. {
  1133. atomic_inc(s);
  1134. }
  1135. #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n)
  1136. /*
  1137. * misc.c
  1138. */
  1139. extern int afs_abort_to_error(u32);
  1140. extern void afs_prioritise_error(struct afs_error *, int, u32);
  1141. static inline void afs_op_nomem(struct afs_operation *op)
  1142. {
  1143. op->cumul_error.error = -ENOMEM;
  1144. }
  1145. static inline int afs_op_error(const struct afs_operation *op)
  1146. {
  1147. return op->cumul_error.error;
  1148. }
  1149. static inline s32 afs_op_abort_code(const struct afs_operation *op)
  1150. {
  1151. return op->cumul_error.abort_code;
  1152. }
  1153. static inline int afs_op_set_error(struct afs_operation *op, int error)
  1154. {
  1155. return op->cumul_error.error = error;
  1156. }
  1157. static inline void afs_op_accumulate_error(struct afs_operation *op, int error, s32 abort_code)
  1158. {
  1159. afs_prioritise_error(&op->cumul_error, error, abort_code);
  1160. }
  1161. /*
  1162. * mntpt.c
  1163. */
  1164. extern const struct inode_operations afs_mntpt_inode_operations;
  1165. extern const struct inode_operations afs_autocell_inode_operations;
  1166. extern const struct file_operations afs_mntpt_file_operations;
  1167. extern struct vfsmount *afs_d_automount(struct path *);
  1168. extern void afs_mntpt_kill_timer(void);
  1169. /*
  1170. * proc.c
  1171. */
  1172. #ifdef CONFIG_PROC_FS
  1173. extern int __net_init afs_proc_init(struct afs_net *);
  1174. extern void __net_exit afs_proc_cleanup(struct afs_net *);
  1175. extern int afs_proc_cell_setup(struct afs_cell *);
  1176. extern void afs_proc_cell_remove(struct afs_cell *);
  1177. extern void afs_put_sysnames(struct afs_sysnames *);
  1178. #else
  1179. static inline int afs_proc_init(struct afs_net *net) { return 0; }
  1180. static inline void afs_proc_cleanup(struct afs_net *net) {}
  1181. static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; }
  1182. static inline void afs_proc_cell_remove(struct afs_cell *cell) {}
  1183. static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {}
  1184. #endif
  1185. /*
  1186. * rotate.c
  1187. */
  1188. void afs_clear_server_states(struct afs_operation *op);
  1189. extern bool afs_select_fileserver(struct afs_operation *);
  1190. extern void afs_dump_edestaddrreq(const struct afs_operation *);
  1191. /*
  1192. * rxrpc.c
  1193. */
  1194. extern struct workqueue_struct *afs_async_calls;
  1195. extern int __net_init afs_open_socket(struct afs_net *);
  1196. extern void __net_exit afs_close_socket(struct afs_net *);
  1197. extern void afs_charge_preallocation(struct work_struct *);
  1198. extern void afs_put_call(struct afs_call *);
  1199. void afs_deferred_put_call(struct afs_call *call);
  1200. void afs_make_call(struct afs_call *call, gfp_t gfp);
  1201. void afs_wait_for_call_to_complete(struct afs_call *call);
  1202. extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
  1203. const struct afs_call_type *,
  1204. size_t, size_t);
  1205. extern void afs_flat_call_destructor(struct afs_call *);
  1206. extern void afs_send_empty_reply(struct afs_call *);
  1207. extern void afs_send_simple_reply(struct afs_call *, const void *, size_t);
  1208. extern int afs_extract_data(struct afs_call *, bool);
  1209. extern int afs_protocol_error(struct afs_call *, enum afs_eproto_cause);
  1210. static inline void afs_see_call(struct afs_call *call, enum afs_call_trace why)
  1211. {
  1212. int r = refcount_read(&call->ref);
  1213. trace_afs_call(call->debug_id, why, r,
  1214. atomic_read(&call->net->nr_outstanding_calls),
  1215. __builtin_return_address(0));
  1216. }
  1217. static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
  1218. gfp_t gfp)
  1219. {
  1220. struct afs_addr_list *alist = op->estate->addresses;
  1221. op->call = call;
  1222. op->type = call->type;
  1223. call->op = op;
  1224. call->key = op->key;
  1225. call->intr = !(op->flags & AFS_OPERATION_UNINTR);
  1226. call->peer = rxrpc_kernel_get_peer(alist->addrs[op->addr_index].peer);
  1227. call->service_id = op->server->service_id;
  1228. afs_make_call(call, gfp);
  1229. }
  1230. static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
  1231. {
  1232. call->iov_len = size;
  1233. call->kvec[0].iov_base = buf;
  1234. call->kvec[0].iov_len = size;
  1235. iov_iter_kvec(&call->def_iter, ITER_DEST, call->kvec, 1, size);
  1236. }
  1237. static inline void afs_extract_to_tmp(struct afs_call *call)
  1238. {
  1239. call->iov_len = sizeof(call->tmp);
  1240. afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
  1241. }
  1242. static inline void afs_extract_to_tmp64(struct afs_call *call)
  1243. {
  1244. call->iov_len = sizeof(call->tmp64);
  1245. afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
  1246. }
  1247. static inline void afs_extract_discard(struct afs_call *call, size_t size)
  1248. {
  1249. call->iov_len = size;
  1250. iov_iter_discard(&call->def_iter, ITER_DEST, size);
  1251. }
  1252. static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
  1253. {
  1254. call->iov_len = size;
  1255. afs_extract_begin(call, call->buffer, size);
  1256. }
  1257. static inline int afs_transfer_reply(struct afs_call *call)
  1258. {
  1259. return afs_extract_data(call, false);
  1260. }
  1261. static inline bool afs_check_call_state(struct afs_call *call,
  1262. enum afs_call_state state)
  1263. {
  1264. return READ_ONCE(call->state) == state;
  1265. }
  1266. static inline bool afs_set_call_state(struct afs_call *call,
  1267. enum afs_call_state from,
  1268. enum afs_call_state to)
  1269. {
  1270. bool ok = false;
  1271. spin_lock_bh(&call->state_lock);
  1272. if (call->state == from) {
  1273. call->state = to;
  1274. trace_afs_call_state(call, from, to, 0, 0);
  1275. ok = true;
  1276. }
  1277. spin_unlock_bh(&call->state_lock);
  1278. return ok;
  1279. }
  1280. static inline void afs_set_call_complete(struct afs_call *call,
  1281. int error, u32 remote_abort)
  1282. {
  1283. enum afs_call_state state;
  1284. bool ok = false;
  1285. spin_lock_bh(&call->state_lock);
  1286. state = call->state;
  1287. if (state != AFS_CALL_COMPLETE) {
  1288. call->abort_code = remote_abort;
  1289. call->error = error;
  1290. call->state = AFS_CALL_COMPLETE;
  1291. trace_afs_call_state(call, state, AFS_CALL_COMPLETE,
  1292. error, remote_abort);
  1293. ok = true;
  1294. }
  1295. spin_unlock_bh(&call->state_lock);
  1296. if (ok) {
  1297. trace_afs_call_done(call);
  1298. /* Asynchronous calls have two refs to release - one from the alloc and
  1299. * one queued with the work item - and we can't just deallocate the
  1300. * call because the work item may be queued again.
  1301. */
  1302. if (call->drop_ref)
  1303. afs_put_call(call);
  1304. }
  1305. }
  1306. /*
  1307. * security.c
  1308. */
  1309. extern void afs_put_permits(struct afs_permits *);
  1310. extern void afs_clear_permits(struct afs_vnode *);
  1311. extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int,
  1312. struct afs_status_cb *);
  1313. extern struct key *afs_request_key(struct afs_cell *);
  1314. extern struct key *afs_request_key_rcu(struct afs_cell *);
  1315. extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *);
  1316. extern int afs_permission(struct mnt_idmap *, struct inode *, int);
  1317. extern void __exit afs_clean_up_permit_cache(void);
  1318. /*
  1319. * server.c
  1320. */
  1321. extern spinlock_t afs_server_peer_lock;
  1322. extern struct afs_server *afs_find_server(struct afs_net *, const struct rxrpc_peer *);
  1323. extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *);
  1324. extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *, u32);
  1325. extern struct afs_server *afs_get_server(struct afs_server *, enum afs_server_trace);
  1326. extern struct afs_server *afs_use_server(struct afs_server *, enum afs_server_trace);
  1327. extern void afs_unuse_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
  1328. extern void afs_unuse_server_notime(struct afs_net *, struct afs_server *, enum afs_server_trace);
  1329. extern void afs_put_server(struct afs_net *, struct afs_server *, enum afs_server_trace);
  1330. extern void afs_manage_servers(struct work_struct *);
  1331. extern void afs_servers_timer(struct timer_list *);
  1332. extern void afs_fs_probe_timer(struct timer_list *);
  1333. extern void __net_exit afs_purge_servers(struct afs_net *);
  1334. bool afs_check_server_record(struct afs_operation *op, struct afs_server *server, struct key *key);
  1335. static inline void afs_inc_servers_outstanding(struct afs_net *net)
  1336. {
  1337. atomic_inc(&net->servers_outstanding);
  1338. }
  1339. static inline void afs_dec_servers_outstanding(struct afs_net *net)
  1340. {
  1341. if (atomic_dec_and_test(&net->servers_outstanding))
  1342. wake_up_var(&net->servers_outstanding);
  1343. }
  1344. static inline bool afs_is_probing_server(struct afs_server *server)
  1345. {
  1346. return list_empty(&server->probe_link);
  1347. }
  1348. /*
  1349. * server_list.c
  1350. */
  1351. static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist)
  1352. {
  1353. refcount_inc(&slist->usage);
  1354. return slist;
  1355. }
  1356. extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *);
  1357. struct afs_server_list *afs_alloc_server_list(struct afs_volume *volume,
  1358. struct key *key,
  1359. struct afs_vldb_entry *vldb);
  1360. extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *);
  1361. void afs_attach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist);
  1362. void afs_reattach_volume_to_servers(struct afs_volume *volume, struct afs_server_list *slist,
  1363. struct afs_server_list *old);
  1364. void afs_detach_volume_from_servers(struct afs_volume *volume, struct afs_server_list *slist);
  1365. /*
  1366. * super.c
  1367. */
  1368. extern int __init afs_fs_init(void);
  1369. extern void afs_fs_exit(void);
  1370. /*
  1371. * validation.c
  1372. */
  1373. bool afs_check_validity(const struct afs_vnode *vnode);
  1374. int afs_update_volume_state(struct afs_operation *op);
  1375. int afs_validate(struct afs_vnode *vnode, struct key *key);
  1376. /*
  1377. * vlclient.c
  1378. */
  1379. extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *,
  1380. const char *, int);
  1381. extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *);
  1382. struct afs_call *afs_vl_get_capabilities(struct afs_net *net,
  1383. struct afs_addr_list *alist,
  1384. unsigned int addr_index,
  1385. struct key *key,
  1386. struct afs_vlserver *server,
  1387. unsigned int server_index);
  1388. extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *);
  1389. extern char *afs_yfsvl_get_cell_name(struct afs_vl_cursor *);
  1390. /*
  1391. * vl_alias.c
  1392. */
  1393. extern int afs_cell_detect_alias(struct afs_cell *, struct key *);
  1394. /*
  1395. * vl_probe.c
  1396. */
  1397. extern void afs_vlserver_probe_result(struct afs_call *);
  1398. extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *);
  1399. extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long);
  1400. /*
  1401. * vl_rotate.c
  1402. */
  1403. extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *,
  1404. struct afs_cell *, struct key *);
  1405. extern bool afs_select_vlserver(struct afs_vl_cursor *);
  1406. extern bool afs_select_current_vlserver(struct afs_vl_cursor *);
  1407. extern int afs_end_vlserver_operation(struct afs_vl_cursor *);
  1408. /*
  1409. * vlserver_list.c
  1410. */
  1411. static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver)
  1412. {
  1413. refcount_inc(&vlserver->ref);
  1414. return vlserver;
  1415. }
  1416. static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist)
  1417. {
  1418. if (vllist)
  1419. refcount_inc(&vllist->ref);
  1420. return vllist;
  1421. }
  1422. extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short);
  1423. extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *);
  1424. extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int);
  1425. extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *);
  1426. extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *,
  1427. const void *, size_t);
  1428. /*
  1429. * volume.c
  1430. */
  1431. extern struct afs_volume *afs_create_volume(struct afs_fs_context *);
  1432. extern int afs_activate_volume(struct afs_volume *);
  1433. extern void afs_deactivate_volume(struct afs_volume *);
  1434. bool afs_try_get_volume(struct afs_volume *volume, enum afs_volume_trace reason);
  1435. extern struct afs_volume *afs_get_volume(struct afs_volume *, enum afs_volume_trace);
  1436. void afs_put_volume(struct afs_volume *volume, enum afs_volume_trace reason);
  1437. extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
  1438. /*
  1439. * write.c
  1440. */
  1441. void afs_prepare_write(struct netfs_io_subrequest *subreq);
  1442. void afs_issue_write(struct netfs_io_subrequest *subreq);
  1443. void afs_begin_writeback(struct netfs_io_request *wreq);
  1444. void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream);
  1445. extern int afs_writepages(struct address_space *, struct writeback_control *);
  1446. extern int afs_fsync(struct file *, loff_t, loff_t, int);
  1447. extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
  1448. extern void afs_prune_wb_keys(struct afs_vnode *);
  1449. /*
  1450. * xattr.c
  1451. */
  1452. extern const struct xattr_handler * const afs_xattr_handlers[];
  1453. /*
  1454. * yfsclient.c
  1455. */
  1456. extern void yfs_fs_fetch_data(struct afs_operation *);
  1457. extern void yfs_fs_create_file(struct afs_operation *);
  1458. extern void yfs_fs_make_dir(struct afs_operation *);
  1459. extern void yfs_fs_remove_file2(struct afs_operation *);
  1460. extern void yfs_fs_remove_file(struct afs_operation *);
  1461. extern void yfs_fs_remove_dir(struct afs_operation *);
  1462. extern void yfs_fs_link(struct afs_operation *);
  1463. extern void yfs_fs_symlink(struct afs_operation *);
  1464. extern void yfs_fs_rename(struct afs_operation *);
  1465. extern void yfs_fs_store_data(struct afs_operation *);
  1466. extern void yfs_fs_setattr(struct afs_operation *);
  1467. extern void yfs_fs_get_volume_status(struct afs_operation *);
  1468. extern void yfs_fs_set_lock(struct afs_operation *);
  1469. extern void yfs_fs_extend_lock(struct afs_operation *);
  1470. extern void yfs_fs_release_lock(struct afs_operation *);
  1471. extern void yfs_fs_fetch_status(struct afs_operation *);
  1472. extern void yfs_fs_inline_bulk_status(struct afs_operation *);
  1473. struct yfs_acl {
  1474. struct afs_acl *acl; /* Dir/file/symlink ACL */
  1475. struct afs_acl *vol_acl; /* Whole volume ACL */
  1476. u32 inherit_flag; /* True if ACL is inherited from parent dir */
  1477. u32 num_cleaned; /* Number of ACEs removed due to subject removal */
  1478. unsigned int flags;
  1479. #define YFS_ACL_WANT_ACL 0x01 /* Set if caller wants ->acl */
  1480. #define YFS_ACL_WANT_VOL_ACL 0x02 /* Set if caller wants ->vol_acl */
  1481. };
  1482. extern void yfs_free_opaque_acl(struct yfs_acl *);
  1483. extern void yfs_fs_fetch_opaque_acl(struct afs_operation *);
  1484. extern void yfs_fs_store_opaque_acl2(struct afs_operation *);
  1485. /*
  1486. * Miscellaneous inline functions.
  1487. */
  1488. static inline struct afs_vnode *AFS_FS_I(struct inode *inode)
  1489. {
  1490. return container_of(inode, struct afs_vnode, netfs.inode);
  1491. }
  1492. static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
  1493. {
  1494. return &vnode->netfs.inode;
  1495. }
  1496. /*
  1497. * Note that a dentry got changed. We need to set d_fsdata to the data version
  1498. * number derived from the result of the operation. It doesn't matter if
  1499. * d_fsdata goes backwards as we'll just revalidate.
  1500. */
  1501. static inline void afs_update_dentry_version(struct afs_operation *op,
  1502. struct afs_vnode_param *dir_vp,
  1503. struct dentry *dentry)
  1504. {
  1505. if (!op->cumul_error.error)
  1506. dentry->d_fsdata =
  1507. (void *)(unsigned long)dir_vp->scb.status.data_version;
  1508. }
  1509. /*
  1510. * Set the file size and block count. Estimate the number of 512 bytes blocks
  1511. * used, rounded up to nearest 1K for consistency with other AFS clients.
  1512. */
  1513. static inline void afs_set_i_size(struct afs_vnode *vnode, u64 size)
  1514. {
  1515. i_size_write(&vnode->netfs.inode, size);
  1516. vnode->netfs.inode.i_blocks = ((size + 1023) >> 10) << 1;
  1517. }
  1518. /*
  1519. * Check for a conflicting operation on a directory that we just unlinked from.
  1520. * If someone managed to sneak a link or an unlink in on the file we just
  1521. * unlinked, we won't be able to trust nlink on an AFS file (but not YFS).
  1522. */
  1523. static inline void afs_check_dir_conflict(struct afs_operation *op,
  1524. struct afs_vnode_param *dvp)
  1525. {
  1526. if (dvp->dv_before + dvp->dv_delta != dvp->scb.status.data_version)
  1527. op->flags |= AFS_OPERATION_DIR_CONFLICT;
  1528. }
  1529. static inline int afs_io_error(struct afs_call *call, enum afs_io_error where)
  1530. {
  1531. trace_afs_io_error(call->debug_id, -EIO, where);
  1532. return -EIO;
  1533. }
  1534. static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where)
  1535. {
  1536. trace_afs_file_error(vnode, -EIO, where);
  1537. return -EIO;
  1538. }
  1539. /*****************************************************************************/
  1540. /*
  1541. * debug tracing
  1542. */
  1543. extern unsigned afs_debug;
  1544. #define dbgprintk(FMT,...) \
  1545. printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
  1546. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1547. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1548. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  1549. #if defined(__KDEBUG)
  1550. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  1551. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  1552. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  1553. #elif defined(CONFIG_AFS_DEBUG)
  1554. #define AFS_DEBUG_KENTER 0x01
  1555. #define AFS_DEBUG_KLEAVE 0x02
  1556. #define AFS_DEBUG_KDEBUG 0x04
  1557. #define _enter(FMT,...) \
  1558. do { \
  1559. if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \
  1560. kenter(FMT,##__VA_ARGS__); \
  1561. } while (0)
  1562. #define _leave(FMT,...) \
  1563. do { \
  1564. if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \
  1565. kleave(FMT,##__VA_ARGS__); \
  1566. } while (0)
  1567. #define _debug(FMT,...) \
  1568. do { \
  1569. if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \
  1570. kdebug(FMT,##__VA_ARGS__); \
  1571. } while (0)
  1572. #else
  1573. #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1574. #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1575. #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
  1576. #endif
  1577. /*
  1578. * debug assertion checking
  1579. */
  1580. #if 1 // defined(__KDEBUGALL)
  1581. #define ASSERT(X) \
  1582. do { \
  1583. if (unlikely(!(X))) { \
  1584. printk(KERN_ERR "\n"); \
  1585. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1586. BUG(); \
  1587. } \
  1588. } while(0)
  1589. #define ASSERTCMP(X, OP, Y) \
  1590. do { \
  1591. if (unlikely(!((X) OP (Y)))) { \
  1592. printk(KERN_ERR "\n"); \
  1593. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1594. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  1595. (unsigned long)(X), (unsigned long)(Y)); \
  1596. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  1597. (unsigned long)(X), (unsigned long)(Y)); \
  1598. BUG(); \
  1599. } \
  1600. } while(0)
  1601. #define ASSERTRANGE(L, OP1, N, OP2, H) \
  1602. do { \
  1603. if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
  1604. printk(KERN_ERR "\n"); \
  1605. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1606. printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \
  1607. (unsigned long)(L), (unsigned long)(N), \
  1608. (unsigned long)(H)); \
  1609. printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \
  1610. (unsigned long)(L), (unsigned long)(N), \
  1611. (unsigned long)(H)); \
  1612. BUG(); \
  1613. } \
  1614. } while(0)
  1615. #define ASSERTIF(C, X) \
  1616. do { \
  1617. if (unlikely((C) && !(X))) { \
  1618. printk(KERN_ERR "\n"); \
  1619. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1620. BUG(); \
  1621. } \
  1622. } while(0)
  1623. #define ASSERTIFCMP(C, X, OP, Y) \
  1624. do { \
  1625. if (unlikely((C) && !((X) OP (Y)))) { \
  1626. printk(KERN_ERR "\n"); \
  1627. printk(KERN_ERR "AFS: Assertion failed\n"); \
  1628. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  1629. (unsigned long)(X), (unsigned long)(Y)); \
  1630. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  1631. (unsigned long)(X), (unsigned long)(Y)); \
  1632. BUG(); \
  1633. } \
  1634. } while(0)
  1635. #else
  1636. #define ASSERT(X) \
  1637. do { \
  1638. } while(0)
  1639. #define ASSERTCMP(X, OP, Y) \
  1640. do { \
  1641. } while(0)
  1642. #define ASSERTRANGE(L, OP1, N, OP2, H) \
  1643. do { \
  1644. } while(0)
  1645. #define ASSERTIF(C, X) \
  1646. do { \
  1647. } while(0)
  1648. #define ASSERTIFCMP(C, X, OP, Y) \
  1649. do { \
  1650. } while(0)
  1651. #endif /* __KDEBUGALL */