2 * NFS internal definitions
6 #include <linux/mount.h>
7 #include <linux/security.h>
9 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
13 #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
16 * Determine if sessions are in use.
18 static inline int nfs4_has_session(const struct nfs_client
*clp
)
20 #ifdef CONFIG_NFS_V4_1
23 #endif /* CONFIG_NFS_V4_1 */
27 static inline int nfs4_has_persistent_session(const struct nfs_client
*clp
)
29 #ifdef CONFIG_NFS_V4_1
30 if (nfs4_has_session(clp
))
31 return (clp
->cl_session
->flags
& SESSION4_PERSIST
);
32 #endif /* CONFIG_NFS_V4_1 */
36 struct nfs_clone_mount
{
37 const struct super_block
*sb
;
38 const struct dentry
*dentry
;
40 struct nfs_fattr
*fattr
;
43 struct sockaddr
*addr
;
45 rpc_authflavor_t authflavor
;
49 * Note: RFC 1813 doesn't limit the number of auth flavors that
50 * a server can return, so make something up.
52 #define NFS_MAX_SECFLAVORS (12)
55 * Value used if the user did not specify a port value.
57 #define NFS_UNSPEC_PORT (-1)
60 * In-kernel mount arguments
62 struct nfs_parsed_mount_data
{
66 int acregmin
, acregmax
,
71 unsigned int auth_flavor_len
;
72 rpc_authflavor_t auth_flavors
[1];
75 unsigned int minorversion
;
79 struct sockaddr_storage address
;
84 unsigned short protocol
;
88 struct sockaddr_storage address
;
93 unsigned short protocol
;
96 struct security_mnt_opts lsm_opts
;
100 struct nfs_mount_request
{
101 struct sockaddr
*sap
;
106 unsigned short protocol
;
109 unsigned int *auth_flav_len
;
110 rpc_authflavor_t
*auth_flavs
;
113 extern int nfs_mount(struct nfs_mount_request
*info
);
114 extern void nfs_umount(const struct nfs_mount_request
*info
);
117 extern struct rpc_program nfs_program
;
119 extern void nfs_put_client(struct nfs_client
*);
120 extern struct nfs_client
*nfs_find_client(const struct sockaddr
*, u32
);
121 extern struct nfs_client
*nfs_find_client_next(struct nfs_client
*);
122 extern struct nfs_server
*nfs_create_server(
123 const struct nfs_parsed_mount_data
*,
125 extern struct nfs_server
*nfs4_create_server(
126 const struct nfs_parsed_mount_data
*,
128 extern struct nfs_server
*nfs4_create_referral_server(struct nfs_clone_mount
*,
130 extern void nfs_free_server(struct nfs_server
*server
);
131 extern struct nfs_server
*nfs_clone_server(struct nfs_server
*,
134 extern void nfs_mark_client_ready(struct nfs_client
*clp
, int state
);
135 extern int nfs4_check_client_ready(struct nfs_client
*clp
);
136 #ifdef CONFIG_PROC_FS
137 extern int __init
nfs_fs_proc_init(void);
138 extern void nfs_fs_proc_exit(void);
140 static inline int nfs_fs_proc_init(void)
144 static inline void nfs_fs_proc_exit(void)
149 /* nfs4namespace.c */
151 extern struct vfsmount
*nfs_do_refmount(const struct vfsmount
*mnt_parent
, struct dentry
*dentry
);
154 struct vfsmount
*nfs_do_refmount(const struct vfsmount
*mnt_parent
, struct dentry
*dentry
)
156 return ERR_PTR(-ENOENT
);
161 extern struct svc_version nfs4_callback_version1
;
162 extern struct svc_version nfs4_callback_version4
;
165 extern int __init
nfs_init_nfspagecache(void);
166 extern void nfs_destroy_nfspagecache(void);
167 extern int __init
nfs_init_readpagecache(void);
168 extern void nfs_destroy_readpagecache(void);
169 extern int __init
nfs_init_writepagecache(void);
170 extern void nfs_destroy_writepagecache(void);
172 extern int __init
nfs_init_directcache(void);
173 extern void nfs_destroy_directcache(void);
176 extern int nfs_stat_to_errno(int);
177 extern struct rpc_procinfo nfs_procedures
[];
178 extern __be32
* nfs_decode_dirent(__be32
*, struct nfs_entry
*, int);
181 extern struct rpc_procinfo nfs3_procedures
[];
182 extern __be32
*nfs3_decode_dirent(__be32
*, struct nfs_entry
*, int);
186 extern __be32
*nfs4_decode_dirent(__be32
*p
, struct nfs_entry
*entry
, int plus
);
188 #ifdef CONFIG_NFS_V4_1
189 extern const u32 nfs41_maxread_overhead
;
190 extern const u32 nfs41_maxwrite_overhead
;
195 extern struct rpc_procinfo nfs4_procedures
[];
199 void nfs_close_context(struct nfs_open_context
*ctx
, int is_sync
);
202 extern int nfs_access_cache_shrinker(struct shrinker
*shrink
,
203 int nr_to_scan
, gfp_t gfp_mask
);
206 extern struct workqueue_struct
*nfsiod_workqueue
;
207 extern struct inode
*nfs_alloc_inode(struct super_block
*sb
);
208 extern void nfs_destroy_inode(struct inode
*);
209 extern int nfs_write_inode(struct inode
*, struct writeback_control
*);
210 extern void nfs_evict_inode(struct inode
*);
212 extern void nfs4_evict_inode(struct inode
*);
214 void nfs_zap_acl_cache(struct inode
*inode
);
215 extern int nfs_wait_bit_killable(void *word
);
218 extern struct file_system_type nfs_xdev_fs_type
;
220 extern struct file_system_type nfs4_xdev_fs_type
;
221 extern struct file_system_type nfs4_referral_fs_type
;
224 extern struct rpc_stat nfs_rpcstat
;
226 extern int __init
register_nfs_fs(void);
227 extern void __exit
unregister_nfs_fs(void);
228 extern void nfs_sb_active(struct super_block
*sb
);
229 extern void nfs_sb_deactive(struct super_block
*sb
);
232 extern char *nfs_path(const char *base
,
233 const struct dentry
*droot
,
234 const struct dentry
*dentry
,
235 char *buffer
, ssize_t buflen
);
238 extern struct dentry
*nfs_get_root(struct super_block
*, struct nfs_fh
*);
240 extern struct dentry
*nfs4_get_root(struct super_block
*, struct nfs_fh
*);
242 extern int nfs4_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*mntfh
);
246 extern void nfs_read_prepare(struct rpc_task
*task
, void *calldata
);
249 extern void nfs_write_prepare(struct rpc_task
*task
, void *calldata
);
250 #ifdef CONFIG_MIGRATION
251 extern int nfs_migrate_page(struct address_space
*,
252 struct page
*, struct page
*);
254 #define nfs_migrate_page NULL
258 extern int _nfs4_call_sync(struct nfs_server
*server
,
259 struct rpc_message
*msg
,
260 struct nfs4_sequence_args
*args
,
261 struct nfs4_sequence_res
*res
,
263 extern int _nfs4_call_sync_session(struct nfs_server
*server
,
264 struct rpc_message
*msg
,
265 struct nfs4_sequence_args
*args
,
266 struct nfs4_sequence_res
*res
,
270 * Determine the device name as a string
272 static inline char *nfs_devname(const struct vfsmount
*mnt_parent
,
273 const struct dentry
*dentry
,
274 char *buffer
, ssize_t buflen
)
276 return nfs_path(mnt_parent
->mnt_devname
, mnt_parent
->mnt_root
,
277 dentry
, buffer
, buflen
);
281 * Determine the actual block size (and log2 thereof)
284 unsigned long nfs_block_bits(unsigned long bsize
, unsigned char *nrbitsp
)
286 /* make sure blocksize is a power of two */
287 if ((bsize
& (bsize
- 1)) || nrbitsp
) {
288 unsigned char nrbits
;
290 for (nrbits
= 31; nrbits
&& !(bsize
& (1 << nrbits
)); nrbits
--)
301 * Calculate the number of 512byte blocks used.
303 static inline blkcnt_t
nfs_calc_block_size(u64 tsize
)
305 blkcnt_t used
= (tsize
+ 511) >> 9;
306 return (used
> ULONG_MAX
) ? ULONG_MAX
: used
;
310 * Compute and set NFS server blocksize
313 unsigned long nfs_block_size(unsigned long bsize
, unsigned char *nrbitsp
)
315 if (bsize
< NFS_MIN_FILE_IO_SIZE
)
316 bsize
= NFS_DEF_FILE_IO_SIZE
;
317 else if (bsize
>= NFS_MAX_FILE_IO_SIZE
)
318 bsize
= NFS_MAX_FILE_IO_SIZE
;
320 return nfs_block_bits(bsize
, nrbitsp
);
324 * Determine the maximum file size for a superblock
327 void nfs_super_set_maxbytes(struct super_block
*sb
, __u64 maxfilesize
)
329 sb
->s_maxbytes
= (loff_t
)maxfilesize
;
330 if (sb
->s_maxbytes
> MAX_LFS_FILESIZE
|| sb
->s_maxbytes
<= 0)
331 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
335 * Determine the number of bytes of data the page contains
338 unsigned int nfs_page_length(struct page
*page
)
340 loff_t i_size
= i_size_read(page
->mapping
->host
);
343 pgoff_t end_index
= (i_size
- 1) >> PAGE_CACHE_SHIFT
;
344 if (page
->index
< end_index
)
345 return PAGE_CACHE_SIZE
;
346 if (page
->index
== end_index
)
347 return ((i_size
- 1) & ~PAGE_CACHE_MASK
) + 1;
353 * Determine the number of pages in an array of length 'len' and
354 * with a base offset of 'base'
357 unsigned int nfs_page_array_len(unsigned int base
, size_t len
)
359 return ((unsigned long)len
+ (unsigned long)base
+
360 PAGE_SIZE
- 1) >> PAGE_SHIFT
;
364 * Helper for restarting RPC calls in the possible presence of NFSv4.1
367 static inline int nfs_restart_rpc(struct rpc_task
*task
, const struct nfs_client
*clp
)
369 if (nfs4_has_session(clp
))
370 return rpc_restart_call_prepare(task
);
371 return rpc_restart_call(task
);