internal.h 9.6 KB

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