blob: ec8a9efa268fec13f78daaf347b37a6b707d6f1e [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct rpc_message msg = {
199 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
200 .rpc_argp = &arg,
201 .rpc_resp = &res,
Chuck Leverdead28d2006-03-20 13:44:23 -0500202 .rpc_cred = entry->cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 };
Trond Myklebustc407d412010-04-16 16:22:48 -0400204 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 dprintk("NFS call access\n");
Trond Myklebustc407d412010-04-16 16:22:48 -0400207 res.fattr = nfs_alloc_fattr();
208 if (res.fattr == NULL)
209 goto out;
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebustc407d412010-04-16 16:22:48 -0400212 nfs_refresh_inode(inode, res.fattr);
Trond Myklebusteda3e202017-07-11 17:54:33 -0400213 if (status == 0)
214 nfs_access_set_mask(entry, res.access);
Trond Myklebustc407d412010-04-16 16:22:48 -0400215 nfs_free_fattr(res.fattr);
216out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 dprintk("NFS reply access: %d\n", status);
218 return status;
219}
220
221static int nfs3_proc_readlink(struct inode *inode, struct page *page,
222 unsigned int pgbase, unsigned int pglen)
223{
Trond Myklebust3b14d652010-04-16 16:22:50 -0400224 struct nfs_fattr *fattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 struct nfs3_readlinkargs args = {
226 .fh = NFS_FH(inode),
227 .pgbase = pgbase,
228 .pglen = pglen,
229 .pages = &page
230 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500231 struct rpc_message msg = {
232 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
233 .rpc_argp = &args,
Chuck Leverdead28d2006-03-20 13:44:23 -0500234 };
Trond Myklebust3b14d652010-04-16 16:22:50 -0400235 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 dprintk("NFS call readlink\n");
Trond Myklebust3b14d652010-04-16 16:22:50 -0400238 fattr = nfs_alloc_fattr();
239 if (fattr == NULL)
240 goto out;
241 msg.rpc_resp = fattr;
242
Chuck Leverdead28d2006-03-20 13:44:23 -0500243 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust3b14d652010-04-16 16:22:50 -0400244 nfs_refresh_inode(inode, fattr);
245 nfs_free_fattr(fattr);
246out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 dprintk("NFS reply readlink: %d\n", status);
248 return status;
249}
250
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400251struct nfs3_createdata {
252 struct rpc_message msg;
253 union {
254 struct nfs3_createargs create;
255 struct nfs3_mkdirargs mkdir;
256 struct nfs3_symlinkargs symlink;
257 struct nfs3_mknodargs mknod;
258 } arg;
259 struct nfs3_diropres res;
260 struct nfs_fh fh;
261 struct nfs_fattr fattr;
262 struct nfs_fattr dir_attr;
263};
264
265static struct nfs3_createdata *nfs3_alloc_createdata(void)
266{
267 struct nfs3_createdata *data;
268
269 data = kzalloc(sizeof(*data), GFP_KERNEL);
270 if (data != NULL) {
271 data->msg.rpc_argp = &data->arg;
272 data->msg.rpc_resp = &data->res;
273 data->res.fh = &data->fh;
274 data->res.fattr = &data->fattr;
275 data->res.dir_attr = &data->dir_attr;
276 nfs_fattr_init(data->res.fattr);
277 nfs_fattr_init(data->res.dir_attr);
278 }
279 return data;
280}
281
282static int nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
283{
284 int status;
285
286 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
287 nfs_post_op_update_inode(dir, data->res.dir_attr);
288 if (status == 0)
David Quigley1775fd32013-05-22 12:50:42 -0400289 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, NULL);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400290 return status;
291}
292
293static void nfs3_free_createdata(struct nfs3_createdata *data)
294{
295 kfree(data);
296}
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298/*
299 * Create a regular file.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 */
301static int
302nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Miklos Szeredi8867fe52012-06-05 15:10:19 +0200303 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800305 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400306 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400307 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Al Viro6de14722013-09-16 10:53:17 -0400309 dprintk("NFS call create %pd\n", dentry);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400310
311 data = nfs3_alloc_createdata();
312 if (data == NULL)
313 goto out;
314
315 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
316 data->arg.create.fh = NFS_FH(dir);
317 data->arg.create.name = dentry->d_name.name;
318 data->arg.create.len = dentry->d_name.len;
319 data->arg.create.sattr = sattr;
320
321 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (flags & O_EXCL) {
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400323 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
Trond Myklebusta9943d12013-08-20 21:04:11 -0400324 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
325 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800328 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
329 if (status)
330 goto out;
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000331
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400332 for (;;) {
333 status = nfs3_do_create(dir, dentry, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400335 if (status != -ENOTSUPP)
336 break;
337 /* If the server doesn't support the exclusive creation
338 * semantics, try again with simple 'guarded' mode. */
339 switch (data->arg.create.createmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 case NFS3_CREATE_EXCLUSIVE:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400341 data->arg.create.createmode = NFS3_CREATE_GUARDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
343
344 case NFS3_CREATE_GUARDED:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400345 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347
348 case NFS3_CREATE_UNCHECKED:
349 goto out;
350 }
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400351 nfs_fattr_init(data->res.dir_attr);
352 nfs_fattr_init(data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800356 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /* When we created the file with exclusive semantics, make
359 * sure we set the attributes afterwards. */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400360 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 dprintk("NFS call setattr (post-create)\n");
362
363 if (!(sattr->ia_valid & ATTR_ATIME_SET))
364 sattr->ia_valid |= ATTR_ATIME;
365 if (!(sattr->ia_valid & ATTR_MTIME_SET))
366 sattr->ia_valid |= ATTR_MTIME;
367
368 /* Note: we could use a guarded setattr here, but I'm
369 * not sure this buys us anything (and I'd have
370 * to revamp the NFSv3 XDR code) */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400371 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
David Howells2b0143b2015-03-17 22:25:59 +0000372 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 dprintk("NFS reply setattr (post-create): %d\n", status);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400374 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800375 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800377
David Howells2b0143b2015-03-17 22:25:59 +0000378 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800379
380out_release_acls:
381 posix_acl_release(acl);
382 posix_acl_release(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400384 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 dprintk("NFS reply create: %d\n", status);
386 return status;
387}
388
389static int
Trond Myklebust912678d2018-03-20 16:43:15 -0400390nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400392 struct nfs_removeargs arg = {
393 .fh = NFS_FH(dir),
Trond Myklebust912678d2018-03-20 16:43:15 -0400394 .name = dentry->d_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 };
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400396 struct nfs_removeres res;
397 struct rpc_message msg = {
398 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
399 .rpc_argp = &arg,
400 .rpc_resp = &res,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 };
Trond Myklebustd3468902010-04-16 16:22:50 -0400402 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Trond Myklebust912678d2018-03-20 16:43:15 -0400404 dprintk("NFS call remove %pd2\n", dentry);
Trond Myklebustd3468902010-04-16 16:22:50 -0400405 res.dir_attr = nfs_alloc_fattr();
406 if (res.dir_attr == NULL)
407 goto out;
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustd3468902010-04-16 16:22:50 -0400410 nfs_post_op_update_inode(dir, res.dir_attr);
411 nfs_free_fattr(res.dir_attr);
412out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 dprintk("NFS reply remove: %d\n", status);
414 return status;
415}
416
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400417static void
Trond Myklebusted7e9ad2018-05-30 16:11:52 -0400418nfs3_proc_unlink_setup(struct rpc_message *msg,
419 struct dentry *dentry,
420 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400425static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
426{
427 rpc_call_start(task);
428}
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430static int
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400431nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400433 struct nfs_removeres *res;
434 if (nfs3_async_handle_jukebox(task, dir))
435 return 0;
436 res = task->tk_msg.rpc_resp;
Trond Myklebustd3468902010-04-16 16:22:50 -0400437 nfs_post_op_update_inode(dir, res->dir_attr);
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400438 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
Jeff Laytond3d41522010-09-17 17:31:57 -0400441static void
Trond Myklebustf2c2c552018-03-20 16:43:16 -0400442nfs3_proc_rename_setup(struct rpc_message *msg,
443 struct dentry *old_dentry,
444 struct dentry *new_dentry)
Jeff Laytond3d41522010-09-17 17:31:57 -0400445{
446 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
447}
448
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400449static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
450{
451 rpc_call_start(task);
452}
453
Jeff Laytond3d41522010-09-17 17:31:57 -0400454static int
455nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
456 struct inode *new_dir)
457{
458 struct nfs_renameres *res;
459
460 if (nfs3_async_handle_jukebox(task, old_dir))
461 return 0;
462 res = task->tk_msg.rpc_resp;
463
464 nfs_post_op_update_inode(old_dir, res->old_fattr);
465 nfs_post_op_update_inode(new_dir, res->new_fattr);
466 return 1;
467}
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469static int
Al Virobeffb8f2016-07-20 16:34:42 -0400470nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 struct nfs3_linkargs arg = {
473 .fromfh = NFS_FH(inode),
474 .tofh = NFS_FH(dir),
475 .toname = name->name,
476 .tolen = name->len
477 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400478 struct nfs3_linkres res;
Chuck Leverdead28d2006-03-20 13:44:23 -0500479 struct rpc_message msg = {
480 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
481 .rpc_argp = &arg,
482 .rpc_resp = &res,
483 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400484 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 dprintk("NFS call link %s\n", name->name);
Trond Myklebust136f2622010-04-16 16:22:49 -0400487 res.fattr = nfs_alloc_fattr();
488 res.dir_attr = nfs_alloc_fattr();
489 if (res.fattr == NULL || res.dir_attr == NULL)
490 goto out;
491
Chuck Leverdead28d2006-03-20 13:44:23 -0500492 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust136f2622010-04-16 16:22:49 -0400493 nfs_post_op_update_inode(dir, res.dir_attr);
494 nfs_post_op_update_inode(inode, res.fattr);
495out:
496 nfs_free_fattr(res.dir_attr);
497 nfs_free_fattr(res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 dprintk("NFS reply link: %d\n", status);
499 return status;
500}
501
502static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400503nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
504 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400506 struct nfs3_createdata *data;
507 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Chuck Lever94a6d752006-08-22 20:06:23 -0400509 if (len > NFS3_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400511
Al Viro6de14722013-09-16 10:53:17 -0400512 dprintk("NFS call symlink %pd\n", dentry);
Chuck Lever94a6d752006-08-22 20:06:23 -0400513
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400514 data = nfs3_alloc_createdata();
515 if (data == NULL)
Chuck Lever4f390c12006-08-22 20:06:22 -0400516 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400517 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
518 data->arg.symlink.fromfh = NFS_FH(dir);
519 data->arg.symlink.fromname = dentry->d_name.name;
520 data->arg.symlink.fromlen = dentry->d_name.len;
521 data->arg.symlink.pages = &page;
522 data->arg.symlink.pathlen = len;
523 data->arg.symlink.sattr = sattr;
524
525 status = nfs3_do_create(dir, dentry, data);
526
527 nfs3_free_createdata(data);
Chuck Lever4f390c12006-08-22 20:06:22 -0400528out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 dprintk("NFS reply symlink: %d\n", status);
530 return status;
531}
532
533static int
534nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
535{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800536 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400537 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400538 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Al Viro6de14722013-09-16 10:53:17 -0400540 dprintk("NFS call mkdir %pd\n", dentry);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000541
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400542 data = nfs3_alloc_createdata();
543 if (data == NULL)
544 goto out;
545
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800546 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
547 if (status)
548 goto out;
549
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400550 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
551 data->arg.mkdir.fh = NFS_FH(dir);
552 data->arg.mkdir.name = dentry->d_name.name;
553 data->arg.mkdir.len = dentry->d_name.len;
554 data->arg.mkdir.sattr = sattr;
555
556 status = nfs3_do_create(dir, dentry, data);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000557 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800558 goto out_release_acls;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400559
David Howells2b0143b2015-03-17 22:25:59 +0000560 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800561
562out_release_acls:
563 posix_acl_release(acl);
564 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000565out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400566 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 dprintk("NFS reply mkdir: %d\n", status);
568 return status;
569}
570
571static int
Al Virobeffb8f2016-07-20 16:34:42 -0400572nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
Trond Myklebust39967dd2010-04-16 16:22:50 -0400574 struct nfs_fattr *dir_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 struct nfs3_diropargs arg = {
576 .fh = NFS_FH(dir),
577 .name = name->name,
578 .len = name->len
579 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500580 struct rpc_message msg = {
581 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
582 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500583 };
Trond Myklebust39967dd2010-04-16 16:22:50 -0400584 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 dprintk("NFS call rmdir %s\n", name->name);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400587 dir_attr = nfs_alloc_fattr();
588 if (dir_attr == NULL)
589 goto out;
590
591 msg.rpc_resp = dir_attr;
Chuck Leverdead28d2006-03-20 13:44:23 -0500592 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400593 nfs_post_op_update_inode(dir, dir_attr);
594 nfs_free_fattr(dir_attr);
595out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 dprintk("NFS reply rmdir: %d\n", status);
597 return status;
598}
599
600/*
601 * The READDIR implementation is somewhat hackish - we pass the user buffer
602 * to the encode function, which installs it in the receive iovec.
603 * The decode function itself doesn't perform any decoding, it just makes
604 * sure the reply is syntactically correct.
605 *
606 * Also note that this implementation handles both plain readdir and
607 * readdirplus.
608 */
609static int
610nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400611 u64 cookie, struct page **pages, unsigned int count, bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
David Howells2b0143b2015-03-17 22:25:59 +0000613 struct inode *dir = d_inode(dentry);
Trond Myklebustc3f52af2012-09-03 14:56:02 -0400614 __be32 *verf = NFS_I(dir)->cookieverf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 struct nfs3_readdirargs arg = {
616 .fh = NFS_FH(dir),
617 .cookie = cookie,
618 .verf = {verf[0], verf[1]},
619 .plus = plus,
620 .count = count,
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400621 .pages = pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 };
623 struct nfs3_readdirres res = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .verf = verf,
625 .plus = plus
626 };
627 struct rpc_message msg = {
628 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
629 .rpc_argp = &arg,
630 .rpc_resp = &res,
631 .rpc_cred = cred
632 };
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400633 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 if (plus)
636 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
637
638 dprintk("NFS call readdir%s %d\n",
639 plus? "plus" : "", (unsigned int) cookie);
640
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400641 res.dir_attr = nfs_alloc_fattr();
642 if (res.dir_attr == NULL)
643 goto out;
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustc4812992007-09-28 17:11:45 -0400646
647 nfs_invalidate_atime(dir);
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400648 nfs_refresh_inode(dir, res.dir_attr);
Trond Myklebustc4812992007-09-28 17:11:45 -0400649
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400650 nfs_free_fattr(res.dir_attr);
651out:
Chuck Leverd141d972010-09-21 16:55:47 -0400652 dprintk("NFS reply readdir%s: %d\n",
653 plus? "plus" : "", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return status;
655}
656
657static int
658nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
659 dev_t rdev)
660{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800661 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400662 struct nfs3_createdata *data;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400663 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Al Viro6de14722013-09-16 10:53:17 -0400665 dprintk("NFS call mknod %pd %u:%u\n", dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 MAJOR(rdev), MINOR(rdev));
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000667
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400668 data = nfs3_alloc_createdata();
669 if (data == NULL)
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000670 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400671
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800672 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
673 if (status)
674 goto out;
675
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400676 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
677 data->arg.mknod.fh = NFS_FH(dir);
678 data->arg.mknod.name = dentry->d_name.name;
679 data->arg.mknod.len = dentry->d_name.len;
680 data->arg.mknod.sattr = sattr;
681 data->arg.mknod.rdev = rdev;
682
683 switch (sattr->ia_mode & S_IFMT) {
684 case S_IFBLK:
685 data->arg.mknod.type = NF3BLK;
686 break;
687 case S_IFCHR:
688 data->arg.mknod.type = NF3CHR;
689 break;
690 case S_IFIFO:
691 data->arg.mknod.type = NF3FIFO;
692 break;
693 case S_IFSOCK:
694 data->arg.mknod.type = NF3SOCK;
695 break;
696 default:
697 status = -EINVAL;
698 goto out;
699 }
700
701 status = nfs3_do_create(dir, dentry, data);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000702 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800703 goto out_release_acls;
704
David Howells2b0143b2015-03-17 22:25:59 +0000705 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800706
707out_release_acls:
708 posix_acl_release(acl);
709 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000710out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400711 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 dprintk("NFS reply mknod: %d\n", status);
713 return status;
714}
715
716static int
717nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
718 struct nfs_fsstat *stat)
719{
Chuck Leverdead28d2006-03-20 13:44:23 -0500720 struct rpc_message msg = {
721 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
722 .rpc_argp = fhandle,
723 .rpc_resp = stat,
724 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 int status;
726
727 dprintk("NFS call fsstat\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400728 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500729 status = rpc_call_sync(server->client, &msg, 0);
Chuck Leverd141d972010-09-21 16:55:47 -0400730 dprintk("NFS reply fsstat: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return status;
732}
733
734static int
EG Keizer37ca8f52008-08-19 16:34:36 -0400735do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 struct nfs_fsinfo *info)
737{
Chuck Leverdead28d2006-03-20 13:44:23 -0500738 struct rpc_message msg = {
739 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
740 .rpc_argp = fhandle,
741 .rpc_resp = info,
742 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 int status;
744
745 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400746 nfs_fattr_init(info->fattr);
EG Keizer37ca8f52008-08-19 16:34:36 -0400747 status = rpc_call_sync(client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 dprintk("NFS reply fsinfo: %d\n", status);
749 return status;
750}
751
EG Keizer37ca8f52008-08-19 16:34:36 -0400752/*
753 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
754 * nfs_create_server
755 */
756static int
757nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
758 struct nfs_fsinfo *info)
759{
760 int status;
761
762 status = do_proc_fsinfo(server->client, fhandle, info);
763 if (status && server->nfs_client->cl_rpcclient != server->client)
764 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
765 return status;
766}
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768static int
769nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
770 struct nfs_pathconf *info)
771{
Chuck Leverdead28d2006-03-20 13:44:23 -0500772 struct rpc_message msg = {
773 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
774 .rpc_argp = fhandle,
775 .rpc_resp = info,
776 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 int status;
778
779 dprintk("NFS call pathconf\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400780 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500781 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 dprintk("NFS reply pathconf: %d\n", status);
783 return status;
784}
785
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400786static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400788 struct inode *inode = hdr->inode;
Fred Isamancd841602012-04-20 14:47:44 -0400789
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400790 if (hdr->pgio_done_cb != NULL)
791 return hdr->pgio_done_cb(task, hdr);
792
Fred Isamancd841602012-04-20 14:47:44 -0400793 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebustec06c092006-03-20 13:44:27 -0500794 return -EAGAIN;
Trond Myklebust8850df92007-09-28 17:20:07 -0400795
Fred Isamancd841602012-04-20 14:47:44 -0400796 nfs_invalidate_atime(inode);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400797 nfs_refresh_inode(inode, &hdr->fattr);
Trond Myklebustec06c092006-03-20 13:44:27 -0500798 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400801static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
802 struct rpc_message *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400804 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400807static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
808 struct nfs_pgio_header *hdr)
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400809{
810 rpc_call_start(task);
NeilBrownef1820f2013-09-04 17:04:49 +1000811 return 0;
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400812}
813
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400814static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400816 struct inode *inode = hdr->inode;
Fred Isamancd841602012-04-20 14:47:44 -0400817
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400818 if (hdr->pgio_done_cb != NULL)
819 return hdr->pgio_done_cb(task, hdr);
820
Fred Isamancd841602012-04-20 14:47:44 -0400821 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500822 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (task->tk_status >= 0)
Trond Myklebusta08a8cd2015-02-26 17:36:09 -0500824 nfs_writeback_update_inode(hdr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500825 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400828static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
Anna Schumakerfb91fb02018-05-04 16:22:48 -0400829 struct rpc_message *msg,
830 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400832 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
Fred Isaman0b7c0152012-04-20 14:47:39 -0400835static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
836{
837 rpc_call_start(task);
838}
839
840static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400842 if (data->commit_done_cb != NULL)
843 return data->commit_done_cb(task, data);
844
Chuck Lever006ea732006-03-20 13:44:14 -0500845 if (nfs3_async_handle_jukebox(task, data->inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500846 return -EAGAIN;
Trond Myklebust9e08a3c2007-10-08 14:10:31 -0400847 nfs_refresh_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500848 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
Anna Schumakere9ae1ee2018-05-04 16:22:49 -0400851static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
852 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400854 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400857static void nfs3_nlm_alloc_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400858{
859 struct nfs_lock_context *l_ctx = data;
860 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
861 get_nfs_open_context(l_ctx->open_context);
862 nfs_get_lock_context(l_ctx->open_context);
863 }
864}
865
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400866static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400867{
868 struct nfs_lock_context *l_ctx = data;
869 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
870 return nfs_async_iocounter_wait(task, l_ctx);
871 return false;
872
873}
874
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400875static void nfs3_nlm_release_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400876{
877 struct nfs_lock_context *l_ctx = data;
878 struct nfs_open_context *ctx;
879 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
880 ctx = l_ctx->open_context;
881 nfs_put_lock_context(l_ctx);
882 put_nfs_open_context(ctx);
883 }
884}
885
Colin Ian King1b720402018-02-07 11:27:54 +0000886static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400887 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
888 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
889 .nlmclnt_release_call = nfs3_nlm_release_call,
890};
891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892static int
893nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
894{
Al Viro496ad9a2013-01-23 17:07:38 -0500895 struct inode *inode = file_inode(filp);
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400896 struct nfs_lock_context *l_ctx = NULL;
897 struct nfs_open_context *ctx = nfs_file_open_context(filp);
898 int status;
Chuck Lever1093a602008-01-11 17:09:59 -0500899
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400900 if (fl->fl_flags & FL_CLOSE) {
901 l_ctx = nfs_get_lock_context(ctx);
902 if (IS_ERR(l_ctx))
903 l_ctx = NULL;
904 else
905 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
906 }
907
908 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
909
910 if (l_ctx)
911 nfs_put_lock_context(l_ctx);
912
913 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
915
Bryan Schumaker011e2a72012-06-20 15:53:43 -0400916static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
917{
918 return 0;
919}
920
Bryan Schumakerab962912012-07-16 16:39:11 -0400921static const struct inode_operations nfs3_dir_inode_operations = {
922 .create = nfs_create,
923 .lookup = nfs_lookup,
924 .link = nfs_link,
925 .unlink = nfs_unlink,
926 .symlink = nfs_symlink,
927 .mkdir = nfs_mkdir,
928 .rmdir = nfs_rmdir,
929 .mknod = nfs_mknod,
930 .rename = nfs_rename,
931 .permission = nfs_permission,
932 .getattr = nfs_getattr,
933 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800934#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200935 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800936 .get_acl = nfs3_get_acl,
937 .set_acl = nfs3_set_acl,
938#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400939};
940
941static const struct inode_operations nfs3_file_inode_operations = {
942 .permission = nfs_permission,
943 .getattr = nfs_getattr,
944 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800945#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200946 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800947 .get_acl = nfs3_get_acl,
948 .set_acl = nfs3_set_acl,
949#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400950};
951
David Howells509de812006-08-22 20:06:11 -0400952const struct nfs_rpc_ops nfs_v3_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 .version = 3, /* protocol version */
954 .dentry_ops = &nfs_dentry_operations,
Andreas Gruenbacherb7fa0552005-06-22 17:16:27 +0000955 .dir_inode_ops = &nfs3_dir_inode_operations,
956 .file_inode_ops = &nfs3_file_inode_operations,
Jeff Layton1788ea62011-11-04 13:31:21 -0400957 .file_ops = &nfs_file_operations,
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400958 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 .getroot = nfs3_proc_get_root,
Bryan Schumaker281cad42012-04-27 13:27:45 -0400960 .submount = nfs_submount,
Bryan Schumakerff9099f22012-07-30 16:05:18 -0400961 .try_mount = nfs_try_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .getattr = nfs3_proc_getattr,
963 .setattr = nfs3_proc_setattr,
964 .lookup = nfs3_proc_lookup,
965 .access = nfs3_proc_access,
966 .readlink = nfs3_proc_readlink,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 .create = nfs3_proc_create,
968 .remove = nfs3_proc_remove,
969 .unlink_setup = nfs3_proc_unlink_setup,
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400970 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 .unlink_done = nfs3_proc_unlink_done,
Jeff Laytond3d41522010-09-17 17:31:57 -0400972 .rename_setup = nfs3_proc_rename_setup,
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400973 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
Jeff Laytond3d41522010-09-17 17:31:57 -0400974 .rename_done = nfs3_proc_rename_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 .link = nfs3_proc_link,
976 .symlink = nfs3_proc_symlink,
977 .mkdir = nfs3_proc_mkdir,
978 .rmdir = nfs3_proc_rmdir,
979 .readdir = nfs3_proc_readdir,
980 .mknod = nfs3_proc_mknod,
981 .statfs = nfs3_proc_statfs,
982 .fsinfo = nfs3_proc_fsinfo,
983 .pathconf = nfs3_proc_pathconf,
984 .decode_dirent = nfs3_decode_dirent,
Anna Schumakera4cdda52014-05-06 09:12:31 -0400985 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .read_setup = nfs3_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -0500987 .read_done = nfs3_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .write_setup = nfs3_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500989 .write_done = nfs3_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 .commit_setup = nfs3_proc_commit_setup,
Fred Isaman0b7c0152012-04-20 14:47:39 -0400991 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
Trond Myklebust788e7a82006-03-20 13:44:27 -0500992 .commit_done = nfs3_commit_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 .lock = nfs3_proc_lock,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800994 .clear_acl_cache = forget_all_cached_acls,
Trond Myklebust7fe5c392009-03-19 15:35:50 -0400995 .close_context = nfs_close_context,
Bryan Schumaker011e2a72012-06-20 15:53:43 -0400996 .have_delegation = nfs3_have_delegation,
Bryan Schumaker6663ee72012-06-20 15:53:46 -0400997 .alloc_client = nfs_alloc_client,
Andy Adamson45a52a02011-03-01 01:34:08 +0000998 .init_client = nfs_init_client,
Bryan Schumakercdb7ece2012-06-20 15:53:45 -0400999 .free_client = nfs_free_client,
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001000 .create_server = nfs3_create_server,
1001 .clone_server = nfs3_clone_server,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002};