Blame view

fs/nfsd/state.h 21.9 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
   *  Copyright (c) 2001 The Regents of the University of Michigan.
   *  All rights reserved.
   *
   *  Kendrick Smith <kmsmith@umich.edu>
   *  Andy Adamson <andros@umich.edu>
   *  
   *  Redistribution and use in source and binary forms, with or without
   *  modification, are permitted provided that the following conditions
   *  are met:
   *  
   *  1. Redistributions of source code must retain the above copyright
   *     notice, this list of conditions and the following disclaimer.
   *  2. Redistributions in binary form must reproduce the above copyright
   *     notice, this list of conditions and the following disclaimer in the
   *     documentation and/or other materials provided with the distribution.
   *  3. Neither the name of the University nor the names of its
   *     contributors may be used to endorse or promote products derived
   *     from this software without specific prior written permission.
   *
   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
   *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   */
  
  #ifndef _NFSD4_STATE_H
  #define _NFSD4_STATE_H
38c2f4b12   J. Bruce Fields   nfsd4: look up st...
37
  #include <linux/idr.h>
19cf5c026   J. Bruce Fields   nfsd4: use callba...
38
  #include <linux/sunrpc/svc_xprt.h>
1557aca79   J. Bruce Fields   nfsd: move most o...
39
  #include "nfsfh.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
43
44
45
46
  typedef struct {
  	u32             cl_boot;
  	u32             cl_id;
  } clientid_t;
  
  typedef struct {
d3b313a46   J. Bruce Fields   nfsd4: construct ...
47
48
  	clientid_t	so_clid;
  	u32		so_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
53
54
  } stateid_opaque_t;
  
  typedef struct {
  	u32                     si_generation;
  	stateid_opaque_t        si_opaque;
  } stateid_t;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55

8c10cbdb4   Benny Halevy   nfsd: use STATEID...
56
57
  #define STATEID_FMT	"(%08x/%08x/%08x/%08x)"
  #define STATEID_VAL(s) \
d3b313a46   J. Bruce Fields   nfsd4: construct ...
58
59
60
  	(s)->si_opaque.so_clid.cl_boot, \
  	(s)->si_opaque.so_clid.cl_id, \
  	(s)->si_opaque.so_id, \
8c10cbdb4   Benny Halevy   nfsd: use STATEID...
61
  	(s)->si_generation
227f98d98   J. Bruce Fields   nfsd4: preallocat...
62
  struct nfsd4_callback {
fb0039232   J. Bruce Fields   nfsd4: remove sep...
63
64
  	struct nfs4_client *cb_clp;
  	u32 cb_minorversion;
5878453db   J. Bruce Fields   nfsd4: generic ca...
65
  	struct rpc_message cb_msg;
0162ac2b9   Christoph Hellwig   nfsd: introduce n...
66
  	struct nfsd4_callback_ops *cb_ops;
b5a1a81e5   J. Bruce Fields   nfsd4: don't slee...
67
  	struct work_struct cb_work;
ef2a1b3e1   Christoph Hellwig   nfsd: split trans...
68
  	int cb_status;
cba5f62b1   Christoph Hellwig   nfsd: fix callbac...
69
  	bool cb_need_restart;
227f98d98   J. Bruce Fields   nfsd4: preallocat...
70
  };
0162ac2b9   Christoph Hellwig   nfsd: introduce n...
71
72
73
74
75
  struct nfsd4_callback_ops {
  	void (*prepare)(struct nfsd4_callback *);
  	int (*done)(struct nfsd4_callback *, struct rpc_task *);
  	void (*release)(struct nfsd4_callback *);
  };
14a571a8e   Jeff Layton   nfsd: add some co...
76
77
78
79
80
  /*
   * A core object that represents a "common" stateid. These are generally
   * embedded within the different (more specific) stateid objects and contain
   * fields that are of general use to any stateid.
   */
d5477a8db   J. Bruce Fields   nfsd4: add common...
81
  struct nfs4_stid {
72c0b0fb9   Trond Myklebust   nfsd: Move the de...
82
  	atomic_t sc_count;
d5477a8db   J. Bruce Fields   nfsd4: add common...
83
84
85
  #define NFS4_OPEN_STID 1
  #define NFS4_LOCK_STID 2
  #define NFS4_DELEG_STID 4
f7a4d8720   J. Bruce Fields   nfsd4: hash close...
86
87
  /* For an open stateid kept around *only* to process close replays: */
  #define NFS4_CLOSED_STID 8
3bd64a5ba   J. Bruce Fields   nfsd4: implement ...
88
89
  /* For a deleg stateid kept around only to process free_stateid's: */
  #define NFS4_REVOKED_DELEG_STID 16
b0fc29d6f   Trond Myklebust   nfsd: Ensure stat...
90
  #define NFS4_CLOSED_DELEG_STID 32
9cf514ccf   Christoph Hellwig   nfsd: implement p...
91
  #define NFS4_LAYOUT_STID 64
f7a4d8720   J. Bruce Fields   nfsd4: hash close...
92
  	unsigned char sc_type;
d5477a8db   J. Bruce Fields   nfsd4: add common...
93
  	stateid_t sc_stateid;
2a74aba79   J. Bruce Fields   nfsd4: move clien...
94
  	struct nfs4_client *sc_client;
11b9164ad   Trond Myklebust   nfsd: Add a struc...
95
  	struct nfs4_file *sc_file;
6011695da   Trond Myklebust   nfsd: Add referen...
96
  	void (*sc_free)(struct nfs4_stid *);
d5477a8db   J. Bruce Fields   nfsd4: add common...
97
  };
