1f7b422b1SDavid Howells /* 2f7b422b1SDavid Howells * NFS internal definitions 3f7b422b1SDavid Howells */ 4f7b422b1SDavid Howells 5f7b422b1SDavid Howells #include <linux/mount.h> 6f7b422b1SDavid Howells 754ceac45SDavid Howells struct nfs_string; 854ceac45SDavid Howells 954ceac45SDavid Howells /* Maximum number of readahead requests 1054ceac45SDavid Howells * FIXME: this should really be a sysctl so that users may tune it to suit 1154ceac45SDavid Howells * their needs. People that do NFS over a slow network, might for 1254ceac45SDavid Howells * instance want to reduce it to something closer to 1 for improved 1354ceac45SDavid Howells * interactive response. 1454ceac45SDavid Howells */ 1554ceac45SDavid Howells #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 1654ceac45SDavid Howells 17f7b422b1SDavid Howells struct nfs_clone_mount { 18f7b422b1SDavid Howells const struct super_block *sb; 19f7b422b1SDavid Howells const struct dentry *dentry; 20f7b422b1SDavid Howells struct nfs_fh *fh; 21f7b422b1SDavid Howells struct nfs_fattr *fattr; 22f7b422b1SDavid Howells char *hostname; 23f7b422b1SDavid Howells char *mnt_path; 24f7b422b1SDavid Howells struct sockaddr_in *addr; 25f7b422b1SDavid Howells rpc_authflavor_t authflavor; 26f7b422b1SDavid Howells }; 27f7b422b1SDavid Howells 286b18eaa0S\"Talpey, Thomas\ /* 296b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 306b18eaa0S\"Talpey, Thomas\ */ 316b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data { 326b18eaa0S\"Talpey, Thomas\ int flags; 336b18eaa0S\"Talpey, Thomas\ int rsize, wsize; 346b18eaa0S\"Talpey, Thomas\ int timeo, retrans; 356b18eaa0S\"Talpey, Thomas\ int acregmin, acregmax, 366b18eaa0S\"Talpey, Thomas\ acdirmin, acdirmax; 376b18eaa0S\"Talpey, Thomas\ int namlen; 386b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 396b18eaa0S\"Talpey, Thomas\ unsigned int auth_flavor_len; 406b18eaa0S\"Talpey, Thomas\ rpc_authflavor_t auth_flavors[1]; 416b18eaa0S\"Talpey, Thomas\ char *client_address; 426b18eaa0S\"Talpey, Thomas\ 436b18eaa0S\"Talpey, Thomas\ struct { 446b18eaa0S\"Talpey, Thomas\ struct sockaddr_in address; 456b18eaa0S\"Talpey, Thomas\ char *hostname; 466b18eaa0S\"Talpey, Thomas\ unsigned int version; 476b18eaa0S\"Talpey, Thomas\ unsigned short port; 486b18eaa0S\"Talpey, Thomas\ int protocol; 496b18eaa0S\"Talpey, Thomas\ } mount_server; 506b18eaa0S\"Talpey, Thomas\ 516b18eaa0S\"Talpey, Thomas\ struct { 526b18eaa0S\"Talpey, Thomas\ struct sockaddr_in address; 536b18eaa0S\"Talpey, Thomas\ char *hostname; 546b18eaa0S\"Talpey, Thomas\ char *export_path; 556b18eaa0S\"Talpey, Thomas\ int protocol; 566b18eaa0S\"Talpey, Thomas\ } nfs_server; 576b18eaa0S\"Talpey, Thomas\ }; 586b18eaa0S\"Talpey, Thomas\ 5924c8dbbbSDavid Howells /* client.c */ 6054ceac45SDavid Howells extern struct rpc_program nfs_program; 6154ceac45SDavid Howells 6224c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 63ff052645SChuck Lever extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); 642283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server( 652283f8d6S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 6654ceac45SDavid Howells struct nfs_fh *); 6791ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 6891ea40b9S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 6954ceac45SDavid Howells struct nfs_fh *); 7054ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 7154ceac45SDavid Howells struct nfs_fh *); 7254ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 7354ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 7454ceac45SDavid Howells struct nfs_fh *, 7554ceac45SDavid Howells struct nfs_fattr *); 766aaca566SDavid Howells #ifdef CONFIG_PROC_FS 776aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 786aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 796aaca566SDavid Howells #else 806aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 816aaca566SDavid Howells { 826aaca566SDavid Howells return 0; 836aaca566SDavid Howells } 846aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 856aaca566SDavid Howells { 866aaca566SDavid Howells } 876aaca566SDavid Howells #endif 8824c8dbbbSDavid Howells 897d4e2747SDavid Howells /* nfs4namespace.c */ 90f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 91f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 92f7b422b1SDavid Howells #else 93f7b422b1SDavid Howells static inline 94f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 95f7b422b1SDavid Howells { 96f7b422b1SDavid Howells return ERR_PTR(-ENOENT); 97f7b422b1SDavid Howells } 98f7b422b1SDavid Howells #endif 99f7b422b1SDavid Howells 100f7b422b1SDavid Howells /* callback_xdr.c */ 101f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 102f7b422b1SDavid Howells 103f7b422b1SDavid Howells /* pagelist.c */ 104f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 105266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 106f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 107266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 108f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 109266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 110f7b422b1SDavid Howells 111f7b422b1SDavid Howells #ifdef CONFIG_NFS_DIRECTIO 112f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 113266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 114f7b422b1SDavid Howells #else 115f7b422b1SDavid Howells #define nfs_init_directcache() (0) 116f7b422b1SDavid Howells #define nfs_destroy_directcache() do {} while(0) 117f7b422b1SDavid Howells #endif 118f7b422b1SDavid Howells 119f7b422b1SDavid Howells /* nfs2xdr.c */ 1207d4e2747SDavid Howells extern int nfs_stat_to_errno(int); 121f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 1220dbb4c67SAl Viro extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int); 123f7b422b1SDavid Howells 124f7b422b1SDavid Howells /* nfs3xdr.c */ 125f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 1260dbb4c67SAl Viro extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int); 127f7b422b1SDavid Howells 128f7b422b1SDavid Howells /* nfs4xdr.c */ 1297d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 1300dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 1317d4e2747SDavid Howells #endif 132f7b422b1SDavid Howells 133f7b422b1SDavid Howells /* nfs4proc.c */ 134d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 135f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 136d75d5414SAndrew Morton #endif 137f7b422b1SDavid Howells 138979df72eSTrond Myklebust /* dir.c */ 139979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 140979df72eSTrond Myklebust 141f7b422b1SDavid Howells /* inode.c */ 142f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 143f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 144f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int); 145f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *); 146f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 147f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *); 148f7b422b1SDavid Howells #endif 149f7b422b1SDavid Howells 150f7b422b1SDavid Howells /* super.c */ 15154ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 152f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 15354ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 15454ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 155f7b422b1SDavid Howells #endif 1564ebd9ab3SDominik Hackl 157f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 1584ebd9ab3SDominik Hackl 159f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 160f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 161ef818a28SSteve Dickson extern void nfs_sb_active(struct nfs_server *server); 162ef818a28SSteve Dickson extern void nfs_sb_deactive(struct nfs_server *server); 163f7b422b1SDavid Howells 164f7b422b1SDavid Howells /* namespace.c */ 16554ceac45SDavid Howells extern char *nfs_path(const char *base, 16654ceac45SDavid Howells const struct dentry *droot, 16754ceac45SDavid Howells const struct dentry *dentry, 168f7b422b1SDavid Howells char *buffer, ssize_t buflen); 169f7b422b1SDavid Howells 17054ceac45SDavid Howells /* getroot.c */ 17154ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); 1727d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 17354ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *); 17454ceac45SDavid Howells 17554ceac45SDavid Howells extern int nfs4_path_walk(struct nfs_server *server, 17654ceac45SDavid Howells struct nfs_fh *mntfh, 17754ceac45SDavid Howells const char *path); 1787d4e2747SDavid Howells #endif 179f7b422b1SDavid Howells 180f7b422b1SDavid Howells /* 181f7b422b1SDavid Howells * Determine the device name as a string 182f7b422b1SDavid Howells */ 183f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent, 184f7b422b1SDavid Howells const struct dentry *dentry, 185f7b422b1SDavid Howells char *buffer, ssize_t buflen) 186f7b422b1SDavid Howells { 18754ceac45SDavid Howells return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root, 18854ceac45SDavid Howells dentry, buffer, buflen); 189f7b422b1SDavid Howells } 190f7b422b1SDavid Howells 191f7b422b1SDavid Howells /* 192f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 193f7b422b1SDavid Howells */ 194f7b422b1SDavid Howells static inline 195f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 196f7b422b1SDavid Howells { 197f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 198f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 199f7b422b1SDavid Howells unsigned char nrbits; 200f7b422b1SDavid Howells 201f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 202f7b422b1SDavid Howells ; 203f7b422b1SDavid Howells bsize = 1 << nrbits; 204f7b422b1SDavid Howells if (nrbitsp) 205f7b422b1SDavid Howells *nrbitsp = nrbits; 206f7b422b1SDavid Howells } 207f7b422b1SDavid Howells 208f7b422b1SDavid Howells return bsize; 209f7b422b1SDavid Howells } 210f7b422b1SDavid Howells 211f7b422b1SDavid Howells /* 212f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 213f7b422b1SDavid Howells */ 2149eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 215f7b422b1SDavid Howells { 2169eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 217f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 218f7b422b1SDavid Howells } 219f7b422b1SDavid Howells 220f7b422b1SDavid Howells /* 221f7b422b1SDavid Howells * Compute and set NFS server blocksize 222f7b422b1SDavid Howells */ 223f7b422b1SDavid Howells static inline 224f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 225f7b422b1SDavid Howells { 226f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 227f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 228f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 229f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 230f7b422b1SDavid Howells 231f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 232f7b422b1SDavid Howells } 233f7b422b1SDavid Howells 234f7b422b1SDavid Howells /* 235f7b422b1SDavid Howells * Determine the maximum file size for a superblock 236f7b422b1SDavid Howells */ 237f7b422b1SDavid Howells static inline 238f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 239f7b422b1SDavid Howells { 240f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 241f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 242f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 243f7b422b1SDavid Howells } 24449a70f27STrond Myklebust 24549a70f27STrond Myklebust /* 24649a70f27STrond Myklebust * Determine the number of bytes of data the page contains 24749a70f27STrond Myklebust */ 24849a70f27STrond Myklebust static inline 24949a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 25049a70f27STrond Myklebust { 25149a70f27STrond Myklebust loff_t i_size = i_size_read(page->mapping->host); 25249a70f27STrond Myklebust 25349a70f27STrond Myklebust if (i_size > 0) { 25449a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 25549a70f27STrond Myklebust if (page->index < end_index) 25649a70f27STrond Myklebust return PAGE_CACHE_SIZE; 25749a70f27STrond Myklebust if (page->index == end_index) 25849a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 25949a70f27STrond Myklebust } 26049a70f27STrond Myklebust return 0; 26149a70f27STrond Myklebust } 2628d5658c9STrond Myklebust 2638d5658c9STrond Myklebust /* 2648d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 2658d5658c9STrond Myklebust * with a base offset of 'base' 2668d5658c9STrond Myklebust */ 2678d5658c9STrond Myklebust static inline 2688d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 2698d5658c9STrond Myklebust { 2708d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 2718d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 2728d5658c9STrond Myklebust } 2738d5658c9STrond Myklebust 274