internal.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. bool need_mount;
  93. struct {
  94. struct sockaddr_storage address;
  95. size_t addrlen;
  96. char *hostname;
  97. u32 version;
  98. int port;
  99. unsigned short protocol;
  100. } mount_server;
  101. struct {
  102. struct sockaddr_storage address;
  103. size_t addrlen;
  104. char *hostname;
  105. char *export_path;
  106. int port;
  107. unsigned short protocol;
  108. } nfs_server;
  109. struct security_mnt_opts lsm_opts;
  110. struct net *net;
  111. };
  112. /* mount_clnt.c */
  113. struct nfs_mount_request {
  114. struct sockaddr *sap;
  115. size_t salen;
  116. char *hostname;
  117. char *dirpath;
  118. u32 version;
  119. unsigned short protocol;
  120. struct nfs_fh *fh;
  121. int noresvport;
  122. unsigned int *auth_flav_len;
  123. rpc_authflavor_t *auth_flavs;
  124. struct net *net;
  125. };
  126. extern int nfs_mount(struct nfs_mount_request *info);
  127. extern void nfs_umount(const struct nfs_mount_request *info);
  128. /* client.c */
  129. extern const struct rpc_program nfs_program;
  130. extern void nfs_clients_init(struct net *net);
  131. extern void nfs_cleanup_cb_ident_idr(struct net *);
  132. extern void nfs_put_client(struct nfs_client *);
  133. extern void nfs_free_client(struct nfs_client *);
  134. extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
  135. extern struct nfs_client *
  136. nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
  137. struct nfs4_sessionid *);
  138. extern struct nfs_server *nfs_create_server(
  139. const struct nfs_parsed_mount_data *,
  140. struct nfs_fh *);
  141. extern struct nfs_server *nfs4_create_server(
  142. const struct nfs_parsed_mount_data *,
  143. struct nfs_fh *);
  144. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  145. struct nfs_fh *);
  146. extern void nfs_free_server(struct nfs_server *server);
  147. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  148. struct nfs_fh *,
  149. struct nfs_fattr *,
  150. rpc_authflavor_t);
  151. extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
  152. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  153. extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
  154. const struct sockaddr *ds_addr,
  155. int ds_addrlen, int ds_proto,
  156. unsigned int ds_timeo,
  157. unsigned int ds_retrans);
  158. #ifdef CONFIG_PROC_FS
  159. extern int __init nfs_fs_proc_init(void);
  160. extern void nfs_fs_proc_exit(void);
  161. #else
  162. static inline int nfs_fs_proc_init(void)
  163. {
  164. return 0;
  165. }
  166. static inline void nfs_fs_proc_exit(void)
  167. {
  168. }
  169. #endif
  170. /* callback_xdr.c */
  171. extern struct svc_version nfs4_callback_version1;
  172. extern struct svc_version nfs4_callback_version4;
  173. struct nfs_pageio_descriptor;
  174. /* pagelist.c */
  175. extern int __init nfs_init_nfspagecache(void);
  176. extern void nfs_destroy_nfspagecache(void);
  177. extern int __init nfs_init_readpagecache(void);
  178. extern void nfs_destroy_readpagecache(void);
  179. extern int __init nfs_init_writepagecache(void);
  180. extern void nfs_destroy_writepagecache(void);
  181. extern int __init nfs_init_directcache(void);
  182. extern void nfs_destroy_directcache(void);
  183. extern bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount);
  184. extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
  185. struct nfs_pgio_header *hdr,
  186. void (*release)(struct nfs_pgio_header *hdr));
  187. void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
  188. /* nfs2xdr.c */
  189. extern struct rpc_procinfo nfs_procedures[];
  190. extern int nfs2_decode_dirent(struct xdr_stream *,
  191. struct nfs_entry *, int);
  192. /* nfs3xdr.c */
  193. extern struct rpc_procinfo nfs3_procedures[];
  194. extern int nfs3_decode_dirent(struct xdr_stream *,
  195. struct nfs_entry *, int);
  196. /* nfs4xdr.c */
  197. #ifdef CONFIG_NFS_V4
  198. extern int nfs4_decode_dirent(struct xdr_stream *,
  199. struct nfs_entry *, int);
  200. #endif
  201. #ifdef CONFIG_NFS_V4_1
  202. extern const u32 nfs41_maxread_overhead;
  203. extern const u32 nfs41_maxwrite_overhead;
  204. #endif
  205. /* nfs4proc.c */
  206. #ifdef CONFIG_NFS_V4
  207. extern struct rpc_procinfo nfs4_procedures[];
  208. #endif
  209. extern int nfs4_init_ds_session(struct nfs_client *, unsigned long);
  210. /* proc.c */
  211. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  212. extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
  213. const struct rpc_timeout *timeparms,
  214. const char *ip_addr, rpc_authflavor_t authflavour);
  215. /* dir.c */
  216. extern int nfs_access_cache_shrinker(struct shrinker *shrink,
  217. struct shrink_control *sc);
  218. /* inode.c */
  219. extern struct workqueue_struct *nfsiod_workqueue;
  220. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  221. extern void nfs_destroy_inode(struct inode *);
  222. extern int nfs_write_inode(struct inode *, struct writeback_control *);
  223. extern void nfs_evict_inode(struct inode *);
  224. #ifdef CONFIG_NFS_V4
  225. extern void nfs4_evict_inode(struct inode *);
  226. #endif
  227. void nfs_zap_acl_cache(struct inode *inode);
  228. extern int nfs_wait_bit_killable(void *word);
  229. /* super.c */
  230. extern struct file_system_type nfs_xdev_fs_type;
  231. #ifdef CONFIG_NFS_V4
  232. extern struct file_system_type nfs4_xdev_fs_type;
  233. extern struct file_system_type nfs4_referral_fs_type;
  234. #endif
  235. extern struct rpc_stat nfs_rpcstat;
  236. extern int __init register_nfs_fs(void);
  237. extern void __exit unregister_nfs_fs(void);
  238. extern void nfs_sb_active(struct super_block *sb);
  239. extern void nfs_sb_deactive(struct super_block *sb);
  240. /* namespace.c */
  241. extern char *nfs_path(char **p, struct dentry *dentry,
  242. char *buffer, ssize_t buflen);
  243. extern struct vfsmount *nfs_d_automount(struct path *path);
  244. struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
  245. struct nfs_fh *, struct nfs_fattr *);
  246. struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
  247. struct nfs_fattr *, rpc_authflavor_t);
  248. /* getroot.c */
  249. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  250. const char *);
  251. #ifdef CONFIG_NFS_V4
  252. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  253. const char *);
  254. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
  255. #endif
  256. struct nfs_pgio_completion_ops;
  257. /* read.c */
  258. extern struct nfs_read_header *nfs_readhdr_alloc(void);
  259. extern void nfs_readhdr_free(struct nfs_pgio_header *hdr);
  260. extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
  261. struct inode *inode,
  262. const struct nfs_pgio_completion_ops *compl_ops);
  263. extern int nfs_initiate_read(struct rpc_clnt *clnt,
  264. struct nfs_read_data *data,
  265. const struct rpc_call_ops *call_ops, int flags);
  266. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  267. extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc,
  268. struct nfs_pgio_header *hdr);
  269. extern void nfs_pageio_init_read_mds(struct nfs_pageio_descriptor *pgio,
  270. struct inode *inode,
  271. const struct nfs_pgio_completion_ops *compl_ops);
  272. extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
  273. extern void nfs_readdata_release(struct nfs_read_data *rdata);
  274. /* write.c */
  275. extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
  276. struct inode *inode, int ioflags,
  277. const struct nfs_pgio_completion_ops *compl_ops);
  278. extern struct nfs_write_header *nfs_writehdr_alloc(void);
  279. extern void nfs_writehdr_free(struct nfs_pgio_header *hdr);
  280. extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
  281. struct nfs_pgio_header *hdr);
  282. extern void nfs_pageio_init_write_mds(struct nfs_pageio_descriptor *pgio,
  283. struct inode *inode, int ioflags,
  284. const struct nfs_pgio_completion_ops *compl_ops);
  285. extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
  286. extern void nfs_writedata_release(struct nfs_write_data *wdata);
  287. extern void nfs_commit_free(struct nfs_commit_data *p);
  288. extern int nfs_initiate_write(struct rpc_clnt *clnt,
  289. struct nfs_write_data *data,
  290. const struct rpc_call_ops *call_ops,
  291. int how, int flags);
  292. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  293. extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
  294. extern int nfs_initiate_commit(struct rpc_clnt *clnt,
  295. struct nfs_commit_data *data,
  296. const struct rpc_call_ops *call_ops,
  297. int how, int flags);
  298. extern void nfs_init_commit(struct nfs_commit_data *data,
  299. struct list_head *head,
  300. struct pnfs_layout_segment *lseg,
  301. struct nfs_commit_info *cinfo);
  302. int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
  303. struct nfs_commit_info *cinfo, int max);
  304. int nfs_scan_commit(struct inode *inode, struct list_head *dst,
  305. struct nfs_commit_info *cinfo);
  306. void nfs_mark_request_commit(struct nfs_page *req,
  307. struct pnfs_layout_segment *lseg,
  308. struct nfs_commit_info *cinfo);
  309. int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
  310. int how, struct nfs_commit_info *cinfo);
  311. void nfs_retry_commit(struct list_head *page_list,
  312. struct pnfs_layout_segment *lseg,
  313. struct nfs_commit_info *cinfo);
  314. void nfs_commitdata_release(struct nfs_commit_data *data);
  315. void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
  316. struct nfs_commit_info *cinfo);
  317. void nfs_request_remove_commit_list(struct nfs_page *req,
  318. struct nfs_commit_info *cinfo);
  319. void nfs_init_cinfo(struct nfs_commit_info *cinfo,
  320. struct inode *inode,
  321. struct nfs_direct_req *dreq);
  322. #ifdef CONFIG_MIGRATION
  323. extern int nfs_migrate_page(struct address_space *,
  324. struct page *, struct page *, enum migrate_mode);
  325. #else
  326. #define nfs_migrate_page NULL
  327. #endif
  328. /* direct.c */
  329. void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
  330. struct nfs_direct_req *dreq);
  331. static inline void nfs_inode_dio_wait(struct inode *inode)
  332. {
  333. inode_dio_wait(inode);
  334. }
  335. /* nfs4proc.c */
  336. extern void __nfs4_read_done_cb(struct nfs_read_data *);
  337. extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
  338. const struct rpc_timeout *timeparms,
  339. const char *ip_addr,
  340. rpc_authflavor_t authflavour);
  341. extern int _nfs4_call_sync(struct rpc_clnt *clnt,
  342. struct nfs_server *server,
  343. struct rpc_message *msg,
  344. struct nfs4_sequence_args *args,
  345. struct nfs4_sequence_res *res,
  346. int cache_reply);
  347. extern int _nfs4_call_sync_session(struct rpc_clnt *clnt,
  348. struct nfs_server *server,
  349. struct rpc_message *msg,
  350. struct nfs4_sequence_args *args,
  351. struct nfs4_sequence_res *res,
  352. int cache_reply);
  353. /*
  354. * Determine the device name as a string
  355. */
  356. static inline char *nfs_devname(struct dentry *dentry,
  357. char *buffer, ssize_t buflen)
  358. {
  359. char *dummy;
  360. return nfs_path(&dummy, dentry, buffer, buflen);
  361. }
  362. /*
  363. * Determine the actual block size (and log2 thereof)
  364. */
  365. static inline
  366. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  367. {
  368. /* make sure blocksize is a power of two */
  369. if ((bsize & (bsize - 1)) || nrbitsp) {
  370. unsigned char nrbits;
  371. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  372. ;
  373. bsize = 1 << nrbits;
  374. if (nrbitsp)
  375. *nrbitsp = nrbits;
  376. }
  377. return bsize;
  378. }
  379. /*
  380. * Calculate the number of 512byte blocks used.
  381. */
  382. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  383. {
  384. blkcnt_t used = (tsize + 511) >> 9;
  385. return (used > ULONG_MAX) ? ULONG_MAX : used;
  386. }
  387. /*
  388. * Compute and set NFS server blocksize
  389. */
  390. static inline
  391. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  392. {
  393. if (bsize < NFS_MIN_FILE_IO_SIZE)
  394. bsize = NFS_DEF_FILE_IO_SIZE;
  395. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  396. bsize = NFS_MAX_FILE_IO_SIZE;
  397. return nfs_block_bits(bsize, nrbitsp);
  398. }
  399. /*
  400. * Determine the maximum file size for a superblock
  401. */
  402. static inline
  403. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  404. {
  405. sb->s_maxbytes = (loff_t)maxfilesize;
  406. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  407. sb->s_maxbytes = MAX_LFS_FILESIZE;
  408. }
  409. /*
  410. * Determine the number of bytes of data the page contains
  411. */
  412. static inline
  413. unsigned int nfs_page_length(struct page *page)
  414. {
  415. loff_t i_size = i_size_read(page->mapping->host);
  416. if (i_size > 0) {
  417. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  418. if (page->index < end_index)
  419. return PAGE_CACHE_SIZE;
  420. if (page->index == end_index)
  421. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  422. }
  423. return 0;
  424. }
  425. /*
  426. * Convert a umode to a dirent->d_type
  427. */
  428. static inline
  429. unsigned char nfs_umode_to_dtype(umode_t mode)
  430. {
  431. return (mode >> 12) & 15;
  432. }
  433. /*
  434. * Determine the number of pages in an array of length 'len' and
  435. * with a base offset of 'base'
  436. */
  437. static inline
  438. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  439. {
  440. return ((unsigned long)len + (unsigned long)base +
  441. PAGE_SIZE - 1) >> PAGE_SHIFT;
  442. }
  443. /*
  444. * Convert a struct timespec into a 64-bit change attribute
  445. *
  446. * This does approximately the same thing as timespec_to_ns(),
  447. * but for calculation efficiency, we multiply the seconds by
  448. * 1024*1024*1024.
  449. */
  450. static inline
  451. u64 nfs_timespec_to_change_attr(const struct timespec *ts)
  452. {
  453. return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
  454. }