Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / fs / nfs / nfs3proc.c
blob9ccadb74518e74fd432223a0c64d48800cca4dea
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/smp_lock.h>
20 #define NFSDBG_FACILITY NFSDBG_PROC
22 extern struct rpc_procinfo nfs3_procedures[];
24 /* A wrapper to handle the EJUKEBOX error message */
25 static int
26 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
28 sigset_t oldset;
29 int res;
30 rpc_clnt_sigmask(clnt, &oldset);
31 do {
32 res = rpc_call_sync(clnt, msg, flags);
33 if (res != -EJUKEBOX)
34 break;
35 set_current_state(TASK_INTERRUPTIBLE);
36 schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
37 res = -ERESTARTSYS;
38 } while (!signalled());
39 rpc_clnt_sigunmask(clnt, &oldset);
40 return res;
43 static inline int
44 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
46 struct rpc_message msg = {
47 .rpc_proc = &nfs3_procedures[proc],
48 .rpc_argp = argp,
49 .rpc_resp = resp,
51 return nfs3_rpc_wrapper(clnt, &msg, flags);
54 #define rpc_call(clnt, proc, argp, resp, flags) \
55 nfs3_rpc_call_wrapper(clnt, proc, argp, resp, flags)
56 #define rpc_call_sync(clnt, msg, flags) \
57 nfs3_rpc_wrapper(clnt, msg, flags)
59 static int
60 nfs3_async_handle_jukebox(struct rpc_task *task)
62 if (task->tk_status != -EJUKEBOX)
63 return 0;
64 task->tk_status = 0;
65 rpc_restart_call(task);
66 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
67 return 1;
71 * Bare-bones access to getattr: this is for nfs_read_super.
73 static int
74 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
75 struct nfs_fattr *fattr)
77 int status;
79 dprintk("NFS call getroot\n");
80 fattr->valid = 0;
81 status = rpc_call(server->client, NFS3PROC_GETATTR, fhandle, fattr, 0);
82 dprintk("NFS reply getroot\n");
83 return status;
87 * One function for each procedure in the NFS protocol.
89 static int
90 nfs3_proc_getattr(struct inode *inode, struct nfs_fattr *fattr)
92 int status;
94 dprintk("NFS call getattr\n");
95 fattr->valid = 0;
96 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_GETATTR,
97 NFS_FH(inode), fattr, 0);
98 dprintk("NFS reply getattr\n");
99 return status;
102 static int
103 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
104 struct iattr *sattr)
106 struct inode *inode = dentry->d_inode;
107 struct nfs3_sattrargs arg = {
108 .fh = NFS_FH(inode),
109 .sattr = sattr,
111 int status;
113 dprintk("NFS call setattr\n");
114 fattr->valid = 0;
115 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
116 dprintk("NFS reply setattr\n");
117 return status;
120 static int
121 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
122 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
124 struct nfs_fattr dir_attr;
125 struct nfs3_diropargs arg = {
126 .fh = NFS_FH(dir),
127 .name = name->name,
128 .len = name->len
130 struct nfs3_diropres res = {
131 .dir_attr = &dir_attr,
132 .fh = fhandle,
133 .fattr = fattr
135 int status;
137 dprintk("NFS call lookup %s\n", name->name);
138 dir_attr.valid = 0;
139 fattr->valid = 0;
140 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
141 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
142 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
143 fhandle, fattr, 0);
144 dprintk("NFS reply lookup: %d\n", status);
145 if (status >= 0)
146 status = nfs_refresh_inode(dir, &dir_attr);
147 return status;
150 static int
151 nfs3_proc_access(struct inode *inode, struct rpc_cred *cred, int mode)
153 struct nfs_fattr fattr;
154 struct nfs3_accessargs arg = {
155 .fh = NFS_FH(inode),
157 struct nfs3_accessres res = {
158 .fattr = &fattr,
160 struct rpc_message msg = {
161 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
162 .rpc_argp = &arg,
163 .rpc_resp = &res,
164 .rpc_cred = cred
166 int status;
168 dprintk("NFS call access\n");
169 fattr.valid = 0;
171 if (mode & MAY_READ)
172 arg.access |= NFS3_ACCESS_READ;
173 if (S_ISDIR(inode->i_mode)) {
174 if (mode & MAY_WRITE)
175 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
176 if (mode & MAY_EXEC)
177 arg.access |= NFS3_ACCESS_LOOKUP;
178 } else {
179 if (mode & MAY_WRITE)
180 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
181 if (mode & MAY_EXEC)
182 arg.access |= NFS3_ACCESS_EXECUTE;
184 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
185 nfs_refresh_inode(inode, &fattr);
186 dprintk("NFS reply access\n");
188 if (status == 0 && (arg.access & res.access) != arg.access)
189 status = -EACCES;
190 return status;
193 static int
194 nfs3_proc_readlink(struct inode *inode, struct page *page)
196 struct nfs_fattr fattr;
197 struct nfs3_readlinkargs args = {
198 .fh = NFS_FH(inode),
199 .count = PAGE_CACHE_SIZE,
200 .pages = &page
202 int status;
204 dprintk("NFS call readlink\n");
205 fattr.valid = 0;
206 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
207 &args, &fattr, 0);
208 nfs_refresh_inode(inode, &fattr);
209 dprintk("NFS reply readlink: %d\n", status);
210 return status;
213 static int
214 nfs3_proc_read(struct inode *inode, struct rpc_cred *cred,
215 struct nfs_fattr *fattr, int flags,
216 unsigned int base, unsigned int count, struct page *page,
217 int *eofp)
219 u64 offset = page_offset(page) + base;
220 struct nfs_readargs arg = {
221 .fh = NFS_FH(inode),
222 .offset = offset,
223 .count = count,
224 .pgbase = base,
225 .pages = &page
227 struct nfs_readres res = {
228 .fattr = fattr,
229 .count = count,
231 struct rpc_message msg = {
232 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
233 .rpc_argp = &arg,
234 .rpc_resp = &res,
235 .rpc_cred = cred
237 int status;
239 dprintk("NFS call read %d @ %Ld\n", count, (long long)offset);
240 fattr->valid = 0;
241 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
242 dprintk("NFS reply read: %d\n", status);
243 *eofp = res.eof;
244 return status;
247 static int
248 nfs3_proc_write(struct inode *inode, struct rpc_cred *cred,
249 struct nfs_fattr *fattr, int flags,
250 unsigned int base, unsigned int count,
251 struct page *page, struct nfs_writeverf *verf)
253 u64 offset = page_offset(page) + base;
254 struct nfs_writeargs arg = {
255 .fh = NFS_FH(inode),
256 .offset = offset,
257 .count = count,
258 .stable = NFS_FILE_SYNC,
259 .pgbase = base,
260 .pages = &page
262 struct nfs_writeres res = {
263 .fattr = fattr,
264 .verf = verf,
266 struct rpc_message msg = {
267 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
268 .rpc_argp = &arg,
269 .rpc_resp = &res,
270 .rpc_cred = cred
272 int status, rpcflags = 0;
274 dprintk("NFS call write %d @ %Ld\n", count, (long long)offset);
275 fattr->valid = 0;
276 if (flags & NFS_RW_SWAP)
277 rpcflags |= NFS_RPC_SWAPFLAGS;
278 arg.stable = (flags & NFS_RW_SYNC) ? NFS_FILE_SYNC : NFS_UNSTABLE;
280 status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
282 dprintk("NFS reply read: %d\n", status);
283 return status < 0? status : res.count;
287 * Create a regular file.
288 * For now, we don't implement O_EXCL.
290 static int
291 nfs3_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,
292 int flags, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
294 struct nfs_fattr dir_attr;
295 struct nfs3_createargs arg = {
296 .fh = NFS_FH(dir),
297 .name = name->name,
298 .len = name->len,
299 .sattr = sattr,
301 struct nfs3_diropres res = {
302 .dir_attr = &dir_attr,
303 .fh = fhandle,
304 .fattr = fattr
306 int status;
308 dprintk("NFS call create %s\n", name->name);
309 arg.createmode = NFS3_CREATE_UNCHECKED;
310 if (flags & O_EXCL) {
311 arg.createmode = NFS3_CREATE_EXCLUSIVE;
312 arg.verifier[0] = jiffies;
313 arg.verifier[1] = current->pid;
316 again:
317 dir_attr.valid = 0;
318 fattr->valid = 0;
319 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
320 nfs_refresh_inode(dir, &dir_attr);
322 /* If the server doesn't support the exclusive creation semantics,
323 * try again with simple 'guarded' mode. */
324 if (status == NFSERR_NOTSUPP) {
325 switch (arg.createmode) {
326 case NFS3_CREATE_EXCLUSIVE:
327 arg.createmode = NFS3_CREATE_GUARDED;
328 break;
330 case NFS3_CREATE_GUARDED:
331 arg.createmode = NFS3_CREATE_UNCHECKED;
332 break;
334 case NFS3_CREATE_UNCHECKED:
335 goto exit;
337 goto again;
340 exit:
341 dprintk("NFS reply create: %d\n", status);
343 /* When we created the file with exclusive semantics, make
344 * sure we set the attributes afterwards. */
345 if (status == 0 && arg.createmode == NFS3_CREATE_EXCLUSIVE) {
346 struct nfs3_sattrargs arg = {
347 .fh = fhandle,
348 .sattr = sattr,
350 dprintk("NFS call setattr (post-create)\n");
352 /* Note: we could use a guarded setattr here, but I'm
353 * not sure this buys us anything (and I'd have
354 * to revamp the NFSv3 XDR code) */
355 fattr->valid = 0;
356 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SETATTR,
357 &arg, fattr, 0);
358 dprintk("NFS reply setattr (post-create): %d\n", status);
361 return status;
364 static int
365 nfs3_proc_remove(struct inode *dir, struct qstr *name)
367 struct nfs_fattr dir_attr;
368 struct nfs3_diropargs arg = {
369 .fh = NFS_FH(dir),
370 .name = name->name,
371 .len = name->len
373 struct rpc_message msg = {
374 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
375 .rpc_argp = &arg,
376 .rpc_resp = &dir_attr,
378 int status;
380 dprintk("NFS call remove %s\n", name->name);
381 dir_attr.valid = 0;
382 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
383 nfs_refresh_inode(dir, &dir_attr);
384 dprintk("NFS reply remove: %d\n", status);
385 return status;
388 static int
389 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
391 struct nfs3_diropargs *arg;
392 struct nfs_fattr *res;
394 arg = (struct nfs3_diropargs *)kmalloc(sizeof(*arg)+sizeof(*res), GFP_KERNEL);
395 if (!arg)
396 return -ENOMEM;
397 res = (struct nfs_fattr*)(arg + 1);
398 arg->fh = NFS_FH(dir->d_inode);
399 arg->name = name->name;
400 arg->len = name->len;
401 res->valid = 0;
402 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
403 msg->rpc_argp = arg;
404 msg->rpc_resp = res;
405 return 0;
408 static int
409 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
411 struct rpc_message *msg = &task->tk_msg;
412 struct nfs_fattr *dir_attr;
414 if (nfs3_async_handle_jukebox(task))
415 return 1;
416 if (msg->rpc_argp) {
417 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
418 nfs_refresh_inode(dir->d_inode, dir_attr);
419 kfree(msg->rpc_argp);
421 return 0;
424 static int
425 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
426 struct inode *new_dir, struct qstr *new_name)
428 struct nfs_fattr old_dir_attr, new_dir_attr;
429 struct nfs3_renameargs arg = {
430 .fromfh = NFS_FH(old_dir),
431 .fromname = old_name->name,
432 .fromlen = old_name->len,
433 .tofh = NFS_FH(new_dir),
434 .toname = new_name->name,
435 .tolen = new_name->len
437 struct nfs3_renameres res = {
438 .fromattr = &old_dir_attr,
439 .toattr = &new_dir_attr
441 int status;
443 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
444 old_dir_attr.valid = 0;
445 new_dir_attr.valid = 0;
446 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
447 nfs_refresh_inode(old_dir, &old_dir_attr);
448 nfs_refresh_inode(new_dir, &new_dir_attr);
449 dprintk("NFS reply rename: %d\n", status);
450 return status;
453 static int
454 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
456 struct nfs_fattr dir_attr, fattr;
457 struct nfs3_linkargs arg = {
458 .fromfh = NFS_FH(inode),
459 .tofh = NFS_FH(dir),
460 .toname = name->name,
461 .tolen = name->len
463 struct nfs3_linkres res = {
464 .dir_attr = &dir_attr,
465 .fattr = &fattr
467 int status;
469 dprintk("NFS call link %s\n", name->name);
470 dir_attr.valid = 0;
471 fattr.valid = 0;
472 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
473 nfs_refresh_inode(dir, &dir_attr);
474 nfs_refresh_inode(inode, &fattr);
475 dprintk("NFS reply link: %d\n", status);
476 return status;
479 static int
480 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
481 struct iattr *sattr, struct nfs_fh *fhandle,
482 struct nfs_fattr *fattr)
484 struct nfs_fattr dir_attr;
485 struct nfs3_symlinkargs arg = {
486 .fromfh = NFS_FH(dir),
487 .fromname = name->name,
488 .fromlen = name->len,
489 .topath = path->name,
490 .tolen = path->len,
491 .sattr = sattr
493 struct nfs3_diropres res = {
494 .dir_attr = &dir_attr,
495 .fh = fhandle,
496 .fattr = fattr
498 int status;
500 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
501 dir_attr.valid = 0;
502 fattr->valid = 0;
503 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
504 nfs_refresh_inode(dir, &dir_attr);
505 dprintk("NFS reply symlink: %d\n", status);
506 return status;
509 static int
510 nfs3_proc_mkdir(struct inode *dir, struct qstr *name, struct iattr *sattr,
511 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
513 struct nfs_fattr dir_attr;
514 struct nfs3_mkdirargs arg = {
515 .fh = NFS_FH(dir),
516 .name = name->name,
517 .len = name->len,
518 .sattr = sattr
520 struct nfs3_diropres res = {
521 .dir_attr = &dir_attr,
522 .fh = fhandle,
523 .fattr = fattr
525 int status;
527 dprintk("NFS call mkdir %s\n", name->name);
528 dir_attr.valid = 0;
529 fattr->valid = 0;
530 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
531 nfs_refresh_inode(dir, &dir_attr);
532 dprintk("NFS reply mkdir: %d\n", status);
533 return status;
536 static int
537 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
539 struct nfs_fattr dir_attr;
540 struct nfs3_diropargs arg = {
541 .fh = NFS_FH(dir),
542 .name = name->name,
543 .len = name->len
545 int status;
547 dprintk("NFS call rmdir %s\n", name->name);
548 dir_attr.valid = 0;
549 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
550 nfs_refresh_inode(dir, &dir_attr);
551 dprintk("NFS reply rmdir: %d\n", status);
552 return status;
556 * The READDIR implementation is somewhat hackish - we pass the user buffer
557 * to the encode function, which installs it in the receive iovec.
558 * The decode function itself doesn't perform any decoding, it just makes
559 * sure the reply is syntactically correct.
561 * Also note that this implementation handles both plain readdir and
562 * readdirplus.
564 static int
565 nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
566 u64 cookie, struct page *page, unsigned int count, int plus)
568 struct inode *dir = dentry->d_inode;
569 struct nfs_fattr dir_attr;
570 u32 *verf = NFS_COOKIEVERF(dir);
571 struct nfs3_readdirargs arg = {
572 .fh = NFS_FH(dir),
573 .cookie = cookie,
574 .verf = {verf[0], verf[1]},
575 .plus = plus,
576 .count = count,
577 .pages = &page
579 struct nfs3_readdirres res = {
580 .dir_attr = &dir_attr,
581 .verf = verf,
582 .plus = plus
584 struct rpc_message msg = {
585 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
586 .rpc_argp = &arg,
587 .rpc_resp = &res,
588 .rpc_cred = cred
590 int status;
592 lock_kernel();
594 if (plus)
595 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
597 dprintk("NFS call readdir%s %d\n",
598 plus? "plus" : "", (unsigned int) cookie);
600 dir_attr.valid = 0;
601 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
602 nfs_refresh_inode(dir, &dir_attr);
603 dprintk("NFS reply readdir: %d\n", status);
604 unlock_kernel();
605 return status;
608 static int
609 nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
610 dev_t rdev, struct nfs_fh *fh, struct nfs_fattr *fattr)
612 struct nfs_fattr dir_attr;
613 struct nfs3_mknodargs arg = {
614 .fh = NFS_FH(dir),
615 .name = name->name,
616 .len = name->len,
617 .sattr = sattr,
618 .rdev = rdev
620 struct nfs3_diropres res = {
621 .dir_attr = &dir_attr,
622 .fh = fh,
623 .fattr = fattr
625 int status;
627 switch (sattr->ia_mode & S_IFMT) {
628 case S_IFBLK: arg.type = NF3BLK; break;
629 case S_IFCHR: arg.type = NF3CHR; break;
630 case S_IFIFO: arg.type = NF3FIFO; break;
631 case S_IFSOCK: arg.type = NF3SOCK; break;
632 default: return -EINVAL;
635 dprintk("NFS call mknod %s %x\n", name->name, rdev);
636 dir_attr.valid = 0;
637 fattr->valid = 0;
638 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
639 nfs_refresh_inode(dir, &dir_attr);
640 dprintk("NFS reply mknod: %d\n", status);
641 return status;
644 static int
645 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
646 struct nfs_fsstat *stat)
648 int status;
650 dprintk("NFS call fsstat\n");
651 stat->fattr->valid = 0;
652 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
653 dprintk("NFS reply statfs: %d\n", status);
654 return status;
657 static int
658 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
659 struct nfs_fsinfo *info)
661 int status;
663 dprintk("NFS call fsinfo\n");
664 info->fattr->valid = 0;
665 status = rpc_call(server->client, NFS3PROC_FSINFO, fhandle, info, 0);
666 dprintk("NFS reply fsinfo: %d\n", status);
667 return status;
670 static int
671 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
672 struct nfs_pathconf *info)
674 int status;
676 dprintk("NFS call pathconf\n");
677 info->fattr->valid = 0;
678 status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
679 dprintk("NFS reply pathconf: %d\n", status);
680 return status;
683 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
685 static void
686 nfs3_read_done(struct rpc_task *task)
688 struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
690 if (nfs3_async_handle_jukebox(task))
691 return;
692 nfs_readpage_result(task, data->u.v3.res.count, data->u.v3.res.eof);
695 static void
696 nfs3_proc_read_setup(struct nfs_read_data *data, unsigned int count)
698 struct rpc_task *task = &data->task;
699 struct inode *inode = data->inode;
700 struct nfs_page *req;
701 int flags;
702 struct rpc_message msg = {
703 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
704 .rpc_argp = &data->u.v3.args,
705 .rpc_resp = &data->u.v3.res,
706 .rpc_cred = data->cred,
709 req = nfs_list_entry(data->pages.next);
710 data->u.v3.args.fh = NFS_FH(inode);
711 data->u.v3.args.offset = req_offset(req) + req->wb_offset;
712 data->u.v3.args.pgbase = req->wb_offset;
713 data->u.v3.args.pages = data->pagevec;
714 data->u.v3.args.count = count;
715 data->u.v3.res.fattr = &data->fattr;
716 data->u.v3.res.count = count;
717 data->u.v3.res.eof = 0;
719 /* N.B. Do we need to test? Never called for swapfile inode */
720 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
722 /* Finalize the task. */
723 rpc_init_task(task, NFS_CLIENT(inode), nfs3_read_done, flags);
724 task->tk_calldata = data;
725 /* Release requests */
726 task->tk_release = nfs_readdata_release;
728 rpc_call_setup(&data->task, &msg, 0);
731 static void
732 nfs3_write_done(struct rpc_task *task)
734 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
736 if (nfs3_async_handle_jukebox(task))
737 return;
738 nfs_writeback_done(task, data->u.v3.args.stable,
739 data->u.v3.args.count, data->u.v3.res.count);
742 static void
743 nfs3_proc_write_setup(struct nfs_write_data *data, unsigned int count, int how)
745 struct rpc_task *task = &data->task;
746 struct inode *inode = data->inode;
747 struct nfs_page *req;
748 int stable;
749 int flags;
750 struct rpc_message msg = {
751 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
752 .rpc_argp = &data->u.v3.args,
753 .rpc_resp = &data->u.v3.res,
754 .rpc_cred = data->cred,
757 if (how & FLUSH_STABLE) {
758 if (!NFS_I(inode)->ncommit)
759 stable = NFS_FILE_SYNC;
760 else
761 stable = NFS_DATA_SYNC;
762 } else
763 stable = NFS_UNSTABLE;
765 req = nfs_list_entry(data->pages.next);
766 data->u.v3.args.fh = NFS_FH(inode);
767 data->u.v3.args.offset = req_offset(req) + req->wb_offset;
768 data->u.v3.args.pgbase = req->wb_offset;
769 data->u.v3.args.count = count;
770 data->u.v3.args.stable = stable;
771 data->u.v3.args.pages = data->pagevec;
772 data->u.v3.res.fattr = &data->fattr;
773 data->u.v3.res.count = count;
774 data->u.v3.res.verf = &data->verf;
776 /* Set the initial flags for the task. */
777 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
779 /* Finalize the task. */
780 rpc_init_task(task, NFS_CLIENT(inode), nfs3_write_done, flags);
781 task->tk_calldata = data;
782 /* Release requests */
783 task->tk_release = nfs_writedata_release;
785 rpc_call_setup(&data->task, &msg, 0);
788 static void
789 nfs3_commit_done(struct rpc_task *task)
791 if (nfs3_async_handle_jukebox(task))
792 return;
793 nfs_commit_done(task);
796 static void
797 nfs3_proc_commit_setup(struct nfs_write_data *data, u64 start, u32 len, int how)
799 struct rpc_task *task = &data->task;
800 struct inode *inode = data->inode;
801 int flags;
802 struct rpc_message msg = {
803 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
804 .rpc_argp = &data->u.v3.args,
805 .rpc_resp = &data->u.v3.res,
806 .rpc_cred = data->cred,
809 data->u.v3.args.fh = NFS_FH(data->inode);
810 data->u.v3.args.offset = start;
811 data->u.v3.args.count = len;
812 data->u.v3.res.count = len;
813 data->u.v3.res.fattr = &data->fattr;
814 data->u.v3.res.verf = &data->verf;
816 /* Set the initial flags for the task. */
817 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
819 /* Finalize the task. */
820 rpc_init_task(task, NFS_CLIENT(inode), nfs3_commit_done, flags);
821 task->tk_calldata = data;
822 /* Release requests */
823 task->tk_release = nfs_commit_release;
825 rpc_call_setup(&data->task, &msg, 0);
828 struct nfs_rpc_ops nfs_v3_clientops = {
829 .version = 3, /* protocol version */
830 .getroot = nfs3_proc_get_root,
831 .getattr = nfs3_proc_getattr,
832 .setattr = nfs3_proc_setattr,
833 .lookup = nfs3_proc_lookup,
834 .access = nfs3_proc_access,
835 .readlink = nfs3_proc_readlink,
836 .read = nfs3_proc_read,
837 .write = nfs3_proc_write,
838 .create = nfs3_proc_create,
839 .remove = nfs3_proc_remove,
840 .unlink_setup = nfs3_proc_unlink_setup,
841 .unlink_done = nfs3_proc_unlink_done,
842 .rename = nfs3_proc_rename,
843 .link = nfs3_proc_link,
844 .symlink = nfs3_proc_symlink,
845 .mkdir = nfs3_proc_mkdir,
846 .rmdir = nfs3_proc_rmdir,
847 .readdir = nfs3_proc_readdir,
848 .mknod = nfs3_proc_mknod,
849 .statfs = nfs3_proc_statfs,
850 .fsinfo = nfs3_proc_fsinfo,
851 .pathconf = nfs3_proc_pathconf,
852 .decode_dirent = nfs3_decode_dirent,
853 .read_setup = nfs3_proc_read_setup,
854 .write_setup = nfs3_proc_write_setup,
855 .commit_setup = nfs3_proc_commit_setup,