blob: 2de7c56a1fbedb2e1e9077c7ba5bebf5992a0954 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Howellsf7b422b2006-06-09 09:34:33 -04002/*
3 * NFS internal definitions
4 */
5
Andy Adamsoneedc0202009-04-01 09:22:41 -04006#include "nfs4_fs.h"
David Howellsf2aedb72019-12-10 07:31:13 -05007#include <linux/fs_context.h>
Eric Parisf9c3a382008-03-05 14:20:18 -05008#include <linux/security.h>
Trond Myklebust1264a2f2013-08-12 16:06:31 -04009#include <linux/crc32.h>
David Howells9954bf92019-12-10 07:31:04 -050010#include <linux/sunrpc/addr.h>
Peng Tao47af81f2014-11-10 08:35:34 +080011#include <linux/nfs_page.h>
Ingo Molnar5dd43ce2017-06-20 12:19:09 +020012#include <linux/wait_bit.h>
David Howellsf7b422b2006-06-09 09:34:33 -040013
Scott Mayhew62a55d02019-12-10 07:31:14 -050014#define NFS_SB_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS)
David Howells08734042009-04-03 16:42:42 +010015
Peng Tao20fa1902017-06-29 06:34:53 -070016extern const struct export_operations nfs_export_ops;
17
David Howells54ceac42006-08-22 20:06:13 -040018struct nfs_string;
David Howellsf2aedb72019-12-10 07:31:13 -050019struct nfs_pageio_descriptor;
David Howells54ceac42006-08-22 20:06:13 -040020
Bryan Schumaker7ebb9312011-03-24 17:12:30 +000021static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
22{
23 if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
24 fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
25}
26
Andy Adamson533eb462011-06-13 18:25:56 -040027static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
28{
29 if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
30 (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
31 ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
32 return 0;
Andy Adamson533eb462011-06-13 18:25:56 -040033 return 1;
34}
35
Trond Myklebustf7b37b82020-01-14 12:06:34 -050036static 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
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -040045/*
Chuck Levera14017d2009-06-17 18:02:12 -070046 * Note: RFC 1813 doesn't limit the number of auth flavors that
47 * a server can return, so make something up.
48 */
49#define NFS_MAX_SECFLAVORS (12)
50
51/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -040052 * Value used if the user did not specify a port value.
53 */
54#define NFS_UNSPEC_PORT (-1)
55
Trond Myklebusta956bed2016-08-16 10:26:47 -040056#define NFS_UNSPEC_RETRANS (UINT_MAX)
57#define NFS_UNSPEC_TIMEO (UINT_MAX)
58
Bryan Schumakerfcf10392012-07-16 16:39:18 -040059struct nfs_client_initdata {
60 unsigned long init_flags;
Trond Myklebust5c6e5b62016-06-22 14:13:12 -040061 const char *hostname; /* Hostname of the server */
62 const struct sockaddr *addr; /* Address of the server */
63 const char *nodename; /* Hostname of the client */
64 const char *ip_addr; /* IP address of the client */
Bryan Schumakerfcf10392012-07-16 16:39:18 -040065 size_t addrlen;
Bryan Schumakerab7017a2012-07-30 16:05:16 -040066 struct nfs_subversion *nfs_mod;
Bryan Schumakerfcf10392012-07-16 16:39:18 -040067 int proto;
68 u32 minorversion;
Trond Myklebust66190792017-04-27 11:13:40 -040069 unsigned int nconnect;
Olga Kornievskaia7e134202021-08-27 14:37:17 -040070 unsigned int max_connect;
Bryan Schumakerfcf10392012-07-16 16:39:18 -040071 struct net *net;
Trond Myklebust5c6e5b62016-06-22 14:13:12 -040072 const struct rpc_timeout *timeparms;
Trond Myklebust1a58e8a2019-04-24 17:46:43 -040073 const struct cred *cred;
Bryan Schumakerfcf10392012-07-16 16:39:18 -040074};
75
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -040076/*
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -040077 * In-kernel mount arguments
78 */
David Howells5eb005c2019-12-10 07:31:06 -050079struct nfs_fs_context {
David Howellsf2aedb72019-12-10 07:31:13 -050080 bool internal;
81 bool skip_reconfig_option_check;
82 bool need_mount;
83 bool sloppy;
David Howellse5581002019-12-10 07:31:10 -050084 unsigned int flags; /* NFS{,4}_MOUNT_* flags */
Chuck Lever8cb7f742012-09-14 17:23:14 -040085 unsigned int rsize, wsize;
86 unsigned int timeo, retrans;
David Howellse5581002019-12-10 07:31:10 -050087 unsigned int acregmin, acregmax;
88 unsigned int acdirmin, acdirmax;
Chuck Lever8cb7f742012-09-14 17:23:14 -040089 unsigned int namlen;
David Howellsb797cac2009-04-03 16:42:48 +010090 unsigned int options;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -040091 unsigned int bsize;
Weston Andros Adamsona3f73c22013-10-18 15:15:16 -040092 struct nfs_auth_info auth_info;
93 rpc_authflavor_t selected_flavor;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -040094 char *client_address;
Chuck Lever764302c2009-09-08 19:50:03 -040095 unsigned int version;
Mike Sager3fd5be92009-04-01 09:21:48 -040096 unsigned int minorversion;
David Howells08734042009-04-03 16:42:42 +010097 char *fscache_uniq;
David Howellsf8ee01e2019-12-10 07:31:07 -050098 unsigned short protofamily;
99 unsigned short mountfamily;
Olga Kornievskaiaec1ade62021-02-19 17:22:33 -0500100 bool has_sec_mnt_opts;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -0400101
102 struct {
David Howellse5581002019-12-10 07:31:10 -0500103 union {
104 struct sockaddr address;
105 struct sockaddr_storage _address;
106 };
Chuck Lever4c568012007-12-10 14:59:28 -0500107 size_t addrlen;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -0400108 char *hostname;
Chuck Lever78fa7012008-03-14 14:10:15 -0400109 u32 version;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400110 int port;
Chuck Lever78fa7012008-03-14 14:10:15 -0400111 unsigned short protocol;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -0400112 } mount_server;
113
114 struct {
David Howellse5581002019-12-10 07:31:10 -0500115 union {
116 struct sockaddr address;
117 struct sockaddr_storage _address;
118 };
Chuck Lever4c568012007-12-10 14:59:28 -0500119 size_t addrlen;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -0400120 char *hostname;
121 char *export_path;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400122 int port;
Chuck Lever78fa7012008-03-14 14:10:15 -0400123 unsigned short protocol;
Trond Myklebust28cc5cd2017-04-26 23:30:48 -0400124 unsigned short nconnect;
Olga Kornievskaia7e134202021-08-27 14:37:17 -0400125 unsigned short max_connect;
David Howellsf2aedb72019-12-10 07:31:13 -0500126 unsigned short export_path_len;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -0400127 } nfs_server;
Eric Parisf9c3a382008-03-05 14:20:18 -0500128
Scott Mayhew62a55d02019-12-10 07:31:14 -0500129 struct nfs_fh *mntfh;
130 struct nfs_server *server;
131 struct nfs_subversion *nfs_mod;
David Howells48be8a62019-12-10 07:31:09 -0500132
Scott Mayhew62a55d02019-12-10 07:31:14 -0500133 /* Information for a cloned mount. */
134 struct nfs_clone_mount {
135 struct super_block *sb;
136 struct dentry *dentry;
137 struct nfs_fattr *fattr;
138 unsigned int inherited_bsize;
139 } clone_data;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -0400140};
141
Scott Mayhewc98e9da2021-01-05 08:54:32 -0500142#define nfs_errorf(fc, fmt, ...) ((fc)->log.log ? \
143 errorf(fc, fmt, ## __VA_ARGS__) : \
144 ({ dprintk(fmt "\n", ## __VA_ARGS__); }))
145
146#define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ? \
147 errorf(fc, fmt, ## __VA_ARGS__) : \
148 ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
149
150#define nfs_invalf(fc, fmt, ...) ((fc)->log.log ? \
151 invalf(fc, fmt, ## __VA_ARGS__) : \
152 ({ dprintk(fmt "\n", ## __VA_ARGS__); -EINVAL; }))
153
154#define nfs_finvalf(fc, fac, fmt, ...) ((fc)->log.log ? \
155 invalf(fc, fmt, ## __VA_ARGS__) : \
156 ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); -EINVAL; }))
157
158#define nfs_warnf(fc, fmt, ...) ((fc)->log.log ? \
159 warnf(fc, fmt, ## __VA_ARGS__) : \
160 ({ dprintk(fmt "\n", ## __VA_ARGS__); }))
161
162#define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ? \
163 warnf(fc, fmt, ## __VA_ARGS__) : \
164 ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
Scott Mayhewce8866f02019-12-10 07:31:15 -0500165
David Howellsf2aedb72019-12-10 07:31:13 -0500166static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
167{
168 return fc->fs_private;
169}
170
Chuck Lever146ec942008-12-23 15:21:34 -0500171/* mount_clnt.c */
Chuck Leverc5d120f2008-12-23 15:21:35 -0500172struct nfs_mount_request {
173 struct sockaddr *sap;
174 size_t salen;
175 char *hostname;
176 char *dirpath;
177 u32 version;
178 unsigned short protocol;
179 struct nfs_fh *fh;
Chuck Lever50a737f2008-12-23 15:21:37 -0500180 int noresvport;
Chuck Lever8e02f6b9a2009-06-17 18:02:13 -0700181 unsigned int *auth_flav_len;
182 rpc_authflavor_t *auth_flavs;
Stanislav Kinsbursky6d59b8d2012-01-10 16:12:54 +0400183 struct net *net;
Chuck Leverc5d120f2008-12-23 15:21:35 -0500184};
185
Eryu Guanc9301cb2021-03-23 10:57:13 +0800186extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans);
Chuck Lever0b524122009-08-09 15:09:30 -0400187extern void nfs_umount(const struct nfs_mount_request *info);
Chuck Lever146ec942008-12-23 15:21:34 -0500188
David Howells24c8dbb2006-08-22 20:06:10 -0400189/* client.c */
Trond Myklebusta613fa12012-01-20 13:53:56 -0500190extern const struct rpc_program nfs_program;
Stanislav Kinsbursky6b131682012-01-23 17:26:05 +0000191extern void nfs_clients_init(struct net *net);
Trond Myklebust10b7a702019-02-06 09:32:50 -0500192extern void nfs_clients_exit(struct net *net);
Bryan Schumaker6663ee72012-06-20 15:53:46 -0400193extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
Trond Myklebust5c6e5b62016-06-22 14:13:12 -0400194int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
Anna Schumaker7d38de32016-11-17 15:15:55 -0500195struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
Anna Schumakere5731132021-10-14 13:55:05 -0400196int nfs_probe_server(struct nfs_server *, struct nfs_fh *);
Bryan Schumakerfcf10392012-07-16 16:39:18 -0400197void nfs_server_insert_lists(struct nfs_server *);
Chuck Lever32e62b72013-10-17 14:12:28 -0400198void nfs_server_remove_lists(struct nfs_server *);
Trond Myklebusta956bed2016-08-16 10:26:47 -0400199void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
Bryan Schumakerfcf10392012-07-16 16:39:18 -0400200int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
201 rpc_authflavor_t);
202struct nfs_server *nfs_alloc_server(void);
203void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
David Howells54ceac42006-08-22 20:06:13 -0400204
David Howells24c8dbb2006-08-22 20:06:10 -0400205extern void nfs_put_client(struct nfs_client *);
Bryan Schumakercdb7ece2012-06-20 15:53:45 -0400206extern void nfs_free_client(struct nfs_client *);
Stanislav Kinsbursky28cd1b32012-01-23 17:26:22 +0000207extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
Andy Adamsonc36fca52011-01-06 02:04:32 +0000208extern struct nfs_client *
Stanislav Kinsburskyc7add9a2012-01-26 15:11:49 +0400209nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
Bryan Schumaker459de2e2013-06-05 11:15:01 -0400210 struct nfs4_sessionid *, u32);
Scott Mayhew62a55d02019-12-10 07:31:14 -0500211extern struct nfs_server *nfs_create_server(struct fs_context *);
Anna Schumaker01dde762021-10-14 13:55:04 -0400212extern void nfs4_server_set_init_caps(struct nfs_server *);
Scott Mayhew62a55d02019-12-10 07:31:14 -0500213extern struct nfs_server *nfs4_create_server(struct fs_context *);
214extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
Chuck Lever32e62b72013-10-17 14:12:28 -0400215extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
Trond Myklebust292f5032014-02-16 21:42:56 -0500216 struct sockaddr *sap, size_t salen,
217 struct net *net);
David Howells54ceac42006-08-22 20:06:13 -0400218extern void nfs_free_server(struct nfs_server *server);
219extern struct nfs_server *nfs_clone_server(struct nfs_server *,
220 struct nfs_fh *,
Bryan Schumaker7e6eb682012-04-27 13:27:42 -0400221 struct nfs_fattr *,
222 rpc_authflavor_t);
Weston Andros Adamsona33e4b02017-03-09 12:56:48 -0500223extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
224extern int nfs_client_init_status(const struct nfs_client *clp);
Trond Myklebust4697bd52012-05-23 13:24:36 -0400225extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
Andy Adamson76db6d92009-04-01 09:22:38 -0400226extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
Tigran Mkrtchyan3fc75f12016-06-13 19:57:35 +0200227extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
Andy Adamsond83217c2011-03-01 01:34:17 +0000228 const struct sockaddr *ds_addr,
Andy Adamson98fc6852012-04-27 17:53:45 -0400229 int ds_addrlen, int ds_proto,
230 unsigned int ds_timeo,
Peng Tao064172f2014-05-29 21:07:00 +0800231 unsigned int ds_retrans,
Anna Schumaker7d38de32016-11-17 15:15:55 -0500232 u32 minor_version);
Andy Adamson0e201622013-09-06 14:14:00 -0400233extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
234 struct inode *);
Tigran Mkrtchyanb224f7c2016-06-13 20:52:00 +0200235extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
Peng Tao1a04c6e2014-05-30 18:15:57 +0800236 const struct sockaddr *ds_addr, int ds_addrlen,
237 int ds_proto, unsigned int ds_timeo,
Anna Schumaker7d38de32016-11-17 15:15:55 -0500238 unsigned int ds_retrans);
David Howells6aaca562006-08-22 20:06:13 -0400239#ifdef CONFIG_PROC_FS
240extern int __init nfs_fs_proc_init(void);
241extern void nfs_fs_proc_exit(void);
Eric W. Biederman65b38852014-07-31 04:35:20 -0700242extern int nfs_fs_proc_net_init(struct net *net);
243extern void nfs_fs_proc_net_exit(struct net *net);
David Howells6aaca562006-08-22 20:06:13 -0400244#else
Eric W. Biederman65b38852014-07-31 04:35:20 -0700245static inline int nfs_fs_proc_net_init(struct net *net)
246{
247 return 0;
248}
249static inline void nfs_fs_proc_net_exit(struct net *net)
250{
251}
David Howells6aaca562006-08-22 20:06:13 -0400252static inline int nfs_fs_proc_init(void)
253{
254 return 0;
255}
256static inline void nfs_fs_proc_exit(void)
257{
258}
259#endif
David Howells24c8dbb2006-08-22 20:06:10 -0400260
David Howellsf7b422b2006-06-09 09:34:33 -0400261/* callback_xdr.c */
Christoph Hellwige9679182017-05-12 16:21:37 +0200262extern const struct svc_version nfs4_callback_version1;
263extern const struct svc_version nfs4_callback_version4;
David Howellsf7b422b2006-06-09 09:34:33 -0400264
David Howellsf2aedb72019-12-10 07:31:13 -0500265/* fs_context.c */
266extern struct file_system_type nfs_fs_type;
David Howells9954bf92019-12-10 07:31:04 -0500267
David Howellsf7b422b2006-06-09 09:34:33 -0400268/* pagelist.c */
269extern int __init nfs_init_nfspagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700270extern void nfs_destroy_nfspagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400271extern int __init nfs_init_readpagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700272extern void nfs_destroy_readpagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400273extern int __init nfs_init_writepagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700274extern void nfs_destroy_writepagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400275
David Howellsf7b422b2006-06-09 09:34:33 -0400276extern int __init nfs_init_directcache(void);
David Brownell266bee82006-06-27 12:59:15 -0700277extern void nfs_destroy_directcache(void);
Fred Isaman4db6e0b2012-04-20 14:47:46 -0400278extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
279 struct nfs_pgio_header *hdr,
280 void (*release)(struct nfs_pgio_header *hdr));
281void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
Benjamin Coddington210c7c12016-01-06 10:40:18 -0500282int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
Trond Myklebust577b4232013-04-08 21:38:12 -0400283
Anna Schumaker41d8d5b2014-05-06 09:12:40 -0400284extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
Weston Andros Adamson1e7f3a42014-06-09 11:48:33 -0400285struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
286void nfs_pgio_header_free(struct nfs_pgio_header *);
Anna Schumakeref2c4882014-05-06 09:12:36 -0400287int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
Peng Tao46a5ab42014-06-13 23:02:25 +0800288int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
NeilBrowna52458b2018-12-03 11:30:31 +1100289 const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
Peng Tao46a5ab42014-06-13 23:02:25 +0800290 const struct rpc_call_ops *call_ops, int how, int flags);
Weston Andros Adamsond4581382014-07-11 10:20:48 -0400291void nfs_free_request(struct nfs_page *req);
Peng Tao48d635f2014-11-10 08:35:35 +0800292struct nfs_pgio_mirror *
293nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
Anna Schumaker00bfa302014-05-06 09:12:29 -0400294
Trond Myklebust138a2932015-10-01 17:17:06 -0400295static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
296 const struct nfs_open_context *ctx2)
297{
NeilBrowna52458b2018-12-03 11:30:31 +1100298 return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
Trond Myklebust138a2932015-10-01 17:17:06 -0400299}
300
David Howellsf7b422b2006-06-09 09:34:33 -0400301/* nfs2xdr.c */
Christoph Hellwig499b4982017-05-12 15:36:49 +0200302extern const struct rpc_procinfo nfs_procedures[];
Chuck Lever573c4e12010-12-14 14:58:11 +0000303extern int nfs2_decode_dirent(struct xdr_stream *,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400304 struct nfs_entry *, bool);
David Howellsf7b422b2006-06-09 09:34:33 -0400305
306/* nfs3xdr.c */
Christoph Hellwig499b4982017-05-12 15:36:49 +0200307extern const struct rpc_procinfo nfs3_procedures[];
Chuck Lever573c4e12010-12-14 14:58:11 +0000308extern int nfs3_decode_dirent(struct xdr_stream *,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400309 struct nfs_entry *, bool);
David Howellsf7b422b2006-06-09 09:34:33 -0400310
311/* nfs4xdr.c */
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400312#if IS_ENABLED(CONFIG_NFS_V4)
Chuck Lever573c4e12010-12-14 14:58:11 +0000313extern int nfs4_decode_dirent(struct xdr_stream *,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400314 struct nfs_entry *, bool);
David Howells7d4e2742006-08-22 20:06:07 -0400315#endif
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500316#ifdef CONFIG_NFS_V4_1
317extern const u32 nfs41_maxread_overhead;
318extern const u32 nfs41_maxwrite_overhead;
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400319extern const u32 nfs41_maxgetdevinfo_overhead;
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500320#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400321
322/* nfs4proc.c */
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400323#if IS_ENABLED(CONFIG_NFS_V4)
Christoph Hellwig499b4982017-05-12 15:36:49 +0200324extern const struct rpc_procinfo nfs4_procedures[];
Andrew Mortond75d5412006-06-25 02:41:26 -0700325#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400326
Anna Schumaker694e0962013-11-13 12:29:08 -0500327#ifdef CONFIG_NFS_V4_SECURITY_LABEL
328extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
Kinglong Meea49c2692015-07-27 15:31:38 +0800329static inline struct nfs4_label *
330nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
331{
332 if (!dst || !src)
333 return NULL;
334
335 if (src->len > NFS4_MAXLABELLEN)
336 return NULL;
337
338 dst->lfs = src->lfs;
339 dst->pi = src->pi;
340 dst->len = src->len;
341 memcpy(dst->label, src->label, src->len);
342
343 return dst;
344}
Trond Myklebustfd1defc2014-02-06 14:38:53 -0500345
346static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
347{
348 if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
349 nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
350}
Anna Schumaker694e0962013-11-13 12:29:08 -0500351#else
352static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
Trond Myklebustfd1defc2014-02-06 14:38:53 -0500353static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
354{
355}
Kinglong Meea49c2692015-07-27 15:31:38 +0800356static inline struct nfs4_label *
357nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
358{
359 return NULL;
360}
Anna Schumaker694e0962013-11-13 12:29:08 -0500361#endif /* CONFIG_NFS_V4_SECURITY_LABEL */
362
Trond Myklebust7fe5c392009-03-19 15:35:50 -0400363/* proc.c */
364void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
Chuck Lever8cab4c32012-05-21 22:45:59 -0400365extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
Trond Myklebust5c6e5b62016-06-22 14:13:12 -0400366 const struct nfs_client_initdata *);
Trond Myklebust7fe5c392009-03-19 15:35:50 -0400367
Trond Myklebust979df722006-07-25 11:28:19 -0400368/* dir.c */
Trond Myklebust1bcf4c52016-12-02 09:15:37 -0500369extern void nfs_advise_use_readdirplus(struct inode *dir);
Trond Myklebust311324a2014-02-07 17:02:08 -0500370extern void nfs_force_use_readdirplus(struct inode *dir);
Dave Chinner1ab6c492013-08-28 10:18:09 +1000371extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
372 struct shrink_control *sc);
373extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
374 struct shrink_control *sc);
Bryan Schumaker597d9282012-07-16 16:39:10 -0400375struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
Trond Myklebust00bdadc2021-12-17 15:36:57 -0500376void nfs_d_prune_case_insensitive_aliases(struct inode *inode);
Christian Brauner549c7292021-01-21 14:19:43 +0100377int nfs_create(struct user_namespace *, struct inode *, struct dentry *,
378 umode_t, bool);
379int nfs_mkdir(struct user_namespace *, struct inode *, struct dentry *,
380 umode_t);
Bryan Schumaker597d9282012-07-16 16:39:10 -0400381int nfs_rmdir(struct inode *, struct dentry *);
382int nfs_unlink(struct inode *, struct dentry *);
Christian Brauner549c7292021-01-21 14:19:43 +0100383int nfs_symlink(struct user_namespace *, struct inode *, struct dentry *,
384 const char *);
Bryan Schumaker597d9282012-07-16 16:39:10 -0400385int nfs_link(struct dentry *, struct inode *, struct dentry *);
Christian Brauner549c7292021-01-21 14:19:43 +0100386int nfs_mknod(struct user_namespace *, struct inode *, struct dentry *, umode_t,
387 dev_t);
388int nfs_rename(struct user_namespace *, struct inode *, struct dentry *,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200389 struct inode *, struct dentry *, unsigned int);
Trond Myklebust979df722006-07-25 11:28:19 -0400390
Bryan Schumakerce4ef7c2012-07-16 16:39:15 -0400391/* file.c */
Christoph Hellwig4ff79bc2016-03-02 17:35:54 +0100392int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
Bryan Schumakerce4ef7c2012-07-16 16:39:15 -0400393loff_t nfs_file_llseek(struct file *, loff_t, int);
Al Viro3aa2d192014-04-02 20:14:12 -0400394ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
Bryan Schumakerce4ef7c2012-07-16 16:39:15 -0400395int nfs_file_mmap(struct file *, struct vm_area_struct *);
Al Viroedaf4362014-04-03 14:07:25 -0400396ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
Bryan Schumakerce4ef7c2012-07-16 16:39:15 -0400397int nfs_file_release(struct inode *, struct file *);
398int nfs_lock(struct file *, int, struct file_lock *);
399int nfs_flock(struct file *, int, struct file_lock *);
Bryan Schumakerce4ef7c2012-07-16 16:39:15 -0400400int nfs_check_flags(int);
Bryan Schumakerce4ef7c2012-07-16 16:39:15 -0400401
David Howellsf7b422b2006-06-09 09:34:33 -0400402/* inode.c */
Trond Myklebust57460062008-02-19 20:04:22 -0500403extern struct workqueue_struct *nfsiod_workqueue;
David Howellsf7b422b2006-06-09 09:34:33 -0400404extern struct inode *nfs_alloc_inode(struct super_block *sb);
Al Viroca1a1992019-04-15 20:19:40 -0400405extern void nfs_free_inode(struct inode *);
Christoph Hellwiga9185b42010-03-05 09:21:37 +0100406extern int nfs_write_inode(struct inode *, struct writeback_control *);
Trond Myklebusteed99352012-12-14 14:36:36 -0500407extern int nfs_drop_inode(struct inode *);
Bryan Schumaker19d87ca2012-07-30 16:05:21 -0400408extern void nfs_clear_inode(struct inode *);
Al Virob57922d2010-06-07 14:34:48 -0400409extern void nfs_evict_inode(struct inode *);
Trond Myklebustfd6d3fe2021-03-08 14:42:53 -0500410extern void nfs_zap_acl_cache(struct inode *inode);
411extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
Trond Myklebust61540bf2016-12-08 18:18:38 -0500412extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
Peter Zijlstradfd01f02015-12-13 22:11:16 +0100413extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
David Howells5e4def22017-11-02 15:27:44 +0000414extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);
David Howellsf7b422b2006-06-09 09:34:33 -0400415
416/* super.c */
Bryan Schumaker6a744902012-07-30 16:05:20 -0400417extern const struct super_operations nfs_sops;
Weston Andros Adamson4d4b69d2013-10-18 15:15:19 -0400418bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
David Howellsf2aedb72019-12-10 07:31:13 -0500419int nfs_try_get_tree(struct fs_context *);
420int nfs_get_tree_common(struct fs_context *);
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400421void nfs_kill_super(struct super_block *);
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +0200422
David Howellsf7b422b2006-06-09 09:34:33 -0400423extern struct rpc_stat nfs_rpcstat;
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +0200424
David Howellsf7b422b2006-06-09 09:34:33 -0400425extern int __init register_nfs_fs(void);
426extern void __exit unregister_nfs_fs(void);
Trond Myklebustea7c38f2015-02-05 15:13:24 -0500427extern bool nfs_sb_active(struct super_block *sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400428extern void nfs_sb_deactive(struct super_block *sb);
Trond Myklebust3c9e5022020-02-26 19:16:09 -0500429extern int nfs_client_for_each_server(struct nfs_client *clp,
430 int (*fn)(struct nfs_server *, void *),
431 void *data);
Trond Myklebusta5864c92016-06-03 17:07:19 -0400432/* io.c */
433extern void nfs_start_io_read(struct inode *inode);
434extern void nfs_end_io_read(struct inode *inode);
435extern void nfs_start_io_write(struct inode *inode);
436extern void nfs_end_io_write(struct inode *inode);
437extern void nfs_start_io_direct(struct inode *inode);
438extern void nfs_end_io_direct(struct inode *inode);
439
Trond Myklebust651b0e72016-06-25 17:24:46 -0400440static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
441{
442 return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
443}
444
David Howellsf7b422b2006-06-09 09:34:33 -0400445/* namespace.c */
Ben Hutchings97a54862012-10-21 19:23:52 +0100446#define NFS_PATH_CANONICAL 1
Al Virob514f872011-03-16 06:26:11 -0400447extern char *nfs_path(char **p, struct dentry *dentry,
Ben Hutchings97a54862012-10-21 19:23:52 +0100448 char *buffer, ssize_t buflen, unsigned flags);
David Howells36d43a42011-01-14 18:45:42 +0000449extern struct vfsmount *nfs_d_automount(struct path *path);
David Howellsf2aedb72019-12-10 07:31:13 -0500450int nfs_submount(struct fs_context *, struct nfs_server *);
451int nfs_do_submount(struct fs_context *);
David Howellsf7b422b2006-06-09 09:34:33 -0400452
David Howells54ceac42006-08-22 20:06:13 -0400453/* getroot.c */
Scott Mayhew62a55d02019-12-10 07:31:14 -0500454extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
Bryan Schumaker89d77c82012-07-30 16:05:25 -0400455#if IS_ENABLED(CONFIG_NFS_V4)
Trond Myklebust5e6b1992013-09-07 12:58:57 -0400456extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
David Howells7d4e2742006-08-22 20:06:07 -0400457#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400458
Fred Isaman061ae2e2012-04-20 14:47:48 -0400459struct nfs_pgio_completion_ops;
Andy Adamsonf11c88a2009-04-01 09:22:25 -0400460/* read.c */
Fred Isaman584aa812012-04-20 14:47:51 -0400461extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
Christoph Hellwigfab5fc22014-04-16 15:07:22 +0200462 struct inode *inode, bool force_mds,
Fred Isaman584aa812012-04-20 14:47:51 -0400463 const struct nfs_pgio_completion_ops *compl_ops);
Andy Adamsonf11c88a2009-04-01 09:22:25 -0400464extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
Trond Myklebust493292d2011-07-13 15:58:28 -0400465extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
Trond Myklebuste885de12011-06-10 13:30:23 -0400466
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400467/* super.c */
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400468void nfs_umount_begin(struct super_block *);
469int nfs_statfs(struct dentry *, struct kstatfs *);
470int nfs_show_options(struct seq_file *, struct dentry *);
471int nfs_show_devname(struct seq_file *, struct dentry *);
472int nfs_show_path(struct seq_file *, struct dentry *);
473int nfs_show_stats(struct seq_file *, struct dentry *);
David Howellsf2aedb72019-12-10 07:31:13 -0500474int nfs_reconfigure(struct fs_context *);
Bryan Schumakerfbdefd62012-07-16 16:39:20 -0400475
Andy Adamsondef6ed72009-04-01 09:22:26 -0400476/* write.c */
Fred Isaman1763da12012-04-20 14:47:57 -0400477extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
Christoph Hellwiga20c93e2014-04-16 15:07:21 +0200478 struct inode *inode, int ioflags, bool force_mds,
Fred Isaman1763da12012-04-20 14:47:57 -0400479 const struct nfs_pgio_completion_ops *compl_ops);
Trond Myklebustdce81292011-07-13 15:59:19 -0400480extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
Fred Isaman0b7c0152012-04-20 14:47:39 -0400481extern void nfs_commit_free(struct nfs_commit_data *p);
Andy Adamsondef6ed72009-04-01 09:22:26 -0400482extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
Fred Isaman0b7c0152012-04-20 14:47:39 -0400483extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
484extern int nfs_initiate_commit(struct rpc_clnt *clnt,
485 struct nfs_commit_data *data,
Peng Taoc36aae92014-06-09 07:10:14 +0800486 const struct nfs_rpc_ops *nfs_ops,
Fred Isamane0c2b382011-03-23 13:27:53 +0000487 const struct rpc_call_ops *call_ops,
Andy Adamson9f0ec1762012-04-27 17:53:44 -0400488 int how, int flags);
Fred Isaman0b7c0152012-04-20 14:47:39 -0400489extern void nfs_init_commit(struct nfs_commit_data *data,
Fred Isamane0c2b382011-03-23 13:27:53 +0000490 struct list_head *head,
Fred Isamanf453a542012-04-20 14:47:54 -0400491 struct pnfs_layout_segment *lseg,
492 struct nfs_commit_info *cinfo);
Fred Isaman1763da12012-04-20 14:47:57 -0400493int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
494 struct nfs_commit_info *cinfo, int max);
Anna Schumakerce595152014-05-06 09:12:34 -0400495unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
Fred Isaman1763da12012-04-20 14:47:57 -0400496int nfs_scan_commit(struct inode *inode, struct list_head *dst,
497 struct nfs_commit_info *cinfo);
498void nfs_mark_request_commit(struct nfs_page *req,
499 struct pnfs_layout_segment *lseg,
Weston Andros Adamsonb57ff132014-09-05 18:20:21 -0400500 struct nfs_commit_info *cinfo,
501 u32 ds_commit_idx);
Weston Andros Adamsonc65e6252014-06-09 11:48:36 -0400502int nfs_write_need_commit(struct nfs_pgio_header *);
Trond Myklebusta08a8cd2015-02-26 17:36:09 -0500503void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
Fred Isaman1763da12012-04-20 14:47:57 -0400504int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
505 int how, struct nfs_commit_info *cinfo);
Fred Isamane0c2b382011-03-23 13:27:53 +0000506void nfs_retry_commit(struct list_head *page_list,
Fred Isamanea2cf222012-04-20 14:47:53 -0400507 struct pnfs_layout_segment *lseg,
Weston Andros Adamsonb57ff132014-09-05 18:20:21 -0400508 struct nfs_commit_info *cinfo,
509 u32 ds_commit_idx);
Fred Isaman0b7c0152012-04-20 14:47:39 -0400510void nfs_commitdata_release(struct nfs_commit_data *data);
Anna Schumaker6272dcc2016-01-15 16:54:15 -0500511void nfs_request_add_commit_list(struct nfs_page *req,
Fred Isamanea2cf222012-04-20 14:47:53 -0400512 struct nfs_commit_info *cinfo);
Trond Myklebust86d80f92015-07-31 16:24:30 -0400513void nfs_request_add_commit_list_locked(struct nfs_page *req,
514 struct list_head *dst,
515 struct nfs_commit_info *cinfo);
Fred Isamanea2cf222012-04-20 14:47:53 -0400516void nfs_request_remove_commit_list(struct nfs_page *req,
517 struct nfs_commit_info *cinfo);
518void nfs_init_cinfo(struct nfs_commit_info *cinfo,
519 struct inode *inode,
520 struct nfs_direct_req *dreq);
Andy Adamsondc248262013-08-14 11:59:16 -0400521int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
Scott Mayhewce52914e2016-06-07 15:14:48 -0400522bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
Weston Andros Adamsona7d42dd2014-09-19 10:55:07 -0400523void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
Fred Isamane0c2b382011-03-23 13:27:53 +0000524
Trond Myklebust837bb1d2016-06-25 18:12:03 -0400525int nfs_filemap_write_and_wait_range(struct address_space *mapping,
526 loff_t lstart, loff_t lend);
527
Trond Myklebusta5314a72016-06-01 21:42:32 -0400528#ifdef CONFIG_NFS_V4_1
Trond Myklebuste3b9f7e2020-03-20 19:06:48 -0400529static inline void
530pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets,
531 unsigned int nbuckets)
532{
533 unsigned int i;
534
535 for (i = 0; i < nbuckets; i++)
536 buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
537}
Trond Myklebusta5314a72016-06-01 21:42:32 -0400538static inline
539void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
540{
Trond Myklebuste3b9f7e2020-03-20 19:06:48 -0400541 struct pnfs_commit_array *array;
Trond Myklebusta5314a72016-06-01 21:42:32 -0400542
Trond Myklebusta9901892020-03-20 16:04:06 -0400543 rcu_read_lock();
544 list_for_each_entry_rcu(array, &cinfo->commits, cinfo_list)
Trond Myklebuste3b9f7e2020-03-20 19:06:48 -0400545 pnfs_bucket_clear_pnfs_ds_commit_verifiers(array->buckets,
546 array->nbuckets);
Trond Myklebusta9901892020-03-20 16:04:06 -0400547 rcu_read_unlock();
Trond Myklebusta5314a72016-06-01 21:42:32 -0400548}
549#else
550static inline
551void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
552{
553}
554#endif
555
Trond Myklebust074cc1d2009-08-10 08:54:13 -0400556#ifdef CONFIG_MIGRATION
557extern int nfs_migrate_page(struct address_space *,
Mel Gormana6bc32b2012-01-12 17:19:43 -0800558 struct page *, struct page *, enum migrate_mode);
Trond Myklebust074cc1d2009-08-10 08:54:13 -0400559#endif
Andy Adamsondef6ed72009-04-01 09:22:26 -0400560
Trond Myklebust8fc3c382016-06-01 21:32:24 -0400561static inline int
562nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
563 const struct nfs_write_verifier *v2)
564{
565 return memcmp(v1->data, v2->data, sizeof(v1->data));
566}
567
Trond Myklebust1f284762020-03-21 09:27:46 -0400568static inline bool
569nfs_write_match_verf(const struct nfs_writeverf *verf,
570 struct nfs_page *req)
571{
572 return verf->committed > NFS_UNSTABLE &&
573 !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier);
574}
575
Jeff Layton0e862a42014-03-17 07:06:55 -0400576/* unlink.c */
577extern struct rpc_task *
578nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
579 struct dentry *old_dentry, struct dentry *new_dentry,
580 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
581extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
582
Fred Isaman1763da12012-04-20 14:47:57 -0400583/* direct.c */
584void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
585 struct nfs_direct_req *dreq);
Peng Tao62965562012-09-25 14:55:57 +0800586extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
Fred Isaman1763da12012-04-20 14:47:57 -0400587
Andy Adamsoncccef3b2009-04-01 09:22:03 -0400588/* nfs4proc.c */
Chuck Lever8cab4c32012-05-21 22:45:59 -0400589extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
Trond Myklebust5c6e5b62016-06-22 14:13:12 -0400590 const struct nfs_client_initdata *);
Chuck Lever05f4c352012-09-14 17:24:32 -0400591extern int nfs40_walk_client_list(struct nfs_client *clp,
592 struct nfs_client **result,
NeilBrowna52458b2018-12-03 11:30:31 +1100593 const struct cred *cred);
Chuck Lever05f4c352012-09-14 17:24:32 -0400594extern int nfs41_walk_client_list(struct nfs_client *clp,
595 struct nfs_client **result,
NeilBrowna52458b2018-12-03 11:30:31 +1100596 const struct cred *cred);
Santosh kumar pradhan10e037d2018-12-19 12:29:57 +0530597extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
598 struct rpc_xprt *xprt,
599 void *data);
Andy Adamsoncccef3b2009-04-01 09:22:03 -0400600
Trond Myklebustea7c38f2015-02-05 15:13:24 -0500601static inline struct inode *nfs_igrab_and_active(struct inode *inode)
602{
Trond Myklebust896567e2021-01-10 15:58:08 -0500603 struct super_block *sb = inode->i_sb;
604
605 if (sb && nfs_sb_active(sb)) {
606 if (igrab(inode))
607 return inode;
608 nfs_sb_deactive(sb);
Trond Myklebustea7c38f2015-02-05 15:13:24 -0500609 }
Trond Myklebust896567e2021-01-10 15:58:08 -0500610 return NULL;
Trond Myklebustea7c38f2015-02-05 15:13:24 -0500611}
612
613static inline void nfs_iput_and_deactive(struct inode *inode)
614{
615 if (inode != NULL) {
616 struct super_block *sb = inode->i_sb;
617
618 iput(inode);
619 nfs_sb_deactive(sb);
620 }
621}
622
Andy Adamson557134a2009-04-01 09:21:53 -0400623/*
David Howellsf7b422b2006-06-09 09:34:33 -0400624 * Determine the device name as a string
625 */
Al Virob514f872011-03-16 06:26:11 -0400626static inline char *nfs_devname(struct dentry *dentry,
David Howells54ceac42006-08-22 20:06:13 -0400627 char *buffer, ssize_t buflen)
David Howellsf7b422b2006-06-09 09:34:33 -0400628{
Al Virob514f872011-03-16 06:26:11 -0400629 char *dummy;
Ben Hutchings97a54862012-10-21 19:23:52 +0100630 return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
David Howellsf7b422b2006-06-09 09:34:33 -0400631}
632
633/*
634 * Determine the actual block size (and log2 thereof)
635 */
636static inline
637unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
638{
639 /* make sure blocksize is a power of two */
640 if ((bsize & (bsize - 1)) || nrbitsp) {
641 unsigned char nrbits;
642
643 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
644 ;
645 bsize = 1 << nrbits;
646 if (nrbitsp)
647 *nrbitsp = nrbits;
648 }
649
650 return bsize;
651}
652
653/*
654 * Calculate the number of 512byte blocks used.
655 */
Chuck Lever9eaa67c2007-07-01 12:12:19 -0400656static inline blkcnt_t nfs_calc_block_size(u64 tsize)
David Howellsf7b422b2006-06-09 09:34:33 -0400657{
Chuck Lever9eaa67c2007-07-01 12:12:19 -0400658 blkcnt_t used = (tsize + 511) >> 9;
David Howellsf7b422b2006-06-09 09:34:33 -0400659 return (used > ULONG_MAX) ? ULONG_MAX : used;
660}
661
662/*
663 * Compute and set NFS server blocksize
664 */
665static inline
666unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
667{
668 if (bsize < NFS_MIN_FILE_IO_SIZE)
669 bsize = NFS_DEF_FILE_IO_SIZE;
670 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
671 bsize = NFS_MAX_FILE_IO_SIZE;
672
673 return nfs_block_bits(bsize, nrbitsp);
674}
675
676/*
677 * Determine the maximum file size for a superblock
678 */
679static inline
680void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
681{
682 sb->s_maxbytes = (loff_t)maxfilesize;
683 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
684 sb->s_maxbytes = MAX_LFS_FILESIZE;
685}
Trond Myklebust49a70f22006-12-05 00:35:38 -0500686
687/*
NeilBrown8d928902020-06-01 21:48:21 -0700688 * Record the page as unstable (an extra writeback period) and mark its
689 * inode as dirty.
Tom Haynesd15bc382015-02-13 13:19:53 -0800690 */
691static inline
Trond Myklebust86d80f92015-07-31 16:24:30 -0400692void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
Tom Haynesd15bc382015-02-13 13:19:53 -0800693{
Trond Myklebust86d80f92015-07-31 16:24:30 -0400694 if (!cinfo->dreq) {
695 struct inode *inode = page_file_mapping(page)->host;
Tom Haynesd15bc382015-02-13 13:19:53 -0800696
NeilBrown8d928902020-06-01 21:48:21 -0700697 /* This page is really still in write-back - just that the
698 * writeback is happening on the server now.
699 */
700 inc_node_page_state(page, NR_WRITEBACK);
701 inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK);
Trond Myklebust86d80f92015-07-31 16:24:30 -0400702 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
703 }
Tom Haynesd15bc382015-02-13 13:19:53 -0800704}
705
706/*
Trond Myklebust49a70f22006-12-05 00:35:38 -0500707 * Determine the number of bytes of data the page contains
708 */
709static inline
710unsigned int nfs_page_length(struct page *page)
711{
Mel Gormand56b4dd2012-07-31 16:45:06 -0700712 loff_t i_size = i_size_read(page_file_mapping(page)->host);
Trond Myklebust49a70f22006-12-05 00:35:38 -0500713
714 if (i_size > 0) {
Huang Ying8cd79782016-10-07 17:00:24 -0700715 pgoff_t index = page_index(page);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300716 pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
Huang Ying8cd79782016-10-07 17:00:24 -0700717 if (index < end_index)
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300718 return PAGE_SIZE;
Huang Ying8cd79782016-10-07 17:00:24 -0700719 if (index == end_index)
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300720 return ((i_size - 1) & ~PAGE_MASK) + 1;
Trond Myklebust49a70f22006-12-05 00:35:38 -0500721 }
722 return 0;
723}
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400724
725/*
Trond Myklebust0b26a0b2010-11-20 14:26:44 -0500726 * Convert a umode to a dirent->d_type
727 */
728static inline
729unsigned char nfs_umode_to_dtype(umode_t mode)
730{
731 return (mode >> 12) & 15;
732}
733
734/*
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400735 * Determine the number of pages in an array of length 'len' and
736 * with a base offset of 'base'
737 */
738static inline
739unsigned int nfs_page_array_len(unsigned int base, size_t len)
740{
741 return ((unsigned long)len + (unsigned long)base +
742 PAGE_SIZE - 1) >> PAGE_SHIFT;
743}
Trond Myklebust0110ee12009-12-07 09:00:24 -0500744
Trond Myklebust3a1556e2012-04-27 13:48:18 -0400745/*
Arnd Bergmannae084832019-11-11 21:16:23 +0100746 * Convert a struct timespec64 into a 64-bit change attribute
Trond Myklebust3a1556e2012-04-27 13:48:18 -0400747 *
Arnd Bergmannae084832019-11-11 21:16:23 +0100748 * This does approximately the same thing as timespec64_to_ns(),
Trond Myklebust3a1556e2012-04-27 13:48:18 -0400749 * but for calculation efficiency, we multiply the seconds by
750 * 1024*1024*1024.
751 */
752static inline
Trond Myklebuste86d5a02019-10-04 16:38:56 -0400753u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
Trond Myklebust3a1556e2012-04-27 13:48:18 -0400754{
755 return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
756}
Trond Myklebust1264a2f2013-08-12 16:06:31 -0400757
758#ifdef CONFIG_CRC32
759/**
760 * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
761 * @fh - pointer to filehandle
762 *
763 * returns a crc32 hash for the filehandle that is compatible with
764 * the one displayed by "wireshark".
765 */
766static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
767{
768 return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
769}
Olga Kornievskaia48c95792015-11-24 13:29:41 -0500770static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
771{
772 return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
773 NFS4_STATEID_OTHER_SIZE);
774}
Trond Myklebust1264a2f2013-08-12 16:06:31 -0400775#else
776static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
777{
778 return 0;
779}
Olga Kornievskaia48c95792015-11-24 13:29:41 -0500780static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
781{
782 return 0;
783}
Trond Myklebust1264a2f2013-08-12 16:06:31 -0400784#endif
Peng Tao0bcbf032015-12-05 15:57:31 +0800785
786static inline bool nfs_error_is_fatal(int err)
787{
788 switch (err) {
789 case -ERESTARTSYS:
Trond Myklebust7dc58ca2019-01-22 07:39:09 -0500790 case -EINTR:
Trond Myklebust54551d82017-04-26 12:21:49 -0400791 case -EACCES:
792 case -EDQUOT:
793 case -EFBIG:
Peng Tao0bcbf032015-12-05 15:57:31 +0800794 case -EIO:
795 case -ENOSPC:
796 case -EROFS:
Trond Myklebust54551d82017-04-26 12:21:49 -0400797 case -ESTALE:
Peng Tao0bcbf032015-12-05 15:57:31 +0800798 case -E2BIG:
Trond Myklebust2dc23af2019-02-13 08:29:27 -0500799 case -ENOMEM:
Trond Myklebust11982a72019-04-07 13:58:59 -0400800 case -ETIMEDOUT:
Peng Tao0bcbf032015-12-05 15:57:31 +0800801 return true;
802 default:
803 return false;
804 }
805}
NeilBrownbf4b4902017-09-11 13:15:50 +1000806
Trond Myklebust8f54c7a2019-08-15 12:26:05 -0400807static inline bool nfs_error_is_fatal_on_server(int err)
808{
809 switch (err) {
810 case 0:
811 case -ERESTARTSYS:
812 case -EINTR:
813 return false;
814 }
815 return nfs_error_is_fatal(err);
816}
David Howells9954bf92019-12-10 07:31:04 -0500817
818/*
819 * Select between a default port value and a user-specified port value.
820 * If a zero value is set, then autobind will be used.
821 */
822static inline void nfs_set_port(struct sockaddr *sap, int *port,
823 const unsigned short default_port)
824{
825 if (*port == NFS_UNSPEC_PORT)
826 *port = default_port;
827
828 rpc_set_port(sap, *port);
829}