1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2f7b422b1SDavid Howells /* 3f7b422b1SDavid Howells * NFS internal definitions 4f7b422b1SDavid Howells */ 5f7b422b1SDavid Howells 6eedc020eSAndy Adamson #include "nfs4_fs.h" 7f2aedb71SDavid Howells #include <linux/fs_context.h> 8f9c3a380SEric Paris #include <linux/security.h> 91264a2f0STrond Myklebust #include <linux/crc32.h> 109954bf92SDavid Howells #include <linux/sunrpc/addr.h> 1147af81f2SPeng Tao #include <linux/nfs_page.h> 125dd43ce2SIngo Molnar #include <linux/wait_bit.h> 13f7b422b1SDavid Howells 1462a55d08SScott Mayhew #define NFS_SB_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS) 1508734048SDavid Howells 1620fa1902SPeng Tao extern const struct export_operations nfs_export_ops; 1720fa1902SPeng Tao 1854ceac45SDavid Howells struct nfs_string; 19f2aedb71SDavid Howells struct nfs_pageio_descriptor; 2054ceac45SDavid Howells 217ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr) 227ebb9315SBryan Schumaker { 237ebb9315SBryan Schumaker if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid)) 247ebb9315SBryan Schumaker fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT; 257ebb9315SBryan Schumaker } 267ebb9315SBryan Schumaker 27533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr) 28533eb461SAndy Adamson { 29533eb461SAndy Adamson if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) || 30533eb461SAndy Adamson (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && 31533eb461SAndy Adamson ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) 32533eb461SAndy Adamson return 0; 33533eb461SAndy Adamson return 1; 34533eb461SAndy Adamson } 35533eb461SAndy Adamson 36f7b37b8bSTrond Myklebust static inline bool nfs_lookup_is_soft_revalidate(const struct dentry *dentry) 37f7b37b8bSTrond Myklebust { 38f7b37b8bSTrond Myklebust if (!(NFS_SB(dentry->d_sb)->flags & NFS_MOUNT_SOFTREVAL)) 39f7b37b8bSTrond Myklebust return false; 40f7b37b8bSTrond Myklebust if (!d_is_positive(dentry) || !NFS_FH(d_inode(dentry))->size) 41f7b37b8bSTrond Myklebust return false; 42f7b37b8bSTrond Myklebust return true; 43f7b37b8bSTrond Myklebust } 44f7b37b8bSTrond Myklebust 45b243874fSChenXiaoSong static inline fmode_t flags_to_mode(int flags) 46b243874fSChenXiaoSong { 47b243874fSChenXiaoSong fmode_t res = (__force fmode_t)flags & FMODE_EXEC; 48b243874fSChenXiaoSong if ((flags & O_ACCMODE) != O_WRONLY) 49b243874fSChenXiaoSong res |= FMODE_READ; 50b243874fSChenXiaoSong if ((flags & O_ACCMODE) != O_RDONLY) 51b243874fSChenXiaoSong res |= FMODE_WRITE; 52b243874fSChenXiaoSong return res; 53b243874fSChenXiaoSong } 54b243874fSChenXiaoSong 556b18eaa0S\"Talpey, Thomas\ /* 56a14017dbSChuck Lever * Note: RFC 1813 doesn't limit the number of auth flavors that 57a14017dbSChuck Lever * a server can return, so make something up. 58a14017dbSChuck Lever */ 59a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS (12) 60a14017dbSChuck Lever 61a14017dbSChuck Lever /* 624cfd74fcSChuck Lever * Value used if the user did not specify a port value. 634cfd74fcSChuck Lever */ 644cfd74fcSChuck Lever #define NFS_UNSPEC_PORT (-1) 654cfd74fcSChuck Lever 66a956bedaSTrond Myklebust #define NFS_UNSPEC_RETRANS (UINT_MAX) 67a956bedaSTrond Myklebust #define NFS_UNSPEC_TIMEO (UINT_MAX) 68a956bedaSTrond Myklebust 69fcf10398SBryan Schumaker struct nfs_client_initdata { 70fcf10398SBryan Schumaker unsigned long init_flags; 715c6e5b60STrond Myklebust const char *hostname; /* Hostname of the server */ 725c6e5b60STrond Myklebust const struct sockaddr *addr; /* Address of the server */ 735c6e5b60STrond Myklebust const char *nodename; /* Hostname of the client */ 745c6e5b60STrond Myklebust const char *ip_addr; /* IP address of the client */ 75fcf10398SBryan Schumaker size_t addrlen; 76ab7017a3SBryan Schumaker struct nfs_subversion *nfs_mod; 77fcf10398SBryan Schumaker int proto; 78fcf10398SBryan Schumaker u32 minorversion; 796619079dSTrond Myklebust unsigned int nconnect; 807e134205SOlga Kornievskaia unsigned int max_connect; 81fcf10398SBryan Schumaker struct net *net; 825c6e5b60STrond Myklebust const struct rpc_timeout *timeparms; 831a58e8a0STrond Myklebust const struct cred *cred; 84fcf10398SBryan Schumaker }; 85fcf10398SBryan Schumaker 8656e4ebf8SBryan Schumaker /* 876b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 886b18eaa0S\"Talpey, Thomas\ */ 895eb005caSDavid Howells struct nfs_fs_context { 90f2aedb71SDavid Howells bool internal; 91f2aedb71SDavid Howells bool skip_reconfig_option_check; 92f2aedb71SDavid Howells bool need_mount; 93f2aedb71SDavid Howells bool sloppy; 94e558100fSDavid Howells unsigned int flags; /* NFS{,4}_MOUNT_* flags */ 958cb7f74eSChuck Lever unsigned int rsize, wsize; 968cb7f74eSChuck Lever unsigned int timeo, retrans; 97e558100fSDavid Howells unsigned int acregmin, acregmax; 98e558100fSDavid Howells unsigned int acdirmin, acdirmax; 998cb7f74eSChuck Lever unsigned int namlen; 100b797cac7SDavid Howells unsigned int options; 1016b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 102a3f73c27SWeston Andros Adamson struct nfs_auth_info auth_info; 103a3f73c27SWeston Andros Adamson rpc_authflavor_t selected_flavor; 1046b18eaa0S\"Talpey, Thomas\ char *client_address; 105764302ccSChuck Lever unsigned int version; 1063fd5be9eSMike Sager unsigned int minorversion; 10708734048SDavid Howells char *fscache_uniq; 108f8ee01e3SDavid Howells unsigned short protofamily; 109f8ee01e3SDavid Howells unsigned short mountfamily; 110ec1ade6aSOlga Kornievskaia bool has_sec_mnt_opts; 1116b18eaa0S\"Talpey, Thomas\ 1126b18eaa0S\"Talpey, Thomas\ struct { 113e558100fSDavid Howells union { 114e558100fSDavid Howells struct sockaddr address; 115e558100fSDavid Howells struct sockaddr_storage _address; 116e558100fSDavid Howells }; 1174c568017SChuck Lever size_t addrlen; 1186b18eaa0S\"Talpey, Thomas\ char *hostname; 11978fa701fSChuck Lever u32 version; 1204cfd74fcSChuck Lever int port; 12178fa701fSChuck Lever unsigned short protocol; 1226b18eaa0S\"Talpey, Thomas\ } mount_server; 1236b18eaa0S\"Talpey, Thomas\ 1246b18eaa0S\"Talpey, Thomas\ struct { 125e558100fSDavid Howells union { 126e558100fSDavid Howells struct sockaddr address; 127e558100fSDavid Howells struct sockaddr_storage _address; 128e558100fSDavid Howells }; 1294c568017SChuck Lever size_t addrlen; 1306b18eaa0S\"Talpey, Thomas\ char *hostname; 1316b18eaa0S\"Talpey, Thomas\ char *export_path; 1324cfd74fcSChuck Lever int port; 13378fa701fSChuck Lever unsigned short protocol; 13428cc5cd8STrond Myklebust unsigned short nconnect; 1357e134205SOlga Kornievskaia unsigned short max_connect; 136f2aedb71SDavid Howells unsigned short export_path_len; 1376b18eaa0S\"Talpey, Thomas\ } nfs_server; 138f9c3a380SEric Paris 13962a55d08SScott Mayhew struct nfs_fh *mntfh; 14062a55d08SScott Mayhew struct nfs_server *server; 14162a55d08SScott Mayhew struct nfs_subversion *nfs_mod; 14248be8a66SDavid Howells 14362a55d08SScott Mayhew /* Information for a cloned mount. */ 14462a55d08SScott Mayhew struct nfs_clone_mount { 14562a55d08SScott Mayhew struct super_block *sb; 14662a55d08SScott Mayhew struct dentry *dentry; 14762a55d08SScott Mayhew struct nfs_fattr *fattr; 14862a55d08SScott Mayhew unsigned int inherited_bsize; 14962a55d08SScott Mayhew } clone_data; 1506b18eaa0S\"Talpey, Thomas\ }; 1516b18eaa0S\"Talpey, Thomas\ 152c98e9daaSScott Mayhew #define nfs_errorf(fc, fmt, ...) ((fc)->log.log ? \ 153c98e9daaSScott Mayhew errorf(fc, fmt, ## __VA_ARGS__) : \ 154c98e9daaSScott Mayhew ({ dprintk(fmt "\n", ## __VA_ARGS__); })) 155c98e9daaSScott Mayhew 156c98e9daaSScott Mayhew #define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ? \ 157c98e9daaSScott Mayhew errorf(fc, fmt, ## __VA_ARGS__) : \ 158c98e9daaSScott Mayhew ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); })) 159c98e9daaSScott Mayhew 160c98e9daaSScott Mayhew #define nfs_invalf(fc, fmt, ...) ((fc)->log.log ? \ 161c98e9daaSScott Mayhew invalf(fc, fmt, ## __VA_ARGS__) : \ 162c98e9daaSScott Mayhew ({ dprintk(fmt "\n", ## __VA_ARGS__); -EINVAL; })) 163c98e9daaSScott Mayhew 164c98e9daaSScott Mayhew #define nfs_finvalf(fc, fac, fmt, ...) ((fc)->log.log ? \ 165c98e9daaSScott Mayhew invalf(fc, fmt, ## __VA_ARGS__) : \ 166c98e9daaSScott Mayhew ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); -EINVAL; })) 167c98e9daaSScott Mayhew 168c98e9daaSScott Mayhew #define nfs_warnf(fc, fmt, ...) ((fc)->log.log ? \ 169c98e9daaSScott Mayhew warnf(fc, fmt, ## __VA_ARGS__) : \ 170c98e9daaSScott Mayhew ({ dprintk(fmt "\n", ## __VA_ARGS__); })) 171c98e9daaSScott Mayhew 172c98e9daaSScott Mayhew #define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ? \ 173c98e9daaSScott Mayhew warnf(fc, fmt, ## __VA_ARGS__) : \ 174c98e9daaSScott Mayhew ({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); })) 175ce8866f0SScott Mayhew 176f2aedb71SDavid Howells static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc) 177f2aedb71SDavid Howells { 178f2aedb71SDavid Howells return fc->fs_private; 179f2aedb71SDavid Howells } 180f2aedb71SDavid Howells 181146ec944SChuck Lever /* mount_clnt.c */ 182c5d120f8SChuck Lever struct nfs_mount_request { 183c5d120f8SChuck Lever struct sockaddr *sap; 184c5d120f8SChuck Lever size_t salen; 185c5d120f8SChuck Lever char *hostname; 186c5d120f8SChuck Lever char *dirpath; 187c5d120f8SChuck Lever u32 version; 188c5d120f8SChuck Lever unsigned short protocol; 189c5d120f8SChuck Lever struct nfs_fh *fh; 19050a737f8SChuck Lever int noresvport; 1918e02f6b9SChuck Lever unsigned int *auth_flav_len; 1928e02f6b9SChuck Lever rpc_authflavor_t *auth_flavs; 1936d59b8d5SStanislav Kinsbursky struct net *net; 194c5d120f8SChuck Lever }; 195c5d120f8SChuck Lever 196c9301cb3SEryu Guan extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans); 1970b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info); 198146ec944SChuck Lever 19924c8dbbbSDavid Howells /* client.c */ 200a613fa16STrond Myklebust extern const struct rpc_program nfs_program; 2016b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net); 20210b7a70cSTrond Myklebust extern void nfs_clients_exit(struct net *net); 2036663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *); 2045c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t); 2057d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *); 206e5731131SAnna Schumaker int nfs_probe_server(struct nfs_server *, struct nfs_fh *); 207fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *); 20832e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *); 209a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans); 210fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t, 211fcf10398SBryan Schumaker rpc_authflavor_t); 212fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void); 213fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); 21454ceac45SDavid Howells 21524c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 216cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *); 21728cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int); 218c36fca52SAndy Adamson extern struct nfs_client * 219c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *, 220459de2edSBryan Schumaker struct nfs4_sessionid *, u32); 22162a55d08SScott Mayhew extern struct nfs_server *nfs_create_server(struct fs_context *); 22201dde76eSAnna Schumaker extern void nfs4_server_set_init_caps(struct nfs_server *); 22362a55d08SScott Mayhew extern struct nfs_server *nfs4_create_server(struct fs_context *); 22462a55d08SScott Mayhew extern struct nfs_server *nfs4_create_referral_server(struct fs_context *); 22532e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname, 226292f503cSTrond Myklebust struct sockaddr *sap, size_t salen, 227292f503cSTrond Myklebust struct net *net); 22854ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 22954ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 23054ceac45SDavid Howells struct nfs_fh *, 2317e6eb683SBryan Schumaker struct nfs_fattr *, 2327e6eb683SBryan Schumaker rpc_authflavor_t); 233a33e4b03SWeston Andros Adamson extern bool nfs_client_init_is_complete(const struct nfs_client *clp); 234a33e4b03SWeston Andros Adamson extern int nfs_client_init_status(const struct nfs_client *clp); 2354697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp); 23676db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state); 2373fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv, 238d83217c1SAndy Adamson const struct sockaddr *ds_addr, 23998fc685aSAndy Adamson int ds_addrlen, int ds_proto, 24098fc685aSAndy Adamson unsigned int ds_timeo, 241064172f3SPeng Tao unsigned int ds_retrans, 2427d38de3fSAnna Schumaker u32 minor_version); 2430e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *, 2440e20162eSAndy Adamson struct inode *); 245b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv, 2461a04c6e1SPeng Tao const struct sockaddr *ds_addr, int ds_addrlen, 2471a04c6e1SPeng Tao int ds_proto, unsigned int ds_timeo, 2487d38de3fSAnna Schumaker unsigned int ds_retrans); 2496aaca566SDavid Howells #ifdef CONFIG_PROC_FS 2506aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 2516aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 25265b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net); 25365b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net); 2546aaca566SDavid Howells #else 25565b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net) 25665b38851SEric W. Biederman { 25765b38851SEric W. Biederman return 0; 25865b38851SEric W. Biederman } 25965b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net) 26065b38851SEric W. Biederman { 26165b38851SEric W. Biederman } 2626aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 2636aaca566SDavid Howells { 2646aaca566SDavid Howells return 0; 2656aaca566SDavid Howells } 2666aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 2676aaca566SDavid Howells { 2686aaca566SDavid Howells } 2696aaca566SDavid Howells #endif 27024c8dbbbSDavid Howells 271f7b422b1SDavid Howells /* callback_xdr.c */ 272e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1; 273e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4; 274f7b422b1SDavid Howells 275f2aedb71SDavid Howells /* fs_context.c */ 276f2aedb71SDavid Howells extern struct file_system_type nfs_fs_type; 2779954bf92SDavid Howells 278f7b422b1SDavid Howells /* pagelist.c */ 279f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 280266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 281f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 282266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 283f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 284266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 285f7b422b1SDavid Howells 286f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 287266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 2884db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, 2894db6e0b7SFred Isaman struct nfs_pgio_header *hdr, 2904db6e0b7SFred Isaman void (*release)(struct nfs_pgio_header *hdr)); 2914db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos); 292210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx); 293577b4232STrond Myklebust 29441d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops; 2951e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *); 2961e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *); 297ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); 29846a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, 299a52458b4SNeilBrown const struct cred *cred, const struct nfs_rpc_ops *rpc_ops, 30046a5ab47SPeng Tao const struct rpc_call_ops *call_ops, int how, int flags); 301d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req); 30248d635f1SPeng Tao struct nfs_pgio_mirror * 30348d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc); 30400bfa30aSAnna Schumaker 305138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1, 306138a2935STrond Myklebust const struct nfs_open_context *ctx2) 307138a2935STrond Myklebust { 308a52458b4SNeilBrown return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state; 309138a2935STrond Myklebust } 310138a2935STrond Myklebust 311f7b422b1SDavid Howells /* nfs2xdr.c */ 312499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs_procedures[]; 313573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *, 314a7a3b1e9SBenjamin Coddington struct nfs_entry *, bool); 315f7b422b1SDavid Howells 316f7b422b1SDavid Howells /* nfs3xdr.c */ 317499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs3_procedures[]; 318573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *, 319a7a3b1e9SBenjamin Coddington struct nfs_entry *, bool); 320f7b422b1SDavid Howells 321f7b422b1SDavid Howells /* nfs4xdr.c */ 32289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 323573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *, 324a7a3b1e9SBenjamin Coddington struct nfs_entry *, bool); 3257d4e2747SDavid Howells #endif 3262449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1 3272449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead; 3282449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead; 329f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead; 3302449ea2eSAlexandros Batsakis #endif 331f7b422b1SDavid Howells 332f7b422b1SDavid Howells /* nfs4proc.c */ 33389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 334499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[]; 335d75d5414SAndrew Morton #endif 336f7b422b1SDavid Howells 337694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL 338694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags); 339a49c2691SKinglong Mee static inline struct nfs4_label * 340a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) 341a49c2691SKinglong Mee { 342a49c2691SKinglong Mee if (!dst || !src) 343a49c2691SKinglong Mee return NULL; 344a49c2691SKinglong Mee 345a49c2691SKinglong Mee if (src->len > NFS4_MAXLABELLEN) 346a49c2691SKinglong Mee return NULL; 347a49c2691SKinglong Mee 348a49c2691SKinglong Mee dst->lfs = src->lfs; 349a49c2691SKinglong Mee dst->pi = src->pi; 350a49c2691SKinglong Mee dst->len = src->len; 351a49c2691SKinglong Mee memcpy(dst->label, src->label, src->len); 352a49c2691SKinglong Mee 353a49c2691SKinglong Mee return dst; 354a49c2691SKinglong Mee } 355fd1defc2STrond Myklebust 356fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) 357fd1defc2STrond Myklebust { 358fd1defc2STrond Myklebust if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL)) 359fd1defc2STrond Myklebust nfsi->cache_validity |= NFS_INO_INVALID_LABEL; 360fd1defc2STrond Myklebust } 361694e096fSAnna Schumaker #else 362694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; } 363fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) 364fd1defc2STrond Myklebust { 365fd1defc2STrond Myklebust } 366a49c2691SKinglong Mee static inline struct nfs4_label * 367a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src) 368a49c2691SKinglong Mee { 369a49c2691SKinglong Mee return NULL; 370a49c2691SKinglong Mee } 371694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ 372694e096fSAnna Schumaker 3737fe5c398STrond Myklebust /* proc.c */ 3747fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 3758cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp, 3765c6e5b60STrond Myklebust const struct nfs_client_initdata *); 3777fe5c398STrond Myklebust 378979df72eSTrond Myklebust /* dir.c */ 379230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_hit(struct inode *dir); 380230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_miss(struct inode *dir); 3811ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink, 3821ab6c499SDave Chinner struct shrink_control *sc); 3831ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink, 3841495f230SYing Han struct shrink_control *sc); 385597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int); 38600bdadc7STrond Myklebust void nfs_d_prune_case_insensitive_aliases(struct inode *inode); 387549c7297SChristian Brauner int nfs_create(struct user_namespace *, struct inode *, struct dentry *, 388549c7297SChristian Brauner umode_t, bool); 389549c7297SChristian Brauner int nfs_mkdir(struct user_namespace *, struct inode *, struct dentry *, 390549c7297SChristian Brauner umode_t); 391597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *); 392597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *); 393549c7297SChristian Brauner int nfs_symlink(struct user_namespace *, struct inode *, struct dentry *, 394549c7297SChristian Brauner const char *); 395597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *); 396549c7297SChristian Brauner int nfs_mknod(struct user_namespace *, struct inode *, struct dentry *, umode_t, 397549c7297SChristian Brauner dev_t); 398549c7297SChristian Brauner int nfs_rename(struct user_namespace *, struct inode *, struct dentry *, 3991cd66c93SMiklos Szeredi struct inode *, struct dentry *, unsigned int); 400979df72eSTrond Myklebust 40184631f84STrond Myklebust #ifdef CONFIG_NFS_V4_2 40284631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server) 40384631f84STrond Myklebust { 40484631f84STrond Myklebust if (!(server->caps & NFS_CAP_XATTR)) 40584631f84STrond Myklebust return 0; 40684631f84STrond Myklebust return NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | NFS4_ACCESS_XALIST; 40784631f84STrond Myklebust } 40884631f84STrond Myklebust #else 40984631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server) 41084631f84STrond Myklebust { 41184631f84STrond Myklebust return 0; 41284631f84STrond Myklebust } 41384631f84STrond Myklebust #endif 41484631f84STrond Myklebust 415ce4ef7c0SBryan Schumaker /* file.c */ 4164ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync); 417ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int); 4183aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *); 419ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *); 420edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *); 421ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *); 422ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *); 423ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *); 424ce4ef7c0SBryan Schumaker int nfs_check_flags(int); 425ce4ef7c0SBryan Schumaker 426f7b422b1SDavid Howells /* inode.c */ 4275746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 428f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 429ca1a199eSAl Viro extern void nfs_free_inode(struct inode *); 430a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *); 431eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *); 43219d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *); 433b57922d9SAl Viro extern void nfs_evict_inode(struct inode *); 434fd6d3feeSTrond Myklebust extern void nfs_zap_acl_cache(struct inode *inode); 435fd6d3feeSTrond Myklebust extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags); 43661540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long); 437dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode); 4385e4def20SDavid Howells extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode); 439f7b422b1SDavid Howells 440f7b422b1SDavid Howells /* super.c */ 4416a74490dSBryan Schumaker extern const struct super_operations nfs_sops; 4424d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t); 443f2aedb71SDavid Howells int nfs_try_get_tree(struct fs_context *); 444f2aedb71SDavid Howells int nfs_get_tree_common(struct fs_context *); 445fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *); 4464ebd9ab3SDominik Hackl 447f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 4484ebd9ab3SDominik Hackl 449f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 450f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 451ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb); 4521daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 4533c9e502bSTrond Myklebust extern int nfs_client_for_each_server(struct nfs_client *clp, 4543c9e502bSTrond Myklebust int (*fn)(struct nfs_server *, void *), 4553c9e502bSTrond Myklebust void *data); 456a5864c99STrond Myklebust /* io.c */ 457a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode); 458a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode); 459a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode); 460a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode); 461a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode); 462a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode); 463a5864c99STrond Myklebust 464651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi) 465651b0e70STrond Myklebust { 466651b0e70STrond Myklebust return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0; 467651b0e70STrond Myklebust } 468651b0e70STrond Myklebust 469f7b422b1SDavid Howells /* namespace.c */ 47097a54868SBen Hutchings #define NFS_PATH_CANONICAL 1 471b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry, 47297a54868SBen Hutchings char *buffer, ssize_t buflen, unsigned flags); 47336d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path); 474f2aedb71SDavid Howells int nfs_submount(struct fs_context *, struct nfs_server *); 475f2aedb71SDavid Howells int nfs_do_submount(struct fs_context *); 476f7b422b1SDavid Howells 47754ceac45SDavid Howells /* getroot.c */ 47862a55d08SScott Mayhew extern int nfs_get_root(struct super_block *s, struct fs_context *fc); 47989d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 4805e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool); 4817d4e2747SDavid Howells #endif 482f7b422b1SDavid Howells 483061ae2edSFred Isaman struct nfs_pgio_completion_ops; 484f11c88afSAndy Adamson /* read.c */ 485584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 486fab5fc25SChristoph Hellwig struct inode *inode, bool force_mds, 487584aa810SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 488f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 489493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 490e885de1aSTrond Myklebust 491fbdefd64SBryan Schumaker /* super.c */ 492fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *); 493fbdefd64SBryan Schumaker int nfs_statfs(struct dentry *, struct kstatfs *); 494fbdefd64SBryan Schumaker int nfs_show_options(struct seq_file *, struct dentry *); 495fbdefd64SBryan Schumaker int nfs_show_devname(struct seq_file *, struct dentry *); 496fbdefd64SBryan Schumaker int nfs_show_path(struct seq_file *, struct dentry *); 497fbdefd64SBryan Schumaker int nfs_show_stats(struct seq_file *, struct dentry *); 498f2aedb71SDavid Howells int nfs_reconfigure(struct fs_context *); 499fbdefd64SBryan Schumaker 500def6ed7eSAndy Adamson /* write.c */ 5011763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 502a20c93e3SChristoph Hellwig struct inode *inode, int ioflags, bool force_mds, 5031763da12SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 504dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); 5050b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p); 506def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata); 5070b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); 5080b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt, 5090b7c0153SFred Isaman struct nfs_commit_data *data, 510c36aae9aSPeng Tao const struct nfs_rpc_ops *nfs_ops, 511e0c2b380SFred Isaman const struct rpc_call_ops *call_ops, 5129f0ec176SAndy Adamson int how, int flags); 5130b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data, 514e0c2b380SFred Isaman struct list_head *head, 515f453a54aSFred Isaman struct pnfs_layout_segment *lseg, 516f453a54aSFred Isaman struct nfs_commit_info *cinfo); 5171763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, 5181763da12SFred Isaman struct nfs_commit_info *cinfo, int max); 519ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *); 5201763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst, 5211763da12SFred Isaman struct nfs_commit_info *cinfo); 5221763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req, 5231763da12SFred Isaman struct pnfs_layout_segment *lseg, 524b57ff130SWeston Andros Adamson struct nfs_commit_info *cinfo, 525b57ff130SWeston Andros Adamson u32 ds_commit_idx); 526c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *); 527a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr); 5281763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head, 5291763da12SFred Isaman int how, struct nfs_commit_info *cinfo); 530e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list, 531ea2cf228SFred Isaman struct pnfs_layout_segment *lseg, 532b57ff130SWeston Andros Adamson struct nfs_commit_info *cinfo, 533b57ff130SWeston Andros Adamson u32 ds_commit_idx); 5340b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data); 5356272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req, 536ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 53786d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req, 53886d80f97STrond Myklebust struct list_head *dst, 53986d80f97STrond Myklebust struct nfs_commit_info *cinfo); 540ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req, 541ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 542ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo, 543ea2cf228SFred Isaman struct inode *inode, 544ea2cf228SFred Isaman struct nfs_direct_req *dreq); 545dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode); 546ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode); 547a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio); 548e0c2b380SFred Isaman 549837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping, 550837bb1d7STrond Myklebust loff_t lstart, loff_t lend); 551837bb1d7STrond Myklebust 552a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1 553e3b9f7e6STrond Myklebust static inline void 554e3b9f7e6STrond Myklebust pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets, 555e3b9f7e6STrond Myklebust unsigned int nbuckets) 556e3b9f7e6STrond Myklebust { 557e3b9f7e6STrond Myklebust unsigned int i; 558e3b9f7e6STrond Myklebust 559e3b9f7e6STrond Myklebust for (i = 0; i < nbuckets; i++) 560e3b9f7e6STrond Myklebust buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW; 561e3b9f7e6STrond Myklebust } 562a5314a74STrond Myklebust static inline 563a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo) 564a5314a74STrond Myklebust { 565e3b9f7e6STrond Myklebust struct pnfs_commit_array *array; 566a5314a74STrond Myklebust 567a9901899STrond Myklebust rcu_read_lock(); 568a9901899STrond Myklebust list_for_each_entry_rcu(array, &cinfo->commits, cinfo_list) 569e3b9f7e6STrond Myklebust pnfs_bucket_clear_pnfs_ds_commit_verifiers(array->buckets, 570e3b9f7e6STrond Myklebust array->nbuckets); 571a9901899STrond Myklebust rcu_read_unlock(); 572a5314a74STrond Myklebust } 573a5314a74STrond Myklebust #else 574a5314a74STrond Myklebust static inline 575a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo) 576a5314a74STrond Myklebust { 577a5314a74STrond Myklebust } 578a5314a74STrond Myklebust #endif 579a5314a74STrond Myklebust 580074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION 581*4ae84a80SMatthew Wilcox (Oracle) int nfs_migrate_folio(struct address_space *, struct folio *dst, 582*4ae84a80SMatthew Wilcox (Oracle) struct folio *src, enum migrate_mode); 583*4ae84a80SMatthew Wilcox (Oracle) #else 584*4ae84a80SMatthew Wilcox (Oracle) #define nfs_migrate_folio NULL 585074cc1deSTrond Myklebust #endif 586def6ed7eSAndy Adamson 5878fc3c386STrond Myklebust static inline int 5888fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1, 5898fc3c386STrond Myklebust const struct nfs_write_verifier *v2) 5908fc3c386STrond Myklebust { 5918fc3c386STrond Myklebust return memcmp(v1->data, v2->data, sizeof(v1->data)); 5928fc3c386STrond Myklebust } 5938fc3c386STrond Myklebust 5941f28476dSTrond Myklebust static inline bool 5951f28476dSTrond Myklebust nfs_write_match_verf(const struct nfs_writeverf *verf, 5961f28476dSTrond Myklebust struct nfs_page *req) 5971f28476dSTrond Myklebust { 5981f28476dSTrond Myklebust return verf->committed > NFS_UNSTABLE && 5991f28476dSTrond Myklebust !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier); 6001f28476dSTrond Myklebust } 6011f28476dSTrond Myklebust 602515dcdcdSTrond Myklebust static inline gfp_t nfs_io_gfp_mask(void) 603515dcdcdSTrond Myklebust { 604515dcdcdSTrond Myklebust if (current->flags & PF_WQ_WORKER) 605515dcdcdSTrond Myklebust return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; 606515dcdcdSTrond Myklebust return GFP_KERNEL; 607515dcdcdSTrond Myklebust } 608515dcdcdSTrond Myklebust 6090e862a40SJeff Layton /* unlink.c */ 6100e862a40SJeff Layton extern struct rpc_task * 6110e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir, 6120e862a40SJeff Layton struct dentry *old_dentry, struct dentry *new_dentry, 6130e862a40SJeff Layton void (*complete)(struct rpc_task *, struct nfs_renamedata *)); 6140e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry); 6150e862a40SJeff Layton 6161763da12SFred Isaman /* direct.c */ 6171763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, 6181763da12SFred Isaman struct nfs_direct_req *dreq); 6196296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); 6201763da12SFred Isaman 621cccef3b9SAndy Adamson /* nfs4proc.c */ 6228cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, 6235c6e5b60STrond Myklebust const struct nfs_client_initdata *); 62405f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp, 62505f4c350SChuck Lever struct nfs_client **result, 626a52458b4SNeilBrown const struct cred *cred); 62705f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp, 62805f4c350SChuck Lever struct nfs_client **result, 629a52458b4SNeilBrown const struct cred *cred); 63010e037d1SSantosh kumar pradhan extern void nfs4_test_session_trunk(struct rpc_clnt *clnt, 63110e037d1SSantosh kumar pradhan struct rpc_xprt *xprt, 63210e037d1SSantosh kumar pradhan void *data); 633cccef3b9SAndy Adamson 634ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode) 635ea7c38feSTrond Myklebust { 636896567eeSTrond Myklebust struct super_block *sb = inode->i_sb; 637896567eeSTrond Myklebust 638896567eeSTrond Myklebust if (sb && nfs_sb_active(sb)) { 639896567eeSTrond Myklebust if (igrab(inode)) 640ea7c38feSTrond Myklebust return inode; 641896567eeSTrond Myklebust nfs_sb_deactive(sb); 642896567eeSTrond Myklebust } 643896567eeSTrond Myklebust return NULL; 644ea7c38feSTrond Myklebust } 645ea7c38feSTrond Myklebust 646ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode) 647ea7c38feSTrond Myklebust { 648ea7c38feSTrond Myklebust if (inode != NULL) { 649ea7c38feSTrond Myklebust struct super_block *sb = inode->i_sb; 650ea7c38feSTrond Myklebust 651ea7c38feSTrond Myklebust iput(inode); 652ea7c38feSTrond Myklebust nfs_sb_deactive(sb); 653ea7c38feSTrond Myklebust } 654ea7c38feSTrond Myklebust } 655ea7c38feSTrond Myklebust 656557134a3SAndy Adamson /* 657f7b422b1SDavid Howells * Determine the device name as a string 658f7b422b1SDavid Howells */ 659b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry, 660f7b422b1SDavid Howells char *buffer, ssize_t buflen) 661f7b422b1SDavid Howells { 662b514f872SAl Viro char *dummy; 66397a54868SBen Hutchings return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL); 664f7b422b1SDavid Howells } 665f7b422b1SDavid Howells 666f7b422b1SDavid Howells /* 667f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 668f7b422b1SDavid Howells */ 669f7b422b1SDavid Howells static inline 670f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 671f7b422b1SDavid Howells { 672f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 673f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 674f7b422b1SDavid Howells unsigned char nrbits; 675f7b422b1SDavid Howells 676f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 677f7b422b1SDavid Howells ; 678f7b422b1SDavid Howells bsize = 1 << nrbits; 679f7b422b1SDavid Howells if (nrbitsp) 680f7b422b1SDavid Howells *nrbitsp = nrbits; 681f7b422b1SDavid Howells } 682f7b422b1SDavid Howells 683f7b422b1SDavid Howells return bsize; 684f7b422b1SDavid Howells } 685f7b422b1SDavid Howells 686f7b422b1SDavid Howells /* 687f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 688f7b422b1SDavid Howells */ 6899eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 690f7b422b1SDavid Howells { 6919eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 692f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 693f7b422b1SDavid Howells } 694f7b422b1SDavid Howells 695f7b422b1SDavid Howells /* 696f7b422b1SDavid Howells * Compute and set NFS server blocksize 697f7b422b1SDavid Howells */ 698f7b422b1SDavid Howells static inline 699f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 700f7b422b1SDavid Howells { 701f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 702f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 703f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 704f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 705f7b422b1SDavid Howells 706f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 707f7b422b1SDavid Howells } 708f7b422b1SDavid Howells 709f7b422b1SDavid Howells /* 710f7b422b1SDavid Howells * Determine the maximum file size for a superblock 711f7b422b1SDavid Howells */ 712f7b422b1SDavid Howells static inline 713f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 714f7b422b1SDavid Howells { 715f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 716f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 717f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 718f7b422b1SDavid Howells } 71949a70f27STrond Myklebust 72049a70f27STrond Myklebust /* 7218d92890bSNeilBrown * Record the page as unstable (an extra writeback period) and mark its 7228d92890bSNeilBrown * inode as dirty. 723d15bc38dSTom Haynes */ 724d15bc38dSTom Haynes static inline 72586d80f97STrond Myklebust void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo) 726d15bc38dSTom Haynes { 72786d80f97STrond Myklebust if (!cinfo->dreq) { 728d15bc38dSTom Haynes struct inode *inode = page_file_mapping(page)->host; 729d15bc38dSTom Haynes 7308d92890bSNeilBrown /* This page is really still in write-back - just that the 7318d92890bSNeilBrown * writeback is happening on the server now. 7328d92890bSNeilBrown */ 7338d92890bSNeilBrown inc_node_page_state(page, NR_WRITEBACK); 7348d92890bSNeilBrown inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK); 735d15bc38dSTom Haynes __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 736d15bc38dSTom Haynes } 73786d80f97STrond Myklebust } 738d15bc38dSTom Haynes 739d15bc38dSTom Haynes /* 74049a70f27STrond Myklebust * Determine the number of bytes of data the page contains 74149a70f27STrond Myklebust */ 74249a70f27STrond Myklebust static inline 74349a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 74449a70f27STrond Myklebust { 745d56b4ddfSMel Gorman loff_t i_size = i_size_read(page_file_mapping(page)->host); 74649a70f27STrond Myklebust 74749a70f27STrond Myklebust if (i_size > 0) { 7488cd79788SHuang Ying pgoff_t index = page_index(page); 74909cbfeafSKirill A. Shutemov pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT; 7508cd79788SHuang Ying if (index < end_index) 75109cbfeafSKirill A. Shutemov return PAGE_SIZE; 7528cd79788SHuang Ying if (index == end_index) 75309cbfeafSKirill A. Shutemov return ((i_size - 1) & ~PAGE_MASK) + 1; 75449a70f27STrond Myklebust } 75549a70f27STrond Myklebust return 0; 75649a70f27STrond Myklebust } 7578d5658c9STrond Myklebust 7588d5658c9STrond Myklebust /* 7590b26a0bfSTrond Myklebust * Convert a umode to a dirent->d_type 7600b26a0bfSTrond Myklebust */ 7610b26a0bfSTrond Myklebust static inline 7620b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode) 7630b26a0bfSTrond Myklebust { 7640b26a0bfSTrond Myklebust return (mode >> 12) & 15; 7650b26a0bfSTrond Myklebust } 7660b26a0bfSTrond Myklebust 7670b26a0bfSTrond Myklebust /* 7688d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 7698d5658c9STrond Myklebust * with a base offset of 'base' 7708d5658c9STrond Myklebust */ 7718d5658c9STrond Myklebust static inline 7728d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 7738d5658c9STrond Myklebust { 7748d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 7758d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 7768d5658c9STrond Myklebust } 7770110ee15STrond Myklebust 7783a1556e8STrond Myklebust /* 779ae08483cSArnd Bergmann * Convert a struct timespec64 into a 64-bit change attribute 7803a1556e8STrond Myklebust * 781ae08483cSArnd Bergmann * This does approximately the same thing as timespec64_to_ns(), 7823a1556e8STrond Myklebust * but for calculation efficiency, we multiply the seconds by 7833a1556e8STrond Myklebust * 1024*1024*1024. 7843a1556e8STrond Myklebust */ 7853a1556e8STrond Myklebust static inline 786e86d5a02STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec64 *ts) 7873a1556e8STrond Myklebust { 7883a1556e8STrond Myklebust return ((u64)ts->tv_sec << 30) + ts->tv_nsec; 7893a1556e8STrond Myklebust } 7901264a2f0STrond Myklebust 7911264a2f0STrond Myklebust #ifdef CONFIG_CRC32 7921264a2f0STrond Myklebust /** 7931264a2f0STrond Myklebust * nfs_fhandle_hash - calculate the crc32 hash for the filehandle 7941264a2f0STrond Myklebust * @fh - pointer to filehandle 7951264a2f0STrond Myklebust * 7961264a2f0STrond Myklebust * returns a crc32 hash for the filehandle that is compatible with 7971264a2f0STrond Myklebust * the one displayed by "wireshark". 7981264a2f0STrond Myklebust */ 7991264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) 8001264a2f0STrond Myklebust { 8011264a2f0STrond Myklebust return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); 8021264a2f0STrond Myklebust } 80348c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid) 80448c9579aSOlga Kornievskaia { 80548c9579aSOlga Kornievskaia return ~crc32_le(0xFFFFFFFF, &stateid->other[0], 80648c9579aSOlga Kornievskaia NFS4_STATEID_OTHER_SIZE); 80748c9579aSOlga Kornievskaia } 8081264a2f0STrond Myklebust #else 8091264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) 8101264a2f0STrond Myklebust { 8111264a2f0STrond Myklebust return 0; 8121264a2f0STrond Myklebust } 81348c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid) 81448c9579aSOlga Kornievskaia { 81548c9579aSOlga Kornievskaia return 0; 81648c9579aSOlga Kornievskaia } 8171264a2f0STrond Myklebust #endif 8180bcbf039SPeng Tao 8190bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err) 8200bcbf039SPeng Tao { 8210bcbf039SPeng Tao switch (err) { 8220bcbf039SPeng Tao case -ERESTARTSYS: 8237dc58ca5STrond Myklebust case -EINTR: 82454551d85STrond Myklebust case -EACCES: 82554551d85STrond Myklebust case -EDQUOT: 82654551d85STrond Myklebust case -EFBIG: 8270bcbf039SPeng Tao case -EIO: 8280bcbf039SPeng Tao case -ENOSPC: 8290bcbf039SPeng Tao case -EROFS: 83054551d85STrond Myklebust case -ESTALE: 8310bcbf039SPeng Tao case -E2BIG: 8322dc23affSTrond Myklebust case -ENOMEM: 83311982a7cSTrond Myklebust case -ETIMEDOUT: 8340bcbf039SPeng Tao return true; 8350bcbf039SPeng Tao default: 8360bcbf039SPeng Tao return false; 8370bcbf039SPeng Tao } 8380bcbf039SPeng Tao } 839bf4b4905SNeilBrown 8408f54c7a4STrond Myklebust static inline bool nfs_error_is_fatal_on_server(int err) 8418f54c7a4STrond Myklebust { 8428f54c7a4STrond Myklebust switch (err) { 8438f54c7a4STrond Myklebust case 0: 8448f54c7a4STrond Myklebust case -ERESTARTSYS: 8458f54c7a4STrond Myklebust case -EINTR: 84645228440STrond Myklebust case -ENOMEM: 8478f54c7a4STrond Myklebust return false; 8488f54c7a4STrond Myklebust } 8498f54c7a4STrond Myklebust return nfs_error_is_fatal(err); 8508f54c7a4STrond Myklebust } 8519954bf92SDavid Howells 8529954bf92SDavid Howells /* 8539954bf92SDavid Howells * Select between a default port value and a user-specified port value. 8549954bf92SDavid Howells * If a zero value is set, then autobind will be used. 8559954bf92SDavid Howells */ 8569954bf92SDavid Howells static inline void nfs_set_port(struct sockaddr *sap, int *port, 8579954bf92SDavid Howells const unsigned short default_port) 8589954bf92SDavid Howells { 8599954bf92SDavid Howells if (*port == NFS_UNSPEC_PORT) 8609954bf92SDavid Howells *port = default_port; 8619954bf92SDavid Howells 8629954bf92SDavid Howells rpc_set_port(sap, *port); 8639954bf92SDavid Howells } 864