linux/fs/nfsd/nfsd.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Hodge-podge collection of knfsd-related stuff.
 * I will sort this out later.
 *
 * Copyright (C) 1995-1997 Olaf Kirch <[email protected]>
 */

#ifndef LINUX_NFSD_NFSD_H
#define LINUX_NFSD_NFSD_H

#include <linux/types.h>
#include <linux/mount.h>

#include <linux/nfs.h>
#include <linux/nfs2.h>
#include <linux/nfs3.h>
#include <linux/nfs4.h>
#include <linux/sunrpc/svc.h>
#include <linux/sunrpc/svc_xprt.h>
#include <linux/sunrpc/msg_prot.h>
#include <linux/sunrpc/addr.h>

#include <uapi/linux/nfsd/debug.h>

#include "netns.h"
#include "export.h"
#include "stats.h"

#undef ifdebug
#ifdef CONFIG_SUNRPC_DEBUG
#define ifdebug(flag)
#else
#define ifdebug
#endif

/*
 * nfsd version
 */
#define NFSD_SUPPORTED_MINOR_VERSION
/*
 * Maximum blocksizes supported by daemon under various circumstances.
 */
#define NFSSVC_MAXBLKSIZE
/* NFSv2 is limited by the protocol specification, see RFC 1094 */
#define NFSSVC_MAXBLKSIZE_V2


/*
 * Largest number of bytes we need to allocate for an NFS
 * call or reply.  Used to control buffer sizes.  We use
 * the length of v3 WRITE, READDIR and READDIR replies
 * which are an RPC header, up to 26 XDR units of reply
 * data, and some page data.
 *
 * Note that accuracy here doesn't matter too much as the
 * size is rounded up to a page size when allocating space.
 */
#define NFSD_BUFSIZE

struct readdir_cd {};

/* Maximum number of operations per session compound */
#define NFSD_MAX_OPS_PER_COMPOUND

struct nfsd_genl_rqstp {};

extern struct svc_program	nfsd_program;
extern const struct svc_version	nfsd_version2, nfsd_version3, nfsd_version4;
extern struct mutex		nfsd_mutex;
extern spinlock_t		nfsd_drc_lock;
extern unsigned long		nfsd_drc_max_mem;
extern unsigned long		nfsd_drc_mem_used;
extern atomic_t			nfsd_th_cnt;		/* number of available threads */

extern const struct seq_operations nfs_exports_op;

/*
 * Common void argument and result helpers
 */
struct nfsd_voidargs {};
struct nfsd_voidres {};
bool		nfssvc_decode_voidarg(struct svc_rqst *rqstp,
				      struct xdr_stream *xdr);
bool		nfssvc_encode_voidres(struct svc_rqst *rqstp,
				      struct xdr_stream *xdr);

/*
 * Function prototypes.
 */
int		nfsd_svc(int n, int *nservers, struct net *net,
			 const struct cred *cred, const char *scope);
int		nfsd_dispatch(struct svc_rqst *rqstp);

int		nfsd_nrthreads(struct net *);
int		nfsd_nrpools(struct net *);
int		nfsd_get_nrthreads(int n, int *, struct net *);
int		nfsd_set_nrthreads(int n, int *, struct net *);
int		nfsd_pool_stats_open(struct inode *, struct file *);
int		nfsd_pool_stats_release(struct inode *, struct file *);
void		nfsd_shutdown_threads(struct net *net);

bool		i_am_nfsd(void);

struct nfsdfs_client {};

struct nfsdfs_client *get_nfsdfs_client(struct inode *);
struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
				 struct nfsdfs_client *ncl, u32 id,
				 const struct tree_descr *,
				 struct dentry **fdentries);
void nfsd_client_rmdir(struct dentry *dentry);


#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
#ifdef CONFIG_NFSD_V2_ACL
extern const struct svc_version nfsd_acl_version2;
#else
#define nfsd_acl_version2
#endif
#ifdef CONFIG_NFSD_V3_ACL
extern const struct svc_version nfsd_acl_version3;
#else
#define nfsd_acl_version3
#endif
#endif

struct nfsd_net;

enum vers_op {};
int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);
int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change);
void nfsd_reset_versions(struct nfsd_net *nn);
int nfsd_create_serv(struct net *net);
void nfsd_destroy_serv(struct net *net);

extern int nfsd_max_blksize;

static inline int nfsd_v4client(struct svc_rqst *rq)
{}
static inline struct user_namespace *
nfsd_user_namespace(const struct svc_rqst *rqstp)
{}

/* 
 * NFSv4 State
 */
