internal.h 15 KB

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