xref: /openbmc/linux/fs/nfs/internal.h (revision 266bee88)
1f7b422b1SDavid Howells /*
2f7b422b1SDavid Howells  * NFS internal definitions
3f7b422b1SDavid Howells  */
4f7b422b1SDavid Howells 
5f7b422b1SDavid Howells #include <linux/mount.h>
6f7b422b1SDavid Howells 
7f7b422b1SDavid Howells struct nfs_clone_mount {
8f7b422b1SDavid Howells 	const struct super_block *sb;
9f7b422b1SDavid Howells 	const struct dentry *dentry;
10f7b422b1SDavid Howells 	struct nfs_fh *fh;
11f7b422b1SDavid Howells 	struct nfs_fattr *fattr;
12f7b422b1SDavid Howells 	char *hostname;
13f7b422b1SDavid Howells 	char *mnt_path;
14f7b422b1SDavid Howells 	struct sockaddr_in *addr;
15f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
16f7b422b1SDavid Howells };
17f7b422b1SDavid Howells 
18f7b422b1SDavid Howells /* namespace-nfs4.c */
19f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
20f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
21f7b422b1SDavid Howells #else
22f7b422b1SDavid Howells static inline
23f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
24f7b422b1SDavid Howells {
25f7b422b1SDavid Howells 	return ERR_PTR(-ENOENT);
26f7b422b1SDavid Howells }
27f7b422b1SDavid Howells #endif
28f7b422b1SDavid Howells 
29f7b422b1SDavid Howells /* callback_xdr.c */
30f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
31f7b422b1SDavid Howells 
32f7b422b1SDavid Howells /* pagelist.c */
33f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
34266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
35f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
36266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
37f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
38266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
39f7b422b1SDavid Howells 
40f7b422b1SDavid Howells #ifdef CONFIG_NFS_DIRECTIO
41f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
42266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
43f7b422b1SDavid Howells #else
44f7b422b1SDavid Howells #define nfs_init_directcache() (0)
45f7b422b1SDavid Howells #define nfs_destroy_directcache() do {} while(0)
46f7b422b1SDavid Howells #endif
47f7b422b1SDavid Howells 
48f7b422b1SDavid Howells /* nfs2xdr.c */
49f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
50f7b422b1SDavid Howells extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
51f7b422b1SDavid Howells 
52f7b422b1SDavid Howells /* nfs3xdr.c */
53f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
54f7b422b1SDavid Howells extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
55f7b422b1SDavid Howells 
56f7b422b1SDavid Howells /* nfs4xdr.c */
57f7b422b1SDavid Howells extern int nfs_stat_to_errno(int);
58f7b422b1SDavid Howells extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
59f7b422b1SDavid Howells 
60f7b422b1SDavid Howells /* nfs4proc.c */
61d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
62f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
63f7b422b1SDavid Howells 
64f7b422b1SDavid Howells extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
65f7b422b1SDavid Howells 				  struct nfs4_fs_locations *fs_locations,
66f7b422b1SDavid Howells 				  struct page *page);
67d75d5414SAndrew Morton #endif
68f7b422b1SDavid Howells 
69f7b422b1SDavid Howells /* inode.c */
70f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
71f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
72f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int);
73f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *);
74f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
75f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *);
76f7b422b1SDavid Howells #endif
77f7b422b1SDavid Howells 
78f7b422b1SDavid Howells /* super.c */
79f7b422b1SDavid Howells extern struct file_system_type nfs_referral_nfs4_fs_type;
80f7b422b1SDavid Howells extern struct file_system_type clone_nfs_fs_type;
81f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
82f7b422b1SDavid Howells extern struct file_system_type clone_nfs4_fs_type;
83f7b422b1SDavid Howells #endif
84f7b422b1SDavid Howells #ifdef CONFIG_PROC_FS
85f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
86f7b422b1SDavid Howells #endif
87f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
88f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
89f7b422b1SDavid Howells 
90f7b422b1SDavid Howells /* namespace.c */
91f7b422b1SDavid Howells extern char *nfs_path(const char *base, const struct dentry *dentry,
92f7b422b1SDavid Howells 		      char *buffer, ssize_t buflen);
93f7b422b1SDavid Howells 
94f7b422b1SDavid Howells /*
95f7b422b1SDavid Howells  * Determine the mount path as a string
96f7b422b1SDavid Howells  */
97d75d5414SAndrew Morton static inline char *
98d75d5414SAndrew Morton nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
99f7b422b1SDavid Howells {
100d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
101f7b422b1SDavid Howells 	return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
102d75d5414SAndrew Morton #else
103d75d5414SAndrew Morton 	return NULL;
104d75d5414SAndrew Morton #endif
105f7b422b1SDavid Howells }
106f7b422b1SDavid Howells 
107f7b422b1SDavid Howells /*
108f7b422b1SDavid Howells  * Determine the device name as a string
109f7b422b1SDavid Howells  */
110f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent,
111f7b422b1SDavid Howells 			 const struct dentry *dentry,
112f7b422b1SDavid Howells 			 char *buffer, ssize_t buflen)
113f7b422b1SDavid Howells {
114f7b422b1SDavid Howells 	return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
115f7b422b1SDavid Howells }
116f7b422b1SDavid Howells 
117f7b422b1SDavid Howells /*
118f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
119f7b422b1SDavid Howells  */
120f7b422b1SDavid Howells static inline
121f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
122f7b422b1SDavid Howells {
123f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
124f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
125f7b422b1SDavid Howells 		unsigned char	nrbits;
126f7b422b1SDavid Howells 
127f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
128f7b422b1SDavid Howells 			;
129f7b422b1SDavid Howells 		bsize = 1 << nrbits;
130f7b422b1SDavid Howells 		if (nrbitsp)
131f7b422b1SDavid Howells 			*nrbitsp = nrbits;
132f7b422b1SDavid Howells 	}
133f7b422b1SDavid Howells 
134f7b422b1SDavid Howells 	return bsize;
135f7b422b1SDavid Howells }
136f7b422b1SDavid Howells 
137f7b422b1SDavid Howells /*
138f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
139f7b422b1SDavid Howells  */
140f7b422b1SDavid Howells static inline unsigned long nfs_calc_block_size(u64 tsize)
141f7b422b1SDavid Howells {
142f7b422b1SDavid Howells 	loff_t used = (tsize + 511) >> 9;
143f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
144f7b422b1SDavid Howells }
145f7b422b1SDavid Howells 
146f7b422b1SDavid Howells /*
147f7b422b1SDavid Howells  * Compute and set NFS server blocksize
148f7b422b1SDavid Howells  */
149f7b422b1SDavid Howells static inline
150f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
151f7b422b1SDavid Howells {
152f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
153f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
154f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
155f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
156f7b422b1SDavid Howells 
157f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
158f7b422b1SDavid Howells }
159f7b422b1SDavid Howells 
160f7b422b1SDavid Howells /*
161f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
162f7b422b1SDavid Howells  */
163f7b422b1SDavid Howells static inline
164f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
165f7b422b1SDavid Howells {
166f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
167f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
168f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
169f7b422b1SDavid Howells }
170f7b422b1SDavid Howells 
171f7b422b1SDavid Howells /*
172f7b422b1SDavid Howells  * Check if the string represents a "valid" IPv4 address
173f7b422b1SDavid Howells  */
174f7b422b1SDavid Howells static inline int valid_ipaddr4(const char *buf)
175f7b422b1SDavid Howells {
176f7b422b1SDavid Howells 	int rc, count, in[4];
177f7b422b1SDavid Howells 
178f7b422b1SDavid Howells 	rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
179f7b422b1SDavid Howells 	if (rc != 4)
180f7b422b1SDavid Howells 		return -EINVAL;
181f7b422b1SDavid Howells 	for (count = 0; count < 4; count++) {
182f7b422b1SDavid Howells 		if (in[count] > 255)
183f7b422b1SDavid Howells 			return -EINVAL;
184f7b422b1SDavid Howells 	}
185f7b422b1SDavid Howells 	return 0;
186f7b422b1SDavid Howells }
187