internal.h 8.0 KB

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