1f7b422b1SDavid Howells /* 2f7b422b1SDavid Howells * NFS internal definitions 3f7b422b1SDavid Howells */ 4f7b422b1SDavid Howells 5f7b422b1SDavid Howells #include <linux/mount.h> 6f9c3a380SEric Paris #include <linux/security.h> 7f7b422b1SDavid Howells 854ceac45SDavid Howells struct nfs_string; 954ceac45SDavid Howells 1054ceac45SDavid Howells /* Maximum number of readahead requests 1154ceac45SDavid Howells * FIXME: this should really be a sysctl so that users may tune it to suit 1254ceac45SDavid Howells * their needs. People that do NFS over a slow network, might for 1354ceac45SDavid Howells * instance want to reduce it to something closer to 1 for improved 1454ceac45SDavid Howells * interactive response. 1554ceac45SDavid Howells */ 1654ceac45SDavid Howells #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 1754ceac45SDavid Howells 18f7b422b1SDavid Howells struct nfs_clone_mount { 19f7b422b1SDavid Howells const struct super_block *sb; 20f7b422b1SDavid Howells const struct dentry *dentry; 21f7b422b1SDavid Howells struct nfs_fh *fh; 22f7b422b1SDavid Howells struct nfs_fattr *fattr; 23f7b422b1SDavid Howells char *hostname; 24f7b422b1SDavid Howells char *mnt_path; 256677d095SChuck Lever struct sockaddr *addr; 266677d095SChuck Lever size_t addrlen; 27f7b422b1SDavid Howells rpc_authflavor_t authflavor; 28f7b422b1SDavid Howells }; 29f7b422b1SDavid Howells 306b18eaa0S\"Talpey, Thomas\ /* 316b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 326b18eaa0S\"Talpey, Thomas\ */ 336b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data { 346b18eaa0S\"Talpey, Thomas\ int flags; 356b18eaa0S\"Talpey, Thomas\ int rsize, wsize; 366b18eaa0S\"Talpey, Thomas\ int timeo, retrans; 376b18eaa0S\"Talpey, Thomas\ int acregmin, acregmax, 386b18eaa0S\"Talpey, Thomas\ acdirmin, acdirmax; 396b18eaa0S\"Talpey, Thomas\ int namlen; 406b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 416b18eaa0S\"Talpey, Thomas\ unsigned int auth_flavor_len; 426b18eaa0S\"Talpey, Thomas\ rpc_authflavor_t auth_flavors[1]; 436b18eaa0S\"Talpey, Thomas\ char *client_address; 446b18eaa0S\"Talpey, Thomas\ 456b18eaa0S\"Talpey, Thomas\ struct { 464c568017SChuck Lever struct sockaddr_storage address; 474c568017SChuck Lever size_t addrlen; 486b18eaa0S\"Talpey, Thomas\ char *hostname; 4978fa701fSChuck Lever u32 version; 506b18eaa0S\"Talpey, Thomas\ unsigned short port; 5178fa701fSChuck Lever unsigned short protocol; 526b18eaa0S\"Talpey, Thomas\ } mount_server; 536b18eaa0S\"Talpey, Thomas\ 546b18eaa0S\"Talpey, Thomas\ struct { 554c568017SChuck Lever struct sockaddr_storage address; 564c568017SChuck Lever size_t addrlen; 576b18eaa0S\"Talpey, Thomas\ char *hostname; 586b18eaa0S\"Talpey, Thomas\ char *export_path; 59f22d6d79SChuck Lever unsigned short port; 6078fa701fSChuck Lever unsigned short protocol; 616b18eaa0S\"Talpey, Thomas\ } nfs_server; 62f9c3a380SEric Paris 63f9c3a380SEric Paris struct security_mnt_opts lsm_opts; 646b18eaa0S\"Talpey, Thomas\ }; 656b18eaa0S\"Talpey, Thomas\ 6624c8dbbbSDavid Howells /* client.c */ 6754ceac45SDavid Howells extern struct rpc_program nfs_program; 6854ceac45SDavid Howells 6924c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 70ff052645SChuck Lever extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); 713fbd67adSTrond Myklebust extern struct nfs_client *nfs_find_client_next(struct nfs_client *); 722283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server( 732283f8d6S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 7454ceac45SDavid Howells struct nfs_fh *); 7591ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 7691ea40b9S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 7754ceac45SDavid Howells struct nfs_fh *); 7854ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 7954ceac45SDavid Howells struct nfs_fh *); 8054ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 8154ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 8254ceac45SDavid Howells struct nfs_fh *, 8354ceac45SDavid Howells struct nfs_fattr *); 846aaca566SDavid Howells #ifdef CONFIG_PROC_FS 856aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 866aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 876aaca566SDavid Howells #else 886aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 896aaca566SDavid Howells { 906aaca566SDavid Howells return 0; 916aaca566SDavid Howells } 926aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 936aaca566SDavid Howells { 946aaca566SDavid Howells } 956aaca566SDavid Howells #endif 9624c8dbbbSDavid Howells 977d4e2747SDavid Howells /* nfs4namespace.c */ 98f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 99f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 100f7b422b1SDavid Howells #else 101f7b422b1SDavid Howells static inline 102f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 103f7b422b1SDavid Howells { 104f7b422b1SDavid Howells return ERR_PTR(-ENOENT); 105f7b422b1SDavid Howells } 106f7b422b1SDavid Howells #endif 107f7b422b1SDavid Howells 108f7b422b1SDavid Howells /* callback_xdr.c */ 109f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 110f7b422b1SDavid Howells 111f7b422b1SDavid Howells /* pagelist.c */ 112f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 113266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 114f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 115266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 116f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 117266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 118f7b422b1SDavid Howells 119f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 120266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 121f7b422b1SDavid Howells 122f7b422b1SDavid Howells /* nfs2xdr.c */ 1237d4e2747SDavid Howells extern int nfs_stat_to_errno(int); 124f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 1250dbb4c67SAl Viro extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int); 126f7b422b1SDavid Howells 127f7b422b1SDavid Howells /* nfs3xdr.c */ 128f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 1290dbb4c67SAl Viro extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int); 130f7b422b1SDavid Howells 131f7b422b1SDavid Howells /* nfs4xdr.c */ 1327d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 1330dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 1347d4e2747SDavid Howells #endif 135f7b422b1SDavid Howells 136f7b422b1SDavid Howells /* nfs4proc.c */ 137d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 138f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 139d75d5414SAndrew Morton #endif 140f7b422b1SDavid Howells 141979df72eSTrond Myklebust /* dir.c */ 142979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 143979df72eSTrond Myklebust 144f7b422b1SDavid Howells /* inode.c */ 1455746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 146f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 147f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 148f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int); 149f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *); 150f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 151f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *); 152f7b422b1SDavid Howells #endif 153f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode); 154f7b422b1SDavid Howells 155f7b422b1SDavid Howells /* super.c */ 156ea31a443SJ. Bruce Fields void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *); 15754ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 158f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 15954ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 16054ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 161f7b422b1SDavid Howells #endif 1624ebd9ab3SDominik Hackl 163f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 1644ebd9ab3SDominik Hackl 165f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 166f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 1671daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb); 1681daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 169f7b422b1SDavid Howells 170f7b422b1SDavid Howells /* namespace.c */ 17154ceac45SDavid Howells extern char *nfs_path(const char *base, 17254ceac45SDavid Howells const struct dentry *droot, 17354ceac45SDavid Howells const struct dentry *dentry, 174f7b422b1SDavid Howells char *buffer, ssize_t buflen); 175f7b422b1SDavid Howells 17654ceac45SDavid Howells /* getroot.c */ 17754ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); 1787d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 17954ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *); 18054ceac45SDavid Howells 18154ceac45SDavid Howells extern int nfs4_path_walk(struct nfs_server *server, 18254ceac45SDavid Howells struct nfs_fh *mntfh, 18354ceac45SDavid Howells const char *path); 1847d4e2747SDavid Howells #endif 185f7b422b1SDavid Howells 186f7b422b1SDavid Howells /* 187f7b422b1SDavid Howells * Determine the device name as a string 188f7b422b1SDavid Howells */ 189f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent, 190f7b422b1SDavid Howells const struct dentry *dentry, 191f7b422b1SDavid Howells char *buffer, ssize_t buflen) 192f7b422b1SDavid Howells { 19354ceac45SDavid Howells return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root, 19454ceac45SDavid Howells dentry, buffer, buflen); 195f7b422b1SDavid Howells } 196f7b422b1SDavid Howells 197f7b422b1SDavid Howells /* 198f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 199f7b422b1SDavid Howells */ 200f7b422b1SDavid Howells static inline 201f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 202f7b422b1SDavid Howells { 203f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 204f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 205f7b422b1SDavid Howells unsigned char nrbits; 206f7b422b1SDavid Howells 207f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 208f7b422b1SDavid Howells ; 209f7b422b1SDavid Howells bsize = 1 << nrbits; 210f7b422b1SDavid Howells if (nrbitsp) 211f7b422b1SDavid Howells *nrbitsp = nrbits; 212f7b422b1SDavid Howells } 213f7b422b1SDavid Howells 214f7b422b1SDavid Howells return bsize; 215f7b422b1SDavid Howells } 216f7b422b1SDavid Howells 217f7b422b1SDavid Howells /* 218f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 219f7b422b1SDavid Howells */ 2209eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 221f7b422b1SDavid Howells { 2229eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 223f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 224f7b422b1SDavid Howells } 225f7b422b1SDavid Howells 226f7b422b1SDavid Howells /* 227f7b422b1SDavid Howells * Compute and set NFS server blocksize 228f7b422b1SDavid Howells */ 229f7b422b1SDavid Howells static inline 230f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 231f7b422b1SDavid Howells { 232f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 233f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 234f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 235f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 236f7b422b1SDavid Howells 237f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 238f7b422b1SDavid Howells } 239f7b422b1SDavid Howells 240f7b422b1SDavid Howells /* 241f7b422b1SDavid Howells * Determine the maximum file size for a superblock 242f7b422b1SDavid Howells */ 243f7b422b1SDavid Howells static inline 244f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 245f7b422b1SDavid Howells { 246f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 247f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 248f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 249f7b422b1SDavid Howells } 25049a70f27STrond Myklebust 25149a70f27STrond Myklebust /* 25249a70f27STrond Myklebust * Determine the number of bytes of data the page contains 25349a70f27STrond Myklebust */ 25449a70f27STrond Myklebust static inline 25549a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 25649a70f27STrond Myklebust { 25749a70f27STrond Myklebust loff_t i_size = i_size_read(page->mapping->host); 25849a70f27STrond Myklebust 25949a70f27STrond Myklebust if (i_size > 0) { 26049a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 26149a70f27STrond Myklebust if (page->index < end_index) 26249a70f27STrond Myklebust return PAGE_CACHE_SIZE; 26349a70f27STrond Myklebust if (page->index == end_index) 26449a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 26549a70f27STrond Myklebust } 26649a70f27STrond Myklebust return 0; 26749a70f27STrond Myklebust } 2688d5658c9STrond Myklebust 2698d5658c9STrond Myklebust /* 2708d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 2718d5658c9STrond Myklebust * with a base offset of 'base' 2728d5658c9STrond Myklebust */ 2738d5658c9STrond Myklebust static inline 2748d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 2758d5658c9STrond Myklebust { 2768d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 2778d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 2788d5658c9STrond Myklebust } 2798d5658c9STrond Myklebust 280ea31a443SJ. Bruce Fields #define IPV6_SCOPE_DELIMITER '%' 281f0c92925SJ. Bruce Fields 282f0c92925SJ. Bruce Fields /* 283f0c92925SJ. Bruce Fields * Set the port number in an address. Be agnostic about the address 284f0c92925SJ. Bruce Fields * family. 285f0c92925SJ. Bruce Fields */ 286f0c92925SJ. Bruce Fields static inline void nfs_set_port(struct sockaddr *sap, unsigned short port) 287f0c92925SJ. Bruce Fields { 288f0c92925SJ. Bruce Fields switch (sap->sa_family) { 289f0c92925SJ. Bruce Fields case AF_INET: { 290f0c92925SJ. Bruce Fields struct sockaddr_in *ap = (struct sockaddr_in *)sap; 291f0c92925SJ. Bruce Fields ap->sin_port = htons(port); 292f0c92925SJ. Bruce Fields break; 293f0c92925SJ. Bruce Fields } 294f0c92925SJ. Bruce Fields case AF_INET6: { 295f0c92925SJ. Bruce Fields struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap; 296f0c92925SJ. Bruce Fields ap->sin6_port = htons(port); 297f0c92925SJ. Bruce Fields break; 298f0c92925SJ. Bruce Fields } 299f0c92925SJ. Bruce Fields } 300f0c92925SJ. Bruce Fields } 301