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> 9f7b422b1SDavid Howells 1008734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) 1108734048SDavid Howells 1254ceac45SDavid Howells struct nfs_string; 1354ceac45SDavid Howells 1454ceac45SDavid Howells /* Maximum number of readahead requests 1554ceac45SDavid Howells * FIXME: this should really be a sysctl so that users may tune it to suit 1654ceac45SDavid Howells * their needs. People that do NFS over a slow network, might for 1754ceac45SDavid Howells * instance want to reduce it to something closer to 1 for improved 1854ceac45SDavid Howells * interactive response. 1954ceac45SDavid Howells */ 2054ceac45SDavid Howells #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 2154ceac45SDavid Howells 227ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr) 237ebb9315SBryan Schumaker { 247ebb9315SBryan Schumaker if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid)) 257ebb9315SBryan Schumaker fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT; 267ebb9315SBryan Schumaker } 277ebb9315SBryan Schumaker 28533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr) 29533eb461SAndy Adamson { 30533eb461SAndy Adamson if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) || 31533eb461SAndy Adamson (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && 32533eb461SAndy Adamson ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) 33533eb461SAndy Adamson return 0; 34533eb461SAndy Adamson 35533eb461SAndy Adamson fattr->fileid = fattr->mounted_on_fileid; 36533eb461SAndy Adamson return 1; 37533eb461SAndy Adamson } 38533eb461SAndy Adamson 39f7b422b1SDavid Howells struct nfs_clone_mount { 40f7b422b1SDavid Howells const struct super_block *sb; 41f7b422b1SDavid Howells const struct dentry *dentry; 42f7b422b1SDavid Howells struct nfs_fh *fh; 43f7b422b1SDavid Howells struct nfs_fattr *fattr; 44f7b422b1SDavid Howells char *hostname; 45f7b422b1SDavid Howells char *mnt_path; 466677d095SChuck Lever struct sockaddr *addr; 476677d095SChuck Lever size_t addrlen; 48f7b422b1SDavid Howells rpc_authflavor_t authflavor; 49f7b422b1SDavid Howells }; 50f7b422b1SDavid Howells 516b18eaa0S\"Talpey, Thomas\ /* 52a14017dbSChuck Lever * Note: RFC 1813 doesn't limit the number of auth flavors that 53a14017dbSChuck Lever * a server can return, so make something up. 54a14017dbSChuck Lever */ 55a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS (12) 56a14017dbSChuck Lever 57a14017dbSChuck Lever /* 584cfd74fcSChuck Lever * Value used if the user did not specify a port value. 594cfd74fcSChuck Lever */ 604cfd74fcSChuck Lever #define NFS_UNSPEC_PORT (-1) 614cfd74fcSChuck Lever 624cfd74fcSChuck Lever /* 6356e4ebf8SBryan Schumaker * Maximum number of pages that readdir can use for creating 6456e4ebf8SBryan Schumaker * a vmapped array of pages. 6556e4ebf8SBryan Schumaker */ 6656e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8 6756e4ebf8SBryan Schumaker 68fcf10398SBryan Schumaker struct nfs_client_initdata { 69fcf10398SBryan Schumaker unsigned long init_flags; 70fcf10398SBryan Schumaker const char *hostname; 71fcf10398SBryan Schumaker const struct sockaddr *addr; 72fcf10398SBryan Schumaker size_t addrlen; 73ab7017a3SBryan Schumaker struct nfs_subversion *nfs_mod; 74fcf10398SBryan Schumaker int proto; 75fcf10398SBryan Schumaker u32 minorversion; 76fcf10398SBryan Schumaker struct net *net; 77fcf10398SBryan Schumaker }; 78fcf10398SBryan Schumaker 7956e4ebf8SBryan Schumaker /* 806b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 816b18eaa0S\"Talpey, Thomas\ */ 826b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data { 836b18eaa0S\"Talpey, Thomas\ int flags; 848cb7f74eSChuck Lever unsigned int rsize, wsize; 858cb7f74eSChuck Lever unsigned int timeo, retrans; 868cb7f74eSChuck Lever unsigned int acregmin, acregmax, 876b18eaa0S\"Talpey, Thomas\ acdirmin, acdirmax; 888cb7f74eSChuck Lever unsigned int namlen; 89b797cac7SDavid Howells unsigned int options; 906b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 91a3f73c27SWeston Andros Adamson struct nfs_auth_info auth_info; 92a3f73c27SWeston Andros Adamson rpc_authflavor_t selected_flavor; 936b18eaa0S\"Talpey, Thomas\ char *client_address; 94764302ccSChuck Lever unsigned int version; 953fd5be9eSMike Sager unsigned int minorversion; 9608734048SDavid Howells char *fscache_uniq; 97b72e4f42SBryan Schumaker bool need_mount; 986b18eaa0S\"Talpey, Thomas\ 996b18eaa0S\"Talpey, Thomas\ struct { 1004c568017SChuck Lever struct sockaddr_storage address; 1014c568017SChuck Lever size_t addrlen; 1026b18eaa0S\"Talpey, Thomas\ char *hostname; 10378fa701fSChuck Lever u32 version; 1044cfd74fcSChuck Lever int port; 10578fa701fSChuck Lever unsigned short protocol; 1066b18eaa0S\"Talpey, Thomas\ } mount_server; 1076b18eaa0S\"Talpey, Thomas\ 1086b18eaa0S\"Talpey, Thomas\ struct { 1094c568017SChuck Lever struct sockaddr_storage address; 1104c568017SChuck Lever size_t addrlen; 1116b18eaa0S\"Talpey, Thomas\ char *hostname; 1126b18eaa0S\"Talpey, Thomas\ char *export_path; 1134cfd74fcSChuck Lever int port; 11478fa701fSChuck Lever unsigned short protocol; 1156b18eaa0S\"Talpey, Thomas\ } nfs_server; 116f9c3a380SEric Paris 117f9c3a380SEric Paris struct security_mnt_opts lsm_opts; 118e50a7a1aSStanislav Kinsbursky struct net *net; 1196b18eaa0S\"Talpey, Thomas\ }; 1206b18eaa0S\"Talpey, Thomas\ 121146ec944SChuck Lever /* mount_clnt.c */ 122c5d120f8SChuck Lever struct nfs_mount_request { 123c5d120f8SChuck Lever struct sockaddr *sap; 124c5d120f8SChuck Lever size_t salen; 125c5d120f8SChuck Lever char *hostname; 126c5d120f8SChuck Lever char *dirpath; 127c5d120f8SChuck Lever u32 version; 128c5d120f8SChuck Lever unsigned short protocol; 129c5d120f8SChuck Lever struct nfs_fh *fh; 13050a737f8SChuck Lever int noresvport; 1318e02f6b9SChuck Lever unsigned int *auth_flav_len; 1328e02f6b9SChuck Lever rpc_authflavor_t *auth_flavs; 1336d59b8d5SStanislav Kinsbursky struct net *net; 134c5d120f8SChuck Lever }; 135c5d120f8SChuck Lever 136fbdefd64SBryan Schumaker struct nfs_mount_info { 137fbdefd64SBryan Schumaker void (*fill_super)(struct super_block *, struct nfs_mount_info *); 138fbdefd64SBryan Schumaker int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *); 139fbdefd64SBryan Schumaker struct nfs_parsed_mount_data *parsed; 140fbdefd64SBryan Schumaker struct nfs_clone_mount *cloned; 141fbdefd64SBryan Schumaker struct nfs_fh *mntfh; 142fbdefd64SBryan Schumaker }; 143fbdefd64SBryan Schumaker 144c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info); 1450b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info); 146146ec944SChuck Lever 14724c8dbbbSDavid Howells /* client.c */ 148a613fa16STrond Myklebust extern const struct rpc_program nfs_program; 1496b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net); 1506663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *); 151428360d7SBryan Schumaker int nfs_create_rpc_client(struct nfs_client *, const struct rpc_timeout *, rpc_authflavor_t); 152fcf10398SBryan Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *, 153fcf10398SBryan Schumaker const struct rpc_timeout *, const char *, 154fcf10398SBryan Schumaker rpc_authflavor_t); 155fcf10398SBryan Schumaker int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *); 156fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *); 15732e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *); 158fcf10398SBryan Schumaker void nfs_init_timeout_values(struct rpc_timeout *, int, unsigned int, unsigned int); 159fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t, 160fcf10398SBryan Schumaker rpc_authflavor_t); 161fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void); 162fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); 16354ceac45SDavid Howells 16428cd1b3fSStanislav Kinsbursky extern void nfs_cleanup_cb_ident_idr(struct net *); 16524c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 166cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *); 16728cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int); 168c36fca52SAndy Adamson extern struct nfs_client * 169c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *, 170459de2edSBryan Schumaker struct nfs4_sessionid *, u32); 1711179acc6SBryan Schumaker extern struct nfs_server *nfs_create_server(struct nfs_mount_info *, 172ab7017a3SBryan Schumaker struct nfs_subversion *); 17391ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 1741179acc6SBryan Schumaker struct nfs_mount_info *, 1751179acc6SBryan Schumaker struct nfs_subversion *); 17654ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 17754ceac45SDavid Howells struct nfs_fh *); 17832e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname, 179292f503cSTrond Myklebust struct sockaddr *sap, size_t salen, 180292f503cSTrond Myklebust struct net *net); 18154ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 18254ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 18354ceac45SDavid Howells struct nfs_fh *, 1847e6eb683SBryan Schumaker struct nfs_fattr *, 1857e6eb683SBryan Schumaker rpc_authflavor_t); 1864697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp); 18776db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state); 188d83217c1SAndy Adamson extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, 189d83217c1SAndy Adamson const struct sockaddr *ds_addr, 19098fc685aSAndy Adamson int ds_addrlen, int ds_proto, 19198fc685aSAndy Adamson unsigned int ds_timeo, 19298fc685aSAndy Adamson unsigned int ds_retrans); 1930e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *, 1940e20162eSAndy Adamson struct inode *); 1956aaca566SDavid Howells #ifdef CONFIG_PROC_FS 1966aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 1976aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 1986aaca566SDavid Howells #else 1996aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 2006aaca566SDavid Howells { 2016aaca566SDavid Howells return 0; 2026aaca566SDavid Howells } 2036aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 2046aaca566SDavid Howells { 2056aaca566SDavid Howells } 2066aaca566SDavid Howells #endif 20724c8dbbbSDavid Howells 208fcf10398SBryan Schumaker #ifdef CONFIG_NFS_V4_1 209fcf10398SBryan Schumaker int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *); 210fcf10398SBryan Schumaker #endif 211fcf10398SBryan Schumaker 2121179acc6SBryan Schumaker /* nfs3client.c */ 2131c606fb7SBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V3) 2141179acc6SBryan Schumaker struct nfs_server *nfs3_create_server(struct nfs_mount_info *, struct nfs_subversion *); 2151179acc6SBryan Schumaker struct nfs_server *nfs3_clone_server(struct nfs_server *, struct nfs_fh *, 2161179acc6SBryan Schumaker struct nfs_fattr *, rpc_authflavor_t); 2171179acc6SBryan Schumaker #endif 2181179acc6SBryan Schumaker 219f7b422b1SDavid Howells /* callback_xdr.c */ 220f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 22107bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4; 222f7b422b1SDavid Howells 2234db6e0b7SFred Isaman struct nfs_pageio_descriptor; 224f7b422b1SDavid Howells /* pagelist.c */ 225f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 226266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 227f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 228266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 229f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 230266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 231f7b422b1SDavid Howells 232f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 233266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 2344db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, 2354db6e0b7SFred Isaman struct nfs_pgio_header *hdr, 2364db6e0b7SFred Isaman void (*release)(struct nfs_pgio_header *hdr)); 2374db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos); 238577b4232STrond Myklebust int nfs_iocounter_wait(struct nfs_io_counter *c); 239577b4232STrond Myklebust 2404a0de55cSAnna Schumaker struct nfs_rw_header *nfs_rw_header_alloc(const struct nfs_rw_ops *); 2414a0de55cSAnna Schumaker void nfs_rw_header_free(struct nfs_pgio_header *); 24200bfa30aSAnna Schumaker void nfs_pgio_data_release(struct nfs_pgio_data *); 243ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *); 24400bfa30aSAnna Schumaker 245577b4232STrond Myklebust static inline void nfs_iocounter_init(struct nfs_io_counter *c) 246577b4232STrond Myklebust { 247577b4232STrond Myklebust c->flags = 0; 248577b4232STrond Myklebust atomic_set(&c->io_count, 0); 249577b4232STrond Myklebust } 250f7b422b1SDavid Howells 251f7b422b1SDavid Howells /* nfs2xdr.c */ 252f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 253573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *, 254573c4e1eSChuck Lever struct nfs_entry *, int); 255f7b422b1SDavid Howells 256f7b422b1SDavid Howells /* nfs3xdr.c */ 257f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 258573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *, 259573c4e1eSChuck Lever struct nfs_entry *, int); 260f7b422b1SDavid Howells 261f7b422b1SDavid Howells /* nfs4xdr.c */ 26289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 263573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *, 264573c4e1eSChuck Lever struct nfs_entry *, int); 2657d4e2747SDavid Howells #endif 2662449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1 2672449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead; 2682449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead; 269f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead; 2702449ea2eSAlexandros Batsakis #endif 271f7b422b1SDavid Howells 272f7b422b1SDavid Howells /* nfs4proc.c */ 27389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 274f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 275d75d5414SAndrew Morton #endif 276f7b422b1SDavid Howells 277694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL 278694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags); 279694e096fSAnna Schumaker static inline void nfs4_label_free(struct nfs4_label *label) 280694e096fSAnna Schumaker { 281694e096fSAnna Schumaker if (label) { 282694e096fSAnna Schumaker kfree(label->label); 283694e096fSAnna Schumaker kfree(label); 284694e096fSAnna Schumaker } 285694e096fSAnna Schumaker return; 286694e096fSAnna Schumaker } 287fd1defc2STrond Myklebust 288fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) 289fd1defc2STrond Myklebust { 290fd1defc2STrond Myklebust if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL)) 291fd1defc2STrond Myklebust nfsi->cache_validity |= NFS_INO_INVALID_LABEL; 292fd1defc2STrond Myklebust } 293694e096fSAnna Schumaker #else 294694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; } 295694e096fSAnna Schumaker static inline void nfs4_label_free(void *label) {} 296fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi) 297fd1defc2STrond Myklebust { 298fd1defc2STrond Myklebust } 299694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */ 300694e096fSAnna Schumaker 3017fe5c398STrond Myklebust /* proc.c */ 3027fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 3038cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp, 30445a52a02SAndy Adamson const struct rpc_timeout *timeparms, 305f8407299SAndy Adamson const char *ip_addr); 3067fe5c398STrond Myklebust 307979df72eSTrond Myklebust /* dir.c */ 308311324adSTrond Myklebust extern void nfs_force_use_readdirplus(struct inode *dir); 3091ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink, 3101ab6c499SDave Chinner struct shrink_control *sc); 3111ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink, 3121495f230SYing Han struct shrink_control *sc); 313597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int); 314597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool); 315597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t); 316597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *); 317597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *); 318597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *); 319597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *); 320597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 321597d9289SBryan Schumaker int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 322979df72eSTrond Myklebust 323ce4ef7c0SBryan Schumaker /* file.c */ 324ce4ef7c0SBryan Schumaker int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int); 325ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int); 326ce4ef7c0SBryan Schumaker int nfs_file_flush(struct file *, fl_owner_t); 327ce4ef7c0SBryan Schumaker ssize_t nfs_file_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); 328ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *, 329ce4ef7c0SBryan Schumaker size_t, unsigned int); 330ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *); 331ce4ef7c0SBryan Schumaker ssize_t nfs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); 332ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *); 333ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *); 334ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *); 335ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_write(struct pipe_inode_info *, struct file *, loff_t *, 336ce4ef7c0SBryan Schumaker size_t, unsigned int); 337ce4ef7c0SBryan Schumaker int nfs_check_flags(int); 338ce4ef7c0SBryan Schumaker int nfs_setlease(struct file *, long, struct file_lock **); 339ce4ef7c0SBryan Schumaker 340f7b422b1SDavid Howells /* inode.c */ 3415746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 342f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 343f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 344a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *); 345eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *); 34619d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *); 347b57922d9SAl Viro extern void nfs_evict_inode(struct inode *); 348f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode); 34972cb77f4STrond Myklebust extern int nfs_wait_bit_killable(void *word); 350f7b422b1SDavid Howells 351f7b422b1SDavid Howells /* super.c */ 3526a74490dSBryan Schumaker extern const struct super_operations nfs_sops; 353ab7017a3SBryan Schumaker extern struct file_system_type nfs_fs_type; 35454ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 35589d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 35654ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 35754ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 358f7b422b1SDavid Howells #endif 3594d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t); 360ff9099f2SBryan Schumaker struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *, 361ff9099f2SBryan Schumaker struct nfs_subversion *); 362fbdefd64SBryan Schumaker void nfs_initialise_sb(struct super_block *); 363fbdefd64SBryan Schumaker int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *); 364fbdefd64SBryan Schumaker int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *); 365ab7017a3SBryan Schumaker struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *, 366ab7017a3SBryan Schumaker struct nfs_mount_info *, struct nfs_subversion *); 367fbdefd64SBryan Schumaker struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *); 368fbdefd64SBryan Schumaker struct dentry * nfs_xdev_mount_common(struct file_system_type *, int, 369fbdefd64SBryan Schumaker const char *, struct nfs_mount_info *); 370fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *); 371fbdefd64SBryan Schumaker void nfs_fill_super(struct super_block *, struct nfs_mount_info *); 3724ebd9ab3SDominik Hackl 373f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 3744ebd9ab3SDominik Hackl 375f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 376f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 3771daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb); 3781daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 379f7b422b1SDavid Howells 380f7b422b1SDavid Howells /* namespace.c */ 38197a54868SBen Hutchings #define NFS_PATH_CANONICAL 1 382b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry, 38397a54868SBen Hutchings char *buffer, ssize_t buflen, unsigned flags); 38436d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path); 385281cad46SBryan Schumaker struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *, 386281cad46SBryan Schumaker struct nfs_fh *, struct nfs_fattr *); 387281cad46SBryan Schumaker struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *, 388281cad46SBryan Schumaker struct nfs_fattr *, rpc_authflavor_t); 389f7b422b1SDavid Howells 39054ceac45SDavid Howells /* getroot.c */ 3910d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *, 3920d5839adSAl Viro const char *); 39389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4) 3940d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *, 3950d5839adSAl Viro const char *); 39654ceac45SDavid Howells 3975e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool); 3987d4e2747SDavid Howells #endif 399f7b422b1SDavid Howells 400061ae2edSFred Isaman struct nfs_pgio_completion_ops; 401f11c88afSAndy Adamson /* read.c */ 402584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 403fab5fc25SChristoph Hellwig struct inode *inode, bool force_mds, 404584aa810SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 405c5996c4eSFred Isaman extern int nfs_initiate_read(struct rpc_clnt *clnt, 4069c7e1b3dSAnna Schumaker struct nfs_pgio_data *data, 4079f0ec176SAndy Adamson const struct rpc_call_ops *call_ops, int flags); 408f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 409493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 410e885de1aSTrond Myklebust 411fbdefd64SBryan Schumaker /* super.c */ 412fbdefd64SBryan Schumaker void nfs_clone_super(struct super_block *, struct nfs_mount_info *); 413fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *); 414fbdefd64SBryan Schumaker int nfs_statfs(struct dentry *, struct kstatfs *); 415fbdefd64SBryan Schumaker int nfs_show_options(struct seq_file *, struct dentry *); 416fbdefd64SBryan Schumaker int nfs_show_devname(struct seq_file *, struct dentry *); 417fbdefd64SBryan Schumaker int nfs_show_path(struct seq_file *, struct dentry *); 418fbdefd64SBryan Schumaker int nfs_show_stats(struct seq_file *, struct dentry *); 419fbdefd64SBryan Schumaker void nfs_put_super(struct super_block *); 420fbdefd64SBryan Schumaker int nfs_remount(struct super_block *sb, int *flags, char *raw_data); 421fbdefd64SBryan Schumaker 422def6ed7eSAndy Adamson /* write.c */ 4231763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 424a20c93e3SChristoph Hellwig struct inode *inode, int ioflags, bool force_mds, 4251763da12SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 426dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); 4270b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p); 428c5996c4eSFred Isaman extern int nfs_initiate_write(struct rpc_clnt *clnt, 4299c7e1b3dSAnna Schumaker struct nfs_pgio_data *data, 430a69aef14SFred Isaman const struct rpc_call_ops *call_ops, 4319f0ec176SAndy Adamson int how, int flags); 432def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata); 4330b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); 4340b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt, 4350b7c0153SFred Isaman struct nfs_commit_data *data, 436e0c2b380SFred Isaman const struct rpc_call_ops *call_ops, 4379f0ec176SAndy Adamson int how, int flags); 4380b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data, 439e0c2b380SFred Isaman struct list_head *head, 440f453a54aSFred Isaman struct pnfs_layout_segment *lseg, 441f453a54aSFred Isaman struct nfs_commit_info *cinfo); 4421763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, 4431763da12SFred Isaman struct nfs_commit_info *cinfo, int max); 444ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *); 4451763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst, 4461763da12SFred Isaman struct nfs_commit_info *cinfo); 4471763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req, 4481763da12SFred Isaman struct pnfs_layout_segment *lseg, 4491763da12SFred Isaman struct nfs_commit_info *cinfo); 4501763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head, 4511763da12SFred Isaman int how, struct nfs_commit_info *cinfo); 452e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list, 453ea2cf228SFred Isaman struct pnfs_layout_segment *lseg, 454ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 4550b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data); 456ea2cf228SFred Isaman void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, 457ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 458ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req, 459ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 460ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo, 461ea2cf228SFred Isaman struct inode *inode, 462ea2cf228SFred Isaman struct nfs_direct_req *dreq); 463dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode); 464dc24826bSAndy Adamson bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx); 465e0c2b380SFred Isaman 466074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION 467074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *, 468a6bc32b8SMel Gorman struct page *, struct page *, enum migrate_mode); 469074cc1deSTrond Myklebust #else 470074cc1deSTrond Myklebust #define nfs_migrate_page NULL 471074cc1deSTrond Myklebust #endif 472def6ed7eSAndy Adamson 4730e862a40SJeff Layton /* unlink.c */ 4740e862a40SJeff Layton extern struct rpc_task * 4750e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir, 4760e862a40SJeff Layton struct dentry *old_dentry, struct dentry *new_dentry, 4770e862a40SJeff Layton void (*complete)(struct rpc_task *, struct nfs_renamedata *)); 4780e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry); 4790e862a40SJeff Layton 4801763da12SFred Isaman /* direct.c */ 4811763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, 4821763da12SFred Isaman struct nfs_direct_req *dreq); 4831d59d61fSTrond Myklebust static inline void nfs_inode_dio_wait(struct inode *inode) 4841d59d61fSTrond Myklebust { 4851d59d61fSTrond Myklebust inode_dio_wait(inode); 4861d59d61fSTrond Myklebust } 4876296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq); 4881763da12SFred Isaman 489cccef3b9SAndy Adamson /* nfs4proc.c */ 4909c7e1b3dSAnna Schumaker extern void __nfs4_read_done_cb(struct nfs_pgio_data *); 4918cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, 49245a52a02SAndy Adamson const struct rpc_timeout *timeparms, 493f8407299SAndy Adamson const char *ip_addr); 49405f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp, 49505f4c350SChuck Lever struct nfs_client **result, 49605f4c350SChuck Lever struct rpc_cred *cred); 49705f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp, 49805f4c350SChuck Lever struct nfs_client **result, 49905f4c350SChuck Lever struct rpc_cred *cred); 500cccef3b9SAndy Adamson 501557134a3SAndy Adamson /* 502f7b422b1SDavid Howells * Determine the device name as a string 503f7b422b1SDavid Howells */ 504b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry, 505f7b422b1SDavid Howells char *buffer, ssize_t buflen) 506f7b422b1SDavid Howells { 507b514f872SAl Viro char *dummy; 50897a54868SBen Hutchings return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL); 509f7b422b1SDavid Howells } 510f7b422b1SDavid Howells 511f7b422b1SDavid Howells /* 512f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 513f7b422b1SDavid Howells */ 514f7b422b1SDavid Howells static inline 515f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 516f7b422b1SDavid Howells { 517f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 518f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 519f7b422b1SDavid Howells unsigned char nrbits; 520f7b422b1SDavid Howells 521f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 522f7b422b1SDavid Howells ; 523f7b422b1SDavid Howells bsize = 1 << nrbits; 524f7b422b1SDavid Howells if (nrbitsp) 525f7b422b1SDavid Howells *nrbitsp = nrbits; 526f7b422b1SDavid Howells } 527f7b422b1SDavid Howells 528f7b422b1SDavid Howells return bsize; 529f7b422b1SDavid Howells } 530f7b422b1SDavid Howells 531f7b422b1SDavid Howells /* 532f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 533f7b422b1SDavid Howells */ 5349eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 535f7b422b1SDavid Howells { 5369eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 537f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 538f7b422b1SDavid Howells } 539f7b422b1SDavid Howells 540f7b422b1SDavid Howells /* 541f7b422b1SDavid Howells * Compute and set NFS server blocksize 542f7b422b1SDavid Howells */ 543f7b422b1SDavid Howells static inline 544f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 545f7b422b1SDavid Howells { 546f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 547f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 548f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 549f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 550f7b422b1SDavid Howells 551f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 552f7b422b1SDavid Howells } 553f7b422b1SDavid Howells 554f7b422b1SDavid Howells /* 555f7b422b1SDavid Howells * Determine the maximum file size for a superblock 556f7b422b1SDavid Howells */ 557f7b422b1SDavid Howells static inline 558f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 559f7b422b1SDavid Howells { 560f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 561f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 562f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 563f7b422b1SDavid Howells } 56449a70f27STrond Myklebust 56549a70f27STrond Myklebust /* 56649a70f27STrond Myklebust * Determine the number of bytes of data the page contains 56749a70f27STrond Myklebust */ 56849a70f27STrond Myklebust static inline 56949a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 57049a70f27STrond Myklebust { 571d56b4ddfSMel Gorman loff_t i_size = i_size_read(page_file_mapping(page)->host); 57249a70f27STrond Myklebust 57349a70f27STrond Myklebust if (i_size > 0) { 574d56b4ddfSMel Gorman pgoff_t page_index = page_file_index(page); 57549a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 576d56b4ddfSMel Gorman if (page_index < end_index) 57749a70f27STrond Myklebust return PAGE_CACHE_SIZE; 578d56b4ddfSMel Gorman if (page_index == end_index) 57949a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 58049a70f27STrond Myklebust } 58149a70f27STrond Myklebust return 0; 58249a70f27STrond Myklebust } 5838d5658c9STrond Myklebust 5848d5658c9STrond Myklebust /* 5850b26a0bfSTrond Myklebust * Convert a umode to a dirent->d_type 5860b26a0bfSTrond Myklebust */ 5870b26a0bfSTrond Myklebust static inline 5880b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode) 5890b26a0bfSTrond Myklebust { 5900b26a0bfSTrond Myklebust return (mode >> 12) & 15; 5910b26a0bfSTrond Myklebust } 5920b26a0bfSTrond Myklebust 5930b26a0bfSTrond Myklebust /* 5948d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 5958d5658c9STrond Myklebust * with a base offset of 'base' 5968d5658c9STrond Myklebust */ 5978d5658c9STrond Myklebust static inline 5988d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 5998d5658c9STrond Myklebust { 6008d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 6018d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 6028d5658c9STrond Myklebust } 6030110ee15STrond Myklebust 6043a1556e8STrond Myklebust /* 6053a1556e8STrond Myklebust * Convert a struct timespec into a 64-bit change attribute 6063a1556e8STrond Myklebust * 6073a1556e8STrond Myklebust * This does approximately the same thing as timespec_to_ns(), 6083a1556e8STrond Myklebust * but for calculation efficiency, we multiply the seconds by 6093a1556e8STrond Myklebust * 1024*1024*1024. 6103a1556e8STrond Myklebust */ 6113a1556e8STrond Myklebust static inline 6123a1556e8STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec *ts) 6133a1556e8STrond Myklebust { 6143a1556e8STrond Myklebust return ((u64)ts->tv_sec << 30) + ts->tv_nsec; 6153a1556e8STrond Myklebust } 6161264a2f0STrond Myklebust 6171264a2f0STrond Myklebust #ifdef CONFIG_CRC32 6181264a2f0STrond Myklebust /** 6191264a2f0STrond Myklebust * nfs_fhandle_hash - calculate the crc32 hash for the filehandle 6201264a2f0STrond Myklebust * @fh - pointer to filehandle 6211264a2f0STrond Myklebust * 6221264a2f0STrond Myklebust * returns a crc32 hash for the filehandle that is compatible with 6231264a2f0STrond Myklebust * the one displayed by "wireshark". 6241264a2f0STrond Myklebust */ 6251264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) 6261264a2f0STrond Myklebust { 6271264a2f0STrond Myklebust return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size); 6281264a2f0STrond Myklebust } 6291264a2f0STrond Myklebust #else 6301264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh) 6311264a2f0STrond Myklebust { 6321264a2f0STrond Myklebust return 0; 6331264a2f0STrond Myklebust } 6341264a2f0STrond Myklebust #endif 635