internal.h 11 KB

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