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