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