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