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