internal.h 24 KB

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