14a571a8e   Jeff Layton   nfsd: add some co...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  /*
   * Represents a delegation stateid. The nfs4_client holds references to these
   * and they are put when it is being destroyed or when the delegation is
   * returned by the client:
   *
   * o 1 reference as long as a delegation is still in force (taken when it's
   *   alloc'd, put when it's returned or revoked)
   *
   * o 1 reference as long as a recall rpc is in progress (taken when the lease
   *   is broken, put when the rpc exits)
   *
   * o 1 more ephemeral reference for each nfsd thread currently doing something
   *   with that delegation without holding the cl_lock
   *
   * If the server attempts to recall a delegation and the client doesn't do so
   * before a timeout, the server may also revoke the delegation. In that case,
   * the object will either be destroyed (v4.0) or moved to a per-client list of
   * revoked delegations (v4.1+).
   *
   * This object is a superset of the nfs4_stid.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
  struct nfs4_delegation {
996e09385   J. Bruce Fields   nfsd4: do idr pre...
120
  	struct nfs4_stid	dl_stid; /* must be first field */
ea1da636e   NeilBrown   [PATCH] knfsd: nf...
121
122
  	struct list_head	dl_perfile;
  	struct list_head	dl_perclnt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
  	struct list_head	dl_recall_lru;  /* delegation recalled */
8287f009b   Sachin Bhamare   nfsd: fix pNFS re...
124
  	struct nfs4_clnt_odstate *dl_clnt_odstate;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
  	u32			dl_type;
  	time_t			dl_time;
b53d40c50   J. Bruce Fields   nfsd4: eliminate ...
127
  /* For recall: */
3aea09dc9   J. Bruce Fields   nfsd4: track reca...
128
  	int			dl_retries;
227f98d98   J. Bruce Fields   nfsd4: preallocat...
129
  	struct nfsd4_callback	dl_recall;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
  };
34549ab09   Jeff Layton   nfsd: eliminate "...
131
132
  #define cb_to_delegation(cb) \
  	container_of(cb, struct nfs4_delegation, dl_recall)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
  /* client delegation callback info */
c237dc030   J. Bruce Fields   nfsd4: rename cal...
134
  struct nfs4_cb_conn {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
  	/* SETCLIENTID info */
aa9a4ec77   Jeff Layton   nfsd: convert nfs...
136
  	struct sockaddr_storage	cb_addr;
6f3d772fb   Takuma Umeya   nfs4: set source ...
137
  	struct sockaddr_storage	cb_saddr;
aa9a4ec77   Jeff Layton   nfsd: convert nfs...
138
  	size_t			cb_addrlen;
8b5ce5cd4   J. Bruce Fields   nfsd4: callback p...
139
140
  	u32                     cb_prog; /* used only in 4.0 case;
  					    per-session otherwise */
ab52ae6db   Andy Adamson   nfsd41: Backchann...
141
  	u32                     cb_ident;	/* minorversion 0 only */
2bf23875f   J. Bruce Fields   nfsd4: rearrange ...
142
  	struct svc_xprt		*cb_xprt;	/* minorversion 1 only */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
  };
f459e4535   J. Bruce Fields   nfsd4: hash deleg...
144
145
146
147
  static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
  {
  	return container_of(s, struct nfs4_delegation, dl_stid);
  }
a649637c7   Andy Adamson   nfsd41: bound for...
148
149
  /* Maximum number of slots per session. 160 is useful for long haul TCP */
  #define NFSD_MAX_SLOTS_PER_SESSION     160
ec6b5d7b5   Andy Adamson   nfsd41: create_se...
150
151
  /* Maximum number of operations per session compound */
  #define NFSD_MAX_OPS_PER_COMPOUND	16
557ce2646   Andy Adamson   nfsd41: replace p...
152
  /* Maximum  session per slot cache size */
24906f323   J. Bruce Fields   nfsd4: allow larg...
153
  #define NFSD_SLOT_CACHE_SIZE		2048
a649637c7   Andy Adamson   nfsd41: bound for...
154
155
156
157
  /* Maximum number of NFSD_SLOT_CACHE_SIZE slots per session */
  #define NFSD_CACHE_SIZE_SLOTS_PER_SESSION	32
  #define NFSD_MAX_MEM_PER_SESSION  \
  		(NFSD_CACHE_SIZE_SLOTS_PER_SESSION * NFSD_SLOT_CACHE_SIZE)
074fe8975   Andy Adamson   nfsd41: DRC save,...
158

7116ed6b9   Andy Adamson   nfsd41: sessions ...
159
  struct nfsd4_slot {
557ce2646   Andy Adamson   nfsd41: replace p...
160
161
162
  	u32	sl_seqid;
  	__be32	sl_status;
  	u32	sl_datalen;
73e79482b   J. Bruce Fields   nfsd4: rearrange ...
163
164
165
  	u16	sl_opcnt;
  #define NFSD4_SLOT_INUSE	(1 << 0)
  #define NFSD4_SLOT_CACHETHIS	(1 << 1)
bf5c43c8f   J. Bruce Fields   nfsd4: check for ...
166
  #define NFSD4_SLOT_INITIALIZED	(1 << 2)
73e79482b   J. Bruce Fields   nfsd4: rearrange ...
167
  	u8	sl_flags;
557ce2646   Andy Adamson   nfsd41: replace p...
168
  	char	sl_data[];
7116ed6b9   Andy Adamson   nfsd41: sessions ...
169
  };
