xref: /openbmc/linux/fs/nfs/internal.h (revision 7ebb9315)
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 
427ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
437ebb9315SBryan Schumaker {
447ebb9315SBryan Schumaker 	if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
457ebb9315SBryan Schumaker 		fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
467ebb9315SBryan Schumaker }
477ebb9315SBryan Schumaker 
48f7b422b1SDavid Howells struct nfs_clone_mount {
49f7b422b1SDavid Howells 	const struct super_block *sb;
50f7b422b1SDavid Howells 	const struct dentry *dentry;
51f7b422b1SDavid Howells 	struct nfs_fh *fh;
52f7b422b1SDavid Howells 	struct nfs_fattr *fattr;
53f7b422b1SDavid Howells 	char *hostname;
54f7b422b1SDavid Howells 	char *mnt_path;
556677d095SChuck Lever 	struct sockaddr *addr;
566677d095SChuck Lever 	size_t addrlen;
57f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
58f7b422b1SDavid Howells };
59f7b422b1SDavid Howells 
606b18eaa0S\"Talpey, Thomas\ /*
61a14017dbSChuck Lever  * Note: RFC 1813 doesn't limit the number of auth flavors that
62a14017dbSChuck Lever  * a server can return, so make something up.
63a14017dbSChuck Lever  */
64a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS	(12)
65a14017dbSChuck Lever 
66a14017dbSChuck Lever /*
674cfd74fcSChuck Lever  * Value used if the user did not specify a port value.
684cfd74fcSChuck Lever  */
694cfd74fcSChuck Lever #define NFS_UNSPEC_PORT		(-1)
704cfd74fcSChuck Lever 
714cfd74fcSChuck Lever /*
7256e4ebf8SBryan Schumaker  * Maximum number of pages that readdir can use for creating
7356e4ebf8SBryan Schumaker  * a vmapped array of pages.
7456e4ebf8SBryan Schumaker  */
7556e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8
7656e4ebf8SBryan Schumaker 
7756e4ebf8SBryan Schumaker /*
786b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
796b18eaa0S\"Talpey, Thomas\  */
806b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data {
816b18eaa0S\"Talpey, Thomas\ 	int			flags;
826b18eaa0S\"Talpey, Thomas\ 	int			rsize, wsize;
836b18eaa0S\"Talpey, Thomas\ 	int			timeo, retrans;
846b18eaa0S\"Talpey, Thomas\ 	int			acregmin, acregmax,
856b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
866b18eaa0S\"Talpey, Thomas\ 	int			namlen;
87b797cac7SDavid Howells 	unsigned int		options;
886b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
896b18eaa0S\"Talpey, Thomas\ 	unsigned int		auth_flavor_len;
906b18eaa0S\"Talpey, Thomas\ 	rpc_authflavor_t	auth_flavors[1];
916b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
92764302ccSChuck Lever 	unsigned int		version;
933fd5be9eSMike Sager 	unsigned int		minorversion;
9408734048SDavid Howells 	char			*fscache_uniq;
956b18eaa0S\"Talpey, Thomas\ 
966b18eaa0S\"Talpey, Thomas\ 	struct {
974c568017SChuck Lever 		struct sockaddr_storage	address;
984c568017SChuck Lever 		size_t			addrlen;
996b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
10078fa701fSChuck Lever 		u32			version;
1014cfd74fcSChuck Lever 		int			port;
10278fa701fSChuck Lever 		unsigned short		protocol;
1036b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1046b18eaa0S\"Talpey, Thomas\ 
1056b18eaa0S\"Talpey, Thomas\ 	struct {
1064c568017SChuck Lever 		struct sockaddr_storage	address;
1074c568017SChuck Lever 		size_t			addrlen;
1086b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1096b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1104cfd74fcSChuck Lever 		int			port;
11178fa701fSChuck Lever 		unsigned short		protocol;
1126b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
113f9c3a380SEric Paris 
114f9c3a380SEric Paris 	struct security_mnt_opts lsm_opts;
1156b18eaa0S\"Talpey, Thomas\ };
1166b18eaa0S\"Talpey, Thomas\ 
117146ec944SChuck Lever /* mount_clnt.c */
118c5d120f8SChuck Lever struct nfs_mount_request {
119c5d120f8SChuck Lever 	struct sockaddr		*sap;
120c5d120f8SChuck Lever 	size_t			salen;
121c5d120f8SChuck Lever 	char			*hostname;
122c5d120f8SChuck Lever 	char			*dirpath;
123c5d120f8SChuck Lever 	u32			version;
124c5d120f8SChuck Lever 	unsigned short		protocol;
125c5d120f8SChuck Lever 	struct nfs_fh		*fh;
12650a737f8SChuck Lever 	int			noresvport;
1278e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1288e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
129c5d120f8SChuck Lever };
130c5d120f8SChuck Lever 
131c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info);
1320b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
133146ec944SChuck Lever 
13424c8dbbbSDavid Howells /* client.c */
13554ceac45SDavid Howells extern struct rpc_program nfs_program;
13654ceac45SDavid Howells 
137f4eecd5dSAndy Adamson extern void nfs_cleanup_cb_ident_idr(void);
13824c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
139c36fca52SAndy Adamson extern struct nfs_client *nfs4_find_client_no_ident(const struct sockaddr *);
140c36fca52SAndy Adamson extern struct nfs_client *nfs4_find_client_ident(int);
141c36fca52SAndy Adamson extern struct nfs_client *
142778be232SAndy Adamson nfs4_find_client_sessionid(const struct sockaddr *, struct nfs4_sessionid *);
1432283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server(
1442283f8d6S\"Talpey, Thomas\ 					const struct nfs_parsed_mount_data *,
14554ceac45SDavid Howells 					struct nfs_fh *);
14691ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server(
14791ea40b9S\"Talpey, Thomas\ 					const struct nfs_parsed_mount_data *,
14854ceac45SDavid Howells 					struct nfs_fh *);
14954ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
15054ceac45SDavid Howells 						      struct nfs_fh *);
15154ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
15254ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
15354ceac45SDavid Howells 					   struct nfs_fh *,
15454ceac45SDavid Howells 					   struct nfs_fattr *);
15576db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
156008f55d0SBenny Halevy extern int nfs4_check_client_ready(struct nfs_client *clp);
157d83217c1SAndy Adamson extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
158d83217c1SAndy Adamson 					     const struct sockaddr *ds_addr,
159d83217c1SAndy Adamson 					     int ds_addrlen, int ds_proto);
1606aaca566SDavid Howells #ifdef CONFIG_PROC_FS
1616aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
1626aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
1636aaca566SDavid Howells #else
1646aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
1656aaca566SDavid Howells {
1666aaca566SDavid Howells 	return 0;
1676aaca566SDavid Howells }
1686aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
1696aaca566SDavid Howells {
1706aaca566SDavid Howells }
1716aaca566SDavid Howells #endif
17224c8dbbbSDavid Howells 
1737d4e2747SDavid Howells /* nfs4namespace.c */
174f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
175f8ad9c4bSAl Viro extern struct vfsmount *nfs_do_refmount(struct dentry *dentry);
176f7b422b1SDavid Howells #else
177f7b422b1SDavid Howells static inline
178f8ad9c4bSAl Viro struct vfsmount *nfs_do_refmount(struct dentry *dentry)
179f7b422b1SDavid Howells {
180f7b422b1SDavid Howells 	return ERR_PTR(-ENOENT);
181f7b422b1SDavid Howells }
182f7b422b1SDavid Howells #endif
183f7b422b1SDavid Howells 
184f7b422b1SDavid Howells /* callback_xdr.c */
185f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
18607bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4;
187f7b422b1SDavid Howells 
188f7b422b1SDavid Howells /* pagelist.c */
189f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
190266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
191f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
192266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
193f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
194266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
195f7b422b1SDavid Howells 
196f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
197266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
198f7b422b1SDavid Howells 
199f7b422b1SDavid Howells /* nfs2xdr.c */
20085828493SChuck Lever extern int nfs_stat_to_errno(enum nfs_stat);
201f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
202573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
203573c4e1eSChuck Lever 				struct nfs_entry *, int);
204f7b422b1SDavid Howells 
205f7b422b1SDavid Howells /* nfs3xdr.c */
206f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
207573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
208573c4e1eSChuck Lever 				struct nfs_entry *, int);
209f7b422b1SDavid Howells 
210f7b422b1SDavid Howells /* nfs4xdr.c */
2117d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
212573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
213573c4e1eSChuck Lever 				struct nfs_entry *, int);
2147d4e2747SDavid Howells #endif
2152449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
2162449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
2172449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
2182449ea2eSAlexandros Batsakis #endif
219f7b422b1SDavid Howells 
220f7b422b1SDavid Howells /* nfs4proc.c */
221d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
222f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
2237ebb9315SBryan Schumaker void nfs_fixup_secinfo_attributes(struct nfs_fattr *, struct nfs_fh *);
224d75d5414SAndrew Morton #endif
225f7b422b1SDavid Howells 
226d83217c1SAndy Adamson extern int nfs4_init_ds_session(struct nfs_client *clp);
227d83217c1SAndy Adamson 
2287fe5c398STrond Myklebust /* proc.c */
2297fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
23045a52a02SAndy Adamson extern int nfs_init_client(struct nfs_client *clp,
23145a52a02SAndy Adamson 			   const struct rpc_timeout *timeparms,
23245a52a02SAndy Adamson 			   const char *ip_addr, rpc_authflavor_t authflavour,
23345a52a02SAndy Adamson 			   int noresvport);
2347fe5c398STrond Myklebust 
235979df72eSTrond Myklebust /* dir.c */
2367f8275d0SDave Chinner extern int nfs_access_cache_shrinker(struct shrinker *shrink,
2377f8275d0SDave Chinner 					int nr_to_scan, gfp_t gfp_mask);
238979df72eSTrond Myklebust 
239f7b422b1SDavid Howells /* inode.c */
2405746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
241f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
242f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
243a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
244b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
245f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
246b57922d9SAl Viro extern void nfs4_evict_inode(struct inode *);
247f7b422b1SDavid Howells #endif
248f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode);
24972cb77f4STrond Myklebust extern int nfs_wait_bit_killable(void *word);
250f7b422b1SDavid Howells 
251f7b422b1SDavid Howells /* super.c */
25254ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
253f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
25454ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
25554ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
256f7b422b1SDavid Howells #endif
2574ebd9ab3SDominik Hackl 
258f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
2594ebd9ab3SDominik Hackl 
260f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
261f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
2621daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb);
2631daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
264f7b422b1SDavid Howells 
265f7b422b1SDavid Howells /* namespace.c */
266b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
267f7b422b1SDavid Howells 		      char *buffer, ssize_t buflen);
26836d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
269f7b422b1SDavid Howells 
27054ceac45SDavid Howells /* getroot.c */
2710d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
2720d5839adSAl Viro 				   const char *);
2737d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
2740d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
2750d5839adSAl Viro 				    const char *);
27654ceac45SDavid Howells 
277815409d2STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
2787d4e2747SDavid Howells #endif
279f7b422b1SDavid Howells 
280f11c88afSAndy Adamson /* read.c */
281dc70d7b3SAndy Adamson extern int nfs_initiate_read(struct nfs_read_data *data, struct rpc_clnt *clnt,
282dc70d7b3SAndy Adamson 			     const struct rpc_call_ops *call_ops);
283f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
284f11c88afSAndy Adamson 
285def6ed7eSAndy Adamson /* write.c */
286a69aef14SFred Isaman extern int nfs_initiate_write(struct nfs_write_data *data,
287a69aef14SFred Isaman 			      struct rpc_clnt *clnt,
288a69aef14SFred Isaman 			      const struct rpc_call_ops *call_ops,
289a69aef14SFred Isaman 			      int how);
290def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
291074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
292074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *,
293074cc1deSTrond Myklebust 		struct page *, struct page *);
294074cc1deSTrond Myklebust #else
295074cc1deSTrond Myklebust #define nfs_migrate_page NULL
296074cc1deSTrond Myklebust #endif
297def6ed7eSAndy Adamson 
298cccef3b9SAndy Adamson /* nfs4proc.c */
299cbdabc7fSAndy Adamson extern void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data);
30045a52a02SAndy Adamson extern int nfs4_init_client(struct nfs_client *clp,
30145a52a02SAndy Adamson 			    const struct rpc_timeout *timeparms,
30245a52a02SAndy Adamson 			    const char *ip_addr,
30345a52a02SAndy Adamson 			    rpc_authflavor_t authflavour,
30445a52a02SAndy Adamson 			    int noresvport);
305a69aef14SFred Isaman extern void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data);
3067c513058SBryan Schumaker extern int _nfs4_call_sync(struct rpc_clnt *clnt,
3077c513058SBryan Schumaker 			   struct nfs_server *server,
308cccef3b9SAndy Adamson 			   struct rpc_message *msg,
309cccef3b9SAndy Adamson 			   struct nfs4_sequence_args *args,
310cccef3b9SAndy Adamson 			   struct nfs4_sequence_res *res,
311cccef3b9SAndy Adamson 			   int cache_reply);
3127c513058SBryan Schumaker extern int _nfs4_call_sync_session(struct rpc_clnt *clnt,
3137c513058SBryan Schumaker 				   struct nfs_server *server,
314cccef3b9SAndy Adamson 				   struct rpc_message *msg,
315cccef3b9SAndy Adamson 				   struct nfs4_sequence_args *args,
316cccef3b9SAndy Adamson 				   struct nfs4_sequence_res *res,
317cccef3b9SAndy Adamson 				   int cache_reply);
318cccef3b9SAndy Adamson 
319557134a3SAndy Adamson /*
320f7b422b1SDavid Howells  * Determine the device name as a string
321f7b422b1SDavid Howells  */
322b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
323f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
324f7b422b1SDavid Howells {
325b514f872SAl Viro 	char *dummy;
326b514f872SAl Viro 	return nfs_path(&dummy, dentry, buffer, buflen);
327f7b422b1SDavid Howells }
328f7b422b1SDavid Howells 
329f7b422b1SDavid Howells /*
330f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
331f7b422b1SDavid Howells  */
332f7b422b1SDavid Howells static inline
333f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
334f7b422b1SDavid Howells {
335f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
336f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
337f7b422b1SDavid Howells 		unsigned char	nrbits;
338f7b422b1SDavid Howells 
339f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
340f7b422b1SDavid Howells 			;
341f7b422b1SDavid Howells 		bsize = 1 << nrbits;
342f7b422b1SDavid Howells 		if (nrbitsp)
343f7b422b1SDavid Howells 			*nrbitsp = nrbits;
344f7b422b1SDavid Howells 	}
345f7b422b1SDavid Howells 
346f7b422b1SDavid Howells 	return bsize;
347f7b422b1SDavid Howells }
348f7b422b1SDavid Howells 
349f7b422b1SDavid Howells /*
350f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
351f7b422b1SDavid Howells  */
3529eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
353f7b422b1SDavid Howells {
3549eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
355f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
356f7b422b1SDavid Howells }
357f7b422b1SDavid Howells 
358f7b422b1SDavid Howells /*
359f7b422b1SDavid Howells  * Compute and set NFS server blocksize
360f7b422b1SDavid Howells  */
361f7b422b1SDavid Howells static inline
362f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
363f7b422b1SDavid Howells {
364f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
365f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
366f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
367f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
368f7b422b1SDavid Howells 
369f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
370f7b422b1SDavid Howells }
371f7b422b1SDavid Howells 
372f7b422b1SDavid Howells /*
373f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
374f7b422b1SDavid Howells  */
375f7b422b1SDavid Howells static inline
376f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
377f7b422b1SDavid Howells {
378f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
379f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
380f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
381f7b422b1SDavid Howells }
38249a70f27STrond Myklebust 
38349a70f27STrond Myklebust /*
38449a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
38549a70f27STrond Myklebust  */
38649a70f27STrond Myklebust static inline
38749a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
38849a70f27STrond Myklebust {
38949a70f27STrond Myklebust 	loff_t i_size = i_size_read(page->mapping->host);
39049a70f27STrond Myklebust 
39149a70f27STrond Myklebust 	if (i_size > 0) {
39249a70f27STrond Myklebust 		pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
39349a70f27STrond Myklebust 		if (page->index < end_index)
39449a70f27STrond Myklebust 			return PAGE_CACHE_SIZE;
39549a70f27STrond Myklebust 		if (page->index == end_index)
39649a70f27STrond Myklebust 			return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
39749a70f27STrond Myklebust 	}
39849a70f27STrond Myklebust 	return 0;
39949a70f27STrond Myklebust }
4008d5658c9STrond Myklebust 
4018d5658c9STrond Myklebust /*
4020b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
4030b26a0bfSTrond Myklebust  */
4040b26a0bfSTrond Myklebust static inline
4050b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
4060b26a0bfSTrond Myklebust {
4070b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
4080b26a0bfSTrond Myklebust }
4090b26a0bfSTrond Myklebust 
4100b26a0bfSTrond Myklebust /*
4118d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
4128d5658c9STrond Myklebust  * with a base offset of 'base'
4138d5658c9STrond Myklebust  */
4148d5658c9STrond Myklebust static inline
4158d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
4168d5658c9STrond Myklebust {
4178d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
4188d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
4198d5658c9STrond Myklebust }
4200110ee15STrond Myklebust 
4210110ee15STrond Myklebust /*
4220110ee15STrond Myklebust  * Helper for restarting RPC calls in the possible presence of NFSv4.1
4230110ee15STrond Myklebust  * sessions.
4240110ee15STrond Myklebust  */
425d05dd4e9STrond Myklebust static inline int nfs_restart_rpc(struct rpc_task *task, const struct nfs_client *clp)
4260110ee15STrond Myklebust {
4270110ee15STrond Myklebust 	if (nfs4_has_session(clp))
428d05dd4e9STrond Myklebust 		return rpc_restart_call_prepare(task);
429d05dd4e9STrond Myklebust 	return rpc_restart_call(task);
4300110ee15STrond Myklebust }
431