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