blob: a2e9e09c37723e83a7ef6610c93e643f2bec0eed [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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 Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/errno.h>
12#include <linux/string.h>
13#include <linux/sunrpc/clnt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#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 Gruenbacherb7fa0552005-06-22 17:16:27 +000020#include <linux/nfs_mount.h>
Jeff Laytond3103102011-12-01 22:44:39 +010021#include <linux/freezer.h>
Tejun Heo0a6be652014-02-03 14:31:07 -050022#include <linux/xattr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Chuck Lever006ea732006-03-20 13:44:14 -050024#include "iostat.h"
David Howellsf7b422b2006-06-09 09:34:33 -040025#include "internal.h"
Anna Schumaker00a36a102014-09-03 12:19:08 -040026#include "nfs3_fs.h"
Chuck Lever006ea732006-03-20 13:44:14 -050027
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define NFSDBG_FACILITY NFSDBG_PROC
29
Andy Adamsoneb96d5c2012-11-27 10:34:19 -050030/* A wrapper to handle the EJUKEBOX error messages */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static int
32nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
33{
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 do {
36 res = rpc_call_sync(clnt, msg, flags);
Andy Adamsoneb96d5c2012-11-27 10:34:19 -050037 if (res != -EJUKEBOX)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 break;
Colin Cross416ad3c2013-05-06 23:50:06 +000039 freezable_schedule_timeout_killable_unsafe(NFS_JUKEBOX_RETRY_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 res = -ERESTARTSYS;
Matthew Wilcox150030b2007-12-06 16:24:39 -050041 } while (!fatal_signal_pending(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 return res;
43}
44
Chuck Leverdead28d2006-03-20 13:44:23 -050045#define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47static int
Chuck Lever006ea732006-03-20 13:44:14 -050048nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Andy Adamsoneb96d5c2012-11-27 10:34:19 -050050 if (task->tk_status != -EJUKEBOX)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 return 0;
Jeff Laytonb68d69b2010-01-07 09:42:04 -050052 if (task->tk_status == -EJUKEBOX)
53 nfs_inc_stats(inode, NFSIOS_DELAY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 task->tk_status = 0;
55 rpc_restart_call(task);
56 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
57 return 1;
58}
59
J. Bruce Fields03c21732006-01-03 09:55:48 +010060static int
61do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
62 struct nfs_fsinfo *info)
63{
Chuck Leverdead28d2006-03-20 13:44:23 -050064 struct rpc_message msg = {
65 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
66 .rpc_argp = fhandle,
67 .rpc_resp = info,
68 };
J. Bruce Fields03c21732006-01-03 09:55:48 +010069 int status;
70
Harvey Harrison3110ff82008-05-02 13:42:44 -070071 dprintk("%s: call fsinfo\n", __func__);
J. Bruce Fields03c21732006-01-03 09:55:48 +010072 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -050073 status = rpc_call_sync(client, &msg, 0);
Harvey Harrison3110ff82008-05-02 13:42:44 -070074 dprintk("%s: reply fsinfo: %d\n", __func__, status);
Trond Myklebust08660042012-08-20 12:42:15 -040075 if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) {
Chuck Leverdead28d2006-03-20 13:44:23 -050076 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
77 msg.rpc_resp = info->fattr;
78 status = rpc_call_sync(client, &msg, 0);
Harvey Harrison3110ff82008-05-02 13:42:44 -070079 dprintk("%s: reply getattr: %d\n", __func__, status);
J. Bruce Fields03c21732006-01-03 09:55:48 +010080 }
81 return status;
82}
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
David Howells54ceac42006-08-22 20:06:13 -040085 * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
87static int
88nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
89 struct nfs_fsinfo *info)
90{
91 int status;
92
J. Bruce Fields03c21732006-01-03 09:55:48 +010093 status = do_proc_get_root(server->client, fhandle, info);
David Howells5006a762006-08-22 20:06:12 -040094 if (status && server->nfs_client->cl_rpcclient != server->client)
95 status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return status;
97}
98
99/*
100 * One function for each procedure in the NFS protocol.
101 */
102static int
103nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
Trond Myklebusta841b542018-04-07 13:50:59 -0400104 struct nfs_fattr *fattr, struct nfs4_label *label,
105 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Chuck Leverdead28d2006-03-20 13:44:23 -0500107 struct rpc_message msg = {
108 .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
109 .rpc_argp = fhandle,
110 .rpc_resp = fattr,
111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 int status;
113
114 dprintk("NFS call getattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400115 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500116 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 dprintk("NFS reply getattr: %d\n", status);
118 return status;
119}
120
121static int
122nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
123 struct iattr *sattr)
124{
David Howells2b0143b2015-03-17 22:25:59 +0000125 struct inode *inode = d_inode(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 struct nfs3_sattrargs arg = {
127 .fh = NFS_FH(inode),
128 .sattr = sattr,
129 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500130 struct rpc_message msg = {
131 .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
132 .rpc_argp = &arg,
133 .rpc_resp = fattr,
134 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 int status;
136
137 dprintk("NFS call setattr\n");
Trond Myklebust659bfcd2008-06-10 19:39:41 -0400138 if (sattr->ia_valid & ATTR_FILE)
139 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400140 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500141 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
chendtdbc898a2018-03-29 16:13:09 +0800142 if (status == 0) {
143 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
144 nfs_zap_acl_cache(inode);
Trond Myklebustf0446362015-02-26 16:09:04 -0500145 nfs_setattr_update_inode(inode, sattr, fattr);
chendtdbc898a2018-03-29 16:13:09 +0800146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 dprintk("NFS reply setattr: %d\n", status);
148 return status;
149}
150
151static int
Al Virobeffb8f2016-07-20 16:34:42 -0400152nfs3_proc_lookup(struct inode *dir, const struct qstr *name,
David Quigley1775fd32013-05-22 12:50:42 -0400153 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
154 struct nfs4_label *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 struct nfs3_diropargs arg = {
157 .fh = NFS_FH(dir),
158 .name = name->name,
159 .len = name->len
160 };
161 struct nfs3_diropres res = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 .fh = fhandle,
163 .fattr = fattr
164 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500165 struct rpc_message msg = {
166 .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
167 .rpc_argp = &arg,
168 .rpc_resp = &res,
169 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 int status;
171
172 dprintk("NFS call lookup %s\n", name->name);
Trond Myklebuste1fb4d02010-04-16 16:22:47 -0400173 res.dir_attr = nfs_alloc_fattr();
174 if (res.dir_attr == NULL)
175 return -ENOMEM;
176
Trond Myklebust0e574af2005-10-27 22:12:38 -0400177 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500178 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebuste1fb4d02010-04-16 16:22:47 -0400179 nfs_refresh_inode(dir, res.dir_attr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500180 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
181 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
182 msg.rpc_argp = fhandle;
183 msg.rpc_resp = fattr;
184 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
185 }
Trond Myklebuste1fb4d02010-04-16 16:22:47 -0400186 nfs_free_fattr(res.dir_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 dprintk("NFS reply lookup: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 return status;
189}
190
191static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
192{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 struct nfs3_accessargs arg = {
194 .fh = NFS_FH(inode),
Anna Schumaker1750d922017-07-26 12:00:21 -0400195 .access = entry->mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 };
Trond Myklebustc407d412010-04-16 16:22:48 -0400197 struct nfs3_accessres res;
NeilBrownb68572e2018-12-03 11:30:30 +1100198 struct auth_cred acred = {
199 .cred = entry->cred,
200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 struct rpc_message msg = {
202 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
203 .rpc_argp = &arg,
204 .rpc_resp = &res,
NeilBrownb68572e2018-12-03 11:30:30 +1100205 .rpc_cred = rpc_lookup_generic_cred(&acred, 0, GFP_NOFS),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 };
Trond Myklebustc407d412010-04-16 16:22:48 -0400207 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 dprintk("NFS call access\n");
NeilBrownb68572e2018-12-03 11:30:30 +1100210 if (!msg.rpc_cred)
211 goto out;
Trond Myklebustc407d412010-04-16 16:22:48 -0400212 res.fattr = nfs_alloc_fattr();
213 if (res.fattr == NULL)
214 goto out;
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebustc407d412010-04-16 16:22:48 -0400217 nfs_refresh_inode(inode, res.fattr);
Trond Myklebusteda3e202017-07-11 17:54:33 -0400218 if (status == 0)
219 nfs_access_set_mask(entry, res.access);
Trond Myklebustc407d412010-04-16 16:22:48 -0400220 nfs_free_fattr(res.fattr);
221out:
NeilBrownb68572e2018-12-03 11:30:30 +1100222 if (msg.rpc_cred)
223 put_rpccred(msg.rpc_cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 dprintk("NFS reply access: %d\n", status);
225 return status;
226}
227
228static int nfs3_proc_readlink(struct inode *inode, struct page *page,
229 unsigned int pgbase, unsigned int pglen)
230{
Trond Myklebust3b14d652010-04-16 16:22:50 -0400231 struct nfs_fattr *fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 struct nfs3_readlinkargs args = {
233 .fh = NFS_FH(inode),
234 .pgbase = pgbase,
235 .pglen = pglen,
236 .pages = &page
237 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500238 struct rpc_message msg = {
239 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
240 .rpc_argp = &args,
Chuck Leverdead28d2006-03-20 13:44:23 -0500241 };
Trond Myklebust3b14d652010-04-16 16:22:50 -0400242 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 dprintk("NFS call readlink\n");
Trond Myklebust3b14d652010-04-16 16:22:50 -0400245 fattr = nfs_alloc_fattr();
246 if (fattr == NULL)
247 goto out;
248 msg.rpc_resp = fattr;
249
Chuck Leverdead28d2006-03-20 13:44:23 -0500250 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust3b14d652010-04-16 16:22:50 -0400251 nfs_refresh_inode(inode, fattr);
252 nfs_free_fattr(fattr);
253out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 dprintk("NFS reply readlink: %d\n", status);
255 return status;
256}
257
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400258struct nfs3_createdata {
259 struct rpc_message msg;
260 union {
261 struct nfs3_createargs create;
262 struct nfs3_mkdirargs mkdir;
263 struct nfs3_symlinkargs symlink;
264 struct nfs3_mknodargs mknod;
265 } arg;
266 struct nfs3_diropres res;
267 struct nfs_fh fh;
268 struct nfs_fattr fattr;
269 struct nfs_fattr dir_attr;
270};
271
272static struct nfs3_createdata *nfs3_alloc_createdata(void)
273{
274 struct nfs3_createdata *data;
275
276 data = kzalloc(sizeof(*data), GFP_KERNEL);
277 if (data != NULL) {
278 data->msg.rpc_argp = &data->arg;
279 data->msg.rpc_resp = &data->res;
280 data->res.fh = &data->fh;
281 data->res.fattr = &data->fattr;
282 data->res.dir_attr = &data->dir_attr;
283 nfs_fattr_init(data->res.fattr);
284 nfs_fattr_init(data->res.dir_attr);
285 }
286 return data;
287}
288
289static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
290{
291 int status;
292
293 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
294 nfs_post_op_update_inode(dir, data->res.dir_attr);
295 if (status == 0)
David Quigley1775fd32013-05-22 12:50:42 -0400296 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400297 return status;
298}
299
300static void nfs3_free_createdata(struct nfs3_createdata *data)
301{
302 kfree(data);
303}
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305/*
306 * Create a regular file.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 */
308static int
309nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Miklos Szeredi8867fe52012-06-05 15:10:19 +0200310 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800312 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400313 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400314 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Al Viro6de14722013-09-16 10:53:17 -0400316 dprintk("NFS call create %pd\n", dentry);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400317
318 data = nfs3_alloc_createdata();
319 if (data == NULL)
320 goto out;
321
322 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
323 data->arg.create.fh = NFS_FH(dir);
324 data->arg.create.name = dentry->d_name.name;
325 data->arg.create.len = dentry->d_name.len;
326 data->arg.create.sattr = sattr;
327
328 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 if (flags & O_EXCL) {
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400330 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
Trond Myklebusta9943d12013-08-20 21:04:11 -0400331 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
332 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800335 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
336 if (status)
337 goto out;
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000338
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400339 for (;;) {
340 status = nfs3_do_create(dir, dentry, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400342 if (status != -ENOTSUPP)
343 break;
344 /* If the server doesn't support the exclusive creation
345 * semantics, try again with simple 'guarded' mode. */
346 switch (data->arg.create.createmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 case NFS3_CREATE_EXCLUSIVE:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400348 data->arg.create.createmode = NFS3_CREATE_GUARDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 break;
350
351 case NFS3_CREATE_GUARDED:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400352 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 break;
354
355 case NFS3_CREATE_UNCHECKED:
356 goto out;
357 }
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400358 nfs_fattr_init(data->res.dir_attr);
359 nfs_fattr_init(data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800363 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 /* When we created the file with exclusive semantics, make
366 * sure we set the attributes afterwards. */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400367 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 dprintk("NFS call setattr (post-create)\n");
369
370 if (!(sattr->ia_valid & ATTR_ATIME_SET))
371 sattr->ia_valid |= ATTR_ATIME;
372 if (!(sattr->ia_valid & ATTR_MTIME_SET))
373 sattr->ia_valid |= ATTR_MTIME;
374
375 /* Note: we could use a guarded setattr here, but I'm
376 * not sure this buys us anything (and I'd have
377 * to revamp the NFSv3 XDR code) */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400378 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
David Howells2b0143b2015-03-17 22:25:59 +0000379 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 dprintk("NFS reply setattr (post-create): %d\n", status);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400381 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800382 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800384
David Howells2b0143b2015-03-17 22:25:59 +0000385 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800386
387out_release_acls:
388 posix_acl_release(acl);
389 posix_acl_release(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400391 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 dprintk("NFS reply create: %d\n", status);
393 return status;
394}
395
396static int
Trond Myklebust912678d2018-03-20 16:43:15 -0400397nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400399 struct nfs_removeargs arg = {
400 .fh = NFS_FH(dir),
Trond Myklebust912678d2018-03-20 16:43:15 -0400401 .name = dentry->d_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 };
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400403 struct nfs_removeres res;
404 struct rpc_message msg = {
405 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
406 .rpc_argp = &arg,
407 .rpc_resp = &res,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 };
Trond Myklebustd3468902010-04-16 16:22:50 -0400409 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Trond Myklebust912678d2018-03-20 16:43:15 -0400411 dprintk("NFS call remove %pd2\n", dentry);
Trond Myklebustd3468902010-04-16 16:22:50 -0400412 res.dir_attr = nfs_alloc_fattr();
413 if (res.dir_attr == NULL)
414 goto out;
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustd3468902010-04-16 16:22:50 -0400417 nfs_post_op_update_inode(dir, res.dir_attr);
418 nfs_free_fattr(res.dir_attr);
419out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 dprintk("NFS reply remove: %d\n", status);
421 return status;
422}
423
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400424static void
Trond Myklebusted7e9ad2018-05-30 16:11:52 -0400425nfs3_proc_unlink_setup(struct rpc_message *msg,
426 struct dentry *dentry,
427 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400432static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
433{
434 rpc_call_start(task);
435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437static int
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400438nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400440 struct nfs_removeres *res;
441 if (nfs3_async_handle_jukebox(task, dir))
442 return 0;
443 res = task->tk_msg.rpc_resp;
Trond Myklebustd3468902010-04-16 16:22:50 -0400444 nfs_post_op_update_inode(dir, res->dir_attr);
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400445 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Jeff Laytond3d41522010-09-17 17:31:57 -0400448static void
Trond Myklebustf2c2c552018-03-20 16:43:16 -0400449nfs3_proc_rename_setup(struct rpc_message *msg,
450 struct dentry *old_dentry,
451 struct dentry *new_dentry)
Jeff Laytond3d41522010-09-17 17:31:57 -0400452{
453 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
454}
455
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400456static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
457{
458 rpc_call_start(task);
459}
460
Jeff Laytond3d41522010-09-17 17:31:57 -0400461static int
462nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
463 struct inode *new_dir)
464{
465 struct nfs_renameres *res;
466
467 if (nfs3_async_handle_jukebox(task, old_dir))
468 return 0;
469 res = task->tk_msg.rpc_resp;
470
471 nfs_post_op_update_inode(old_dir, res->old_fattr);
472 nfs_post_op_update_inode(new_dir, res->new_fattr);
473 return 1;
474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476static int
Al Virobeffb8f2016-07-20 16:34:42 -0400477nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 struct nfs3_linkargs arg = {
480 .fromfh = NFS_FH(inode),
481 .tofh = NFS_FH(dir),
482 .toname = name->name,
483 .tolen = name->len
484 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400485 struct nfs3_linkres res;
Chuck Leverdead28d2006-03-20 13:44:23 -0500486 struct rpc_message msg = {
487 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
488 .rpc_argp = &arg,
489 .rpc_resp = &res,
490 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400491 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 dprintk("NFS call link %s\n", name->name);
Trond Myklebust136f2622010-04-16 16:22:49 -0400494 res.fattr = nfs_alloc_fattr();
495 res.dir_attr = nfs_alloc_fattr();
496 if (res.fattr == NULL || res.dir_attr == NULL)
497 goto out;
498
Chuck Leverdead28d2006-03-20 13:44:23 -0500499 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust136f2622010-04-16 16:22:49 -0400500 nfs_post_op_update_inode(dir, res.dir_attr);
501 nfs_post_op_update_inode(inode, res.fattr);
502out:
503 nfs_free_fattr(res.dir_attr);
504 nfs_free_fattr(res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 dprintk("NFS reply link: %d\n", status);
506 return status;
507}
508
509static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400510nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
511 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400513 struct nfs3_createdata *data;
514 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Chuck Lever94a6d752006-08-22 20:06:23 -0400516 if (len > NFS3_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400518
Al Viro6de14722013-09-16 10:53:17 -0400519 dprintk("NFS call symlink %pd\n", dentry);
Chuck Lever94a6d752006-08-22 20:06:23 -0400520
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400521 data = nfs3_alloc_createdata();
522 if (data == NULL)
Chuck Lever4f390c12006-08-22 20:06:22 -0400523 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400524 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
525 data->arg.symlink.fromfh = NFS_FH(dir);
526 data->arg.symlink.fromname = dentry->d_name.name;
527 data->arg.symlink.fromlen = dentry->d_name.len;
528 data->arg.symlink.pages = &page;
529 data->arg.symlink.pathlen = len;
530 data->arg.symlink.sattr = sattr;
531
532 status = nfs3_do_create(dir, dentry, data);
533
534 nfs3_free_createdata(data);
Chuck Lever4f390c12006-08-22 20:06:22 -0400535out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 dprintk("NFS reply symlink: %d\n", status);
537 return status;
538}
539
540static int
541nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
542{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800543 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400544 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400545 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Al Viro6de14722013-09-16 10:53:17 -0400547 dprintk("NFS call mkdir %pd\n", dentry);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000548
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400549 data = nfs3_alloc_createdata();
550 if (data == NULL)
551 goto out;
552
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800553 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
554 if (status)
555 goto out;
556
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400557 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
558 data->arg.mkdir.fh = NFS_FH(dir);
559 data->arg.mkdir.name = dentry->d_name.name;
560 data->arg.mkdir.len = dentry->d_name.len;
561 data->arg.mkdir.sattr = sattr;
562
563 status = nfs3_do_create(dir, dentry, data);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000564 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800565 goto out_release_acls;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400566
David Howells2b0143b2015-03-17 22:25:59 +0000567 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800568
569out_release_acls:
570 posix_acl_release(acl);
571 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000572out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400573 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 dprintk("NFS reply mkdir: %d\n", status);
575 return status;
576}
577
578static int
Al Virobeffb8f2016-07-20 16:34:42 -0400579nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Trond Myklebust39967dd2010-04-16 16:22:50 -0400581 struct nfs_fattr *dir_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 struct nfs3_diropargs arg = {
583 .fh = NFS_FH(dir),
584 .name = name->name,
585 .len = name->len
586 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500587 struct rpc_message msg = {
588 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
589 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500590 };
Trond Myklebust39967dd2010-04-16 16:22:50 -0400591 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 dprintk("NFS call rmdir %s\n", name->name);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400594 dir_attr = nfs_alloc_fattr();
595 if (dir_attr == NULL)
596 goto out;
597
598 msg.rpc_resp = dir_attr;
Chuck Leverdead28d2006-03-20 13:44:23 -0500599 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400600 nfs_post_op_update_inode(dir, dir_attr);
601 nfs_free_fattr(dir_attr);
602out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 dprintk("NFS reply rmdir: %d\n", status);
604 return status;
605}
606
607/*
608 * The READDIR implementation is somewhat hackish - we pass the user buffer
609 * to the encode function, which installs it in the receive iovec.
610 * The decode function itself doesn't perform any decoding, it just makes
611 * sure the reply is syntactically correct.
612 *
613 * Also note that this implementation handles both plain readdir and
614 * readdirplus.
615 */
616static int
NeilBrown684f39b2018-12-03 11:30:30 +1100617nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400618 u64 cookie, struct page **pages, unsigned int count, bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
David Howells2b0143b2015-03-17 22:25:59 +0000620 struct inode *dir = d_inode(dentry);
Trond Myklebustc3f52af2012-09-03 14:56:02 -0400621 __be32 *verf = NFS_I(dir)->cookieverf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 struct nfs3_readdirargs arg = {
623 .fh = NFS_FH(dir),
624 .cookie = cookie,
625 .verf = {verf[0], verf[1]},
626 .plus = plus,
627 .count = count,
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400628 .pages = pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 };
630 struct nfs3_readdirres res = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .verf = verf,
632 .plus = plus
633 };
NeilBrown684f39b2018-12-03 11:30:30 +1100634 struct auth_cred acred = {
635 .cred = cred,
636 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 struct rpc_message msg = {
638 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
639 .rpc_argp = &arg,
640 .rpc_resp = &res,
NeilBrown684f39b2018-12-03 11:30:30 +1100641 .rpc_cred = rpc_lookup_generic_cred(&acred,
642 0, GFP_NOFS),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 };
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400644 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (plus)
647 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
648
649 dprintk("NFS call readdir%s %d\n",
650 plus? "plus" : "", (unsigned int) cookie);
651
NeilBrown684f39b2018-12-03 11:30:30 +1100652 if (!msg.rpc_cred)
653 return -ENOMEM;
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400654 res.dir_attr = nfs_alloc_fattr();
655 if (res.dir_attr == NULL)
656 goto out;
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustc4812992007-09-28 17:11:45 -0400659
660 nfs_invalidate_atime(dir);
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400661 nfs_refresh_inode(dir, res.dir_attr);
Trond Myklebustc4812992007-09-28 17:11:45 -0400662
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400663 nfs_free_fattr(res.dir_attr);
664out:
NeilBrown684f39b2018-12-03 11:30:30 +1100665 put_rpccred(msg.rpc_cred);
Chuck Leverd141d972010-09-21 16:55:47 -0400666 dprintk("NFS reply readdir%s: %d\n",
667 plus? "plus" : "", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return status;
669}
670
671static int
672nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
673 dev_t rdev)
674{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800675 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400676 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400677 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Al Viro6de14722013-09-16 10:53:17 -0400679 dprintk("NFS call mknod %pd %u:%u\n", dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 MAJOR(rdev), MINOR(rdev));
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000681
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400682 data = nfs3_alloc_createdata();
683 if (data == NULL)
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000684 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400685
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800686 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
687 if (status)
688 goto out;
689
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400690 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
691 data->arg.mknod.fh = NFS_FH(dir);
692 data->arg.mknod.name = dentry->d_name.name;
693 data->arg.mknod.len = dentry->d_name.len;
694 data->arg.mknod.sattr = sattr;
695 data->arg.mknod.rdev = rdev;
696
697 switch (sattr->ia_mode & S_IFMT) {
698 case S_IFBLK:
699 data->arg.mknod.type = NF3BLK;
700 break;
701 case S_IFCHR:
702 data->arg.mknod.type = NF3CHR;
703 break;
704 case S_IFIFO:
705 data->arg.mknod.type = NF3FIFO;
706 break;
707 case S_IFSOCK:
708 data->arg.mknod.type = NF3SOCK;
709 break;
710 default:
711 status = -EINVAL;
712 goto out;
713 }
714
715 status = nfs3_do_create(dir, dentry, data);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000716 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800717 goto out_release_acls;
718
David Howells2b0143b2015-03-17 22:25:59 +0000719 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800720
721out_release_acls:
722 posix_acl_release(acl);
723 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000724out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400725 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 dprintk("NFS reply mknod: %d\n", status);
727 return status;
728}
729
730static int
731nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
732 struct nfs_fsstat *stat)
733{
Chuck Leverdead28d2006-03-20 13:44:23 -0500734 struct rpc_message msg = {
735 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
736 .rpc_argp = fhandle,
737 .rpc_resp = stat,
738 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 int status;
740
741 dprintk("NFS call fsstat\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400742 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500743 status = rpc_call_sync(server->client, &msg, 0);
Chuck Leverd141d972010-09-21 16:55:47 -0400744 dprintk("NFS reply fsstat: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 return status;
746}
747
748static int
EG Keizer37ca8f52008-08-19 16:34:36 -0400749do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 struct nfs_fsinfo *info)
751{
Chuck Leverdead28d2006-03-20 13:44:23 -0500752 struct rpc_message msg = {
753 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
754 .rpc_argp = fhandle,
755 .rpc_resp = info,
756 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 int status;
758
759 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400760 nfs_fattr_init(info->fattr);
EG Keizer37ca8f52008-08-19 16:34:36 -0400761 status = rpc_call_sync(client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 dprintk("NFS reply fsinfo: %d\n", status);
763 return status;
764}
765
EG Keizer37ca8f52008-08-19 16:34:36 -0400766/*
767 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
768 * nfs_create_server
769 */
770static int
771nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
772 struct nfs_fsinfo *info)
773{
774 int status;
775
776 status = do_proc_fsinfo(server->client, fhandle, info);
777 if (status && server->nfs_client->cl_rpcclient != server->client)
778 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
779 return status;
780}
781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782static int
783nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
784 struct nfs_pathconf *info)
785{
Chuck Leverdead28d2006-03-20 13:44:23 -0500786 struct rpc_message msg = {
787 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
788 .rpc_argp = fhandle,
789 .rpc_resp = info,
790 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 int status;
792
793 dprintk("NFS call pathconf\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400794 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500795 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 dprintk("NFS reply pathconf: %d\n", status);
797 return status;
798}
799
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400800static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400802 struct inode *inode = hdr->inode;
Trond Myklebust8d8928d2018-03-05 12:03:00 -0500803 struct nfs_server *server = NFS_SERVER(inode);
Fred Isamancd841602012-04-20 14:47:44 -0400804
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400805 if (hdr->pgio_done_cb != NULL)
806 return hdr->pgio_done_cb(task, hdr);
807
Fred Isamancd841602012-04-20 14:47:44 -0400808 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebustec06c092006-03-20 13:44:27 -0500809 return -EAGAIN;
Trond Myklebust8850df92007-09-28 17:20:07 -0400810
Trond Myklebust8d8928d2018-03-05 12:03:00 -0500811 if (task->tk_status >= 0 && !server->read_hdrsize)
812 cmpxchg(&server->read_hdrsize, 0, hdr->res.replen);
813
Fred Isamancd841602012-04-20 14:47:44 -0400814 nfs_invalidate_atime(inode);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400815 nfs_refresh_inode(inode, &hdr->fattr);
Trond Myklebustec06c092006-03-20 13:44:27 -0500816 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400819static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
820 struct rpc_message *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400822 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
Trond Myklebust8d8928d2018-03-05 12:03:00 -0500823 hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824}
825
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400826static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
827 struct nfs_pgio_header *hdr)
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400828{
829 rpc_call_start(task);
NeilBrownef1820f2013-09-04 17:04:49 +1000830 return 0;
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400831}
832
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400833static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400835 struct inode *inode = hdr->inode;
Fred Isamancd841602012-04-20 14:47:44 -0400836
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400837 if (hdr->pgio_done_cb != NULL)
838 return hdr->pgio_done_cb(task, hdr);
839
Fred Isamancd841602012-04-20 14:47:44 -0400840 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500841 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 if (task->tk_status >= 0)
Trond Myklebusta08a8cd2015-02-26 17:36:09 -0500843 nfs_writeback_update_inode(hdr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500844 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400847static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
Anna Schumakerfb91fb02018-05-04 16:22:48 -0400848 struct rpc_message *msg,
849 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400851 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
Fred Isaman0b7c0152012-04-20 14:47:39 -0400854static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
855{
856 rpc_call_start(task);
857}
858
859static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400861 if (data->commit_done_cb != NULL)
862 return data->commit_done_cb(task, data);
863
Chuck Lever006ea732006-03-20 13:44:14 -0500864 if (nfs3_async_handle_jukebox(task, data->inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500865 return -EAGAIN;
Trond Myklebust9e08a3c2007-10-08 14:10:31 -0400866 nfs_refresh_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500867 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
Anna Schumakere9ae1ee2018-05-04 16:22:49 -0400870static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
871 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400873 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400876static void nfs3_nlm_alloc_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400877{
878 struct nfs_lock_context *l_ctx = data;
879 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
880 get_nfs_open_context(l_ctx->open_context);
881 nfs_get_lock_context(l_ctx->open_context);
882 }
883}
884
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400885static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400886{
887 struct nfs_lock_context *l_ctx = data;
888 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
889 return nfs_async_iocounter_wait(task, l_ctx);
890 return false;
891
892}
893
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400894static void nfs3_nlm_release_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400895{
896 struct nfs_lock_context *l_ctx = data;
897 struct nfs_open_context *ctx;
898 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
899 ctx = l_ctx->open_context;
900 nfs_put_lock_context(l_ctx);
901 put_nfs_open_context(ctx);
902 }
903}
904
Colin Ian King1b720402018-02-07 11:27:54 +0000905static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400906 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
907 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
908 .nlmclnt_release_call = nfs3_nlm_release_call,
909};
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911static int
912nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
913{
Al Viro496ad9a2013-01-23 17:07:38 -0500914 struct inode *inode = file_inode(filp);
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400915 struct nfs_lock_context *l_ctx = NULL;
916 struct nfs_open_context *ctx = nfs_file_open_context(filp);
917 int status;
Chuck Lever1093a602008-01-11 17:09:59 -0500918
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400919 if (fl->fl_flags & FL_CLOSE) {
920 l_ctx = nfs_get_lock_context(ctx);
921 if (IS_ERR(l_ctx))
922 l_ctx = NULL;
923 else
924 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
925 }
926
927 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
928
929 if (l_ctx)
930 nfs_put_lock_context(l_ctx);
931
932 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
Bryan Schumaker011e2a72012-06-20 15:53:43 -0400935static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
936{
937 return 0;
938}
939
Bryan Schumakerab962912012-07-16 16:39:11 -0400940static const struct inode_operations nfs3_dir_inode_operations = {
941 .create = nfs_create,
942 .lookup = nfs_lookup,
943 .link = nfs_link,
944 .unlink = nfs_unlink,
945 .symlink = nfs_symlink,
946 .mkdir = nfs_mkdir,
947 .rmdir = nfs_rmdir,
948 .mknod = nfs_mknod,
949 .rename = nfs_rename,
950 .permission = nfs_permission,
951 .getattr = nfs_getattr,
952 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800953#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200954 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800955 .get_acl = nfs3_get_acl,
956 .set_acl = nfs3_set_acl,
957#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400958};
959
960static const struct inode_operations nfs3_file_inode_operations = {
961 .permission = nfs_permission,
962 .getattr = nfs_getattr,
963 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800964#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200965 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800966 .get_acl = nfs3_get_acl,
967 .set_acl = nfs3_set_acl,
968#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400969};
970
David Howells509de812006-08-22 20:06:11 -0400971const struct nfs_rpc_ops nfs_v3_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 .version = 3, /* protocol version */
973 .dentry_ops = &nfs_dentry_operations,
Andreas Gruenbacherb7fa0552005-06-22 17:16:27 +0000974 .dir_inode_ops = &nfs3_dir_inode_operations,
975 .file_inode_ops = &nfs3_file_inode_operations,
Jeff Layton1788ea62011-11-04 13:31:21 -0400976 .file_ops = &nfs_file_operations,
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400977 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 .getroot = nfs3_proc_get_root,
Bryan Schumaker281cad42012-04-27 13:27:45 -0400979 .submount = nfs_submount,
Bryan Schumakerff9099f22012-07-30 16:05:18 -0400980 .try_mount = nfs_try_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 .getattr = nfs3_proc_getattr,
982 .setattr = nfs3_proc_setattr,
983 .lookup = nfs3_proc_lookup,
984 .access = nfs3_proc_access,
985 .readlink = nfs3_proc_readlink,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .create = nfs3_proc_create,
987 .remove = nfs3_proc_remove,
988 .unlink_setup = nfs3_proc_unlink_setup,
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400989 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 .unlink_done = nfs3_proc_unlink_done,
Jeff Laytond3d41522010-09-17 17:31:57 -0400991 .rename_setup = nfs3_proc_rename_setup,
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400992 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
Jeff Laytond3d41522010-09-17 17:31:57 -0400993 .rename_done = nfs3_proc_rename_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 .link = nfs3_proc_link,
995 .symlink = nfs3_proc_symlink,
996 .mkdir = nfs3_proc_mkdir,
997 .rmdir = nfs3_proc_rmdir,
998 .readdir = nfs3_proc_readdir,
999 .mknod = nfs3_proc_mknod,
1000 .statfs = nfs3_proc_statfs,
1001 .fsinfo = nfs3_proc_fsinfo,
1002 .pathconf = nfs3_proc_pathconf,
1003 .decode_dirent = nfs3_decode_dirent,
Anna Schumakera4cdda52014-05-06 09:12:31 -04001004 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .read_setup = nfs3_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -05001006 .read_done = nfs3_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 .write_setup = nfs3_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001008 .write_done = nfs3_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 .commit_setup = nfs3_proc_commit_setup,
Fred Isaman0b7c0152012-04-20 14:47:39 -04001010 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001011 .commit_done = nfs3_commit_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .lock = nfs3_proc_lock,
Christoph Hellwig013cdf12013-12-20 05:16:53 -08001013 .clear_acl_cache = forget_all_cached_acls,
Trond Myklebust7fe5c392009-03-19 15:35:50 -04001014 .close_context = nfs_close_context,
Bryan Schumaker011e2a72012-06-20 15:53:43 -04001015 .have_delegation = nfs3_have_delegation,
Bryan Schumaker6663ee72012-06-20 15:53:46 -04001016 .alloc_client = nfs_alloc_client,
Andy Adamson45a52a02011-03-01 01:34:08 +00001017 .init_client = nfs_init_client,
Bryan Schumakercdb7ece2012-06-20 15:53:45 -04001018 .free_client = nfs_free_client,
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001019 .create_server = nfs3_create_server,
1020 .clone_server = nfs3_clone_server,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021};