internal.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * NFS internal definitions
  3. */
  4. #include "nfs4_fs.h"
  5. #include <linux/mount.h>
  6. #include <linux/security.h>
  7. #include <linux/crc32.h>
  8. #include <linux/nfs_page.h>
  9. #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
  10. struct nfs_string;
  11. /* Maximum number of readahead requests
  12. * FIXME: this should really be a sysctl so that users may tune it to suit
  13. * their needs. People that do NFS over a slow network, might for
  14. * instance want to reduce it to something closer to 1 for improved
  15. * interactive response.
  16. */
  17. #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
  18. static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
  19. {
  20. if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
  21. fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
  22. }
  23. static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
  24. {
  25. if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
  26. (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
  27. ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
  28. return 0;
  29. return 1;
  30. }
  31. struct nfs_clone_mount {
  32. const struct super_block *sb;
  33. const struct dentry *dentry;
  34. struct nfs_fh *fh;
  35. struct nfs_fattr *fattr;
  36. char *hostname;
  37. char *mnt_path;
  38. struct sockaddr *addr;
  39. size_t addrlen;
  40. rpc_authflavor_t authflavor;
  41. };
  42. /*
  43. * Note: RFC 1813 doesn't limit the number of auth flavors that
  44. * a server can return, so make something up.
  45. */
  46. #define NFS_MAX_SECFLAVORS (12)
  47. /*
  48. * Value used if the user did not specify a port value.
  49. */
  50. #define NFS_UNSPEC_PORT (-1)
  51. /*
  52. * Maximum number of pages that readdir can use for creating
  53. * a vmapped array of pages.
  54. */
  55. #define NFS_MAX_READDIR_PAGES 8
  56. struct nfs_client_initdata {
  57. unsigned long init_flags;
  58. const char *hostname;
  59. const struct sockaddr *addr;
  60. size_t addrlen;
  61. struct nfs_subversion *nfs_mod;
  62. int proto;
  63. u32 minorversion;
  64. struct net *net;
  65. };
  66. /*
  67. * In-kernel mount arguments
  68. */
  69. struct nfs_parsed_mount_data {
  70. int flags;
  71. unsigned int rsize, wsize;
  72. unsigned int timeo, retrans;
  73. unsigned int acregmin, acregmax,
  74. acdirmin, acdirmax;
  75. unsigned int namlen;
  76. unsigned int options;
  77. unsigned int bsize;
  78. struct nfs_auth_info auth_info;
  79. rpc_authflavor_t selected_flavor;
  80. char *client_address;
  81. unsigned int version;
  82. unsigned int minorversion;
  83. char *fscache_uniq;
  84. bool need_mount;
  85. struct {
  86. struct sockaddr_storage address;
  87. size_t addrlen;
  88. char *hostname;
  89. u32 version;
  90. int port;
  91. unsigned short protocol;
  92. } mount_server;
  93. struct {
  94. struct sockaddr_storage address;
  95. size_t addrlen;
  96. char *hostname;
  97. char *export_path;
  98. int port;
  99. unsigned short protocol;
  100. } nfs_server;
  101. struct security_mnt_opts lsm_opts;
  102. struct net *net;
  103. };
  104. /* mount_clnt.c */
  105. struct nfs_mount_request {
  106. struct sockaddr *sap;
  107. size_t salen;
  108. char *hostname;
  109. char *dirpath;
  110. u32 version;
  111. unsigned short protocol;
  112. struct nfs_fh *fh;
  113. int noresvport;
  114. unsigned int *auth_flav_len;
  115. rpc_authflavor_t *auth_flavs;
  116. struct net *net;
  117. };
  118. struct nfs_mount_info {
  119. void (*fill_super)(struct super_block *, struct nfs_mount_info *);
  120. int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
  121. struct nfs_parsed_mount_data *parsed;
  122. struct nfs_clone_mount *cloned;
  123. struct nfs_fh *mntfh;
  124. };
  125. extern int nfs_mount(struct nfs_mount_request *info);
  126. extern void nfs_umount(const struct nfs_mount_request *info);
  127. /* client.c */
  128. extern const struct rpc_program nfs_program;
  129. extern void nfs_clients_init(struct net *net);
  130. extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
  131. int nfs_create_rpc_client(struct nfs_client *, const struct rpc_timeout *, rpc_authflavor_t);
  132. struct nfs_client *nfs_get_client(const struct nfs_client_initdata *,
  133. const struct rpc_timeout *, const char *,
  134. rpc_authflavor_t);
  135. int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
  136. void nfs_server_insert_lists(struct nfs_server *);
  137. void nfs_server_remove_lists(struct nfs_server *);
  138. void nfs_init_timeout_values(struct rpc_timeout *, int, unsigned int, unsigned int);
  139. int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
  140. rpc_authflavor_t);
  141. struct nfs_server *nfs_alloc_server(void);
  142. void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
  143. extern void nfs_cleanup_cb_ident_idr(struct net *);
  144. extern void nfs_put_client(struct nfs_client *);
  145. extern void nfs_free_client(struct nfs_client *);
  146. extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
  147. extern struct nfs_client *
  148. nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
  149. struct nfs4_sessionid *, u32);
  150. extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
  151. struct nfs_subversion *);
  152. extern struct nfs_server *nfs4_create_server(
  153. struct nfs_mount_info *,
  154. struct nfs_subversion *);
  155. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  156. struct nfs_fh *);
  157. extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
  158. struct sockaddr *sap, size_t salen,
  159. struct net *net);
  160. extern void nfs_free_server(struct nfs_server *server);
  161. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  162. struct nfs_fh *,
  163. struct nfs_fattr *,
  164. rpc_authflavor_t);
  165. extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
  166. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  167. extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
  168. const struct sockaddr *ds_addr,
  169. int ds_addrlen, int ds_proto,
  170. unsigned int ds_timeo,
  171. unsigned int ds_retrans,
  172. u32 minor_version,
  173. rpc_authflavor_t au_flavor);
  174. extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
  175. struct inode *);
  176. extern struct nfs_client *nfs3_set_ds_client(struct nfs_client *mds_clp,
  177. const struct sockaddr *ds_addr, int ds_addrlen,
  178. int ds_proto, unsigned int ds_timeo,
  179. unsigned int ds_retrans, rpc_authflavor_t au_flavor);
  180. #ifdef CONFIG_PROC_FS
  181. extern int __init nfs_fs_proc_init(void);
  182. extern void nfs_fs_proc_exit(void);
  183. extern int nfs_fs_proc_net_init(struct net *net);
  184. extern void nfs_fs_proc_net_exit(struct net *net);
  185. #else
  186. static inline int nfs_fs_proc_net_init(struct net *net)
  187. {
  188. return 0;
  189. }
  190. static inline void nfs_fs_proc_net_exit(struct net *net)
  191. {
  192. }
  193. static inline int nfs_fs_proc_init(void)
  194. {
  195. return 0;
  196. }
  197. static inline void nfs_fs_proc_exit(void)
  198. {
  199. }
  200. #endif
  201. #ifdef CONFIG_NFS_V4_1
  202. int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *);
  203. #endif
  204. /* callback_xdr.c */
  205. extern struct svc_version nfs4_callback_version1;
  206. extern struct svc_version nfs4_callback_version4;
  207. struct nfs_pageio_descriptor;
  208. /* pagelist.c */
  209. extern int __init nfs_init_nfspagecache(void);
  210. extern void nfs_destroy_nfspagecache(void);
  211. extern int __init nfs_init_readpagecache(void);
  212. extern void nfs_destroy_readpagecache(void);
  213. extern int __init nfs_init_writepagecache(void);
  214. extern void nfs_destroy_writepagecache(void);
  215. extern int __init nfs_init_directcache(void);
  216. extern void nfs_destroy_directcache(void);
  217. extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
  218. struct nfs_pgio_header *hdr,
  219. void (*release)(struct nfs_pgio_header *hdr));
  220. void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
  221. int nfs_iocounter_wait(struct nfs_io_counter *c);
  222. extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
  223. struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
  224. void nfs_pgio_header_free(struct nfs_pgio_header *);
  225. void nfs_pgio_data_destroy(struct nfs_pgio_header *);
  226. int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
  227. int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
  228. struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops,
  229. const struct rpc_call_ops *call_ops, int how, int flags);
  230. void nfs_free_request(struct nfs_page *req);
  231. struct nfs_pgio_mirror *
  232. nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
  233. static inline void nfs_iocounter_init(struct nfs_io_counter *c)
  234. {
  235. c->flags = 0;
  236. atomic_set(&c->io_count, 0);
  237. }
  238. static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
  239. {
  240. WARN_ON_ONCE(desc->pg_mirror_count < 1);
  241. return desc->pg_mirror_count > 1;
  242. }
  243. /* nfs2xdr.c */
  244. extern struct rpc_procinfo nfs_procedures[];
  245. extern int nfs2_decode_dirent(struct xdr_stream *,
  246. struct nfs_entry *, int);
  247. /* nfs3xdr.c */
  248. extern struct rpc_procinfo nfs3_procedures[];
  249. extern int nfs3_decode_dirent(struct xdr_stream *,
  250. struct nfs_entry *, int);
  251. /* nfs4xdr.c */
  252. #if IS_ENABLED(CONFIG_NFS_V4)
  253. extern int nfs4_decode_dirent(struct xdr_stream *,
  254. struct nfs_entry *, int);
  255. #endif
  256. #ifdef CONFIG_NFS_V4_1
  257. extern const u32 nfs41_maxread_overhead;
  258. extern const u32 nfs41_maxwrite_overhead;
  259. extern const u32 nfs41_maxgetdevinfo_overhead;
  260. #endif
  261. /* nfs4proc.c */
  262. #if IS_ENABLED(CONFIG_NFS_V4)
  263. extern struct rpc_procinfo nfs4_procedures[];
  264. #endif
  265. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  266. extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
  267. static inline void nfs4_label_free(struct nfs4_label *label)
  268. {
  269. if (label) {
  270. kfree(label->label);
  271. kfree(label);
  272. }
  273. return;
  274. }
  275. static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
  276. {
  277. if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
  278. nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
  279. }
  280. #else
  281. static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
  282. static inline void nfs4_label_free(void *label) {}
  283. static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
  284. {
  285. }
  286. #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
  287. /* proc.c */
  288. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  289. extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
  290. const struct rpc_timeout *timeparms,
  291. const char *ip_addr);
  292. /* dir.c */
  293. extern void nfs_force_use_readdirplus(struct inode *dir);
  294. extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
  295. struct shrink_control *sc);
  296. extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
  297. struct shrink_control *sc);
  298. struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
  299. int nfs_create(struct inode *, struct dentry *, umode_t, bool);
  300. int nfs_mkdir(struct inode *, struct dentry *, umode_t);
  301. int nfs_rmdir(struct inode *, struct dentry *);
  302. int nfs_unlink(struct inode *, struct dentry *);
  303. int nfs_symlink(struct inode *, struct dentry *, const char *);
  304. int nfs_link(struct dentry *, struct inode *, struct dentry *);
  305. int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
  306. int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
  307. /* file.c */
  308. int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int);
  309. loff_t nfs_file_llseek(struct file *, loff_t, int);
  310. int nfs_file_flush(struct file *, fl_owner_t);
  311. ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
  312. ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *,
  313. size_t, unsigned int);
  314. int nfs_file_mmap(struct file *, struct vm_area_struct *);
  315. ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
  316. int nfs_file_release(struct inode *, struct file *);
  317. int nfs_lock(struct file *, int, struct file_lock *);
  318. int nfs_flock(struct file *, int, struct file_lock *);
  319. int nfs_check_flags(int);
  320. /* inode.c */
  321. extern struct workqueue_struct *nfsiod_workqueue;
  322. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  323. extern void nfs_destroy_inode(struct inode *);
  324. extern int nfs_write_inode(struct inode *, struct writeback_control *);
  325. extern int nfs_drop_inode(struct inode *);
  326. extern void nfs_clear_inode(struct inode *);
  327. extern void nfs_evict_inode(struct inode *);
  328. void nfs_zap_acl_cache(struct inode *inode);
  329. extern int nfs_wait_bit_killable(struct wait_bit_key *key);
  330. /* super.c */
  331. extern const struct super_operations nfs_sops;
  332. extern struct file_system_type nfs_fs_type;
  333. extern struct file_system_type nfs_xdev_fs_type;
  334. #if IS_ENABLED(CONFIG_NFS_V4)
  335. extern struct file_system_type nfs4_xdev_fs_type;
  336. extern struct file_system_type nfs4_referral_fs_type;
  337. #endif
  338. bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
  339. struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *,
  340. struct nfs_subversion *);
  341. void nfs_initialise_sb(struct super_block *);
  342. int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
  343. int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
  344. struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *,
  345. struct nfs_mount_info *, struct nfs_subversion *);
  346. struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
  347. struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
  348. const char *, struct nfs_mount_info *);
  349. void nfs_kill_super(struct super_block *);
  350. void nfs_fill_super(struct super_block *, struct nfs_mount_info *);
  351. extern struct rpc_stat nfs_rpcstat;
  352. extern int __init register_nfs_fs(void);
  353. extern void __exit unregister_nfs_fs(void);
  354. extern bool nfs_sb_active(struct super_block *sb);
  355. extern void nfs_sb_deactive(struct super_block *sb);
  356. /* namespace.c */
  357. #define NFS_PATH_CANONICAL 1
  358. extern char *nfs_path(char **p, struct dentry *dentry,
  359. char *buffer, ssize_t buflen, unsigned flags);
  360. extern struct vfsmount *nfs_d_automount(struct path *path);
  361. struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
  362. struct nfs_fh *, struct nfs_fattr *);
  363. struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
  364. struct nfs_fattr *, rpc_authflavor_t);
  365. /* getroot.c */
  366. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  367. const char *);
  368. #if IS_ENABLED(CONFIG_NFS_V4)
  369. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  370. const char *);
  371. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
  372. #endif
  373. struct nfs_pgio_completion_ops;
  374. /* read.c */
  375. extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
  376. struct inode *inode, bool force_mds,
  377. const struct nfs_pgio_completion_ops *compl_ops);
  378. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  379. extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
  380. /* super.c */
  381. void nfs_clone_super(struct super_block *, struct nfs_mount_info *);
  382. void nfs_umount_begin(struct super_block *);
  383. int nfs_statfs(struct dentry *, struct kstatfs *);
  384. int nfs_show_options(struct seq_file *, struct dentry *);
  385. int nfs_show_devname(struct seq_file *, struct dentry *);
  386. int nfs_show_path(struct seq_file *, struct dentry *);
  387. int nfs_show_stats(struct seq_file *, struct dentry *);
  388. int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
  389. /* write.c */
  390. extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
  391. struct inode *inode, int ioflags, bool force_mds,
  392. const struct nfs_pgio_completion_ops *compl_ops);
  393. extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
  394. extern void nfs_commit_free(struct nfs_commit_data *p);
  395. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  396. extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
  397. extern int nfs_initiate_commit(struct rpc_clnt *clnt,
  398. struct nfs_commit_data *data,
  399. const struct nfs_rpc_ops *nfs_ops,
  400. const struct rpc_call_ops *call_ops,
  401. int how, int flags);
  402. extern void nfs_init_commit(struct nfs_commit_data *data,
  403. struct list_head *head,
  404. struct pnfs_layout_segment *lseg,
  405. struct nfs_commit_info *cinfo);
  406. int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
  407. struct nfs_commit_info *cinfo, int max);
  408. unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
  409. int nfs_scan_commit(struct inode *inode, struct list_head *dst,
  410. struct nfs_commit_info *cinfo);
  411. void nfs_mark_request_commit(struct nfs_page *req,
  412. struct pnfs_layout_segment *lseg,
  413. struct nfs_commit_info *cinfo,
  414. u32 ds_commit_idx);
  415. int nfs_write_need_commit(struct nfs_pgio_header *);
  416. void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
  417. int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
  418. int how, struct nfs_commit_info *cinfo);
  419. void nfs_retry_commit(struct list_head *page_list,
  420. struct pnfs_layout_segment *lseg,
  421. struct nfs_commit_info *cinfo,
  422. u32 ds_commit_idx);
  423. void nfs_commitdata_release(struct nfs_commit_data *data);
  424. void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
  425. struct nfs_commit_info *cinfo);
  426. void nfs_request_remove_commit_list(struct nfs_page *req,
  427. struct nfs_commit_info *cinfo);
  428. void nfs_init_cinfo(struct nfs_commit_info *cinfo,
  429. struct inode *inode,
  430. struct nfs_direct_req *dreq);
  431. int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
  432. bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx);
  433. void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
  434. #ifdef CONFIG_MIGRATION
  435. extern int nfs_migrate_page(struct address_space *,
  436. struct page *, struct page *, enum migrate_mode);
  437. #else
  438. #define nfs_migrate_page NULL
  439. #endif
  440. /* unlink.c */
  441. extern struct rpc_task *
  442. nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
  443. struct dentry *old_dentry, struct dentry *new_dentry,
  444. void (*complete)(struct rpc_task *, struct nfs_renamedata *));
  445. extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
  446. /* direct.c */
  447. void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
  448. struct nfs_direct_req *dreq);
  449. static inline void nfs_inode_dio_wait(struct inode *inode)
  450. {
  451. inode_dio_wait(inode);
  452. }
  453. extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
  454. extern void nfs_direct_set_resched_writes(struct nfs_direct_req *dreq);
  455. /* nfs4proc.c */
  456. extern void __nfs4_read_done_cb(struct nfs_pgio_header *);
  457. extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
  458. const struct rpc_timeout *timeparms,
  459. const char *ip_addr);
  460. extern int nfs40_walk_client_list(struct nfs_client *clp,
  461. struct nfs_client **result,
  462. struct rpc_cred *cred);
  463. extern int nfs41_walk_client_list(struct nfs_client *clp,
  464. struct nfs_client **result,
  465. struct rpc_cred *cred);
  466. static inline struct inode *nfs_igrab_and_active(struct inode *inode)
  467. {
  468. inode = igrab(inode);
  469. if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
  470. iput(inode);
  471. inode = NULL;
  472. }
  473. return inode;
  474. }
  475. static inline void nfs_iput_and_deactive(struct inode *inode)
  476. {
  477. if (inode != NULL) {
  478. struct super_block *sb = inode->i_sb;
  479. iput(inode);
  480. nfs_sb_deactive(sb);
  481. }
  482. }
  483. /*
  484. * Determine the device name as a string
  485. */
  486. static inline char *nfs_devname(struct dentry *dentry,
  487. char *buffer, ssize_t buflen)
  488. {
  489. char *dummy;
  490. return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
  491. }
  492. /*
  493. * Determine the actual block size (and log2 thereof)
  494. */
  495. static inline
  496. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  497. {
  498. /* make sure blocksize is a power of two */
  499. if ((bsize & (bsize - 1)) || nrbitsp) {
  500. unsigned char nrbits;
  501. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  502. ;
  503. bsize = 1 << nrbits;
  504. if (nrbitsp)
  505. *nrbitsp = nrbits;
  506. }
  507. return bsize;
  508. }
  509. /*
  510. * Calculate the number of 512byte blocks used.
  511. */
  512. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  513. {
  514. blkcnt_t used = (tsize + 511) >> 9;
  515. return (used > ULONG_MAX) ? ULONG_MAX : used;
  516. }
  517. /*
  518. * Compute and set NFS server blocksize
  519. */
  520. static inline
  521. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  522. {
  523. if (bsize < NFS_MIN_FILE_IO_SIZE)
  524. bsize = NFS_DEF_FILE_IO_SIZE;
  525. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  526. bsize = NFS_MAX_FILE_IO_SIZE;
  527. return nfs_block_bits(bsize, nrbitsp);
  528. }
  529. /*
  530. * Determine the maximum file size for a superblock
  531. */
  532. static inline
  533. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  534. {
  535. sb->s_maxbytes = (loff_t)maxfilesize;
  536. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  537. sb->s_maxbytes = MAX_LFS_FILESIZE;
  538. }
  539. /*
  540. * Record the page as unstable and mark its inode as dirty.
  541. */
  542. static inline
  543. void nfs_mark_page_unstable(struct page *page)
  544. {
  545. struct inode *inode = page_file_mapping(page)->host;
  546. inc_zone_page_state(page, NR_UNSTABLE_NFS);
  547. inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
  548. __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
  549. }
  550. /*
  551. * Determine the number of bytes of data the page contains
  552. */
  553. static inline
  554. unsigned int nfs_page_length(struct page *page)
  555. {
  556. loff_t i_size = i_size_read(page_file_mapping(page)->host);
  557. if (i_size > 0) {
  558. pgoff_t page_index = page_file_index(page);
  559. pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
  560. if (page_index < end_index)
  561. return PAGE_CACHE_SIZE;
  562. if (page_index == end_index)
  563. return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
  564. }
  565. return 0;
  566. }
  567. /*
  568. * Convert a umode to a dirent->d_type
  569. */
  570. static inline
  571. unsigned char nfs_umode_to_dtype(umode_t mode)
  572. {
  573. return (mode >> 12) & 15;
  574. }
  575. /*
  576. * Determine the number of pages in an array of length 'len' and
  577. * with a base offset of 'base'
  578. */
  579. static inline
  580. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  581. {
  582. return ((unsigned long)len + (unsigned long)base +
  583. PAGE_SIZE - 1) >> PAGE_SHIFT;
  584. }
  585. /*
  586. * Convert a struct timespec into a 64-bit change attribute
  587. *
  588. * This does approximately the same thing as timespec_to_ns(),
  589. * but for calculation efficiency, we multiply the seconds by
  590. * 1024*1024*1024.
  591. */
  592. static inline
  593. u64 nfs_timespec_to_change_attr(const struct timespec *ts)
  594. {
  595. return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
  596. }
  597. #ifdef CONFIG_CRC32
  598. /**
  599. * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
  600. * @fh - pointer to filehandle
  601. *
  602. * returns a crc32 hash for the filehandle that is compatible with
  603. * the one displayed by "wireshark".
  604. */
  605. static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
  606. {
  607. return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
  608. }
  609. #else
  610. static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
  611. {
  612. return 0;
  613. }
  614. #endif