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> 24f044c884SDavid Howells #include <net/net_namespace.h> 258324f0bcSDavid Howells #include <net/af_rxrpc.h> 2600c541eaSAndrew Morton 2708e0e7c8SDavid Howells #include "afs.h" 2808e0e7c8SDavid Howells #include "afs_vl.h" 2908e0e7c8SDavid Howells 3008e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15 3108e0e7c8SDavid Howells 3231143d5dSDavid Howells struct pagevec; 3308e0e7c8SDavid Howells struct afs_call; 3408e0e7c8SDavid Howells 3500d3b7a4SDavid Howells struct afs_mount_params { 3600d3b7a4SDavid Howells bool rwpath; /* T if the parent should be considered R/W */ 3700d3b7a4SDavid Howells bool force; /* T to force cell type */ 38bec5eb61Swanglei bool autocell; /* T if set auto mount operation */ 394d673da1SDavid Howells bool dyn_root; /* T if dynamic root */ 4000d3b7a4SDavid Howells afs_voltype_t type; /* type of volume requested */ 4100d3b7a4SDavid Howells int volnamesz; /* size of volume name */ 4200d3b7a4SDavid Howells const char *volname; /* name of volume to mount */ 43f044c884SDavid Howells struct afs_net *net; /* Network namespace in effect */ 4400d3b7a4SDavid Howells struct afs_cell *cell; /* cell in which to find volume */ 4500d3b7a4SDavid Howells struct afs_volume *volume; /* volume record */ 4600d3b7a4SDavid Howells struct key *key; /* key to use for secure mounting */ 4700d3b7a4SDavid Howells }; 4800d3b7a4SDavid Howells 49c435ee34SDavid Howells struct afs_iget_data { 50c435ee34SDavid Howells struct afs_fid fid; 51c435ee34SDavid Howells struct afs_volume *volume; /* volume on which resides */ 52c435ee34SDavid Howells }; 53c435ee34SDavid Howells 548e8d7f13SDavid Howells enum afs_call_state { 5598bf40cdSDavid Howells AFS_CALL_CL_REQUESTING, /* Client: Request is being sent */ 5698bf40cdSDavid Howells AFS_CALL_CL_AWAIT_REPLY, /* Client: Awaiting reply */ 5798bf40cdSDavid Howells AFS_CALL_CL_PROC_REPLY, /* Client: rxrpc call complete; processing reply */ 5898bf40cdSDavid Howells AFS_CALL_SV_AWAIT_OP_ID, /* Server: Awaiting op ID */ 5998bf40cdSDavid Howells AFS_CALL_SV_AWAIT_REQUEST, /* Server: Awaiting request data */ 6098bf40cdSDavid Howells AFS_CALL_SV_REPLYING, /* Server: Replying */ 6198bf40cdSDavid Howells AFS_CALL_SV_AWAIT_ACK, /* Server: Awaiting final ACK */ 628e8d7f13SDavid Howells AFS_CALL_COMPLETE, /* Completed or failed */ 638e8d7f13SDavid Howells }; 64f044c884SDavid Howells 6508e0e7c8SDavid Howells /* 668b2a464cSDavid Howells * List of server addresses. 678b2a464cSDavid Howells */ 688b2a464cSDavid Howells struct afs_addr_list { 698b2a464cSDavid Howells struct rcu_head rcu; /* Must be first */ 708b2a464cSDavid Howells refcount_t usage; 71d2ddc776SDavid Howells u32 version; /* Version */ 728b2a464cSDavid Howells unsigned short nr_addrs; 738b2a464cSDavid Howells unsigned short index; /* Address currently in use */ 74d2ddc776SDavid Howells unsigned short nr_ipv4; /* Number of IPv4 addresses */ 75bf99a53cSDavid Howells unsigned long probed; /* Mask of servers that have been probed */ 76bf99a53cSDavid Howells unsigned long yfs; /* Mask of servers that are YFS */ 778b2a464cSDavid Howells struct sockaddr_rxrpc addrs[]; 788b2a464cSDavid Howells }; 798b2a464cSDavid Howells 808b2a464cSDavid Howells /* 8108e0e7c8SDavid Howells * a record of an in-progress RxRPC call 8208e0e7c8SDavid Howells */ 8308e0e7c8SDavid Howells struct afs_call { 8408e0e7c8SDavid Howells const struct afs_call_type *type; /* type of call */ 8508e0e7c8SDavid Howells wait_queue_head_t waitq; /* processes awaiting completion */ 86341f741fSDavid Howells struct work_struct async_work; /* async I/O processor */ 8708e0e7c8SDavid Howells struct work_struct work; /* actual work processor */ 8808e0e7c8SDavid Howells struct rxrpc_call *rxcall; /* RxRPC call handle */ 8908e0e7c8SDavid Howells struct key *key; /* security for this call */ 90f044c884SDavid Howells struct afs_net *net; /* The network namespace */ 91d0676a16SDavid Howells struct afs_server *cm_server; /* Server affected by incoming CM call */ 92d2ddc776SDavid Howells struct afs_cb_interest *cbi; /* Callback interest for server used */ 9308e0e7c8SDavid Howells void *request; /* request data (first part) */ 944343d008SDavid Howells struct address_space *mapping; /* Pages being written from */ 9508e0e7c8SDavid Howells void *buffer; /* reply receive buffer */ 9697e3043aSDavid Howells void *reply[4]; /* Where to put the reply */ 9731143d5dSDavid Howells pgoff_t first; /* first page in mapping to deal with */ 9831143d5dSDavid Howells pgoff_t last; /* last page in mapping to deal with */ 99d001648eSDavid Howells size_t offset; /* offset into received data store */ 100341f741fSDavid Howells atomic_t usage; 1018e8d7f13SDavid Howells enum afs_call_state state; 10298bf40cdSDavid Howells spinlock_t state_lock; 10308e0e7c8SDavid Howells int error; /* error code */ 104d001648eSDavid Howells u32 abort_code; /* Remote abort ID or 0 */ 10508e0e7c8SDavid Howells unsigned request_size; /* size of request data */ 10608e0e7c8SDavid Howells unsigned reply_max; /* maximum size of reply */ 10731143d5dSDavid Howells unsigned first_offset; /* offset into mapping[first] */ 108c435ee34SDavid Howells unsigned int cb_break; /* cb_break + cb_s_break before the call */ 109bcd89270SMarc Dionne union { 11031143d5dSDavid Howells unsigned last_to; /* amount of mapping[last] */ 111bcd89270SMarc Dionne unsigned count2; /* count used in unmarshalling */ 112bcd89270SMarc Dionne }; 11308e0e7c8SDavid Howells unsigned char unmarshall; /* unmarshalling phase */ 11408e0e7c8SDavid Howells bool incoming; /* T if incoming call */ 11531143d5dSDavid Howells bool send_pages; /* T if data from mapping should be sent */ 116d001648eSDavid Howells bool need_attention; /* T if RxRPC poked us */ 11756ff9c83SDavid Howells bool async; /* T if asynchronous */ 11833cd7f2bSDavid Howells bool ret_reply0; /* T if should return reply[0] on success */ 119a68f4a27SDavid Howells bool upgrade; /* T to request service upgrade */ 120bf99a53cSDavid Howells u16 service_id; /* Actual service ID (after upgrade) */ 121a25e21f0SDavid Howells unsigned int debug_id; /* Trace ID */ 12250a2c953SDavid Howells u32 operation_ID; /* operation ID for an incoming call */ 12308e0e7c8SDavid Howells u32 count; /* count for use in unmarshalling */ 12408e0e7c8SDavid Howells __be32 tmp; /* place to extract temporary data */ 1250c3a5ac2SDavid Howells afs_dataversion_t expected_version; /* Updated version expected from store */ 1260c3a5ac2SDavid Howells afs_dataversion_t expected_version_2; /* 2nd updated version expected from store */ 12708e0e7c8SDavid Howells }; 12808e0e7c8SDavid Howells 12908e0e7c8SDavid Howells struct afs_call_type { 13000d3b7a4SDavid Howells const char *name; 131025db80cSDavid Howells unsigned int op; /* Really enum afs_fs_operation */ 13200d3b7a4SDavid Howells 13308e0e7c8SDavid Howells /* deliver request or reply data to an call 13408e0e7c8SDavid Howells * - returning an error will cause the call to be aborted 13508e0e7c8SDavid Howells */ 136d001648eSDavid Howells int (*deliver)(struct afs_call *call); 13708e0e7c8SDavid Howells 13808e0e7c8SDavid Howells /* clean up a call */ 13908e0e7c8SDavid Howells void (*destructor)(struct afs_call *call); 140341f741fSDavid Howells 141341f741fSDavid Howells /* Work function */ 142341f741fSDavid Howells void (*work)(struct work_struct *work); 14308e0e7c8SDavid Howells }; 14408e0e7c8SDavid Howells 14508e0e7c8SDavid Howells /* 1464343d008SDavid Howells * Key available for writeback on a file. 1474343d008SDavid Howells */ 1484343d008SDavid Howells struct afs_wb_key { 1494343d008SDavid Howells refcount_t usage; 1504343d008SDavid Howells struct key *key; 1514343d008SDavid Howells struct list_head vnode_link; /* Link in vnode->wb_keys */ 1524343d008SDavid Howells }; 1534343d008SDavid Howells 1544343d008SDavid Howells /* 155215804a9SDavid Howells * AFS open file information record. Pointed to by file->private_data. 156215804a9SDavid Howells */ 157215804a9SDavid Howells struct afs_file { 158215804a9SDavid Howells struct key *key; /* The key this file was opened with */ 1594343d008SDavid Howells struct afs_wb_key *wb; /* Writeback key record for this file */ 160215804a9SDavid Howells }; 161215804a9SDavid Howells 162215804a9SDavid Howells static inline struct key *afs_file_key(struct file *file) 163215804a9SDavid Howells { 164215804a9SDavid Howells struct afs_file *af = file->private_data; 165215804a9SDavid Howells 166215804a9SDavid Howells return af->key; 167215804a9SDavid Howells } 168215804a9SDavid Howells 169215804a9SDavid Howells /* 170196ee9cdSDavid Howells * Record of an outstanding read operation on a vnode. 171196ee9cdSDavid Howells */ 172196ee9cdSDavid Howells struct afs_read { 173196ee9cdSDavid Howells loff_t pos; /* Where to start reading */ 174e8e581a8SDavid Howells loff_t len; /* How much we're asking for */ 175196ee9cdSDavid Howells loff_t actual_len; /* How much we're actually getting */ 1766a0e3999SDavid Howells loff_t remain; /* Amount remaining */ 1770c3a5ac2SDavid Howells afs_dataversion_t new_version; /* Version number returned by server */ 178196ee9cdSDavid Howells atomic_t usage; 179196ee9cdSDavid Howells unsigned int index; /* Which page we're reading into */ 180196ee9cdSDavid Howells unsigned int nr_pages; 181196ee9cdSDavid Howells void (*page_done)(struct afs_call *, struct afs_read *); 182196ee9cdSDavid Howells struct page *pages[]; 183196ee9cdSDavid Howells }; 184196ee9cdSDavid Howells 185196ee9cdSDavid Howells /* 18608e0e7c8SDavid Howells * AFS superblock private data 18708e0e7c8SDavid Howells * - there's one superblock per volume 18808e0e7c8SDavid Howells */ 18908e0e7c8SDavid Howells struct afs_super_info { 190f044c884SDavid Howells struct afs_net *net; /* Network namespace */ 19149566f6fSDavid Howells struct afs_cell *cell; /* The cell in which the volume resides */ 19208e0e7c8SDavid Howells struct afs_volume *volume; /* volume record */ 1934d673da1SDavid Howells bool dyn_root; /* True if dynamic root */ 19408e0e7c8SDavid Howells }; 19508e0e7c8SDavid Howells 19608e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) 19708e0e7c8SDavid Howells { 19808e0e7c8SDavid Howells return sb->s_fs_info; 19908e0e7c8SDavid Howells } 20008e0e7c8SDavid Howells 20108e0e7c8SDavid Howells extern struct file_system_type afs_fs_type; 20208e0e7c8SDavid Howells 20308e0e7c8SDavid Howells /* 2046f8880d8SDavid Howells * Set of substitutes for @sys. 2056f8880d8SDavid Howells */ 2066f8880d8SDavid Howells struct afs_sysnames { 2076f8880d8SDavid Howells #define AFS_NR_SYSNAME 16 2086f8880d8SDavid Howells char *subs[AFS_NR_SYSNAME]; 2096f8880d8SDavid Howells refcount_t usage; 2106f8880d8SDavid Howells unsigned short nr; 2116f8880d8SDavid Howells short error; 2126f8880d8SDavid Howells char blank[1]; 2136f8880d8SDavid Howells }; 2146f8880d8SDavid Howells 2156f8880d8SDavid Howells /* 216f044c884SDavid Howells * AFS network namespace record. 217f044c884SDavid Howells */ 218f044c884SDavid Howells struct afs_net { 219f044c884SDavid Howells struct afs_uuid uuid; 220f044c884SDavid Howells bool live; /* F if this namespace is being removed */ 221f044c884SDavid Howells 222f044c884SDavid Howells /* AF_RXRPC I/O stuff */ 223f044c884SDavid Howells struct socket *socket; 224f044c884SDavid Howells struct afs_call *spare_incoming_call; 225f044c884SDavid Howells struct work_struct charge_preallocation_work; 226f044c884SDavid Howells struct mutex socket_mutex; 227f044c884SDavid Howells atomic_t nr_outstanding_calls; 228f044c884SDavid Howells atomic_t nr_superblocks; 229f044c884SDavid Howells 230f044c884SDavid Howells /* Cell database */ 231989782dcSDavid Howells struct rb_root cells; 232f044c884SDavid Howells struct afs_cell *ws_cell; 233989782dcSDavid Howells struct work_struct cells_manager; 234989782dcSDavid Howells struct timer_list cells_timer; 235989782dcSDavid Howells atomic_t cells_outstanding; 236989782dcSDavid Howells seqlock_t cells_lock; 237f044c884SDavid Howells 238989782dcSDavid Howells spinlock_t proc_cells_lock; 239f044c884SDavid Howells struct list_head proc_cells; 240f044c884SDavid Howells 241d2ddc776SDavid Howells /* Known servers. Theoretically each fileserver can only be in one 242d2ddc776SDavid Howells * cell, but in practice, people create aliases and subsets and there's 243d2ddc776SDavid Howells * no easy way to distinguish them. 244d2ddc776SDavid Howells */ 245d2ddc776SDavid Howells seqlock_t fs_lock; /* For fs_servers */ 246d2ddc776SDavid Howells struct rb_root fs_servers; /* afs_server (by server UUID or address) */ 247d2ddc776SDavid Howells struct list_head fs_updates; /* afs_server (by update_at) */ 248d2ddc776SDavid Howells struct hlist_head fs_proc; /* procfs servers list */ 249d2ddc776SDavid Howells 250d2ddc776SDavid Howells struct hlist_head fs_addresses4; /* afs_server (by lowest IPv4 addr) */ 251d2ddc776SDavid Howells struct hlist_head fs_addresses6; /* afs_server (by lowest IPv6 addr) */ 252d2ddc776SDavid Howells seqlock_t fs_addr_lock; /* For fs_addresses[46] */ 253d2ddc776SDavid Howells 254d2ddc776SDavid Howells struct work_struct fs_manager; 255d2ddc776SDavid Howells struct timer_list fs_timer; 256d2ddc776SDavid Howells atomic_t servers_outstanding; 257f044c884SDavid Howells 258f044c884SDavid Howells /* File locking renewal management */ 259f044c884SDavid Howells struct mutex lock_manager_mutex; 260f044c884SDavid Howells 261f044c884SDavid Howells /* Misc */ 262f044c884SDavid Howells struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */ 2636f8880d8SDavid Howells struct afs_sysnames *sysnames; 2646f8880d8SDavid Howells rwlock_t sysnames_lock; 265d55b4da4SDavid Howells 266d55b4da4SDavid Howells /* Statistics counters */ 267d55b4da4SDavid Howells atomic_t n_lookup; /* Number of lookups done */ 268d55b4da4SDavid Howells atomic_t n_reval; /* Number of dentries needing revalidation */ 269d55b4da4SDavid Howells atomic_t n_inval; /* Number of invalidations by the server */ 270d55b4da4SDavid Howells atomic_t n_read_dir; /* Number of directory pages read */ 271f044c884SDavid Howells }; 272f044c884SDavid Howells 2736f8880d8SDavid Howells extern const char afs_init_sysname[]; 274f044c884SDavid Howells extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns 275f044c884SDavid Howells 276989782dcSDavid Howells enum afs_cell_state { 277989782dcSDavid Howells AFS_CELL_UNSET, 278989782dcSDavid Howells AFS_CELL_ACTIVATING, 279989782dcSDavid Howells AFS_CELL_ACTIVE, 280989782dcSDavid Howells AFS_CELL_DEACTIVATING, 281989782dcSDavid Howells AFS_CELL_INACTIVE, 282989782dcSDavid Howells AFS_CELL_FAILED, 283989782dcSDavid Howells }; 284989782dcSDavid Howells 285f044c884SDavid Howells /* 286d2ddc776SDavid Howells * AFS cell record. 287d2ddc776SDavid Howells * 288d2ddc776SDavid Howells * This is a tricky concept to get right as it is possible to create aliases 289d2ddc776SDavid Howells * simply by pointing AFSDB/SRV records for two names at the same set of VL 290d2ddc776SDavid Howells * servers; it is also possible to do things like setting up two sets of VL 291d2ddc776SDavid Howells * servers, one of which provides a superset of the volumes provided by the 292d2ddc776SDavid Howells * other (for internal/external division, for example). 293d2ddc776SDavid Howells * 294d2ddc776SDavid Howells * Cells only exist in the sense that (a) a cell's name maps to a set of VL 295d2ddc776SDavid Howells * servers and (b) a cell's name is used by the client to select the key to use 296d2ddc776SDavid Howells * for authentication and encryption. The cell name is not typically used in 297d2ddc776SDavid Howells * the protocol. 298d2ddc776SDavid Howells * 299d2ddc776SDavid Howells * There is no easy way to determine if two cells are aliases or one is a 300d2ddc776SDavid Howells * subset of another. 30108e0e7c8SDavid Howells */ 30208e0e7c8SDavid Howells struct afs_cell { 303989782dcSDavid Howells union { 304989782dcSDavid Howells struct rcu_head rcu; 305989782dcSDavid Howells struct rb_node net_node; /* Node in net->cells */ 306989782dcSDavid Howells }; 307989782dcSDavid Howells struct afs_net *net; 30800d3b7a4SDavid Howells struct key *anonymous_key; /* anonymous user key for this cell */ 309989782dcSDavid Howells struct work_struct manager; /* Manager for init/deinit/dns */ 31008e0e7c8SDavid Howells struct list_head proc_link; /* /proc cell list link */ 3119b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 3129b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 3131da177e4SLinus Torvalds #endif 314989782dcSDavid Howells time64_t dns_expiry; /* Time AFSDB/SRV record expires */ 315989782dcSDavid Howells time64_t last_inactive; /* Time of last drop of usage count */ 316989782dcSDavid Howells atomic_t usage; 317989782dcSDavid Howells unsigned long flags; 318989782dcSDavid Howells #define AFS_CELL_FL_NOT_READY 0 /* The cell record is not ready for use */ 319989782dcSDavid Howells #define AFS_CELL_FL_NO_GC 1 /* The cell was added manually, don't auto-gc */ 320989782dcSDavid Howells #define AFS_CELL_FL_NOT_FOUND 2 /* Permanent DNS error */ 321989782dcSDavid Howells #define AFS_CELL_FL_DNS_FAIL 3 /* Failed to access DNS */ 3228b2a464cSDavid Howells #define AFS_CELL_FL_NO_LOOKUP_YET 4 /* Not completed first DNS lookup yet */ 323989782dcSDavid Howells enum afs_cell_state state; 324989782dcSDavid Howells short error; 325989782dcSDavid Howells 326d2ddc776SDavid Howells /* Active fileserver interaction state. */ 327d2ddc776SDavid Howells struct list_head proc_volumes; /* procfs volume list */ 328d2ddc776SDavid Howells rwlock_t proc_lock; 329989782dcSDavid Howells 330d2ddc776SDavid Howells /* VL server list. */ 3318b2a464cSDavid Howells rwlock_t vl_addrs_lock; /* Lock on vl_addrs */ 3328b2a464cSDavid Howells struct afs_addr_list __rcu *vl_addrs; /* List of VL servers */ 333989782dcSDavid Howells u8 name_len; /* Length of name */ 334989782dcSDavid Howells char name[64 + 1]; /* Cell name, case-flattened and NUL-padded */ 33508e0e7c8SDavid Howells }; 33608e0e7c8SDavid Howells 33708e0e7c8SDavid Howells /* 338d2ddc776SDavid Howells * Cached VLDB entry. 339d2ddc776SDavid Howells * 340d2ddc776SDavid Howells * This is pointed to by cell->vldb_entries, indexed by name. 34108e0e7c8SDavid Howells */ 342d2ddc776SDavid Howells struct afs_vldb_entry { 343d2ddc776SDavid Howells afs_volid_t vid[3]; /* Volume IDs for R/W, R/O and Bak volumes */ 34400d3b7a4SDavid Howells 345d2ddc776SDavid Howells unsigned long flags; 346d2ddc776SDavid Howells #define AFS_VLDB_HAS_RW 0 /* - R/W volume exists */ 347d2ddc776SDavid Howells #define AFS_VLDB_HAS_RO 1 /* - R/O volume exists */ 348d2ddc776SDavid Howells #define AFS_VLDB_HAS_BAK 2 /* - Backup volume exists */ 349d2ddc776SDavid Howells #define AFS_VLDB_QUERY_VALID 3 /* - Record is valid */ 350d2ddc776SDavid Howells #define AFS_VLDB_QUERY_ERROR 4 /* - VL server returned error */ 351d2ddc776SDavid Howells 352d2ddc776SDavid Howells uuid_t fs_server[AFS_NMAXNSERVERS]; 353d2ddc776SDavid Howells u8 fs_mask[AFS_NMAXNSERVERS]; 35408e0e7c8SDavid Howells #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */ 35508e0e7c8SDavid Howells #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */ 35608e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */ 357d2ddc776SDavid Howells short error; 358d2ddc776SDavid Howells u8 nr_servers; /* Number of server records */ 359d2ddc776SDavid Howells u8 name_len; 360d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */ 36108e0e7c8SDavid Howells }; 36208e0e7c8SDavid Howells 36308e0e7c8SDavid Howells /* 364d2ddc776SDavid Howells * Record of fileserver with which we're actively communicating. 36508e0e7c8SDavid Howells */ 36608e0e7c8SDavid Howells struct afs_server { 367d2ddc776SDavid Howells struct rcu_head rcu; 368d2ddc776SDavid Howells union { 369d2ddc776SDavid Howells uuid_t uuid; /* Server ID */ 370d2ddc776SDavid Howells struct afs_uuid _uuid; 371d2ddc776SDavid Howells }; 372c435ee34SDavid Howells 373d2ddc776SDavid Howells struct afs_addr_list __rcu *addresses; 374d2ddc776SDavid Howells struct rb_node uuid_rb; /* Link in net->servers */ 375d2ddc776SDavid Howells struct hlist_node addr4_link; /* Link in net->fs_addresses4 */ 376d2ddc776SDavid Howells struct hlist_node addr6_link; /* Link in net->fs_addresses6 */ 377d2ddc776SDavid Howells struct hlist_node proc_link; /* Link in net->fs_proc */ 378d2ddc776SDavid Howells struct afs_server *gc_next; /* Next server in manager's list */ 379d2ddc776SDavid Howells time64_t put_time; /* Time at which last put */ 380d2ddc776SDavid Howells time64_t update_at; /* Time at which to next update the record */ 381c435ee34SDavid Howells unsigned long flags; 382d2ddc776SDavid Howells #define AFS_SERVER_FL_NEW 0 /* New server, don't inc cb_s_break */ 383d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_READY 1 /* The record is not ready for use */ 384d2ddc776SDavid Howells #define AFS_SERVER_FL_NOT_FOUND 2 /* VL server says no such server */ 385d2ddc776SDavid Howells #define AFS_SERVER_FL_VL_FAIL 3 /* Failed to access VL server */ 386d2ddc776SDavid Howells #define AFS_SERVER_FL_UPDATING 4 387d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBED 5 /* The fileserver has been probed */ 388d2ddc776SDavid Howells #define AFS_SERVER_FL_PROBING 6 /* Fileserver is being probed */ 3895cf9dd55SDavid Howells #define AFS_SERVER_FL_NO_IBULK 7 /* Fileserver doesn't support FS.InlineBulkStatus */ 390d2ddc776SDavid Howells atomic_t usage; 391d2ddc776SDavid Howells u32 addr_version; /* Address list version */ 39208e0e7c8SDavid Howells 39308e0e7c8SDavid Howells /* file service access */ 394d2ddc776SDavid Howells rwlock_t fs_lock; /* access lock */ 39508e0e7c8SDavid Howells 39608e0e7c8SDavid Howells /* callback promise management */ 397c435ee34SDavid Howells struct list_head cb_interests; /* List of superblocks using this server */ 398c435ee34SDavid Howells unsigned cb_s_break; /* Break-everything counter. */ 399c435ee34SDavid Howells rwlock_t cb_break_lock; /* Volume finding lock */ 400c435ee34SDavid Howells }; 401c435ee34SDavid Howells 402c435ee34SDavid Howells /* 403c435ee34SDavid Howells * Interest by a superblock on a server. 404c435ee34SDavid Howells */ 405c435ee34SDavid Howells struct afs_cb_interest { 406c435ee34SDavid Howells struct list_head cb_link; /* Link in server->cb_interests */ 407c435ee34SDavid Howells struct afs_server *server; /* Server on which this interest resides */ 408c435ee34SDavid Howells struct super_block *sb; /* Superblock on which inodes reside */ 409c435ee34SDavid Howells afs_volid_t vid; /* Volume ID to match */ 410c435ee34SDavid Howells refcount_t usage; 41108e0e7c8SDavid Howells }; 41208e0e7c8SDavid Howells 41308e0e7c8SDavid Howells /* 414d2ddc776SDavid Howells * Replaceable server list. 41508e0e7c8SDavid Howells */ 416d2ddc776SDavid Howells struct afs_server_entry { 417d2ddc776SDavid Howells struct afs_server *server; 418d2ddc776SDavid Howells struct afs_cb_interest *cb_interest; 419d2ddc776SDavid Howells }; 420d2ddc776SDavid Howells 421d2ddc776SDavid Howells struct afs_server_list { 422d2ddc776SDavid Howells refcount_t usage; 423d2ddc776SDavid Howells unsigned short nr_servers; 424d2ddc776SDavid Howells unsigned short index; /* Server currently in use */ 425d2ddc776SDavid Howells unsigned short vnovol_mask; /* Servers to be skipped due to VNOVOL */ 426d2ddc776SDavid Howells unsigned int seq; /* Set to ->servers_seq when installed */ 427d2ddc776SDavid Howells struct afs_server_entry servers[]; 42808e0e7c8SDavid Howells }; 42908e0e7c8SDavid Howells 43008e0e7c8SDavid Howells /* 431d2ddc776SDavid Howells * Live AFS volume management. 43208e0e7c8SDavid Howells */ 433d2ddc776SDavid Howells struct afs_volume { 434d2ddc776SDavid Howells afs_volid_t vid; /* volume ID */ 435d2ddc776SDavid Howells atomic_t usage; 436d2ddc776SDavid Howells time64_t update_at; /* Time at which to next update */ 437d2ddc776SDavid Howells struct afs_cell *cell; /* Cell to which belongs (pins ref) */ 438d2ddc776SDavid Howells struct list_head proc_link; /* Link in cell->vl_proc */ 439d2ddc776SDavid Howells unsigned long flags; 440d2ddc776SDavid Howells #define AFS_VOLUME_NEEDS_UPDATE 0 /* - T if an update needs performing */ 441d2ddc776SDavid Howells #define AFS_VOLUME_UPDATING 1 /* - T if an update is in progress */ 442d2ddc776SDavid Howells #define AFS_VOLUME_WAIT 2 /* - T if users must wait for update */ 443d2ddc776SDavid Howells #define AFS_VOLUME_DELETED 3 /* - T if volume appears deleted */ 444d2ddc776SDavid Howells #define AFS_VOLUME_OFFLINE 4 /* - T if volume offline notice given */ 445d2ddc776SDavid Howells #define AFS_VOLUME_BUSY 5 /* - T if volume busy notice given */ 446d2ddc776SDavid Howells #ifdef CONFIG_AFS_FSCACHE 447d2ddc776SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 448d2ddc776SDavid Howells #endif 449d2ddc776SDavid Howells struct afs_server_list *servers; /* List of servers on which volume resides */ 450d2ddc776SDavid Howells rwlock_t servers_lock; /* Lock for ->servers */ 451d2ddc776SDavid Howells unsigned int servers_seq; /* Incremented each time ->servers changes */ 452d2ddc776SDavid Howells 453d2ddc776SDavid Howells afs_voltype_t type; /* type of volume */ 454d2ddc776SDavid Howells short error; 455d2ddc776SDavid Howells char type_force; /* force volume type (suppress R/O -> R/W) */ 456d2ddc776SDavid Howells u8 name_len; 457d2ddc776SDavid Howells u8 name[AFS_MAXVOLNAME + 1]; /* NUL-padded volume name */ 45808e0e7c8SDavid Howells }; 45908e0e7c8SDavid Howells 4600fafdc9fSDavid Howells enum afs_lock_state { 4610fafdc9fSDavid Howells AFS_VNODE_LOCK_NONE, /* The vnode has no lock on the server */ 4620fafdc9fSDavid Howells AFS_VNODE_LOCK_WAITING_FOR_CB, /* We're waiting for the server to break the callback */ 4630fafdc9fSDavid Howells AFS_VNODE_LOCK_SETTING, /* We're asking the server for a lock */ 4640fafdc9fSDavid Howells AFS_VNODE_LOCK_GRANTED, /* We have a lock on the server */ 4650fafdc9fSDavid Howells AFS_VNODE_LOCK_EXTENDING, /* We're extending a lock on the server */ 4660fafdc9fSDavid Howells AFS_VNODE_LOCK_NEED_UNLOCK, /* We need to unlock on the server */ 4670fafdc9fSDavid Howells AFS_VNODE_LOCK_UNLOCKING, /* We're telling the server to unlock */ 4680fafdc9fSDavid Howells }; 4690fafdc9fSDavid Howells 47008e0e7c8SDavid Howells /* 471f8de483eSDavid Howells * AFS inode private data. 472f8de483eSDavid Howells * 473f8de483eSDavid Howells * Note that afs_alloc_inode() *must* reset anything that could incorrectly 474f8de483eSDavid Howells * leak from one inode to another. 47508e0e7c8SDavid Howells */ 47608e0e7c8SDavid Howells struct afs_vnode { 47708e0e7c8SDavid Howells struct inode vfs_inode; /* the VFS's inode record */ 47808e0e7c8SDavid Howells 47908e0e7c8SDavid Howells struct afs_volume *volume; /* volume on which vnode resides */ 48008e0e7c8SDavid Howells struct afs_fid fid; /* the file identifier for this inode */ 48108e0e7c8SDavid Howells struct afs_file_status status; /* AFS status info for this file */ 4829b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 4839b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 48408e0e7c8SDavid Howells #endif 485fe342cf7SDavid Howells struct afs_permits __rcu *permit_cache; /* cache of permits so far obtained */ 486d2ddc776SDavid Howells struct mutex io_lock; /* Lock for serialising I/O on this mutex */ 487260a9803SDavid Howells struct mutex validate_lock; /* lock for validating this vnode */ 4884343d008SDavid Howells spinlock_t wb_lock; /* lock for wb_keys */ 48908e0e7c8SDavid Howells spinlock_t lock; /* waitqueue/flags lock */ 49008e0e7c8SDavid Howells unsigned long flags; 491c435ee34SDavid Howells #define AFS_VNODE_CB_PROMISED 0 /* Set if vnode has a callback promise */ 492260a9803SDavid Howells #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */ 493c435ee34SDavid Howells #define AFS_VNODE_DIR_MODIFIED 2 /* set if dir vnode's data modified */ 49408e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */ 49508e0e7c8SDavid Howells #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */ 49608e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */ 4970fafdc9fSDavid Howells #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */ 4980fafdc9fSDavid Howells #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */ 49908e0e7c8SDavid Howells 5004343d008SDavid Howells struct list_head wb_keys; /* List of keys available for writeback */ 501e8d6c554SDavid Howells struct list_head pending_locks; /* locks waiting to be granted */ 502e8d6c554SDavid Howells struct list_head granted_locks; /* locks granted on this file */ 503e8d6c554SDavid Howells struct delayed_work lock_work; /* work to be done in locking */ 5040fafdc9fSDavid Howells struct key *lock_key; /* Key to be used in lock ops */ 5050fafdc9fSDavid Howells enum afs_lock_state lock_state : 8; 5060fafdc9fSDavid Howells afs_lock_type_t lock_type : 8; 50731143d5dSDavid Howells 50808e0e7c8SDavid Howells /* outstanding callback notification on this file */ 509c435ee34SDavid Howells struct afs_cb_interest *cb_interest; /* Server on which this resides */ 510c435ee34SDavid Howells unsigned int cb_s_break; /* Mass break counter on ->server */ 511c435ee34SDavid Howells unsigned int cb_break; /* Break counter on vnode */ 512c435ee34SDavid Howells seqlock_t cb_lock; /* Lock for ->cb_interest, ->status, ->cb_*break */ 513c435ee34SDavid Howells 514c435ee34SDavid Howells time64_t cb_expires_at; /* time at which callback expires */ 51508e0e7c8SDavid Howells unsigned cb_version; /* callback version */ 51608e0e7c8SDavid Howells afs_callback_type_t cb_type; /* type of callback */ 51708e0e7c8SDavid Howells }; 51808e0e7c8SDavid Howells 51900d3b7a4SDavid Howells /* 52000d3b7a4SDavid Howells * cached security record for one user's attempt to access a vnode 52100d3b7a4SDavid Howells */ 52200d3b7a4SDavid Howells struct afs_permit { 52300d3b7a4SDavid Howells struct key *key; /* RxRPC ticket holding a security context */ 524be080a6fSDavid Howells afs_access_t access; /* CallerAccess value for this key */ 52500d3b7a4SDavid Howells }; 52600d3b7a4SDavid Howells 52700d3b7a4SDavid Howells /* 528be080a6fSDavid Howells * Immutable cache of CallerAccess records from attempts to access vnodes. 529be080a6fSDavid Howells * These may be shared between multiple vnodes. 53000d3b7a4SDavid Howells */ 53100d3b7a4SDavid Howells struct afs_permits { 532be080a6fSDavid Howells struct rcu_head rcu; 533be080a6fSDavid Howells struct hlist_node hash_node; /* Link in hash */ 534be080a6fSDavid Howells unsigned long h; /* Hash value for this permit list */ 535be080a6fSDavid Howells refcount_t usage; 536be080a6fSDavid Howells unsigned short nr_permits; /* Number of records */ 537be080a6fSDavid Howells bool invalidated; /* Invalidated due to key change */ 538be080a6fSDavid Howells struct afs_permit permits[]; /* List of permits sorted by key pointer */ 53900d3b7a4SDavid Howells }; 54000d3b7a4SDavid Howells 541b908fe6bSDavid Howells /* 542b908fe6bSDavid Howells * record of one of a system's set of network interfaces 543b908fe6bSDavid Howells */ 544b908fe6bSDavid Howells struct afs_interface { 545b908fe6bSDavid Howells struct in_addr address; /* IPv4 address bound to interface */ 546b908fe6bSDavid Howells struct in_addr netmask; /* netmask applied to address */ 547b908fe6bSDavid Howells unsigned mtu; /* MTU of interface */ 548b908fe6bSDavid Howells }; 549b908fe6bSDavid Howells 5508b2a464cSDavid Howells /* 5518b2a464cSDavid Howells * Cursor for iterating over a server's address list. 5528b2a464cSDavid Howells */ 5538b2a464cSDavid Howells struct afs_addr_cursor { 5548b2a464cSDavid Howells struct afs_addr_list *alist; /* Current address list (pins ref) */ 5558b2a464cSDavid Howells struct sockaddr_rxrpc *addr; 556d2ddc776SDavid Howells u32 abort_code; 5578b2a464cSDavid Howells unsigned short start; /* Starting point in alist->addrs[] */ 5588b2a464cSDavid Howells unsigned short index; /* Wrapping offset from start to current addr */ 5598b2a464cSDavid Howells short error; 5608b2a464cSDavid Howells bool begun; /* T if we've begun iteration */ 5618b2a464cSDavid Howells bool responded; /* T if the current address responded */ 5628b2a464cSDavid Howells }; 5638b2a464cSDavid Howells 5648b2a464cSDavid Howells /* 5658b2a464cSDavid Howells * Cursor for iterating over a set of fileservers. 5668b2a464cSDavid Howells */ 5678b2a464cSDavid Howells struct afs_fs_cursor { 5688b2a464cSDavid Howells struct afs_addr_cursor ac; 569d2ddc776SDavid Howells struct afs_vnode *vnode; 570d2ddc776SDavid Howells struct afs_server_list *server_list; /* Current server list (pins ref) */ 571d2ddc776SDavid Howells struct afs_cb_interest *cbi; /* Server on which this resides (pins ref) */ 572d2ddc776SDavid Howells struct key *key; /* Key for the server */ 573d2ddc776SDavid Howells unsigned int cb_break; /* cb_break + cb_s_break before the call */ 574d2ddc776SDavid Howells unsigned int cb_break_2; /* cb_break + cb_s_break (2nd vnode) */ 575d2ddc776SDavid Howells unsigned char start; /* Initial index in server list */ 576d2ddc776SDavid Howells unsigned char index; /* Number of servers tried beyond start */ 577d2ddc776SDavid Howells unsigned short flags; 578d2ddc776SDavid Howells #define AFS_FS_CURSOR_STOP 0x0001 /* Set to cease iteration */ 579d2ddc776SDavid Howells #define AFS_FS_CURSOR_VBUSY 0x0002 /* Set if seen VBUSY */ 580d2ddc776SDavid Howells #define AFS_FS_CURSOR_VMOVED 0x0004 /* Set if seen VMOVED */ 581d2ddc776SDavid Howells #define AFS_FS_CURSOR_VNOVOL 0x0008 /* Set if seen VNOVOL */ 582d2ddc776SDavid Howells #define AFS_FS_CURSOR_CUR_ONLY 0x0010 /* Set if current server only (file lock held) */ 583d2ddc776SDavid Howells #define AFS_FS_CURSOR_NO_VSLEEP 0x0020 /* Set to prevent sleep on VBUSY, VOFFLINE, ... */ 5848b2a464cSDavid Howells }; 5858b2a464cSDavid Howells 586402cb8ddSDavid Howells /* 587402cb8ddSDavid Howells * Cache auxiliary data. 588402cb8ddSDavid Howells */ 589402cb8ddSDavid Howells struct afs_vnode_cache_aux { 590402cb8ddSDavid Howells u64 data_version; 591402cb8ddSDavid Howells } __packed; 592402cb8ddSDavid Howells 59398bf40cdSDavid Howells #include <trace/events/afs.h> 59498bf40cdSDavid Howells 59508e0e7c8SDavid Howells /*****************************************************************************/ 59608e0e7c8SDavid Howells /* 5978b2a464cSDavid Howells * addr_list.c 5988b2a464cSDavid Howells */ 5998b2a464cSDavid Howells static inline struct afs_addr_list *afs_get_addrlist(struct afs_addr_list *alist) 6008b2a464cSDavid Howells { 6018b2a464cSDavid Howells if (alist) 6028b2a464cSDavid Howells refcount_inc(&alist->usage); 6038b2a464cSDavid Howells return alist; 6048b2a464cSDavid Howells } 6058b2a464cSDavid Howells extern struct afs_addr_list *afs_alloc_addrlist(unsigned int, 6068b2a464cSDavid Howells unsigned short, 6078b2a464cSDavid Howells unsigned short); 6088b2a464cSDavid Howells extern void afs_put_addrlist(struct afs_addr_list *); 6098b2a464cSDavid Howells extern struct afs_addr_list *afs_parse_text_addrs(const char *, size_t, char, 6108b2a464cSDavid Howells unsigned short, unsigned short); 6118b2a464cSDavid Howells extern struct afs_addr_list *afs_dns_query(struct afs_cell *, time64_t *); 6128b2a464cSDavid Howells extern bool afs_iterate_addresses(struct afs_addr_cursor *); 6138b2a464cSDavid Howells extern int afs_end_cursor(struct afs_addr_cursor *); 6148b2a464cSDavid Howells extern int afs_set_vl_cursor(struct afs_addr_cursor *, struct afs_cell *); 6158b2a464cSDavid Howells 616bf99a53cSDavid Howells extern void afs_merge_fs_addr4(struct afs_addr_list *, __be32, u16); 617bf99a53cSDavid Howells extern void afs_merge_fs_addr6(struct afs_addr_list *, __be32 *, u16); 618d2ddc776SDavid Howells 6198b2a464cSDavid Howells /* 6209b3f26c9SDavid Howells * cache.c 6219b3f26c9SDavid Howells */ 6229b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 6239b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs; 6249b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def; 6259b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def; 6269b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def; 6279b3f26c9SDavid Howells #else 6289b3f26c9SDavid Howells #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL) 6299b3f26c9SDavid Howells #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL) 6309b3f26c9SDavid Howells #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL) 6319b3f26c9SDavid Howells #endif 6329b3f26c9SDavid Howells 6339b3f26c9SDavid Howells /* 63408e0e7c8SDavid Howells * callback.c 63508e0e7c8SDavid Howells */ 63608e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *); 637c435ee34SDavid Howells extern void afs_break_callback(struct afs_vnode *); 6385cf9dd55SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, struct afs_callback_break*); 639c435ee34SDavid Howells 640d2ddc776SDavid Howells extern int afs_register_server_cb_interest(struct afs_vnode *, struct afs_server_entry *); 641c435ee34SDavid Howells extern void afs_put_cb_interest(struct afs_net *, struct afs_cb_interest *); 642d2ddc776SDavid Howells extern void afs_clear_callback_interests(struct afs_net *, struct afs_server_list *); 643c435ee34SDavid Howells 644c435ee34SDavid Howells static inline struct afs_cb_interest *afs_get_cb_interest(struct afs_cb_interest *cbi) 645c435ee34SDavid Howells { 646c435ee34SDavid Howells refcount_inc(&cbi->usage); 647c435ee34SDavid Howells return cbi; 648c435ee34SDavid Howells } 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds /* 6511da177e4SLinus Torvalds * cell.c 6521da177e4SLinus Torvalds */ 653989782dcSDavid Howells extern int afs_cell_init(struct afs_net *, const char *); 654989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell_rcu(struct afs_net *, const char *, unsigned); 655989782dcSDavid Howells extern struct afs_cell *afs_lookup_cell(struct afs_net *, const char *, unsigned, 656989782dcSDavid Howells const char *, bool); 6578b2a464cSDavid Howells extern struct afs_cell *afs_get_cell(struct afs_cell *); 6589ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *); 659989782dcSDavid Howells extern void afs_manage_cells(struct work_struct *); 660989782dcSDavid Howells extern void afs_cells_timer(struct timer_list *); 661f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *); 66208e0e7c8SDavid Howells 66308e0e7c8SDavid Howells /* 66408e0e7c8SDavid Howells * cmservice.c 66508e0e7c8SDavid Howells */ 66608e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *); 66708e0e7c8SDavid Howells 6681da177e4SLinus Torvalds /* 6691da177e4SLinus Torvalds * dir.c 6701da177e4SLinus Torvalds */ 6714b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations; 6724d673da1SDavid Howells extern const struct inode_operations afs_dir_inode_operations; 6734d673da1SDavid Howells extern const struct file_operations afs_dynroot_file_operations; 6744d673da1SDavid Howells extern const struct inode_operations afs_dynroot_inode_operations; 6754d673da1SDavid Howells extern const struct dentry_operations afs_fs_dentry_operations; 6764d673da1SDavid Howells 6774d673da1SDavid Howells extern bool afs_dir_check_page(struct inode *, struct page *); 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds /* 6801da177e4SLinus Torvalds * file.c 6811da177e4SLinus Torvalds */ 682f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops; 683754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations; 68400d3b7a4SDavid Howells extern const struct file_operations afs_file_operations; 68500d3b7a4SDavid Howells 6864343d008SDavid Howells extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *); 6874343d008SDavid Howells extern void afs_put_wb_key(struct afs_wb_key *); 68800d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *); 68900d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *); 690d2ddc776SDavid Howells extern int afs_fetch_data(struct afs_vnode *, struct key *, struct afs_read *); 691f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *); 692196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *); 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds /* 695e8d6c554SDavid Howells * flock.c 696e8d6c554SDavid Howells */ 697f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager; 698f044c884SDavid Howells 699e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *); 700e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *); 701e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *); 702e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *); 703e8d6c554SDavid Howells 704e8d6c554SDavid Howells /* 70508e0e7c8SDavid Howells * fsclient.c 70608e0e7c8SDavid Howells */ 707dd9fbcb8SDavid Howells #define AFS_VNODE_NOT_YET_SET 0x01 708dd9fbcb8SDavid Howells #define AFS_VNODE_META_CHANGED 0x02 709dd9fbcb8SDavid Howells #define AFS_VNODE_DATA_CHANGED 0x04 710dd9fbcb8SDavid Howells extern void afs_update_inode_from_status(struct afs_vnode *, struct afs_file_status *, 711dd9fbcb8SDavid Howells const afs_dataversion_t *, u8); 712dd9fbcb8SDavid Howells 7130c3a5ac2SDavid Howells extern int afs_fs_fetch_file_status(struct afs_fs_cursor *, struct afs_volsync *, bool); 714d2ddc776SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *); 715d2ddc776SDavid Howells extern int afs_fs_fetch_data(struct afs_fs_cursor *, struct afs_read *); 716d2ddc776SDavid Howells extern int afs_fs_create(struct afs_fs_cursor *, const char *, umode_t, 717d2ddc776SDavid Howells struct afs_fid *, struct afs_file_status *, struct afs_callback *); 718d2ddc776SDavid Howells extern int afs_fs_remove(struct afs_fs_cursor *, const char *, bool); 719d2ddc776SDavid Howells extern int afs_fs_link(struct afs_fs_cursor *, struct afs_vnode *, const char *); 720d2ddc776SDavid Howells extern int afs_fs_symlink(struct afs_fs_cursor *, const char *, const char *, 721d2ddc776SDavid Howells struct afs_fid *, struct afs_file_status *); 722d2ddc776SDavid Howells extern int afs_fs_rename(struct afs_fs_cursor *, const char *, 723d2ddc776SDavid Howells struct afs_vnode *, const char *); 7244343d008SDavid Howells extern int afs_fs_store_data(struct afs_fs_cursor *, struct address_space *, 725d2ddc776SDavid Howells pgoff_t, pgoff_t, unsigned, unsigned); 726d2ddc776SDavid Howells extern int afs_fs_setattr(struct afs_fs_cursor *, struct iattr *); 727d2ddc776SDavid Howells extern int afs_fs_get_volume_status(struct afs_fs_cursor *, struct afs_volume_status *); 728d2ddc776SDavid Howells extern int afs_fs_set_lock(struct afs_fs_cursor *, afs_lock_type_t); 729d2ddc776SDavid Howells extern int afs_fs_extend_lock(struct afs_fs_cursor *); 730d2ddc776SDavid Howells extern int afs_fs_release_lock(struct afs_fs_cursor *); 731d2ddc776SDavid Howells extern int afs_fs_give_up_all_callbacks(struct afs_net *, struct afs_server *, 732d2ddc776SDavid Howells struct afs_addr_cursor *, struct key *); 733d2ddc776SDavid Howells extern int afs_fs_get_capabilities(struct afs_net *, struct afs_server *, 734d2ddc776SDavid Howells struct afs_addr_cursor *, struct key *); 7355cf9dd55SDavid Howells extern int afs_fs_inline_bulk_status(struct afs_fs_cursor *, struct afs_net *, 7365cf9dd55SDavid Howells struct afs_fid *, struct afs_file_status *, 7375cf9dd55SDavid Howells struct afs_callback *, unsigned int, 7385cf9dd55SDavid Howells struct afs_volsync *); 7395cf9dd55SDavid Howells extern int afs_fs_fetch_status(struct afs_fs_cursor *, struct afs_net *, 7405cf9dd55SDavid Howells struct afs_fid *, struct afs_file_status *, 7415cf9dd55SDavid Howells struct afs_callback *, struct afs_volsync *); 74208e0e7c8SDavid Howells 74308e0e7c8SDavid Howells /* 7441da177e4SLinus Torvalds * inode.c 7451da177e4SLinus Torvalds */ 7460c3a5ac2SDavid Howells extern int afs_fetch_status(struct afs_vnode *, struct key *, bool); 747c435ee34SDavid Howells extern int afs_iget5_test(struct inode *, void *); 7484d673da1SDavid Howells extern struct inode *afs_iget_pseudo_dir(struct super_block *, bool); 74900d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *, 750260a9803SDavid Howells struct afs_fid *, struct afs_file_status *, 751d2ddc776SDavid Howells struct afs_callback *, 752d2ddc776SDavid Howells struct afs_cb_interest *); 753416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *); 754260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *); 755a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int); 75631143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *); 757b57922d9SAl Viro extern void afs_evict_inode(struct inode *); 758bec5eb61Swanglei extern int afs_drop_inode(struct inode *); 7591da177e4SLinus Torvalds 7601da177e4SLinus Torvalds /* 7611da177e4SLinus Torvalds * main.c 7621da177e4SLinus Torvalds */ 7630ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq; 764f044c884SDavid Howells 765f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry) 766f044c884SDavid Howells { 767f044c884SDavid Howells return &__afs_net; 768f044c884SDavid Howells } 769f044c884SDavid Howells 770f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode) 771f044c884SDavid Howells { 772f044c884SDavid Howells return &__afs_net; 773f044c884SDavid Howells } 774f044c884SDavid Howells 775f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode) 776f044c884SDavid Howells { 777f044c884SDavid Howells return &__afs_net; 778f044c884SDavid Howells } 779f044c884SDavid Howells 780f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk) 781f044c884SDavid Howells { 782f044c884SDavid Howells return &__afs_net; 783f044c884SDavid Howells } 784f044c884SDavid Howells 785f044c884SDavid Howells static inline struct afs_net *afs_get_net(struct afs_net *net) 786f044c884SDavid Howells { 787f044c884SDavid Howells return net; 788f044c884SDavid Howells } 789f044c884SDavid Howells 790f044c884SDavid Howells static inline void afs_put_net(struct afs_net *net) 791f044c884SDavid Howells { 792f044c884SDavid Howells } 7931da177e4SLinus Torvalds 794d55b4da4SDavid Howells static inline void __afs_stat(atomic_t *s) 795d55b4da4SDavid Howells { 796d55b4da4SDavid Howells atomic_inc(s); 797d55b4da4SDavid Howells } 798d55b4da4SDavid Howells 799d55b4da4SDavid Howells #define afs_stat_v(vnode, n) __afs_stat(&afs_v2net(vnode)->n) 800d55b4da4SDavid Howells 8011da177e4SLinus Torvalds /* 80208e0e7c8SDavid Howells * misc.c 80308e0e7c8SDavid Howells */ 80408e0e7c8SDavid Howells extern int afs_abort_to_error(u32); 80508e0e7c8SDavid Howells 80608e0e7c8SDavid Howells /* 8071da177e4SLinus Torvalds * mntpt.c 8081da177e4SLinus Torvalds */ 809754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations; 810bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations; 8114b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations; 8121da177e4SLinus Torvalds 813d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *); 81408e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void); 8151da177e4SLinus Torvalds 8161da177e4SLinus Torvalds /* 817b4db2b35SArnd Bergmann * netdevices.c 818b4db2b35SArnd Bergmann */ 819b4db2b35SArnd Bergmann extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool); 820b4db2b35SArnd Bergmann 821b4db2b35SArnd Bergmann /* 8221da177e4SLinus Torvalds * proc.c 8231da177e4SLinus Torvalds */ 824f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *); 825f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *); 826f044c884SDavid Howells extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *); 827f044c884SDavid Howells extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *); 8286f8880d8SDavid Howells extern void afs_put_sysnames(struct afs_sysnames *); 8291da177e4SLinus Torvalds 83008e0e7c8SDavid Howells /* 831d2ddc776SDavid Howells * rotate.c 832d2ddc776SDavid Howells */ 833d2ddc776SDavid Howells extern bool afs_begin_vnode_operation(struct afs_fs_cursor *, struct afs_vnode *, 834d2ddc776SDavid Howells struct key *); 835d2ddc776SDavid Howells extern bool afs_select_fileserver(struct afs_fs_cursor *); 836d2ddc776SDavid Howells extern bool afs_select_current_fileserver(struct afs_fs_cursor *); 837d2ddc776SDavid Howells extern int afs_end_vnode_operation(struct afs_fs_cursor *); 838d2ddc776SDavid Howells 839d2ddc776SDavid Howells /* 84008e0e7c8SDavid Howells * rxrpc.c 84108e0e7c8SDavid Howells */ 842f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls; 8438324f0bcSDavid Howells 844f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *); 845f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *); 846f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *); 847341f741fSDavid Howells extern void afs_put_call(struct afs_call *); 848341f741fSDavid Howells extern int afs_queue_call_work(struct afs_call *); 8498b2a464cSDavid Howells extern long afs_make_call(struct afs_addr_cursor *, struct afs_call *, gfp_t, bool); 850f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *, 851f044c884SDavid Howells const struct afs_call_type *, 85208e0e7c8SDavid Howells size_t, size_t); 85308e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *); 85408e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *); 855b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t); 856d001648eSDavid Howells extern int afs_extract_data(struct afs_call *, void *, size_t, bool); 85708e0e7c8SDavid Howells 858d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call) 859372ee163SDavid Howells { 860d001648eSDavid Howells return afs_extract_data(call, call->buffer, call->reply_max, false); 861372ee163SDavid Howells } 862372ee163SDavid Howells 86398bf40cdSDavid Howells static inline bool afs_check_call_state(struct afs_call *call, 86498bf40cdSDavid Howells enum afs_call_state state) 86598bf40cdSDavid Howells { 86698bf40cdSDavid Howells return READ_ONCE(call->state) == state; 86798bf40cdSDavid Howells } 86898bf40cdSDavid Howells 86998bf40cdSDavid Howells static inline bool afs_set_call_state(struct afs_call *call, 87098bf40cdSDavid Howells enum afs_call_state from, 87198bf40cdSDavid Howells enum afs_call_state to) 87298bf40cdSDavid Howells { 87398bf40cdSDavid Howells bool ok = false; 87498bf40cdSDavid Howells 87598bf40cdSDavid Howells spin_lock_bh(&call->state_lock); 87698bf40cdSDavid Howells if (call->state == from) { 87798bf40cdSDavid Howells call->state = to; 87898bf40cdSDavid Howells trace_afs_call_state(call, from, to, 0, 0); 87998bf40cdSDavid Howells ok = true; 88098bf40cdSDavid Howells } 88198bf40cdSDavid Howells spin_unlock_bh(&call->state_lock); 88298bf40cdSDavid Howells return ok; 88398bf40cdSDavid Howells } 88498bf40cdSDavid Howells 88598bf40cdSDavid Howells static inline void afs_set_call_complete(struct afs_call *call, 88698bf40cdSDavid Howells int error, u32 remote_abort) 88798bf40cdSDavid Howells { 88898bf40cdSDavid Howells enum afs_call_state state; 88998bf40cdSDavid Howells bool ok = false; 89098bf40cdSDavid Howells 89198bf40cdSDavid Howells spin_lock_bh(&call->state_lock); 89298bf40cdSDavid Howells state = call->state; 89398bf40cdSDavid Howells if (state != AFS_CALL_COMPLETE) { 89498bf40cdSDavid Howells call->abort_code = remote_abort; 89598bf40cdSDavid Howells call->error = error; 89698bf40cdSDavid Howells call->state = AFS_CALL_COMPLETE; 89798bf40cdSDavid Howells trace_afs_call_state(call, state, AFS_CALL_COMPLETE, 89898bf40cdSDavid Howells error, remote_abort); 89998bf40cdSDavid Howells ok = true; 90098bf40cdSDavid Howells } 90198bf40cdSDavid Howells spin_unlock_bh(&call->state_lock); 90298bf40cdSDavid Howells if (ok) 90398bf40cdSDavid Howells trace_afs_call_done(call); 90498bf40cdSDavid Howells } 90598bf40cdSDavid Howells 90608e0e7c8SDavid Howells /* 90700d3b7a4SDavid Howells * security.c 90800d3b7a4SDavid Howells */ 909be080a6fSDavid Howells extern void afs_put_permits(struct afs_permits *); 91000d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *); 911be080a6fSDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, unsigned int); 912416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *); 91300d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *); 9140fafdc9fSDavid Howells extern int afs_check_permit(struct afs_vnode *, struct key *, afs_access_t *); 91510556cb2SAl Viro extern int afs_permission(struct inode *, int); 916be080a6fSDavid Howells extern void __exit afs_clean_up_permit_cache(void); 91700d3b7a4SDavid Howells 91800d3b7a4SDavid Howells /* 91908e0e7c8SDavid Howells * server.c 92008e0e7c8SDavid Howells */ 92108e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock; 92208e0e7c8SDavid Howells 923c435ee34SDavid Howells static inline struct afs_server *afs_get_server(struct afs_server *server) 924c435ee34SDavid Howells { 925c435ee34SDavid Howells atomic_inc(&server->usage); 926c435ee34SDavid Howells return server; 927c435ee34SDavid Howells } 92808e0e7c8SDavid Howells 929f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *, 930f044c884SDavid Howells const struct sockaddr_rxrpc *); 931d2ddc776SDavid Howells extern struct afs_server *afs_find_server_by_uuid(struct afs_net *, const uuid_t *); 932d2ddc776SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, struct key *, const uuid_t *); 9339ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *); 934d2ddc776SDavid Howells extern void afs_manage_servers(struct work_struct *); 935d2ddc776SDavid Howells extern void afs_servers_timer(struct timer_list *); 936f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *); 937d2ddc776SDavid Howells extern bool afs_probe_fileserver(struct afs_fs_cursor *); 938d2ddc776SDavid Howells extern bool afs_check_server_record(struct afs_fs_cursor *, struct afs_server *); 939d2ddc776SDavid Howells 940d2ddc776SDavid Howells /* 941d2ddc776SDavid Howells * server_list.c 942d2ddc776SDavid Howells */ 943d2ddc776SDavid Howells static inline struct afs_server_list *afs_get_serverlist(struct afs_server_list *slist) 944d2ddc776SDavid Howells { 945d2ddc776SDavid Howells refcount_inc(&slist->usage); 946d2ddc776SDavid Howells return slist; 947d2ddc776SDavid Howells } 948d2ddc776SDavid Howells 949d2ddc776SDavid Howells extern void afs_put_serverlist(struct afs_net *, struct afs_server_list *); 950d2ddc776SDavid Howells extern struct afs_server_list *afs_alloc_server_list(struct afs_cell *, struct key *, 951d2ddc776SDavid Howells struct afs_vldb_entry *, 952d2ddc776SDavid Howells u8); 953d2ddc776SDavid Howells extern bool afs_annotate_server_list(struct afs_server_list *, struct afs_server_list *); 95408e0e7c8SDavid Howells 95508e0e7c8SDavid Howells /* 95600d3b7a4SDavid Howells * super.c 95700d3b7a4SDavid Howells */ 958f044c884SDavid Howells extern int __init afs_fs_init(void); 959f044c884SDavid Howells extern void __exit afs_fs_exit(void); 96000d3b7a4SDavid Howells 96100d3b7a4SDavid Howells /* 96208e0e7c8SDavid Howells * vlclient.c 96308e0e7c8SDavid Howells */ 964d2ddc776SDavid Howells extern struct afs_vldb_entry *afs_vl_get_entry_by_name_u(struct afs_net *, 965d2ddc776SDavid Howells struct afs_addr_cursor *, 966d2ddc776SDavid Howells struct key *, const char *, int); 967d2ddc776SDavid Howells extern struct afs_addr_list *afs_vl_get_addrs_u(struct afs_net *, struct afs_addr_cursor *, 968d2ddc776SDavid Howells struct key *, const uuid_t *); 969bf99a53cSDavid Howells extern int afs_vl_get_capabilities(struct afs_net *, struct afs_addr_cursor *, struct key *); 970bf99a53cSDavid Howells extern struct afs_addr_list *afs_yfsvl_get_endpoints(struct afs_net *, struct afs_addr_cursor *, 971bf99a53cSDavid Howells struct key *, const uuid_t *); 97208e0e7c8SDavid Howells 97308e0e7c8SDavid Howells /* 97408e0e7c8SDavid Howells * volume.c 97508e0e7c8SDavid Howells */ 976d2ddc776SDavid Howells static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume) 97749566f6fSDavid Howells { 97849566f6fSDavid Howells if (volume) 97949566f6fSDavid Howells atomic_inc(&volume->usage); 98049566f6fSDavid Howells return volume; 98149566f6fSDavid Howells } 98208e0e7c8SDavid Howells 983d2ddc776SDavid Howells extern struct afs_volume *afs_create_volume(struct afs_mount_params *); 984d2ddc776SDavid Howells extern void afs_activate_volume(struct afs_volume *); 985d2ddc776SDavid Howells extern void afs_deactivate_volume(struct afs_volume *); 9869ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *); 987d2ddc776SDavid Howells extern int afs_check_volume_status(struct afs_volume *, struct key *); 98808e0e7c8SDavid Howells 98931143d5dSDavid Howells /* 99031143d5dSDavid Howells * write.c 99131143d5dSDavid Howells */ 99231143d5dSDavid Howells extern int afs_set_page_dirty(struct page *); 99315b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping, 99415b4650eSNick Piggin loff_t pos, unsigned len, unsigned flags, 99515b4650eSNick Piggin struct page **pagep, void **fsdata); 99615b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping, 99715b4650eSNick Piggin loff_t pos, unsigned len, unsigned copied, 99815b4650eSNick Piggin struct page *page, void *fsdata); 99931143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *); 100031143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *); 100131143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); 100250b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); 100358fed94dSDavid Howells extern int afs_flush(struct file *, fl_owner_t); 100402c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int); 10051cf7a151SDavid Howells extern int afs_page_mkwrite(struct vm_fault *); 10064343d008SDavid Howells extern void afs_prune_wb_keys(struct afs_vnode *); 10074343d008SDavid Howells extern int afs_launder_page(struct page *); 100831143d5dSDavid Howells 1009d3e3b7eaSDavid Howells /* 1010d3e3b7eaSDavid Howells * xattr.c 1011d3e3b7eaSDavid Howells */ 1012d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[]; 1013d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t); 101431143d5dSDavid Howells 1015d2ddc776SDavid Howells 1016d2ddc776SDavid Howells /* 1017d2ddc776SDavid Howells * Miscellaneous inline functions. 1018d2ddc776SDavid Howells */ 1019d2ddc776SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode) 1020d2ddc776SDavid Howells { 1021d2ddc776SDavid Howells return container_of(inode, struct afs_vnode, vfs_inode); 1022d2ddc776SDavid Howells } 1023d2ddc776SDavid Howells 1024d2ddc776SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode) 1025d2ddc776SDavid Howells { 1026d2ddc776SDavid Howells return &vnode->vfs_inode; 1027d2ddc776SDavid Howells } 1028d2ddc776SDavid Howells 1029d2ddc776SDavid Howells static inline void afs_vnode_commit_status(struct afs_fs_cursor *fc, 1030d2ddc776SDavid Howells struct afs_vnode *vnode, 1031d2ddc776SDavid Howells unsigned int cb_break) 1032d2ddc776SDavid Howells { 1033d2ddc776SDavid Howells if (fc->ac.error == 0) 1034d2ddc776SDavid Howells afs_cache_permit(vnode, fc->key, cb_break); 1035d2ddc776SDavid Howells } 1036d2ddc776SDavid Howells 1037d2ddc776SDavid Howells static inline void afs_check_for_remote_deletion(struct afs_fs_cursor *fc, 1038d2ddc776SDavid Howells struct afs_vnode *vnode) 1039d2ddc776SDavid Howells { 1040d2ddc776SDavid Howells if (fc->ac.error == -ENOENT) { 1041d2ddc776SDavid Howells set_bit(AFS_VNODE_DELETED, &vnode->flags); 1042d2ddc776SDavid Howells afs_break_callback(vnode); 1043d2ddc776SDavid Howells } 1044d2ddc776SDavid Howells } 1045d2ddc776SDavid Howells 1046d2ddc776SDavid Howells 104708e0e7c8SDavid Howells /*****************************************************************************/ 104808e0e7c8SDavid Howells /* 104908e0e7c8SDavid Howells * debug tracing 105008e0e7c8SDavid Howells */ 105108e0e7c8SDavid Howells extern unsigned afs_debug; 105208e0e7c8SDavid Howells 105308e0e7c8SDavid Howells #define dbgprintk(FMT,...) \ 1054ad16df84SSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 105508e0e7c8SDavid Howells 1056530b6412SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 1057530b6412SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 105808e0e7c8SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 105908e0e7c8SDavid Howells 106008e0e7c8SDavid Howells 106108e0e7c8SDavid Howells #if defined(__KDEBUG) 106208e0e7c8SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 106308e0e7c8SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 106408e0e7c8SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 106508e0e7c8SDavid Howells 106608e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG) 106708e0e7c8SDavid Howells #define AFS_DEBUG_KENTER 0x01 106808e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE 0x02 106908e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG 0x04 107008e0e7c8SDavid Howells 107108e0e7c8SDavid Howells #define _enter(FMT,...) \ 107208e0e7c8SDavid Howells do { \ 107308e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \ 107408e0e7c8SDavid Howells kenter(FMT,##__VA_ARGS__); \ 107508e0e7c8SDavid Howells } while (0) 107608e0e7c8SDavid Howells 107708e0e7c8SDavid Howells #define _leave(FMT,...) \ 107808e0e7c8SDavid Howells do { \ 107908e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \ 108008e0e7c8SDavid Howells kleave(FMT,##__VA_ARGS__); \ 108108e0e7c8SDavid Howells } while (0) 108208e0e7c8SDavid Howells 108308e0e7c8SDavid Howells #define _debug(FMT,...) \ 108408e0e7c8SDavid Howells do { \ 108508e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \ 108608e0e7c8SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 108708e0e7c8SDavid Howells } while (0) 108808e0e7c8SDavid Howells 108908e0e7c8SDavid Howells #else 109012fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 109112fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 109212fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 109308e0e7c8SDavid Howells #endif 109408e0e7c8SDavid Howells 109508e0e7c8SDavid Howells /* 109608e0e7c8SDavid Howells * debug assertion checking 109708e0e7c8SDavid Howells */ 109808e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL) 109908e0e7c8SDavid Howells 110008e0e7c8SDavid Howells #define ASSERT(X) \ 110108e0e7c8SDavid Howells do { \ 110208e0e7c8SDavid Howells if (unlikely(!(X))) { \ 110308e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 110408e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 110508e0e7c8SDavid Howells BUG(); \ 110608e0e7c8SDavid Howells } \ 110708e0e7c8SDavid Howells } while(0) 110808e0e7c8SDavid Howells 110908e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 111008e0e7c8SDavid Howells do { \ 111108e0e7c8SDavid Howells if (unlikely(!((X) OP (Y)))) { \ 111208e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 111308e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 111408e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 111508e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 111608e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 111708e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 111808e0e7c8SDavid Howells BUG(); \ 111908e0e7c8SDavid Howells } \ 112008e0e7c8SDavid Howells } while(0) 112108e0e7c8SDavid Howells 1122416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 1123416351f2SDavid Howells do { \ 1124416351f2SDavid Howells if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \ 1125416351f2SDavid Howells printk(KERN_ERR "\n"); \ 1126416351f2SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 1127416351f2SDavid Howells printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \ 1128416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 1129416351f2SDavid Howells (unsigned long)(H)); \ 1130416351f2SDavid Howells printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \ 1131416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 1132416351f2SDavid Howells (unsigned long)(H)); \ 1133416351f2SDavid Howells BUG(); \ 1134416351f2SDavid Howells } \ 1135416351f2SDavid Howells } while(0) 1136416351f2SDavid Howells 113708e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 113808e0e7c8SDavid Howells do { \ 113908e0e7c8SDavid Howells if (unlikely((C) && !(X))) { \ 114008e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 114108e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 114208e0e7c8SDavid Howells BUG(); \ 114308e0e7c8SDavid Howells } \ 114408e0e7c8SDavid Howells } while(0) 114508e0e7c8SDavid Howells 114608e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 114708e0e7c8SDavid Howells do { \ 114808e0e7c8SDavid Howells if (unlikely((C) && !((X) OP (Y)))) { \ 114908e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 115008e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 115108e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 115208e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 115308e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 115408e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 115508e0e7c8SDavid Howells BUG(); \ 115608e0e7c8SDavid Howells } \ 115708e0e7c8SDavid Howells } while(0) 115808e0e7c8SDavid Howells 115908e0e7c8SDavid Howells #else 116008e0e7c8SDavid Howells 116108e0e7c8SDavid Howells #define ASSERT(X) \ 116208e0e7c8SDavid Howells do { \ 116308e0e7c8SDavid Howells } while(0) 116408e0e7c8SDavid Howells 116508e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 116608e0e7c8SDavid Howells do { \ 116708e0e7c8SDavid Howells } while(0) 116808e0e7c8SDavid Howells 1169416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 1170416351f2SDavid Howells do { \ 1171416351f2SDavid Howells } while(0) 1172416351f2SDavid Howells 117308e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 117408e0e7c8SDavid Howells do { \ 117508e0e7c8SDavid Howells } while(0) 117608e0e7c8SDavid Howells 117708e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 117808e0e7c8SDavid Howells do { \ 117908e0e7c8SDavid Howells } while(0) 118008e0e7c8SDavid Howells 118108e0e7c8SDavid Howells #endif /* __KDEBUGALL */ 1182