source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/linux/nfsd/state.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 10.6 KB
Line 
1/*
2 *  linux/include/nfsd/state.h
3 *
4 *  Copyright (c) 2001 The Regents of the University of Michigan.
5 *  All rights reserved.
6 *
7 *  Kendrick Smith <kmsmith@umich.edu>
8 *  Andy Adamson <andros@umich.edu>
9 * 
10 *  Redistribution and use in source and binary forms, with or without
11 *  modification, are permitted provided that the following conditions
12 *  are met:
13 * 
14 *  1. Redistributions of source code must retain the above copyright
15 *     notice, this list of conditions and the following disclaimer.
16 *  2. Redistributions in binary form must reproduce the above copyright
17 *     notice, this list of conditions and the following disclaimer in the
18 *     documentation and/or other materials provided with the distribution.
19 *  3. Neither the name of the University nor the names of its
20 *     contributors may be used to endorse or promote products derived
21 *     from this software without specific prior written permission.
22 *
23 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37#ifndef _NFSD4_STATE_H
38#define _NFSD4_STATE_H
39
40#include <asm/types.h>
41
42#include <linux/kref.h>
43#include <linux/sunrpc/clnt.h>
44
45#define NFS4_OPAQUE_LIMIT 1024
46typedef struct {
47        __u32             cl_boot;
48        __u32             cl_id;
49} clientid_t;
50
51typedef struct {
52        __u32             so_boot;
53        __u32             so_stateownerid;
54        __u32             so_fileid;
55} stateid_opaque_t;
56
57typedef struct {
58        __u32                     si_generation;
59        stateid_opaque_t        si_opaque;
60} stateid_t;
61#define si_boot           si_opaque.so_boot
62#define si_stateownerid   si_opaque.so_stateownerid
63#define si_fileid         si_opaque.so_fileid
64
65extern stateid_t zerostateid;
66extern stateid_t onestateid;
67
68#define ZERO_STATEID(stateid)       (!memcmp((stateid), &zerostateid, sizeof(stateid_t)))
69#define ONE_STATEID(stateid)        (!memcmp((stateid), &onestateid, sizeof(stateid_t)))
70
71struct nfs4_cb_recall {
72        __u32                   cbr_ident;
73        int                     cbr_trunc;
74        stateid_t               cbr_stateid;
75        __u32                   cbr_fhlen;
76        __u32                   cbr_fhval[NFS4_FHSIZE];
77        struct nfs4_delegation  *cbr_dp;
78};
79
80struct nfs4_delegation {
81        struct list_head        dl_del_perfile; /* nfs4_file->fi_del_perfile */
82        struct list_head        dl_del_perclnt; /* nfs4_client->cl_del_perclnt*/
83        struct list_head        dl_recall_lru;  /* delegation recalled */
84        atomic_t                dl_count;       /* ref count */
85        struct nfs4_client      *dl_client;
86        struct nfs4_file        *dl_file;
87        struct file_lock        *dl_flock;
88        struct file             *dl_vfs_file;
89        __u32                   dl_type;
90        time_t                  dl_time;
91        struct nfs4_cb_recall   dl_recall;
92};
93
94#define dl_stateid      dl_recall.cbr_stateid
95#define dl_fhlen        dl_recall.cbr_fhlen
96#define dl_fhval        dl_recall.cbr_fhval
97
98/* client delegation callback info */
99struct nfs4_callback {
100        /* SETCLIENTID info */
101        __u32                   cb_parsed;  /* addr parsed */
102        __u32                     cb_addr;
103        unsigned short          cb_port;
104        __u32                     cb_prog;
105        __u32                     cb_ident;
106        /* RPC client info */
107        atomic_t                cb_set;     /* successful CB_NULL call */
108        struct rpc_program      cb_program;
109        struct rpc_stat         cb_stat;
110        struct rpc_clnt *       cb_client;
111};
112
113/*
114 * struct nfs4_client - one per client.  Clientids live here.
115 *      o Each nfs4_client is hashed by clientid.
116 *
117 *      o Each nfs4_clients is also hashed by name
118 *        (the opaque quantity initially sent by the client to identify itself).
119 *       
120 *      o cl_perclient list is used to ensure no dangling stateowner references
121 *        when we expire the nfs4_client
122 */
123struct nfs4_client {
124        struct list_head        cl_idhash;      /* hash by cl_clientid.id */
125        struct list_head        cl_strhash;     /* hash by cl_name */
126        struct list_head        cl_perclient;   /* list: stateowners */
127        struct list_head        cl_del_perclnt; /* list: delegations */
128        struct list_head        cl_lru;         /* tail queue */
129        struct xdr_netobj       cl_name;        /* id generated by client */
130        nfs4_verifier           cl_verifier;    /* generated by client */
131        time_t                  cl_time;        /* time of last lease renewal */
132        __u32                   cl_addr;        /* client ipaddress */
133        struct svc_cred         cl_cred;        /* setclientid principal */
134        clientid_t              cl_clientid;    /* generated by server */
135        nfs4_verifier           cl_confirm;     /* generated by server */
136        struct nfs4_callback    cl_callback;    /* callback info */
137        atomic_t                cl_count;       /* ref count */
138};
139
140/* struct nfs4_client_reset
141 * one per old client. Populates reset_str_hashtbl. Filled from conf_id_hashtbl
142 * upon lease reset, or from upcall to state_daemon (to read in state
143 * from non-volitile storage) upon reboot.
144 */
145struct nfs4_client_reclaim {
146        struct list_head        cr_strhash;     /* hash by cr_name */
147        struct xdr_netobj       cr_name;        /* id generated by client */
148};
149
150static inline void
151update_stateid(stateid_t *stateid)
152{
153        stateid->si_generation++;
154}
155
156/* A reasonable value for REPLAY_ISIZE was estimated as follows: 
157 * The OPEN response, typically the largest, requires
158 *   4(status) + 8(stateid) + 20(changeinfo) + 4(rflags) +  8(verifier) +
159 *   4(deleg. type) + 8(deleg. stateid) + 4(deleg. recall flag) +
160 *   20(deleg. space limit) + ~32(deleg. ace) = 112 bytes
161 */
162
163#define NFSD4_REPLAY_ISIZE       112
164
165/*
166 * Replay buffer, where the result of the last seqid-mutating operation
167 * is cached.
168 */
169struct nfs4_replay {
170        __u32                   rp_status;
171        unsigned int            rp_buflen;
172        char                    *rp_buf;
173        unsigned                intrp_allocated;
174        int                     rp_openfh_len;
175        char                    rp_openfh[NFS4_FHSIZE];
176        char                    rp_ibuf[NFSD4_REPLAY_ISIZE];
177};
178
179/*
180* nfs4_stateowner can either be an open_owner, or a lock_owner
181*
182*    so_idhash:  stateid_hashtbl[] for open owner, lockstateid_hashtbl[]
183*         for lock_owner
184*    so_strhash: ownerstr_hashtbl[] for open_owner, lock_ownerstr_hashtbl[]
185*         for lock_owner
186*    so_perclient: nfs4_client->cl_perclient entry - used when nfs4_client
187*         struct is reaped.
188*    so_perfilestate: heads the list of nfs4_stateid (either open or lock)
189*         and is used to ensure no dangling nfs4_stateid references when we
190*         release a stateowner.
191*    so_perlockowner: (open) nfs4_stateid->st_perlockowner entry - used when
192*         close is called to reap associated byte-range locks
193*    so_close_lru: (open) stateowner is placed on this list instead of being
194*         reaped (when so_perfilestate is empty) to hold the last close replay.
195*         reaped by laundramat thread after lease period.
196*/
197struct nfs4_stateowner {
198        struct kref             so_ref;
199        struct list_head        so_idhash;   /* hash by so_id */
200        struct list_head        so_strhash;   /* hash by op_name */
201        struct list_head        so_perclient; /* nfs4_client->cl_perclient */
202        struct list_head        so_perfilestate; /* list: nfs4_stateid */
203        struct list_head        so_perlockowner; /* nfs4_stateid->st_perlockowner */
204        struct list_head        so_close_lru; /* tail queue */
205        time_t                  so_time; /* time of placement on so_close_lru */
206        int                     so_is_open_owner; /* 1=openowner,0=lockowner */
207        __u32                     so_id;
208        struct nfs4_client *    so_client;
209        __u32                     so_seqid;   
210        struct xdr_netobj       so_owner;     /* open owner name */
211        int                     so_confirmed; /* successful OPEN_CONFIRM? */
212        struct nfs4_replay      so_replay;
213};
214
215/*
216*  nfs4_file: a file opened by some number of (open) nfs4_stateowners.
217*    o fi_perfile list is used to search for conflicting
218*      share_acces, share_deny on the file.
219*/
220struct nfs4_file {
221        struct list_head        fi_hash;    /* hash by "struct inode *" */
222        struct list_head        fi_perfile; /* list: nfs4_stateid */
223        struct list_head        fi_del_perfile; /* list: nfs4_delegation */
224        struct inode            *fi_inode;
225        __u32                     fi_id;      /* used with stateowner->so_id
226                                             * for stateid_hashtbl hash */
227};
228
229/*
230* nfs4_stateid can either be an open stateid or (eventually) a lock stateid
231*
232* (open)nfs4_stateid: one per (open)nfs4_stateowner, nfs4_file
233*
234*       st_hash: stateid_hashtbl[] entry or lockstateid_hashtbl entry
235*       st_perfile: file_hashtbl[] entry.
236*       st_perfile_state: nfs4_stateowner->so_perfilestate
237*       st_perlockowner: (open stateid) list of lock nfs4_stateowners
238*       st_access_bmap: used only for open stateid
239*       st_deny_bmap: used only for open stateid
240*/
241
242struct nfs4_stateid {
243        struct list_head              st_hash; 
244        struct list_head              st_perfile;
245        struct list_head              st_perfilestate; 
246        struct list_head              st_perlockowner;
247        struct nfs4_stateowner      * st_stateowner;
248        struct nfs4_file            * st_file;
249        stateid_t                     st_stateid;
250        struct file                 * st_vfs_file;
251        unsigned long                 st_access_bmap;
252        unsigned long                 st_deny_bmap;
253};
254
255/* flags for preprocess_seqid_op() */
256#define CHECK_FH                0x00000001
257#define CONFIRM                 0x00000002
258#define OPEN_STATE              0x00000004
259#define LOCK_STATE              0x00000008
260#define RD_STATE                0x00000010
261#define WR_STATE                0x00000020
262#define CLOSE_STATE             0x00000040
263#define DELEG_RET               0x00000080
264
265#define seqid_mutating_err(err)                       \
266        (((err) != nfserr_stale_clientid) &&    \
267        ((err) != nfserr_bad_seqid) &&          \
268        ((err) != nfserr_stale_stateid) &&      \
269        ((err) != nfserr_bad_stateid))
270
271extern time_t nfs4_laundromat(void);
272extern int nfsd4_renew(clientid_t *clid);
273extern int nfs4_preprocess_stateid_op(struct svc_fh *current_fh, 
274                stateid_t *stateid, int flags, struct file **filp);
275extern int nfs4_share_conflict(struct svc_fh *current_fh, 
276                unsigned int deny_type);
277extern void nfs4_lock_state(void);
278extern void nfs4_unlock_state(void);
279extern int nfs4_in_grace(void);
280extern int nfs4_check_open_reclaim(clientid_t *clid);
281extern void put_nfs4_client(struct nfs4_client *clp);
282extern void nfs4_free_stateowner(struct kref *kref);
283extern void nfsd4_probe_callback(struct nfs4_client *clp);
284extern void nfsd4_cb_recall(struct nfs4_delegation *dp);
285extern void nfs4_put_delegation(struct nfs4_delegation *dp);
286
287static inline void
288nfs4_put_stateowner(struct nfs4_stateowner *so)
289{
290        kref_put(&so->so_ref, nfs4_free_stateowner);
291}
292
293static inline void
294nfs4_get_stateowner(struct nfs4_stateowner *so)
295{
296        kref_get(&so->so_ref);
297}
298
299#endif   /* NFSD4_STATE_H */
Note: See TracBrowser for help on using the repository browser.