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