internal.h 6.1 KB

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