6c18ba9f5   Alexandros Batsakis   nfsd41: move chan...
170
171
172
173
174
175
176
177
178
179
  struct nfsd4_channel_attrs {
  	u32		headerpadsz;
  	u32		maxreq_sz;
  	u32		maxresp_sz;
  	u32		maxresp_cached;
  	u32		maxops;
  	u32		maxreqs;
  	u32		nr_rdma_attrs;
  	u32		rdma_attrs;
  };
acb2887e0   J. Bruce Fields   nfsd4: clean up c...
180
  struct nfsd4_cb_sec {
12fc3e92d   J. Bruce Fields   nfsd4: backchanne...
181
  	u32	flavor; /* (u32)(-1) used to mean "no valid flavor" */
03bc6d1cc   Eric W. Biederman   nfsd: Modify nfsd...
182
183
  	kuid_t	uid;
  	kgid_t	gid;
acb2887e0   J. Bruce Fields   nfsd4: clean up c...
184
  };
49557cc74   Andy Adamson   nfsd41: Use separ...
185
186
187
188
189
190
191
192
  struct nfsd4_create_session {
  	clientid_t			clientid;
  	struct nfs4_sessionid		sessionid;
  	u32				seqid;
  	u32				flags;
  	struct nfsd4_channel_attrs	fore_channel;
  	struct nfsd4_channel_attrs	back_channel;
  	u32				callback_prog;
acb2887e0   J. Bruce Fields   nfsd4: clean up c...
193
  	struct nfsd4_cb_sec		cb_sec;
49557cc74   Andy Adamson   nfsd41: Use separ...
194
  };
cb73a9f46   J. Bruce Fields   nfsd4: implement ...
195
196
197
198
  struct nfsd4_backchannel_ctl {
  	u32	bc_cb_program;
  	struct nfsd4_cb_sec		bc_cb_sec;
  };
1d1bc8f20   J. Bruce Fields   nfsd4: support BI...
199
200
201
202
  struct nfsd4_bind_conn_to_session {
  	struct nfs4_sessionid		sessionid;
  	u32				dir;
  };
49557cc74   Andy Adamson   nfsd41: Use separ...
203
204
205
206
207
208
  /* The single slot clientid cache structure */
  struct nfsd4_clid_slot {
  	u32				sl_seqid;
  	__be32				sl_status;
  	struct nfsd4_create_session	sl_cr_ses;
  };
c7662518c   J. Bruce Fields   nfsd4: keep per-s...
209
210
211
  struct nfsd4_conn {
  	struct list_head cn_persession;
  	struct svc_xprt *cn_xprt;
19cf5c026   J. Bruce Fields   nfsd4: use callba...
212
213
  	struct svc_xpt_user cn_xpt_user;
  	struct nfsd4_session *cn_session;
c7662518c   J. Bruce Fields   nfsd4: keep per-s...
214
215
216
  /* CDFC4_FORE, CDFC4_BACK: */
  	unsigned char cn_flags;
  };
14a571a8e   Jeff Layton   nfsd: add some co...
217
218
219
220
221
  /*
   * Representation of a v4.1+ session. These are refcounted in a similar fashion
   * to the nfs4_client. References are only taken when the server is actively
   * working on the object (primarily during the processing of compounds).
   */
7116ed6b9   Andy Adamson   nfsd41: sessions ...
222
  struct nfsd4_session {
66b2b9b2b   J. Bruce Fields   nfsd4: don't dest...
223
  	atomic_t		se_ref;
7116ed6b9   Andy Adamson   nfsd41: sessions ...
224
225
  	struct list_head	se_hash;	/* hash by sessionid */
  	struct list_head	se_perclnt;
66b2b9b2b   J. Bruce Fields   nfsd4: don't dest...
226
227
  /* See SESSION4_PERSIST, etc. for standard flags; this is internal-only: */
  #define NFS4_SESSION_DEAD	0x010
7116ed6b9   Andy Adamson   nfsd41: sessions ...
228
  	u32			se_flags;
07cd4909a   Benny Halevy   nfsd4: mark_clien...
229
  	struct nfs4_client	*se_client;
7116ed6b9   Andy Adamson   nfsd41: sessions ...
230
  	struct nfs4_sessionid	se_sessionid;
6c18ba9f5   Alexandros Batsakis   nfsd41: move chan...
231
232
  	struct nfsd4_channel_attrs se_fchannel;
  	struct nfsd4_channel_attrs se_bchannel;
acb2887e0   J. Bruce Fields   nfsd4: clean up c...
233
  	struct nfsd4_cb_sec	se_cb_sec;
c7662518c   J. Bruce Fields   nfsd4: keep per-s...
234
  	struct list_head	se_conns;
8b5ce5cd4   J. Bruce Fields   nfsd4: callback p...
235
  	u32			se_cb_prog;
ac7c46f29   J. Bruce Fields   nfsd4: make backc...
236
  	u32			se_cb_seq_nr;
557ce2646   Andy Adamson   nfsd41: replace p...
237
  	struct nfsd4_slot	*se_slots[];	/* forward channel slots */
7116ed6b9   Andy Adamson   nfsd41: sessions ...
238
  };
5282fd724   Marc Eshel   nfsd41: sessionid...
239
240
241
242
243
244
  /* formatted contents of nfs4_sessionid */
  struct nfsd4_sessionid {
  	clientid_t	clientid;
  	u32		sequence;
  	u32		reserved;
  };
a55370a3c   NeilBrown   [PATCH] knfsd: nf...
245
  #define HEXDIR_LEN     33 /* hex version of 16 byte md5 of cl_name plus '\0' */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246
