internal.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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. #define NFS_UNSPEC_RETRANS (UINT_MAX)
  52. #define NFS_UNSPEC_TIMEO (UINT_MAX)
  53. /*
  54. * Maximum number of pages that readdir can use for creating
  55. * a vmapped array of pages.
  56. */
  57. #define NFS_MAX_READDIR_PAGES 8
  58. struct nfs_client_initdata {
  59. unsigned long init_flags;
  60. const char *hostname; /* Hostname of the server */
  61. const struct sockaddr *addr; /* Address of the server */
  62. const char *nodename; /* Hostname of the client */
  63. const char *ip_addr; /* IP address of the client */
  64. size_t addrlen;
  65. struct nfs_subversion *nfs_mod;
  66. int proto;
  67. u32 minorversion;
  68. struct net *net;
  69. const struct rpc_timeout *timeparms;
  70. };
  71. /*
  72. * In-kernel mount arguments
  73. */
  74. struct nfs_parsed_mount_data {
  75. int flags;
  76. unsigned int rsize, wsize;
  77. unsigned int timeo, retrans;
  78. unsigned int acregmin, acregmax,
  79. acdirmin, acdirmax;
  80. unsigned int namlen;
  81. unsigned int options;
  82. unsigned int bsize;
  83. struct nfs_auth_info auth_info;
  84. rpc_authflavor_t selected_flavor;
  85. char *client_address;
  86. unsigned int version;
  87. unsigned int minorversion;
  88. char *fscache_uniq;
  89. bool need_mount;
  90. struct {
  91. struct sockaddr_storage address;
  92. size_t addrlen;
  93. char *hostname;
  94. u32 version;
  95. int port;
  96. unsigned short protocol;
  97. } mount_server;
  98. struct {
  99. struct sockaddr_storage address;
  100. size_t addrlen;
  101. char *hostname;
  102. char *export_path;
  103. int port;
  104. unsigned short protocol;
  105. } nfs_server;
  106. struct security_mnt_opts lsm_opts;
  107. struct net *net;
  108. };
  109. /* mount_clnt.c */
  110. struct nfs_mount_request {
  111. struct sockaddr *sap;
  112. size_t salen;
  113. char *hostname;
  114. char *dirpath;
  115. u32 version;
  116. unsigned short protocol;
  117. struct nfs_fh *fh;
  118. int noresvport;
  119. unsigned int *auth_flav_len;
  120. rpc_authflavor_t *auth_flavs;
  121. struct net *net;
  122. };
  123. struct nfs_mount_info {
  124. void (*fill_super)(struct super_block *, struct nfs_mount_info *);
  125. int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
  126. struct nfs_parsed_mount_data *parsed;
  127. struct nfs_clone_mount *cloned;
  128. struct nfs_fh *mntfh;
  129. };
  130. extern int nfs_mount(struct nfs_mount_request *info);
  131. extern void nfs_umount(const struct nfs_mount_request *info);
  132. /* client.c */
  133. extern const struct rpc_program nfs_program;
  134. extern void nfs_clients_init(struct net *net);
  135. extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
  136. int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
  137. struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
  138. int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
  139. void nfs_server_insert_lists(struct nfs_server *);
  140. void nfs_server_remove_lists(struct nfs_server *);
  141. void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
  142. int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
  143. rpc_authflavor_t);
  144. struct nfs_server *nfs_alloc_server(void);
  145. void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
  146. extern void nfs_cleanup_cb_ident_idr(struct net *);
  147. extern void nfs_put_client(struct nfs_client *);
  148. extern void nfs_free_client(struct nfs_client *);
  149. extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
  150. extern struct nfs_client *
  151. nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
  152. struct nfs4_sessionid *, u32);
  153. extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
  154. struct nfs_subversion *);
  155. extern struct nfs_server *nfs4_create_server(
  156. struct nfs_mount_info *,
  157. struct nfs_subversion *);
  158. extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
  159. struct nfs_fh *);
  160. extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
  161. struct sockaddr *sap, size_t salen,
  162. struct net *net);
  163. extern void nfs_free_server(struct nfs_server *server);
  164. extern struct nfs_server *nfs_clone_server(struct nfs_server *,
  165. struct nfs_fh *,
  166. struct nfs_fattr *,
  167. rpc_authflavor_t);
  168. extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
  169. extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
  170. extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
  171. const struct sockaddr *ds_addr,
  172. int ds_addrlen, int ds_proto,
  173. unsigned int ds_timeo,
  174. unsigned int ds_retrans,
  175. u32 minor_version);
  176. extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
  177. struct inode *);
  178. extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
  179. const struct sockaddr *ds_addr, int ds_addrlen,
  180. int ds_proto, unsigned int ds_timeo,
  181. unsigned int ds_retrans);
  182. #ifdef CONFIG_PROC_FS
  183. extern int __init nfs_fs_proc_init(void);
  184. extern void nfs_fs_proc_exit(void);
  185. extern int nfs_fs_proc_net_init(struct net *net);
  186. extern void nfs_fs_proc_net_exit(struct net *net);
  187. #else
  188. static inline int nfs_fs_proc_net_init(struct net *net)
  189. {
  190. return 0;
  191. }
  192. static inline void nfs_fs_proc_net_exit(struct net *net)
  193. {
  194. }
  195. static inline int nfs_fs_proc_init(void)
  196. {
  197. return 0;
  198. }
  199. static inline void nfs_fs_proc_exit(void)
  200. {
  201. }
  202. #endif
  203. /* callback_xdr.c */
  204. extern struct svc_version nfs4_callback_version1;
  205. extern struct svc_version nfs4_callback_version4;
  206. struct nfs_pageio_descriptor;
  207. /* pagelist.c */
  208. extern int __init nfs_init_nfspagecache(void);
  209. extern void nfs_destroy_nfspagecache(void);
  210. extern int __init nfs_init_readpagecache(void);
  211. extern void nfs_destroy_readpagecache(void);
  212. extern int __init nfs_init_writepagecache(void);
  213. extern void nfs_destroy_writepagecache(void);
  214. extern int __init nfs_init_directcache(void);
  215. extern void nfs_destroy_directcache(void);
  216. extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
  217. struct nfs_pgio_header *hdr,
  218. void (*release)(struct nfs_pgio_header *hdr));
  219. void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
  220. int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
  221. extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
  222. struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
  223. void nfs_pgio_header_free(struct nfs_pgio_header *);
  224. void nfs_pgio_data_destroy(struct nfs_pgio_header *);
  225. int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
  226. int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
  227. struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops,
  228. const struct rpc_call_ops *call_ops, int how, int flags);
  229. void nfs_free_request(struct nfs_page *req);
  230. struct nfs_pgio_mirror *
  231. nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
  232. static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
  233. {
  234. WARN_ON_ONCE(desc->pg_mirror_count < 1);
  235. return desc->pg_mirror_count > 1;
  236. }
  237. static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
  238. const struct nfs_open_context *ctx2)
  239. {
  240. return ctx1->cred == ctx2->cred && ctx1->state == ctx2->state;
  241. }
  242. /* nfs2xdr.c */
  243. extern struct rpc_procinfo nfs_procedures[];
  244. extern int nfs2_decode_dirent(struct xdr_stream *,
  245. struct nfs_entry *, int);
  246. /* nfs3xdr.c */
  247. extern struct rpc_procinfo nfs3_procedures[];
  248. extern int nfs3_decode_dirent(struct xdr_stream *,
  249. struct nfs_entry *, int);
  250. /* nfs4xdr.c */
  251. #if IS_ENABLED(CONFIG_NFS_V4)
  252. extern int nfs4_decode_dirent(struct xdr_stream *,
  253. struct nfs_entry *, int);
  254. #endif
  255. #ifdef CONFIG_NFS_V4_1
  256. extern const u32 nfs41_maxread_overhead;
  257. extern const u32 nfs41_maxwrite_overhead;
  258. extern const u32 nfs41_maxgetdevinfo_overhead;
  259. #endif
  260. /* nfs4proc.c */
  261. #if IS_ENABLED(CONFIG_NFS_V4)
  262. extern struct rpc_procinfo nfs4_procedures[];
  263. #endif
  264. #ifdef CONFIG_NFS_V4_SECURITY_LABEL
  265. extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
  266. static inline struct nfs4_label *
  267. nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
  268. {
  269. if (!dst || !src)
  270. return NULL;
  271. if (src->len > NFS4_MAXLABELLEN)
  272. return NULL;
  273. dst->lfs = src->lfs;
  274. dst->pi = src->pi;
  275. dst->len = src->len;
  276. memcpy(dst->label, src->label, src->len);
  277. return dst;
  278. }
  279. static inline void nfs4_label_free(struct nfs4_label *label)
  280. {
  281. if (label) {
  282. kfree(label->label);
  283. kfree(label);
  284. }
  285. return;
  286. }
  287. static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
  288. {
  289. if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
  290. nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
  291. }
  292. #else
  293. static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
  294. static inline void nfs4_label_free(void *label) {}
  295. static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
  296. {
  297. }
  298. static inline struct nfs4_label *
  299. nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
  300. {
  301. return NULL;
  302. }
  303. #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
  304. /* proc.c */
  305. void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
  306. extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
  307. const struct nfs_client_initdata *);
  308. /* dir.c */
  309. extern void nfs_force_use_readdirplus(struct inode *dir);
  310. extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
  311. struct shrink_control *sc);
  312. extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
  313. struct shrink_control *sc);
  314. struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
  315. int nfs_create(struct inode *, struct dentry *, umode_t, bool);
  316. int nfs_mkdir(struct inode *, struct dentry *, umode_t);
  317. int nfs_rmdir(struct inode *, struct dentry *);
  318. int nfs_unlink(struct inode *, struct dentry *);
  319. int nfs_symlink(struct inode *, struct dentry *, const char *);
  320. int nfs_link(struct dentry *, struct inode *, struct dentry *);
  321. int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
  322. int nfs_rename(struct inode *, struct dentry *,
  323. struct inode *, struct dentry *, unsigned int);
  324. /* file.c */
  325. int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
  326. loff_t nfs_file_llseek(struct file *, loff_t, int);
  327. ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
  328. int nfs_file_mmap(struct file *, struct vm_area_struct *);
  329. ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
  330. int nfs_file_release(struct inode *, struct file *);
  331. int nfs_lock(struct file *, int, struct file_lock *);
  332. int nfs_flock(struct file *, int, struct file_lock *);
  333. int nfs_check_flags(int);
  334. /* inode.c */
  335. extern struct workqueue_struct *nfsiod_workqueue;
  336. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  337. extern void nfs_destroy_inode(struct inode *);
  338. extern int nfs_write_inode(struct inode *, struct writeback_control *);
  339. extern int nfs_drop_inode(struct inode *);
  340. extern void nfs_clear_inode(struct inode *);
  341. extern void nfs_evict_inode(struct inode *);
  342. void nfs_zap_acl_cache(struct inode *inode);
  343. extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
  344. extern int nfs_wait_atomic_killable(atomic_t *p);
  345. /* super.c */
  346. extern const struct super_operations nfs_sops;
  347. extern struct file_system_type nfs_fs_type;
  348. extern struct file_system_type nfs_xdev_fs_type;
  349. #if IS_ENABLED(CONFIG_NFS_V4)
  350. extern struct file_system_type nfs4_xdev_fs_type;
  351. extern struct file_system_type nfs4_referral_fs_type;
  352. #endif
  353. bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
  354. struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *,
  355. struct nfs_subversion *);
  356. void nfs_initialise_sb(struct super_block *);
  357. int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
  358. int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
  359. struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *,
  360. struct nfs_mount_info *, struct nfs_subversion *);
  361. struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
  362. struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
  363. const char *, struct nfs_mount_info *);
  364. void nfs_kill_super(struct super_block *);
  365. void nfs_fill_super(struct super_block *, struct nfs_mount_info *);
  366. extern struct rpc_stat nfs_rpcstat;
  367. extern int __init register_nfs_fs(void);
  368. extern void __exit unregister_nfs_fs(void);
  369. extern bool nfs_sb_active(struct super_block *sb);
  370. extern void nfs_sb_deactive(struct super_block *sb);
  371. /* io.c */
  372. extern void nfs_start_io_read(struct inode *inode);
  373. extern void nfs_end_io_read(struct inode *inode);
  374. extern void nfs_start_io_write(struct inode *inode);
  375. extern void nfs_end_io_write(struct inode *inode);
  376. extern void nfs_start_io_direct(struct inode *inode);
  377. extern void nfs_end_io_direct(struct inode *inode);
  378. static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
  379. {
  380. return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
  381. }
  382. /* namespace.c */
  383. #define NFS_PATH_CANONICAL 1
  384. extern char *nfs_path(char **p, struct dentry *dentry,
  385. char *buffer, ssize_t buflen, unsigned flags);
  386. extern struct vfsmount *nfs_d_automount(struct path *path);
  387. struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
  388. struct nfs_fh *, struct nfs_fattr *);
  389. struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
  390. struct nfs_fattr *, rpc_authflavor_t);
  391. /* getroot.c */
  392. extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
  393. const char *);
  394. #if IS_ENABLED(CONFIG_NFS_V4)
  395. extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
  396. const char *);
  397. extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
  398. #endif
  399. struct nfs_pgio_completion_ops;
  400. /* read.c */
  401. extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
  402. struct inode *inode, bool force_mds,
  403. const struct nfs_pgio_completion_ops *compl_ops);
  404. extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
  405. extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
  406. /* super.c */
  407. void nfs_clone_super(struct super_block *, struct nfs_mount_info *);
  408. void nfs_umount_begin(struct super_block *);
  409. int nfs_statfs(struct dentry *, struct kstatfs *);
  410. int nfs_show_options(struct seq_file *, struct dentry *);
  411. int nfs_show_devname(struct seq_file *, struct dentry *);
  412. int nfs_show_path(struct seq_file *, struct dentry *);
  413. int nfs_show_stats(struct seq_file *, struct dentry *);
  414. int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
  415. /* write.c */
  416. extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
  417. struct inode *inode, int ioflags, bool force_mds,
  418. const struct nfs_pgio_completion_ops *compl_ops);
  419. extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
  420. extern void nfs_commit_free(struct nfs_commit_data *p);
  421. extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
  422. extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
  423. extern int nfs_initiate_commit(struct rpc_clnt *clnt,
  424. struct nfs_commit_data *data,
  425. const struct nfs_rpc_ops *nfs_ops,
  426. const struct rpc_call_ops *call_ops,
  427. int how, int flags);
  428. extern void nfs_init_commit(struct nfs_commit_data *data,
  429. struct list_head *head,
  430. struct pnfs_layout_segment *lseg,
  431. struct nfs_commit_info *cinfo);
  432. int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
  433. struct nfs_commit_info *cinfo, int max);
  434. unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
  435. int nfs_scan_commit(struct inode *inode, struct list_head *dst,
  436. struct nfs_commit_info *cinfo);
  437. void nfs_mark_request_commit(struct nfs_page *req,
  438. struct pnfs_layout_segment *lseg,
  439. struct nfs_commit_info *cinfo,
  440. u32 ds_commit_idx);
  441. int nfs_write_need_commit(struct nfs_pgio_header *);
  442. void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
  443. int nfs_commit_file(struct file *file, struct nfs_write_verifier *verf);
  444. int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
  445. int how, struct nfs_commit_info *cinfo);
  446. void nfs_retry_commit(struct list_head *page_list,
  447. struct pnfs_layout_segment *lseg,
  448. struct nfs_commit_info *cinfo,
  449. u32 ds_commit_idx);
  450. void nfs_commitdata_release(struct nfs_commit_data *data);
  451. void nfs_request_add_commit_list(struct nfs_page *req,
  452. struct nfs_commit_info *cinfo);
  453. void nfs_request_add_commit_list_locked(struct nfs_page *req,
  454. struct list_head *dst,
  455. struct nfs_commit_info *cinfo);
  456. void nfs_request_remove_commit_list(struct nfs_page *req,
  457. struct nfs_commit_info *cinfo);
  458. void nfs_init_cinfo(struct nfs_commit_info *cinfo,
  459. struct inode *inode,
  460. struct nfs_direct_req *dreq);
  461. int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
  462. bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
  463. void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
  464. int nfs_filemap_write_and_wait_range(struct address_space *mapping,
  465. loff_t lstart, loff_t lend);
  466. #ifdef CONFIG_NFS_V4_1
  467. static inline
  468. void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
  469. {
  470. int i;
  471. for (i = 0; i < cinfo->nbuckets; i++)
  472. cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
  473. }
  474. #else
  475. static inline
  476. void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
  477. {
  478. }
  479. #endif
  480. #ifdef CONFIG_MIGRATION
  481. extern int nfs_migrate_page(struct address_space *,
  482. struct page *, struct page *, enum migrate_mode);
  483. #endif
  484. static inline int
  485. nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
  486. const struct nfs_write_verifier *v2)
  487. {
  488. return memcmp(v1->data, v2->data, sizeof(v1->data));
  489. }
  490. /* unlink.c */
  491. extern struct rpc_task *
  492. nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
  493. struct dentry *old_dentry, struct dentry *new_dentry,
  494. void (*complete)(struct rpc_task *, struct nfs_renamedata *));
  495. extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
  496. /* direct.c */
  497. void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
  498. struct nfs_direct_req *dreq);
  499. extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
  500. /* nfs4proc.c */
  501. extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
  502. const struct nfs_client_initdata *);
  503. extern int nfs40_walk_client_list(struct nfs_client *clp,
  504. struct nfs_client **result,
  505. struct rpc_cred *cred);
  506. extern int nfs41_walk_client_list(struct nfs_client *clp,
  507. struct nfs_client **result,
  508. struct rpc_cred *cred);
  509. extern int nfs4_test_session_trunk(struct rpc_clnt *,
  510. struct rpc_xprt *,
  511. void *);
  512. static inline struct inode *nfs_igrab_and_active(struct inode *inode)
  513. {
  514. inode = igrab(inode);
  515. if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
  516. iput(inode);
  517. inode = NULL;
  518. }
  519. return inode;
  520. }
  521. static inline void nfs_iput_and_deactive(struct inode *inode)
  522. {
  523. if (inode != NULL) {
  524. struct super_block *sb = inode->i_sb;
  525. iput(inode);
  526. nfs_sb_deactive(sb);
  527. }
  528. }
  529. /*
  530. * Determine the device name as a string
  531. */
  532. static inline char *nfs_devname(struct dentry *dentry,
  533. char *buffer, ssize_t buflen)
  534. {
  535. char *dummy;
  536. return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
  537. }
  538. /*
  539. * Determine the actual block size (and log2 thereof)
  540. */
  541. static inline
  542. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  543. {
  544. /* make sure blocksize is a power of two */
  545. if ((bsize & (bsize - 1)) || nrbitsp) {
  546. unsigned char nrbits;
  547. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  548. ;
  549. bsize = 1 << nrbits;
  550. if (nrbitsp)
  551. *nrbitsp = nrbits;
  552. }
  553. return bsize;
  554. }
  555. /*
  556. * Calculate the number of 512byte blocks used.
  557. */
  558. static inline blkcnt_t nfs_calc_block_size(u64 tsize)
  559. {
  560. blkcnt_t used = (tsize + 511) >> 9;
  561. return (used > ULONG_MAX) ? ULONG_MAX : used;
  562. }
  563. /*
  564. * Compute and set NFS server blocksize
  565. */
  566. static inline
  567. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  568. {
  569. if (bsize < NFS_MIN_FILE_IO_SIZE)
  570. bsize = NFS_DEF_FILE_IO_SIZE;
  571. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  572. bsize = NFS_MAX_FILE_IO_SIZE;
  573. return nfs_block_bits(bsize, nrbitsp);
  574. }
  575. /*
  576. * Determine the maximum file size for a superblock
  577. */
  578. static inline
  579. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  580. {
  581. sb->s_maxbytes = (loff_t)maxfilesize;
  582. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  583. sb->s_maxbytes = MAX_LFS_FILESIZE;
  584. }
  585. /*
  586. * Record the page as unstable and mark its inode as dirty.
  587. */
  588. static inline
  589. void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
  590. {
  591. if (!cinfo->dreq) {
  592. struct inode *inode = page_file_mapping(page)->host;
  593. inc_node_page_state(page, NR_UNSTABLE_NFS);
  594. inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
  595. __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
  596. }
  597. }
  598. /*
  599. * Determine the number of bytes of data the page contains
  600. */
  601. static inline
  602. unsigned int nfs_page_length(struct page *page)
  603. {
  604. loff_t i_size = i_size_read(page_file_mapping(page)->host);
  605. if (i_size > 0) {
  606. pgoff_t index = page_index(page);
  607. pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
  608. if (index < end_index)
  609. return PAGE_SIZE;
  610. if (index == end_index)
  611. return ((i_size - 1) & ~PAGE_MASK) + 1;
  612. }
  613. return 0;
  614. }
  615. /*
  616. * Convert a umode to a dirent->d_type
  617. */
  618. static inline
  619. unsigned char nfs_umode_to_dtype(umode_t mode)
  620. {
  621. return (mode >> 12) & 15;
  622. }
  623. /*
  624. * Determine the number of pages in an array of length 'len' and
  625. * with a base offset of 'base'
  626. */
  627. static inline
  628. unsigned int nfs_page_array_len(unsigned int base, size_t len)
  629. {
  630. return ((unsigned long)len + (unsigned long)base +
  631. PAGE_SIZE - 1) >> PAGE_SHIFT;
  632. }
  633. /*
  634. * Convert a struct timespec into a 64-bit change attribute
  635. *
  636. * This does approximately the same thing as timespec_to_ns(),
  637. * but for calculation efficiency, we multiply the seconds by
  638. * 1024*1024*1024.
  639. */
  640. static inline
  641. u64 nfs_timespec_to_change_attr(const struct timespec *ts)
  642. {
  643. return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
  644. }
  645. #ifdef CONFIG_CRC32
  646. /**
  647. * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
  648. * @fh - pointer to filehandle
  649. *
  650. * returns a crc32 hash for the filehandle that is compatible with
  651. * the one displayed by "wireshark".
  652. */
  653. static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
  654. {
  655. return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
  656. }
  657. static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
  658. {
  659. return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
  660. NFS4_STATEID_OTHER_SIZE);
  661. }
  662. #else
  663. static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
  664. {
  665. return 0;
  666. }
  667. static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
  668. {
  669. return 0;
  670. }
  671. #endif
  672. static inline bool nfs_error_is_fatal(int err)
  673. {
  674. switch (err) {
  675. case -ERESTARTSYS:
  676. case -EIO:
  677. case -ENOSPC:
  678. case -EROFS:
  679. case -E2BIG:
  680. return true;
  681. default:
  682. return false;
  683. }
  684. }