hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/nfs/internal.h
....@@ -4,25 +4,19 @@
44 */
55
66 #include "nfs4_fs.h"
7
-#include <linux/mount.h>
7
+#include <linux/fs_context.h>
88 #include <linux/security.h>
99 #include <linux/crc32.h>
10
+#include <linux/sunrpc/addr.h>
1011 #include <linux/nfs_page.h>
1112 #include <linux/wait_bit.h>
1213
13
-#define NFS_MS_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS)
14
+#define NFS_SB_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS)
1415
1516 extern const struct export_operations nfs_export_ops;
1617
1718 struct nfs_string;
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)
19
+struct nfs_pageio_descriptor;
2620
2721 static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
2822 {
....@@ -39,17 +33,24 @@
3933 return 1;
4034 }
4135
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;
49
- struct sockaddr *addr;
50
- size_t addrlen;
51
- rpc_authflavor_t authflavor;
52
-};
36
+static inline bool nfs_lookup_is_soft_revalidate(const struct dentry *dentry)
37
+{
38
+ if (!(NFS_SB(dentry->d_sb)->flags & NFS_MOUNT_SOFTREVAL))
39
+ return false;
40
+ if (!d_is_positive(dentry) || !NFS_FH(d_inode(dentry))->size)
41
+ return false;
42
+ return true;
43
+}
44
+
45
+static inline fmode_t flags_to_mode(int flags)
46
+{
47
+ fmode_t res = (__force fmode_t)flags & FMODE_EXEC;
48
+ if ((flags & O_ACCMODE) != O_WRONLY)
49
+ res |= FMODE_READ;
50
+ if ((flags & O_ACCMODE) != O_RDONLY)
51
+ res |= FMODE_WRITE;
52
+ return res;
53
+}
5354
5455 /*
5556 * Note: RFC 1813 doesn't limit the number of auth flavors that
....@@ -81,19 +82,25 @@
8182 struct nfs_subversion *nfs_mod;
8283 int proto;
8384 u32 minorversion;
85
+ unsigned int nconnect;
8486 struct net *net;
8587 const struct rpc_timeout *timeparms;
88
+ const struct cred *cred;
8689 };
8790
8891 /*
8992 * In-kernel mount arguments
9093 */
91
-struct nfs_parsed_mount_data {
92
- int flags;
94
+struct nfs_fs_context {
95
+ bool internal;
96
+ bool skip_reconfig_option_check;
97
+ bool need_mount;
98
+ bool sloppy;
99
+ unsigned int flags; /* NFS{,4}_MOUNT_* flags */
93100 unsigned int rsize, wsize;
94101 unsigned int timeo, retrans;
95
- unsigned int acregmin, acregmax,
96
- acdirmin, acdirmax;
102
+ unsigned int acregmin, acregmax;
103
+ unsigned int acdirmin, acdirmax;
97104 unsigned int namlen;
98105 unsigned int options;
99106 unsigned int bsize;
....@@ -103,10 +110,14 @@
103110 unsigned int version;
104111 unsigned int minorversion;
105112 char *fscache_uniq;
106
- bool need_mount;
113
+ unsigned short protofamily;
114
+ unsigned short mountfamily;
107115
108116 struct {
109
- struct sockaddr_storage address;
117
+ union {
118
+ struct sockaddr address;
119
+ struct sockaddr_storage _address;
120
+ };
110121 size_t addrlen;
111122 char *hostname;
112123 u32 version;
....@@ -115,17 +126,60 @@
115126 } mount_server;
116127
117128 struct {
118
- struct sockaddr_storage address;
129
+ union {
130
+ struct sockaddr address;
131
+ struct sockaddr_storage _address;
132
+ };
119133 size_t addrlen;
120134 char *hostname;
121135 char *export_path;
122136 int port;
123137 unsigned short protocol;
138
+ unsigned short nconnect;
139
+ unsigned short export_path_len;
124140 } nfs_server;
125141
126
- struct security_mnt_opts lsm_opts;
127
- struct net *net;
142
+ struct nfs_fh *mntfh;
143
+ struct nfs_server *server;
144
+ struct nfs_subversion *nfs_mod;
145
+
146
+ /* Information for a cloned mount. */
147
+ struct nfs_clone_mount {
148
+ struct super_block *sb;
149
+ struct dentry *dentry;
150
+ struct nfs_fattr *fattr;
151
+ unsigned int inherited_bsize;
152
+ } clone_data;
128153 };
154
+
155
+#define nfs_errorf(fc, fmt, ...) ((fc)->log.log ? \
156
+ errorf(fc, fmt, ## __VA_ARGS__) : \
157
+ ({ dprintk(fmt "\n", ## __VA_ARGS__); }))
158
+
159
+#define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ? \
160
+ errorf(fc, fmt, ## __VA_ARGS__) : \
161
+ ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
162
+
163
+#define nfs_invalf(fc, fmt, ...) ((fc)->log.log ? \
164
+ invalf(fc, fmt, ## __VA_ARGS__) : \
165
+ ({ dprintk(fmt "\n", ## __VA_ARGS__); -EINVAL; }))
166
+
167
+#define nfs_finvalf(fc, fac, fmt, ...) ((fc)->log.log ? \
168
+ invalf(fc, fmt, ## __VA_ARGS__) : \
169
+ ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); -EINVAL; }))
170
+
171
+#define nfs_warnf(fc, fmt, ...) ((fc)->log.log ? \
172
+ warnf(fc, fmt, ## __VA_ARGS__) : \
173
+ ({ dprintk(fmt "\n", ## __VA_ARGS__); }))
174
+
175
+#define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ? \
176
+ warnf(fc, fmt, ## __VA_ARGS__) : \
177
+ ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
178
+
179
+static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
180
+{
181
+ return fc->fs_private;
182
+}
129183
130184 /* mount_clnt.c */
131185 struct nfs_mount_request {
....@@ -142,20 +196,13 @@
142196 struct net *net;
143197 };
144198
145
-struct nfs_mount_info {
146
- void (*fill_super)(struct super_block *, struct nfs_mount_info *);
147
- int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
148
- struct nfs_parsed_mount_data *parsed;
149
- struct nfs_clone_mount *cloned;
150
- struct nfs_fh *mntfh;
151
-};
152
-
153199 extern int nfs_mount(struct nfs_mount_request *info);
154200 extern void nfs_umount(const struct nfs_mount_request *info);
155201
156202 /* client.c */
157203 extern const struct rpc_program nfs_program;
158204 extern void nfs_clients_init(struct net *net);
205
+extern void nfs_clients_exit(struct net *net);
159206 extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
160207 int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
161208 struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
....@@ -168,20 +215,15 @@
168215 struct nfs_server *nfs_alloc_server(void);
169216 void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
170217
171
-extern void nfs_cleanup_cb_ident_idr(struct net *);
172218 extern void nfs_put_client(struct nfs_client *);
173219 extern void nfs_free_client(struct nfs_client *);
174220 extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
175221 extern struct nfs_client *
176222 nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
177223 struct nfs4_sessionid *, u32);
178
-extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
179
- struct nfs_subversion *);
180
-extern struct nfs_server *nfs4_create_server(
181
- struct nfs_mount_info *,
182
- struct nfs_subversion *);
183
-extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
184
- struct nfs_fh *);
224
+extern struct nfs_server *nfs_create_server(struct fs_context *);
225
+extern struct nfs_server *nfs4_create_server(struct fs_context *);
226
+extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
185227 extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
186228 struct sockaddr *sap, size_t salen,
187229 struct net *net);
....@@ -232,7 +274,9 @@
232274 extern const struct svc_version nfs4_callback_version1;
233275 extern const struct svc_version nfs4_callback_version4;
234276
235
-struct nfs_pageio_descriptor;
277
+/* fs_context.c */
278
+extern struct file_system_type nfs_fs_type;
279
+
236280 /* pagelist.c */
237281 extern int __init nfs_init_nfspagecache(void);
238282 extern void nfs_destroy_nfspagecache(void);
....@@ -254,22 +298,16 @@
254298 void nfs_pgio_header_free(struct nfs_pgio_header *);
255299 int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
256300 int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
257
- struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops,
301
+ const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
258302 const struct rpc_call_ops *call_ops, int how, int flags);
259303 void nfs_free_request(struct nfs_page *req);
260304 struct nfs_pgio_mirror *
261305 nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
262306
263
-static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
264
-{
265
- WARN_ON_ONCE(desc->pg_mirror_count < 1);
266
- return desc->pg_mirror_count > 1;
267
-}
268
-
269307 static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
270308 const struct nfs_open_context *ctx2)
271309 {
272
- return ctx1->cred == ctx2->cred && ctx1->state == ctx2->state;
310
+ return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
273311 }
274312
275313 /* nfs2xdr.c */
....@@ -380,7 +418,7 @@
380418 /* inode.c */
381419 extern struct workqueue_struct *nfsiod_workqueue;
382420 extern struct inode *nfs_alloc_inode(struct super_block *sb);
383
-extern void nfs_destroy_inode(struct inode *);
421
+extern void nfs_free_inode(struct inode *);
384422 extern int nfs_write_inode(struct inode *, struct writeback_control *);
385423 extern int nfs_drop_inode(struct inode *);
386424 extern void nfs_clear_inode(struct inode *);
....@@ -392,24 +430,10 @@
392430
393431 /* super.c */
394432 extern const struct super_operations nfs_sops;
395
-extern struct file_system_type nfs_fs_type;
396
-extern struct file_system_type nfs_xdev_fs_type;
397
-#if IS_ENABLED(CONFIG_NFS_V4)
398
-extern struct file_system_type nfs4_xdev_fs_type;
399
-extern struct file_system_type nfs4_referral_fs_type;
400
-#endif
401433 bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
402
-struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *,
403
- struct nfs_subversion *);
404
-int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
405
-int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
406
-struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *,
407
- struct nfs_mount_info *, struct nfs_subversion *);
408
-struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
409
-struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
410
- const char *, struct nfs_mount_info *);
434
+int nfs_try_get_tree(struct fs_context *);
435
+int nfs_get_tree_common(struct fs_context *);
411436 void nfs_kill_super(struct super_block *);
412
-void nfs_fill_super(struct super_block *, struct nfs_mount_info *);
413437
414438 extern struct rpc_stat nfs_rpcstat;
415439
....@@ -417,7 +441,9 @@
417441 extern void __exit unregister_nfs_fs(void);
418442 extern bool nfs_sb_active(struct super_block *sb);
419443 extern void nfs_sb_deactive(struct super_block *sb);
420
-
444
+extern int nfs_client_for_each_server(struct nfs_client *clp,
445
+ int (*fn)(struct nfs_server *, void *),
446
+ void *data);
421447 /* io.c */
422448 extern void nfs_start_io_read(struct inode *inode);
423449 extern void nfs_end_io_read(struct inode *inode);
....@@ -436,18 +462,12 @@
436462 extern char *nfs_path(char **p, struct dentry *dentry,
437463 char *buffer, ssize_t buflen, unsigned flags);
438464 extern struct vfsmount *nfs_d_automount(struct path *path);
439
-struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
440
- struct nfs_fh *, struct nfs_fattr *);
441
-struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
442
- struct nfs_fattr *, rpc_authflavor_t);
465
+int nfs_submount(struct fs_context *, struct nfs_server *);
466
+int nfs_do_submount(struct fs_context *);
443467
444468 /* getroot.c */
445
-extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
446
- const char *);
469
+extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
447470 #if IS_ENABLED(CONFIG_NFS_V4)
448
-extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
449
- const char *);
450
-
451471 extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
452472 #endif
453473
....@@ -466,7 +486,7 @@
466486 int nfs_show_devname(struct seq_file *, struct dentry *);
467487 int nfs_show_path(struct seq_file *, struct dentry *);
468488 int nfs_show_stats(struct seq_file *, struct dentry *);
469
-int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
489
+int nfs_reconfigure(struct fs_context *);
470490
471491 /* write.c */
472492 extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
....@@ -521,13 +541,25 @@
521541 loff_t lstart, loff_t lend);
522542
523543 #ifdef CONFIG_NFS_V4_1
544
+static inline void
545
+pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets,
546
+ unsigned int nbuckets)
547
+{
548
+ unsigned int i;
549
+
550
+ for (i = 0; i < nbuckets; i++)
551
+ buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
552
+}
524553 static inline
525554 void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
526555 {
527
- int i;
556
+ struct pnfs_commit_array *array;
528557
529
- for (i = 0; i < cinfo->nbuckets; i++)
530
- cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
558
+ rcu_read_lock();
559
+ list_for_each_entry_rcu(array, &cinfo->commits, cinfo_list)
560
+ pnfs_bucket_clear_pnfs_ds_commit_verifiers(array->buckets,
561
+ array->nbuckets);
562
+ rcu_read_unlock();
531563 }
532564 #else
533565 static inline
....@@ -548,6 +580,21 @@
548580 return memcmp(v1->data, v2->data, sizeof(v1->data));
549581 }
550582
583
+static inline bool
584
+nfs_write_match_verf(const struct nfs_writeverf *verf,
585
+ struct nfs_page *req)
586
+{
587
+ return verf->committed > NFS_UNSTABLE &&
588
+ !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier);
589
+}
590
+
591
+static inline gfp_t nfs_io_gfp_mask(void)
592
+{
593
+ if (current->flags & PF_WQ_WORKER)
594
+ return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
595
+ return GFP_KERNEL;
596
+}
597
+
551598 /* unlink.c */
552599 extern struct rpc_task *
553600 nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
....@@ -565,13 +612,13 @@
565612 const struct nfs_client_initdata *);
566613 extern int nfs40_walk_client_list(struct nfs_client *clp,
567614 struct nfs_client **result,
568
- struct rpc_cred *cred);
615
+ const struct cred *cred);
569616 extern int nfs41_walk_client_list(struct nfs_client *clp,
570617 struct nfs_client **result,
571
- struct rpc_cred *cred);
572
-extern int nfs4_test_session_trunk(struct rpc_clnt *,
573
- struct rpc_xprt *,
574
- void *);
618
+ const struct cred *cred);
619
+extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
620
+ struct rpc_xprt *xprt,
621
+ void *data);
575622
576623 static inline struct inode *nfs_igrab_and_active(struct inode *inode)
577624 {
....@@ -660,7 +707,8 @@
660707 }
661708
662709 /*
663
- * Record the page as unstable and mark its inode as dirty.
710
+ * Record the page as unstable (an extra writeback period) and mark its
711
+ * inode as dirty.
664712 */
665713 static inline
666714 void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
....@@ -668,8 +716,11 @@
668716 if (!cinfo->dreq) {
669717 struct inode *inode = page_file_mapping(page)->host;
670718
671
- inc_node_page_state(page, NR_UNSTABLE_NFS);
672
- inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
719
+ /* This page is really still in write-back - just that the
720
+ * writeback is happening on the server now.
721
+ */
722
+ inc_node_page_state(page, NR_WRITEBACK);
723
+ inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK);
673724 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
674725 }
675726 }
....@@ -714,14 +765,14 @@
714765 }
715766
716767 /*
717
- * Convert a struct timespec into a 64-bit change attribute
768
+ * Convert a struct timespec64 into a 64-bit change attribute
718769 *
719
- * This does approximately the same thing as timespec_to_ns(),
770
+ * This does approximately the same thing as timespec64_to_ns(),
720771 * but for calculation efficiency, we multiply the seconds by
721772 * 1024*1024*1024.
722773 */
723774 static inline
724
-u64 nfs_timespec_to_change_attr(const struct timespec *ts)
775
+u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
725776 {
726777 return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
727778 }
....@@ -758,6 +809,7 @@
758809 {
759810 switch (err) {
760811 case -ERESTARTSYS:
812
+ case -EINTR:
761813 case -EACCES:
762814 case -EDQUOT:
763815 case -EFBIG:
....@@ -766,15 +818,35 @@
766818 case -EROFS:
767819 case -ESTALE:
768820 case -E2BIG:
821
+ case -ENOMEM:
822
+ case -ETIMEDOUT:
769823 return true;
770824 default:
771825 return false;
772826 }
773827 }
774828
775
-static inline void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
829
+static inline bool nfs_error_is_fatal_on_server(int err)
776830 {
777
- ctx->error = error;
778
- smp_wmb();
779
- set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
831
+ switch (err) {
832
+ case 0:
833
+ case -ERESTARTSYS:
834
+ case -EINTR:
835
+ case -ENOMEM:
836
+ return false;
837
+ }
838
+ return nfs_error_is_fatal(err);
839
+}
840
+
841
+/*
842
+ * Select between a default port value and a user-specified port value.
843
+ * If a zero value is set, then autobind will be used.
844
+ */
845
+static inline void nfs_set_port(struct sockaddr *sap, int *port,
846
+ const unsigned short default_port)
847
+{
848
+ if (*port == NFS_UNSPEC_PORT)
849
+ *port = default_port;
850
+
851
+ rpc_set_port(sap, *port);
780852 }