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