247
  /*
   * struct nfs4_client - one per client.  Clientids live here.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
   *
14a571a8e   Jeff Layton   nfsd: add some co...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
   * The initial object created by an NFS client using SETCLIENTID (for NFSv4.0)
   * or EXCHANGE_ID (for NFSv4.1+). These objects are refcounted and timestamped.
   * Each nfsd_net_ns object contains a set of these and they are tracked via
   * short and long form clientid. They are hashed and searched for under the
   * per-nfsd_net client_lock spinlock.
   *
   * References to it are only held during the processing of compounds, and in
   * certain other operations. In their "resting state" they have a refcount of
   * 0. If they are not renewed within a lease period, they become eligible for
   * destruction by the laundromat.
   *
   * These objects can also be destroyed prematurely by the fault injection code,
   * or if the client sends certain forms of SETCLIENTID or EXCHANGE_ID updates.
   * Care is taken *not* to do this however when the objects have an elevated
   * refcount.
   *
   * o Each nfs4_client is hashed by clientid
   *
   * o Each nfs4_clients is also hashed by name (the opaque quantity initially
   *   sent by the client to identify itself).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
   * 	  
14a571a8e   Jeff Layton   nfsd: add some co...
270
271
   * o cl_perclient list is used to ensure no dangling stateowner references
   *   when we expire the nfs4_client
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
273
274
   */
  struct nfs4_client {
  	struct list_head	cl_idhash; 	/* hash by cl_clientid.id */
ac55fdc40   Jeff Layton   nfsd: move the co...
275
  	struct rb_node		cl_namenode;	/* link into by-name trees */
d4f0489f3   Trond Myklebust   nfsd: Move the op...
276
  	struct list_head	*cl_ownerstr_hashtbl;
ea1da636e   NeilBrown   [PATCH] knfsd: nf...
277
  	struct list_head	cl_openowners;
38c2f4b12   J. Bruce Fields   nfsd4: look up st...
278
  	struct idr		cl_stateids;	/* stateid lookup */
ea1da636e   NeilBrown   [PATCH] knfsd: nf...
279
  	struct list_head	cl_delegations;
3bd64a5ba   J. Bruce Fields   nfsd4: implement ...
280
  	struct list_head	cl_revoked;	/* unacknowledged, revoked 4.1 state */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
281
  	struct list_head        cl_lru;         /* tail queue */
9cf514ccf   Christoph Hellwig   nfsd: implement p...
282
283
284
  #ifdef CONFIG_NFSD_PNFS
  	struct list_head	cl_lo_states;	/* outstanding layout states */
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
285
286
287
  	struct xdr_netobj	cl_name; 	/* id generated by client */
  	nfs4_verifier		cl_verifier; 	/* generated by client */
  	time_t                  cl_time;        /* time of last lease renewal */
363168b4e   Jeff Layton   nfsd: make nfs4_c...
288
  	struct sockaddr_storage	cl_addr; 	/* client ipaddress */
57266a6e9   J. Bruce Fields   nfsd4: implement ...
289
  	bool			cl_mach_cred;	/* SP4_MACH_CRED in force */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
  	struct svc_cred		cl_cred; 	/* setclientid principal */
  	clientid_t		cl_clientid;	/* generated by server */
  	nfs4_verifier		cl_confirm;	/* generated by server */
8323c3b2a   J. Bruce Fields   nfsd4: move minor...
293
  	u32			cl_minorversion;
9fb870702   Marc Eshel   nfsd41: introduce...
294

2bf23875f   J. Bruce Fields   nfsd4: rearrange ...
295
296
  	/* for v4.0 and v4.1 callbacks: */
  	struct nfs4_cb_conn	cl_cb_conn;
a52d726bb   Jeff Layton   nfsd: convert nfs...
297
298
299
300
  #define NFSD4_CLIENT_CB_UPDATE		(0)
  #define NFSD4_CLIENT_CB_KILL		(1)
  #define NFSD4_CLIENT_STABLE		(2)	/* client on stable storage */
  #define NFSD4_CLIENT_RECLAIM_COMPLETE	(3)	/* reclaim_complete done */
ac55fdc40   Jeff Layton   nfsd: move the co...
301
  #define NFSD4_CLIENT_CONFIRMED		(4)	/* client is confirmed */
d682e750c   Jeff Layton   nfsd: serialize n...
302
  #define NFSD4_CLIENT_UPCALL_LOCK	(5)	/* upcall serialization */
a52d726bb   Jeff Layton   nfsd: convert nfs...
303
304
305
  #define NFSD4_CLIENT_CB_FLAG_MASK	(1 << NFSD4_CLIENT_CB_UPDATE | \
  					 1 << NFSD4_CLIENT_CB_KILL)
  	unsigned long		cl_flags;
c6bb3ca27   J. Bruce Fields   nfsd4: use callba...
306
  	struct rpc_cred		*cl_cb_cred;
2bf23875f   J. Bruce Fields   nfsd4: rearrange ...
307
  	struct rpc_clnt		*cl_cb_client;
6ff8da088   J. Bruce Fields   nfsd4: Move callb...
308
  	u32			cl_cb_ident;
77a3569d6   J. Bruce Fields   nfsd4: keep finer...
309
310
311
  #define NFSD4_CB_UP		0
  #define NFSD4_CB_UNKNOWN	1
  #define NFSD4_CB_DOWN		2
5423732a7   Benny Halevy   nfsd41: use SEQ4_...
312
  #define NFSD4_CB_FAULT		3
