^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Hodge-podge collection of knfsd-related stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * I will sort this out later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef LINUX_NFSD_NFSD_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define LINUX_NFSD_NFSD_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/nfs2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/nfs3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/nfs4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sunrpc/svc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/sunrpc/svc_xprt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sunrpc/msg_prot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <uapi/linux/nfsd/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "export.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #undef ifdebug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #ifdef CONFIG_SUNRPC_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) # define ifdebug(flag) if (nfsd_debug & NFSDDBG_##flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) # define ifdebug(flag) if (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * nfsd version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define NFSD_SUPPORTED_MINOR_VERSION 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Maximum blocksizes supported by daemon under various circumstances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define NFSSVC_MAXBLKSIZE RPCSVC_MAXPAYLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* NFSv2 is limited by the protocol specification, see RFC 1094 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define NFSSVC_MAXBLKSIZE_V2 (8*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Largest number of bytes we need to allocate for an NFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * call or reply. Used to control buffer sizes. We use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * the length of v3 WRITE, READDIR and READDIR replies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * which are an RPC header, up to 26 XDR units of reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * data, and some page data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Note that accuracy here doesn't matter too much as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * size is rounded up to a page size when allocating space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define NFSD_BUFSIZE ((RPC_MAX_HEADER_WITH_AUTH+26)*XDR_UNIT + NFSSVC_MAXBLKSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct readdir_cd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __be32 err; /* 0, nfserr, or nfserr_eof */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) extern struct svc_program nfsd_program;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) extern const struct svc_version nfsd_version2, nfsd_version3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) nfsd_version4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) extern struct mutex nfsd_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) extern spinlock_t nfsd_drc_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) extern unsigned long nfsd_drc_max_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) extern unsigned long nfsd_drc_mem_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) extern const struct seq_operations nfs_exports_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Function prototypes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int nfsd_svc(int nrservs, struct net *net, const struct cred *cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int nfsd_nrthreads(struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int nfsd_nrpools(struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int nfsd_get_nrthreads(int n, int *, struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int nfsd_set_nrthreads(int n, int *, struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int nfsd_pool_stats_open(struct inode *, struct file *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int nfsd_pool_stats_release(struct inode *, struct file *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void nfsd_destroy(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) bool i_am_nfsd(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int get_nfsdfs(struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct nfsdfs_client {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct kref cl_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) void (*cl_release)(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct nfsdfs_client *get_nfsdfs_client(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct nfsdfs_client *ncl, u32 id, const struct tree_descr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void nfsd_client_rmdir(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #ifdef CONFIG_NFSD_V2_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) extern const struct svc_version nfsd_acl_version2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define nfsd_acl_version2 NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #ifdef CONFIG_NFSD_V3_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) extern const struct svc_version nfsd_acl_version3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define nfsd_acl_version3 NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct nfsd_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) enum vers_op {NFSD_SET, NFSD_CLEAR, NFSD_TEST, NFSD_AVAIL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) void nfsd_reset_versions(struct nfsd_net *nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int nfsd_create_serv(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) extern int nfsd_max_blksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static inline int nfsd_v4client(struct svc_rqst *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return rq->rq_prog == NFS_PROGRAM && rq->rq_vers == 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline struct user_namespace *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) nfsd_user_namespace(const struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) const struct cred *cred = rqstp->rq_xprt->xpt_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return cred ? cred->user_ns : &init_user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * NFSv4 State
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #ifdef CONFIG_NFSD_V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) extern unsigned long max_delegations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int nfsd4_init_slabs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void nfsd4_free_slabs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int nfs4_state_start(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int nfs4_state_start_net(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void nfs4_state_shutdown(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) void nfs4_state_shutdown_net(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int nfs4_reset_recoverydir(char *recdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) char * nfs4_recoverydir(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) bool nfsd4_spo_must_allow(struct svc_rqst *rqstp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static inline int nfsd4_init_slabs(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline void nfsd4_free_slabs(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline int nfs4_state_start(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static inline int nfs4_state_start_net(struct net *net) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline void nfs4_state_shutdown(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static inline void nfs4_state_shutdown_net(struct net *net) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static inline int nfs4_reset_recoverydir(char *recdir) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline char * nfs4_recoverydir(void) {return NULL; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * lockd binding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) void nfsd_lockd_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) void nfsd_lockd_shutdown(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * These macros provide pre-xdr'ed values for faster operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define nfs_ok cpu_to_be32(NFS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define nfserr_perm cpu_to_be32(NFSERR_PERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #define nfserr_noent cpu_to_be32(NFSERR_NOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #define nfserr_io cpu_to_be32(NFSERR_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define nfserr_nxio cpu_to_be32(NFSERR_NXIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define nfserr_eagain cpu_to_be32(NFSERR_EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define nfserr_acces cpu_to_be32(NFSERR_ACCES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define nfserr_exist cpu_to_be32(NFSERR_EXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define nfserr_xdev cpu_to_be32(NFSERR_XDEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define nfserr_nodev cpu_to_be32(NFSERR_NODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #define nfserr_notdir cpu_to_be32(NFSERR_NOTDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define nfserr_isdir cpu_to_be32(NFSERR_ISDIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define nfserr_inval cpu_to_be32(NFSERR_INVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define nfserr_fbig cpu_to_be32(NFSERR_FBIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define nfserr_nospc cpu_to_be32(NFSERR_NOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define nfserr_rofs cpu_to_be32(NFSERR_ROFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #define nfserr_mlink cpu_to_be32(NFSERR_MLINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define nfserr_opnotsupp cpu_to_be32(NFSERR_OPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define nfserr_nametoolong cpu_to_be32(NFSERR_NAMETOOLONG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #define nfserr_notempty cpu_to_be32(NFSERR_NOTEMPTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define nfserr_dquot cpu_to_be32(NFSERR_DQUOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define nfserr_stale cpu_to_be32(NFSERR_STALE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define nfserr_remote cpu_to_be32(NFSERR_REMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define nfserr_wflush cpu_to_be32(NFSERR_WFLUSH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define nfserr_badhandle cpu_to_be32(NFSERR_BADHANDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define nfserr_notsync cpu_to_be32(NFSERR_NOT_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define nfserr_badcookie cpu_to_be32(NFSERR_BAD_COOKIE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define nfserr_notsupp cpu_to_be32(NFSERR_NOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define nfserr_toosmall cpu_to_be32(NFSERR_TOOSMALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define nfserr_serverfault cpu_to_be32(NFSERR_SERVERFAULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #define nfserr_badtype cpu_to_be32(NFSERR_BADTYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define nfserr_jukebox cpu_to_be32(NFSERR_JUKEBOX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define nfserr_denied cpu_to_be32(NFSERR_DENIED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define nfserr_deadlock cpu_to_be32(NFSERR_DEADLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define nfserr_expired cpu_to_be32(NFSERR_EXPIRED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define nfserr_bad_cookie cpu_to_be32(NFSERR_BAD_COOKIE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define nfserr_same cpu_to_be32(NFSERR_SAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define nfserr_clid_inuse cpu_to_be32(NFSERR_CLID_INUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define nfserr_stale_clientid cpu_to_be32(NFSERR_STALE_CLIENTID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define nfserr_resource cpu_to_be32(NFSERR_RESOURCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define nfserr_moved cpu_to_be32(NFSERR_MOVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define nfserr_nofilehandle cpu_to_be32(NFSERR_NOFILEHANDLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define nfserr_minor_vers_mismatch cpu_to_be32(NFSERR_MINOR_VERS_MISMATCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define nfserr_share_denied cpu_to_be32(NFSERR_SHARE_DENIED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define nfserr_stale_stateid cpu_to_be32(NFSERR_STALE_STATEID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #define nfserr_old_stateid cpu_to_be32(NFSERR_OLD_STATEID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define nfserr_bad_stateid cpu_to_be32(NFSERR_BAD_STATEID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define nfserr_bad_seqid cpu_to_be32(NFSERR_BAD_SEQID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define nfserr_symlink cpu_to_be32(NFSERR_SYMLINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define nfserr_not_same cpu_to_be32(NFSERR_NOT_SAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #define nfserr_lock_range cpu_to_be32(NFSERR_LOCK_RANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #define nfserr_restorefh cpu_to_be32(NFSERR_RESTOREFH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define nfserr_attrnotsupp cpu_to_be32(NFSERR_ATTRNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #define nfserr_bad_xdr cpu_to_be32(NFSERR_BAD_XDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define nfserr_openmode cpu_to_be32(NFSERR_OPENMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define nfserr_badowner cpu_to_be32(NFSERR_BADOWNER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define nfserr_locks_held cpu_to_be32(NFSERR_LOCKS_HELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #define nfserr_op_illegal cpu_to_be32(NFSERR_OP_ILLEGAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define nfserr_grace cpu_to_be32(NFSERR_GRACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define nfserr_no_grace cpu_to_be32(NFSERR_NO_GRACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define nfserr_reclaim_bad cpu_to_be32(NFSERR_RECLAIM_BAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define nfserr_badname cpu_to_be32(NFSERR_BADNAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define nfserr_cb_path_down cpu_to_be32(NFSERR_CB_PATH_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define nfserr_locked cpu_to_be32(NFSERR_LOCKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define nfserr_wrongsec cpu_to_be32(NFSERR_WRONGSEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define nfserr_badiomode cpu_to_be32(NFS4ERR_BADIOMODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define nfserr_badlayout cpu_to_be32(NFS4ERR_BADLAYOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define nfserr_bad_session_digest cpu_to_be32(NFS4ERR_BAD_SESSION_DIGEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define nfserr_badsession cpu_to_be32(NFS4ERR_BADSESSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #define nfserr_badslot cpu_to_be32(NFS4ERR_BADSLOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define nfserr_complete_already cpu_to_be32(NFS4ERR_COMPLETE_ALREADY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define nfserr_conn_not_bound_to_session cpu_to_be32(NFS4ERR_CONN_NOT_BOUND_TO_SESSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define nfserr_deleg_already_wanted cpu_to_be32(NFS4ERR_DELEG_ALREADY_WANTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define nfserr_back_chan_busy cpu_to_be32(NFS4ERR_BACK_CHAN_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define nfserr_layouttrylater cpu_to_be32(NFS4ERR_LAYOUTTRYLATER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #define nfserr_layoutunavailable cpu_to_be32(NFS4ERR_LAYOUTUNAVAILABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #define nfserr_nomatching_layout cpu_to_be32(NFS4ERR_NOMATCHING_LAYOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define nfserr_recallconflict cpu_to_be32(NFS4ERR_RECALLCONFLICT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #define nfserr_unknown_layouttype cpu_to_be32(NFS4ERR_UNKNOWN_LAYOUTTYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define nfserr_seq_misordered cpu_to_be32(NFS4ERR_SEQ_MISORDERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #define nfserr_sequence_pos cpu_to_be32(NFS4ERR_SEQUENCE_POS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #define nfserr_req_too_big cpu_to_be32(NFS4ERR_REQ_TOO_BIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #define nfserr_rep_too_big cpu_to_be32(NFS4ERR_REP_TOO_BIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #define nfserr_rep_too_big_to_cache cpu_to_be32(NFS4ERR_REP_TOO_BIG_TO_CACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #define nfserr_retry_uncached_rep cpu_to_be32(NFS4ERR_RETRY_UNCACHED_REP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define nfserr_unsafe_compound cpu_to_be32(NFS4ERR_UNSAFE_COMPOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #define nfserr_too_many_ops cpu_to_be32(NFS4ERR_TOO_MANY_OPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #define nfserr_op_not_in_session cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define nfserr_hash_alg_unsupp cpu_to_be32(NFS4ERR_HASH_ALG_UNSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #define nfserr_clientid_busy cpu_to_be32(NFS4ERR_CLIENTID_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #define nfserr_pnfs_io_hole cpu_to_be32(NFS4ERR_PNFS_IO_HOLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define nfserr_seq_false_retry cpu_to_be32(NFS4ERR_SEQ_FALSE_RETRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #define nfserr_bad_high_slot cpu_to_be32(NFS4ERR_BAD_HIGH_SLOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #define nfserr_deadsession cpu_to_be32(NFS4ERR_DEADSESSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #define nfserr_encr_alg_unsupp cpu_to_be32(NFS4ERR_ENCR_ALG_UNSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #define nfserr_pnfs_no_layout cpu_to_be32(NFS4ERR_PNFS_NO_LAYOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define nfserr_not_only_op cpu_to_be32(NFS4ERR_NOT_ONLY_OP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define nfserr_wrong_cred cpu_to_be32(NFS4ERR_WRONG_CRED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #define nfserr_wrong_type cpu_to_be32(NFS4ERR_WRONG_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #define nfserr_dirdeleg_unavail cpu_to_be32(NFS4ERR_DIRDELEG_UNAVAIL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define nfserr_reject_deleg cpu_to_be32(NFS4ERR_REJECT_DELEG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define nfserr_returnconflict cpu_to_be32(NFS4ERR_RETURNCONFLICT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #define nfserr_deleg_revoked cpu_to_be32(NFS4ERR_DELEG_REVOKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define nfserr_partner_notsupp cpu_to_be32(NFS4ERR_PARTNER_NOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define nfserr_partner_no_auth cpu_to_be32(NFS4ERR_PARTNER_NO_AUTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #define nfserr_union_notsupp cpu_to_be32(NFS4ERR_UNION_NOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #define nfserr_offload_denied cpu_to_be32(NFS4ERR_OFFLOAD_DENIED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define nfserr_wrong_lfs cpu_to_be32(NFS4ERR_WRONG_LFS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define nfserr_badlabel cpu_to_be32(NFS4ERR_BADLABEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define nfserr_file_open cpu_to_be32(NFS4ERR_FILE_OPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define nfserr_xattr2big cpu_to_be32(NFS4ERR_XATTR2BIG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define nfserr_noxattr cpu_to_be32(NFS4ERR_NOXATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* error codes for internal use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* if a request fails due to kmalloc failure, it gets dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * Client should resend eventually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #define nfserr_dropit cpu_to_be32(30000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /* end-of-file indicator in readdir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #define nfserr_eof cpu_to_be32(30001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* replay detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #define nfserr_replay_me cpu_to_be32(11001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* nfs41 replay detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #define nfserr_replay_cache cpu_to_be32(11002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* Check for dir entries '.' and '..' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #define isdotent(n, l) (l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) #ifdef CONFIG_NFSD_V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* before processing a COMPOUND operation, we have to check that there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * is enough space in the buffer for XDR encode to succeed. otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * we might process an operation with side effects, and be unable to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * tell the client that the operation succeeded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * COMPOUND_SLACK_SPACE - this is the minimum bytes of buffer space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * needed to encode an "ordinary" _successful_ operation. (GETATTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * READ, READDIR, and READLINK have their own buffer checks.) if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * fall below this level, we fail the next operation with NFS4ERR_RESOURCE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * COMPOUND_ERR_SLACK_SPACE - this is the minimum bytes of buffer space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * needed to encode an operation which has failed with NFS4ERR_RESOURCE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * care is taken to ensure that we never fall below this level for any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * reason.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #define COMPOUND_SLACK_SPACE 140 /* OP_GETFH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define COMPOUND_ERR_SLACK_SPACE 16 /* OP_SETATTR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #define NFSD_LAUNDROMAT_MINTIMEOUT 1 /* seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * The following attributes are currently not supported by the NFSv4 server:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * ARCHIVE (deprecated anyway)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * HIDDEN (unlikely to be supported any time soon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * MIMETYPE (unlikely to be supported any time soon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * QUOTA_* (will be supported in a forthcoming patch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * SYSTEM (unlikely to be supported any time soon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * TIME_BACKUP (unlikely to be supported any time soon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * TIME_CREATE (unlikely to be supported any time soon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #define NFSD4_SUPPORTED_ATTRS_WORD0 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) (FATTR4_WORD0_SUPPORTED_ATTRS | FATTR4_WORD0_TYPE | FATTR4_WORD0_FH_EXPIRE_TYPE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) | FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE | FATTR4_WORD0_LINK_SUPPORT \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) | FATTR4_WORD0_SYMLINK_SUPPORT | FATTR4_WORD0_NAMED_ATTR | FATTR4_WORD0_FSID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) | FATTR4_WORD0_UNIQUE_HANDLES | FATTR4_WORD0_LEASE_TIME | FATTR4_WORD0_RDATTR_ERROR \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) | FATTR4_WORD0_ACLSUPPORT | FATTR4_WORD0_CANSETTIME | FATTR4_WORD0_CASE_INSENSITIVE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) | FATTR4_WORD0_CASE_PRESERVING | FATTR4_WORD0_CHOWN_RESTRICTED \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) | FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FILEID | FATTR4_WORD0_FILES_AVAIL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_HOMOGENEOUS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) | FATTR4_WORD0_MAXFILESIZE | FATTR4_WORD0_MAXLINK | FATTR4_WORD0_MAXNAME \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) | FATTR4_WORD0_MAXREAD | FATTR4_WORD0_MAXWRITE | FATTR4_WORD0_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #define NFSD4_SUPPORTED_ATTRS_WORD1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) (FATTR4_WORD1_MODE | FATTR4_WORD1_NO_TRUNC | FATTR4_WORD1_NUMLINKS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP | FATTR4_WORD1_RAWDEV \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) | FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) | FATTR4_WORD1_SPACE_USED | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_ACCESS_SET \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) | FATTR4_WORD1_TIME_MODIFY | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #define NFSD4_SUPPORTED_ATTRS_WORD2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* 4.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #ifdef CONFIG_NFSD_PNFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) #define PNFSD_SUPPORTED_ATTRS_WORD1 FATTR4_WORD1_FS_LAYOUT_TYPES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #define PNFSD_SUPPORTED_ATTRS_WORD2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) (FATTR4_WORD2_LAYOUT_BLKSIZE | FATTR4_WORD2_LAYOUT_TYPES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) #define PNFSD_SUPPORTED_ATTRS_WORD1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #define PNFSD_SUPPORTED_ATTRS_WORD2 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #endif /* CONFIG_NFSD_PNFS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #define NFSD4_1_SUPPORTED_ATTRS_WORD0 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) NFSD4_SUPPORTED_ATTRS_WORD0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #define NFSD4_1_SUPPORTED_ATTRS_WORD1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) (NFSD4_SUPPORTED_ATTRS_WORD1 | PNFSD_SUPPORTED_ATTRS_WORD1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #define NFSD4_1_SUPPORTED_ATTRS_WORD2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) (NFSD4_SUPPORTED_ATTRS_WORD2 | PNFSD_SUPPORTED_ATTRS_WORD2 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) FATTR4_WORD2_SUPPATTR_EXCLCREAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* 4.2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #define NFSD4_2_SECURITY_ATTRS FATTR4_WORD2_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #define NFSD4_2_SECURITY_ATTRS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #define NFSD4_2_SUPPORTED_ATTRS_WORD2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) (NFSD4_1_SUPPORTED_ATTRS_WORD2 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) FATTR4_WORD2_CHANGE_ATTR_TYPE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) FATTR4_WORD2_MODE_UMASK | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) NFSD4_2_SECURITY_ATTRS | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) FATTR4_WORD2_XATTR_SUPPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) extern const u32 nfsd_suppattrs[3][3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static inline __be32 nfsd4_set_netaddr(struct sockaddr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct nfs42_netaddr *netaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct sockaddr_in *sin = (struct sockaddr_in *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) unsigned int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) size_t ret_addr, ret_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) switch (addr->sa_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) port = ntohs(sin->sin_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) sprintf(netaddr->netid, "tcp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) netaddr->netid_len = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) port = ntohs(sin6->sin6_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) sprintf(netaddr->netid, "tcp6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) netaddr->netid_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return nfserr_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ret_addr = rpc_ntop(addr, netaddr->addr, sizeof(netaddr->addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ret_port = snprintf(netaddr->addr + ret_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) RPCBIND_MAXUADDRLEN + 1 - ret_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ".%u.%u", port >> 8, port & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) WARN_ON(ret_port >= RPCBIND_MAXUADDRLEN + 1 - ret_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) netaddr->addr_len = ret_addr + ret_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static inline bool bmval_is_subset(const u32 *bm1, const u32 *bm2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return !((bm1[0] & ~bm2[0]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) (bm1[1] & ~bm2[1]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) (bm1[2] & ~bm2[2]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return bmval_is_subset(bmval, nfsd_suppattrs[minorversion]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* These will return ERR_INVAL if specified in GETATTR or READDIR. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #define NFSD_WRITEONLY_ATTRS_WORD1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) (FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * These are the only attrs allowed in CREATE/OPEN/SETATTR. Don't add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * a writeable attribute here without also adding code to parse it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * nfsd4_decode_fattr().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #define NFSD_WRITEABLE_ATTRS_WORD0 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) (FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) #define NFSD_WRITEABLE_ATTRS_WORD1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #define MAYBE_FATTR4_WORD2_SECURITY_LABEL \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) FATTR4_WORD2_SECURITY_LABEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) #define MAYBE_FATTR4_WORD2_SECURITY_LABEL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) #define NFSD_WRITEABLE_ATTRS_WORD2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) (FATTR4_WORD2_MODE_UMASK \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) | MAYBE_FATTR4_WORD2_SECURITY_LABEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #define NFSD_SUPPATTR_EXCLCREAT_WORD0 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) NFSD_WRITEABLE_ATTRS_WORD0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * we currently store the exclusive create verifier in the v_{a,m}time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * attributes so the client can't set these at create time using EXCLUSIVE4_1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #define NFSD_SUPPATTR_EXCLCREAT_WORD1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) (NFSD_WRITEABLE_ATTRS_WORD1 & \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) ~(FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) #define NFSD_SUPPATTR_EXCLCREAT_WORD2 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) NFSD_WRITEABLE_ATTRS_WORD2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) extern int nfsd4_is_junction(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) extern int register_cld_notifier(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) extern void unregister_cld_notifier(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) #else /* CONFIG_NFSD_V4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static inline int nfsd4_is_junction(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) #define register_cld_notifier() 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) #define unregister_cld_notifier() do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) #endif /* CONFIG_NFSD_V4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) #endif /* LINUX_NFSD_NFSD_H */