internal.h 7.8 KB

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