internal.h 37 KB

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