internal.h 58 KB

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