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 808734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) 908734048SDavid Howells 1054ceac45SDavid Howells struct nfs_string; 1154ceac45SDavid Howells 1254ceac45SDavid Howells /* Maximum number of readahead requests 1354ceac45SDavid Howells * FIXME: this should really be a sysctl so that users may tune it to suit 1454ceac45SDavid Howells * their needs. People that do NFS over a slow network, might for 1554ceac45SDavid Howells * instance want to reduce it to something closer to 1 for improved 1654ceac45SDavid Howells * interactive response. 1754ceac45SDavid Howells */ 1854ceac45SDavid Howells #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 1954ceac45SDavid Howells 20f7b422b1SDavid Howells struct nfs_clone_mount { 21f7b422b1SDavid Howells const struct super_block *sb; 22f7b422b1SDavid Howells const struct dentry *dentry; 23f7b422b1SDavid Howells struct nfs_fh *fh; 24f7b422b1SDavid Howells struct nfs_fattr *fattr; 25f7b422b1SDavid Howells char *hostname; 26f7b422b1SDavid Howells char *mnt_path; 276677d095SChuck Lever struct sockaddr *addr; 286677d095SChuck Lever size_t addrlen; 29f7b422b1SDavid Howells rpc_authflavor_t authflavor; 30f7b422b1SDavid Howells }; 31f7b422b1SDavid Howells 326b18eaa0S\"Talpey, Thomas\ /* 336b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 346b18eaa0S\"Talpey, Thomas\ */ 356b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data { 366b18eaa0S\"Talpey, Thomas\ int flags; 376b18eaa0S\"Talpey, Thomas\ int rsize, wsize; 386b18eaa0S\"Talpey, Thomas\ int timeo, retrans; 396b18eaa0S\"Talpey, Thomas\ int acregmin, acregmax, 406b18eaa0S\"Talpey, Thomas\ acdirmin, acdirmax; 416b18eaa0S\"Talpey, Thomas\ int namlen; 426b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 436b18eaa0S\"Talpey, Thomas\ unsigned int auth_flavor_len; 446b18eaa0S\"Talpey, Thomas\ rpc_authflavor_t auth_flavors[1]; 456b18eaa0S\"Talpey, Thomas\ char *client_address; 4608734048SDavid Howells char *fscache_uniq; 476b18eaa0S\"Talpey, Thomas\ 486b18eaa0S\"Talpey, Thomas\ struct { 494c568017SChuck Lever struct sockaddr_storage address; 504c568017SChuck Lever size_t addrlen; 516b18eaa0S\"Talpey, Thomas\ char *hostname; 5278fa701fSChuck Lever u32 version; 536b18eaa0S\"Talpey, Thomas\ unsigned short port; 5478fa701fSChuck Lever unsigned short protocol; 556b18eaa0S\"Talpey, Thomas\ } mount_server; 566b18eaa0S\"Talpey, Thomas\ 576b18eaa0S\"Talpey, Thomas\ struct { 584c568017SChuck Lever struct sockaddr_storage address; 594c568017SChuck Lever size_t addrlen; 606b18eaa0S\"Talpey, Thomas\ char *hostname; 616b18eaa0S\"Talpey, Thomas\ char *export_path; 62f22d6d79SChuck Lever unsigned short port; 6378fa701fSChuck Lever unsigned short protocol; 646b18eaa0S\"Talpey, Thomas\ } nfs_server; 65f9c3a380SEric Paris 66f9c3a380SEric Paris struct security_mnt_opts lsm_opts; 676b18eaa0S\"Talpey, Thomas\ }; 686b18eaa0S\"Talpey, Thomas\ 69146ec944SChuck Lever /* mount_clnt.c */ 70c5d120f8SChuck Lever struct nfs_mount_request { 71c5d120f8SChuck Lever struct sockaddr *sap; 72c5d120f8SChuck Lever size_t salen; 73c5d120f8SChuck Lever char *hostname; 74c5d120f8SChuck Lever char *dirpath; 75c5d120f8SChuck Lever u32 version; 76c5d120f8SChuck Lever unsigned short protocol; 77c5d120f8SChuck Lever struct nfs_fh *fh; 7850a737f8SChuck Lever int noresvport; 79c5d120f8SChuck Lever }; 80c5d120f8SChuck Lever 81c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info); 82146ec944SChuck Lever 8324c8dbbbSDavid Howells /* client.c */ 8454ceac45SDavid Howells extern struct rpc_program nfs_program; 8554ceac45SDavid Howells 8624c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 87ff052645SChuck Lever extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); 883fbd67adSTrond Myklebust extern struct nfs_client *nfs_find_client_next(struct nfs_client *); 892283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server( 902283f8d6S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 9154ceac45SDavid Howells struct nfs_fh *); 9291ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 9391ea40b9S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 9454ceac45SDavid Howells struct nfs_fh *); 9554ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 9654ceac45SDavid Howells struct nfs_fh *); 9754ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 9854ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 9954ceac45SDavid Howells struct nfs_fh *, 10054ceac45SDavid Howells struct nfs_fattr *); 1016aaca566SDavid Howells #ifdef CONFIG_PROC_FS 1026aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 1036aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 1046aaca566SDavid Howells #else 1056aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 1066aaca566SDavid Howells { 1076aaca566SDavid Howells return 0; 1086aaca566SDavid Howells } 1096aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 1106aaca566SDavid Howells { 1116aaca566SDavid Howells } 1126aaca566SDavid Howells #endif 11324c8dbbbSDavid Howells 1147d4e2747SDavid Howells /* nfs4namespace.c */ 115f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 116f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 117f7b422b1SDavid Howells #else 118f7b422b1SDavid Howells static inline 119f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 120f7b422b1SDavid Howells { 121f7b422b1SDavid Howells return ERR_PTR(-ENOENT); 122f7b422b1SDavid Howells } 123f7b422b1SDavid Howells #endif 124f7b422b1SDavid Howells 125f7b422b1SDavid Howells /* callback_xdr.c */ 126f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 127f7b422b1SDavid Howells 128f7b422b1SDavid Howells /* pagelist.c */ 129f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 130266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 131f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 132266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 133f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 134266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 135f7b422b1SDavid Howells 136f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 137266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 138f7b422b1SDavid Howells 139f7b422b1SDavid Howells /* nfs2xdr.c */ 1407d4e2747SDavid Howells extern int nfs_stat_to_errno(int); 141f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 1420dbb4c67SAl Viro extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int); 143f7b422b1SDavid Howells 144f7b422b1SDavid Howells /* nfs3xdr.c */ 145f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 1460dbb4c67SAl Viro extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int); 147f7b422b1SDavid Howells 148f7b422b1SDavid Howells /* nfs4xdr.c */ 1497d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 1500dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 1517d4e2747SDavid Howells #endif 152f7b422b1SDavid Howells 153f7b422b1SDavid Howells /* nfs4proc.c */ 154d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 155f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 156d75d5414SAndrew Morton #endif 157f7b422b1SDavid Howells 1587fe5c398STrond Myklebust /* proc.c */ 1597fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 1607fe5c398STrond Myklebust 161979df72eSTrond Myklebust /* dir.c */ 162979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 163979df72eSTrond Myklebust 164f7b422b1SDavid Howells /* inode.c */ 1655746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 166f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 167f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 168f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int); 169f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *); 170f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 171f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *); 172f7b422b1SDavid Howells #endif 173f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode); 17472cb77f4STrond Myklebust extern int nfs_wait_bit_killable(void *word); 175f7b422b1SDavid Howells 176f7b422b1SDavid Howells /* super.c */ 177ea31a443SJ. Bruce Fields void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *); 17854ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 179f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 18054ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 18154ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 182f7b422b1SDavid Howells #endif 1834ebd9ab3SDominik Hackl 184f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 1854ebd9ab3SDominik Hackl 186f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 187f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 1881daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb); 1891daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 190f7b422b1SDavid Howells 191f7b422b1SDavid Howells /* namespace.c */ 19254ceac45SDavid Howells extern char *nfs_path(const char *base, 19354ceac45SDavid Howells const struct dentry *droot, 19454ceac45SDavid Howells const struct dentry *dentry, 195f7b422b1SDavid Howells char *buffer, ssize_t buflen); 196f7b422b1SDavid Howells 19754ceac45SDavid Howells /* getroot.c */ 19854ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); 1997d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 20054ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *); 20154ceac45SDavid Howells 20254ceac45SDavid Howells extern int nfs4_path_walk(struct nfs_server *server, 20354ceac45SDavid Howells struct nfs_fh *mntfh, 20454ceac45SDavid Howells const char *path); 2057d4e2747SDavid Howells #endif 206f7b422b1SDavid Howells 207f7b422b1SDavid Howells /* 208f7b422b1SDavid Howells * Determine the device name as a string 209f7b422b1SDavid Howells */ 210f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent, 211f7b422b1SDavid Howells const struct dentry *dentry, 212f7b422b1SDavid Howells char *buffer, ssize_t buflen) 213f7b422b1SDavid Howells { 21454ceac45SDavid Howells return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root, 21554ceac45SDavid Howells dentry, buffer, buflen); 216f7b422b1SDavid Howells } 217f7b422b1SDavid Howells 218f7b422b1SDavid Howells /* 219f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 220f7b422b1SDavid Howells */ 221f7b422b1SDavid Howells static inline 222f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 223f7b422b1SDavid Howells { 224f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 225f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 226f7b422b1SDavid Howells unsigned char nrbits; 227f7b422b1SDavid Howells 228f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 229f7b422b1SDavid Howells ; 230f7b422b1SDavid Howells bsize = 1 << nrbits; 231f7b422b1SDavid Howells if (nrbitsp) 232f7b422b1SDavid Howells *nrbitsp = nrbits; 233f7b422b1SDavid Howells } 234f7b422b1SDavid Howells 235f7b422b1SDavid Howells return bsize; 236f7b422b1SDavid Howells } 237f7b422b1SDavid Howells 238f7b422b1SDavid Howells /* 239f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 240f7b422b1SDavid Howells */ 2419eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 242f7b422b1SDavid Howells { 2439eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 244f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 245f7b422b1SDavid Howells } 246f7b422b1SDavid Howells 247f7b422b1SDavid Howells /* 248f7b422b1SDavid Howells * Compute and set NFS server blocksize 249f7b422b1SDavid Howells */ 250f7b422b1SDavid Howells static inline 251f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 252f7b422b1SDavid Howells { 253f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 254f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 255f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 256f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 257f7b422b1SDavid Howells 258f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 259f7b422b1SDavid Howells } 260f7b422b1SDavid Howells 261f7b422b1SDavid Howells /* 262f7b422b1SDavid Howells * Determine the maximum file size for a superblock 263f7b422b1SDavid Howells */ 264f7b422b1SDavid Howells static inline 265f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 266f7b422b1SDavid Howells { 267f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 268f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 269f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 270f7b422b1SDavid Howells } 27149a70f27STrond Myklebust 27249a70f27STrond Myklebust /* 27349a70f27STrond Myklebust * Determine the number of bytes of data the page contains 27449a70f27STrond Myklebust */ 27549a70f27STrond Myklebust static inline 27649a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 27749a70f27STrond Myklebust { 27849a70f27STrond Myklebust loff_t i_size = i_size_read(page->mapping->host); 27949a70f27STrond Myklebust 28049a70f27STrond Myklebust if (i_size > 0) { 28149a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 28249a70f27STrond Myklebust if (page->index < end_index) 28349a70f27STrond Myklebust return PAGE_CACHE_SIZE; 28449a70f27STrond Myklebust if (page->index == end_index) 28549a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 28649a70f27STrond Myklebust } 28749a70f27STrond Myklebust return 0; 28849a70f27STrond Myklebust } 2898d5658c9STrond Myklebust 2908d5658c9STrond Myklebust /* 2918d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 2928d5658c9STrond Myklebust * with a base offset of 'base' 2938d5658c9STrond Myklebust */ 2948d5658c9STrond Myklebust static inline 2958d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 2968d5658c9STrond Myklebust { 2978d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 2988d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 2998d5658c9STrond Myklebust } 3008d5658c9STrond Myklebust 301ea31a443SJ. Bruce Fields #define IPV6_SCOPE_DELIMITER '%' 302f0c92925SJ. Bruce Fields 303f0c92925SJ. Bruce Fields /* 304f0c92925SJ. Bruce Fields * Set the port number in an address. Be agnostic about the address 305f0c92925SJ. Bruce Fields * family. 306f0c92925SJ. Bruce Fields */ 307f0c92925SJ. Bruce Fields static inline void nfs_set_port(struct sockaddr *sap, unsigned short port) 308f0c92925SJ. Bruce Fields { 309f0c92925SJ. Bruce Fields struct sockaddr_in *ap = (struct sockaddr_in *)sap; 310456018d7SJ. Bruce Fields struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap; 311456018d7SJ. Bruce Fields 312456018d7SJ. Bruce Fields switch (sap->sa_family) { 313456018d7SJ. Bruce Fields case AF_INET: 314f0c92925SJ. Bruce Fields ap->sin_port = htons(port); 315f0c92925SJ. Bruce Fields break; 316456018d7SJ. Bruce Fields case AF_INET6: 317456018d7SJ. Bruce Fields ap6->sin6_port = htons(port); 318f0c92925SJ. Bruce Fields break; 319f0c92925SJ. Bruce Fields } 320f0c92925SJ. Bruce Fields } 321