Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  Copyright (c) 2001 The Regents of the University of Michigan.
0003  *  All rights reserved.
0004  *
0005  *  Kendrick Smith <kmsmith@umich.edu>
0006  *  Andy Adamson <andros@umich.edu>
0007  *  
0008  *  Redistribution and use in source and binary forms, with or without
0009  *  modification, are permitted provided that the following conditions
0010  *  are met:
0011  *  
0012  *  1. Redistributions of source code must retain the above copyright
0013  *     notice, this list of conditions and the following disclaimer.
0014  *  2. Redistributions in binary form must reproduce the above copyright
0015  *     notice, this list of conditions and the following disclaimer in the
0016  *     documentation and/or other materials provided with the distribution.
0017  *  3. Neither the name of the University nor the names of its
0018  *     contributors may be used to endorse or promote products derived
0019  *     from this software without specific prior written permission.
0020  *
0021  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
0022  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0023  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0024  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0025  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
0028  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0029  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0030  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0031  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0032  *
0033  */
0034 
0035 #ifndef _NFSD4_STATE_H
0036 #define _NFSD4_STATE_H
0037 
0038 #include <linux/idr.h>
0039 #include <linux/refcount.h>
0040 #include <linux/sunrpc/svc_xprt.h>
0041 #include "nfsfh.h"
0042 #include "nfsd.h"
0043 
0044 typedef struct {
0045     u32             cl_boot;
0046     u32             cl_id;
0047 } clientid_t;
0048 
0049 typedef struct {
0050     clientid_t  so_clid;
0051     u32     so_id;
0052 } stateid_opaque_t;
0053 
0054 typedef struct {
0055     u32                     si_generation;
0056     stateid_opaque_t        si_opaque;
0057 } stateid_t;
0058 
0059 typedef struct {
0060     stateid_t       stid;
0061 #define NFS4_COPY_STID 1
0062 #define NFS4_COPYNOTIFY_STID 2
0063     unsigned char       sc_type;
0064     refcount_t      sc_count;
0065 } copy_stateid_t;
0066 
0067 struct nfsd4_callback {
0068     struct nfs4_client *cb_clp;
0069     struct rpc_message cb_msg;
0070     const struct nfsd4_callback_ops *cb_ops;
0071     struct work_struct cb_work;
0072     int cb_seq_status;
0073     int cb_status;
0074     bool cb_need_restart;
0075     bool cb_holds_slot;
0076 };
0077 
0078 struct nfsd4_callback_ops {
0079     void (*prepare)(struct nfsd4_callback *);
0080     int (*done)(struct nfsd4_callback *, struct rpc_task *);
0081     void (*release)(struct nfsd4_callback *);
0082 };
0083 
0084 /*
0085  * A core object that represents a "common" stateid. These are generally
0086  * embedded within the different (more specific) stateid objects and contain
0087  * fields that are of general use to any stateid.
0088  */
0089 struct nfs4_stid {
0090     refcount_t      sc_count;
0091 #define NFS4_OPEN_STID 1
0092 #define NFS4_LOCK_STID 2
0093 #define NFS4_DELEG_STID 4
0094 /* For an open stateid kept around *only* to process close replays: */
0095 #define NFS4_CLOSED_STID 8
0096 /* For a deleg stateid kept around only to process free_stateid's: */
0097 #define NFS4_REVOKED_DELEG_STID 16
0098 #define NFS4_CLOSED_DELEG_STID 32
0099 #define NFS4_LAYOUT_STID 64
0100     struct list_head    sc_cp_list;
0101     unsigned char       sc_type;
0102     stateid_t       sc_stateid;
0103     spinlock_t      sc_lock;
0104     struct nfs4_client  *sc_client;
0105     struct nfs4_file    *sc_file;
0106     void            (*sc_free)(struct nfs4_stid *);
0107 };
0108 
0109 /* Keep a list of stateids issued by the COPY_NOTIFY, associate it with the
0110  * parent OPEN/LOCK/DELEG stateid.
0111  */
0112 struct nfs4_cpntf_state {
0113     copy_stateid_t      cp_stateid;
0114     struct list_head    cp_list;    /* per parent nfs4_stid */
0115     stateid_t       cp_p_stateid;   /* copy of parent's stateid */
0116     clientid_t      cp_p_clid;  /* copy of parent's clid */
0117     time64_t        cpntf_time; /* last time stateid used */
0118 };
0119 
0120 /*
0121  * Represents a delegation stateid. The nfs4_client holds references to these
0122  * and they are put when it is being destroyed or when the delegation is
0123  * returned by the client:
0124  *
0125  * o 1 reference as long as a delegation is still in force (taken when it's
0126  *   alloc'd, put when it's returned or revoked)
0127  *
0128  * o 1 reference as long as a recall rpc is in progress (taken when the lease
0129  *   is broken, put when the rpc exits)
0130  *
0131  * o 1 more ephemeral reference for each nfsd thread currently doing something
0132  *   with that delegation without holding the cl_lock
0133  *
0134  * If the server attempts to recall a delegation and the client doesn't do so
0135  * before a timeout, the server may also revoke the delegation. In that case,
0136  * the object will either be destroyed (v4.0) or moved to a per-client list of
0137  * revoked delegations (v4.1+).
0138  *
0139  * This object is a superset of the nfs4_stid.
0140  */
0141 struct nfs4_delegation {
0142     struct nfs4_stid    dl_stid; /* must be first field */
0143     struct list_head    dl_perfile;
0144     struct list_head    dl_perclnt;
0145     struct list_head    dl_recall_lru;  /* delegation recalled */
0146     struct nfs4_clnt_odstate *dl_clnt_odstate;
0147     u32         dl_type;
0148     time64_t        dl_time;
0149 /* For recall: */
0150     int         dl_retries;
0151     struct nfsd4_callback   dl_recall;
0152     bool            dl_recalled;
0153 };
0154 
0155 #define cb_to_delegation(cb) \
0156     container_of(cb, struct nfs4_delegation, dl_recall)
0157 
0158 /* client delegation callback info */
0159 struct nfs4_cb_conn {
0160     /* SETCLIENTID info */
0161     struct sockaddr_storage cb_addr;
0162     struct sockaddr_storage cb_saddr;
0163     size_t          cb_addrlen;
0164     u32                     cb_prog; /* used only in 4.0 case;
0165                         per-session otherwise */
0166     u32                     cb_ident;   /* minorversion 0 only */
0167     struct svc_xprt     *cb_xprt;   /* minorversion 1 only */
0168 };
0169 
0170 static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
0171 {
0172     return container_of(s, struct nfs4_delegation, dl_stid);
0173 }
0174 
0175 /* Maximum number of slots per session. 160 is useful for long haul TCP */
0176 #define NFSD_MAX_SLOTS_PER_SESSION     160
0177 /* Maximum number of operations per session compound */
0178 #define NFSD_MAX_OPS_PER_COMPOUND   16
0179 /* Maximum  session per slot cache size */
0180 #define NFSD_SLOT_CACHE_SIZE        2048
0181 /* Maximum number of NFSD_SLOT_CACHE_SIZE slots per session */
0182 #define NFSD_CACHE_SIZE_SLOTS_PER_SESSION   32
0183 #define NFSD_MAX_MEM_PER_SESSION  \
0184         (NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
0185 
0186 struct nfsd4_slot {
0187     u32 sl_seqid;
0188     __be32  sl_status;
0189     struct svc_cred sl_cred;
0190     u32 sl_datalen;
0191     u16 sl_opcnt;
0192 #define NFSD4_SLOT_INUSE    (1 << 0)
0193 #define NFSD4_SLOT_CACHETHIS    (1 << 1)
0194 #define NFSD4_SLOT_INITIALIZED  (1 << 2)
0195 #define NFSD4_SLOT_CACHED   (1 << 3)
0196     u8  sl_flags;
0197     char    sl_data[];
0198 };
0199 
0200 struct nfsd4_channel_attrs {
0201     u32     headerpadsz;
0202     u32     maxreq_sz;
0203     u32     maxresp_sz;
0204     u32     maxresp_cached;
0205     u32     maxops;
0206     u32     maxreqs;
0207     u32     nr_rdma_attrs;
0208     u32     rdma_attrs;
0209 };
0210 
0211 struct nfsd4_cb_sec {
0212     u32 flavor; /* (u32)(-1) used to mean "no valid flavor" */
0213     kuid_t  uid;
0214     kgid_t  gid;
0215 };
0216 
0217 struct nfsd4_create_session {
0218     clientid_t          clientid;
0219     struct nfs4_sessionid       sessionid;
0220     u32             seqid;
0221     u32             flags;
0222     struct nfsd4_channel_attrs  fore_channel;
0223     struct nfsd4_channel_attrs  back_channel;
0224     u32             callback_prog;
0225     struct nfsd4_cb_sec     cb_sec;
0226 };
0227 
0228 struct nfsd4_backchannel_ctl {
0229     u32 bc_cb_program;
0230     struct nfsd4_cb_sec     bc_cb_sec;
0231 };
0232 
0233 struct nfsd4_bind_conn_to_session {
0234     struct nfs4_sessionid       sessionid;
0235     u32             dir;
0236 };
0237 
0238 /* The single slot clientid cache structure */
0239 struct nfsd4_clid_slot {
0240     u32             sl_seqid;
0241     __be32              sl_status;
0242     struct nfsd4_create_session sl_cr_ses;
0243 };
0244 
0245 struct nfsd4_conn {
0246     struct list_head cn_persession;
0247     struct svc_xprt *cn_xprt;
0248     struct svc_xpt_user cn_xpt_user;
0249     struct nfsd4_session *cn_session;
0250 /* CDFC4_FORE, CDFC4_BACK: */
0251     unsigned char cn_flags;
0252 };
0253 
0254 /*
0255  * Representation of a v4.1+ session. These are refcounted in a similar fashion
0256  * to the nfs4_client. References are only taken when the server is actively
0257  * working on the object (primarily during the processing of compounds).
0258  */
0259 struct nfsd4_session {
0260     atomic_t        se_ref;
0261     struct list_head    se_hash;    /* hash by sessionid */
0262     struct list_head    se_perclnt;
0263 /* See SESSION4_PERSIST, etc. for standard flags; this is internal-only: */
0264 #define NFS4_SESSION_DEAD   0x010
0265     u32         se_flags;
0266     struct nfs4_client  *se_client;
0267     struct nfs4_sessionid   se_sessionid;
0268     struct nfsd4_channel_attrs se_fchannel;
0269     struct nfsd4_channel_attrs se_bchannel;
0270     struct nfsd4_cb_sec se_cb_sec;
0271     struct list_head    se_conns;
0272     u32         se_cb_prog;
0273     u32         se_cb_seq_nr;
0274     struct nfsd4_slot   *se_slots[];    /* forward channel slots */
0275 };
0276 
0277 /* formatted contents of nfs4_sessionid */
0278 struct nfsd4_sessionid {
0279     clientid_t  clientid;
0280     u32     sequence;
0281     u32     reserved;
0282 };
0283 
0284 #define HEXDIR_LEN     33 /* hex version of 16 byte md5 of cl_name plus '\0' */
0285 
0286 /*
0287  *       State                Meaning                  Where set
0288  * --------------------------------------------------------------------------
0289  * | NFSD4_ACTIVE      | Confirmed, active    | Default                     |
0290  * |------------------- ----------------------------------------------------|
0291  * | NFSD4_COURTESY    | Courtesy state.      | nfs4_get_client_reaplist    |
0292  * |                   | Lease/lock/share     |                             |
0293  * |                   | reservation conflict |                             |
0294  * |                   | can cause Courtesy   |                             |
0295  * |                   | client to be expired |                             |
0296  * |------------------------------------------------------------------------|
0297  * | NFSD4_EXPIRABLE   | Courtesy client to be| nfs4_laundromat             |
0298  * |                   | expired by Laundromat| try_to_expire_client        |
0299  * |                   | due to conflict      |                             |
0300  * |------------------------------------------------------------------------|
0301  */
0302 enum {
0303     NFSD4_ACTIVE = 0,
0304     NFSD4_COURTESY,
0305     NFSD4_EXPIRABLE,
0306 };
0307 
0308 /*
0309  * struct nfs4_client - one per client.  Clientids live here.
0310  *
0311  * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
0312  * or EXCHANGE_ID (for NFSv4.1+). These objects are refcounted and timestamped.
0313  * Each nfsd_net_ns object contains a set of these and they are tracked via
0314  * short and long form clientid. They are hashed and searched for under the
0315  * per-nfsd_net client_lock spinlock.
0316  *
0317  * References to it are only held during the processing of compounds, and in
0318  * certain other operations. In their "resting state" they have a refcount of
0319  * 0. If they are not renewed within a lease period, they become eligible for
0320  * destruction by the laundromat.
0321  *
0322  * These objects can also be destroyed prematurely by the fault injection code,
0323  * or if the client sends certain forms of SETCLIENTID or EXCHANGE_ID updates.
0324  * Care is taken *not* to do this however when the objects have an elevated
0325  * refcount.
0326  *
0327  * o Each nfs4_client is hashed by clientid
0328  *
0329  * o Each nfs4_clients is also hashed by name (the opaque quantity initially
0330  *   sent by the client to identify itself).
0331  *    
0332  * o cl_perclient list is used to ensure no dangling stateowner references
0333  *   when we expire the nfs4_client
0334  */
0335 struct nfs4_client {
0336     struct list_head    cl_idhash;  /* hash by cl_clientid.id */
0337     struct rb_node      cl_namenode;    /* link into by-name trees */
0338     struct list_head    *cl_ownerstr_hashtbl;
0339     struct list_head    cl_openowners;
0340     struct idr      cl_stateids;    /* stateid lookup */
0341     struct list_head    cl_delegations;
0342     struct list_head    cl_revoked; /* unacknowledged, revoked 4.1 state */
0343     struct list_head        cl_lru;         /* tail queue */
0344 #ifdef CONFIG_NFSD_PNFS
0345     struct list_head    cl_lo_states;   /* outstanding layout states */
0346 #endif
0347     struct xdr_netobj   cl_name;    /* id generated by client */
0348     nfs4_verifier       cl_verifier;    /* generated by client */
0349     time64_t        cl_time;    /* time of last lease renewal */
0350     struct sockaddr_storage cl_addr;    /* client ipaddress */
0351     bool            cl_mach_cred;   /* SP4_MACH_CRED in force */
0352     struct svc_cred     cl_cred;    /* setclientid principal */
0353     clientid_t      cl_clientid;    /* generated by server */
0354     nfs4_verifier       cl_confirm; /* generated by server */
0355     u32         cl_minorversion;
0356     /* NFSv4.1 client implementation id: */
0357     struct xdr_netobj   cl_nii_domain;
0358     struct xdr_netobj   cl_nii_name;
0359     struct timespec64   cl_nii_time;
0360 
0361     /* for v4.0 and v4.1 callbacks: */
0362     struct nfs4_cb_conn cl_cb_conn;
0363 #define NFSD4_CLIENT_CB_UPDATE      (0)
0364 #define NFSD4_CLIENT_CB_KILL        (1)
0365 #define NFSD4_CLIENT_STABLE     (2) /* client on stable storage */
0366 #define NFSD4_CLIENT_RECLAIM_COMPLETE   (3) /* reclaim_complete done */
0367 #define NFSD4_CLIENT_CONFIRMED      (4) /* client is confirmed */
0368 #define NFSD4_CLIENT_UPCALL_LOCK    (5) /* upcall serialization */
0369 #define NFSD4_CLIENT_CB_FLAG_MASK   (1 << NFSD4_CLIENT_CB_UPDATE | \
0370                      1 << NFSD4_CLIENT_CB_KILL)
0371     unsigned long       cl_flags;
0372     const struct cred   *cl_cb_cred;
0373     struct rpc_clnt     *cl_cb_client;
0374     u32         cl_cb_ident;
0375 #define NFSD4_CB_UP     0
0376 #define NFSD4_CB_UNKNOWN    1
0377 #define NFSD4_CB_DOWN       2
0378 #define NFSD4_CB_FAULT      3
0379     int         cl_cb_state;
0380     struct nfsd4_callback   cl_cb_null;
0381     struct nfsd4_session    *cl_cb_session;
0382 
0383     /* for all client information that callback code might need: */
0384     spinlock_t      cl_lock;
0385 
0386     /* for nfs41 */
0387     struct list_head    cl_sessions;
0388     struct nfsd4_clid_slot  cl_cs_slot; /* create_session slot */
0389     u32         cl_exchange_flags;
0390     /* number of rpc's in progress over an associated session: */
0391     atomic_t        cl_rpc_users;
0392     struct nfsdfs_client    cl_nfsdfs;
0393     struct nfs4_op_map      cl_spo_must_allow;
0394 
0395     /* debugging info directory under nfsd/clients/ : */
0396     struct dentry       *cl_nfsd_dentry;
0397     /* 'info' file within that directory. Ref is not counted,
0398      * but will remain valid iff cl_nfsd_dentry != NULL
0399      */
0400     struct dentry       *cl_nfsd_info_dentry;
0401 
0402     /* for nfs41 callbacks */
0403     /* We currently support a single back channel with a single slot */
0404     unsigned long       cl_cb_slot_busy;
0405     struct rpc_wait_queue   cl_cb_waitq;    /* backchannel callers may */
0406                         /* wait here for slots */
0407     struct net      *net;
0408     struct list_head    async_copies;   /* list of async copies */
0409     spinlock_t      async_lock; /* lock for async copies */
0410     atomic_t        cl_cb_inflight; /* Outstanding callbacks */
0411 
0412     unsigned int        cl_state;
0413     atomic_t        cl_delegs_in_recall;
0414 };
0415 
0416 /* struct nfs4_client_reset
0417  * one per old client. Populates reset_str_hashtbl. Filled from conf_id_hashtbl
0418  * upon lease reset, or from upcall to state_daemon (to read in state
0419  * from non-volitile storage) upon reboot.
0420  */
0421 struct nfs4_client_reclaim {
0422     struct list_head    cr_strhash; /* hash by cr_name */
0423     struct nfs4_client  *cr_clp;    /* pointer to associated clp */
0424     struct xdr_netobj   cr_name;    /* recovery dir name */
0425     struct xdr_netobj   cr_princhash;
0426 };
0427 
0428 /* A reasonable value for REPLAY_ISIZE was estimated as follows:  
0429  * The OPEN response, typically the largest, requires 
0430  *   4(status) + 8(stateid) + 20(changeinfo) + 4(rflags) +  8(verifier) + 
0431  *   4(deleg. type) + 8(deleg. stateid) + 4(deleg. recall flag) + 
0432  *   20(deleg. space limit) + ~32(deleg. ace) = 112 bytes 
0433  */
0434 
0435 #define NFSD4_REPLAY_ISIZE       112 
0436 
0437 /*
0438  * Replay buffer, where the result of the last seqid-mutating operation 
0439  * is cached. 
0440  */
0441 struct nfs4_replay {
0442     __be32          rp_status;
0443     unsigned int        rp_buflen;
0444     char            *rp_buf;
0445     struct knfsd_fh     rp_openfh;
0446     struct mutex        rp_mutex;
0447     char            rp_ibuf[NFSD4_REPLAY_ISIZE];
0448 };
0449 
0450 struct nfs4_stateowner;
0451 
0452 struct nfs4_stateowner_operations {
0453     void (*so_unhash)(struct nfs4_stateowner *);
0454     void (*so_free)(struct nfs4_stateowner *);
0455 };
0456 
0457 /*
0458  * A core object that represents either an open or lock owner. The object and
0459  * lock owner objects have one of these embedded within them. Refcounts and
0460  * other fields common to both owner types are contained within these
0461  * structures.
0462  */
0463 struct nfs4_stateowner {
0464     struct list_head            so_strhash;
0465     struct list_head            so_stateids;
0466     struct nfs4_client          *so_client;
0467     const struct nfs4_stateowner_operations *so_ops;
0468     /* after increment in nfsd4_bump_seqid, represents the next
0469      * sequence id expected from the client: */
0470     atomic_t                so_count;
0471     u32                 so_seqid;
0472     struct xdr_netobj           so_owner; /* open owner name */
0473     struct nfs4_replay          so_replay;
0474     bool                    so_is_open_owner;
0475 };
0476 
0477 /*
0478  * When a file is opened, the client provides an open state owner opaque string
0479  * that indicates the "owner" of that open. These objects are refcounted.
0480  * References to it are held by each open state associated with it. This object
0481  * is a superset of the nfs4_stateowner struct.
0482  */
0483 struct nfs4_openowner {
0484     struct nfs4_stateowner  oo_owner; /* must be first field */
0485     struct list_head        oo_perclient;
0486     /*
0487      * We keep around openowners a little while after last close,
0488      * which saves clients from having to confirm, and allows us to
0489      * handle close replays if they come soon enough.  The close_lru
0490      * is a list of such openowners, to be reaped by the laundromat
0491      * thread eventually if they remain unused:
0492      */
0493     struct list_head    oo_close_lru;
0494     struct nfs4_ol_stateid *oo_last_closed_stid;
0495     time64_t        oo_time; /* time of placement on so_close_lru */
0496 #define NFS4_OO_CONFIRMED   1
0497     unsigned char       oo_flags;
0498 };
0499 
0500 /*
0501  * Represents a generic "lockowner". Similar to an openowner. References to it
0502  * are held by the lock stateids that are created on its behalf. This object is
0503  * a superset of the nfs4_stateowner struct.
0504  */
0505 struct nfs4_lockowner {
0506     struct nfs4_stateowner  lo_owner;   /* must be first element */
0507     struct list_head    lo_blocked; /* blocked file_locks */
0508 };
0509 
0510 static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
0511 {
0512     return container_of(so, struct nfs4_openowner, oo_owner);
0513 }
0514 
0515 static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
0516 {
0517     return container_of(so, struct nfs4_lockowner, lo_owner);
0518 }
0519 
0520 /*
0521  * Per-client state indicating no. of opens and outstanding delegations
0522  * on a file from a particular client.'od' stands for 'open & delegation'
0523  */
0524 struct nfs4_clnt_odstate {
0525     struct nfs4_client  *co_client;
0526     struct nfs4_file    *co_file;
0527     struct list_head    co_perfile;
0528     refcount_t      co_odcount;
0529 };
0530 
0531 /*
0532  * nfs4_file: a file opened by some number of (open) nfs4_stateowners.
0533  *
0534  * These objects are global. nfsd keeps one instance of a nfs4_file per
0535  * filehandle (though it may keep multiple file descriptors for each). Each
0536  * inode can have multiple filehandles associated with it, so there is
0537  * (potentially) a many to one relationship between this struct and struct
0538  * inode.
0539  *
0540  * These are hashed by filehandle in the file_hashtbl, which is protected by
0541  * the global state_lock spinlock.
0542  */
0543 struct nfs4_file {
0544     refcount_t      fi_ref;
0545     struct inode *      fi_inode;
0546     bool            fi_aliased;
0547     spinlock_t      fi_lock;
0548     struct hlist_node       fi_hash;    /* hash on fi_fhandle */
0549     struct list_head        fi_stateids;
0550     union {
0551         struct list_head    fi_delegations;
0552         struct rcu_head     fi_rcu;
0553     };
0554     struct list_head    fi_clnt_odstate;
0555     /* One each for O_RDONLY, O_WRONLY, O_RDWR: */
0556     struct nfsd_file    *fi_fds[3];
0557     /*
0558      * Each open or lock stateid contributes 0-4 to the counts
0559      * below depending on which bits are set in st_access_bitmap:
0560      *     1 to fi_access[O_RDONLY] if NFS4_SHARE_ACCES_READ is set
0561      *   + 1 to fi_access[O_WRONLY] if NFS4_SHARE_ACCESS_WRITE is set
0562      *   + 1 to both of the above if NFS4_SHARE_ACCESS_BOTH is set.
0563      */
0564     atomic_t        fi_access[2];
0565     u32         fi_share_deny;
0566     struct nfsd_file    *fi_deleg_file;
0567     int         fi_delegees;
0568     struct knfsd_fh     fi_fhandle;
0569     bool            fi_had_conflict;
0570 #ifdef CONFIG_NFSD_PNFS
0571     struct list_head    fi_lo_states;
0572     atomic_t        fi_lo_recalls;
0573 #endif
0574 };
0575 
0576 /*
0577  * A generic struct representing either a open or lock stateid. The nfs4_client
0578  * holds a reference to each of these objects, and they in turn hold a
0579  * reference to their respective stateowners. The client's reference is
0580  * released in response to a close or unlock (depending on whether it's an open
0581  * or lock stateid) or when the client is being destroyed.
0582  *
0583  * In the case of v4.0 open stateids, these objects are preserved for a little
0584  * while after close in order to handle CLOSE replays. Those are eventually
0585  * reclaimed via a LRU scheme by the laundromat.
0586  *
0587  * This object is a superset of the nfs4_stid. "ol" stands for "Open or Lock".
0588  * Better suggestions welcome.
0589  */
0590 struct nfs4_ol_stateid {
0591     struct nfs4_stid        st_stid;
0592     struct list_head        st_perfile;
0593     struct list_head        st_perstateowner;
0594     struct list_head        st_locks;
0595     struct nfs4_stateowner      *st_stateowner;
0596     struct nfs4_clnt_odstate    *st_clnt_odstate;
0597 /*
0598  * These bitmasks use 3 separate bits for READ, ALLOW, and BOTH; see the
0599  * comment above bmap_to_share_mode() for explanation:
0600  */
0601     unsigned char           st_access_bmap;
0602     unsigned char           st_deny_bmap;
0603     struct nfs4_ol_stateid      *st_openstp;
0604     struct mutex            st_mutex;
0605 };
0606 
0607 static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
0608 {
0609     return container_of(s, struct nfs4_ol_stateid, st_stid);
0610 }
0611 
0612 struct nfs4_layout_stateid {
0613     struct nfs4_stid        ls_stid;
0614     struct list_head        ls_perclnt;
0615     struct list_head        ls_perfile;
0616     spinlock_t          ls_lock;
0617     struct list_head        ls_layouts;
0618     u32             ls_layout_type;
0619     struct nfsd_file        *ls_file;
0620     struct nfsd4_callback       ls_recall;
0621     stateid_t           ls_recall_sid;
0622     bool                ls_recalled;
0623     struct mutex            ls_mutex;
0624 };
0625 
0626 static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
0627 {
0628     return container_of(s, struct nfs4_layout_stateid, ls_stid);
0629 }
0630 
0631 /* flags for preprocess_seqid_op() */
0632 #define RD_STATE            0x00000010
0633 #define WR_STATE            0x00000020
0634 
0635 enum nfsd4_cb_op {
0636     NFSPROC4_CLNT_CB_NULL = 0,
0637     NFSPROC4_CLNT_CB_RECALL,
0638     NFSPROC4_CLNT_CB_LAYOUT,
0639     NFSPROC4_CLNT_CB_OFFLOAD,
0640     NFSPROC4_CLNT_CB_SEQUENCE,
0641     NFSPROC4_CLNT_CB_NOTIFY_LOCK,
0642 };
0643 
0644 /* Returns true iff a is later than b: */
0645 static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
0646 {
0647     return (s32)(a->si_generation - b->si_generation) > 0;
0648 }
0649 
0650 /*
0651  * When a client tries to get a lock on a file, we set one of these objects
0652  * on the blocking lock. When the lock becomes free, we can then issue a
0653  * CB_NOTIFY_LOCK to the server.
0654  */
0655 struct nfsd4_blocked_lock {
0656     struct list_head    nbl_list;
0657     struct list_head    nbl_lru;
0658     time64_t        nbl_time;
0659     struct file_lock    nbl_lock;
0660     struct knfsd_fh     nbl_fh;
0661     struct nfsd4_callback   nbl_cb;
0662     struct kref     nbl_kref;
0663 };
0664 
0665 struct nfsd4_compound_state;
0666 struct nfsd_net;
0667 struct nfsd4_copy;
0668 
0669 extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
0670         struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
0671         stateid_t *stateid, int flags, struct nfsd_file **filp,
0672         struct nfs4_stid **cstid);
0673 __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
0674              stateid_t *stateid, unsigned char typemask,
0675              struct nfs4_stid **s, struct nfsd_net *nn);
0676 struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab,
0677                   void (*sc_free)(struct nfs4_stid *));
0678 int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy);
0679 void nfs4_free_copy_state(struct nfsd4_copy *copy);
0680 struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
0681             struct nfs4_stid *p_stid);
0682 void nfs4_unhash_stid(struct nfs4_stid *s);
0683 void nfs4_put_stid(struct nfs4_stid *s);
0684 void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid);
0685 void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
0686 extern void nfs4_release_reclaim(struct nfsd_net *);
0687 extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct xdr_netobj name,
0688                             struct nfsd_net *nn);
0689 extern __be32 nfs4_check_open_reclaim(struct nfs4_client *);
0690 extern void nfsd4_probe_callback(struct nfs4_client *clp);
0691 extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
0692 extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
0693 extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
0694         const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
0695 extern void nfsd4_run_cb(struct nfsd4_callback *cb);
0696 extern int nfsd4_create_callback_queue(void);
0697 extern void nfsd4_destroy_callback_queue(void);
0698 extern void nfsd4_shutdown_callback(struct nfs4_client *);
0699 extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
0700 extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
0701 extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
0702                 struct xdr_netobj princhash, struct nfsd_net *nn);
0703 extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
0704 
0705 void put_nfs4_file(struct nfs4_file *fi);
0706 extern struct nfsd4_copy *
0707 find_async_copy(struct nfs4_client *clp, stateid_t *staetid);
0708 extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
0709                  struct nfs4_cpntf_state *cps);
0710 extern __be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
0711                  struct nfs4_client *clp,
0712                  struct nfs4_cpntf_state **cps);
0713 static inline void get_nfs4_file(struct nfs4_file *fi)
0714 {
0715     refcount_inc(&fi->fi_ref);
0716 }
0717 struct nfsd_file *find_any_file(struct nfs4_file *f);
0718 
0719 /* grace period management */
0720 void nfsd4_end_grace(struct nfsd_net *nn);
0721 
0722 /* nfs4recover operations */
0723 extern int nfsd4_client_tracking_init(struct net *net);
0724 extern void nfsd4_client_tracking_exit(struct net *net);
0725 extern void nfsd4_client_record_create(struct nfs4_client *clp);
0726 extern void nfsd4_client_record_remove(struct nfs4_client *clp);
0727 extern int nfsd4_client_record_check(struct nfs4_client *clp);
0728 extern void nfsd4_record_grace_done(struct nfsd_net *nn);
0729 
0730 static inline bool try_to_expire_client(struct nfs4_client *clp)
0731 {
0732     cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
0733     return clp->cl_state == NFSD4_EXPIRABLE;
0734 }
0735 #endif   /* NFSD4_STATE_H */