77a3569d6   J. Bruce Fields   nfsd4: keep finer...
313
  	int			cl_cb_state;
cee277d92   J. Bruce Fields   nfsd4: use generi...
314
  	struct nfsd4_callback	cl_cb_null;
edd767866   J. Bruce Fields   nfsd4: move callb...
315
  	struct nfsd4_session	*cl_cb_session;
2bf23875f   J. Bruce Fields   nfsd4: rearrange ...
316

6ff8da088   J. Bruce Fields   nfsd4: Move callb...
317
318
  	/* for all client information that callback code might need: */
  	spinlock_t		cl_lock;
9fb870702   Marc Eshel   nfsd41: introduce...
319
320
  	/* for nfs41 */
  	struct list_head	cl_sessions;
49557cc74   Andy Adamson   nfsd41: Use separ...
321
  	struct nfsd4_clid_slot	cl_cs_slot;	/* create_session slot */
0733d2133   Andy Adamson   nfsd41: exchange_...
322
  	u32			cl_exchange_flags;
46583e259   Benny Halevy   nfsd4: introduce ...
323
324
  	/* number of rpc's in progress over an associated session: */
  	atomic_t		cl_refcount;
38524ab38   Andy Adamson   nfsd41: Backchann...
325
326
  
  	/* for nfs41 callbacks */
199ff35e1   Ricardo Labiaga   nfsd41: Backchann...
327
328
  	/* We currently support a single back channel with a single slot */
  	unsigned long		cl_cb_slot_busy;
199ff35e1   Ricardo Labiaga   nfsd41: Backchann...
329
330
  	struct rpc_wait_queue	cl_cb_waitq;	/* backchannel callers may */
  						/* wait here for slots */
c212cecfa   Stanislav Kinsbursky   nfsd: make nfs4_c...
331
  	struct net		*net;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
332
333
334
335
336
337
338
339
340
  };
  
  /* struct nfs4_client_reset
   * one per old client. Populates reset_str_hashtbl. Filled from conf_id_hashtbl
   * upon lease reset, or from upcall to state_daemon (to read in state
   * from non-volitile storage) upon reboot.
   */
  struct nfs4_client_reclaim {
  	struct list_head	cr_strhash;	/* hash by cr_name */
0ce0c2b5d   Jeff Layton   nfsd: don't searc...
341
  	struct nfs4_client	*cr_clp;	/* pointer to associated clp */
a55370a3c   NeilBrown   [PATCH] knfsd: nf...
342
  	char			cr_recdir[HEXDIR_LEN]; /* recover dir */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
345
346
347
348
  };
  
  static inline void
  update_stateid(stateid_t *stateid)
  {
  	stateid->si_generation++;
81b829655   J. Bruce Fields   nfsd4: simplify s...
349
350
351
  	/* Wraparound recommendation from 3530bis-13 9.1.3.2: */
  	if (stateid->si_generation == 0)
  		stateid->si_generation = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  }
  
  /* A reasonable value for REPLAY_ISIZE was estimated as follows:  
   * The OPEN response, typically the largest, requires 
   *   4(status) + 8(stateid) + 20(changeinfo) + 4(rflags) +  8(verifier) + 
   *   4(deleg. type) + 8(deleg. stateid) + 4(deleg. recall flag) + 
   *   20(deleg. space limit) + ~32(deleg. ace) = 112 bytes 
   */
  
  #define NFSD4_REPLAY_ISIZE       112 
  
  /*
   * Replay buffer, where the result of the last seqid-mutating operation 
   * is cached. 
   */
  struct nfs4_replay {
b37ad28bc   Al Viro   [PATCH] nfsd: nfs...
368
  	__be32			rp_status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
  	unsigned int		rp_buflen;
  	char			*rp_buf;
a4773c08f   J. Bruce Fields   nfsd4: use helper...
371
  	struct knfsd_fh		rp_openfh;
58fb12e6a   Jeff Layton   nfsd: Add a mutex...
372
  	struct mutex		rp_mutex;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
374
  	char			rp_ibuf[NFSD4_REPLAY_ISIZE];
  };
6b180f0b5   Jeff Layton   nfsd: Add referen...
375
376
377
  struct nfs4_stateowner;
  
  struct nfs4_stateowner_operations {
8f4b54c53   Jeff Layton   nfsd: add an oper...
378
  	void (*so_unhash)(struct nfs4_stateowner *);
6b180f0b5   Jeff Layton   nfsd: Add referen...
379
380
  	void (*so_free)(struct nfs4_stateowner *);
  };
14a571a8e   Jeff Layton   nfsd: add some co...
381
382
383
384
385
386
  /*
   * A core object that represents either an open or lock owner. The object and
   * lock owner objects have one of these embedded within them. Refcounts and
   * other fields common to both owner types are contained within these
   * structures.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
  struct nfs4_stateowner {
6b180f0b5   Jeff Layton   nfsd: Add referen...
388
389
390
391
  	struct list_head			so_strhash;
  	struct list_head			so_stateids;
  	struct nfs4_client			*so_client;
  	const struct nfs4_stateowner_operations	*so_ops;
83e452fee   J. Bruce Fields   nfsd4: fix out of...
392
  	/* after increment in nfsd4_bump_seqid, represents the next
7fb64cee3   NeilBrown   [PATCH] nfsd4: se...
393
  	 * sequence id expected from the client: */
6b180f0b5   Jeff Layton   nfsd: Add referen...
394
395
396
397
398
  	atomic_t				so_count;
  	u32					so_seqid;
  	struct xdr_netobj			so_owner; /* open owner name */
  	struct nfs4_replay			so_replay;
  	bool					so_is_open_owner;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
  };
