[PATCH] DVB: misc. updates to the dvb-core
[linux-2.6/history.git] / fs / nfs / nfs3proc.c
blob6be08f678009170e47e6a9a08b0753d84c8679f3
1 /*
2 * linux/fs/nfs/nfs3proc.c
4 * Client-side NFSv3 procedures stubs.
6 * Copyright (C) 1997, Olaf Kirch
7 */
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>
21 #define NFSDBG_FACILITY NFSDBG_PROC
23 extern struct rpc_procinfo nfs3_procedures[];
25 /* A wrapper to handle the EJUKEBOX error message */
26 static int
27 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
29 sigset_t oldset;
30 int res;
31 rpc_clnt_sigmask(clnt, &oldset);
32 do {
33 res = rpc_call_sync(clnt, msg, flags);
34 if (res != -EJUKEBOX)
35 break;
36 set_current_state(TASK_INTERRUPTIBLE);
37 schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
38 res = -ERESTARTSYS;
39 } while (!signalled());
40 rpc_clnt_sigunmask(clnt, &oldset);
41 return res;
44 static inline int
45 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
47 struct rpc_message msg = {
48 .rpc_proc = &nfs3_procedures[proc],
49 .rpc_argp = argp,
50 .rpc_resp = resp,
52 return nfs3_rpc_wrapper(clnt, &msg, flags);
55 #define rpc_call(clnt, proc, argp, resp, flags) \
56 nfs3_rpc_call_wrapper(clnt, proc, argp, resp, flags)
57 #define rpc_call_sync(clnt, msg, flags) \
58 nfs3_rpc_wrapper(clnt, msg, flags)
60 static int
61 nfs3_async_handle_jukebox(struct rpc_task *task)
63 if (task->tk_status != -EJUKEBOX)
64 return 0;
65 task->tk_status = 0;
66 rpc_restart_call(task);
67 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
68 return 1;
72 * Bare-bones access to getattr: this is for nfs_read_super.
74 static int
75 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
76 struct nfs_fsinfo *info)
78 int status;
80 dprintk("%s: call fsinfo\n", __FUNCTION__);
81 info->fattr->valid = 0;
82 status = rpc_call(server->client_sys, 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(server->client_sys, NFS3PROC_GETATTR, fhandle, info->fattr, 0);
86 dprintk("%s: reply getattr %d\n", __FUNCTION__, status);
88 return status;
92 * One function for each procedure in the NFS protocol.
94 static int
95 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
96 struct nfs_fattr *fattr)
98 int status;
100 dprintk("NFS call getattr\n");
101 fattr->valid = 0;
102 status = rpc_call(server->client, NFS3PROC_GETATTR,
103 fhandle, fattr, 0);
104 dprintk("NFS reply getattr\n");
105 return status;
108 static int
109 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
110 struct iattr *sattr)
112 struct inode *inode = dentry->d_inode;
113 struct nfs3_sattrargs arg = {
114 .fh = NFS_FH(inode),
115 .sattr = sattr,
117 int status;
119 dprintk("NFS call setattr\n");
120 fattr->valid = 0;
121 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
122 dprintk("NFS reply setattr\n");
123 return status;
126 static int
127 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
128 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
130 struct nfs_fattr dir_attr;
131 struct nfs3_diropargs arg = {
132 .fh = NFS_FH(dir),
133 .name = name->name,
134 .len = name->len
136 struct nfs3_diropres res = {
137 .dir_attr = &dir_attr,
138 .fh = fhandle,
139 .fattr = fattr
141 int status;
143 dprintk("NFS call lookup %s\n", name->name);
144 dir_attr.valid = 0;
145 fattr->valid = 0;
146 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
147 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
148 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
149 fhandle, fattr, 0);
150 dprintk("NFS reply lookup: %d\n", status);
151 if (status >= 0)
152 status = nfs_refresh_inode(dir, &dir_attr);
153 return status;
156 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
158 struct nfs_fattr fattr;
159 struct nfs3_accessargs arg = {
160 .fh = NFS_FH(inode),
162 struct nfs3_accessres res = {
163 .fattr = &fattr,
165 struct rpc_message msg = {
166 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
167 .rpc_argp = &arg,
168 .rpc_resp = &res,
169 .rpc_cred = entry->cred
171 int mode = entry->mask;
172 int status;
174 dprintk("NFS call access\n");
175 fattr.valid = 0;
177 if (mode & MAY_READ)
178 arg.access |= NFS3_ACCESS_READ;
179 if (S_ISDIR(inode->i_mode)) {
180 if (mode & MAY_WRITE)
181 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
182 if (mode & MAY_EXEC)
183 arg.access |= NFS3_ACCESS_LOOKUP;
184 } else {
185 if (mode & MAY_WRITE)
186 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
187 if (mode & MAY_EXEC)
188 arg.access |= NFS3_ACCESS_EXECUTE;
190 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
191 nfs_refresh_inode(inode, &fattr);
192 if (status == 0) {
193 entry->mask = 0;
194 if (res.access & NFS3_ACCESS_READ)
195 entry->mask |= MAY_READ;
196 if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
197 entry->mask |= MAY_WRITE;
198 if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
199 entry->mask |= MAY_EXEC;
201 dprintk("NFS reply access, status = %d\n", status);
202 return status;
205 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
206 unsigned int pgbase, unsigned int pglen)
208 struct nfs_fattr fattr;
209 struct nfs3_readlinkargs args = {
210 .fh = NFS_FH(inode),
211 .pgbase = pgbase,
212 .pglen = pglen,
213 .pages = &page
215 int status;
217 dprintk("NFS call readlink\n");
218 fattr.valid = 0;
219 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
220 &args, &fattr, 0);
221 nfs_refresh_inode(inode, &fattr);
222 dprintk("NFS reply readlink: %d\n", status);
223 return status;
226 static int nfs3_proc_read(struct nfs_read_data *rdata)
228 int flags = rdata->flags;
229 struct inode * inode = rdata->inode;
230 struct nfs_fattr * fattr = rdata->res.fattr;
231 struct rpc_message msg = {
232 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
233 .rpc_argp = &rdata->args,
234 .rpc_resp = &rdata->res,
235 .rpc_cred = rdata->cred,
237 int status;
239 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
240 (long long) rdata->args.offset);
241 fattr->valid = 0;
242 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
243 if (status >= 0)
244 nfs_refresh_inode(inode, fattr);
245 dprintk("NFS reply read: %d\n", status);
246 return status;
249 static int nfs3_proc_write(struct nfs_write_data *wdata)
251 int rpcflags = wdata->flags;
252 struct inode * inode = wdata->inode;
253 struct nfs_fattr * fattr = wdata->res.fattr;
254 struct rpc_message msg = {
255 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
256 .rpc_argp = &wdata->args,
257 .rpc_resp = &wdata->res,
258 .rpc_cred = wdata->cred,
260 int status;
262 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
263 (long long) wdata->args.offset);
264 fattr->valid = 0;
265 status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
266 if (status >= 0)
267 nfs_refresh_inode(inode, fattr);
268 dprintk("NFS reply write: %d\n", status);
269 return status < 0? status : wdata->res.count;
272 static int nfs3_proc_commit(struct nfs_write_data *cdata)
274 struct inode * inode = cdata->inode;
275 struct nfs_fattr * fattr = cdata->res.fattr;
276 struct rpc_message msg = {
277 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
278 .rpc_argp = &cdata->args,
279 .rpc_resp = &cdata->res,
280 .rpc_cred = cdata->cred,
282 int status;
284 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
285 (long long) cdata->args.offset);
286 fattr->valid = 0;
287 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
288 if (status >= 0)
289 nfs_refresh_inode(inode, fattr);
290 dprintk("NFS reply commit: %d\n", status);
291 return status;
295 * Create a regular file.
296 * For now, we don't implement O_EXCL.
298 static struct inode *
299 nfs3_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,
300 int flags)
302 struct nfs_fh fhandle;
303 struct nfs_fattr fattr;
304 struct nfs_fattr dir_attr;
305 struct nfs3_createargs arg = {
306 .fh = NFS_FH(dir),
307 .name = name->name,
308 .len = name->len,
309 .sattr = sattr,
311 struct nfs3_diropres res = {
312 .dir_attr = &dir_attr,
313 .fh = &fhandle,
314 .fattr = &fattr
316 int status;
318 dprintk("NFS call create %s\n", name->name);
319 arg.createmode = NFS3_CREATE_UNCHECKED;
320 if (flags & O_EXCL) {
321 arg.createmode = NFS3_CREATE_EXCLUSIVE;
322 arg.verifier[0] = jiffies;
323 arg.verifier[1] = current->pid;
326 again:
327 dir_attr.valid = 0;
328 fattr.valid = 0;
329 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
330 nfs_refresh_inode(dir, &dir_attr);
332 /* If the server doesn't support the exclusive creation semantics,
333 * try again with simple 'guarded' mode. */
334 if (status == NFSERR_NOTSUPP) {
335 switch (arg.createmode) {
336 case NFS3_CREATE_EXCLUSIVE:
337 arg.createmode = NFS3_CREATE_GUARDED;
338 break;
340 case NFS3_CREATE_GUARDED:
341 arg.createmode = NFS3_CREATE_UNCHECKED;
342 break;
344 case NFS3_CREATE_UNCHECKED:
345 goto exit;
347 goto again;
350 exit:
351 dprintk("NFS reply create: %d\n", status);
353 if (status != 0)
354 goto out;
355 if (fhandle.size == 0 || !(fattr.valid & NFS_ATTR_FATTR)) {
356 status = nfs3_proc_lookup(dir, name, &fhandle, &fattr);
357 if (status != 0)
358 goto out;
361 /* When we created the file with exclusive semantics, make
362 * sure we set the attributes afterwards. */
363 if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
364 struct nfs3_sattrargs arg = {
365 .fh = &fhandle,
366 .sattr = sattr,
368 dprintk("NFS call setattr (post-create)\n");
370 if (!(sattr->ia_valid & ATTR_ATIME_SET))
371 sattr->ia_valid |= ATTR_ATIME;
372 if (!(sattr->ia_valid & ATTR_MTIME_SET))
373 sattr->ia_valid |= ATTR_MTIME;
375 /* Note: we could use a guarded setattr here, but I'm
376 * not sure this buys us anything (and I'd have
377 * to revamp the NFSv3 XDR code) */
378 fattr.valid = 0;
379 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SETATTR,
380 &arg, &fattr, 0);
381 dprintk("NFS reply setattr (post-create): %d\n", status);
383 if (status == 0) {
384 struct inode *inode;
385 inode = nfs_fhget(dir->i_sb, &fhandle, &fattr);
386 if (inode)
387 return inode;
388 status = -ENOMEM;
390 out:
391 return ERR_PTR(status);
394 static int
395 nfs3_proc_remove(struct inode *dir, struct qstr *name)
397 struct nfs_fattr dir_attr;
398 struct nfs3_diropargs arg = {
399 .fh = NFS_FH(dir),
400 .name = name->name,
401 .len = name->len
403 struct rpc_message msg = {
404 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
405 .rpc_argp = &arg,
406 .rpc_resp = &dir_attr,
408 int status;
410 dprintk("NFS call remove %s\n", name->name);
411 dir_attr.valid = 0;
412 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
413 nfs_refresh_inode(dir, &dir_attr);
414 dprintk("NFS reply remove: %d\n", status);
415 return status;
418 static int
419 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
421 struct unlinkxdr {
422 struct nfs3_diropargs arg;
423 struct nfs_fattr res;
424 } *ptr;
426 ptr = (struct unlinkxdr *)kmalloc(sizeof(*ptr), GFP_KERNEL);
427 if (!ptr)
428 return -ENOMEM;
429 ptr->arg.fh = NFS_FH(dir->d_inode);
430 ptr->arg.name = name->name;
431 ptr->arg.len = name->len;
432 ptr->res.valid = 0;
433 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
434 msg->rpc_argp = &ptr->arg;
435 msg->rpc_resp = &ptr->res;
436 return 0;
439 static int
440 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
442 struct rpc_message *msg = &task->tk_msg;
443 struct nfs_fattr *dir_attr;
445 if (nfs3_async_handle_jukebox(task))
446 return 1;
447 if (msg->rpc_argp) {
448 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
449 nfs_refresh_inode(dir->d_inode, dir_attr);
450 kfree(msg->rpc_argp);
452 return 0;
455 static int
456 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
457 struct inode *new_dir, struct qstr *new_name)
459 struct nfs_fattr old_dir_attr, new_dir_attr;
460 struct nfs3_renameargs arg = {
461 .fromfh = NFS_FH(old_dir),
462 .fromname = old_name->name,
463 .fromlen = old_name->len,
464 .tofh = NFS_FH(new_dir),
465 .toname = new_name->name,
466 .tolen = new_name->len
468 struct nfs3_renameres res = {
469 .fromattr = &old_dir_attr,
470 .toattr = &new_dir_attr
472 int status;
474 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
475 old_dir_attr.valid = 0;
476 new_dir_attr.valid = 0;
477 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
478 nfs_refresh_inode(old_dir, &old_dir_attr);
479 nfs_refresh_inode(new_dir, &new_dir_attr);
480 dprintk("NFS reply rename: %d\n", status);
481 return status;
484 static int
485 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
487 struct nfs_fattr dir_attr, fattr;
488 struct nfs3_linkargs arg = {
489 .fromfh = NFS_FH(inode),
490 .tofh = NFS_FH(dir),
491 .toname = name->name,
492 .tolen = name->len
494 struct nfs3_linkres res = {
495 .dir_attr = &dir_attr,
496 .fattr = &fattr
498 int status;
500 dprintk("NFS call link %s\n", name->name);
501 dir_attr.valid = 0;
502 fattr.valid = 0;
503 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
504 nfs_refresh_inode(dir, &dir_attr);
505 nfs_refresh_inode(inode, &fattr);
506 dprintk("NFS reply link: %d\n", status);
507 return status;
510 static int
511 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
512 struct iattr *sattr, struct nfs_fh *fhandle,
513 struct nfs_fattr *fattr)
515 struct nfs_fattr dir_attr;
516 struct nfs3_symlinkargs arg = {
517 .fromfh = NFS_FH(dir),
518 .fromname = name->name,
519 .fromlen = name->len,
520 .topath = path->name,
521 .tolen = path->len,
522 .sattr = sattr
524 struct nfs3_diropres res = {
525 .dir_attr = &dir_attr,
526 .fh = fhandle,
527 .fattr = fattr
529 int status;
531 if (path->len > NFS3_MAXPATHLEN)
532 return -ENAMETOOLONG;
533 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
534 dir_attr.valid = 0;
535 fattr->valid = 0;
536 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
537 nfs_refresh_inode(dir, &dir_attr);
538 dprintk("NFS reply symlink: %d\n", status);
539 return status;
542 static int
543 nfs3_proc_mkdir(struct inode *dir, struct qstr *name, struct iattr *sattr,
544 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
546 struct nfs_fattr dir_attr;
547 struct nfs3_mkdirargs arg = {
548 .fh = NFS_FH(dir),
549 .name = name->name,
550 .len = name->len,
551 .sattr = sattr
553 struct nfs3_diropres res = {
554 .dir_attr = &dir_attr,
555 .fh = fhandle,
556 .fattr = fattr
558 int status;
560 dprintk("NFS call mkdir %s\n", name->name);
561 dir_attr.valid = 0;
562 fattr->valid = 0;
563 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
564 nfs_refresh_inode(dir, &dir_attr);
565 dprintk("NFS reply mkdir: %d\n", status);
566 return status;
569 static int
570 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
572 struct nfs_fattr dir_attr;
573 struct nfs3_diropargs arg = {
574 .fh = NFS_FH(dir),
575 .name = name->name,
576 .len = name->len
578 int status;
580 dprintk("NFS call rmdir %s\n", name->name);
581 dir_attr.valid = 0;
582 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
583 nfs_refresh_inode(dir, &dir_attr);
584 dprintk("NFS reply rmdir: %d\n", status);
585 return status;
589 * The READDIR implementation is somewhat hackish - we pass the user buffer
590 * to the encode function, which installs it in the receive iovec.
591 * The decode function itself doesn't perform any decoding, it just makes
592 * sure the reply is syntactically correct.
594 * Also note that this implementation handles both plain readdir and
595 * readdirplus.
597 static int
598 nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
599 u64 cookie, struct page *page, unsigned int count, int plus)
601 struct inode *dir = dentry->d_inode;
602 struct nfs_fattr dir_attr;
603 u32 *verf = NFS_COOKIEVERF(dir);
604 struct nfs3_readdirargs arg = {
605 .fh = NFS_FH(dir),
606 .cookie = cookie,
607 .verf = {verf[0], verf[1]},
608 .plus = plus,
609 .count = count,
610 .pages = &page
612 struct nfs3_readdirres res = {
613 .dir_attr = &dir_attr,
614 .verf = verf,
615 .plus = plus
617 struct rpc_message msg = {
618 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
619 .rpc_argp = &arg,
620 .rpc_resp = &res,
621 .rpc_cred = cred
623 int status;
625 lock_kernel();
627 if (plus)
628 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
630 dprintk("NFS call readdir%s %d\n",
631 plus? "plus" : "", (unsigned int) cookie);
633 dir_attr.valid = 0;
634 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
635 nfs_refresh_inode(dir, &dir_attr);
636 dprintk("NFS reply readdir: %d\n", status);
637 unlock_kernel();
638 return status;
641 static int
642 nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
643 dev_t rdev, struct nfs_fh *fh, struct nfs_fattr *fattr)
645 struct nfs_fattr dir_attr;
646 struct nfs3_mknodargs arg = {
647 .fh = NFS_FH(dir),
648 .name = name->name,
649 .len = name->len,
650 .sattr = sattr,
651 .rdev = rdev
653 struct nfs3_diropres res = {
654 .dir_attr = &dir_attr,
655 .fh = fh,
656 .fattr = fattr
658 int status;
660 switch (sattr->ia_mode & S_IFMT) {
661 case S_IFBLK: arg.type = NF3BLK; break;
662 case S_IFCHR: arg.type = NF3CHR; break;
663 case S_IFIFO: arg.type = NF3FIFO; break;
664 case S_IFSOCK: arg.type = NF3SOCK; break;
665 default: return -EINVAL;
668 dprintk("NFS call mknod %s %u:%u\n", name->name,
669 MAJOR(rdev), MINOR(rdev));
670 dir_attr.valid = 0;
671 fattr->valid = 0;
672 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
673 nfs_refresh_inode(dir, &dir_attr);
674 dprintk("NFS reply mknod: %d\n", status);
675 return status;
678 static int
679 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
680 struct nfs_fsstat *stat)
682 int status;
684 dprintk("NFS call fsstat\n");
685 stat->fattr->valid = 0;
686 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
687 dprintk("NFS reply statfs: %d\n", status);
688 return status;
691 static int
692 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
693 struct nfs_fsinfo *info)
695 int status;
697 dprintk("NFS call fsinfo\n");
698 info->fattr->valid = 0;
699 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
700 dprintk("NFS reply fsinfo: %d\n", status);
701 return status;
704 static int
705 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
706 struct nfs_pathconf *info)
708 int status;
710 dprintk("NFS call pathconf\n");
711 info->fattr->valid = 0;
712 status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
713 dprintk("NFS reply pathconf: %d\n", status);
714 return status;
717 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
719 static void
720 nfs3_read_done(struct rpc_task *task)
722 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
724 if (nfs3_async_handle_jukebox(task))
725 return;
726 /* Call back common NFS readpage processing */
727 if (task->tk_status >= 0)
728 nfs_refresh_inode(data->inode, &data->fattr);
729 nfs_readpage_result(task);
732 static void
733 nfs3_proc_read_setup(struct nfs_read_data *data)
735 struct rpc_task *task = &data->task;
736 struct inode *inode = data->inode;
737 int flags;
738 struct rpc_message msg = {
739 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
740 .rpc_argp = &data->args,
741 .rpc_resp = &data->res,
742 .rpc_cred = data->cred,
745 /* N.B. Do we need to test? Never called for swapfile inode */
746 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
748 /* Finalize the task. */
749 rpc_init_task(task, NFS_CLIENT(inode), nfs3_read_done, flags);
750 rpc_call_setup(task, &msg, 0);
753 static void
754 nfs3_write_done(struct rpc_task *task)
756 struct nfs_write_data *data;
758 if (nfs3_async_handle_jukebox(task))
759 return;
760 data = (struct nfs_write_data *)task->tk_calldata;
761 if (task->tk_status >= 0)
762 nfs_refresh_inode(data->inode, data->res.fattr);
763 nfs_writeback_done(task);
766 static void
767 nfs3_proc_write_setup(struct nfs_write_data *data, int how)
769 struct rpc_task *task = &data->task;
770 struct inode *inode = data->inode;
771 int stable;
772 int flags;
773 struct rpc_message msg = {
774 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
775 .rpc_argp = &data->args,
776 .rpc_resp = &data->res,
777 .rpc_cred = data->cred,
780 if (how & FLUSH_STABLE) {
781 if (!NFS_I(inode)->ncommit)
782 stable = NFS_FILE_SYNC;
783 else
784 stable = NFS_DATA_SYNC;
785 } else
786 stable = NFS_UNSTABLE;
787 data->args.stable = stable;
789 /* Set the initial flags for the task. */
790 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
792 /* Finalize the task. */
793 rpc_init_task(task, NFS_CLIENT(inode), nfs3_write_done, flags);
794 rpc_call_setup(task, &msg, 0);
797 static void
798 nfs3_commit_done(struct rpc_task *task)
800 struct nfs_write_data *data;
802 if (nfs3_async_handle_jukebox(task))
803 return;
804 data = (struct nfs_write_data *)task->tk_calldata;
805 if (task->tk_status >= 0)
806 nfs_refresh_inode(data->inode, data->res.fattr);
807 nfs_commit_done(task);
810 static void
811 nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
813 struct rpc_task *task = &data->task;
814 struct inode *inode = data->inode;
815 int flags;
816 struct rpc_message msg = {
817 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
818 .rpc_argp = &data->args,
819 .rpc_resp = &data->res,
820 .rpc_cred = data->cred,
823 /* Set the initial flags for the task. */
824 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
826 /* Finalize the task. */
827 rpc_init_task(task, NFS_CLIENT(inode), nfs3_commit_done, flags);
828 rpc_call_setup(task, &msg, 0);
831 static int
832 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
834 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
837 struct nfs_rpc_ops nfs_v3_clientops = {
838 .version = 3, /* protocol version */
839 .dentry_ops = &nfs_dentry_operations,
840 .dir_inode_ops = &nfs_dir_inode_operations,
841 .getroot = nfs3_proc_get_root,
842 .getattr = nfs3_proc_getattr,
843 .setattr = nfs3_proc_setattr,
844 .lookup = nfs3_proc_lookup,
845 .access = nfs3_proc_access,
846 .readlink = nfs3_proc_readlink,
847 .read = nfs3_proc_read,
848 .write = nfs3_proc_write,
849 .commit = nfs3_proc_commit,
850 .create = nfs3_proc_create,
851 .remove = nfs3_proc_remove,
852 .unlink_setup = nfs3_proc_unlink_setup,
853 .unlink_done = nfs3_proc_unlink_done,
854 .rename = nfs3_proc_rename,
855 .link = nfs3_proc_link,
856 .symlink = nfs3_proc_symlink,
857 .mkdir = nfs3_proc_mkdir,
858 .rmdir = nfs3_proc_rmdir,
859 .readdir = nfs3_proc_readdir,
860 .mknod = nfs3_proc_mknod,
861 .statfs = nfs3_proc_statfs,
862 .fsinfo = nfs3_proc_fsinfo,
863 .pathconf = nfs3_proc_pathconf,
864 .decode_dirent = nfs3_decode_dirent,
865 .read_setup = nfs3_proc_read_setup,
866 .write_setup = nfs3_proc_write_setup,
867 .commit_setup = nfs3_proc_commit_setup,
868 .file_open = nfs_open,
869 .file_release = nfs_release,
870 .lock = nfs3_proc_lock,