#ifdef CONFIG_NFSD_V4
extern unsigned long max_delegations;
int nfsd4_init_slabs(void);
void nfsd4_free_slabs(void);
int nfs4_state_start(void);
int nfs4_state_start_net(struct net *net);
void nfs4_state_shutdown(void);
void nfs4_state_shutdown_net(struct net *net);
int nfs4_reset_recoverydir(char *recdir);
char * nfs4_recoverydir(void);
bool nfsd4_spo_must_allow(struct svc_rqst *rqstp);
int nfsd4_create_laundry_wq(void);
void nfsd4_destroy_laundry_wq(void);
bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp, struct inode *inode);
#else
static inline int nfsd4_init_slabs(void) { return 0; }
static inline void nfsd4_free_slabs(void) { }
static inline int nfs4_state_start(void) { return 0; }
static inline int nfs4_state_start_net(struct net *net) { return 0; }
static inline void nfs4_state_shutdown(void) { }
static inline void nfs4_state_shutdown_net(struct net *net) { }
static inline int nfs4_reset_recoverydir(char *recdir) { return 0; }
static inline char * nfs4_recoverydir(void) {return NULL; }
static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
{
	return false;
}
static inline int nfsd4_create_laundry_wq(void) { return 0; };
static inline void nfsd4_destroy_laundry_wq(void) {};
static inline bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp,
					      struct inode *inode)
{
	return false;
}
#endif

/*
 * lockd binding
 */
void		nfsd_lockd_init(void);
void		nfsd_lockd_shutdown(void);


/*
 * These macros provide pre-xdr'ed values for faster operation.
 */
#define nfs_ok
#define nfserr_perm
#define nfserr_noent
#define nfserr_io
#define nfserr_nxio
#define nfserr_eagain
#define nfserr_acces
#define nfserr_exist
#define nfserr_xdev
#define nfserr_nodev
#define nfserr_notdir
#define nfserr_isdir
#define nfserr_inval
#define nfserr_fbig
#define nfserr_nospc
#define nfserr_rofs
#define nfserr_mlink
#define nfserr_nametoolong
#define nfserr_notempty
#define nfserr_dquot
#define nfserr_stale
#define nfserr_remote
#define nfserr_wflush
#define nfserr_badhandle
#define nfserr_notsync
#define nfserr_badcookie
#define nfserr_notsupp
#define nfserr_toosmall
#define nfserr_serverfault
#define nfserr_badtype
#define nfserr_jukebox
#define nfserr_denied
#define nfserr_deadlock
#define nfserr_expired
#define nfserr_bad_cookie
#define nfserr_same
#define nfserr_clid_inuse
#define nfserr_stale_clientid
#define nfserr_resource
#define nfserr_moved
#define nfserr_nofilehandle
#define nfserr_minor_vers_mismatch
#define nfserr_share_denied
#define nfserr_stale_stateid
#define nfserr_old_stateid
#define nfserr_bad_stateid
#define nfserr_bad_seqid
#define nfserr_symlink
#define nfserr_not_same
#define nfserr_lock_range
#define nfserr_restorefh
#define nfserr_attrnotsupp
#define nfserr_bad_xdr
#define nfserr_openmode
#define nfserr_badowner
#define nfserr_locks_held
#define nfserr_op_illegal
#define nfserr_grace
#define nfserr_no_grace
#define nfserr_reclaim_bad
#define nfserr_badname
#define nfserr_admin_revoked
#define nfserr_cb_path_down
#define nfserr_locked
#define nfserr_wrongsec
#define nfserr_badiomode
#define nfserr_badlayout
#define nfserr_bad_session_digest
#define nfserr_badsession
#define nfserr_badslot
#define nfserr_complete_already
#define nfserr_conn_not_bound_to_session
#define nfserr_deleg_already_wanted
#define nfserr_back_chan_busy
#define nfserr_layouttrylater
#define nfserr_layoutunavailable
#define nfserr_nomatching_layout
#define nfserr_recallconflict
#define nfserr_unknown_layouttype
#define nfserr_seq_misordered
#define nfserr_sequence_pos
#define nfserr_req_too_big
#define nfserr_rep_too_big
#define nfserr_rep_too_big_to_cache
#define nfserr_retry_uncached_rep
#define nfserr_unsafe_compound
#define nfserr_too_many_ops
#define nfserr_op_not_in_session
#define nfserr_hash_alg_unsupp
#define nfserr_clientid_busy
#define nfserr_pnfs_io_hole
#define nfserr_seq_false_retry
#define nfserr_bad_high_slot
#define nfserr_deadsession
#define nfserr_encr_alg_unsupp
#define nfserr_pnfs_no_layout
#define nfserr_not_only_op
#define nfserr_wrong_cred
#define nfserr_wrong_type
#define nfserr_dirdeleg_unavail
#define nfserr_reject_deleg
#define nfserr_returnconflict
#define nfserr_deleg_revoked
#define nfserr_partner_notsupp
#define nfserr_partner_no_auth
#define nfserr_union_notsupp
#define nfserr_offload_denied
#define nfserr_wrong_lfs
#define nfserr_badlabel
#define nfserr_file_open
#define nfserr_xattr2big
#define nfserr_noxattr

/* error codes for internal use */
/* if a request fails due to kmalloc failure, it gets dropped.
 *  Client should resend eventually
 */
#define nfserr_dropit
/* end-of-file indicator in readdir */
#define nfserr_eof
/* replay detected */
#define nfserr_replay_me
/* nfs41 replay detected */
#define nfserr_replay_cache

