Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/nfs/nfs3proc.c |
| 4 | * |
| 5 | * Client-side NFSv3 procedures stubs. |
| 6 | * |
| 7 | * Copyright (C) 1997, Olaf Kirch |
| 8 | */ |
| 9 | |
| 10 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/errno.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/sunrpc/clnt.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/nfs.h> |
| 16 | #include <linux/nfs3.h> |
| 17 | #include <linux/nfs_fs.h> |
| 18 | #include <linux/nfs_page.h> |
| 19 | #include <linux/lockd/bind.h> |
Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 20 | #include <linux/nfs_mount.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 21 | #include <linux/freezer.h> |
Tejun Heo | 0a6be65 | 2014-02-03 14:31:07 -0500 | [diff] [blame] | 22 | #include <linux/xattr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 24 | #include "iostat.h" |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 25 | #include "internal.h" |
Anna Schumaker | 00a36a10 | 2014-09-03 12:19:08 -0400 | [diff] [blame] | 26 | #include "nfs3_fs.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 29 | |
Andy Adamson | eb96d5c | 2012-11-27 10:34:19 -0500 | [diff] [blame] | 30 | /* A wrapper to handle the EJUKEBOX error messages */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | static int |
| 32 | nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) |
| 33 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | do { |
| 36 | res = rpc_call_sync(clnt, msg, flags); |
Andy Adamson | eb96d5c | 2012-11-27 10:34:19 -0500 | [diff] [blame] | 37 | if (res != -EJUKEBOX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | break; |
Colin Cross | 416ad3c | 2013-05-06 23:50:06 +0000 | [diff] [blame] | 39 | freezable_schedule_timeout_killable_unsafe(NFS_JUKEBOX_RETRY_TIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | res = -ERESTARTSYS; |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 41 | } while (!fatal_signal_pending(current)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return res; |
| 43 | } |
| 44 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 45 | #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | static int |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 48 | nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Andy Adamson | eb96d5c | 2012-11-27 10:34:19 -0500 | [diff] [blame] | 50 | if (task->tk_status != -EJUKEBOX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | return 0; |
Jeff Layton | b68d69b | 2010-01-07 09:42:04 -0500 | [diff] [blame] | 52 | if (task->tk_status == -EJUKEBOX) |
| 53 | nfs_inc_stats(inode, NFSIOS_DELAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | task->tk_status = 0; |
| 55 | rpc_restart_call(task); |
| 56 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); |
| 57 | return 1; |
| 58 | } |
| 59 | |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 60 | static int |
| 61 | do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle, |
| 62 | struct nfs_fsinfo *info) |
| 63 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 64 | struct rpc_message msg = { |
| 65 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], |
| 66 | .rpc_argp = fhandle, |
| 67 | .rpc_resp = info, |
| 68 | }; |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 69 | int status; |
| 70 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 71 | dprintk("%s: call fsinfo\n", __func__); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 72 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 73 | status = rpc_call_sync(client, &msg, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 74 | dprintk("%s: reply fsinfo: %d\n", __func__, status); |
Trond Myklebust | 0866004 | 2012-08-20 12:42:15 -0400 | [diff] [blame] | 75 | if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 76 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; |
| 77 | msg.rpc_resp = info->fattr; |
| 78 | status = rpc_call_sync(client, &msg, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 79 | dprintk("%s: reply getattr: %d\n", __func__, status); |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 80 | } |
| 81 | return status; |
| 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 85 | * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ |
| 87 | static int |
| 88 | nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 89 | struct nfs_fsinfo *info) |
| 90 | { |
| 91 | int status; |
| 92 | |
J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 93 | status = do_proc_get_root(server->client, fhandle, info); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 94 | if (status && server->nfs_client->cl_rpcclient != server->client) |
| 95 | status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return status; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * One function for each procedure in the NFS protocol. |
| 101 | */ |
| 102 | static int |
| 103 | nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 104 | struct nfs_fattr *fattr, struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 106 | struct rpc_message msg = { |
| 107 | .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR], |
| 108 | .rpc_argp = fhandle, |
| 109 | .rpc_resp = fattr, |
| 110 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int status; |
| 112 | |
| 113 | dprintk("NFS call getattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 114 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 115 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | dprintk("NFS reply getattr: %d\n", status); |
| 117 | return status; |
| 118 | } |
| 119 | |
| 120 | static int |
| 121 | nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 122 | struct iattr *sattr) |
| 123 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 124 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | struct nfs3_sattrargs arg = { |
| 126 | .fh = NFS_FH(inode), |
| 127 | .sattr = sattr, |
| 128 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 129 | struct rpc_message msg = { |
| 130 | .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR], |
| 131 | .rpc_argp = &arg, |
| 132 | .rpc_resp = fattr, |
| 133 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | int status; |
| 135 | |
| 136 | dprintk("NFS call setattr\n"); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 137 | if (sattr->ia_valid & ATTR_FILE) |
| 138 | msg.rpc_cred = nfs_file_cred(sattr->ia_file); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 139 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 140 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 141 | if (status == 0) |
Trond Myklebust | f044636 | 2015-02-26 16:09:04 -0500 | [diff] [blame] | 142 | nfs_setattr_update_inode(inode, sattr, fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | dprintk("NFS reply setattr: %d\n", status); |
| 144 | return status; |
| 145 | } |
| 146 | |
| 147 | static int |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 148 | nfs3_proc_lookup(struct inode *dir, const struct qstr *name, |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 149 | struct nfs_fh *fhandle, struct nfs_fattr *fattr, |
| 150 | struct nfs4_label *label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | struct nfs3_diropargs arg = { |
| 153 | .fh = NFS_FH(dir), |
| 154 | .name = name->name, |
| 155 | .len = name->len |
| 156 | }; |
| 157 | struct nfs3_diropres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | .fh = fhandle, |
| 159 | .fattr = fattr |
| 160 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 161 | struct rpc_message msg = { |
| 162 | .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP], |
| 163 | .rpc_argp = &arg, |
| 164 | .rpc_resp = &res, |
| 165 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | int status; |
| 167 | |
| 168 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | e1fb4d0 | 2010-04-16 16:22:47 -0400 | [diff] [blame] | 169 | res.dir_attr = nfs_alloc_fattr(); |
| 170 | if (res.dir_attr == NULL) |
| 171 | return -ENOMEM; |
| 172 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 173 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 174 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | e1fb4d0 | 2010-04-16 16:22:47 -0400 | [diff] [blame] | 175 | nfs_refresh_inode(dir, res.dir_attr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 176 | if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) { |
| 177 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; |
| 178 | msg.rpc_argp = fhandle; |
| 179 | msg.rpc_resp = fattr; |
| 180 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 181 | } |
Trond Myklebust | e1fb4d0 | 2010-04-16 16:22:47 -0400 | [diff] [blame] | 182 | nfs_free_fattr(res.dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | dprintk("NFS reply lookup: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return status; |
| 185 | } |
| 186 | |
| 187 | static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 188 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | struct nfs3_accessargs arg = { |
| 190 | .fh = NFS_FH(inode), |
| 191 | }; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 192 | struct nfs3_accessres res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | struct rpc_message msg = { |
| 194 | .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS], |
| 195 | .rpc_argp = &arg, |
| 196 | .rpc_resp = &res, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 197 | .rpc_cred = entry->cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | }; |
| 199 | int mode = entry->mask; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 200 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | dprintk("NFS call access\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | if (mode & MAY_READ) |
| 205 | arg.access |= NFS3_ACCESS_READ; |
| 206 | if (S_ISDIR(inode->i_mode)) { |
| 207 | if (mode & MAY_WRITE) |
| 208 | arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE; |
| 209 | if (mode & MAY_EXEC) |
| 210 | arg.access |= NFS3_ACCESS_LOOKUP; |
| 211 | } else { |
| 212 | if (mode & MAY_WRITE) |
| 213 | arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND; |
| 214 | if (mode & MAY_EXEC) |
| 215 | arg.access |= NFS3_ACCESS_EXECUTE; |
| 216 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 217 | |
| 218 | res.fattr = nfs_alloc_fattr(); |
| 219 | if (res.fattr == NULL) |
| 220 | goto out; |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 223 | nfs_refresh_inode(inode, res.fattr); |
Trond Myklebust | eda3e20 | 2017-07-11 17:54:33 -0400 | [diff] [blame] | 224 | if (status == 0) |
| 225 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 226 | nfs_free_fattr(res.fattr); |
| 227 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | dprintk("NFS reply access: %d\n", status); |
| 229 | return status; |
| 230 | } |
| 231 | |
| 232 | static int nfs3_proc_readlink(struct inode *inode, struct page *page, |
| 233 | unsigned int pgbase, unsigned int pglen) |
| 234 | { |
Trond Myklebust | 3b14d65 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 235 | struct nfs_fattr *fattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | struct nfs3_readlinkargs args = { |
| 237 | .fh = NFS_FH(inode), |
| 238 | .pgbase = pgbase, |
| 239 | .pglen = pglen, |
| 240 | .pages = &page |
| 241 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 242 | struct rpc_message msg = { |
| 243 | .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK], |
| 244 | .rpc_argp = &args, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 245 | }; |
Trond Myklebust | 3b14d65 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 246 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | dprintk("NFS call readlink\n"); |
Trond Myklebust | 3b14d65 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 249 | fattr = nfs_alloc_fattr(); |
| 250 | if (fattr == NULL) |
| 251 | goto out; |
| 252 | msg.rpc_resp = fattr; |
| 253 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 254 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 3b14d65 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 255 | nfs_refresh_inode(inode, fattr); |
| 256 | nfs_free_fattr(fattr); |
| 257 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | dprintk("NFS reply readlink: %d\n", status); |
| 259 | return status; |
| 260 | } |
| 261 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 262 | struct nfs3_createdata { |
| 263 | struct rpc_message msg; |
| 264 | union { |
| 265 | struct nfs3_createargs create; |
| 266 | struct nfs3_mkdirargs mkdir; |
| 267 | struct nfs3_symlinkargs symlink; |
| 268 | struct nfs3_mknodargs mknod; |
| 269 | } arg; |
| 270 | struct nfs3_diropres res; |
| 271 | struct nfs_fh fh; |
| 272 | struct nfs_fattr fattr; |
| 273 | struct nfs_fattr dir_attr; |
| 274 | }; |
| 275 | |
| 276 | static struct nfs3_createdata *nfs3_alloc_createdata(void) |
| 277 | { |
| 278 | struct nfs3_createdata *data; |
| 279 | |
| 280 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 281 | if (data != NULL) { |
| 282 | data->msg.rpc_argp = &data->arg; |
| 283 | data->msg.rpc_resp = &data->res; |
| 284 | data->res.fh = &data->fh; |
| 285 | data->res.fattr = &data->fattr; |
| 286 | data->res.dir_attr = &data->dir_attr; |
| 287 | nfs_fattr_init(data->res.fattr); |
| 288 | nfs_fattr_init(data->res.dir_attr); |
| 289 | } |
| 290 | return data; |
| 291 | } |
| 292 | |
| 293 | static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data) |
| 294 | { |
| 295 | int status; |
| 296 | |
| 297 | status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0); |
| 298 | nfs_post_op_update_inode(dir, data->res.dir_attr); |
| 299 | if (status == 0) |
David Quigley | 1775fd3 | 2013-05-22 12:50:42 -0400 | [diff] [blame] | 300 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL); |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 301 | return status; |
| 302 | } |
| 303 | |
| 304 | static void nfs3_free_createdata(struct nfs3_createdata *data) |
| 305 | { |
| 306 | kfree(data); |
| 307 | } |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /* |
| 310 | * Create a regular file. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | */ |
| 312 | static int |
| 313 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 314 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 316 | struct posix_acl *default_acl, *acl; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 317 | struct nfs3_createdata *data; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 318 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 320 | dprintk("NFS call create %pd\n", dentry); |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 321 | |
| 322 | data = nfs3_alloc_createdata(); |
| 323 | if (data == NULL) |
| 324 | goto out; |
| 325 | |
| 326 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE]; |
| 327 | data->arg.create.fh = NFS_FH(dir); |
| 328 | data->arg.create.name = dentry->d_name.name; |
| 329 | data->arg.create.len = dentry->d_name.len; |
| 330 | data->arg.create.sattr = sattr; |
| 331 | |
| 332 | data->arg.create.createmode = NFS3_CREATE_UNCHECKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (flags & O_EXCL) { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 334 | data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE; |
Trond Myklebust | a9943d1 | 2013-08-20 21:04:11 -0400 | [diff] [blame] | 335 | data->arg.create.verifier[0] = cpu_to_be32(jiffies); |
| 336 | data->arg.create.verifier[1] = cpu_to_be32(current->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 339 | status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); |
| 340 | if (status) |
| 341 | goto out; |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 342 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 343 | for (;;) { |
| 344 | status = nfs3_do_create(dir, dentry, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 346 | if (status != -ENOTSUPP) |
| 347 | break; |
| 348 | /* If the server doesn't support the exclusive creation |
| 349 | * semantics, try again with simple 'guarded' mode. */ |
| 350 | switch (data->arg.create.createmode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | case NFS3_CREATE_EXCLUSIVE: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 352 | data->arg.create.createmode = NFS3_CREATE_GUARDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | break; |
| 354 | |
| 355 | case NFS3_CREATE_GUARDED: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 356 | data->arg.create.createmode = NFS3_CREATE_UNCHECKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | break; |
| 358 | |
| 359 | case NFS3_CREATE_UNCHECKED: |
| 360 | goto out; |
| 361 | } |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 362 | nfs_fattr_init(data->res.dir_attr); |
| 363 | nfs_fattr_init(data->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (status != 0) |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 367 | goto out_release_acls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | /* When we created the file with exclusive semantics, make |
| 370 | * sure we set the attributes afterwards. */ |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 371 | if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | dprintk("NFS call setattr (post-create)\n"); |
| 373 | |
| 374 | if (!(sattr->ia_valid & ATTR_ATIME_SET)) |
| 375 | sattr->ia_valid |= ATTR_ATIME; |
| 376 | if (!(sattr->ia_valid & ATTR_MTIME_SET)) |
| 377 | sattr->ia_valid |= ATTR_MTIME; |
| 378 | |
| 379 | /* Note: we could use a guarded setattr here, but I'm |
| 380 | * not sure this buys us anything (and I'd have |
| 381 | * to revamp the NFSv3 XDR code) */ |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 382 | status = nfs3_proc_setattr(dentry, data->res.fattr, sattr); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 383 | nfs_post_op_update_inode(d_inode(dentry), data->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | dprintk("NFS reply setattr (post-create): %d\n", status); |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 385 | if (status != 0) |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 386 | goto out_release_acls; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 388 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 389 | status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 390 | |
| 391 | out_release_acls: |
| 392 | posix_acl_release(acl); |
| 393 | posix_acl_release(default_acl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | out: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 395 | nfs3_free_createdata(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | dprintk("NFS reply create: %d\n", status); |
| 397 | return status; |
| 398 | } |
| 399 | |
| 400 | static int |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 401 | nfs3_proc_remove(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 403 | struct nfs_removeargs arg = { |
| 404 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 405 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 407 | struct nfs_removeres res; |
| 408 | struct rpc_message msg = { |
| 409 | .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE], |
| 410 | .rpc_argp = &arg, |
| 411 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 413 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | dprintk("NFS call remove %s\n", name->name); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 416 | res.dir_attr = nfs_alloc_fattr(); |
| 417 | if (res.dir_attr == NULL) |
| 418 | goto out; |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 421 | nfs_post_op_update_inode(dir, res.dir_attr); |
| 422 | nfs_free_fattr(res.dir_attr); |
| 423 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | dprintk("NFS reply remove: %d\n", status); |
| 425 | return status; |
| 426 | } |
| 427 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 428 | static void |
| 429 | nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 434 | static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 435 | { |
| 436 | rpc_call_start(task); |
| 437 | } |
| 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | static int |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 440 | nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 442 | struct nfs_removeres *res; |
| 443 | if (nfs3_async_handle_jukebox(task, dir)) |
| 444 | return 0; |
| 445 | res = task->tk_msg.rpc_resp; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 446 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 447 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 450 | static void |
| 451 | nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 452 | { |
| 453 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME]; |
| 454 | } |
| 455 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 456 | static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 457 | { |
| 458 | rpc_call_start(task); |
| 459 | } |
| 460 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 461 | static int |
| 462 | nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 463 | struct inode *new_dir) |
| 464 | { |
| 465 | struct nfs_renameres *res; |
| 466 | |
| 467 | if (nfs3_async_handle_jukebox(task, old_dir)) |
| 468 | return 0; |
| 469 | res = task->tk_msg.rpc_resp; |
| 470 | |
| 471 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 472 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 473 | return 1; |
| 474 | } |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | static int |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 477 | nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | struct nfs3_linkargs arg = { |
| 480 | .fromfh = NFS_FH(inode), |
| 481 | .tofh = NFS_FH(dir), |
| 482 | .toname = name->name, |
| 483 | .tolen = name->len |
| 484 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 485 | struct nfs3_linkres res; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 486 | struct rpc_message msg = { |
| 487 | .rpc_proc = &nfs3_procedures[NFS3PROC_LINK], |
| 488 | .rpc_argp = &arg, |
| 489 | .rpc_resp = &res, |
| 490 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 491 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | dprintk("NFS call link %s\n", name->name); |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 494 | res.fattr = nfs_alloc_fattr(); |
| 495 | res.dir_attr = nfs_alloc_fattr(); |
| 496 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 497 | goto out; |
| 498 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 499 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 500 | nfs_post_op_update_inode(dir, res.dir_attr); |
| 501 | nfs_post_op_update_inode(inode, res.fattr); |
| 502 | out: |
| 503 | nfs_free_fattr(res.dir_attr); |
| 504 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | dprintk("NFS reply link: %d\n", status); |
| 506 | return status; |
| 507 | } |
| 508 | |
| 509 | static int |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 510 | nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
| 511 | unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 513 | struct nfs3_createdata *data; |
| 514 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 516 | if (len > NFS3_MAXPATHLEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | return -ENAMETOOLONG; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 518 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 519 | dprintk("NFS call symlink %pd\n", dentry); |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 520 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 521 | data = nfs3_alloc_createdata(); |
| 522 | if (data == NULL) |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 523 | goto out; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 524 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK]; |
| 525 | data->arg.symlink.fromfh = NFS_FH(dir); |
| 526 | data->arg.symlink.fromname = dentry->d_name.name; |
| 527 | data->arg.symlink.fromlen = dentry->d_name.len; |
| 528 | data->arg.symlink.pages = &page; |
| 529 | data->arg.symlink.pathlen = len; |
| 530 | data->arg.symlink.sattr = sattr; |
| 531 | |
| 532 | status = nfs3_do_create(dir, dentry, data); |
| 533 | |
| 534 | nfs3_free_createdata(data); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 535 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | dprintk("NFS reply symlink: %d\n", status); |
| 537 | return status; |
| 538 | } |
| 539 | |
| 540 | static int |
| 541 | nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 542 | { |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 543 | struct posix_acl *default_acl, *acl; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 544 | struct nfs3_createdata *data; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 545 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 547 | dprintk("NFS call mkdir %pd\n", dentry); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 548 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 549 | data = nfs3_alloc_createdata(); |
| 550 | if (data == NULL) |
| 551 | goto out; |
| 552 | |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 553 | status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); |
| 554 | if (status) |
| 555 | goto out; |
| 556 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 557 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR]; |
| 558 | data->arg.mkdir.fh = NFS_FH(dir); |
| 559 | data->arg.mkdir.name = dentry->d_name.name; |
| 560 | data->arg.mkdir.len = dentry->d_name.len; |
| 561 | data->arg.mkdir.sattr = sattr; |
| 562 | |
| 563 | status = nfs3_do_create(dir, dentry, data); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 564 | if (status != 0) |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 565 | goto out_release_acls; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 566 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 567 | status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 568 | |
| 569 | out_release_acls: |
| 570 | posix_acl_release(acl); |
| 571 | posix_acl_release(default_acl); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 572 | out: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 573 | nfs3_free_createdata(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | dprintk("NFS reply mkdir: %d\n", status); |
| 575 | return status; |
| 576 | } |
| 577 | |
| 578 | static int |
Al Viro | beffb8f | 2016-07-20 16:34:42 -0400 | [diff] [blame] | 579 | nfs3_proc_rmdir(struct inode *dir, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
Trond Myklebust | 39967dd | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 581 | struct nfs_fattr *dir_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | struct nfs3_diropargs arg = { |
| 583 | .fh = NFS_FH(dir), |
| 584 | .name = name->name, |
| 585 | .len = name->len |
| 586 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 587 | struct rpc_message msg = { |
| 588 | .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR], |
| 589 | .rpc_argp = &arg, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 590 | }; |
Trond Myklebust | 39967dd | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 591 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
| 593 | dprintk("NFS call rmdir %s\n", name->name); |
Trond Myklebust | 39967dd | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 594 | dir_attr = nfs_alloc_fattr(); |
| 595 | if (dir_attr == NULL) |
| 596 | goto out; |
| 597 | |
| 598 | msg.rpc_resp = dir_attr; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 599 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | 39967dd | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 600 | nfs_post_op_update_inode(dir, dir_attr); |
| 601 | nfs_free_fattr(dir_attr); |
| 602 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | dprintk("NFS reply rmdir: %d\n", status); |
| 604 | return status; |
| 605 | } |
| 606 | |
| 607 | /* |
| 608 | * The READDIR implementation is somewhat hackish - we pass the user buffer |
| 609 | * to the encode function, which installs it in the receive iovec. |
| 610 | * The decode function itself doesn't perform any decoding, it just makes |
| 611 | * sure the reply is syntactically correct. |
| 612 | * |
| 613 | * Also note that this implementation handles both plain readdir and |
| 614 | * readdirplus. |
| 615 | */ |
| 616 | static int |
| 617 | nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Benjamin Coddington | a7a3b1e | 2017-06-20 08:33:44 -0400 | [diff] [blame] | 618 | u64 cookie, struct page **pages, unsigned int count, bool plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 620 | struct inode *dir = d_inode(dentry); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 621 | __be32 *verf = NFS_I(dir)->cookieverf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | struct nfs3_readdirargs arg = { |
| 623 | .fh = NFS_FH(dir), |
| 624 | .cookie = cookie, |
| 625 | .verf = {verf[0], verf[1]}, |
| 626 | .plus = plus, |
| 627 | .count = count, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 628 | .pages = pages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | }; |
| 630 | struct nfs3_readdirres res = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | .verf = verf, |
| 632 | .plus = plus |
| 633 | }; |
| 634 | struct rpc_message msg = { |
| 635 | .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR], |
| 636 | .rpc_argp = &arg, |
| 637 | .rpc_resp = &res, |
| 638 | .rpc_cred = cred |
| 639 | }; |
Trond Myklebust | aa49b4c | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 640 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | if (plus) |
| 643 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; |
| 644 | |
| 645 | dprintk("NFS call readdir%s %d\n", |
| 646 | plus? "plus" : "", (unsigned int) cookie); |
| 647 | |
Trond Myklebust | aa49b4c | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 648 | res.dir_attr = nfs_alloc_fattr(); |
| 649 | if (res.dir_attr == NULL) |
| 650 | goto out; |
| 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 653 | |
| 654 | nfs_invalidate_atime(dir); |
Trond Myklebust | aa49b4c | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 655 | nfs_refresh_inode(dir, res.dir_attr); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 656 | |
Trond Myklebust | aa49b4c | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 657 | nfs_free_fattr(res.dir_attr); |
| 658 | out: |
Chuck Lever | d141d97 | 2010-09-21 16:55:47 -0400 | [diff] [blame] | 659 | dprintk("NFS reply readdir%s: %d\n", |
| 660 | plus? "plus" : "", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return status; |
| 662 | } |
| 663 | |
| 664 | static int |
| 665 | nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
| 666 | dev_t rdev) |
| 667 | { |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 668 | struct posix_acl *default_acl, *acl; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 669 | struct nfs3_createdata *data; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 670 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Al Viro | 6de1472 | 2013-09-16 10:53:17 -0400 | [diff] [blame] | 672 | dprintk("NFS call mknod %pd %u:%u\n", dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | MAJOR(rdev), MINOR(rdev)); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 674 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 675 | data = nfs3_alloc_createdata(); |
| 676 | if (data == NULL) |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 677 | goto out; |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 678 | |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 679 | status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); |
| 680 | if (status) |
| 681 | goto out; |
| 682 | |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 683 | data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD]; |
| 684 | data->arg.mknod.fh = NFS_FH(dir); |
| 685 | data->arg.mknod.name = dentry->d_name.name; |
| 686 | data->arg.mknod.len = dentry->d_name.len; |
| 687 | data->arg.mknod.sattr = sattr; |
| 688 | data->arg.mknod.rdev = rdev; |
| 689 | |
| 690 | switch (sattr->ia_mode & S_IFMT) { |
| 691 | case S_IFBLK: |
| 692 | data->arg.mknod.type = NF3BLK; |
| 693 | break; |
| 694 | case S_IFCHR: |
| 695 | data->arg.mknod.type = NF3CHR; |
| 696 | break; |
| 697 | case S_IFIFO: |
| 698 | data->arg.mknod.type = NF3FIFO; |
| 699 | break; |
| 700 | case S_IFSOCK: |
| 701 | data->arg.mknod.type = NF3SOCK; |
| 702 | break; |
| 703 | default: |
| 704 | status = -EINVAL; |
| 705 | goto out; |
| 706 | } |
| 707 | |
| 708 | status = nfs3_do_create(dir, dentry, data); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 709 | if (status != 0) |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 710 | goto out_release_acls; |
| 711 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 712 | status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 713 | |
| 714 | out_release_acls: |
| 715 | posix_acl_release(acl); |
| 716 | posix_acl_release(default_acl); |
Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 717 | out: |
Trond Myklebust | 0b4aae7 | 2008-06-20 17:00:23 -0400 | [diff] [blame] | 718 | nfs3_free_createdata(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | dprintk("NFS reply mknod: %d\n", status); |
| 720 | return status; |
| 721 | } |
| 722 | |
| 723 | static int |
| 724 | nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 725 | struct nfs_fsstat *stat) |
| 726 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 727 | struct rpc_message msg = { |
| 728 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT], |
| 729 | .rpc_argp = fhandle, |
| 730 | .rpc_resp = stat, |
| 731 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | int status; |
| 733 | |
| 734 | dprintk("NFS call fsstat\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 735 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 736 | status = rpc_call_sync(server->client, &msg, 0); |
Chuck Lever | d141d97 | 2010-09-21 16:55:47 -0400 | [diff] [blame] | 737 | dprintk("NFS reply fsstat: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return status; |
| 739 | } |
| 740 | |
| 741 | static int |
EG Keizer | 37ca8f5 | 2008-08-19 16:34:36 -0400 | [diff] [blame] | 742 | do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | struct nfs_fsinfo *info) |
| 744 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 745 | struct rpc_message msg = { |
| 746 | .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], |
| 747 | .rpc_argp = fhandle, |
| 748 | .rpc_resp = info, |
| 749 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | int status; |
| 751 | |
| 752 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 753 | nfs_fattr_init(info->fattr); |
EG Keizer | 37ca8f5 | 2008-08-19 16:34:36 -0400 | [diff] [blame] | 754 | status = rpc_call_sync(client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | dprintk("NFS reply fsinfo: %d\n", status); |
| 756 | return status; |
| 757 | } |
| 758 | |
EG Keizer | 37ca8f5 | 2008-08-19 16:34:36 -0400 | [diff] [blame] | 759 | /* |
| 760 | * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via |
| 761 | * nfs_create_server |
| 762 | */ |
| 763 | static int |
| 764 | nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 765 | struct nfs_fsinfo *info) |
| 766 | { |
| 767 | int status; |
| 768 | |
| 769 | status = do_proc_fsinfo(server->client, fhandle, info); |
| 770 | if (status && server->nfs_client->cl_rpcclient != server->client) |
| 771 | status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info); |
| 772 | return status; |
| 773 | } |
| 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | static int |
| 776 | nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 777 | struct nfs_pathconf *info) |
| 778 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 779 | struct rpc_message msg = { |
| 780 | .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF], |
| 781 | .rpc_argp = fhandle, |
| 782 | .rpc_resp = info, |
| 783 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | int status; |
| 785 | |
| 786 | dprintk("NFS call pathconf\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 787 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 788 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | dprintk("NFS reply pathconf: %d\n", status); |
| 790 | return status; |
| 791 | } |
| 792 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 793 | static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 795 | struct inode *inode = hdr->inode; |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 796 | |
Trond Myklebust | 16cecdf | 2014-06-22 12:55:11 -0400 | [diff] [blame] | 797 | if (hdr->pgio_done_cb != NULL) |
| 798 | return hdr->pgio_done_cb(task, hdr); |
| 799 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 800 | if (nfs3_async_handle_jukebox(task, inode)) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 801 | return -EAGAIN; |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 802 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 803 | nfs_invalidate_atime(inode); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 804 | nfs_refresh_inode(inode, &hdr->fattr); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 805 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 808 | static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr, |
| 809 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 811 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 814 | static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task, |
| 815 | struct nfs_pgio_header *hdr) |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 816 | { |
| 817 | rpc_call_start(task); |
NeilBrown | ef1820f | 2013-09-04 17:04:49 +1000 | [diff] [blame] | 818 | return 0; |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 819 | } |
| 820 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 821 | static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 823 | struct inode *inode = hdr->inode; |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 824 | |
Trond Myklebust | 16cecdf | 2014-06-22 12:55:11 -0400 | [diff] [blame] | 825 | if (hdr->pgio_done_cb != NULL) |
| 826 | return hdr->pgio_done_cb(task, hdr); |
| 827 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 828 | if (nfs3_async_handle_jukebox(task, inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 829 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | if (task->tk_status >= 0) |
Trond Myklebust | a08a8cd | 2015-02-26 17:36:09 -0500 | [diff] [blame] | 831 | nfs_writeback_update_inode(hdr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 832 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 835 | static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr, |
| 836 | struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 838 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 841 | static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 842 | { |
| 843 | rpc_call_start(task); |
| 844 | } |
| 845 | |
| 846 | static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
Trond Myklebust | 16cecdf | 2014-06-22 12:55:11 -0400 | [diff] [blame] | 848 | if (data->commit_done_cb != NULL) |
| 849 | return data->commit_done_cb(task, data); |
| 850 | |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 851 | if (nfs3_async_handle_jukebox(task, data->inode)) |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 852 | return -EAGAIN; |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 853 | nfs_refresh_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 854 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 857 | static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 859 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Trond Myklebust | bb3393d | 2017-04-25 16:25:06 -0400 | [diff] [blame] | 862 | static void nfs3_nlm_alloc_call(void *data) |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 863 | { |
| 864 | struct nfs_lock_context *l_ctx = data; |
| 865 | if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) { |
| 866 | get_nfs_open_context(l_ctx->open_context); |
| 867 | nfs_get_lock_context(l_ctx->open_context); |
| 868 | } |
| 869 | } |
| 870 | |
Trond Myklebust | bb3393d | 2017-04-25 16:25:06 -0400 | [diff] [blame] | 871 | static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data) |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 872 | { |
| 873 | struct nfs_lock_context *l_ctx = data; |
| 874 | if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) |
| 875 | return nfs_async_iocounter_wait(task, l_ctx); |
| 876 | return false; |
| 877 | |
| 878 | } |
| 879 | |
Trond Myklebust | bb3393d | 2017-04-25 16:25:06 -0400 | [diff] [blame] | 880 | static void nfs3_nlm_release_call(void *data) |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 881 | { |
| 882 | struct nfs_lock_context *l_ctx = data; |
| 883 | struct nfs_open_context *ctx; |
| 884 | if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) { |
| 885 | ctx = l_ctx->open_context; |
| 886 | nfs_put_lock_context(l_ctx); |
| 887 | put_nfs_open_context(ctx); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = { |
| 892 | .nlmclnt_alloc_call = nfs3_nlm_alloc_call, |
| 893 | .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare, |
| 894 | .nlmclnt_release_call = nfs3_nlm_release_call, |
| 895 | }; |
| 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | static int |
| 898 | nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 899 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 900 | struct inode *inode = file_inode(filp); |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 901 | struct nfs_lock_context *l_ctx = NULL; |
| 902 | struct nfs_open_context *ctx = nfs_file_open_context(filp); |
| 903 | int status; |
Chuck Lever | 1093a60 | 2008-01-11 17:09:59 -0500 | [diff] [blame] | 904 | |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 905 | if (fl->fl_flags & FL_CLOSE) { |
| 906 | l_ctx = nfs_get_lock_context(ctx); |
| 907 | if (IS_ERR(l_ctx)) |
| 908 | l_ctx = NULL; |
| 909 | else |
| 910 | set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); |
| 911 | } |
| 912 | |
| 913 | status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx); |
| 914 | |
| 915 | if (l_ctx) |
| 916 | nfs_put_lock_context(l_ctx); |
| 917 | |
| 918 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 921 | static int nfs3_have_delegation(struct inode *inode, fmode_t flags) |
| 922 | { |
| 923 | return 0; |
| 924 | } |
| 925 | |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 926 | static int nfs3_return_delegation(struct inode *inode) |
| 927 | { |
| 928 | nfs_wb_all(inode); |
| 929 | return 0; |
| 930 | } |
| 931 | |
Bryan Schumaker | ab96291 | 2012-07-16 16:39:11 -0400 | [diff] [blame] | 932 | static const struct inode_operations nfs3_dir_inode_operations = { |
| 933 | .create = nfs_create, |
| 934 | .lookup = nfs_lookup, |
| 935 | .link = nfs_link, |
| 936 | .unlink = nfs_unlink, |
| 937 | .symlink = nfs_symlink, |
| 938 | .mkdir = nfs_mkdir, |
| 939 | .rmdir = nfs_rmdir, |
| 940 | .mknod = nfs_mknod, |
| 941 | .rename = nfs_rename, |
| 942 | .permission = nfs_permission, |
| 943 | .getattr = nfs_getattr, |
| 944 | .setattr = nfs_setattr, |
Christoph Hellwig | 5f13ee9 | 2014-01-30 06:01:52 -0800 | [diff] [blame] | 945 | #ifdef CONFIG_NFS_V3_ACL |
Christoph Hellwig | 74adf83 | 2014-06-18 11:07:03 +0200 | [diff] [blame] | 946 | .listxattr = nfs3_listxattr, |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 947 | .get_acl = nfs3_get_acl, |
| 948 | .set_acl = nfs3_set_acl, |
| 949 | #endif |
Bryan Schumaker | ab96291 | 2012-07-16 16:39:11 -0400 | [diff] [blame] | 950 | }; |
| 951 | |
| 952 | static const struct inode_operations nfs3_file_inode_operations = { |
| 953 | .permission = nfs_permission, |
| 954 | .getattr = nfs_getattr, |
| 955 | .setattr = nfs_setattr, |
Christoph Hellwig | 5f13ee9 | 2014-01-30 06:01:52 -0800 | [diff] [blame] | 956 | #ifdef CONFIG_NFS_V3_ACL |
Christoph Hellwig | 74adf83 | 2014-06-18 11:07:03 +0200 | [diff] [blame] | 957 | .listxattr = nfs3_listxattr, |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 958 | .get_acl = nfs3_get_acl, |
| 959 | .set_acl = nfs3_set_acl, |
| 960 | #endif |
Bryan Schumaker | ab96291 | 2012-07-16 16:39:11 -0400 | [diff] [blame] | 961 | }; |
| 962 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 963 | const struct nfs_rpc_ops nfs_v3_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | .version = 3, /* protocol version */ |
| 965 | .dentry_ops = &nfs_dentry_operations, |
Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 966 | .dir_inode_ops = &nfs3_dir_inode_operations, |
| 967 | .file_inode_ops = &nfs3_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 968 | .file_ops = &nfs_file_operations, |
Benjamin Coddington | f30cb75 | 2017-04-11 12:50:12 -0400 | [diff] [blame] | 969 | .nlmclnt_ops = &nlmclnt_fl_close_lock_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | .getroot = nfs3_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 971 | .submount = nfs_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 972 | .try_mount = nfs_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | .getattr = nfs3_proc_getattr, |
| 974 | .setattr = nfs3_proc_setattr, |
| 975 | .lookup = nfs3_proc_lookup, |
| 976 | .access = nfs3_proc_access, |
| 977 | .readlink = nfs3_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | .create = nfs3_proc_create, |
| 979 | .remove = nfs3_proc_remove, |
| 980 | .unlink_setup = nfs3_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 981 | .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | .unlink_done = nfs3_proc_unlink_done, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 983 | .rename_setup = nfs3_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 984 | .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 985 | .rename_done = nfs3_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | .link = nfs3_proc_link, |
| 987 | .symlink = nfs3_proc_symlink, |
| 988 | .mkdir = nfs3_proc_mkdir, |
| 989 | .rmdir = nfs3_proc_rmdir, |
| 990 | .readdir = nfs3_proc_readdir, |
| 991 | .mknod = nfs3_proc_mknod, |
| 992 | .statfs = nfs3_proc_statfs, |
| 993 | .fsinfo = nfs3_proc_fsinfo, |
| 994 | .pathconf = nfs3_proc_pathconf, |
| 995 | .decode_dirent = nfs3_decode_dirent, |
Anna Schumaker | a4cdda5 | 2014-05-06 09:12:31 -0400 | [diff] [blame] | 996 | .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | .read_setup = nfs3_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 998 | .read_done = nfs3_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | .write_setup = nfs3_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1000 | .write_done = nfs3_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | .commit_setup = nfs3_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 1002 | .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 1003 | .commit_done = nfs3_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | .lock = nfs3_proc_lock, |
Christoph Hellwig | 013cdf1 | 2013-12-20 05:16:53 -0800 | [diff] [blame] | 1005 | .clear_acl_cache = forget_all_cached_acls, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 1006 | .close_context = nfs_close_context, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 1007 | .have_delegation = nfs3_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1008 | .return_delegation = nfs3_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 1009 | .alloc_client = nfs_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 1010 | .init_client = nfs_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 1011 | .free_client = nfs_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 1012 | .create_server = nfs3_create_server, |
| 1013 | .clone_server = nfs3_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | }; |