[PATCH] NFS: Cache the NFSv3 acls.
[linux-2.6/verdex.git] / fs / nfs / nfs3proc.c
blob7851569b31c63f03a5095f503d0b1b18183273d4
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>
20 #include <linux/nfs_mount.h>
22 #define NFSDBG_FACILITY NFSDBG_PROC
24 extern struct rpc_procinfo nfs3_procedures[];
26 /* A wrapper to handle the EJUKEBOX error message */
27 static int
28 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
30 sigset_t oldset;
31 int res;
32 rpc_clnt_sigmask(clnt, &oldset);
33 do {
34 res = rpc_call_sync(clnt, msg, flags);
35 if (res != -EJUKEBOX)
36 break;
37 set_current_state(TASK_INTERRUPTIBLE);
38 schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
39 res = -ERESTARTSYS;
40 } while (!signalled());
41 rpc_clnt_sigunmask(clnt, &oldset);
42 return res;
45 static inline int
46 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
48 struct rpc_message msg = {
49 .rpc_proc = &clnt->cl_procinfo[proc],
50 .rpc_argp = argp,
51 .rpc_resp = resp,
53 return nfs3_rpc_wrapper(clnt, &msg, flags);
56 #define rpc_call(clnt, proc, argp, resp, flags) \
57 nfs3_rpc_call_wrapper(clnt, proc, argp, resp, flags)
58 #define rpc_call_sync(clnt, msg, flags) \
59 nfs3_rpc_wrapper(clnt, msg, flags)
61 static int
62 nfs3_async_handle_jukebox(struct rpc_task *task)
64 if (task->tk_status != -EJUKEBOX)
65 return 0;
66 task->tk_status = 0;
67 rpc_restart_call(task);
68 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
69 return 1;
73 * Bare-bones access to getattr: this is for nfs_read_super.
75 static int
76 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
77 struct nfs_fsinfo *info)
79 int status;
81 dprintk("%s: call fsinfo\n", __FUNCTION__);
82 info->fattr->valid = 0;
83 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
84 dprintk("%s: reply fsinfo: %d\n", __FUNCTION__, status);
85 if (!(info->fattr->valid & NFS_ATTR_FATTR)) {
86 status = rpc_call(server->client_sys, NFS3PROC_GETATTR, fhandle, info->fattr, 0);
87 dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
89 return status;
93 * One function for each procedure in the NFS protocol.
95 static int
96 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
97 struct nfs_fattr *fattr)
99 int status;
101 dprintk("NFS call getattr\n");
102 fattr->valid = 0;
103 status = rpc_call(server->client, NFS3PROC_GETATTR,
104 fhandle, fattr, 0);
105 dprintk("NFS reply getattr: %d\n", status);
106 return status;
109 static int
110 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
111 struct iattr *sattr)
113 struct inode *inode = dentry->d_inode;
114 struct nfs3_sattrargs arg = {
115 .fh = NFS_FH(inode),
116 .sattr = sattr,
118 int status;
120 dprintk("NFS call setattr\n");
121 fattr->valid = 0;
122 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
123 dprintk("NFS reply setattr: %d\n", status);
124 return status;
127 static int
128 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
129 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
131 struct nfs_fattr dir_attr;
132 struct nfs3_diropargs arg = {
133 .fh = NFS_FH(dir),
134 .name = name->name,
135 .len = name->len
137 struct nfs3_diropres res = {
138 .dir_attr = &dir_attr,
139 .fh = fhandle,
140 .fattr = fattr
142 int status;
144 dprintk("NFS call lookup %s\n", name->name);
145 dir_attr.valid = 0;
146 fattr->valid = 0;
147 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
148 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
149 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
150 fhandle, fattr, 0);
151 dprintk("NFS reply lookup: %d\n", status);
152 if (status >= 0)
153 status = nfs_refresh_inode(dir, &dir_attr);
154 return status;
157 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
159 struct nfs_fattr fattr;
160 struct nfs3_accessargs arg = {
161 .fh = NFS_FH(inode),
163 struct nfs3_accessres res = {
164 .fattr = &fattr,
166 struct rpc_message msg = {
167 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
168 .rpc_argp = &arg,
169 .rpc_resp = &res,
170 .rpc_cred = entry->cred
172 int mode = entry->mask;
173 int status;
175 dprintk("NFS call access\n");
176 fattr.valid = 0;
178 if (mode & MAY_READ)
179 arg.access |= NFS3_ACCESS_READ;
180 if (S_ISDIR(inode->i_mode)) {
181 if (mode & MAY_WRITE)
182 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
183 if (mode & MAY_EXEC)
184 arg.access |= NFS3_ACCESS_LOOKUP;
185 } else {
186 if (mode & MAY_WRITE)
187 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
188 if (mode & MAY_EXEC)
189 arg.access |= NFS3_ACCESS_EXECUTE;
191 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
192 nfs_refresh_inode(inode, &fattr);
193 if (status == 0) {
194 entry->mask = 0;
195 if (res.access & NFS3_ACCESS_READ)
196 entry->mask |= MAY_READ;
197 if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
198 entry->mask |= MAY_WRITE;
199 if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
200 entry->mask |= MAY_EXEC;
202 dprintk("NFS reply access: %d\n", status);
203 return status;
206 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
207 unsigned int pgbase, unsigned int pglen)
209 struct nfs_fattr fattr;
210 struct nfs3_readlinkargs args = {
211 .fh = NFS_FH(inode),
212 .pgbase = pgbase,
213 .pglen = pglen,
214 .pages = &page
216 int status;
218 dprintk("NFS call readlink\n");
219 fattr.valid = 0;
220 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
221 &args, &fattr, 0);
222 nfs_refresh_inode(inode, &fattr);
223 dprintk("NFS reply readlink: %d\n", status);
224 return status;
227 static int nfs3_proc_read(struct nfs_read_data *rdata)
229 int flags = rdata->flags;
230 struct inode * inode = rdata->inode;
231 struct nfs_fattr * fattr = rdata->res.fattr;
232 struct rpc_message msg = {
233 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
234 .rpc_argp = &rdata->args,
235 .rpc_resp = &rdata->res,
236 .rpc_cred = rdata->cred,
238 int status;
240 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
241 (long long) rdata->args.offset);
242 fattr->valid = 0;
243 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
244 if (status >= 0)
245 nfs_refresh_inode(inode, fattr);
246 dprintk("NFS reply read: %d\n", status);
247 return status;
250 static int nfs3_proc_write(struct nfs_write_data *wdata)
252 int rpcflags = wdata->flags;
253 struct inode * inode = wdata->inode;
254 struct nfs_fattr * fattr = wdata->res.fattr;
255 struct rpc_message msg = {
256 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
257 .rpc_argp = &wdata->args,
258 .rpc_resp = &wdata->res,
259 .rpc_cred = wdata->cred,
261 int status;
263 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
264 (long long) wdata->args.offset);
265 fattr->valid = 0;
266 status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
267 if (status >= 0)
268 nfs_refresh_inode(inode, fattr);
269 dprintk("NFS reply write: %d\n", status);
270 return status < 0? status : wdata->res.count;
273 static int nfs3_proc_commit(struct nfs_write_data *cdata)
275 struct inode * inode = cdata->inode;
276 struct nfs_fattr * fattr = cdata->res.fattr;
277 struct rpc_message msg = {
278 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
279 .rpc_argp = &cdata->args,
280 .rpc_resp = &cdata->res,
281 .rpc_cred = cdata->cred,
283 int status;
285 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
286 (long long) cdata->args.offset);
287 fattr->valid = 0;
288 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
289 if (status >= 0)
290 nfs_refresh_inode(inode, fattr);
291 dprintk("NFS reply commit: %d\n", status);
292 return status;
296 * Create a regular file.
297 * For now, we don't implement O_EXCL.
299 static int
300 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
301 int flags)
303 struct nfs_fh fhandle;
304 struct nfs_fattr fattr;
305 struct nfs_fattr dir_attr;
306 struct nfs3_createargs arg = {
307 .fh = NFS_FH(dir),
308 .name = dentry->d_name.name,
309 .len = dentry->d_name.len,
310 .sattr = sattr,
312 struct nfs3_diropres res = {
313 .dir_attr = &dir_attr,
314 .fh = &fhandle,
315 .fattr = &fattr
317 mode_t mode = sattr->ia_mode;
318 int status;
320 dprintk("NFS call create %s\n", dentry->d_name.name);
321 arg.createmode = NFS3_CREATE_UNCHECKED;
322 if (flags & O_EXCL) {
323 arg.createmode = NFS3_CREATE_EXCLUSIVE;
324 arg.verifier[0] = jiffies;
325 arg.verifier[1] = current->pid;
328 sattr->ia_mode &= ~current->fs->umask;
330 again:
331 dir_attr.valid = 0;
332 fattr.valid = 0;
333 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
334 nfs_refresh_inode(dir, &dir_attr);
336 /* If the server doesn't support the exclusive creation semantics,
337 * try again with simple 'guarded' mode. */
338 if (status == NFSERR_NOTSUPP) {
339 switch (arg.createmode) {
340 case NFS3_CREATE_EXCLUSIVE:
341 arg.createmode = NFS3_CREATE_GUARDED;
342 break;
344 case NFS3_CREATE_GUARDED:
345 arg.createmode = NFS3_CREATE_UNCHECKED;
346 break;
348 case NFS3_CREATE_UNCHECKED:
349 goto out;
351 goto again;
354 if (status == 0)
355 status = nfs_instantiate(dentry, &fhandle, &fattr);
356 if (status != 0)
357 goto out;
359 /* When we created the file with exclusive semantics, make
360 * sure we set the attributes afterwards. */
361 if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
362 dprintk("NFS call setattr (post-create)\n");
364 if (!(sattr->ia_valid & ATTR_ATIME_SET))
365 sattr->ia_valid |= ATTR_ATIME;
366 if (!(sattr->ia_valid & ATTR_MTIME_SET))
367 sattr->ia_valid |= ATTR_MTIME;
369 /* Note: we could use a guarded setattr here, but I'm
370 * not sure this buys us anything (and I'd have
371 * to revamp the NFSv3 XDR code) */
372 status = nfs3_proc_setattr(dentry, &fattr, sattr);
373 nfs_refresh_inode(dentry->d_inode, &fattr);
374 dprintk("NFS reply setattr (post-create): %d\n", status);
376 if (status != 0)
377 goto out;
378 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
379 out:
380 dprintk("NFS reply create: %d\n", status);
381 return status;
384 static int
385 nfs3_proc_remove(struct inode *dir, struct qstr *name)
387 struct nfs_fattr dir_attr;
388 struct nfs3_diropargs arg = {
389 .fh = NFS_FH(dir),
390 .name = name->name,
391 .len = name->len
393 struct rpc_message msg = {
394 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
395 .rpc_argp = &arg,
396 .rpc_resp = &dir_attr,
398 int status;
400 dprintk("NFS call remove %s\n", name->name);
401 dir_attr.valid = 0;
402 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
403 nfs_refresh_inode(dir, &dir_attr);
404 dprintk("NFS reply remove: %d\n", status);
405 return status;
408 static int
409 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
411 struct unlinkxdr {
412 struct nfs3_diropargs arg;
413 struct nfs_fattr res;
414 } *ptr;
416 ptr = (struct unlinkxdr *)kmalloc(sizeof(*ptr), GFP_KERNEL);
417 if (!ptr)
418 return -ENOMEM;
419 ptr->arg.fh = NFS_FH(dir->d_inode);
420 ptr->arg.name = name->name;
421 ptr->arg.len = name->len;
422 ptr->res.valid = 0;
423 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
424 msg->rpc_argp = &ptr->arg;
425 msg->rpc_resp = &ptr->res;
426 return 0;
429 static int
430 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
432 struct rpc_message *msg = &task->tk_msg;
433 struct nfs_fattr *dir_attr;
435 if (nfs3_async_handle_jukebox(task))
436 return 1;
437 if (msg->rpc_argp) {
438 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
439 nfs_refresh_inode(dir->d_inode, dir_attr);
440 kfree(msg->rpc_argp);
442 return 0;
445 static int
446 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
447 struct inode *new_dir, struct qstr *new_name)
449 struct nfs_fattr old_dir_attr, new_dir_attr;
450 struct nfs3_renameargs arg = {
451 .fromfh = NFS_FH(old_dir),
452 .fromname = old_name->name,
453 .fromlen = old_name->len,
454 .tofh = NFS_FH(new_dir),
455 .toname = new_name->name,
456 .tolen = new_name->len
458 struct nfs3_renameres res = {
459 .fromattr = &old_dir_attr,
460 .toattr = &new_dir_attr
462 int status;
464 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
465 old_dir_attr.valid = 0;
466 new_dir_attr.valid = 0;
467 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
468 nfs_refresh_inode(old_dir, &old_dir_attr);
469 nfs_refresh_inode(new_dir, &new_dir_attr);
470 dprintk("NFS reply rename: %d\n", status);
471 return status;
474 static int
475 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
477 struct nfs_fattr dir_attr, fattr;
478 struct nfs3_linkargs arg = {
479 .fromfh = NFS_FH(inode),
480 .tofh = NFS_FH(dir),
481 .toname = name->name,
482 .tolen = name->len
484 struct nfs3_linkres res = {
485 .dir_attr = &dir_attr,
486 .fattr = &fattr
488 int status;
490 dprintk("NFS call link %s\n", name->name);
491 dir_attr.valid = 0;
492 fattr.valid = 0;
493 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
494 nfs_refresh_inode(dir, &dir_attr);
495 nfs_refresh_inode(inode, &fattr);
496 dprintk("NFS reply link: %d\n", status);
497 return status;
500 static int
501 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
502 struct iattr *sattr, struct nfs_fh *fhandle,
503 struct nfs_fattr *fattr)
505 struct nfs_fattr dir_attr;
506 struct nfs3_symlinkargs arg = {
507 .fromfh = NFS_FH(dir),
508 .fromname = name->name,
509 .fromlen = name->len,
510 .topath = path->name,
511 .tolen = path->len,
512 .sattr = sattr
514 struct nfs3_diropres res = {
515 .dir_attr = &dir_attr,
516 .fh = fhandle,
517 .fattr = fattr
519 int status;
521 if (path->len > NFS3_MAXPATHLEN)
522 return -ENAMETOOLONG;
523 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
524 dir_attr.valid = 0;
525 fattr->valid = 0;
526 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
527 nfs_refresh_inode(dir, &dir_attr);
528 dprintk("NFS reply symlink: %d\n", status);
529 return status;
532 static int
533 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
535 struct nfs_fh fhandle;
536 struct nfs_fattr fattr, dir_attr;
537 struct nfs3_mkdirargs arg = {
538 .fh = NFS_FH(dir),
539 .name = dentry->d_name.name,
540 .len = dentry->d_name.len,
541 .sattr = sattr
543 struct nfs3_diropres res = {
544 .dir_attr = &dir_attr,
545 .fh = &fhandle,
546 .fattr = &fattr
548 int mode = sattr->ia_mode;
549 int status;
551 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
552 dir_attr.valid = 0;
553 fattr.valid = 0;
555 sattr->ia_mode &= ~current->fs->umask;
557 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
558 nfs_refresh_inode(dir, &dir_attr);
559 if (status != 0)
560 goto out;
561 status = nfs_instantiate(dentry, &fhandle, &fattr);
562 if (status != 0)
563 goto out;
564 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
565 out:
566 dprintk("NFS reply mkdir: %d\n", status);
567 return status;
570 static int
571 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
573 struct nfs_fattr dir_attr;
574 struct nfs3_diropargs arg = {
575 .fh = NFS_FH(dir),
576 .name = name->name,
577 .len = name->len
579 int status;
581 dprintk("NFS call rmdir %s\n", name->name);
582 dir_attr.valid = 0;
583 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
584 nfs_refresh_inode(dir, &dir_attr);
585 dprintk("NFS reply rmdir: %d\n", status);
586 return status;
590 * The READDIR implementation is somewhat hackish - we pass the user buffer
591 * to the encode function, which installs it in the receive iovec.
592 * The decode function itself doesn't perform any decoding, it just makes
593 * sure the reply is syntactically correct.
595 * Also note that this implementation handles both plain readdir and
596 * readdirplus.
598 static int
599 nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
600 u64 cookie, struct page *page, unsigned int count, int plus)
602 struct inode *dir = dentry->d_inode;
603 struct nfs_fattr dir_attr;
604 u32 *verf = NFS_COOKIEVERF(dir);
605 struct nfs3_readdirargs arg = {
606 .fh = NFS_FH(dir),
607 .cookie = cookie,
608 .verf = {verf[0], verf[1]},
609 .plus = plus,
610 .count = count,
611 .pages = &page
613 struct nfs3_readdirres res = {
614 .dir_attr = &dir_attr,
615 .verf = verf,
616 .plus = plus
618 struct rpc_message msg = {
619 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
620 .rpc_argp = &arg,
621 .rpc_resp = &res,
622 .rpc_cred = cred
624 int status;
626 lock_kernel();
628 if (plus)
629 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
631 dprintk("NFS call readdir%s %d\n",
632 plus? "plus" : "", (unsigned int) cookie);
634 dir_attr.valid = 0;
635 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
636 nfs_refresh_inode(dir, &dir_attr);
637 dprintk("NFS reply readdir: %d\n", status);
638 unlock_kernel();
639 return status;
642 static int
643 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
644 dev_t rdev)
646 struct nfs_fh fh;
647 struct nfs_fattr fattr, dir_attr;
648 struct nfs3_mknodargs arg = {
649 .fh = NFS_FH(dir),
650 .name = dentry->d_name.name,
651 .len = dentry->d_name.len,
652 .sattr = sattr,
653 .rdev = rdev
655 struct nfs3_diropres res = {
656 .dir_attr = &dir_attr,
657 .fh = &fh,
658 .fattr = &fattr
660 mode_t mode = sattr->ia_mode;
661 int status;
663 switch (sattr->ia_mode & S_IFMT) {
664 case S_IFBLK: arg.type = NF3BLK; break;
665 case S_IFCHR: arg.type = NF3CHR; break;
666 case S_IFIFO: arg.type = NF3FIFO; break;
667 case S_IFSOCK: arg.type = NF3SOCK; break;
668 default: return -EINVAL;
671 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
672 MAJOR(rdev), MINOR(rdev));
674 sattr->ia_mode &= ~current->fs->umask;
676 dir_attr.valid = 0;
677 fattr.valid = 0;
678 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
679 nfs_refresh_inode(dir, &dir_attr);
680 if (status != 0)
681 goto out;
682 status = nfs_instantiate(dentry, &fh, &fattr);
683 if (status != 0)
684 goto out;
685 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
686 out:
687 dprintk("NFS reply mknod: %d\n", status);
688 return status;
691 static int
692 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
693 struct nfs_fsstat *stat)
695 int status;
697 dprintk("NFS call fsstat\n");
698 stat->fattr->valid = 0;
699 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
700 dprintk("NFS reply statfs: %d\n", status);
701 return status;
704 static int
705 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
706 struct nfs_fsinfo *info)
708 int status;
710 dprintk("NFS call fsinfo\n");
711 info->fattr->valid = 0;
712 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
713 dprintk("NFS reply fsinfo: %d\n", status);
714 return status;
717 static int
718 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
719 struct nfs_pathconf *info)
721 int status;
723 dprintk("NFS call pathconf\n");
724 info->fattr->valid = 0;
725 status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
726 dprintk("NFS reply pathconf: %d\n", status);
727 return status;
730 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
732 static void
733 nfs3_read_done(struct rpc_task *task)
735 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
737 if (nfs3_async_handle_jukebox(task))
738 return;
739 /* Call back common NFS readpage processing */
740 if (task->tk_status >= 0)
741 nfs_refresh_inode(data->inode, &data->fattr);
742 nfs_readpage_result(task);
745 static void
746 nfs3_proc_read_setup(struct nfs_read_data *data)
748 struct rpc_task *task = &data->task;
749 struct inode *inode = data->inode;
750 int flags;
751 struct rpc_message msg = {
752 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
753 .rpc_argp = &data->args,
754 .rpc_resp = &data->res,
755 .rpc_cred = data->cred,
758 /* N.B. Do we need to test? Never called for swapfile inode */
759 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
761 /* Finalize the task. */
762 rpc_init_task(task, NFS_CLIENT(inode), nfs3_read_done, flags);
763 rpc_call_setup(task, &msg, 0);
766 static void
767 nfs3_write_done(struct rpc_task *task)
769 struct nfs_write_data *data;
771 if (nfs3_async_handle_jukebox(task))
772 return;
773 data = (struct nfs_write_data *)task->tk_calldata;
774 if (task->tk_status >= 0)
775 nfs_refresh_inode(data->inode, data->res.fattr);
776 nfs_writeback_done(task);
779 static void
780 nfs3_proc_write_setup(struct nfs_write_data *data, int how)
782 struct rpc_task *task = &data->task;
783 struct inode *inode = data->inode;
784 int stable;
785 int flags;
786 struct rpc_message msg = {
787 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
788 .rpc_argp = &data->args,
789 .rpc_resp = &data->res,
790 .rpc_cred = data->cred,
793 if (how & FLUSH_STABLE) {
794 if (!NFS_I(inode)->ncommit)
795 stable = NFS_FILE_SYNC;
796 else
797 stable = NFS_DATA_SYNC;
798 } else
799 stable = NFS_UNSTABLE;
800 data->args.stable = stable;
802 /* Set the initial flags for the task. */
803 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
805 /* Finalize the task. */
806 rpc_init_task(task, NFS_CLIENT(inode), nfs3_write_done, flags);
807 rpc_call_setup(task, &msg, 0);
810 static void
811 nfs3_commit_done(struct rpc_task *task)
813 struct nfs_write_data *data;
815 if (nfs3_async_handle_jukebox(task))
816 return;
817 data = (struct nfs_write_data *)task->tk_calldata;
818 if (task->tk_status >= 0)
819 nfs_refresh_inode(data->inode, data->res.fattr);
820 nfs_commit_done(task);
823 static void
824 nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
826 struct rpc_task *task = &data->task;
827 struct inode *inode = data->inode;
828 int flags;
829 struct rpc_message msg = {
830 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
831 .rpc_argp = &data->args,
832 .rpc_resp = &data->res,
833 .rpc_cred = data->cred,
836 /* Set the initial flags for the task. */
837 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
839 /* Finalize the task. */
840 rpc_init_task(task, NFS_CLIENT(inode), nfs3_commit_done, flags);
841 rpc_call_setup(task, &msg, 0);
844 static int
845 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
847 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
850 struct nfs_rpc_ops nfs_v3_clientops = {
851 .version = 3, /* protocol version */
852 .dentry_ops = &nfs_dentry_operations,
853 .dir_inode_ops = &nfs3_dir_inode_operations,
854 .file_inode_ops = &nfs3_file_inode_operations,
855 .getroot = nfs3_proc_get_root,
856 .getattr = nfs3_proc_getattr,
857 .setattr = nfs3_proc_setattr,
858 .lookup = nfs3_proc_lookup,
859 .access = nfs3_proc_access,
860 .readlink = nfs3_proc_readlink,
861 .read = nfs3_proc_read,
862 .write = nfs3_proc_write,
863 .commit = nfs3_proc_commit,
864 .create = nfs3_proc_create,
865 .remove = nfs3_proc_remove,
866 .unlink_setup = nfs3_proc_unlink_setup,
867 .unlink_done = nfs3_proc_unlink_done,
868 .rename = nfs3_proc_rename,
869 .link = nfs3_proc_link,
870 .symlink = nfs3_proc_symlink,
871 .mkdir = nfs3_proc_mkdir,
872 .rmdir = nfs3_proc_rmdir,
873 .readdir = nfs3_proc_readdir,
874 .mknod = nfs3_proc_mknod,
875 .statfs = nfs3_proc_statfs,
876 .fsinfo = nfs3_proc_fsinfo,
877 .pathconf = nfs3_proc_pathconf,
878 .decode_dirent = nfs3_decode_dirent,
879 .read_setup = nfs3_proc_read_setup,
880 .write_setup = nfs3_proc_write_setup,
881 .commit_setup = nfs3_proc_commit_setup,
882 .file_open = nfs_open,
883 .file_release = nfs_release,
884 .lock = nfs3_proc_lock,
885 .clear_acl_cache = nfs3_forget_cached_acls,