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> 8f7b422b1SDavid Howells 908734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) 1008734048SDavid Howells 1154ceac45SDavid Howells struct nfs_string; 1254ceac45SDavid Howells 1354ceac45SDavid Howells /* Maximum number of readahead requests 1454ceac45SDavid Howells * FIXME: this should really be a sysctl so that users may tune it to suit 1554ceac45SDavid Howells * their needs. People that do NFS over a slow network, might for 1654ceac45SDavid Howells * instance want to reduce it to something closer to 1 for improved 1754ceac45SDavid Howells * interactive response. 1854ceac45SDavid Howells */ 1954ceac45SDavid Howells #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 2054ceac45SDavid Howells 21eedc020eSAndy Adamson /* 22eedc020eSAndy Adamson * Determine if sessions are in use. 23eedc020eSAndy Adamson */ 24eedc020eSAndy Adamson static inline int nfs4_has_session(const struct nfs_client *clp) 25eedc020eSAndy Adamson { 26eedc020eSAndy Adamson #ifdef CONFIG_NFS_V4_1 27eedc020eSAndy Adamson if (clp->cl_session) 28eedc020eSAndy Adamson return 1; 29eedc020eSAndy Adamson #endif /* CONFIG_NFS_V4_1 */ 30eedc020eSAndy Adamson return 0; 31eedc020eSAndy Adamson } 32eedc020eSAndy Adamson 33d8cb1a7cSAlexandros Batsakis static inline int nfs4_has_persistent_session(const struct nfs_client *clp) 34d8cb1a7cSAlexandros Batsakis { 35d8cb1a7cSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1 36d8cb1a7cSAlexandros Batsakis if (nfs4_has_session(clp)) 37d8cb1a7cSAlexandros Batsakis return (clp->cl_session->flags & SESSION4_PERSIST); 38d8cb1a7cSAlexandros Batsakis #endif /* CONFIG_NFS_V4_1 */ 39d8cb1a7cSAlexandros Batsakis return 0; 40d8cb1a7cSAlexandros Batsakis } 41d8cb1a7cSAlexandros Batsakis 427ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr) 437ebb9315SBryan Schumaker { 447ebb9315SBryan Schumaker if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid)) 457ebb9315SBryan Schumaker fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT; 467ebb9315SBryan Schumaker } 477ebb9315SBryan Schumaker 48533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr) 49533eb461SAndy Adamson { 50533eb461SAndy Adamson if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) || 51533eb461SAndy Adamson (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) && 52533eb461SAndy Adamson ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0))) 53533eb461SAndy Adamson return 0; 54533eb461SAndy Adamson 55533eb461SAndy Adamson fattr->fileid = fattr->mounted_on_fileid; 56533eb461SAndy Adamson return 1; 57533eb461SAndy Adamson } 58533eb461SAndy Adamson 59f7b422b1SDavid Howells struct nfs_clone_mount { 60f7b422b1SDavid Howells const struct super_block *sb; 61f7b422b1SDavid Howells const struct dentry *dentry; 62f7b422b1SDavid Howells struct nfs_fh *fh; 63f7b422b1SDavid Howells struct nfs_fattr *fattr; 64f7b422b1SDavid Howells char *hostname; 65f7b422b1SDavid Howells char *mnt_path; 666677d095SChuck Lever struct sockaddr *addr; 676677d095SChuck Lever size_t addrlen; 68f7b422b1SDavid Howells rpc_authflavor_t authflavor; 69f7b422b1SDavid Howells }; 70f7b422b1SDavid Howells 716b18eaa0S\"Talpey, Thomas\ /* 72a14017dbSChuck Lever * Note: RFC 1813 doesn't limit the number of auth flavors that 73a14017dbSChuck Lever * a server can return, so make something up. 74a14017dbSChuck Lever */ 75a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS (12) 76a14017dbSChuck Lever 77a14017dbSChuck Lever /* 784cfd74fcSChuck Lever * Value used if the user did not specify a port value. 794cfd74fcSChuck Lever */ 804cfd74fcSChuck Lever #define NFS_UNSPEC_PORT (-1) 814cfd74fcSChuck Lever 824cfd74fcSChuck Lever /* 8356e4ebf8SBryan Schumaker * Maximum number of pages that readdir can use for creating 8456e4ebf8SBryan Schumaker * a vmapped array of pages. 8556e4ebf8SBryan Schumaker */ 8656e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8 8756e4ebf8SBryan Schumaker 8856e4ebf8SBryan Schumaker /* 896b18eaa0S\"Talpey, Thomas\ * In-kernel mount arguments 906b18eaa0S\"Talpey, Thomas\ */ 916b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data { 926b18eaa0S\"Talpey, Thomas\ int flags; 936b18eaa0S\"Talpey, Thomas\ int rsize, wsize; 946b18eaa0S\"Talpey, Thomas\ int timeo, retrans; 956b18eaa0S\"Talpey, Thomas\ int acregmin, acregmax, 966b18eaa0S\"Talpey, Thomas\ acdirmin, acdirmax; 976b18eaa0S\"Talpey, Thomas\ int namlen; 98b797cac7SDavid Howells unsigned int options; 996b18eaa0S\"Talpey, Thomas\ unsigned int bsize; 1006b18eaa0S\"Talpey, Thomas\ unsigned int auth_flavor_len; 1016b18eaa0S\"Talpey, Thomas\ rpc_authflavor_t auth_flavors[1]; 1026b18eaa0S\"Talpey, Thomas\ char *client_address; 103764302ccSChuck Lever unsigned int version; 1043fd5be9eSMike Sager unsigned int minorversion; 10508734048SDavid Howells char *fscache_uniq; 106b72e4f42SBryan Schumaker bool need_mount; 1076b18eaa0S\"Talpey, Thomas\ 1086b18eaa0S\"Talpey, Thomas\ struct { 1094c568017SChuck Lever struct sockaddr_storage address; 1104c568017SChuck Lever size_t addrlen; 1116b18eaa0S\"Talpey, Thomas\ char *hostname; 11278fa701fSChuck Lever u32 version; 1134cfd74fcSChuck Lever int port; 11478fa701fSChuck Lever unsigned short protocol; 1156b18eaa0S\"Talpey, Thomas\ } mount_server; 1166b18eaa0S\"Talpey, Thomas\ 1176b18eaa0S\"Talpey, Thomas\ struct { 1184c568017SChuck Lever struct sockaddr_storage address; 1194c568017SChuck Lever size_t addrlen; 1206b18eaa0S\"Talpey, Thomas\ char *hostname; 1216b18eaa0S\"Talpey, Thomas\ char *export_path; 1224cfd74fcSChuck Lever int port; 12378fa701fSChuck Lever unsigned short protocol; 1246b18eaa0S\"Talpey, Thomas\ } nfs_server; 125f9c3a380SEric Paris 126f9c3a380SEric Paris struct security_mnt_opts lsm_opts; 127e50a7a1aSStanislav Kinsbursky struct net *net; 1286b18eaa0S\"Talpey, Thomas\ }; 1296b18eaa0S\"Talpey, Thomas\ 130146ec944SChuck Lever /* mount_clnt.c */ 131c5d120f8SChuck Lever struct nfs_mount_request { 132c5d120f8SChuck Lever struct sockaddr *sap; 133c5d120f8SChuck Lever size_t salen; 134c5d120f8SChuck Lever char *hostname; 135c5d120f8SChuck Lever char *dirpath; 136c5d120f8SChuck Lever u32 version; 137c5d120f8SChuck Lever unsigned short protocol; 138c5d120f8SChuck Lever struct nfs_fh *fh; 13950a737f8SChuck Lever int noresvport; 1408e02f6b9SChuck Lever unsigned int *auth_flav_len; 1418e02f6b9SChuck Lever rpc_authflavor_t *auth_flavs; 1426d59b8d5SStanislav Kinsbursky struct net *net; 143c5d120f8SChuck Lever }; 144c5d120f8SChuck Lever 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 *); 15254ceac45SDavid Howells 15328cd1b3fSStanislav Kinsbursky extern void nfs_cleanup_cb_ident_idr(struct net *); 15424c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *); 155cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *); 15628cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int); 157c36fca52SAndy Adamson extern struct nfs_client * 158c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *, 159c7add9a9SStanislav Kinsbursky struct nfs4_sessionid *); 1602283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server( 1612283f8d6S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 16254ceac45SDavid Howells struct nfs_fh *); 16391ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server( 16491ea40b9S\"Talpey, Thomas\ const struct nfs_parsed_mount_data *, 16554ceac45SDavid Howells struct nfs_fh *); 16654ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 16754ceac45SDavid Howells struct nfs_fh *); 16854ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server); 16954ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *, 17054ceac45SDavid Howells struct nfs_fh *, 1717e6eb683SBryan Schumaker struct nfs_fattr *, 1727e6eb683SBryan Schumaker rpc_authflavor_t); 1734697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp); 17476db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state); 175d83217c1SAndy Adamson extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp, 176d83217c1SAndy Adamson const struct sockaddr *ds_addr, 17798fc685aSAndy Adamson int ds_addrlen, int ds_proto, 17898fc685aSAndy Adamson unsigned int ds_timeo, 17998fc685aSAndy Adamson unsigned int ds_retrans); 1806aaca566SDavid Howells #ifdef CONFIG_PROC_FS 1816aaca566SDavid Howells extern int __init nfs_fs_proc_init(void); 1826aaca566SDavid Howells extern void nfs_fs_proc_exit(void); 1836aaca566SDavid Howells #else 1846aaca566SDavid Howells static inline int nfs_fs_proc_init(void) 1856aaca566SDavid Howells { 1866aaca566SDavid Howells return 0; 1876aaca566SDavid Howells } 1886aaca566SDavid Howells static inline void nfs_fs_proc_exit(void) 1896aaca566SDavid Howells { 1906aaca566SDavid Howells } 1916aaca566SDavid Howells #endif 19224c8dbbbSDavid Howells 193f7b422b1SDavid Howells /* callback_xdr.c */ 194f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1; 19507bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4; 196f7b422b1SDavid Howells 1974db6e0b7SFred Isaman struct nfs_pageio_descriptor; 198f7b422b1SDavid Howells /* pagelist.c */ 199f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void); 200266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void); 201f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void); 202266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void); 203f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void); 204266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void); 205f7b422b1SDavid Howells 206f7b422b1SDavid Howells extern int __init nfs_init_directcache(void); 207266bee88SDavid Brownell extern void nfs_destroy_directcache(void); 20830dd374fSFred Isaman extern bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount); 2094db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc, 2104db6e0b7SFred Isaman struct nfs_pgio_header *hdr, 2114db6e0b7SFred Isaman void (*release)(struct nfs_pgio_header *hdr)); 2124db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos); 213f7b422b1SDavid Howells 214f7b422b1SDavid Howells /* nfs2xdr.c */ 215f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[]; 216573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *, 217573c4e1eSChuck Lever struct nfs_entry *, int); 218f7b422b1SDavid Howells 219f7b422b1SDavid Howells /* nfs3xdr.c */ 220f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[]; 221573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *, 222573c4e1eSChuck Lever struct nfs_entry *, int); 223f7b422b1SDavid Howells 224f7b422b1SDavid Howells /* nfs4xdr.c */ 2257d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 226573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *, 227573c4e1eSChuck Lever struct nfs_entry *, int); 2287d4e2747SDavid Howells #endif 2292449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1 2302449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead; 2312449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead; 2322449ea2eSAlexandros Batsakis #endif 233f7b422b1SDavid Howells 234f7b422b1SDavid Howells /* nfs4proc.c */ 235d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4 236f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[]; 237d75d5414SAndrew Morton #endif 238f7b422b1SDavid Howells 2397b38c368STrond Myklebust extern int nfs4_init_ds_session(struct nfs_client *, unsigned long); 240d83217c1SAndy Adamson 2417fe5c398STrond Myklebust /* proc.c */ 2427fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 2438cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp, 24445a52a02SAndy Adamson const struct rpc_timeout *timeparms, 2454bf590e0SChuck Lever const char *ip_addr, rpc_authflavor_t authflavour); 2467fe5c398STrond Myklebust 247979df72eSTrond Myklebust /* dir.c */ 2487f8275d0SDave Chinner extern int nfs_access_cache_shrinker(struct shrinker *shrink, 2491495f230SYing Han struct shrink_control *sc); 250597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int); 251597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool); 252597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t); 253597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *); 254597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *); 255597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *); 256597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *); 257597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 258597d9289SBryan Schumaker int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 259979df72eSTrond Myklebust 260ce4ef7c0SBryan Schumaker /* file.c */ 261ce4ef7c0SBryan Schumaker int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int); 262ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int); 263ce4ef7c0SBryan Schumaker int nfs_file_flush(struct file *, fl_owner_t); 264ce4ef7c0SBryan Schumaker ssize_t nfs_file_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); 265ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *, 266ce4ef7c0SBryan Schumaker size_t, unsigned int); 267ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *); 268ce4ef7c0SBryan Schumaker ssize_t nfs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); 269ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *); 270ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *); 271ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *); 272ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_write(struct pipe_inode_info *, struct file *, loff_t *, 273ce4ef7c0SBryan Schumaker size_t, unsigned int); 274ce4ef7c0SBryan Schumaker int nfs_check_flags(int); 275ce4ef7c0SBryan Schumaker int nfs_setlease(struct file *, long, struct file_lock **); 276ce4ef7c0SBryan Schumaker 277f7b422b1SDavid Howells /* inode.c */ 2785746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue; 279f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb); 280f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *); 281a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *); 282b57922d9SAl Viro extern void nfs_evict_inode(struct inode *); 283f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 284b57922d9SAl Viro extern void nfs4_evict_inode(struct inode *); 285f7b422b1SDavid Howells #endif 286f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode); 28772cb77f4STrond Myklebust extern int nfs_wait_bit_killable(void *word); 288f7b422b1SDavid Howells 289f7b422b1SDavid Howells /* super.c */ 29054ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type; 291f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4 29254ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type; 29354ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type; 294f7b422b1SDavid Howells #endif 2954ebd9ab3SDominik Hackl 296f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat; 2974ebd9ab3SDominik Hackl 298f7b422b1SDavid Howells extern int __init register_nfs_fs(void); 299f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void); 3001daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb); 3011daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb); 302f7b422b1SDavid Howells 303f7b422b1SDavid Howells /* namespace.c */ 304b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry, 305f7b422b1SDavid Howells char *buffer, ssize_t buflen); 30636d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path); 307281cad46SBryan Schumaker struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *, 308281cad46SBryan Schumaker struct nfs_fh *, struct nfs_fattr *); 309281cad46SBryan Schumaker struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *, 310281cad46SBryan Schumaker struct nfs_fattr *, rpc_authflavor_t); 311f7b422b1SDavid Howells 31254ceac45SDavid Howells /* getroot.c */ 3130d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *, 3140d5839adSAl Viro const char *); 3157d4e2747SDavid Howells #ifdef CONFIG_NFS_V4 3160d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *, 3170d5839adSAl Viro const char *); 31854ceac45SDavid Howells 319815409d2STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh); 3207d4e2747SDavid Howells #endif 321f7b422b1SDavid Howells 322061ae2edSFred Isaman struct nfs_pgio_completion_ops; 323f11c88afSAndy Adamson /* read.c */ 3244db6e0b7SFred Isaman extern struct nfs_read_header *nfs_readhdr_alloc(void); 325cd841605SFred Isaman extern void nfs_readhdr_free(struct nfs_pgio_header *hdr); 326584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 327584aa810SFred Isaman struct inode *inode, 328584aa810SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 329c5996c4eSFred Isaman extern int nfs_initiate_read(struct rpc_clnt *clnt, 330c5996c4eSFred Isaman struct nfs_read_data *data, 3319f0ec176SAndy Adamson const struct rpc_call_ops *call_ops, int flags); 332f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata); 333493292ddSTrond Myklebust extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc, 3344db6e0b7SFred Isaman struct nfs_pgio_header *hdr); 3351abb5088SBryan Schumaker extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, 336061ae2edSFred Isaman struct inode *inode, 337061ae2edSFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 338493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio); 339493292ddSTrond Myklebust extern void nfs_readdata_release(struct nfs_read_data *rdata); 340e885de1aSTrond Myklebust 341def6ed7eSAndy Adamson /* write.c */ 3421763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 3431763da12SFred Isaman struct inode *inode, int ioflags, 3441763da12SFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 3456c75dc0dSFred Isaman extern struct nfs_write_header *nfs_writehdr_alloc(void); 346cd841605SFred Isaman extern void nfs_writehdr_free(struct nfs_pgio_header *hdr); 347dce81290STrond Myklebust extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc, 3486c75dc0dSFred Isaman struct nfs_pgio_header *hdr); 34957208fa7SBryan Schumaker extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, 350061ae2edSFred Isaman struct inode *inode, int ioflags, 351061ae2edSFred Isaman const struct nfs_pgio_completion_ops *compl_ops); 352dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio); 353dce81290STrond Myklebust extern void nfs_writedata_release(struct nfs_write_data *wdata); 3540b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p); 355c5996c4eSFred Isaman extern int nfs_initiate_write(struct rpc_clnt *clnt, 356c5996c4eSFred Isaman struct nfs_write_data *data, 357a69aef14SFred Isaman const struct rpc_call_ops *call_ops, 3589f0ec176SAndy Adamson int how, int flags); 359def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata); 3600b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata); 3610b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt, 3620b7c0153SFred Isaman struct nfs_commit_data *data, 363e0c2b380SFred Isaman const struct rpc_call_ops *call_ops, 3649f0ec176SAndy Adamson int how, int flags); 3650b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data, 366e0c2b380SFred Isaman struct list_head *head, 367f453a54aSFred Isaman struct pnfs_layout_segment *lseg, 368f453a54aSFred Isaman struct nfs_commit_info *cinfo); 3691763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, 3701763da12SFred Isaman struct nfs_commit_info *cinfo, int max); 3711763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst, 3721763da12SFred Isaman struct nfs_commit_info *cinfo); 3731763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req, 3741763da12SFred Isaman struct pnfs_layout_segment *lseg, 3751763da12SFred Isaman struct nfs_commit_info *cinfo); 3761763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head, 3771763da12SFred Isaman int how, struct nfs_commit_info *cinfo); 378e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list, 379ea2cf228SFred Isaman struct pnfs_layout_segment *lseg, 380ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 3810b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data); 382ea2cf228SFred Isaman void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst, 383ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 384ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req, 385ea2cf228SFred Isaman struct nfs_commit_info *cinfo); 386ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo, 387ea2cf228SFred Isaman struct inode *inode, 388ea2cf228SFred Isaman struct nfs_direct_req *dreq); 389e0c2b380SFred Isaman 390074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION 391074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *, 392a6bc32b8SMel Gorman struct page *, struct page *, enum migrate_mode); 393074cc1deSTrond Myklebust #else 394074cc1deSTrond Myklebust #define nfs_migrate_page NULL 395074cc1deSTrond Myklebust #endif 396def6ed7eSAndy Adamson 3971763da12SFred Isaman /* direct.c */ 3981763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo, 3991763da12SFred Isaman struct nfs_direct_req *dreq); 4001d59d61fSTrond Myklebust static inline void nfs_inode_dio_wait(struct inode *inode) 4011d59d61fSTrond Myklebust { 4021d59d61fSTrond Myklebust inode_dio_wait(inode); 4031d59d61fSTrond Myklebust } 4041763da12SFred Isaman 405cccef3b9SAndy Adamson /* nfs4proc.c */ 406d20581aaSBenny Halevy extern void __nfs4_read_done_cb(struct nfs_read_data *); 4078cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp, 40845a52a02SAndy Adamson const struct rpc_timeout *timeparms, 40945a52a02SAndy Adamson const char *ip_addr, 4104bf590e0SChuck Lever rpc_authflavor_t authflavour); 4117c513058SBryan Schumaker extern int _nfs4_call_sync(struct rpc_clnt *clnt, 4127c513058SBryan Schumaker struct nfs_server *server, 413cccef3b9SAndy Adamson struct rpc_message *msg, 414cccef3b9SAndy Adamson struct nfs4_sequence_args *args, 415cccef3b9SAndy Adamson struct nfs4_sequence_res *res, 416cccef3b9SAndy Adamson int cache_reply); 4177c513058SBryan Schumaker extern int _nfs4_call_sync_session(struct rpc_clnt *clnt, 4187c513058SBryan Schumaker struct nfs_server *server, 419cccef3b9SAndy Adamson struct rpc_message *msg, 420cccef3b9SAndy Adamson struct nfs4_sequence_args *args, 421cccef3b9SAndy Adamson struct nfs4_sequence_res *res, 422cccef3b9SAndy Adamson int cache_reply); 423cccef3b9SAndy Adamson 424557134a3SAndy Adamson /* 425f7b422b1SDavid Howells * Determine the device name as a string 426f7b422b1SDavid Howells */ 427b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry, 428f7b422b1SDavid Howells char *buffer, ssize_t buflen) 429f7b422b1SDavid Howells { 430b514f872SAl Viro char *dummy; 431b514f872SAl Viro return nfs_path(&dummy, dentry, buffer, buflen); 432f7b422b1SDavid Howells } 433f7b422b1SDavid Howells 434f7b422b1SDavid Howells /* 435f7b422b1SDavid Howells * Determine the actual block size (and log2 thereof) 436f7b422b1SDavid Howells */ 437f7b422b1SDavid Howells static inline 438f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 439f7b422b1SDavid Howells { 440f7b422b1SDavid Howells /* make sure blocksize is a power of two */ 441f7b422b1SDavid Howells if ((bsize & (bsize - 1)) || nrbitsp) { 442f7b422b1SDavid Howells unsigned char nrbits; 443f7b422b1SDavid Howells 444f7b422b1SDavid Howells for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 445f7b422b1SDavid Howells ; 446f7b422b1SDavid Howells bsize = 1 << nrbits; 447f7b422b1SDavid Howells if (nrbitsp) 448f7b422b1SDavid Howells *nrbitsp = nrbits; 449f7b422b1SDavid Howells } 450f7b422b1SDavid Howells 451f7b422b1SDavid Howells return bsize; 452f7b422b1SDavid Howells } 453f7b422b1SDavid Howells 454f7b422b1SDavid Howells /* 455f7b422b1SDavid Howells * Calculate the number of 512byte blocks used. 456f7b422b1SDavid Howells */ 4579eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize) 458f7b422b1SDavid Howells { 4599eaa67c6SChuck Lever blkcnt_t used = (tsize + 511) >> 9; 460f7b422b1SDavid Howells return (used > ULONG_MAX) ? ULONG_MAX : used; 461f7b422b1SDavid Howells } 462f7b422b1SDavid Howells 463f7b422b1SDavid Howells /* 464f7b422b1SDavid Howells * Compute and set NFS server blocksize 465f7b422b1SDavid Howells */ 466f7b422b1SDavid Howells static inline 467f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 468f7b422b1SDavid Howells { 469f7b422b1SDavid Howells if (bsize < NFS_MIN_FILE_IO_SIZE) 470f7b422b1SDavid Howells bsize = NFS_DEF_FILE_IO_SIZE; 471f7b422b1SDavid Howells else if (bsize >= NFS_MAX_FILE_IO_SIZE) 472f7b422b1SDavid Howells bsize = NFS_MAX_FILE_IO_SIZE; 473f7b422b1SDavid Howells 474f7b422b1SDavid Howells return nfs_block_bits(bsize, nrbitsp); 475f7b422b1SDavid Howells } 476f7b422b1SDavid Howells 477f7b422b1SDavid Howells /* 478f7b422b1SDavid Howells * Determine the maximum file size for a superblock 479f7b422b1SDavid Howells */ 480f7b422b1SDavid Howells static inline 481f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 482f7b422b1SDavid Howells { 483f7b422b1SDavid Howells sb->s_maxbytes = (loff_t)maxfilesize; 484f7b422b1SDavid Howells if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 485f7b422b1SDavid Howells sb->s_maxbytes = MAX_LFS_FILESIZE; 486f7b422b1SDavid Howells } 48749a70f27STrond Myklebust 48849a70f27STrond Myklebust /* 48949a70f27STrond Myklebust * Determine the number of bytes of data the page contains 49049a70f27STrond Myklebust */ 49149a70f27STrond Myklebust static inline 49249a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page) 49349a70f27STrond Myklebust { 49449a70f27STrond Myklebust loff_t i_size = i_size_read(page->mapping->host); 49549a70f27STrond Myklebust 49649a70f27STrond Myklebust if (i_size > 0) { 49749a70f27STrond Myklebust pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 49849a70f27STrond Myklebust if (page->index < end_index) 49949a70f27STrond Myklebust return PAGE_CACHE_SIZE; 50049a70f27STrond Myklebust if (page->index == end_index) 50149a70f27STrond Myklebust return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 50249a70f27STrond Myklebust } 50349a70f27STrond Myklebust return 0; 50449a70f27STrond Myklebust } 5058d5658c9STrond Myklebust 5068d5658c9STrond Myklebust /* 5070b26a0bfSTrond Myklebust * Convert a umode to a dirent->d_type 5080b26a0bfSTrond Myklebust */ 5090b26a0bfSTrond Myklebust static inline 5100b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode) 5110b26a0bfSTrond Myklebust { 5120b26a0bfSTrond Myklebust return (mode >> 12) & 15; 5130b26a0bfSTrond Myklebust } 5140b26a0bfSTrond Myklebust 5150b26a0bfSTrond Myklebust /* 5168d5658c9STrond Myklebust * Determine the number of pages in an array of length 'len' and 5178d5658c9STrond Myklebust * with a base offset of 'base' 5188d5658c9STrond Myklebust */ 5198d5658c9STrond Myklebust static inline 5208d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len) 5218d5658c9STrond Myklebust { 5228d5658c9STrond Myklebust return ((unsigned long)len + (unsigned long)base + 5238d5658c9STrond Myklebust PAGE_SIZE - 1) >> PAGE_SHIFT; 5248d5658c9STrond Myklebust } 5250110ee15STrond Myklebust 5263a1556e8STrond Myklebust /* 5273a1556e8STrond Myklebust * Convert a struct timespec into a 64-bit change attribute 5283a1556e8STrond Myklebust * 5293a1556e8STrond Myklebust * This does approximately the same thing as timespec_to_ns(), 5303a1556e8STrond Myklebust * but for calculation efficiency, we multiply the seconds by 5313a1556e8STrond Myklebust * 1024*1024*1024. 5323a1556e8STrond Myklebust */ 5333a1556e8STrond Myklebust static inline 5343a1556e8STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec *ts) 5353a1556e8STrond Myklebust { 5363a1556e8STrond Myklebust return ((u64)ts->tv_sec << 30) + ts->tv_nsec; 5373a1556e8STrond Myklebust } 538