blob: 3ffaff4715925d174e71c0fe42a45e7ee796ee0c [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,
David Quigley1775fd32013-05-22 12:50:42 -0400104 struct nfs_fattr *fattr, struct nfs4_label *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Chuck Leverdead28d2006-03-20 13:44:23 -0500106 struct rpc_message msg = {
107 .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
108 .rpc_argp = fhandle,
109 .rpc_resp = fattr,
110 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 int status;
112
113 dprintk("NFS call getattr\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400114 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500115 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 dprintk("NFS reply getattr: %d\n", status);
117 return status;
118}
119
120static int
121nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
122 struct iattr *sattr)
123{
David Howells2b0143b2015-03-17 22:25:59 +0000124 struct inode *inode = d_inode(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 struct nfs3_sattrargs arg = {
126 .fh = NFS_FH(inode),
127 .sattr = sattr,
128 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500129 struct rpc_message msg = {
130 .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
131 .rpc_argp = &arg,
132 .rpc_resp = fattr,
133 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 int status;
135
136 dprintk("NFS call setattr\n");
Trond Myklebust659bfcd2008-06-10 19:39:41 -0400137 if (sattr->ia_valid & ATTR_FILE)
138 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
Trond Myklebust0e574af2005-10-27 22:12:38 -0400139 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500140 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
chendtdbc898a2018-03-29 16:13:09 +0800141 if (status == 0) {
142 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
143 nfs_zap_acl_cache(inode);
Trond Myklebustf0446362015-02-26 16:09:04 -0500144 nfs_setattr_update_inode(inode, sattr, fattr);
chendtdbc898a2018-03-29 16:13:09 +0800145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 dprintk("NFS reply setattr: %d\n", status);
147 return status;
148}
149
150static int
Al Virobeffb8f2016-07-20 16:34:42 -0400151nfs3_proc_lookup(struct inode *dir, const struct qstr *name,
David Quigley1775fd32013-05-22 12:50:42 -0400152 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
153 struct nfs4_label *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 struct nfs3_diropargs arg = {
156 .fh = NFS_FH(dir),
157 .name = name->name,
158 .len = name->len
159 };
160 struct nfs3_diropres res = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 .fh = fhandle,
162 .fattr = fattr
163 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500164 struct rpc_message msg = {
165 .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
166 .rpc_argp = &arg,
167 .rpc_resp = &res,
168 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 int status;
170
171 dprintk("NFS call lookup %s\n", name->name);
Trond Myklebuste1fb4d02010-04-16 16:22:47 -0400172 res.dir_attr = nfs_alloc_fattr();
173 if (res.dir_attr == NULL)
174 return -ENOMEM;
175
Trond Myklebust0e574af2005-10-27 22:12:38 -0400176 nfs_fattr_init(fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500177 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebuste1fb4d02010-04-16 16:22:47 -0400178 nfs_refresh_inode(dir, res.dir_attr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500179 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
180 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
181 msg.rpc_argp = fhandle;
182 msg.rpc_resp = fattr;
183 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
184 }
Trond Myklebuste1fb4d02010-04-16 16:22:47 -0400185 nfs_free_fattr(res.dir_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 dprintk("NFS reply lookup: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 return status;
188}
189
190static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
191{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 struct nfs3_accessargs arg = {
193 .fh = NFS_FH(inode),
Anna Schumaker1750d922017-07-26 12:00:21 -0400194 .access = entry->mask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 };
Trond Myklebustc407d412010-04-16 16:22:48 -0400196 struct nfs3_accessres res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 struct rpc_message msg = {
198 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
199 .rpc_argp = &arg,
200 .rpc_resp = &res,
Chuck Leverdead28d2006-03-20 13:44:23 -0500201 .rpc_cred = entry->cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 };
Trond Myklebustc407d412010-04-16 16:22:48 -0400203 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 dprintk("NFS call access\n");
Trond Myklebustc407d412010-04-16 16:22:48 -0400206 res.fattr = nfs_alloc_fattr();
207 if (res.fattr == NULL)
208 goto out;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebustc407d412010-04-16 16:22:48 -0400211 nfs_refresh_inode(inode, res.fattr);
Trond Myklebusteda3e202017-07-11 17:54:33 -0400212 if (status == 0)
213 nfs_access_set_mask(entry, res.access);
Trond Myklebustc407d412010-04-16 16:22:48 -0400214 nfs_free_fattr(res.fattr);
215out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 dprintk("NFS reply access: %d\n", status);
217 return status;
218}
219
220static int nfs3_proc_readlink(struct inode *inode, struct page *page,
221 unsigned int pgbase, unsigned int pglen)
222{
Trond Myklebust3b14d652010-04-16 16:22:50 -0400223 struct nfs_fattr *fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 struct nfs3_readlinkargs args = {
225 .fh = NFS_FH(inode),
226 .pgbase = pgbase,
227 .pglen = pglen,
228 .pages = &page
229 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500230 struct rpc_message msg = {
231 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
232 .rpc_argp = &args,
Chuck Leverdead28d2006-03-20 13:44:23 -0500233 };
Trond Myklebust3b14d652010-04-16 16:22:50 -0400234 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 dprintk("NFS call readlink\n");
Trond Myklebust3b14d652010-04-16 16:22:50 -0400237 fattr = nfs_alloc_fattr();
238 if (fattr == NULL)
239 goto out;
240 msg.rpc_resp = fattr;
241
Chuck Leverdead28d2006-03-20 13:44:23 -0500242 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust3b14d652010-04-16 16:22:50 -0400243 nfs_refresh_inode(inode, fattr);
244 nfs_free_fattr(fattr);
245out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 dprintk("NFS reply readlink: %d\n", status);
247 return status;
248}
249
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400250struct nfs3_createdata {
251 struct rpc_message msg;
252 union {
253 struct nfs3_createargs create;
254 struct nfs3_mkdirargs mkdir;
255 struct nfs3_symlinkargs symlink;
256 struct nfs3_mknodargs mknod;
257 } arg;
258 struct nfs3_diropres res;
259 struct nfs_fh fh;
260 struct nfs_fattr fattr;
261 struct nfs_fattr dir_attr;
262};
263
264static struct nfs3_createdata *nfs3_alloc_createdata(void)
265{
266 struct nfs3_createdata *data;
267
268 data = kzalloc(sizeof(*data), GFP_KERNEL);
269 if (data != NULL) {
270 data->msg.rpc_argp = &data->arg;
271 data->msg.rpc_resp = &data->res;
272 data->res.fh = &data->fh;
273 data->res.fattr = &data->fattr;
274 data->res.dir_attr = &data->dir_attr;
275 nfs_fattr_init(data->res.fattr);
276 nfs_fattr_init(data->res.dir_attr);
277 }
278 return data;
279}
280
281static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
282{
283 int status;
284
285 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
286 nfs_post_op_update_inode(dir, data->res.dir_attr);
287 if (status == 0)
David Quigley1775fd32013-05-22 12:50:42 -0400288 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400289 return status;
290}
291
292static void nfs3_free_createdata(struct nfs3_createdata *data)
293{
294 kfree(data);
295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*
298 * Create a regular file.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 */
300static int
301nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Miklos Szeredi8867fe52012-06-05 15:10:19 +0200302 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800304 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400305 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400306 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Al Viro6de14722013-09-16 10:53:17 -0400308 dprintk("NFS call create %pd\n", dentry);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400309
310 data = nfs3_alloc_createdata();
311 if (data == NULL)
312 goto out;
313
314 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
315 data->arg.create.fh = NFS_FH(dir);
316 data->arg.create.name = dentry->d_name.name;
317 data->arg.create.len = dentry->d_name.len;
318 data->arg.create.sattr = sattr;
319
320 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (flags & O_EXCL) {
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400322 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
Trond Myklebusta9943d12013-08-20 21:04:11 -0400323 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
324 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800327 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
328 if (status)
329 goto out;
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000330
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400331 for (;;) {
332 status = nfs3_do_create(dir, dentry, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400334 if (status != -ENOTSUPP)
335 break;
336 /* If the server doesn't support the exclusive creation
337 * semantics, try again with simple 'guarded' mode. */
338 switch (data->arg.create.createmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 case NFS3_CREATE_EXCLUSIVE:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400340 data->arg.create.createmode = NFS3_CREATE_GUARDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
342
343 case NFS3_CREATE_GUARDED:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400344 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 break;
346
347 case NFS3_CREATE_UNCHECKED:
348 goto out;
349 }
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400350 nfs_fattr_init(data->res.dir_attr);
351 nfs_fattr_init(data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800355 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 /* When we created the file with exclusive semantics, make
358 * sure we set the attributes afterwards. */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400359 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 dprintk("NFS call setattr (post-create)\n");
361
362 if (!(sattr->ia_valid & ATTR_ATIME_SET))
363 sattr->ia_valid |= ATTR_ATIME;
364 if (!(sattr->ia_valid & ATTR_MTIME_SET))
365 sattr->ia_valid |= ATTR_MTIME;
366
367 /* Note: we could use a guarded setattr here, but I'm
368 * not sure this buys us anything (and I'd have
369 * to revamp the NFSv3 XDR code) */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400370 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
David Howells2b0143b2015-03-17 22:25:59 +0000371 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 dprintk("NFS reply setattr (post-create): %d\n", status);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400373 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800374 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800376
David Howells2b0143b2015-03-17 22:25:59 +0000377 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800378
379out_release_acls:
380 posix_acl_release(acl);
381 posix_acl_release(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400383 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 dprintk("NFS reply create: %d\n", status);
385 return status;
386}
387
388static int
Trond Myklebust912678d2018-03-20 16:43:15 -0400389nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400391 struct nfs_removeargs arg = {
392 .fh = NFS_FH(dir),
Trond Myklebust912678d2018-03-20 16:43:15 -0400393 .name = dentry->d_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 };
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400395 struct nfs_removeres res;
396 struct rpc_message msg = {
397 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
398 .rpc_argp = &arg,
399 .rpc_resp = &res,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 };
Trond Myklebustd3468902010-04-16 16:22:50 -0400401 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Trond Myklebust912678d2018-03-20 16:43:15 -0400403 dprintk("NFS call remove %pd2\n", dentry);
Trond Myklebustd3468902010-04-16 16:22:50 -0400404 res.dir_attr = nfs_alloc_fattr();
405 if (res.dir_attr == NULL)
406 goto out;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustd3468902010-04-16 16:22:50 -0400409 nfs_post_op_update_inode(dir, res.dir_attr);
410 nfs_free_fattr(res.dir_attr);
411out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 dprintk("NFS reply remove: %d\n", status);
413 return status;
414}
415
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400416static void
Trond Myklebust977fcc22018-03-20 16:43:17 -0400417nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400422static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
423{
424 rpc_call_start(task);
425}
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427static int
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400428nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400430 struct nfs_removeres *res;
431 if (nfs3_async_handle_jukebox(task, dir))
432 return 0;
433 res = task->tk_msg.rpc_resp;
Trond Myklebustd3468902010-04-16 16:22:50 -0400434 nfs_post_op_update_inode(dir, res->dir_attr);
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400435 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Jeff Laytond3d41522010-09-17 17:31:57 -0400438static void
Trond Myklebustf2c2c552018-03-20 16:43:16 -0400439nfs3_proc_rename_setup(struct rpc_message *msg,
440 struct dentry *old_dentry,
441 struct dentry *new_dentry)
Jeff Laytond3d41522010-09-17 17:31:57 -0400442{
443 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
444}
445
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400446static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
447{
448 rpc_call_start(task);
449}
450
Jeff Laytond3d41522010-09-17 17:31:57 -0400451static int
452nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
453 struct inode *new_dir)
454{
455 struct nfs_renameres *res;
456
457 if (nfs3_async_handle_jukebox(task, old_dir))
458 return 0;
459 res = task->tk_msg.rpc_resp;
460
461 nfs_post_op_update_inode(old_dir, res->old_fattr);
462 nfs_post_op_update_inode(new_dir, res->new_fattr);
463 return 1;
464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466static int
Al Virobeffb8f2016-07-20 16:34:42 -0400467nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 struct nfs3_linkargs arg = {
470 .fromfh = NFS_FH(inode),
471 .tofh = NFS_FH(dir),
472 .toname = name->name,
473 .tolen = name->len
474 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400475 struct nfs3_linkres res;
Chuck Leverdead28d2006-03-20 13:44:23 -0500476 struct rpc_message msg = {
477 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
478 .rpc_argp = &arg,
479 .rpc_resp = &res,
480 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400481 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 dprintk("NFS call link %s\n", name->name);
Trond Myklebust136f2622010-04-16 16:22:49 -0400484 res.fattr = nfs_alloc_fattr();
485 res.dir_attr = nfs_alloc_fattr();
486 if (res.fattr == NULL || res.dir_attr == NULL)
487 goto out;
488
Chuck Leverdead28d2006-03-20 13:44:23 -0500489 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust136f2622010-04-16 16:22:49 -0400490 nfs_post_op_update_inode(dir, res.dir_attr);
491 nfs_post_op_update_inode(inode, res.fattr);
492out:
493 nfs_free_fattr(res.dir_attr);
494 nfs_free_fattr(res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 dprintk("NFS reply link: %d\n", status);
496 return status;
497}
498
499static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400500nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
501 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400503 struct nfs3_createdata *data;
504 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
Chuck Lever94a6d752006-08-22 20:06:23 -0400506 if (len > NFS3_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400508
Al Viro6de14722013-09-16 10:53:17 -0400509 dprintk("NFS call symlink %pd\n", dentry);
Chuck Lever94a6d752006-08-22 20:06:23 -0400510
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400511 data = nfs3_alloc_createdata();
512 if (data == NULL)
Chuck Lever4f390c12006-08-22 20:06:22 -0400513 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400514 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
515 data->arg.symlink.fromfh = NFS_FH(dir);
516 data->arg.symlink.fromname = dentry->d_name.name;
517 data->arg.symlink.fromlen = dentry->d_name.len;
518 data->arg.symlink.pages = &page;
519 data->arg.symlink.pathlen = len;
520 data->arg.symlink.sattr = sattr;
521
522 status = nfs3_do_create(dir, dentry, data);
523
524 nfs3_free_createdata(data);
Chuck Lever4f390c12006-08-22 20:06:22 -0400525out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 dprintk("NFS reply symlink: %d\n", status);
527 return status;
528}
529
530static int
531nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
532{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800533 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400534 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400535 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Al Viro6de14722013-09-16 10:53:17 -0400537 dprintk("NFS call mkdir %pd\n", dentry);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000538
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400539 data = nfs3_alloc_createdata();
540 if (data == NULL)
541 goto out;
542
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800543 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
544 if (status)
545 goto out;
546
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400547 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
548 data->arg.mkdir.fh = NFS_FH(dir);
549 data->arg.mkdir.name = dentry->d_name.name;
550 data->arg.mkdir.len = dentry->d_name.len;
551 data->arg.mkdir.sattr = sattr;
552
553 status = nfs3_do_create(dir, dentry, data);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000554 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800555 goto out_release_acls;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400556
David Howells2b0143b2015-03-17 22:25:59 +0000557 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800558
559out_release_acls:
560 posix_acl_release(acl);
561 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000562out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400563 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 dprintk("NFS reply mkdir: %d\n", status);
565 return status;
566}
567
568static int
Al Virobeffb8f2016-07-20 16:34:42 -0400569nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Trond Myklebust39967dd2010-04-16 16:22:50 -0400571 struct nfs_fattr *dir_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 struct nfs3_diropargs arg = {
573 .fh = NFS_FH(dir),
574 .name = name->name,
575 .len = name->len
576 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500577 struct rpc_message msg = {
578 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
579 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500580 };
Trond Myklebust39967dd2010-04-16 16:22:50 -0400581 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 dprintk("NFS call rmdir %s\n", name->name);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400584 dir_attr = nfs_alloc_fattr();
585 if (dir_attr == NULL)
586 goto out;
587
588 msg.rpc_resp = dir_attr;
Chuck Leverdead28d2006-03-20 13:44:23 -0500589 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400590 nfs_post_op_update_inode(dir, dir_attr);
591 nfs_free_fattr(dir_attr);
592out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 dprintk("NFS reply rmdir: %d\n", status);
594 return status;
595}
596
597/*
598 * The READDIR implementation is somewhat hackish - we pass the user buffer
599 * to the encode function, which installs it in the receive iovec.
600 * The decode function itself doesn't perform any decoding, it just makes
601 * sure the reply is syntactically correct.
602 *
603 * Also note that this implementation handles both plain readdir and
604 * readdirplus.
605 */
606static int
607nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400608 u64 cookie, struct page **pages, unsigned int count, bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
David Howells2b0143b2015-03-17 22:25:59 +0000610 struct inode *dir = d_inode(dentry);
Trond Myklebustc3f52af2012-09-03 14:56:02 -0400611 __be32 *verf = NFS_I(dir)->cookieverf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 struct nfs3_readdirargs arg = {
613 .fh = NFS_FH(dir),
614 .cookie = cookie,
615 .verf = {verf[0], verf[1]},
616 .plus = plus,
617 .count = count,
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400618 .pages = pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 };
620 struct nfs3_readdirres res = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .verf = verf,
622 .plus = plus
623 };
624 struct rpc_message msg = {
625 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
626 .rpc_argp = &arg,
627 .rpc_resp = &res,
628 .rpc_cred = cred
629 };
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400630 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 if (plus)
633 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
634
635 dprintk("NFS call readdir%s %d\n",
636 plus? "plus" : "", (unsigned int) cookie);
637
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400638 res.dir_attr = nfs_alloc_fattr();
639 if (res.dir_attr == NULL)
640 goto out;
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustc4812992007-09-28 17:11:45 -0400643
644 nfs_invalidate_atime(dir);
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400645 nfs_refresh_inode(dir, res.dir_attr);
Trond Myklebustc4812992007-09-28 17:11:45 -0400646
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400647 nfs_free_fattr(res.dir_attr);
648out:
Chuck Leverd141d972010-09-21 16:55:47 -0400649 dprintk("NFS reply readdir%s: %d\n",
650 plus? "plus" : "", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 return status;
652}
653
654static int
655nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
656 dev_t rdev)
657{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800658 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400659 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400660 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Al Viro6de14722013-09-16 10:53:17 -0400662 dprintk("NFS call mknod %pd %u:%u\n", dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 MAJOR(rdev), MINOR(rdev));
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000664
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400665 data = nfs3_alloc_createdata();
666 if (data == NULL)
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000667 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400668
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800669 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
670 if (status)
671 goto out;
672
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400673 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
674 data->arg.mknod.fh = NFS_FH(dir);
675 data->arg.mknod.name = dentry->d_name.name;
676 data->arg.mknod.len = dentry->d_name.len;
677 data->arg.mknod.sattr = sattr;
678 data->arg.mknod.rdev = rdev;
679
680 switch (sattr->ia_mode & S_IFMT) {
681 case S_IFBLK:
682 data->arg.mknod.type = NF3BLK;
683 break;
684 case S_IFCHR:
685 data->arg.mknod.type = NF3CHR;
686 break;
687 case S_IFIFO:
688 data->arg.mknod.type = NF3FIFO;
689 break;
690 case S_IFSOCK:
691 data->arg.mknod.type = NF3SOCK;
692 break;
693 default:
694 status = -EINVAL;
695 goto out;
696 }
697
698 status = nfs3_do_create(dir, dentry, data);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000699 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800700 goto out_release_acls;
701
David Howells2b0143b2015-03-17 22:25:59 +0000702 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800703
704out_release_acls:
705 posix_acl_release(acl);
706 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000707out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400708 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 dprintk("NFS reply mknod: %d\n", status);
710 return status;
711}
712
713static int
714nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
715 struct nfs_fsstat *stat)
716{
Chuck Leverdead28d2006-03-20 13:44:23 -0500717 struct rpc_message msg = {
718 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
719 .rpc_argp = fhandle,
720 .rpc_resp = stat,
721 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 int status;
723
724 dprintk("NFS call fsstat\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400725 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500726 status = rpc_call_sync(server->client, &msg, 0);
Chuck Leverd141d972010-09-21 16:55:47 -0400727 dprintk("NFS reply fsstat: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 return status;
729}
730
731static int
EG Keizer37ca8f52008-08-19 16:34:36 -0400732do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 struct nfs_fsinfo *info)
734{
Chuck Leverdead28d2006-03-20 13:44:23 -0500735 struct rpc_message msg = {
736 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
737 .rpc_argp = fhandle,
738 .rpc_resp = info,
739 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 int status;
741
742 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400743 nfs_fattr_init(info->fattr);
EG Keizer37ca8f52008-08-19 16:34:36 -0400744 status = rpc_call_sync(client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 dprintk("NFS reply fsinfo: %d\n", status);
746 return status;
747}
748
EG Keizer37ca8f52008-08-19 16:34:36 -0400749/*
750 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
751 * nfs_create_server
752 */
753static int
754nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
755 struct nfs_fsinfo *info)
756{
757 int status;
758
759 status = do_proc_fsinfo(server->client, fhandle, info);
760 if (status && server->nfs_client->cl_rpcclient != server->client)
761 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
762 return status;
763}
764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765static int
766nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
767 struct nfs_pathconf *info)
768{
Chuck Leverdead28d2006-03-20 13:44:23 -0500769 struct rpc_message msg = {
770 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
771 .rpc_argp = fhandle,
772 .rpc_resp = info,
773 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 int status;
775
776 dprintk("NFS call pathconf\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400777 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500778 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 dprintk("NFS reply pathconf: %d\n", status);
780 return status;
781}
782
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400783static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400785 struct inode *inode = hdr->inode;
Fred Isamancd841602012-04-20 14:47:44 -0400786
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400787 if (hdr->pgio_done_cb != NULL)
788 return hdr->pgio_done_cb(task, hdr);
789
Fred Isamancd841602012-04-20 14:47:44 -0400790 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebustec06c092006-03-20 13:44:27 -0500791 return -EAGAIN;
Trond Myklebust8850df92007-09-28 17:20:07 -0400792
Fred Isamancd841602012-04-20 14:47:44 -0400793 nfs_invalidate_atime(inode);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400794 nfs_refresh_inode(inode, &hdr->fattr);
Trond Myklebustec06c092006-03-20 13:44:27 -0500795 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400798static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
799 struct rpc_message *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400801 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802}
803
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400804static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
805 struct nfs_pgio_header *hdr)
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400806{
807 rpc_call_start(task);
NeilBrownef1820f2013-09-04 17:04:49 +1000808 return 0;
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400809}
810
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400811static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400813 struct inode *inode = hdr->inode;
Fred Isamancd841602012-04-20 14:47:44 -0400814
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400815 if (hdr->pgio_done_cb != NULL)
816 return hdr->pgio_done_cb(task, hdr);
817
Fred Isamancd841602012-04-20 14:47:44 -0400818 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500819 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (task->tk_status >= 0)
Trond Myklebusta08a8cd2015-02-26 17:36:09 -0500821 nfs_writeback_update_inode(hdr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400825static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
Anna Schumakerfb91fb02018-05-04 16:22:48 -0400826 struct rpc_message *msg,
827 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400829 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
Fred Isaman0b7c0152012-04-20 14:47:39 -0400832static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
833{
834 rpc_call_start(task);
835}
836
837static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400839 if (data->commit_done_cb != NULL)
840 return data->commit_done_cb(task, data);
841
Chuck Lever006ea732006-03-20 13:44:14 -0500842 if (nfs3_async_handle_jukebox(task, data->inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500843 return -EAGAIN;
Trond Myklebust9e08a3c2007-10-08 14:10:31 -0400844 nfs_refresh_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500845 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Fred Isaman0b7c0152012-04-20 14:47:39 -0400848static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400850 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851}
852
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400853static void nfs3_nlm_alloc_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400854{
855 struct nfs_lock_context *l_ctx = data;
856 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
857 get_nfs_open_context(l_ctx->open_context);
858 nfs_get_lock_context(l_ctx->open_context);
859 }
860}
861
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400862static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400863{
864 struct nfs_lock_context *l_ctx = data;
865 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
866 return nfs_async_iocounter_wait(task, l_ctx);
867 return false;
868
869}
870
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400871static void nfs3_nlm_release_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400872{
873 struct nfs_lock_context *l_ctx = data;
874 struct nfs_open_context *ctx;
875 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
876 ctx = l_ctx->open_context;
877 nfs_put_lock_context(l_ctx);
878 put_nfs_open_context(ctx);
879 }
880}
881
Colin Ian King1b720402018-02-07 11:27:54 +0000882static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400883 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
884 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
885 .nlmclnt_release_call = nfs3_nlm_release_call,
886};
887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888static int
889nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
890{
Al Viro496ad9a2013-01-23 17:07:38 -0500891 struct inode *inode = file_inode(filp);
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400892 struct nfs_lock_context *l_ctx = NULL;
893 struct nfs_open_context *ctx = nfs_file_open_context(filp);
894 int status;
Chuck Lever1093a602008-01-11 17:09:59 -0500895
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400896 if (fl->fl_flags & FL_CLOSE) {
897 l_ctx = nfs_get_lock_context(ctx);
898 if (IS_ERR(l_ctx))
899 l_ctx = NULL;
900 else
901 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
902 }
903
904 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
905
906 if (l_ctx)
907 nfs_put_lock_context(l_ctx);
908
909 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910}
911
Bryan Schumaker011e2a72012-06-20 15:53:43 -0400912static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
913{
914 return 0;
915}
916
Bryan Schumakerab962912012-07-16 16:39:11 -0400917static const struct inode_operations nfs3_dir_inode_operations = {
918 .create = nfs_create,
919 .lookup = nfs_lookup,
920 .link = nfs_link,
921 .unlink = nfs_unlink,
922 .symlink = nfs_symlink,
923 .mkdir = nfs_mkdir,
924 .rmdir = nfs_rmdir,
925 .mknod = nfs_mknod,
926 .rename = nfs_rename,
927 .permission = nfs_permission,
928 .getattr = nfs_getattr,
929 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800930#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200931 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800932 .get_acl = nfs3_get_acl,
933 .set_acl = nfs3_set_acl,
934#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400935};
936
937static const struct inode_operations nfs3_file_inode_operations = {
938 .permission = nfs_permission,
939 .getattr = nfs_getattr,
940 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800941#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200942 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800943 .get_acl = nfs3_get_acl,
944 .set_acl = nfs3_set_acl,
945#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400946};
947
David Howells509de812006-08-22 20:06:11 -0400948const struct nfs_rpc_ops nfs_v3_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 .version = 3, /* protocol version */
950 .dentry_ops = &nfs_dentry_operations,
Andreas Gruenbacherb7fa0552005-06-22 17:16:27 +0000951 .dir_inode_ops = &nfs3_dir_inode_operations,
952 .file_inode_ops = &nfs3_file_inode_operations,
Jeff Layton1788ea62011-11-04 13:31:21 -0400953 .file_ops = &nfs_file_operations,
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400954 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 .getroot = nfs3_proc_get_root,
Bryan Schumaker281cad42012-04-27 13:27:45 -0400956 .submount = nfs_submount,
Bryan Schumakerff9099f22012-07-30 16:05:18 -0400957 .try_mount = nfs_try_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 .getattr = nfs3_proc_getattr,
959 .setattr = nfs3_proc_setattr,
960 .lookup = nfs3_proc_lookup,
961 .access = nfs3_proc_access,
962 .readlink = nfs3_proc_readlink,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 .create = nfs3_proc_create,
964 .remove = nfs3_proc_remove,
965 .unlink_setup = nfs3_proc_unlink_setup,
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400966 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 .unlink_done = nfs3_proc_unlink_done,
Jeff Laytond3d41522010-09-17 17:31:57 -0400968 .rename_setup = nfs3_proc_rename_setup,
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400969 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
Jeff Laytond3d41522010-09-17 17:31:57 -0400970 .rename_done = nfs3_proc_rename_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 .link = nfs3_proc_link,
972 .symlink = nfs3_proc_symlink,
973 .mkdir = nfs3_proc_mkdir,
974 .rmdir = nfs3_proc_rmdir,
975 .readdir = nfs3_proc_readdir,
976 .mknod = nfs3_proc_mknod,
977 .statfs = nfs3_proc_statfs,
978 .fsinfo = nfs3_proc_fsinfo,
979 .pathconf = nfs3_proc_pathconf,
980 .decode_dirent = nfs3_decode_dirent,
Anna Schumakera4cdda52014-05-06 09:12:31 -0400981 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 .read_setup = nfs3_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500983 .read_done = nfs3_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 .write_setup = nfs3_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500985 .write_done = nfs3_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .commit_setup = nfs3_proc_commit_setup,
Fred Isaman0b7c0152012-04-20 14:47:39 -0400987 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500988 .commit_done = nfs3_commit_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 .lock = nfs3_proc_lock,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800990 .clear_acl_cache = forget_all_cached_acls,
Trond Myklebust7fe5c392009-03-19 15:35:50 -0400991 .close_context = nfs_close_context,
Bryan Schumaker011e2a72012-06-20 15:53:43 -0400992 .have_delegation = nfs3_have_delegation,
Bryan Schumaker6663ee72012-06-20 15:53:46 -0400993 .alloc_client = nfs_alloc_client,
Andy Adamson45a52a02011-03-01 01:34:08 +0000994 .init_client = nfs_init_client,
Bryan Schumakercdb7ece2012-06-20 15:53:45 -0400995 .free_client = nfs_free_client,
Bryan Schumaker1179acc2012-07-30 16:05:19 -0400996 .create_server = nfs3_create_server,
997 .clone_server = nfs3_clone_server,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998};