14a571a8e   Jeff Layton   nfsd: add some co...
400
401
402
403
404
405
  /*
   * When a file is opened, the client provides an open state owner opaque string
   * that indicates the "owner" of that open. These objects are refcounted.
   * References to it are held by each open state associated with it. This object
   * is a superset of the nfs4_stateowner struct.
   */
fe0750e5c   J. Bruce Fields   nfsd4: split stat...
406
407
408
  struct nfs4_openowner {
  	struct nfs4_stateowner	oo_owner; /* must be first field */
  	struct list_head        oo_perclient;
b31b30e5c   J. Bruce Fields   nfsd4: cleanup st...
409
410
411
412
413
414
415
416
  	/*
  	 * We keep around openowners a little while after last close,
  	 * which saves clients from having to confirm, and allows us to
  	 * handle close replays if they come soon enough.  The close_lru
  	 * is a list of such openowners, to be reaped by the laundromat
  	 * thread eventually if they remain unused:
  	 */
  	struct list_head	oo_close_lru;
38c387b52   J. Bruce Fields   nfsd4: match clos...
417
  	struct nfs4_ol_stateid *oo_last_closed_stid;
fe0750e5c   J. Bruce Fields   nfsd4: split stat...
418
  	time_t			oo_time; /* time of placement on so_close_lru */
dad1c067e   J. Bruce Fields   nfsd4: replace oo...
419
420
  #define NFS4_OO_CONFIRMED   1
  	unsigned char		oo_flags;
fe0750e5c   J. Bruce Fields   nfsd4: split stat...
421
  };
14a571a8e   Jeff Layton   nfsd: add some co...
422
423
424
425
426
427
  /*
   * Represents a generic "lockowner". Similar to an openowner. References to it
   * are held by the lock stateids that are created on its behalf. This object is
   * a superset of the nfs4_stateowner struct (or would be if it needed any extra
   * fields).
   */
fe0750e5c   J. Bruce Fields   nfsd4: split stat...
428
429
  struct nfs4_lockowner {
  	struct nfs4_stateowner	lo_owner; /* must be first element */
fe0750e5c   J. Bruce Fields   nfsd4: split stat...
430
431
432
433
434
435
436
437
438
439
440
  };
  
  static inline struct nfs4_openowner * openowner(struct nfs4_stateowner *so)
  {
  	return container_of(so, struct nfs4_openowner, oo_owner);
  }
  
  static inline struct nfs4_lockowner * lockowner(struct nfs4_stateowner *so)
  {
  	return container_of(so, struct nfs4_lockowner, lo_owner);
  }
14a571a8e   Jeff Layton   nfsd: add some co...
441
  /*
8287f009b   Sachin Bhamare   nfsd: fix pNFS re...
442
443
444
445
446
447
448
449
450
451
452
   * Per-client state indicating no. of opens and outstanding delegations
   * on a file from a particular client.'od' stands for 'open & delegation'
   */
  struct nfs4_clnt_odstate {
  	struct nfs4_client	*co_client;
  	struct nfs4_file	*co_file;
  	struct list_head	co_perfile;
  	atomic_t		co_odcount;
  };
  
  /*
14a571a8e   Jeff Layton   nfsd: add some co...
453
454
   * nfs4_file: a file opened by some number of (open) nfs4_stateowners.
   *
ccc6398ea   Jeff Layton   nfsd: clean up co...
455
456
457
458
459
460
461
462
   * These objects are global. nfsd keeps one instance of a nfs4_file per
   * filehandle (though it may keep multiple file descriptors for each). Each
   * inode can have multiple filehandles associated with it, so there is
   * (potentially) a many to one relationship between this struct and struct
   * inode.
   *
   * These are hashed by filehandle in the file_hashtbl, which is protected by
   * the global state_lock spinlock.
14a571a8e   Jeff Layton   nfsd: add some co...
463
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
464
  struct nfs4_file {
8b671b807   J. Bruce Fields   nfsd4: remove use...
465
  	atomic_t		fi_ref;
1d31a2531   Trond Myklebust   nfsd: Add fine gr...
466
  	spinlock_t		fi_lock;
ccc6398ea   Jeff Layton   nfsd: clean up co...
467
  	struct hlist_node       fi_hash;	/* hash on fi_fhandle */
8beefa249   NeilBrown   [PATCH] nfsd4: re...
468
  	struct list_head        fi_stateids;
5b095e999   Jeff Layton   nfsd: convert nfs...
469
470
471
472
  	union {
  		struct list_head	fi_delegations;
  		struct rcu_head		fi_rcu;
  	};
8287f009b   Sachin Bhamare   nfsd: fix pNFS re...
473
  	struct list_head	fi_clnt_odstate;
f9d7562fd   J. Bruce Fields   nfsd4: share file...
474
475
  	/* One each for O_RDONLY, O_WRONLY, O_RDWR: */
  	struct file *		fi_fds[3];
f9d7562fd   J. Bruce Fields   nfsd4: share file...
476
  	/*
6409a5a65   J. Bruce Fields   nfsd4: clean up d...
477
478
479
480
481
  	 * Each open or lock stateid contributes 0-4 to the counts
  	 * below depending on which bits are set in st_access_bitmap:
  	 *     1 to fi_access[O_RDONLY] if NFS4_SHARE_ACCES_READ is set
  	 *   + 1 to fi_access[O_WRONLY] if NFS4_SHARE_ACCESS_WRITE is set
  	 *   + 1 to both of the above if NFS4_SHARE_ACCESS_BOTH is set.
f9d7562fd   J. Bruce Fields   nfsd4: share file...
482
  	 */
