Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Hodge-podge collection of knfsd-related stuff.
0004  * I will sort this out later.
0005  *
0006  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
0007  */
0008 
0009 #ifndef LINUX_NFSD_NFSD_H
0010 #define LINUX_NFSD_NFSD_H
0011 
0012 #include <linux/types.h>
0013 #include <linux/mount.h>
0014 
0015 #include <linux/nfs.h>
0016 #include <linux/nfs2.h>
0017 #include <linux/nfs3.h>
0018 #include <linux/nfs4.h>
0019 #include <linux/sunrpc/svc.h>
0020 #include <linux/sunrpc/svc_xprt.h>
0021 #include <linux/sunrpc/msg_prot.h>
0022 #include <linux/sunrpc/addr.h>
0023 
0024 #include <uapi/linux/nfsd/debug.h>
0025 
0026 #include "netns.h"
0027 #include "export.h"
0028 #include "stats.h"
0029 
0030 #undef ifdebug
0031 #ifdef CONFIG_SUNRPC_DEBUG
0032 # define ifdebug(flag)      if (nfsd_debug & NFSDDBG_##flag)
0033 #else
0034 # define ifdebug(flag)      if (0)
0035 #endif
0036 
0037 /*
0038  * nfsd version
0039  */
0040 #define NFSD_SUPPORTED_MINOR_VERSION    2
0041 /*
0042  * Maximum blocksizes supported by daemon under various circumstances.
0043  */
0044 #define NFSSVC_MAXBLKSIZE       RPCSVC_MAXPAYLOAD
0045 /* NFSv2 is limited by the protocol specification, see RFC 1094 */
0046 #define NFSSVC_MAXBLKSIZE_V2    (8*1024)
0047 
0048 
0049 /*
0050  * Largest number of bytes we need to allocate for an NFS
0051  * call or reply.  Used to control buffer sizes.  We use
0052  * the length of v3 WRITE, READDIR and READDIR replies
0053  * which are an RPC header, up to 26 XDR units of reply
0054  * data, and some page data.
0055  *
0056  * Note that accuracy here doesn't matter too much as the
0057  * size is rounded up to a page size when allocating space.
0058  */
0059 #define NFSD_BUFSIZE            ((RPC_MAX_HEADER_WITH_AUTH+26)*XDR_UNIT + NFSSVC_MAXBLKSIZE)
0060 
0061 struct readdir_cd {
0062     __be32          err;    /* 0, nfserr, or nfserr_eof */
0063 };
0064 
0065 
0066 extern struct svc_program   nfsd_program;
0067 extern const struct svc_version nfsd_version2, nfsd_version3,
0068                 nfsd_version4;
0069 extern struct mutex     nfsd_mutex;
0070 extern spinlock_t       nfsd_drc_lock;
0071 extern unsigned long        nfsd_drc_max_mem;
0072 extern unsigned long        nfsd_drc_mem_used;
0073 
0074 extern const struct seq_operations nfs_exports_op;
0075 
0076 /*
0077  * Common void argument and result helpers
0078  */
0079 struct nfsd_voidargs { };
0080 struct nfsd_voidres { };
0081 bool        nfssvc_decode_voidarg(struct svc_rqst *rqstp,
0082                       struct xdr_stream *xdr);
0083 bool        nfssvc_encode_voidres(struct svc_rqst *rqstp,
0084                       struct xdr_stream *xdr);
0085 
0086 /*
0087  * Function prototypes.
0088  */
0089 int     nfsd_svc(int nrservs, struct net *net, const struct cred *cred);
0090 int     nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp);
0091 
0092 int     nfsd_nrthreads(struct net *);
0093 int     nfsd_nrpools(struct net *);
0094 int     nfsd_get_nrthreads(int n, int *, struct net *);
0095 int     nfsd_set_nrthreads(int n, int *, struct net *);
0096 int     nfsd_pool_stats_open(struct inode *, struct file *);
0097 int     nfsd_pool_stats_release(struct inode *, struct file *);
0098 void        nfsd_shutdown_threads(struct net *net);
0099 
0100 void        nfsd_put(struct net *net);
0101 
0102 bool        i_am_nfsd(void);
0103 
0104 struct nfsdfs_client {
0105     struct kref cl_ref;
0106     void (*cl_release)(struct kref *kref);
0107 };
0108 
0109 struct nfsdfs_client *get_nfsdfs_client(struct inode *);
0110 struct dentry *nfsd_client_mkdir(struct nfsd_net *nn,
0111                  struct nfsdfs_client *ncl, u32 id,
0112                  const struct tree_descr *,
0113                  struct dentry **fdentries);
0114 void nfsd_client_rmdir(struct dentry *dentry);
0115 
0116 
0117 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
0118 #ifdef CONFIG_NFSD_V2_ACL
0119 extern const struct svc_version nfsd_acl_version2;
0120 #else
0121 #define nfsd_acl_version2 NULL
0122 #endif
0123 #ifdef CONFIG_NFSD_V3_ACL
0124 extern const struct svc_version nfsd_acl_version3;
0125 #else
0126 #define nfsd_acl_version3 NULL
0127 #endif
0128 #endif
0129 
0130 struct nfsd_net;
0131 
0132 enum vers_op {NFSD_SET, NFSD_CLEAR, NFSD_TEST, NFSD_AVAIL };
0133 int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);
0134 int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change);
0135 void nfsd_reset_versions(struct nfsd_net *nn);
0136 int nfsd_create_serv(struct net *net);
0137 
0138 extern int nfsd_max_blksize;
0139 
0140 static inline int nfsd_v4client(struct svc_rqst *rq)
0141 {
0142     return rq->rq_prog == NFS_PROGRAM && rq->rq_vers == 4;
0143 }
0144 static inline struct user_namespace *
0145 nfsd_user_namespace(const struct svc_rqst *rqstp)
0146 {
0147     const struct cred *cred = rqstp->rq_xprt->xpt_cred;
0148     return cred ? cred->user_ns : &init_user_ns;
0149 }
0150 
0151 /* 
0152  * NFSv4 State
0153  */
0154 #ifdef CONFIG_NFSD_V4
0155 extern unsigned long max_delegations;
0156 int nfsd4_init_slabs(void);
0157 void nfsd4_free_slabs(void);
0158 int nfs4_state_start(void);
0159 int nfs4_state_start_net(struct net *net);
0160 void nfs4_state_shutdown(void);
0161 void nfs4_state_shutdown_net(struct net *net);
0162 int nfs4_reset_recoverydir(char *recdir);
0163 char * nfs4_recoverydir(void);
0164 bool nfsd4_spo_must_allow(struct svc_rqst *rqstp);
0165 int nfsd4_create_laundry_wq(void);
0166 void nfsd4_destroy_laundry_wq(void);
0167 #else
0168 static inline int nfsd4_init_slabs(void) { return 0; }
0169 static inline void nfsd4_free_slabs(void) { }
0170 static inline int nfs4_state_start(void) { return 0; }
0171 static inline int nfs4_state_start_net(struct net *net) { return 0; }
0172 static inline void nfs4_state_shutdown(void) { }
0173 static inline void nfs4_state_shutdown_net(struct net *net) { }
0174 static inline int nfs4_reset_recoverydir(char *recdir) { return 0; }
0175 static inline char * nfs4_recoverydir(void) {return NULL; }
0176 static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
0177 {
0178     return false;
0179 }
0180 static inline int nfsd4_create_laundry_wq(void) { return 0; };
0181 static inline void nfsd4_destroy_laundry_wq(void) {};
0182 #endif
0183 
0184 /*
0185  * lockd binding
0186  */
0187 void        nfsd_lockd_init(void);
0188 void        nfsd_lockd_shutdown(void);
0189 
0190 
0191 /*
0192  * These macros provide pre-xdr'ed values for faster operation.
0193  */
0194 #define nfs_ok          cpu_to_be32(NFS_OK)
0195 #define nfserr_perm     cpu_to_be32(NFSERR_PERM)
0196 #define nfserr_noent        cpu_to_be32(NFSERR_NOENT)
0197 #define nfserr_io       cpu_to_be32(NFSERR_IO)
0198 #define nfserr_nxio     cpu_to_be32(NFSERR_NXIO)
0199 #define nfserr_eagain       cpu_to_be32(NFSERR_EAGAIN)
0200 #define nfserr_acces        cpu_to_be32(NFSERR_ACCES)
0201 #define nfserr_exist        cpu_to_be32(NFSERR_EXIST)
0202 #define nfserr_xdev     cpu_to_be32(NFSERR_XDEV)
0203 #define nfserr_nodev        cpu_to_be32(NFSERR_NODEV)
0204 #define nfserr_notdir       cpu_to_be32(NFSERR_NOTDIR)
0205 #define nfserr_isdir        cpu_to_be32(NFSERR_ISDIR)
0206 #define nfserr_inval        cpu_to_be32(NFSERR_INVAL)
0207 #define nfserr_fbig     cpu_to_be32(NFSERR_FBIG)
0208 #define nfserr_nospc        cpu_to_be32(NFSERR_NOSPC)
0209 #define nfserr_rofs     cpu_to_be32(NFSERR_ROFS)
0210 #define nfserr_mlink        cpu_to_be32(NFSERR_MLINK)
0211 #define nfserr_opnotsupp    cpu_to_be32(NFSERR_OPNOTSUPP)
0212 #define nfserr_nametoolong  cpu_to_be32(NFSERR_NAMETOOLONG)
0213 #define nfserr_notempty     cpu_to_be32(NFSERR_NOTEMPTY)
0214 #define nfserr_dquot        cpu_to_be32(NFSERR_DQUOT)
0215 #define nfserr_stale        cpu_to_be32(NFSERR_STALE)
0216 #define nfserr_remote       cpu_to_be32(NFSERR_REMOTE)
0217 #define nfserr_wflush       cpu_to_be32(NFSERR_WFLUSH)
0218 #define nfserr_badhandle    cpu_to_be32(NFSERR_BADHANDLE)
0219 #define nfserr_notsync      cpu_to_be32(NFSERR_NOT_SYNC)
0220 #define nfserr_badcookie    cpu_to_be32(NFSERR_BAD_COOKIE)
0221 #define nfserr_notsupp      cpu_to_be32(NFSERR_NOTSUPP)
0222 #define nfserr_toosmall     cpu_to_be32(NFSERR_TOOSMALL)
0223 #define nfserr_serverfault  cpu_to_be32(NFSERR_SERVERFAULT)
0224 #define nfserr_badtype      cpu_to_be32(NFSERR_BADTYPE)
0225 #define nfserr_jukebox      cpu_to_be32(NFSERR_JUKEBOX)
0226 #define nfserr_denied       cpu_to_be32(NFSERR_DENIED)
0227 #define nfserr_deadlock     cpu_to_be32(NFSERR_DEADLOCK)
0228 #define nfserr_expired          cpu_to_be32(NFSERR_EXPIRED)
0229 #define nfserr_bad_cookie   cpu_to_be32(NFSERR_BAD_COOKIE)
0230 #define nfserr_same     cpu_to_be32(NFSERR_SAME)
0231 #define nfserr_clid_inuse   cpu_to_be32(NFSERR_CLID_INUSE)
0232 #define nfserr_stale_clientid   cpu_to_be32(NFSERR_STALE_CLIENTID)
0233 #define nfserr_resource     cpu_to_be32(NFSERR_RESOURCE)
0234 #define nfserr_moved        cpu_to_be32(NFSERR_MOVED)
0235 #define nfserr_nofilehandle cpu_to_be32(NFSERR_NOFILEHANDLE)
0236 #define nfserr_minor_vers_mismatch  cpu_to_be32(NFSERR_MINOR_VERS_MISMATCH)
0237 #define nfserr_share_denied cpu_to_be32(NFSERR_SHARE_DENIED)
0238 #define nfserr_stale_stateid    cpu_to_be32(NFSERR_STALE_STATEID)
0239 #define nfserr_old_stateid  cpu_to_be32(NFSERR_OLD_STATEID)
0240 #define nfserr_bad_stateid  cpu_to_be32(NFSERR_BAD_STATEID)
0241 #define nfserr_bad_seqid    cpu_to_be32(NFSERR_BAD_SEQID)
0242 #define nfserr_symlink      cpu_to_be32(NFSERR_SYMLINK)
0243 #define nfserr_not_same     cpu_to_be32(NFSERR_NOT_SAME)
0244 #define nfserr_lock_range   cpu_to_be32(NFSERR_LOCK_RANGE)
0245 #define nfserr_restorefh    cpu_to_be32(NFSERR_RESTOREFH)
0246 #define nfserr_attrnotsupp  cpu_to_be32(NFSERR_ATTRNOTSUPP)
0247 #define nfserr_bad_xdr      cpu_to_be32(NFSERR_BAD_XDR)
0248 #define nfserr_openmode     cpu_to_be32(NFSERR_OPENMODE)
0249 #define nfserr_badowner     cpu_to_be32(NFSERR_BADOWNER)
0250 #define nfserr_locks_held   cpu_to_be32(NFSERR_LOCKS_HELD)
0251 #define nfserr_op_illegal   cpu_to_be32(NFSERR_OP_ILLEGAL)
0252 #define nfserr_grace        cpu_to_be32(NFSERR_GRACE)
0253 #define nfserr_no_grace     cpu_to_be32(NFSERR_NO_GRACE)
0254 #define nfserr_reclaim_bad  cpu_to_be32(NFSERR_RECLAIM_BAD)
0255 #define nfserr_badname      cpu_to_be32(NFSERR_BADNAME)
0256 #define nfserr_cb_path_down cpu_to_be32(NFSERR_CB_PATH_DOWN)
0257 #define nfserr_locked       cpu_to_be32(NFSERR_LOCKED)
0258 #define nfserr_wrongsec     cpu_to_be32(NFSERR_WRONGSEC)
0259 #define nfserr_badiomode        cpu_to_be32(NFS4ERR_BADIOMODE)
0260 #define nfserr_badlayout        cpu_to_be32(NFS4ERR_BADLAYOUT)
0261 #define nfserr_bad_session_digest   cpu_to_be32(NFS4ERR_BAD_SESSION_DIGEST)
0262 #define nfserr_badsession       cpu_to_be32(NFS4ERR_BADSESSION)
0263 #define nfserr_badslot          cpu_to_be32(NFS4ERR_BADSLOT)
0264 #define nfserr_complete_already     cpu_to_be32(NFS4ERR_COMPLETE_ALREADY)
0265 #define nfserr_conn_not_bound_to_session cpu_to_be32(NFS4ERR_CONN_NOT_BOUND_TO_SESSION)
0266 #define nfserr_deleg_already_wanted cpu_to_be32(NFS4ERR_DELEG_ALREADY_WANTED)
0267 #define nfserr_back_chan_busy       cpu_to_be32(NFS4ERR_BACK_CHAN_BUSY)
0268 #define nfserr_layouttrylater       cpu_to_be32(NFS4ERR_LAYOUTTRYLATER)
0269 #define nfserr_layoutunavailable    cpu_to_be32(NFS4ERR_LAYOUTUNAVAILABLE)
0270 #define nfserr_nomatching_layout    cpu_to_be32(NFS4ERR_NOMATCHING_LAYOUT)
0271 #define nfserr_recallconflict       cpu_to_be32(NFS4ERR_RECALLCONFLICT)
0272 #define nfserr_unknown_layouttype   cpu_to_be32(NFS4ERR_UNKNOWN_LAYOUTTYPE)
0273 #define nfserr_seq_misordered       cpu_to_be32(NFS4ERR_SEQ_MISORDERED)
0274 #define nfserr_sequence_pos     cpu_to_be32(NFS4ERR_SEQUENCE_POS)
0275 #define nfserr_req_too_big      cpu_to_be32(NFS4ERR_REQ_TOO_BIG)
0276 #define nfserr_rep_too_big      cpu_to_be32(NFS4ERR_REP_TOO_BIG)
0277 #define nfserr_rep_too_big_to_cache cpu_to_be32(NFS4ERR_REP_TOO_BIG_TO_CACHE)
0278 #define nfserr_retry_uncached_rep   cpu_to_be32(NFS4ERR_RETRY_UNCACHED_REP)
0279 #define nfserr_unsafe_compound      cpu_to_be32(NFS4ERR_UNSAFE_COMPOUND)
0280 #define nfserr_too_many_ops     cpu_to_be32(NFS4ERR_TOO_MANY_OPS)
0281 #define nfserr_op_not_in_session    cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION)
0282 #define nfserr_hash_alg_unsupp      cpu_to_be32(NFS4ERR_HASH_ALG_UNSUPP)
0283 #define nfserr_clientid_busy        cpu_to_be32(NFS4ERR_CLIENTID_BUSY)
0284 #define nfserr_pnfs_io_hole     cpu_to_be32(NFS4ERR_PNFS_IO_HOLE)
0285 #define nfserr_seq_false_retry      cpu_to_be32(NFS4ERR_SEQ_FALSE_RETRY)
0286 #define nfserr_bad_high_slot        cpu_to_be32(NFS4ERR_BAD_HIGH_SLOT)
0287 #define nfserr_deadsession      cpu_to_be32(NFS4ERR_DEADSESSION)
0288 #define nfserr_encr_alg_unsupp      cpu_to_be32(NFS4ERR_ENCR_ALG_UNSUPP)
0289 #define nfserr_pnfs_no_layout       cpu_to_be32(NFS4ERR_PNFS_NO_LAYOUT)
0290 #define nfserr_not_only_op      cpu_to_be32(NFS4ERR_NOT_ONLY_OP)
0291 #define nfserr_wrong_cred       cpu_to_be32(NFS4ERR_WRONG_CRED)
0292 #define nfserr_wrong_type       cpu_to_be32(NFS4ERR_WRONG_TYPE)
0293 #define nfserr_dirdeleg_unavail     cpu_to_be32(NFS4ERR_DIRDELEG_UNAVAIL)
0294 #define nfserr_reject_deleg     cpu_to_be32(NFS4ERR_REJECT_DELEG)
0295 #define nfserr_returnconflict       cpu_to_be32(NFS4ERR_RETURNCONFLICT)
0296 #define nfserr_deleg_revoked        cpu_to_be32(NFS4ERR_DELEG_REVOKED)
0297 #define nfserr_partner_notsupp      cpu_to_be32(NFS4ERR_PARTNER_NOTSUPP)
0298 #define nfserr_partner_no_auth      cpu_to_be32(NFS4ERR_PARTNER_NO_AUTH)
0299 #define nfserr_union_notsupp        cpu_to_be32(NFS4ERR_UNION_NOTSUPP)
0300 #define nfserr_offload_denied       cpu_to_be32(NFS4ERR_OFFLOAD_DENIED)
0301 #define nfserr_wrong_lfs        cpu_to_be32(NFS4ERR_WRONG_LFS)
0302 #define nfserr_badlabel         cpu_to_be32(NFS4ERR_BADLABEL)
0303 #define nfserr_file_open        cpu_to_be32(NFS4ERR_FILE_OPEN)
0304 #define nfserr_xattr2big        cpu_to_be32(NFS4ERR_XATTR2BIG)
0305 #define nfserr_noxattr          cpu_to_be32(NFS4ERR_NOXATTR)
0306 
0307 /* error codes for internal use */
0308 /* if a request fails due to kmalloc failure, it gets dropped.
0309  *  Client should resend eventually
0310  */
0311 #define nfserr_dropit       cpu_to_be32(30000)
0312 /* end-of-file indicator in readdir */
0313 #define nfserr_eof      cpu_to_be32(30001)
0314 /* replay detected */
0315 #define nfserr_replay_me    cpu_to_be32(11001)
0316 /* nfs41 replay detected */
0317 #define nfserr_replay_cache cpu_to_be32(11002)
0318 
0319 /* Check for dir entries '.' and '..' */
0320 #define isdotent(n, l)  (l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))
0321 
0322 #ifdef CONFIG_NFSD_V4
0323 
0324 /* before processing a COMPOUND operation, we have to check that there
0325  * is enough space in the buffer for XDR encode to succeed.  otherwise,
0326  * we might process an operation with side effects, and be unable to
0327  * tell the client that the operation succeeded.
0328  *
0329  * COMPOUND_SLACK_SPACE - this is the minimum bytes of buffer space
0330  * needed to encode an "ordinary" _successful_ operation.  (GETATTR,
0331  * READ, READDIR, and READLINK have their own buffer checks.)  if we
0332  * fall below this level, we fail the next operation with NFS4ERR_RESOURCE.
0333  *
0334  * COMPOUND_ERR_SLACK_SPACE - this is the minimum bytes of buffer space
0335  * needed to encode an operation which has failed with NFS4ERR_RESOURCE.
0336  * care is taken to ensure that we never fall below this level for any
0337  * reason.
0338  */
0339 #define COMPOUND_SLACK_SPACE        140    /* OP_GETFH */
0340 #define COMPOUND_ERR_SLACK_SPACE    16     /* OP_SETATTR */
0341 
0342 #define NFSD_LAUNDROMAT_MINTIMEOUT      1   /* seconds */
0343 #define NFSD_COURTESY_CLIENT_TIMEOUT    (24 * 60 * 60)  /* seconds */
0344 #define NFSD_CLIENT_MAX_TRIM_PER_RUN    128
0345 #define NFS4_CLIENTS_PER_GB     1024
0346 
0347 /*
0348  * The following attributes are currently not supported by the NFSv4 server:
0349  *    ARCHIVE       (deprecated anyway)
0350  *    HIDDEN        (unlikely to be supported any time soon)
0351  *    MIMETYPE      (unlikely to be supported any time soon)
0352  *    QUOTA_*       (will be supported in a forthcoming patch)
0353  *    SYSTEM        (unlikely to be supported any time soon)
0354  *    TIME_BACKUP   (unlikely to be supported any time soon)
0355  *    TIME_CREATE   (unlikely to be supported any time soon)
0356  */
0357 #define NFSD4_SUPPORTED_ATTRS_WORD0                                                         \
0358 (FATTR4_WORD0_SUPPORTED_ATTRS   | FATTR4_WORD0_TYPE         | FATTR4_WORD0_FH_EXPIRE_TYPE   \
0359  | FATTR4_WORD0_CHANGE          | FATTR4_WORD0_SIZE         | FATTR4_WORD0_LINK_SUPPORT     \
0360  | FATTR4_WORD0_SYMLINK_SUPPORT | FATTR4_WORD0_NAMED_ATTR   | FATTR4_WORD0_FSID             \
0361  | FATTR4_WORD0_UNIQUE_HANDLES  | FATTR4_WORD0_LEASE_TIME   | FATTR4_WORD0_RDATTR_ERROR     \
0362  | FATTR4_WORD0_ACLSUPPORT      | FATTR4_WORD0_CANSETTIME   | FATTR4_WORD0_CASE_INSENSITIVE \
0363  | FATTR4_WORD0_CASE_PRESERVING | FATTR4_WORD0_CHOWN_RESTRICTED                             \
0364  | FATTR4_WORD0_FILEHANDLE      | FATTR4_WORD0_FILEID       | FATTR4_WORD0_FILES_AVAIL      \
0365  | FATTR4_WORD0_FILES_FREE      | FATTR4_WORD0_FILES_TOTAL  | FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_HOMOGENEOUS      \
0366  | FATTR4_WORD0_MAXFILESIZE     | FATTR4_WORD0_MAXLINK      | FATTR4_WORD0_MAXNAME          \
0367  | FATTR4_WORD0_MAXREAD         | FATTR4_WORD0_MAXWRITE     | FATTR4_WORD0_ACL)
0368 
0369 #define NFSD4_SUPPORTED_ATTRS_WORD1                                                         \
0370 (FATTR4_WORD1_MODE              | FATTR4_WORD1_NO_TRUNC     | FATTR4_WORD1_NUMLINKS         \
0371  | FATTR4_WORD1_OWNER           | FATTR4_WORD1_OWNER_GROUP  | FATTR4_WORD1_RAWDEV           \
0372  | FATTR4_WORD1_SPACE_AVAIL     | FATTR4_WORD1_SPACE_FREE   | FATTR4_WORD1_SPACE_TOTAL      \
0373  | FATTR4_WORD1_SPACE_USED      | FATTR4_WORD1_TIME_ACCESS  | FATTR4_WORD1_TIME_ACCESS_SET  \
0374  | FATTR4_WORD1_TIME_DELTA      | FATTR4_WORD1_TIME_METADATA   | FATTR4_WORD1_TIME_CREATE      \
0375  | FATTR4_WORD1_TIME_MODIFY     | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID)
0376 
0377 #define NFSD4_SUPPORTED_ATTRS_WORD2 0
0378 
0379 /* 4.1 */
0380 #ifdef CONFIG_NFSD_PNFS
0381 #define PNFSD_SUPPORTED_ATTRS_WORD1 FATTR4_WORD1_FS_LAYOUT_TYPES
0382 #define PNFSD_SUPPORTED_ATTRS_WORD2 \
0383 (FATTR4_WORD2_LAYOUT_BLKSIZE    | FATTR4_WORD2_LAYOUT_TYPES)
0384 #else
0385 #define PNFSD_SUPPORTED_ATTRS_WORD1 0
0386 #define PNFSD_SUPPORTED_ATTRS_WORD2 0
0387 #endif /* CONFIG_NFSD_PNFS */
0388 
0389 #define NFSD4_1_SUPPORTED_ATTRS_WORD0 \
0390     NFSD4_SUPPORTED_ATTRS_WORD0
0391 
0392 #define NFSD4_1_SUPPORTED_ATTRS_WORD1 \
0393     (NFSD4_SUPPORTED_ATTRS_WORD1    | PNFSD_SUPPORTED_ATTRS_WORD1)
0394 
0395 #define NFSD4_1_SUPPORTED_ATTRS_WORD2 \
0396     (NFSD4_SUPPORTED_ATTRS_WORD2    | PNFSD_SUPPORTED_ATTRS_WORD2 | \
0397      FATTR4_WORD2_SUPPATTR_EXCLCREAT)
0398 
0399 /* 4.2 */
0400 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
0401 #define NFSD4_2_SECURITY_ATTRS      FATTR4_WORD2_SECURITY_LABEL
0402 #else
0403 #define NFSD4_2_SECURITY_ATTRS      0
0404 #endif
0405 
0406 #define NFSD4_2_SUPPORTED_ATTRS_WORD2 \
0407     (NFSD4_1_SUPPORTED_ATTRS_WORD2 | \
0408     FATTR4_WORD2_MODE_UMASK | \
0409     NFSD4_2_SECURITY_ATTRS | \
0410     FATTR4_WORD2_XATTR_SUPPORT)
0411 
0412 extern const u32 nfsd_suppattrs[3][3];
0413 
0414 static inline __be32 nfsd4_set_netaddr(struct sockaddr *addr,
0415                     struct nfs42_netaddr *netaddr)
0416 {
0417     struct sockaddr_in *sin = (struct sockaddr_in *)addr;
0418     struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
0419     unsigned int port;
0420     size_t ret_addr, ret_port;
0421 
0422     switch (addr->sa_family) {
0423     case AF_INET:
0424         port = ntohs(sin->sin_port);
0425         sprintf(netaddr->netid, "tcp");
0426         netaddr->netid_len = 3;
0427         break;
0428     case AF_INET6:
0429         port = ntohs(sin6->sin6_port);
0430         sprintf(netaddr->netid, "tcp6");
0431         netaddr->netid_len = 4;
0432         break;
0433     default:
0434         return nfserr_inval;
0435     }
0436     ret_addr = rpc_ntop(addr, netaddr->addr, sizeof(netaddr->addr));
0437     ret_port = snprintf(netaddr->addr + ret_addr,
0438                 RPCBIND_MAXUADDRLEN + 1 - ret_addr,
0439                 ".%u.%u", port >> 8, port & 0xff);
0440     WARN_ON(ret_port >= RPCBIND_MAXUADDRLEN + 1 - ret_addr);
0441     netaddr->addr_len = ret_addr + ret_port;
0442     return 0;
0443 }
0444 
0445 static inline bool bmval_is_subset(const u32 *bm1, const u32 *bm2)
0446 {
0447     return !((bm1[0] & ~bm2[0]) ||
0448              (bm1[1] & ~bm2[1]) ||
0449          (bm1[2] & ~bm2[2]));
0450 }
0451 
0452 static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
0453 {
0454     return bmval_is_subset(bmval, nfsd_suppattrs[minorversion]);
0455 }
0456 
0457 /* These will return ERR_INVAL if specified in GETATTR or READDIR. */
0458 #define NFSD_WRITEONLY_ATTRS_WORD1 \
0459     (FATTR4_WORD1_TIME_ACCESS_SET   | FATTR4_WORD1_TIME_MODIFY_SET)
0460 
0461 /*
0462  * These are the only attrs allowed in CREATE/OPEN/SETATTR. Don't add
0463  * a writeable attribute here without also adding code to parse it to
0464  * nfsd4_decode_fattr().
0465  */
0466 #define NFSD_WRITEABLE_ATTRS_WORD0 \
0467     (FATTR4_WORD0_SIZE | FATTR4_WORD0_ACL)
0468 #define NFSD_WRITEABLE_ATTRS_WORD1 \
0469     (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \
0470     | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_CREATE \
0471     | FATTR4_WORD1_TIME_MODIFY_SET)
0472 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
0473 #define MAYBE_FATTR4_WORD2_SECURITY_LABEL \
0474     FATTR4_WORD2_SECURITY_LABEL
0475 #else
0476 #define MAYBE_FATTR4_WORD2_SECURITY_LABEL 0
0477 #endif
0478 #define NFSD_WRITEABLE_ATTRS_WORD2 \
0479     (FATTR4_WORD2_MODE_UMASK \
0480     | MAYBE_FATTR4_WORD2_SECURITY_LABEL)
0481 
0482 #define NFSD_SUPPATTR_EXCLCREAT_WORD0 \
0483     NFSD_WRITEABLE_ATTRS_WORD0
0484 /*
0485  * we currently store the exclusive create verifier in the v_{a,m}time
0486  * attributes so the client can't set these at create time using EXCLUSIVE4_1
0487  */
0488 #define NFSD_SUPPATTR_EXCLCREAT_WORD1 \
0489     (NFSD_WRITEABLE_ATTRS_WORD1 & \
0490      ~(FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET))
0491 #define NFSD_SUPPATTR_EXCLCREAT_WORD2 \
0492     NFSD_WRITEABLE_ATTRS_WORD2
0493 
0494 extern int nfsd4_is_junction(struct dentry *dentry);
0495 extern int register_cld_notifier(void);
0496 extern void unregister_cld_notifier(void);
0497 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
0498 extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
0499 #endif
0500 
0501 extern void nfsd4_init_leases_net(struct nfsd_net *nn);
0502 
0503 #else /* CONFIG_NFSD_V4 */
0504 static inline int nfsd4_is_junction(struct dentry *dentry)
0505 {
0506     return 0;
0507 }
0508 
0509 static inline void nfsd4_init_leases_net(struct nfsd_net *nn) {};
0510 
0511 #define register_cld_notifier() 0
0512 #define unregister_cld_notifier() do { } while(0)
0513 
0514 #endif /* CONFIG_NFSD_V4 */
0515 
0516 #endif /* LINUX_NFSD_NFSD_H */