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 3508e0e7c8SDavid Howells typedef enum { 3608e0e7c8SDavid Howells AFS_VL_NEW, /* new, uninitialised record */ 3708e0e7c8SDavid Howells AFS_VL_CREATING, /* creating record */ 3808e0e7c8SDavid Howells AFS_VL_VALID, /* record is pending */ 3908e0e7c8SDavid Howells AFS_VL_NO_VOLUME, /* no such volume available */ 4008e0e7c8SDavid Howells AFS_VL_UPDATING, /* update in progress */ 4108e0e7c8SDavid Howells AFS_VL_VOLUME_DELETED, /* volume was deleted */ 4208e0e7c8SDavid Howells AFS_VL_UNCERTAIN, /* uncertain state (update failed) */ 4308e0e7c8SDavid Howells } __attribute__((packed)) afs_vlocation_state_t; 441da177e4SLinus Torvalds 4500d3b7a4SDavid Howells struct afs_mount_params { 4600d3b7a4SDavid Howells bool rwpath; /* T if the parent should be considered R/W */ 4700d3b7a4SDavid Howells bool force; /* T to force cell type */ 48bec5eb61Swanglei bool autocell; /* T if set auto mount operation */ 4900d3b7a4SDavid Howells afs_voltype_t type; /* type of volume requested */ 5000d3b7a4SDavid Howells int volnamesz; /* size of volume name */ 5100d3b7a4SDavid Howells const char *volname; /* name of volume to mount */ 52f044c884SDavid Howells struct afs_net *net; /* Network namespace in effect */ 5300d3b7a4SDavid Howells struct afs_cell *cell; /* cell in which to find volume */ 5400d3b7a4SDavid Howells struct afs_volume *volume; /* volume record */ 5500d3b7a4SDavid Howells struct key *key; /* key to use for secure mounting */ 5600d3b7a4SDavid Howells }; 5700d3b7a4SDavid Howells 588e8d7f13SDavid Howells enum afs_call_state { 598e8d7f13SDavid Howells AFS_CALL_REQUESTING, /* request is being sent for outgoing call */ 608e8d7f13SDavid Howells AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */ 618e8d7f13SDavid Howells AFS_CALL_AWAIT_OP_ID, /* awaiting op ID on incoming call */ 628e8d7f13SDavid Howells AFS_CALL_AWAIT_REQUEST, /* awaiting request data on incoming call */ 638e8d7f13SDavid Howells AFS_CALL_REPLYING, /* replying to incoming call */ 648e8d7f13SDavid Howells AFS_CALL_AWAIT_ACK, /* awaiting final ACK of incoming call */ 658e8d7f13SDavid Howells AFS_CALL_COMPLETE, /* Completed or failed */ 668e8d7f13SDavid Howells }; 67f044c884SDavid Howells 6808e0e7c8SDavid Howells /* 6908e0e7c8SDavid Howells * a record of an in-progress RxRPC call 7008e0e7c8SDavid Howells */ 7108e0e7c8SDavid Howells struct afs_call { 7208e0e7c8SDavid Howells const struct afs_call_type *type; /* type of call */ 7308e0e7c8SDavid Howells wait_queue_head_t waitq; /* processes awaiting completion */ 74341f741fSDavid Howells struct work_struct async_work; /* async I/O processor */ 7508e0e7c8SDavid Howells struct work_struct work; /* actual work processor */ 7608e0e7c8SDavid Howells struct rxrpc_call *rxcall; /* RxRPC call handle */ 7708e0e7c8SDavid Howells struct key *key; /* security for this call */ 78f044c884SDavid Howells struct afs_net *net; /* The network namespace */ 7908e0e7c8SDavid Howells struct afs_server *server; /* server affected by incoming CM call */ 8008e0e7c8SDavid Howells void *request; /* request data (first part) */ 8131143d5dSDavid Howells struct address_space *mapping; /* page set */ 8231143d5dSDavid Howells struct afs_writeback *wb; /* writeback being performed */ 8308e0e7c8SDavid Howells void *buffer; /* reply receive buffer */ 8408e0e7c8SDavid Howells void *reply; /* reply buffer (first part) */ 8508e0e7c8SDavid Howells void *reply2; /* reply buffer (second part) */ 8608e0e7c8SDavid Howells void *reply3; /* reply buffer (third part) */ 87260a9803SDavid Howells void *reply4; /* reply buffer (fourth part) */ 8831143d5dSDavid Howells pgoff_t first; /* first page in mapping to deal with */ 8931143d5dSDavid Howells pgoff_t last; /* last page in mapping to deal with */ 90d001648eSDavid Howells size_t offset; /* offset into received data store */ 91341f741fSDavid Howells atomic_t usage; 928e8d7f13SDavid Howells enum afs_call_state state; 9308e0e7c8SDavid Howells int error; /* error code */ 94d001648eSDavid Howells u32 abort_code; /* Remote abort ID or 0 */ 9508e0e7c8SDavid Howells unsigned request_size; /* size of request data */ 9608e0e7c8SDavid Howells unsigned reply_max; /* maximum size of reply */ 9731143d5dSDavid Howells unsigned first_offset; /* offset into mapping[first] */ 98bcd89270SMarc Dionne union { 9931143d5dSDavid Howells unsigned last_to; /* amount of mapping[last] */ 100bcd89270SMarc Dionne unsigned count2; /* count used in unmarshalling */ 101bcd89270SMarc Dionne }; 10208e0e7c8SDavid Howells unsigned char unmarshall; /* unmarshalling phase */ 10308e0e7c8SDavid Howells bool incoming; /* T if incoming call */ 10431143d5dSDavid Howells bool send_pages; /* T if data from mapping should be sent */ 105d001648eSDavid Howells bool need_attention; /* T if RxRPC poked us */ 10656ff9c83SDavid Howells bool async; /* T if asynchronous */ 107a68f4a27SDavid Howells bool upgrade; /* T to request service upgrade */ 10808e0e7c8SDavid Howells u16 service_id; /* RxRPC service ID to call */ 10908e0e7c8SDavid Howells __be16 port; /* target UDP port */ 11050a2c953SDavid Howells u32 operation_ID; /* operation ID for an incoming call */ 11108e0e7c8SDavid Howells u32 count; /* count for use in unmarshalling */ 11208e0e7c8SDavid Howells __be32 tmp; /* place to extract temporary data */ 11331143d5dSDavid Howells afs_dataversion_t store_version; /* updated version expected from store */ 11408e0e7c8SDavid Howells }; 11508e0e7c8SDavid Howells 11608e0e7c8SDavid Howells struct afs_call_type { 11700d3b7a4SDavid Howells const char *name; 11800d3b7a4SDavid Howells 11908e0e7c8SDavid Howells /* deliver request or reply data to an call 12008e0e7c8SDavid Howells * - returning an error will cause the call to be aborted 12108e0e7c8SDavid Howells */ 122d001648eSDavid Howells int (*deliver)(struct afs_call *call); 12308e0e7c8SDavid Howells 12408e0e7c8SDavid Howells /* map an abort code to an error number */ 12508e0e7c8SDavid Howells int (*abort_to_error)(u32 abort_code); 12608e0e7c8SDavid Howells 12708e0e7c8SDavid Howells /* clean up a call */ 12808e0e7c8SDavid Howells void (*destructor)(struct afs_call *call); 129341f741fSDavid Howells 130341f741fSDavid Howells /* Work function */ 131341f741fSDavid Howells void (*work)(struct work_struct *work); 13208e0e7c8SDavid Howells }; 13308e0e7c8SDavid Howells 13408e0e7c8SDavid Howells /* 135196ee9cdSDavid Howells * Record of an outstanding read operation on a vnode. 136196ee9cdSDavid Howells */ 137196ee9cdSDavid Howells struct afs_read { 138196ee9cdSDavid Howells loff_t pos; /* Where to start reading */ 139e8e581a8SDavid Howells loff_t len; /* How much we're asking for */ 140196ee9cdSDavid Howells loff_t actual_len; /* How much we're actually getting */ 1416a0e3999SDavid Howells loff_t remain; /* Amount remaining */ 142196ee9cdSDavid Howells atomic_t usage; 143196ee9cdSDavid Howells unsigned int index; /* Which page we're reading into */ 144196ee9cdSDavid Howells unsigned int nr_pages; 145196ee9cdSDavid Howells void (*page_done)(struct afs_call *, struct afs_read *); 146196ee9cdSDavid Howells struct page *pages[]; 147196ee9cdSDavid Howells }; 148196ee9cdSDavid Howells 149196ee9cdSDavid Howells /* 15031143d5dSDavid Howells * record of an outstanding writeback on a vnode 15131143d5dSDavid Howells */ 15231143d5dSDavid Howells struct afs_writeback { 15331143d5dSDavid Howells struct list_head link; /* link in vnode->writebacks */ 15431143d5dSDavid Howells struct work_struct writer; /* work item to perform the writeback */ 15531143d5dSDavid Howells struct afs_vnode *vnode; /* vnode to which this write applies */ 15631143d5dSDavid Howells struct key *key; /* owner of this write */ 15731143d5dSDavid Howells wait_queue_head_t waitq; /* completion and ready wait queue */ 15831143d5dSDavid Howells pgoff_t first; /* first page in batch */ 15931143d5dSDavid Howells pgoff_t point; /* last page in current store op */ 16031143d5dSDavid Howells pgoff_t last; /* last page in batch (inclusive) */ 16131143d5dSDavid Howells unsigned offset_first; /* offset into first page of start of write */ 16231143d5dSDavid Howells unsigned to_last; /* offset into last page of end of write */ 16331143d5dSDavid Howells int num_conflicts; /* count of conflicting writes in list */ 16431143d5dSDavid Howells int usage; 16531143d5dSDavid Howells bool conflicts; /* T if has dependent conflicts */ 16631143d5dSDavid Howells enum { 16731143d5dSDavid Howells AFS_WBACK_SYNCING, /* synchronisation being performed */ 16831143d5dSDavid Howells AFS_WBACK_PENDING, /* write pending */ 16931143d5dSDavid Howells AFS_WBACK_CONFLICTING, /* conflicting writes posted */ 17031143d5dSDavid Howells AFS_WBACK_WRITING, /* writing back */ 17131143d5dSDavid Howells AFS_WBACK_COMPLETE /* the writeback record has been unlinked */ 17231143d5dSDavid Howells } state __attribute__((packed)); 17331143d5dSDavid Howells }; 17431143d5dSDavid Howells 17531143d5dSDavid Howells /* 17608e0e7c8SDavid Howells * AFS superblock private data 17708e0e7c8SDavid Howells * - there's one superblock per volume 17808e0e7c8SDavid Howells */ 17908e0e7c8SDavid Howells struct afs_super_info { 180f044c884SDavid Howells struct afs_net *net; /* Network namespace */ 18149566f6fSDavid Howells struct afs_cell *cell; /* The cell in which the volume resides */ 18208e0e7c8SDavid Howells struct afs_volume *volume; /* volume record */ 18308e0e7c8SDavid Howells char rwparent; /* T if parent is R/W AFS volume */ 18408e0e7c8SDavid Howells }; 18508e0e7c8SDavid Howells 18608e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) 18708e0e7c8SDavid Howells { 18808e0e7c8SDavid Howells return sb->s_fs_info; 18908e0e7c8SDavid Howells } 19008e0e7c8SDavid Howells 19108e0e7c8SDavid Howells extern struct file_system_type afs_fs_type; 19208e0e7c8SDavid Howells 19308e0e7c8SDavid Howells /* 19408e0e7c8SDavid Howells * entry in the cached cell catalogue 19508e0e7c8SDavid Howells */ 19608e0e7c8SDavid Howells struct afs_cache_cell { 19700d3b7a4SDavid Howells char name[AFS_MAXCELLNAME]; /* cell name (padded with NULs) */ 19808e0e7c8SDavid Howells struct in_addr vl_servers[15]; /* cached cell VL servers */ 19908e0e7c8SDavid Howells }; 20008e0e7c8SDavid Howells 20108e0e7c8SDavid Howells /* 202f044c884SDavid Howells * AFS network namespace record. 203f044c884SDavid Howells */ 204f044c884SDavid Howells struct afs_net { 205f044c884SDavid Howells struct afs_uuid uuid; 206f044c884SDavid Howells bool live; /* F if this namespace is being removed */ 207f044c884SDavid Howells 208f044c884SDavid Howells /* AF_RXRPC I/O stuff */ 209f044c884SDavid Howells struct socket *socket; 210f044c884SDavid Howells struct afs_call *spare_incoming_call; 211f044c884SDavid Howells struct work_struct charge_preallocation_work; 212f044c884SDavid Howells struct mutex socket_mutex; 213f044c884SDavid Howells atomic_t nr_outstanding_calls; 214f044c884SDavid Howells atomic_t nr_superblocks; 215f044c884SDavid Howells 216f044c884SDavid Howells /* Cell database */ 217f044c884SDavid Howells struct list_head cells; 218f044c884SDavid Howells struct afs_cell *ws_cell; 219f044c884SDavid Howells rwlock_t cells_lock; 220f044c884SDavid Howells struct rw_semaphore cells_sem; 221f044c884SDavid Howells wait_queue_head_t cells_freeable_wq; 222f044c884SDavid Howells 223f044c884SDavid Howells struct rw_semaphore proc_cells_sem; 224f044c884SDavid Howells struct list_head proc_cells; 225f044c884SDavid Howells 226f044c884SDavid Howells /* Volume location database */ 227f044c884SDavid Howells struct list_head vl_updates; /* VL records in need-update order */ 228f044c884SDavid Howells struct list_head vl_graveyard; /* Inactive VL records */ 229f044c884SDavid Howells struct delayed_work vl_reaper; 230f044c884SDavid Howells struct delayed_work vl_updater; 231f044c884SDavid Howells spinlock_t vl_updates_lock; 232f044c884SDavid Howells spinlock_t vl_graveyard_lock; 233f044c884SDavid Howells 234f044c884SDavid Howells /* File locking renewal management */ 235f044c884SDavid Howells struct mutex lock_manager_mutex; 236f044c884SDavid Howells 237f044c884SDavid Howells /* Server database */ 238f044c884SDavid Howells struct rb_root servers; /* Active servers */ 239f044c884SDavid Howells rwlock_t servers_lock; 240f044c884SDavid Howells struct list_head server_graveyard; /* Inactive server LRU list */ 241f044c884SDavid Howells spinlock_t server_graveyard_lock; 24259fa1c4aSDavid Howells struct timer_list server_timer; 24359fa1c4aSDavid Howells struct work_struct server_reaper; 24459fa1c4aSDavid Howells atomic_t servers_outstanding; 245f044c884SDavid Howells 246f044c884SDavid Howells /* Misc */ 247f044c884SDavid Howells struct proc_dir_entry *proc_afs; /* /proc/net/afs directory */ 248f044c884SDavid Howells }; 249f044c884SDavid Howells 250f044c884SDavid Howells extern struct afs_net __afs_net;// Dummy AFS network namespace; TODO: replace with real netns 251f044c884SDavid Howells 252f044c884SDavid Howells /* 25308e0e7c8SDavid Howells * AFS cell record 25408e0e7c8SDavid Howells */ 25508e0e7c8SDavid Howells struct afs_cell { 25608e0e7c8SDavid Howells atomic_t usage; 25708e0e7c8SDavid Howells struct list_head link; /* main cell list link */ 258f044c884SDavid Howells struct afs_net *net; /* The network namespace */ 25900d3b7a4SDavid Howells struct key *anonymous_key; /* anonymous user key for this cell */ 26008e0e7c8SDavid Howells struct list_head proc_link; /* /proc cell list link */ 2619b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 2629b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 2631da177e4SLinus Torvalds #endif 2641da177e4SLinus Torvalds 26508e0e7c8SDavid Howells /* server record management */ 26608e0e7c8SDavid Howells rwlock_t servers_lock; /* active server list lock */ 26708e0e7c8SDavid Howells struct list_head servers; /* active server list */ 2681da177e4SLinus Torvalds 26908e0e7c8SDavid Howells /* volume location record management */ 27008e0e7c8SDavid Howells struct rw_semaphore vl_sem; /* volume management serialisation semaphore */ 27108e0e7c8SDavid Howells struct list_head vl_list; /* cell's active VL record list */ 27208e0e7c8SDavid Howells spinlock_t vl_lock; /* vl_list lock */ 27308e0e7c8SDavid Howells unsigned short vl_naddrs; /* number of VL servers in addr list */ 27408e0e7c8SDavid Howells unsigned short vl_curr_svix; /* current server index */ 27508e0e7c8SDavid Howells struct in_addr vl_addrs[AFS_CELL_MAX_ADDRS]; /* cell VL server addresses */ 27608e0e7c8SDavid Howells 27708e0e7c8SDavid Howells char name[0]; /* cell name - must go last */ 27808e0e7c8SDavid Howells }; 27908e0e7c8SDavid Howells 28008e0e7c8SDavid Howells /* 28108e0e7c8SDavid Howells * entry in the cached volume location catalogue 28208e0e7c8SDavid Howells */ 28308e0e7c8SDavid Howells struct afs_cache_vlocation { 28400d3b7a4SDavid Howells /* volume name (lowercase, padded with NULs) */ 28500d3b7a4SDavid Howells uint8_t name[AFS_MAXVOLNAME + 1]; 28600d3b7a4SDavid Howells 28708e0e7c8SDavid Howells uint8_t nservers; /* number of entries used in servers[] */ 28808e0e7c8SDavid Howells uint8_t vidmask; /* voltype mask for vid[] */ 28908e0e7c8SDavid Howells uint8_t srvtmask[8]; /* voltype masks for servers[] */ 29008e0e7c8SDavid Howells #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */ 29108e0e7c8SDavid Howells #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */ 29208e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */ 29308e0e7c8SDavid Howells 29408e0e7c8SDavid Howells afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */ 29508e0e7c8SDavid Howells struct in_addr servers[8]; /* fileserver addresses */ 29608e0e7c8SDavid Howells time_t rtime; /* last retrieval time */ 29708e0e7c8SDavid Howells }; 29808e0e7c8SDavid Howells 29908e0e7c8SDavid Howells /* 30008e0e7c8SDavid Howells * volume -> vnode hash table entry 30108e0e7c8SDavid Howells */ 30208e0e7c8SDavid Howells struct afs_cache_vhash { 30308e0e7c8SDavid Howells afs_voltype_t vtype; /* which volume variation */ 30408e0e7c8SDavid Howells uint8_t hash_bucket; /* which hash bucket this represents */ 30508e0e7c8SDavid Howells } __attribute__((packed)); 30608e0e7c8SDavid Howells 30708e0e7c8SDavid Howells /* 30808e0e7c8SDavid Howells * AFS volume location record 30908e0e7c8SDavid Howells */ 31008e0e7c8SDavid Howells struct afs_vlocation { 31108e0e7c8SDavid Howells atomic_t usage; 3128a79790bSTina Ruchandani time64_t time_of_death; /* time at which put reduced usage to 0 */ 31308e0e7c8SDavid Howells struct list_head link; /* link in cell volume location list */ 31408e0e7c8SDavid Howells struct list_head grave; /* link in master graveyard list */ 31508e0e7c8SDavid Howells struct list_head update; /* link in master update list */ 31608e0e7c8SDavid Howells struct afs_cell *cell; /* cell to which volume belongs */ 3179b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 3189b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 31908e0e7c8SDavid Howells #endif 32008e0e7c8SDavid Howells struct afs_cache_vlocation vldb; /* volume information DB record */ 32108e0e7c8SDavid Howells struct afs_volume *vols[3]; /* volume access record pointer (index by type) */ 32208e0e7c8SDavid Howells wait_queue_head_t waitq; /* status change waitqueue */ 3238a79790bSTina Ruchandani time64_t update_at; /* time at which record should be updated */ 32439bf0949SDavid S. Miller spinlock_t lock; /* access lock */ 32508e0e7c8SDavid Howells afs_vlocation_state_t state; /* volume location state */ 32608e0e7c8SDavid Howells unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */ 32708e0e7c8SDavid Howells unsigned short upd_busy_cnt; /* EBUSY count during update */ 32808e0e7c8SDavid Howells bool valid; /* T if valid */ 32908e0e7c8SDavid Howells }; 33008e0e7c8SDavid Howells 33108e0e7c8SDavid Howells /* 33208e0e7c8SDavid Howells * AFS fileserver record 33308e0e7c8SDavid Howells */ 33408e0e7c8SDavid Howells struct afs_server { 33508e0e7c8SDavid Howells atomic_t usage; 3368a79790bSTina Ruchandani time64_t time_of_death; /* time at which put reduced usage to 0 */ 33708e0e7c8SDavid Howells struct in_addr addr; /* server address */ 3389ed900b1SDavid Howells struct afs_net *net; /* Network namespace in which the server resides */ 33908e0e7c8SDavid Howells struct afs_cell *cell; /* cell in which server resides */ 34008e0e7c8SDavid Howells struct list_head link; /* link in cell's server list */ 34108e0e7c8SDavid Howells struct list_head grave; /* link in master graveyard list */ 34208e0e7c8SDavid Howells struct rb_node master_rb; /* link in master by-addr tree */ 34308e0e7c8SDavid Howells struct rw_semaphore sem; /* access lock */ 34408e0e7c8SDavid Howells 34508e0e7c8SDavid Howells /* file service access */ 34608e0e7c8SDavid Howells struct rb_root fs_vnodes; /* vnodes backed by this server (ordered by FID) */ 34708e0e7c8SDavid Howells unsigned long fs_act_jif; /* time at which last activity occurred */ 34808e0e7c8SDavid Howells unsigned long fs_dead_jif; /* time at which no longer to be considered dead */ 34908e0e7c8SDavid Howells spinlock_t fs_lock; /* access lock */ 35008e0e7c8SDavid Howells int fs_state; /* 0 or reason FS currently marked dead (-errno) */ 35108e0e7c8SDavid Howells 35208e0e7c8SDavid Howells /* callback promise management */ 35308e0e7c8SDavid Howells struct rb_root cb_promises; /* vnode expiration list (ordered earliest first) */ 35408e0e7c8SDavid Howells struct delayed_work cb_updater; /* callback updater */ 35508e0e7c8SDavid Howells struct delayed_work cb_break_work; /* collected break dispatcher */ 35608e0e7c8SDavid Howells wait_queue_head_t cb_break_waitq; /* space available in cb_break waitqueue */ 35708e0e7c8SDavid Howells spinlock_t cb_lock; /* access lock */ 35808e0e7c8SDavid Howells struct afs_callback cb_break[64]; /* ring of callbacks awaiting breaking */ 35908e0e7c8SDavid Howells atomic_t cb_break_n; /* number of pending breaks */ 36008e0e7c8SDavid Howells u8 cb_break_head; /* head of callback breaking ring */ 36108e0e7c8SDavid Howells u8 cb_break_tail; /* tail of callback breaking ring */ 36208e0e7c8SDavid Howells }; 36308e0e7c8SDavid Howells 36408e0e7c8SDavid Howells /* 36508e0e7c8SDavid Howells * AFS volume access record 36608e0e7c8SDavid Howells */ 36708e0e7c8SDavid Howells struct afs_volume { 36808e0e7c8SDavid Howells atomic_t usage; 36908e0e7c8SDavid Howells struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */ 37008e0e7c8SDavid Howells struct afs_vlocation *vlocation; /* volume location */ 3719b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 3729b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 37308e0e7c8SDavid Howells #endif 37408e0e7c8SDavid Howells afs_volid_t vid; /* volume ID */ 37508e0e7c8SDavid Howells afs_voltype_t type; /* type of volume */ 37608e0e7c8SDavid Howells char type_force; /* force volume type (suppress R/O -> R/W) */ 37708e0e7c8SDavid Howells unsigned short nservers; /* number of server slots filled */ 37808e0e7c8SDavid Howells unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */ 37908e0e7c8SDavid Howells struct afs_server *servers[8]; /* servers on which volume resides (ordered) */ 38008e0e7c8SDavid Howells struct rw_semaphore server_sem; /* lock for accessing current server */ 38108e0e7c8SDavid Howells }; 38208e0e7c8SDavid Howells 38308e0e7c8SDavid Howells /* 38408e0e7c8SDavid Howells * vnode catalogue entry 38508e0e7c8SDavid Howells */ 38608e0e7c8SDavid Howells struct afs_cache_vnode { 38708e0e7c8SDavid Howells afs_vnodeid_t vnode_id; /* vnode ID */ 38808e0e7c8SDavid Howells unsigned vnode_unique; /* vnode ID uniquifier */ 38908e0e7c8SDavid Howells afs_dataversion_t data_version; /* data version */ 39008e0e7c8SDavid Howells }; 39108e0e7c8SDavid Howells 39208e0e7c8SDavid Howells /* 39308e0e7c8SDavid Howells * AFS inode private data 39408e0e7c8SDavid Howells */ 39508e0e7c8SDavid Howells struct afs_vnode { 39608e0e7c8SDavid Howells struct inode vfs_inode; /* the VFS's inode record */ 39708e0e7c8SDavid Howells 39808e0e7c8SDavid Howells struct afs_volume *volume; /* volume on which vnode resides */ 39908e0e7c8SDavid Howells struct afs_server *server; /* server currently supplying this file */ 40008e0e7c8SDavid Howells struct afs_fid fid; /* the file identifier for this inode */ 40108e0e7c8SDavid Howells struct afs_file_status status; /* AFS status info for this file */ 4029b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 4039b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 40408e0e7c8SDavid Howells #endif 40500d3b7a4SDavid Howells struct afs_permits *permits; /* cache of permits so far obtained */ 40600d3b7a4SDavid Howells struct mutex permits_lock; /* lock for altering permits list */ 407260a9803SDavid Howells struct mutex validate_lock; /* lock for validating this vnode */ 40808e0e7c8SDavid Howells wait_queue_head_t update_waitq; /* status fetch waitqueue */ 409260a9803SDavid Howells int update_cnt; /* number of outstanding ops that will update the 41008e0e7c8SDavid Howells * status */ 41131143d5dSDavid Howells spinlock_t writeback_lock; /* lock for writebacks */ 41208e0e7c8SDavid Howells spinlock_t lock; /* waitqueue/flags lock */ 41308e0e7c8SDavid Howells unsigned long flags; 41408e0e7c8SDavid Howells #define AFS_VNODE_CB_BROKEN 0 /* set if vnode's callback was broken */ 415260a9803SDavid Howells #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */ 41608e0e7c8SDavid Howells #define AFS_VNODE_MODIFIED 2 /* set if vnode's data modified */ 41708e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */ 41808e0e7c8SDavid Howells #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */ 41908e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */ 420e8d6c554SDavid Howells #define AFS_VNODE_LOCKING 6 /* set if waiting for lock on vnode */ 421e8d6c554SDavid Howells #define AFS_VNODE_READLOCKED 7 /* set if vnode is read-locked on the server */ 422e8d6c554SDavid Howells #define AFS_VNODE_WRITELOCKED 8 /* set if vnode is write-locked on the server */ 423e8d6c554SDavid Howells #define AFS_VNODE_UNLOCKING 9 /* set if vnode is being unlocked on the server */ 424bec5eb61Swanglei #define AFS_VNODE_AUTOCELL 10 /* set if Vnode is an auto mount point */ 425bec5eb61Swanglei #define AFS_VNODE_PSEUDODIR 11 /* set if Vnode is a pseudo directory */ 42608e0e7c8SDavid Howells 42700d3b7a4SDavid Howells long acl_order; /* ACL check count (callback break count) */ 42800d3b7a4SDavid Howells 42931143d5dSDavid Howells struct list_head writebacks; /* alterations in pagecache that need writing */ 430e8d6c554SDavid Howells struct list_head pending_locks; /* locks waiting to be granted */ 431e8d6c554SDavid Howells struct list_head granted_locks; /* locks granted on this file */ 432e8d6c554SDavid Howells struct delayed_work lock_work; /* work to be done in locking */ 433e8d6c554SDavid Howells struct key *unlock_key; /* key to be used in unlocking */ 43431143d5dSDavid Howells 43508e0e7c8SDavid Howells /* outstanding callback notification on this file */ 43608e0e7c8SDavid Howells struct rb_node server_rb; /* link in server->fs_vnodes */ 43708e0e7c8SDavid Howells struct rb_node cb_promise; /* link in server->cb_promises */ 43808e0e7c8SDavid Howells struct work_struct cb_broken_work; /* work to be done on callback break */ 43956e71431STina Ruchandani time64_t cb_expires; /* time at which callback expires */ 44056e71431STina Ruchandani time64_t cb_expires_at; /* time used to order cb_promise */ 44108e0e7c8SDavid Howells unsigned cb_version; /* callback version */ 44208e0e7c8SDavid Howells unsigned cb_expiry; /* callback expiry time */ 44308e0e7c8SDavid Howells afs_callback_type_t cb_type; /* type of callback */ 44408e0e7c8SDavid Howells bool cb_promised; /* true if promise still holds */ 44508e0e7c8SDavid Howells }; 44608e0e7c8SDavid Howells 44700d3b7a4SDavid Howells /* 44800d3b7a4SDavid Howells * cached security record for one user's attempt to access a vnode 44900d3b7a4SDavid Howells */ 45000d3b7a4SDavid Howells struct afs_permit { 45100d3b7a4SDavid Howells struct key *key; /* RxRPC ticket holding a security context */ 45200d3b7a4SDavid Howells afs_access_t access_mask; /* access mask for this key */ 45300d3b7a4SDavid Howells }; 45400d3b7a4SDavid Howells 45500d3b7a4SDavid Howells /* 45600d3b7a4SDavid Howells * cache of security records from attempts to access a vnode 45700d3b7a4SDavid Howells */ 45800d3b7a4SDavid Howells struct afs_permits { 45900d3b7a4SDavid Howells struct rcu_head rcu; /* disposal procedure */ 46000d3b7a4SDavid Howells int count; /* number of records */ 46100d3b7a4SDavid Howells struct afs_permit permits[0]; /* the permits so far examined */ 46200d3b7a4SDavid Howells }; 46300d3b7a4SDavid Howells 464b908fe6bSDavid Howells /* 465b908fe6bSDavid Howells * record of one of a system's set of network interfaces 466b908fe6bSDavid Howells */ 467b908fe6bSDavid Howells struct afs_interface { 468b908fe6bSDavid Howells struct in_addr address; /* IPv4 address bound to interface */ 469b908fe6bSDavid Howells struct in_addr netmask; /* netmask applied to address */ 470b908fe6bSDavid Howells unsigned mtu; /* MTU of interface */ 471b908fe6bSDavid Howells }; 472b908fe6bSDavid Howells 47308e0e7c8SDavid Howells /*****************************************************************************/ 47408e0e7c8SDavid Howells /* 4759b3f26c9SDavid Howells * cache.c 4769b3f26c9SDavid Howells */ 4779b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 4789b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs; 4799b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def; 4809b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vlocation_cache_index_def; 4819b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def; 4829b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def; 4839b3f26c9SDavid Howells #else 4849b3f26c9SDavid Howells #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL) 4859b3f26c9SDavid Howells #define afs_vlocation_cache_index_def (*(struct fscache_cookie_def *) NULL) 4869b3f26c9SDavid Howells #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL) 4879b3f26c9SDavid Howells #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL) 4889b3f26c9SDavid Howells #endif 4899b3f26c9SDavid Howells 4909b3f26c9SDavid Howells /* 49108e0e7c8SDavid Howells * callback.c 49208e0e7c8SDavid Howells */ 493f044c884SDavid Howells extern struct workqueue_struct *afs_callback_update_worker; 494f044c884SDavid Howells 49508e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *); 49608e0e7c8SDavid Howells extern void afs_broken_callback_work(struct work_struct *); 49708e0e7c8SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, 49808e0e7c8SDavid Howells struct afs_callback[]); 499260a9803SDavid Howells extern void afs_discard_callback_on_delete(struct afs_vnode *); 50008e0e7c8SDavid Howells extern void afs_give_up_callback(struct afs_vnode *); 50108e0e7c8SDavid Howells extern void afs_dispatch_give_up_callbacks(struct work_struct *); 50208e0e7c8SDavid Howells extern void afs_flush_callback_breaks(struct afs_server *); 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds /* 5051da177e4SLinus Torvalds * cell.c 5061da177e4SLinus Torvalds */ 50749566f6fSDavid Howells static inline struct afs_cell *afs_get_cell(struct afs_cell *cell) 50849566f6fSDavid Howells { 50949566f6fSDavid Howells if (cell) 51049566f6fSDavid Howells atomic_inc(&cell->usage); 51149566f6fSDavid Howells return cell; 51249566f6fSDavid Howells } 513f044c884SDavid Howells extern int afs_cell_init(struct afs_net *, char *); 514f044c884SDavid Howells extern struct afs_cell *afs_cell_create(struct afs_net *, const char *, unsigned, char *, bool); 515f044c884SDavid Howells extern struct afs_cell *afs_cell_lookup(struct afs_net *, const char *, unsigned, bool); 51608e0e7c8SDavid Howells extern struct afs_cell *afs_grab_cell(struct afs_cell *); 5179ed900b1SDavid Howells extern void afs_put_cell(struct afs_net *, struct afs_cell *); 518f044c884SDavid Howells extern void __net_exit afs_cell_purge(struct afs_net *); 51908e0e7c8SDavid Howells 52008e0e7c8SDavid Howells /* 52108e0e7c8SDavid Howells * cmservice.c 52208e0e7c8SDavid Howells */ 52308e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *); 52408e0e7c8SDavid Howells 5251da177e4SLinus Torvalds /* 5261da177e4SLinus Torvalds * dir.c 5271da177e4SLinus Torvalds */ 528754661f1SArjan van de Ven extern const struct inode_operations afs_dir_inode_operations; 529d61dcce2SAl Viro extern const struct dentry_operations afs_fs_dentry_operations; 5304b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations; 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds /* 5331da177e4SLinus Torvalds * file.c 5341da177e4SLinus Torvalds */ 535f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops; 536754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations; 53700d3b7a4SDavid Howells extern const struct file_operations afs_file_operations; 53800d3b7a4SDavid Howells 53900d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *); 54000d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *); 541f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *); 542196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *); 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds /* 545e8d6c554SDavid Howells * flock.c 546e8d6c554SDavid Howells */ 547f044c884SDavid Howells extern struct workqueue_struct *afs_lock_manager; 548f044c884SDavid Howells 549e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *); 550e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *); 551e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *); 552e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *); 553e8d6c554SDavid Howells 554e8d6c554SDavid Howells /* 55508e0e7c8SDavid Howells * fsclient.c 55608e0e7c8SDavid Howells */ 55700d3b7a4SDavid Howells extern int afs_fs_fetch_file_status(struct afs_server *, struct key *, 55800d3b7a4SDavid Howells struct afs_vnode *, struct afs_volsync *, 55956ff9c83SDavid Howells bool); 560f044c884SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_net *, struct afs_server *, bool); 56100d3b7a4SDavid Howells extern int afs_fs_fetch_data(struct afs_server *, struct key *, 56256ff9c83SDavid Howells struct afs_vnode *, struct afs_read *, bool); 563260a9803SDavid Howells extern int afs_fs_create(struct afs_server *, struct key *, 564260a9803SDavid Howells struct afs_vnode *, const char *, umode_t, 565260a9803SDavid Howells struct afs_fid *, struct afs_file_status *, 56656ff9c83SDavid Howells struct afs_callback *, bool); 567260a9803SDavid Howells extern int afs_fs_remove(struct afs_server *, struct key *, 56856ff9c83SDavid Howells struct afs_vnode *, const char *, bool, bool); 569260a9803SDavid Howells extern int afs_fs_link(struct afs_server *, struct key *, struct afs_vnode *, 57056ff9c83SDavid Howells struct afs_vnode *, const char *, bool); 571260a9803SDavid Howells extern int afs_fs_symlink(struct afs_server *, struct key *, 572260a9803SDavid Howells struct afs_vnode *, const char *, const char *, 57356ff9c83SDavid Howells struct afs_fid *, struct afs_file_status *, bool); 574260a9803SDavid Howells extern int afs_fs_rename(struct afs_server *, struct key *, 575260a9803SDavid Howells struct afs_vnode *, const char *, 57656ff9c83SDavid Howells struct afs_vnode *, const char *, bool); 57731143d5dSDavid Howells extern int afs_fs_store_data(struct afs_server *, struct afs_writeback *, 57856ff9c83SDavid Howells pgoff_t, pgoff_t, unsigned, unsigned, bool); 57931143d5dSDavid Howells extern int afs_fs_setattr(struct afs_server *, struct key *, 58056ff9c83SDavid Howells struct afs_vnode *, struct iattr *, bool); 58145222b9eSDavid Howells extern int afs_fs_get_volume_status(struct afs_server *, struct key *, 58245222b9eSDavid Howells struct afs_vnode *, 58356ff9c83SDavid Howells struct afs_volume_status *, bool); 584e8d6c554SDavid Howells extern int afs_fs_set_lock(struct afs_server *, struct key *, 58556ff9c83SDavid Howells struct afs_vnode *, afs_lock_type_t, bool); 586e8d6c554SDavid Howells extern int afs_fs_extend_lock(struct afs_server *, struct key *, 58756ff9c83SDavid Howells struct afs_vnode *, bool); 588e8d6c554SDavid Howells extern int afs_fs_release_lock(struct afs_server *, struct key *, 58956ff9c83SDavid Howells struct afs_vnode *, bool); 59008e0e7c8SDavid Howells 59108e0e7c8SDavid Howells /* 5921da177e4SLinus Torvalds * inode.c 5931da177e4SLinus Torvalds */ 594bec5eb61Swanglei extern struct inode *afs_iget_autocell(struct inode *, const char *, int, 595bec5eb61Swanglei struct key *); 59600d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *, 597260a9803SDavid Howells struct afs_fid *, struct afs_file_status *, 598260a9803SDavid Howells struct afs_callback *); 599416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *); 600260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *); 601a528d35eSDavid Howells extern int afs_getattr(const struct path *, struct kstat *, u32, unsigned int); 60231143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *); 603b57922d9SAl Viro extern void afs_evict_inode(struct inode *); 604bec5eb61Swanglei extern int afs_drop_inode(struct inode *); 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds /* 6071da177e4SLinus Torvalds * main.c 6081da177e4SLinus Torvalds */ 6090ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq; 610f044c884SDavid Howells 611f044c884SDavid Howells static inline struct afs_net *afs_d2net(struct dentry *dentry) 612f044c884SDavid Howells { 613f044c884SDavid Howells return &__afs_net; 614f044c884SDavid Howells } 615f044c884SDavid Howells 616f044c884SDavid Howells static inline struct afs_net *afs_i2net(struct inode *inode) 617f044c884SDavid Howells { 618f044c884SDavid Howells return &__afs_net; 619f044c884SDavid Howells } 620f044c884SDavid Howells 621f044c884SDavid Howells static inline struct afs_net *afs_v2net(struct afs_vnode *vnode) 622f044c884SDavid Howells { 623f044c884SDavid Howells return &__afs_net; 624f044c884SDavid Howells } 625f044c884SDavid Howells 626f044c884SDavid Howells static inline struct afs_net *afs_sock2net(struct sock *sk) 627f044c884SDavid Howells { 628f044c884SDavid Howells return &__afs_net; 629f044c884SDavid Howells } 630f044c884SDavid Howells 631f044c884SDavid Howells static inline struct afs_net *afs_get_net(struct afs_net *net) 632f044c884SDavid Howells { 633f044c884SDavid Howells return net; 634f044c884SDavid Howells } 635f044c884SDavid Howells 636f044c884SDavid Howells static inline void afs_put_net(struct afs_net *net) 637f044c884SDavid Howells { 638f044c884SDavid Howells } 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds /* 64108e0e7c8SDavid Howells * misc.c 64208e0e7c8SDavid Howells */ 64308e0e7c8SDavid Howells extern int afs_abort_to_error(u32); 64408e0e7c8SDavid Howells 64508e0e7c8SDavid Howells /* 6461da177e4SLinus Torvalds * mntpt.c 6471da177e4SLinus Torvalds */ 648754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations; 649bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations; 6504b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations; 6511da177e4SLinus Torvalds 652d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *); 65308e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void); 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds /* 656b4db2b35SArnd Bergmann * netdevices.c 657b4db2b35SArnd Bergmann */ 658b4db2b35SArnd Bergmann extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool); 659b4db2b35SArnd Bergmann 660b4db2b35SArnd Bergmann /* 6611da177e4SLinus Torvalds * proc.c 6621da177e4SLinus Torvalds */ 663f044c884SDavid Howells extern int __net_init afs_proc_init(struct afs_net *); 664f044c884SDavid Howells extern void __net_exit afs_proc_cleanup(struct afs_net *); 665f044c884SDavid Howells extern int afs_proc_cell_setup(struct afs_net *, struct afs_cell *); 666f044c884SDavid Howells extern void afs_proc_cell_remove(struct afs_net *, struct afs_cell *); 6671da177e4SLinus Torvalds 66808e0e7c8SDavid Howells /* 66908e0e7c8SDavid Howells * rxrpc.c 67008e0e7c8SDavid Howells */ 671f044c884SDavid Howells extern struct workqueue_struct *afs_async_calls; 6728324f0bcSDavid Howells 673f044c884SDavid Howells extern int __net_init afs_open_socket(struct afs_net *); 674f044c884SDavid Howells extern void __net_exit afs_close_socket(struct afs_net *); 675f044c884SDavid Howells extern void afs_charge_preallocation(struct work_struct *); 676341f741fSDavid Howells extern void afs_put_call(struct afs_call *); 677341f741fSDavid Howells extern int afs_queue_call_work(struct afs_call *); 67856ff9c83SDavid Howells extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t, bool); 679f044c884SDavid Howells extern struct afs_call *afs_alloc_flat_call(struct afs_net *, 680f044c884SDavid Howells const struct afs_call_type *, 68108e0e7c8SDavid Howells size_t, size_t); 68208e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *); 68308e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *); 684b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t); 685d001648eSDavid Howells extern int afs_extract_data(struct afs_call *, void *, size_t, bool); 68608e0e7c8SDavid Howells 687d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call) 688372ee163SDavid Howells { 689d001648eSDavid Howells return afs_extract_data(call, call->buffer, call->reply_max, false); 690372ee163SDavid Howells } 691372ee163SDavid Howells 69208e0e7c8SDavid Howells /* 69300d3b7a4SDavid Howells * security.c 69400d3b7a4SDavid Howells */ 69500d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *); 69600d3b7a4SDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, long); 697416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *); 69800d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *); 69910556cb2SAl Viro extern int afs_permission(struct inode *, int); 70000d3b7a4SDavid Howells 70100d3b7a4SDavid Howells /* 70208e0e7c8SDavid Howells * server.c 70308e0e7c8SDavid Howells */ 70408e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock; 70508e0e7c8SDavid Howells 706260a9803SDavid Howells #define afs_get_server(S) \ 707260a9803SDavid Howells do { \ 708260a9803SDavid Howells _debug("GET SERVER %d", atomic_read(&(S)->usage)); \ 709260a9803SDavid Howells atomic_inc(&(S)->usage); \ 710260a9803SDavid Howells } while(0) 71108e0e7c8SDavid Howells 71259fa1c4aSDavid Howells extern void afs_server_timer(struct timer_list *); 71308e0e7c8SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, 71408e0e7c8SDavid Howells const struct in_addr *); 715f044c884SDavid Howells extern struct afs_server *afs_find_server(struct afs_net *, 716f044c884SDavid Howells const struct sockaddr_rxrpc *); 7179ed900b1SDavid Howells extern void afs_put_server(struct afs_net *, struct afs_server *); 718f044c884SDavid Howells extern void afs_reap_server(struct work_struct *); 719f044c884SDavid Howells extern void __net_exit afs_purge_servers(struct afs_net *); 72008e0e7c8SDavid Howells 72108e0e7c8SDavid Howells /* 72200d3b7a4SDavid Howells * super.c 72300d3b7a4SDavid Howells */ 724f044c884SDavid Howells extern int __init afs_fs_init(void); 725f044c884SDavid Howells extern void __exit afs_fs_exit(void); 72600d3b7a4SDavid Howells 72700d3b7a4SDavid Howells /* 72808e0e7c8SDavid Howells * vlclient.c 72908e0e7c8SDavid Howells */ 730f044c884SDavid Howells extern int afs_vl_get_entry_by_name(struct afs_net *, 731f044c884SDavid Howells struct in_addr *, struct key *, 73200d3b7a4SDavid Howells const char *, struct afs_cache_vlocation *, 73356ff9c83SDavid Howells bool); 734f044c884SDavid Howells extern int afs_vl_get_entry_by_id(struct afs_net *, 735f044c884SDavid Howells struct in_addr *, struct key *, 73600d3b7a4SDavid Howells afs_volid_t, afs_voltype_t, 73756ff9c83SDavid Howells struct afs_cache_vlocation *, bool); 73808e0e7c8SDavid Howells 73908e0e7c8SDavid Howells /* 74008e0e7c8SDavid Howells * vlocation.c 74108e0e7c8SDavid Howells */ 742f044c884SDavid Howells extern struct workqueue_struct *afs_vlocation_update_worker; 743f044c884SDavid Howells 74408e0e7c8SDavid Howells #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0) 74508e0e7c8SDavid Howells 746f044c884SDavid Howells extern struct afs_vlocation *afs_vlocation_lookup(struct afs_net *, 747f044c884SDavid Howells struct afs_cell *, 74800d3b7a4SDavid Howells struct key *, 74908e0e7c8SDavid Howells const char *, size_t); 750f044c884SDavid Howells extern void afs_put_vlocation(struct afs_net *, struct afs_vlocation *); 751f044c884SDavid Howells extern void afs_vlocation_updater(struct work_struct *); 752f044c884SDavid Howells extern void afs_vlocation_reaper(struct work_struct *); 753f044c884SDavid Howells extern void __net_exit afs_vlocation_purge(struct afs_net *); 75408e0e7c8SDavid Howells 75508e0e7c8SDavid Howells /* 75608e0e7c8SDavid Howells * vnode.c 75708e0e7c8SDavid Howells */ 75808e0e7c8SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode) 75908e0e7c8SDavid Howells { 76008e0e7c8SDavid Howells return container_of(inode, struct afs_vnode, vfs_inode); 76108e0e7c8SDavid Howells } 76208e0e7c8SDavid Howells 76308e0e7c8SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode) 76408e0e7c8SDavid Howells { 76508e0e7c8SDavid Howells return &vnode->vfs_inode; 76608e0e7c8SDavid Howells } 76708e0e7c8SDavid Howells 768260a9803SDavid Howells extern void afs_vnode_finalise_status_update(struct afs_vnode *, 769260a9803SDavid Howells struct afs_server *); 77000d3b7a4SDavid Howells extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *, 77100d3b7a4SDavid Howells struct key *); 77200d3b7a4SDavid Howells extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *, 773196ee9cdSDavid Howells struct afs_read *); 774260a9803SDavid Howells extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *, 775260a9803SDavid Howells umode_t, struct afs_fid *, struct afs_file_status *, 776260a9803SDavid Howells struct afs_callback *, struct afs_server **); 777260a9803SDavid Howells extern int afs_vnode_remove(struct afs_vnode *, struct key *, const char *, 778260a9803SDavid Howells bool); 779260a9803SDavid Howells extern int afs_vnode_link(struct afs_vnode *, struct afs_vnode *, struct key *, 780260a9803SDavid Howells const char *); 781260a9803SDavid Howells extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *, 782260a9803SDavid Howells const char *, struct afs_fid *, 783260a9803SDavid Howells struct afs_file_status *, struct afs_server **); 784260a9803SDavid Howells extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *, 785260a9803SDavid Howells struct key *, const char *, const char *); 78631143d5dSDavid Howells extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t, 78731143d5dSDavid Howells unsigned, unsigned); 78831143d5dSDavid Howells extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *); 78945222b9eSDavid Howells extern int afs_vnode_get_volume_status(struct afs_vnode *, struct key *, 79045222b9eSDavid Howells struct afs_volume_status *); 791e8d6c554SDavid Howells extern int afs_vnode_set_lock(struct afs_vnode *, struct key *, 792e8d6c554SDavid Howells afs_lock_type_t); 793e8d6c554SDavid Howells extern int afs_vnode_extend_lock(struct afs_vnode *, struct key *); 794e8d6c554SDavid Howells extern int afs_vnode_release_lock(struct afs_vnode *, struct key *); 79508e0e7c8SDavid Howells 79608e0e7c8SDavid Howells /* 79708e0e7c8SDavid Howells * volume.c 79808e0e7c8SDavid Howells */ 79949566f6fSDavid Howells static inline struct afs_volume *afs_get_volume(struct afs_volume *volume) 80049566f6fSDavid Howells { 80149566f6fSDavid Howells if (volume) 80249566f6fSDavid Howells atomic_inc(&volume->usage); 80349566f6fSDavid Howells return volume; 80449566f6fSDavid Howells } 80508e0e7c8SDavid Howells 8069ed900b1SDavid Howells extern void afs_put_volume(struct afs_cell *, struct afs_volume *); 80700d3b7a4SDavid Howells extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *); 80808e0e7c8SDavid Howells extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *); 80908e0e7c8SDavid Howells extern int afs_volume_release_fileserver(struct afs_vnode *, 81008e0e7c8SDavid Howells struct afs_server *, int); 81108e0e7c8SDavid Howells 81231143d5dSDavid Howells /* 81331143d5dSDavid Howells * write.c 81431143d5dSDavid Howells */ 81531143d5dSDavid Howells extern int afs_set_page_dirty(struct page *); 81631143d5dSDavid Howells extern void afs_put_writeback(struct afs_writeback *); 81715b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping, 81815b4650eSNick Piggin loff_t pos, unsigned len, unsigned flags, 81915b4650eSNick Piggin struct page **pagep, void **fsdata); 82015b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping, 82115b4650eSNick Piggin loff_t pos, unsigned len, unsigned copied, 82215b4650eSNick Piggin struct page *page, void *fsdata); 82331143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *); 82431143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *); 82531143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); 82650b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); 82731143d5dSDavid Howells extern int afs_writeback_all(struct afs_vnode *); 82858fed94dSDavid Howells extern int afs_flush(struct file *, fl_owner_t); 82902c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int); 83031143d5dSDavid Howells 831d3e3b7eaSDavid Howells /* 832d3e3b7eaSDavid Howells * xattr.c 833d3e3b7eaSDavid Howells */ 834d3e3b7eaSDavid Howells extern const struct xattr_handler *afs_xattr_handlers[]; 835d3e3b7eaSDavid Howells extern ssize_t afs_listxattr(struct dentry *, char *, size_t); 83631143d5dSDavid Howells 83708e0e7c8SDavid Howells /*****************************************************************************/ 83808e0e7c8SDavid Howells /* 83908e0e7c8SDavid Howells * debug tracing 84008e0e7c8SDavid Howells */ 8418e8d7f13SDavid Howells #include <trace/events/afs.h> 8428e8d7f13SDavid Howells 84308e0e7c8SDavid Howells extern unsigned afs_debug; 84408e0e7c8SDavid Howells 84508e0e7c8SDavid Howells #define dbgprintk(FMT,...) \ 846ad16df84SSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 84708e0e7c8SDavid Howells 848530b6412SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 849530b6412SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 85008e0e7c8SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 85108e0e7c8SDavid Howells 85208e0e7c8SDavid Howells 85308e0e7c8SDavid Howells #if defined(__KDEBUG) 85408e0e7c8SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 85508e0e7c8SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 85608e0e7c8SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 85708e0e7c8SDavid Howells 85808e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG) 85908e0e7c8SDavid Howells #define AFS_DEBUG_KENTER 0x01 86008e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE 0x02 86108e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG 0x04 86208e0e7c8SDavid Howells 86308e0e7c8SDavid Howells #define _enter(FMT,...) \ 86408e0e7c8SDavid Howells do { \ 86508e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \ 86608e0e7c8SDavid Howells kenter(FMT,##__VA_ARGS__); \ 86708e0e7c8SDavid Howells } while (0) 86808e0e7c8SDavid Howells 86908e0e7c8SDavid Howells #define _leave(FMT,...) \ 87008e0e7c8SDavid Howells do { \ 87108e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \ 87208e0e7c8SDavid Howells kleave(FMT,##__VA_ARGS__); \ 87308e0e7c8SDavid Howells } while (0) 87408e0e7c8SDavid Howells 87508e0e7c8SDavid Howells #define _debug(FMT,...) \ 87608e0e7c8SDavid Howells do { \ 87708e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \ 87808e0e7c8SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 87908e0e7c8SDavid Howells } while (0) 88008e0e7c8SDavid Howells 88108e0e7c8SDavid Howells #else 88212fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 88312fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 88412fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 88508e0e7c8SDavid Howells #endif 88608e0e7c8SDavid Howells 88708e0e7c8SDavid Howells /* 88808e0e7c8SDavid Howells * debug assertion checking 88908e0e7c8SDavid Howells */ 89008e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL) 89108e0e7c8SDavid Howells 89208e0e7c8SDavid Howells #define ASSERT(X) \ 89308e0e7c8SDavid Howells do { \ 89408e0e7c8SDavid Howells if (unlikely(!(X))) { \ 89508e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 89608e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 89708e0e7c8SDavid Howells BUG(); \ 89808e0e7c8SDavid Howells } \ 89908e0e7c8SDavid Howells } while(0) 90008e0e7c8SDavid Howells 90108e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 90208e0e7c8SDavid Howells do { \ 90308e0e7c8SDavid Howells if (unlikely(!((X) OP (Y)))) { \ 90408e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 90508e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 90608e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 90708e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 90808e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 90908e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 91008e0e7c8SDavid Howells BUG(); \ 91108e0e7c8SDavid Howells } \ 91208e0e7c8SDavid Howells } while(0) 91308e0e7c8SDavid Howells 914416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 915416351f2SDavid Howells do { \ 916416351f2SDavid Howells if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \ 917416351f2SDavid Howells printk(KERN_ERR "\n"); \ 918416351f2SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 919416351f2SDavid Howells printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \ 920416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 921416351f2SDavid Howells (unsigned long)(H)); \ 922416351f2SDavid Howells printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \ 923416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 924416351f2SDavid Howells (unsigned long)(H)); \ 925416351f2SDavid Howells BUG(); \ 926416351f2SDavid Howells } \ 927416351f2SDavid Howells } while(0) 928416351f2SDavid Howells 92908e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 93008e0e7c8SDavid Howells do { \ 93108e0e7c8SDavid Howells if (unlikely((C) && !(X))) { \ 93208e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 93308e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 93408e0e7c8SDavid Howells BUG(); \ 93508e0e7c8SDavid Howells } \ 93608e0e7c8SDavid Howells } while(0) 93708e0e7c8SDavid Howells 93808e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 93908e0e7c8SDavid Howells do { \ 94008e0e7c8SDavid Howells if (unlikely((C) && !((X) OP (Y)))) { \ 94108e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 94208e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 94308e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 94408e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 94508e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 94608e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 94708e0e7c8SDavid Howells BUG(); \ 94808e0e7c8SDavid Howells } \ 94908e0e7c8SDavid Howells } while(0) 95008e0e7c8SDavid Howells 95108e0e7c8SDavid Howells #else 95208e0e7c8SDavid Howells 95308e0e7c8SDavid Howells #define ASSERT(X) \ 95408e0e7c8SDavid Howells do { \ 95508e0e7c8SDavid Howells } while(0) 95608e0e7c8SDavid Howells 95708e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 95808e0e7c8SDavid Howells do { \ 95908e0e7c8SDavid Howells } while(0) 96008e0e7c8SDavid Howells 961416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 962416351f2SDavid Howells do { \ 963416351f2SDavid Howells } while(0) 964416351f2SDavid Howells 96508e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 96608e0e7c8SDavid Howells do { \ 96708e0e7c8SDavid Howells } while(0) 96808e0e7c8SDavid Howells 96908e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 97008e0e7c8SDavid Howells do { \ 97108e0e7c8SDavid Howells } while(0) 97208e0e7c8SDavid Howells 97308e0e7c8SDavid Howells #endif /* __KDEBUGALL */ 974