2 * linux/fs/nfs/nfs3proc.c
4 * Client-side NFSv3 procedures stubs.
6 * Copyright (C) 1997, Olaf Kirch
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 #include <linux/nfs_mount.h>
22 #define NFSDBG_FACILITY NFSDBG_PROC
24 extern struct rpc_procinfo nfs3_procedures[];
26 /* A wrapper to handle the EJUKEBOX error message */
28 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
32 rpc_clnt_sigmask(clnt, &oldset);
34 res = rpc_call_sync(clnt, msg, flags);
37 set_current_state(TASK_INTERRUPTIBLE);
38 schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
40 } while (!signalled());
41 rpc_clnt_sigunmask(clnt, &oldset);
46 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
48 struct rpc_message msg = {
49 .rpc_proc = &clnt->cl_procinfo[proc],
53 return nfs3_rpc_wrapper(clnt, &msg, flags);
56 #define rpc_call(clnt, proc, argp, resp, flags) \
57 nfs3_rpc_call_wrapper(clnt, proc, argp, resp, flags)
58 #define rpc_call_sync(clnt, msg, flags) \
59 nfs3_rpc_wrapper(clnt, msg, flags)
62 nfs3_async_handle_jukebox(struct rpc_task *task)
64 if (task->tk_status != -EJUKEBOX)
67 rpc_restart_call(task);
68 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
72 static struct rpc_cred *
73 nfs_cred(struct inode *inode, struct file *filp)
75 struct rpc_cred *cred = NULL;
78 cred = (struct rpc_cred *)filp->private_data;
80 cred = NFS_I(inode)->mm_cred;
85 * Bare-bones access to getattr: this is for nfs_read_super.
88 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
89 struct nfs_fsinfo *info)
93 dprintk("%s: call fsinfo\n", __FUNCTION__);
94 info->fattr->valid = 0;
95 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
96 dprintk("%s: reply fsinfo %d\n", __FUNCTION__, status);
97 if (!(info->fattr->valid & NFS_ATTR_FATTR)) {
98 status = rpc_call(server->client_sys, NFS3PROC_GETATTR, fhandle, info->fattr, 0);
99 dprintk("%s: reply getattr %d\n", __FUNCTION__, status);
105 * One function for each procedure in the NFS protocol.
108 nfs3_proc_getattr(struct inode *inode, struct nfs_fattr *fattr)
112 dprintk("NFS call getattr\n");
114 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_GETATTR,
115 NFS_FH(inode), fattr, 0);
116 dprintk("NFS reply getattr\n");
121 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
124 struct inode *inode = dentry->d_inode;
125 struct nfs3_sattrargs arg = {
131 dprintk("NFS call setattr\n");
133 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
134 dprintk("NFS reply setattr\n");
139 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
140 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
142 struct nfs_fattr dir_attr;
143 struct nfs3_diropargs arg = {
148 struct nfs3_diropres res = {
149 .dir_attr = &dir_attr,
155 dprintk("NFS call lookup %s\n", name->name);
158 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
159 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
160 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
162 dprintk("NFS reply lookup: %d\n", status);
164 status = nfs_refresh_inode(dir, &dir_attr);
169 nfs3_proc_access(struct inode *inode, struct rpc_cred *cred, int mode)
171 struct nfs_fattr fattr;
172 struct nfs3_accessargs arg = {
175 struct nfs3_accessres res = {
178 struct rpc_message msg = {
179 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
186 dprintk("NFS call access\n");
190 arg.access |= NFS3_ACCESS_READ;
191 if (S_ISDIR(inode->i_mode)) {
192 if (mode & MAY_WRITE)
193 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
195 arg.access |= NFS3_ACCESS_LOOKUP;
197 if (mode & MAY_WRITE)
198 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
200 arg.access |= NFS3_ACCESS_EXECUTE;
202 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
203 nfs_refresh_inode(inode, &fattr);
204 dprintk("NFS reply access\n");
206 if (status == 0 && (arg.access & res.access) != arg.access)
212 nfs3_proc_readlink(struct inode *inode, struct page *page)
214 struct nfs_fattr fattr;
215 struct nfs3_readlinkargs args = {
217 .count = PAGE_CACHE_SIZE,
222 dprintk("NFS call readlink\n");
224 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
226 nfs_refresh_inode(inode, &fattr);
227 dprintk("NFS reply readlink: %d\n", status);
232 nfs3_proc_read(struct nfs_read_data *rdata, struct file *filp)
234 int flags = rdata->flags;
235 struct inode * inode = rdata->inode;
236 struct nfs_fattr * fattr = rdata->res.fattr;
237 struct rpc_message msg = {
238 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
239 .rpc_argp = &rdata->args,
240 .rpc_resp = &rdata->res,
244 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
245 (long long) rdata->args.offset);
247 msg.rpc_cred = nfs_cred(inode, filp);
248 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
250 nfs_refresh_inode(inode, fattr);
251 dprintk("NFS reply read: %d\n", status);
256 nfs3_proc_write(struct nfs_write_data *wdata, struct file *filp)
258 int rpcflags = wdata->flags;
259 struct inode * inode = wdata->inode;
260 struct nfs_fattr * fattr = wdata->res.fattr;
261 struct rpc_message msg = {
262 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
263 .rpc_argp = &wdata->args,
264 .rpc_resp = &wdata->res,
268 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
269 (long long) wdata->args.offset);
271 msg.rpc_cred = nfs_cred(inode, filp);
272 status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
274 nfs_refresh_inode(inode, fattr);
275 dprintk("NFS reply write: %d\n", status);
276 return status < 0? status : wdata->res.count;
280 nfs3_proc_commit(struct nfs_write_data *cdata, struct file *filp)
282 struct inode * inode = cdata->inode;
283 struct nfs_fattr * fattr = cdata->res.fattr;
284 struct rpc_message msg = {
285 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
286 .rpc_argp = &cdata->args,
287 .rpc_resp = &cdata->res,
291 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
292 (long long) cdata->args.offset);
294 msg.rpc_cred = nfs_cred(inode, filp);
295 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
297 nfs_refresh_inode(inode, fattr);
298 dprintk("NFS reply commit: %d\n", status);
303 * Create a regular file.
304 * For now, we don't implement O_EXCL.
306 static struct inode *
307 nfs3_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,
310 struct nfs_fh fhandle;
311 struct nfs_fattr fattr;
312 struct nfs_fattr dir_attr;
313 struct nfs3_createargs arg = {
319 struct nfs3_diropres res = {
320 .dir_attr = &dir_attr,
326 dprintk("NFS call create %s\n", name->name);
327 arg.createmode = NFS3_CREATE_UNCHECKED;
328 if (flags & O_EXCL) {
329 arg.createmode = NFS3_CREATE_EXCLUSIVE;
330 arg.verifier[0] = jiffies;
331 arg.verifier[1] = current->pid;
337 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
338 nfs_refresh_inode(dir, &dir_attr);
340 /* If the server doesn't support the exclusive creation semantics,
341 * try again with simple 'guarded' mode. */
342 if (status == NFSERR_NOTSUPP) {
343 switch (arg.createmode) {
344 case NFS3_CREATE_EXCLUSIVE:
345 arg.createmode = NFS3_CREATE_GUARDED;
348 case NFS3_CREATE_GUARDED:
349 arg.createmode = NFS3_CREATE_UNCHECKED;
352 case NFS3_CREATE_UNCHECKED:
359 dprintk("NFS reply create: %d\n", status);
363 if (fhandle.size == 0 || !(fattr.valid & NFS_ATTR_FATTR)) {
364 status = nfs3_proc_lookup(dir, name, &fhandle, &fattr);
369 /* When we created the file with exclusive semantics, make
370 * sure we set the attributes afterwards. */
371 if (arg.createmode == NFS3_CREATE_EXCLUSIVE) {
372 struct nfs3_sattrargs arg = {
376 dprintk("NFS call setattr (post-create)\n");
378 if (!(sattr->ia_valid & ATTR_ATIME_SET))
379 sattr->ia_valid |= ATTR_ATIME;
380 if (!(sattr->ia_valid & ATTR_MTIME_SET))
381 sattr->ia_valid |= ATTR_MTIME;
383 /* Note: we could use a guarded setattr here, but I'm
384 * not sure this buys us anything (and I'd have
385 * to revamp the NFSv3 XDR code) */
387 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SETATTR,
389 dprintk("NFS reply setattr (post-create): %d\n", status);
393 inode = nfs_fhget(dir->i_sb, &fhandle, &fattr);
399 return ERR_PTR(status);
403 nfs3_proc_remove(struct inode *dir, struct qstr *name)
405 struct nfs_fattr dir_attr;
406 struct nfs3_diropargs arg = {
411 struct rpc_message msg = {
412 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
414 .rpc_resp = &dir_attr,
418 dprintk("NFS call remove %s\n", name->name);
420 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
421 nfs_refresh_inode(dir, &dir_attr);
422 dprintk("NFS reply remove: %d\n", status);
427 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
429 struct nfs3_diropargs *arg;
430 struct nfs_fattr *res;
432 arg = (struct nfs3_diropargs *)kmalloc(sizeof(*arg)+sizeof(*res), GFP_KERNEL);
435 res = (struct nfs_fattr*)(arg + 1);
436 arg->fh = NFS_FH(dir->d_inode);
437 arg->name = name->name;
438 arg->len = name->len;
440 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
447 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
449 struct rpc_message *msg = &task->tk_msg;
450 struct nfs_fattr *dir_attr;
452 if (nfs3_async_handle_jukebox(task))
455 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
456 nfs_refresh_inode(dir->d_inode, dir_attr);
457 kfree(msg->rpc_argp);
463 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
464 struct inode *new_dir, struct qstr *new_name)
466 struct nfs_fattr old_dir_attr, new_dir_attr;
467 struct nfs3_renameargs arg = {
468 .fromfh = NFS_FH(old_dir),
469 .fromname = old_name->name,
470 .fromlen = old_name->len,
471 .tofh = NFS_FH(new_dir),
472 .toname = new_name->name,
473 .tolen = new_name->len
475 struct nfs3_renameres res = {
476 .fromattr = &old_dir_attr,
477 .toattr = &new_dir_attr
481 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
482 old_dir_attr.valid = 0;
483 new_dir_attr.valid = 0;
484 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
485 nfs_refresh_inode(old_dir, &old_dir_attr);
486 nfs_refresh_inode(new_dir, &new_dir_attr);
487 dprintk("NFS reply rename: %d\n", status);
492 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
494 struct nfs_fattr dir_attr, fattr;
495 struct nfs3_linkargs arg = {
496 .fromfh = NFS_FH(inode),
498 .toname = name->name,
501 struct nfs3_linkres res = {
502 .dir_attr = &dir_attr,
507 dprintk("NFS call link %s\n", name->name);
510 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
511 nfs_refresh_inode(dir, &dir_attr);
512 nfs_refresh_inode(inode, &fattr);
513 dprintk("NFS reply link: %d\n", status);
518 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
519 struct iattr *sattr, struct nfs_fh *fhandle,
520 struct nfs_fattr *fattr)
522 struct nfs_fattr dir_attr;
523 struct nfs3_symlinkargs arg = {
524 .fromfh = NFS_FH(dir),
525 .fromname = name->name,
526 .fromlen = name->len,
527 .topath = path->name,
531 struct nfs3_diropres res = {
532 .dir_attr = &dir_attr,
538 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
541 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
542 nfs_refresh_inode(dir, &dir_attr);
543 dprintk("NFS reply symlink: %d\n", status);
548 nfs3_proc_mkdir(struct inode *dir, struct qstr *name, struct iattr *sattr,
549 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
551 struct nfs_fattr dir_attr;
552 struct nfs3_mkdirargs arg = {
558 struct nfs3_diropres res = {
559 .dir_attr = &dir_attr,
565 dprintk("NFS call mkdir %s\n", name->name);
568 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
569 nfs_refresh_inode(dir, &dir_attr);
570 dprintk("NFS reply mkdir: %d\n", status);
575 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
577 struct nfs_fattr dir_attr;
578 struct nfs3_diropargs arg = {
585 dprintk("NFS call rmdir %s\n", name->name);
587 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
588 nfs_refresh_inode(dir, &dir_attr);
589 dprintk("NFS reply rmdir: %d\n", status);
594 * The READDIR implementation is somewhat hackish - we pass the user buffer
595 * to the encode function, which installs it in the receive iovec.
596 * The decode function itself doesn't perform any decoding, it just makes
597 * sure the reply is syntactically correct.
599 * Also note that this implementation handles both plain readdir and
603 nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
604 u64 cookie, struct page *page, unsigned int count, int plus)
606 struct inode *dir = dentry->d_inode;
607 struct nfs_fattr dir_attr;
608 u32 *verf = NFS_COOKIEVERF(dir);
609 struct nfs3_readdirargs arg = {
612 .verf = {verf[0], verf[1]},
617 struct nfs3_readdirres res = {
618 .dir_attr = &dir_attr,
622 struct rpc_message msg = {
623 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
633 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
635 dprintk("NFS call readdir%s %d\n",
636 plus? "plus" : "", (unsigned int) cookie);
639 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
640 nfs_refresh_inode(dir, &dir_attr);
641 dprintk("NFS reply readdir: %d\n", status);
647 nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
648 dev_t rdev, struct nfs_fh *fh, struct nfs_fattr *fattr)
650 struct nfs_fattr dir_attr;
651 struct nfs3_mknodargs arg = {
658 struct nfs3_diropres res = {
659 .dir_attr = &dir_attr,
665 switch (sattr->ia_mode & S_IFMT) {
666 case S_IFBLK: arg.type = NF3BLK; break;
667 case S_IFCHR: arg.type = NF3CHR; break;
668 case S_IFIFO: arg.type = NF3FIFO; break;
669 case S_IFSOCK: arg.type = NF3SOCK; break;
670 default: return -EINVAL;
673 dprintk("NFS call mknod %s %u:%u\n", name->name,
674 MAJOR(rdev), MINOR(rdev));
677 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
678 nfs_refresh_inode(dir, &dir_attr);
679 dprintk("NFS reply mknod: %d\n", status);
684 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
685 struct nfs_fsstat *stat)
689 dprintk("NFS call fsstat\n");
690 stat->fattr->valid = 0;
691 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, stat, 0);
692 dprintk("NFS reply statfs: %d\n", status);
697 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
698 struct nfs_fsinfo *info)
702 dprintk("NFS call fsinfo\n");
703 info->fattr->valid = 0;
704 status = rpc_call(server->client_sys, NFS3PROC_FSINFO, fhandle, info, 0);
705 dprintk("NFS reply fsinfo: %d\n", status);
710 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
711 struct nfs_pathconf *info)
715 dprintk("NFS call pathconf\n");
716 info->fattr->valid = 0;
717 status = rpc_call(server->client, NFS3PROC_PATHCONF, fhandle, info, 0);
718 dprintk("NFS reply pathconf: %d\n", status);
722 #ifdef CONFIG_NFS_ACL
724 nfs3_proc_checkacls(struct inode *inode)
726 struct nfs_server *server = NFS_SERVER(inode);
727 struct nfs_fattr fattr;
728 struct nfs3_getaclargs args = { };
729 struct nfs3_getaclres res = { &fattr };
732 if (!(server->flags & NFSACL) || (server->flags & NFS_MOUNT_NOACL))
735 args.fh = NFS_FH(inode);
736 args.mask = NFS3_ACLCNT | NFS3_DFACLCNT;
738 dprintk("NFS call getacl\n");
739 status = rpc_call(server->acl_client, NFS3PROC_GETACL,
741 dprintk("NFS reply getacl: %d\n", status);
744 if (status == -ENOSYS) {
745 dprintk("NFS_ACL extension not supported; disabling\n");
746 server->flags &= ~NFSACL;
747 status = -EOPNOTSUPP;
748 } else if (status == -ENOTSUPP)
749 status = -EOPNOTSUPP;
752 if ((args.mask & res.mask) != args.mask) {
757 status = nfs_refresh_inode(inode, &fattr);
760 posix_acl_release(res.acl_access);
761 posix_acl_release(res.acl_default);
764 /* The (count > 4) test will exclude ACL entries from the list
765 of names even if their ACL_GROUP_ENTRY and ACL_MASK have
766 different permissions. Getacl still returns these as
767 four-entry ACLs, instead of minimal (three-entry) ACLs. */
769 if ((args.mask & NFS3_ACLCNT) && res.acl_access_count > 4)
770 status |= ACL_TYPE_ACCESS;
771 if ((args.mask & NFS3_DFACLCNT) && res.acl_default_count > 0)
772 status |= ACL_TYPE_DEFAULT;
776 #endif /* CONFIG_NFS_ACL */
778 #ifdef CONFIG_NFS_ACL
779 static struct posix_acl *
780 nfs3_proc_getacl(struct inode *inode, int type)
782 struct nfs_server *server = NFS_SERVER(inode);
783 struct nfs_fattr fattr;
784 struct page *pages[NFSACL_MAXPAGES] = { };
785 struct nfs3_getaclargs args = {
786 /* The xdr layer may allocate pages here. */
789 struct nfs3_getaclres res = {
792 struct posix_acl *acl = NULL;
795 if (!(server->flags & NFSACL) || (server->flags & NFS_MOUNT_NOACL))
796 return ERR_PTR(-EOPNOTSUPP);
798 args.fh = NFS_FH(inode);
800 case ACL_TYPE_ACCESS:
801 args.mask = NFS3_ACLCNT|NFS3_ACL;
804 case ACL_TYPE_DEFAULT:
805 if (!S_ISDIR(inode->i_mode))
807 args.mask = NFS3_DFACLCNT|NFS3_DFACL;
811 return ERR_PTR(-EINVAL);
814 dprintk("NFS call getacl\n");
815 status = rpc_call(server->acl_client, NFS3PROC_GETACL,
817 dprintk("NFS reply getacl: %d\n", status);
819 /* pages may have been allocated at the xdr layer. */
820 for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++)
821 __free_page(args.pages[count]);
824 if (status == -ENOSYS) {
825 dprintk("NFS_ACL extension not supported; disabling\n");
826 server->flags &= ~NFSACL;
827 status = -EOPNOTSUPP;
828 } else if (status == -ENOTSUPP)
829 status = -EOPNOTSUPP;
832 if ((args.mask & res.mask) != args.mask) {
837 if (type == ACL_TYPE_ACCESS) {
838 if (res.acl_access) {
839 mode_t mode = inode->i_mode;
840 if (!posix_acl_equiv_mode(res.acl_access, &mode) &&
841 inode->i_mode == mode) {
842 posix_acl_release(res.acl_access);
843 res.acl_access = NULL;
846 acl = res.acl_access;
847 res.acl_access = NULL;
849 acl = res.acl_default;
850 res.acl_default = NULL;
853 status = nfs_refresh_inode(inode, &fattr);
856 posix_acl_release(res.acl_access);
857 posix_acl_release(res.acl_default);
860 posix_acl_release(acl);
861 acl = ERR_PTR(status);
865 #endif /* CONFIG_NFS_ACL */
867 #ifdef CONFIG_NFS_ACL
869 nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl)
871 struct nfs_server *server = NFS_SERVER(inode);
872 struct nfs_fattr fattr;
873 struct page *pages[NFSACL_MAXPAGES] = { };
874 struct nfs3_setaclargs args = {
879 if (!(server->flags & NFSACL) || (server->flags & NFS_MOUNT_NOACL))
882 /* We are doing this here, because XDR marshalling can only
884 if (acl && acl->a_count > NFS3_ACL_MAX_ENTRIES)
887 args.mask = NFS3_ACL|NFS3_DFACL;
888 if (S_ISDIR(inode->i_mode)) {
890 case ACL_TYPE_ACCESS:
891 args.acl_access = acl;
892 args.acl_default = NFS_PROTO(inode)->getacl(
893 inode, ACL_TYPE_DEFAULT);
894 status = PTR_ERR(args.acl_default);
895 if (IS_ERR(args.acl_default)) {
896 args.acl_default = NULL;
901 case ACL_TYPE_DEFAULT:
902 args.acl_access = NFS_PROTO(inode)->getacl(
903 inode, ACL_TYPE_ACCESS);
904 status = PTR_ERR(args.acl_access);
905 if (IS_ERR(args.acl_access)) {
906 args.acl_access = NULL;
909 args.acl_default = acl;
918 if (type != ACL_TYPE_ACCESS)
920 args.mask = NFS3_ACL;
921 args.acl_access = acl;
923 if (args.acl_access == NULL) {
924 args.acl_access = posix_acl_from_mode(inode->i_mode,
926 status = PTR_ERR(args.acl_access);
927 if (IS_ERR(args.acl_access)) {
928 args.acl_access = NULL;
932 args.mask = NFS3_ACL | (args.acl_default ? NFS3_DFACL : 0);
934 dprintk("NFS call setacl\n");
935 status = rpc_call(server->acl_client, NFS3PROC_SETACL,
937 dprintk("NFS reply setacl: %d\n", status);
939 /* pages may have been allocated at the xdr layer. */
940 for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++)
941 __free_page(args.pages[count]);
944 if (status == -ENOSYS) {
945 dprintk("NFS_ACL SETACL RPC not supported"
946 "(will not retry)\n");
947 server->flags &= ~NFSACL;
948 status = -EOPNOTSUPP;
949 } else if (status == -ENOTSUPP)
950 status = -EOPNOTSUPP;
952 /* Force an attribute cache update if the file mode
954 if (inode->i_mode != fattr.mode)
956 status = nfs_refresh_inode(inode, &fattr);
960 if (args.acl_access != acl)
961 posix_acl_release(args.acl_access);
962 if (args.acl_default != acl)
963 posix_acl_release(args.acl_default);
966 #endif /* CONFIG_NFS_ACL */
968 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
971 nfs3_read_done(struct rpc_task *task)
973 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
975 if (nfs3_async_handle_jukebox(task))
977 /* Call back common NFS readpage processing */
978 if (task->tk_status >= 0)
979 nfs_refresh_inode(data->inode, &data->fattr);
980 nfs_readpage_result(task);
984 nfs3_proc_read_setup(struct nfs_read_data *data)
986 struct rpc_task *task = &data->task;
987 struct inode *inode = data->inode;
989 struct rpc_message msg = {
990 .rpc_proc = &nfs3_procedures[NFS3PROC_READ],
991 .rpc_argp = &data->args,
992 .rpc_resp = &data->res,
993 .rpc_cred = data->cred,
996 /* N.B. Do we need to test? Never called for swapfile inode */
997 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
999 /* Finalize the task. */
1000 rpc_init_task(task, NFS_CLIENT(inode), nfs3_read_done, flags);
1001 rpc_call_setup(task, &msg, 0);
1005 nfs3_write_done(struct rpc_task *task)
1007 struct nfs_write_data *data;
1009 if (nfs3_async_handle_jukebox(task))
1011 data = (struct nfs_write_data *)task->tk_calldata;
1012 if (task->tk_status >= 0)
1013 nfs_refresh_inode(data->inode, data->res.fattr);
1014 nfs_writeback_done(task);
1018 nfs3_proc_write_setup(struct nfs_write_data *data, int how)
1020 struct rpc_task *task = &data->task;
1021 struct inode *inode = data->inode;
1024 struct rpc_message msg = {
1025 .rpc_proc = &nfs3_procedures[NFS3PROC_WRITE],
1026 .rpc_argp = &data->args,
1027 .rpc_resp = &data->res,
1028 .rpc_cred = data->cred,
1031 if (how & FLUSH_STABLE) {
1032 if (!NFS_I(inode)->ncommit)
1033 stable = NFS_FILE_SYNC;
1035 stable = NFS_DATA_SYNC;
1037 stable = NFS_UNSTABLE;
1038 data->args.stable = stable;
1040 /* Set the initial flags for the task. */
1041 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
1043 /* Finalize the task. */
1044 rpc_init_task(task, NFS_CLIENT(inode), nfs3_write_done, flags);
1045 rpc_call_setup(task, &msg, 0);
1049 nfs3_commit_done(struct rpc_task *task)
1051 struct nfs_write_data *data;
1053 if (nfs3_async_handle_jukebox(task))
1055 data = (struct nfs_write_data *)task->tk_calldata;
1056 if (task->tk_status >= 0)
1057 nfs_refresh_inode(data->inode, data->res.fattr);
1058 nfs_commit_done(task);
1062 nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
1064 struct rpc_task *task = &data->task;
1065 struct inode *inode = data->inode;
1067 struct rpc_message msg = {
1068 .rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT],
1069 .rpc_argp = &data->args,
1070 .rpc_resp = &data->res,
1071 .rpc_cred = data->cred,
1074 /* Set the initial flags for the task. */
1075 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
1077 /* Finalize the task. */
1078 rpc_init_task(task, NFS_CLIENT(inode), nfs3_commit_done, flags);
1079 rpc_call_setup(task, &msg, 0);
1083 * Set up the nfspage struct with the right credentials
1086 nfs3_request_init(struct nfs_page *req, struct file *filp)
1088 req->wb_cred = get_rpccred(nfs_cred(req->wb_inode, filp));
1092 nfs3_request_compatible(struct nfs_page *req, struct file *filp, struct page *page)
1094 if (req->wb_file != filp)
1096 if (req->wb_page != page)
1098 if (req->wb_cred != nfs_file_cred(filp))
1104 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
1106 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl);
1109 struct nfs_rpc_ops nfs_v3_clientops = {
1110 .version = 3, /* protocol version */
1111 .dentry_ops = &nfs_dentry_operations,
1112 .dir_inode_ops = &nfs_dir_inode_operations,
1113 .getroot = nfs3_proc_get_root,
1114 .getattr = nfs3_proc_getattr,
1115 .setattr = nfs3_proc_setattr,
1116 .lookup = nfs3_proc_lookup,
1117 .access = nfs3_proc_access,
1118 .readlink = nfs3_proc_readlink,
1119 .read = nfs3_proc_read,
1120 .write = nfs3_proc_write,
1121 .commit = nfs3_proc_commit,
1122 .create = nfs3_proc_create,
1123 .remove = nfs3_proc_remove,
1124 .unlink_setup = nfs3_proc_unlink_setup,
1125 .unlink_done = nfs3_proc_unlink_done,
1126 .rename = nfs3_proc_rename,
1127 .link = nfs3_proc_link,
1128 .symlink = nfs3_proc_symlink,
1129 .mkdir = nfs3_proc_mkdir,
1130 .rmdir = nfs3_proc_rmdir,
1131 .readdir = nfs3_proc_readdir,
1132 .mknod = nfs3_proc_mknod,
1133 .statfs = nfs3_proc_statfs,
1134 .fsinfo = nfs3_proc_fsinfo,
1135 .pathconf = nfs3_proc_pathconf,
1136 .decode_dirent = nfs3_decode_dirent,
1137 .read_setup = nfs3_proc_read_setup,
1138 .write_setup = nfs3_proc_write_setup,
1139 .commit_setup = nfs3_proc_commit_setup,
1140 .file_open = nfs_open,
1141 .file_release = nfs_release,
1142 .request_init = nfs3_request_init,
1143 .request_compatible = nfs3_request_compatible,
1144 .lock = nfs3_proc_lock,
1145 #ifdef CONFIG_NFS_ACL
1146 .getacl = nfs3_proc_getacl,
1147 .setacl = nfs3_proc_setacl,
1148 .checkacls = nfs3_proc_checkacls,
1149 #endif /* CONFIG_NFS_ACL */