internal.h 59 KB

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