1ec26815aSDavid Howells /* internal AFS stuff 21da177e4SLinus Torvalds * 308e0e7c8SDavid Howells * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved. 41da177e4SLinus Torvalds * Written by David Howells (dhowells@redhat.com) 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 71da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 81da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 91da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 101da177e4SLinus Torvalds */ 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <linux/compiler.h> 131da177e4SLinus Torvalds #include <linux/kernel.h> 148a79790bSTina Ruchandani #include <linux/ktime.h> 151da177e4SLinus Torvalds #include <linux/fs.h> 161da177e4SLinus Torvalds #include <linux/pagemap.h> 1708e0e7c8SDavid Howells #include <linux/rxrpc.h> 1800d3b7a4SDavid Howells #include <linux/key.h> 19e8edc6e0SAlexey Dobriyan #include <linux/workqueue.h> 2000c541eaSAndrew Morton #include <linux/sched.h> 2180e50be4SChristoph Hellwig #include <linux/fscache.h> 22e1da0222SJens Axboe #include <linux/backing-dev.h> 23ff548773SDavid Howells #include <linux/uuid.h> 240722f186SSouptick Joarder #include <linux/mm_types.h> 250a5143f2SDavid Howells #include <linux/dns_resolver.h> 26f044c884SDavid Howells #include <net/net_namespace.h> 275b86d4ffSDavid Howells #include <net/netns/generic.h> 285b86d4ffSDavid Howells #include <net/sock.h> 298324f0bcSDavid Howells #include <net/af_rxrpc.h> 3000c541eaSAndrew Morton 3108e0e7c8SDavid Howells #include "afs.h" 3208e0e7c8SDavid Howells #include "afs_vl.h" 3308e0e7c8SDavid Howells 3408e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15 3508e0e7c8SDavid Howells 3631143d5dSDavid Howells struct pagevec; 3708e0e7c8SDavid Howells struct afs_call; 3808e0e7c8SDavid Howells 3913fcc683SDavid Howells struct afs_fs_context { 4000d3b7a4SDavid Howells bool force; /* T to force cell type */ 41bec5eb61Swanglei bool autocell; /* T if set auto mount operation */ 424d673da1SDavid Howells bool dyn_root; /* T if dynamic root */ 4313fcc683SDavid Howells bool no_cell; /* T if the source is "none" (for dynroot) */ 4400d3b7a4SDavid Howells afs_voltype_t type; /* type of volume requested */ 4513fcc683SDavid Howells unsigned int volnamesz; /* size of volume name */ 4600d3b7a4SDavid Howells const char *volname; /* name of volume to mount */ 475b86d4ffSDavid Howells struct afs_net *net; /* the AFS net namespace stuff */ 4800d3b7a4SDavid Howells struct afs_cell *cell; /* cell in which to find volume */ 4900d3b7a4SDavid Howells struct afs_volume *volume; /* volume record */ 5000d3b7a4SDavid Howells struct key *key; /* key to use for secure mounting */ 5100d3b7a4SDavid Howells }; 5200d3b7a4SDavid Howells 53c435ee34SDavid Howells struct afs_iget_data { 54c435ee34SDavid Howells struct afs_fid fid; 55c435ee34SDavid Howells struct afs_volume *volume; /* volume on which resides */ 56c435ee34SDavid Howells }; 57c435ee34SDavid Howells 588e8d7f13SDavid Howells enum afs_call_state { 5998bf40cdSDavid Howells AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */ 6098bf40cdSDavid Howells AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */ 6198bf40cdSDavid Howells AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */ 6298bf40cdSDavid Howells AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */ 6398bf40cdSDavid Howells AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */ 6498bf40cdSDavid Howells AFS_CALL_SV_REPLYING, /* Server: Replying */ 6598bf40cdSDavid Howells AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */ 668e8d7f13SDavid Howells AFS_CALL_COMPLETE, /* Completed or failed */ 678e8d7f13SDavid Howells }; 68f044c884SDavid Howells 6908e0e7c8SDavid Howells /* 708b2a464cSDavid Howells * List of server addresses. 718b2a464cSDavid Howells */ 728b2a464cSDavid Howells struct afs_addr_list { 738b2a464cSDavid Howells struct rcu_head rcu; /* Must be first */ 748b2a464cSDavid Howells refcount_t usage; 75d2ddc776SDavid Howells u32 version; /* Version */ 7668eb64c3SDavid Howells unsigned char max_addrs; 7768eb64c3SDavid Howells unsigned char nr_addrs; 783bf0fb6fSDavid Howells unsigned char preferred; /* Preferred address */ 7968eb64c3SDavid Howells unsigned char nr_ipv4; /* Number of IPv4 addresses */ 800a5143f2SDavid Howells enum dns_record_source source:8; 810a5143f2SDavid Howells enum dns_lookup_status status:8; 82bf99a53cSDavid Howells unsigned long probed; /* Mask of servers that have been probed */ 833bf0fb6fSDavid Howells unsigned long failed; /* Mask of addrs that failed locally/ICMP */ 843bf0fb6fSDavid Howells unsigned long responded; /* Mask of addrs that responded */ 858b2a464cSDavid Howells struct sockaddr_rxrpc addrs[]; 8668eb64c3SDavid Howells #define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8)) 878b2a464cSDavid Howells }; 888b2a464cSDavid Howells 898b2a464cSDavid Howells /* 9008e0e7c8SDavid Howells * a record of an in-progress RxRPC call 9108e0e7c8SDavid Howells */ 9208e0e7c8SDavid Howells struct afs_call { 9308e0e7c8SDavid Howells const struct afs_call_type *type; /* type of call */ 943bf0fb6fSDavid Howells struct afs_addr_list *alist; /* Address is alist[addr_ix] */ 9508e0e7c8SDavid Howells wait_queue_head_t waitq; /* processes awaiting completion */ 96341f741fSDavid Howells struct work_struct async_work; /* async I/O processor */ 9708e0e7c8SDavid Howells struct work_struct work; /* actual work processor */ 9808e0e7c8SDavid Howells struct rxrpc_call *rxcall; /* RxRPC call handle */ 9908e0e7c8SDavid Howells struct key *key; /* security for this call */ 100f044c884SDavid Howells struct afs_net *net; /* The network namespace */ 101d0676a16SDavid Howells struct afs_server *cm_server; /* Server affected by incoming CM call */ 102d2ddc776SDavid Howells struct afs_cb_interest *cbi; /* Callback interest for server used */ 10308e0e7c8SDavid Howells void *request; /* request data (first part) */ 1044343d008SDavid Howells struct address_space *mapping; /* Pages being written from */ 10512bdcf33SDavid Howells struct iov_iter iter; /* Buffer iterator */ 10612bdcf33SDavid Howells struct iov_iter *_iter; /* Iterator currently in use */ 10712bdcf33SDavid Howells union { /* Convenience for ->iter */ 10812bdcf33SDavid Howells struct kvec kvec[1]; 10912bdcf33SDavid Howells struct bio_vec bvec[1]; 11012bdcf33SDavid Howells }; 11108e0e7c8SDavid Howells void *buffer; /* reply receive buffer */ 11297e3043aSDavid Howells void *reply[4]; /* Where to put the reply */ 11331143d5dSDavid Howells pgoff_t first; /* first page in mapping to deal with */ 11431143d5dSDavid Howells pgoff_t last; /* last page in mapping to deal with */ 115341f741fSDavid Howells atomic_t usage; 1168e8d7f13SDavid Howells enum afs_call_state state; 11798bf40cdSDavid Howells spinlock_t state_lock; 11808e0e7c8SDavid Howells int error; /* error code */ 119d001648eSDavid Howells u32 abort_code; /* Remote abort ID or 0 */ 1203bf0fb6fSDavid Howells u32 epoch; 12108e0e7c8SDavid Howells unsigned request_size; /* size of request data */ 12208e0e7c8SDavid Howells unsigned reply_max; /* maximum size of reply */ 12331143d5dSDavid Howells unsigned first_offset; /* offset into mapping[first] */ 124c435ee34SDavid Howells unsigned int cb_break; /* cb_break + cb_s_break before the call */ 125bcd89270SMarc Dionne union { 12631143d5dSDavid Howells unsigned last_to; /* amount of mapping[last] */ 127bcd89270SMarc Dionne unsigned count2; /* count used in unmarshalling */ 128bcd89270SMarc Dionne }; 12908e0e7c8SDavid Howells unsigned char unmarshall; /* unmarshalling phase */ 1303bf0fb6fSDavid Howells unsigned char addr_ix; /* Address in ->alist */ 13108e0e7c8SDavid Howells bool incoming; /* T if incoming call */ 13231143d5dSDavid Howells bool send_pages; /* T if data from mapping should be sent */ 133d001648eSDavid Howells bool need_attention; /* T if RxRPC poked us */ 13456ff9c83SDavid Howells bool async; /* T if asynchronous */ 13533cd7f2bSDavid Howells bool ret_reply0; /* T if should return reply[0] on success */ 136a68f4a27SDavid Howells bool upgrade; /* T to request service upgrade */ 13712d8e95aSDavid Howells bool want_reply_time; /* T if want reply_time */ 138bf99a53cSDavid Howells u16 service_id; /* Actual service ID (after upgrade) */ 139a25e21f0SDavid Howells unsigned int debug_id; /* Trace ID */ 14050a2c953SDavid Howells u32 operation_ID; /* operation ID for an incoming call */ 14108e0e7c8SDavid Howells u32 count; /* count for use in unmarshalling */ 14212bdcf33SDavid Howells union { /* place to extract temporary data */ 14312bdcf33SDavid Howells struct { 14412bdcf33SDavid Howells __be32 tmp_u; 14512bdcf33SDavid Howells __be32 tmp; 14612bdcf33SDavid Howells } __attribute__((packed)); 14712bdcf33SDavid Howells __be64 tmp64; 14812bdcf33SDavid Howells }; 1490c3a5ac2SDavid Howells afs_dataversion_t expected_version; /* Updated version expected from store */ 1500c3a5ac2SDavid Howells afs_dataversion_t expected_version_2; /* 2nd updated version expected from store */ 15112d8e95aSDavid Howells ktime_t reply_time; /* Time of first reply packet */ 15208e0e7c8SDavid Howells }; 15308e0e7c8SDavid Howells 15408e0e7c8SDavid Howells struct afs_call_type { 15500d3b7a4SDavid Howells const char *name; 156025db80cSDavid Howells unsigned int op; /* Really enum afs_fs_operation */ 15700d3b7a4SDavid Howells 15808e0e7c8SDavid Howells /* deliver request or reply data to an call 15908e0e7c8SDavid Howells * - returning an error will cause the call to be aborted 16008e0e7c8SDavid Howells */ 161d001648eSDavid Howells int (*deliver)(struct afs_call *call); 16208e0e7c8SDavid Howells 16308e0e7c8SDavid Howells /* clean up a call */ 16408e0e7c8SDavid Howells void (*destructor)(struct afs_call *call); 165341f741fSDavid Howells 166341f741fSDavid Howells /* Work function */ 167341f741fSDavid Howells void (*work)(struct work_struct *work); 1683bf0fb6fSDavid Howells 1693bf0fb6fSDavid Howells /* Call done function (gets called immediately on success or failure) */ 1703bf0fb6fSDavid Howells void (*done)(struct afs_call *call); 17108e0e7c8SDavid Howells }; 17208e0e7c8SDavid Howells 17308e0e7c8SDavid Howells /* 1744343d008SDavid Howells * Key available for writeback on a file. 1754343d008SDavid Howells */ 1764343d008SDavid Howells struct afs_wb_key { 1774343d008SDavid Howells refcount_t usage; 1784343d008SDavid Howells struct key *key; 1794343d008SDavid Howells struct list_head vnode_link; /* Link in vnode->wb_keys */ 1804343d008SDavid Howells }; 1814343d008SDavid Howells 1824343d008SDavid Howells /* 183215804a9SDavid Howells * AFS open file information record. Pointed to by file->private_data. 184215804a9SDavid Howells */ 185215804a9SDavid Howells struct afs_file { 186215804a9SDavid Howells struct key *key; /* The key this file was opened with */ 1874343d008SDavid Howells struct afs_wb_key *wb; /* Writeback key record for this file */ 188215804a9SDavid Howells }; 189215804a9SDavid Howells 190215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file) 191215804a9SDavid Howells { 192215804a9SDavid Howells struct afs_file *af = file->private_data; 193215804a9SDavid Howells 194215804a9SDavid Howells return af->key; 195215804a9SDavid Howells } 196215804a9SDavid Howells 197215804a9SDavid Howells /* 198196ee9cdSDavid Howells * Record of an outstanding read operation on a vnode. 199196ee9cdSDavid Howells */ 200196ee9cdSDavid Howells struct afs_read { 201196ee9cdSDavid Howells loff_t pos; /* Where to start reading */ 202e8e581a8SDavid Howells loff_t len; /* How much we're asking for */ 203196ee9cdSDavid Howells loff_t actual_len; /* How much we're actually getting */ 2046a0e3999SDavid Howells loff_t remain; /* Amount remaining */ 205f3ddee8dSDavid Howells loff_t file_size; /* File size returned by server */ 206f3ddee8dSDavid Howells afs_dataversion_t data_version; /* Version number returned by server */ 207f3ddee8dSDavid Howells refcount_t usage; 208196ee9cdSDavid Howells unsigned int index; /* Which page we're reading into */ 209196ee9cdSDavid Howells unsigned int nr_pages; 21012bdcf33SDavid Howells unsigned int offset; /* offset into current page */ 211196ee9cdSDavid Howells void (*page_done)(struct afs_call *, struct afs_read *); 212f3ddee8dSDavid Howells struct page **pages; 213f3ddee8dSDavid Howells struct page *array[]; 214196ee9cdSDavid Howells }; 215196ee9cdSDavid Howells 216196ee9cdSDavid Howells /* 21708e0e7c8SDavid Howells * AFS superblock private data 21808e0e7c8SDavid Howells * - there's one superblock per volume 21908e0e7c8SDavid Howells */ 22008e0e7c8SDavid Howells struct afs_super_info { 2215b86d4ffSDavid Howells struct net *net_ns; /* Network namespace */ 22249566f6fSDavid Howells struct afs_cell *cell; /* The cell in which the volume resides */ 22308e0e7c8SDavid Howells struct afs_volume *volume; /* volume record */ 2244d673da1SDavid Howells bool dyn_root; /* True if dynamic root */ 22508e0e7c8SDavid Howells }; 22608e0e7c8SDavid Howells 22708e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) 22808e0e7c8SDavid Howells { 22908e0e7c8SDavid Howells return sb->s_fs_info; 23008e0e7c8SDavid Howells } 23108e0e7c8SDavid Howells 23208e0e7c8SDavid Howells extern struct file_system_type afs_fs_type; 23308e0e7c8SDavid Howells 23408e0e7c8SDavid Howells /* 2356f8880d8SDavid Howells * Set of substitutes for @sys. 2366f8880d8SDavid Howells */ 2376f8880d8SDavid Howells struct afs_sysnames { 2386f8880d8SDavid Howells #define AFS_NR_SYSNAME 16 2396f8880d8SDavid Howells char *subs[AFS_NR_SYSNAME]; 2406f8880d8SDavid Howells refcount_t usage; 2416f8880d8SDavid Howells unsigned short nr; 2426f8880d8SDavid Howells char blank[1]; 2436f8880d8SDavid Howells }; 2446f8880d8SDavid Howells 2456f8880d8SDavid Howells /* 246f044c884SDavid Howells * AFS network namespace record. 247f044c884SDavid Howells */ 248f044c884SDavid Howells struct afs_net { 2495b86d4ffSDavid Howells struct net *net; /* Backpointer to the owning net namespace */ 250f044c884SDavid Howells struct afs_uuid uuid; 251f044c884SDavid Howells bool live; /* F if this namespace is being removed */ 252f044c884SDavid Howells 253f044c884SDavid Howells /* AF_RXRPC I/O stuff */ 254f044c884SDavid Howells struct socket *socket; 255f044c884SDavid Howells struct afs_call *spare_incoming_call; 256f044c884SDavid Howells struct work_struct charge_preallocation_work; 257f044c884SDavid Howells struct mutex socket_mutex; 258f044c884SDavid Howells atomic_t nr_outstanding_calls; 259f044c884SDavid Howells atomic_t nr_superblocks; 260f044c884SDavid Howells 261f044c884SDavid Howells /* Cell database */ 262989782dcSDavid Howells struct rb_root cells; 2631588def9SDavid Howells struct afs_cell __rcu *ws_cell; 264989782dcSDavid Howells struct work_struct cells_manager; 265989782dcSDavid Howells struct timer_list cells_timer; 266989782dcSDavid Howells atomic_t cells_outstanding; 267989782dcSDavid Howells seqlock_t cells_lock; 268f044c884SDavid Howells 2690da0b7fdSDavid Howells struct mutex proc_cells_lock; 2706b3944e4SDavid Howells struct hlist_head proc_cells; 271f044c884SDavid Howells 272d2ddc776SDavid Howells /* Known servers. Theoretically each fileserver can only be in one 273d2ddc776SDavid Howells * cell, but in practice, people create aliases and subsets and there's 274d2ddc776SDavid Howells * no easy way to distinguish them. 275d2ddc776SDavid Howells */ 276d2ddc776SDavid Howells seqlock_t fs_lock; /* For fs_servers */ 277d2ddc776SDavid Howells struct rb_root fs_servers; /* afs_server (by server UUID or address) */ 278d2ddc776SDavid Howells struct list_head fs_updates; /* afs_server (by update_at) */ 279d2ddc776SDavid Howells struct hlist_head fs_proc; /* procfs servers list */ 280d2ddc776SDavid Howells 281d2ddc776SDavid Howells struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */ 282d2ddc776SDavid Howells struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */ 283d2ddc776SDavid Howells seqlock_t fs_addr_lock; /* For fs_addresses[46] */ 284d2ddc776SDavid Howells 285d2ddc776SDavid Howells struct work_struct fs_manager; 286d2ddc776SDavid Howells struct timer_list fs_timer; 287d2ddc776SDavid Howells atomic_t servers_outstanding; 288f044c884SDavid Howells 289f044c884SDavid Howells /* File locking renewal management */ 290f044c884SDavid Howells struct mutex lock_manager_mutex; 291f044c884SDavid Howells 292f044c884SDavid Howells /* Misc */ 2930da0b7fdSDavid Howells struct super_block *dynroot_sb; /* Dynamic root mount superblock */ 294f044c884SDavid Howells struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */ 2956f8880d8SDavid Howells struct afs_sysnames *sysnames; 2966f8880d8SDavid Howells rwlock_t sysnames_lock; 297d55b4da4SDavid Howells 298d55b4da4SDavid Howells /* Statistics counters */ 299d55b4da4SDavid Howells atomic_t n_lookup; /* Number of lookups done */ 300d55b4da4SDavid Howells atomic_t n_reval; /* Number of dentries needing revalidation */ 301d55b4da4SDavid Howells atomic_t n_inval; /* Number of invalidations by the server */ 302f3ddee8dSDavid Howells atomic_t n_relpg; /* Number of invalidations by releasepage */ 303d55b4da4SDavid Howells atomic_t n_read_dir; /* Number of directory pages read */ 30463a4681fSDavid Howells atomic_t n_dir_cr; /* Number of directory entry creation edits */ 30563a4681fSDavid Howells atomic_t n_dir_rm; /* Number of directory entry removal edits */ 30676a5cb6fSDavid Howells atomic_t n_stores; /* Number of store ops */ 30776a5cb6fSDavid Howells atomic_long_t n_store_bytes; /* Number of bytes stored */ 30876a5cb6fSDavid Howells atomic_long_t n_fetch_bytes; /* Number of bytes fetched */ 30976a5cb6fSDavid Howells atomic_t n_fetches; /* Number of data fetch ops */ 310f044c884SDavid Howells }; 311f044c884SDavid Howells 3126f8880d8SDavid Howells extern const char afs_init_sysname[]; 313f044c884SDavid Howells 314989782dcSDavid Howells enum afs_cell_state { 315989782dcSDavid Howells AFS_CELL_UNSET, 316989782dcSDavid Howells AFS_CELL_ACTIVATING, 317989782dcSDavid Howells AFS_CELL_ACTIVE, 318989782dcSDavid Howells AFS_CELL_DEACTIVATING, 319989782dcSDavid Howells AFS_CELL_INACTIVE, 320989782dcSDavid Howells AFS_CELL_FAILED, 321989782dcSDavid Howells }; 322989782dcSDavid Howells 323f044c884SDavid Howells /* 324d2ddc776SDavid Howells * AFS cell record. 325d2ddc776SDavid Howells * 326d2ddc776SDavid Howells * This is a tricky concept to get right as it is possible to create aliases 327d2ddc776SDavid Howells * simply by pointing AFSDB/SRV records for two names at the same set of VL 328d2ddc776SDavid Howells * servers; it is also possible to do things like setting up two sets of VL 329d2ddc776SDavid Howells * servers, one of which provides a superset of the volumes provided by the 330d2ddc776SDavid Howells * other (for internal/external division, for example). 331d2ddc776SDavid Howells * 332d2ddc776SDavid Howells * Cells only exist in the sense that (a) a cell's name maps to a set of VL 333d2ddc776SDavid Howells * servers and (b) a cell's name is used by the client to select the key to use 334d2ddc776SDavid Howells * for authentication and encryption. The cell name is not typically used in 335d2ddc776SDavid Howells * the protocol. 336d2ddc776SDavid Howells * 337d2ddc776SDavid Howells * There is no easy way to determine if two cells are aliases or one is a 338d2ddc776SDavid Howells * subset of another. 33908e0e7c8SDavid Howells */ 34008e0e7c8SDavid Howells struct afs_cell { 341989782dcSDavid Howells union { 342989782dcSDavid Howells struct rcu_head rcu; 343989782dcSDavid Howells struct rb_node net_node; /* Node in net->cells */ 344989782dcSDavid Howells }; 345989782dcSDavid Howells struct afs_net *net; 34600d3b7a4SDavid Howells struct key *anonymous_key; /* anonymous user key for this cell */ 347989782dcSDavid Howells struct work_struct manager; /* Manager for init/deinit/dns */ 3486b3944e4SDavid Howells struct hlist_node proc_link; /* /proc cell list link */ 3499b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 3509b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 3511da177e4SLinus Torvalds #endif 352989782dcSDavid Howells time64_t dns_expiry; /* Time AFSDB/SRV record expires */ 353989782dcSDavid Howells time64_t last_inactive; /* Time of last drop of usage count */ 354989782dcSDavid Howells atomic_t usage; 355989782dcSDavid Howells unsigned long flags; 356989782dcSDavid Howells #define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */ 357989782dcSDavid Howells #define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */ 358989782dcSDavid Howells #define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */ 359989782dcSDavid Howells #define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */ 3608b2a464cSDavid Howells #define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */ 361989782dcSDavid Howells enum afs_cell_state state; 362989782dcSDavid Howells short error; 363989782dcSDavid Howells 364d2ddc776SDavid Howells /* Active fileserver interaction state. */ 365d2ddc776SDavid Howells struct list_head proc_volumes; /* procfs volume list */ 366d2ddc776SDavid Howells rwlock_t proc_lock; 367989782dcSDavid Howells 368d2ddc776SDavid Howells /* VL server list. */ 3690a5143f2SDavid Howells rwlock_t vl_servers_lock; /* Lock on vl_servers */ 3700a5143f2SDavid Howells struct afs_vlserver_list __rcu *vl_servers; 3710a5143f2SDavid Howells 372989782dcSDavid Howells u8 name_len; /* Length of name */ 373989782dcSDavid Howells char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */ 37408e0e7c8SDavid Howells }; 37508e0e7c8SDavid Howells 37608e0e7c8SDavid Howells /* 3770a5143f2SDavid Howells * Volume Location server record. 3780a5143f2SDavid Howells */ 3790a5143f2SDavid Howells struct afs_vlserver { 3800a5143f2SDavid Howells struct rcu_head rcu; 3810a5143f2SDavid Howells struct afs_addr_list __rcu *addresses; /* List of addresses for this VL server */ 3820a5143f2SDavid Howells unsigned long flags; 3830a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBED 0 /* The VL server has been probed */ 3840a5143f2SDavid Howells #define AFS_VLSERVER_FL_PROBING 1 /* VL server is being probed */ 3853bf0fb6fSDavid Howells #define AFS_VLSERVER_FL_IS_YFS 2 /* Server is YFS not AFS */ 3860a5143f2SDavid Howells rwlock_t lock; /* Lock on addresses */ 3870a5143f2SDavid Howells atomic_t usage; 3883bf0fb6fSDavid Howells 3893bf0fb6fSDavid Howells /* Probe state */ 3903bf0fb6fSDavid Howells wait_queue_head_t probe_wq; 3913bf0fb6fSDavid Howells atomic_t probe_outstanding; 3923bf0fb6fSDavid Howells spinlock_t probe_lock; 3933bf0fb6fSDavid Howells struct { 3943bf0fb6fSDavid Howells unsigned int rtt; /* RTT as ktime/64 */ 3953bf0fb6fSDavid Howells u32 abort_code; 3963bf0fb6fSDavid Howells short error; 3973bf0fb6fSDavid Howells bool have_result; 3983bf0fb6fSDavid Howells bool responded:1; 3993bf0fb6fSDavid Howells bool is_yfs:1; 4003bf0fb6fSDavid Howells bool not_yfs:1; 4013bf0fb6fSDavid Howells bool local_failure:1; 4023bf0fb6fSDavid Howells } probe; 4033bf0fb6fSDavid Howells 4040a5143f2SDavid Howells u16 port; 4053bf0fb6fSDavid Howells u16 name_len; /* Length of name */ 4060a5143f2SDavid Howells char name[]; /* Server name, case-flattened */ 4070a5143f2SDavid Howells }; 4080a5143f2SDavid Howells 4090a5143f2SDavid Howells /* 4100a5143f2SDavid Howells * Weighted list of Volume Location servers. 4110a5143f2SDavid Howells */ 4120a5143f2SDavid Howells struct afs_vlserver_entry { 4130a5143f2SDavid Howells u16 priority; /* Preference (as SRV) */ 4140a5143f2SDavid Howells u16 weight; /* Weight (as SRV) */ 4150a5143f2SDavid Howells enum dns_record_source source:8; 4160a5143f2SDavid Howells enum dns_lookup_status status:8; 4170a5143f2SDavid Howells struct afs_vlserver *server; 4180a5143f2SDavid Howells }; 4190a5143f2SDavid Howells 4200a5143f2SDavid Howells struct afs_vlserver_list { 4210a5143f2SDavid Howells struct rcu_head rcu; 4220a5143f2SDavid Howells atomic_t usage; 4230a5143f2SDavid Howells u8 nr_servers; 4240a5143f2SDavid Howells u8 index; /* Server currently in use */ 4253bf0fb6fSDavid Howells u8 preferred; /* Preferred server */ 4260a5143f2SDavid Howells enum dns_record_source source:8; 4270a5143f2SDavid Howells enum dns_lookup_status status:8; 4280a5143f2SDavid Howells rwlock_t lock; 4290a5143f2SDavid Howells struct afs_vlserver_entry servers[]; 4300a5143f2SDavid Howells }; 4310a5143f2SDavid Howells 4320a5143f2SDavid Howells /* 433d2ddc776SDavid Howells * Cached VLDB entry. 434d2ddc776SDavid Howells * 435d2ddc776SDavid Howells * This is pointed to by cell->vldb_entries, indexed by name. 43608e0e7c8SDavid Howells */ 437d2ddc776SDavid Howells struct afs_vldb_entry { 438d2ddc776SDavid Howells afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */ 43900d3b7a4SDavid Howells 440d2ddc776SDavid Howells unsigned long flags; 441d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */ 442d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */ 443d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */ 444d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */ 445d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */ 446d2ddc776SDavid Howells 447d2ddc776SDavid Howells uuid_t fs_server[AFS_NMAXNSERVERS]; 448d2ddc776SDavid Howells u8 fs_mask[AFS_NMAXNSERVERS]; 44908e0e7c8SDavid Howells #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */ 45008e0e7c8SDavid Howells #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */ 45108e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */ 452d2ddc776SDavid Howells short error; 453d2ddc776SDavid Howells u8 nr_servers; /* Number of server records */ 454d2ddc776SDavid Howells u8 name_len; 455d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */ 45608e0e7c8SDavid Howells }; 45708e0e7c8SDavid Howells 45808e0e7c8SDavid Howells /* 459d2ddc776SDavid Howells * Record of fileserver with which we're actively communicating. 46008e0e7c8SDavid Howells */ 46108e0e7c8SDavid Howells struct afs_server { 462d2ddc776SDavid Howells struct rcu_head rcu; 463d2ddc776SDavid Howells union { 464d2ddc776SDavid Howells uuid_t uuid; /* Server ID */ 465d2ddc776SDavid Howells struct afs_uuid _uuid; 466d2ddc776SDavid Howells }; 467c435ee34SDavid Howells 468d2ddc776SDavid Howells struct afs_addr_list __rcu *addresses; 469d2ddc776SDavid Howells struct rb_node uuid_rb; /* Link in net->servers */ 470d2ddc776SDavid Howells struct hlist_node addr4_link; /* Link in net->fs_addresses4 */ 471d2ddc776SDavid Howells struct hlist_node addr6_link; /* Link in net->fs_addresses6 */ 472d2ddc776SDavid Howells struct hlist_node proc_link; /* Link in net->fs_proc */ 473d2ddc776SDavid Howells struct afs_server *gc_next; /* Next server in manager's list */ 474d2ddc776SDavid Howells time64_t put_time; /* Time at which last put */ 475d2ddc776SDavid Howells time64_t update_at; /* Time at which to next update the record */ 476c435ee34SDavid Howells unsigned long flags; 477d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */ 478d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */ 479d2ddc776SDavid Howells #define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */ 480d2ddc776SDavid Howells #define AFS_SERVER_FL_UPDATING 4 481d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */ 482d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */ 4835cf9dd55SDavid Howells #define AFS_SERVER_FL_NO_IBULK 7 /* Fileserver doesn't support FS.InlineBulkStatus */ 484f2686b09SDavid Howells #define AFS_SERVER_FL_MAY_HAVE_CB 8 /* May have callbacks on this fileserver */ 48530062bd1SDavid Howells #define AFS_SERVER_FL_IS_YFS 9 /* Server is YFS not AFS */ 48630062bd1SDavid Howells #define AFS_SERVER_FL_NO_RM2 10 /* Fileserver doesn't support YFS.RemoveFile2 */ 4873bf0fb6fSDavid Howells #define AFS_SERVER_FL_HAVE_EPOCH 11 /* ->epoch is valid */ 488d2ddc776SDavid Howells atomic_t usage; 489d2ddc776SDavid Howells u32 addr_version; /* Address list version */ 4903bf0fb6fSDavid Howells u32 cm_epoch; /* Server RxRPC epoch */ 49108e0e7c8SDavid Howells 49208e0e7c8SDavid Howells /* file service access */ 493d2ddc776SDavid Howells rwlock_t fs_lock; /* access lock */ 49408e0e7c8SDavid Howells 49508e0e7c8SDavid Howells /* callback promise management */ 49647ea0f2eSDavid Howells struct hlist_head cb_volumes; /* List of volume interests on this server */ 497c435ee34SDavid Howells unsigned cb_s_break; /* Break-everything counter. */ 498c435ee34SDavid Howells rwlock_t cb_break_lock; /* Volume finding lock */ 4993bf0fb6fSDavid Howells 5003bf0fb6fSDavid Howells /* Probe state */ 5013bf0fb6fSDavid Howells wait_queue_head_t probe_wq; 5023bf0fb6fSDavid Howells atomic_t probe_outstanding; 5033bf0fb6fSDavid Howells spinlock_t probe_lock; 5043bf0fb6fSDavid Howells struct { 5053bf0fb6fSDavid Howells unsigned int rtt; /* RTT as ktime/64 */ 5063bf0fb6fSDavid Howells u32 abort_code; 5073bf0fb6fSDavid Howells u32 cm_epoch; 5083bf0fb6fSDavid Howells short error; 5093bf0fb6fSDavid Howells bool have_result; 5103bf0fb6fSDavid Howells bool responded:1; 5113bf0fb6fSDavid Howells bool is_yfs:1; 5123bf0fb6fSDavid Howells bool not_yfs:1; 5133bf0fb6fSDavid Howells bool local_failure:1; 5143bf0fb6fSDavid Howells bool no_epoch:1; 5153bf0fb6fSDavid Howells bool cm_probed:1; 5163bf0fb6fSDavid Howells bool said_rebooted:1; 5173bf0fb6fSDavid Howells bool said_inconsistent:1; 5183bf0fb6fSDavid Howells } probe; 519c435ee34SDavid Howells }; 520c435ee34SDavid Howells 521c435ee34SDavid Howells /* 52247ea0f2eSDavid Howells * Volume collation in the server's callback interest list. 52347ea0f2eSDavid Howells */ 52447ea0f2eSDavid Howells struct afs_vol_interest { 52547ea0f2eSDavid Howells struct hlist_node srv_link; /* Link in server->cb_volumes */ 52647ea0f2eSDavid Howells struct hlist_head cb_interests; /* List of callback interests on the server */ 52747ea0f2eSDavid Howells afs_volid_t vid; /* Volume ID to match */ 52847ea0f2eSDavid Howells unsigned int usage; 52947ea0f2eSDavid Howells }; 53047ea0f2eSDavid Howells 53147ea0f2eSDavid Howells /* 532c435ee34SDavid Howells * Interest by a superblock on a server. 533c435ee34SDavid Howells */ 534c435ee34SDavid Howells struct afs_cb_interest { 53547ea0f2eSDavid Howells struct hlist_node cb_vlink; /* Link in vol_interest->cb_interests */ 53647ea0f2eSDavid Howells struct afs_vol_interest *vol_interest; 537c435ee34SDavid Howells struct afs_server *server; /* Server on which this interest resides */ 538c435ee34SDavid Howells struct super_block *sb; /* Superblock on which inodes reside */ 539c435ee34SDavid Howells afs_volid_t vid; /* Volume ID to match */ 540c435ee34SDavid Howells refcount_t usage; 54108e0e7c8SDavid Howells }; 54208e0e7c8SDavid Howells 54308e0e7c8SDavid Howells /* 544d2ddc776SDavid Howells * Replaceable server list. 54508e0e7c8SDavid Howells */ 546d2ddc776SDavid Howells struct afs_server_entry { 547d2ddc776SDavid Howells struct afs_server *server; 548d2ddc776SDavid Howells struct afs_cb_interest *cb_interest; 549d2ddc776SDavid Howells }; 550d2ddc776SDavid Howells 551d2ddc776SDavid Howells struct afs_server_list { 552d2ddc776SDavid Howells refcount_t usage; 5533bf0fb6fSDavid Howells unsigned char nr_servers; 5543bf0fb6fSDavid Howells unsigned char preferred; /* Preferred server */ 555d2ddc776SDavid Howells unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */ 556d2ddc776SDavid Howells unsigned int seq; /* Set to ->servers_seq when installed */ 557d4a96becSDavid Howells rwlock_t lock; 558d2ddc776SDavid Howells struct afs_server_entry servers[]; 55908e0e7c8SDavid Howells }; 56008e0e7c8SDavid Howells 56108e0e7c8SDavid Howells /* 562d2ddc776SDavid Howells * Live AFS volume management. 56308e0e7c8SDavid Howells */ 564d2ddc776SDavid Howells struct afs_volume { 565d2ddc776SDavid Howells afs_volid_t vid; /* volume ID */ 566d2ddc776SDavid Howells atomic_t usage; 567d2ddc776SDavid Howells time64_t update_at; /* Time at which to next update */ 568d2ddc776SDavid Howells struct afs_cell *cell; /* Cell to which belongs (pins ref) */ 569d2ddc776SDavid Howells struct list_head proc_link; /* Link in cell->vl_proc */ 570d2ddc776SDavid Howells unsigned long flags; 571d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */ 572d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */ 573d2ddc776SDavid Howells #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */ 574d2ddc776SDavid Howells #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */ 575d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */ 576d2ddc776SDavid Howells #define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */ 577d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE 578d2ddc776SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 579d2ddc776SDavid Howells #endif 580d2ddc776SDavid Howells struct afs_server_list *servers; /* List of servers on which volume resides */ 581d2ddc776SDavid Howells rwlock_t servers_lock; /* Lock for ->servers */ 582d2ddc776SDavid Howells unsigned int servers_seq; /* Incremented each time ->servers changes */ 583d2ddc776SDavid Howells 58468251f0aSDavid Howells unsigned cb_v_break; /* Break-everything counter. */ 58568251f0aSDavid Howells rwlock_t cb_break_lock; 58668251f0aSDavid Howells 587d2ddc776SDavid Howells afs_voltype_t type; /* type of volume */ 588d2ddc776SDavid Howells short error; 589d2ddc776SDavid Howells char type_force; /* force volume type (suppress R/O -> R/W) */ 590d2ddc776SDavid Howells u8 name_len; 591d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */ 59208e0e7c8SDavid Howells }; 59308e0e7c8SDavid Howells 5940fafdc9fSDavid Howells enum afs_lock_state { 5950fafdc9fSDavid Howells AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */ 5960fafdc9fSDavid Howells AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */ 5970fafdc9fSDavid Howells AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */ 5980fafdc9fSDavid Howells AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */ 5990fafdc9fSDavid Howells AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */ 6000fafdc9fSDavid Howells AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */ 6010fafdc9fSDavid Howells AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */ 6020fafdc9fSDavid Howells }; 6030fafdc9fSDavid Howells 60408e0e7c8SDavid Howells /* 605f8de483eSDavid Howells * AFS inode private data. 606f8de483eSDavid Howells * 607f8de483eSDavid Howells * Note that afs_alloc_inode() *must* reset anything that could incorrectly 608f8de483eSDavid Howells * leak from one inode to another. 60908e0e7c8SDavid Howells */ 61008e0e7c8SDavid Howells struct afs_vnode { 61108e0e7c8SDavid Howells struct inode vfs_inode; /* the VFS's inode record */ 61208e0e7c8SDavid Howells 61308e0e7c8SDavid Howells struct afs_volume *volume; /* volume on which vnode resides */ 61408e0e7c8SDavid Howells struct afs_fid fid; /* the file identifier for this inode */ 61508e0e7c8SDavid Howells struct afs_file_status status; /* AFS status info for this file */ 616a4ff7401SDavid Howells afs_dataversion_t invalid_before; /* Child dentries are invalid before this */ 6179b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 6189b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 61908e0e7c8SDavid Howells #endif 620fe342cf7SDavid Howells struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */ 621d2ddc776SDavid Howells struct mutex io_lock; /* Lock for serialising I/O on this mutex */ 622b61f7dcfSDavid Howells struct rw_semaphore validate_lock; /* lock for validating this vnode */ 6234343d008SDavid Howells spinlock_t wb_lock; /* lock for wb_keys */ 62408e0e7c8SDavid Howells spinlock_t lock; /* waitqueue/flags lock */ 62508e0e7c8SDavid Howells unsigned long flags; 626c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */ 627260a9803SDavid Howells #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */ 628f3ddee8dSDavid Howells #define AFS_VNODE_DIR_VALID 2 /* Set if dir contents are valid */ 62908e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */ 63008e0e7c8SDavid Howells #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */ 63108e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */ 6320fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */ 6330fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */ 6345a813276SDavid Howells #define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */ 63508e0e7c8SDavid Howells 6364343d008SDavid Howells struct list_head wb_keys; /* List of keys available for writeback */ 637e8d6c554SDavid Howells struct list_head pending_locks; /* locks waiting to be granted */ 638e8d6c554SDavid Howells struct list_head granted_locks; /* locks granted on this file */ 639e8d6c554SDavid Howells struct delayed_work lock_work; /* work to be done in locking */ 6400fafdc9fSDavid Howells struct key *lock_key; /* Key to be used in lock ops */ 6410fafdc9fSDavid Howells enum afs_lock_state lock_state : 8; 6420fafdc9fSDavid Howells afs_lock_type_t lock_type : 8; 64331143d5dSDavid Howells 64408e0e7c8SDavid Howells /* outstanding callback notification on this file */ 645c435ee34SDavid Howells struct afs_cb_interest *cb_interest; /* Server on which this resides */ 646c435ee34SDavid Howells unsigned int cb_s_break; /* Mass break counter on ->server */ 64768251f0aSDavid Howells unsigned int cb_v_break; /* Mass break counter on ->volume */ 648c435ee34SDavid Howells unsigned int cb_break; /* Break counter on vnode */ 649c435ee34SDavid Howells seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */ 650c435ee34SDavid Howells 651c435ee34SDavid Howells time64_t cb_expires_at; /* time at which callback expires */ 65208e0e7c8SDavid Howells unsigned cb_version; /* callback version */ 65308e0e7c8SDavid Howells afs_callback_type_t cb_type; /* type of callback */ 65408e0e7c8SDavid Howells }; 65508e0e7c8SDavid Howells 65612bdcf33SDavid Howells static inline struct fscache_cookie *afs_vnode_cache(struct afs_vnode *vnode) 65712bdcf33SDavid Howells { 65812bdcf33SDavid Howells #ifdef CONFIG_AFS_FSCACHE 65912bdcf33SDavid Howells return vnode->cache; 66012bdcf33SDavid Howells #else 66112bdcf33SDavid Howells return NULL; 66212bdcf33SDavid Howells #endif 66312bdcf33SDavid Howells } 66412bdcf33SDavid Howells 66500d3b7a4SDavid Howells /* 66600d3b7a4SDavid Howells * cached security record for one user's attempt to access a vnode 66700d3b7a4SDavid Howells */ 66800d3b7a4SDavid Howells struct afs_permit { 66900d3b7a4SDavid Howells struct key *key; /* RxRPC ticket holding a security context */ 670be080a6fSDavid Howells afs_access_t access; /* CallerAccess value for this key */ 67100d3b7a4SDavid Howells }; 67200d3b7a4SDavid Howells 67300d3b7a4SDavid Howells /* 674be080a6fSDavid Howells * Immutable cache of CallerAccess records from attempts to access vnodes. 675be080a6fSDavid Howells * These may be shared between multiple vnodes. 67600d3b7a4SDavid Howells */ 67700d3b7a4SDavid Howells struct afs_permits { 678be080a6fSDavid Howells struct rcu_head rcu; 679be080a6fSDavid Howells struct hlist_node hash_node; /* Link in hash */ 680be080a6fSDavid Howells unsigned long h; /* Hash value for this permit list */ 681be080a6fSDavid Howells refcount_t usage; 682be080a6fSDavid Howells unsigned short nr_permits; /* Number of records */ 683be080a6fSDavid Howells bool invalidated; /* Invalidated due to key change */ 684be080a6fSDavid Howells struct afs_permit permits[]; /* List of permits sorted by key pointer */ 68500d3b7a4SDavid Howells }; 68600d3b7a4SDavid Howells 687b908fe6bSDavid Howells /* 688b908fe6bSDavid Howells * record of one of a system's set of network interfaces 689b908fe6bSDavid Howells */ 690b908fe6bSDavid Howells struct afs_interface { 691b908fe6bSDavid Howells struct in_addr address; /* IPv4 address bound to interface */ 692b908fe6bSDavid Howells struct in_addr netmask; /* netmask applied to address */ 693b908fe6bSDavid Howells unsigned mtu; /* MTU of interface */ 694b908fe6bSDavid Howells }; 695b908fe6bSDavid Howells 6968b2a464cSDavid Howells /* 6974584ae96SDavid Howells * Error prioritisation and accumulation. 6984584ae96SDavid Howells */ 6994584ae96SDavid Howells struct afs_error { 7004584ae96SDavid Howells short error; /* Accumulated error */ 7014584ae96SDavid Howells bool responded; /* T if server responded */ 7024584ae96SDavid Howells }; 7034584ae96SDavid Howells 7044584ae96SDavid Howells /* 7058b2a464cSDavid Howells * Cursor for iterating over a server's address list. 7068b2a464cSDavid Howells */ 7078b2a464cSDavid Howells struct afs_addr_cursor { 7088b2a464cSDavid Howells struct afs_addr_list *alist; /* Current address list (pins ref) */ 7093bf0fb6fSDavid Howells unsigned long tried; /* Tried addresses */ 7103bf0fb6fSDavid Howells signed char index; /* Current address */ 7118b2a464cSDavid Howells bool responded; /* T if the current address responded */ 712744bcd71SDavid Howells unsigned short nr_iterations; /* Number of address iterations */ 7133bf0fb6fSDavid Howells short error; 7143bf0fb6fSDavid Howells u32 abort_code; 7158b2a464cSDavid Howells }; 7168b2a464cSDavid Howells 7178b2a464cSDavid Howells /* 7180a5143f2SDavid Howells * Cursor for iterating over a set of volume location servers. 7190a5143f2SDavid Howells */ 7200a5143f2SDavid Howells struct afs_vl_cursor { 7210a5143f2SDavid Howells struct afs_addr_cursor ac; 7220a5143f2SDavid Howells struct afs_cell *cell; /* The cell we're querying */ 7230a5143f2SDavid Howells struct afs_vlserver_list *server_list; /* Current server list (pins ref) */ 7243bf0fb6fSDavid Howells struct afs_vlserver *server; /* Server on which this resides */ 7250a5143f2SDavid Howells struct key *key; /* Key for the server */ 7263bf0fb6fSDavid Howells unsigned long untried; /* Bitmask of untried servers */ 7273bf0fb6fSDavid Howells short index; /* Current server */ 7280a5143f2SDavid Howells short error; 7290a5143f2SDavid Howells unsigned short flags; 7300a5143f2SDavid Howells #define AFS_VL_CURSOR_STOP 0x0001 /* Set to cease iteration */ 7310a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRY 0x0002 /* Set to do a retry */ 7320a5143f2SDavid Howells #define AFS_VL_CURSOR_RETRIED 0x0004 /* Set if started a retry */ 733744bcd71SDavid Howells unsigned short nr_iterations; /* Number of server iterations */ 7340a5143f2SDavid Howells }; 7350a5143f2SDavid Howells 7360a5143f2SDavid Howells /* 7378b2a464cSDavid Howells * Cursor for iterating over a set of fileservers. 7388b2a464cSDavid Howells */ 7398b2a464cSDavid Howells struct afs_fs_cursor { 7408b2a464cSDavid Howells struct afs_addr_cursor ac; 741d2ddc776SDavid Howells struct afs_vnode *vnode; 742d2ddc776SDavid Howells struct afs_server_list *server_list; /* Current server list (pins ref) */ 743d2ddc776SDavid Howells struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */ 744d2ddc776SDavid Howells struct key *key; /* Key for the server */ 7453bf0fb6fSDavid Howells unsigned long untried; /* Bitmask of untried servers */ 746d2ddc776SDavid Howells unsigned int cb_break; /* cb_break + cb_s_break before the call */ 747d2ddc776SDavid Howells unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */ 7483bf0fb6fSDavid Howells short index; /* Current server */ 749e7f680f4SDavid Howells short error; 750d2ddc776SDavid Howells unsigned short flags; 751d2ddc776SDavid Howells #define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */ 752d2ddc776SDavid Howells #define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */ 753d2ddc776SDavid Howells #define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */ 754d2ddc776SDavid Howells #define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */ 755d2ddc776SDavid Howells #define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */ 756d2ddc776SDavid Howells #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */ 757744bcd71SDavid Howells unsigned short nr_iterations; /* Number of server iterations */ 7588b2a464cSDavid Howells }; 7598b2a464cSDavid Howells 760402cb8ddSDavid Howells /* 761402cb8ddSDavid Howells * Cache auxiliary data. 762402cb8ddSDavid Howells */ 763402cb8ddSDavid Howells struct afs_vnode_cache_aux { 764402cb8ddSDavid Howells u64 data_version; 765402cb8ddSDavid Howells } __packed; 766402cb8ddSDavid Howells 76798bf40cdSDavid Howells #include <trace/events/afs.h> 76898bf40cdSDavid Howells 76908e0e7c8SDavid Howells /*****************************************************************************/ 77008e0e7c8SDavid Howells /* 7718b2a464cSDavid Howells * addr_list.c 7728b2a464cSDavid Howells */ 7738b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist) 7748b2a464cSDavid Howells { 7758b2a464cSDavid Howells if (alist) 7768b2a464cSDavid Howells refcount_inc(&alist->usage); 7778b2a464cSDavid Howells return alist; 7788b2a464cSDavid Howells } 7798b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int, 7808b2a464cSDavid Howells unsigned short, 7818b2a464cSDavid Howells unsigned short); 7828b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *); 7830a5143f2SDavid Howells extern struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *, 7840a5143f2SDavid Howells const char *, size_t, char, 7858b2a464cSDavid Howells unsigned short, unsigned short); 7860a5143f2SDavid Howells extern struct afs_vlserver_list *afs_dns_query(struct afs_cell *, time64_t *); 7878b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *); 7888b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *); 7898b2a464cSDavid Howells 790bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16); 791bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16); 792d2ddc776SDavid Howells 7938b2a464cSDavid Howells /* 7949b3f26c9SDavid Howells * cache.c 7959b3f26c9SDavid Howells */ 7969b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 7979b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs; 7989b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def; 7999b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def; 8009b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def; 8019b3f26c9SDavid Howells #else 8029b3f26c9SDavid Howells #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL) 8039b3f26c9SDavid Howells #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL) 8049b3f26c9SDavid Howells #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL) 8059b3f26c9SDavid Howells #endif 8069b3f26c9SDavid Howells 8079b3f26c9SDavid Howells /* 80808e0e7c8SDavid Howells * callback.c 80908e0e7c8SDavid Howells */ 81008e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *); 81130062bd1SDavid Howells extern void __afs_break_callback(struct afs_vnode *); 812c435ee34SDavid Howells extern void afs_break_callback(struct afs_vnode *); 8135cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*); 814c435ee34SDavid Howells 815d4a96becSDavid Howells extern int afs_register_server_cb_interest(struct afs_vnode *, 816d4a96becSDavid Howells struct afs_server_list *, unsigned int); 817c435ee34SDavid Howells extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *); 818d2ddc776SDavid Howells extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *); 819c435ee34SDavid Howells 820c435ee34SDavid Howells static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi) 821c435ee34SDavid Howells { 822d4a96becSDavid Howells if (cbi) 823c435ee34SDavid Howells refcount_inc(&cbi->usage); 824c435ee34SDavid Howells return cbi; 825c435ee34SDavid Howells } 8261da177e4SLinus Torvalds 82768251f0aSDavid Howells static inline unsigned int afs_calc_vnode_cb_break(struct afs_vnode *vnode) 82868251f0aSDavid Howells { 829eeba1e9cSDavid Howells return vnode->cb_break + vnode->cb_v_break; 83068251f0aSDavid Howells } 83168251f0aSDavid Howells 83218ac6185SDavid Howells static inline bool afs_cb_is_broken(unsigned int cb_break, 83318ac6185SDavid Howells const struct afs_vnode *vnode, 83418ac6185SDavid Howells const struct afs_cb_interest *cbi) 83568251f0aSDavid Howells { 83618ac6185SDavid Howells return !cbi || cb_break != (vnode->cb_break + 83718ac6185SDavid Howells vnode->volume->cb_v_break); 83868251f0aSDavid Howells } 83968251f0aSDavid Howells 8401da177e4SLinus Torvalds /* 8411da177e4SLinus Torvalds * cell.c 8421da177e4SLinus Torvalds */ 843989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *); 844989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned); 845989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned, 846989782dcSDavid Howells const char *, bool); 8478b2a464cSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *); 8489ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *); 849989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *); 850989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *); 851f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *); 85208e0e7c8SDavid Howells 85308e0e7c8SDavid Howells /* 85408e0e7c8SDavid Howells * cmservice.c 85508e0e7c8SDavid Howells */ 85608e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *); 85708e0e7c8SDavid Howells 8581da177e4SLinus Torvalds /* 8591da177e4SLinus Torvalds * dir.c 8601da177e4SLinus Torvalds */ 8614b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations; 8624d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations; 863f3ddee8dSDavid Howells extern const struct address_space_operations afs_dir_aops; 8644d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations; 8654d673da1SDavid Howells 86666c7e1d3SDavid Howells extern void afs_d_release(struct dentry *); 86766c7e1d3SDavid Howells 86866c7e1d3SDavid Howells /* 86963a4681fSDavid Howells * dir_edit.c 87063a4681fSDavid Howells */ 87163a4681fSDavid Howells extern void afs_edit_dir_add(struct afs_vnode *, struct qstr *, struct afs_fid *, 87263a4681fSDavid Howells enum afs_edit_dir_reason); 87363a4681fSDavid Howells extern void afs_edit_dir_remove(struct afs_vnode *, struct qstr *, enum afs_edit_dir_reason); 87463a4681fSDavid Howells 87563a4681fSDavid Howells /* 87666c7e1d3SDavid Howells * dynroot.c 87766c7e1d3SDavid Howells */ 87866c7e1d3SDavid Howells extern const struct file_operations afs_dynroot_file_operations; 87966c7e1d3SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations; 88066c7e1d3SDavid Howells extern const struct dentry_operations afs_dynroot_dentry_operations; 88166c7e1d3SDavid Howells 88266c7e1d3SDavid Howells extern struct inode *afs_try_auto_mntpt(struct dentry *, struct inode *); 8830da0b7fdSDavid Howells extern int afs_dynroot_mkdir(struct afs_net *, struct afs_cell *); 8840da0b7fdSDavid Howells extern void afs_dynroot_rmdir(struct afs_net *, struct afs_cell *); 8850da0b7fdSDavid Howells extern int afs_dynroot_populate(struct super_block *); 8860da0b7fdSDavid Howells extern void afs_dynroot_depopulate(struct super_block *); 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds /* 8891da177e4SLinus Torvalds * file.c 8901da177e4SLinus Torvalds */ 891f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops; 892754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations; 89300d3b7a4SDavid Howells extern const struct file_operations afs_file_operations; 89400d3b7a4SDavid Howells 8954343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *); 8964343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *); 89700d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *); 89800d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *); 899d2ddc776SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *); 900f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *); 901196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *); 9021da177e4SLinus Torvalds 9031da177e4SLinus Torvalds /* 904e8d6c554SDavid Howells * flock.c 905e8d6c554SDavid Howells */ 906f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager; 907f044c884SDavid Howells 908e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *); 909e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *); 910e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *); 911e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *); 912e8d6c554SDavid Howells 913e8d6c554SDavid Howells /* 91408e0e7c8SDavid Howells * fsclient.c 91508e0e7c8SDavid Howells */ 916dd9fbcb8SDavid Howells #define AFS_VNODE_NOT_YET_SET 0x01 917dd9fbcb8SDavid Howells #define AFS_VNODE_META_CHANGED 0x02 918dd9fbcb8SDavid Howells #define AFS_VNODE_DATA_CHANGED 0x04 919dd9fbcb8SDavid Howells extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *, 920dd9fbcb8SDavid Howells const afs_dataversion_t *, u8); 921dd9fbcb8SDavid Howells 9220c3a5ac2SDavid Howells extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool); 923d2ddc776SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *); 924d2ddc776SDavid Howells extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *); 92563a4681fSDavid Howells extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, u64, 926d2ddc776SDavid Howells struct afs_fid *, struct afs_file_status *, struct afs_callback *); 92730062bd1SDavid Howells extern int afs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool, u64); 92863a4681fSDavid Howells extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64); 92963a4681fSDavid Howells extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64, 930d2ddc776SDavid Howells struct afs_fid *, struct afs_file_status *); 931d2ddc776SDavid Howells extern int afs_fs_rename(struct afs_fs_cursor *, const char *, 93263a4681fSDavid Howells struct afs_vnode *, const char *, u64, u64); 9334343d008SDavid Howells extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *, 934d2ddc776SDavid Howells pgoff_t, pgoff_t, unsigned, unsigned); 935d2ddc776SDavid Howells extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *); 936d2ddc776SDavid Howells extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *); 937d2ddc776SDavid Howells extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t); 938d2ddc776SDavid Howells extern int afs_fs_extend_lock(struct afs_fs_cursor *); 939d2ddc776SDavid Howells extern int afs_fs_release_lock(struct afs_fs_cursor *); 940d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *, 941d2ddc776SDavid Howells struct afs_addr_cursor *, struct key *); 9420b9bf381SDavid Howells extern struct afs_call *afs_fs_get_capabilities(struct afs_net *, struct afs_server *, 9430b9bf381SDavid Howells struct afs_addr_cursor *, struct key *, 9440b9bf381SDavid Howells unsigned int); 9455cf9dd55SDavid Howells extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *, 9465cf9dd55SDavid Howells struct afs_fid *, struct afs_file_status *, 9475cf9dd55SDavid Howells struct afs_callback *, unsigned int, 9485cf9dd55SDavid Howells struct afs_volsync *); 9495cf9dd55SDavid Howells extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *, 9505cf9dd55SDavid Howells struct afs_fid *, struct afs_file_status *, 9515cf9dd55SDavid Howells struct afs_callback *, struct afs_volsync *); 95208e0e7c8SDavid Howells 95308e0e7c8SDavid Howells /* 9543bf0fb6fSDavid Howells * fs_probe.c 9553bf0fb6fSDavid Howells */ 9563bf0fb6fSDavid Howells extern void afs_fileserver_probe_result(struct afs_call *); 9573bf0fb6fSDavid Howells extern int afs_probe_fileservers(struct afs_net *, struct key *, struct afs_server_list *); 9583bf0fb6fSDavid Howells extern int afs_wait_for_fs_probes(struct afs_server_list *, unsigned long); 9593bf0fb6fSDavid Howells 9603bf0fb6fSDavid Howells /* 9611da177e4SLinus Torvalds * inode.c 9621da177e4SLinus Torvalds */ 9630c3a5ac2SDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool); 964c435ee34SDavid Howells extern int afs_iget5_test(struct inode *, void *); 9654d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool); 96600d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *, 967260a9803SDavid Howells struct afs_fid *, struct afs_file_status *, 968d2ddc776SDavid Howells struct afs_callback *, 969d2ddc776SDavid Howells struct afs_cb_interest *); 970416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *); 971260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *); 972a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int); 97331143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *); 974b57922d9SAl Viro extern void afs_evict_inode(struct inode *); 975bec5eb61Swanglei extern int afs_drop_inode(struct inode *); 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds /* 9781da177e4SLinus Torvalds * main.c 9791da177e4SLinus Torvalds */ 9800ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq; 9815b86d4ffSDavid Howells extern int afs_net_id; 9825b86d4ffSDavid Howells 9835b86d4ffSDavid Howells static inline struct afs_net *afs_net(struct net *net) 9845b86d4ffSDavid Howells { 9855b86d4ffSDavid Howells return net_generic(net, afs_net_id); 9865b86d4ffSDavid Howells } 9875b86d4ffSDavid Howells 9885b86d4ffSDavid Howells static inline struct afs_net *afs_sb2net(struct super_block *sb) 9895b86d4ffSDavid Howells { 9905b86d4ffSDavid Howells return afs_net(AFS_FS_S(sb)->net_ns); 9915b86d4ffSDavid Howells } 992f044c884SDavid Howells 993f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry) 994f044c884SDavid Howells { 9955b86d4ffSDavid Howells return afs_sb2net(dentry->d_sb); 996f044c884SDavid Howells } 997f044c884SDavid Howells 998f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode) 999f044c884SDavid Howells { 10005b86d4ffSDavid Howells return afs_sb2net(inode->i_sb); 1001f044c884SDavid Howells } 1002f044c884SDavid Howells 1003f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode) 1004f044c884SDavid Howells { 10055b86d4ffSDavid Howells return afs_i2net(&vnode->vfs_inode); 1006f044c884SDavid Howells } 1007f044c884SDavid Howells 1008f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk) 1009f044c884SDavid Howells { 10105b86d4ffSDavid Howells return net_generic(sock_net(sk), afs_net_id); 1011f044c884SDavid Howells } 10121da177e4SLinus Torvalds 1013d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s) 1014d55b4da4SDavid Howells { 1015d55b4da4SDavid Howells atomic_inc(s); 1016d55b4da4SDavid Howells } 1017d55b4da4SDavid Howells 1018d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n) 1019d55b4da4SDavid Howells 10201da177e4SLinus Torvalds /* 102108e0e7c8SDavid Howells * misc.c 102208e0e7c8SDavid Howells */ 102308e0e7c8SDavid Howells extern int afs_abort_to_error(u32); 10244584ae96SDavid Howells extern void afs_prioritise_error(struct afs_error *, int, u32); 102508e0e7c8SDavid Howells 102608e0e7c8SDavid Howells /* 10271da177e4SLinus Torvalds * mntpt.c 10281da177e4SLinus Torvalds */ 1029754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations; 1030bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations; 10314b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations; 10321da177e4SLinus Torvalds 1033d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *); 103408e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void); 10351da177e4SLinus Torvalds 10361da177e4SLinus Torvalds /* 1037b4db2b35SArnd Bergmann * netdevices.c 1038b4db2b35SArnd Bergmann */ 10395b86d4ffSDavid Howells extern int afs_get_ipv4_interfaces(struct afs_net *, struct afs_interface *, 10405b86d4ffSDavid Howells size_t, bool); 1041b4db2b35SArnd Bergmann 1042b4db2b35SArnd Bergmann /* 10431da177e4SLinus Torvalds * proc.c 10441da177e4SLinus Torvalds */ 1045b6cfbecaSDavid Howells #ifdef CONFIG_PROC_FS 1046f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *); 1047f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *); 10485b86d4ffSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *); 10495b86d4ffSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *); 10506f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *); 1051b6cfbecaSDavid Howells #else 1052b6cfbecaSDavid Howells static inline int afs_proc_init(struct afs_net *net) { return 0; } 1053b6cfbecaSDavid Howells static inline void afs_proc_cleanup(struct afs_net *net) {} 1054b6cfbecaSDavid Howells static inline int afs_proc_cell_setup(struct afs_cell *cell) { return 0; } 1055b6cfbecaSDavid Howells static inline void afs_proc_cell_remove(struct afs_cell *cell) {} 1056b6cfbecaSDavid Howells static inline void afs_put_sysnames(struct afs_sysnames *sysnames) {} 1057b6cfbecaSDavid Howells #endif 10581da177e4SLinus Torvalds 105908e0e7c8SDavid Howells /* 1060d2ddc776SDavid Howells * rotate.c 1061d2ddc776SDavid Howells */ 1062d2ddc776SDavid Howells extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *, 1063d2ddc776SDavid Howells struct key *); 1064d2ddc776SDavid Howells extern bool afs_select_fileserver(struct afs_fs_cursor *); 1065d2ddc776SDavid Howells extern bool afs_select_current_fileserver(struct afs_fs_cursor *); 1066d2ddc776SDavid Howells extern int afs_end_vnode_operation(struct afs_fs_cursor *); 1067d2ddc776SDavid Howells 1068d2ddc776SDavid Howells /* 106908e0e7c8SDavid Howells * rxrpc.c 107008e0e7c8SDavid Howells */ 1071f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls; 10728324f0bcSDavid Howells 1073f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *); 1074f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *); 1075f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *); 1076341f741fSDavid Howells extern void afs_put_call(struct afs_call *); 10770b9bf381SDavid Howells extern void afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t); 10780b9bf381SDavid Howells extern long afs_wait_for_call_to_complete(struct afs_call *, struct afs_addr_cursor *); 1079f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *, 1080f044c884SDavid Howells const struct afs_call_type *, 108108e0e7c8SDavid Howells size_t, size_t); 108208e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *); 108308e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *); 1084b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t); 108512bdcf33SDavid Howells extern int afs_extract_data(struct afs_call *, bool); 1086160cb957SDavid Howells extern int afs_protocol_error(struct afs_call *, int, enum afs_eproto_cause); 108708e0e7c8SDavid Howells 108812bdcf33SDavid Howells static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size) 108912bdcf33SDavid Howells { 109012bdcf33SDavid Howells call->kvec[0].iov_base = buf; 109112bdcf33SDavid Howells call->kvec[0].iov_len = size; 109212bdcf33SDavid Howells iov_iter_kvec(&call->iter, READ, call->kvec, 1, size); 109312bdcf33SDavid Howells } 109412bdcf33SDavid Howells 109512bdcf33SDavid Howells static inline void afs_extract_to_tmp(struct afs_call *call) 109612bdcf33SDavid Howells { 109712bdcf33SDavid Howells afs_extract_begin(call, &call->tmp, sizeof(call->tmp)); 109812bdcf33SDavid Howells } 109912bdcf33SDavid Howells 110012bdcf33SDavid Howells static inline void afs_extract_to_tmp64(struct afs_call *call) 110112bdcf33SDavid Howells { 110212bdcf33SDavid Howells afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64)); 110312bdcf33SDavid Howells } 110412bdcf33SDavid Howells 110512bdcf33SDavid Howells static inline void afs_extract_discard(struct afs_call *call, size_t size) 110612bdcf33SDavid Howells { 110712bdcf33SDavid Howells iov_iter_discard(&call->iter, READ, size); 110812bdcf33SDavid Howells } 110912bdcf33SDavid Howells 111012bdcf33SDavid Howells static inline void afs_extract_to_buf(struct afs_call *call, size_t size) 111112bdcf33SDavid Howells { 111212bdcf33SDavid Howells afs_extract_begin(call, call->buffer, size); 111312bdcf33SDavid Howells } 111412bdcf33SDavid Howells 1115d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call) 1116372ee163SDavid Howells { 111712bdcf33SDavid Howells return afs_extract_data(call, false); 1118372ee163SDavid Howells } 1119372ee163SDavid Howells 112098bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call, 112198bf40cdSDavid Howells enum afs_call_state state) 112298bf40cdSDavid Howells { 112398bf40cdSDavid Howells return READ_ONCE(call->state) == state; 112498bf40cdSDavid Howells } 112598bf40cdSDavid Howells 112698bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call, 112798bf40cdSDavid Howells enum afs_call_state from, 112898bf40cdSDavid Howells enum afs_call_state to) 112998bf40cdSDavid Howells { 113098bf40cdSDavid Howells bool ok = false; 113198bf40cdSDavid Howells 113298bf40cdSDavid Howells spin_lock_bh(&call->state_lock); 113398bf40cdSDavid Howells if (call->state == from) { 113498bf40cdSDavid Howells call->state = to; 113598bf40cdSDavid Howells trace_afs_call_state(call, from, to, 0, 0); 113698bf40cdSDavid Howells ok = true; 113798bf40cdSDavid Howells } 113898bf40cdSDavid Howells spin_unlock_bh(&call->state_lock); 113998bf40cdSDavid Howells return ok; 114098bf40cdSDavid Howells } 114198bf40cdSDavid Howells 114298bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call, 114398bf40cdSDavid Howells int error, u32 remote_abort) 114498bf40cdSDavid Howells { 114598bf40cdSDavid Howells enum afs_call_state state; 114698bf40cdSDavid Howells bool ok = false; 114798bf40cdSDavid Howells 114898bf40cdSDavid Howells spin_lock_bh(&call->state_lock); 114998bf40cdSDavid Howells state = call->state; 115098bf40cdSDavid Howells if (state != AFS_CALL_COMPLETE) { 115198bf40cdSDavid Howells call->abort_code = remote_abort; 115298bf40cdSDavid Howells call->error = error; 115398bf40cdSDavid Howells call->state = AFS_CALL_COMPLETE; 115498bf40cdSDavid Howells trace_afs_call_state(call, state, AFS_CALL_COMPLETE, 115598bf40cdSDavid Howells error, remote_abort); 115698bf40cdSDavid Howells ok = true; 115798bf40cdSDavid Howells } 115898bf40cdSDavid Howells spin_unlock_bh(&call->state_lock); 115998bf40cdSDavid Howells if (ok) 116098bf40cdSDavid Howells trace_afs_call_done(call); 116198bf40cdSDavid Howells } 116298bf40cdSDavid Howells 116308e0e7c8SDavid Howells /* 116400d3b7a4SDavid Howells * security.c 116500d3b7a4SDavid Howells */ 1166be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *); 116700d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *); 1168be080a6fSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int); 1169416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *); 117000d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *); 11710fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *); 117210556cb2SAl Viro extern int afs_permission(struct inode *, int); 1173be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void); 117400d3b7a4SDavid Howells 117500d3b7a4SDavid Howells /* 117608e0e7c8SDavid Howells * server.c 117708e0e7c8SDavid Howells */ 117808e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock; 117908e0e7c8SDavid Howells 1180c435ee34SDavid Howells static inline struct afs_server *afs_get_server(struct afs_server *server) 1181c435ee34SDavid Howells { 1182c435ee34SDavid Howells atomic_inc(&server->usage); 1183c435ee34SDavid Howells return server; 1184c435ee34SDavid Howells } 118508e0e7c8SDavid Howells 1186f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *, 1187f044c884SDavid Howells const struct sockaddr_rxrpc *); 1188d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *); 1189d2ddc776SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *); 11909ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *); 1191d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *); 1192d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *); 1193f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *); 1194d2ddc776SDavid Howells extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *); 1195d2ddc776SDavid Howells 1196d2ddc776SDavid Howells /* 1197d2ddc776SDavid Howells * server_list.c 1198d2ddc776SDavid Howells */ 1199d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist) 1200d2ddc776SDavid Howells { 1201d2ddc776SDavid Howells refcount_inc(&slist->usage); 1202d2ddc776SDavid Howells return slist; 1203d2ddc776SDavid Howells } 1204d2ddc776SDavid Howells 1205d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *); 1206d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *, 1207d2ddc776SDavid Howells struct afs_vldb_entry *, 1208d2ddc776SDavid Howells u8); 1209d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *); 121008e0e7c8SDavid Howells 121108e0e7c8SDavid Howells /* 121200d3b7a4SDavid Howells * super.c 121300d3b7a4SDavid Howells */ 1214f044c884SDavid Howells extern int __init afs_fs_init(void); 12155b86d4ffSDavid Howells extern void afs_fs_exit(void); 121600d3b7a4SDavid Howells 121700d3b7a4SDavid Howells /* 121808e0e7c8SDavid Howells * vlclient.c 121908e0e7c8SDavid Howells */ 12200a5143f2SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_vl_cursor *, 12210a5143f2SDavid Howells const char *, int); 12220a5143f2SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_vl_cursor *, const uuid_t *); 12230b9bf381SDavid Howells extern struct afs_call *afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, 12240b9bf381SDavid Howells struct key *, struct afs_vlserver *, unsigned int); 12250a5143f2SDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_vl_cursor *, const uuid_t *); 12260a5143f2SDavid Howells 12270a5143f2SDavid Howells /* 12283bf0fb6fSDavid Howells * vl_probe.c 12293bf0fb6fSDavid Howells */ 12303bf0fb6fSDavid Howells extern void afs_vlserver_probe_result(struct afs_call *); 12313bf0fb6fSDavid Howells extern int afs_send_vl_probes(struct afs_net *, struct key *, struct afs_vlserver_list *); 12323bf0fb6fSDavid Howells extern int afs_wait_for_vl_probes(struct afs_vlserver_list *, unsigned long); 12333bf0fb6fSDavid Howells 12343bf0fb6fSDavid Howells /* 12350a5143f2SDavid Howells * vl_rotate.c 12360a5143f2SDavid Howells */ 12370a5143f2SDavid Howells extern bool afs_begin_vlserver_operation(struct afs_vl_cursor *, 12380a5143f2SDavid Howells struct afs_cell *, struct key *); 12390a5143f2SDavid Howells extern bool afs_select_vlserver(struct afs_vl_cursor *); 12400a5143f2SDavid Howells extern bool afs_select_current_vlserver(struct afs_vl_cursor *); 12410a5143f2SDavid Howells extern int afs_end_vlserver_operation(struct afs_vl_cursor *); 12420a5143f2SDavid Howells 12430a5143f2SDavid Howells /* 12440a5143f2SDavid Howells * vlserver_list.c 12450a5143f2SDavid Howells */ 12460a5143f2SDavid Howells static inline struct afs_vlserver *afs_get_vlserver(struct afs_vlserver *vlserver) 12470a5143f2SDavid Howells { 12480a5143f2SDavid Howells atomic_inc(&vlserver->usage); 12490a5143f2SDavid Howells return vlserver; 12500a5143f2SDavid Howells } 12510a5143f2SDavid Howells 12520a5143f2SDavid Howells static inline struct afs_vlserver_list *afs_get_vlserverlist(struct afs_vlserver_list *vllist) 12530a5143f2SDavid Howells { 12540a5143f2SDavid Howells if (vllist) 12550a5143f2SDavid Howells atomic_inc(&vllist->usage); 12560a5143f2SDavid Howells return vllist; 12570a5143f2SDavid Howells } 12580a5143f2SDavid Howells 12590a5143f2SDavid Howells extern struct afs_vlserver *afs_alloc_vlserver(const char *, size_t, unsigned short); 12600a5143f2SDavid Howells extern void afs_put_vlserver(struct afs_net *, struct afs_vlserver *); 12610a5143f2SDavid Howells extern struct afs_vlserver_list *afs_alloc_vlserver_list(unsigned int); 12620a5143f2SDavid Howells extern void afs_put_vlserverlist(struct afs_net *, struct afs_vlserver_list *); 12630a5143f2SDavid Howells extern struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *, 12640a5143f2SDavid Howells const void *, size_t); 126508e0e7c8SDavid Howells 126608e0e7c8SDavid Howells /* 126708e0e7c8SDavid Howells * volume.c 126808e0e7c8SDavid Howells */ 1269d2ddc776SDavid Howells static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume) 127049566f6fSDavid Howells { 127149566f6fSDavid Howells if (volume) 127249566f6fSDavid Howells atomic_inc(&volume->usage); 127349566f6fSDavid Howells return volume; 127449566f6fSDavid Howells } 127508e0e7c8SDavid Howells 127613fcc683SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_fs_context *); 1277d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *); 1278d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *); 12799ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *); 1280d2ddc776SDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct key *); 128108e0e7c8SDavid Howells 128231143d5dSDavid Howells /* 128331143d5dSDavid Howells * write.c 128431143d5dSDavid Howells */ 128531143d5dSDavid Howells extern int afs_set_page_dirty(struct page *); 128615b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping, 128715b4650eSNick Piggin loff_t pos, unsigned len, unsigned flags, 128815b4650eSNick Piggin struct page **pagep, void **fsdata); 128915b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping, 129015b4650eSNick Piggin loff_t pos, unsigned len, unsigned copied, 129115b4650eSNick Piggin struct page *page, void *fsdata); 129231143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *); 129331143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *); 129431143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); 129550b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); 129602c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int); 12970722f186SSouptick Joarder extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf); 12984343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *); 12994343d008SDavid Howells extern int afs_launder_page(struct page *); 130031143d5dSDavid Howells 1301d3e3b7eaSDavid Howells /* 1302d3e3b7eaSDavid Howells * xattr.c 1303d3e3b7eaSDavid Howells */ 1304d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[]; 1305d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t); 130631143d5dSDavid Howells 130730062bd1SDavid Howells /* 130830062bd1SDavid Howells * yfsclient.c 130930062bd1SDavid Howells */ 131030062bd1SDavid Howells extern int yfs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool); 131130062bd1SDavid Howells extern int yfs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *); 131230062bd1SDavid Howells extern int yfs_fs_create_file(struct afs_fs_cursor *, const char *, umode_t, u64, 131330062bd1SDavid Howells struct afs_fid *, struct afs_file_status *, struct afs_callback *); 131430062bd1SDavid Howells extern int yfs_fs_make_dir(struct afs_fs_cursor *, const char *, umode_t, u64, 131530062bd1SDavid Howells struct afs_fid *, struct afs_file_status *, struct afs_callback *); 131630062bd1SDavid Howells extern int yfs_fs_remove_file2(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64); 131730062bd1SDavid Howells extern int yfs_fs_remove(struct afs_fs_cursor *, struct afs_vnode *, const char *, bool, u64); 131830062bd1SDavid Howells extern int yfs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *, u64); 131930062bd1SDavid Howells extern int yfs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, u64, 132030062bd1SDavid Howells struct afs_fid *, struct afs_file_status *); 132130062bd1SDavid Howells extern int yfs_fs_rename(struct afs_fs_cursor *, const char *, 132230062bd1SDavid Howells struct afs_vnode *, const char *, u64, u64); 132330062bd1SDavid Howells extern int yfs_fs_store_data(struct afs_fs_cursor *, struct address_space *, 132430062bd1SDavid Howells pgoff_t, pgoff_t, unsigned, unsigned); 132530062bd1SDavid Howells extern int yfs_fs_setattr(struct afs_fs_cursor *, struct iattr *); 132630062bd1SDavid Howells extern int yfs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *); 132730062bd1SDavid Howells extern int yfs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t); 132830062bd1SDavid Howells extern int yfs_fs_extend_lock(struct afs_fs_cursor *); 132930062bd1SDavid Howells extern int yfs_fs_release_lock(struct afs_fs_cursor *); 133030062bd1SDavid Howells extern int yfs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *, 133130062bd1SDavid Howells struct afs_fid *, struct afs_file_status *, 133230062bd1SDavid Howells struct afs_callback *, struct afs_volsync *); 133330062bd1SDavid Howells extern int yfs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *, 133430062bd1SDavid Howells struct afs_fid *, struct afs_file_status *, 133530062bd1SDavid Howells struct afs_callback *, unsigned int, 133630062bd1SDavid Howells struct afs_volsync *); 1337d2ddc776SDavid Howells 1338d2ddc776SDavid Howells /* 1339d2ddc776SDavid Howells * Miscellaneous inline functions. 1340d2ddc776SDavid Howells */ 1341d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode) 1342d2ddc776SDavid Howells { 1343d2ddc776SDavid Howells return container_of(inode, struct afs_vnode, vfs_inode); 1344d2ddc776SDavid Howells } 1345d2ddc776SDavid Howells 1346d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode) 1347d2ddc776SDavid Howells { 1348d2ddc776SDavid Howells return &vnode->vfs_inode; 1349d2ddc776SDavid Howells } 1350d2ddc776SDavid Howells 1351d2ddc776SDavid Howells static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc, 1352d2ddc776SDavid Howells struct afs_vnode *vnode, 1353d2ddc776SDavid Howells unsigned int cb_break) 1354d2ddc776SDavid Howells { 1355d2ddc776SDavid Howells if (fc->ac.error == 0) 1356d2ddc776SDavid Howells afs_cache_permit(vnode, fc->key, cb_break); 1357d2ddc776SDavid Howells } 1358d2ddc776SDavid Howells 1359d2ddc776SDavid Howells static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc, 1360d2ddc776SDavid Howells struct afs_vnode *vnode) 1361d2ddc776SDavid Howells { 1362d2ddc776SDavid Howells if (fc->ac.error == -ENOENT) { 1363d2ddc776SDavid Howells set_bit(AFS_VNODE_DELETED, &vnode->flags); 1364d2ddc776SDavid Howells afs_break_callback(vnode); 1365d2ddc776SDavid Howells } 1366d2ddc776SDavid Howells } 1367d2ddc776SDavid Howells 1368f51375cdSDavid Howells static inline int afs_io_error(struct afs_call *call, enum afs_io_error where) 1369f51375cdSDavid Howells { 1370f51375cdSDavid Howells trace_afs_io_error(call->debug_id, -EIO, where); 1371f51375cdSDavid Howells return -EIO; 1372f51375cdSDavid Howells } 1373f51375cdSDavid Howells 1374f51375cdSDavid Howells static inline int afs_bad(struct afs_vnode *vnode, enum afs_file_error where) 1375f51375cdSDavid Howells { 1376f51375cdSDavid Howells trace_afs_file_error(vnode, -EIO, where); 1377f51375cdSDavid Howells return -EIO; 1378f51375cdSDavid Howells } 1379d2ddc776SDavid Howells 138008e0e7c8SDavid Howells /*****************************************************************************/ 138108e0e7c8SDavid Howells /* 138208e0e7c8SDavid Howells * debug tracing 138308e0e7c8SDavid Howells */ 138408e0e7c8SDavid Howells extern unsigned afs_debug; 138508e0e7c8SDavid Howells 138608e0e7c8SDavid Howells #define dbgprintk(FMT,...) \ 1387ad16df84SSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 138808e0e7c8SDavid Howells 1389530b6412SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 1390530b6412SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 139108e0e7c8SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 139208e0e7c8SDavid Howells 139308e0e7c8SDavid Howells 139408e0e7c8SDavid Howells #if defined(__KDEBUG) 139508e0e7c8SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 139608e0e7c8SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 139708e0e7c8SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 139808e0e7c8SDavid Howells 139908e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG) 140008e0e7c8SDavid Howells #define AFS_DEBUG_KENTER 0x01 140108e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE 0x02 140208e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG 0x04 140308e0e7c8SDavid Howells 140408e0e7c8SDavid Howells #define _enter(FMT,...) \ 140508e0e7c8SDavid Howells do { \ 140608e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \ 140708e0e7c8SDavid Howells kenter(FMT,##__VA_ARGS__); \ 140808e0e7c8SDavid Howells } while (0) 140908e0e7c8SDavid Howells 141008e0e7c8SDavid Howells #define _leave(FMT,...) \ 141108e0e7c8SDavid Howells do { \ 141208e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \ 141308e0e7c8SDavid Howells kleave(FMT,##__VA_ARGS__); \ 141408e0e7c8SDavid Howells } while (0) 141508e0e7c8SDavid Howells 141608e0e7c8SDavid Howells #define _debug(FMT,...) \ 141708e0e7c8SDavid Howells do { \ 141808e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \ 141908e0e7c8SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 142008e0e7c8SDavid Howells } while (0) 142108e0e7c8SDavid Howells 142208e0e7c8SDavid Howells #else 142312fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 142412fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 142512fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 142608e0e7c8SDavid Howells #endif 142708e0e7c8SDavid Howells 142808e0e7c8SDavid Howells /* 142908e0e7c8SDavid Howells * debug assertion checking 143008e0e7c8SDavid Howells */ 143108e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL) 143208e0e7c8SDavid Howells 143308e0e7c8SDavid Howells #define ASSERT(X) \ 143408e0e7c8SDavid Howells do { \ 143508e0e7c8SDavid Howells if (unlikely(!(X))) { \ 143608e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 143708e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 143808e0e7c8SDavid Howells BUG(); \ 143908e0e7c8SDavid Howells } \ 144008e0e7c8SDavid Howells } while(0) 144108e0e7c8SDavid Howells 144208e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 144308e0e7c8SDavid Howells do { \ 144408e0e7c8SDavid Howells if (unlikely(!((X) OP (Y)))) { \ 144508e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 144608e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 144708e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 144808e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 144908e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 145008e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 145108e0e7c8SDavid Howells BUG(); \ 145208e0e7c8SDavid Howells } \ 145308e0e7c8SDavid Howells } while(0) 145408e0e7c8SDavid Howells 1455416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 1456416351f2SDavid Howells do { \ 1457416351f2SDavid Howells if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \ 1458416351f2SDavid Howells printk(KERN_ERR "\n"); \ 1459416351f2SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 1460416351f2SDavid Howells printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \ 1461416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 1462416351f2SDavid Howells (unsigned long)(H)); \ 1463416351f2SDavid Howells printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \ 1464416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 1465416351f2SDavid Howells (unsigned long)(H)); \ 1466416351f2SDavid Howells BUG(); \ 1467416351f2SDavid Howells } \ 1468416351f2SDavid Howells } while(0) 1469416351f2SDavid Howells 147008e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 147108e0e7c8SDavid Howells do { \ 147208e0e7c8SDavid Howells if (unlikely((C) && !(X))) { \ 147308e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 147408e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 147508e0e7c8SDavid Howells BUG(); \ 147608e0e7c8SDavid Howells } \ 147708e0e7c8SDavid Howells } while(0) 147808e0e7c8SDavid Howells 147908e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 148008e0e7c8SDavid Howells do { \ 148108e0e7c8SDavid Howells if (unlikely((C) && !((X) OP (Y)))) { \ 148208e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 148308e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 148408e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 148508e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 148608e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 148708e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 148808e0e7c8SDavid Howells BUG(); \ 148908e0e7c8SDavid Howells } \ 149008e0e7c8SDavid Howells } while(0) 149108e0e7c8SDavid Howells 149208e0e7c8SDavid Howells #else 149308e0e7c8SDavid Howells 149408e0e7c8SDavid Howells #define ASSERT(X) \ 149508e0e7c8SDavid Howells do { \ 149608e0e7c8SDavid Howells } while(0) 149708e0e7c8SDavid Howells 149808e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 149908e0e7c8SDavid Howells do { \ 150008e0e7c8SDavid Howells } while(0) 150108e0e7c8SDavid Howells 1502416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 1503416351f2SDavid Howells do { \ 1504416351f2SDavid Howells } while(0) 1505416351f2SDavid Howells 150608e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 150708e0e7c8SDavid Howells do { \ 150808e0e7c8SDavid Howells } while(0) 150908e0e7c8SDavid Howells 151008e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 151108e0e7c8SDavid Howells do { \ 151208e0e7c8SDavid Howells } while(0) 151308e0e7c8SDavid Howells 151408e0e7c8SDavid Howells #endif /* __KDEBUGALL */ 1515