internal.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * NFS internal definitions
  3. */
  4. #include <linux/mount.h>
  5. struct nfs_string;
  6. /* Maximum number of readahead requests
  7. * FIXME: this should really be a sysctl so that users may tune it to suit
  8. * their needs. People that do NFS over a slow network, might for
  9. * instance want to reduce it to something closer to 1 for improved
  10. * interactive response.
  11. */
  12. #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
  13. struct nfs_clone_mount {
  14. const struct super_block *sb;
  15. const struct dentry *dentry;
  16. struct nfs_fh *fh;
  17. struct nfs_fattr *fattr;
  18. char *hostname;
  19. char *mnt_path;
  20. struct sockaddr *addr;
  21. size_t addrlen;
  22. rpc_authflavor_t authflavor;
  23. };
  24. /*
  25. * In-kernel mount arguments
  26. */
  27. struct nfs_parsed_mount_data {
  28. int flags;
  29. int rsize, wsize;
  30. int timeo, retrans;
  31. int acregmin, acregmax,
  32. acdirmin, acdirmax;
  33. int namlen;
  34. unsigned int bsize;
  35. unsigned int auth_flavor_len;
  36. rpc_authflavor_t auth_flavors[1];
  37. char *client_address;
  38. struct {
  39. struct sockaddr_storage address;
  40. size_t addrlen;
  41. char *hostname;
  42. unsigned int version;
  43. unsigned short port;
  44. int protocol;
  45. } mount_server;
  46. struct {
  47. struct sockaddr_storage address;
  48. size_t addrlen;
  49. char *hostname;
  50. char *export_path;
  51. int protocol;
  52. } nfs_server;
  53. };
  54. /* client.c */
  55. extern struct rpc_program nfs_program;
  56. extern void nfs_put_client(struct nfs_client *);
  57. extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
  58. extern struct nfs_server *nfs_create_server(
  59. const struct nfs_parsed_mount_data *,
  60. struct nfs_fh *);
  61. extern struct nfs_server *nfs4_create_server(
  62. const struct nfs_parsed_mount_data *,
  63. struct nfs_fh *);
  64. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  65. struct nfs_fh *);
  66. extern void nfs_free_server(struct nfs_server *server);
  67. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  68. struct nfs_fh *,
  69. struct nfs_fattr *);
  70. #ifdef CONFIG_PROC_FS
  71. extern int __init nfs_fs_proc_init(void);
  72. extern void nfs_fs_proc_exit(void);
  73. #else
  74. static inline int nfs_fs_proc_init(void)
  75. {
  76. return 0;
  77. }
  78. static inline void nfs_fs_proc_exit(void)
  79. {
  80. }
  81. #endif
  82. /* nfs4namespace.c */
  83. #ifdef CONFIG_NFS_V4
  84. extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
  85. #else
  86. static inline
  87. struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
  88. {
  89. return ERR_PTR(-ENOENT);
  90. }
  91. #endif
  92. /* callback_xdr.c */
  93. extern struct svc_version nfs4_callback_version1;
  94. /* pagelist.c */
  95. extern int __init nfs_init_nfspagecache(void);
  96. extern void nfs_destroy_nfspagecache(void);
  97. extern int __init nfs_init_readpagecache(void);
  98. extern void nfs_destroy_readpagecache(void);
  99. extern int __init nfs_init_writepagecache(void);
  100. extern void nfs_destroy_writepagecache(void);
  101. #ifdef CONFIG_NFS_DIRECTIO
  102. extern int __init nfs_init_directcache(void);
  103. extern void nfs_destroy_directcache(void);
  104. #else
  105. #define nfs_init_directcache() (0)
  106. #define nfs_destroy_directcache() do {} while(0)
  107. #endif
  108. /* nfs2xdr.c */
  109. extern int nfs_stat_to_errno(int);
  110. extern struct rpc_procinfo nfs_procedures[];
  111. extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
  112. /* nfs3xdr.c */
  113. extern struct rpc_procinfo nfs3_procedures[];
  114. extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
  115. /* nfs4xdr.c */
  116. #ifdef CONFIG_NFS_V4
  117. extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
  118. #endif
  119. /* nfs4proc.c */
  120. #ifdef CONFIG_NFS_V4
  121. extern struct rpc_procinfo nfs4_procedures[];
  122. #endif
  123. /* dir.c */
  124. extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
  125. /* inode.c */
  126. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  127. extern void nfs_destroy_inode(struct inode *);
  128. extern int nfs_write_inode(struct inode *,int);
  129. extern void nfs_clear_inode(struct inode *);
  130. #ifdef CONFIG_NFS_V4
  131. extern void nfs4_clear_inode(struct inode *);
  132. #endif
  133. /* super.c */
  134. extern struct file_system_type nfs_xdev_fs_type;
  135. #ifdef CONFIG_NFS_V4
  136. extern struct file_system_type nfs4_xdev_fs_type;
  137. extern struct file_system_type nfs4_referral_fs_type;
  138. #endif
  139. extern struct rpc_stat nfs_rpcstat;
  140. extern int __init register_nfs_fs(void);
  141. extern void __exit unregister_nfs_fs(void);
  142. extern void nfs_sb_active(struct nfs_server *server);
  143. extern void nfs_sb_deactive(struct nfs_server *server);
  144. /* namespace.c */
  145. extern char *nfs_path(const char *base,
  146. const struct dentry *droot,
  147. const struct dentry *dentry,
  148. char *buffer, ssize_t buflen);
  149. /* getroot.c */
  150. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
  151. #ifdef CONFIG_NFS_V4
  152. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
  153. extern int nfs4_path_walk(struct nfs_server *server,
  154. struct nfs_fh *mntfh,
  155. const char *path);
  156. #endif
  157. /*
  158. * Determine the device name as a string
  159. */
  160. static inline char *nfs_devname(const struct vfsmount *mnt_parent,
  161. const struct dentry *dentry,
  162. char *buffer, ssize_t buflen)
  163. {
  164. return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
  165. dentry, buffer, buflen);
  166. }
  167. /*
  168. * Determine the actual block size (and log2 thereof)
  169. */
  170. static inline
  171. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  172. {
  173. /* make sure blocksize is a power of two */
  174. if ((bsize & (bsize - 1)) || nrbitsp) {
  175. unsigned char nrbits;
  176. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  177. ;
  178. bsize = 1 << nrbits;
  179. if (nrbitsp)
  180. *nrbitsp = nrbits;
  181. }
  182. return bsize;
  183. }
  184. /*
  185. * Calculate the number of 512byte blocks used.
  186. */
  187. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  188. {
  189. blkcnt_t used = (tsize + 511) >> 9;
  190. return (used > ULONG_MAX) ? ULONG_MAX : used;
  191. }
  192. /*
  193. * Compute and set NFS server blocksize
  194. */
  195. static inline
  196. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  197. {
  198. if (bsize < NFS_MIN_FILE_IO_SIZE)
  199. bsize = NFS_DEF_FILE_IO_SIZE;
  200. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  201. bsize = NFS_MAX_FILE_IO_SIZE;
  202. return nfs_block_bits(bsize, nrbitsp);
  203. }
  204. /*
  205. * Determine the maximum file size for a superblock
  206. */
  207. static inline
  208. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  209. {
  210. sb->s_maxbytes = (loff_t)maxfilesize;
  211. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  212. sb->s_maxbytes = MAX_LFS_FILESIZE;
  213. }
  214. /*
  215. * Determine the number of bytes of data the page contains
  216. */
  217. static inline
  218. unsigned int nfs_page_length(struct page *page)
  219. {
  220. loff_t i_size = i_size_read(page->mapping->host);
  221. if (i_size > 0) {
  222. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  223. if (page->index < end_index)
  224. return PAGE_CACHE_SIZE;
  225. if (page->index == end_index)
  226. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  227. }
  228. return 0;
  229. }
  230. /*
  231. * Determine the number of pages in an array of length 'len' and
  232. * with a base offset of 'base'
  233. */
  234. static inline
  235. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  236. {
  237. return ((unsigned long)len + (unsigned long)base +
  238. PAGE_SIZE - 1) >> PAGE_SHIFT;
  239. }