internal.h 8.3 KB

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