19a74af21SBoaz Harrosh /*
29a74af21SBoaz Harrosh * Copyright (c) 2001 The Regents of the University of Michigan.
39a74af21SBoaz Harrosh * All rights reserved.
49a74af21SBoaz Harrosh *
59a74af21SBoaz Harrosh * Kendrick Smith <kmsmith@umich.edu>
69a74af21SBoaz Harrosh * Andy Adamson <andros@umich.edu>
79a74af21SBoaz Harrosh *
89a74af21SBoaz Harrosh * Redistribution and use in source and binary forms, with or without
99a74af21SBoaz Harrosh * modification, are permitted provided that the following conditions
109a74af21SBoaz Harrosh * are met:
119a74af21SBoaz Harrosh *
129a74af21SBoaz Harrosh * 1. Redistributions of source code must retain the above copyright
139a74af21SBoaz Harrosh * notice, this list of conditions and the following disclaimer.
149a74af21SBoaz Harrosh * 2. Redistributions in binary form must reproduce the above copyright
159a74af21SBoaz Harrosh * notice, this list of conditions and the following disclaimer in the
169a74af21SBoaz Harrosh * documentation and/or other materials provided with the distribution.
179a74af21SBoaz Harrosh * 3. Neither the name of the University nor the names of its
189a74af21SBoaz Harrosh * contributors may be used to endorse or promote products derived
199a74af21SBoaz Harrosh * from this software without specific prior written permission.
209a74af21SBoaz Harrosh *
219a74af21SBoaz Harrosh * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
229a74af21SBoaz Harrosh * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
239a74af21SBoaz Harrosh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
249a74af21SBoaz Harrosh * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
259a74af21SBoaz Harrosh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
269a74af21SBoaz Harrosh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
279a74af21SBoaz Harrosh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
289a74af21SBoaz Harrosh * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
299a74af21SBoaz Harrosh * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
309a74af21SBoaz Harrosh * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
319a74af21SBoaz Harrosh * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
329a74af21SBoaz Harrosh *
339a74af21SBoaz Harrosh */
349a74af21SBoaz Harrosh
359a74af21SBoaz Harrosh #ifndef _NFSD4_STATE_H
369a74af21SBoaz Harrosh #define _NFSD4_STATE_H
379a74af21SBoaz Harrosh
3838c2f4b1SJ. Bruce Fields #include <linux/idr.h>
39a15dfcd5SElena Reshetova #include <linux/refcount.h>
4019cf5c02SJ. Bruce Fields #include <linux/sunrpc/svc_xprt.h>
411557aca7SJ. Bruce Fields #include "nfsfh.h"
42e8a79fb1SJ. Bruce Fields #include "nfsd.h"
439a74af21SBoaz Harrosh
449a74af21SBoaz Harrosh typedef struct {
459a74af21SBoaz Harrosh u32 cl_boot;
469a74af21SBoaz Harrosh u32 cl_id;
479a74af21SBoaz Harrosh } clientid_t;
489a74af21SBoaz Harrosh
499a74af21SBoaz Harrosh typedef struct {
50d3b313a4SJ. Bruce Fields clientid_t so_clid;
51d3b313a4SJ. Bruce Fields u32 so_id;
529a74af21SBoaz Harrosh } stateid_opaque_t;
539a74af21SBoaz Harrosh
549a74af21SBoaz Harrosh typedef struct {
559a74af21SBoaz Harrosh u32 si_generation;
569a74af21SBoaz Harrosh stateid_opaque_t si_opaque;
579a74af21SBoaz Harrosh } stateid_t;
589a74af21SBoaz Harrosh
59624322f1SOlga Kornievskaia typedef struct {
60781fde1aSChuck Lever stateid_t cs_stid;
61624322f1SOlga Kornievskaia #define NFS4_COPY_STID 1
62624322f1SOlga Kornievskaia #define NFS4_COPYNOTIFY_STID 2
63781fde1aSChuck Lever unsigned char cs_type;
64781fde1aSChuck Lever refcount_t cs_count;
65624322f1SOlga Kornievskaia } copy_stateid_t;
66624322f1SOlga Kornievskaia
67227f98d9SJ. Bruce Fields struct nfsd4_callback {
68fb003923SJ. Bruce Fields struct nfs4_client *cb_clp;
695878453dSJ. Bruce Fields struct rpc_message cb_msg;
70c4cb8974SJulia Lawall const struct nfsd4_callback_ops *cb_ops;
71b5a1a81eSJ. Bruce Fields struct work_struct cb_work;
727ba6cad6SKinglong Mee int cb_seq_status;
73ef2a1b3eSChristoph Hellwig int cb_status;
74cba5f62bSChristoph Hellwig bool cb_need_restart;
75e6abc8caSTrond Myklebust bool cb_holds_slot;
76227f98d9SJ. Bruce Fields };
77227f98d9SJ. Bruce Fields
780162ac2bSChristoph Hellwig struct nfsd4_callback_ops {
790162ac2bSChristoph Hellwig void (*prepare)(struct nfsd4_callback *);
800162ac2bSChristoph Hellwig int (*done)(struct nfsd4_callback *, struct rpc_task *);
810162ac2bSChristoph Hellwig void (*release)(struct nfsd4_callback *);
820162ac2bSChristoph Hellwig };
830162ac2bSChristoph Hellwig
8414a571a8SJeff Layton /*
8514a571a8SJeff Layton * A core object that represents a "common" stateid. These are generally
8614a571a8SJeff Layton * embedded within the different (more specific) stateid objects and contain
8714a571a8SJeff Layton * fields that are of general use to any stateid.
8814a571a8SJeff Layton */
89d5477a8dSJ. Bruce Fields struct nfs4_stid {
90a15dfcd5SElena Reshetova refcount_t sc_count;
91d5477a8dSJ. Bruce Fields #define NFS4_OPEN_STID 1
92d5477a8dSJ. Bruce Fields #define NFS4_LOCK_STID 2
93d5477a8dSJ. Bruce Fields #define NFS4_DELEG_STID 4
94f7a4d872SJ. Bruce Fields /* For an open stateid kept around *only* to process close replays: */
95f7a4d872SJ. Bruce Fields #define NFS4_CLOSED_STID 8
963bd64a5bSJ. Bruce Fields /* For a deleg stateid kept around only to process free_stateid's: */
973bd64a5bSJ. Bruce Fields #define NFS4_REVOKED_DELEG_STID 16
98b0fc29d6STrond Myklebust #define NFS4_CLOSED_DELEG_STID 32
999cf514ccSChristoph Hellwig #define NFS4_LAYOUT_STID 64
100624322f1SOlga Kornievskaia struct list_head sc_cp_list;
101f7a4d872SJ. Bruce Fields unsigned char sc_type;
102d5477a8dSJ. Bruce Fields stateid_t sc_stateid;
1039767feb2SJeff Layton spinlock_t sc_lock;
1042a74aba7SJ. Bruce Fields struct nfs4_client *sc_client;
10511b9164aSTrond Myklebust struct nfs4_file *sc_file;
1066011695dSTrond Myklebust void (*sc_free)(struct nfs4_stid *);
107d5477a8dSJ. Bruce Fields };
108d5477a8dSJ. Bruce Fields
109624322f1SOlga Kornievskaia /* Keep a list of stateids issued by the COPY_NOTIFY, associate it with the
110624322f1SOlga Kornievskaia * parent OPEN/LOCK/DELEG stateid.
111624322f1SOlga Kornievskaia */
112624322f1SOlga Kornievskaia struct nfs4_cpntf_state {
113624322f1SOlga Kornievskaia copy_stateid_t cp_stateid;
114624322f1SOlga Kornievskaia struct list_head cp_list; /* per parent nfs4_stid */
115624322f1SOlga Kornievskaia stateid_t cp_p_stateid; /* copy of parent's stateid */
116624322f1SOlga Kornievskaia clientid_t cp_p_clid; /* copy of parent's clid */
11720b7d86fSArnd Bergmann time64_t cpntf_time; /* last time stateid used */
118624322f1SOlga Kornievskaia };
119624322f1SOlga Kornievskaia
12014a571a8SJeff Layton /*
12114a571a8SJeff Layton * Represents a delegation stateid. The nfs4_client holds references to these
12214a571a8SJeff Layton * and they are put when it is being destroyed or when the delegation is
12314a571a8SJeff Layton * returned by the client:
12414a571a8SJeff Layton *
12514a571a8SJeff Layton * o 1 reference as long as a delegation is still in force (taken when it's
12614a571a8SJeff Layton * alloc'd, put when it's returned or revoked)
12714a571a8SJeff Layton *
12814a571a8SJeff Layton * o 1 reference as long as a recall rpc is in progress (taken when the lease
12914a571a8SJeff Layton * is broken, put when the rpc exits)
13014a571a8SJeff Layton *
13114a571a8SJeff Layton * o 1 more ephemeral reference for each nfsd thread currently doing something
13214a571a8SJeff Layton * with that delegation without holding the cl_lock
13314a571a8SJeff Layton *
13414a571a8SJeff Layton * If the server attempts to recall a delegation and the client doesn't do so
13514a571a8SJeff Layton * before a timeout, the server may also revoke the delegation. In that case,
13614a571a8SJeff Layton * the object will either be destroyed (v4.0) or moved to a per-client list of
13714a571a8SJeff Layton * revoked delegations (v4.1+).
13814a571a8SJeff Layton *
13914a571a8SJeff Layton * This object is a superset of the nfs4_stid.
14014a571a8SJeff Layton */
1419a74af21SBoaz Harrosh struct nfs4_delegation {
142996e0938SJ. Bruce Fields struct nfs4_stid dl_stid; /* must be first field */
1439a74af21SBoaz Harrosh struct list_head dl_perfile;
1449a74af21SBoaz Harrosh struct list_head dl_perclnt;
1459a74af21SBoaz Harrosh struct list_head dl_recall_lru; /* delegation recalled */
1468287f009SSachin Bhamare struct nfs4_clnt_odstate *dl_clnt_odstate;
1479a74af21SBoaz Harrosh u32 dl_type;
14820b7d86fSArnd Bergmann time64_t dl_time;
1499a74af21SBoaz Harrosh /* For recall: */
1509a74af21SBoaz Harrosh int dl_retries;
151227f98d9SJ. Bruce Fields struct nfsd4_callback dl_recall;
15266af2579SDai Ngo bool dl_recalled;
1539a74af21SBoaz Harrosh };
1549a74af21SBoaz Harrosh
15534549ab0SJeff Layton #define cb_to_delegation(cb) \
15634549ab0SJeff Layton container_of(cb, struct nfs4_delegation, dl_recall)
15734549ab0SJeff Layton
1589a74af21SBoaz Harrosh /* client delegation callback info */
1599a74af21SBoaz Harrosh struct nfs4_cb_conn {
1609a74af21SBoaz Harrosh /* SETCLIENTID info */
1619a74af21SBoaz Harrosh struct sockaddr_storage cb_addr;
1626f3d772fSTakuma Umeya struct sockaddr_storage cb_saddr;
1639a74af21SBoaz Harrosh size_t cb_addrlen;
1648b5ce5cdSJ. Bruce Fields u32 cb_prog; /* used only in 4.0 case;
1658b5ce5cdSJ. Bruce Fields per-session otherwise */
1669a74af21SBoaz Harrosh u32 cb_ident; /* minorversion 0 only */
1672bf23875SJ. Bruce Fields struct svc_xprt *cb_xprt; /* minorversion 1 only */
1689a74af21SBoaz Harrosh };
1699a74af21SBoaz Harrosh
delegstateid(struct nfs4_stid * s)170f459e453SJ. Bruce Fields static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
171f459e453SJ. Bruce Fields {
172f459e453SJ. Bruce Fields return container_of(s, struct nfs4_delegation, dl_stid);
173f459e453SJ. Bruce Fields }
174f459e453SJ. Bruce Fields
1759a74af21SBoaz Harrosh /* Maximum number of slots per session. 160 is useful for long haul TCP */
1769a74af21SBoaz Harrosh #define NFSD_MAX_SLOTS_PER_SESSION 160
1779a74af21SBoaz Harrosh /* Maximum number of operations per session compound */
17880e591ceSChuck Lever #define NFSD_MAX_OPS_PER_COMPOUND 50
1799a74af21SBoaz Harrosh /* Maximum session per slot cache size */
18024906f32SJ. Bruce Fields #define NFSD_SLOT_CACHE_SIZE 2048
1819a74af21SBoaz Harrosh /* Maximum number of NFSD_SLOT_CACHE_SIZE slots per session */
1829a74af21SBoaz Harrosh #define NFSD_CACHE_SIZE_SLOTS_PER_SESSION 32
1839a74af21SBoaz Harrosh #define NFSD_MAX_MEM_PER_SESSION \
1849a74af21SBoaz Harrosh (NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
1859a74af21SBoaz Harrosh
1869a74af21SBoaz Harrosh struct nfsd4_slot {
1879a74af21SBoaz Harrosh u32 sl_seqid;
1889a74af21SBoaz Harrosh __be32 sl_status;
18953da6a53SJ. Bruce Fields struct svc_cred sl_cred;
1909a74af21SBoaz Harrosh u32 sl_datalen;
19173e79482SJ. Bruce Fields u16 sl_opcnt;
19273e79482SJ. Bruce Fields #define NFSD4_SLOT_INUSE (1 << 0)
19373e79482SJ. Bruce Fields #define NFSD4_SLOT_CACHETHIS (1 << 1)
194bf5c43c8SJ. Bruce Fields #define NFSD4_SLOT_INITIALIZED (1 << 2)
195085def3aSJ. Bruce Fields #define NFSD4_SLOT_CACHED (1 << 3)
19673e79482SJ. Bruce Fields u8 sl_flags;
1979a74af21SBoaz Harrosh char sl_data[];
1989a74af21SBoaz Harrosh };
1999a74af21SBoaz Harrosh
2009a74af21SBoaz Harrosh struct nfsd4_channel_attrs {
2019a74af21SBoaz Harrosh u32 headerpadsz;
2029a74af21SBoaz Harrosh u32 maxreq_sz;
2039a74af21SBoaz Harrosh u32 maxresp_sz;
2049a74af21SBoaz Harrosh u32 maxresp_cached;
2059a74af21SBoaz Harrosh u32 maxops;
2069a74af21SBoaz Harrosh u32 maxreqs;
2079a74af21SBoaz Harrosh u32 nr_rdma_attrs;
2089a74af21SBoaz Harrosh u32 rdma_attrs;
2099a74af21SBoaz Harrosh };
2109a74af21SBoaz Harrosh
211acb2887eSJ. Bruce Fields struct nfsd4_cb_sec {
21212fc3e92SJ. Bruce Fields u32 flavor; /* (u32)(-1) used to mean "no valid flavor" */
21303bc6d1cSEric W. Biederman kuid_t uid;
21403bc6d1cSEric W. Biederman kgid_t gid;
215acb2887eSJ. Bruce Fields };
216acb2887eSJ. Bruce Fields
2179a74af21SBoaz Harrosh struct nfsd4_create_session {
2189a74af21SBoaz Harrosh clientid_t clientid;
2199a74af21SBoaz Harrosh struct nfs4_sessionid sessionid;
2209a74af21SBoaz Harrosh u32 seqid;
2219a74af21SBoaz Harrosh u32 flags;
2229a74af21SBoaz Harrosh struct nfsd4_channel_attrs fore_channel;
2239a74af21SBoaz Harrosh struct nfsd4_channel_attrs back_channel;
2249a74af21SBoaz Harrosh u32 callback_prog;
225acb2887eSJ. Bruce Fields struct nfsd4_cb_sec cb_sec;
2269a74af21SBoaz Harrosh };
2279a74af21SBoaz Harrosh
228cb73a9f4SJ. Bruce Fields struct nfsd4_backchannel_ctl {
229cb73a9f4SJ. Bruce Fields u32 bc_cb_program;
230cb73a9f4SJ. Bruce Fields struct nfsd4_cb_sec bc_cb_sec;
231cb73a9f4SJ. Bruce Fields };
232cb73a9f4SJ. Bruce Fields
2331d1bc8f2SJ. Bruce Fields struct nfsd4_bind_conn_to_session {
2341d1bc8f2SJ. Bruce Fields struct nfs4_sessionid sessionid;
2351d1bc8f2SJ. Bruce Fields u32 dir;
2361d1bc8f2SJ. Bruce Fields };
2371d1bc8f2SJ. Bruce Fields
2389a74af21SBoaz Harrosh /* The single slot clientid cache structure */
2399a74af21SBoaz Harrosh struct nfsd4_clid_slot {
2409a74af21SBoaz Harrosh u32 sl_seqid;
2419a74af21SBoaz Harrosh __be32 sl_status;
2429a74af21SBoaz Harrosh struct nfsd4_create_session sl_cr_ses;
2439a74af21SBoaz Harrosh };
2449a74af21SBoaz Harrosh
245c7662518SJ. Bruce Fields struct nfsd4_conn {
246c7662518SJ. Bruce Fields struct list_head cn_persession;
247c7662518SJ. Bruce Fields struct svc_xprt *cn_xprt;
24819cf5c02SJ. Bruce Fields struct svc_xpt_user cn_xpt_user;
24919cf5c02SJ. Bruce Fields struct nfsd4_session *cn_session;
250c7662518SJ. Bruce Fields /* CDFC4_FORE, CDFC4_BACK: */
251c7662518SJ. Bruce Fields unsigned char cn_flags;
252c7662518SJ. Bruce Fields };
253c7662518SJ. Bruce Fields
25414a571a8SJeff Layton /*
25514a571a8SJeff Layton * Representation of a v4.1+ session. These are refcounted in a similar fashion
25614a571a8SJeff Layton * to the nfs4_client. References are only taken when the server is actively
25714a571a8SJeff Layton * working on the object (primarily during the processing of compounds).
25814a571a8SJeff Layton */
2599a74af21SBoaz Harrosh struct nfsd4_session {
26066b2b9b2SJ. Bruce Fields atomic_t se_ref;
2619a74af21SBoaz Harrosh struct list_head se_hash; /* hash by sessionid */
2629a74af21SBoaz Harrosh struct list_head se_perclnt;
26366b2b9b2SJ. Bruce Fields /* See SESSION4_PERSIST, etc. for standard flags; this is internal-only: */
26466b2b9b2SJ. Bruce Fields #define NFS4_SESSION_DEAD 0x010
2659a74af21SBoaz Harrosh u32 se_flags;
26607cd4909SBenny Halevy struct nfs4_client *se_client;
2679a74af21SBoaz Harrosh struct nfs4_sessionid se_sessionid;
2689a74af21SBoaz Harrosh struct nfsd4_channel_attrs se_fchannel;
2699a74af21SBoaz Harrosh struct nfsd4_channel_attrs se_bchannel;
270acb2887eSJ. Bruce Fields struct nfsd4_cb_sec se_cb_sec;
271c7662518SJ. Bruce Fields struct list_head se_conns;
2728b5ce5cdSJ. Bruce Fields u32 se_cb_prog;
273ac7c46f2SJ. Bruce Fields u32 se_cb_seq_nr;
2749a74af21SBoaz Harrosh struct nfsd4_slot *se_slots[]; /* forward channel slots */
2759a74af21SBoaz Harrosh };
2769a74af21SBoaz Harrosh
2779a74af21SBoaz Harrosh /* formatted contents of nfs4_sessionid */
2789a74af21SBoaz Harrosh struct nfsd4_sessionid {
2799a74af21SBoaz Harrosh clientid_t clientid;
2809a74af21SBoaz Harrosh u32 sequence;
2819a74af21SBoaz Harrosh u32 reserved;
2829a74af21SBoaz Harrosh };
2839a74af21SBoaz Harrosh
2849a74af21SBoaz Harrosh #define HEXDIR_LEN 33 /* hex version of 16 byte md5 of cl_name plus '\0' */
2859a74af21SBoaz Harrosh
2869a74af21SBoaz Harrosh /*
28766af2579SDai Ngo * State Meaning Where set
28866af2579SDai Ngo * --------------------------------------------------------------------------
28966af2579SDai Ngo * | NFSD4_ACTIVE | Confirmed, active | Default |
29066af2579SDai Ngo * |------------------- ----------------------------------------------------|
29166af2579SDai Ngo * | NFSD4_COURTESY | Courtesy state. | nfs4_get_client_reaplist |
29266af2579SDai Ngo * | | Lease/lock/share | |
29366af2579SDai Ngo * | | reservation conflict | |
29466af2579SDai Ngo * | | can cause Courtesy | |
29566af2579SDai Ngo * | | client to be expired | |
29666af2579SDai Ngo * |------------------------------------------------------------------------|
29766af2579SDai Ngo * | NFSD4_EXPIRABLE | Courtesy client to be| nfs4_laundromat |
29866af2579SDai Ngo * | | expired by Laundromat| try_to_expire_client |
29966af2579SDai Ngo * | | due to conflict | |
30066af2579SDai Ngo * |------------------------------------------------------------------------|
30166af2579SDai Ngo */
30266af2579SDai Ngo enum {
30366af2579SDai Ngo NFSD4_ACTIVE = 0,
30466af2579SDai Ngo NFSD4_COURTESY,
30566af2579SDai Ngo NFSD4_EXPIRABLE,
30666af2579SDai Ngo };
30766af2579SDai Ngo
30866af2579SDai Ngo /*
3099a74af21SBoaz Harrosh * struct nfs4_client - one per client. Clientids live here.
3109a74af21SBoaz Harrosh *
31114a571a8SJeff Layton * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
31214a571a8SJeff Layton * or EXCHANGE_ID (for NFSv4.1+). These objects are refcounted and timestamped.
31314a571a8SJeff Layton * Each nfsd_net_ns object contains a set of these and they are tracked via
31414a571a8SJeff Layton * short and long form clientid. They are hashed and searched for under the
31514a571a8SJeff Layton * per-nfsd_net client_lock spinlock.
31614a571a8SJeff Layton *
31714a571a8SJeff Layton * References to it are only held during the processing of compounds, and in
31814a571a8SJeff Layton * certain other operations. In their "resting state" they have a refcount of
31914a571a8SJeff Layton * 0. If they are not renewed within a lease period, they become eligible for
32014a571a8SJeff Layton * destruction by the laundromat.
32114a571a8SJeff Layton *
32214a571a8SJeff Layton * These objects can also be destroyed prematurely by the fault injection code,
32314a571a8SJeff Layton * or if the client sends certain forms of SETCLIENTID or EXCHANGE_ID updates.
32414a571a8SJeff Layton * Care is taken *not* to do this however when the objects have an elevated
32514a571a8SJeff Layton * refcount.
32614a571a8SJeff Layton *
32714a571a8SJeff Layton * o Each nfs4_client is hashed by clientid
32814a571a8SJeff Layton *
32914a571a8SJeff Layton * o Each nfs4_clients is also hashed by name (the opaque quantity initially
33014a571a8SJeff Layton * sent by the client to identify itself).
3319a74af21SBoaz Harrosh *
3329a74af21SBoaz Harrosh * o cl_perclient list is used to ensure no dangling stateowner references
3339a74af21SBoaz Harrosh * when we expire the nfs4_client
3349a74af21SBoaz Harrosh */
3359a74af21SBoaz Harrosh struct nfs4_client {
3369a74af21SBoaz Harrosh struct list_head cl_idhash; /* hash by cl_clientid.id */
337ac55fdc4SJeff Layton struct rb_node cl_namenode; /* link into by-name trees */
338d4f0489fSTrond Myklebust struct list_head *cl_ownerstr_hashtbl;
3399a74af21SBoaz Harrosh struct list_head cl_openowners;
34038c2f4b1SJ. Bruce Fields struct idr cl_stateids; /* stateid lookup */
3419a74af21SBoaz Harrosh struct list_head cl_delegations;
3423bd64a5bSJ. Bruce Fields struct list_head cl_revoked; /* unacknowledged, revoked 4.1 state */
3439a74af21SBoaz Harrosh struct list_head cl_lru; /* tail queue */
3449cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
3459cf514ccSChristoph Hellwig struct list_head cl_lo_states; /* outstanding layout states */
3469cf514ccSChristoph Hellwig #endif
3479a74af21SBoaz Harrosh struct xdr_netobj cl_name; /* id generated by client */
3489a74af21SBoaz Harrosh nfs4_verifier cl_verifier; /* generated by client */
34920b7d86fSArnd Bergmann time64_t cl_time; /* time of last lease renewal */
3509a74af21SBoaz Harrosh struct sockaddr_storage cl_addr; /* client ipaddress */
35157266a6eSJ. Bruce Fields bool cl_mach_cred; /* SP4_MACH_CRED in force */
3529a74af21SBoaz Harrosh struct svc_cred cl_cred; /* setclientid principal */
3539a74af21SBoaz Harrosh clientid_t cl_clientid; /* generated by server */
3549a74af21SBoaz Harrosh nfs4_verifier cl_confirm; /* generated by server */
3558323c3b2SJ. Bruce Fields u32 cl_minorversion;
35679123444SJ. Bruce Fields /* NFSv4.1 client implementation id: */
35779123444SJ. Bruce Fields struct xdr_netobj cl_nii_domain;
35879123444SJ. Bruce Fields struct xdr_netobj cl_nii_name;
359e29f4703SArnd Bergmann struct timespec64 cl_nii_time;
3609a74af21SBoaz Harrosh
3612bf23875SJ. Bruce Fields /* for v4.0 and v4.1 callbacks: */
3622bf23875SJ. Bruce Fields struct nfs4_cb_conn cl_cb_conn;
363a52d726bSJeff Layton #define NFSD4_CLIENT_CB_UPDATE (0)
364a52d726bSJeff Layton #define NFSD4_CLIENT_CB_KILL (1)
365a52d726bSJeff Layton #define NFSD4_CLIENT_STABLE (2) /* client on stable storage */
366a52d726bSJeff Layton #define NFSD4_CLIENT_RECLAIM_COMPLETE (3) /* reclaim_complete done */
367ac55fdc4SJeff Layton #define NFSD4_CLIENT_CONFIRMED (4) /* client is confirmed */
368d682e750SJeff Layton #define NFSD4_CLIENT_UPCALL_LOCK (5) /* upcall serialization */
369a52d726bSJeff Layton #define NFSD4_CLIENT_CB_FLAG_MASK (1 << NFSD4_CLIENT_CB_UPDATE | \
370a52d726bSJeff Layton 1 << NFSD4_CLIENT_CB_KILL)
37144df6f43SDai Ngo #define NFSD4_CLIENT_CB_RECALL_ANY (6)
372a52d726bSJeff Layton unsigned long cl_flags;
373a52458b4SNeilBrown const struct cred *cl_cb_cred;
3742bf23875SJ. Bruce Fields struct rpc_clnt *cl_cb_client;
3756ff8da08SJ. Bruce Fields u32 cl_cb_ident;
37677a3569dSJ. Bruce Fields #define NFSD4_CB_UP 0
37777a3569dSJ. Bruce Fields #define NFSD4_CB_UNKNOWN 1
37877a3569dSJ. Bruce Fields #define NFSD4_CB_DOWN 2
3795423732aSBenny Halevy #define NFSD4_CB_FAULT 3
38077a3569dSJ. Bruce Fields int cl_cb_state;
381cee277d9SJ. Bruce Fields struct nfsd4_callback cl_cb_null;
382edd76786SJ. Bruce Fields struct nfsd4_session *cl_cb_session;
3832bf23875SJ. Bruce Fields
3846ff8da08SJ. Bruce Fields /* for all client information that callback code might need: */
3856ff8da08SJ. Bruce Fields spinlock_t cl_lock;
3866ff8da08SJ. Bruce Fields
3879a74af21SBoaz Harrosh /* for nfs41 */
3889a74af21SBoaz Harrosh struct list_head cl_sessions;
3899a74af21SBoaz Harrosh struct nfsd4_clid_slot cl_cs_slot; /* create_session slot */
3909a74af21SBoaz Harrosh u32 cl_exchange_flags;
39146583e25SBenny Halevy /* number of rpc's in progress over an associated session: */
39214ed14ccSJ. Bruce Fields atomic_t cl_rpc_users;
393e8a79fb1SJ. Bruce Fields struct nfsdfs_client cl_nfsdfs;
394ed941643SAndrew Elble struct nfs4_op_map cl_spo_must_allow;
3959a74af21SBoaz Harrosh
396e8a79fb1SJ. Bruce Fields /* debugging info directory under nfsd/clients/ : */
397e8a79fb1SJ. Bruce Fields struct dentry *cl_nfsd_dentry;
398472d155aSNeilBrown /* 'info' file within that directory. Ref is not counted,
399472d155aSNeilBrown * but will remain valid iff cl_nfsd_dentry != NULL
400472d155aSNeilBrown */
401472d155aSNeilBrown struct dentry *cl_nfsd_info_dentry;
402e8a79fb1SJ. Bruce Fields
4039a74af21SBoaz Harrosh /* for nfs41 callbacks */
4049a74af21SBoaz Harrosh /* We currently support a single back channel with a single slot */
4059a74af21SBoaz Harrosh unsigned long cl_cb_slot_busy;
4069a74af21SBoaz Harrosh struct rpc_wait_queue cl_cb_waitq; /* backchannel callers may */
4079a74af21SBoaz Harrosh /* wait here for slots */
408c212cecfSStanislav Kinsbursky struct net *net;
409e0639dc5SOlga Kornievskaia struct list_head async_copies; /* list of async copies */
410e0639dc5SOlga Kornievskaia spinlock_t async_lock; /* lock for async copies */
4112bbfed98STrond Myklebust atomic_t cl_cb_inflight; /* Outstanding callbacks */
41266af2579SDai Ngo
41366af2579SDai Ngo unsigned int cl_state;
41466af2579SDai Ngo atomic_t cl_delegs_in_recall;
41544df6f43SDai Ngo
41644df6f43SDai Ngo struct nfsd4_cb_recall_any *cl_ra;
41744df6f43SDai Ngo time64_t cl_ra_time;
41844df6f43SDai Ngo struct list_head cl_ra_cblist;
4199a74af21SBoaz Harrosh };
4209a74af21SBoaz Harrosh
4219a74af21SBoaz Harrosh /* struct nfs4_client_reset
4229a74af21SBoaz Harrosh * one per old client. Populates reset_str_hashtbl. Filled from conf_id_hashtbl
4239a74af21SBoaz Harrosh * upon lease reset, or from upcall to state_daemon (to read in state
4249a74af21SBoaz Harrosh * from non-volitile storage) upon reboot.
4259a74af21SBoaz Harrosh */
4269a74af21SBoaz Harrosh struct nfs4_client_reclaim {
4279a74af21SBoaz Harrosh struct list_head cr_strhash; /* hash by cr_name */
4280ce0c2b5SJeff Layton struct nfs4_client *cr_clp; /* pointer to associated clp */
4296b189105SScott Mayhew struct xdr_netobj cr_name; /* recovery dir name */
4306ee95d1cSScott Mayhew struct xdr_netobj cr_princhash;
4319a74af21SBoaz Harrosh };
4329a74af21SBoaz Harrosh
4339a74af21SBoaz Harrosh /* A reasonable value for REPLAY_ISIZE was estimated as follows:
4349a74af21SBoaz Harrosh * The OPEN response, typically the largest, requires
4359a74af21SBoaz Harrosh * 4(status) + 8(stateid) + 20(changeinfo) + 4(rflags) + 8(verifier) +
4369a74af21SBoaz Harrosh * 4(deleg. type) + 8(deleg. stateid) + 4(deleg. recall flag) +
4379a74af21SBoaz Harrosh * 20(deleg. space limit) + ~32(deleg. ace) = 112 bytes
4389a74af21SBoaz Harrosh */
4399a74af21SBoaz Harrosh
4409a74af21SBoaz Harrosh #define NFSD4_REPLAY_ISIZE 112
4419a74af21SBoaz Harrosh
4429a74af21SBoaz Harrosh /*
4439a74af21SBoaz Harrosh * Replay buffer, where the result of the last seqid-mutating operation
4449a74af21SBoaz Harrosh * is cached.
4459a74af21SBoaz Harrosh */
4469a74af21SBoaz Harrosh struct nfs4_replay {
4479a74af21SBoaz Harrosh __be32 rp_status;
4489a74af21SBoaz Harrosh unsigned int rp_buflen;
4499a74af21SBoaz Harrosh char *rp_buf;
4509a74af21SBoaz Harrosh struct knfsd_fh rp_openfh;
45158fb12e6SJeff Layton struct mutex rp_mutex;
4529a74af21SBoaz Harrosh char rp_ibuf[NFSD4_REPLAY_ISIZE];
4539a74af21SBoaz Harrosh };
4549a74af21SBoaz Harrosh
4556b180f0bSJeff Layton struct nfs4_stateowner;
4566b180f0bSJeff Layton
4576b180f0bSJeff Layton struct nfs4_stateowner_operations {
4588f4b54c5SJeff Layton void (*so_unhash)(struct nfs4_stateowner *);
4596b180f0bSJeff Layton void (*so_free)(struct nfs4_stateowner *);
4606b180f0bSJeff Layton };
4616b180f0bSJeff Layton
46214a571a8SJeff Layton /*
46314a571a8SJeff Layton * A core object that represents either an open or lock owner. The object and
46414a571a8SJeff Layton * lock owner objects have one of these embedded within them. Refcounts and
46514a571a8SJeff Layton * other fields common to both owner types are contained within these
46614a571a8SJeff Layton * structures.
46714a571a8SJeff Layton */
4689a74af21SBoaz Harrosh struct nfs4_stateowner {
4696b180f0bSJeff Layton struct list_head so_strhash;
4709a74af21SBoaz Harrosh struct list_head so_stateids;
4719a74af21SBoaz Harrosh struct nfs4_client *so_client;
4726b180f0bSJeff Layton const struct nfs4_stateowner_operations *so_ops;
47383e452feSJ. Bruce Fields /* after increment in nfsd4_bump_seqid, represents the next
4749a74af21SBoaz Harrosh * sequence id expected from the client: */
4756b180f0bSJeff Layton atomic_t so_count;
4769a74af21SBoaz Harrosh u32 so_seqid;
4779a74af21SBoaz Harrosh struct xdr_netobj so_owner; /* open owner name */
4789a74af21SBoaz Harrosh struct nfs4_replay so_replay;
4793557e43bSJ. Bruce Fields bool so_is_open_owner;
4809a74af21SBoaz Harrosh };
4819a74af21SBoaz Harrosh
48214a571a8SJeff Layton /*
48314a571a8SJeff Layton * When a file is opened, the client provides an open state owner opaque string
48414a571a8SJeff Layton * that indicates the "owner" of that open. These objects are refcounted.
48514a571a8SJeff Layton * References to it are held by each open state associated with it. This object
48614a571a8SJeff Layton * is a superset of the nfs4_stateowner struct.
48714a571a8SJeff Layton */
488fe0750e5SJ. Bruce Fields struct nfs4_openowner {
489fe0750e5SJ. Bruce Fields struct nfs4_stateowner oo_owner; /* must be first field */
490fe0750e5SJ. Bruce Fields struct list_head oo_perclient;
491b31b30e5SJ. Bruce Fields /*
492b31b30e5SJ. Bruce Fields * We keep around openowners a little while after last close,
493b31b30e5SJ. Bruce Fields * which saves clients from having to confirm, and allows us to
494b31b30e5SJ. Bruce Fields * handle close replays if they come soon enough. The close_lru
495b31b30e5SJ. Bruce Fields * is a list of such openowners, to be reaped by the laundromat
496b31b30e5SJ. Bruce Fields * thread eventually if they remain unused:
497b31b30e5SJ. Bruce Fields */
498b31b30e5SJ. Bruce Fields struct list_head oo_close_lru;
49938c387b5SJ. Bruce Fields struct nfs4_ol_stateid *oo_last_closed_stid;
50020b7d86fSArnd Bergmann time64_t oo_time; /* time of placement on so_close_lru */
501dad1c067SJ. Bruce Fields #define NFS4_OO_CONFIRMED 1
502dad1c067SJ. Bruce Fields unsigned char oo_flags;
503fe0750e5SJ. Bruce Fields };
504fe0750e5SJ. Bruce Fields
50514a571a8SJeff Layton /*
50614a571a8SJeff Layton * Represents a generic "lockowner". Similar to an openowner. References to it
50714a571a8SJeff Layton * are held by the lock stateids that are created on its behalf. This object is
50876d348faSJeff Layton * a superset of the nfs4_stateowner struct.
50914a571a8SJeff Layton */
510fe0750e5SJ. Bruce Fields struct nfs4_lockowner {
511fe0750e5SJ. Bruce Fields struct nfs4_stateowner lo_owner; /* must be first element */
51276d348faSJeff Layton struct list_head lo_blocked; /* blocked file_locks */
513fe0750e5SJ. Bruce Fields };
514fe0750e5SJ. Bruce Fields
openowner(struct nfs4_stateowner * so)515fe0750e5SJ. Bruce Fields static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
516fe0750e5SJ. Bruce Fields {
517fe0750e5SJ. Bruce Fields return container_of(so, struct nfs4_openowner, oo_owner);
518fe0750e5SJ. Bruce Fields }
519fe0750e5SJ. Bruce Fields
lockowner(struct nfs4_stateowner * so)520fe0750e5SJ. Bruce Fields static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
521fe0750e5SJ. Bruce Fields {
522fe0750e5SJ. Bruce Fields return container_of(so, struct nfs4_lockowner, lo_owner);
523fe0750e5SJ. Bruce Fields }
524fe0750e5SJ. Bruce Fields
52514a571a8SJeff Layton /*
5268287f009SSachin Bhamare * Per-client state indicating no. of opens and outstanding delegations
5278287f009SSachin Bhamare * on a file from a particular client.'od' stands for 'open & delegation'
5288287f009SSachin Bhamare */
5298287f009SSachin Bhamare struct nfs4_clnt_odstate {
5308287f009SSachin Bhamare struct nfs4_client *co_client;
5318287f009SSachin Bhamare struct nfs4_file *co_file;
5328287f009SSachin Bhamare struct list_head co_perfile;
533cff7cb2eSElena Reshetova refcount_t co_odcount;
5348287f009SSachin Bhamare };
5358287f009SSachin Bhamare
5368287f009SSachin Bhamare /*
53714a571a8SJeff Layton * nfs4_file: a file opened by some number of (open) nfs4_stateowners.
53814a571a8SJeff Layton *
539ccc6398eSJeff Layton * These objects are global. nfsd keeps one instance of a nfs4_file per
540ccc6398eSJeff Layton * filehandle (though it may keep multiple file descriptors for each). Each
541ccc6398eSJeff Layton * inode can have multiple filehandles associated with it, so there is
542ccc6398eSJeff Layton * (potentially) a many to one relationship between this struct and struct
543ccc6398eSJeff Layton * inode.
54414a571a8SJeff Layton */
5459a74af21SBoaz Harrosh struct nfs4_file {
546818a34ebSElena Reshetova refcount_t fi_ref;
547a0ce4837SJ. Bruce Fields struct inode * fi_inode;
548a0ce4837SJ. Bruce Fields bool fi_aliased;
5491d31a253STrond Myklebust spinlock_t fi_lock;
550d47b295eSChuck Lever struct rhlist_head fi_rlist;
5519a74af21SBoaz Harrosh struct list_head fi_stateids;
5525b095e99SJeff Layton union {
5539a74af21SBoaz Harrosh struct list_head fi_delegations;
5545b095e99SJeff Layton struct rcu_head fi_rcu;
5555b095e99SJeff Layton };
5568287f009SSachin Bhamare struct list_head fi_clnt_odstate;
557f9d7562fSJ. Bruce Fields /* One each for O_RDONLY, O_WRONLY, O_RDWR: */
558fd4f83fdSJeff Layton struct nfsd_file *fi_fds[3];
559f9d7562fSJ. Bruce Fields /*
5606409a5a6SJ. Bruce Fields * Each open or lock stateid contributes 0-4 to the counts
5616409a5a6SJ. Bruce Fields * below depending on which bits are set in st_access_bitmap:
5626409a5a6SJ. Bruce Fields * 1 to fi_access[O_RDONLY] if NFS4_SHARE_ACCES_READ is set
5636409a5a6SJ. Bruce Fields * + 1 to fi_access[O_WRONLY] if NFS4_SHARE_ACCESS_WRITE is set
5646409a5a6SJ. Bruce Fields * + 1 to both of the above if NFS4_SHARE_ACCESS_BOTH is set.
565f9d7562fSJ. Bruce Fields */
5669ae78bccSJ. Bruce Fields atomic_t fi_access[2];
567baeb4ff0SJeff Layton u32 fi_share_deny;
568eb82dd39SJeff Layton struct nfsd_file *fi_deleg_file;
56967db1034SJeff Layton int fi_delegees;
570e2cf80d7STrond Myklebust struct knfsd_fh fi_fhandle;
5719a74af21SBoaz Harrosh bool fi_had_conflict;
5729cf514ccSChristoph Hellwig #ifdef CONFIG_NFSD_PNFS
5739cf514ccSChristoph Hellwig struct list_head fi_lo_states;
574c5c707f9SChristoph Hellwig atomic_t fi_lo_recalls;
5759cf514ccSChristoph Hellwig #endif
5769a74af21SBoaz Harrosh };
5779a74af21SBoaz Harrosh
57814a571a8SJeff Layton /*
57914a571a8SJeff Layton * A generic struct representing either a open or lock stateid. The nfs4_client
58014a571a8SJeff Layton * holds a reference to each of these objects, and they in turn hold a
58114a571a8SJeff Layton * reference to their respective stateowners. The client's reference is
58214a571a8SJeff Layton * released in response to a close or unlock (depending on whether it's an open
58314a571a8SJeff Layton * or lock stateid) or when the client is being destroyed.
58414a571a8SJeff Layton *
58514a571a8SJeff Layton * In the case of v4.0 open stateids, these objects are preserved for a little
58614a571a8SJeff Layton * while after close in order to handle CLOSE replays. Those are eventually
58714a571a8SJeff Layton * reclaimed via a LRU scheme by the laundromat.
58814a571a8SJeff Layton *
58914a571a8SJeff Layton * This object is a superset of the nfs4_stid. "ol" stands for "Open or Lock".
59014a571a8SJeff Layton * Better suggestions welcome.
59114a571a8SJeff Layton */
592dcef0413SJ. Bruce Fields struct nfs4_ol_stateid {
59335a92fe8SJeff Layton struct nfs4_stid st_stid;
5949a74af21SBoaz Harrosh struct list_head st_perfile;
5959a74af21SBoaz Harrosh struct list_head st_perstateowner;
5963c87b9b7STrond Myklebust struct list_head st_locks;
5979a74af21SBoaz Harrosh struct nfs4_stateowner *st_stateowner;
5988287f009SSachin Bhamare struct nfs4_clnt_odstate *st_clnt_odstate;
5993dcd1d8aSJ. Bruce Fields /*
6003dcd1d8aSJ. Bruce Fields * These bitmasks use 3 separate bits for READ, ALLOW, and BOTH; see the
6013dcd1d8aSJ. Bruce Fields * comment above bmap_to_share_mode() for explanation:
6023dcd1d8aSJ. Bruce Fields */
603c11c591fSJeff Layton unsigned char st_access_bmap;
604c11c591fSJeff Layton unsigned char st_deny_bmap;
605dcef0413SJ. Bruce Fields struct nfs4_ol_stateid *st_openstp;
606feb9dad5SOleg Drokin struct mutex st_mutex;
6079a74af21SBoaz Harrosh };
6089a74af21SBoaz Harrosh
openlockstateid(struct nfs4_stid * s)609dcef0413SJ. Bruce Fields static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
610dcef0413SJ. Bruce Fields {
611dcef0413SJ. Bruce Fields return container_of(s, struct nfs4_ol_stateid, st_stid);
612dcef0413SJ. Bruce Fields }
613dcef0413SJ. Bruce Fields
6149cf514ccSChristoph Hellwig struct nfs4_layout_stateid {
6159cf514ccSChristoph Hellwig struct nfs4_stid ls_stid;
6169cf514ccSChristoph Hellwig struct list_head ls_perclnt;
6179cf514ccSChristoph Hellwig struct list_head ls_perfile;
6189cf514ccSChristoph Hellwig spinlock_t ls_lock;
6199cf514ccSChristoph Hellwig struct list_head ls_layouts;
6209cf514ccSChristoph Hellwig u32 ls_layout_type;
621eb82dd39SJeff Layton struct nfsd_file *ls_file;
622c5c707f9SChristoph Hellwig struct nfsd4_callback ls_recall;
623c5c707f9SChristoph Hellwig stateid_t ls_recall_sid;
624c5c707f9SChristoph Hellwig bool ls_recalled;
625cc8a5532SJeff Layton struct mutex ls_mutex;
6269cf514ccSChristoph Hellwig };
6279cf514ccSChristoph Hellwig
layoutstateid(struct nfs4_stid * s)6289cf514ccSChristoph Hellwig static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
6299cf514ccSChristoph Hellwig {
6309cf514ccSChristoph Hellwig return container_of(s, struct nfs4_layout_stateid, ls_stid);
6319cf514ccSChristoph Hellwig }
6329cf514ccSChristoph Hellwig
6339a74af21SBoaz Harrosh /* flags for preprocess_seqid_op() */
6349a74af21SBoaz Harrosh #define RD_STATE 0x00000010
6359a74af21SBoaz Harrosh #define WR_STATE 0x00000020
6369a74af21SBoaz Harrosh
637326129d0SChristoph Hellwig enum nfsd4_cb_op {
638326129d0SChristoph Hellwig NFSPROC4_CLNT_CB_NULL = 0,
639326129d0SChristoph Hellwig NFSPROC4_CLNT_CB_RECALL,
640c5c707f9SChristoph Hellwig NFSPROC4_CLNT_CB_LAYOUT,
6419eb190fcSOlga Kornievskaia NFSPROC4_CLNT_CB_OFFLOAD,
642326129d0SChristoph Hellwig NFSPROC4_CLNT_CB_SEQUENCE,
643a188620eSJeff Layton NFSPROC4_CLNT_CB_NOTIFY_LOCK,
6443959066bSDai Ngo NFSPROC4_CLNT_CB_RECALL_ANY,
645326129d0SChristoph Hellwig };
646326129d0SChristoph Hellwig
64714b7f4a1SJeff Layton /* Returns true iff a is later than b: */
nfsd4_stateid_generation_after(stateid_t * a,stateid_t * b)64814b7f4a1SJeff Layton static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
64914b7f4a1SJeff Layton {
65014b7f4a1SJeff Layton return (s32)(a->si_generation - b->si_generation) > 0;
65114b7f4a1SJeff Layton }
652326129d0SChristoph Hellwig
65376d348faSJeff Layton /*
65476d348faSJeff Layton * When a client tries to get a lock on a file, we set one of these objects
65576d348faSJeff Layton * on the blocking lock. When the lock becomes free, we can then issue a
65676d348faSJeff Layton * CB_NOTIFY_LOCK to the server.
65776d348faSJeff Layton */
658a188620eSJeff Layton struct nfsd4_blocked_lock {
65976d348faSJeff Layton struct list_head nbl_list;
6607919d0a2SJeff Layton struct list_head nbl_lru;
66120b7d86fSArnd Bergmann time64_t nbl_time;
662a188620eSJeff Layton struct file_lock nbl_lock;
663a188620eSJeff Layton struct knfsd_fh nbl_fh;
664a188620eSJeff Layton struct nfsd4_callback nbl_cb;
66547446d74SVasily Averin struct kref nbl_kref;
666a188620eSJeff Layton };
667a188620eSJeff Layton
6689a74af21SBoaz Harrosh struct nfsd4_compound_state;
6692c142baaSStanislav Kinsbursky struct nfsd_net;
670e0639dc5SOlga Kornievskaia struct nfsd4_copy;
6719a74af21SBoaz Harrosh
672af90f707SChristoph Hellwig extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
673aa0d6aedSAnna Schumaker struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
674624322f1SOlga Kornievskaia stateid_t *stateid, int flags, struct nfsd_file **filp,
675624322f1SOlga Kornievskaia struct nfs4_stid **cstid);
676cd61c522SChristoph Hellwig __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
677cd61c522SChristoph Hellwig stateid_t *stateid, unsigned char typemask,
678cd61c522SChristoph Hellwig struct nfs4_stid **s, struct nfsd_net *nn);
679d19fb70dSKinglong Mee struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cache *slab,
680d19fb70dSKinglong Mee void (*sc_free)(struct nfs4_stid *));
681624322f1SOlga Kornievskaia int nfs4_init_copy_state(struct nfsd_net *nn, struct nfsd4_copy *copy);
682624322f1SOlga Kornievskaia void nfs4_free_copy_state(struct nfsd4_copy *copy);
683624322f1SOlga Kornievskaia struct nfs4_cpntf_state *nfs4_alloc_init_cpntf_state(struct nfsd_net *nn,
684624322f1SOlga Kornievskaia struct nfs4_stid *p_stid);
685cd61c522SChristoph Hellwig void nfs4_unhash_stid(struct nfs4_stid *s);
6866011695dSTrond Myklebust void nfs4_put_stid(struct nfs4_stid *s);
6879767feb2SJeff Layton void nfs4_inc_and_copy_stateid(stateid_t *dst, struct nfs4_stid *stid);
68852e19c09SStanislav Kinsbursky void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
68952e19c09SStanislav Kinsbursky extern void nfs4_release_reclaim(struct nfsd_net *);
6906b189105SScott Mayhew extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(struct xdr_netobj name,
69152e19c09SStanislav Kinsbursky struct nfsd_net *nn);
6921722b046SJ. Bruce Fields extern __be32 nfs4_check_open_reclaim(struct nfs4_client *);
6935a3c9d71SJ. Bruce Fields extern void nfsd4_probe_callback(struct nfs4_client *clp);
69484f5f7ccSJ. Bruce Fields extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
6955a3c9d71SJ. Bruce Fields extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
696f0b5de1bSChristoph Hellwig extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
697c4cb8974SJulia Lawall const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
698b95239caSJeff Layton extern bool nfsd4_run_cb(struct nfsd4_callback *cb);
699b5a1a81eSJ. Bruce Fields extern int nfsd4_create_callback_queue(void);
700b5a1a81eSJ. Bruce Fields extern void nfsd4_destroy_callback_queue(void);
7016ff8da08SJ. Bruce Fields extern void nfsd4_shutdown_callback(struct nfs4_client *);
702e0639dc5SOlga Kornievskaia extern void nfsd4_shutdown_copy(struct nfs4_client *clp);
7036b189105SScott Mayhew extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(struct xdr_netobj name,
7046ee95d1cSScott Mayhew struct xdr_netobj princhash, struct nfsd_net *nn);
7056b189105SScott Mayhew extern bool nfs4_has_reclaimed_state(struct xdr_netobj name, struct nfsd_net *nn);
7069a74af21SBoaz Harrosh
707e6ba76e1SChristoph Hellwig void put_nfs4_file(struct nfs4_file *fi);
708624322f1SOlga Kornievskaia extern void nfs4_put_cpntf_state(struct nfsd_net *nn,
709624322f1SOlga Kornievskaia struct nfs4_cpntf_state *cps);
710ce0887acSOlga Kornievskaia extern __be32 manage_cpntf_state(struct nfsd_net *nn, stateid_t *st,
711ce0887acSOlga Kornievskaia struct nfs4_client *clp,
712ce0887acSOlga Kornievskaia struct nfs4_cpntf_state **cps);
get_nfs4_file(struct nfs4_file * fi)713e6ba76e1SChristoph Hellwig static inline void get_nfs4_file(struct nfs4_file *fi)
714e6ba76e1SChristoph Hellwig {
715818a34ebSElena Reshetova refcount_inc(&fi->fi_ref);
716e6ba76e1SChristoph Hellwig }
717eb82dd39SJeff Layton struct nfsd_file *find_any_file(struct nfs4_file *f);
718e6ba76e1SChristoph Hellwig
7197f5ef2e9SJeff Layton /* grace period management */
7207f5ef2e9SJeff Layton void nfsd4_end_grace(struct nfsd_net *nn);
7217f5ef2e9SJeff Layton
7222a4317c5SJeff Layton /* nfs4recover operations */
7232a4317c5SJeff Layton extern int nfsd4_client_tracking_init(struct net *net);
7242a4317c5SJeff Layton extern void nfsd4_client_tracking_exit(struct net *net);
7252a4317c5SJeff Layton extern void nfsd4_client_record_create(struct nfs4_client *clp);
7262a4317c5SJeff Layton extern void nfsd4_client_record_remove(struct nfs4_client *clp);
7272a4317c5SJeff Layton extern int nfsd4_client_record_check(struct nfs4_client *clp);
728919b8049SJeff Layton extern void nfsd4_record_grace_done(struct nfsd_net *nn);
729f3c7521fSBryan Schumaker
try_to_expire_client(struct nfs4_client * clp)73066af2579SDai Ngo static inline bool try_to_expire_client(struct nfs4_client *clp)
73166af2579SDai Ngo {
73266af2579SDai Ngo cmpxchg(&clp->cl_state, NFSD4_COURTESY, NFSD4_EXPIRABLE);
73366af2579SDai Ngo return clp->cl_state == NFSD4_EXPIRABLE;
73466af2579SDai Ngo }
735*fd19ca36SDai Ngo
736*fd19ca36SDai Ngo extern __be32 nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp,
737*fd19ca36SDai Ngo struct inode *inode);
7389a74af21SBoaz Harrosh #endif /* NFSD4_STATE_H */
739