]> git.karo-electronics.de Git - mv-sheeva.git/blob - fs/nfs/nfs3proc.c
NFS: add hooks to account for NFSERR_JUKEBOX errors
[mv-sheeva.git] / fs / nfs / nfs3proc.c
1 /*
2  *  linux/fs/nfs/nfs3proc.c
3  *
4  *  Client-side NFSv3 procedures stubs.
5  *
6  *  Copyright (C) 1997, Olaf Kirch
7  */
8
9 #include <linux/mm.h>
10 #include <linux/utsname.h>
11 #include <linux/errno.h>
12 #include <linux/string.h>
13 #include <linux/sunrpc/clnt.h>
14 #include <linux/nfs.h>
15 #include <linux/nfs3.h>
16 #include <linux/nfs_fs.h>
17 #include <linux/nfs_page.h>
18 #include <linux/lockd/bind.h>
19 #include <linux/smp_lock.h>
20 #include <linux/nfs_mount.h>
21
22 #include "iostat.h"
23
24 #define NFSDBG_FACILITY         NFSDBG_PROC
25
26 extern struct rpc_procinfo nfs3_procedures[];
27
28 /* A wrapper to handle the EJUKEBOX error message */
29 static int
30 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
31 {
32         sigset_t oldset;
33         int res;
34         rpc_clnt_sigmask(clnt, &oldset);
35         do {
36                 res = rpc_call_sync(clnt, msg, flags);
37                 if (res != -EJUKEBOX)
38                         break;
39                 schedule_timeout_interruptible(NFS_JUKEBOX_RETRY_TIME);
40                 res = -ERESTARTSYS;
41         } while (!signalled());
42         rpc_clnt_sigunmask(clnt, &oldset);
43         return res;
44 }
45
46 static inline int
47 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
48 {
49         struct rpc_message msg = {
50                 .rpc_proc       = &clnt->cl_procinfo[proc],
51                 .rpc_argp       = argp,
52                 .rpc_resp       = resp,
53         };
54         return nfs3_rpc_wrapper(clnt, &msg, flags);
55 }
56
57 #define rpc_call(clnt, proc, argp, resp, flags) \
58                 nfs3_rpc_call_wrapper(clnt, proc, argp, resp, flags)
59 #define rpc_call_sync(clnt, msg, flags) \
60                 nfs3_rpc_wrapper(clnt, msg, flags)
61
62 static int
63 nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
64 {
65         if (task->tk_status != -EJUKEBOX)
66                 return 0;
67         nfs_inc_stats(inode, NFSIOS_DELAY);
68         task->tk_status = 0;
69         rpc_restart_call(task);
70         rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
71         return 1;
72 }
73
74 static int
75 do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
76                  struct nfs_fsinfo *info)
77 {
78         int     status;
79
80         dprintk("%s: call  fsinfo\n", __FUNCTION__);
81         nfs_fattr_init(info->fattr);
82         status = rpc_call(client, NFS3PROC_FSINFO, fhandle, info, 0);
83         dprintk("%s: reply fsinfo: %d\n", __FUNCTION__, status);
84         if (!(info->fattr->valid & NFS_ATTR_FATTR)) {
85                 status = rpc_call(client, NFS3PROC_GETATTR, fhandle, info->fattr, 0);
86                 dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
87         }
88         return status;
89 }
90
91 /*
92  * Bare-bones access to getattr: this is for nfs_read_super.
93  */
94 static int
95 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
96                    struct nfs_fsinfo *info)
97 {
98         int     status;
99
100         status = do_proc_get_root(server->client, fhandle, info);
101         if (status && server->client_sys != server->client)
102                 status = do_proc_get_root(server->client_sys, fhandle, info);
103         return status;
104 }
105
106 /*
107  * One function for each procedure in the NFS protocol.
108  */
109 static int
110 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
111                 struct nfs_fattr *fattr)
112 {
113         int     status;
114
115         dprintk("NFS call  getattr\n");
116         nfs_fattr_init(fattr);
117         status = rpc_call(server->client, NFS3PROC_GETATTR,
118                           fhandle, fattr, 0);
119         dprintk("NFS reply getattr: %d\n", status);
120         return status;
121 }
122
123 static int
124 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
125                         struct iattr *sattr)
126 {
127         struct inode *inode = dentry->d_inode;
128         struct nfs3_sattrargs   arg = {
129                 .fh             = NFS_FH(inode),
130                 .sattr          = sattr,
131         };
132         int     status;
133
134         dprintk("NFS call  setattr\n");
135         nfs_fattr_init(fattr);
136         status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
137         if (status == 0)
138                 nfs_setattr_update_inode(inode, sattr);
139         dprintk("NFS reply setattr: %d\n", status);
140         return status;
141 }
142
143 static int
144 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
145                  struct nfs_fh *fhandle, struct nfs_fattr *fattr)
146 {
147         struct nfs_fattr        dir_attr;
148         struct nfs3_diropargs   arg = {
149                 .fh             = NFS_FH(dir),
150                 .name           = name->name,
151                 .len            = name->len
152         };
153         struct nfs3_diropres    res = {
154                 .dir_attr       = &dir_attr,
155                 .fh             = fhandle,
156                 .fattr          = fattr
157         };
158         int                     status;
159
160         dprintk("NFS call  lookup %s\n", name->name);
161         nfs_fattr_init(&dir_attr);
162         nfs_fattr_init(fattr);
163         status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
164         if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
165                 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
166                          fhandle, fattr, 0);
167         dprintk("NFS reply lookup: %d\n", status);
168         if (status >= 0)
169                 status = nfs_refresh_inode(dir, &dir_attr);
170         return status;
171 }
172
173 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
174 {
175         struct nfs_fattr        fattr;
176         struct nfs3_accessargs  arg = {
177                 .fh             = NFS_FH(inode),
178         };
179         struct nfs3_accessres   res = {
180                 .fattr          = &fattr,
181         };
182         struct rpc_message msg = {
183                 .rpc_proc       = &nfs3_procedures[NFS3PROC_ACCESS],
184                 .rpc_argp       = &arg,
185                 .rpc_resp       = &res,
186                 .rpc_cred       = entry->cred
187         };
188         int mode = entry->mask;
189         int status;
190
191         dprintk("NFS call  access\n");
192
193         if (mode & MAY_READ)
194                 arg.access |= NFS3_ACCESS_READ;
195         if (S_ISDIR(inode->i_mode)) {
196                 if (mode & MAY_WRITE)
197                         arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
198                 if (mode & MAY_EXEC)
199                         arg.access |= NFS3_ACCESS_LOOKUP;
200         } else {
201                 if (mode & MAY_WRITE)
202                         arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
203                 if (mode & MAY_EXEC)
204                         arg.access |= NFS3_ACCESS_EXECUTE;
205         }
206         nfs_fattr_init(&fattr);
207         status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
208         nfs_refresh_inode(inode, &fattr);
209         if (status == 0) {
210                 entry->mask = 0;
211                 if (res.access & NFS3_ACCESS_READ)
212                         entry->mask |= MAY_READ;
213                 if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
214                         entry->mask |= MAY_WRITE;
215                 if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
216                         entry->mask |= MAY_EXEC;
217         }
218         dprintk("NFS reply access: %d\n", status);
219         return status;
220 }
221
222 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
223                 unsigned int pgbase, unsigned int pglen)
224 {
225         struct nfs_fattr        fattr;
226         struct nfs3_readlinkargs args = {
227                 .fh             = NFS_FH(inode),
228                 .pgbase         = pgbase,
229                 .pglen          = pglen,
230                 .pages          = &page
231         };
232         int                     status;
233
234         dprintk("NFS call  readlink\n");
235         nfs_fattr_init(&fattr);
236         status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
237                           &args, &fattr, 0);
238         nfs_refresh_inode(inode, &fattr);
239         dprintk("NFS reply readlink: %d\n", status);
240         return status;
241 }
242
243 static int nfs3_proc_read(struct nfs_read_data *rdata)
244 {
245         int                     flags = rdata->flags;
246         struct inode *          inode = rdata->inode;
247         struct nfs_fattr *      fattr = rdata->res.fattr;
248         struct rpc_message      msg = {
249                 .rpc_proc       = &nfs3_procedures[NFS3PROC_READ],
250                 .rpc_argp       = &rdata->args,
251                 .rpc_resp       = &rdata->res,
252                 .rpc_cred       = rdata->cred,
253         };
254         int                     status;
255
256         dprintk("NFS call  read %d @ %Ld\n", rdata->args.count,
257                         (long long) rdata->args.offset);
258         nfs_fattr_init(fattr);
259         status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
260         if (status >= 0)
261                 nfs_refresh_inode(inode, fattr);
262         dprintk("NFS reply read: %d\n", status);
263         return status;
264 }
265
266 static int nfs3_proc_write(struct nfs_write_data *wdata)
267 {
268         int                     rpcflags = wdata->flags;
269         struct inode *          inode = wdata->inode;
270         struct nfs_fattr *      fattr = wdata->res.fattr;
271         struct rpc_message      msg = {
272                 .rpc_proc       = &nfs3_procedures[NFS3PROC_WRITE],
273                 .rpc_argp       = &wdata->args,
274                 .rpc_resp       = &wdata->res,
275                 .rpc_cred       = wdata->cred,
276         };
277         int                     status;
278
279         dprintk("NFS call  write %d @ %Ld\n", wdata->args.count,
280                         (long long) wdata->args.offset);
281         nfs_fattr_init(fattr);
282         status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
283         if (status >= 0)
284                 nfs_post_op_update_inode(inode, fattr);
285         dprintk("NFS reply write: %d\n", status);
286         return status < 0? status : wdata->res.count;
287 }
288
289 static int nfs3_proc_commit(struct nfs_write_data *cdata)
290 {
291         struct inode *          inode = cdata->inode;
292         struct nfs_fattr *      fattr = cdata->res.fattr;
293         struct rpc_message      msg = {
294                 .rpc_proc       = &nfs3_procedures[NFS3PROC_COMMIT],
295                 .rpc_argp       = &cdata->args,
296                 .rpc_resp       = &cdata->res,
297                 .rpc_cred       = cdata->cred,
298         };
299         int                     status;
300
301         dprintk("NFS call  commit %d @ %Ld\n", cdata->args.count,
302                         (long long) cdata->args.offset);
303         nfs_fattr_init(fattr);
304         status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
305         if (status >= 0)
306                 nfs_post_op_update_inode(inode, fattr);
307         dprintk("NFS reply commit: %d\n", status);
308         return status;
309 }
310
311 /*
312  * Create a regular file.
313  * For now, we don't implement O_EXCL.
314  */
315 static int
316 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
317                  int flags, struct nameidata *nd)
318 {
319         struct nfs_fh           fhandle;
320         struct nfs_fattr        fattr;
321         struct nfs_fattr        dir_attr;
322         struct nfs3_createargs  arg = {
323                 .fh             = NFS_FH(dir),
324                 .name           = dentry->d_name.name,
325                 .len            = dentry->d_name.len,
326                 .sattr          = sattr,
327         };
328         struct nfs3_diropres    res = {
329                 .dir_attr       = &dir_attr,
330                 .fh             = &fhandle,
331                 .fattr          = &fattr
332         };
333         mode_t mode = sattr->ia_mode;
334         int status;
335
336         dprintk("NFS call  create %s\n", dentry->d_name.name);
337         arg.createmode = NFS3_CREATE_UNCHECKED;
338         if (flags & O_EXCL) {
339                 arg.createmode  = NFS3_CREATE_EXCLUSIVE;
340                 arg.verifier[0] = jiffies;
341                 arg.verifier[1] = current->pid;
342         }
343
344         sattr->ia_mode &= ~current->fs->umask;
345
346 again:
347         nfs_fattr_init(&dir_attr);
348         nfs_fattr_init(&fattr);
349         status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
350         nfs_post_op_update_inode(dir, &dir_attr);
351
352         /* If the server doesn't support the exclusive creation semantics,
353          * try again with simple 'guarded' mode. */
354         if (status == NFSERR_NOTSUPP) {
355                 switch (arg.createmode) {
356                         case NFS3_CREATE_EXCLUSIVE:
357                                 arg.createmode = NFS3_CREATE_GUARDED;
358                                 break;
359
360                         case NFS3_CREATE_GUARDED:
361                                 arg.createmode = NFS3_CREATE_UNCHECKED;
362                                 break;
363
364                         case NFS3_CREATE_UNCHECKED:
365                                 goto out;
366                 }
367                 goto again;
368         }
369
370         if (status == 0)
371                 status = nfs_instantiate(dentry, &fhandle, &fattr);
372         if (status != 0)
373                 goto out;
374
375         /* When we created the file with exclusive semantics, make
376          * sure we set the attributes afterwards. */
377         if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
378                 dprintk("NFS call  setattr (post-create)\n");
379
380                 if (!(sattr->ia_valid & ATTR_ATIME_SET))
381                         sattr->ia_valid |= ATTR_ATIME;
382                 if (!(sattr->ia_valid & ATTR_MTIME_SET))
383                         sattr->ia_valid |= ATTR_MTIME;
384
385                 /* Note: we could use a guarded setattr here, but I'm
386                  * not sure this buys us anything (and I'd have
387                  * to revamp the NFSv3 XDR code) */
388                 status = nfs3_proc_setattr(dentry, &fattr, sattr);
389                 if (status == 0)
390                         nfs_setattr_update_inode(dentry->d_inode, sattr);
391                 nfs_refresh_inode(dentry->d_inode, &fattr);
392                 dprintk("NFS reply setattr (post-create): %d\n", status);
393         }
394         if (status != 0)
395                 goto out;
396         status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
397 out:
398         dprintk("NFS reply create: %d\n", status);
399         return status;
400 }
401
402 static int
403 nfs3_proc_remove(struct inode *dir, struct qstr *name)
404 {
405         struct nfs_fattr        dir_attr;
406         struct nfs3_diropargs   arg = {
407                 .fh             = NFS_FH(dir),
408                 .name           = name->name,
409                 .len            = name->len
410         };
411         struct rpc_message      msg = {
412                 .rpc_proc       = &nfs3_procedures[NFS3PROC_REMOVE],
413                 .rpc_argp       = &arg,
414                 .rpc_resp       = &dir_attr,
415         };
416         int                     status;
417
418         dprintk("NFS call  remove %s\n", name->name);
419         nfs_fattr_init(&dir_attr);
420         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
421         nfs_post_op_update_inode(dir, &dir_attr);
422         dprintk("NFS reply remove: %d\n", status);
423         return status;
424 }
425
426 static int
427 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
428 {
429         struct unlinkxdr {
430                 struct nfs3_diropargs arg;
431                 struct nfs_fattr res;
432         } *ptr;
433
434         ptr = (struct unlinkxdr *)kmalloc(sizeof(*ptr), GFP_KERNEL);
435         if (!ptr)
436                 return -ENOMEM;
437         ptr->arg.fh = NFS_FH(dir->d_inode);
438         ptr->arg.name = name->name;
439         ptr->arg.len = name->len;
440         nfs_fattr_init(&ptr->res);
441         msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
442         msg->rpc_argp = &ptr->arg;
443         msg->rpc_resp = &ptr->res;
444         return 0;
445 }
446
447 static int
448 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
449 {
450         struct rpc_message *msg = &task->tk_msg;
451         struct nfs_fattr        *dir_attr;
452
453         if (nfs3_async_handle_jukebox(task, dir->d_inode))
454                 return 1;
455         if (msg->rpc_argp) {
456                 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
457                 nfs_post_op_update_inode(dir->d_inode, dir_attr);
458                 kfree(msg->rpc_argp);
459         }
460         return 0;
461 }
462
463 static int
464 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
465                  struct inode *new_dir, struct qstr *new_name)
466 {
467         struct nfs_fattr        old_dir_attr, new_dir_attr;
468         struct nfs3_renameargs  arg = {
469                 .fromfh         = NFS_FH(old_dir),
470                 .fromname       = old_name->name,
471                 .fromlen        = old_name->len,
472                 .tofh           = NFS_FH(new_dir),
473                 .toname         = new_name->name,
474                 .tolen          = new_name->len
475         };
476         struct nfs3_renameres   res = {
477                 .fromattr       = &old_dir_attr,
478                 .toattr         = &new_dir_attr
479         };
480         int                     status;
481
482         dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name);
483         nfs_fattr_init(&old_dir_attr);
484         nfs_fattr_init(&new_dir_attr);
485         status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
486         nfs_post_op_update_inode(old_dir, &old_dir_attr);
487         nfs_post_op_update_inode(new_dir, &new_dir_attr);
488         dprintk("NFS reply rename: %d\n", status);
489         return status;
490 }
491
492 static int
493 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
494 {
495         struct nfs_fattr        dir_attr, fattr;
496         struct nfs3_linkargs    arg = {
497                 .fromfh         = NFS_FH(inode),
498                 .tofh           = NFS_FH(dir),
499                 .toname         = name->name,
500                 .tolen          = name->len
501         };
502         struct nfs3_linkres     res = {
503                 .dir_attr       = &dir_attr,
504                 .fattr          = &fattr
505         };
506         int                     status;
507
508         dprintk("NFS call  link %s\n", name->name);
509         nfs_fattr_init(&dir_attr);
510         nfs_fattr_init(&fattr);
511         status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
512         nfs_post_op_update_inode(dir, &dir_attr);
513         nfs_post_op_update_inode(inode, &fattr);
514         dprintk("NFS reply link: %d\n", status);
515         return status;
516 }
517
518 static int
519 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
520                   struct iattr *sattr, struct nfs_fh *fhandle,
521                   struct nfs_fattr *fattr)
522 {
523         struct nfs_fattr        dir_attr;
524         struct nfs3_symlinkargs arg = {
525                 .fromfh         = NFS_FH(dir),
526                 .fromname       = name->name,
527                 .fromlen        = name->len,
528                 .topath         = path->name,
529                 .tolen          = path->len,
530                 .sattr          = sattr
531         };
532         struct nfs3_diropres    res = {
533                 .dir_attr       = &dir_attr,
534                 .fh             = fhandle,
535                 .fattr          = fattr
536         };
537         int                     status;
538
539         if (path->len > NFS3_MAXPATHLEN)
540                 return -ENAMETOOLONG;
541         dprintk("NFS call  symlink %s -> %s\n", name->name, path->name);
542         nfs_fattr_init(&dir_attr);
543         nfs_fattr_init(fattr);
544         status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
545         nfs_post_op_update_inode(dir, &dir_attr);
546         dprintk("NFS reply symlink: %d\n", status);
547         return status;
548 }
549
550 static int
551 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
552 {
553         struct nfs_fh fhandle;
554         struct nfs_fattr fattr, dir_attr;
555         struct nfs3_mkdirargs   arg = {
556                 .fh             = NFS_FH(dir),
557                 .name           = dentry->d_name.name,
558                 .len            = dentry->d_name.len,
559                 .sattr          = sattr
560         };
561         struct nfs3_diropres    res = {
562                 .dir_attr       = &dir_attr,
563                 .fh             = &fhandle,
564                 .fattr          = &fattr
565         };
566         int mode = sattr->ia_mode;
567         int status;
568
569         dprintk("NFS call  mkdir %s\n", dentry->d_name.name);
570
571         sattr->ia_mode &= ~current->fs->umask;
572
573         nfs_fattr_init(&dir_attr);
574         nfs_fattr_init(&fattr);
575         status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
576         nfs_post_op_update_inode(dir, &dir_attr);
577         if (status != 0)
578                 goto out;
579         status = nfs_instantiate(dentry, &fhandle, &fattr);
580         if (status != 0)
581                 goto out;
582         status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
583 out:
584         dprintk("NFS reply mkdir: %d\n", status);
585         return status;
586 }
587
588 static int
589 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
590 {
591         struct nfs_fattr        dir_attr;
592         struct nfs3_diropargs   arg = {
593                 .fh             = NFS_FH(dir),
594                 .name           = name->name,
595                 .len            = name->len
596         };
597         int                     status;
598
599         dprintk("NFS call  rmdir %s\n", name->name);
600         nfs_fattr_init(&dir_attr);
601         status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
602         nfs_post_op_update_inode(dir, &dir_attr);
603         dprintk("NFS reply rmdir: %d\n", status);
604         return status;
605 }
606
607 /*
608  * The READDIR implementation is somewhat hackish - we pass the user buffer
609  * to the encode function, which installs it in the receive iovec.
610  * The decode function itself doesn't perform any decoding, it just makes
611  * sure the reply is syntactically correct.
612  *
613  * Also note that this implementation handles both plain readdir and
614  * readdirplus.
615  */
616 static int
617 nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
618                   u64 cookie, struct page *page, unsigned int count, int plus)
619 {
620         struct inode            *dir = dentry->d_inode;
621         struct nfs_fattr        dir_attr;
622         u32                     *verf = NFS_COOKIEVERF(dir);
623         struct nfs3_readdirargs arg = {
624                 .fh             = NFS_FH(dir),
625                 .cookie         = cookie,
626                 .verf           = {verf[0], verf[1]},
627                 .plus           = plus,
628                 .count          = count,
629                 .pages          = &page
630         };
631         struct nfs3_readdirres  res = {
632                 .dir_attr       = &dir_attr,
633                 .verf           = verf,
634                 .plus           = plus
635         };
636         struct rpc_message      msg = {
637                 .rpc_proc       = &nfs3_procedures[NFS3PROC_READDIR],
638                 .rpc_argp       = &arg,
639                 .rpc_resp       = &res,
640                 .rpc_cred       = cred
641         };
642         int                     status;
643
644         lock_kernel();
645
646         if (plus)
647                 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
648
649         dprintk("NFS call  readdir%s %d\n",
650                         plus? "plus" : "", (unsigned int) cookie);
651
652         nfs_fattr_init(&dir_attr);
653         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
654         nfs_refresh_inode(dir, &dir_attr);
655         dprintk("NFS reply readdir: %d\n", status);
656         unlock_kernel();
657         return status;
658 }
659
660 static int
661 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
662                 dev_t rdev)
663 {
664         struct nfs_fh fh;
665         struct nfs_fattr fattr, dir_attr;
666         struct nfs3_mknodargs   arg = {
667                 .fh             = NFS_FH(dir),
668                 .name           = dentry->d_name.name,
669                 .len            = dentry->d_name.len,
670                 .sattr          = sattr,
671                 .rdev           = rdev
672         };
673         struct nfs3_diropres    res = {
674                 .dir_attr       = &dir_attr,
675                 .fh             = &fh,
676                 .fattr          = &fattr
677         };
678         mode_t mode = sattr->ia_mode;
679         int status;
680
681         switch (sattr->ia_mode & S_IFMT) {
682         case S_IFBLK:   arg.type = NF3BLK;  break;
683         case S_IFCHR:   arg.type = NF3CHR;  break;
684         case S_IFIFO:   arg.type = NF3FIFO; break;
685         case S_IFSOCK:  arg.type = NF3SOCK; break;
686         default:        return -EINVAL;
687         }
688
689         dprintk("NFS call  mknod %s %u:%u\n", dentry->d_name.name,
690                         MAJOR(rdev), MINOR(rdev));
691
692         sattr->ia_mode &= ~current->fs->umask;
693
694         nfs_fattr_init(&dir_attr);
695         nfs_fattr_init(&fattr);
696         status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
697         nfs_post_op_update_inode(dir, &dir_attr);
698         if (status != 0)
699                 goto out;
700         status = nfs_instantiate(dentry, &fh, &fattr);
701         if (status != 0)
702                 goto out;
703         status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
704 out:
705         dprintk("NFS reply mknod: %d\n", status);
706         return status;
707 }
708
709 static int
710 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
711                  struct nfs_fsstat *stat)
712 {
713         int     status;
714
715         dprintk("NFS call  fsstat\n");
716         nfs_fattr_init(stat->fattr);
717         status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
718         dprintk("NFS reply statfs: %d\n", status);
719         return status;
720 }
721
722 static int
723 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
724                  struct nfs_fsinfo *info)
725 {
726         int     status;
727
728         dprintk("NFS call  fsinfo\n");
729         nfs_fattr_init(info->fattr);
730         status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
731         dprintk("NFS reply fsinfo: %d\n", status);
732         return status;
733 }
734
735 static int
736 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
737                    struct nfs_pathconf *info)
738 {
739         int     status;
740
741         dprintk("NFS call  pathconf\n");
742         nfs_fattr_init(info->fattr);
743         status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
744         dprintk("NFS reply pathconf: %d\n", status);
745         return status;
746 }
747
748 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
749
750 static void nfs3_read_done(struct rpc_task *task, void *calldata)
751 {
752         struct nfs_read_data *data = calldata;
753
754         if (nfs3_async_handle_jukebox(task, data->inode))
755                 return;
756         /* Call back common NFS readpage processing */
757         if (task->tk_status >= 0)
758                 nfs_refresh_inode(data->inode, &data->fattr);
759         nfs_readpage_result(task, calldata);
760 }
761
762 static const struct rpc_call_ops nfs3_read_ops = {
763         .rpc_call_done = nfs3_read_done,
764         .rpc_release = nfs_readdata_release,
765 };
766
767 static void
768 nfs3_proc_read_setup(struct nfs_read_data *data)
769 {
770         struct rpc_task         *task = &data->task;
771         struct inode            *inode = data->inode;
772         int                     flags;
773         struct rpc_message      msg = {
774                 .rpc_proc       = &nfs3_procedures[NFS3PROC_READ],
775                 .rpc_argp       = &data->args,
776                 .rpc_resp       = &data->res,
777                 .rpc_cred       = data->cred,
778         };
779
780         /* N.B. Do we need to test? Never called for swapfile inode */
781         flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
782
783         /* Finalize the task. */
784         rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs3_read_ops, data);
785         rpc_call_setup(task, &msg, 0);
786 }
787
788 static void nfs3_write_done(struct rpc_task *task, void *calldata)
789 {
790         struct nfs_write_data *data = calldata;
791
792         if (nfs3_async_handle_jukebox(task, data->inode))
793                 return;
794         if (task->tk_status >= 0)
795                 nfs_post_op_update_inode(data->inode, data->res.fattr);
796         nfs_writeback_done(task, calldata);
797 }
798
799 static const struct rpc_call_ops nfs3_write_ops = {
800         .rpc_call_done = nfs3_write_done,
801         .rpc_release = nfs_writedata_release,
802 };
803
804 static void
805 nfs3_proc_write_setup(struct nfs_write_data *data, int how)
806 {
807         struct rpc_task         *task = &data->task;
808         struct inode            *inode = data->inode;
809         int                     stable;
810         int                     flags;
811         struct rpc_message      msg = {
812                 .rpc_proc       = &nfs3_procedures[NFS3PROC_WRITE],
813                 .rpc_argp       = &data->args,
814                 .rpc_resp       = &data->res,
815                 .rpc_cred       = data->cred,
816         };
817
818         if (how & FLUSH_STABLE) {
819                 if (!NFS_I(inode)->ncommit)
820                         stable = NFS_FILE_SYNC;
821                 else
822                         stable = NFS_DATA_SYNC;
823         } else
824                 stable = NFS_UNSTABLE;
825         data->args.stable = stable;
826
827         /* Set the initial flags for the task.  */
828         flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
829
830         /* Finalize the task. */
831         rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs3_write_ops, data);
832         rpc_call_setup(task, &msg, 0);
833 }
834
835 static void nfs3_commit_done(struct rpc_task *task, void *calldata)
836 {
837         struct nfs_write_data *data = calldata;
838
839         if (nfs3_async_handle_jukebox(task, data->inode))
840                 return;
841         if (task->tk_status >= 0)
842                 nfs_post_op_update_inode(data->inode, data->res.fattr);
843         nfs_commit_done(task, calldata);
844 }
845
846 static const struct rpc_call_ops nfs3_commit_ops = {
847         .rpc_call_done = nfs3_commit_done,
848         .rpc_release = nfs_commit_release,
849 };
850
851 static void
852 nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
853 {
854         struct rpc_task         *task = &data->task;
855         struct inode            *inode = data->inode;
856         int                     flags;
857         struct rpc_message      msg = {
858                 .rpc_proc       = &nfs3_procedures[NFS3PROC_COMMIT],
859                 .rpc_argp       = &data->args,
860                 .rpc_resp       = &data->res,
861                 .rpc_cred       = data->cred,
862         };
863
864         /* Set the initial flags for the task.  */
865         flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
866
867         /* Finalize the task. */
868         rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs3_commit_ops, data);
869         rpc_call_setup(task, &msg, 0);
870 }
871
872 static int
873 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
874 {
875         return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
876 }
877
878 struct nfs_rpc_ops      nfs_v3_clientops = {
879         .version        = 3,                    /* protocol version */
880         .dentry_ops     = &nfs_dentry_operations,
881         .dir_inode_ops  = &nfs3_dir_inode_operations,
882         .file_inode_ops = &nfs3_file_inode_operations,
883         .getroot        = nfs3_proc_get_root,
884         .getattr        = nfs3_proc_getattr,
885         .setattr        = nfs3_proc_setattr,
886         .lookup         = nfs3_proc_lookup,
887         .access         = nfs3_proc_access,
888         .readlink       = nfs3_proc_readlink,
889         .read           = nfs3_proc_read,
890         .write          = nfs3_proc_write,
891         .commit         = nfs3_proc_commit,
892         .create         = nfs3_proc_create,
893         .remove         = nfs3_proc_remove,
894         .unlink_setup   = nfs3_proc_unlink_setup,
895         .unlink_done    = nfs3_proc_unlink_done,
896         .rename         = nfs3_proc_rename,
897         .link           = nfs3_proc_link,
898         .symlink        = nfs3_proc_symlink,
899         .mkdir          = nfs3_proc_mkdir,
900         .rmdir          = nfs3_proc_rmdir,
901         .readdir        = nfs3_proc_readdir,
902         .mknod          = nfs3_proc_mknod,
903         .statfs         = nfs3_proc_statfs,
904         .fsinfo         = nfs3_proc_fsinfo,
905         .pathconf       = nfs3_proc_pathconf,
906         .decode_dirent  = nfs3_decode_dirent,
907         .read_setup     = nfs3_proc_read_setup,
908         .write_setup    = nfs3_proc_write_setup,
909         .commit_setup   = nfs3_proc_commit_setup,
910         .file_open      = nfs_open,
911         .file_release   = nfs_release,
912         .lock           = nfs3_proc_lock,
913         .clear_acl_cache = nfs3_forget_cached_acls,
914 };