xref: /openbmc/linux/fs/nfs/internal.h (revision f4eecd5d)
1f7b422b1SDavid Howells /*
2f7b422b1SDavid Howells  * NFS internal definitions
3f7b422b1SDavid Howells  */
4f7b422b1SDavid Howells 
5eedc020eSAndy Adamson #include "nfs4_fs.h"
6f7b422b1SDavid Howells #include <linux/mount.h>
7f9c3a380SEric Paris #include <linux/security.h>
8f7b422b1SDavid Howells 
908734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1008734048SDavid Howells 
1154ceac45SDavid Howells struct nfs_string;
1254ceac45SDavid Howells 
1354ceac45SDavid Howells /* Maximum number of readahead requests
1454ceac45SDavid Howells  * FIXME: this should really be a sysctl so that users may tune it to suit
1554ceac45SDavid Howells  *        their needs. People that do NFS over a slow network, might for
1654ceac45SDavid Howells  *        instance want to reduce it to something closer to 1 for improved
1754ceac45SDavid Howells  *        interactive response.
1854ceac45SDavid Howells  */
1954ceac45SDavid Howells #define NFS_MAX_READAHEAD	(RPC_DEF_SLOT_TABLE - 1)
2054ceac45SDavid Howells 
21eedc020eSAndy Adamson /*
22eedc020eSAndy Adamson  * Determine if sessions are in use.
23eedc020eSAndy Adamson  */
24eedc020eSAndy Adamson static inline int nfs4_has_session(const struct nfs_client *clp)
25eedc020eSAndy Adamson {
26eedc020eSAndy Adamson #ifdef CONFIG_NFS_V4_1
27eedc020eSAndy Adamson 	if (clp->cl_session)
28eedc020eSAndy Adamson 		return 1;
29eedc020eSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
30eedc020eSAndy Adamson 	return 0;
31eedc020eSAndy Adamson }
32eedc020eSAndy Adamson 
33d8cb1a7cSAlexandros Batsakis static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
34d8cb1a7cSAlexandros Batsakis {
35d8cb1a7cSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
36d8cb1a7cSAlexandros Batsakis 	if (nfs4_has_session(clp))
37d8cb1a7cSAlexandros Batsakis 		return (clp->cl_session->flags & SESSION4_PERSIST);
38d8cb1a7cSAlexandros Batsakis #endif /* CONFIG_NFS_V4_1 */
39d8cb1a7cSAlexandros Batsakis 	return 0;
40d8cb1a7cSAlexandros Batsakis }
41d8cb1a7cSAlexandros Batsakis 
42f7b422b1SDavid Howells struct nfs_clone_mount {
43f7b422b1SDavid Howells 	const struct super_block *sb;
44f7b422b1SDavid Howells 	const struct dentry *dentry;
45f7b422b1SDavid Howells 	struct nfs_fh *fh;
46f7b422b1SDavid Howells 	struct nfs_fattr *fattr;
47f7b422b1SDavid Howells 	char *hostname;
48f7b422b1SDavid Howells 	char *mnt_path;
496677d095SChuck Lever 	struct sockaddr *addr;
506677d095SChuck Lever 	size_t addrlen;
51f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
52f7b422b1SDavid Howells };
53f7b422b1SDavid Howells 
546b18eaa0S\"Talpey, Thomas\ /*
55a14017dbSChuck Lever  * Note: RFC 1813 doesn't limit the number of auth flavors that
56a14017dbSChuck Lever  * a server can return, so make something up.
57a14017dbSChuck Lever  */
58a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS	(12)
59a14017dbSChuck Lever 
60a14017dbSChuck Lever /*
614cfd74fcSChuck Lever  * Value used if the user did not specify a port value.
624cfd74fcSChuck Lever  */
634cfd74fcSChuck Lever #define NFS_UNSPEC_PORT		(-1)
644cfd74fcSChuck Lever 
654cfd74fcSChuck Lever /*
6656e4ebf8SBryan Schumaker  * Maximum number of pages that readdir can use for creating
6756e4ebf8SBryan Schumaker  * a vmapped array of pages.
6856e4ebf8SBryan Schumaker  */
6956e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8
7056e4ebf8SBryan Schumaker 
7156e4ebf8SBryan Schumaker /*
726b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
736b18eaa0S\"Talpey, Thomas\  */
746b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data {
756b18eaa0S\"Talpey, Thomas\ 	int			flags;
766b18eaa0S\"Talpey, Thomas\ 	int			rsize, wsize;
776b18eaa0S\"Talpey, Thomas\ 	int			timeo, retrans;
786b18eaa0S\"Talpey, Thomas\ 	int			acregmin, acregmax,
796b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
806b18eaa0S\"Talpey, Thomas\ 	int			namlen;
81b797cac7SDavid Howells 	unsigned int		options;
826b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
836b18eaa0S\"Talpey, Thomas\ 	unsigned int		auth_flavor_len;
846b18eaa0S\"Talpey, Thomas\ 	rpc_authflavor_t	auth_flavors[1];
856b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
86764302ccSChuck Lever 	unsigned int		version;
873fd5be9eSMike Sager 	unsigned int		minorversion;
8808734048SDavid Howells 	char			*fscache_uniq;
896b18eaa0S\"Talpey, Thomas\ 
906b18eaa0S\"Talpey, Thomas\ 	struct {
914c568017SChuck Lever 		struct sockaddr_storage	address;
924c568017SChuck Lever 		size_t			addrlen;
936b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
9478fa701fSChuck Lever 		u32			version;
954cfd74fcSChuck Lever 		int			port;
9678fa701fSChuck Lever 		unsigned short		protocol;
976b18eaa0S\"Talpey, Thomas\ 	} mount_server;
986b18eaa0S\"Talpey, Thomas\ 
996b18eaa0S\"Talpey, Thomas\ 	struct {
1004c568017SChuck Lever 		struct sockaddr_storage	address;
1014c568017SChuck Lever 		size_t			addrlen;
1026b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1036b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1044cfd74fcSChuck Lever 		int			port;
10578fa701fSChuck Lever 		unsigned short		protocol;
1066b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
107f9c3a380SEric Paris 
108f9c3a380SEric Paris 	struct security_mnt_opts lsm_opts;
1096b18eaa0S\"Talpey, Thomas\ };
1106b18eaa0S\"Talpey, Thomas\ 
111146ec944SChuck Lever /* mount_clnt.c */
112c5d120f8SChuck Lever struct nfs_mount_request {
113c5d120f8SChuck Lever 	struct sockaddr		*sap;
114c5d120f8SChuck Lever 	size_t			salen;
115c5d120f8SChuck Lever 	char			*hostname;
116c5d120f8SChuck Lever 	char			*dirpath;
117c5d120f8SChuck Lever 	u32			version;
118c5d120f8SChuck Lever 	unsigned short		protocol;
119c5d120f8SChuck Lever 	struct nfs_fh		*fh;
12050a737f8SChuck Lever 	int			noresvport;
1218e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1228e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
123c5d120f8SChuck Lever };
124c5d120f8SChuck Lever 
125c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info);
1260b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
127146ec944SChuck Lever 
12824c8dbbbSDavid Howells /* client.c */
12954ceac45SDavid Howells extern struct rpc_program nfs_program;
13054ceac45SDavid Howells 
131f4eecd5dSAndy Adamson extern void nfs_cleanup_cb_ident_idr(void);
13224c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
133ff052645SChuck Lever extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
1343fbd67adSTrond Myklebust extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
1352283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server(
1362283f8d6S\"Talpey, Thomas\ 					const struct nfs_parsed_mount_data *,
13754ceac45SDavid Howells 					struct nfs_fh *);
13891ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server(
13991ea40b9S\"Talpey, Thomas\ 					const struct nfs_parsed_mount_data *,
14054ceac45SDavid Howells 					struct nfs_fh *);
14154ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
14254ceac45SDavid Howells 						      struct nfs_fh *);
14354ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
14454ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
14554ceac45SDavid Howells 					   struct nfs_fh *,
14654ceac45SDavid Howells 					   struct nfs_fattr *);
14776db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
148008f55d0SBenny Halevy extern int nfs4_check_client_ready(struct nfs_client *clp);
1496aaca566SDavid Howells #ifdef CONFIG_PROC_FS
1506aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
1516aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
1526aaca566SDavid Howells #else
1536aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
1546aaca566SDavid Howells {
1556aaca566SDavid Howells 	return 0;
1566aaca566SDavid Howells }
1576aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
1586aaca566SDavid Howells {
1596aaca566SDavid Howells }
1606aaca566SDavid Howells #endif
16124c8dbbbSDavid Howells 
1627d4e2747SDavid Howells /* nfs4namespace.c */
163f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
164f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
165f7b422b1SDavid Howells #else
166f7b422b1SDavid Howells static inline
167f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
168f7b422b1SDavid Howells {
169f7b422b1SDavid Howells 	return ERR_PTR(-ENOENT);
170f7b422b1SDavid Howells }
171f7b422b1SDavid Howells #endif
172f7b422b1SDavid Howells 
173f7b422b1SDavid Howells /* callback_xdr.c */
174f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
17507bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4;
176f7b422b1SDavid Howells 
177f7b422b1SDavid Howells /* pagelist.c */
178f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
179266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
180f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
181266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
182f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
183266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
184f7b422b1SDavid Howells 
185f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
186266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
187f7b422b1SDavid Howells 
188f7b422b1SDavid Howells /* nfs2xdr.c */
18985828493SChuck Lever extern int nfs_stat_to_errno(enum nfs_stat);
190f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
191573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
192573c4e1eSChuck Lever 				struct nfs_entry *, int);
193f7b422b1SDavid Howells 
194f7b422b1SDavid Howells /* nfs3xdr.c */
195f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
196573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
197573c4e1eSChuck Lever 				struct nfs_entry *, int);
198f7b422b1SDavid Howells 
199f7b422b1SDavid Howells /* nfs4xdr.c */
2007d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
201573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
202573c4e1eSChuck Lever 				struct nfs_entry *, int);
2037d4e2747SDavid Howells #endif
2042449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
2052449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
2062449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
2072449ea2eSAlexandros Batsakis #endif
208f7b422b1SDavid Howells 
209f7b422b1SDavid Howells /* nfs4proc.c */
210d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
211f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
212d75d5414SAndrew Morton #endif
213f7b422b1SDavid Howells 
2147fe5c398STrond Myklebust /* proc.c */
2157fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
2167fe5c398STrond Myklebust 
217979df72eSTrond Myklebust /* dir.c */
2187f8275d0SDave Chinner extern int nfs_access_cache_shrinker(struct shrinker *shrink,
2197f8275d0SDave Chinner 					int nr_to_scan, gfp_t gfp_mask);
220979df72eSTrond Myklebust 
221f7b422b1SDavid Howells /* inode.c */
2225746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
223f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
224f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
225a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
226b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
227f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
228b57922d9SAl Viro extern void nfs4_evict_inode(struct inode *);
229f7b422b1SDavid Howells #endif
230f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode);
23172cb77f4STrond Myklebust extern int nfs_wait_bit_killable(void *word);
232f7b422b1SDavid Howells 
233f7b422b1SDavid Howells /* super.c */
23454ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
235f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
23654ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
23754ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
238f7b422b1SDavid Howells #endif
2394ebd9ab3SDominik Hackl 
240f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
2414ebd9ab3SDominik Hackl 
242f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
243f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
2441daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb);
2451daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
246f7b422b1SDavid Howells 
247f7b422b1SDavid Howells /* namespace.c */
24854ceac45SDavid Howells extern char *nfs_path(const char *base,
24954ceac45SDavid Howells 		      const struct dentry *droot,
25054ceac45SDavid Howells 		      const struct dentry *dentry,
251f7b422b1SDavid Howells 		      char *buffer, ssize_t buflen);
252f7b422b1SDavid Howells 
25354ceac45SDavid Howells /* getroot.c */
25454ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
2557d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
25654ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
25754ceac45SDavid Howells 
258815409d2STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
2597d4e2747SDavid Howells #endif
260f7b422b1SDavid Howells 
261f11c88afSAndy Adamson /* read.c */
262f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
263f11c88afSAndy Adamson 
264def6ed7eSAndy Adamson /* write.c */
265def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
266074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
267074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *,
268074cc1deSTrond Myklebust 		struct page *, struct page *);
269074cc1deSTrond Myklebust #else
270074cc1deSTrond Myklebust #define nfs_migrate_page NULL
271074cc1deSTrond Myklebust #endif
272def6ed7eSAndy Adamson 
273cccef3b9SAndy Adamson /* nfs4proc.c */
274cccef3b9SAndy Adamson extern int _nfs4_call_sync(struct nfs_server *server,
275cccef3b9SAndy Adamson 			   struct rpc_message *msg,
276cccef3b9SAndy Adamson 			   struct nfs4_sequence_args *args,
277cccef3b9SAndy Adamson 			   struct nfs4_sequence_res *res,
278cccef3b9SAndy Adamson 			   int cache_reply);
279cccef3b9SAndy Adamson extern int _nfs4_call_sync_session(struct nfs_server *server,
280cccef3b9SAndy Adamson 				   struct rpc_message *msg,
281cccef3b9SAndy Adamson 				   struct nfs4_sequence_args *args,
282cccef3b9SAndy Adamson 				   struct nfs4_sequence_res *res,
283cccef3b9SAndy Adamson 				   int cache_reply);
284cccef3b9SAndy Adamson 
285557134a3SAndy Adamson /*
286f7b422b1SDavid Howells  * Determine the device name as a string
287f7b422b1SDavid Howells  */
288f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent,
289f7b422b1SDavid Howells 				const struct dentry *dentry,
290f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
291f7b422b1SDavid Howells {
29254ceac45SDavid Howells 	return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
29354ceac45SDavid Howells 			dentry, buffer, buflen);
294f7b422b1SDavid Howells }
295f7b422b1SDavid Howells 
296f7b422b1SDavid Howells /*
297f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
298f7b422b1SDavid Howells  */
299f7b422b1SDavid Howells static inline
300f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
301f7b422b1SDavid Howells {
302f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
303f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
304f7b422b1SDavid Howells 		unsigned char	nrbits;
305f7b422b1SDavid Howells 
306f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
307f7b422b1SDavid Howells 			;
308f7b422b1SDavid Howells 		bsize = 1 << nrbits;
309f7b422b1SDavid Howells 		if (nrbitsp)
310f7b422b1SDavid Howells 			*nrbitsp = nrbits;
311f7b422b1SDavid Howells 	}
312f7b422b1SDavid Howells 
313f7b422b1SDavid Howells 	return bsize;
314f7b422b1SDavid Howells }
315f7b422b1SDavid Howells 
316f7b422b1SDavid Howells /*
317f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
318f7b422b1SDavid Howells  */
3199eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
320f7b422b1SDavid Howells {
3219eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
322f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
323f7b422b1SDavid Howells }
324f7b422b1SDavid Howells 
325f7b422b1SDavid Howells /*
326f7b422b1SDavid Howells  * Compute and set NFS server blocksize
327f7b422b1SDavid Howells  */
328f7b422b1SDavid Howells static inline
329f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
330f7b422b1SDavid Howells {
331f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
332f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
333f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
334f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
335f7b422b1SDavid Howells 
336f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
337f7b422b1SDavid Howells }
338f7b422b1SDavid Howells 
339f7b422b1SDavid Howells /*
340f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
341f7b422b1SDavid Howells  */
342f7b422b1SDavid Howells static inline
343f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
344f7b422b1SDavid Howells {
345f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
346f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
347f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
348f7b422b1SDavid Howells }
34949a70f27STrond Myklebust 
35049a70f27STrond Myklebust /*
35149a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
35249a70f27STrond Myklebust  */
35349a70f27STrond Myklebust static inline
35449a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
35549a70f27STrond Myklebust {
35649a70f27STrond Myklebust 	loff_t i_size = i_size_read(page->mapping->host);
35749a70f27STrond Myklebust 
35849a70f27STrond Myklebust 	if (i_size > 0) {
35949a70f27STrond Myklebust 		pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
36049a70f27STrond Myklebust 		if (page->index < end_index)
36149a70f27STrond Myklebust 			return PAGE_CACHE_SIZE;
36249a70f27STrond Myklebust 		if (page->index == end_index)
36349a70f27STrond Myklebust 			return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
36449a70f27STrond Myklebust 	}
36549a70f27STrond Myklebust 	return 0;
36649a70f27STrond Myklebust }
3678d5658c9STrond Myklebust 
3688d5658c9STrond Myklebust /*
3690b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
3700b26a0bfSTrond Myklebust  */
3710b26a0bfSTrond Myklebust static inline
3720b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
3730b26a0bfSTrond Myklebust {
3740b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
3750b26a0bfSTrond Myklebust }
3760b26a0bfSTrond Myklebust 
3770b26a0bfSTrond Myklebust /*
3788d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
3798d5658c9STrond Myklebust  * with a base offset of 'base'
3808d5658c9STrond Myklebust  */
3818d5658c9STrond Myklebust static inline
3828d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
3838d5658c9STrond Myklebust {
3848d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
3858d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
3868d5658c9STrond Myklebust }
3870110ee15STrond Myklebust 
3880110ee15STrond Myklebust /*
3890110ee15STrond Myklebust  * Helper for restarting RPC calls in the possible presence of NFSv4.1
3900110ee15STrond Myklebust  * sessions.
3910110ee15STrond Myklebust  */
392d05dd4e9STrond Myklebust static inline int nfs_restart_rpc(struct rpc_task *task, const struct nfs_client *clp)
3930110ee15STrond Myklebust {
3940110ee15STrond Myklebust 	if (nfs4_has_session(clp))
395d05dd4e9STrond Myklebust 		return rpc_restart_call_prepare(task);
396d05dd4e9STrond Myklebust 	return rpc_restart_call(task);
3970110ee15STrond Myklebust }
398