internal.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. struct nfs_pageio_descriptor;
  180. /* pagelist.c */
  181. extern int __init nfs_init_nfspagecache(void);
  182. extern void nfs_destroy_nfspagecache(void);
  183. extern int __init nfs_init_readpagecache(void);
  184. extern void nfs_destroy_readpagecache(void);
  185. extern int __init nfs_init_writepagecache(void);
  186. extern void nfs_destroy_writepagecache(void);
  187. extern int __init nfs_init_directcache(void);
  188. extern void nfs_destroy_directcache(void);
  189. extern bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount);
  190. extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
  191. struct nfs_pgio_header *hdr,
  192. void (*release)(struct nfs_pgio_header *hdr));
  193. void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
  194. /* nfs2xdr.c */
  195. extern int nfs_stat_to_errno(enum nfs_stat);
  196. extern struct rpc_procinfo nfs_procedures[];
  197. extern int nfs2_decode_dirent(struct xdr_stream *,
  198. struct nfs_entry *, int);
  199. /* nfs3xdr.c */
  200. extern struct rpc_procinfo nfs3_procedures[];
  201. extern int nfs3_decode_dirent(struct xdr_stream *,
  202. struct nfs_entry *, int);
  203. /* nfs4xdr.c */
  204. #ifdef CONFIG_NFS_V4
  205. extern int nfs4_decode_dirent(struct xdr_stream *,
  206. struct nfs_entry *, int);
  207. #endif
  208. #ifdef CONFIG_NFS_V4_1
  209. extern const u32 nfs41_maxread_overhead;
  210. extern const u32 nfs41_maxwrite_overhead;
  211. #endif
  212. /* nfs4proc.c */
  213. #ifdef CONFIG_NFS_V4
  214. extern struct rpc_procinfo nfs4_procedures[];
  215. #endif
  216. extern int nfs4_init_ds_session(struct nfs_client *clp);
  217. /* proc.c */
  218. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  219. extern int nfs_init_client(struct nfs_client *clp,
  220. const struct rpc_timeout *timeparms,
  221. const char *ip_addr, rpc_authflavor_t authflavour,
  222. int noresvport);
  223. /* dir.c */
  224. extern int nfs_access_cache_shrinker(struct shrinker *shrink,
  225. struct shrink_control *sc);
  226. /* inode.c */
  227. extern struct workqueue_struct *nfsiod_workqueue;
  228. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  229. extern void nfs_destroy_inode(struct inode *);
  230. extern int nfs_write_inode(struct inode *, struct writeback_control *);
  231. extern void nfs_evict_inode(struct inode *);
  232. #ifdef CONFIG_NFS_V4
  233. extern void nfs4_evict_inode(struct inode *);
  234. #endif
  235. void nfs_zap_acl_cache(struct inode *inode);
  236. extern int nfs_wait_bit_killable(void *word);
  237. /* super.c */
  238. extern struct file_system_type nfs_xdev_fs_type;
  239. #ifdef CONFIG_NFS_V4
  240. extern struct file_system_type nfs4_xdev_fs_type;
  241. extern struct file_system_type nfs4_referral_fs_type;
  242. #endif
  243. extern struct rpc_stat nfs_rpcstat;
  244. extern int __init register_nfs_fs(void);
  245. extern void __exit unregister_nfs_fs(void);
  246. extern void nfs_sb_active(struct super_block *sb);
  247. extern void nfs_sb_deactive(struct super_block *sb);
  248. /* namespace.c */
  249. extern char *nfs_path(char **p, struct dentry *dentry,
  250. char *buffer, ssize_t buflen);
  251. extern struct vfsmount *nfs_d_automount(struct path *path);
  252. /* getroot.c */
  253. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  254. const char *);
  255. #ifdef CONFIG_NFS_V4
  256. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  257. const char *);
  258. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
  259. #endif
  260. struct nfs_pgio_completion_ops;
  261. /* read.c */
  262. extern struct nfs_read_header *nfs_readhdr_alloc(void);
  263. extern void nfs_readhdr_free(struct nfs_pgio_header *hdr);
  264. extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
  265. struct inode *inode,
  266. const struct nfs_pgio_completion_ops *compl_ops);
  267. extern int nfs_initiate_read(struct rpc_clnt *clnt,
  268. struct nfs_read_data *data,
  269. const struct rpc_call_ops *call_ops);
  270. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  271. extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc,
  272. struct nfs_pgio_header *hdr);
  273. extern void nfs_pageio_init_read_mds(struct nfs_pageio_descriptor *pgio,
  274. struct inode *inode,
  275. const struct nfs_pgio_completion_ops *compl_ops);
  276. extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
  277. extern void nfs_readdata_release(struct nfs_read_data *rdata);
  278. /* write.c */
  279. extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
  280. struct inode *inode, int ioflags,
  281. const struct nfs_pgio_completion_ops *compl_ops);
  282. extern struct nfs_write_header *nfs_writehdr_alloc(void);
  283. extern void nfs_writehdr_free(struct nfs_pgio_header *hdr);
  284. extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
  285. struct nfs_pgio_header *hdr);
  286. extern void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio,
  287. struct inode *inode, int ioflags,
  288. const struct nfs_pgio_completion_ops *compl_ops);
  289. extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
  290. extern void nfs_writedata_release(struct nfs_write_data *wdata);
  291. extern void nfs_commit_free(struct nfs_commit_data *p);
  292. extern int nfs_initiate_write(struct rpc_clnt *clnt,
  293. struct nfs_write_data *data,
  294. const struct rpc_call_ops *call_ops,
  295. int how);
  296. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  297. extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
  298. extern int nfs_initiate_commit(struct rpc_clnt *clnt,
  299. struct nfs_commit_data *data,
  300. const struct rpc_call_ops *call_ops,
  301. int how);
  302. extern void nfs_init_commit(struct nfs_commit_data *data,
  303. struct list_head *head,
  304. struct pnfs_layout_segment *lseg,
  305. struct nfs_commit_info *cinfo);
  306. int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
  307. struct nfs_commit_info *cinfo, int max);
  308. int nfs_scan_commit(struct inode *inode, struct list_head *dst,
  309. struct nfs_commit_info *cinfo);
  310. void nfs_mark_request_commit(struct nfs_page *req,
  311. struct pnfs_layout_segment *lseg,
  312. struct nfs_commit_info *cinfo);
  313. int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
  314. int how, struct nfs_commit_info *cinfo);
  315. void nfs_retry_commit(struct list_head *page_list,
  316. struct pnfs_layout_segment *lseg,
  317. struct nfs_commit_info *cinfo);
  318. void nfs_commitdata_release(struct nfs_commit_data *data);
  319. void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
  320. struct nfs_commit_info *cinfo);
  321. void nfs_request_remove_commit_list(struct nfs_page *req,
  322. struct nfs_commit_info *cinfo);
  323. void nfs_init_cinfo(struct nfs_commit_info *cinfo,
  324. struct inode *inode,
  325. struct nfs_direct_req *dreq);
  326. #ifdef CONFIG_MIGRATION
  327. extern int nfs_migrate_page(struct address_space *,
  328. struct page *, struct page *, enum migrate_mode);
  329. #else
  330. #define nfs_migrate_page NULL
  331. #endif
  332. /* direct.c */
  333. void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
  334. struct nfs_direct_req *dreq);
  335. /* nfs4proc.c */
  336. extern void __nfs4_read_done_cb(struct nfs_read_data *);
  337. extern void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data);
  338. extern int nfs4_init_client(struct nfs_client *clp,
  339. const struct rpc_timeout *timeparms,
  340. const char *ip_addr,
  341. rpc_authflavor_t authflavour,
  342. int noresvport);
  343. extern void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data);
  344. extern int _nfs4_call_sync(struct rpc_clnt *clnt,
  345. struct nfs_server *server,
  346. struct rpc_message *msg,
  347. struct nfs4_sequence_args *args,
  348. struct nfs4_sequence_res *res,
  349. int cache_reply);
  350. extern int _nfs4_call_sync_session(struct rpc_clnt *clnt,
  351. struct nfs_server *server,
  352. struct rpc_message *msg,
  353. struct nfs4_sequence_args *args,
  354. struct nfs4_sequence_res *res,
  355. int cache_reply);
  356. /*
  357. * Determine the device name as a string
  358. */
  359. static inline char *nfs_devname(struct dentry *dentry,
  360. char *buffer, ssize_t buflen)
  361. {
  362. char *dummy;
  363. return nfs_path(&dummy, dentry, buffer, buflen);
  364. }
  365. /*
  366. * Determine the actual block size (and log2 thereof)
  367. */
  368. static inline
  369. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  370. {
  371. /* make sure blocksize is a power of two */
  372. if ((bsize & (bsize - 1)) || nrbitsp) {
  373. unsigned char nrbits;
  374. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  375. ;
  376. bsize = 1 << nrbits;
  377. if (nrbitsp)
  378. *nrbitsp = nrbits;
  379. }
  380. return bsize;
  381. }
  382. /*
  383. * Calculate the number of 512byte blocks used.
  384. */
  385. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  386. {
  387. blkcnt_t used = (tsize + 511) >> 9;
  388. return (used > ULONG_MAX) ? ULONG_MAX : used;
  389. }
  390. /*
  391. * Compute and set NFS server blocksize
  392. */
  393. static inline
  394. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  395. {
  396. if (bsize < NFS_MIN_FILE_IO_SIZE)
  397. bsize = NFS_DEF_FILE_IO_SIZE;
  398. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  399. bsize = NFS_MAX_FILE_IO_SIZE;
  400. return nfs_block_bits(bsize, nrbitsp);
  401. }
  402. /*
  403. * Determine the maximum file size for a superblock
  404. */
  405. static inline
  406. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  407. {
  408. sb->s_maxbytes = (loff_t)maxfilesize;
  409. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  410. sb->s_maxbytes = MAX_LFS_FILESIZE;
  411. }
  412. /*
  413. * Determine the number of bytes of data the page contains
  414. */
  415. static inline
  416. unsigned int nfs_page_length(struct page *page)
  417. {
  418. loff_t i_size = i_size_read(page->mapping->host);
  419. if (i_size > 0) {
  420. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  421. if (page->index < end_index)
  422. return PAGE_CACHE_SIZE;
  423. if (page->index == end_index)
  424. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  425. }
  426. return 0;
  427. }
  428. /*
  429. * Convert a umode to a dirent->d_type
  430. */
  431. static inline
  432. unsigned char nfs_umode_to_dtype(umode_t mode)
  433. {
  434. return (mode >> 12) & 15;
  435. }
  436. /*
  437. * Determine the number of pages in an array of length 'len' and
  438. * with a base offset of 'base'
  439. */
  440. static inline
  441. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  442. {
  443. return ((unsigned long)len + (unsigned long)base +
  444. PAGE_SIZE - 1) >> PAGE_SHIFT;
  445. }