internal.h 12 KB

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