/* Check for dir entries '.' and '..' */
#define isdotent(n, l)

#ifdef CONFIG_NFSD_V4

/* before processing a COMPOUND operation, we have to check that there
 * is enough space in the buffer for XDR encode to succeed.  otherwise,
 * we might process an operation with side effects, and be unable to
 * tell the client that the operation succeeded.
 *
 * COMPOUND_SLACK_SPACE - this is the minimum bytes of buffer space
 * needed to encode an "ordinary" _successful_ operation.  (GETATTR,
 * READ, READDIR, and READLINK have their own buffer checks.)  if we
 * fall below this level, we fail the next operation with NFS4ERR_RESOURCE.
 *
 * COMPOUND_ERR_SLACK_SPACE - this is the minimum bytes of buffer space
 * needed to encode an operation which has failed with NFS4ERR_RESOURCE.
 * care is taken to ensure that we never fall below this level for any
 * reason.
 */
#define COMPOUND_SLACK_SPACE
#define COMPOUND_ERR_SLACK_SPACE

#define NFSD_LAUNDROMAT_MINTIMEOUT
#define NFSD_COURTESY_CLIENT_TIMEOUT
#define NFSD_CLIENT_MAX_TRIM_PER_RUN
#define NFS4_CLIENTS_PER_GB
#define NFSD_DELEGRETURN_TIMEOUT
#define NFSD_CB_GETATTR_TIMEOUT

/*
 * The following attributes are currently not supported by the NFSv4 server:
 *    ARCHIVE       (deprecated anyway)
 *    HIDDEN        (unlikely to be supported any time soon)
 *    MIMETYPE      (unlikely to be supported any time soon)
 *    QUOTA_*       (will be supported in a forthcoming patch)
 *    SYSTEM        (unlikely to be supported any time soon)
 *    TIME_BACKUP   (unlikely to be supported any time soon)
 *    TIME_CREATE   (unlikely to be supported any time soon)
 */
#define NFSD4_SUPPORTED_ATTRS_WORD0

#define NFSD4_SUPPORTED_ATTRS_WORD1

#define NFSD4_SUPPORTED_ATTRS_WORD2

/* 4.1 */
#ifdef CONFIG_NFSD_PNFS
#define PNFSD_SUPPORTED_ATTRS_WORD1
#define PNFSD_SUPPORTED_ATTRS_WORD2
#else
#define PNFSD_SUPPORTED_ATTRS_WORD1
#define PNFSD_SUPPORTED_ATTRS_WORD2
#endif /* CONFIG_NFSD_PNFS */

#define NFSD4_1_SUPPORTED_ATTRS_WORD0

#define NFSD4_1_SUPPORTED_ATTRS_WORD1

#define NFSD4_1_SUPPORTED_ATTRS_WORD2

/* 4.2 */
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
#define NFSD4_2_SECURITY_ATTRS
#else
#define NFSD4_2_SECURITY_ATTRS
#endif

#define NFSD4_2_SUPPORTED_ATTRS_WORD2

extern const u32 nfsd_suppattrs[3][3];

static inline __be32 nfsd4_set_netaddr(struct sockaddr *addr,
				    struct nfs42_netaddr *netaddr)
{}

static inline bool bmval_is_subset(const u32 *bm1, const u32 *bm2)
{}

static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
{}

/* These will return ERR_INVAL if specified in GETATTR or READDIR. */
#define NFSD_WRITEONLY_ATTRS_WORD1

/*
 * These are the only attrs allowed in CREATE/OPEN/SETATTR. Don't add
 * a writeable attribute here without also adding code to parse it to
 * nfsd4_decode_fattr().
 */
#define NFSD_WRITEABLE_ATTRS_WORD0
#define NFSD_WRITEABLE_ATTRS_WORD1
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
#define MAYBE_FATTR4_WORD2_SECURITY_LABEL
#else
#define MAYBE_FATTR4_WORD2_SECURITY_LABEL
#endif
#define NFSD_WRITEABLE_ATTRS_WORD2

#define NFSD_SUPPATTR_EXCLCREAT_WORD0
/*
 * we currently store the exclusive create verifier in the v_{a,m}time
 * attributes so the client can't set these at create time using EXCLUSIVE4_1
 */
#define NFSD_SUPPATTR_EXCLCREAT_WORD1
#define NFSD_SUPPATTR_EXCLCREAT_WORD2

extern int nfsd4_is_junction(struct dentry *dentry);
extern int register_cld_notifier(void);
extern void unregister_cld_notifier(void);
#ifdef CONFIG_NFSD_V4_2_INTER_SSC
extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
#endif

extern void nfsd4_init_leases_net(struct nfsd_net *nn);

#else /* CONFIG_NFSD_V4 */
static inline int nfsd4_is_junction(struct dentry *dentry)
{
	return 0;
}

static inline void nfsd4_init_leases_net(struct nfsd_net *nn) { };

#define register_cld_notifier
#define unregister_cld_notifier

#endif /* CONFIG_NFSD_V4 */

#endif /* LINUX_NFSD_NFSD_H */