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> 141da177e4SLinus Torvalds #include <linux/fs.h> 151da177e4SLinus Torvalds #include <linux/pagemap.h> 1608e0e7c8SDavid Howells #include <linux/rxrpc.h> 1700d3b7a4SDavid Howells #include <linux/key.h> 18e8edc6e0SAlexey Dobriyan #include <linux/workqueue.h> 1900c541eaSAndrew Morton #include <linux/sched.h> 2080e50be4SChristoph Hellwig #include <linux/fscache.h> 21e1da0222SJens Axboe #include <linux/backing-dev.h> 228324f0bcSDavid Howells #include <net/af_rxrpc.h> 2300c541eaSAndrew Morton 2408e0e7c8SDavid Howells #include "afs.h" 2508e0e7c8SDavid Howells #include "afs_vl.h" 2608e0e7c8SDavid Howells 2708e0e7c8SDavid Howells #define AFS_CELL_MAX_ADDRS 15 2808e0e7c8SDavid Howells 2931143d5dSDavid Howells struct pagevec; 3008e0e7c8SDavid Howells struct afs_call; 3108e0e7c8SDavid Howells 3208e0e7c8SDavid Howells typedef enum { 3308e0e7c8SDavid Howells AFS_VL_NEW, /* new, uninitialised record */ 3408e0e7c8SDavid Howells AFS_VL_CREATING, /* creating record */ 3508e0e7c8SDavid Howells AFS_VL_VALID, /* record is pending */ 3608e0e7c8SDavid Howells AFS_VL_NO_VOLUME, /* no such volume available */ 3708e0e7c8SDavid Howells AFS_VL_UPDATING, /* update in progress */ 3808e0e7c8SDavid Howells AFS_VL_VOLUME_DELETED, /* volume was deleted */ 3908e0e7c8SDavid Howells AFS_VL_UNCERTAIN, /* uncertain state (update failed) */ 4008e0e7c8SDavid Howells } __attribute__((packed)) afs_vlocation_state_t; 411da177e4SLinus Torvalds 4200d3b7a4SDavid Howells struct afs_mount_params { 4300d3b7a4SDavid Howells bool rwpath; /* T if the parent should be considered R/W */ 4400d3b7a4SDavid Howells bool force; /* T to force cell type */ 45bec5eb61Swanglei bool autocell; /* T if set auto mount operation */ 4600d3b7a4SDavid Howells afs_voltype_t type; /* type of volume requested */ 4700d3b7a4SDavid Howells int volnamesz; /* size of volume name */ 4800d3b7a4SDavid Howells const char *volname; /* name of volume to mount */ 4900d3b7a4SDavid Howells struct afs_cell *cell; /* cell in which to find volume */ 5000d3b7a4SDavid Howells struct afs_volume *volume; /* volume record */ 5100d3b7a4SDavid Howells struct key *key; /* key to use for secure mounting */ 5200d3b7a4SDavid Howells }; 5300d3b7a4SDavid Howells 548e8d7f13SDavid Howells enum afs_call_state { 558e8d7f13SDavid Howells AFS_CALL_REQUESTING, /* request is being sent for outgoing call */ 568e8d7f13SDavid Howells AFS_CALL_AWAIT_REPLY, /* awaiting reply to outgoing call */ 578e8d7f13SDavid Howells AFS_CALL_AWAIT_OP_ID, /* awaiting op ID on incoming call */ 588e8d7f13SDavid Howells AFS_CALL_AWAIT_REQUEST, /* awaiting request data on incoming call */ 598e8d7f13SDavid Howells AFS_CALL_REPLYING, /* replying to incoming call */ 608e8d7f13SDavid Howells AFS_CALL_AWAIT_ACK, /* awaiting final ACK of incoming call */ 618e8d7f13SDavid Howells AFS_CALL_COMPLETE, /* Completed or failed */ 628e8d7f13SDavid Howells }; 6308e0e7c8SDavid Howells /* 6408e0e7c8SDavid Howells * a record of an in-progress RxRPC call 6508e0e7c8SDavid Howells */ 6608e0e7c8SDavid Howells struct afs_call { 6708e0e7c8SDavid Howells const struct afs_call_type *type; /* type of call */ 6808e0e7c8SDavid Howells wait_queue_head_t waitq; /* processes awaiting completion */ 6908e0e7c8SDavid Howells struct work_struct async_work; /* asynchronous work processor */ 7008e0e7c8SDavid Howells struct work_struct work; /* actual work processor */ 7108e0e7c8SDavid Howells struct rxrpc_call *rxcall; /* RxRPC call handle */ 7208e0e7c8SDavid Howells struct key *key; /* security for this call */ 7308e0e7c8SDavid Howells struct afs_server *server; /* server affected by incoming CM call */ 7408e0e7c8SDavid Howells void *request; /* request data (first part) */ 7531143d5dSDavid Howells struct address_space *mapping; /* page set */ 7631143d5dSDavid Howells struct afs_writeback *wb; /* writeback being performed */ 7708e0e7c8SDavid Howells void *buffer; /* reply receive buffer */ 7808e0e7c8SDavid Howells void *reply; /* reply buffer (first part) */ 7908e0e7c8SDavid Howells void *reply2; /* reply buffer (second part) */ 8008e0e7c8SDavid Howells void *reply3; /* reply buffer (third part) */ 81260a9803SDavid Howells void *reply4; /* reply buffer (fourth part) */ 8231143d5dSDavid Howells pgoff_t first; /* first page in mapping to deal with */ 8331143d5dSDavid Howells pgoff_t last; /* last page in mapping to deal with */ 84d001648eSDavid Howells size_t offset; /* offset into received data store */ 858e8d7f13SDavid Howells enum afs_call_state state; 8608e0e7c8SDavid Howells int error; /* error code */ 87d001648eSDavid Howells u32 abort_code; /* Remote abort ID or 0 */ 8808e0e7c8SDavid Howells unsigned request_size; /* size of request data */ 8908e0e7c8SDavid Howells unsigned reply_max; /* maximum size of reply */ 9031143d5dSDavid Howells unsigned first_offset; /* offset into mapping[first] */ 9131143d5dSDavid Howells unsigned last_to; /* amount of mapping[last] */ 9208e0e7c8SDavid Howells unsigned char unmarshall; /* unmarshalling phase */ 9308e0e7c8SDavid Howells bool incoming; /* T if incoming call */ 9431143d5dSDavid Howells bool send_pages; /* T if data from mapping should be sent */ 95d001648eSDavid Howells bool need_attention; /* T if RxRPC poked us */ 96*56ff9c83SDavid Howells bool async; /* T if asynchronous */ 9708e0e7c8SDavid Howells u16 service_id; /* RxRPC service ID to call */ 9808e0e7c8SDavid Howells __be16 port; /* target UDP port */ 9950a2c953SDavid Howells u32 operation_ID; /* operation ID for an incoming call */ 10008e0e7c8SDavid Howells u32 count; /* count for use in unmarshalling */ 10108e0e7c8SDavid Howells __be32 tmp; /* place to extract temporary data */ 10231143d5dSDavid Howells afs_dataversion_t store_version; /* updated version expected from store */ 10308e0e7c8SDavid Howells }; 10408e0e7c8SDavid Howells 10508e0e7c8SDavid Howells struct afs_call_type { 10600d3b7a4SDavid Howells const char *name; 10700d3b7a4SDavid Howells 10808e0e7c8SDavid Howells /* deliver request or reply data to an call 10908e0e7c8SDavid Howells * - returning an error will cause the call to be aborted 11008e0e7c8SDavid Howells */ 111d001648eSDavid Howells int (*deliver)(struct afs_call *call); 11208e0e7c8SDavid Howells 11308e0e7c8SDavid Howells /* map an abort code to an error number */ 11408e0e7c8SDavid Howells int (*abort_to_error)(u32 abort_code); 11508e0e7c8SDavid Howells 11608e0e7c8SDavid Howells /* clean up a call */ 11708e0e7c8SDavid Howells void (*destructor)(struct afs_call *call); 11808e0e7c8SDavid Howells }; 11908e0e7c8SDavid Howells 12008e0e7c8SDavid Howells /* 121196ee9cdSDavid Howells * Record of an outstanding read operation on a vnode. 122196ee9cdSDavid Howells */ 123196ee9cdSDavid Howells struct afs_read { 124196ee9cdSDavid Howells loff_t pos; /* Where to start reading */ 125196ee9cdSDavid Howells loff_t len; /* How much to read */ 126196ee9cdSDavid Howells loff_t actual_len; /* How much we're actually getting */ 127196ee9cdSDavid Howells atomic_t usage; 128196ee9cdSDavid Howells unsigned int remain; /* Amount remaining */ 129196ee9cdSDavid Howells unsigned int index; /* Which page we're reading into */ 130196ee9cdSDavid Howells unsigned int pg_offset; /* Offset in page we're at */ 131196ee9cdSDavid Howells unsigned int nr_pages; 132196ee9cdSDavid Howells void (*page_done)(struct afs_call *, struct afs_read *); 133196ee9cdSDavid Howells struct page *pages[]; 134196ee9cdSDavid Howells }; 135196ee9cdSDavid Howells 136196ee9cdSDavid Howells /* 13731143d5dSDavid Howells * record of an outstanding writeback on a vnode 13831143d5dSDavid Howells */ 13931143d5dSDavid Howells struct afs_writeback { 14031143d5dSDavid Howells struct list_head link; /* link in vnode->writebacks */ 14131143d5dSDavid Howells struct work_struct writer; /* work item to perform the writeback */ 14231143d5dSDavid Howells struct afs_vnode *vnode; /* vnode to which this write applies */ 14331143d5dSDavid Howells struct key *key; /* owner of this write */ 14431143d5dSDavid Howells wait_queue_head_t waitq; /* completion and ready wait queue */ 14531143d5dSDavid Howells pgoff_t first; /* first page in batch */ 14631143d5dSDavid Howells pgoff_t point; /* last page in current store op */ 14731143d5dSDavid Howells pgoff_t last; /* last page in batch (inclusive) */ 14831143d5dSDavid Howells unsigned offset_first; /* offset into first page of start of write */ 14931143d5dSDavid Howells unsigned to_last; /* offset into last page of end of write */ 15031143d5dSDavid Howells int num_conflicts; /* count of conflicting writes in list */ 15131143d5dSDavid Howells int usage; 15231143d5dSDavid Howells bool conflicts; /* T if has dependent conflicts */ 15331143d5dSDavid Howells enum { 15431143d5dSDavid Howells AFS_WBACK_SYNCING, /* synchronisation being performed */ 15531143d5dSDavid Howells AFS_WBACK_PENDING, /* write pending */ 15631143d5dSDavid Howells AFS_WBACK_CONFLICTING, /* conflicting writes posted */ 15731143d5dSDavid Howells AFS_WBACK_WRITING, /* writing back */ 15831143d5dSDavid Howells AFS_WBACK_COMPLETE /* the writeback record has been unlinked */ 15931143d5dSDavid Howells } state __attribute__((packed)); 16031143d5dSDavid Howells }; 16131143d5dSDavid Howells 16231143d5dSDavid Howells /* 16308e0e7c8SDavid Howells * AFS superblock private data 16408e0e7c8SDavid Howells * - there's one superblock per volume 16508e0e7c8SDavid Howells */ 16608e0e7c8SDavid Howells struct afs_super_info { 16708e0e7c8SDavid Howells struct afs_volume *volume; /* volume record */ 16808e0e7c8SDavid Howells char rwparent; /* T if parent is R/W AFS volume */ 16908e0e7c8SDavid Howells }; 17008e0e7c8SDavid Howells 17108e0e7c8SDavid Howells static inline struct afs_super_info *AFS_FS_S(struct super_block *sb) 17208e0e7c8SDavid Howells { 17308e0e7c8SDavid Howells return sb->s_fs_info; 17408e0e7c8SDavid Howells } 17508e0e7c8SDavid Howells 17608e0e7c8SDavid Howells extern struct file_system_type afs_fs_type; 17708e0e7c8SDavid Howells 17808e0e7c8SDavid Howells /* 17908e0e7c8SDavid Howells * entry in the cached cell catalogue 18008e0e7c8SDavid Howells */ 18108e0e7c8SDavid Howells struct afs_cache_cell { 18200d3b7a4SDavid Howells char name[AFS_MAXCELLNAME]; /* cell name (padded with NULs) */ 18308e0e7c8SDavid Howells struct in_addr vl_servers[15]; /* cached cell VL servers */ 18408e0e7c8SDavid Howells }; 18508e0e7c8SDavid Howells 18608e0e7c8SDavid Howells /* 18708e0e7c8SDavid Howells * AFS cell record 18808e0e7c8SDavid Howells */ 18908e0e7c8SDavid Howells struct afs_cell { 19008e0e7c8SDavid Howells atomic_t usage; 19108e0e7c8SDavid Howells struct list_head link; /* main cell list link */ 19200d3b7a4SDavid Howells struct key *anonymous_key; /* anonymous user key for this cell */ 19308e0e7c8SDavid Howells struct list_head proc_link; /* /proc cell list link */ 1949b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 1959b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 1961da177e4SLinus Torvalds #endif 1971da177e4SLinus Torvalds 19808e0e7c8SDavid Howells /* server record management */ 19908e0e7c8SDavid Howells rwlock_t servers_lock; /* active server list lock */ 20008e0e7c8SDavid Howells struct list_head servers; /* active server list */ 2011da177e4SLinus Torvalds 20208e0e7c8SDavid Howells /* volume location record management */ 20308e0e7c8SDavid Howells struct rw_semaphore vl_sem; /* volume management serialisation semaphore */ 20408e0e7c8SDavid Howells struct list_head vl_list; /* cell's active VL record list */ 20508e0e7c8SDavid Howells spinlock_t vl_lock; /* vl_list lock */ 20608e0e7c8SDavid Howells unsigned short vl_naddrs; /* number of VL servers in addr list */ 20708e0e7c8SDavid Howells unsigned short vl_curr_svix; /* current server index */ 20808e0e7c8SDavid Howells struct in_addr vl_addrs[AFS_CELL_MAX_ADDRS]; /* cell VL server addresses */ 20908e0e7c8SDavid Howells 21008e0e7c8SDavid Howells char name[0]; /* cell name - must go last */ 21108e0e7c8SDavid Howells }; 21208e0e7c8SDavid Howells 21308e0e7c8SDavid Howells /* 21408e0e7c8SDavid Howells * entry in the cached volume location catalogue 21508e0e7c8SDavid Howells */ 21608e0e7c8SDavid Howells struct afs_cache_vlocation { 21700d3b7a4SDavid Howells /* volume name (lowercase, padded with NULs) */ 21800d3b7a4SDavid Howells uint8_t name[AFS_MAXVOLNAME + 1]; 21900d3b7a4SDavid Howells 22008e0e7c8SDavid Howells uint8_t nservers; /* number of entries used in servers[] */ 22108e0e7c8SDavid Howells uint8_t vidmask; /* voltype mask for vid[] */ 22208e0e7c8SDavid Howells uint8_t srvtmask[8]; /* voltype masks for servers[] */ 22308e0e7c8SDavid Howells #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */ 22408e0e7c8SDavid Howells #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */ 22508e0e7c8SDavid Howells #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */ 22608e0e7c8SDavid Howells 22708e0e7c8SDavid Howells afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */ 22808e0e7c8SDavid Howells struct in_addr servers[8]; /* fileserver addresses */ 22908e0e7c8SDavid Howells time_t rtime; /* last retrieval time */ 23008e0e7c8SDavid Howells }; 23108e0e7c8SDavid Howells 23208e0e7c8SDavid Howells /* 23308e0e7c8SDavid Howells * volume -> vnode hash table entry 23408e0e7c8SDavid Howells */ 23508e0e7c8SDavid Howells struct afs_cache_vhash { 23608e0e7c8SDavid Howells afs_voltype_t vtype; /* which volume variation */ 23708e0e7c8SDavid Howells uint8_t hash_bucket; /* which hash bucket this represents */ 23808e0e7c8SDavid Howells } __attribute__((packed)); 23908e0e7c8SDavid Howells 24008e0e7c8SDavid Howells /* 24108e0e7c8SDavid Howells * AFS volume location record 24208e0e7c8SDavid Howells */ 24308e0e7c8SDavid Howells struct afs_vlocation { 24408e0e7c8SDavid Howells atomic_t usage; 24508e0e7c8SDavid Howells time_t time_of_death; /* time at which put reduced usage to 0 */ 24608e0e7c8SDavid Howells struct list_head link; /* link in cell volume location list */ 24708e0e7c8SDavid Howells struct list_head grave; /* link in master graveyard list */ 24808e0e7c8SDavid Howells struct list_head update; /* link in master update list */ 24908e0e7c8SDavid Howells struct afs_cell *cell; /* cell to which volume belongs */ 2509b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 2519b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 25208e0e7c8SDavid Howells #endif 25308e0e7c8SDavid Howells struct afs_cache_vlocation vldb; /* volume information DB record */ 25408e0e7c8SDavid Howells struct afs_volume *vols[3]; /* volume access record pointer (index by type) */ 25508e0e7c8SDavid Howells wait_queue_head_t waitq; /* status change waitqueue */ 25608e0e7c8SDavid Howells time_t update_at; /* time at which record should be updated */ 25739bf0949SDavid S. Miller spinlock_t lock; /* access lock */ 25808e0e7c8SDavid Howells afs_vlocation_state_t state; /* volume location state */ 25908e0e7c8SDavid Howells unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */ 26008e0e7c8SDavid Howells unsigned short upd_busy_cnt; /* EBUSY count during update */ 26108e0e7c8SDavid Howells bool valid; /* T if valid */ 26208e0e7c8SDavid Howells }; 26308e0e7c8SDavid Howells 26408e0e7c8SDavid Howells /* 26508e0e7c8SDavid Howells * AFS fileserver record 26608e0e7c8SDavid Howells */ 26708e0e7c8SDavid Howells struct afs_server { 26808e0e7c8SDavid Howells atomic_t usage; 26908e0e7c8SDavid Howells time_t time_of_death; /* time at which put reduced usage to 0 */ 27008e0e7c8SDavid Howells struct in_addr addr; /* server address */ 27108e0e7c8SDavid Howells struct afs_cell *cell; /* cell in which server resides */ 27208e0e7c8SDavid Howells struct list_head link; /* link in cell's server list */ 27308e0e7c8SDavid Howells struct list_head grave; /* link in master graveyard list */ 27408e0e7c8SDavid Howells struct rb_node master_rb; /* link in master by-addr tree */ 27508e0e7c8SDavid Howells struct rw_semaphore sem; /* access lock */ 27608e0e7c8SDavid Howells 27708e0e7c8SDavid Howells /* file service access */ 27808e0e7c8SDavid Howells struct rb_root fs_vnodes; /* vnodes backed by this server (ordered by FID) */ 27908e0e7c8SDavid Howells unsigned long fs_act_jif; /* time at which last activity occurred */ 28008e0e7c8SDavid Howells unsigned long fs_dead_jif; /* time at which no longer to be considered dead */ 28108e0e7c8SDavid Howells spinlock_t fs_lock; /* access lock */ 28208e0e7c8SDavid Howells int fs_state; /* 0 or reason FS currently marked dead (-errno) */ 28308e0e7c8SDavid Howells 28408e0e7c8SDavid Howells /* callback promise management */ 28508e0e7c8SDavid Howells struct rb_root cb_promises; /* vnode expiration list (ordered earliest first) */ 28608e0e7c8SDavid Howells struct delayed_work cb_updater; /* callback updater */ 28708e0e7c8SDavid Howells struct delayed_work cb_break_work; /* collected break dispatcher */ 28808e0e7c8SDavid Howells wait_queue_head_t cb_break_waitq; /* space available in cb_break waitqueue */ 28908e0e7c8SDavid Howells spinlock_t cb_lock; /* access lock */ 29008e0e7c8SDavid Howells struct afs_callback cb_break[64]; /* ring of callbacks awaiting breaking */ 29108e0e7c8SDavid Howells atomic_t cb_break_n; /* number of pending breaks */ 29208e0e7c8SDavid Howells u8 cb_break_head; /* head of callback breaking ring */ 29308e0e7c8SDavid Howells u8 cb_break_tail; /* tail of callback breaking ring */ 29408e0e7c8SDavid Howells }; 29508e0e7c8SDavid Howells 29608e0e7c8SDavid Howells /* 29708e0e7c8SDavid Howells * AFS volume access record 29808e0e7c8SDavid Howells */ 29908e0e7c8SDavid Howells struct afs_volume { 30008e0e7c8SDavid Howells atomic_t usage; 30108e0e7c8SDavid Howells struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */ 30208e0e7c8SDavid Howells struct afs_vlocation *vlocation; /* volume location */ 3039b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 3049b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 30508e0e7c8SDavid Howells #endif 30608e0e7c8SDavid Howells afs_volid_t vid; /* volume ID */ 30708e0e7c8SDavid Howells afs_voltype_t type; /* type of volume */ 30808e0e7c8SDavid Howells char type_force; /* force volume type (suppress R/O -> R/W) */ 30908e0e7c8SDavid Howells unsigned short nservers; /* number of server slots filled */ 31008e0e7c8SDavid Howells unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */ 31108e0e7c8SDavid Howells struct afs_server *servers[8]; /* servers on which volume resides (ordered) */ 31208e0e7c8SDavid Howells struct rw_semaphore server_sem; /* lock for accessing current server */ 313e1da0222SJens Axboe struct backing_dev_info bdi; 31408e0e7c8SDavid Howells }; 31508e0e7c8SDavid Howells 31608e0e7c8SDavid Howells /* 31708e0e7c8SDavid Howells * vnode catalogue entry 31808e0e7c8SDavid Howells */ 31908e0e7c8SDavid Howells struct afs_cache_vnode { 32008e0e7c8SDavid Howells afs_vnodeid_t vnode_id; /* vnode ID */ 32108e0e7c8SDavid Howells unsigned vnode_unique; /* vnode ID uniquifier */ 32208e0e7c8SDavid Howells afs_dataversion_t data_version; /* data version */ 32308e0e7c8SDavid Howells }; 32408e0e7c8SDavid Howells 32508e0e7c8SDavid Howells /* 32608e0e7c8SDavid Howells * AFS inode private data 32708e0e7c8SDavid Howells */ 32808e0e7c8SDavid Howells struct afs_vnode { 32908e0e7c8SDavid Howells struct inode vfs_inode; /* the VFS's inode record */ 33008e0e7c8SDavid Howells 33108e0e7c8SDavid Howells struct afs_volume *volume; /* volume on which vnode resides */ 33208e0e7c8SDavid Howells struct afs_server *server; /* server currently supplying this file */ 33308e0e7c8SDavid Howells struct afs_fid fid; /* the file identifier for this inode */ 33408e0e7c8SDavid Howells struct afs_file_status status; /* AFS status info for this file */ 3359b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 3369b3f26c9SDavid Howells struct fscache_cookie *cache; /* caching cookie */ 33708e0e7c8SDavid Howells #endif 33800d3b7a4SDavid Howells struct afs_permits *permits; /* cache of permits so far obtained */ 33900d3b7a4SDavid Howells struct mutex permits_lock; /* lock for altering permits list */ 340260a9803SDavid Howells struct mutex validate_lock; /* lock for validating this vnode */ 34108e0e7c8SDavid Howells wait_queue_head_t update_waitq; /* status fetch waitqueue */ 342260a9803SDavid Howells int update_cnt; /* number of outstanding ops that will update the 34308e0e7c8SDavid Howells * status */ 34431143d5dSDavid Howells spinlock_t writeback_lock; /* lock for writebacks */ 34508e0e7c8SDavid Howells spinlock_t lock; /* waitqueue/flags lock */ 34608e0e7c8SDavid Howells unsigned long flags; 34708e0e7c8SDavid Howells #define AFS_VNODE_CB_BROKEN 0 /* set if vnode's callback was broken */ 348260a9803SDavid Howells #define AFS_VNODE_UNSET 1 /* set if vnode attributes not yet set */ 34908e0e7c8SDavid Howells #define AFS_VNODE_MODIFIED 2 /* set if vnode's data modified */ 35008e0e7c8SDavid Howells #define AFS_VNODE_ZAP_DATA 3 /* set if vnode's data should be invalidated */ 35108e0e7c8SDavid Howells #define AFS_VNODE_DELETED 4 /* set if vnode deleted on server */ 35208e0e7c8SDavid Howells #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */ 353e8d6c554SDavid Howells #define AFS_VNODE_LOCKING 6 /* set if waiting for lock on vnode */ 354e8d6c554SDavid Howells #define AFS_VNODE_READLOCKED 7 /* set if vnode is read-locked on the server */ 355e8d6c554SDavid Howells #define AFS_VNODE_WRITELOCKED 8 /* set if vnode is write-locked on the server */ 356e8d6c554SDavid Howells #define AFS_VNODE_UNLOCKING 9 /* set if vnode is being unlocked on the server */ 357bec5eb61Swanglei #define AFS_VNODE_AUTOCELL 10 /* set if Vnode is an auto mount point */ 358bec5eb61Swanglei #define AFS_VNODE_PSEUDODIR 11 /* set if Vnode is a pseudo directory */ 35908e0e7c8SDavid Howells 36000d3b7a4SDavid Howells long acl_order; /* ACL check count (callback break count) */ 36100d3b7a4SDavid Howells 36231143d5dSDavid Howells struct list_head writebacks; /* alterations in pagecache that need writing */ 363e8d6c554SDavid Howells struct list_head pending_locks; /* locks waiting to be granted */ 364e8d6c554SDavid Howells struct list_head granted_locks; /* locks granted on this file */ 365e8d6c554SDavid Howells struct delayed_work lock_work; /* work to be done in locking */ 366e8d6c554SDavid Howells struct key *unlock_key; /* key to be used in unlocking */ 36731143d5dSDavid Howells 36808e0e7c8SDavid Howells /* outstanding callback notification on this file */ 36908e0e7c8SDavid Howells struct rb_node server_rb; /* link in server->fs_vnodes */ 37008e0e7c8SDavid Howells struct rb_node cb_promise; /* link in server->cb_promises */ 37108e0e7c8SDavid Howells struct work_struct cb_broken_work; /* work to be done on callback break */ 37208e0e7c8SDavid Howells time_t cb_expires; /* time at which callback expires */ 37308e0e7c8SDavid Howells time_t cb_expires_at; /* time used to order cb_promise */ 37408e0e7c8SDavid Howells unsigned cb_version; /* callback version */ 37508e0e7c8SDavid Howells unsigned cb_expiry; /* callback expiry time */ 37608e0e7c8SDavid Howells afs_callback_type_t cb_type; /* type of callback */ 37708e0e7c8SDavid Howells bool cb_promised; /* true if promise still holds */ 37808e0e7c8SDavid Howells }; 37908e0e7c8SDavid Howells 38000d3b7a4SDavid Howells /* 38100d3b7a4SDavid Howells * cached security record for one user's attempt to access a vnode 38200d3b7a4SDavid Howells */ 38300d3b7a4SDavid Howells struct afs_permit { 38400d3b7a4SDavid Howells struct key *key; /* RxRPC ticket holding a security context */ 38500d3b7a4SDavid Howells afs_access_t access_mask; /* access mask for this key */ 38600d3b7a4SDavid Howells }; 38700d3b7a4SDavid Howells 38800d3b7a4SDavid Howells /* 38900d3b7a4SDavid Howells * cache of security records from attempts to access a vnode 39000d3b7a4SDavid Howells */ 39100d3b7a4SDavid Howells struct afs_permits { 39200d3b7a4SDavid Howells struct rcu_head rcu; /* disposal procedure */ 39300d3b7a4SDavid Howells int count; /* number of records */ 39400d3b7a4SDavid Howells struct afs_permit permits[0]; /* the permits so far examined */ 39500d3b7a4SDavid Howells }; 39600d3b7a4SDavid Howells 397b908fe6bSDavid Howells /* 398b908fe6bSDavid Howells * record of one of a system's set of network interfaces 399b908fe6bSDavid Howells */ 400b908fe6bSDavid Howells struct afs_interface { 401b908fe6bSDavid Howells struct in_addr address; /* IPv4 address bound to interface */ 402b908fe6bSDavid Howells struct in_addr netmask; /* netmask applied to address */ 403b908fe6bSDavid Howells unsigned mtu; /* MTU of interface */ 404b908fe6bSDavid Howells }; 405b908fe6bSDavid Howells 406b908fe6bSDavid Howells /* 407b908fe6bSDavid Howells * UUID definition [internet draft] 408b908fe6bSDavid Howells * - the timestamp is a 60-bit value, split 32/16/12, and goes in 100ns 409b908fe6bSDavid Howells * increments since midnight 15th October 1582 410b908fe6bSDavid Howells * - add AFS_UUID_TO_UNIX_TIME to convert unix time in 100ns units to UUID 411b908fe6bSDavid Howells * time 412b908fe6bSDavid Howells * - the clock sequence is a 14-bit counter to avoid duplicate times 413b908fe6bSDavid Howells */ 414b908fe6bSDavid Howells struct afs_uuid { 415b908fe6bSDavid Howells u32 time_low; /* low part of timestamp */ 416b908fe6bSDavid Howells u16 time_mid; /* mid part of timestamp */ 417b908fe6bSDavid Howells u16 time_hi_and_version; /* high part of timestamp and version */ 418b1bdb691SDavid Howells #define AFS_UUID_TO_UNIX_TIME 0x01b21dd213814000ULL 419b908fe6bSDavid Howells #define AFS_UUID_TIMEHI_MASK 0x0fff 420b908fe6bSDavid Howells #define AFS_UUID_VERSION_TIME 0x1000 /* time-based UUID */ 421b908fe6bSDavid Howells #define AFS_UUID_VERSION_NAME 0x3000 /* name-based UUID */ 422b908fe6bSDavid Howells #define AFS_UUID_VERSION_RANDOM 0x4000 /* (pseudo-)random generated UUID */ 423b908fe6bSDavid Howells u8 clock_seq_hi_and_reserved; /* clock seq hi and variant */ 424b908fe6bSDavid Howells #define AFS_UUID_CLOCKHI_MASK 0x3f 425b908fe6bSDavid Howells #define AFS_UUID_VARIANT_STD 0x80 426b908fe6bSDavid Howells u8 clock_seq_low; /* clock seq low */ 427b908fe6bSDavid Howells u8 node[6]; /* spatially unique node ID (MAC addr) */ 428b908fe6bSDavid Howells }; 429b908fe6bSDavid Howells 43008e0e7c8SDavid Howells /*****************************************************************************/ 43108e0e7c8SDavid Howells /* 4329b3f26c9SDavid Howells * cache.c 4339b3f26c9SDavid Howells */ 4349b3f26c9SDavid Howells #ifdef CONFIG_AFS_FSCACHE 4359b3f26c9SDavid Howells extern struct fscache_netfs afs_cache_netfs; 4369b3f26c9SDavid Howells extern struct fscache_cookie_def afs_cell_cache_index_def; 4379b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vlocation_cache_index_def; 4389b3f26c9SDavid Howells extern struct fscache_cookie_def afs_volume_cache_index_def; 4399b3f26c9SDavid Howells extern struct fscache_cookie_def afs_vnode_cache_index_def; 4409b3f26c9SDavid Howells #else 4419b3f26c9SDavid Howells #define afs_cell_cache_index_def (*(struct fscache_cookie_def *) NULL) 4429b3f26c9SDavid Howells #define afs_vlocation_cache_index_def (*(struct fscache_cookie_def *) NULL) 4439b3f26c9SDavid Howells #define afs_volume_cache_index_def (*(struct fscache_cookie_def *) NULL) 4449b3f26c9SDavid Howells #define afs_vnode_cache_index_def (*(struct fscache_cookie_def *) NULL) 4459b3f26c9SDavid Howells #endif 4469b3f26c9SDavid Howells 4479b3f26c9SDavid Howells /* 44808e0e7c8SDavid Howells * callback.c 44908e0e7c8SDavid Howells */ 45008e0e7c8SDavid Howells extern void afs_init_callback_state(struct afs_server *); 45108e0e7c8SDavid Howells extern void afs_broken_callback_work(struct work_struct *); 45208e0e7c8SDavid Howells extern void afs_break_callbacks(struct afs_server *, size_t, 45308e0e7c8SDavid Howells struct afs_callback[]); 454260a9803SDavid Howells extern void afs_discard_callback_on_delete(struct afs_vnode *); 45508e0e7c8SDavid Howells extern void afs_give_up_callback(struct afs_vnode *); 45608e0e7c8SDavid Howells extern void afs_dispatch_give_up_callbacks(struct work_struct *); 45708e0e7c8SDavid Howells extern void afs_flush_callback_breaks(struct afs_server *); 45808e0e7c8SDavid Howells extern int __init afs_callback_update_init(void); 459fbb3fcbaSDavid Howells extern void afs_callback_update_kill(void); 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds /* 4621da177e4SLinus Torvalds * cell.c 4631da177e4SLinus Torvalds */ 4641da177e4SLinus Torvalds extern struct rw_semaphore afs_proc_cells_sem; 4651da177e4SLinus Torvalds extern struct list_head afs_proc_cells; 4661da177e4SLinus Torvalds 46708e0e7c8SDavid Howells #define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0) 46808e0e7c8SDavid Howells extern int afs_cell_init(char *); 469bec5eb61Swanglei extern struct afs_cell *afs_cell_create(const char *, unsigned, char *, bool); 470bec5eb61Swanglei extern struct afs_cell *afs_cell_lookup(const char *, unsigned, bool); 47108e0e7c8SDavid Howells extern struct afs_cell *afs_grab_cell(struct afs_cell *); 47208e0e7c8SDavid Howells extern void afs_put_cell(struct afs_cell *); 47308e0e7c8SDavid Howells extern void afs_cell_purge(void); 47408e0e7c8SDavid Howells 47508e0e7c8SDavid Howells /* 47608e0e7c8SDavid Howells * cmservice.c 47708e0e7c8SDavid Howells */ 47808e0e7c8SDavid Howells extern bool afs_cm_incoming_call(struct afs_call *); 47908e0e7c8SDavid Howells 4801da177e4SLinus Torvalds /* 4811da177e4SLinus Torvalds * dir.c 4821da177e4SLinus Torvalds */ 483754661f1SArjan van de Ven extern const struct inode_operations afs_dir_inode_operations; 484d61dcce2SAl Viro extern const struct dentry_operations afs_fs_dentry_operations; 4854b6f5d20SArjan van de Ven extern const struct file_operations afs_dir_file_operations; 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds /* 4881da177e4SLinus Torvalds * file.c 4891da177e4SLinus Torvalds */ 490f5e54d6eSChristoph Hellwig extern const struct address_space_operations afs_fs_aops; 491754661f1SArjan van de Ven extern const struct inode_operations afs_file_inode_operations; 49200d3b7a4SDavid Howells extern const struct file_operations afs_file_operations; 49300d3b7a4SDavid Howells 49400d3b7a4SDavid Howells extern int afs_open(struct inode *, struct file *); 49500d3b7a4SDavid Howells extern int afs_release(struct inode *, struct file *); 496f6d335c0SAl Viro extern int afs_page_filler(void *, struct page *); 497196ee9cdSDavid Howells extern void afs_put_read(struct afs_read *); 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds /* 500e8d6c554SDavid Howells * flock.c 501e8d6c554SDavid Howells */ 502e8d6c554SDavid Howells extern void __exit afs_kill_lock_manager(void); 503e8d6c554SDavid Howells extern void afs_lock_work(struct work_struct *); 504e8d6c554SDavid Howells extern void afs_lock_may_be_available(struct afs_vnode *); 505e8d6c554SDavid Howells extern int afs_lock(struct file *, int, struct file_lock *); 506e8d6c554SDavid Howells extern int afs_flock(struct file *, int, struct file_lock *); 507e8d6c554SDavid Howells 508e8d6c554SDavid Howells /* 50908e0e7c8SDavid Howells * fsclient.c 51008e0e7c8SDavid Howells */ 51100d3b7a4SDavid Howells extern int afs_fs_fetch_file_status(struct afs_server *, struct key *, 51200d3b7a4SDavid Howells struct afs_vnode *, struct afs_volsync *, 513*56ff9c83SDavid Howells bool); 514*56ff9c83SDavid Howells extern int afs_fs_give_up_callbacks(struct afs_server *, bool); 51500d3b7a4SDavid Howells extern int afs_fs_fetch_data(struct afs_server *, struct key *, 516*56ff9c83SDavid Howells struct afs_vnode *, struct afs_read *, bool); 517260a9803SDavid Howells extern int afs_fs_create(struct afs_server *, struct key *, 518260a9803SDavid Howells struct afs_vnode *, const char *, umode_t, 519260a9803SDavid Howells struct afs_fid *, struct afs_file_status *, 520*56ff9c83SDavid Howells struct afs_callback *, bool); 521260a9803SDavid Howells extern int afs_fs_remove(struct afs_server *, struct key *, 522*56ff9c83SDavid Howells struct afs_vnode *, const char *, bool, bool); 523260a9803SDavid Howells extern int afs_fs_link(struct afs_server *, struct key *, struct afs_vnode *, 524*56ff9c83SDavid Howells struct afs_vnode *, const char *, bool); 525260a9803SDavid Howells extern int afs_fs_symlink(struct afs_server *, struct key *, 526260a9803SDavid Howells struct afs_vnode *, const char *, const char *, 527*56ff9c83SDavid Howells struct afs_fid *, struct afs_file_status *, bool); 528260a9803SDavid Howells extern int afs_fs_rename(struct afs_server *, struct key *, 529260a9803SDavid Howells struct afs_vnode *, const char *, 530*56ff9c83SDavid Howells struct afs_vnode *, const char *, bool); 53131143d5dSDavid Howells extern int afs_fs_store_data(struct afs_server *, struct afs_writeback *, 532*56ff9c83SDavid Howells pgoff_t, pgoff_t, unsigned, unsigned, bool); 53331143d5dSDavid Howells extern int afs_fs_setattr(struct afs_server *, struct key *, 534*56ff9c83SDavid Howells struct afs_vnode *, struct iattr *, bool); 53545222b9eSDavid Howells extern int afs_fs_get_volume_status(struct afs_server *, struct key *, 53645222b9eSDavid Howells struct afs_vnode *, 537*56ff9c83SDavid Howells struct afs_volume_status *, bool); 538e8d6c554SDavid Howells extern int afs_fs_set_lock(struct afs_server *, struct key *, 539*56ff9c83SDavid Howells struct afs_vnode *, afs_lock_type_t, bool); 540e8d6c554SDavid Howells extern int afs_fs_extend_lock(struct afs_server *, struct key *, 541*56ff9c83SDavid Howells struct afs_vnode *, bool); 542e8d6c554SDavid Howells extern int afs_fs_release_lock(struct afs_server *, struct key *, 543*56ff9c83SDavid Howells struct afs_vnode *, bool); 54408e0e7c8SDavid Howells 54508e0e7c8SDavid Howells /* 5461da177e4SLinus Torvalds * inode.c 5471da177e4SLinus Torvalds */ 548bec5eb61Swanglei extern struct inode *afs_iget_autocell(struct inode *, const char *, int, 549bec5eb61Swanglei struct key *); 55000d3b7a4SDavid Howells extern struct inode *afs_iget(struct super_block *, struct key *, 551260a9803SDavid Howells struct afs_fid *, struct afs_file_status *, 552260a9803SDavid Howells struct afs_callback *); 553416351f2SDavid Howells extern void afs_zap_data(struct afs_vnode *); 554260a9803SDavid Howells extern int afs_validate(struct afs_vnode *, struct key *); 555416351f2SDavid Howells extern int afs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 55631143d5dSDavid Howells extern int afs_setattr(struct dentry *, struct iattr *); 557b57922d9SAl Viro extern void afs_evict_inode(struct inode *); 558bec5eb61Swanglei extern int afs_drop_inode(struct inode *); 5591da177e4SLinus Torvalds 5601da177e4SLinus Torvalds /* 5611da177e4SLinus Torvalds * main.c 5621da177e4SLinus Torvalds */ 5630ad53eeeSTejun Heo extern struct workqueue_struct *afs_wq; 564b908fe6bSDavid Howells extern struct afs_uuid afs_uuid; 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds /* 56708e0e7c8SDavid Howells * misc.c 56808e0e7c8SDavid Howells */ 56908e0e7c8SDavid Howells extern int afs_abort_to_error(u32); 57008e0e7c8SDavid Howells 57108e0e7c8SDavid Howells /* 5721da177e4SLinus Torvalds * mntpt.c 5731da177e4SLinus Torvalds */ 574754661f1SArjan van de Ven extern const struct inode_operations afs_mntpt_inode_operations; 575bec5eb61Swanglei extern const struct inode_operations afs_autocell_inode_operations; 5764b6f5d20SArjan van de Ven extern const struct file_operations afs_mntpt_file_operations; 5771da177e4SLinus Torvalds 578d18610b0SDavid Howells extern struct vfsmount *afs_d_automount(struct path *); 57900d3b7a4SDavid Howells extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *); 58008e0e7c8SDavid Howells extern void afs_mntpt_kill_timer(void); 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds /* 5831da177e4SLinus Torvalds * proc.c 5841da177e4SLinus Torvalds */ 5851da177e4SLinus Torvalds extern int afs_proc_init(void); 5861da177e4SLinus Torvalds extern void afs_proc_cleanup(void); 587ec26815aSDavid Howells extern int afs_proc_cell_setup(struct afs_cell *); 588ec26815aSDavid Howells extern void afs_proc_cell_remove(struct afs_cell *); 5891da177e4SLinus Torvalds 59008e0e7c8SDavid Howells /* 59108e0e7c8SDavid Howells * rxrpc.c 59208e0e7c8SDavid Howells */ 5938324f0bcSDavid Howells extern struct socket *afs_socket; 5948324f0bcSDavid Howells 59508e0e7c8SDavid Howells extern int afs_open_socket(void); 59608e0e7c8SDavid Howells extern void afs_close_socket(void); 597*56ff9c83SDavid Howells extern int afs_make_call(struct in_addr *, struct afs_call *, gfp_t, bool); 59808e0e7c8SDavid Howells extern struct afs_call *afs_alloc_flat_call(const struct afs_call_type *, 59908e0e7c8SDavid Howells size_t, size_t); 60008e0e7c8SDavid Howells extern void afs_flat_call_destructor(struct afs_call *); 60108e0e7c8SDavid Howells extern void afs_send_empty_reply(struct afs_call *); 602b908fe6bSDavid Howells extern void afs_send_simple_reply(struct afs_call *, const void *, size_t); 603d001648eSDavid Howells extern int afs_extract_data(struct afs_call *, void *, size_t, bool); 60408e0e7c8SDavid Howells 605d001648eSDavid Howells static inline int afs_transfer_reply(struct afs_call *call) 606372ee163SDavid Howells { 607d001648eSDavid Howells return afs_extract_data(call, call->buffer, call->reply_max, false); 608372ee163SDavid Howells } 609372ee163SDavid Howells 61008e0e7c8SDavid Howells /* 61100d3b7a4SDavid Howells * security.c 61200d3b7a4SDavid Howells */ 61300d3b7a4SDavid Howells extern void afs_clear_permits(struct afs_vnode *); 61400d3b7a4SDavid Howells extern void afs_cache_permit(struct afs_vnode *, struct key *, long); 615416351f2SDavid Howells extern void afs_zap_permits(struct rcu_head *); 61600d3b7a4SDavid Howells extern struct key *afs_request_key(struct afs_cell *); 61710556cb2SAl Viro extern int afs_permission(struct inode *, int); 61800d3b7a4SDavid Howells 61900d3b7a4SDavid Howells /* 62008e0e7c8SDavid Howells * server.c 62108e0e7c8SDavid Howells */ 62208e0e7c8SDavid Howells extern spinlock_t afs_server_peer_lock; 62308e0e7c8SDavid Howells 624260a9803SDavid Howells #define afs_get_server(S) \ 625260a9803SDavid Howells do { \ 626260a9803SDavid Howells _debug("GET SERVER %d", atomic_read(&(S)->usage)); \ 627260a9803SDavid Howells atomic_inc(&(S)->usage); \ 628260a9803SDavid Howells } while(0) 62908e0e7c8SDavid Howells 63008e0e7c8SDavid Howells extern struct afs_server *afs_lookup_server(struct afs_cell *, 63108e0e7c8SDavid Howells const struct in_addr *); 6328324f0bcSDavid Howells extern struct afs_server *afs_find_server(const struct sockaddr_rxrpc *); 63308e0e7c8SDavid Howells extern void afs_put_server(struct afs_server *); 63408e0e7c8SDavid Howells extern void __exit afs_purge_servers(void); 63508e0e7c8SDavid Howells 63608e0e7c8SDavid Howells /* 63700d3b7a4SDavid Howells * super.c 63800d3b7a4SDavid Howells */ 63900d3b7a4SDavid Howells extern int afs_fs_init(void); 64000d3b7a4SDavid Howells extern void afs_fs_exit(void); 64100d3b7a4SDavid Howells 64200d3b7a4SDavid Howells /* 643b908fe6bSDavid Howells * use-rtnetlink.c 644b908fe6bSDavid Howells */ 645b908fe6bSDavid Howells extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool); 646ec9c9485SDavid Howells extern int afs_get_MAC_address(u8 *, size_t); 647b908fe6bSDavid Howells 648b908fe6bSDavid Howells /* 64908e0e7c8SDavid Howells * vlclient.c 65008e0e7c8SDavid Howells */ 65100d3b7a4SDavid Howells extern int afs_vl_get_entry_by_name(struct in_addr *, struct key *, 65200d3b7a4SDavid Howells const char *, struct afs_cache_vlocation *, 653*56ff9c83SDavid Howells bool); 65400d3b7a4SDavid Howells extern int afs_vl_get_entry_by_id(struct in_addr *, struct key *, 65500d3b7a4SDavid Howells afs_volid_t, afs_voltype_t, 656*56ff9c83SDavid Howells struct afs_cache_vlocation *, bool); 65708e0e7c8SDavid Howells 65808e0e7c8SDavid Howells /* 65908e0e7c8SDavid Howells * vlocation.c 66008e0e7c8SDavid Howells */ 66108e0e7c8SDavid Howells #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0) 66208e0e7c8SDavid Howells 66308e0e7c8SDavid Howells extern int __init afs_vlocation_update_init(void); 66408e0e7c8SDavid Howells extern struct afs_vlocation *afs_vlocation_lookup(struct afs_cell *, 66500d3b7a4SDavid Howells struct key *, 66608e0e7c8SDavid Howells const char *, size_t); 66708e0e7c8SDavid Howells extern void afs_put_vlocation(struct afs_vlocation *); 668fbb3fcbaSDavid Howells extern void afs_vlocation_purge(void); 66908e0e7c8SDavid Howells 67008e0e7c8SDavid Howells /* 67108e0e7c8SDavid Howells * vnode.c 67208e0e7c8SDavid Howells */ 67308e0e7c8SDavid Howells static inline struct afs_vnode *AFS_FS_I(struct inode *inode) 67408e0e7c8SDavid Howells { 67508e0e7c8SDavid Howells return container_of(inode, struct afs_vnode, vfs_inode); 67608e0e7c8SDavid Howells } 67708e0e7c8SDavid Howells 67808e0e7c8SDavid Howells static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode) 67908e0e7c8SDavid Howells { 68008e0e7c8SDavid Howells return &vnode->vfs_inode; 68108e0e7c8SDavid Howells } 68208e0e7c8SDavid Howells 683260a9803SDavid Howells extern void afs_vnode_finalise_status_update(struct afs_vnode *, 684260a9803SDavid Howells struct afs_server *); 68500d3b7a4SDavid Howells extern int afs_vnode_fetch_status(struct afs_vnode *, struct afs_vnode *, 68600d3b7a4SDavid Howells struct key *); 68700d3b7a4SDavid Howells extern int afs_vnode_fetch_data(struct afs_vnode *, struct key *, 688196ee9cdSDavid Howells struct afs_read *); 689260a9803SDavid Howells extern int afs_vnode_create(struct afs_vnode *, struct key *, const char *, 690260a9803SDavid Howells umode_t, struct afs_fid *, struct afs_file_status *, 691260a9803SDavid Howells struct afs_callback *, struct afs_server **); 692260a9803SDavid Howells extern int afs_vnode_remove(struct afs_vnode *, struct key *, const char *, 693260a9803SDavid Howells bool); 694260a9803SDavid Howells extern int afs_vnode_link(struct afs_vnode *, struct afs_vnode *, struct key *, 695260a9803SDavid Howells const char *); 696260a9803SDavid Howells extern int afs_vnode_symlink(struct afs_vnode *, struct key *, const char *, 697260a9803SDavid Howells const char *, struct afs_fid *, 698260a9803SDavid Howells struct afs_file_status *, struct afs_server **); 699260a9803SDavid Howells extern int afs_vnode_rename(struct afs_vnode *, struct afs_vnode *, 700260a9803SDavid Howells struct key *, const char *, const char *); 70131143d5dSDavid Howells extern int afs_vnode_store_data(struct afs_writeback *, pgoff_t, pgoff_t, 70231143d5dSDavid Howells unsigned, unsigned); 70331143d5dSDavid Howells extern int afs_vnode_setattr(struct afs_vnode *, struct key *, struct iattr *); 70445222b9eSDavid Howells extern int afs_vnode_get_volume_status(struct afs_vnode *, struct key *, 70545222b9eSDavid Howells struct afs_volume_status *); 706e8d6c554SDavid Howells extern int afs_vnode_set_lock(struct afs_vnode *, struct key *, 707e8d6c554SDavid Howells afs_lock_type_t); 708e8d6c554SDavid Howells extern int afs_vnode_extend_lock(struct afs_vnode *, struct key *); 709e8d6c554SDavid Howells extern int afs_vnode_release_lock(struct afs_vnode *, struct key *); 71008e0e7c8SDavid Howells 71108e0e7c8SDavid Howells /* 71208e0e7c8SDavid Howells * volume.c 71308e0e7c8SDavid Howells */ 71408e0e7c8SDavid Howells #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0) 71508e0e7c8SDavid Howells 71608e0e7c8SDavid Howells extern void afs_put_volume(struct afs_volume *); 71700d3b7a4SDavid Howells extern struct afs_volume *afs_volume_lookup(struct afs_mount_params *); 71808e0e7c8SDavid Howells extern struct afs_server *afs_volume_pick_fileserver(struct afs_vnode *); 71908e0e7c8SDavid Howells extern int afs_volume_release_fileserver(struct afs_vnode *, 72008e0e7c8SDavid Howells struct afs_server *, int); 72108e0e7c8SDavid Howells 72231143d5dSDavid Howells /* 72331143d5dSDavid Howells * write.c 72431143d5dSDavid Howells */ 72531143d5dSDavid Howells extern int afs_set_page_dirty(struct page *); 72631143d5dSDavid Howells extern void afs_put_writeback(struct afs_writeback *); 72715b4650eSNick Piggin extern int afs_write_begin(struct file *file, struct address_space *mapping, 72815b4650eSNick Piggin loff_t pos, unsigned len, unsigned flags, 72915b4650eSNick Piggin struct page **pagep, void **fsdata); 73015b4650eSNick Piggin extern int afs_write_end(struct file *file, struct address_space *mapping, 73115b4650eSNick Piggin loff_t pos, unsigned len, unsigned copied, 73215b4650eSNick Piggin struct page *page, void *fsdata); 73331143d5dSDavid Howells extern int afs_writepage(struct page *, struct writeback_control *); 73431143d5dSDavid Howells extern int afs_writepages(struct address_space *, struct writeback_control *); 73531143d5dSDavid Howells extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); 73650b5551dSAl Viro extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); 73731143d5dSDavid Howells extern int afs_writeback_all(struct afs_vnode *); 73802c24a82SJosef Bacik extern int afs_fsync(struct file *, loff_t, loff_t, int); 73931143d5dSDavid Howells 74031143d5dSDavid Howells 74108e0e7c8SDavid Howells /*****************************************************************************/ 74208e0e7c8SDavid Howells /* 74308e0e7c8SDavid Howells * debug tracing 74408e0e7c8SDavid Howells */ 7458e8d7f13SDavid Howells #include <trace/events/afs.h> 7468e8d7f13SDavid Howells 74708e0e7c8SDavid Howells extern unsigned afs_debug; 74808e0e7c8SDavid Howells 74908e0e7c8SDavid Howells #define dbgprintk(FMT,...) \ 750ad16df84SSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 75108e0e7c8SDavid Howells 752530b6412SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 753530b6412SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 75408e0e7c8SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 75508e0e7c8SDavid Howells 75608e0e7c8SDavid Howells 75708e0e7c8SDavid Howells #if defined(__KDEBUG) 75808e0e7c8SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 75908e0e7c8SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 76008e0e7c8SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 76108e0e7c8SDavid Howells 76208e0e7c8SDavid Howells #elif defined(CONFIG_AFS_DEBUG) 76308e0e7c8SDavid Howells #define AFS_DEBUG_KENTER 0x01 76408e0e7c8SDavid Howells #define AFS_DEBUG_KLEAVE 0x02 76508e0e7c8SDavid Howells #define AFS_DEBUG_KDEBUG 0x04 76608e0e7c8SDavid Howells 76708e0e7c8SDavid Howells #define _enter(FMT,...) \ 76808e0e7c8SDavid Howells do { \ 76908e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KENTER)) \ 77008e0e7c8SDavid Howells kenter(FMT,##__VA_ARGS__); \ 77108e0e7c8SDavid Howells } while (0) 77208e0e7c8SDavid Howells 77308e0e7c8SDavid Howells #define _leave(FMT,...) \ 77408e0e7c8SDavid Howells do { \ 77508e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KLEAVE)) \ 77608e0e7c8SDavid Howells kleave(FMT,##__VA_ARGS__); \ 77708e0e7c8SDavid Howells } while (0) 77808e0e7c8SDavid Howells 77908e0e7c8SDavid Howells #define _debug(FMT,...) \ 78008e0e7c8SDavid Howells do { \ 78108e0e7c8SDavid Howells if (unlikely(afs_debug & AFS_DEBUG_KDEBUG)) \ 78208e0e7c8SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 78308e0e7c8SDavid Howells } while (0) 78408e0e7c8SDavid Howells 78508e0e7c8SDavid Howells #else 78612fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 78712fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 78812fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 78908e0e7c8SDavid Howells #endif 79008e0e7c8SDavid Howells 79108e0e7c8SDavid Howells /* 79208e0e7c8SDavid Howells * debug assertion checking 79308e0e7c8SDavid Howells */ 79408e0e7c8SDavid Howells #if 1 // defined(__KDEBUGALL) 79508e0e7c8SDavid Howells 79608e0e7c8SDavid Howells #define ASSERT(X) \ 79708e0e7c8SDavid Howells do { \ 79808e0e7c8SDavid Howells if (unlikely(!(X))) { \ 79908e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 80008e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 80108e0e7c8SDavid Howells BUG(); \ 80208e0e7c8SDavid Howells } \ 80308e0e7c8SDavid Howells } while(0) 80408e0e7c8SDavid Howells 80508e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 80608e0e7c8SDavid Howells do { \ 80708e0e7c8SDavid Howells if (unlikely(!((X) OP (Y)))) { \ 80808e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 80908e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 81008e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 81108e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 81208e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 81308e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 81408e0e7c8SDavid Howells BUG(); \ 81508e0e7c8SDavid Howells } \ 81608e0e7c8SDavid Howells } while(0) 81708e0e7c8SDavid Howells 818416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 819416351f2SDavid Howells do { \ 820416351f2SDavid Howells if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \ 821416351f2SDavid Howells printk(KERN_ERR "\n"); \ 822416351f2SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 823416351f2SDavid Howells printk(KERN_ERR "%lu "#OP1" %lu "#OP2" %lu is false\n", \ 824416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 825416351f2SDavid Howells (unsigned long)(H)); \ 826416351f2SDavid Howells printk(KERN_ERR "0x%lx "#OP1" 0x%lx "#OP2" 0x%lx is false\n", \ 827416351f2SDavid Howells (unsigned long)(L), (unsigned long)(N), \ 828416351f2SDavid Howells (unsigned long)(H)); \ 829416351f2SDavid Howells BUG(); \ 830416351f2SDavid Howells } \ 831416351f2SDavid Howells } while(0) 832416351f2SDavid Howells 83308e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 83408e0e7c8SDavid Howells do { \ 83508e0e7c8SDavid Howells if (unlikely((C) && !(X))) { \ 83608e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 83708e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 83808e0e7c8SDavid Howells BUG(); \ 83908e0e7c8SDavid Howells } \ 84008e0e7c8SDavid Howells } while(0) 84108e0e7c8SDavid Howells 84208e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 84308e0e7c8SDavid Howells do { \ 84408e0e7c8SDavid Howells if (unlikely((C) && !((X) OP (Y)))) { \ 84508e0e7c8SDavid Howells printk(KERN_ERR "\n"); \ 84608e0e7c8SDavid Howells printk(KERN_ERR "AFS: Assertion failed\n"); \ 84708e0e7c8SDavid Howells printk(KERN_ERR "%lu " #OP " %lu is false\n", \ 84808e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 84908e0e7c8SDavid Howells printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \ 85008e0e7c8SDavid Howells (unsigned long)(X), (unsigned long)(Y)); \ 85108e0e7c8SDavid Howells BUG(); \ 85208e0e7c8SDavid Howells } \ 85308e0e7c8SDavid Howells } while(0) 85408e0e7c8SDavid Howells 85508e0e7c8SDavid Howells #else 85608e0e7c8SDavid Howells 85708e0e7c8SDavid Howells #define ASSERT(X) \ 85808e0e7c8SDavid Howells do { \ 85908e0e7c8SDavid Howells } while(0) 86008e0e7c8SDavid Howells 86108e0e7c8SDavid Howells #define ASSERTCMP(X, OP, Y) \ 86208e0e7c8SDavid Howells do { \ 86308e0e7c8SDavid Howells } while(0) 86408e0e7c8SDavid Howells 865416351f2SDavid Howells #define ASSERTRANGE(L, OP1, N, OP2, H) \ 866416351f2SDavid Howells do { \ 867416351f2SDavid Howells } while(0) 868416351f2SDavid Howells 86908e0e7c8SDavid Howells #define ASSERTIF(C, X) \ 87008e0e7c8SDavid Howells do { \ 87108e0e7c8SDavid Howells } while(0) 87208e0e7c8SDavid Howells 87308e0e7c8SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 87408e0e7c8SDavid Howells do { \ 87508e0e7c8SDavid Howells } while(0) 87608e0e7c8SDavid Howells 87708e0e7c8SDavid Howells #endif /* __KDEBUGALL */ 878