internal.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. };
  110. /* mount_clnt.c */
  111. struct nfs_mount_request {
  112. struct sockaddr *sap;
  113. size_t salen;
  114. char *hostname;
  115. char *dirpath;
  116. u32 version;
  117. unsigned short protocol;
  118. struct nfs_fh *fh;
  119. int noresvport;
  120. unsigned int *auth_flav_len;
  121. rpc_authflavor_t *auth_flavs;
  122. };
  123. extern int nfs_mount(struct nfs_mount_request *info);
  124. extern void nfs_umount(const struct nfs_mount_request *info);
  125. /* client.c */
  126. extern struct rpc_program nfs_program;
  127. extern void nfs_cleanup_cb_ident_idr(void);
  128. extern void nfs_put_client(struct nfs_client *);
  129. extern struct nfs_client *nfs4_find_client_no_ident(const struct sockaddr *);
  130. extern struct nfs_client *nfs4_find_client_ident(int);
  131. extern struct nfs_client *
  132. nfs4_find_client_sessionid(const struct sockaddr *, struct nfs4_sessionid *);
  133. extern struct nfs_server *nfs_create_server(
  134. const struct nfs_parsed_mount_data *,
  135. struct nfs_fh *);
  136. extern struct nfs_server *nfs4_create_server(
  137. const struct nfs_parsed_mount_data *,
  138. struct nfs_fh *);
  139. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  140. struct nfs_fh *);
  141. extern void nfs_free_server(struct nfs_server *server);
  142. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  143. struct nfs_fh *,
  144. struct nfs_fattr *);
  145. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  146. extern int nfs4_check_client_ready(struct nfs_client *clp);
  147. extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
  148. const struct sockaddr *ds_addr,
  149. int ds_addrlen, int ds_proto);
  150. #ifdef CONFIG_PROC_FS
  151. extern int __init nfs_fs_proc_init(void);
  152. extern void nfs_fs_proc_exit(void);
  153. #else
  154. static inline int nfs_fs_proc_init(void)
  155. {
  156. return 0;
  157. }
  158. static inline void nfs_fs_proc_exit(void)
  159. {
  160. }
  161. #endif
  162. /* nfs4namespace.c */
  163. #ifdef CONFIG_NFS_V4
  164. extern struct vfsmount *nfs_do_refmount(struct dentry *dentry);
  165. #else
  166. static inline
  167. struct vfsmount *nfs_do_refmount(struct dentry *dentry)
  168. {
  169. return ERR_PTR(-ENOENT);
  170. }
  171. #endif
  172. /* callback_xdr.c */
  173. extern struct svc_version nfs4_callback_version1;
  174. extern struct svc_version nfs4_callback_version4;
  175. /* pagelist.c */
  176. extern int __init nfs_init_nfspagecache(void);
  177. extern void nfs_destroy_nfspagecache(void);
  178. extern int __init nfs_init_readpagecache(void);
  179. extern void nfs_destroy_readpagecache(void);
  180. extern int __init nfs_init_writepagecache(void);
  181. extern void nfs_destroy_writepagecache(void);
  182. extern int __init nfs_init_directcache(void);
  183. extern void nfs_destroy_directcache(void);
  184. /* nfs2xdr.c */
  185. extern int nfs_stat_to_errno(enum nfs_stat);
  186. extern struct rpc_procinfo nfs_procedures[];
  187. extern int nfs2_decode_dirent(struct xdr_stream *,
  188. struct nfs_entry *, int);
  189. /* nfs3xdr.c */
  190. extern struct rpc_procinfo nfs3_procedures[];
  191. extern int nfs3_decode_dirent(struct xdr_stream *,
  192. struct nfs_entry *, int);
  193. /* nfs4xdr.c */
  194. #ifdef CONFIG_NFS_V4
  195. extern int nfs4_decode_dirent(struct xdr_stream *,
  196. struct nfs_entry *, int);
  197. #endif
  198. #ifdef CONFIG_NFS_V4_1
  199. extern const u32 nfs41_maxread_overhead;
  200. extern const u32 nfs41_maxwrite_overhead;
  201. #endif
  202. /* nfs4proc.c */
  203. #ifdef CONFIG_NFS_V4
  204. extern struct rpc_procinfo nfs4_procedures[];
  205. void nfs_fixup_secinfo_attributes(struct nfs_fattr *, struct nfs_fh *);
  206. #endif
  207. extern int nfs4_init_ds_session(struct nfs_client *clp);
  208. /* proc.c */
  209. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  210. extern int nfs_init_client(struct nfs_client *clp,
  211. const struct rpc_timeout *timeparms,
  212. const char *ip_addr, rpc_authflavor_t authflavour,
  213. int noresvport);
  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. /* getroot.c */
  244. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  245. const char *);
  246. #ifdef CONFIG_NFS_V4
  247. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  248. const char *);
  249. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
  250. #endif
  251. /* read.c */
  252. extern int nfs_initiate_read(struct nfs_read_data *data, struct rpc_clnt *clnt,
  253. const struct rpc_call_ops *call_ops);
  254. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  255. /* write.c */
  256. extern void nfs_commit_free(struct nfs_write_data *p);
  257. extern int nfs_initiate_write(struct nfs_write_data *data,
  258. struct rpc_clnt *clnt,
  259. const struct rpc_call_ops *call_ops,
  260. int how);
  261. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  262. extern int nfs_initiate_commit(struct nfs_write_data *data,
  263. struct rpc_clnt *clnt,
  264. const struct rpc_call_ops *call_ops,
  265. int how);
  266. extern void nfs_init_commit(struct nfs_write_data *data,
  267. struct list_head *head,
  268. struct pnfs_layout_segment *lseg);
  269. void nfs_retry_commit(struct list_head *page_list,
  270. struct pnfs_layout_segment *lseg);
  271. void nfs_commit_clear_lock(struct nfs_inode *nfsi);
  272. void nfs_commitdata_release(void *data);
  273. void nfs_commit_release_pages(struct nfs_write_data *data);
  274. #ifdef CONFIG_MIGRATION
  275. extern int nfs_migrate_page(struct address_space *,
  276. struct page *, struct page *);
  277. #else
  278. #define nfs_migrate_page NULL
  279. #endif
  280. /* nfs4proc.c */
  281. extern void __nfs4_read_done_cb(struct nfs_read_data *);
  282. extern void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data);
  283. extern int nfs4_init_client(struct nfs_client *clp,
  284. const struct rpc_timeout *timeparms,
  285. const char *ip_addr,
  286. rpc_authflavor_t authflavour,
  287. int noresvport);
  288. extern void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data);
  289. extern int _nfs4_call_sync(struct rpc_clnt *clnt,
  290. struct nfs_server *server,
  291. struct rpc_message *msg,
  292. struct nfs4_sequence_args *args,
  293. struct nfs4_sequence_res *res,
  294. int cache_reply);
  295. extern int _nfs4_call_sync_session(struct rpc_clnt *clnt,
  296. struct nfs_server *server,
  297. struct rpc_message *msg,
  298. struct nfs4_sequence_args *args,
  299. struct nfs4_sequence_res *res,
  300. int cache_reply);
  301. /*
  302. * Determine the device name as a string
  303. */
  304. static inline char *nfs_devname(struct dentry *dentry,
  305. char *buffer, ssize_t buflen)
  306. {
  307. char *dummy;
  308. return nfs_path(&dummy, dentry, buffer, buflen);
  309. }
  310. /*
  311. * Determine the actual block size (and log2 thereof)
  312. */
  313. static inline
  314. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  315. {
  316. /* make sure blocksize is a power of two */
  317. if ((bsize & (bsize - 1)) || nrbitsp) {
  318. unsigned char nrbits;
  319. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  320. ;
  321. bsize = 1 << nrbits;
  322. if (nrbitsp)
  323. *nrbitsp = nrbits;
  324. }
  325. return bsize;
  326. }
  327. /*
  328. * Calculate the number of 512byte blocks used.
  329. */
  330. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  331. {
  332. blkcnt_t used = (tsize + 511) >> 9;
  333. return (used > ULONG_MAX) ? ULONG_MAX : used;
  334. }
  335. /*
  336. * Compute and set NFS server blocksize
  337. */
  338. static inline
  339. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  340. {
  341. if (bsize < NFS_MIN_FILE_IO_SIZE)
  342. bsize = NFS_DEF_FILE_IO_SIZE;
  343. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  344. bsize = NFS_MAX_FILE_IO_SIZE;
  345. return nfs_block_bits(bsize, nrbitsp);
  346. }
  347. /*
  348. * Determine the maximum file size for a superblock
  349. */
  350. static inline
  351. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  352. {
  353. sb->s_maxbytes = (loff_t)maxfilesize;
  354. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  355. sb->s_maxbytes = MAX_LFS_FILESIZE;
  356. }
  357. /*
  358. * Determine the number of bytes of data the page contains
  359. */
  360. static inline
  361. unsigned int nfs_page_length(struct page *page)
  362. {
  363. loff_t i_size = i_size_read(page->mapping->host);
  364. if (i_size > 0) {
  365. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  366. if (page->index < end_index)
  367. return PAGE_CACHE_SIZE;
  368. if (page->index == end_index)
  369. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  370. }
  371. return 0;
  372. }
  373. /*
  374. * Convert a umode to a dirent->d_type
  375. */
  376. static inline
  377. unsigned char nfs_umode_to_dtype(umode_t mode)
  378. {
  379. return (mode >> 12) & 15;
  380. }
  381. /*
  382. * Determine the number of pages in an array of length 'len' and
  383. * with a base offset of 'base'
  384. */
  385. static inline
  386. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  387. {
  388. return ((unsigned long)len + (unsigned long)base +
  389. PAGE_SIZE - 1) >> PAGE_SHIFT;
  390. }
  391. /*
  392. * Helper for restarting RPC calls in the possible presence of NFSv4.1
  393. * sessions.
  394. */
  395. static inline int nfs_restart_rpc(struct rpc_task *task, const struct nfs_client *clp)
  396. {
  397. if (nfs4_has_session(clp))
  398. return rpc_restart_call_prepare(task);
  399. return rpc_restart_call(task);
  400. }