]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - fs/nfs/nfs3proc.c
NLM: fix parsing of sm notify procedure
[mirror_ubuntu-zesty-kernel.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>
19#include <linux/smp_lock.h>
b7fa0554 20#include <linux/nfs_mount.h>
1da177e4
LT
21
22#define NFSDBG_FACILITY NFSDBG_PROC
23
24extern struct rpc_procinfo nfs3_procedures[];
25
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
44static inline int
45nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
46{
47 struct rpc_message msg = {
b7fa0554 48 .rpc_proc = &clnt->cl_procinfo[proc],
1da177e4
LT
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
60static int
61nfs3_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 */
74static int
75nfs3_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__);
0e574af1 81 nfs_fattr_init(info->fattr);
1da177e4
LT
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 */
94static int
95nfs3_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");
0e574af1 101 nfs_fattr_init(fattr);
1da177e4
LT
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
108static int
109nfs3_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");
0e574af1 120 nfs_fattr_init(fattr);
1da177e4 121 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
65e4308d
TM
122 if (status == 0)
123 nfs_setattr_update_inode(inode, sattr);
1da177e4
LT
124 dprintk("NFS reply setattr: %d\n", status);
125 return status;
126}
127
128static int
129nfs3_proc_lookup(struct inode *dir, struct qstr *name,
130 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
131{
132 struct nfs_fattr dir_attr;
133 struct nfs3_diropargs arg = {
134 .fh = NFS_FH(dir),
135 .name = name->name,
136 .len = name->len
137 };
138 struct nfs3_diropres res = {
139 .dir_attr = &dir_attr,
140 .fh = fhandle,
141 .fattr = fattr
142 };
143 int status;
144
145 dprintk("NFS call lookup %s\n", name->name);
0e574af1
TM
146 nfs_fattr_init(&dir_attr);
147 nfs_fattr_init(fattr);
1da177e4
LT
148 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
149 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
150 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
151 fhandle, fattr, 0);
152 dprintk("NFS reply lookup: %d\n", status);
153 if (status >= 0)
154 status = nfs_refresh_inode(dir, &dir_attr);
155 return status;
156}
157
158static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
159{
160 struct nfs_fattr fattr;
161 struct nfs3_accessargs arg = {
162 .fh = NFS_FH(inode),
163 };
164 struct nfs3_accessres res = {
165 .fattr = &fattr,
166 };
167 struct rpc_message msg = {
168 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
169 .rpc_argp = &arg,
170 .rpc_resp = &res,
171 .rpc_cred = entry->cred
172 };
173 int mode = entry->mask;
174 int status;
175
176 dprintk("NFS call access\n");
1da177e4
LT
177
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;
190 }
0e574af1 191 nfs_fattr_init(&fattr);
1da177e4
LT
192 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
193 nfs_refresh_inode(inode, &fattr);
194 if (status == 0) {
195 entry->mask = 0;
196 if (res.access & NFS3_ACCESS_READ)
197 entry->mask |= MAY_READ;
198 if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE))
199 entry->mask |= MAY_WRITE;
200 if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
201 entry->mask |= MAY_EXEC;
202 }
203 dprintk("NFS reply access: %d\n", status);
204 return status;
205}
206
207static int nfs3_proc_readlink(struct inode *inode, struct page *page,
208 unsigned int pgbase, unsigned int pglen)
209{
210 struct nfs_fattr fattr;
211 struct nfs3_readlinkargs args = {
212 .fh = NFS_FH(inode),
213 .pgbase = pgbase,
214 .pglen = pglen,
215 .pages = &page
216 };
217 int status;
218
219 dprintk("NFS call readlink\n");
0e574af1 220 nfs_fattr_init(&fattr);
1da177e4
LT
221 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
222 &args, &fattr, 0);
223 nfs_refresh_inode(inode, &fattr);
224 dprintk("NFS reply readlink: %d\n", status);
225 return status;
226}
227
228static int nfs3_proc_read(struct nfs_read_data *rdata)
229{
230 int flags = rdata->flags;
231 struct inode * inode = rdata->inode;
232 struct nfs_fattr * fattr = rdata->res.fattr;
233 struct rpc_message msg = {
234 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
235 .rpc_argp = &rdata->args,
236 .rpc_resp = &rdata->res,
237 .rpc_cred = rdata->cred,
238 };
239 int status;
240
241 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
242 (long long) rdata->args.offset);
0e574af1 243 nfs_fattr_init(fattr);
1da177e4
LT
244 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
245 if (status >= 0)
246 nfs_refresh_inode(inode, fattr);
247 dprintk("NFS reply read: %d\n", status);
248 return status;
249}
250
251static int nfs3_proc_write(struct nfs_write_data *wdata)
252{
253 int rpcflags = wdata->flags;
254 struct inode * inode = wdata->inode;
255 struct nfs_fattr * fattr = wdata->res.fattr;
256 struct rpc_message msg = {
257 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
258 .rpc_argp = &wdata->args,
259 .rpc_resp = &wdata->res,
260 .rpc_cred = wdata->cred,
261 };
262 int status;
263
264 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
265 (long long) wdata->args.offset);
0e574af1 266 nfs_fattr_init(fattr);
1da177e4
LT
267 status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
268 if (status >= 0)
decf491f 269 nfs_post_op_update_inode(inode, fattr);
1da177e4
LT
270 dprintk("NFS reply write: %d\n", status);
271 return status < 0? status : wdata->res.count;
272}
273
274static int nfs3_proc_commit(struct nfs_write_data *cdata)
275{
276 struct inode * inode = cdata->inode;
277 struct nfs_fattr * fattr = cdata->res.fattr;
278 struct rpc_message msg = {
279 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
280 .rpc_argp = &cdata->args,
281 .rpc_resp = &cdata->res,
282 .rpc_cred = cdata->cred,
283 };
284 int status;
285
286 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
287 (long long) cdata->args.offset);
0e574af1 288 nfs_fattr_init(fattr);
1da177e4
LT
289 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
290 if (status >= 0)
decf491f 291 nfs_post_op_update_inode(inode, fattr);
1da177e4
LT
292 dprintk("NFS reply commit: %d\n", status);
293 return status;
294}
295
296/*
297 * Create a regular file.
298 * For now, we don't implement O_EXCL.
299 */
300static int
301nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
02a913a7 302 int flags, struct nameidata *nd)
1da177e4
LT
303{
304 struct nfs_fh fhandle;
305 struct nfs_fattr fattr;
306 struct nfs_fattr dir_attr;
307 struct nfs3_createargs arg = {
308 .fh = NFS_FH(dir),
309 .name = dentry->d_name.name,
310 .len = dentry->d_name.len,
311 .sattr = sattr,
312 };
313 struct nfs3_diropres res = {
314 .dir_attr = &dir_attr,
315 .fh = &fhandle,
316 .fattr = &fattr
317 };
055ffbea
AG
318 mode_t mode = sattr->ia_mode;
319 int status;
1da177e4
LT
320
321 dprintk("NFS call create %s\n", dentry->d_name.name);
322 arg.createmode = NFS3_CREATE_UNCHECKED;
323 if (flags & O_EXCL) {
324 arg.createmode = NFS3_CREATE_EXCLUSIVE;
325 arg.verifier[0] = jiffies;
326 arg.verifier[1] = current->pid;
327 }
328
055ffbea
AG
329 sattr->ia_mode &= ~current->fs->umask;
330
1da177e4 331again:
0e574af1
TM
332 nfs_fattr_init(&dir_attr);
333 nfs_fattr_init(&fattr);
1da177e4 334 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
decf491f 335 nfs_post_op_update_inode(dir, &dir_attr);
1da177e4
LT
336
337 /* If the server doesn't support the exclusive creation semantics,
338 * try again with simple 'guarded' mode. */
339 if (status == NFSERR_NOTSUPP) {
340 switch (arg.createmode) {
341 case NFS3_CREATE_EXCLUSIVE:
342 arg.createmode = NFS3_CREATE_GUARDED;
343 break;
344
345 case NFS3_CREATE_GUARDED:
346 arg.createmode = NFS3_CREATE_UNCHECKED;
347 break;
348
349 case NFS3_CREATE_UNCHECKED:
350 goto out;
351 }
352 goto again;
353 }
354
355 if (status == 0)
356 status = nfs_instantiate(dentry, &fhandle, &fattr);
357 if (status != 0)
358 goto out;
359
360 /* When we created the file with exclusive semantics, make
361 * sure we set the attributes afterwards. */
362 if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
363 dprintk("NFS call setattr (post-create)\n");
364
365 if (!(sattr->ia_valid & ATTR_ATIME_SET))
366 sattr->ia_valid |= ATTR_ATIME;
367 if (!(sattr->ia_valid & ATTR_MTIME_SET))
368 sattr->ia_valid |= ATTR_MTIME;
369
370 /* Note: we could use a guarded setattr here, but I'm
371 * not sure this buys us anything (and I'd have
372 * to revamp the NFSv3 XDR code) */
373 status = nfs3_proc_setattr(dentry, &fattr, sattr);
65e4308d
TM
374 if (status == 0)
375 nfs_setattr_update_inode(dentry->d_inode, sattr);
1da177e4
LT
376 nfs_refresh_inode(dentry->d_inode, &fattr);
377 dprintk("NFS reply setattr (post-create): %d\n", status);
378 }
055ffbea
AG
379 if (status != 0)
380 goto out;
381 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
1da177e4
LT
382out:
383 dprintk("NFS reply create: %d\n", status);
384 return status;
385}
386
387static int
388nfs3_proc_remove(struct inode *dir, struct qstr *name)
389{
390 struct nfs_fattr dir_attr;
391 struct nfs3_diropargs arg = {
392 .fh = NFS_FH(dir),
393 .name = name->name,
394 .len = name->len
395 };
396 struct rpc_message msg = {
397 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
398 .rpc_argp = &arg,
399 .rpc_resp = &dir_attr,
400 };
401 int status;
402
403 dprintk("NFS call remove %s\n", name->name);
0e574af1 404 nfs_fattr_init(&dir_attr);
1da177e4 405 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
decf491f 406 nfs_post_op_update_inode(dir, &dir_attr);
1da177e4
LT
407 dprintk("NFS reply remove: %d\n", status);
408 return status;
409}
410
411static int
412nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
413{
414 struct unlinkxdr {
415 struct nfs3_diropargs arg;
416 struct nfs_fattr res;
417 } *ptr;
418
419 ptr = (struct unlinkxdr *)kmalloc(sizeof(*ptr), GFP_KERNEL);
420 if (!ptr)
421 return -ENOMEM;
422 ptr->arg.fh = NFS_FH(dir->d_inode);
423 ptr->arg.name = name->name;
424 ptr->arg.len = name->len;
0e574af1 425 nfs_fattr_init(&ptr->res);
1da177e4
LT
426 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
427 msg->rpc_argp = &ptr->arg;
428 msg->rpc_resp = &ptr->res;
429 return 0;
430}
431
432static int
433nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
434{
435 struct rpc_message *msg = &task->tk_msg;
436 struct nfs_fattr *dir_attr;
437
438 if (nfs3_async_handle_jukebox(task))
439 return 1;
440 if (msg->rpc_argp) {
441 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
decf491f 442 nfs_post_op_update_inode(dir->d_inode, dir_attr);
1da177e4
LT
443 kfree(msg->rpc_argp);
444 }
445 return 0;
446}
447
448static int
449nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
450 struct inode *new_dir, struct qstr *new_name)
451{
452 struct nfs_fattr old_dir_attr, new_dir_attr;
453 struct nfs3_renameargs arg = {
454 .fromfh = NFS_FH(old_dir),
455 .fromname = old_name->name,
456 .fromlen = old_name->len,
457 .tofh = NFS_FH(new_dir),
458 .toname = new_name->name,
459 .tolen = new_name->len
460 };
461 struct nfs3_renameres res = {
462 .fromattr = &old_dir_attr,
463 .toattr = &new_dir_attr
464 };
465 int status;
466
467 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
0e574af1
TM
468 nfs_fattr_init(&old_dir_attr);
469 nfs_fattr_init(&new_dir_attr);
1da177e4 470 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
decf491f
TM
471 nfs_post_op_update_inode(old_dir, &old_dir_attr);
472 nfs_post_op_update_inode(new_dir, &new_dir_attr);
1da177e4
LT
473 dprintk("NFS reply rename: %d\n", status);
474 return status;
475}
476
477static int
478nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
479{
480 struct nfs_fattr dir_attr, fattr;
481 struct nfs3_linkargs arg = {
482 .fromfh = NFS_FH(inode),
483 .tofh = NFS_FH(dir),
484 .toname = name->name,
485 .tolen = name->len
486 };
487 struct nfs3_linkres res = {
488 .dir_attr = &dir_attr,
489 .fattr = &fattr
490 };
491 int status;
492
493 dprintk("NFS call link %s\n", name->name);
0e574af1
TM
494 nfs_fattr_init(&dir_attr);
495 nfs_fattr_init(&fattr);
1da177e4 496 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
decf491f
TM
497 nfs_post_op_update_inode(dir, &dir_attr);
498 nfs_post_op_update_inode(inode, &fattr);
1da177e4
LT
499 dprintk("NFS reply link: %d\n", status);
500 return status;
501}
502
503static int
504nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
505 struct iattr *sattr, struct nfs_fh *fhandle,
506 struct nfs_fattr *fattr)
507{
508 struct nfs_fattr dir_attr;
509 struct nfs3_symlinkargs arg = {
510 .fromfh = NFS_FH(dir),
511 .fromname = name->name,
512 .fromlen = name->len,
513 .topath = path->name,
514 .tolen = path->len,
515 .sattr = sattr
516 };
517 struct nfs3_diropres res = {
518 .dir_attr = &dir_attr,
519 .fh = fhandle,
520 .fattr = fattr
521 };
522 int status;
523
524 if (path->len > NFS3_MAXPATHLEN)
525 return -ENAMETOOLONG;
526 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
0e574af1
TM
527 nfs_fattr_init(&dir_attr);
528 nfs_fattr_init(fattr);
1da177e4 529 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
decf491f 530 nfs_post_op_update_inode(dir, &dir_attr);
1da177e4
LT
531 dprintk("NFS reply symlink: %d\n", status);
532 return status;
533}
534
535static int
536nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
537{
538 struct nfs_fh fhandle;
539 struct nfs_fattr fattr, dir_attr;
540 struct nfs3_mkdirargs arg = {
541 .fh = NFS_FH(dir),
542 .name = dentry->d_name.name,
543 .len = dentry->d_name.len,
544 .sattr = sattr
545 };
546 struct nfs3_diropres res = {
547 .dir_attr = &dir_attr,
548 .fh = &fhandle,
549 .fattr = &fattr
550 };
055ffbea
AG
551 int mode = sattr->ia_mode;
552 int status;
1da177e4
LT
553
554 dprintk("NFS call mkdir %s\n", dentry->d_name.name);
055ffbea
AG
555
556 sattr->ia_mode &= ~current->fs->umask;
557
0e574af1
TM
558 nfs_fattr_init(&dir_attr);
559 nfs_fattr_init(&fattr);
1da177e4 560 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
decf491f 561 nfs_post_op_update_inode(dir, &dir_attr);
055ffbea
AG
562 if (status != 0)
563 goto out;
564 status = nfs_instantiate(dentry, &fhandle, &fattr);
565 if (status != 0)
566 goto out;
567 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
568out:
1da177e4
LT
569 dprintk("NFS reply mkdir: %d\n", status);
570 return status;
571}
572
573static int
574nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
575{
576 struct nfs_fattr dir_attr;
577 struct nfs3_diropargs arg = {
578 .fh = NFS_FH(dir),
579 .name = name->name,
580 .len = name->len
581 };
582 int status;
583
584 dprintk("NFS call rmdir %s\n", name->name);
0e574af1 585 nfs_fattr_init(&dir_attr);
1da177e4 586 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
decf491f 587 nfs_post_op_update_inode(dir, &dir_attr);
1da177e4
LT
588 dprintk("NFS reply rmdir: %d\n", status);
589 return status;
590}
591
592/*
593 * The READDIR implementation is somewhat hackish - we pass the user buffer
594 * to the encode function, which installs it in the receive iovec.
595 * The decode function itself doesn't perform any decoding, it just makes
596 * sure the reply is syntactically correct.
597 *
598 * Also note that this implementation handles both plain readdir and
599 * readdirplus.
600 */
601static int
602nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
603 u64 cookie, struct page *page, unsigned int count, int plus)
604{
605 struct inode *dir = dentry->d_inode;
606 struct nfs_fattr dir_attr;
607 u32 *verf = NFS_COOKIEVERF(dir);
608 struct nfs3_readdirargs arg = {
609 .fh = NFS_FH(dir),
610 .cookie = cookie,
611 .verf = {verf[0], verf[1]},
612 .plus = plus,
613 .count = count,
614 .pages = &page
615 };
616 struct nfs3_readdirres res = {
617 .dir_attr = &dir_attr,
618 .verf = verf,
619 .plus = plus
620 };
621 struct rpc_message msg = {
622 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
623 .rpc_argp = &arg,
624 .rpc_resp = &res,
625 .rpc_cred = cred
626 };
627 int status;
628
629 lock_kernel();
630
631 if (plus)
632 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
633
634 dprintk("NFS call readdir%s %d\n",
635 plus? "plus" : "", (unsigned int) cookie);
636
0e574af1 637 nfs_fattr_init(&dir_attr);
1da177e4
LT
638 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
639 nfs_refresh_inode(dir, &dir_attr);
640 dprintk("NFS reply readdir: %d\n", status);
641 unlock_kernel();
642 return status;
643}
644
645static int
646nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
647 dev_t rdev)
648{
649 struct nfs_fh fh;
650 struct nfs_fattr fattr, dir_attr;
651 struct nfs3_mknodargs arg = {
652 .fh = NFS_FH(dir),
653 .name = dentry->d_name.name,
654 .len = dentry->d_name.len,
655 .sattr = sattr,
656 .rdev = rdev
657 };
658 struct nfs3_diropres res = {
659 .dir_attr = &dir_attr,
660 .fh = &fh,
661 .fattr = &fattr
662 };
055ffbea 663 mode_t mode = sattr->ia_mode;
1da177e4
LT
664 int status;
665
666 switch (sattr->ia_mode & S_IFMT) {
667 case S_IFBLK: arg.type = NF3BLK; break;
668 case S_IFCHR: arg.type = NF3CHR; break;
669 case S_IFIFO: arg.type = NF3FIFO; break;
670 case S_IFSOCK: arg.type = NF3SOCK; break;
671 default: return -EINVAL;
672 }
673
674 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
675 MAJOR(rdev), MINOR(rdev));
055ffbea
AG
676
677 sattr->ia_mode &= ~current->fs->umask;
678
0e574af1
TM
679 nfs_fattr_init(&dir_attr);
680 nfs_fattr_init(&fattr);
1da177e4 681 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
decf491f 682 nfs_post_op_update_inode(dir, &dir_attr);
055ffbea
AG
683 if (status != 0)
684 goto out;
685 status = nfs_instantiate(dentry, &fh, &fattr);
686 if (status != 0)
687 goto out;
688 status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode);
689out:
1da177e4
LT
690 dprintk("NFS reply mknod: %d\n", status);
691 return status;
692}
693
694static int
695nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
696 struct nfs_fsstat *stat)
697{
698 int status;
699
700 dprintk("NFS call fsstat\n");
0e574af1 701 nfs_fattr_init(stat->fattr);
1da177e4
LT
702 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
703 dprintk("NFS reply statfs: %d\n", status);
704 return status;
705}
706
707static int
708nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
709 struct nfs_fsinfo *info)
710{
711 int status;
712
713 dprintk("NFS call fsinfo\n");
0e574af1 714 nfs_fattr_init(info->fattr);
1da177e4
LT
715 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
716 dprintk("NFS reply fsinfo: %d\n", status);
717 return status;
718}
719
720static int
721nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
722 struct nfs_pathconf *info)
723{
724 int status;
725
726 dprintk("NFS call pathconf\n");
0e574af1 727 nfs_fattr_init(info->fattr);
1da177e4
LT
728 status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
729 dprintk("NFS reply pathconf: %d\n", status);
730 return status;
731}
732
733extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
734
963d8fe5 735static void nfs3_read_done(struct rpc_task *task, void *calldata)
1da177e4 736{
963d8fe5 737 struct nfs_read_data *data = calldata;
1da177e4
LT
738
739 if (nfs3_async_handle_jukebox(task))
740 return;
741 /* Call back common NFS readpage processing */
742 if (task->tk_status >= 0)
743 nfs_refresh_inode(data->inode, &data->fattr);
963d8fe5 744 nfs_readpage_result(task, calldata);
1da177e4
LT
745}
746
963d8fe5
TM
747static const struct rpc_call_ops nfs3_read_ops = {
748 .rpc_call_done = nfs3_read_done,
749 .rpc_release = nfs_readdata_release,
750};
751
1da177e4
LT
752static void
753nfs3_proc_read_setup(struct nfs_read_data *data)
754{
755 struct rpc_task *task = &data->task;
756 struct inode *inode = data->inode;
757 int flags;
758 struct rpc_message msg = {
759 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
760 .rpc_argp = &data->args,
761 .rpc_resp = &data->res,
762 .rpc_cred = data->cred,
763 };
764
765 /* N.B. Do we need to test? Never called for swapfile inode */
766 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
767
768 /* Finalize the task. */
963d8fe5 769 rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs3_read_ops, data);
1da177e4
LT
770 rpc_call_setup(task, &msg, 0);
771}
772
963d8fe5 773static void nfs3_write_done(struct rpc_task *task, void *calldata)
1da177e4 774{
963d8fe5 775 struct nfs_write_data *data = calldata;
1da177e4
LT
776
777 if (nfs3_async_handle_jukebox(task))
778 return;
1da177e4 779 if (task->tk_status >= 0)
decf491f 780 nfs_post_op_update_inode(data->inode, data->res.fattr);
963d8fe5 781 nfs_writeback_done(task, calldata);
1da177e4
LT
782}
783
963d8fe5
TM
784static const struct rpc_call_ops nfs3_write_ops = {
785 .rpc_call_done = nfs3_write_done,
786 .rpc_release = nfs_writedata_release,
787};
788
1da177e4
LT
789static void
790nfs3_proc_write_setup(struct nfs_write_data *data, int how)
791{
792 struct rpc_task *task = &data->task;
793 struct inode *inode = data->inode;
794 int stable;
795 int flags;
796 struct rpc_message msg = {
797 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
798 .rpc_argp = &data->args,
799 .rpc_resp = &data->res,
800 .rpc_cred = data->cred,
801 };
802
803 if (how & FLUSH_STABLE) {
804 if (!NFS_I(inode)->ncommit)
805 stable = NFS_FILE_SYNC;
806 else
807 stable = NFS_DATA_SYNC;
808 } else
809 stable = NFS_UNSTABLE;
810 data->args.stable = stable;
811
812 /* Set the initial flags for the task. */
813 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
814
815 /* Finalize the task. */
963d8fe5 816 rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs3_write_ops, data);
1da177e4
LT
817 rpc_call_setup(task, &msg, 0);
818}
819
963d8fe5 820static void nfs3_commit_done(struct rpc_task *task, void *calldata)
1da177e4 821{
963d8fe5 822 struct nfs_write_data *data = calldata;
1da177e4
LT
823
824 if (nfs3_async_handle_jukebox(task))
825 return;
1da177e4 826 if (task->tk_status >= 0)
decf491f 827 nfs_post_op_update_inode(data->inode, data->res.fattr);
963d8fe5 828 nfs_commit_done(task, calldata);
1da177e4
LT
829}
830
963d8fe5
TM
831static const struct rpc_call_ops nfs3_commit_ops = {
832 .rpc_call_done = nfs3_commit_done,
833 .rpc_release = nfs_commit_release,
834};
835
1da177e4
LT
836static void
837nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
838{
839 struct rpc_task *task = &data->task;
840 struct inode *inode = data->inode;
841 int flags;
842 struct rpc_message msg = {
843 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
844 .rpc_argp = &data->args,
845 .rpc_resp = &data->res,
846 .rpc_cred = data->cred,
847 };
848
849 /* Set the initial flags for the task. */
850 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
851
852 /* Finalize the task. */
963d8fe5 853 rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs3_commit_ops, data);
1da177e4
LT
854 rpc_call_setup(task, &msg, 0);
855}
856
857static int
858nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
859{
860 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
861}
862
863struct nfs_rpc_ops nfs_v3_clientops = {
864 .version = 3, /* protocol version */
865 .dentry_ops = &nfs_dentry_operations,
b7fa0554
AG
866 .dir_inode_ops = &nfs3_dir_inode_operations,
867 .file_inode_ops = &nfs3_file_inode_operations,
1da177e4
LT
868 .getroot = nfs3_proc_get_root,
869 .getattr = nfs3_proc_getattr,
870 .setattr = nfs3_proc_setattr,
871 .lookup = nfs3_proc_lookup,
872 .access = nfs3_proc_access,
873 .readlink = nfs3_proc_readlink,
874 .read = nfs3_proc_read,
875 .write = nfs3_proc_write,
876 .commit = nfs3_proc_commit,
877 .create = nfs3_proc_create,
878 .remove = nfs3_proc_remove,
879 .unlink_setup = nfs3_proc_unlink_setup,
880 .unlink_done = nfs3_proc_unlink_done,
881 .rename = nfs3_proc_rename,
882 .link = nfs3_proc_link,
883 .symlink = nfs3_proc_symlink,
884 .mkdir = nfs3_proc_mkdir,
885 .rmdir = nfs3_proc_rmdir,
886 .readdir = nfs3_proc_readdir,
887 .mknod = nfs3_proc_mknod,
888 .statfs = nfs3_proc_statfs,
889 .fsinfo = nfs3_proc_fsinfo,
890 .pathconf = nfs3_proc_pathconf,
891 .decode_dirent = nfs3_decode_dirent,
892 .read_setup = nfs3_proc_read_setup,
893 .write_setup = nfs3_proc_write_setup,
894 .commit_setup = nfs3_proc_commit_setup,
895 .file_open = nfs_open,
896 .file_release = nfs_release,
897 .lock = nfs3_proc_lock,
5c6a9f7d 898 .clear_acl_cache = nfs3_forget_cached_acls,
1da177e4 899};