Linux-2.6.12-rc2
[GitHub/mt8127/android_kernel_alcatel_ttab.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
21 #define NFSDBG_FACILITY NFSDBG_PROC
22
23 extern struct rpc_procinfo nfs3_procedures[];
24
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)
28 {
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;
42 }
43
44 static inline int
45 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
46 {
47 struct rpc_message msg = {
48 .rpc_proc = &nfs3_procedures[proc],
49 .rpc_argp = argp,
50 .rpc_resp = resp,
51 };
52 return nfs3_rpc_wrapper(clnt, &msg, flags);
53 }
54
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)
59
60 static int
61 nfs3_async_handle_jukebox(struct rpc_task *task)
62 {
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;
69 }
70
71 /*
72 * Bare-bones access to getattr: this is for nfs_read_super.
73 */
74 static int
75 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
76 struct nfs_fsinfo *info)
77 {
78 int status;
79
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);
87 }
88 return status;
89 }
90
91 /*
92 * One function for each procedure in the NFS protocol.
93 */
94 static int
95 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
96 struct nfs_fattr *fattr)
97 {
98 int status;
99
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: %d\n", status);
105 return status;
106 }
107
108 static int
109 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
110 struct iattr *sattr)
111 {
112 struct inode *inode = dentry->d_inode;
113 struct nfs3_sattrargs arg = {
114 .fh = NFS_FH(inode),
115 .sattr = sattr,
116 };
117 int status;
118
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: %d\n", status);
123 return status;
124 }
125
126 static int
127 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
128 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
129 {
130 struct nfs_fattr dir_attr;
131 struct nfs3_diropargs arg = {
132 .fh = NFS_FH(dir),
133 .name = name->name,
134 .len = name->len
135 };
136 struct nfs3_diropres res = {
137 .dir_attr = &dir_attr,
138 .fh = fhandle,
139 .fattr = fattr
140 };
141 int status;
142
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;
154 }
155
156 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
157 {
158 struct nfs_fattr fattr;
159 struct nfs3_accessargs arg = {
160 .fh = NFS_FH(inode),
161 };
162 struct nfs3_accessres res = {
163 .fattr = &fattr,
164 };
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
170 };
171 int mode = entry->mask;
172 int status;
173
174 dprintk("NFS call access\n");
175 fattr.valid = 0;
176
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;
189 }
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;
200 }
201 dprintk("NFS reply access: %d\n", status);
202 return status;
203 }
204
205 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
206 unsigned int pgbase, unsigned int pglen)
207 {
208 struct nfs_fattr fattr;
209 struct nfs3_readlinkargs args = {
210 .fh = NFS_FH(inode),
211 .pgbase = pgbase,
212 .pglen = pglen,
213 .pages = &page
214 };
215 int status;
216
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;
224 }
225
226 static int nfs3_proc_read(struct nfs_read_data *rdata)
227 {
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,
236 };
237 int status;
238
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;
247 }
248
249 static int nfs3_proc_write(struct nfs_write_data *wdata)
250 {
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,
259 };
260 int status;
261
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;
270 }
271
272 static int nfs3_proc_commit(struct nfs_write_data *cdata)
273 {
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,
281 };
282 int status;
283
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;
292 }
293
294 /*
295 * Create a regular file.
296 * For now, we don't implement O_EXCL.
297 */
298 static int
299 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
300 int flags)
301 {
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 = dentry->d_name.name,
308 .len = dentry->d_name.len,
309 .sattr = sattr,
310 };
311 struct nfs3_diropres res = {
312 .dir_attr = &dir_attr,
313 .fh = &fhandle,
314 .fattr = &fattr
315 };
316 int status;
317
318 dprintk("NFS call create %s\n", dentry->d_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;
324 }
325
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);
331
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;
339
340 case NFS3_CREATE_GUARDED:
341 arg.createmode = NFS3_CREATE_UNCHECKED;
342 break;
343
344 case NFS3_CREATE_UNCHECKED:
345 goto out;
346 }
347 goto again;
348 }
349
350 if (status == 0)
351 status = nfs_instantiate(dentry, &fhandle, &fattr);
352 if (status != 0)
353 goto out;
354
355 /* When we created the file with exclusive semantics, make
356 * sure we set the attributes afterwards. */
357 if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
358 dprintk("NFS call setattr (post-create)\n");
359
360 if (!(sattr->ia_valid & ATTR_ATIME_SET))
361 sattr->ia_valid |= ATTR_ATIME;
362 if (!(sattr->ia_valid & ATTR_MTIME_SET))
363 sattr->ia_valid |= ATTR_MTIME;
364
365 /* Note: we could use a guarded setattr here, but I'm
366 * not sure this buys us anything (and I'd have
367 * to revamp the NFSv3 XDR code) */
368 status = nfs3_proc_setattr(dentry, &fattr, sattr);
369 nfs_refresh_inode(dentry->d_inode, &fattr);
370 dprintk("NFS reply setattr (post-create): %d\n", status);
371 }
372 out:
373 dprintk("NFS reply create: %d\n", status);
374 return status;
375 }
376
377 static int
378 nfs3_proc_remove(struct inode *dir, struct qstr *name)
379 {
380 struct nfs_fattr dir_attr;
381 struct nfs3_diropargs arg = {
382 .fh = NFS_FH(dir),
383 .name = name->name,
384 .len = name->len
385 };
386 struct rpc_message msg = {
387 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
388 .rpc_argp = &arg,
389 .rpc_resp = &dir_attr,
390 };
391 int status;
392
393 dprintk("NFS call remove %s\n", name->name);
394 dir_attr.valid = 0;
395 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
396 nfs_refresh_inode(dir, &dir_attr);
397 dprintk("NFS reply remove: %d\n", status);
398 return status;
399 }
400
401 static int
402 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
403 {
404 struct unlinkxdr {
405 struct nfs3_diropargs arg;
406 struct nfs_fattr res;
407 } *ptr;
408
409 ptr = (struct unlinkxdr *)kmalloc(sizeof(*ptr), GFP_KERNEL);
410 if (!ptr)
411 return -ENOMEM;
412 ptr->arg.fh = NFS_FH(dir->d_inode);
413 ptr->arg.name = name->name;
414 ptr->arg.len = name->len;
415 ptr->res.valid = 0;
416 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
417 msg->rpc_argp = &ptr->arg;
418 msg->rpc_resp = &ptr->res;
419 return 0;
420 }
421
422 static int
423 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
424 {
425 struct rpc_message *msg = &task->tk_msg;
426 struct nfs_fattr *dir_attr;
427
428 if (nfs3_async_handle_jukebox(task))
429 return 1;
430 if (msg->rpc_argp) {
431 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
432 nfs_refresh_inode(dir->d_inode, dir_attr);
433 kfree(msg->rpc_argp);
434 }
435 return 0;
436 }
437
438 static int
439 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
440 struct inode *new_dir, struct qstr *new_name)
441 {
442 struct nfs_fattr old_dir_attr, new_dir_attr;
443 struct nfs3_renameargs arg = {
444 .fromfh = NFS_FH(old_dir),
445 .fromname = old_name->name,
446 .fromlen = old_name->len,
447 .tofh = NFS_FH(new_dir),
448 .toname = new_name->name,
449 .tolen = new_name->len
450 };
451 struct nfs3_renameres res = {
452 .fromattr = &old_dir_attr,
453 .toattr = &new_dir_attr
454 };
455 int status;
456
457 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
458 old_dir_attr.valid = 0;
459 new_dir_attr.valid = 0;
460 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
461 nfs_refresh_inode(old_dir, &old_dir_attr);
462 nfs_refresh_inode(new_dir, &new_dir_attr);
463 dprintk("NFS reply rename: %d\n", status);
464 return status;
465 }
466
467 static int
468 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
469 {
470 struct nfs_fattr dir_attr, fattr;
471 struct nfs3_linkargs arg = {
472 .fromfh = NFS_FH(inode),
473 .tofh = NFS_FH(dir),
474 .toname = name->name,
475 .tolen = name->len
476 };
477 struct nfs3_linkres res = {
478 .dir_attr = &dir_attr,
479 .fattr = &fattr
480 };
481 int status;
482
483 dprintk("NFS call link %s\n", name->name);
484 dir_attr.valid = 0;
485 fattr.valid = 0;
486 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
487 nfs_refresh_inode(dir, &dir_attr);
488 nfs_refresh_inode(inode, &fattr);
489 dprintk("NFS reply link: %d\n", status);
490 return status;
491 }
492
493 static int
494 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
495 struct iattr *sattr, struct nfs_fh *fhandle,
496 struct nfs_fattr *fattr)
497 {
498 struct nfs_fattr dir_attr;
499 struct nfs3_symlinkargs arg = {
500 .fromfh = NFS_FH(dir),
501 .fromname = name->name,
502 .fromlen = name->len,
503 .topath = path->name,
504 .tolen = path->len,
505 .sattr = sattr
506 };
507 struct nfs3_diropres res = {
508 .dir_attr = &dir_attr,
509 .fh = fhandle,
510 .fattr = fattr
511 };
512 int status;
513
514 if (path->len > NFS3_MAXPATHLEN)
515 return -ENAMETOOLONG;
516 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
517 dir_attr.valid = 0;
518 fattr->valid = 0;
519 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
520 nfs_refresh_inode(dir, &dir_attr);
521 dprintk("NFS reply symlink: %d\n", status);
522 return status;
523 }
524
525 static int
526 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
527 {
528 struct nfs_fh fhandle;
529 struct nfs_fattr fattr, dir_attr;
530 struct nfs3_mkdirargs arg = {
531 .fh = NFS_FH(dir),
532 .name = dentry->d_name.name,
533 .len = dentry->d_name.len,
534 .sattr = sattr
535 };
536 struct nfs3_diropres res = {
537 .dir_attr = &dir_attr,
538 .fh = &fhandle,
539 .fattr = &fattr
540 };
541 int status;
542
543 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
544 dir_attr.valid = 0;
545 fattr.valid = 0;
546 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
547 nfs_refresh_inode(dir, &dir_attr);
548 if (status == 0)
549 status = nfs_instantiate(dentry, &fhandle, &fattr);
550 dprintk("NFS reply mkdir: %d\n", status);
551 return status;
552 }
553
554 static int
555 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
556 {
557 struct nfs_fattr dir_attr;
558 struct nfs3_diropargs arg = {
559 .fh = NFS_FH(dir),
560 .name = name->name,
561 .len = name->len
562 };
563 int status;
564
565 dprintk("NFS call rmdir %s\n", name->name);
566 dir_attr.valid = 0;
567 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
568 nfs_refresh_inode(dir, &dir_attr);
569 dprintk("NFS reply rmdir: %d\n", status);
570 return status;
571 }
572
573 /*
574 * The READDIR implementation is somewhat hackish - we pass the user buffer
575 * to the encode function, which installs it in the receive iovec.
576 * The decode function itself doesn't perform any decoding, it just makes
577 * sure the reply is syntactically correct.
578 *
579 * Also note that this implementation handles both plain readdir and
580 * readdirplus.
581 */
582 static int
583 nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
584 u64 cookie, struct page *page, unsigned int count, int plus)
585 {
586 struct inode *dir = dentry->d_inode;
587 struct nfs_fattr dir_attr;
588 u32 *verf = NFS_COOKIEVERF(dir);
589 struct nfs3_readdirargs arg = {
590 .fh = NFS_FH(dir),
591 .cookie = cookie,
592 .verf = {verf[0], verf[1]},
593 .plus = plus,
594 .count = count,
595 .pages = &page
596 };
597 struct nfs3_readdirres res = {
598 .dir_attr = &dir_attr,
599 .verf = verf,
600 .plus = plus
601 };
602 struct rpc_message msg = {
603 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
604 .rpc_argp = &arg,
605 .rpc_resp = &res,
606 .rpc_cred = cred
607 };
608 int status;
609
610 lock_kernel();
611
612 if (plus)
613 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
614
615 dprintk("NFS call readdir%s %d\n",
616 plus? "plus" : "", (unsigned int) cookie);
617
618 dir_attr.valid = 0;
619 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
620 nfs_refresh_inode(dir, &dir_attr);
621 dprintk("NFS reply readdir: %d\n", status);
622 unlock_kernel();
623 return status;
624 }
625
626 static int
627 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
628 dev_t rdev)
629 {
630 struct nfs_fh fh;
631 struct nfs_fattr fattr, dir_attr;
632 struct nfs3_mknodargs arg = {
633 .fh = NFS_FH(dir),
634 .name = dentry->d_name.name,
635 .len = dentry->d_name.len,
636 .sattr = sattr,
637 .rdev = rdev
638 };
639 struct nfs3_diropres res = {
640 .dir_attr = &dir_attr,
641 .fh = &fh,
642 .fattr = &fattr
643 };
644 int status;
645
646 switch (sattr->ia_mode & S_IFMT) {
647 case S_IFBLK: arg.type = NF3BLK; break;
648 case S_IFCHR: arg.type = NF3CHR; break;
649 case S_IFIFO: arg.type = NF3FIFO; break;
650 case S_IFSOCK: arg.type = NF3SOCK; break;
651 default: return -EINVAL;
652 }
653
654 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
655 MAJOR(rdev), MINOR(rdev));
656 dir_attr.valid = 0;
657 fattr.valid = 0;
658 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
659 nfs_refresh_inode(dir, &dir_attr);
660 if (status == 0)
661 status = nfs_instantiate(dentry, &fh, &fattr);
662 dprintk("NFS reply mknod: %d\n", status);
663 return status;
664 }
665
666 static int
667 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
668 struct nfs_fsstat *stat)
669 {
670 int status;
671
672 dprintk("NFS call fsstat\n");
673 stat->fattr->valid = 0;
674 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
675 dprintk("NFS reply statfs: %d\n", status);
676 return status;
677 }
678
679 static int
680 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
681 struct nfs_fsinfo *info)
682 {
683 int status;
684
685 dprintk("NFS call fsinfo\n");
686 info->fattr->valid = 0;
687 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
688 dprintk("NFS reply fsinfo: %d\n", status);
689 return status;
690 }
691
692 static int
693 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
694 struct nfs_pathconf *info)
695 {
696 int status;
697
698 dprintk("NFS call pathconf\n");
699 info->fattr->valid = 0;
700 status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
701 dprintk("NFS reply pathconf: %d\n", status);
702 return status;
703 }
704
705 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
706
707 static void
708 nfs3_read_done(struct rpc_task *task)
709 {
710 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
711
712 if (nfs3_async_handle_jukebox(task))
713 return;
714 /* Call back common NFS readpage processing */
715 if (task->tk_status >= 0)
716 nfs_refresh_inode(data->inode, &data->fattr);
717 nfs_readpage_result(task);
718 }
719
720 static void
721 nfs3_proc_read_setup(struct nfs_read_data *data)
722 {
723 struct rpc_task *task = &data->task;
724 struct inode *inode = data->inode;
725 int flags;
726 struct rpc_message msg = {
727 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
728 .rpc_argp = &data->args,
729 .rpc_resp = &data->res,
730 .rpc_cred = data->cred,
731 };
732
733 /* N.B. Do we need to test? Never called for swapfile inode */
734 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
735
736 /* Finalize the task. */
737 rpc_init_task(task, NFS_CLIENT(inode), nfs3_read_done, flags);
738 rpc_call_setup(task, &msg, 0);
739 }
740
741 static void
742 nfs3_write_done(struct rpc_task *task)
743 {
744 struct nfs_write_data *data;
745
746 if (nfs3_async_handle_jukebox(task))
747 return;
748 data = (struct nfs_write_data *)task->tk_calldata;
749 if (task->tk_status >= 0)
750 nfs_refresh_inode(data->inode, data->res.fattr);
751 nfs_writeback_done(task);
752 }
753
754 static void
755 nfs3_proc_write_setup(struct nfs_write_data *data, int how)
756 {
757 struct rpc_task *task = &data->task;
758 struct inode *inode = data->inode;
759 int stable;
760 int flags;
761 struct rpc_message msg = {
762 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
763 .rpc_argp = &data->args,
764 .rpc_resp = &data->res,
765 .rpc_cred = data->cred,
766 };
767
768 if (how & FLUSH_STABLE) {
769 if (!NFS_I(inode)->ncommit)
770 stable = NFS_FILE_SYNC;
771 else
772 stable = NFS_DATA_SYNC;
773 } else
774 stable = NFS_UNSTABLE;
775 data->args.stable = stable;
776
777 /* Set the initial flags for the task. */
778 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
779
780 /* Finalize the task. */
781 rpc_init_task(task, NFS_CLIENT(inode), nfs3_write_done, flags);
782 rpc_call_setup(task, &msg, 0);
783 }
784
785 static void
786 nfs3_commit_done(struct rpc_task *task)
787 {
788 struct nfs_write_data *data;
789
790 if (nfs3_async_handle_jukebox(task))
791 return;
792 data = (struct nfs_write_data *)task->tk_calldata;
793 if (task->tk_status >= 0)
794 nfs_refresh_inode(data->inode, data->res.fattr);
795 nfs_commit_done(task);
796 }
797
798 static void
799 nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
800 {
801 struct rpc_task *task = &data->task;
802 struct inode *inode = data->inode;
803 int flags;
804 struct rpc_message msg = {
805 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
806 .rpc_argp = &data->args,
807 .rpc_resp = &data->res,
808 .rpc_cred = data->cred,
809 };
810
811 /* Set the initial flags for the task. */
812 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
813
814 /* Finalize the task. */
815 rpc_init_task(task, NFS_CLIENT(inode), nfs3_commit_done, flags);
816 rpc_call_setup(task, &msg, 0);
817 }
818
819 static int
820 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
821 {
822 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
823 }
824
825 struct nfs_rpc_ops nfs_v3_clientops = {
826 .version = 3, /* protocol version */
827 .dentry_ops = &nfs_dentry_operations,
828 .dir_inode_ops = &nfs_dir_inode_operations,
829 .getroot = nfs3_proc_get_root,
830 .getattr = nfs3_proc_getattr,
831 .setattr = nfs3_proc_setattr,
832 .lookup = nfs3_proc_lookup,
833 .access = nfs3_proc_access,
834 .readlink = nfs3_proc_readlink,
835 .read = nfs3_proc_read,
836 .write = nfs3_proc_write,
837 .commit = nfs3_proc_commit,
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,
856 .file_open = nfs_open,
857 .file_release = nfs_release,
858 .lock = nfs3_proc_lock,
859 };