internal.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*
  2. * NFS internal definitions
  3. */
  4. #include "nfs4_fs.h"
  5. #include <linux/mount.h>
  6. #include <linux/security.h>
  7. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  8. struct nfs_string;
  9. /* Maximum number of readahead requests
  10. * FIXME: this should really be a sysctl so that users may tune it to suit
  11. * their needs. People that do NFS over a slow network, might for
  12. * instance want to reduce it to something closer to 1 for improved
  13. * interactive response.
  14. */
  15. #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
  16. /*
  17. * Determine if sessions are in use.
  18. */
  19. static inline int nfs4_has_session(const struct nfs_client *clp)
  20. {
  21. #ifdef CONFIG_NFS_V4_1
  22. if (clp->cl_session)
  23. return 1;
  24. #endif /* CONFIG_NFS_V4_1 */
  25. return 0;
  26. }
  27. struct nfs_clone_mount {
  28. const struct super_block *sb;
  29. const struct dentry *dentry;
  30. struct nfs_fh *fh;
  31. struct nfs_fattr *fattr;
  32. char *hostname;
  33. char *mnt_path;
  34. struct sockaddr *addr;
  35. size_t addrlen;
  36. rpc_authflavor_t authflavor;
  37. };
  38. /*
  39. * Note: RFC 1813 doesn't limit the number of auth flavors that
  40. * a server can return, so make something up.
  41. */
  42. #define NFS_MAX_SECFLAVORS (12)
  43. /*
  44. * Value used if the user did not specify a port value.
  45. */
  46. #define NFS_UNSPEC_PORT (-1)
  47. /*
  48. * In-kernel mount arguments
  49. */
  50. struct nfs_parsed_mount_data {
  51. int flags;
  52. int rsize, wsize;
  53. int timeo, retrans;
  54. int acregmin, acregmax,
  55. acdirmin, acdirmax;
  56. int namlen;
  57. unsigned int options;
  58. unsigned int bsize;
  59. unsigned int auth_flavor_len;
  60. rpc_authflavor_t auth_flavors[1];
  61. char *client_address;
  62. unsigned int version;
  63. unsigned int minorversion;
  64. char *fscache_uniq;
  65. struct {
  66. struct sockaddr_storage address;
  67. size_t addrlen;
  68. char *hostname;
  69. u32 version;
  70. int port;
  71. unsigned short protocol;
  72. } mount_server;
  73. struct {
  74. struct sockaddr_storage address;
  75. size_t addrlen;
  76. char *hostname;
  77. char *export_path;
  78. int port;
  79. unsigned short protocol;
  80. } nfs_server;
  81. struct security_mnt_opts lsm_opts;
  82. };
  83. /* mount_clnt.c */
  84. struct nfs_mount_request {
  85. struct sockaddr *sap;
  86. size_t salen;
  87. char *hostname;
  88. char *dirpath;
  89. u32 version;
  90. unsigned short protocol;
  91. struct nfs_fh *fh;
  92. int noresvport;
  93. unsigned int *auth_flav_len;
  94. rpc_authflavor_t *auth_flavs;
  95. };
  96. extern int nfs_mount(struct nfs_mount_request *info);
  97. extern void nfs_umount(const struct nfs_mount_request *info);
  98. /* client.c */
  99. extern struct rpc_program nfs_program;
  100. extern void nfs_put_client(struct nfs_client *);
  101. extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
  102. extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
  103. extern struct nfs_server *nfs_create_server(
  104. const struct nfs_parsed_mount_data *,
  105. struct nfs_fh *);
  106. extern struct nfs_server *nfs4_create_server(
  107. const struct nfs_parsed_mount_data *,
  108. struct nfs_fh *);
  109. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  110. struct nfs_fh *);
  111. extern void nfs_free_server(struct nfs_server *server);
  112. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  113. struct nfs_fh *,
  114. struct nfs_fattr *);
  115. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  116. extern int nfs4_check_client_ready(struct nfs_client *clp);
  117. #ifdef CONFIG_PROC_FS
  118. extern int __init nfs_fs_proc_init(void);
  119. extern void nfs_fs_proc_exit(void);
  120. #else
  121. static inline int nfs_fs_proc_init(void)
  122. {
  123. return 0;
  124. }
  125. static inline void nfs_fs_proc_exit(void)
  126. {
  127. }
  128. #endif
  129. /* nfs4namespace.c */
  130. #ifdef CONFIG_NFS_V4
  131. extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
  132. #else
  133. static inline
  134. struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
  135. {
  136. return ERR_PTR(-ENOENT);
  137. }
  138. #endif
  139. /* callback_xdr.c */
  140. extern struct svc_version nfs4_callback_version1;
  141. /* pagelist.c */
  142. extern int __init nfs_init_nfspagecache(void);
  143. extern void nfs_destroy_nfspagecache(void);
  144. extern int __init nfs_init_readpagecache(void);
  145. extern void nfs_destroy_readpagecache(void);
  146. extern int __init nfs_init_writepagecache(void);
  147. extern void nfs_destroy_writepagecache(void);
  148. extern int __init nfs_init_directcache(void);
  149. extern void nfs_destroy_directcache(void);
  150. /* nfs2xdr.c */
  151. extern int nfs_stat_to_errno(int);
  152. extern struct rpc_procinfo nfs_procedures[];
  153. extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
  154. /* nfs3xdr.c */
  155. extern struct rpc_procinfo nfs3_procedures[];
  156. extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
  157. /* nfs4proc.c */
  158. static inline void nfs4_restart_rpc(struct rpc_task *task,
  159. const struct nfs_client *clp)
  160. {
  161. #ifdef CONFIG_NFS_V4_1
  162. if (nfs4_has_session(clp) &&
  163. test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) {
  164. rpc_restart_call_prepare(task);
  165. return;
  166. }
  167. #endif /* CONFIG_NFS_V4_1 */
  168. rpc_restart_call(task);
  169. }
  170. /* nfs4xdr.c */
  171. #ifdef CONFIG_NFS_V4
  172. extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
  173. #endif
  174. /* nfs4proc.c */
  175. #ifdef CONFIG_NFS_V4
  176. extern struct rpc_procinfo nfs4_procedures[];
  177. #endif
  178. /* proc.c */
  179. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  180. /* dir.c */
  181. extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
  182. /* inode.c */
  183. extern struct workqueue_struct *nfsiod_workqueue;
  184. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  185. extern void nfs_destroy_inode(struct inode *);
  186. extern int nfs_write_inode(struct inode *,int);
  187. extern void nfs_clear_inode(struct inode *);
  188. #ifdef CONFIG_NFS_V4
  189. extern void nfs4_clear_inode(struct inode *);
  190. #endif
  191. void nfs_zap_acl_cache(struct inode *inode);
  192. extern int nfs_wait_bit_killable(void *word);
  193. /* super.c */
  194. extern struct file_system_type nfs_xdev_fs_type;
  195. #ifdef CONFIG_NFS_V4
  196. extern struct file_system_type nfs4_xdev_fs_type;
  197. extern struct file_system_type nfs4_referral_fs_type;
  198. #endif
  199. extern struct rpc_stat nfs_rpcstat;
  200. extern int __init register_nfs_fs(void);
  201. extern void __exit unregister_nfs_fs(void);
  202. extern void nfs_sb_active(struct super_block *sb);
  203. extern void nfs_sb_deactive(struct super_block *sb);
  204. /* namespace.c */
  205. extern char *nfs_path(const char *base,
  206. const struct dentry *droot,
  207. const struct dentry *dentry,
  208. char *buffer, ssize_t buflen);
  209. /* getroot.c */
  210. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
  211. #ifdef CONFIG_NFS_V4
  212. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
  213. extern int nfs4_path_walk(struct nfs_server *server,
  214. struct nfs_fh *mntfh,
  215. const char *path);
  216. #endif
  217. /* read.c */
  218. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  219. /* write.c */
  220. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  221. #ifdef CONFIG_MIGRATION
  222. extern int nfs_migrate_page(struct address_space *,
  223. struct page *, struct page *);
  224. #else
  225. #define nfs_migrate_page NULL
  226. #endif
  227. /* nfs4proc.c */
  228. extern int _nfs4_call_sync(struct nfs_server *server,
  229. struct rpc_message *msg,
  230. struct nfs4_sequence_args *args,
  231. struct nfs4_sequence_res *res,
  232. int cache_reply);
  233. extern int _nfs4_call_sync_session(struct nfs_server *server,
  234. struct rpc_message *msg,
  235. struct nfs4_sequence_args *args,
  236. struct nfs4_sequence_res *res,
  237. int cache_reply);
  238. #ifdef CONFIG_NFS_V4_1
  239. extern void nfs41_sequence_free_slot(const struct nfs_client *,
  240. struct nfs4_sequence_res *res);
  241. #endif /* CONFIG_NFS_V4_1 */
  242. static inline void nfs4_sequence_free_slot(const struct nfs_client *clp,
  243. struct nfs4_sequence_res *res)
  244. {
  245. #ifdef CONFIG_NFS_V4_1
  246. if (nfs4_has_session(clp))
  247. nfs41_sequence_free_slot(clp, res);
  248. #endif /* CONFIG_NFS_V4_1 */
  249. }
  250. /*
  251. * Determine the device name as a string
  252. */
  253. static inline char *nfs_devname(const struct vfsmount *mnt_parent,
  254. const struct dentry *dentry,
  255. char *buffer, ssize_t buflen)
  256. {
  257. return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
  258. dentry, buffer, buflen);
  259. }
  260. /*
  261. * Determine the actual block size (and log2 thereof)
  262. */
  263. static inline
  264. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  265. {
  266. /* make sure blocksize is a power of two */
  267. if ((bsize & (bsize - 1)) || nrbitsp) {
  268. unsigned char nrbits;
  269. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  270. ;
  271. bsize = 1 << nrbits;
  272. if (nrbitsp)
  273. *nrbitsp = nrbits;
  274. }
  275. return bsize;
  276. }
  277. /*
  278. * Calculate the number of 512byte blocks used.
  279. */
  280. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  281. {
  282. blkcnt_t used = (tsize + 511) >> 9;
  283. return (used > ULONG_MAX) ? ULONG_MAX : used;
  284. }
  285. /*
  286. * Compute and set NFS server blocksize
  287. */
  288. static inline
  289. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  290. {
  291. if (bsize < NFS_MIN_FILE_IO_SIZE)
  292. bsize = NFS_DEF_FILE_IO_SIZE;
  293. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  294. bsize = NFS_MAX_FILE_IO_SIZE;
  295. return nfs_block_bits(bsize, nrbitsp);
  296. }
  297. /*
  298. * Determine the maximum file size for a superblock
  299. */
  300. static inline
  301. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  302. {
  303. sb->s_maxbytes = (loff_t)maxfilesize;
  304. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  305. sb->s_maxbytes = MAX_LFS_FILESIZE;
  306. }
  307. /*
  308. * Determine the number of bytes of data the page contains
  309. */
  310. static inline
  311. unsigned int nfs_page_length(struct page *page)
  312. {
  313. loff_t i_size = i_size_read(page->mapping->host);
  314. if (i_size > 0) {
  315. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  316. if (page->index < end_index)
  317. return PAGE_CACHE_SIZE;
  318. if (page->index == end_index)
  319. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  320. }
  321. return 0;
  322. }
  323. /*
  324. * Determine the number of pages in an array of length 'len' and
  325. * with a base offset of 'base'
  326. */
  327. static inline
  328. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  329. {
  330. return ((unsigned long)len + (unsigned long)base +
  331. PAGE_SIZE - 1) >> PAGE_SHIFT;
  332. }