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