9ae78bcc0   J. Bruce Fields   nfsd4: fix commen...
483
  	atomic_t		fi_access[2];
baeb4ff0e   Jeff Layton   nfsd: make deny m...
484
  	u32			fi_share_deny;
acfdf5c38   J. Bruce Fields   nfsd4: acquire on...
485
  	struct file		*fi_deleg_file;
67db10344   Jeff Layton   nfsd: fi_delegees...
486
  	int			fi_delegees;
e2cf80d73   Trond Myklebust   nfsd: Store the f...
487
  	struct knfsd_fh		fi_fhandle;
47f9940c5   Meelap Shah   knfsd: nfsd4: don...
488
  	bool			fi_had_conflict;
9cf514ccf   Christoph Hellwig   nfsd: implement p...
489
490
  #ifdef CONFIG_NFSD_PNFS
  	struct list_head	fi_lo_states;
c5c707f96   Christoph Hellwig   nfsd: implement p...
491
  	atomic_t		fi_lo_recalls;
9cf514ccf   Christoph Hellwig   nfsd: implement p...
492
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493
  };
14a571a8e   Jeff Layton   nfsd: add some co...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  /*
   * A generic struct representing either a open or lock stateid. The nfs4_client
   * holds a reference to each of these objects, and they in turn hold a
   * reference to their respective stateowners. The client's reference is
   * released in response to a close or unlock (depending on whether it's an open
   * or lock stateid) or when the client is being destroyed.
   *
   * In the case of v4.0 open stateids, these objects are preserved for a little
   * while after close in order to handle CLOSE replays. Those are eventually
   * reclaimed via a LRU scheme by the laundromat.
   *
   * This object is a superset of the nfs4_stid. "ol" stands for "Open or Lock".
   * Better suggestions welcome.
   */
dcef0413d   J. Bruce Fields   nfsd4: move some ...
508
  struct nfs4_ol_stateid {
35b2e295e   Jeff Layton   nfsd: serialize s...
509
510
511
512
513
514
515
516
517
518
  	struct nfs4_stid		st_stid;
  	struct list_head		st_perfile;
  	struct list_head		st_perstateowner;
  	struct list_head		st_locks;
  	struct nfs4_stateowner		*st_stateowner;
  	struct nfs4_clnt_odstate	*st_clnt_odstate;
  	unsigned char			st_access_bmap;
  	unsigned char			st_deny_bmap;
  	struct nfs4_ol_stateid		*st_openstp;
  	struct rw_semaphore		st_rwsem;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519
  };
dcef0413d   J. Bruce Fields   nfsd4: move some ...
520
521
522
523
  static inline struct nfs4_ol_stateid *openlockstateid(struct nfs4_stid *s)
  {
  	return container_of(s, struct nfs4_ol_stateid, st_stid);
  }
9cf514ccf   Christoph Hellwig   nfsd: implement p...
524
525
526
527
528
529
530
  struct nfs4_layout_stateid {
  	struct nfs4_stid		ls_stid;
  	struct list_head		ls_perclnt;
  	struct list_head		ls_perfile;
  	spinlock_t			ls_lock;
  	struct list_head		ls_layouts;
  	u32				ls_layout_type;
c5c707f96   Christoph Hellwig   nfsd: implement p...
531
532
533
534
  	struct file			*ls_file;
  	struct nfsd4_callback		ls_recall;
  	stateid_t			ls_recall_sid;
  	bool				ls_recalled;
9cf514ccf   Christoph Hellwig   nfsd: implement p...
535
536
537
538
539
540
  };
  
  static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
  {
  	return container_of(s, struct nfs4_layout_stateid, ls_stid);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
541
  /* flags for preprocess_seqid_op() */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
542
543
  #define RD_STATE	        0x00000010
  #define WR_STATE	        0x00000020
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
544

326129d02   Christoph Hellwig   nfsd: introduce a...
545
546
547
  enum nfsd4_cb_op {
  	NFSPROC4_CLNT_CB_NULL = 0,
  	NFSPROC4_CLNT_CB_RECALL,
c5c707f96   Christoph Hellwig   nfsd: implement p...
548
  	NFSPROC4_CLNT_CB_LAYOUT,
326129d02   Christoph Hellwig   nfsd: introduce a...
549
550
  	NFSPROC4_CLNT_CB_SEQUENCE,
  };
dd453dfd7   Benny Halevy   nfsd: pass nfsd4_...
551
  struct nfsd4_compound_state;
2c142baa7   Stanislav Kinsbursky   NFSd: make boot_t...
552
  struct nfsd_net;
dd453dfd7   Benny Halevy   nfsd: pass nfsd4_...
553

5ccb0066f   Stanislav Kinsbursky   LockD: pass actua...
554
555
  extern __be32 nfs4_preprocess_stateid_op(struct net *net,
  		struct nfsd4_compound_state *cstate,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556
  		stateid_t *stateid, int flags, struct file **filp);
cd61c5223   Christoph Hellwig   nfsd: make lookup...
557
558
559
560
561
562
  __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
  		     stateid_t *stateid, unsigned char typemask,
  		     struct nfs4_stid **s, struct nfsd_net *nn);
  struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl,
  		struct kmem_cache *slab);
  void nfs4_unhash_stid(struct nfs4_stid *s);
