internal.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
  17. {
  18. if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
  19. fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
  20. }
  21. static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
  22. {
  23. if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
  24. (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
  25. ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
  26. return 0;
  27. fattr->fileid = fattr->mounted_on_fileid;
  28. return 1;
  29. }
  30. struct nfs_clone_mount {
  31. const struct super_block *sb;
  32. const struct dentry *dentry;
  33. struct nfs_fh *fh;
  34. struct nfs_fattr *fattr;
  35. char *hostname;
  36. char *mnt_path;
  37. struct sockaddr *addr;
  38. size_t addrlen;
  39. rpc_authflavor_t authflavor;
  40. };
  41. /*
  42. * Note: RFC 1813 doesn't limit the number of auth flavors that
  43. * a server can return, so make something up.
  44. */
  45. #define NFS_MAX_SECFLAVORS (12)
  46. /*
  47. * Value used if the user did not specify a port value.
  48. */
  49. #define NFS_UNSPEC_PORT (-1)
  50. /*
  51. * Maximum number of pages that readdir can use for creating
  52. * a vmapped array of pages.
  53. */
  54. #define NFS_MAX_READDIR_PAGES 8
  55. struct nfs_client_initdata {
  56. unsigned long init_flags;
  57. const char *hostname;
  58. const struct sockaddr *addr;
  59. size_t addrlen;
  60. struct nfs_subversion *nfs_mod;
  61. int proto;
  62. u32 minorversion;
  63. struct net *net;
  64. };
  65. /*
  66. * In-kernel mount arguments
  67. */
  68. struct nfs_parsed_mount_data {
  69. int flags;
  70. unsigned int rsize, wsize;
  71. unsigned int timeo, retrans;
  72. unsigned int acregmin, acregmax,
  73. acdirmin, acdirmax;
  74. unsigned 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. bool need_mount;
  84. struct {
  85. struct sockaddr_storage address;
  86. size_t addrlen;
  87. char *hostname;
  88. u32 version;
  89. int port;
  90. unsigned short protocol;
  91. } mount_server;
  92. struct {
  93. struct sockaddr_storage address;
  94. size_t addrlen;
  95. char *hostname;
  96. char *export_path;
  97. int port;
  98. unsigned short protocol;
  99. } nfs_server;
  100. struct security_mnt_opts lsm_opts;
  101. struct net *net;
  102. };
  103. /* mount_clnt.c */
  104. struct nfs_mount_request {
  105. struct sockaddr *sap;
  106. size_t salen;
  107. char *hostname;
  108. char *dirpath;
  109. u32 version;
  110. unsigned short protocol;
  111. struct nfs_fh *fh;
  112. int noresvport;
  113. unsigned int *auth_flav_len;
  114. rpc_authflavor_t *auth_flavs;
  115. struct net *net;
  116. };
  117. struct nfs_mount_info {
  118. void (*fill_super)(struct super_block *, struct nfs_mount_info *);
  119. int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
  120. struct nfs_parsed_mount_data *parsed;
  121. struct nfs_clone_mount *cloned;
  122. struct nfs_fh *mntfh;
  123. };
  124. extern int nfs_mount(struct nfs_mount_request *info);
  125. extern void nfs_umount(const struct nfs_mount_request *info);
  126. /* client.c */
  127. extern const struct rpc_program nfs_program;
  128. extern void nfs_clients_init(struct net *net);
  129. extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
  130. int nfs_create_rpc_client(struct nfs_client *, const struct rpc_timeout *, rpc_authflavor_t);
  131. struct nfs_client *nfs_get_client(const struct nfs_client_initdata *,
  132. const struct rpc_timeout *, const char *,
  133. rpc_authflavor_t);
  134. int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
  135. void nfs_server_insert_lists(struct nfs_server *);
  136. void nfs_init_timeout_values(struct rpc_timeout *, int, unsigned int, unsigned int);
  137. int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
  138. rpc_authflavor_t);
  139. struct nfs_server *nfs_alloc_server(void);
  140. void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
  141. extern void nfs_cleanup_cb_ident_idr(struct net *);
  142. extern void nfs_put_client(struct nfs_client *);
  143. extern void nfs_free_client(struct nfs_client *);
  144. extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
  145. extern struct nfs_client *
  146. nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
  147. struct nfs4_sessionid *, u32);
  148. extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
  149. struct nfs_subversion *);
  150. extern struct nfs_server *nfs4_create_server(
  151. struct nfs_mount_info *,
  152. struct nfs_subversion *);
  153. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  154. struct nfs_fh *);
  155. extern void nfs_free_server(struct nfs_server *server);
  156. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  157. struct nfs_fh *,
  158. struct nfs_fattr *,
  159. rpc_authflavor_t);
  160. extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
  161. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  162. extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
  163. const struct sockaddr *ds_addr,
  164. int ds_addrlen, int ds_proto,
  165. unsigned int ds_timeo,
  166. unsigned int ds_retrans);
  167. #ifdef CONFIG_PROC_FS
  168. extern int __init nfs_fs_proc_init(void);
  169. extern void nfs_fs_proc_exit(void);
  170. #else
  171. static inline int nfs_fs_proc_init(void)
  172. {
  173. return 0;
  174. }
  175. static inline void nfs_fs_proc_exit(void)
  176. {
  177. }
  178. #endif
  179. #ifdef CONFIG_NFS_V4_1
  180. int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *);
  181. #endif
  182. /* nfs3client.c */
  183. #if IS_ENABLED(CONFIG_NFS_V3)
  184. struct nfs_server *nfs3_create_server(struct nfs_mount_info *, struct nfs_subversion *);
  185. struct nfs_server *nfs3_clone_server(struct nfs_server *, struct nfs_fh *,
  186. struct nfs_fattr *, rpc_authflavor_t);
  187. #endif
  188. /* callback_xdr.c */
  189. extern struct svc_version nfs4_callback_version1;
  190. extern struct svc_version nfs4_callback_version4;
  191. struct nfs_pageio_descriptor;
  192. /* pagelist.c */
  193. extern int __init nfs_init_nfspagecache(void);
  194. extern void nfs_destroy_nfspagecache(void);
  195. extern int __init nfs_init_readpagecache(void);
  196. extern void nfs_destroy_readpagecache(void);
  197. extern int __init nfs_init_writepagecache(void);
  198. extern void nfs_destroy_writepagecache(void);
  199. extern int __init nfs_init_directcache(void);
  200. extern void nfs_destroy_directcache(void);
  201. extern bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount);
  202. extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
  203. struct nfs_pgio_header *hdr,
  204. void (*release)(struct nfs_pgio_header *hdr));
  205. void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
  206. int nfs_iocounter_wait(struct nfs_io_counter *c);
  207. static inline void nfs_iocounter_init(struct nfs_io_counter *c)
  208. {
  209. c->flags = 0;
  210. atomic_set(&c->io_count, 0);
  211. }
  212. /* nfs2xdr.c */
  213. extern struct rpc_procinfo nfs_procedures[];
  214. extern int nfs2_decode_dirent(struct xdr_stream *,
  215. struct nfs_entry *, int);
  216. /* nfs3xdr.c */
  217. extern struct rpc_procinfo nfs3_procedures[];
  218. extern int nfs3_decode_dirent(struct xdr_stream *,
  219. struct nfs_entry *, int);
  220. /* nfs4xdr.c */
  221. #if IS_ENABLED(CONFIG_NFS_V4)
  222. extern int nfs4_decode_dirent(struct xdr_stream *,
  223. struct nfs_entry *, int);
  224. #endif
  225. #ifdef CONFIG_NFS_V4_1
  226. extern const u32 nfs41_maxread_overhead;
  227. extern const u32 nfs41_maxwrite_overhead;
  228. extern const u32 nfs41_maxgetdevinfo_overhead;
  229. #endif
  230. /* nfs4proc.c */
  231. #if IS_ENABLED(CONFIG_NFS_V4)
  232. extern struct rpc_procinfo nfs4_procedures[];
  233. #endif
  234. /* proc.c */
  235. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  236. extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
  237. const struct rpc_timeout *timeparms,
  238. const char *ip_addr, rpc_authflavor_t authflavour);
  239. /* dir.c */
  240. extern int nfs_access_cache_shrinker(struct shrinker *shrink,
  241. struct shrink_control *sc);
  242. struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
  243. int nfs_create(struct inode *, struct dentry *, umode_t, bool);
  244. int nfs_mkdir(struct inode *, struct dentry *, umode_t);
  245. int nfs_rmdir(struct inode *, struct dentry *);
  246. int nfs_unlink(struct inode *, struct dentry *);
  247. int nfs_symlink(struct inode *, struct dentry *, const char *);
  248. int nfs_link(struct dentry *, struct inode *, struct dentry *);
  249. int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
  250. int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  251. /* file.c */
  252. int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int);
  253. loff_t nfs_file_llseek(struct file *, loff_t, int);
  254. int nfs_file_flush(struct file *, fl_owner_t);
  255. ssize_t nfs_file_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
  256. ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *,
  257. size_t, unsigned int);
  258. int nfs_file_mmap(struct file *, struct vm_area_struct *);
  259. ssize_t nfs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
  260. int nfs_file_release(struct inode *, struct file *);
  261. int nfs_lock(struct file *, int, struct file_lock *);
  262. int nfs_flock(struct file *, int, struct file_lock *);
  263. ssize_t nfs_file_splice_write(struct pipe_inode_info *, struct file *, loff_t *,
  264. size_t, unsigned int);
  265. int nfs_check_flags(int);
  266. int nfs_setlease(struct file *, long, struct file_lock **);
  267. /* inode.c */
  268. extern struct workqueue_struct *nfsiod_workqueue;
  269. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  270. extern void nfs_destroy_inode(struct inode *);
  271. extern int nfs_write_inode(struct inode *, struct writeback_control *);
  272. extern int nfs_drop_inode(struct inode *);
  273. extern void nfs_clear_inode(struct inode *);
  274. extern void nfs_evict_inode(struct inode *);
  275. void nfs_zap_acl_cache(struct inode *inode);
  276. extern int nfs_wait_bit_killable(void *word);
  277. /* super.c */
  278. extern const struct super_operations nfs_sops;
  279. extern struct file_system_type nfs_fs_type;
  280. extern struct file_system_type nfs_xdev_fs_type;
  281. #if IS_ENABLED(CONFIG_NFS_V4)
  282. extern struct file_system_type nfs4_xdev_fs_type;
  283. extern struct file_system_type nfs4_referral_fs_type;
  284. #endif
  285. struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *,
  286. struct nfs_subversion *);
  287. void nfs_initialise_sb(struct super_block *);
  288. int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
  289. int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
  290. struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *,
  291. struct nfs_mount_info *, struct nfs_subversion *);
  292. struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
  293. struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
  294. const char *, struct nfs_mount_info *);
  295. void nfs_kill_super(struct super_block *);
  296. void nfs_fill_super(struct super_block *, struct nfs_mount_info *);
  297. extern struct rpc_stat nfs_rpcstat;
  298. extern int __init register_nfs_fs(void);
  299. extern void __exit unregister_nfs_fs(void);
  300. extern void nfs_sb_active(struct super_block *sb);
  301. extern void nfs_sb_deactive(struct super_block *sb);
  302. /* namespace.c */
  303. #define NFS_PATH_CANONICAL 1
  304. extern char *nfs_path(char **p, struct dentry *dentry,
  305. char *buffer, ssize_t buflen, unsigned flags);
  306. extern struct vfsmount *nfs_d_automount(struct path *path);
  307. struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
  308. struct nfs_fh *, struct nfs_fattr *);
  309. struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
  310. struct nfs_fattr *, rpc_authflavor_t);
  311. /* getroot.c */
  312. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  313. const char *);
  314. #if IS_ENABLED(CONFIG_NFS_V4)
  315. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  316. const char *);
  317. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
  318. #endif
  319. struct nfs_pgio_completion_ops;
  320. /* read.c */
  321. extern struct nfs_read_header *nfs_readhdr_alloc(void);
  322. extern void nfs_readhdr_free(struct nfs_pgio_header *hdr);
  323. extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
  324. struct inode *inode,
  325. const struct nfs_pgio_completion_ops *compl_ops);
  326. extern int nfs_initiate_read(struct rpc_clnt *clnt,
  327. struct nfs_read_data *data,
  328. const struct rpc_call_ops *call_ops, int flags);
  329. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  330. extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc,
  331. struct nfs_pgio_header *hdr);
  332. extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
  333. extern void nfs_readdata_release(struct nfs_read_data *rdata);
  334. /* super.c */
  335. void nfs_clone_super(struct super_block *, struct nfs_mount_info *);
  336. void nfs_umount_begin(struct super_block *);
  337. int nfs_statfs(struct dentry *, struct kstatfs *);
  338. int nfs_show_options(struct seq_file *, struct dentry *);
  339. int nfs_show_devname(struct seq_file *, struct dentry *);
  340. int nfs_show_path(struct seq_file *, struct dentry *);
  341. int nfs_show_stats(struct seq_file *, struct dentry *);
  342. void nfs_put_super(struct super_block *);
  343. int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
  344. /* write.c */
  345. extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
  346. struct inode *inode, int ioflags,
  347. const struct nfs_pgio_completion_ops *compl_ops);
  348. extern struct nfs_write_header *nfs_writehdr_alloc(void);
  349. extern void nfs_writehdr_free(struct nfs_pgio_header *hdr);
  350. extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
  351. struct nfs_pgio_header *hdr);
  352. extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
  353. extern void nfs_writedata_release(struct nfs_write_data *wdata);
  354. extern void nfs_commit_free(struct nfs_commit_data *p);
  355. extern int nfs_initiate_write(struct rpc_clnt *clnt,
  356. struct nfs_write_data *data,
  357. const struct rpc_call_ops *call_ops,
  358. int how, int flags);
  359. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  360. extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
  361. extern int nfs_initiate_commit(struct rpc_clnt *clnt,
  362. struct nfs_commit_data *data,
  363. const struct rpc_call_ops *call_ops,
  364. int how, int flags);
  365. extern void nfs_init_commit(struct nfs_commit_data *data,
  366. struct list_head *head,
  367. struct pnfs_layout_segment *lseg,
  368. struct nfs_commit_info *cinfo);
  369. int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
  370. struct nfs_commit_info *cinfo, int max);
  371. int nfs_scan_commit(struct inode *inode, struct list_head *dst,
  372. struct nfs_commit_info *cinfo);
  373. void nfs_mark_request_commit(struct nfs_page *req,
  374. struct pnfs_layout_segment *lseg,
  375. struct nfs_commit_info *cinfo);
  376. int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
  377. int how, struct nfs_commit_info *cinfo);
  378. void nfs_retry_commit(struct list_head *page_list,
  379. struct pnfs_layout_segment *lseg,
  380. struct nfs_commit_info *cinfo);
  381. void nfs_commitdata_release(struct nfs_commit_data *data);
  382. void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
  383. struct nfs_commit_info *cinfo);
  384. void nfs_request_remove_commit_list(struct nfs_page *req,
  385. struct nfs_commit_info *cinfo);
  386. void nfs_init_cinfo(struct nfs_commit_info *cinfo,
  387. struct inode *inode,
  388. struct nfs_direct_req *dreq);
  389. #ifdef CONFIG_MIGRATION
  390. extern int nfs_migrate_page(struct address_space *,
  391. struct page *, struct page *, enum migrate_mode);
  392. #else
  393. #define nfs_migrate_page NULL
  394. #endif
  395. /* direct.c */
  396. void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
  397. struct nfs_direct_req *dreq);
  398. static inline void nfs_inode_dio_wait(struct inode *inode)
  399. {
  400. inode_dio_wait(inode);
  401. }
  402. extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
  403. /* nfs4proc.c */
  404. extern void __nfs4_read_done_cb(struct nfs_read_data *);
  405. extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
  406. const struct rpc_timeout *timeparms,
  407. const char *ip_addr,
  408. rpc_authflavor_t authflavour);
  409. extern int nfs40_walk_client_list(struct nfs_client *clp,
  410. struct nfs_client **result,
  411. struct rpc_cred *cred);
  412. extern int nfs41_walk_client_list(struct nfs_client *clp,
  413. struct nfs_client **result,
  414. struct rpc_cred *cred);
  415. /*
  416. * Determine the device name as a string
  417. */
  418. static inline char *nfs_devname(struct dentry *dentry,
  419. char *buffer, ssize_t buflen)
  420. {
  421. char *dummy;
  422. return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
  423. }
  424. /*
  425. * Determine the actual block size (and log2 thereof)
  426. */
  427. static inline
  428. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  429. {
  430. /* make sure blocksize is a power of two */
  431. if ((bsize & (bsize - 1)) || nrbitsp) {
  432. unsigned char nrbits;
  433. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  434. ;
  435. bsize = 1 << nrbits;
  436. if (nrbitsp)
  437. *nrbitsp = nrbits;
  438. }
  439. return bsize;
  440. }
  441. /*
  442. * Calculate the number of 512byte blocks used.
  443. */
  444. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  445. {
  446. blkcnt_t used = (tsize + 511) >> 9;
  447. return (used > ULONG_MAX) ? ULONG_MAX : used;
  448. }
  449. /*
  450. * Compute and set NFS server blocksize
  451. */
  452. static inline
  453. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  454. {
  455. if (bsize < NFS_MIN_FILE_IO_SIZE)
  456. bsize = NFS_DEF_FILE_IO_SIZE;
  457. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  458. bsize = NFS_MAX_FILE_IO_SIZE;
  459. return nfs_block_bits(bsize, nrbitsp);
  460. }
  461. /*
  462. * Determine the maximum file size for a superblock
  463. */
  464. static inline
  465. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  466. {
  467. sb->s_maxbytes = (loff_t)maxfilesize;
  468. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  469. sb->s_maxbytes = MAX_LFS_FILESIZE;
  470. }
  471. /*
  472. * Determine the number of bytes of data the page contains
  473. */
  474. static inline
  475. unsigned int nfs_page_length(struct page *page)
  476. {
  477. loff_t i_size = i_size_read(page_file_mapping(page)->host);
  478. if (i_size > 0) {
  479. pgoff_t page_index = page_file_index(page);
  480. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  481. if (page_index < end_index)
  482. return PAGE_CACHE_SIZE;
  483. if (page_index == end_index)
  484. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  485. }
  486. return 0;
  487. }
  488. /*
  489. * Convert a umode to a dirent->d_type
  490. */
  491. static inline
  492. unsigned char nfs_umode_to_dtype(umode_t mode)
  493. {
  494. return (mode >> 12) & 15;
  495. }
  496. /*
  497. * Determine the number of pages in an array of length 'len' and
  498. * with a base offset of 'base'
  499. */
  500. static inline
  501. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  502. {
  503. return ((unsigned long)len + (unsigned long)base +
  504. PAGE_SIZE - 1) >> PAGE_SHIFT;
  505. }
  506. /*
  507. * Convert a struct timespec into a 64-bit change attribute
  508. *
  509. * This does approximately the same thing as timespec_to_ns(),
  510. * but for calculation efficiency, we multiply the seconds by
  511. * 1024*1024*1024.
  512. */
  513. static inline
  514. u64 nfs_timespec_to_change_attr(const struct timespec *ts)
  515. {
  516. return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
  517. }