1f7b422b1SDavid Howells /* 2f7b422b1SDavid Howells * NFS internal definitions 3f7b422b1SDavid Howells */ 4f7b422b1SDavid Howells 5eedc020eSAndy Adamson #include "nfs4_fs.h" 6f7b422b1SDavid Howells #include <linux/mount.h> 7f9c3a380SEric Paris #include <linux/security.h> 81264a2f0STrond Myklebust #include <linux/crc32.h> 947af81f2SPeng Tao #include <linux/nfs_page.h> 10f7b422b1SDavid Howells 1108734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) 1208734048SDavid Howells 1354ceac45SDavid Howells struct nfs_string; 1454ceac45SDavid Howells 1554ceac45SDavid Howells /* Maximum number of readahead requests 1654ceac45SDavid Howells * FIXME: this should really be a sysctl so that users may tune it to suit 1754ceac45SDavid Howells * their needs. People that do NFS over a slow network, might for 1854ceac45SDavid Howells * instance want to reduce it to something closer to 1 for improved 1954ceac45SDavid Howells * interactive response. 2054ceac45SDavid Howells */ 2154ceac45SDavid Howells #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 2254ceac45SDavid Howells 237ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr) 247ebb9315SBryan Schumaker { 257ebb9315SBryan Schumaker if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid)) 267ebb9315SBryan Schumaker fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT; 277ebb9315SBryan Schumaker } 287ebb9315SBryan Schumaker 29533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr) 30533eb461SAndy Adamson { 31533eb461SAndy Adamson if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) || 32533eb461SAndy Adamson (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && 33533eb461SAndy Adamson ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) 34533eb461SAndy Adamson return 0; 35533eb461SAndy Adamson 36533eb461SAndy Adamson fattr->fileid = fattr->mounted_on_fileid; 37533eb461SAndy Adamson return 1; 38533eb461SAndy Adamson } 39533eb461SAndy Adamson 40f7b422b1SDavid Howells struct nfs_clone_mount { 41f7b422b1SDavid Howells const struct super_block *sb; 42f7b422b1SDavid Howells const struct dentry *dentry; 43f7b422b1SDavid Howells struct nfs_fh *fh; 44f7b422b1SDavid Howells struct nfs_fattr *fattr; 45f7b422b1SDavid Howells char *hostname; 46f7b422b1SDavid Howells char *mnt_path; 476677d095SChuck Lever struct sockaddr *addr; 486677d095SChuck Lever size_t addrlen; 49f7b422b1SDavid Howells rpc_authflavor_t authflavor; 50f7b422b1SDavid Howells }; 51f7b422b1SDavid Howells 526b18eaa0S\"Talpey, Thomas\ /* 53a14017dbSChuck Lever * Note: RFC 1813 doesn't limit the number of auth flavors that 54a14017dbSChuck Lever * a server can return, so make something up. 55a14017dbSChuck Lever */ 56a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS (12) 57a14017dbSChuck Lever 58a14017dbSChuck Lever /* 594cfd74fcSChuck Lever * Value used if the user did not specify a port value. 604cfd74fcSChuck Lever */ 614cfd74fcSChuck Lever #define NFS_UNSPEC_PORT (-1) 624cfd74fcSChuck Lever 634cfd74fcSChuck Lever /* 6456e4ebf8SBryan Schumaker * Maximum number of pages that readdir can use for creating 6556e4ebf8SBryan Schumaker * a vmapped array of pages. 6656e4ebf8SBryan Schumaker */ 6756e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8 6856e4ebf8SBryan Schumaker 69fcf10398SBryan Schumaker struct nfs_client_initdata { 70fcf10398SBryan Schumaker unsigned long init_flags; 71fcf10398SBryan Schumaker const char *hostname; 72fcf10398SBryan Schumaker const struct sockaddr *addr; 73fcf10398SBryan Schumaker size_t addrlen; 74ab7017a3SBryan Schumaker struct nfs_subversion *nfs_mod; 75fcf10398SBryan Schumaker int proto; 76fcf10398SBryan Schumaker u32 minorversion; 77fcf10398SBryan Schumaker struct net *net; 78fcf10398SBryan Schumaker }; 79fcf10398SBryan Schumaker 8056e4ebf8SBryan Schumaker /* 816b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 826b18eaa0S\"Talpey, Thomas\ */ 836b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data { 846b18eaa0S\"Talpey, Thomas\ int flags; 858cb7f74eSChuck Lever unsigned int rsize, wsize; 868cb7f74eSChuck Lever unsigned int timeo, retrans; 878cb7f74eSChuck Lever unsigned int acregmin, acregmax, 886b18eaa0S\"Talpey, Thomas\ acdirmin, acdirmax; 898cb7f74eSChuck Lever unsigned int namlen; 90b797cac7SDavid Howells unsigned int options; 916b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 92a3f73c27SWeston Andros Adamson struct nfs_auth_info auth_info; 93a3f73c27SWeston Andros Adamson rpc_authflavor_t selected_flavor; 946b18eaa0S\"Talpey, Thomas\ char *client_address; 95764302ccSChuck Lever unsigned int version; 963fd5be9eSMike Sager unsigned int minorversion; 9708734048SDavid Howells char *fscache_uniq; 98b72e4f42SBryan Schumaker bool need_mount; 996b18eaa0S\"Talpey, Thomas\ 1006b18eaa0S\"Talpey, Thomas\ struct { 1014c568017SChuck Lever struct sockaddr_storage address; 1024c568017SChuck Lever size_t addrlen; 1036b18eaa0S\"Talpey, Thomas\ char *hostname; 10478fa701fSChuck Lever u32 version; 1054cfd74fcSChuck Lever int port; 10678fa701fSChuck Lever unsigned short protocol; 1076b18eaa0S\"Talpey, Thomas\ } mount_server; 1086b18eaa0S\"Talpey, Thomas\ 1096b18eaa0S\"Talpey, Thomas\ struct { 1104c568017SChuck Lever struct sockaddr_storage address; 1114c568017SChuck Lever size_t addrlen; 1126b18eaa0S\"Talpey, Thomas\ char *hostname; 1136b18eaa0S\"Talpey, Thomas\ char *export_path; 1144cfd74fcSChuck Lever int port; 11578fa701fSChuck Lever unsigned short protocol; 1166b18eaa0S\"Talpey, Thomas\ } nfs_server; 117f9c3a380SEric Paris 118f9c3a380SEric Paris struct security_mnt_opts lsm_opts; 119e50a7a1aSStanislav Kinsbursky struct net *net; 1206b18eaa0S\"Talpey, Thomas\ }; 1216b18eaa0S\"Talpey, Thomas\ 122146ec944SChuck Lever /* mount_clnt.c */ 123c5d120f8SChuck Lever struct nfs_mount_request { 124c5d120f8SChuck Lever struct sockaddr *sap; 125c5d120f8SChuck Lever size_t salen; 126c5d120f8SChuck Lever char *hostname; 127c5d120f8SChuck Lever char *dirpath; 128c5d120f8SChuck Lever u32 version; 129c5d120f8SChuck Lever unsigned short protocol; 130c5d120f8SChuck Lever struct nfs_fh *fh; 13150a737f8SChuck Lever int noresvport; 1328e02f6b9SChuck Lever unsigned int *auth_flav_len; 1338e02f6b9SChuck Lever rpc_authflavor_t *auth_flavs; 1346d59b8d5SStanislav Kinsbursky struct net *net; 135c5d120f8SChuck Lever }; 136c5d120f8SChuck Lever 137fbdefd64SBryan Schumaker struct nfs_mount_info { 138fbdefd64SBryan Schumaker void (*fill_super)(struct super_block *, struct nfs_mount_info *); 139fbdefd64SBryan Schumaker int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *); 140fbdefd64SBryan Schumaker struct nfs_parsed_mount_data *parsed; 141fbdefd64SBryan Schumaker struct nfs_clone_mount *cloned; 142fbdefd64SBryan Schumaker struct nfs_fh *mntfh; 143fbdefd64SBryan Schumaker }; 144fbdefd64SBryan Schumaker 145c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info); 1460b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info); 147146ec944SChuck Lever 14824c8dbbbSDavid Howells /* client.c */ 149a613fa16STrond Myklebust extern const struct rpc_program nfs_program; 1506b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net); 1516663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *); 152428360d7SBryan Schumaker int nfs_create_rpc_client(struct nfs_client *, const struct rpc_timeout *, rpc_authflavor_t); 153fcf10398SBryan Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *, 154fcf10398SBryan Schumaker const struct rpc_timeout *, const char *, 155fcf10398SBryan Schumaker rpc_authflavor_t); 156fcf10398SBryan Schumaker int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *); 157fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *); 15832e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *); 159fcf10398SBryan Schumaker void nfs_init_timeout_values(struct rpc_timeout *, int, unsigned int, unsigned int); 160fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t, 161fcf10398SBryan Schumaker rpc_authflavor_t); 162fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void); 163fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); 16454ceac45SDavid Howells 16528cd1b3fSStanislav Kinsbursky extern void nfs_cleanup_cb_ident_idr(struct net *); 16624c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 167cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *); 16828cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int); 169c36fca52SAndy Adamson extern struct nfs_client * 170c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *, 171459de2edSBryan Schumaker struct nfs4_sessionid *, u32); 1721179acc6SBryan Schumaker extern struct nfs_server *nfs_create_server(struct nfs_mount_info *, 173ab7017a3SBryan Schumaker struct nfs_subversion *); 17491ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 1751179acc6SBryan Schumaker struct nfs_mount_info *, 1761179acc6SBryan Schumaker struct nfs_subversion *); 17754ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 17854ceac45SDavid Howells struct nfs_fh *); 17932e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname, 180292f503cSTrond Myklebust struct sockaddr *sap, size_t salen, 181292f503cSTrond Myklebust struct net *net); 18254ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 18354ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 18454ceac45SDavid Howells struct nfs_fh *, 1857e6eb683SBryan Schumaker struct nfs_fattr *, 1867e6eb683SBryan Schumaker rpc_authflavor_t); 1874697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp); 18876db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state); 189d83217c1SAndy Adamson extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, 190d83217c1SAndy Adamson const struct sockaddr *ds_addr, 19198fc685aSAndy Adamson int ds_addrlen, int ds_proto, 19298fc685aSAndy Adamson unsigned int ds_timeo, 193064172f3SPeng Tao unsigned int ds_retrans, 19430626f9cSPeng Tao u32 minor_version, 195064172f3SPeng Tao rpc_authflavor_t au_flavor); 1960e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *, 1970e20162eSAndy Adamson struct inode *); 1981a04c6e1SPeng Tao extern struct nfs_client *nfs3_set_ds_client(struct nfs_client *mds_clp, 1991a04c6e1SPeng Tao const struct sockaddr *ds_addr, int ds_addrlen, 2001a04c6e1SPeng Tao int ds_proto, unsigned int ds_timeo, 2011a04c6e1SPeng Tao unsigned int ds_retrans, rpc_authflavor_t au_flavor); 2026aaca566SDavid Howells #ifdef CONFIG_PROC_FS 2036aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 2046aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 20565b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net); 20665b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net); 2076aaca566SDavid Howells #else 20865b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net) 20965b38851SEric W. Biederman { 21065b38851SEric W. Biederman return 0; 21165b38851SEric W. Biederman } 21265b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net) 21365b38851SEric W. Biederman { 21465b38851SEric W. Biederman } 2156aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 2166aaca566SDavid Howells { 2176aaca566SDavid Howells return 0; 2186aaca566SDavid Howells } 2196aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 2206aaca566SDavid Howells { 2216aaca566SDavid Howells } 2226aaca566SDavid Howells #endif 22324c8dbbbSDavid Howells 224fcf10398SBryan Schumaker #ifdef CONFIG_NFS_V4_1 225fcf10398SBryan Schumaker int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *); 226fcf10398SBryan Schumaker #endif 227fcf10398SBryan Schumaker 228f7b422b1SDavid Howells /* callback_xdr.c */ 229f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 23007bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4; 231f7b422b1SDavid Howells 2324db6e0b7SFred Isaman struct nfs_pageio_descriptor; 233f7b422b1SDavid Howells /* pagelist.c */ 234f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 235266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 236f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 237266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 238f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 239266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 240f7b422b1SDavid Howells 241f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 242266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 2434db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, 2444db6e0b7SFred Isaman struct nfs_pgio_header *hdr, 2454db6e0b7SFred Isaman void (*release)(struct nfs_pgio_header *hdr)); 2464db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos); 247577b4232STrond Myklebust int nfs_iocounter_wait(struct nfs_io_counter *c); 248577b4232STrond Myklebust 24941d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops; 2501e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *); 2511e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *); 252d45f60c6SWeston Andros Adamson void nfs_pgio_data_destroy(struct nfs_pgio_header *); 253ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); 25446a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr, 25546a5ab47SPeng Tao struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops, 25646a5ab47SPeng Tao const struct rpc_call_ops *call_ops, int how, int flags); 257d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req); 25848d635f1SPeng Tao struct nfs_pgio_mirror * 25948d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc); 26000bfa30aSAnna Schumaker 261577b4232STrond Myklebust static inline void nfs_iocounter_init(struct nfs_io_counter *c) 262577b4232STrond Myklebust { 263577b4232STrond Myklebust c->flags = 0; 264577b4232STrond Myklebust atomic_set(&c->io_count, 0); 265577b4232STrond Myklebust } 266f7b422b1SDavid Howells 26747af81f2SPeng Tao static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc) 26847af81f2SPeng Tao { 26947af81f2SPeng Tao WARN_ON_ONCE(desc->pg_mirror_count < 1); 27047af81f2SPeng Tao return desc->pg_mirror_count > 1; 27147af81f2SPeng Tao } 27247af81f2SPeng Tao 273f7b422b1SDavid Howells /* nfs2xdr.c */ 274f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 275573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *, 276573c4e1eSChuck Lever struct nfs_entry *, int); 277f7b422b1SDavid Howells 278f7b422b1SDavid Howells /* nfs3xdr.c */ 279f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 280573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *, 281573c4e1eSChuck Lever struct nfs_entry *, int); 282f7b422b1SDavid Howells 283f7b422b1SDavid Howells /* nfs4xdr.c */ 28489d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 285573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *, 286573c4e1eSChuck Lever struct nfs_entry *, int); 2877d4e2747SDavid Howells #endif 2882449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1 2892449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead; 2902449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead; 291f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead; 2922449ea2eSAlexandros Batsakis #endif 293f7b422b1SDavid Howells 294f7b422b1SDavid Howells /* nfs4proc.c */ 29589d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 296f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 297d75d5414SAndrew Morton #endif 298f7b422b1SDavid Howells 299694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL 300694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags); 301694e096fSAnna Schumaker static inline void nfs4_label_free(struct nfs4_label *label) 302694e096fSAnna Schumaker { 303694e096fSAnna Schumaker if (label) { 304694e096fSAnna Schumaker kfree(label->label); 305694e096fSAnna Schumaker kfree(label); 306694e096fSAnna Schumaker } 307694e096fSAnna Schumaker return; 308694e096fSAnna Schumaker } 309fd1defc2STrond Myklebust 310fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) 311fd1defc2STrond Myklebust { 312fd1defc2STrond Myklebust if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL)) 313fd1defc2STrond Myklebust nfsi->cache_validity |= NFS_INO_INVALID_LABEL; 314fd1defc2STrond Myklebust } 315694e096fSAnna Schumaker #else 316694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; } 317694e096fSAnna Schumaker static inline void nfs4_label_free(void *label) {} 318fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) 319fd1defc2STrond Myklebust { 320fd1defc2STrond Myklebust } 321694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ 322694e096fSAnna Schumaker 3237fe5c398STrond Myklebust /* proc.c */ 3247fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 3258cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp, 32645a52a02SAndy Adamson const struct rpc_timeout *timeparms, 327f8407299SAndy Adamson const char *ip_addr); 3287fe5c398STrond Myklebust 329979df72eSTrond Myklebust /* dir.c */ 330311324adSTrond Myklebust extern void nfs_force_use_readdirplus(struct inode *dir); 3311ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink, 3321ab6c499SDave Chinner struct shrink_control *sc); 3331ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink, 3341495f230SYing Han struct shrink_control *sc); 335597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int); 336597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool); 337597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t); 338597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *); 339597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *); 340597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *); 341597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *); 342597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 343597d9289SBryan Schumaker int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 344979df72eSTrond Myklebust 345ce4ef7c0SBryan Schumaker /* file.c */ 346ce4ef7c0SBryan Schumaker int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int); 347ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int); 348ce4ef7c0SBryan Schumaker int nfs_file_flush(struct file *, fl_owner_t); 3493aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *); 350ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *, 351ce4ef7c0SBryan Schumaker size_t, unsigned int); 352ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *); 353edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *); 354ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *); 355ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *); 356ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *); 357ce4ef7c0SBryan Schumaker int nfs_check_flags(int); 358ce4ef7c0SBryan Schumaker 359f7b422b1SDavid Howells /* inode.c */ 3605746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 361f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 362f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 363a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *); 364eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *); 36519d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *); 366b57922d9SAl Viro extern void nfs_evict_inode(struct inode *); 367f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode); 368c1221321SNeilBrown extern int nfs_wait_bit_killable(struct wait_bit_key *key); 369f7b422b1SDavid Howells 370f7b422b1SDavid Howells /* super.c */ 3716a74490dSBryan Schumaker extern const struct super_operations nfs_sops; 372ab7017a3SBryan Schumaker extern struct file_system_type nfs_fs_type; 37354ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 37489d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 37554ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 37654ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 377f7b422b1SDavid Howells #endif 3784d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t); 379ff9099f2SBryan Schumaker struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *, 380ff9099f2SBryan Schumaker struct nfs_subversion *); 381fbdefd64SBryan Schumaker void nfs_initialise_sb(struct super_block *); 382fbdefd64SBryan Schumaker int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *); 383fbdefd64SBryan Schumaker int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *); 384ab7017a3SBryan Schumaker struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *, 385ab7017a3SBryan Schumaker struct nfs_mount_info *, struct nfs_subversion *); 386fbdefd64SBryan Schumaker struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *); 387fbdefd64SBryan Schumaker struct dentry * nfs_xdev_mount_common(struct file_system_type *, int, 388fbdefd64SBryan Schumaker const char *, struct nfs_mount_info *); 389fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *); 390fbdefd64SBryan Schumaker void nfs_fill_super(struct super_block *, struct nfs_mount_info *); 3914ebd9ab3SDominik Hackl 392f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 3934ebd9ab3SDominik Hackl 394f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 395f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 3961daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb); 3971daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 398f7b422b1SDavid Howells 399f7b422b1SDavid Howells /* namespace.c */ 40097a54868SBen Hutchings #define NFS_PATH_CANONICAL 1 401b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry, 40297a54868SBen Hutchings char *buffer, ssize_t buflen, unsigned flags); 40336d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path); 404281cad46SBryan Schumaker struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *, 405281cad46SBryan Schumaker struct nfs_fh *, struct nfs_fattr *); 406281cad46SBryan Schumaker struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *, 407281cad46SBryan Schumaker struct nfs_fattr *, rpc_authflavor_t); 408f7b422b1SDavid Howells 40954ceac45SDavid Howells /* getroot.c */ 4100d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *, 4110d5839adSAl Viro const char *); 41289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 4130d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *, 4140d5839adSAl Viro const char *); 41554ceac45SDavid Howells 4165e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool); 4177d4e2747SDavid Howells #endif 418f7b422b1SDavid Howells 419061ae2edSFred Isaman struct nfs_pgio_completion_ops; 420f11c88afSAndy Adamson /* read.c */ 421584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 422fab5fc25SChristoph Hellwig struct inode *inode, bool force_mds, 423584aa810SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 424f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 425493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 426e885de1aSTrond Myklebust 427fbdefd64SBryan Schumaker /* super.c */ 428fbdefd64SBryan Schumaker void nfs_clone_super(struct super_block *, struct nfs_mount_info *); 429fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *); 430fbdefd64SBryan Schumaker int nfs_statfs(struct dentry *, struct kstatfs *); 431fbdefd64SBryan Schumaker int nfs_show_options(struct seq_file *, struct dentry *); 432fbdefd64SBryan Schumaker int nfs_show_devname(struct seq_file *, struct dentry *); 433fbdefd64SBryan Schumaker int nfs_show_path(struct seq_file *, struct dentry *); 434fbdefd64SBryan Schumaker int nfs_show_stats(struct seq_file *, struct dentry *); 435fbdefd64SBryan Schumaker void nfs_put_super(struct super_block *); 436fbdefd64SBryan Schumaker int nfs_remount(struct super_block *sb, int *flags, char *raw_data); 437fbdefd64SBryan Schumaker 438def6ed7eSAndy Adamson /* write.c */ 4391763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 440a20c93e3SChristoph Hellwig struct inode *inode, int ioflags, bool force_mds, 4411763da12SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 442dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); 4430b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p); 444def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata); 4450b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); 4460b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt, 4470b7c0153SFred Isaman struct nfs_commit_data *data, 448c36aae9aSPeng Tao const struct nfs_rpc_ops *nfs_ops, 449e0c2b380SFred Isaman const struct rpc_call_ops *call_ops, 4509f0ec176SAndy Adamson int how, int flags); 4510b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data, 452e0c2b380SFred Isaman struct list_head *head, 453f453a54aSFred Isaman struct pnfs_layout_segment *lseg, 454f453a54aSFred Isaman struct nfs_commit_info *cinfo); 4551763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, 4561763da12SFred Isaman struct nfs_commit_info *cinfo, int max); 457ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *); 4581763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst, 4591763da12SFred Isaman struct nfs_commit_info *cinfo); 4601763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req, 4611763da12SFred Isaman struct pnfs_layout_segment *lseg, 462b57ff130SWeston Andros Adamson struct nfs_commit_info *cinfo, 463b57ff130SWeston Andros Adamson u32 ds_commit_idx); 464c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *); 4651763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head, 4661763da12SFred Isaman int how, struct nfs_commit_info *cinfo); 467e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list, 468ea2cf228SFred Isaman struct pnfs_layout_segment *lseg, 469b57ff130SWeston Andros Adamson struct nfs_commit_info *cinfo, 470b57ff130SWeston Andros Adamson u32 ds_commit_idx); 4710b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data); 472ea2cf228SFred Isaman void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, 473ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 474ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req, 475ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 476ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo, 477ea2cf228SFred Isaman struct inode *inode, 478ea2cf228SFred Isaman struct nfs_direct_req *dreq); 479dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode); 480dc24826bSAndy Adamson bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx); 481a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio); 482e0c2b380SFred Isaman 483074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION 484074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *, 485a6bc32b8SMel Gorman struct page *, struct page *, enum migrate_mode); 486074cc1deSTrond Myklebust #else 487074cc1deSTrond Myklebust #define nfs_migrate_page NULL 488074cc1deSTrond Myklebust #endif 489def6ed7eSAndy Adamson 4900e862a40SJeff Layton /* unlink.c */ 4910e862a40SJeff Layton extern struct rpc_task * 4920e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir, 4930e862a40SJeff Layton struct dentry *old_dentry, struct dentry *new_dentry, 4940e862a40SJeff Layton void (*complete)(struct rpc_task *, struct nfs_renamedata *)); 4950e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry); 4960e862a40SJeff Layton 4971763da12SFred Isaman /* direct.c */ 4981763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, 4991763da12SFred Isaman struct nfs_direct_req *dreq); 5001d59d61fSTrond Myklebust static inline void nfs_inode_dio_wait(struct inode *inode) 5011d59d61fSTrond Myklebust { 5021d59d61fSTrond Myklebust inode_dio_wait(inode); 5031d59d61fSTrond Myklebust } 5046296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); 505012fa16dSPeng Tao extern void nfs_direct_set_resched_writes(struct nfs_direct_req *dreq); 5061763da12SFred Isaman 507cccef3b9SAndy Adamson /* nfs4proc.c */ 508d45f60c6SWeston Andros Adamson extern void __nfs4_read_done_cb(struct nfs_pgio_header *); 5098cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, 51045a52a02SAndy Adamson const struct rpc_timeout *timeparms, 511f8407299SAndy Adamson const char *ip_addr); 51205f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp, 51305f4c350SChuck Lever struct nfs_client **result, 51405f4c350SChuck Lever struct rpc_cred *cred); 51505f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp, 51605f4c350SChuck Lever struct nfs_client **result, 51705f4c350SChuck Lever struct rpc_cred *cred); 518cccef3b9SAndy Adamson 519557134a3SAndy Adamson /* 520f7b422b1SDavid Howells * Determine the device name as a string 521f7b422b1SDavid Howells */ 522b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry, 523f7b422b1SDavid Howells char *buffer, ssize_t buflen) 524f7b422b1SDavid Howells { 525b514f872SAl Viro char *dummy; 52697a54868SBen Hutchings return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL); 527f7b422b1SDavid Howells } 528f7b422b1SDavid Howells 529f7b422b1SDavid Howells /* 530f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 531f7b422b1SDavid Howells */ 532f7b422b1SDavid Howells static inline 533f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 534f7b422b1SDavid Howells { 535f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 536f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 537f7b422b1SDavid Howells unsigned char nrbits; 538f7b422b1SDavid Howells 539f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 540f7b422b1SDavid Howells ; 541f7b422b1SDavid Howells bsize = 1 << nrbits; 542f7b422b1SDavid Howells if (nrbitsp) 543f7b422b1SDavid Howells *nrbitsp = nrbits; 544f7b422b1SDavid Howells } 545f7b422b1SDavid Howells 546f7b422b1SDavid Howells return bsize; 547f7b422b1SDavid Howells } 548f7b422b1SDavid Howells 549f7b422b1SDavid Howells /* 550f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 551f7b422b1SDavid Howells */ 5529eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 553f7b422b1SDavid Howells { 5549eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 555f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 556f7b422b1SDavid Howells } 557f7b422b1SDavid Howells 558f7b422b1SDavid Howells /* 559f7b422b1SDavid Howells * Compute and set NFS server blocksize 560f7b422b1SDavid Howells */ 561f7b422b1SDavid Howells static inline 562f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 563f7b422b1SDavid Howells { 564f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 565f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 566f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 567f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 568f7b422b1SDavid Howells 569f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 570f7b422b1SDavid Howells } 571f7b422b1SDavid Howells 572f7b422b1SDavid Howells /* 573f7b422b1SDavid Howells * Determine the maximum file size for a superblock 574f7b422b1SDavid Howells */ 575f7b422b1SDavid Howells static inline 576f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 577f7b422b1SDavid Howells { 578f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 579f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 580f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 581f7b422b1SDavid Howells } 58249a70f27STrond Myklebust 58349a70f27STrond Myklebust /* 58449a70f27STrond Myklebust * Determine the number of bytes of data the page contains 58549a70f27STrond Myklebust */ 58649a70f27STrond Myklebust static inline 58749a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 58849a70f27STrond Myklebust { 589d56b4ddfSMel Gorman loff_t i_size = i_size_read(page_file_mapping(page)->host); 59049a70f27STrond Myklebust 59149a70f27STrond Myklebust if (i_size > 0) { 592d56b4ddfSMel Gorman pgoff_t page_index = page_file_index(page); 59349a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 594d56b4ddfSMel Gorman if (page_index < end_index) 59549a70f27STrond Myklebust return PAGE_CACHE_SIZE; 596d56b4ddfSMel Gorman if (page_index == end_index) 59749a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 59849a70f27STrond Myklebust } 59949a70f27STrond Myklebust return 0; 60049a70f27STrond Myklebust } 6018d5658c9STrond Myklebust 6028d5658c9STrond Myklebust /* 6030b26a0bfSTrond Myklebust * Convert a umode to a dirent->d_type 6040b26a0bfSTrond Myklebust */ 6050b26a0bfSTrond Myklebust static inline 6060b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode) 6070b26a0bfSTrond Myklebust { 6080b26a0bfSTrond Myklebust return (mode >> 12) & 15; 6090b26a0bfSTrond Myklebust } 6100b26a0bfSTrond Myklebust 6110b26a0bfSTrond Myklebust /* 6128d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 6138d5658c9STrond Myklebust * with a base offset of 'base' 6148d5658c9STrond Myklebust */ 6158d5658c9STrond Myklebust static inline 6168d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 6178d5658c9STrond Myklebust { 6188d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 6198d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 6208d5658c9STrond Myklebust } 6210110ee15STrond Myklebust 6223a1556e8STrond Myklebust /* 6233a1556e8STrond Myklebust * Convert a struct timespec into a 64-bit change attribute 6243a1556e8STrond Myklebust * 6253a1556e8STrond Myklebust * This does approximately the same thing as timespec_to_ns(), 6263a1556e8STrond Myklebust * but for calculation efficiency, we multiply the seconds by 6273a1556e8STrond Myklebust * 1024*1024*1024. 6283a1556e8STrond Myklebust */ 6293a1556e8STrond Myklebust static inline 6303a1556e8STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec *ts) 6313a1556e8STrond Myklebust { 6323a1556e8STrond Myklebust return ((u64)ts->tv_sec << 30) + ts->tv_nsec; 6333a1556e8STrond Myklebust } 6341264a2f0STrond Myklebust 6351264a2f0STrond Myklebust #ifdef CONFIG_CRC32 6361264a2f0STrond Myklebust /** 6371264a2f0STrond Myklebust * nfs_fhandle_hash - calculate the crc32 hash for the filehandle 6381264a2f0STrond Myklebust * @fh - pointer to filehandle 6391264a2f0STrond Myklebust * 6401264a2f0STrond Myklebust * returns a crc32 hash for the filehandle that is compatible with 6411264a2f0STrond Myklebust * the one displayed by "wireshark". 6421264a2f0STrond Myklebust */ 6431264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) 6441264a2f0STrond Myklebust { 6451264a2f0STrond Myklebust return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); 6461264a2f0STrond Myklebust } 6471264a2f0STrond Myklebust #else 6481264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) 6491264a2f0STrond Myklebust { 6501264a2f0STrond Myklebust return 0; 6511264a2f0STrond Myklebust } 6521264a2f0STrond Myklebust #endif 653