internal.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. int noresvport;
  67. };
  68. extern int nfs_mount(struct nfs_mount_request *info);
  69. /* client.c */
  70. extern struct rpc_program nfs_program;
  71. extern void nfs_put_client(struct nfs_client *);
  72. extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
  73. extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
  74. extern struct nfs_server *nfs_create_server(
  75. const struct nfs_parsed_mount_data *,
  76. struct nfs_fh *);
  77. extern struct nfs_server *nfs4_create_server(
  78. const struct nfs_parsed_mount_data *,
  79. struct nfs_fh *);
  80. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  81. struct nfs_fh *);
  82. extern void nfs_free_server(struct nfs_server *server);
  83. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  84. struct nfs_fh *,
  85. struct nfs_fattr *);
  86. #ifdef CONFIG_PROC_FS
  87. extern int __init nfs_fs_proc_init(void);
  88. extern void nfs_fs_proc_exit(void);
  89. #else
  90. static inline int nfs_fs_proc_init(void)
  91. {
  92. return 0;
  93. }
  94. static inline void nfs_fs_proc_exit(void)
  95. {
  96. }
  97. #endif
  98. /* nfs4namespace.c */
  99. #ifdef CONFIG_NFS_V4
  100. extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
  101. #else
  102. static inline
  103. struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
  104. {
  105. return ERR_PTR(-ENOENT);
  106. }
  107. #endif
  108. /* callback_xdr.c */
  109. extern struct svc_version nfs4_callback_version1;
  110. /* pagelist.c */
  111. extern int __init nfs_init_nfspagecache(void);
  112. extern void nfs_destroy_nfspagecache(void);
  113. extern int __init nfs_init_readpagecache(void);
  114. extern void nfs_destroy_readpagecache(void);
  115. extern int __init nfs_init_writepagecache(void);
  116. extern void nfs_destroy_writepagecache(void);
  117. extern int __init nfs_init_directcache(void);
  118. extern void nfs_destroy_directcache(void);
  119. /* nfs2xdr.c */
  120. extern int nfs_stat_to_errno(int);
  121. extern struct rpc_procinfo nfs_procedures[];
  122. extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
  123. /* nfs3xdr.c */
  124. extern struct rpc_procinfo nfs3_procedures[];
  125. extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
  126. /* nfs4xdr.c */
  127. #ifdef CONFIG_NFS_V4
  128. extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
  129. #endif
  130. /* nfs4proc.c */
  131. #ifdef CONFIG_NFS_V4
  132. extern struct rpc_procinfo nfs4_procedures[];
  133. #endif
  134. /* proc.c */
  135. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  136. /* dir.c */
  137. extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
  138. /* inode.c */
  139. extern struct workqueue_struct *nfsiod_workqueue;
  140. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  141. extern void nfs_destroy_inode(struct inode *);
  142. extern int nfs_write_inode(struct inode *,int);
  143. extern void nfs_clear_inode(struct inode *);
  144. #ifdef CONFIG_NFS_V4
  145. extern void nfs4_clear_inode(struct inode *);
  146. #endif
  147. void nfs_zap_acl_cache(struct inode *inode);
  148. extern int nfs_wait_bit_killable(void *word);
  149. /* super.c */
  150. void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *);
  151. extern struct file_system_type nfs_xdev_fs_type;
  152. #ifdef CONFIG_NFS_V4
  153. extern struct file_system_type nfs4_xdev_fs_type;
  154. extern struct file_system_type nfs4_referral_fs_type;
  155. #endif
  156. extern struct rpc_stat nfs_rpcstat;
  157. extern int __init register_nfs_fs(void);
  158. extern void __exit unregister_nfs_fs(void);
  159. extern void nfs_sb_active(struct super_block *sb);
  160. extern void nfs_sb_deactive(struct super_block *sb);
  161. /* namespace.c */
  162. extern char *nfs_path(const char *base,
  163. const struct dentry *droot,
  164. const struct dentry *dentry,
  165. char *buffer, ssize_t buflen);
  166. /* getroot.c */
  167. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
  168. #ifdef CONFIG_NFS_V4
  169. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
  170. extern int nfs4_path_walk(struct nfs_server *server,
  171. struct nfs_fh *mntfh,
  172. const char *path);
  173. #endif
  174. /*
  175. * Determine the device name as a string
  176. */
  177. static inline char *nfs_devname(const struct vfsmount *mnt_parent,
  178. const struct dentry *dentry,
  179. char *buffer, ssize_t buflen)
  180. {
  181. return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
  182. dentry, buffer, buflen);
  183. }
  184. /*
  185. * Determine the actual block size (and log2 thereof)
  186. */
  187. static inline
  188. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  189. {
  190. /* make sure blocksize is a power of two */
  191. if ((bsize & (bsize - 1)) || nrbitsp) {
  192. unsigned char nrbits;
  193. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  194. ;
  195. bsize = 1 << nrbits;
  196. if (nrbitsp)
  197. *nrbitsp = nrbits;
  198. }
  199. return bsize;
  200. }
  201. /*
  202. * Calculate the number of 512byte blocks used.
  203. */
  204. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  205. {
  206. blkcnt_t used = (tsize + 511) >> 9;
  207. return (used > ULONG_MAX) ? ULONG_MAX : used;
  208. }
  209. /*
  210. * Compute and set NFS server blocksize
  211. */
  212. static inline
  213. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  214. {
  215. if (bsize < NFS_MIN_FILE_IO_SIZE)
  216. bsize = NFS_DEF_FILE_IO_SIZE;
  217. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  218. bsize = NFS_MAX_FILE_IO_SIZE;
  219. return nfs_block_bits(bsize, nrbitsp);
  220. }
  221. /*
  222. * Determine the maximum file size for a superblock
  223. */
  224. static inline
  225. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  226. {
  227. sb->s_maxbytes = (loff_t)maxfilesize;
  228. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  229. sb->s_maxbytes = MAX_LFS_FILESIZE;
  230. }
  231. /*
  232. * Determine the number of bytes of data the page contains
  233. */
  234. static inline
  235. unsigned int nfs_page_length(struct page *page)
  236. {
  237. loff_t i_size = i_size_read(page->mapping->host);
  238. if (i_size > 0) {
  239. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  240. if (page->index < end_index)
  241. return PAGE_CACHE_SIZE;
  242. if (page->index == end_index)
  243. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  244. }
  245. return 0;
  246. }
  247. /*
  248. * Determine the number of pages in an array of length 'len' and
  249. * with a base offset of 'base'
  250. */
  251. static inline
  252. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  253. {
  254. return ((unsigned long)len + (unsigned long)base +
  255. PAGE_SIZE - 1) >> PAGE_SHIFT;
  256. }
  257. #define IPV6_SCOPE_DELIMITER '%'
  258. /*
  259. * Set the port number in an address. Be agnostic about the address
  260. * family.
  261. */
  262. static inline void nfs_set_port(struct sockaddr *sap, unsigned short port)
  263. {
  264. struct sockaddr_in *ap = (struct sockaddr_in *)sap;
  265. struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap;
  266. switch (sap->sa_family) {
  267. case AF_INET:
  268. ap->sin_port = htons(port);
  269. break;
  270. case AF_INET6:
  271. ap6->sin6_port = htons(port);
  272. break;
  273. }
  274. }