6011695da   Trond Myklebust   nfsd: Add referen...
563
  void nfs4_put_stid(struct nfs4_stid *s);
52e19c09a   Stanislav Kinsbursky   nfsd: make reclai...
564
565
566
567
  void nfs4_remove_reclaim_record(struct nfs4_client_reclaim *, struct nfsd_net *);
  extern void nfs4_release_reclaim(struct nfsd_net *);
  extern struct nfs4_client_reclaim *nfsd4_find_reclaim_client(const char *recdir,
  							struct nfsd_net *nn);
0fe492db6   Trond Myklebust   nfsd: Convert nfs...
568
569
  extern __be32 nfs4_check_open_reclaim(clientid_t *clid,
  		struct nfsd4_compound_state *cstate, struct nfsd_net *nn);
80fc015bd   J. Bruce Fields   nfsd4: use common...
570
  extern int set_callback_cred(void);
5a3c9d713   J. Bruce Fields   nfsd4: separate c...
571
  extern void nfsd4_probe_callback(struct nfs4_client *clp);
84f5f7ccc   J. Bruce Fields   nfsd4: make sure ...
572
  extern void nfsd4_probe_callback_sync(struct nfs4_client *clp);
5a3c9d713   J. Bruce Fields   nfsd4: separate c...
573
  extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
f0b5de1b6   Christoph Hellwig   nfsd: split nfsd4...
574
  extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp,
0162ac2b9   Christoph Hellwig   nfsd: introduce n...
575
  		struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op);
f0b5de1b6   Christoph Hellwig   nfsd: split nfsd4...
576
  extern void nfsd4_run_cb(struct nfsd4_callback *cb);
b5a1a81e5   J. Bruce Fields   nfsd4: don't slee...
577
578
  extern int nfsd4_create_callback_queue(void);
  extern void nfsd4_destroy_callback_queue(void);
6ff8da088   J. Bruce Fields   nfsd4: Move callb...
579
  extern void nfsd4_shutdown_callback(struct nfs4_client *);
02e1215f9   Jeff Layton   nfsd: Avoid takin...
580
  extern void nfsd4_prepare_cb_recall(struct nfs4_delegation *dp);
52e19c09a   Stanislav Kinsbursky   nfsd: make reclai...
581
582
583
  extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(const char *name,
  							struct nfsd_net *nn);
  extern bool nfs4_has_reclaimed_state(const char *name, struct nfsd_net *nn);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
584

e6ba76e19   Christoph Hellwig   nfsd: make find/g...
585
586
587
588
589
590
  struct nfs4_file *find_file(struct knfsd_fh *fh);
  void put_nfs4_file(struct nfs4_file *fi);
  static inline void get_nfs4_file(struct nfs4_file *fi)
  {
  	atomic_inc(&fi->fi_ref);
  }
4d227fca1   Christoph Hellwig   nfsd: make find_a...
591
  struct file *find_any_file(struct nfs4_file *f);
e6ba76e19   Christoph Hellwig   nfsd: make find/g...
592

7f5ef2e90   Jeff Layton   nfsd: add a v4_en...
593
594
  /* grace period management */
  void nfsd4_end_grace(struct nfsd_net *nn);
2a4317c55   Jeff Layton   nfsd: add nfsd4_c...
595
596
597
598
599
600
  /* nfs4recover operations */
  extern int nfsd4_client_tracking_init(struct net *net);
  extern void nfsd4_client_tracking_exit(struct net *net);
  extern void nfsd4_client_record_create(struct nfs4_client *clp);
  extern void nfsd4_client_record_remove(struct nfs4_client *clp);
  extern int nfsd4_client_record_check(struct nfs4_client *clp);
919b8049f   Jeff Layton   nfsd: remove redu...
601
  extern void nfsd4_record_grace_done(struct nfsd_net *nn);
f3c7521fe   Bryan Schumaker   NFSD: Fold fault_...
602
603
604
605
606
  
  /* nfs fault injection functions */
  #ifdef CONFIG_NFSD_FAULT_INJECTION
  int nfsd_fault_inject_init(void);
  void nfsd_fault_inject_cleanup(void);
285abdee5   Jeff Layton   nfsd: remove old ...
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
  
  u64 nfsd_inject_print_clients(void);
  u64 nfsd_inject_forget_client(struct sockaddr_storage *, size_t);
  u64 nfsd_inject_forget_clients(u64);
  
  u64 nfsd_inject_print_locks(void);
  u64 nfsd_inject_forget_client_locks(struct sockaddr_storage *, size_t);
  u64 nfsd_inject_forget_locks(u64);
  
  u64 nfsd_inject_print_openowners(void);
  u64 nfsd_inject_forget_client_openowners(struct sockaddr_storage *, size_t);
  u64 nfsd_inject_forget_openowners(u64);
  
  u64 nfsd_inject_print_delegations(void);
  u64 nfsd_inject_forget_client_delegations(struct sockaddr_storage *, size_t);
  u64 nfsd_inject_forget_delegations(u64);
  u64 nfsd_inject_recall_client_delegations(struct sockaddr_storage *, size_t);
  u64 nfsd_inject_recall_delegations(u64);
f3c7521fe   Bryan Schumaker   NFSD: Fold fault_...
625
626
627
628
  #else /* CONFIG_NFSD_FAULT_INJECTION */
  static inline int nfsd_fault_inject_init(void) { return 0; }
  static inline void nfsd_fault_inject_cleanup(void) {}
  #endif /* CONFIG_NFSD_FAULT_INJECTION */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
629
  #endif   /* NFSD4_STATE_H */