NFSv4: Fix a potential CLOSE race
[linux-2.6-block.git] / fs / nfs / nfs4proc.c
1 /*
2  *  fs/nfs/nfs4proc.c
3  *
4  *  Client-side procedure declarations 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 #include <linux/mm.h>
39 #include <linux/utsname.h>
40 #include <linux/delay.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/nfs.h>
45 #include <linux/nfs4.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/nfs_page.h>
48 #include <linux/smp_lock.h>
49 #include <linux/namei.h>
50
51 #include "nfs4_fs.h"
52 #include "delegation.h"
53
54 #define NFSDBG_FACILITY         NFSDBG_PROC
55
56 #define NFS4_POLL_RETRY_MIN     (1*HZ)
57 #define NFS4_POLL_RETRY_MAX     (15*HZ)
58
59 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
60 static int nfs4_async_handle_error(struct rpc_task *, struct nfs_server *);
61 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
62 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
63 extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
64 extern struct rpc_procinfo nfs4_procedures[];
65
66 /* Prevent leaks of NFSv4 errors into userland */
67 int nfs4_map_errors(int err)
68 {
69         if (err < -1000) {
70                 dprintk("%s could not handle NFSv4 error %d\n",
71                                 __FUNCTION__, -err);
72                 return -EIO;
73         }
74         return err;
75 }
76
77 /*
78  * This is our standard bitmap for GETATTR requests.
79  */
80 const u32 nfs4_fattr_bitmap[2] = {
81         FATTR4_WORD0_TYPE
82         | FATTR4_WORD0_CHANGE
83         | FATTR4_WORD0_SIZE
84         | FATTR4_WORD0_FSID
85         | FATTR4_WORD0_FILEID,
86         FATTR4_WORD1_MODE
87         | FATTR4_WORD1_NUMLINKS
88         | FATTR4_WORD1_OWNER
89         | FATTR4_WORD1_OWNER_GROUP
90         | FATTR4_WORD1_RAWDEV
91         | FATTR4_WORD1_SPACE_USED
92         | FATTR4_WORD1_TIME_ACCESS
93         | FATTR4_WORD1_TIME_METADATA
94         | FATTR4_WORD1_TIME_MODIFY
95 };
96
97 const u32 nfs4_statfs_bitmap[2] = {
98         FATTR4_WORD0_FILES_AVAIL
99         | FATTR4_WORD0_FILES_FREE
100         | FATTR4_WORD0_FILES_TOTAL,
101         FATTR4_WORD1_SPACE_AVAIL
102         | FATTR4_WORD1_SPACE_FREE
103         | FATTR4_WORD1_SPACE_TOTAL
104 };
105
106 const u32 nfs4_pathconf_bitmap[2] = {
107         FATTR4_WORD0_MAXLINK
108         | FATTR4_WORD0_MAXNAME,
109         0
110 };
111
112 const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
113                         | FATTR4_WORD0_MAXREAD
114                         | FATTR4_WORD0_MAXWRITE
115                         | FATTR4_WORD0_LEASE_TIME,
116                         0
117 };
118
119 static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry,
120                 struct nfs4_readdir_arg *readdir)
121 {
122         u32 *start, *p;
123
124         BUG_ON(readdir->count < 80);
125         if (cookie > 2) {
126                 readdir->cookie = cookie;
127                 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
128                 return;
129         }
130
131         readdir->cookie = 0;
132         memset(&readdir->verifier, 0, sizeof(readdir->verifier));
133         if (cookie == 2)
134                 return;
135         
136         /*
137          * NFSv4 servers do not return entries for '.' and '..'
138          * Therefore, we fake these entries here.  We let '.'
139          * have cookie 0 and '..' have cookie 1.  Note that
140          * when talking to the server, we always send cookie 0
141          * instead of 1 or 2.
142          */
143         start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0);
144         
145         if (cookie == 0) {
146                 *p++ = xdr_one;                                  /* next */
147                 *p++ = xdr_zero;                   /* cookie, first word */
148                 *p++ = xdr_one;                   /* cookie, second word */
149                 *p++ = xdr_one;                             /* entry len */
150                 memcpy(p, ".\0\0\0", 4);                        /* entry */
151                 p++;
152                 *p++ = xdr_one;                         /* bitmap length */
153                 *p++ = htonl(FATTR4_WORD0_FILEID);             /* bitmap */
154                 *p++ = htonl(8);              /* attribute buffer length */
155                 p = xdr_encode_hyper(p, dentry->d_inode->i_ino);
156         }
157         
158         *p++ = xdr_one;                                  /* next */
159         *p++ = xdr_zero;                   /* cookie, first word */
160         *p++ = xdr_two;                   /* cookie, second word */
161         *p++ = xdr_two;                             /* entry len */
162         memcpy(p, "..\0\0", 4);                         /* entry */
163         p++;
164         *p++ = xdr_one;                         /* bitmap length */
165         *p++ = htonl(FATTR4_WORD0_FILEID);             /* bitmap */
166         *p++ = htonl(8);              /* attribute buffer length */
167         p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino);
168
169         readdir->pgbase = (char *)p - (char *)start;
170         readdir->count -= readdir->pgbase;
171         kunmap_atomic(start, KM_USER0);
172 }
173
174 static void
175 renew_lease(struct nfs_server *server, unsigned long timestamp)
176 {
177         struct nfs4_client *clp = server->nfs4_state;
178         spin_lock(&clp->cl_lock);
179         if (time_before(clp->cl_last_renewal,timestamp))
180                 clp->cl_last_renewal = timestamp;
181         spin_unlock(&clp->cl_lock);
182 }
183
184 static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo)
185 {
186         struct nfs_inode *nfsi = NFS_I(inode);
187
188         if (cinfo->before == nfsi->change_attr && cinfo->atomic)
189                 nfsi->change_attr = cinfo->after;
190 }
191
192 /* Helper for asynchronous RPC calls */
193 static int nfs4_call_async(struct rpc_clnt *clnt, rpc_action tk_begin,
194                 rpc_action tk_exit, void *calldata)
195 {
196         struct rpc_task *task;
197
198         if (!(task = rpc_new_task(clnt, tk_exit, RPC_TASK_ASYNC)))
199                 return -ENOMEM;
200
201         task->tk_calldata = calldata;
202         task->tk_action = tk_begin;
203         rpc_execute(task);
204         return 0;
205 }
206
207 static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
208 {
209         struct inode *inode = state->inode;
210
211         open_flags &= (FMODE_READ|FMODE_WRITE);
212         /* Protect against nfs4_find_state() */
213         spin_lock(&inode->i_lock);
214         state->state |= open_flags;
215         /* NB! List reordering - see the reclaim code for why.  */
216         if ((open_flags & FMODE_WRITE) && 0 == state->nwriters++)
217                 list_move(&state->open_states, &state->owner->so_states);
218         if (open_flags & FMODE_READ)
219                 state->nreaders++;
220         memcpy(&state->stateid, stateid, sizeof(state->stateid));
221         spin_unlock(&inode->i_lock);
222 }
223
224 /*
225  * OPEN_RECLAIM:
226  *      reclaim state on the server after a reboot.
227  *      Assumes caller is holding the sp->so_sem
228  */
229 static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
230 {
231         struct inode *inode = state->inode;
232         struct nfs_server *server = NFS_SERVER(inode);
233         struct nfs_delegation *delegation = NFS_I(inode)->delegation;
234         struct nfs_openargs o_arg = {
235                 .fh = NFS_FH(inode),
236                 .id = sp->so_id,
237                 .open_flags = state->state,
238                 .clientid = server->nfs4_state->cl_clientid,
239                 .claim = NFS4_OPEN_CLAIM_PREVIOUS,
240                 .bitmask = server->attr_bitmask,
241         };
242         struct nfs_openres o_res = {
243                 .server = server,       /* Grrr */
244         };
245         struct rpc_message msg = {
246                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
247                 .rpc_argp       = &o_arg,
248                 .rpc_resp       = &o_res,
249                 .rpc_cred       = sp->so_cred,
250         };
251         int status;
252
253         if (delegation != NULL) {
254                 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
255                         memcpy(&state->stateid, &delegation->stateid,
256                                         sizeof(state->stateid));
257                         set_bit(NFS_DELEGATED_STATE, &state->flags);
258                         return 0;
259                 }
260                 o_arg.u.delegation_type = delegation->type;
261         }
262         o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
263         if (o_arg.seqid == NULL)
264                 return -ENOMEM;
265         status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
266         /* Confirm the sequence as being established */
267         nfs_confirm_seqid(&sp->so_seqid, status);
268         nfs_increment_open_seqid(status, o_arg.seqid);
269         if (status == 0) {
270                 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
271                 if (o_res.delegation_type != 0) {
272                         nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
273                         /* Did the server issue an immediate delegation recall? */
274                         if (o_res.do_recall)
275                                 nfs_async_inode_return_delegation(inode, &o_res.stateid);
276                 }
277         }
278         nfs_free_seqid(o_arg.seqid);
279         clear_bit(NFS_DELEGATED_STATE, &state->flags);
280         /* Ensure we update the inode attributes */
281         NFS_CACHEINV(inode);
282         return status;
283 }
284
285 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
286 {
287         struct nfs_server *server = NFS_SERVER(state->inode);
288         struct nfs4_exception exception = { };
289         int err;
290         do {
291                 err = _nfs4_open_reclaim(sp, state);
292                 if (err != -NFS4ERR_DELAY)
293                         break;
294                 nfs4_handle_exception(server, err, &exception);
295         } while (exception.retry);
296         return err;
297 }
298
299 static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
300 {
301         struct nfs4_state_owner  *sp  = state->owner;
302         struct inode *inode = dentry->d_inode;
303         struct nfs_server *server = NFS_SERVER(inode);
304         struct dentry *parent = dget_parent(dentry);
305         struct nfs_openargs arg = {
306                 .fh = NFS_FH(parent->d_inode),
307                 .clientid = server->nfs4_state->cl_clientid,
308                 .name = &dentry->d_name,
309                 .id = sp->so_id,
310                 .server = server,
311                 .bitmask = server->attr_bitmask,
312                 .claim = NFS4_OPEN_CLAIM_DELEGATE_CUR,
313         };
314         struct nfs_openres res = {
315                 .server = server,
316         };
317         struct  rpc_message msg = {
318                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
319                 .rpc_argp       = &arg,
320                 .rpc_resp       = &res,
321                 .rpc_cred       = sp->so_cred,
322         };
323         int status = 0;
324
325         down(&sp->so_sema);
326         if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
327                 goto out;
328         if (state->state == 0)
329                 goto out;
330         arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
331         status = -ENOMEM;
332         if (arg.seqid == NULL)
333                 goto out;
334         arg.open_flags = state->state;
335         memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data));
336         status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
337         nfs_increment_open_seqid(status, arg.seqid);
338         if (status >= 0) {
339                 memcpy(state->stateid.data, res.stateid.data,
340                                 sizeof(state->stateid.data));
341                 clear_bit(NFS_DELEGATED_STATE, &state->flags);
342         }
343         nfs_free_seqid(arg.seqid);
344 out:
345         up(&sp->so_sema);
346         dput(parent);
347         return status;
348 }
349
350 int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
351 {
352         struct nfs4_exception exception = { };
353         struct nfs_server *server = NFS_SERVER(dentry->d_inode);
354         int err;
355         do {
356                 err = _nfs4_open_delegation_recall(dentry, state);
357                 switch (err) {
358                         case 0:
359                                 return err;
360                         case -NFS4ERR_STALE_CLIENTID:
361                         case -NFS4ERR_STALE_STATEID:
362                         case -NFS4ERR_EXPIRED:
363                                 /* Don't recall a delegation if it was lost */
364                                 nfs4_schedule_state_recovery(server->nfs4_state);
365                                 return err;
366                 }
367                 err = nfs4_handle_exception(server, err, &exception);
368         } while (exception.retry);
369         return err;
370 }
371
372 static inline int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid)
373 {
374         struct nfs_open_confirmargs arg = {
375                 .fh             = fh,
376                 .seqid          = seqid,
377                 .stateid        = *stateid,
378         };
379         struct nfs_open_confirmres res;
380         struct  rpc_message msg = {
381                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
382                 .rpc_argp       = &arg,
383                 .rpc_resp       = &res,
384                 .rpc_cred       = sp->so_cred,
385         };
386         int status;
387
388         status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR);
389         /* Confirm the sequence as being established */
390         nfs_confirm_seqid(&sp->so_seqid, status);
391         nfs_increment_open_seqid(status, seqid);
392         if (status >= 0)
393                 memcpy(stateid, &res.stateid, sizeof(*stateid));
394         return status;
395 }
396
397 static int _nfs4_proc_open(struct inode *dir, struct nfs4_state_owner  *sp, struct nfs_openargs *o_arg, struct nfs_openres *o_res)
398 {
399         struct nfs_server *server = NFS_SERVER(dir);
400         struct rpc_message msg = {
401                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
402                 .rpc_argp = o_arg,
403                 .rpc_resp = o_res,
404                 .rpc_cred = sp->so_cred,
405         };
406         int status;
407
408         /* Update sequence id. The caller must serialize! */
409         o_arg->id = sp->so_id;
410         o_arg->clientid = sp->so_client->cl_clientid;
411
412         status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
413         nfs_increment_open_seqid(status, o_arg->seqid);
414         if (status != 0)
415                 goto out;
416         update_changeattr(dir, &o_res->cinfo);
417         if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
418                 status = _nfs4_proc_open_confirm(server->client, &o_res->fh,
419                                 sp, &o_res->stateid, o_arg->seqid);
420                 if (status != 0)
421                         goto out;
422         }
423         nfs_confirm_seqid(&sp->so_seqid, 0);
424         if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
425                 status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr);
426 out:
427         return status;
428 }
429
430 static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags)
431 {
432         struct nfs_access_entry cache;
433         int mask = 0;
434         int status;
435
436         if (openflags & FMODE_READ)
437                 mask |= MAY_READ;
438         if (openflags & FMODE_WRITE)
439                 mask |= MAY_WRITE;
440         status = nfs_access_get_cached(inode, cred, &cache);
441         if (status == 0)
442                 goto out;
443
444         /* Be clever: ask server to check for all possible rights */
445         cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ;
446         cache.cred = cred;
447         cache.jiffies = jiffies;
448         status = _nfs4_proc_access(inode, &cache);
449         if (status != 0)
450                 return status;
451         nfs_access_add_cache(inode, &cache);
452 out:
453         if ((cache.mask & mask) == mask)
454                 return 0;
455         return -EACCES;
456 }
457
458 /*
459  * OPEN_EXPIRED:
460  *      reclaim state on the server after a network partition.
461  *      Assumes caller holds the appropriate lock
462  */
463 static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
464 {
465         struct dentry *parent = dget_parent(dentry);
466         struct inode *dir = parent->d_inode;
467         struct inode *inode = state->inode;
468         struct nfs_server *server = NFS_SERVER(dir);
469         struct nfs_delegation *delegation = NFS_I(inode)->delegation;
470         struct nfs_fattr        f_attr = {
471                 .valid = 0,
472         };
473         struct nfs_openargs o_arg = {
474                 .fh = NFS_FH(dir),
475                 .open_flags = state->state,
476                 .name = &dentry->d_name,
477                 .bitmask = server->attr_bitmask,
478                 .claim = NFS4_OPEN_CLAIM_NULL,
479         };
480         struct nfs_openres o_res = {
481                 .f_attr = &f_attr,
482                 .server = server,
483         };
484         int status = 0;
485
486         if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
487                 status = _nfs4_do_access(inode, sp->so_cred, state->state);
488                 if (status < 0)
489                         goto out;
490                 memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid));
491                 set_bit(NFS_DELEGATED_STATE, &state->flags);
492                 goto out;
493         }
494         o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
495         status = -ENOMEM;
496         if (o_arg.seqid == NULL)
497                 goto out;
498         status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
499         if (status != 0)
500                 goto out_nodeleg;
501         /* Check if files differ */
502         if ((f_attr.mode & S_IFMT) != (inode->i_mode & S_IFMT))
503                 goto out_stale;
504         /* Has the file handle changed? */
505         if (nfs_compare_fh(&o_res.fh, NFS_FH(inode)) != 0) {
506                 /* Verify if the change attributes are the same */
507                 if (f_attr.change_attr != NFS_I(inode)->change_attr)
508                         goto out_stale;
509                 if (nfs_size_to_loff_t(f_attr.size) != inode->i_size)
510                         goto out_stale;
511                 /* Lets just pretend that this is the same file */
512                 nfs_copy_fh(NFS_FH(inode), &o_res.fh);
513                 NFS_I(inode)->fileid = f_attr.fileid;
514         }
515         memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
516         if (o_res.delegation_type != 0) {
517                 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM))
518                         nfs_inode_set_delegation(inode, sp->so_cred, &o_res);
519                 else
520                         nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
521         }
522 out_nodeleg:
523         nfs_free_seqid(o_arg.seqid);
524         clear_bit(NFS_DELEGATED_STATE, &state->flags);
525 out:
526         dput(parent);
527         return status;
528 out_stale:
529         status = -ESTALE;
530         /* Invalidate the state owner so we don't ever use it again */
531         nfs4_drop_state_owner(sp);
532         d_drop(dentry);
533         /* Should we be trying to close that stateid? */
534         goto out_nodeleg;
535 }
536
537 static inline int nfs4_do_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
538 {
539         struct nfs_server *server = NFS_SERVER(dentry->d_inode);
540         struct nfs4_exception exception = { };
541         int err;
542
543         do {
544                 err = _nfs4_open_expired(sp, state, dentry);
545                 if (err == -NFS4ERR_DELAY)
546                         nfs4_handle_exception(server, err, &exception);
547         } while (exception.retry);
548         return err;
549 }
550
551 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
552 {
553         struct nfs_inode *nfsi = NFS_I(state->inode);
554         struct nfs_open_context *ctx;
555         int status;
556
557         spin_lock(&state->inode->i_lock);
558         list_for_each_entry(ctx, &nfsi->open_files, list) {
559                 if (ctx->state != state)
560                         continue;
561                 get_nfs_open_context(ctx);
562                 spin_unlock(&state->inode->i_lock);
563                 status = nfs4_do_open_expired(sp, state, ctx->dentry);
564                 put_nfs_open_context(ctx);
565                 return status;
566         }
567         spin_unlock(&state->inode->i_lock);
568         return -ENOENT;
569 }
570
571 /*
572  * Returns an nfs4_state + an extra reference to the inode
573  */
574 static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res)
575 {
576         struct nfs_delegation *delegation;
577         struct nfs_server *server = NFS_SERVER(inode);
578         struct nfs4_client *clp = server->nfs4_state;
579         struct nfs_inode *nfsi = NFS_I(inode);
580         struct nfs4_state_owner *sp = NULL;
581         struct nfs4_state *state = NULL;
582         int open_flags = flags & (FMODE_READ|FMODE_WRITE);
583         int err;
584
585         /* Protect against reboot recovery - NOTE ORDER! */
586         down_read(&clp->cl_sem);
587         /* Protect against delegation recall */
588         down_read(&nfsi->rwsem);
589         delegation = NFS_I(inode)->delegation;
590         err = -ENOENT;
591         if (delegation == NULL || (delegation->type & open_flags) != open_flags)
592                 goto out_err;
593         err = -ENOMEM;
594         if (!(sp = nfs4_get_state_owner(server, cred))) {
595                 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
596                 goto out_err;
597         }
598         down(&sp->so_sema);
599         state = nfs4_get_open_state(inode, sp);
600         if (state == NULL)
601                 goto out_err;
602
603         err = -ENOENT;
604         if ((state->state & open_flags) == open_flags) {
605                 spin_lock(&inode->i_lock);
606                 if (open_flags & FMODE_READ)
607                         state->nreaders++;
608                 if (open_flags & FMODE_WRITE)
609                         state->nwriters++;
610                 spin_unlock(&inode->i_lock);
611                 goto out_ok;
612         } else if (state->state != 0)
613                 goto out_err;
614
615         lock_kernel();
616         err = _nfs4_do_access(inode, cred, open_flags);
617         unlock_kernel();
618         if (err != 0)
619                 goto out_err;
620         set_bit(NFS_DELEGATED_STATE, &state->flags);
621         update_open_stateid(state, &delegation->stateid, open_flags);
622 out_ok:
623         up(&sp->so_sema);
624         nfs4_put_state_owner(sp);
625         up_read(&nfsi->rwsem);
626         up_read(&clp->cl_sem);
627         igrab(inode);
628         *res = state;
629         return 0; 
630 out_err:
631         if (sp != NULL) {
632                 if (state != NULL)
633                         nfs4_put_open_state(state);
634                 up(&sp->so_sema);
635                 nfs4_put_state_owner(sp);
636         }
637         up_read(&nfsi->rwsem);
638         up_read(&clp->cl_sem);
639         return err;
640 }
641
642 static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred)
643 {
644         struct nfs4_exception exception = { };
645         struct nfs4_state *res;
646         int err;
647
648         do {
649                 err = _nfs4_open_delegated(inode, flags, cred, &res);
650                 if (err == 0)
651                         break;
652                 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode),
653                                         err, &exception));
654         } while (exception.retry);
655         return res;
656 }
657
658 /*
659  * Returns an nfs4_state + an referenced inode
660  */
661 static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
662 {
663         struct nfs4_state_owner  *sp;
664         struct nfs4_state     *state = NULL;
665         struct nfs_server       *server = NFS_SERVER(dir);
666         struct nfs4_client *clp = server->nfs4_state;
667         struct inode *inode = NULL;
668         int                     status;
669         struct nfs_fattr        f_attr = {
670                 .valid          = 0,
671         };
672         struct nfs_openargs o_arg = {
673                 .fh             = NFS_FH(dir),
674                 .open_flags     = flags,
675                 .name           = &dentry->d_name,
676                 .server         = server,
677                 .bitmask = server->attr_bitmask,
678                 .claim = NFS4_OPEN_CLAIM_NULL,
679         };
680         struct nfs_openres o_res = {
681                 .f_attr         = &f_attr,
682                 .server         = server,
683         };
684
685         /* Protect against reboot recovery conflicts */
686         down_read(&clp->cl_sem);
687         status = -ENOMEM;
688         if (!(sp = nfs4_get_state_owner(server, cred))) {
689                 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
690                 goto out_err;
691         }
692         if (flags & O_EXCL) {
693                 u32 *p = (u32 *) o_arg.u.verifier.data;
694                 p[0] = jiffies;
695                 p[1] = current->pid;
696         } else
697                 o_arg.u.attrs = sattr;
698         /* Serialization for the sequence id */
699         down(&sp->so_sema);
700
701         o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
702         if (o_arg.seqid == NULL)
703                 return -ENOMEM;
704         status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
705         if (status != 0)
706                 goto out_err;
707
708         status = -ENOMEM;
709         inode = nfs_fhget(dir->i_sb, &o_res.fh, &f_attr);
710         if (!inode)
711                 goto out_err;
712         state = nfs4_get_open_state(inode, sp);
713         if (!state)
714                 goto out_err;
715         update_open_stateid(state, &o_res.stateid, flags);
716         if (o_res.delegation_type != 0)
717                 nfs_inode_set_delegation(inode, cred, &o_res);
718         nfs_free_seqid(o_arg.seqid);
719         up(&sp->so_sema);
720         nfs4_put_state_owner(sp);
721         up_read(&clp->cl_sem);
722         *res = state;
723         return 0;
724 out_err:
725         if (sp != NULL) {
726                 if (state != NULL)
727                         nfs4_put_open_state(state);
728                 nfs_free_seqid(o_arg.seqid);
729                 up(&sp->so_sema);
730                 nfs4_put_state_owner(sp);
731         }
732         /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
733         up_read(&clp->cl_sem);
734         if (inode != NULL)
735                 iput(inode);
736         *res = NULL;
737         return status;
738 }
739
740
741 static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred)
742 {
743         struct nfs4_exception exception = { };
744         struct nfs4_state *res;
745         int status;
746
747         do {
748                 status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res);
749                 if (status == 0)
750                         break;
751                 /* NOTE: BAD_SEQID means the server and client disagree about the
752                  * book-keeping w.r.t. state-changing operations
753                  * (OPEN/CLOSE/LOCK/LOCKU...)
754                  * It is actually a sign of a bug on the client or on the server.
755                  *
756                  * If we receive a BAD_SEQID error in the particular case of
757                  * doing an OPEN, we assume that nfs_increment_open_seqid() will
758                  * have unhashed the old state_owner for us, and that we can
759                  * therefore safely retry using a new one. We should still warn
760                  * the user though...
761                  */
762                 if (status == -NFS4ERR_BAD_SEQID) {
763                         printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n");
764                         exception.retry = 1;
765                         continue;
766                 }
767                 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
768                                         status, &exception));
769         } while (exception.retry);
770         return res;
771 }
772
773 static int _nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
774                 struct nfs_fh *fhandle, struct iattr *sattr,
775                 struct nfs4_state *state)
776 {
777         struct nfs_setattrargs  arg = {
778                 .fh             = fhandle,
779                 .iap            = sattr,
780                 .server         = server,
781                 .bitmask = server->attr_bitmask,
782         };
783         struct nfs_setattrres  res = {
784                 .fattr          = fattr,
785                 .server         = server,
786         };
787         struct rpc_message msg = {
788                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
789                 .rpc_argp       = &arg,
790                 .rpc_resp       = &res,
791         };
792         int status;
793
794         fattr->valid = 0;
795
796         if (state != NULL) {
797                 msg.rpc_cred = state->owner->so_cred;
798                 nfs4_copy_stateid(&arg.stateid, state, current->files);
799         } else
800                 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
801
802         status = rpc_call_sync(server->client, &msg, 0);
803         return status;
804 }
805
806 static int nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
807                 struct nfs_fh *fhandle, struct iattr *sattr,
808                 struct nfs4_state *state)
809 {
810         struct nfs4_exception exception = { };
811         int err;
812         do {
813                 err = nfs4_handle_exception(server,
814                                 _nfs4_do_setattr(server, fattr, fhandle, sattr,
815                                         state),
816                                 &exception);
817         } while (exception.retry);
818         return err;
819 }
820
821 struct nfs4_closedata {
822         struct inode *inode;
823         struct nfs4_state *state;
824         struct nfs_closeargs arg;
825         struct nfs_closeres res;
826 };
827
828 static void nfs4_free_closedata(struct nfs4_closedata *calldata)
829 {
830         struct nfs4_state *state = calldata->state;
831         struct nfs4_state_owner *sp = state->owner;
832         struct nfs_server *server = NFS_SERVER(calldata->inode);
833
834         nfs4_put_open_state(calldata->state);
835         nfs_free_seqid(calldata->arg.seqid);
836         up(&sp->so_sema);
837         nfs4_put_state_owner(sp);
838         up_read(&server->nfs4_state->cl_sem);
839         kfree(calldata);
840 }
841
842 static void nfs4_close_done(struct rpc_task *task)
843 {
844         struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
845         struct nfs4_state *state = calldata->state;
846         struct nfs_server *server = NFS_SERVER(calldata->inode);
847
848         /* hmm. we are done with the inode, and in the process of freeing
849          * the state_owner. we keep this around to process errors
850          */
851         nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid);
852         switch (task->tk_status) {
853                 case 0:
854                         memcpy(&state->stateid, &calldata->res.stateid,
855                                         sizeof(state->stateid));
856                         break;
857                 case -NFS4ERR_STALE_STATEID:
858                 case -NFS4ERR_EXPIRED:
859                         state->state = calldata->arg.open_flags;
860                         nfs4_schedule_state_recovery(server->nfs4_state);
861                         break;
862                 default:
863                         if (nfs4_async_handle_error(task, server) == -EAGAIN) {
864                                 rpc_restart_call(task);
865                                 return;
866                         }
867         }
868         state->state = calldata->arg.open_flags;
869         nfs4_free_closedata(calldata);
870 }
871
872 static void nfs4_close_begin(struct rpc_task *task)
873 {
874         struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
875         struct nfs4_state *state = calldata->state;
876         struct rpc_message msg = {
877                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
878                 .rpc_argp = &calldata->arg,
879                 .rpc_resp = &calldata->res,
880                 .rpc_cred = state->owner->so_cred,
881         };
882         int mode = 0;
883         int status;
884
885         status = nfs_wait_on_sequence(calldata->arg.seqid, task);
886         if (status != 0)
887                 return;
888         /* Don't reorder reads */
889         smp_rmb();
890         /* Recalculate the new open mode in case someone reopened the file
891          * while we were waiting in line to be scheduled.
892          */
893         if (state->nreaders != 0)
894                 mode |= FMODE_READ;
895         if (state->nwriters != 0)
896                 mode |= FMODE_WRITE;
897         if (test_bit(NFS_DELEGATED_STATE, &state->flags))
898                 state->state = mode;
899         if (mode == state->state) {
900                 nfs4_free_closedata(calldata);
901                 task->tk_exit = NULL;
902                 rpc_exit(task, 0);
903                 return;
904         }
905         if (mode != 0)
906                 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
907         calldata->arg.open_flags = mode;
908         rpc_call_setup(task, &msg, 0);
909 }
910
911 /* 
912  * It is possible for data to be read/written from a mem-mapped file 
913  * after the sys_close call (which hits the vfs layer as a flush).
914  * This means that we can't safely call nfsv4 close on a file until 
915  * the inode is cleared. This in turn means that we are not good
916  * NFSv4 citizens - we do not indicate to the server to update the file's 
917  * share state even when we are done with one of the three share 
918  * stateid's in the inode.
919  *
920  * NOTE: Caller must be holding the sp->so_owner semaphore!
921  */
922 int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode) 
923 {
924         struct nfs4_closedata *calldata;
925         int status = -ENOMEM;
926
927         calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
928         if (calldata == NULL)
929                 goto out;
930         calldata->inode = inode;
931         calldata->state = state;
932         calldata->arg.fh = NFS_FH(inode);
933         calldata->arg.stateid = &state->stateid;
934         /* Serialization for the sequence id */
935         calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
936         if (calldata->arg.seqid == NULL)
937                 goto out_free_calldata;
938
939         status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_close_begin,
940                         nfs4_close_done, calldata);
941         if (status == 0)
942                 goto out;
943
944         nfs_free_seqid(calldata->arg.seqid);
945 out_free_calldata:
946         kfree(calldata);
947 out:
948         return status;
949 }
950
951 struct inode *
952 nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
953 {
954         struct iattr attr;
955         struct rpc_cred *cred;
956         struct nfs4_state *state;
957
958         if (nd->flags & LOOKUP_CREATE) {
959                 attr.ia_mode = nd->intent.open.create_mode;
960                 attr.ia_valid = ATTR_MODE;
961                 if (!IS_POSIXACL(dir))
962                         attr.ia_mode &= ~current->fs->umask;
963         } else {
964                 attr.ia_valid = 0;
965                 BUG_ON(nd->intent.open.flags & O_CREAT);
966         }
967
968         cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
969         if (IS_ERR(cred))
970                 return (struct inode *)cred;
971         state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
972         put_rpccred(cred);
973         if (IS_ERR(state))
974                 return (struct inode *)state;
975         return state->inode;
976 }
977
978 int
979 nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags)
980 {
981         struct rpc_cred *cred;
982         struct nfs4_state *state;
983         struct inode *inode;
984
985         cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
986         if (IS_ERR(cred))
987                 return PTR_ERR(cred);
988         state = nfs4_open_delegated(dentry->d_inode, openflags, cred);
989         if (IS_ERR(state))
990                 state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
991         put_rpccred(cred);
992         if (state == ERR_PTR(-ENOENT) && dentry->d_inode == 0)
993                 return 1;
994         if (IS_ERR(state))
995                 return 0;
996         inode = state->inode;
997         if (inode == dentry->d_inode) {
998                 iput(inode);
999                 return 1;
1000         }
1001         d_drop(dentry);
1002         nfs4_close_state(state, openflags);
1003         iput(inode);
1004         return 0;
1005 }
1006
1007
1008 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1009 {
1010         struct nfs4_server_caps_res res = {};
1011         struct rpc_message msg = {
1012                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
1013                 .rpc_argp = fhandle,
1014                 .rpc_resp = &res,
1015         };
1016         int status;
1017
1018         status = rpc_call_sync(server->client, &msg, 0);
1019         if (status == 0) {
1020                 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
1021                 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
1022                         server->caps |= NFS_CAP_ACLS;
1023                 if (res.has_links != 0)
1024                         server->caps |= NFS_CAP_HARDLINKS;
1025                 if (res.has_symlinks != 0)
1026                         server->caps |= NFS_CAP_SYMLINKS;
1027                 server->acl_bitmask = res.acl_bitmask;
1028         }
1029         return status;
1030 }
1031
1032 static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1033 {
1034         struct nfs4_exception exception = { };
1035         int err;
1036         do {
1037                 err = nfs4_handle_exception(server,
1038                                 _nfs4_server_capabilities(server, fhandle),
1039                                 &exception);
1040         } while (exception.retry);
1041         return err;
1042 }
1043
1044 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1045                 struct nfs_fsinfo *info)
1046 {
1047         struct nfs_fattr *      fattr = info->fattr;
1048         struct nfs4_lookup_root_arg args = {
1049                 .bitmask = nfs4_fattr_bitmap,
1050         };
1051         struct nfs4_lookup_res res = {
1052                 .server = server,
1053                 .fattr = fattr,
1054                 .fh = fhandle,
1055         };
1056         struct rpc_message msg = {
1057                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
1058                 .rpc_argp = &args,
1059                 .rpc_resp = &res,
1060         };
1061         fattr->valid = 0;
1062         return rpc_call_sync(server->client, &msg, 0);
1063 }
1064
1065 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1066                 struct nfs_fsinfo *info)
1067 {
1068         struct nfs4_exception exception = { };
1069         int err;
1070         do {
1071                 err = nfs4_handle_exception(server,
1072                                 _nfs4_lookup_root(server, fhandle, info),
1073                                 &exception);
1074         } while (exception.retry);
1075         return err;
1076 }
1077
1078 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
1079                 struct nfs_fsinfo *info)
1080 {
1081         struct nfs_fattr *      fattr = info->fattr;
1082         unsigned char *         p;
1083         struct qstr             q;
1084         struct nfs4_lookup_arg args = {
1085                 .dir_fh = fhandle,
1086                 .name = &q,
1087                 .bitmask = nfs4_fattr_bitmap,
1088         };
1089         struct nfs4_lookup_res res = {
1090                 .server = server,
1091                 .fattr = fattr,
1092                 .fh = fhandle,
1093         };
1094         struct rpc_message msg = {
1095                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1096                 .rpc_argp = &args,
1097                 .rpc_resp = &res,
1098         };
1099         int status;
1100
1101         /*
1102          * Now we do a separate LOOKUP for each component of the mount path.
1103          * The LOOKUPs are done separately so that we can conveniently
1104          * catch an ERR_WRONGSEC if it occurs along the way...
1105          */
1106         status = nfs4_lookup_root(server, fhandle, info);
1107         if (status)
1108                 goto out;
1109
1110         p = server->mnt_path;
1111         for (;;) {
1112                 struct nfs4_exception exception = { };
1113
1114                 while (*p == '/')
1115                         p++;
1116                 if (!*p)
1117                         break;
1118                 q.name = p;
1119                 while (*p && (*p != '/'))
1120                         p++;
1121                 q.len = p - q.name;
1122
1123                 do {
1124                         fattr->valid = 0;
1125                         status = nfs4_handle_exception(server,
1126                                         rpc_call_sync(server->client, &msg, 0),
1127                                         &exception);
1128                 } while (exception.retry);
1129                 if (status == 0)
1130                         continue;
1131                 if (status == -ENOENT) {
1132                         printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path);
1133                         printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n");
1134                 }
1135                 break;
1136         }
1137         if (status == 0)
1138                 status = nfs4_server_capabilities(server, fhandle);
1139         if (status == 0)
1140                 status = nfs4_do_fsinfo(server, fhandle, info);
1141 out:
1142         return status;
1143 }
1144
1145 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1146 {
1147         struct nfs4_getattr_arg args = {
1148                 .fh = fhandle,
1149                 .bitmask = server->attr_bitmask,
1150         };
1151         struct nfs4_getattr_res res = {
1152                 .fattr = fattr,
1153                 .server = server,
1154         };
1155         struct rpc_message msg = {
1156                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
1157                 .rpc_argp = &args,
1158                 .rpc_resp = &res,
1159         };
1160         
1161         fattr->valid = 0;
1162         return rpc_call_sync(server->client, &msg, 0);
1163 }
1164
1165 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1166 {
1167         struct nfs4_exception exception = { };
1168         int err;
1169         do {
1170                 err = nfs4_handle_exception(server,
1171                                 _nfs4_proc_getattr(server, fhandle, fattr),
1172                                 &exception);
1173         } while (exception.retry);
1174         return err;
1175 }
1176
1177 /* 
1178  * The file is not closed if it is opened due to the a request to change
1179  * the size of the file. The open call will not be needed once the
1180  * VFS layer lookup-intents are implemented.
1181  *
1182  * Close is called when the inode is destroyed.
1183  * If we haven't opened the file for O_WRONLY, we
1184  * need to in the size_change case to obtain a stateid.
1185  *
1186  * Got race?
1187  * Because OPEN is always done by name in nfsv4, it is
1188  * possible that we opened a different file by the same
1189  * name.  We can recognize this race condition, but we
1190  * can't do anything about it besides returning an error.
1191  *
1192  * This will be fixed with VFS changes (lookup-intent).
1193  */
1194 static int
1195 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1196                   struct iattr *sattr)
1197 {
1198         struct rpc_cred *cred;
1199         struct inode *inode = dentry->d_inode;
1200         struct nfs4_state *state;
1201         int status;
1202
1203         fattr->valid = 0;
1204         
1205         cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
1206         if (IS_ERR(cred))
1207                 return PTR_ERR(cred);
1208         /* Search for an existing WRITE delegation first */
1209         state = nfs4_open_delegated(inode, FMODE_WRITE, cred);
1210         if (!IS_ERR(state)) {
1211                 /* NB: nfs4_open_delegated() bumps the inode->i_count */
1212                 iput(inode);
1213         } else {
1214                 /* Search for an existing open(O_WRITE) stateid */
1215                 state = nfs4_find_state(inode, cred, FMODE_WRITE);
1216         }
1217
1218         status = nfs4_do_setattr(NFS_SERVER(inode), fattr,
1219                         NFS_FH(inode), sattr, state);
1220         if (status == 0)
1221                 nfs_setattr_update_inode(inode, sattr);
1222         if (state != NULL)
1223                 nfs4_close_state(state, FMODE_WRITE);
1224         put_rpccred(cred);
1225         return status;
1226 }
1227
1228 static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,
1229                 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1230 {
1231         int                    status;
1232         struct nfs_server *server = NFS_SERVER(dir);
1233         struct nfs4_lookup_arg args = {
1234                 .bitmask = server->attr_bitmask,
1235                 .dir_fh = NFS_FH(dir),
1236                 .name = name,
1237         };
1238         struct nfs4_lookup_res res = {
1239                 .server = server,
1240                 .fattr = fattr,
1241                 .fh = fhandle,
1242         };
1243         struct rpc_message msg = {
1244                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1245                 .rpc_argp = &args,
1246                 .rpc_resp = &res,
1247         };
1248         
1249         fattr->valid = 0;
1250         
1251         dprintk("NFS call  lookup %s\n", name->name);
1252         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1253         dprintk("NFS reply lookup: %d\n", status);
1254         return status;
1255 }
1256
1257 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1258 {
1259         struct nfs4_exception exception = { };
1260         int err;
1261         do {
1262                 err = nfs4_handle_exception(NFS_SERVER(dir),
1263                                 _nfs4_proc_lookup(dir, name, fhandle, fattr),
1264                                 &exception);
1265         } while (exception.retry);
1266         return err;
1267 }
1268
1269 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1270 {
1271         struct nfs4_accessargs args = {
1272                 .fh = NFS_FH(inode),
1273         };
1274         struct nfs4_accessres res = { 0 };
1275         struct rpc_message msg = {
1276                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
1277                 .rpc_argp = &args,
1278                 .rpc_resp = &res,
1279                 .rpc_cred = entry->cred,
1280         };
1281         int mode = entry->mask;
1282         int status;
1283
1284         /*
1285          * Determine which access bits we want to ask for...
1286          */
1287         if (mode & MAY_READ)
1288                 args.access |= NFS4_ACCESS_READ;
1289         if (S_ISDIR(inode->i_mode)) {
1290                 if (mode & MAY_WRITE)
1291                         args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
1292                 if (mode & MAY_EXEC)
1293                         args.access |= NFS4_ACCESS_LOOKUP;
1294         } else {
1295                 if (mode & MAY_WRITE)
1296                         args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
1297                 if (mode & MAY_EXEC)
1298                         args.access |= NFS4_ACCESS_EXECUTE;
1299         }
1300         status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1301         if (!status) {
1302                 entry->mask = 0;
1303                 if (res.access & NFS4_ACCESS_READ)
1304                         entry->mask |= MAY_READ;
1305                 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
1306                         entry->mask |= MAY_WRITE;
1307                 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
1308                         entry->mask |= MAY_EXEC;
1309         }
1310         return status;
1311 }
1312
1313 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1314 {
1315         struct nfs4_exception exception = { };
1316         int err;
1317         do {
1318                 err = nfs4_handle_exception(NFS_SERVER(inode),
1319                                 _nfs4_proc_access(inode, entry),
1320                                 &exception);
1321         } while (exception.retry);
1322         return err;
1323 }
1324
1325 /*
1326  * TODO: For the time being, we don't try to get any attributes
1327  * along with any of the zero-copy operations READ, READDIR,
1328  * READLINK, WRITE.
1329  *
1330  * In the case of the first three, we want to put the GETATTR
1331  * after the read-type operation -- this is because it is hard
1332  * to predict the length of a GETATTR response in v4, and thus
1333  * align the READ data correctly.  This means that the GETATTR
1334  * may end up partially falling into the page cache, and we should
1335  * shift it into the 'tail' of the xdr_buf before processing.
1336  * To do this efficiently, we need to know the total length
1337  * of data received, which doesn't seem to be available outside
1338  * of the RPC layer.
1339  *
1340  * In the case of WRITE, we also want to put the GETATTR after
1341  * the operation -- in this case because we want to make sure
1342  * we get the post-operation mtime and size.  This means that
1343  * we can't use xdr_encode_pages() as written: we need a variant
1344  * of it which would leave room in the 'tail' iovec.
1345  *
1346  * Both of these changes to the XDR layer would in fact be quite
1347  * minor, but I decided to leave them for a subsequent patch.
1348  */
1349 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
1350                 unsigned int pgbase, unsigned int pglen)
1351 {
1352         struct nfs4_readlink args = {
1353                 .fh       = NFS_FH(inode),
1354                 .pgbase   = pgbase,
1355                 .pglen    = pglen,
1356                 .pages    = &page,
1357         };
1358         struct rpc_message msg = {
1359                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
1360                 .rpc_argp = &args,
1361                 .rpc_resp = NULL,
1362         };
1363
1364         return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1365 }
1366
1367 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
1368                 unsigned int pgbase, unsigned int pglen)
1369 {
1370         struct nfs4_exception exception = { };
1371         int err;
1372         do {
1373                 err = nfs4_handle_exception(NFS_SERVER(inode),
1374                                 _nfs4_proc_readlink(inode, page, pgbase, pglen),
1375                                 &exception);
1376         } while (exception.retry);
1377         return err;
1378 }
1379
1380 static int _nfs4_proc_read(struct nfs_read_data *rdata)
1381 {
1382         int flags = rdata->flags;
1383         struct inode *inode = rdata->inode;
1384         struct nfs_fattr *fattr = rdata->res.fattr;
1385         struct nfs_server *server = NFS_SERVER(inode);
1386         struct rpc_message msg = {
1387                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_READ],
1388                 .rpc_argp       = &rdata->args,
1389                 .rpc_resp       = &rdata->res,
1390                 .rpc_cred       = rdata->cred,
1391         };
1392         unsigned long timestamp = jiffies;
1393         int status;
1394
1395         dprintk("NFS call  read %d @ %Ld\n", rdata->args.count,
1396                         (long long) rdata->args.offset);
1397
1398         fattr->valid = 0;
1399         status = rpc_call_sync(server->client, &msg, flags);
1400         if (!status)
1401                 renew_lease(server, timestamp);
1402         dprintk("NFS reply read: %d\n", status);
1403         return status;
1404 }
1405
1406 static int nfs4_proc_read(struct nfs_read_data *rdata)
1407 {
1408         struct nfs4_exception exception = { };
1409         int err;
1410         do {
1411                 err = nfs4_handle_exception(NFS_SERVER(rdata->inode),
1412                                 _nfs4_proc_read(rdata),
1413                                 &exception);
1414         } while (exception.retry);
1415         return err;
1416 }
1417
1418 static int _nfs4_proc_write(struct nfs_write_data *wdata)
1419 {
1420         int rpcflags = wdata->flags;
1421         struct inode *inode = wdata->inode;
1422         struct nfs_fattr *fattr = wdata->res.fattr;
1423         struct nfs_server *server = NFS_SERVER(inode);
1424         struct rpc_message msg = {
1425                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
1426                 .rpc_argp       = &wdata->args,
1427                 .rpc_resp       = &wdata->res,
1428                 .rpc_cred       = wdata->cred,
1429         };
1430         int status;
1431
1432         dprintk("NFS call  write %d @ %Ld\n", wdata->args.count,
1433                         (long long) wdata->args.offset);
1434
1435         fattr->valid = 0;
1436         status = rpc_call_sync(server->client, &msg, rpcflags);
1437         dprintk("NFS reply write: %d\n", status);
1438         return status;
1439 }
1440
1441 static int nfs4_proc_write(struct nfs_write_data *wdata)
1442 {
1443         struct nfs4_exception exception = { };
1444         int err;
1445         do {
1446                 err = nfs4_handle_exception(NFS_SERVER(wdata->inode),
1447                                 _nfs4_proc_write(wdata),
1448                                 &exception);
1449         } while (exception.retry);
1450         return err;
1451 }
1452
1453 static int _nfs4_proc_commit(struct nfs_write_data *cdata)
1454 {
1455         struct inode *inode = cdata->inode;
1456         struct nfs_fattr *fattr = cdata->res.fattr;
1457         struct nfs_server *server = NFS_SERVER(inode);
1458         struct rpc_message msg = {
1459                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
1460                 .rpc_argp       = &cdata->args,
1461                 .rpc_resp       = &cdata->res,
1462                 .rpc_cred       = cdata->cred,
1463         };
1464         int status;
1465
1466         dprintk("NFS call  commit %d @ %Ld\n", cdata->args.count,
1467                         (long long) cdata->args.offset);
1468
1469         fattr->valid = 0;
1470         status = rpc_call_sync(server->client, &msg, 0);
1471         dprintk("NFS reply commit: %d\n", status);
1472         return status;
1473 }
1474
1475 static int nfs4_proc_commit(struct nfs_write_data *cdata)
1476 {
1477         struct nfs4_exception exception = { };
1478         int err;
1479         do {
1480                 err = nfs4_handle_exception(NFS_SERVER(cdata->inode),
1481                                 _nfs4_proc_commit(cdata),
1482                                 &exception);
1483         } while (exception.retry);
1484         return err;
1485 }
1486
1487 /*
1488  * Got race?
1489  * We will need to arrange for the VFS layer to provide an atomic open.
1490  * Until then, this create/open method is prone to inefficiency and race
1491  * conditions due to the lookup, create, and open VFS calls from sys_open()
1492  * placed on the wire.
1493  *
1494  * Given the above sorry state of affairs, I'm simply sending an OPEN.
1495  * The file will be opened again in the subsequent VFS open call
1496  * (nfs4_proc_file_open).
1497  *
1498  * The open for read will just hang around to be used by any process that
1499  * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1500  */
1501
1502 static int
1503 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1504                  int flags)
1505 {
1506         struct nfs4_state *state;
1507         struct rpc_cred *cred;
1508         int status = 0;
1509
1510         cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1511         if (IS_ERR(cred)) {
1512                 status = PTR_ERR(cred);
1513                 goto out;
1514         }
1515         state = nfs4_do_open(dir, dentry, flags, sattr, cred);
1516         put_rpccred(cred);
1517         if (IS_ERR(state)) {
1518                 status = PTR_ERR(state);
1519                 goto out;
1520         }
1521         d_instantiate(dentry, state->inode);
1522         if (flags & O_EXCL) {
1523                 struct nfs_fattr fattr;
1524                 status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,
1525                                      NFS_FH(state->inode), sattr, state);
1526                 if (status == 0) {
1527                         nfs_setattr_update_inode(state->inode, sattr);
1528                         goto out;
1529                 }
1530         } else if (flags != 0)
1531                 goto out;
1532         nfs4_close_state(state, flags);
1533 out:
1534         return status;
1535 }
1536
1537 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
1538 {
1539         struct nfs4_remove_arg args = {
1540                 .fh = NFS_FH(dir),
1541                 .name = name,
1542         };
1543         struct nfs4_change_info res;
1544         struct rpc_message msg = {
1545                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
1546                 .rpc_argp       = &args,
1547                 .rpc_resp       = &res,
1548         };
1549         int                     status;
1550
1551         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1552         if (status == 0)
1553                 update_changeattr(dir, &res);
1554         return status;
1555 }
1556
1557 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
1558 {
1559         struct nfs4_exception exception = { };
1560         int err;
1561         do {
1562                 err = nfs4_handle_exception(NFS_SERVER(dir),
1563                                 _nfs4_proc_remove(dir, name),
1564                                 &exception);
1565         } while (exception.retry);
1566         return err;
1567 }
1568
1569 struct unlink_desc {
1570         struct nfs4_remove_arg  args;
1571         struct nfs4_change_info res;
1572 };
1573
1574 static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir,
1575                 struct qstr *name)
1576 {
1577         struct unlink_desc *up;
1578
1579         up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL);
1580         if (!up)
1581                 return -ENOMEM;
1582         
1583         up->args.fh = NFS_FH(dir->d_inode);
1584         up->args.name = name;
1585         
1586         msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
1587         msg->rpc_argp = &up->args;
1588         msg->rpc_resp = &up->res;
1589         return 0;
1590 }
1591
1592 static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
1593 {
1594         struct rpc_message *msg = &task->tk_msg;
1595         struct unlink_desc *up;
1596         
1597         if (msg->rpc_resp != NULL) {
1598                 up = container_of(msg->rpc_resp, struct unlink_desc, res);
1599                 update_changeattr(dir->d_inode, &up->res);
1600                 kfree(up);
1601                 msg->rpc_resp = NULL;
1602                 msg->rpc_argp = NULL;
1603         }
1604         return 0;
1605 }
1606
1607 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1608                 struct inode *new_dir, struct qstr *new_name)
1609 {
1610         struct nfs4_rename_arg arg = {
1611                 .old_dir = NFS_FH(old_dir),
1612                 .new_dir = NFS_FH(new_dir),
1613                 .old_name = old_name,
1614                 .new_name = new_name,
1615         };
1616         struct nfs4_rename_res res = { };
1617         struct rpc_message msg = {
1618                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
1619                 .rpc_argp = &arg,
1620                 .rpc_resp = &res,
1621         };
1622         int                     status;
1623         
1624         status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
1625
1626         if (!status) {
1627                 update_changeattr(old_dir, &res.old_cinfo);
1628                 update_changeattr(new_dir, &res.new_cinfo);
1629         }
1630         return status;
1631 }
1632
1633 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1634                 struct inode *new_dir, struct qstr *new_name)
1635 {
1636         struct nfs4_exception exception = { };
1637         int err;
1638         do {
1639                 err = nfs4_handle_exception(NFS_SERVER(old_dir),
1640                                 _nfs4_proc_rename(old_dir, old_name,
1641                                         new_dir, new_name),
1642                                 &exception);
1643         } while (exception.retry);
1644         return err;
1645 }
1646
1647 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1648 {
1649         struct nfs4_link_arg arg = {
1650                 .fh     = NFS_FH(inode),
1651                 .dir_fh = NFS_FH(dir),
1652                 .name   = name,
1653         };
1654         struct nfs4_change_info cinfo = { };
1655         struct rpc_message msg = {
1656                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
1657                 .rpc_argp = &arg,
1658                 .rpc_resp = &cinfo,
1659         };
1660         int                     status;
1661
1662         status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1663         if (!status)
1664                 update_changeattr(dir, &cinfo);
1665
1666         return status;
1667 }
1668
1669 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1670 {
1671         struct nfs4_exception exception = { };
1672         int err;
1673         do {
1674                 err = nfs4_handle_exception(NFS_SERVER(inode),
1675                                 _nfs4_proc_link(inode, dir, name),
1676                                 &exception);
1677         } while (exception.retry);
1678         return err;
1679 }
1680
1681 static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1682                 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1683                 struct nfs_fattr *fattr)
1684 {
1685         struct nfs_server *server = NFS_SERVER(dir);
1686         struct nfs4_create_arg arg = {
1687                 .dir_fh = NFS_FH(dir),
1688                 .server = server,
1689                 .name = name,
1690                 .attrs = sattr,
1691                 .ftype = NF4LNK,
1692                 .bitmask = server->attr_bitmask,
1693         };
1694         struct nfs4_create_res res = {
1695                 .server = server,
1696                 .fh = fhandle,
1697                 .fattr = fattr,
1698         };
1699         struct rpc_message msg = {
1700                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK],
1701                 .rpc_argp = &arg,
1702                 .rpc_resp = &res,
1703         };
1704         int                     status;
1705
1706         if (path->len > NFS4_MAXPATHLEN)
1707                 return -ENAMETOOLONG;
1708         arg.u.symlink = path;
1709         fattr->valid = 0;
1710         
1711         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1712         if (!status)
1713                 update_changeattr(dir, &res.dir_cinfo);
1714         return status;
1715 }
1716
1717 static int nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1718                 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1719                 struct nfs_fattr *fattr)
1720 {
1721         struct nfs4_exception exception = { };
1722         int err;
1723         do {
1724                 err = nfs4_handle_exception(NFS_SERVER(dir),
1725                                 _nfs4_proc_symlink(dir, name, path, sattr,
1726                                         fhandle, fattr),
1727                                 &exception);
1728         } while (exception.retry);
1729         return err;
1730 }
1731
1732 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
1733                 struct iattr *sattr)
1734 {
1735         struct nfs_server *server = NFS_SERVER(dir);
1736         struct nfs_fh fhandle;
1737         struct nfs_fattr fattr;
1738         struct nfs4_create_arg arg = {
1739                 .dir_fh = NFS_FH(dir),
1740                 .server = server,
1741                 .name = &dentry->d_name,
1742                 .attrs = sattr,
1743                 .ftype = NF4DIR,
1744                 .bitmask = server->attr_bitmask,
1745         };
1746         struct nfs4_create_res res = {
1747                 .server = server,
1748                 .fh = &fhandle,
1749                 .fattr = &fattr,
1750         };
1751         struct rpc_message msg = {
1752                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
1753                 .rpc_argp = &arg,
1754                 .rpc_resp = &res,
1755         };
1756         int                     status;
1757
1758         fattr.valid = 0;
1759         
1760         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1761         if (!status) {
1762                 update_changeattr(dir, &res.dir_cinfo);
1763                 status = nfs_instantiate(dentry, &fhandle, &fattr);
1764         }
1765         return status;
1766 }
1767
1768 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
1769                 struct iattr *sattr)
1770 {
1771         struct nfs4_exception exception = { };
1772         int err;
1773         do {
1774                 err = nfs4_handle_exception(NFS_SERVER(dir),
1775                                 _nfs4_proc_mkdir(dir, dentry, sattr),
1776                                 &exception);
1777         } while (exception.retry);
1778         return err;
1779 }
1780
1781 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
1782                   u64 cookie, struct page *page, unsigned int count, int plus)
1783 {
1784         struct inode            *dir = dentry->d_inode;
1785         struct nfs4_readdir_arg args = {
1786                 .fh = NFS_FH(dir),
1787                 .pages = &page,
1788                 .pgbase = 0,
1789                 .count = count,
1790                 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
1791         };
1792         struct nfs4_readdir_res res;
1793         struct rpc_message msg = {
1794                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
1795                 .rpc_argp = &args,
1796                 .rpc_resp = &res,
1797                 .rpc_cred = cred,
1798         };
1799         int                     status;
1800
1801         dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__,
1802                         dentry->d_parent->d_name.name,
1803                         dentry->d_name.name,
1804                         (unsigned long long)cookie);
1805         lock_kernel();
1806         nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
1807         res.pgbase = args.pgbase;
1808         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1809         if (status == 0)
1810                 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
1811         unlock_kernel();
1812         dprintk("%s: returns %d\n", __FUNCTION__, status);
1813         return status;
1814 }
1815
1816 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
1817                   u64 cookie, struct page *page, unsigned int count, int plus)
1818 {
1819         struct nfs4_exception exception = { };
1820         int err;
1821         do {
1822                 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
1823                                 _nfs4_proc_readdir(dentry, cred, cookie,
1824                                         page, count, plus),
1825                                 &exception);
1826         } while (exception.retry);
1827         return err;
1828 }
1829
1830 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
1831                 struct iattr *sattr, dev_t rdev)
1832 {
1833         struct nfs_server *server = NFS_SERVER(dir);
1834         struct nfs_fh fh;
1835         struct nfs_fattr fattr;
1836         struct nfs4_create_arg arg = {
1837                 .dir_fh = NFS_FH(dir),
1838                 .server = server,
1839                 .name = &dentry->d_name,
1840                 .attrs = sattr,
1841                 .bitmask = server->attr_bitmask,
1842         };
1843         struct nfs4_create_res res = {
1844                 .server = server,
1845                 .fh = &fh,
1846                 .fattr = &fattr,
1847         };
1848         struct rpc_message msg = {
1849                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
1850                 .rpc_argp = &arg,
1851                 .rpc_resp = &res,
1852         };
1853         int                     status;
1854         int                     mode = sattr->ia_mode;
1855
1856         fattr.valid = 0;
1857
1858         BUG_ON(!(sattr->ia_valid & ATTR_MODE));
1859         BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
1860         if (S_ISFIFO(mode))
1861                 arg.ftype = NF4FIFO;
1862         else if (S_ISBLK(mode)) {
1863                 arg.ftype = NF4BLK;
1864                 arg.u.device.specdata1 = MAJOR(rdev);
1865                 arg.u.device.specdata2 = MINOR(rdev);
1866         }
1867         else if (S_ISCHR(mode)) {
1868                 arg.ftype = NF4CHR;
1869                 arg.u.device.specdata1 = MAJOR(rdev);
1870                 arg.u.device.specdata2 = MINOR(rdev);
1871         }
1872         else
1873                 arg.ftype = NF4SOCK;
1874         
1875         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1876         if (status == 0) {
1877                 update_changeattr(dir, &res.dir_cinfo);
1878                 status = nfs_instantiate(dentry, &fh, &fattr);
1879         }
1880         return status;
1881 }
1882
1883 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
1884                 struct iattr *sattr, dev_t rdev)
1885 {
1886         struct nfs4_exception exception = { };
1887         int err;
1888         do {
1889                 err = nfs4_handle_exception(NFS_SERVER(dir),
1890                                 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
1891                                 &exception);
1892         } while (exception.retry);
1893         return err;
1894 }
1895
1896 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
1897                  struct nfs_fsstat *fsstat)
1898 {
1899         struct nfs4_statfs_arg args = {
1900                 .fh = fhandle,
1901                 .bitmask = server->attr_bitmask,
1902         };
1903         struct rpc_message msg = {
1904                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
1905                 .rpc_argp = &args,
1906                 .rpc_resp = fsstat,
1907         };
1908
1909         fsstat->fattr->valid = 0;
1910         return rpc_call_sync(server->client, &msg, 0);
1911 }
1912
1913 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
1914 {
1915         struct nfs4_exception exception = { };
1916         int err;
1917         do {
1918                 err = nfs4_handle_exception(server,
1919                                 _nfs4_proc_statfs(server, fhandle, fsstat),
1920                                 &exception);
1921         } while (exception.retry);
1922         return err;
1923 }
1924
1925 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
1926                 struct nfs_fsinfo *fsinfo)
1927 {
1928         struct nfs4_fsinfo_arg args = {
1929                 .fh = fhandle,
1930                 .bitmask = server->attr_bitmask,
1931         };
1932         struct rpc_message msg = {
1933                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
1934                 .rpc_argp = &args,
1935                 .rpc_resp = fsinfo,
1936         };
1937
1938         return rpc_call_sync(server->client, &msg, 0);
1939 }
1940
1941 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
1942 {
1943         struct nfs4_exception exception = { };
1944         int err;
1945
1946         do {
1947                 err = nfs4_handle_exception(server,
1948                                 _nfs4_do_fsinfo(server, fhandle, fsinfo),
1949                                 &exception);
1950         } while (exception.retry);
1951         return err;
1952 }
1953
1954 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
1955 {
1956         fsinfo->fattr->valid = 0;
1957         return nfs4_do_fsinfo(server, fhandle, fsinfo);
1958 }
1959
1960 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
1961                 struct nfs_pathconf *pathconf)
1962 {
1963         struct nfs4_pathconf_arg args = {
1964                 .fh = fhandle,
1965                 .bitmask = server->attr_bitmask,
1966         };
1967         struct rpc_message msg = {
1968                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
1969                 .rpc_argp = &args,
1970                 .rpc_resp = pathconf,
1971         };
1972
1973         /* None of the pathconf attributes are mandatory to implement */
1974         if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
1975                 memset(pathconf, 0, sizeof(*pathconf));
1976                 return 0;
1977         }
1978
1979         pathconf->fattr->valid = 0;
1980         return rpc_call_sync(server->client, &msg, 0);
1981 }
1982
1983 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
1984                 struct nfs_pathconf *pathconf)
1985 {
1986         struct nfs4_exception exception = { };
1987         int err;
1988
1989         do {
1990                 err = nfs4_handle_exception(server,
1991                                 _nfs4_proc_pathconf(server, fhandle, pathconf),
1992                                 &exception);
1993         } while (exception.retry);
1994         return err;
1995 }
1996
1997 static void
1998 nfs4_read_done(struct rpc_task *task)
1999 {
2000         struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
2001         struct inode *inode = data->inode;
2002
2003         if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2004                 rpc_restart_call(task);
2005                 return;
2006         }
2007         if (task->tk_status > 0)
2008                 renew_lease(NFS_SERVER(inode), data->timestamp);
2009         /* Call back common NFS readpage processing */
2010         nfs_readpage_result(task);
2011 }
2012
2013 static void
2014 nfs4_proc_read_setup(struct nfs_read_data *data)
2015 {
2016         struct rpc_task *task = &data->task;
2017         struct rpc_message msg = {
2018                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
2019                 .rpc_argp = &data->args,
2020                 .rpc_resp = &data->res,
2021                 .rpc_cred = data->cred,
2022         };
2023         struct inode *inode = data->inode;
2024         int flags;
2025
2026         data->timestamp   = jiffies;
2027
2028         /* N.B. Do we need to test? Never called for swapfile inode */
2029         flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
2030
2031         /* Finalize the task. */
2032         rpc_init_task(task, NFS_CLIENT(inode), nfs4_read_done, flags);
2033         rpc_call_setup(task, &msg, 0);
2034 }
2035
2036 static void
2037 nfs4_write_done(struct rpc_task *task)
2038 {
2039         struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
2040         struct inode *inode = data->inode;
2041         
2042         if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2043                 rpc_restart_call(task);
2044                 return;
2045         }
2046         if (task->tk_status >= 0)
2047                 renew_lease(NFS_SERVER(inode), data->timestamp);
2048         /* Call back common NFS writeback processing */
2049         nfs_writeback_done(task);
2050 }
2051
2052 static void
2053 nfs4_proc_write_setup(struct nfs_write_data *data, int how)
2054 {
2055         struct rpc_task *task = &data->task;
2056         struct rpc_message msg = {
2057                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
2058                 .rpc_argp = &data->args,
2059                 .rpc_resp = &data->res,
2060                 .rpc_cred = data->cred,
2061         };
2062         struct inode *inode = data->inode;
2063         int stable;
2064         int flags;
2065         
2066         if (how & FLUSH_STABLE) {
2067                 if (!NFS_I(inode)->ncommit)
2068                         stable = NFS_FILE_SYNC;
2069                 else
2070                         stable = NFS_DATA_SYNC;
2071         } else
2072                 stable = NFS_UNSTABLE;
2073         data->args.stable = stable;
2074
2075         data->timestamp   = jiffies;
2076
2077         /* Set the initial flags for the task.  */
2078         flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2079
2080         /* Finalize the task. */
2081         rpc_init_task(task, NFS_CLIENT(inode), nfs4_write_done, flags);
2082         rpc_call_setup(task, &msg, 0);
2083 }
2084
2085 static void
2086 nfs4_commit_done(struct rpc_task *task)
2087 {
2088         struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
2089         struct inode *inode = data->inode;
2090         
2091         if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2092                 rpc_restart_call(task);
2093                 return;
2094         }
2095         /* Call back common NFS writeback processing */
2096         nfs_commit_done(task);
2097 }
2098
2099 static void
2100 nfs4_proc_commit_setup(struct nfs_write_data *data, int how)
2101 {
2102         struct rpc_task *task = &data->task;
2103         struct rpc_message msg = {
2104                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
2105                 .rpc_argp = &data->args,
2106                 .rpc_resp = &data->res,
2107                 .rpc_cred = data->cred,
2108         };      
2109         struct inode *inode = data->inode;
2110         int flags;
2111         
2112         /* Set the initial flags for the task.  */
2113         flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2114
2115         /* Finalize the task. */
2116         rpc_init_task(task, NFS_CLIENT(inode), nfs4_commit_done, flags);
2117         rpc_call_setup(task, &msg, 0);  
2118 }
2119
2120 /*
2121  * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2122  * standalone procedure for queueing an asynchronous RENEW.
2123  */
2124 static void
2125 renew_done(struct rpc_task *task)
2126 {
2127         struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp;
2128         unsigned long timestamp = (unsigned long)task->tk_calldata;
2129
2130         if (task->tk_status < 0) {
2131                 switch (task->tk_status) {
2132                         case -NFS4ERR_STALE_CLIENTID:
2133                         case -NFS4ERR_EXPIRED:
2134                         case -NFS4ERR_CB_PATH_DOWN:
2135                                 nfs4_schedule_state_recovery(clp);
2136                 }
2137                 return;
2138         }
2139         spin_lock(&clp->cl_lock);
2140         if (time_before(clp->cl_last_renewal,timestamp))
2141                 clp->cl_last_renewal = timestamp;
2142         spin_unlock(&clp->cl_lock);
2143 }
2144
2145 int
2146 nfs4_proc_async_renew(struct nfs4_client *clp)
2147 {
2148         struct rpc_message msg = {
2149                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2150                 .rpc_argp       = clp,
2151                 .rpc_cred       = clp->cl_cred,
2152         };
2153
2154         return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
2155                         renew_done, (void *)jiffies);
2156 }
2157
2158 int
2159 nfs4_proc_renew(struct nfs4_client *clp)
2160 {
2161         struct rpc_message msg = {
2162                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2163                 .rpc_argp       = clp,
2164                 .rpc_cred       = clp->cl_cred,
2165         };
2166         unsigned long now = jiffies;
2167         int status;
2168
2169         status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2170         if (status < 0)
2171                 return status;
2172         spin_lock(&clp->cl_lock);
2173         if (time_before(clp->cl_last_renewal,now))
2174                 clp->cl_last_renewal = now;
2175         spin_unlock(&clp->cl_lock);
2176         return 0;
2177 }
2178
2179 /*
2180  * We will need to arrange for the VFS layer to provide an atomic open.
2181  * Until then, this open method is prone to inefficiency and race conditions
2182  * due to the lookup, potential create, and open VFS calls from sys_open()
2183  * placed on the wire.
2184  */
2185 static int
2186 nfs4_proc_file_open(struct inode *inode, struct file *filp)
2187 {
2188         struct dentry *dentry = filp->f_dentry;
2189         struct nfs_open_context *ctx;
2190         struct nfs4_state *state = NULL;
2191         struct rpc_cred *cred;
2192         int status = -ENOMEM;
2193
2194         dprintk("nfs4_proc_file_open: starting on (%.*s/%.*s)\n",
2195                                (int)dentry->d_parent->d_name.len,
2196                                dentry->d_parent->d_name.name,
2197                                (int)dentry->d_name.len, dentry->d_name.name);
2198
2199
2200         /* Find our open stateid */
2201         cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
2202         if (IS_ERR(cred))
2203                 return PTR_ERR(cred);
2204         ctx = alloc_nfs_open_context(dentry, cred);
2205         put_rpccred(cred);
2206         if (unlikely(ctx == NULL))
2207                 return -ENOMEM;
2208         status = -EIO; /* ERACE actually */
2209         state = nfs4_find_state(inode, cred, filp->f_mode);
2210         if (unlikely(state == NULL))
2211                 goto no_state;
2212         ctx->state = state;
2213         nfs4_close_state(state, filp->f_mode);
2214         ctx->mode = filp->f_mode;
2215         nfs_file_set_open_context(filp, ctx);
2216         put_nfs_open_context(ctx);
2217         if (filp->f_mode & FMODE_WRITE)
2218                 nfs_begin_data_update(inode);
2219         return 0;
2220 no_state:
2221         printk(KERN_WARNING "NFS: v4 raced in function %s\n", __FUNCTION__);
2222         put_nfs_open_context(ctx);
2223         return status;
2224 }
2225
2226 /*
2227  * Release our state
2228  */
2229 static int
2230 nfs4_proc_file_release(struct inode *inode, struct file *filp)
2231 {
2232         if (filp->f_mode & FMODE_WRITE)
2233                 nfs_end_data_update(inode);
2234         nfs_file_clear_open_context(filp);
2235         return 0;
2236 }
2237
2238 static inline int nfs4_server_supports_acls(struct nfs_server *server)
2239 {
2240         return (server->caps & NFS_CAP_ACLS)
2241                 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
2242                 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
2243 }
2244
2245 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2246  * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2247  * the stack.
2248  */
2249 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2250
2251 static void buf_to_pages(const void *buf, size_t buflen,
2252                 struct page **pages, unsigned int *pgbase)
2253 {
2254         const void *p = buf;
2255
2256         *pgbase = offset_in_page(buf);
2257         p -= *pgbase;
2258         while (p < buf + buflen) {
2259                 *(pages++) = virt_to_page(p);
2260                 p += PAGE_CACHE_SIZE;
2261         }
2262 }
2263
2264 struct nfs4_cached_acl {
2265         int cached;
2266         size_t len;
2267         char data[0];
2268 };
2269
2270 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
2271 {
2272         struct nfs_inode *nfsi = NFS_I(inode);
2273
2274         spin_lock(&inode->i_lock);
2275         kfree(nfsi->nfs4_acl);
2276         nfsi->nfs4_acl = acl;
2277         spin_unlock(&inode->i_lock);
2278 }
2279
2280 static void nfs4_zap_acl_attr(struct inode *inode)
2281 {
2282         nfs4_set_cached_acl(inode, NULL);
2283 }
2284
2285 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
2286 {
2287         struct nfs_inode *nfsi = NFS_I(inode);
2288         struct nfs4_cached_acl *acl;
2289         int ret = -ENOENT;
2290
2291         spin_lock(&inode->i_lock);
2292         acl = nfsi->nfs4_acl;
2293         if (acl == NULL)
2294                 goto out;
2295         if (buf == NULL) /* user is just asking for length */
2296                 goto out_len;
2297         if (acl->cached == 0)
2298                 goto out;
2299         ret = -ERANGE; /* see getxattr(2) man page */
2300         if (acl->len > buflen)
2301                 goto out;
2302         memcpy(buf, acl->data, acl->len);
2303 out_len:
2304         ret = acl->len;
2305 out:
2306         spin_unlock(&inode->i_lock);
2307         return ret;
2308 }
2309
2310 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
2311 {
2312         struct nfs4_cached_acl *acl;
2313
2314         if (buf && acl_len <= PAGE_SIZE) {
2315                 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
2316                 if (acl == NULL)
2317                         goto out;
2318                 acl->cached = 1;
2319                 memcpy(acl->data, buf, acl_len);
2320         } else {
2321                 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
2322                 if (acl == NULL)
2323                         goto out;
2324                 acl->cached = 0;
2325         }
2326         acl->len = acl_len;
2327 out:
2328         nfs4_set_cached_acl(inode, acl);
2329 }
2330
2331 static inline ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
2332 {
2333         struct page *pages[NFS4ACL_MAXPAGES];
2334         struct nfs_getaclargs args = {
2335                 .fh = NFS_FH(inode),
2336                 .acl_pages = pages,
2337                 .acl_len = buflen,
2338         };
2339         size_t resp_len = buflen;
2340         void *resp_buf;
2341         struct rpc_message msg = {
2342                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
2343                 .rpc_argp = &args,
2344                 .rpc_resp = &resp_len,
2345         };
2346         struct page *localpage = NULL;
2347         int ret;
2348
2349         if (buflen < PAGE_SIZE) {
2350                 /* As long as we're doing a round trip to the server anyway,
2351                  * let's be prepared for a page of acl data. */
2352                 localpage = alloc_page(GFP_KERNEL);
2353                 resp_buf = page_address(localpage);
2354                 if (localpage == NULL)
2355                         return -ENOMEM;
2356                 args.acl_pages[0] = localpage;
2357                 args.acl_pgbase = 0;
2358                 args.acl_len = PAGE_SIZE;
2359         } else {
2360                 resp_buf = buf;
2361                 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
2362         }
2363         ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2364         if (ret)
2365                 goto out_free;
2366         if (resp_len > args.acl_len)
2367                 nfs4_write_cached_acl(inode, NULL, resp_len);
2368         else
2369                 nfs4_write_cached_acl(inode, resp_buf, resp_len);
2370         if (buf) {
2371                 ret = -ERANGE;
2372                 if (resp_len > buflen)
2373                         goto out_free;
2374                 if (localpage)
2375                         memcpy(buf, resp_buf, resp_len);
2376         }
2377         ret = resp_len;
2378 out_free:
2379         if (localpage)
2380                 __free_page(localpage);
2381         return ret;
2382 }
2383
2384 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
2385 {
2386         struct nfs_server *server = NFS_SERVER(inode);
2387         int ret;
2388
2389         if (!nfs4_server_supports_acls(server))
2390                 return -EOPNOTSUPP;
2391         ret = nfs_revalidate_inode(server, inode);
2392         if (ret < 0)
2393                 return ret;
2394         ret = nfs4_read_cached_acl(inode, buf, buflen);
2395         if (ret != -ENOENT)
2396                 return ret;
2397         return nfs4_get_acl_uncached(inode, buf, buflen);
2398 }
2399
2400 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
2401 {
2402         struct nfs_server *server = NFS_SERVER(inode);
2403         struct page *pages[NFS4ACL_MAXPAGES];
2404         struct nfs_setaclargs arg = {
2405                 .fh             = NFS_FH(inode),
2406                 .acl_pages      = pages,
2407                 .acl_len        = buflen,
2408         };
2409         struct rpc_message msg = {
2410                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
2411                 .rpc_argp       = &arg,
2412                 .rpc_resp       = NULL,
2413         };
2414         int ret;
2415
2416         if (!nfs4_server_supports_acls(server))
2417                 return -EOPNOTSUPP;
2418         buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
2419         ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0);
2420         if (ret == 0)
2421                 nfs4_write_cached_acl(inode, buf, buflen);
2422         return ret;
2423 }
2424
2425 static int
2426 nfs4_async_handle_error(struct rpc_task *task, struct nfs_server *server)
2427 {
2428         struct nfs4_client *clp = server->nfs4_state;
2429
2430         if (!clp || task->tk_status >= 0)
2431                 return 0;
2432         switch(task->tk_status) {
2433                 case -NFS4ERR_STALE_CLIENTID:
2434                 case -NFS4ERR_STALE_STATEID:
2435                 case -NFS4ERR_EXPIRED:
2436                         rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL);
2437                         nfs4_schedule_state_recovery(clp);
2438                         if (test_bit(NFS4CLNT_OK, &clp->cl_state))
2439                                 rpc_wake_up_task(task);
2440                         task->tk_status = 0;
2441                         return -EAGAIN;
2442                 case -NFS4ERR_GRACE:
2443                 case -NFS4ERR_DELAY:
2444                         rpc_delay(task, NFS4_POLL_RETRY_MAX);
2445                         task->tk_status = 0;
2446                         return -EAGAIN;
2447                 case -NFS4ERR_OLD_STATEID:
2448                         task->tk_status = 0;
2449                         return -EAGAIN;
2450         }
2451         task->tk_status = nfs4_map_errors(task->tk_status);
2452         return 0;
2453 }
2454
2455 static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp)
2456 {
2457         DEFINE_WAIT(wait);
2458         sigset_t oldset;
2459         int interruptible, res = 0;
2460
2461         might_sleep();
2462
2463         rpc_clnt_sigmask(clnt, &oldset);
2464         interruptible = TASK_UNINTERRUPTIBLE;
2465         if (clnt->cl_intr)
2466                 interruptible = TASK_INTERRUPTIBLE;
2467         prepare_to_wait(&clp->cl_waitq, &wait, interruptible);
2468         nfs4_schedule_state_recovery(clp);
2469         if (clnt->cl_intr && signalled())
2470                 res = -ERESTARTSYS;
2471         else if (!test_bit(NFS4CLNT_OK, &clp->cl_state))
2472                 schedule();
2473         finish_wait(&clp->cl_waitq, &wait);
2474         rpc_clnt_sigunmask(clnt, &oldset);
2475         return res;
2476 }
2477
2478 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
2479 {
2480         sigset_t oldset;
2481         int res = 0;
2482
2483         might_sleep();
2484
2485         if (*timeout <= 0)
2486                 *timeout = NFS4_POLL_RETRY_MIN;
2487         if (*timeout > NFS4_POLL_RETRY_MAX)
2488                 *timeout = NFS4_POLL_RETRY_MAX;
2489         rpc_clnt_sigmask(clnt, &oldset);
2490         if (clnt->cl_intr) {
2491                 schedule_timeout_interruptible(*timeout);
2492                 if (signalled())
2493                         res = -ERESTARTSYS;
2494         } else
2495                 schedule_timeout_uninterruptible(*timeout);
2496         rpc_clnt_sigunmask(clnt, &oldset);
2497         *timeout <<= 1;
2498         return res;
2499 }
2500
2501 /* This is the error handling routine for processes that are allowed
2502  * to sleep.
2503  */
2504 int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
2505 {
2506         struct nfs4_client *clp = server->nfs4_state;
2507         int ret = errorcode;
2508
2509         exception->retry = 0;
2510         switch(errorcode) {
2511                 case 0:
2512                         return 0;
2513                 case -NFS4ERR_STALE_CLIENTID:
2514                 case -NFS4ERR_STALE_STATEID:
2515                 case -NFS4ERR_EXPIRED:
2516                         ret = nfs4_wait_clnt_recover(server->client, clp);
2517                         if (ret == 0)
2518                                 exception->retry = 1;
2519                         break;
2520                 case -NFS4ERR_GRACE:
2521                 case -NFS4ERR_DELAY:
2522                         ret = nfs4_delay(server->client, &exception->timeout);
2523                         if (ret == 0)
2524                                 exception->retry = 1;
2525                         break;
2526                 case -NFS4ERR_OLD_STATEID:
2527                         if (ret == 0)
2528                                 exception->retry = 1;
2529         }
2530         /* We failed to handle the error */
2531         return nfs4_map_errors(ret);
2532 }
2533
2534 int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port)
2535 {
2536         nfs4_verifier sc_verifier;
2537         struct nfs4_setclientid setclientid = {
2538                 .sc_verifier = &sc_verifier,
2539                 .sc_prog = program,
2540         };
2541         struct rpc_message msg = {
2542                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
2543                 .rpc_argp = &setclientid,
2544                 .rpc_resp = clp,
2545                 .rpc_cred = clp->cl_cred,
2546         };
2547         u32 *p;
2548         int loop = 0;
2549         int status;
2550
2551         p = (u32*)sc_verifier.data;
2552         *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
2553         *p = htonl((u32)clp->cl_boot_time.tv_nsec);
2554
2555         for(;;) {
2556                 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
2557                                 sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u",
2558                                 clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr),
2559                                 clp->cl_cred->cr_ops->cr_name,
2560                                 clp->cl_id_uniquifier);
2561                 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
2562                                 sizeof(setclientid.sc_netid), "tcp");
2563                 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
2564                                 sizeof(setclientid.sc_uaddr), "%s.%d.%d",
2565                                 clp->cl_ipaddr, port >> 8, port & 255);
2566
2567                 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2568                 if (status != -NFS4ERR_CLID_INUSE)
2569                         break;
2570                 if (signalled())
2571                         break;
2572                 if (loop++ & 1)
2573                         ssleep(clp->cl_lease_time + 1);
2574                 else
2575                         if (++clp->cl_id_uniquifier == 0)
2576                                 break;
2577         }
2578         return status;
2579 }
2580
2581 int
2582 nfs4_proc_setclientid_confirm(struct nfs4_client *clp)
2583 {
2584         struct nfs_fsinfo fsinfo;
2585         struct rpc_message msg = {
2586                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
2587                 .rpc_argp = clp,
2588                 .rpc_resp = &fsinfo,
2589                 .rpc_cred = clp->cl_cred,
2590         };
2591         unsigned long now;
2592         int status;
2593
2594         now = jiffies;
2595         status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2596         if (status == 0) {
2597                 spin_lock(&clp->cl_lock);
2598                 clp->cl_lease_time = fsinfo.lease_time * HZ;
2599                 clp->cl_last_renewal = now;
2600                 spin_unlock(&clp->cl_lock);
2601         }
2602         return status;
2603 }
2604
2605 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2606 {
2607         struct nfs4_delegreturnargs args = {
2608                 .fhandle = NFS_FH(inode),
2609                 .stateid = stateid,
2610         };
2611         struct rpc_message msg = {
2612                 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
2613                 .rpc_argp = &args,
2614                 .rpc_cred = cred,
2615         };
2616
2617         return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2618 }
2619
2620 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2621 {
2622         struct nfs_server *server = NFS_SERVER(inode);
2623         struct nfs4_exception exception = { };
2624         int err;
2625         do {
2626                 err = _nfs4_proc_delegreturn(inode, cred, stateid);
2627                 switch (err) {
2628                         case -NFS4ERR_STALE_STATEID:
2629                         case -NFS4ERR_EXPIRED:
2630                                 nfs4_schedule_state_recovery(server->nfs4_state);
2631                         case 0:
2632                                 return 0;
2633                 }
2634                 err = nfs4_handle_exception(server, err, &exception);
2635         } while (exception.retry);
2636         return err;
2637 }
2638
2639 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
2640 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
2641
2642 /* 
2643  * sleep, with exponential backoff, and retry the LOCK operation. 
2644  */
2645 static unsigned long
2646 nfs4_set_lock_task_retry(unsigned long timeout)
2647 {
2648         schedule_timeout_interruptible(timeout);
2649         timeout <<= 1;
2650         if (timeout > NFS4_LOCK_MAXTIMEOUT)
2651                 return NFS4_LOCK_MAXTIMEOUT;
2652         return timeout;
2653 }
2654
2655 static inline int
2656 nfs4_lck_type(int cmd, struct file_lock *request)
2657 {
2658         /* set lock type */
2659         switch (request->fl_type) {
2660                 case F_RDLCK:
2661                         return IS_SETLKW(cmd) ? NFS4_READW_LT : NFS4_READ_LT;
2662                 case F_WRLCK:
2663                         return IS_SETLKW(cmd) ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
2664                 case F_UNLCK:
2665                         return NFS4_WRITE_LT; 
2666         }
2667         BUG();
2668         return 0;
2669 }
2670
2671 static inline uint64_t
2672 nfs4_lck_length(struct file_lock *request)
2673 {
2674         if (request->fl_end == OFFSET_MAX)
2675                 return ~(uint64_t)0;
2676         return request->fl_end - request->fl_start + 1;
2677 }
2678
2679 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2680 {
2681         struct inode *inode = state->inode;
2682         struct nfs_server *server = NFS_SERVER(inode);
2683         struct nfs4_client *clp = server->nfs4_state;
2684         struct nfs_lockargs arg = {
2685                 .fh = NFS_FH(inode),
2686                 .type = nfs4_lck_type(cmd, request),
2687                 .offset = request->fl_start,
2688                 .length = nfs4_lck_length(request),
2689         };
2690         struct nfs_lockres res = {
2691                 .server = server,
2692         };
2693         struct rpc_message msg = {
2694                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
2695                 .rpc_argp       = &arg,
2696                 .rpc_resp       = &res,
2697                 .rpc_cred       = state->owner->so_cred,
2698         };
2699         struct nfs_lowner nlo;
2700         struct nfs4_lock_state *lsp;
2701         int status;
2702
2703         down_read(&clp->cl_sem);
2704         nlo.clientid = clp->cl_clientid;
2705         down(&state->lock_sema);
2706         status = nfs4_set_lock_state(state, request);
2707         if (status != 0)
2708                 goto out;
2709         lsp = request->fl_u.nfs4_fl.owner;
2710         nlo.id = lsp->ls_id; 
2711         arg.u.lockt = &nlo;
2712         status = rpc_call_sync(server->client, &msg, 0);
2713         if (!status) {
2714                 request->fl_type = F_UNLCK;
2715         } else if (status == -NFS4ERR_DENIED) {
2716                 int64_t len, start, end;
2717                 start = res.u.denied.offset;
2718                 len = res.u.denied.length;
2719                 end = start + len - 1;
2720                 if (end < 0 || len == 0)
2721                         request->fl_end = OFFSET_MAX;
2722                 else
2723                         request->fl_end = (loff_t)end;
2724                 request->fl_start = (loff_t)start;
2725                 request->fl_type = F_WRLCK;
2726                 if (res.u.denied.type & 1)
2727                         request->fl_type = F_RDLCK;
2728                 request->fl_pid = 0;
2729                 status = 0;
2730         }
2731 out:
2732         up(&state->lock_sema);
2733         up_read(&clp->cl_sem);
2734         return status;
2735 }
2736
2737 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2738 {
2739         struct nfs4_exception exception = { };
2740         int err;
2741
2742         do {
2743                 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2744                                 _nfs4_proc_getlk(state, cmd, request),
2745                                 &exception);
2746         } while (exception.retry);
2747         return err;
2748 }
2749
2750 static int do_vfs_lock(struct file *file, struct file_lock *fl)
2751 {
2752         int res = 0;
2753         switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
2754                 case FL_POSIX:
2755                         res = posix_lock_file_wait(file, fl);
2756                         break;
2757                 case FL_FLOCK:
2758                         res = flock_lock_file_wait(file, fl);
2759                         break;
2760                 default:
2761                         BUG();
2762         }
2763         if (res < 0)
2764                 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
2765                                 __FUNCTION__);
2766         return res;
2767 }
2768
2769 static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
2770 {
2771         struct inode *inode = state->inode;
2772         struct nfs_server *server = NFS_SERVER(inode);
2773         struct nfs4_client *clp = server->nfs4_state;
2774         struct nfs_lockargs arg = {
2775                 .fh = NFS_FH(inode),
2776                 .type = nfs4_lck_type(cmd, request),
2777                 .offset = request->fl_start,
2778                 .length = nfs4_lck_length(request),
2779         };
2780         struct nfs_lockres res = {
2781                 .server = server,
2782         };
2783         struct rpc_message msg = {
2784                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
2785                 .rpc_argp       = &arg,
2786                 .rpc_resp       = &res,
2787                 .rpc_cred       = state->owner->so_cred,
2788         };
2789         struct nfs4_lock_state *lsp;
2790         struct nfs_locku_opargs luargs;
2791         int status;
2792                         
2793         down_read(&clp->cl_sem);
2794         down(&state->lock_sema);
2795         status = nfs4_set_lock_state(state, request);
2796         if (status != 0)
2797                 goto out;
2798         lsp = request->fl_u.nfs4_fl.owner;
2799         /* We might have lost the locks! */
2800         if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
2801                 goto out;
2802         luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2803         status = -ENOMEM;
2804         if (luargs.seqid == NULL)
2805                 goto out;
2806         memcpy(luargs.stateid.data, lsp->ls_stateid.data, sizeof(luargs.stateid.data));
2807         arg.u.locku = &luargs;
2808         status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
2809         nfs_increment_lock_seqid(status, luargs.seqid);
2810
2811         if (status == 0)
2812                 memcpy(lsp->ls_stateid.data, res.u.stateid.data, 
2813                                 sizeof(lsp->ls_stateid.data));
2814         nfs_free_seqid(luargs.seqid);
2815 out:
2816         up(&state->lock_sema);
2817         if (status == 0)
2818                 do_vfs_lock(request->fl_file, request);
2819         up_read(&clp->cl_sem);
2820         return status;
2821 }
2822
2823 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
2824 {
2825         struct nfs4_exception exception = { };
2826         int err;
2827
2828         do {
2829                 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2830                                 _nfs4_proc_unlck(state, cmd, request),
2831                                 &exception);
2832         } while (exception.retry);
2833         return err;
2834 }
2835
2836 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
2837 {
2838         struct inode *inode = state->inode;
2839         struct nfs_server *server = NFS_SERVER(inode);
2840         struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
2841         struct nfs_lockargs arg = {
2842                 .fh = NFS_FH(inode),
2843                 .type = nfs4_lck_type(cmd, request),
2844                 .offset = request->fl_start,
2845                 .length = nfs4_lck_length(request),
2846         };
2847         struct nfs_lockres res = {
2848                 .server = server,
2849         };
2850         struct rpc_message msg = {
2851                 .rpc_proc       = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
2852                 .rpc_argp       = &arg,
2853                 .rpc_resp       = &res,
2854                 .rpc_cred       = state->owner->so_cred,
2855         };
2856         struct nfs_lock_opargs largs = {
2857                 .reclaim = reclaim,
2858                 .new_lock_owner = 0,
2859         };
2860         struct nfs_seqid *lock_seqid;
2861         int status = -ENOMEM;
2862
2863         lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2864         if (lock_seqid == NULL)
2865                 return -ENOMEM;
2866         if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
2867                 struct nfs4_state_owner *owner = state->owner;
2868                 struct nfs_open_to_lock otl = {
2869                         .lock_owner = {
2870                                 .clientid = server->nfs4_state->cl_clientid,
2871                         },
2872                 };
2873
2874                 otl.lock_seqid = lock_seqid;
2875                 otl.lock_owner.id = lsp->ls_id;
2876                 memcpy(&otl.open_stateid, &state->stateid, sizeof(otl.open_stateid));
2877                 largs.u.open_lock = &otl;
2878                 largs.new_lock_owner = 1;
2879                 arg.u.lock = &largs;
2880                 down(&owner->so_sema);
2881                 otl.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
2882                 if (otl.open_seqid != NULL) {
2883                         status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
2884                         /* increment seqid on success, and seqid mutating errors */
2885                         nfs_increment_open_seqid(status, otl.open_seqid);
2886                         nfs_free_seqid(otl.open_seqid);
2887                 }
2888                 up(&owner->so_sema);
2889                 if (status == 0)
2890                         nfs_confirm_seqid(&lsp->ls_seqid, 0);
2891         } else {
2892                 struct nfs_exist_lock el;
2893                 memcpy(&el.stateid, &lsp->ls_stateid, sizeof(el.stateid));
2894                 largs.u.exist_lock = &el;
2895                 arg.u.lock = &largs;
2896                 el.seqid = lock_seqid;
2897                 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
2898         }
2899         /* increment seqid on success, and seqid mutating errors*/
2900         nfs_increment_lock_seqid(status, lock_seqid);
2901         /* save the returned stateid. */
2902         if (status == 0) {
2903                 memcpy(lsp->ls_stateid.data, res.u.stateid.data, sizeof(lsp->ls_stateid.data));
2904                 lsp->ls_flags |= NFS_LOCK_INITIALIZED;
2905         } else if (status == -NFS4ERR_DENIED)
2906                 status = -EAGAIN;
2907         nfs_free_seqid(lock_seqid);
2908         return status;
2909 }
2910
2911 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
2912 {
2913         struct nfs_server *server = NFS_SERVER(state->inode);
2914         struct nfs4_exception exception = { };
2915         int err;
2916
2917         do {
2918                 err = _nfs4_do_setlk(state, F_SETLK, request, 1);
2919                 if (err != -NFS4ERR_DELAY)
2920                         break;
2921                 nfs4_handle_exception(server, err, &exception);
2922         } while (exception.retry);
2923         return err;
2924 }
2925
2926 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
2927 {
2928         struct nfs_server *server = NFS_SERVER(state->inode);
2929         struct nfs4_exception exception = { };
2930         int err;
2931
2932         do {
2933                 err = _nfs4_do_setlk(state, F_SETLK, request, 0);
2934                 if (err != -NFS4ERR_DELAY)
2935                         break;
2936                 nfs4_handle_exception(server, err, &exception);
2937         } while (exception.retry);
2938         return err;
2939 }
2940
2941 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2942 {
2943         struct nfs4_client *clp = state->owner->so_client;
2944         int status;
2945
2946         down_read(&clp->cl_sem);
2947         down(&state->lock_sema);
2948         status = nfs4_set_lock_state(state, request);
2949         if (status == 0)
2950                 status = _nfs4_do_setlk(state, cmd, request, 0);
2951         up(&state->lock_sema);
2952         if (status == 0) {
2953                 /* Note: we always want to sleep here! */
2954                 request->fl_flags |= FL_SLEEP;
2955                 if (do_vfs_lock(request->fl_file, request) < 0)
2956                         printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
2957         }
2958         up_read(&clp->cl_sem);
2959         return status;
2960 }
2961
2962 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2963 {
2964         struct nfs4_exception exception = { };
2965         int err;
2966
2967         do {
2968                 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2969                                 _nfs4_proc_setlk(state, cmd, request),
2970                                 &exception);
2971         } while (exception.retry);
2972         return err;
2973 }
2974
2975 static int
2976 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
2977 {
2978         struct nfs_open_context *ctx;
2979         struct nfs4_state *state;
2980         unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
2981         int status;
2982
2983         /* verify open state */
2984         ctx = (struct nfs_open_context *)filp->private_data;
2985         state = ctx->state;
2986
2987         if (request->fl_start < 0 || request->fl_end < 0)
2988                 return -EINVAL;
2989
2990         if (IS_GETLK(cmd))
2991                 return nfs4_proc_getlk(state, F_GETLK, request);
2992
2993         if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
2994                 return -EINVAL;
2995
2996         if (request->fl_type == F_UNLCK)
2997                 return nfs4_proc_unlck(state, cmd, request);
2998
2999         do {
3000                 status = nfs4_proc_setlk(state, cmd, request);
3001                 if ((status != -EAGAIN) || IS_SETLK(cmd))
3002                         break;
3003                 timeout = nfs4_set_lock_task_retry(timeout);
3004                 status = -ERESTARTSYS;
3005                 if (signalled())
3006                         break;
3007         } while(status < 0);
3008         return status;
3009 }
3010
3011
3012 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3013
3014 int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
3015                 size_t buflen, int flags)
3016 {
3017         struct inode *inode = dentry->d_inode;
3018
3019         if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3020                 return -EOPNOTSUPP;
3021
3022         if (!S_ISREG(inode->i_mode) &&
3023             (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3024                 return -EPERM;
3025
3026         return nfs4_proc_set_acl(inode, buf, buflen);
3027 }
3028
3029 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
3030  * and that's what we'll do for e.g. user attributes that haven't been set.
3031  * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3032  * attributes in kernel-managed attribute namespaces. */
3033 ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
3034                 size_t buflen)
3035 {
3036         struct inode *inode = dentry->d_inode;
3037
3038         if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3039                 return -EOPNOTSUPP;
3040
3041         return nfs4_proc_get_acl(inode, buf, buflen);
3042 }
3043
3044 ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
3045 {
3046         size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
3047
3048         if (buf && buflen < len)
3049                 return -ERANGE;
3050         if (buf)
3051                 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
3052         return len;
3053 }
3054
3055 struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
3056         .recover_open   = nfs4_open_reclaim,
3057         .recover_lock   = nfs4_lock_reclaim,
3058 };
3059
3060 struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = {
3061         .recover_open   = nfs4_open_expired,
3062         .recover_lock   = nfs4_lock_expired,
3063 };
3064
3065 static struct inode_operations nfs4_file_inode_operations = {
3066         .permission     = nfs_permission,
3067         .getattr        = nfs_getattr,
3068         .setattr        = nfs_setattr,
3069         .getxattr       = nfs4_getxattr,
3070         .setxattr       = nfs4_setxattr,
3071         .listxattr      = nfs4_listxattr,
3072 };
3073
3074 struct nfs_rpc_ops      nfs_v4_clientops = {
3075         .version        = 4,                    /* protocol version */
3076         .dentry_ops     = &nfs4_dentry_operations,
3077         .dir_inode_ops  = &nfs4_dir_inode_operations,
3078         .file_inode_ops = &nfs4_file_inode_operations,
3079         .getroot        = nfs4_proc_get_root,
3080         .getattr        = nfs4_proc_getattr,
3081         .setattr        = nfs4_proc_setattr,
3082         .lookup         = nfs4_proc_lookup,
3083         .access         = nfs4_proc_access,
3084         .readlink       = nfs4_proc_readlink,
3085         .read           = nfs4_proc_read,
3086         .write          = nfs4_proc_write,
3087         .commit         = nfs4_proc_commit,
3088         .create         = nfs4_proc_create,
3089         .remove         = nfs4_proc_remove,
3090         .unlink_setup   = nfs4_proc_unlink_setup,
3091         .unlink_done    = nfs4_proc_unlink_done,
3092         .rename         = nfs4_proc_rename,
3093         .link           = nfs4_proc_link,
3094         .symlink        = nfs4_proc_symlink,
3095         .mkdir          = nfs4_proc_mkdir,
3096         .rmdir          = nfs4_proc_remove,
3097         .readdir        = nfs4_proc_readdir,
3098         .mknod          = nfs4_proc_mknod,
3099         .statfs         = nfs4_proc_statfs,
3100         .fsinfo         = nfs4_proc_fsinfo,
3101         .pathconf       = nfs4_proc_pathconf,
3102         .decode_dirent  = nfs4_decode_dirent,
3103         .read_setup     = nfs4_proc_read_setup,
3104         .write_setup    = nfs4_proc_write_setup,
3105         .commit_setup   = nfs4_proc_commit_setup,
3106         .file_open      = nfs4_proc_file_open,
3107         .file_release   = nfs4_proc_file_release,
3108         .lock           = nfs4_proc_lock,
3109         .clear_acl_cache = nfs4_zap_acl_attr,
3110 };
3111
3112 /*
3113  * Local variables:
3114  *  c-basic-offset: 8
3115  * End:
3116  */