vserver 1.9.3
[linux-2.6.git] / include / linux / nfsd / xdr4.h
1 /*
2  *  include/linux/nfsd/xdr4.h
3  *
4  *  Server-side types for NFSv4.
5  *
6  *  Copyright (c) 2002 The Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  Kendrick Smith <kmsmith@umich.edu>
10  *  Andy Adamson   <andros@umich.edu>
11  *
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions
14  *  are met:
15  *
16  *  1. Redistributions of source code must retain the above copyright
17  *     notice, this list of conditions and the following disclaimer.
18  *  2. Redistributions in binary form must reproduce the above copyright
19  *     notice, this list of conditions and the following disclaimer in the
20  *     documentation and/or other materials provided with the distribution.
21  *  3. Neither the name of the University nor the names of its
22  *     contributors may be used to endorse or promote products derived
23  *     from this software without specific prior written permission.
24  *
25  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38
39 #ifndef _LINUX_NFSD_XDR4_H
40 #define _LINUX_NFSD_XDR4_H
41
42 #include <linux/nfs4.h>
43
44 #define NFSD4_MAX_TAGLEN        128
45 #define XDR_LEN(n)                     (((n) + 3) & ~3)
46
47 typedef u32 delegation_zero_t;
48 typedef u32 delegation_boot_t;
49 typedef u64 delegation_id_t;
50
51 typedef struct {
52         delegation_zero_t       ds_zero;
53         delegation_boot_t       ds_boot;
54         delegation_id_t         ds_id;
55 } delegation_stateid_t;
56
57 struct nfsd4_change_info {
58         u32             atomic;
59         u32             before_ctime_sec;
60         u32             before_ctime_nsec;
61         u32             after_ctime_sec;
62         u32             after_ctime_nsec;
63 };
64
65 struct nfsd4_access {
66         u32             ac_req_access;      /* request */
67         u32             ac_supported;       /* response */
68         u32             ac_resp_access;     /* response */
69 };
70
71 struct nfsd4_close {
72         u32             cl_seqid;           /* request */
73         stateid_t       cl_stateid;         /* request+response */
74         struct nfs4_stateowner * cl_stateowner; /* response */
75 };
76
77 struct nfsd4_commit {
78         u64             co_offset;          /* request */
79         u32             co_count;           /* request */
80         nfs4_verifier   co_verf;            /* response */
81 };
82
83 struct nfsd4_create {
84         u32             cr_namelen;         /* request */
85         char *          cr_name;            /* request */
86         u32             cr_type;            /* request */
87         union {                             /* request */
88                 struct {
89                         u32 namelen;
90                         char *name;
91                 } link;   /* NF4LNK */
92                 struct {
93                         u32 specdata1;
94                         u32 specdata2;
95                 } dev;    /* NF4BLK, NF4CHR */
96         } u;
97         u32             cr_bmval[2];        /* request */
98         struct iattr    cr_iattr;           /* request */
99         struct nfsd4_change_info  cr_cinfo; /* response */
100         struct nfs4_acl *cr_acl;
101 };
102 #define cr_linklen      u.link.namelen
103 #define cr_linkname     u.link.name
104 #define cr_specdata1    u.dev.specdata1
105 #define cr_specdata2    u.dev.specdata2
106
107 struct nfsd4_getattr {
108         u32             ga_bmval[2];        /* request */
109         struct svc_fh   *ga_fhp;            /* response */
110 };
111
112 struct nfsd4_link {
113         u32             li_namelen;         /* request */
114         char *          li_name;            /* request */
115         struct nfsd4_change_info  li_cinfo; /* response */
116 };
117
118 struct nfsd4_lock_denied {
119         struct nfs4_stateowner   *ld_sop;
120         u64             ld_start;
121         u64             ld_length;
122         u32             ld_type;
123 };
124
125 struct nfsd4_lock {
126         /* request */
127         u32             lk_type;
128         u32             lk_reclaim;         /* boolean */
129         u64             lk_offset;
130         u64             lk_length;
131         u32             lk_is_new;
132         union {
133                 struct {
134                         u32             open_seqid;
135                         stateid_t       open_stateid;
136                         u32             lock_seqid;
137                         clientid_t      clientid;
138                         struct xdr_netobj owner;
139                 } new;
140                 struct {
141                         stateid_t       lock_stateid;
142                         u32             lock_seqid;
143                 } old;
144         } v;
145
146         /* response */
147         union {
148                 struct {
149                         stateid_t               stateid;
150                 } ok;
151                 struct nfsd4_lock_denied        denied;
152         } u;
153
154         struct nfs4_stateowner *lk_stateowner;
155 };
156 #define lk_new_open_seqid       v.new.open_seqid
157 #define lk_new_open_stateid     v.new.open_stateid
158 #define lk_new_lock_seqid       v.new.lock_seqid
159 #define lk_new_clientid         v.new.clientid
160 #define lk_new_owner            v.new.owner
161 #define lk_old_lock_stateid     v.old.lock_stateid
162 #define lk_old_lock_seqid       v.old.lock_seqid
163
164 #define lk_rflags       u.ok.rflags
165 #define lk_resp_stateid u.ok.stateid
166 #define lk_denied       u.denied
167
168
169 struct nfsd4_lockt {
170         u32                             lt_type;
171         clientid_t                      lt_clientid;
172         struct xdr_netobj               lt_owner;
173         u64                             lt_offset;
174         u64                             lt_length;
175         struct nfs4_stateowner *        lt_stateowner;
176         struct nfsd4_lock_denied        lt_denied;
177 };
178
179  
180 struct nfsd4_locku {
181         u32             lu_type;
182         u32             lu_seqid;
183         stateid_t       lu_stateid;
184         u64             lu_offset;
185         u64             lu_length;
186         struct nfs4_stateowner  *lu_stateowner;
187 };
188
189
190 struct nfsd4_lookup {
191         u32             lo_len;             /* request */
192         char *          lo_name;            /* request */
193 };
194
195 struct nfsd4_putfh {
196         u32             pf_fhlen;           /* request */
197         char            *pf_fhval;          /* request */
198 };
199
200 struct nfsd4_open {
201         u32             op_claim_type;      /* request */
202         struct xdr_netobj op_fname;         /* request - everything but CLAIM_PREV */
203         u32             op_delegate_type;   /* request - CLAIM_PREV only */
204         delegation_stateid_t    op_delegate_stateid; /* request - CLAIM_DELEGATE_CUR only */
205         u32             op_create;          /* request */
206         u32             op_createmode;      /* request */
207         u32             op_bmval[2];        /* request */
208         union {                             /* request */
209                 struct iattr    iattr;                      /* UNCHECKED4,GUARDED4 */
210                 nfs4_verifier   verf;                                /* EXCLUSIVE4 */
211         } u;
212         clientid_t      op_clientid;        /* request */
213         struct xdr_netobj op_owner;           /* request */
214         u32             op_seqid;           /* request */
215         u32             op_share_access;    /* request */
216         u32             op_share_deny;      /* request */
217         stateid_t       op_stateid;         /* response */
218         struct nfsd4_change_info  op_cinfo; /* response */
219         u32             op_rflags;          /* response */
220         int             op_truncate;        /* used during processing */
221         struct nfs4_stateowner *op_stateowner; /* used during processing */
222         struct nfs4_acl *op_acl;
223 };
224 #define op_iattr        u.iattr
225 #define op_verf         u.verf
226
227 struct nfsd4_open_confirm {
228         stateid_t       oc_req_stateid          /* request */;
229         u32             oc_seqid                /* request */;
230         stateid_t       oc_resp_stateid         /* response */;
231         struct nfs4_stateowner * oc_stateowner; /* response */
232 };
233
234 struct nfsd4_open_downgrade {
235         stateid_t       od_stateid;
236         u32             od_seqid;
237         u32             od_share_access;
238         u32             od_share_deny;
239         struct nfs4_stateowner *od_stateowner;
240 };
241
242
243 struct nfsd4_read {
244         stateid_t       rd_stateid;         /* request */
245         u64             rd_offset;          /* request */
246         u32             rd_length;          /* request */
247         struct kvec     rd_iov[RPCSVC_MAXPAGES];
248         int             rd_vlen;
249         
250         struct svc_rqst *rd_rqstp;          /* response */
251         struct svc_fh * rd_fhp;             /* response */
252 };
253
254 struct nfsd4_readdir {
255         u64             rd_cookie;          /* request */
256         nfs4_verifier   rd_verf;            /* request */
257         u32             rd_dircount;        /* request */
258         u32             rd_maxcount;        /* request */
259         u32             rd_bmval[2];        /* request */
260         struct svc_rqst *rd_rqstp;          /* response */
261         struct svc_fh * rd_fhp;             /* response */
262
263         struct readdir_cd       common;
264         u32 *                   buffer;
265         int                     buflen;
266         u32 *                   offset;
267 };
268
269 struct nfsd4_release_lockowner {
270         clientid_t        rl_clientid;
271         struct xdr_netobj rl_owner;
272 };
273 struct nfsd4_readlink {
274         struct svc_rqst *rl_rqstp;          /* request */
275         struct svc_fh * rl_fhp;             /* request */
276 };
277
278 struct nfsd4_remove {
279         u32             rm_namelen;         /* request */
280         char *          rm_name;            /* request */
281         struct nfsd4_change_info  rm_cinfo; /* response */
282 };
283
284 struct nfsd4_rename {
285         u32             rn_snamelen;        /* request */
286         char *          rn_sname;           /* request */
287         u32             rn_tnamelen;        /* request */
288         char *          rn_tname;           /* request */
289         struct nfsd4_change_info  rn_sinfo; /* response */
290         struct nfsd4_change_info  rn_tinfo; /* response */
291 };
292
293 struct nfsd4_setattr {
294         stateid_t       sa_stateid;         /* request */
295         u32             sa_bmval[2];        /* request */
296         struct iattr    sa_iattr;           /* request */
297         struct nfs4_acl *sa_acl;
298 };
299
300 struct nfsd4_setclientid {
301         nfs4_verifier   se_verf;            /* request */
302         u32             se_namelen;         /* request */
303         char *          se_name;            /* request */
304         u32             se_callback_prog;   /* request */
305         u32             se_callback_netid_len;  /* request */
306         char *          se_callback_netid_val;  /* request */
307         u32             se_callback_addr_len;   /* request */
308         char *          se_callback_addr_val;   /* request */
309         u32             se_callback_ident;  /* request */
310         clientid_t      se_clientid;        /* response */
311         nfs4_verifier   se_confirm;         /* response */
312 };
313
314 struct nfsd4_setclientid_confirm {
315         clientid_t      sc_clientid;
316         nfs4_verifier   sc_confirm;
317 };
318
319 /* also used for NVERIFY */
320 struct nfsd4_verify {
321         u32             ve_bmval[2];        /* request */
322         u32             ve_attrlen;         /* request */
323         char *          ve_attrval;         /* request */
324 };
325
326 struct nfsd4_write {
327         stateid_t       wr_stateid;         /* request */
328         u64             wr_offset;          /* request */
329         u32             wr_stable_how;      /* request */
330         u32             wr_buflen;          /* request */
331         struct kvec     wr_vec[RPCSVC_MAXPAGES]; /* request */
332         int             wr_vlen;
333
334         u32             wr_bytes_written;   /* response */
335         u32             wr_how_written;     /* response */
336         nfs4_verifier   wr_verifier;        /* response */
337 };
338
339 struct nfsd4_op {
340         int                                     opnum;
341         int                                     status;
342         union {
343                 struct nfsd4_access             access;
344                 struct nfsd4_close              close;
345                 struct nfsd4_commit             commit;
346                 struct nfsd4_create             create;
347                 struct nfsd4_getattr            getattr;
348                 struct svc_fh *                 getfh;
349                 struct nfsd4_link               link;
350                 struct nfsd4_lock               lock;
351                 struct nfsd4_lockt              lockt;
352                 struct nfsd4_locku              locku;
353                 struct nfsd4_lookup             lookup;
354                 struct nfsd4_verify             nverify;
355                 struct nfsd4_open               open;
356                 struct nfsd4_open_confirm       open_confirm;
357                 struct nfsd4_open_downgrade     open_downgrade;
358                 struct nfsd4_putfh              putfh;
359                 struct nfsd4_read               read;
360                 struct nfsd4_readdir            readdir;
361                 struct nfsd4_readlink           readlink;
362                 struct nfsd4_remove             remove;
363                 struct nfsd4_rename             rename;
364                 clientid_t                      renew;
365                 struct nfsd4_setattr            setattr;
366                 struct nfsd4_setclientid        setclientid;
367                 struct nfsd4_setclientid_confirm setclientid_confirm;
368                 struct nfsd4_verify             verify;
369                 struct nfsd4_write              write;
370                 struct nfsd4_release_lockowner  release_lockowner;
371         } u;
372         struct nfs4_replay *                    replay;
373 };
374
375 struct nfsd4_compoundargs {
376         /* scratch variables for XDR decode */
377         u32 *                           p;
378         u32 *                           end;
379         struct page **                  pagelist;
380         int                             pagelen;
381         u32                             tmp[8];
382         u32 *                           tmpp;
383         struct tmpbuf {
384                 struct tmpbuf *next;
385                 void (*release)(const void *);
386                 void *buf;
387         }                               *to_free;
388
389         struct svc_rqst                 *rqstp;
390
391         u32                             taglen;
392         char *                          tag;
393         u32                             minorversion;
394         u32                             opcnt;
395         struct nfsd4_op                 *ops;
396         struct nfsd4_op                 iops[8];
397 };
398
399 struct nfsd4_compoundres {
400         /* scratch variables for XDR encode */
401         u32 *                           p;
402         u32 *                           end;
403         struct xdr_buf *                xbuf;
404         struct svc_rqst *               rqstp;
405
406         u32                             taglen;
407         char *                          tag;
408         u32                             opcnt;
409         u32 *                           tagp; /* where to encode tag and  opcount */
410 };
411
412 #define NFS4_SVC_XDRSIZE                sizeof(struct nfsd4_compoundargs)
413
414 static inline void
415 set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp)
416 {
417         BUG_ON(!fhp->fh_pre_saved || !fhp->fh_post_saved);
418         cinfo->atomic = 1;
419         cinfo->before_ctime_sec = fhp->fh_pre_ctime.tv_sec;
420         cinfo->before_ctime_nsec = fhp->fh_pre_ctime.tv_nsec;
421         cinfo->after_ctime_sec = fhp->fh_post_ctime.tv_sec;
422         cinfo->after_ctime_nsec = fhp->fh_post_ctime.tv_nsec;
423 }
424
425 int nfs4svc_encode_voidres(struct svc_rqst *, u32 *, void *);
426 int nfs4svc_decode_compoundargs(struct svc_rqst *, u32 *, 
427                 struct nfsd4_compoundargs *);
428 int nfs4svc_encode_compoundres(struct svc_rqst *, u32 *, 
429                 struct nfsd4_compoundres *);
430 void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *);
431 void nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op);
432 int nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
433                        struct dentry *dentry, u32 *buffer, int *countp, 
434                        u32 *bmval, struct svc_rqst *);
435 extern int nfsd4_setclientid(struct svc_rqst *rqstp, 
436                 struct nfsd4_setclientid *setclid);
437 extern int nfsd4_setclientid_confirm(struct svc_rqst *rqstp, 
438                 struct nfsd4_setclientid_confirm *setclientid_confirm);
439 extern int nfsd4_process_open1(struct nfsd4_open *open);
440 extern int nfsd4_process_open2(struct svc_rqst *rqstp, 
441                 struct svc_fh *current_fh, struct nfsd4_open *open);
442 extern int nfsd4_open_confirm(struct svc_rqst *rqstp, 
443                 struct svc_fh *current_fh, struct nfsd4_open_confirm *oc);
444 extern  int nfsd4_close(struct svc_rqst *rqstp, struct svc_fh *current_fh, 
445                 struct nfsd4_close *close);
446 extern int nfsd4_open_downgrade(struct svc_rqst *rqstp, 
447                 struct svc_fh *current_fh, struct nfsd4_open_downgrade *od);
448 extern int nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, 
449                 struct nfsd4_lock *lock);
450 extern int nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, 
451                 struct nfsd4_lockt *lockt);
452 extern int nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, 
453                 struct nfsd4_locku *locku);
454 extern int
455 nfsd4_release_lockowner(struct svc_rqst *rqstp,
456                 struct nfsd4_release_lockowner *rlockowner);
457 extern void nfsd4_release_compoundargs(struct nfsd4_compoundargs *);
458 #endif
459
460 /*
461  * Local variables:
462  *  c-basic-offset: 8
463  * End:
464  */