1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 29a74af21SBoaz Harrosh /* 39a74af21SBoaz Harrosh * Hodge-podge collection of knfsd-related stuff. 49a74af21SBoaz Harrosh * I will sort this out later. 59a74af21SBoaz Harrosh * 69a74af21SBoaz Harrosh * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> 79a74af21SBoaz Harrosh */ 89a74af21SBoaz Harrosh 99a74af21SBoaz Harrosh #ifndef LINUX_NFSD_NFSD_H 109a74af21SBoaz Harrosh #define LINUX_NFSD_NFSD_H 119a74af21SBoaz Harrosh 129a74af21SBoaz Harrosh #include <linux/types.h> 139a74af21SBoaz Harrosh #include <linux/mount.h> 149a74af21SBoaz Harrosh 15c10bd39dSJ. Bruce Fields #include <linux/nfs.h> 16c10bd39dSJ. Bruce Fields #include <linux/nfs2.h> 17c10bd39dSJ. Bruce Fields #include <linux/nfs3.h> 18c10bd39dSJ. Bruce Fields #include <linux/nfs4.h> 199c69de4cSChristoph Hellwig #include <linux/sunrpc/svc.h> 20e45d1a18STrond Myklebust #include <linux/sunrpc/svc_xprt.h> 21c10bd39dSJ. Bruce Fields #include <linux/sunrpc/msg_prot.h> 22af76fc6cSOlga Kornievskaia #include <linux/sunrpc/addr.h> 23c10bd39dSJ. Bruce Fields 246f226e2aSChristoph Hellwig #include <uapi/linux/nfsd/debug.h> 25c10bd39dSJ. Bruce Fields 26e8a79fb1SJ. Bruce Fields #include "netns.h" 27d430e8d5SChristoph Hellwig #include "export.h" 2820ad856eSAmir Goldstein #include "stats.h" 29d430e8d5SChristoph Hellwig 306f226e2aSChristoph Hellwig #undef ifdebug 31135dd002SMark Salter #ifdef CONFIG_SUNRPC_DEBUG 326f226e2aSChristoph Hellwig # define ifdebug(flag) if (nfsd_debug & NFSDDBG_##flag) 336f226e2aSChristoph Hellwig #else 346f226e2aSChristoph Hellwig # define ifdebug(flag) if (0) 356f226e2aSChristoph Hellwig #endif 366f226e2aSChristoph Hellwig 379a74af21SBoaz Harrosh /* 389a74af21SBoaz Harrosh * nfsd version 399a74af21SBoaz Harrosh */ 404bdc33edSSteve Dickson #define NFSD_SUPPORTED_MINOR_VERSION 2 41c10bd39dSJ. Bruce Fields /* 42c10bd39dSJ. Bruce Fields * Maximum blocksizes supported by daemon under various circumstances. 43c10bd39dSJ. Bruce Fields */ 44c10bd39dSJ. Bruce Fields #define NFSSVC_MAXBLKSIZE RPCSVC_MAXPAYLOAD 45c10bd39dSJ. Bruce Fields /* NFSv2 is limited by the protocol specification, see RFC 1094 */ 46c10bd39dSJ. Bruce Fields #define NFSSVC_MAXBLKSIZE_V2 (8*1024) 47c10bd39dSJ. Bruce Fields 48c10bd39dSJ. Bruce Fields 49c10bd39dSJ. Bruce Fields /* 50c10bd39dSJ. Bruce Fields * Largest number of bytes we need to allocate for an NFS 51c10bd39dSJ. Bruce Fields * call or reply. Used to control buffer sizes. We use 52c10bd39dSJ. Bruce Fields * the length of v3 WRITE, READDIR and READDIR replies 53c10bd39dSJ. Bruce Fields * which are an RPC header, up to 26 XDR units of reply 54c10bd39dSJ. Bruce Fields * data, and some page data. 55c10bd39dSJ. Bruce Fields * 56c10bd39dSJ. Bruce Fields * Note that accuracy here doesn't matter too much as the 57c10bd39dSJ. Bruce Fields * size is rounded up to a page size when allocating space. 58c10bd39dSJ. Bruce Fields */ 59c10bd39dSJ. Bruce Fields #define NFSD_BUFSIZE ((RPC_MAX_HEADER_WITH_AUTH+26)*XDR_UNIT + NFSSVC_MAXBLKSIZE) 609a74af21SBoaz Harrosh 619a74af21SBoaz Harrosh struct readdir_cd { 629a74af21SBoaz Harrosh __be32 err; /* 0, nfserr, or nfserr_eof */ 639a74af21SBoaz Harrosh }; 649a74af21SBoaz Harrosh 659a74af21SBoaz Harrosh 669a74af21SBoaz Harrosh extern struct svc_program nfsd_program; 672f3a4b2aSJeff Layton extern const struct svc_version nfsd_version2, nfsd_version3, nfsd_version4; 689a74af21SBoaz Harrosh extern struct mutex nfsd_mutex; 699a74af21SBoaz Harrosh extern spinlock_t nfsd_drc_lock; 70697ce9beSZhang Yanfei extern unsigned long nfsd_drc_max_mem; 71697ce9beSZhang Yanfei extern unsigned long nfsd_drc_mem_used; 729a74af21SBoaz Harrosh 739a74af21SBoaz Harrosh extern const struct seq_operations nfs_exports_op; 749a74af21SBoaz Harrosh 759a74af21SBoaz Harrosh /* 76788f7183SChuck Lever * Common void argument and result helpers 77788f7183SChuck Lever */ 78788f7183SChuck Lever struct nfsd_voidargs { }; 79788f7183SChuck Lever struct nfsd_voidres { }; 80c44b31c2SChuck Lever bool nfssvc_decode_voidarg(struct svc_rqst *rqstp, 8116c66364SChuck Lever struct xdr_stream *xdr); 82130e2054SChuck Lever bool nfssvc_encode_voidres(struct svc_rqst *rqstp, 83fda49441SChuck Lever struct xdr_stream *xdr); 84788f7183SChuck Lever 85788f7183SChuck Lever /* 869a74af21SBoaz Harrosh * Function prototypes. 879a74af21SBoaz Harrosh */ 884df493a2STrond Myklebust int nfsd_svc(int nrservs, struct net *net, const struct cred *cred); 89cee4db19SChuck Lever int nfsd_dispatch(struct svc_rqst *rqstp); 909a74af21SBoaz Harrosh 919dd9845fSStanislav Kinsbursky int nfsd_nrthreads(struct net *); 929dd9845fSStanislav Kinsbursky int nfsd_nrpools(struct net *); 939dd9845fSStanislav Kinsbursky int nfsd_get_nrthreads(int n, int *, struct net *); 943938a0d5SStanislav Kinsbursky int nfsd_set_nrthreads(int n, int *, struct net *); 957f2e7dc0SJ. Bruce Fields int nfsd_pool_stats_open(struct inode *, struct file *); 967f2e7dc0SJ. Bruce Fields int nfsd_pool_stats_release(struct inode *, struct file *); 97c6c7f2a8STrond Myklebust void nfsd_shutdown_threads(struct net *net); 989a74af21SBoaz Harrosh 9928df3d15SJ. Bruce Fields bool i_am_nfsd(void); 10028df3d15SJ. Bruce Fields 101e8a79fb1SJ. Bruce Fields struct nfsdfs_client { 102e8a79fb1SJ. Bruce Fields struct kref cl_ref; 103e8a79fb1SJ. Bruce Fields void (*cl_release)(struct kref *kref); 104e8a79fb1SJ. Bruce Fields }; 105e8a79fb1SJ. Bruce Fields 10697ad4031SJ. Bruce Fields struct nfsdfs_client *get_nfsdfs_client(struct inode *); 10797ad4031SJ. Bruce Fields struct dentry *nfsd_client_mkdir(struct nfsd_net *nn, 108472d155aSNeilBrown struct nfsdfs_client *ncl, u32 id, 109472d155aSNeilBrown const struct tree_descr *, 110472d155aSNeilBrown struct dentry **fdentries); 111e8a79fb1SJ. Bruce Fields void nfsd_client_rmdir(struct dentry *dentry); 112e8a79fb1SJ. Bruce Fields 113681370f4SJ. Bruce Fields 1149a74af21SBoaz Harrosh #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) 1159a74af21SBoaz Harrosh #ifdef CONFIG_NFSD_V2_ACL 116e9679189SChristoph Hellwig extern const struct svc_version nfsd_acl_version2; 1179a74af21SBoaz Harrosh #else 1189a74af21SBoaz Harrosh #define nfsd_acl_version2 NULL 1199a74af21SBoaz Harrosh #endif 1209a74af21SBoaz Harrosh #ifdef CONFIG_NFSD_V3_ACL 121e9679189SChristoph Hellwig extern const struct svc_version nfsd_acl_version3; 1229a74af21SBoaz Harrosh #else 1239a74af21SBoaz Harrosh #define nfsd_acl_version3 NULL 1249a74af21SBoaz Harrosh #endif 1259a74af21SBoaz Harrosh #endif 1269a74af21SBoaz Harrosh 127e333f3bbSTrond Myklebust struct nfsd_net; 128e333f3bbSTrond Myklebust 1299a74af21SBoaz Harrosh enum vers_op {NFSD_SET, NFSD_CLEAR, NFSD_TEST, NFSD_AVAIL }; 130e333f3bbSTrond Myklebust int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change); 131e333f3bbSTrond Myklebust int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change); 132e333f3bbSTrond Myklebust void nfsd_reset_versions(struct nfsd_net *nn); 1336777436bSStanislav Kinsbursky int nfsd_create_serv(struct net *net); 134*c21acd67SNeilBrown void nfsd_last_thread(struct net *net); 1359a74af21SBoaz Harrosh 1369a74af21SBoaz Harrosh extern int nfsd_max_blksize; 1379a74af21SBoaz Harrosh 13803a816b4SSteve Dickson static inline int nfsd_v4client(struct svc_rqst *rq) 13903a816b4SSteve Dickson { 14003a816b4SSteve Dickson return rq->rq_prog == NFS_PROGRAM && rq->rq_vers == 4; 14103a816b4SSteve Dickson } 142e45d1a18STrond Myklebust static inline struct user_namespace * 143e45d1a18STrond Myklebust nfsd_user_namespace(const struct svc_rqst *rqstp) 144e45d1a18STrond Myklebust { 145e45d1a18STrond Myklebust const struct cred *cred = rqstp->rq_xprt->xpt_cred; 146e45d1a18STrond Myklebust return cred ? cred->user_ns : &init_user_ns; 147e45d1a18STrond Myklebust } 14803a816b4SSteve Dickson 1499a74af21SBoaz Harrosh /* 1509a74af21SBoaz Harrosh * NFSv4 State 1519a74af21SBoaz Harrosh */ 1529a74af21SBoaz Harrosh #ifdef CONFIG_NFSD_V4 153697ce9beSZhang Yanfei extern unsigned long max_delegations; 15472083396SBryan Schumaker int nfsd4_init_slabs(void); 1559a74af21SBoaz Harrosh void nfsd4_free_slabs(void); 1569a74af21SBoaz Harrosh int nfs4_state_start(void); 157f252bc68SStanislav Kinsbursky int nfs4_state_start_net(struct net *net); 1589a74af21SBoaz Harrosh void nfs4_state_shutdown(void); 159f252bc68SStanislav Kinsbursky void nfs4_state_shutdown_net(struct net *net); 1609a74af21SBoaz Harrosh int nfs4_reset_recoverydir(char *recdir); 16187f26f9bSJ. Bruce Fields char * nfs4_recoverydir(void); 162ed941643SAndrew Elble bool nfsd4_spo_must_allow(struct svc_rqst *rqstp); 163d76cc46bSDai Ngo int nfsd4_create_laundry_wq(void); 164d76cc46bSDai Ngo void nfsd4_destroy_laundry_wq(void); 165c035362eSChuck Lever bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp, struct inode *inode); 1669a74af21SBoaz Harrosh #else 16772083396SBryan Schumaker static inline int nfsd4_init_slabs(void) { return 0; } 1689a74af21SBoaz Harrosh static inline void nfsd4_free_slabs(void) { } 1699a74af21SBoaz Harrosh static inline int nfs4_state_start(void) { return 0; } 170f252bc68SStanislav Kinsbursky static inline int nfs4_state_start_net(struct net *net) { return 0; } 1719a74af21SBoaz Harrosh static inline void nfs4_state_shutdown(void) { } 172f252bc68SStanislav Kinsbursky static inline void nfs4_state_shutdown_net(struct net *net) { } 1739a74af21SBoaz Harrosh static inline int nfs4_reset_recoverydir(char *recdir) { return 0; } 17487f26f9bSJ. Bruce Fields static inline char * nfs4_recoverydir(void) {return NULL; } 175ed941643SAndrew Elble static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) 176ed941643SAndrew Elble { 177ed941643SAndrew Elble return false; 178ed941643SAndrew Elble } 179d76cc46bSDai Ngo static inline int nfsd4_create_laundry_wq(void) { return 0; }; 180d76cc46bSDai Ngo static inline void nfsd4_destroy_laundry_wq(void) {}; 181c035362eSChuck Lever static inline bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp, 182c035362eSChuck Lever struct inode *inode) 183c035362eSChuck Lever { 184c035362eSChuck Lever return false; 185c035362eSChuck Lever } 1869a74af21SBoaz Harrosh #endif 1879a74af21SBoaz Harrosh 1889a74af21SBoaz Harrosh /* 1899a74af21SBoaz Harrosh * lockd binding 1909a74af21SBoaz Harrosh */ 1919a74af21SBoaz Harrosh void nfsd_lockd_init(void); 1929a74af21SBoaz Harrosh void nfsd_lockd_shutdown(void); 1939a74af21SBoaz Harrosh 1949a74af21SBoaz Harrosh 1959a74af21SBoaz Harrosh /* 1969a74af21SBoaz Harrosh * These macros provide pre-xdr'ed values for faster operation. 1979a74af21SBoaz Harrosh */ 1989a74af21SBoaz Harrosh #define nfs_ok cpu_to_be32(NFS_OK) 1999a74af21SBoaz Harrosh #define nfserr_perm cpu_to_be32(NFSERR_PERM) 2009a74af21SBoaz Harrosh #define nfserr_noent cpu_to_be32(NFSERR_NOENT) 2019a74af21SBoaz Harrosh #define nfserr_io cpu_to_be32(NFSERR_IO) 2029a74af21SBoaz Harrosh #define nfserr_nxio cpu_to_be32(NFSERR_NXIO) 2039a74af21SBoaz Harrosh #define nfserr_eagain cpu_to_be32(NFSERR_EAGAIN) 2049a74af21SBoaz Harrosh #define nfserr_acces cpu_to_be32(NFSERR_ACCES) 2059a74af21SBoaz Harrosh #define nfserr_exist cpu_to_be32(NFSERR_EXIST) 2069a74af21SBoaz Harrosh #define nfserr_xdev cpu_to_be32(NFSERR_XDEV) 2079a74af21SBoaz Harrosh #define nfserr_nodev cpu_to_be32(NFSERR_NODEV) 2089a74af21SBoaz Harrosh #define nfserr_notdir cpu_to_be32(NFSERR_NOTDIR) 2099a74af21SBoaz Harrosh #define nfserr_isdir cpu_to_be32(NFSERR_ISDIR) 2109a74af21SBoaz Harrosh #define nfserr_inval cpu_to_be32(NFSERR_INVAL) 2119a74af21SBoaz Harrosh #define nfserr_fbig cpu_to_be32(NFSERR_FBIG) 2129a74af21SBoaz Harrosh #define nfserr_nospc cpu_to_be32(NFSERR_NOSPC) 2139a74af21SBoaz Harrosh #define nfserr_rofs cpu_to_be32(NFSERR_ROFS) 2149a74af21SBoaz Harrosh #define nfserr_mlink cpu_to_be32(NFSERR_MLINK) 2159a74af21SBoaz Harrosh #define nfserr_opnotsupp cpu_to_be32(NFSERR_OPNOTSUPP) 2169a74af21SBoaz Harrosh #define nfserr_nametoolong cpu_to_be32(NFSERR_NAMETOOLONG) 2179a74af21SBoaz Harrosh #define nfserr_notempty cpu_to_be32(NFSERR_NOTEMPTY) 2189a74af21SBoaz Harrosh #define nfserr_dquot cpu_to_be32(NFSERR_DQUOT) 2199a74af21SBoaz Harrosh #define nfserr_stale cpu_to_be32(NFSERR_STALE) 2209a74af21SBoaz Harrosh #define nfserr_remote cpu_to_be32(NFSERR_REMOTE) 2219a74af21SBoaz Harrosh #define nfserr_wflush cpu_to_be32(NFSERR_WFLUSH) 2229a74af21SBoaz Harrosh #define nfserr_badhandle cpu_to_be32(NFSERR_BADHANDLE) 2239a74af21SBoaz Harrosh #define nfserr_notsync cpu_to_be32(NFSERR_NOT_SYNC) 2249a74af21SBoaz Harrosh #define nfserr_badcookie cpu_to_be32(NFSERR_BAD_COOKIE) 2259a74af21SBoaz Harrosh #define nfserr_notsupp cpu_to_be32(NFSERR_NOTSUPP) 2269a74af21SBoaz Harrosh #define nfserr_toosmall cpu_to_be32(NFSERR_TOOSMALL) 2279a74af21SBoaz Harrosh #define nfserr_serverfault cpu_to_be32(NFSERR_SERVERFAULT) 2289a74af21SBoaz Harrosh #define nfserr_badtype cpu_to_be32(NFSERR_BADTYPE) 2299a74af21SBoaz Harrosh #define nfserr_jukebox cpu_to_be32(NFSERR_JUKEBOX) 2309a74af21SBoaz Harrosh #define nfserr_denied cpu_to_be32(NFSERR_DENIED) 2319a74af21SBoaz Harrosh #define nfserr_deadlock cpu_to_be32(NFSERR_DEADLOCK) 2329a74af21SBoaz Harrosh #define nfserr_expired cpu_to_be32(NFSERR_EXPIRED) 2339a74af21SBoaz Harrosh #define nfserr_bad_cookie cpu_to_be32(NFSERR_BAD_COOKIE) 2349a74af21SBoaz Harrosh #define nfserr_same cpu_to_be32(NFSERR_SAME) 2359a74af21SBoaz Harrosh #define nfserr_clid_inuse cpu_to_be32(NFSERR_CLID_INUSE) 2369a74af21SBoaz Harrosh #define nfserr_stale_clientid cpu_to_be32(NFSERR_STALE_CLIENTID) 2379a74af21SBoaz Harrosh #define nfserr_resource cpu_to_be32(NFSERR_RESOURCE) 2389a74af21SBoaz Harrosh #define nfserr_moved cpu_to_be32(NFSERR_MOVED) 2399a74af21SBoaz Harrosh #define nfserr_nofilehandle cpu_to_be32(NFSERR_NOFILEHANDLE) 2409a74af21SBoaz Harrosh #define nfserr_minor_vers_mismatch cpu_to_be32(NFSERR_MINOR_VERS_MISMATCH) 2419a74af21SBoaz Harrosh #define nfserr_share_denied cpu_to_be32(NFSERR_SHARE_DENIED) 2429a74af21SBoaz Harrosh #define nfserr_stale_stateid cpu_to_be32(NFSERR_STALE_STATEID) 2439a74af21SBoaz Harrosh #define nfserr_old_stateid cpu_to_be32(NFSERR_OLD_STATEID) 2449a74af21SBoaz Harrosh #define nfserr_bad_stateid cpu_to_be32(NFSERR_BAD_STATEID) 2459a74af21SBoaz Harrosh #define nfserr_bad_seqid cpu_to_be32(NFSERR_BAD_SEQID) 2469a74af21SBoaz Harrosh #define nfserr_symlink cpu_to_be32(NFSERR_SYMLINK) 2479a74af21SBoaz Harrosh #define nfserr_not_same cpu_to_be32(NFSERR_NOT_SAME) 248f9d7562fSJ. Bruce Fields #define nfserr_lock_range cpu_to_be32(NFSERR_LOCK_RANGE) 2499a74af21SBoaz Harrosh #define nfserr_restorefh cpu_to_be32(NFSERR_RESTOREFH) 2509a74af21SBoaz Harrosh #define nfserr_attrnotsupp cpu_to_be32(NFSERR_ATTRNOTSUPP) 2519a74af21SBoaz Harrosh #define nfserr_bad_xdr cpu_to_be32(NFSERR_BAD_XDR) 2529a74af21SBoaz Harrosh #define nfserr_openmode cpu_to_be32(NFSERR_OPENMODE) 253f6af99ecSJ. Bruce Fields #define nfserr_badowner cpu_to_be32(NFSERR_BADOWNER) 2549a74af21SBoaz Harrosh #define nfserr_locks_held cpu_to_be32(NFSERR_LOCKS_HELD) 2559a74af21SBoaz Harrosh #define nfserr_op_illegal cpu_to_be32(NFSERR_OP_ILLEGAL) 2569a74af21SBoaz Harrosh #define nfserr_grace cpu_to_be32(NFSERR_GRACE) 2579a74af21SBoaz Harrosh #define nfserr_no_grace cpu_to_be32(NFSERR_NO_GRACE) 2589a74af21SBoaz Harrosh #define nfserr_reclaim_bad cpu_to_be32(NFSERR_RECLAIM_BAD) 2599a74af21SBoaz Harrosh #define nfserr_badname cpu_to_be32(NFSERR_BADNAME) 2609a74af21SBoaz Harrosh #define nfserr_cb_path_down cpu_to_be32(NFSERR_CB_PATH_DOWN) 2619a74af21SBoaz Harrosh #define nfserr_locked cpu_to_be32(NFSERR_LOCKED) 2629a74af21SBoaz Harrosh #define nfserr_wrongsec cpu_to_be32(NFSERR_WRONGSEC) 2639a74af21SBoaz Harrosh #define nfserr_badiomode cpu_to_be32(NFS4ERR_BADIOMODE) 2649a74af21SBoaz Harrosh #define nfserr_badlayout cpu_to_be32(NFS4ERR_BADLAYOUT) 2659a74af21SBoaz Harrosh #define nfserr_bad_session_digest cpu_to_be32(NFS4ERR_BAD_SESSION_DIGEST) 2669a74af21SBoaz Harrosh #define nfserr_badsession cpu_to_be32(NFS4ERR_BADSESSION) 2679a74af21SBoaz Harrosh #define nfserr_badslot cpu_to_be32(NFS4ERR_BADSLOT) 2689a74af21SBoaz Harrosh #define nfserr_complete_already cpu_to_be32(NFS4ERR_COMPLETE_ALREADY) 2699a74af21SBoaz Harrosh #define nfserr_conn_not_bound_to_session cpu_to_be32(NFS4ERR_CONN_NOT_BOUND_TO_SESSION) 2709a74af21SBoaz Harrosh #define nfserr_deleg_already_wanted cpu_to_be32(NFS4ERR_DELEG_ALREADY_WANTED) 2719a74af21SBoaz Harrosh #define nfserr_back_chan_busy cpu_to_be32(NFS4ERR_BACK_CHAN_BUSY) 2729a74af21SBoaz Harrosh #define nfserr_layouttrylater cpu_to_be32(NFS4ERR_LAYOUTTRYLATER) 2739a74af21SBoaz Harrosh #define nfserr_layoutunavailable cpu_to_be32(NFS4ERR_LAYOUTUNAVAILABLE) 2749a74af21SBoaz Harrosh #define nfserr_nomatching_layout cpu_to_be32(NFS4ERR_NOMATCHING_LAYOUT) 2759a74af21SBoaz Harrosh #define nfserr_recallconflict cpu_to_be32(NFS4ERR_RECALLCONFLICT) 2769a74af21SBoaz Harrosh #define nfserr_unknown_layouttype cpu_to_be32(NFS4ERR_UNKNOWN_LAYOUTTYPE) 2779a74af21SBoaz Harrosh #define nfserr_seq_misordered cpu_to_be32(NFS4ERR_SEQ_MISORDERED) 2789a74af21SBoaz Harrosh #define nfserr_sequence_pos cpu_to_be32(NFS4ERR_SEQUENCE_POS) 2799a74af21SBoaz Harrosh #define nfserr_req_too_big cpu_to_be32(NFS4ERR_REQ_TOO_BIG) 2809a74af21SBoaz Harrosh #define nfserr_rep_too_big cpu_to_be32(NFS4ERR_REP_TOO_BIG) 2819a74af21SBoaz Harrosh #define nfserr_rep_too_big_to_cache cpu_to_be32(NFS4ERR_REP_TOO_BIG_TO_CACHE) 2829a74af21SBoaz Harrosh #define nfserr_retry_uncached_rep cpu_to_be32(NFS4ERR_RETRY_UNCACHED_REP) 2839a74af21SBoaz Harrosh #define nfserr_unsafe_compound cpu_to_be32(NFS4ERR_UNSAFE_COMPOUND) 2849a74af21SBoaz Harrosh #define nfserr_too_many_ops cpu_to_be32(NFS4ERR_TOO_MANY_OPS) 2859a74af21SBoaz Harrosh #define nfserr_op_not_in_session cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION) 2869a74af21SBoaz Harrosh #define nfserr_hash_alg_unsupp cpu_to_be32(NFS4ERR_HASH_ALG_UNSUPP) 2879a74af21SBoaz Harrosh #define nfserr_clientid_busy cpu_to_be32(NFS4ERR_CLIENTID_BUSY) 2889a74af21SBoaz Harrosh #define nfserr_pnfs_io_hole cpu_to_be32(NFS4ERR_PNFS_IO_HOLE) 2899a74af21SBoaz Harrosh #define nfserr_seq_false_retry cpu_to_be32(NFS4ERR_SEQ_FALSE_RETRY) 2909a74af21SBoaz Harrosh #define nfserr_bad_high_slot cpu_to_be32(NFS4ERR_BAD_HIGH_SLOT) 2919a74af21SBoaz Harrosh #define nfserr_deadsession cpu_to_be32(NFS4ERR_DEADSESSION) 2929a74af21SBoaz Harrosh #define nfserr_encr_alg_unsupp cpu_to_be32(NFS4ERR_ENCR_ALG_UNSUPP) 2939a74af21SBoaz Harrosh #define nfserr_pnfs_no_layout cpu_to_be32(NFS4ERR_PNFS_NO_LAYOUT) 2949a74af21SBoaz Harrosh #define nfserr_not_only_op cpu_to_be32(NFS4ERR_NOT_ONLY_OP) 2959a74af21SBoaz Harrosh #define nfserr_wrong_cred cpu_to_be32(NFS4ERR_WRONG_CRED) 2969a74af21SBoaz Harrosh #define nfserr_wrong_type cpu_to_be32(NFS4ERR_WRONG_TYPE) 2979a74af21SBoaz Harrosh #define nfserr_dirdeleg_unavail cpu_to_be32(NFS4ERR_DIRDELEG_UNAVAIL) 2989a74af21SBoaz Harrosh #define nfserr_reject_deleg cpu_to_be32(NFS4ERR_REJECT_DELEG) 2999a74af21SBoaz Harrosh #define nfserr_returnconflict cpu_to_be32(NFS4ERR_RETURNCONFLICT) 3009a74af21SBoaz Harrosh #define nfserr_deleg_revoked cpu_to_be32(NFS4ERR_DELEG_REVOKED) 3014488cc96SSteve Dickson #define nfserr_partner_notsupp cpu_to_be32(NFS4ERR_PARTNER_NOTSUPP) 3024488cc96SSteve Dickson #define nfserr_partner_no_auth cpu_to_be32(NFS4ERR_PARTNER_NO_AUTH) 3032b8941b9SAnna Schumaker #define nfserr_union_notsupp cpu_to_be32(NFS4ERR_UNION_NOTSUPP) 3044488cc96SSteve Dickson #define nfserr_offload_denied cpu_to_be32(NFS4ERR_OFFLOAD_DENIED) 3054488cc96SSteve Dickson #define nfserr_wrong_lfs cpu_to_be32(NFS4ERR_WRONG_LFS) 3064488cc96SSteve Dickson #define nfserr_badlabel cpu_to_be32(NFS4ERR_BADLABEL) 307466e16f0SNeilBrown #define nfserr_file_open cpu_to_be32(NFS4ERR_FILE_OPEN) 3084dd05fceSFrank van der Linden #define nfserr_xattr2big cpu_to_be32(NFS4ERR_XATTR2BIG) 3094dd05fceSFrank van der Linden #define nfserr_noxattr cpu_to_be32(NFS4ERR_NOXATTR) 3109a74af21SBoaz Harrosh 3119a74af21SBoaz Harrosh /* error codes for internal use */ 3129a74af21SBoaz Harrosh /* if a request fails due to kmalloc failure, it gets dropped. 3139a74af21SBoaz Harrosh * Client should resend eventually 3149a74af21SBoaz Harrosh */ 3159a74af21SBoaz Harrosh #define nfserr_dropit cpu_to_be32(30000) 3169a74af21SBoaz Harrosh /* end-of-file indicator in readdir */ 3179a74af21SBoaz Harrosh #define nfserr_eof cpu_to_be32(30001) 3189a74af21SBoaz Harrosh /* replay detected */ 3199a74af21SBoaz Harrosh #define nfserr_replay_me cpu_to_be32(11001) 3209a74af21SBoaz Harrosh /* nfs41 replay detected */ 3219a74af21SBoaz Harrosh #define nfserr_replay_cache cpu_to_be32(11002) 3229a74af21SBoaz Harrosh 3239a74af21SBoaz Harrosh /* Check for dir entries '.' and '..' */ 3249a74af21SBoaz Harrosh #define isdotent(n, l) (l < 3 && n[0] == '.' && (l == 1 || n[1] == '.')) 3259a74af21SBoaz Harrosh 3269a74af21SBoaz Harrosh #ifdef CONFIG_NFSD_V4 3279a74af21SBoaz Harrosh 3289a74af21SBoaz Harrosh /* before processing a COMPOUND operation, we have to check that there 3299a74af21SBoaz Harrosh * is enough space in the buffer for XDR encode to succeed. otherwise, 3309a74af21SBoaz Harrosh * we might process an operation with side effects, and be unable to 3319a74af21SBoaz Harrosh * tell the client that the operation succeeded. 3329a74af21SBoaz Harrosh * 3339a74af21SBoaz Harrosh * COMPOUND_SLACK_SPACE - this is the minimum bytes of buffer space 3349a74af21SBoaz Harrosh * needed to encode an "ordinary" _successful_ operation. (GETATTR, 3359a74af21SBoaz Harrosh * READ, READDIR, and READLINK have their own buffer checks.) if we 3369a74af21SBoaz Harrosh * fall below this level, we fail the next operation with NFS4ERR_RESOURCE. 3379a74af21SBoaz Harrosh * 3389a74af21SBoaz Harrosh * COMPOUND_ERR_SLACK_SPACE - this is the minimum bytes of buffer space 3399a74af21SBoaz Harrosh * needed to encode an operation which has failed with NFS4ERR_RESOURCE. 3409a74af21SBoaz Harrosh * care is taken to ensure that we never fall below this level for any 3419a74af21SBoaz Harrosh * reason. 3429a74af21SBoaz Harrosh */ 3439a74af21SBoaz Harrosh #define COMPOUND_SLACK_SPACE 140 /* OP_GETFH */ 34404819bf6SJ. Bruce Fields #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */ 3459a74af21SBoaz Harrosh 346ecec6e34SJ. Bruce Fields #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */ 34766af2579SDai Ngo #define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60) /* seconds */ 3484271c2c0SDai Ngo #define NFSD_CLIENT_MAX_TRIM_PER_RUN 128 3494271c2c0SDai Ngo #define NFS4_CLIENTS_PER_GB 1024 350c035362eSChuck Lever #define NFSD_DELEGRETURN_TIMEOUT (HZ / 34) /* 30ms */ 3519a74af21SBoaz Harrosh 3529a74af21SBoaz Harrosh /* 3539a74af21SBoaz Harrosh * The following attributes are currently not supported by the NFSv4 server: 3549a74af21SBoaz Harrosh * ARCHIVE (deprecated anyway) 3559a74af21SBoaz Harrosh * HIDDEN (unlikely to be supported any time soon) 3569a74af21SBoaz Harrosh * MIMETYPE (unlikely to be supported any time soon) 3579a74af21SBoaz Harrosh * QUOTA_* (will be supported in a forthcoming patch) 3589a74af21SBoaz Harrosh * SYSTEM (unlikely to be supported any time soon) 3599a74af21SBoaz Harrosh * TIME_BACKUP (unlikely to be supported any time soon) 3609a74af21SBoaz Harrosh * TIME_CREATE (unlikely to be supported any time soon) 3619a74af21SBoaz Harrosh */ 3629a74af21SBoaz Harrosh #define NFSD4_SUPPORTED_ATTRS_WORD0 \ 3639a74af21SBoaz Harrosh (FATTR4_WORD0_SUPPORTED_ATTRS | FATTR4_WORD0_TYPE | FATTR4_WORD0_FH_EXPIRE_TYPE \ 3649a74af21SBoaz Harrosh | FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE | FATTR4_WORD0_LINK_SUPPORT \ 3659a74af21SBoaz Harrosh | FATTR4_WORD0_SYMLINK_SUPPORT | FATTR4_WORD0_NAMED_ATTR | FATTR4_WORD0_FSID \ 3669a74af21SBoaz Harrosh | FATTR4_WORD0_UNIQUE_HANDLES | FATTR4_WORD0_LEASE_TIME | FATTR4_WORD0_RDATTR_ERROR \ 3679a74af21SBoaz Harrosh | FATTR4_WORD0_ACLSUPPORT | FATTR4_WORD0_CANSETTIME | FATTR4_WORD0_CASE_INSENSITIVE \ 3689a74af21SBoaz Harrosh | FATTR4_WORD0_CASE_PRESERVING | FATTR4_WORD0_CHOWN_RESTRICTED \ 3699a74af21SBoaz Harrosh | FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FILEID | FATTR4_WORD0_FILES_AVAIL \ 3709a74af21SBoaz Harrosh | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_HOMOGENEOUS \ 3719a74af21SBoaz Harrosh | FATTR4_WORD0_MAXFILESIZE | FATTR4_WORD0_MAXLINK | FATTR4_WORD0_MAXNAME \ 3729a74af21SBoaz Harrosh | FATTR4_WORD0_MAXREAD | FATTR4_WORD0_MAXWRITE | FATTR4_WORD0_ACL) 3739a74af21SBoaz Harrosh 3749a74af21SBoaz Harrosh #define NFSD4_SUPPORTED_ATTRS_WORD1 \ 3759a74af21SBoaz Harrosh (FATTR4_WORD1_MODE | FATTR4_WORD1_NO_TRUNC | FATTR4_WORD1_NUMLINKS \ 3769a74af21SBoaz Harrosh | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP | FATTR4_WORD1_RAWDEV \ 3779a74af21SBoaz Harrosh | FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL \ 3789a74af21SBoaz Harrosh | FATTR4_WORD1_SPACE_USED | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_ACCESS_SET \ 379e377a3e6SOndrej Valousek | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA | FATTR4_WORD1_TIME_CREATE \ 3809a74af21SBoaz Harrosh | FATTR4_WORD1_TIME_MODIFY | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID) 3819a74af21SBoaz Harrosh 3829a74af21SBoaz Harrosh #define NFSD4_SUPPORTED_ATTRS_WORD2 0 3839a74af21SBoaz Harrosh 3849cf514ccSChristoph Hellwig /* 4.1 */ 3859cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS 3869cf514ccSChristoph Hellwig #define PNFSD_SUPPORTED_ATTRS_WORD1 FATTR4_WORD1_FS_LAYOUT_TYPES 3879cf514ccSChristoph Hellwig #define PNFSD_SUPPORTED_ATTRS_WORD2 \ 3889cf514ccSChristoph Hellwig (FATTR4_WORD2_LAYOUT_BLKSIZE | FATTR4_WORD2_LAYOUT_TYPES) 3899cf514ccSChristoph Hellwig #else 3909cf514ccSChristoph Hellwig #define PNFSD_SUPPORTED_ATTRS_WORD1 0 3919cf514ccSChristoph Hellwig #define PNFSD_SUPPORTED_ATTRS_WORD2 0 3929cf514ccSChristoph Hellwig #endif /* CONFIG_NFSD_PNFS */ 3939cf514ccSChristoph Hellwig 3949a74af21SBoaz Harrosh #define NFSD4_1_SUPPORTED_ATTRS_WORD0 \ 3959a74af21SBoaz Harrosh NFSD4_SUPPORTED_ATTRS_WORD0 3969a74af21SBoaz Harrosh 3979a74af21SBoaz Harrosh #define NFSD4_1_SUPPORTED_ATTRS_WORD1 \ 3989cf514ccSChristoph Hellwig (NFSD4_SUPPORTED_ATTRS_WORD1 | PNFSD_SUPPORTED_ATTRS_WORD1) 3999a74af21SBoaz Harrosh 4009a74af21SBoaz Harrosh #define NFSD4_1_SUPPORTED_ATTRS_WORD2 \ 4019cf514ccSChristoph Hellwig (NFSD4_SUPPORTED_ATTRS_WORD2 | PNFSD_SUPPORTED_ATTRS_WORD2 | \ 4029cf514ccSChristoph Hellwig FATTR4_WORD2_SUPPATTR_EXCLCREAT) 4039a74af21SBoaz Harrosh 4049cf514ccSChristoph Hellwig /* 4.2 */ 40518032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 4066d0ba043SChristoph Hellwig #define NFSD4_2_SECURITY_ATTRS FATTR4_WORD2_SECURITY_LABEL 40718032ca0SDavid Quigley #else 4086d0ba043SChristoph Hellwig #define NFSD4_2_SECURITY_ATTRS 0 40918032ca0SDavid Quigley #endif 41018032ca0SDavid Quigley 4116d0ba043SChristoph Hellwig #define NFSD4_2_SUPPORTED_ATTRS_WORD2 \ 4126d0ba043SChristoph Hellwig (NFSD4_1_SUPPORTED_ATTRS_WORD2 | \ 41347057abdSAndreas Gruenbacher FATTR4_WORD2_MODE_UMASK | \ 4144dd05fceSFrank van der Linden NFSD4_2_SECURITY_ATTRS | \ 4154dd05fceSFrank van der Linden FATTR4_WORD2_XATTR_SUPPORT) 4166d0ba043SChristoph Hellwig 4175cf23dbbSJ. Bruce Fields extern const u32 nfsd_suppattrs[3][3]; 418916d2d84SJ. Bruce Fields 41910db6512SOlga Kornievskaia static inline __be32 nfsd4_set_netaddr(struct sockaddr *addr, 420af76fc6cSOlga Kornievskaia struct nfs42_netaddr *netaddr) 421af76fc6cSOlga Kornievskaia { 422af76fc6cSOlga Kornievskaia struct sockaddr_in *sin = (struct sockaddr_in *)addr; 423af76fc6cSOlga Kornievskaia struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; 424af76fc6cSOlga Kornievskaia unsigned int port; 425af76fc6cSOlga Kornievskaia size_t ret_addr, ret_port; 426af76fc6cSOlga Kornievskaia 427af76fc6cSOlga Kornievskaia switch (addr->sa_family) { 428af76fc6cSOlga Kornievskaia case AF_INET: 429af76fc6cSOlga Kornievskaia port = ntohs(sin->sin_port); 430af76fc6cSOlga Kornievskaia sprintf(netaddr->netid, "tcp"); 431af76fc6cSOlga Kornievskaia netaddr->netid_len = 3; 432af76fc6cSOlga Kornievskaia break; 433af76fc6cSOlga Kornievskaia case AF_INET6: 434af76fc6cSOlga Kornievskaia port = ntohs(sin6->sin6_port); 435af76fc6cSOlga Kornievskaia sprintf(netaddr->netid, "tcp6"); 436af76fc6cSOlga Kornievskaia netaddr->netid_len = 4; 437af76fc6cSOlga Kornievskaia break; 438af76fc6cSOlga Kornievskaia default: 439af76fc6cSOlga Kornievskaia return nfserr_inval; 440af76fc6cSOlga Kornievskaia } 441af76fc6cSOlga Kornievskaia ret_addr = rpc_ntop(addr, netaddr->addr, sizeof(netaddr->addr)); 442af76fc6cSOlga Kornievskaia ret_port = snprintf(netaddr->addr + ret_addr, 443af76fc6cSOlga Kornievskaia RPCBIND_MAXUADDRLEN + 1 - ret_addr, 444af76fc6cSOlga Kornievskaia ".%u.%u", port >> 8, port & 0xff); 445af76fc6cSOlga Kornievskaia WARN_ON(ret_port >= RPCBIND_MAXUADDRLEN + 1 - ret_addr); 446af76fc6cSOlga Kornievskaia netaddr->addr_len = ret_addr + ret_port; 447af76fc6cSOlga Kornievskaia return 0; 448af76fc6cSOlga Kornievskaia } 449af76fc6cSOlga Kornievskaia 4505cf23dbbSJ. Bruce Fields static inline bool bmval_is_subset(const u32 *bm1, const u32 *bm2) 4519a74af21SBoaz Harrosh { 452916d2d84SJ. Bruce Fields return !((bm1[0] & ~bm2[0]) || 453916d2d84SJ. Bruce Fields (bm1[1] & ~bm2[1]) || 454916d2d84SJ. Bruce Fields (bm1[2] & ~bm2[2])); 4559a74af21SBoaz Harrosh } 4569a74af21SBoaz Harrosh 4575cf23dbbSJ. Bruce Fields static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval) 4589a74af21SBoaz Harrosh { 459916d2d84SJ. Bruce Fields return bmval_is_subset(bmval, nfsd_suppattrs[minorversion]); 4609a74af21SBoaz Harrosh } 4619a74af21SBoaz Harrosh 4629a74af21SBoaz Harrosh /* These will return ERR_INVAL if specified in GETATTR or READDIR. */ 4639a74af21SBoaz Harrosh #define NFSD_WRITEONLY_ATTRS_WORD1 \ 4649a74af21SBoaz Harrosh (FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET) 4659a74af21SBoaz Harrosh 466e864c189SJ. Bruce Fields /* 467e864c189SJ. Bruce Fields * These are the only attrs allowed in CREATE/OPEN/SETATTR. Don't add 468e864c189SJ. Bruce Fields * a writeable attribute here without also adding code to parse it to 469e864c189SJ. Bruce Fields * nfsd4_decode_fattr(). 470e864c189SJ. Bruce Fields */ 4719a74af21SBoaz Harrosh #define NFSD_WRITEABLE_ATTRS_WORD0 \ 4729a74af21SBoaz Harrosh (FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL) 4739a74af21SBoaz Harrosh #define NFSD_WRITEABLE_ATTRS_WORD1 \ 4749a74af21SBoaz Harrosh (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \ 4755b2f3e07SChuck Lever | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_CREATE \ 4765b2f3e07SChuck Lever | FATTR4_WORD1_TIME_MODIFY_SET) 47718032ca0SDavid Quigley #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 47847057abdSAndreas Gruenbacher #define MAYBE_FATTR4_WORD2_SECURITY_LABEL \ 47947057abdSAndreas Gruenbacher FATTR4_WORD2_SECURITY_LABEL 48018032ca0SDavid Quigley #else 48147057abdSAndreas Gruenbacher #define MAYBE_FATTR4_WORD2_SECURITY_LABEL 0 48218032ca0SDavid Quigley #endif 48347057abdSAndreas Gruenbacher #define NFSD_WRITEABLE_ATTRS_WORD2 \ 48447057abdSAndreas Gruenbacher (FATTR4_WORD2_MODE_UMASK \ 48547057abdSAndreas Gruenbacher | MAYBE_FATTR4_WORD2_SECURITY_LABEL) 4869a74af21SBoaz Harrosh 4879a74af21SBoaz Harrosh #define NFSD_SUPPATTR_EXCLCREAT_WORD0 \ 4889a74af21SBoaz Harrosh NFSD_WRITEABLE_ATTRS_WORD0 4899a74af21SBoaz Harrosh /* 4909a74af21SBoaz Harrosh * we currently store the exclusive create verifier in the v_{a,m}time 4919a74af21SBoaz Harrosh * attributes so the client can't set these at create time using EXCLUSIVE4_1 4929a74af21SBoaz Harrosh */ 4939a74af21SBoaz Harrosh #define NFSD_SUPPATTR_EXCLCREAT_WORD1 \ 4949a74af21SBoaz Harrosh (NFSD_WRITEABLE_ATTRS_WORD1 & \ 4959a74af21SBoaz Harrosh ~(FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)) 4969a74af21SBoaz Harrosh #define NFSD_SUPPATTR_EXCLCREAT_WORD2 \ 4979a74af21SBoaz Harrosh NFSD_WRITEABLE_ATTRS_WORD2 4989a74af21SBoaz Harrosh 49911fcee02STrond Myklebust extern int nfsd4_is_junction(struct dentry *dentry); 500797a9d79SJeff Layton extern int register_cld_notifier(void); 501797a9d79SJeff Layton extern void unregister_cld_notifier(void); 502f4e44b39SDai Ngo #ifdef CONFIG_NFSD_V4_2_INTER_SSC 503f4e44b39SDai Ngo extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn); 504f4e44b39SDai Ngo #endif 505f4e44b39SDai Ngo 506f385f7d2SDai Ngo extern void nfsd4_init_leases_net(struct nfsd_net *nn); 5076867137eSDai Ngo 508797a9d79SJeff Layton #else /* CONFIG_NFSD_V4 */ 50911fcee02STrond Myklebust static inline int nfsd4_is_junction(struct dentry *dentry) 51011fcee02STrond Myklebust { 51111fcee02STrond Myklebust return 0; 51211fcee02STrond Myklebust } 51311fcee02STrond Myklebust 514f385f7d2SDai Ngo static inline void nfsd4_init_leases_net(struct nfsd_net *nn) { }; 5156867137eSDai Ngo 516797a9d79SJeff Layton #define register_cld_notifier() 0 517797a9d79SJeff Layton #define unregister_cld_notifier() do { } while(0) 518797a9d79SJeff Layton 5199a74af21SBoaz Harrosh #endif /* CONFIG_NFSD_V4 */ 5209a74af21SBoaz Harrosh 5219a74af21SBoaz Harrosh #endif /* LINUX_NFSD_NFSD_H */ 522