1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NFS internal definitions
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>
14 #define NFS_SB_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS)
16 extern const struct export_operations nfs_export_ops;
19 struct nfs_pageio_descriptor;
21 static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
23 if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
24 fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
27 static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
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)))
37 * Note: RFC 1813 doesn't limit the number of auth flavors that
38 * a server can return, so make something up.
40 #define NFS_MAX_SECFLAVORS (12)
43 * Value used if the user did not specify a port value.
45 #define NFS_UNSPEC_PORT (-1)
47 #define NFS_UNSPEC_RETRANS (UINT_MAX)
48 #define NFS_UNSPEC_TIMEO (UINT_MAX)
51 * Maximum number of pages that readdir can use for creating
52 * a vmapped array of pages.
54 #define NFS_MAX_READDIR_PAGES 8
56 struct nfs_client_initdata {
57 unsigned long init_flags;
58 const char *hostname; /* Hostname of the server */
59 const struct sockaddr *addr; /* Address of the server */
60 const char *nodename; /* Hostname of the client */
61 const char *ip_addr; /* IP address of the client */
63 struct nfs_subversion *nfs_mod;
66 unsigned int nconnect;
68 const struct rpc_timeout *timeparms;
69 const struct cred *cred;
73 * In-kernel mount arguments
75 struct nfs_fs_context {
77 bool skip_reconfig_option_check;
80 unsigned int flags; /* NFS{,4}_MOUNT_* flags */
81 unsigned int rsize, wsize;
82 unsigned int timeo, retrans;
83 unsigned int acregmin, acregmax;
84 unsigned int acdirmin, acdirmax;
88 struct nfs_auth_info auth_info;
89 rpc_authflavor_t selected_flavor;
92 unsigned int minorversion;
94 unsigned short protofamily;
95 unsigned short mountfamily;
99 struct sockaddr address;
100 struct sockaddr_storage _address;
106 unsigned short protocol;
111 struct sockaddr address;
112 struct sockaddr_storage _address;
118 unsigned short protocol;
119 unsigned short nconnect;
120 unsigned short export_path_len;
123 struct nfs_fh *mntfh;
124 struct nfs_server *server;
125 struct nfs_subversion *nfs_mod;
127 /* Information for a cloned mount. */
128 struct nfs_clone_mount {
129 struct super_block *sb;
130 struct dentry *dentry;
131 struct nfs_fattr *fattr;
132 unsigned int inherited_bsize;
136 #define nfs_errorf(fc, fmt, ...) errorf(fc, fmt, ## __VA_ARGS__)
137 #define nfs_invalf(fc, fmt, ...) invalf(fc, fmt, ## __VA_ARGS__)
138 #define nfs_warnf(fc, fmt, ...) warnf(fc, fmt, ## __VA_ARGS__)
140 static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
142 return fc->fs_private;
146 struct nfs_mount_request {
147 struct sockaddr *sap;
152 unsigned short protocol;
155 unsigned int *auth_flav_len;
156 rpc_authflavor_t *auth_flavs;
160 extern int nfs_mount(struct nfs_mount_request *info);
161 extern void nfs_umount(const struct nfs_mount_request *info);
164 extern const struct rpc_program nfs_program;
165 extern void nfs_clients_init(struct net *net);
166 extern void nfs_clients_exit(struct net *net);
167 extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
168 int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
169 struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
170 int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
171 void nfs_server_insert_lists(struct nfs_server *);
172 void nfs_server_remove_lists(struct nfs_server *);
173 void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
174 int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
176 struct nfs_server *nfs_alloc_server(void);
177 void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
179 extern void nfs_put_client(struct nfs_client *);
180 extern void nfs_free_client(struct nfs_client *);
181 extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
182 extern struct nfs_client *
183 nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
184 struct nfs4_sessionid *, u32);
185 extern struct nfs_server *nfs_create_server(struct fs_context *);
186 extern struct nfs_server *nfs4_create_server(struct fs_context *);
187 extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
188 extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
189 struct sockaddr *sap, size_t salen,
191 extern void nfs_free_server(struct nfs_server *server);
192 extern struct nfs_server *nfs_clone_server(struct nfs_server *,
196 extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
197 extern int nfs_client_init_status(const struct nfs_client *clp);
198 extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
199 extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
200 extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
201 const struct sockaddr *ds_addr,
202 int ds_addrlen, int ds_proto,
203 unsigned int ds_timeo,
204 unsigned int ds_retrans,
206 extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
208 extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
209 const struct sockaddr *ds_addr, int ds_addrlen,
210 int ds_proto, unsigned int ds_timeo,
211 unsigned int ds_retrans);
212 #ifdef CONFIG_PROC_FS
213 extern int __init nfs_fs_proc_init(void);
214 extern void nfs_fs_proc_exit(void);
215 extern int nfs_fs_proc_net_init(struct net *net);
216 extern void nfs_fs_proc_net_exit(struct net *net);
218 static inline int nfs_fs_proc_net_init(struct net *net)
222 static inline void nfs_fs_proc_net_exit(struct net *net)
225 static inline int nfs_fs_proc_init(void)
229 static inline void nfs_fs_proc_exit(void)
235 extern const struct svc_version nfs4_callback_version1;
236 extern const struct svc_version nfs4_callback_version4;
239 extern struct file_system_type nfs_fs_type;
242 extern int __init nfs_init_nfspagecache(void);
243 extern void nfs_destroy_nfspagecache(void);
244 extern int __init nfs_init_readpagecache(void);
245 extern void nfs_destroy_readpagecache(void);
246 extern int __init nfs_init_writepagecache(void);
247 extern void nfs_destroy_writepagecache(void);
249 extern int __init nfs_init_directcache(void);
250 extern void nfs_destroy_directcache(void);
251 extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
252 struct nfs_pgio_header *hdr,
253 void (*release)(struct nfs_pgio_header *hdr));
254 void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
255 int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
257 extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
258 struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
259 void nfs_pgio_header_free(struct nfs_pgio_header *);
260 int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
261 int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
262 const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
263 const struct rpc_call_ops *call_ops, int how, int flags);
264 void nfs_free_request(struct nfs_page *req);
265 struct nfs_pgio_mirror *
266 nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
268 static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
270 WARN_ON_ONCE(desc->pg_mirror_count < 1);
271 return desc->pg_mirror_count > 1;
274 static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
275 const struct nfs_open_context *ctx2)
277 return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
281 extern const struct rpc_procinfo nfs_procedures[];
282 extern int nfs2_decode_dirent(struct xdr_stream *,
283 struct nfs_entry *, bool);
286 extern const struct rpc_procinfo nfs3_procedures[];
287 extern int nfs3_decode_dirent(struct xdr_stream *,
288 struct nfs_entry *, bool);
291 #if IS_ENABLED(CONFIG_NFS_V4)
292 extern int nfs4_decode_dirent(struct xdr_stream *,
293 struct nfs_entry *, bool);
295 #ifdef CONFIG_NFS_V4_1
296 extern const u32 nfs41_maxread_overhead;
297 extern const u32 nfs41_maxwrite_overhead;
298 extern const u32 nfs41_maxgetdevinfo_overhead;
302 #if IS_ENABLED(CONFIG_NFS_V4)
303 extern const struct rpc_procinfo nfs4_procedures[];
306 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
307 extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
308 static inline struct nfs4_label *
309 nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
314 if (src->len > NFS4_MAXLABELLEN)
320 memcpy(dst->label, src->label, src->len);
324 static inline void nfs4_label_free(struct nfs4_label *label)
333 static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
335 if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
336 nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
339 static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
340 static inline void nfs4_label_free(void *label) {}
341 static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
344 static inline struct nfs4_label *
345 nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
349 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
352 void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
353 extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
354 const struct nfs_client_initdata *);
357 extern void nfs_advise_use_readdirplus(struct inode *dir);
358 extern void nfs_force_use_readdirplus(struct inode *dir);
359 extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
360 struct shrink_control *sc);
361 extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
362 struct shrink_control *sc);
363 struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
364 int nfs_create(struct inode *, struct dentry *, umode_t, bool);
365 int nfs_mkdir(struct inode *, struct dentry *, umode_t);
366 int nfs_rmdir(struct inode *, struct dentry *);
367 int nfs_unlink(struct inode *, struct dentry *);
368 int nfs_symlink(struct inode *, struct dentry *, const char *);
369 int nfs_link(struct dentry *, struct inode *, struct dentry *);
370 int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
371 int nfs_rename(struct inode *, struct dentry *,
372 struct inode *, struct dentry *, unsigned int);
375 int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
376 loff_t nfs_file_llseek(struct file *, loff_t, int);
377 ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
378 int nfs_file_mmap(struct file *, struct vm_area_struct *);
379 ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
380 int nfs_file_release(struct inode *, struct file *);
381 int nfs_lock(struct file *, int, struct file_lock *);
382 int nfs_flock(struct file *, int, struct file_lock *);
383 int nfs_check_flags(int);
386 extern struct workqueue_struct *nfsiod_workqueue;
387 extern struct inode *nfs_alloc_inode(struct super_block *sb);
388 extern void nfs_free_inode(struct inode *);
389 extern int nfs_write_inode(struct inode *, struct writeback_control *);
390 extern int nfs_drop_inode(struct inode *);
391 extern void nfs_clear_inode(struct inode *);
392 extern void nfs_evict_inode(struct inode *);
393 void nfs_zap_acl_cache(struct inode *inode);
394 extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
395 extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
396 extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);
399 extern const struct super_operations nfs_sops;
400 bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
401 int nfs_try_get_tree(struct fs_context *);
402 int nfs_get_tree_common(struct fs_context *);
403 void nfs_kill_super(struct super_block *);
405 extern struct rpc_stat nfs_rpcstat;
407 extern int __init register_nfs_fs(void);
408 extern void __exit unregister_nfs_fs(void);
409 extern bool nfs_sb_active(struct super_block *sb);
410 extern void nfs_sb_deactive(struct super_block *sb);
413 extern void nfs_start_io_read(struct inode *inode);
414 extern void nfs_end_io_read(struct inode *inode);
415 extern void nfs_start_io_write(struct inode *inode);
416 extern void nfs_end_io_write(struct inode *inode);
417 extern void nfs_start_io_direct(struct inode *inode);
418 extern void nfs_end_io_direct(struct inode *inode);
420 static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
422 return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
426 #define NFS_PATH_CANONICAL 1
427 extern char *nfs_path(char **p, struct dentry *dentry,
428 char *buffer, ssize_t buflen, unsigned flags);
429 extern struct vfsmount *nfs_d_automount(struct path *path);
430 int nfs_submount(struct fs_context *, struct nfs_server *);
431 int nfs_do_submount(struct fs_context *);
434 extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
435 #if IS_ENABLED(CONFIG_NFS_V4)
436 extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
439 struct nfs_pgio_completion_ops;
441 extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
442 struct inode *inode, bool force_mds,
443 const struct nfs_pgio_completion_ops *compl_ops);
444 extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
445 extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
448 void nfs_umount_begin(struct super_block *);
449 int nfs_statfs(struct dentry *, struct kstatfs *);
450 int nfs_show_options(struct seq_file *, struct dentry *);
451 int nfs_show_devname(struct seq_file *, struct dentry *);
452 int nfs_show_path(struct seq_file *, struct dentry *);
453 int nfs_show_stats(struct seq_file *, struct dentry *);
454 int nfs_reconfigure(struct fs_context *);
457 extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
458 struct inode *inode, int ioflags, bool force_mds,
459 const struct nfs_pgio_completion_ops *compl_ops);
460 extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
461 extern void nfs_commit_free(struct nfs_commit_data *p);
462 extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
463 extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
464 extern int nfs_initiate_commit(struct rpc_clnt *clnt,
465 struct nfs_commit_data *data,
466 const struct nfs_rpc_ops *nfs_ops,
467 const struct rpc_call_ops *call_ops,
469 extern void nfs_init_commit(struct nfs_commit_data *data,
470 struct list_head *head,
471 struct pnfs_layout_segment *lseg,
472 struct nfs_commit_info *cinfo);
473 int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
474 struct nfs_commit_info *cinfo, int max);
475 unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
476 int nfs_scan_commit(struct inode *inode, struct list_head *dst,
477 struct nfs_commit_info *cinfo);
478 void nfs_mark_request_commit(struct nfs_page *req,
479 struct pnfs_layout_segment *lseg,
480 struct nfs_commit_info *cinfo,
482 int nfs_write_need_commit(struct nfs_pgio_header *);
483 void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
484 int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
485 int how, struct nfs_commit_info *cinfo);
486 void nfs_retry_commit(struct list_head *page_list,
487 struct pnfs_layout_segment *lseg,
488 struct nfs_commit_info *cinfo,
490 void nfs_commitdata_release(struct nfs_commit_data *data);
491 void nfs_request_add_commit_list(struct nfs_page *req,
492 struct nfs_commit_info *cinfo);
493 void nfs_request_add_commit_list_locked(struct nfs_page *req,
494 struct list_head *dst,
495 struct nfs_commit_info *cinfo);
496 void nfs_request_remove_commit_list(struct nfs_page *req,
497 struct nfs_commit_info *cinfo);
498 void nfs_init_cinfo(struct nfs_commit_info *cinfo,
500 struct nfs_direct_req *dreq);
501 int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
502 bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
503 void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
505 int nfs_filemap_write_and_wait_range(struct address_space *mapping,
506 loff_t lstart, loff_t lend);
508 #ifdef CONFIG_NFS_V4_1
510 void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
514 for (i = 0; i < cinfo->nbuckets; i++)
515 cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
519 void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
524 #ifdef CONFIG_MIGRATION
525 extern int nfs_migrate_page(struct address_space *,
526 struct page *, struct page *, enum migrate_mode);
530 nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
531 const struct nfs_write_verifier *v2)
533 return memcmp(v1->data, v2->data, sizeof(v1->data));
537 extern struct rpc_task *
538 nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
539 struct dentry *old_dentry, struct dentry *new_dentry,
540 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
541 extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
544 void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
545 struct nfs_direct_req *dreq);
546 extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
549 extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
550 const struct nfs_client_initdata *);
551 extern int nfs40_walk_client_list(struct nfs_client *clp,
552 struct nfs_client **result,
553 const struct cred *cred);
554 extern int nfs41_walk_client_list(struct nfs_client *clp,
555 struct nfs_client **result,
556 const struct cred *cred);
557 extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
558 struct rpc_xprt *xprt,
561 static inline struct inode *nfs_igrab_and_active(struct inode *inode)
563 inode = igrab(inode);
564 if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
571 static inline void nfs_iput_and_deactive(struct inode *inode)
574 struct super_block *sb = inode->i_sb;
582 * Determine the device name as a string
584 static inline char *nfs_devname(struct dentry *dentry,
585 char *buffer, ssize_t buflen)
588 return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
592 * Determine the actual block size (and log2 thereof)
595 unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
597 /* make sure blocksize is a power of two */
598 if ((bsize & (bsize - 1)) || nrbitsp) {
599 unsigned char nrbits;
601 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
612 * Calculate the number of 512byte blocks used.
614 static inline blkcnt_t nfs_calc_block_size(u64 tsize)
616 blkcnt_t used = (tsize + 511) >> 9;
617 return (used > ULONG_MAX) ? ULONG_MAX : used;
621 * Compute and set NFS server blocksize
624 unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
626 if (bsize < NFS_MIN_FILE_IO_SIZE)
627 bsize = NFS_DEF_FILE_IO_SIZE;
628 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
629 bsize = NFS_MAX_FILE_IO_SIZE;
631 return nfs_block_bits(bsize, nrbitsp);
635 * Determine the maximum file size for a superblock
638 void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
640 sb->s_maxbytes = (loff_t)maxfilesize;
641 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
642 sb->s_maxbytes = MAX_LFS_FILESIZE;
646 * Record the page as unstable and mark its inode as dirty.
649 void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
652 struct inode *inode = page_file_mapping(page)->host;
654 inc_node_page_state(page, NR_UNSTABLE_NFS);
655 inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
656 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
661 * Determine the number of bytes of data the page contains
664 unsigned int nfs_page_length(struct page *page)
666 loff_t i_size = i_size_read(page_file_mapping(page)->host);
669 pgoff_t index = page_index(page);
670 pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
671 if (index < end_index)
673 if (index == end_index)
674 return ((i_size - 1) & ~PAGE_MASK) + 1;
680 * Convert a umode to a dirent->d_type
683 unsigned char nfs_umode_to_dtype(umode_t mode)
685 return (mode >> 12) & 15;
689 * Determine the number of pages in an array of length 'len' and
690 * with a base offset of 'base'
693 unsigned int nfs_page_array_len(unsigned int base, size_t len)
695 return ((unsigned long)len + (unsigned long)base +
696 PAGE_SIZE - 1) >> PAGE_SHIFT;
700 * Convert a struct timespec64 into a 64-bit change attribute
702 * This does approximately the same thing as timespec64_to_ns(),
703 * but for calculation efficiency, we multiply the seconds by
707 u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
709 return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
714 * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
715 * @fh - pointer to filehandle
717 * returns a crc32 hash for the filehandle that is compatible with
718 * the one displayed by "wireshark".
720 static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
722 return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
724 static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
726 return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
727 NFS4_STATEID_OTHER_SIZE);
730 static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
734 static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
740 static inline bool nfs_error_is_fatal(int err)
761 static inline bool nfs_error_is_fatal_on_server(int err)
769 return nfs_error_is_fatal(err);
773 * Select between a default port value and a user-specified port value.
774 * If a zero value is set, then autobind will be used.
776 static inline void nfs_set_port(struct sockaddr *sap, int *port,
777 const unsigned short default_port)
779 if (*port == NFS_UNSPEC_PORT)
780 *port = default_port;
782 rpc_set_port(sap, *port);