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