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\ 66146ec944SChuck Lever /* mount_clnt.c */ 67c5d120f8SChuck Lever struct nfs_mount_request { 68c5d120f8SChuck Lever struct sockaddr *sap; 69c5d120f8SChuck Lever size_t salen; 70c5d120f8SChuck Lever char *hostname; 71c5d120f8SChuck Lever char *dirpath; 72c5d120f8SChuck Lever u32 version; 73c5d120f8SChuck Lever unsigned short protocol; 74c5d120f8SChuck Lever struct nfs_fh *fh; 75c5d120f8SChuck Lever }; 76c5d120f8SChuck Lever 77c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info); 78146ec944SChuck Lever 7924c8dbbbSDavid Howells /* client.c */ 8054ceac45SDavid Howells extern struct rpc_program nfs_program; 8154ceac45SDavid Howells 8224c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 83ff052645SChuck Lever extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); 843fbd67adSTrond Myklebust extern struct nfs_client *nfs_find_client_next(struct nfs_client *); 852283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server( 862283f8d6S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 8754ceac45SDavid Howells struct nfs_fh *); 8891ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 8991ea40b9S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 9054ceac45SDavid Howells struct nfs_fh *); 9154ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 9254ceac45SDavid Howells struct nfs_fh *); 9354ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 9454ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 9554ceac45SDavid Howells struct nfs_fh *, 9654ceac45SDavid Howells struct nfs_fattr *); 976aaca566SDavid Howells #ifdef CONFIG_PROC_FS 986aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 996aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 1006aaca566SDavid Howells #else 1016aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 1026aaca566SDavid Howells { 1036aaca566SDavid Howells return 0; 1046aaca566SDavid Howells } 1056aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 1066aaca566SDavid Howells { 1076aaca566SDavid Howells } 1086aaca566SDavid Howells #endif 10924c8dbbbSDavid Howells 1107d4e2747SDavid Howells /* nfs4namespace.c */ 111f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 112f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 113f7b422b1SDavid Howells #else 114f7b422b1SDavid Howells static inline 115f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 116f7b422b1SDavid Howells { 117f7b422b1SDavid Howells return ERR_PTR(-ENOENT); 118f7b422b1SDavid Howells } 119f7b422b1SDavid Howells #endif 120f7b422b1SDavid Howells 121f7b422b1SDavid Howells /* callback_xdr.c */ 122f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 123f7b422b1SDavid Howells 124f7b422b1SDavid Howells /* pagelist.c */ 125f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 126266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 127f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 128266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 129f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 130266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 131f7b422b1SDavid Howells 132f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 133266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 134f7b422b1SDavid Howells 135f7b422b1SDavid Howells /* nfs2xdr.c */ 1367d4e2747SDavid Howells extern int nfs_stat_to_errno(int); 137f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 1380dbb4c67SAl Viro extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int); 139f7b422b1SDavid Howells 140f7b422b1SDavid Howells /* nfs3xdr.c */ 141f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 1420dbb4c67SAl Viro extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int); 143f7b422b1SDavid Howells 144f7b422b1SDavid Howells /* nfs4xdr.c */ 1457d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 1460dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 1477d4e2747SDavid Howells #endif 148f7b422b1SDavid Howells 149f7b422b1SDavid Howells /* nfs4proc.c */ 150d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 151f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 152d75d5414SAndrew Morton #endif 153f7b422b1SDavid Howells 154979df72eSTrond Myklebust /* dir.c */ 155979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 156979df72eSTrond Myklebust 157f7b422b1SDavid Howells /* inode.c */ 1585746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 159f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 160f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 161f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int); 162f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *); 163f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 164f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *); 165f7b422b1SDavid Howells #endif 166f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode); 167f7b422b1SDavid Howells 168f7b422b1SDavid Howells /* super.c */ 169ea31a443SJ. Bruce Fields void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *); 17054ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 171f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 17254ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 17354ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 174f7b422b1SDavid Howells #endif 1754ebd9ab3SDominik Hackl 176f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 1774ebd9ab3SDominik Hackl 178f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 179f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 1801daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb); 1811daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 182f7b422b1SDavid Howells 183f7b422b1SDavid Howells /* namespace.c */ 18454ceac45SDavid Howells extern char *nfs_path(const char *base, 18554ceac45SDavid Howells const struct dentry *droot, 18654ceac45SDavid Howells const struct dentry *dentry, 187f7b422b1SDavid Howells char *buffer, ssize_t buflen); 188f7b422b1SDavid Howells 18954ceac45SDavid Howells /* getroot.c */ 19054ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); 1917d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 19254ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *); 19354ceac45SDavid Howells 19454ceac45SDavid Howells extern int nfs4_path_walk(struct nfs_server *server, 19554ceac45SDavid Howells struct nfs_fh *mntfh, 19654ceac45SDavid Howells const char *path); 1977d4e2747SDavid Howells #endif 198f7b422b1SDavid Howells 199f7b422b1SDavid Howells /* 200f7b422b1SDavid Howells * Determine the device name as a string 201f7b422b1SDavid Howells */ 202f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent, 203f7b422b1SDavid Howells const struct dentry *dentry, 204f7b422b1SDavid Howells char *buffer, ssize_t buflen) 205f7b422b1SDavid Howells { 20654ceac45SDavid Howells return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root, 20754ceac45SDavid Howells dentry, buffer, buflen); 208f7b422b1SDavid Howells } 209f7b422b1SDavid Howells 210f7b422b1SDavid Howells /* 211f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 212f7b422b1SDavid Howells */ 213f7b422b1SDavid Howells static inline 214f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 215f7b422b1SDavid Howells { 216f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 217f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 218f7b422b1SDavid Howells unsigned char nrbits; 219f7b422b1SDavid Howells 220f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 221f7b422b1SDavid Howells ; 222f7b422b1SDavid Howells bsize = 1 << nrbits; 223f7b422b1SDavid Howells if (nrbitsp) 224f7b422b1SDavid Howells *nrbitsp = nrbits; 225f7b422b1SDavid Howells } 226f7b422b1SDavid Howells 227f7b422b1SDavid Howells return bsize; 228f7b422b1SDavid Howells } 229f7b422b1SDavid Howells 230f7b422b1SDavid Howells /* 231f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 232f7b422b1SDavid Howells */ 2339eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 234f7b422b1SDavid Howells { 2359eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 236f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 237f7b422b1SDavid Howells } 238f7b422b1SDavid Howells 239f7b422b1SDavid Howells /* 240f7b422b1SDavid Howells * Compute and set NFS server blocksize 241f7b422b1SDavid Howells */ 242f7b422b1SDavid Howells static inline 243f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 244f7b422b1SDavid Howells { 245f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 246f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 247f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 248f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 249f7b422b1SDavid Howells 250f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 251f7b422b1SDavid Howells } 252f7b422b1SDavid Howells 253f7b422b1SDavid Howells /* 254f7b422b1SDavid Howells * Determine the maximum file size for a superblock 255f7b422b1SDavid Howells */ 256f7b422b1SDavid Howells static inline 257f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 258f7b422b1SDavid Howells { 259f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 260f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 261f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 262f7b422b1SDavid Howells } 26349a70f27STrond Myklebust 26449a70f27STrond Myklebust /* 26549a70f27STrond Myklebust * Determine the number of bytes of data the page contains 26649a70f27STrond Myklebust */ 26749a70f27STrond Myklebust static inline 26849a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 26949a70f27STrond Myklebust { 27049a70f27STrond Myklebust loff_t i_size = i_size_read(page->mapping->host); 27149a70f27STrond Myklebust 27249a70f27STrond Myklebust if (i_size > 0) { 27349a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 27449a70f27STrond Myklebust if (page->index < end_index) 27549a70f27STrond Myklebust return PAGE_CACHE_SIZE; 27649a70f27STrond Myklebust if (page->index == end_index) 27749a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 27849a70f27STrond Myklebust } 27949a70f27STrond Myklebust return 0; 28049a70f27STrond Myklebust } 2818d5658c9STrond Myklebust 2828d5658c9STrond Myklebust /* 2838d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 2848d5658c9STrond Myklebust * with a base offset of 'base' 2858d5658c9STrond Myklebust */ 2868d5658c9STrond Myklebust static inline 2878d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 2888d5658c9STrond Myklebust { 2898d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 2908d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 2918d5658c9STrond Myklebust } 2928d5658c9STrond Myklebust 293ea31a443SJ. Bruce Fields #define IPV6_SCOPE_DELIMITER '%' 294f0c92925SJ. Bruce Fields 295f0c92925SJ. Bruce Fields /* 296f0c92925SJ. Bruce Fields * Set the port number in an address. Be agnostic about the address 297f0c92925SJ. Bruce Fields * family. 298f0c92925SJ. Bruce Fields */ 299f0c92925SJ. Bruce Fields static inline void nfs_set_port(struct sockaddr *sap, unsigned short port) 300f0c92925SJ. Bruce Fields { 301f0c92925SJ. Bruce Fields struct sockaddr_in *ap = (struct sockaddr_in *)sap; 302456018d7SJ. Bruce Fields struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap; 303456018d7SJ. Bruce Fields 304456018d7SJ. Bruce Fields switch (sap->sa_family) { 305456018d7SJ. Bruce Fields case AF_INET: 306f0c92925SJ. Bruce Fields ap->sin_port = htons(port); 307f0c92925SJ. Bruce Fields break; 308456018d7SJ. Bruce Fields case AF_INET6: 309456018d7SJ. Bruce Fields ap6->sin6_port = htons(port); 310f0c92925SJ. Bruce Fields break; 311f0c92925SJ. Bruce Fields } 312f0c92925SJ. Bruce Fields } 313