]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
f7b422b1 DH |
2 | /* |
3 | * NFS internal definitions | |
4 | */ | |
5 | ||
eedc020e | 6 | #include "nfs4_fs.h" |
f7b422b1 | 7 | #include <linux/mount.h> |
f9c3a380 | 8 | #include <linux/security.h> |
1264a2f0 | 9 | #include <linux/crc32.h> |
47af81f2 | 10 | #include <linux/nfs_page.h> |
5dd43ce2 | 11 | #include <linux/wait_bit.h> |
f7b422b1 | 12 | |
1751e8a6 | 13 | #define NFS_MS_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS) |
08734048 | 14 | |
20fa1902 PT |
15 | extern const struct export_operations nfs_export_ops; |
16 | ||
54ceac45 | 17 | struct nfs_string; |
54ceac45 DH |
18 | |
19 | /* Maximum number of readahead requests | |
20 | * FIXME: this should really be a sysctl so that users may tune it to suit | |
21 | * their needs. People that do NFS over a slow network, might for | |
22 | * instance want to reduce it to something closer to 1 for improved | |
23 | * interactive response. | |
24 | */ | |
25 | #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) | |
26 | ||
7ebb9315 BS |
27 | static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr) |
28 | { | |
29 | if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid)) | |
30 | fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT; | |
31 | } | |
32 | ||
533eb461 AA |
33 | static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr) |
34 | { | |
35 | if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) || | |
36 | (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && | |
37 | ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) | |
38 | return 0; | |
533eb461 AA |
39 | return 1; |
40 | } | |
41 | ||
f7b422b1 DH |
42 | struct nfs_clone_mount { |
43 | const struct super_block *sb; | |
44 | const struct dentry *dentry; | |
45 | struct nfs_fh *fh; | |
46 | struct nfs_fattr *fattr; | |
47 | char *hostname; | |
48 | char *mnt_path; | |
6677d095 CL |
49 | struct sockaddr *addr; |
50 | size_t addrlen; | |
f7b422b1 DH |
51 | rpc_authflavor_t authflavor; |
52 | }; | |
53 | ||
a14017db CL |
54 | /* |
55 | * Note: RFC 1813 doesn't limit the number of auth flavors that | |
56 | * a server can return, so make something up. | |
57 | */ | |
58 | #define NFS_MAX_SECFLAVORS (12) | |
59 | ||
4cfd74fc CL |
60 | /* |
61 | * Value used if the user did not specify a port value. | |
62 | */ | |
63 | #define NFS_UNSPEC_PORT (-1) | |
64 | ||
a956beda TM |
65 | #define NFS_UNSPEC_RETRANS (UINT_MAX) |
66 | #define NFS_UNSPEC_TIMEO (UINT_MAX) | |
67 | ||
56e4ebf8 BS |
68 | /* |
69 | * Maximum number of pages that readdir can use for creating | |
70 | * a vmapped array of pages. | |
71 | */ | |
db531db9 | 72 | #define NFS_MAX_READDIR_PAGES 8 |
56e4ebf8 | 73 | |
fcf10398 BS |
74 | struct nfs_client_initdata { |
75 | unsigned long init_flags; | |
5c6e5b60 TM |
76 | const char *hostname; /* Hostname of the server */ |
77 | const struct sockaddr *addr; /* Address of the server */ | |
78 | const char *nodename; /* Hostname of the client */ | |
79 | const char *ip_addr; /* IP address of the client */ | |
fcf10398 | 80 | size_t addrlen; |
ab7017a3 | 81 | struct nfs_subversion *nfs_mod; |
fcf10398 BS |
82 | int proto; |
83 | u32 minorversion; | |
6619079d | 84 | unsigned int nconnect; |
fcf10398 | 85 | struct net *net; |
5c6e5b60 | 86 | const struct rpc_timeout *timeparms; |
1a58e8a0 | 87 | const struct cred *cred; |
fcf10398 BS |
88 | }; |
89 | ||
6b18eaa0 TT |
90 | /* |
91 | * In-kernel mount arguments | |
92 | */ | |
93 | struct nfs_parsed_mount_data { | |
94 | int flags; | |
8cb7f74e CL |
95 | unsigned int rsize, wsize; |
96 | unsigned int timeo, retrans; | |
97 | unsigned int acregmin, acregmax, | |
6b18eaa0 | 98 | acdirmin, acdirmax; |
8cb7f74e | 99 | unsigned int namlen; |
b797cac7 | 100 | unsigned int options; |
6b18eaa0 | 101 | unsigned int bsize; |
a3f73c27 WAA |
102 | struct nfs_auth_info auth_info; |
103 | rpc_authflavor_t selected_flavor; | |
6b18eaa0 | 104 | char *client_address; |
764302cc | 105 | unsigned int version; |
3fd5be9e | 106 | unsigned int minorversion; |
08734048 | 107 | char *fscache_uniq; |
b72e4f42 | 108 | bool need_mount; |
6b18eaa0 TT |
109 | |
110 | struct { | |
4c568017 CL |
111 | struct sockaddr_storage address; |
112 | size_t addrlen; | |
6b18eaa0 | 113 | char *hostname; |
78fa701f | 114 | u32 version; |
4cfd74fc | 115 | int port; |
78fa701f | 116 | unsigned short protocol; |
6b18eaa0 TT |
117 | } mount_server; |
118 | ||
119 | struct { | |
4c568017 CL |
120 | struct sockaddr_storage address; |
121 | size_t addrlen; | |
6b18eaa0 TT |
122 | char *hostname; |
123 | char *export_path; | |
4cfd74fc | 124 | int port; |
78fa701f | 125 | unsigned short protocol; |
28cc5cd8 | 126 | unsigned short nconnect; |
6b18eaa0 | 127 | } nfs_server; |
f9c3a380 | 128 | |
204cc0cc | 129 | void *lsm_opts; |
e50a7a1a | 130 | struct net *net; |
6b18eaa0 TT |
131 | }; |
132 | ||
146ec944 | 133 | /* mount_clnt.c */ |
c5d120f8 CL |
134 | struct nfs_mount_request { |
135 | struct sockaddr *sap; | |
136 | size_t salen; | |
137 | char *hostname; | |
138 | char *dirpath; | |
139 | u32 version; | |
140 | unsigned short protocol; | |
141 | struct nfs_fh *fh; | |
50a737f8 | 142 | int noresvport; |
8e02f6b9 CL |
143 | unsigned int *auth_flav_len; |
144 | rpc_authflavor_t *auth_flavs; | |
6d59b8d5 | 145 | struct net *net; |
c5d120f8 CL |
146 | }; |
147 | ||
fbdefd64 BS |
148 | struct nfs_mount_info { |
149 | void (*fill_super)(struct super_block *, struct nfs_mount_info *); | |
150 | int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *); | |
151 | struct nfs_parsed_mount_data *parsed; | |
152 | struct nfs_clone_mount *cloned; | |
153 | struct nfs_fh *mntfh; | |
154 | }; | |
155 | ||
c5d120f8 | 156 | extern int nfs_mount(struct nfs_mount_request *info); |
0b524123 | 157 | extern void nfs_umount(const struct nfs_mount_request *info); |
146ec944 | 158 | |
24c8dbbb | 159 | /* client.c */ |
a613fa16 | 160 | extern const struct rpc_program nfs_program; |
6b13168b | 161 | extern void nfs_clients_init(struct net *net); |
10b7a70c | 162 | extern void nfs_clients_exit(struct net *net); |
6663ee7f | 163 | extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *); |
5c6e5b60 | 164 | int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t); |
7d38de3f | 165 | struct nfs_client *nfs_get_client(const struct nfs_client_initdata *); |
fcf10398 BS |
166 | int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *); |
167 | void nfs_server_insert_lists(struct nfs_server *); | |
32e62b7c | 168 | void nfs_server_remove_lists(struct nfs_server *); |
a956beda | 169 | void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans); |
fcf10398 BS |
170 | int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t, |
171 | rpc_authflavor_t); | |
172 | struct nfs_server *nfs_alloc_server(void); | |
173 | void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); | |
54ceac45 | 174 | |
24c8dbbb | 175 | extern void nfs_put_client(struct nfs_client *); |
cdb7eced | 176 | extern void nfs_free_client(struct nfs_client *); |
28cd1b3f | 177 | extern struct nfs_client *nfs4_find_client_ident(struct net *, int); |
c36fca52 | 178 | extern struct nfs_client * |
c7add9a9 | 179 | nfs4_find_client_sessionid(struct net *, const struct sockaddr *, |
459de2ed | 180 | struct nfs4_sessionid *, u32); |
1179acc6 | 181 | extern struct nfs_server *nfs_create_server(struct nfs_mount_info *, |
ab7017a3 | 182 | struct nfs_subversion *); |
91ea40b9 | 183 | extern struct nfs_server *nfs4_create_server( |
1179acc6 BS |
184 | struct nfs_mount_info *, |
185 | struct nfs_subversion *); | |
54ceac45 DH |
186 | extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, |
187 | struct nfs_fh *); | |
32e62b7c | 188 | extern int nfs4_update_server(struct nfs_server *server, const char *hostname, |
292f503c TM |
189 | struct sockaddr *sap, size_t salen, |
190 | struct net *net); | |
54ceac45 DH |
191 | extern void nfs_free_server(struct nfs_server *server); |
192 | extern struct nfs_server *nfs_clone_server(struct nfs_server *, | |
193 | struct nfs_fh *, | |
7e6eb683 BS |
194 | struct nfs_fattr *, |
195 | rpc_authflavor_t); | |
a33e4b03 WAA |
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); | |
4697bd5e | 198 | extern int nfs_wait_client_init_complete(const struct nfs_client *clp); |
76db6d95 | 199 | extern void nfs_mark_client_ready(struct nfs_client *clp, int state); |
3fc75f12 | 200 | extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv, |
d83217c1 | 201 | const struct sockaddr *ds_addr, |
98fc685a AA |
202 | int ds_addrlen, int ds_proto, |
203 | unsigned int ds_timeo, | |
064172f3 | 204 | unsigned int ds_retrans, |
7d38de3f | 205 | u32 minor_version); |
0e20162e AA |
206 | extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *, |
207 | struct inode *); | |
b224f7cb | 208 | extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv, |
1a04c6e1 PT |
209 | const struct sockaddr *ds_addr, int ds_addrlen, |
210 | int ds_proto, unsigned int ds_timeo, | |
7d38de3f | 211 | unsigned int ds_retrans); |
6aaca566 DH |
212 | #ifdef CONFIG_PROC_FS |
213 | extern int __init nfs_fs_proc_init(void); | |
214 | extern void nfs_fs_proc_exit(void); | |
65b38851 EB |
215 | extern int nfs_fs_proc_net_init(struct net *net); |
216 | extern void nfs_fs_proc_net_exit(struct net *net); | |
6aaca566 | 217 | #else |
65b38851 EB |
218 | static inline int nfs_fs_proc_net_init(struct net *net) |
219 | { | |
220 | return 0; | |
221 | } | |
222 | static inline void nfs_fs_proc_net_exit(struct net *net) | |
223 | { | |
224 | } | |
6aaca566 DH |
225 | static inline int nfs_fs_proc_init(void) |
226 | { | |
227 | return 0; | |
228 | } | |
229 | static inline void nfs_fs_proc_exit(void) | |
230 | { | |
231 | } | |
232 | #endif | |
24c8dbbb | 233 | |
f7b422b1 | 234 | /* callback_xdr.c */ |
e9679189 CH |
235 | extern const struct svc_version nfs4_callback_version1; |
236 | extern const struct svc_version nfs4_callback_version4; | |
f7b422b1 | 237 | |
4db6e0b7 | 238 | struct nfs_pageio_descriptor; |
f7b422b1 DH |
239 | /* pagelist.c */ |
240 | extern int __init nfs_init_nfspagecache(void); | |
266bee88 | 241 | extern void nfs_destroy_nfspagecache(void); |
f7b422b1 | 242 | extern int __init nfs_init_readpagecache(void); |
266bee88 | 243 | extern void nfs_destroy_readpagecache(void); |
f7b422b1 | 244 | extern int __init nfs_init_writepagecache(void); |
266bee88 | 245 | extern void nfs_destroy_writepagecache(void); |
f7b422b1 | 246 | |
f7b422b1 | 247 | extern int __init nfs_init_directcache(void); |
266bee88 | 248 | extern void nfs_destroy_directcache(void); |
4db6e0b7 FI |
249 | extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, |
250 | struct nfs_pgio_header *hdr, | |
251 | void (*release)(struct nfs_pgio_header *hdr)); | |
252 | void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos); | |
210c7c17 | 253 | int nfs_iocounter_wait(struct nfs_lock_context *l_ctx); |
577b4232 | 254 | |
41d8d5b7 | 255 | extern const struct nfs_pageio_ops nfs_pgio_rw_ops; |
1e7f3a48 WAA |
256 | struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *); |
257 | void nfs_pgio_header_free(struct nfs_pgio_header *); | |
ef2c488c | 258 | int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); |
46a5ab47 | 259 | int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, |
a52458b4 | 260 | const struct cred *cred, const struct nfs_rpc_ops *rpc_ops, |
46a5ab47 | 261 | const struct rpc_call_ops *call_ops, int how, int flags); |
d4581383 | 262 | void nfs_free_request(struct nfs_page *req); |
48d635f1 PT |
263 | struct nfs_pgio_mirror * |
264 | nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc); | |
00bfa30a | 265 | |
47af81f2 PT |
266 | static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc) |
267 | { | |
268 | WARN_ON_ONCE(desc->pg_mirror_count < 1); | |
269 | return desc->pg_mirror_count > 1; | |
270 | } | |
271 | ||
138a2935 TM |
272 | static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1, |
273 | const struct nfs_open_context *ctx2) | |
274 | { | |
a52458b4 | 275 | return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state; |
138a2935 TM |
276 | } |
277 | ||
f7b422b1 | 278 | /* nfs2xdr.c */ |
499b4988 | 279 | extern const struct rpc_procinfo nfs_procedures[]; |
573c4e1e | 280 | extern int nfs2_decode_dirent(struct xdr_stream *, |
a7a3b1e9 | 281 | struct nfs_entry *, bool); |
f7b422b1 DH |
282 | |
283 | /* nfs3xdr.c */ | |
499b4988 | 284 | extern const struct rpc_procinfo nfs3_procedures[]; |
573c4e1e | 285 | extern int nfs3_decode_dirent(struct xdr_stream *, |
a7a3b1e9 | 286 | struct nfs_entry *, bool); |
f7b422b1 DH |
287 | |
288 | /* nfs4xdr.c */ | |
89d77c8f | 289 | #if IS_ENABLED(CONFIG_NFS_V4) |
573c4e1e | 290 | extern int nfs4_decode_dirent(struct xdr_stream *, |
a7a3b1e9 | 291 | struct nfs_entry *, bool); |
7d4e2747 | 292 | #endif |
2449ea2e AB |
293 | #ifdef CONFIG_NFS_V4_1 |
294 | extern const u32 nfs41_maxread_overhead; | |
295 | extern const u32 nfs41_maxwrite_overhead; | |
f1c097be | 296 | extern const u32 nfs41_maxgetdevinfo_overhead; |
2449ea2e | 297 | #endif |
f7b422b1 DH |
298 | |
299 | /* nfs4proc.c */ | |
89d77c8f | 300 | #if IS_ENABLED(CONFIG_NFS_V4) |
499b4988 | 301 | extern const struct rpc_procinfo nfs4_procedures[]; |
d75d5414 | 302 | #endif |
f7b422b1 | 303 | |
694e096f AS |
304 | #ifdef CONFIG_NFS_V4_SECURITY_LABEL |
305 | extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags); | |
a49c2691 KM |
306 | static inline struct nfs4_label * |
307 | nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) | |
308 | { | |
309 | if (!dst || !src) | |
310 | return NULL; | |
311 | ||
312 | if (src->len > NFS4_MAXLABELLEN) | |
313 | return NULL; | |
314 | ||
315 | dst->lfs = src->lfs; | |
316 | dst->pi = src->pi; | |
317 | dst->len = src->len; | |
318 | memcpy(dst->label, src->label, src->len); | |
319 | ||
320 | return dst; | |
321 | } | |
694e096f AS |
322 | static inline void nfs4_label_free(struct nfs4_label *label) |
323 | { | |
324 | if (label) { | |
325 | kfree(label->label); | |
326 | kfree(label); | |
327 | } | |
328 | return; | |
329 | } | |
fd1defc2 TM |
330 | |
331 | static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) | |
332 | { | |
333 | if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL)) | |
334 | nfsi->cache_validity |= NFS_INO_INVALID_LABEL; | |
335 | } | |
694e096f AS |
336 | #else |
337 | static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; } | |
338 | static inline void nfs4_label_free(void *label) {} | |
fd1defc2 TM |
339 | static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) |
340 | { | |
341 | } | |
a49c2691 KM |
342 | static inline struct nfs4_label * |
343 | nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) | |
344 | { | |
345 | return NULL; | |
346 | } | |
694e096f AS |
347 | #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ |
348 | ||
7fe5c398 TM |
349 | /* proc.c */ |
350 | void nfs_close_context(struct nfs_open_context *ctx, int is_sync); | |
8cab4c39 | 351 | extern struct nfs_client *nfs_init_client(struct nfs_client *clp, |
5c6e5b60 | 352 | const struct nfs_client_initdata *); |
7fe5c398 | 353 | |
979df72e | 354 | /* dir.c */ |
1bcf4c5c | 355 | extern void nfs_advise_use_readdirplus(struct inode *dir); |
311324ad | 356 | extern void nfs_force_use_readdirplus(struct inode *dir); |
1ab6c499 DC |
357 | extern unsigned long nfs_access_cache_count(struct shrinker *shrink, |
358 | struct shrink_control *sc); | |
359 | extern unsigned long nfs_access_cache_scan(struct shrinker *shrink, | |
360 | struct shrink_control *sc); | |
597d9289 BS |
361 | struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int); |
362 | int nfs_create(struct inode *, struct dentry *, umode_t, bool); | |
363 | int nfs_mkdir(struct inode *, struct dentry *, umode_t); | |
364 | int nfs_rmdir(struct inode *, struct dentry *); | |
365 | int nfs_unlink(struct inode *, struct dentry *); | |
366 | int nfs_symlink(struct inode *, struct dentry *, const char *); | |
367 | int nfs_link(struct dentry *, struct inode *, struct dentry *); | |
368 | int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); | |
1cd66c93 MS |
369 | int nfs_rename(struct inode *, struct dentry *, |
370 | struct inode *, struct dentry *, unsigned int); | |
979df72e | 371 | |
ce4ef7c0 | 372 | /* file.c */ |
4ff79bc7 | 373 | int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync); |
ce4ef7c0 | 374 | loff_t nfs_file_llseek(struct file *, loff_t, int); |
3aa2d199 | 375 | ssize_t nfs_file_read(struct kiocb *, struct iov_iter *); |
ce4ef7c0 | 376 | int nfs_file_mmap(struct file *, struct vm_area_struct *); |
edaf4369 | 377 | ssize_t nfs_file_write(struct kiocb *, struct iov_iter *); |
ce4ef7c0 BS |
378 | int nfs_file_release(struct inode *, struct file *); |
379 | int nfs_lock(struct file *, int, struct file_lock *); | |
380 | int nfs_flock(struct file *, int, struct file_lock *); | |
ce4ef7c0 | 381 | int nfs_check_flags(int); |
ce4ef7c0 | 382 | |
f7b422b1 | 383 | /* inode.c */ |
5746006f | 384 | extern struct workqueue_struct *nfsiod_workqueue; |
f7b422b1 | 385 | extern struct inode *nfs_alloc_inode(struct super_block *sb); |
ca1a199e | 386 | extern void nfs_free_inode(struct inode *); |
a9185b41 | 387 | extern int nfs_write_inode(struct inode *, struct writeback_control *); |
eed99357 | 388 | extern int nfs_drop_inode(struct inode *); |
19d87ca3 | 389 | extern void nfs_clear_inode(struct inode *); |
b57922d9 | 390 | extern void nfs_evict_inode(struct inode *); |
f41f7418 | 391 | void nfs_zap_acl_cache(struct inode *inode); |
61540bf6 | 392 | extern bool nfs_check_cache_invalid(struct inode *, unsigned long); |
dfd01f02 | 393 | extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode); |
5e4def20 | 394 | extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode); |
f7b422b1 DH |
395 | |
396 | /* super.c */ | |
6a74490d | 397 | extern const struct super_operations nfs_sops; |
ab7017a3 | 398 | extern struct file_system_type nfs_fs_type; |
54ceac45 | 399 | extern struct file_system_type nfs_xdev_fs_type; |
89d77c8f | 400 | #if IS_ENABLED(CONFIG_NFS_V4) |
54ceac45 | 401 | extern struct file_system_type nfs4_referral_fs_type; |
f7b422b1 | 402 | #endif |
4d4b69dd | 403 | bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t); |
ff9099f2 BS |
404 | struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *, |
405 | struct nfs_subversion *); | |
fbdefd64 BS |
406 | int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *); |
407 | int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *); | |
ab7017a3 BS |
408 | struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *, |
409 | struct nfs_mount_info *, struct nfs_subversion *); | |
fbdefd64 BS |
410 | struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *); |
411 | struct dentry * nfs_xdev_mount_common(struct file_system_type *, int, | |
412 | const char *, struct nfs_mount_info *); | |
413 | void nfs_kill_super(struct super_block *); | |
414 | void nfs_fill_super(struct super_block *, struct nfs_mount_info *); | |
4ebd9ab3 | 415 | |
f7b422b1 | 416 | extern struct rpc_stat nfs_rpcstat; |
4ebd9ab3 | 417 | |
f7b422b1 DH |
418 | extern int __init register_nfs_fs(void); |
419 | extern void __exit unregister_nfs_fs(void); | |
ea7c38fe | 420 | extern bool nfs_sb_active(struct super_block *sb); |
1daef0a8 | 421 | extern void nfs_sb_deactive(struct super_block *sb); |
f7b422b1 | 422 | |
a5864c99 TM |
423 | /* io.c */ |
424 | extern void nfs_start_io_read(struct inode *inode); | |
425 | extern void nfs_end_io_read(struct inode *inode); | |
426 | extern void nfs_start_io_write(struct inode *inode); | |
427 | extern void nfs_end_io_write(struct inode *inode); | |
428 | extern void nfs_start_io_direct(struct inode *inode); | |
429 | extern void nfs_end_io_direct(struct inode *inode); | |
430 | ||
651b0e70 TM |
431 | static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi) |
432 | { | |
433 | return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0; | |
434 | } | |
435 | ||
f7b422b1 | 436 | /* namespace.c */ |
97a54868 | 437 | #define NFS_PATH_CANONICAL 1 |
b514f872 | 438 | extern char *nfs_path(char **p, struct dentry *dentry, |
97a54868 | 439 | char *buffer, ssize_t buflen, unsigned flags); |
36d43a43 | 440 | extern struct vfsmount *nfs_d_automount(struct path *path); |
281cad46 BS |
441 | struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *, |
442 | struct nfs_fh *, struct nfs_fattr *); | |
443 | struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *, | |
444 | struct nfs_fattr *, rpc_authflavor_t); | |
f7b422b1 | 445 | |
54ceac45 | 446 | /* getroot.c */ |
0d5839ad AV |
447 | extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *, |
448 | const char *); | |
89d77c8f | 449 | #if IS_ENABLED(CONFIG_NFS_V4) |
0d5839ad AV |
450 | extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *, |
451 | const char *); | |
54ceac45 | 452 | |
5e6b1990 | 453 | extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool); |
7d4e2747 | 454 | #endif |
f7b422b1 | 455 | |
061ae2ed | 456 | struct nfs_pgio_completion_ops; |
f11c88af | 457 | /* read.c */ |
584aa810 | 458 | extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, |
fab5fc25 | 459 | struct inode *inode, bool force_mds, |
584aa810 | 460 | const struct nfs_pgio_completion_ops *compl_ops); |
f11c88af | 461 | extern void nfs_read_prepare(struct rpc_task *task, void *calldata); |
493292dd | 462 | extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); |
e885de1a | 463 | |
fbdefd64 | 464 | /* super.c */ |
fbdefd64 BS |
465 | void nfs_umount_begin(struct super_block *); |
466 | int nfs_statfs(struct dentry *, struct kstatfs *); | |
467 | int nfs_show_options(struct seq_file *, struct dentry *); | |
468 | int nfs_show_devname(struct seq_file *, struct dentry *); | |
469 | int nfs_show_path(struct seq_file *, struct dentry *); | |
470 | int nfs_show_stats(struct seq_file *, struct dentry *); | |
fbdefd64 BS |
471 | int nfs_remount(struct super_block *sb, int *flags, char *raw_data); |
472 | ||
def6ed7e | 473 | /* write.c */ |
1763da12 | 474 | extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, |
a20c93e3 | 475 | struct inode *inode, int ioflags, bool force_mds, |
1763da12 | 476 | const struct nfs_pgio_completion_ops *compl_ops); |
dce81290 | 477 | extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); |
0b7c0153 | 478 | extern void nfs_commit_free(struct nfs_commit_data *p); |
def6ed7e | 479 | extern void nfs_write_prepare(struct rpc_task *task, void *calldata); |
0b7c0153 FI |
480 | extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); |
481 | extern int nfs_initiate_commit(struct rpc_clnt *clnt, | |
482 | struct nfs_commit_data *data, | |
c36aae9a | 483 | const struct nfs_rpc_ops *nfs_ops, |
e0c2b380 | 484 | const struct rpc_call_ops *call_ops, |
9f0ec176 | 485 | int how, int flags); |
0b7c0153 | 486 | extern void nfs_init_commit(struct nfs_commit_data *data, |
e0c2b380 | 487 | struct list_head *head, |
f453a54a FI |
488 | struct pnfs_layout_segment *lseg, |
489 | struct nfs_commit_info *cinfo); | |
1763da12 FI |
490 | int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, |
491 | struct nfs_commit_info *cinfo, int max); | |
ce59515c | 492 | unsigned long nfs_reqs_to_commit(struct nfs_commit_info *); |
1763da12 FI |
493 | int nfs_scan_commit(struct inode *inode, struct list_head *dst, |
494 | struct nfs_commit_info *cinfo); | |
495 | void nfs_mark_request_commit(struct nfs_page *req, | |
496 | struct pnfs_layout_segment *lseg, | |
b57ff130 WAA |
497 | struct nfs_commit_info *cinfo, |
498 | u32 ds_commit_idx); | |
c65e6254 | 499 | int nfs_write_need_commit(struct nfs_pgio_header *); |
a08a8cd3 | 500 | void nfs_writeback_update_inode(struct nfs_pgio_header *hdr); |
1763da12 FI |
501 | int nfs_generic_commit_list(struct inode *inode, struct list_head *head, |
502 | int how, struct nfs_commit_info *cinfo); | |
e0c2b380 | 503 | void nfs_retry_commit(struct list_head *page_list, |
ea2cf228 | 504 | struct pnfs_layout_segment *lseg, |
b57ff130 WAA |
505 | struct nfs_commit_info *cinfo, |
506 | u32 ds_commit_idx); | |
0b7c0153 | 507 | void nfs_commitdata_release(struct nfs_commit_data *data); |
6272dcc6 | 508 | void nfs_request_add_commit_list(struct nfs_page *req, |
ea2cf228 | 509 | struct nfs_commit_info *cinfo); |
86d80f97 TM |
510 | void nfs_request_add_commit_list_locked(struct nfs_page *req, |
511 | struct list_head *dst, | |
512 | struct nfs_commit_info *cinfo); | |
ea2cf228 FI |
513 | void nfs_request_remove_commit_list(struct nfs_page *req, |
514 | struct nfs_commit_info *cinfo); | |
515 | void nfs_init_cinfo(struct nfs_commit_info *cinfo, | |
516 | struct inode *inode, | |
517 | struct nfs_direct_req *dreq); | |
dc24826b | 518 | int nfs_key_timeout_notify(struct file *filp, struct inode *inode); |
ce52914e | 519 | bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode); |
a7d42ddb | 520 | void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio); |
e0c2b380 | 521 | |
837bb1d7 TM |
522 | int nfs_filemap_write_and_wait_range(struct address_space *mapping, |
523 | loff_t lstart, loff_t lend); | |
524 | ||
a5314a74 TM |
525 | #ifdef CONFIG_NFS_V4_1 |
526 | static inline | |
527 | void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo) | |
528 | { | |
529 | int i; | |
530 | ||
531 | for (i = 0; i < cinfo->nbuckets; i++) | |
532 | cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW; | |
533 | } | |
534 | #else | |
535 | static inline | |
536 | void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo) | |
537 | { | |
538 | } | |
539 | #endif | |
540 | ||
074cc1de TM |
541 | #ifdef CONFIG_MIGRATION |
542 | extern int nfs_migrate_page(struct address_space *, | |
a6bc32b8 | 543 | struct page *, struct page *, enum migrate_mode); |
074cc1de | 544 | #endif |
def6ed7e | 545 | |
8fc3c386 TM |
546 | static inline int |
547 | nfs_write_verifier_cmp(const struct nfs_write_verifier *v1, | |
548 | const struct nfs_write_verifier *v2) | |
549 | { | |
550 | return memcmp(v1->data, v2->data, sizeof(v1->data)); | |
551 | } | |
552 | ||
0e862a40 JL |
553 | /* unlink.c */ |
554 | extern struct rpc_task * | |
555 | nfs_async_rename(struct inode *old_dir, struct inode *new_dir, | |
556 | struct dentry *old_dentry, struct dentry *new_dentry, | |
557 | void (*complete)(struct rpc_task *, struct nfs_renamedata *)); | |
558 | extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry); | |
559 | ||
1763da12 FI |
560 | /* direct.c */ |
561 | void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, | |
562 | struct nfs_direct_req *dreq); | |
6296556f | 563 | extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); |
1763da12 | 564 | |
cccef3b9 | 565 | /* nfs4proc.c */ |
8cab4c39 | 566 | extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, |
5c6e5b60 | 567 | const struct nfs_client_initdata *); |
05f4c350 CL |
568 | extern int nfs40_walk_client_list(struct nfs_client *clp, |
569 | struct nfs_client **result, | |
a52458b4 | 570 | const struct cred *cred); |
05f4c350 CL |
571 | extern int nfs41_walk_client_list(struct nfs_client *clp, |
572 | struct nfs_client **result, | |
a52458b4 | 573 | const struct cred *cred); |
10e037d1 S |
574 | extern void nfs4_test_session_trunk(struct rpc_clnt *clnt, |
575 | struct rpc_xprt *xprt, | |
576 | void *data); | |
cccef3b9 | 577 | |
ea7c38fe TM |
578 | static inline struct inode *nfs_igrab_and_active(struct inode *inode) |
579 | { | |
580 | inode = igrab(inode); | |
581 | if (inode != NULL && !nfs_sb_active(inode->i_sb)) { | |
582 | iput(inode); | |
583 | inode = NULL; | |
584 | } | |
585 | return inode; | |
586 | } | |
587 | ||
588 | static inline void nfs_iput_and_deactive(struct inode *inode) | |
589 | { | |
590 | if (inode != NULL) { | |
591 | struct super_block *sb = inode->i_sb; | |
592 | ||
593 | iput(inode); | |
594 | nfs_sb_deactive(sb); | |
595 | } | |
596 | } | |
597 | ||
f7b422b1 DH |
598 | /* |
599 | * Determine the device name as a string | |
600 | */ | |
b514f872 | 601 | static inline char *nfs_devname(struct dentry *dentry, |
54ceac45 | 602 | char *buffer, ssize_t buflen) |
f7b422b1 | 603 | { |
b514f872 | 604 | char *dummy; |
97a54868 | 605 | return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL); |
f7b422b1 DH |
606 | } |
607 | ||
608 | /* | |
609 | * Determine the actual block size (and log2 thereof) | |
610 | */ | |
611 | static inline | |
612 | unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) | |
613 | { | |
614 | /* make sure blocksize is a power of two */ | |
615 | if ((bsize & (bsize - 1)) || nrbitsp) { | |
616 | unsigned char nrbits; | |
617 | ||
618 | for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) | |
619 | ; | |
620 | bsize = 1 << nrbits; | |
621 | if (nrbitsp) | |
622 | *nrbitsp = nrbits; | |
623 | } | |
624 | ||
625 | return bsize; | |
626 | } | |
627 | ||
628 | /* | |
629 | * Calculate the number of 512byte blocks used. | |
630 | */ | |
9eaa67c6 | 631 | static inline blkcnt_t nfs_calc_block_size(u64 tsize) |
f7b422b1 | 632 | { |
9eaa67c6 | 633 | blkcnt_t used = (tsize + 511) >> 9; |
f7b422b1 DH |
634 | return (used > ULONG_MAX) ? ULONG_MAX : used; |
635 | } | |
636 | ||
637 | /* | |
638 | * Compute and set NFS server blocksize | |
639 | */ | |
640 | static inline | |
641 | unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) | |
642 | { | |
643 | if (bsize < NFS_MIN_FILE_IO_SIZE) | |
644 | bsize = NFS_DEF_FILE_IO_SIZE; | |
645 | else if (bsize >= NFS_MAX_FILE_IO_SIZE) | |
646 | bsize = NFS_MAX_FILE_IO_SIZE; | |
647 | ||
648 | return nfs_block_bits(bsize, nrbitsp); | |
649 | } | |
650 | ||
651 | /* | |
652 | * Determine the maximum file size for a superblock | |
653 | */ | |
654 | static inline | |
655 | void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) | |
656 | { | |
657 | sb->s_maxbytes = (loff_t)maxfilesize; | |
658 | if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) | |
659 | sb->s_maxbytes = MAX_LFS_FILESIZE; | |
660 | } | |
49a70f27 | 661 | |
d15bc38d TH |
662 | /* |
663 | * Record the page as unstable and mark its inode as dirty. | |
664 | */ | |
665 | static inline | |
86d80f97 | 666 | void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo) |
d15bc38d | 667 | { |
86d80f97 TM |
668 | if (!cinfo->dreq) { |
669 | struct inode *inode = page_file_mapping(page)->host; | |
d15bc38d | 670 | |
11fb9989 | 671 | inc_node_page_state(page, NR_UNSTABLE_NFS); |
86d80f97 TM |
672 | inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE); |
673 | __mark_inode_dirty(inode, I_DIRTY_DATASYNC); | |
674 | } | |
d15bc38d TH |
675 | } |
676 | ||
49a70f27 TM |
677 | /* |
678 | * Determine the number of bytes of data the page contains | |
679 | */ | |
680 | static inline | |
681 | unsigned int nfs_page_length(struct page *page) | |
682 | { | |
d56b4ddf | 683 | loff_t i_size = i_size_read(page_file_mapping(page)->host); |
49a70f27 TM |
684 | |
685 | if (i_size > 0) { | |
8cd79788 | 686 | pgoff_t index = page_index(page); |
09cbfeaf | 687 | pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT; |
8cd79788 | 688 | if (index < end_index) |
09cbfeaf | 689 | return PAGE_SIZE; |
8cd79788 | 690 | if (index == end_index) |
09cbfeaf | 691 | return ((i_size - 1) & ~PAGE_MASK) + 1; |
49a70f27 TM |
692 | } |
693 | return 0; | |
694 | } | |
8d5658c9 | 695 | |
0b26a0bf TM |
696 | /* |
697 | * Convert a umode to a dirent->d_type | |
698 | */ | |
699 | static inline | |
700 | unsigned char nfs_umode_to_dtype(umode_t mode) | |
701 | { | |
702 | return (mode >> 12) & 15; | |
703 | } | |
704 | ||
8d5658c9 TM |
705 | /* |
706 | * Determine the number of pages in an array of length 'len' and | |
707 | * with a base offset of 'base' | |
708 | */ | |
709 | static inline | |
710 | unsigned int nfs_page_array_len(unsigned int base, size_t len) | |
711 | { | |
712 | return ((unsigned long)len + (unsigned long)base + | |
713 | PAGE_SIZE - 1) >> PAGE_SHIFT; | |
714 | } | |
0110ee15 | 715 | |
3a1556e8 TM |
716 | /* |
717 | * Convert a struct timespec into a 64-bit change attribute | |
718 | * | |
719 | * This does approximately the same thing as timespec_to_ns(), | |
720 | * but for calculation efficiency, we multiply the seconds by | |
721 | * 1024*1024*1024. | |
722 | */ | |
723 | static inline | |
724 | u64 nfs_timespec_to_change_attr(const struct timespec *ts) | |
725 | { | |
726 | return ((u64)ts->tv_sec << 30) + ts->tv_nsec; | |
727 | } | |
1264a2f0 TM |
728 | |
729 | #ifdef CONFIG_CRC32 | |
730 | /** | |
731 | * nfs_fhandle_hash - calculate the crc32 hash for the filehandle | |
732 | * @fh - pointer to filehandle | |
733 | * | |
734 | * returns a crc32 hash for the filehandle that is compatible with | |
735 | * the one displayed by "wireshark". | |
736 | */ | |
737 | static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) | |
738 | { | |
739 | return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); | |
740 | } | |
48c9579a OK |
741 | static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid) |
742 | { | |
743 | return ~crc32_le(0xFFFFFFFF, &stateid->other[0], | |
744 | NFS4_STATEID_OTHER_SIZE); | |
745 | } | |
1264a2f0 TM |
746 | #else |
747 | static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) | |
748 | { | |
749 | return 0; | |
750 | } | |
48c9579a OK |
751 | static inline u32 nfs_stateid_hash(nfs4_stateid *stateid) |
752 | { | |
753 | return 0; | |
754 | } | |
1264a2f0 | 755 | #endif |
0bcbf039 PT |
756 | |
757 | static inline bool nfs_error_is_fatal(int err) | |
758 | { | |
759 | switch (err) { | |
760 | case -ERESTARTSYS: | |
7dc58ca5 | 761 | case -EINTR: |
54551d85 TM |
762 | case -EACCES: |
763 | case -EDQUOT: | |
764 | case -EFBIG: | |
0bcbf039 PT |
765 | case -EIO: |
766 | case -ENOSPC: | |
767 | case -EROFS: | |
54551d85 | 768 | case -ESTALE: |
0bcbf039 | 769 | case -E2BIG: |
2dc23aff | 770 | case -ENOMEM: |
11982a7c | 771 | case -ETIMEDOUT: |
0bcbf039 PT |
772 | return true; |
773 | default: | |
774 | return false; | |
775 | } | |
776 | } | |
bf4b4905 | 777 | |
8f54c7a4 TM |
778 | static inline bool nfs_error_is_fatal_on_server(int err) |
779 | { | |
780 | switch (err) { | |
781 | case 0: | |
782 | case -ERESTARTSYS: | |
783 | case -EINTR: | |
784 | return false; | |
785 | } | |
786 | return nfs_error_is_fatal(err); | |
787 | } |