internal.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
  36. {
  37. if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
  38. fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
  39. }
  40. static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
  41. {
  42. if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
  43. (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
  44. ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
  45. return 0;
  46. fattr->fileid = fattr->mounted_on_fileid;
  47. return 1;
  48. }
  49. struct nfs_clone_mount {
  50. const struct super_block *sb;
  51. const struct dentry *dentry;
  52. struct nfs_fh *fh;
  53. struct nfs_fattr *fattr;
  54. char *hostname;
  55. char *mnt_path;
  56. struct sockaddr *addr;
  57. size_t addrlen;
  58. rpc_authflavor_t authflavor;
  59. };
  60. /*
  61. * Note: RFC 1813 doesn't limit the number of auth flavors that
  62. * a server can return, so make something up.
  63. */
  64. #define NFS_MAX_SECFLAVORS (12)
  65. /*
  66. * Value used if the user did not specify a port value.
  67. */
  68. #define NFS_UNSPEC_PORT (-1)
  69. /*
  70. * Maximum number of pages that readdir can use for creating
  71. * a vmapped array of pages.
  72. */
  73. #define NFS_MAX_READDIR_PAGES 8
  74. /*
  75. * In-kernel mount arguments
  76. */
  77. struct nfs_parsed_mount_data {
  78. int flags;
  79. int rsize, wsize;
  80. int timeo, retrans;
  81. int acregmin, acregmax,
  82. acdirmin, acdirmax;
  83. int namlen;
  84. unsigned int options;
  85. unsigned int bsize;
  86. unsigned int auth_flavor_len;
  87. rpc_authflavor_t auth_flavors[1];
  88. char *client_address;
  89. unsigned int version;
  90. unsigned int minorversion;
  91. char *fscache_uniq;
  92. struct {
  93. struct sockaddr_storage address;
  94. size_t addrlen;
  95. char *hostname;
  96. u32 version;
  97. int port;
  98. unsigned short protocol;
  99. } mount_server;
  100. struct {
  101. struct sockaddr_storage address;
  102. size_t addrlen;
  103. char *hostname;
  104. char *export_path;
  105. int port;
  106. unsigned short protocol;
  107. } nfs_server;
  108. struct security_mnt_opts lsm_opts;
  109. struct net *net;
  110. };
  111. /* mount_clnt.c */
  112. struct nfs_mount_request {
  113. struct sockaddr *sap;
  114. size_t salen;
  115. char *hostname;
  116. char *dirpath;
  117. u32 version;
  118. unsigned short protocol;
  119. struct nfs_fh *fh;
  120. int noresvport;
  121. unsigned int *auth_flav_len;
  122. rpc_authflavor_t *auth_flavs;
  123. struct net *net;
  124. };
  125. extern int nfs_mount(struct nfs_mount_request *info);
  126. extern void nfs_umount(const struct nfs_mount_request *info);
  127. /* client.c */
  128. extern const struct rpc_program nfs_program;
  129. extern void nfs_clients_init(struct net *net);
  130. extern void nfs_cleanup_cb_ident_idr(struct net *);
  131. extern void nfs_put_client(struct nfs_client *);
  132. extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
  133. extern struct nfs_client *
  134. nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
  135. struct nfs4_sessionid *);
  136. extern struct nfs_server *nfs_create_server(
  137. const struct nfs_parsed_mount_data *,
  138. struct nfs_fh *);
  139. extern struct nfs_server *nfs4_create_server(
  140. const struct nfs_parsed_mount_data *,
  141. struct nfs_fh *);
  142. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  143. struct nfs_fh *);
  144. extern void nfs_free_server(struct nfs_server *server);
  145. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  146. struct nfs_fh *,
  147. struct nfs_fattr *,
  148. rpc_authflavor_t);
  149. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  150. extern int nfs4_check_client_ready(struct nfs_client *clp);
  151. extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
  152. const struct sockaddr *ds_addr,
  153. int ds_addrlen, int ds_proto);
  154. #ifdef CONFIG_PROC_FS
  155. extern int __init nfs_fs_proc_init(void);
  156. extern void nfs_fs_proc_exit(void);
  157. #else
  158. static inline int nfs_fs_proc_init(void)
  159. {
  160. return 0;
  161. }
  162. static inline void nfs_fs_proc_exit(void)
  163. {
  164. }
  165. #endif
  166. /* nfs4namespace.c */
  167. #ifdef CONFIG_NFS_V4
  168. extern struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry);
  169. #else
  170. static inline
  171. struct vfsmount *nfs_do_refmount(struct rpc_clnt *client, struct dentry *dentry)
  172. {
  173. return ERR_PTR(-ENOENT);
  174. }
  175. #endif
  176. /* callback_xdr.c */
  177. extern struct svc_version nfs4_callback_version1;
  178. extern struct svc_version nfs4_callback_version4;
  179. /* pagelist.c */
  180. extern int __init nfs_init_nfspagecache(void);
  181. extern void nfs_destroy_nfspagecache(void);
  182. extern int __init nfs_init_readpagecache(void);
  183. extern void nfs_destroy_readpagecache(void);
  184. extern int __init nfs_init_writepagecache(void);
  185. extern void nfs_destroy_writepagecache(void);
  186. extern int __init nfs_init_directcache(void);
  187. extern void nfs_destroy_directcache(void);
  188. /* nfs2xdr.c */
  189. extern int nfs_stat_to_errno(enum nfs_stat);
  190. extern struct rpc_procinfo nfs_procedures[];
  191. extern int nfs2_decode_dirent(struct xdr_stream *,
  192. struct nfs_entry *, int);
  193. /* nfs3xdr.c */
  194. extern struct rpc_procinfo nfs3_procedures[];
  195. extern int nfs3_decode_dirent(struct xdr_stream *,
  196. struct nfs_entry *, int);
  197. /* nfs4xdr.c */
  198. #ifdef CONFIG_NFS_V4
  199. extern int nfs4_decode_dirent(struct xdr_stream *,
  200. struct nfs_entry *, int);
  201. #endif
  202. #ifdef CONFIG_NFS_V4_1
  203. extern const u32 nfs41_maxread_overhead;
  204. extern const u32 nfs41_maxwrite_overhead;
  205. #endif
  206. /* nfs4proc.c */
  207. #ifdef CONFIG_NFS_V4
  208. extern struct rpc_procinfo nfs4_procedures[];
  209. #endif
  210. extern int nfs4_init_ds_session(struct nfs_client *clp);
  211. /* proc.c */
  212. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  213. extern int nfs_init_client(struct nfs_client *clp,
  214. const struct rpc_timeout *timeparms,
  215. const char *ip_addr, rpc_authflavor_t authflavour,
  216. int noresvport);
  217. /* dir.c */
  218. extern int nfs_access_cache_shrinker(struct shrinker *shrink,
  219. struct shrink_control *sc);
  220. /* inode.c */
  221. extern struct workqueue_struct *nfsiod_workqueue;
  222. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  223. extern void nfs_destroy_inode(struct inode *);
  224. extern int nfs_write_inode(struct inode *, struct writeback_control *);
  225. extern void nfs_evict_inode(struct inode *);
  226. #ifdef CONFIG_NFS_V4
  227. extern void nfs4_evict_inode(struct inode *);
  228. #endif
  229. void nfs_zap_acl_cache(struct inode *inode);
  230. extern int nfs_wait_bit_killable(void *word);
  231. /* super.c */
  232. extern struct file_system_type nfs_xdev_fs_type;
  233. #ifdef CONFIG_NFS_V4
  234. extern struct file_system_type nfs4_xdev_fs_type;
  235. extern struct file_system_type nfs4_referral_fs_type;
  236. #endif
  237. extern struct rpc_stat nfs_rpcstat;
  238. extern int __init register_nfs_fs(void);
  239. extern void __exit unregister_nfs_fs(void);
  240. extern void nfs_sb_active(struct super_block *sb);
  241. extern void nfs_sb_deactive(struct super_block *sb);
  242. /* namespace.c */
  243. #define NFS_PATH_CANONICAL 1
  244. extern char *nfs_path(char **p, struct dentry *dentry,
  245. char *buffer, ssize_t buflen, unsigned flags);
  246. extern struct vfsmount *nfs_d_automount(struct path *path);
  247. #ifdef CONFIG_NFS_V4
  248. rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *);
  249. #endif
  250. /* getroot.c */
  251. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  252. const char *);
  253. #ifdef CONFIG_NFS_V4
  254. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  255. const char *);
  256. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
  257. #endif
  258. struct nfs_pageio_descriptor;
  259. /* read.c */
  260. extern int nfs_initiate_read(struct nfs_read_data *data, struct rpc_clnt *clnt,
  261. const struct rpc_call_ops *call_ops);
  262. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  263. extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc,
  264. struct list_head *head);
  265. extern void nfs_pageio_init_read_mds(struct nfs_pageio_descriptor *pgio,
  266. struct inode *inode);
  267. extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
  268. extern void nfs_readdata_release(struct nfs_read_data *rdata);
  269. /* write.c */
  270. extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
  271. struct list_head *head);
  272. extern void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio,
  273. struct inode *inode, int ioflags);
  274. extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
  275. extern void nfs_writedata_release(struct nfs_write_data *wdata);
  276. extern void nfs_commit_free(struct nfs_write_data *p);
  277. extern int nfs_initiate_write(struct nfs_write_data *data,
  278. struct rpc_clnt *clnt,
  279. const struct rpc_call_ops *call_ops,
  280. int how);
  281. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  282. extern int nfs_initiate_commit(struct nfs_write_data *data,
  283. struct rpc_clnt *clnt,
  284. const struct rpc_call_ops *call_ops,
  285. int how);
  286. extern void nfs_init_commit(struct nfs_write_data *data,
  287. struct list_head *head,
  288. struct pnfs_layout_segment *lseg);
  289. void nfs_retry_commit(struct list_head *page_list,
  290. struct pnfs_layout_segment *lseg);
  291. void nfs_commit_clear_lock(struct nfs_inode *nfsi);
  292. void nfs_commitdata_release(void *data);
  293. void nfs_commit_release_pages(struct nfs_write_data *data);
  294. void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *head);
  295. void nfs_request_remove_commit_list(struct nfs_page *req);
  296. #ifdef CONFIG_MIGRATION
  297. extern int nfs_migrate_page(struct address_space *,
  298. struct page *, struct page *, enum migrate_mode);
  299. #else
  300. #define nfs_migrate_page NULL
  301. #endif
  302. /* nfs4proc.c */
  303. extern void __nfs4_read_done_cb(struct nfs_read_data *);
  304. extern void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data);
  305. extern int nfs4_init_client(struct nfs_client *clp,
  306. const struct rpc_timeout *timeparms,
  307. const char *ip_addr,
  308. rpc_authflavor_t authflavour,
  309. int noresvport);
  310. extern void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data);
  311. extern int _nfs4_call_sync(struct rpc_clnt *clnt,
  312. struct nfs_server *server,
  313. struct rpc_message *msg,
  314. struct nfs4_sequence_args *args,
  315. struct nfs4_sequence_res *res,
  316. int cache_reply);
  317. extern int _nfs4_call_sync_session(struct rpc_clnt *clnt,
  318. struct nfs_server *server,
  319. struct rpc_message *msg,
  320. struct nfs4_sequence_args *args,
  321. struct nfs4_sequence_res *res,
  322. int cache_reply);
  323. /*
  324. * Determine the device name as a string
  325. */
  326. static inline char *nfs_devname(struct dentry *dentry,
  327. char *buffer, ssize_t buflen)
  328. {
  329. char *dummy;
  330. return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
  331. }
  332. /*
  333. * Determine the actual block size (and log2 thereof)
  334. */
  335. static inline
  336. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  337. {
  338. /* make sure blocksize is a power of two */
  339. if ((bsize & (bsize - 1)) || nrbitsp) {
  340. unsigned char nrbits;
  341. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  342. ;
  343. bsize = 1 << nrbits;
  344. if (nrbitsp)
  345. *nrbitsp = nrbits;
  346. }
  347. return bsize;
  348. }
  349. /*
  350. * Calculate the number of 512byte blocks used.
  351. */
  352. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  353. {
  354. blkcnt_t used = (tsize + 511) >> 9;
  355. return (used > ULONG_MAX) ? ULONG_MAX : used;
  356. }
  357. /*
  358. * Compute and set NFS server blocksize
  359. */
  360. static inline
  361. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  362. {
  363. if (bsize < NFS_MIN_FILE_IO_SIZE)
  364. bsize = NFS_DEF_FILE_IO_SIZE;
  365. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  366. bsize = NFS_MAX_FILE_IO_SIZE;
  367. return nfs_block_bits(bsize, nrbitsp);
  368. }
  369. /*
  370. * Determine the maximum file size for a superblock
  371. */
  372. static inline
  373. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  374. {
  375. sb->s_maxbytes = (loff_t)maxfilesize;
  376. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  377. sb->s_maxbytes = MAX_LFS_FILESIZE;
  378. }
  379. /*
  380. * Determine the number of bytes of data the page contains
  381. */
  382. static inline
  383. unsigned int nfs_page_length(struct page *page)
  384. {
  385. loff_t i_size = i_size_read(page->mapping->host);
  386. if (i_size > 0) {
  387. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  388. if (page->index < end_index)
  389. return PAGE_CACHE_SIZE;
  390. if (page->index == end_index)
  391. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  392. }
  393. return 0;
  394. }
  395. /*
  396. * Convert a umode to a dirent->d_type
  397. */
  398. static inline
  399. unsigned char nfs_umode_to_dtype(umode_t mode)
  400. {
  401. return (mode >> 12) & 15;
  402. }
  403. /*
  404. * Determine the number of pages in an array of length 'len' and
  405. * with a base offset of 'base'
  406. */
  407. static inline
  408. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  409. {
  410. return ((unsigned long)len + (unsigned long)base +
  411. PAGE_SIZE - 1) >> PAGE_SHIFT;
  412. }