blob: 9eb2f1a503ab0a0ef57bf8f9e8844f1bece1904a [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,
NeilBrowna52458b2018-12-03 11:30:31 +1100202 .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
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400282static struct dentry *
283nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400284{
285 int status;
286
287 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
288 nfs_post_op_update_inode(dir, data->res.dir_attr);
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400289 if (status != 0)
290 return ERR_PTR(status);
291
292 return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr, NULL);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400293}
294
295static void nfs3_free_createdata(struct nfs3_createdata *data)
296{
297 kfree(data);
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/*
301 * Create a regular file.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 */
303static int
304nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
Miklos Szeredi8867fe52012-06-05 15:10:19 +0200305 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800307 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400308 struct nfs3_createdata *data;
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400309 struct dentry *d_alias;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400310 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Al Viro6de14722013-09-16 10:53:17 -0400312 dprintk("NFS call create %pd\n", dentry);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400313
314 data = nfs3_alloc_createdata();
315 if (data == NULL)
316 goto out;
317
318 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
319 data->arg.create.fh = NFS_FH(dir);
320 data->arg.create.name = dentry->d_name.name;
321 data->arg.create.len = dentry->d_name.len;
322 data->arg.create.sattr = sattr;
323
324 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (flags & O_EXCL) {
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400326 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
Trond Myklebusta9943d12013-08-20 21:04:11 -0400327 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
328 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800331 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
332 if (status)
333 goto out;
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000334
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400335 for (;;) {
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400336 d_alias = nfs3_do_create(dir, dentry, data);
337 status = PTR_ERR_OR_ZERO(d_alias);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400339 if (status != -ENOTSUPP)
340 break;
341 /* If the server doesn't support the exclusive creation
342 * semantics, try again with simple 'guarded' mode. */
343 switch (data->arg.create.createmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 case NFS3_CREATE_EXCLUSIVE:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400345 data->arg.create.createmode = NFS3_CREATE_GUARDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347
348 case NFS3_CREATE_GUARDED:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400349 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
351
352 case NFS3_CREATE_UNCHECKED:
353 goto out;
354 }
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400355 nfs_fattr_init(data->res.dir_attr);
356 nfs_fattr_init(data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800360 goto out_release_acls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400362 if (d_alias)
363 dentry = d_alias;
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 /* When we created the file with exclusive semantics, make
366 * sure we set the attributes afterwards. */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400367 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 dprintk("NFS call setattr (post-create)\n");
369
370 if (!(sattr->ia_valid & ATTR_ATIME_SET))
371 sattr->ia_valid |= ATTR_ATIME;
372 if (!(sattr->ia_valid & ATTR_MTIME_SET))
373 sattr->ia_valid |= ATTR_MTIME;
374
375 /* Note: we could use a guarded setattr here, but I'm
376 * not sure this buys us anything (and I'd have
377 * to revamp the NFSv3 XDR code) */
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400378 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
David Howells2b0143b2015-03-17 22:25:59 +0000379 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 dprintk("NFS reply setattr (post-create): %d\n", status);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400381 if (status != 0)
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400382 goto out_dput;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800384
David Howells2b0143b2015-03-17 22:25:59 +0000385 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800386
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400387out_dput:
388 dput(d_alias);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800389out_release_acls:
390 posix_acl_release(acl);
391 posix_acl_release(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400393 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 dprintk("NFS reply create: %d\n", status);
395 return status;
396}
397
398static int
Trond Myklebust912678d2018-03-20 16:43:15 -0400399nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400401 struct nfs_removeargs arg = {
402 .fh = NFS_FH(dir),
Trond Myklebust912678d2018-03-20 16:43:15 -0400403 .name = dentry->d_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 };
Trond Myklebust4fdc17b2007-07-14 15:39:57 -0400405 struct nfs_removeres res;
406 struct rpc_message msg = {
407 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
408 .rpc_argp = &arg,
409 .rpc_resp = &res,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 };
Trond Myklebustd3468902010-04-16 16:22:50 -0400411 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Trond Myklebust912678d2018-03-20 16:43:15 -0400413 dprintk("NFS call remove %pd2\n", dentry);
Trond Myklebustd3468902010-04-16 16:22:50 -0400414 res.dir_attr = nfs_alloc_fattr();
415 if (res.dir_attr == NULL)
416 goto out;
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustd3468902010-04-16 16:22:50 -0400419 nfs_post_op_update_inode(dir, res.dir_attr);
420 nfs_free_fattr(res.dir_attr);
421out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 dprintk("NFS reply remove: %d\n", status);
423 return status;
424}
425
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400426static void
Trond Myklebusted7e9ad2018-05-30 16:11:52 -0400427nfs3_proc_unlink_setup(struct rpc_message *msg,
428 struct dentry *dentry,
429 struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Bryan Schumaker34e137c2012-03-19 14:54:41 -0400434static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
435{
436 rpc_call_start(task);
437}
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439static int
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400440nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400442 struct nfs_removeres *res;
443 if (nfs3_async_handle_jukebox(task, dir))
444 return 0;
445 res = task->tk_msg.rpc_resp;
Trond Myklebustd3468902010-04-16 16:22:50 -0400446 nfs_post_op_update_inode(dir, res->dir_attr);
Trond Myklebuste4eff1a2007-07-14 15:39:58 -0400447 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
449
Jeff Laytond3d41522010-09-17 17:31:57 -0400450static void
Trond Myklebustf2c2c552018-03-20 16:43:16 -0400451nfs3_proc_rename_setup(struct rpc_message *msg,
452 struct dentry *old_dentry,
453 struct dentry *new_dentry)
Jeff Laytond3d41522010-09-17 17:31:57 -0400454{
455 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
456}
457
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -0400458static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
459{
460 rpc_call_start(task);
461}
462
Jeff Laytond3d41522010-09-17 17:31:57 -0400463static int
464nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
465 struct inode *new_dir)
466{
467 struct nfs_renameres *res;
468
469 if (nfs3_async_handle_jukebox(task, old_dir))
470 return 0;
471 res = task->tk_msg.rpc_resp;
472
473 nfs_post_op_update_inode(old_dir, res->old_fattr);
474 nfs_post_op_update_inode(new_dir, res->new_fattr);
475 return 1;
476}
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478static int
Al Virobeffb8f2016-07-20 16:34:42 -0400479nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 struct nfs3_linkargs arg = {
482 .fromfh = NFS_FH(inode),
483 .tofh = NFS_FH(dir),
484 .toname = name->name,
485 .tolen = name->len
486 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400487 struct nfs3_linkres res;
Chuck Leverdead28d2006-03-20 13:44:23 -0500488 struct rpc_message msg = {
489 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
490 .rpc_argp = &arg,
491 .rpc_resp = &res,
492 };
Trond Myklebust136f2622010-04-16 16:22:49 -0400493 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 dprintk("NFS call link %s\n", name->name);
Trond Myklebust136f2622010-04-16 16:22:49 -0400496 res.fattr = nfs_alloc_fattr();
497 res.dir_attr = nfs_alloc_fattr();
498 if (res.fattr == NULL || res.dir_attr == NULL)
499 goto out;
500
Chuck Leverdead28d2006-03-20 13:44:23 -0500501 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
Trond Myklebust136f2622010-04-16 16:22:49 -0400502 nfs_post_op_update_inode(dir, res.dir_attr);
503 nfs_post_op_update_inode(inode, res.fattr);
504out:
505 nfs_free_fattr(res.dir_attr);
506 nfs_free_fattr(res.fattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 dprintk("NFS reply link: %d\n", status);
508 return status;
509}
510
511static int
Chuck Lever94a6d752006-08-22 20:06:23 -0400512nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
513 unsigned int len, struct iattr *sattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400515 struct nfs3_createdata *data;
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400516 struct dentry *d_alias;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400517 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Chuck Lever94a6d752006-08-22 20:06:23 -0400519 if (len > NFS3_MAXPATHLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 return -ENAMETOOLONG;
Chuck Lever4f390c12006-08-22 20:06:22 -0400521
Al Viro6de14722013-09-16 10:53:17 -0400522 dprintk("NFS call symlink %pd\n", dentry);
Chuck Lever94a6d752006-08-22 20:06:23 -0400523
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400524 data = nfs3_alloc_createdata();
525 if (data == NULL)
Chuck Lever4f390c12006-08-22 20:06:22 -0400526 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400527 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
528 data->arg.symlink.fromfh = NFS_FH(dir);
529 data->arg.symlink.fromname = dentry->d_name.name;
530 data->arg.symlink.fromlen = dentry->d_name.len;
531 data->arg.symlink.pages = &page;
532 data->arg.symlink.pathlen = len;
533 data->arg.symlink.sattr = sattr;
534
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400535 d_alias = nfs3_do_create(dir, dentry, data);
536 status = PTR_ERR_OR_ZERO(d_alias);
537
538 if (status == 0)
539 dput(d_alias);
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400540
541 nfs3_free_createdata(data);
Chuck Lever4f390c12006-08-22 20:06:22 -0400542out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 dprintk("NFS reply symlink: %d\n", status);
544 return status;
545}
546
547static int
548nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
549{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800550 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400551 struct nfs3_createdata *data;
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400552 struct dentry *d_alias;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400553 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Al Viro6de14722013-09-16 10:53:17 -0400555 dprintk("NFS call mkdir %pd\n", dentry);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000556
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400557 data = nfs3_alloc_createdata();
558 if (data == NULL)
559 goto out;
560
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800561 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
562 if (status)
563 goto out;
564
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400565 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
566 data->arg.mkdir.fh = NFS_FH(dir);
567 data->arg.mkdir.name = dentry->d_name.name;
568 data->arg.mkdir.len = dentry->d_name.len;
569 data->arg.mkdir.sattr = sattr;
570
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400571 d_alias = nfs3_do_create(dir, dentry, data);
572 status = PTR_ERR_OR_ZERO(d_alias);
573
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000574 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800575 goto out_release_acls;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400576
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400577 if (d_alias)
578 dentry = d_alias;
579
David Howells2b0143b2015-03-17 22:25:59 +0000580 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800581
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400582 dput(d_alias);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800583out_release_acls:
584 posix_acl_release(acl);
585 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000586out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400587 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 dprintk("NFS reply mkdir: %d\n", status);
589 return status;
590}
591
592static int
Al Virobeffb8f2016-07-20 16:34:42 -0400593nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Trond Myklebust39967dd2010-04-16 16:22:50 -0400595 struct nfs_fattr *dir_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 struct nfs3_diropargs arg = {
597 .fh = NFS_FH(dir),
598 .name = name->name,
599 .len = name->len
600 };
Chuck Leverdead28d2006-03-20 13:44:23 -0500601 struct rpc_message msg = {
602 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
603 .rpc_argp = &arg,
Chuck Leverdead28d2006-03-20 13:44:23 -0500604 };
Trond Myklebust39967dd2010-04-16 16:22:50 -0400605 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 dprintk("NFS call rmdir %s\n", name->name);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400608 dir_attr = nfs_alloc_fattr();
609 if (dir_attr == NULL)
610 goto out;
611
612 msg.rpc_resp = dir_attr;
Chuck Leverdead28d2006-03-20 13:44:23 -0500613 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebust39967dd2010-04-16 16:22:50 -0400614 nfs_post_op_update_inode(dir, dir_attr);
615 nfs_free_fattr(dir_attr);
616out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 dprintk("NFS reply rmdir: %d\n", status);
618 return status;
619}
620
621/*
622 * The READDIR implementation is somewhat hackish - we pass the user buffer
623 * to the encode function, which installs it in the receive iovec.
624 * The decode function itself doesn't perform any decoding, it just makes
625 * sure the reply is syntactically correct.
626 *
627 * Also note that this implementation handles both plain readdir and
628 * readdirplus.
629 */
630static int
NeilBrown684f39b2018-12-03 11:30:30 +1100631nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -0400632 u64 cookie, struct page **pages, unsigned int count, bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
David Howells2b0143b2015-03-17 22:25:59 +0000634 struct inode *dir = d_inode(dentry);
Trond Myklebustc3f52af2012-09-03 14:56:02 -0400635 __be32 *verf = NFS_I(dir)->cookieverf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 struct nfs3_readdirargs arg = {
637 .fh = NFS_FH(dir),
638 .cookie = cookie,
639 .verf = {verf[0], verf[1]},
640 .plus = plus,
641 .count = count,
Bryan Schumaker56e4ebf2010-10-20 15:44:37 -0400642 .pages = pages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 };
644 struct nfs3_readdirres res = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .verf = verf,
646 .plus = plus
647 };
648 struct rpc_message msg = {
649 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
650 .rpc_argp = &arg,
651 .rpc_resp = &res,
NeilBrowna52458b2018-12-03 11:30:31 +1100652 .rpc_cred = cred,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 };
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400654 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (plus)
657 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
658
659 dprintk("NFS call readdir%s %d\n",
660 plus? "plus" : "", (unsigned int) cookie);
661
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400662 res.dir_attr = nfs_alloc_fattr();
663 if (res.dir_attr == NULL)
664 goto out;
665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
Trond Myklebustc4812992007-09-28 17:11:45 -0400667
668 nfs_invalidate_atime(dir);
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400669 nfs_refresh_inode(dir, res.dir_attr);
Trond Myklebustc4812992007-09-28 17:11:45 -0400670
Trond Myklebustaa49b4c2010-04-16 16:22:49 -0400671 nfs_free_fattr(res.dir_attr);
672out:
Chuck Leverd141d972010-09-21 16:55:47 -0400673 dprintk("NFS reply readdir%s: %d\n",
674 plus? "plus" : "", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 return status;
676}
677
678static int
679nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
680 dev_t rdev)
681{
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800682 struct posix_acl *default_acl, *acl;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400683 struct nfs3_createdata *data;
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400684 struct dentry *d_alias;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400685 int status = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Al Viro6de14722013-09-16 10:53:17 -0400687 dprintk("NFS call mknod %pd %u:%u\n", dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 MAJOR(rdev), MINOR(rdev));
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000689
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400690 data = nfs3_alloc_createdata();
691 if (data == NULL)
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000692 goto out;
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400693
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800694 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
695 if (status)
696 goto out;
697
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400698 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
699 data->arg.mknod.fh = NFS_FH(dir);
700 data->arg.mknod.name = dentry->d_name.name;
701 data->arg.mknod.len = dentry->d_name.len;
702 data->arg.mknod.sattr = sattr;
703 data->arg.mknod.rdev = rdev;
704
705 switch (sattr->ia_mode & S_IFMT) {
706 case S_IFBLK:
707 data->arg.mknod.type = NF3BLK;
708 break;
709 case S_IFCHR:
710 data->arg.mknod.type = NF3CHR;
711 break;
712 case S_IFIFO:
713 data->arg.mknod.type = NF3FIFO;
714 break;
715 case S_IFSOCK:
716 data->arg.mknod.type = NF3SOCK;
717 break;
718 default:
719 status = -EINVAL;
720 goto out;
721 }
722
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400723 d_alias = nfs3_do_create(dir, dentry, data);
724 status = PTR_ERR_OR_ZERO(d_alias);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000725 if (status != 0)
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800726 goto out_release_acls;
727
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400728 if (d_alias)
729 dentry = d_alias;
730
David Howells2b0143b2015-03-17 22:25:59 +0000731 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800732
Benjamin Coddington17fd6e42019-09-13 08:29:03 -0400733 dput(d_alias);
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800734out_release_acls:
735 posix_acl_release(acl);
736 posix_acl_release(default_acl);
Andreas Gruenbacher055ffbe2005-06-22 17:16:27 +0000737out:
Trond Myklebust0b4aae72008-06-20 17:00:23 -0400738 nfs3_free_createdata(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 dprintk("NFS reply mknod: %d\n", status);
740 return status;
741}
742
743static int
744nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
745 struct nfs_fsstat *stat)
746{
Chuck Leverdead28d2006-03-20 13:44:23 -0500747 struct rpc_message msg = {
748 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
749 .rpc_argp = fhandle,
750 .rpc_resp = stat,
751 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 int status;
753
754 dprintk("NFS call fsstat\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400755 nfs_fattr_init(stat->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500756 status = rpc_call_sync(server->client, &msg, 0);
Chuck Leverd141d972010-09-21 16:55:47 -0400757 dprintk("NFS reply fsstat: %d\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 return status;
759}
760
761static int
EG Keizer37ca8f52008-08-19 16:34:36 -0400762do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 struct nfs_fsinfo *info)
764{
Chuck Leverdead28d2006-03-20 13:44:23 -0500765 struct rpc_message msg = {
766 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
767 .rpc_argp = fhandle,
768 .rpc_resp = info,
769 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 int status;
771
772 dprintk("NFS call fsinfo\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400773 nfs_fattr_init(info->fattr);
EG Keizer37ca8f52008-08-19 16:34:36 -0400774 status = rpc_call_sync(client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 dprintk("NFS reply fsinfo: %d\n", status);
776 return status;
777}
778
EG Keizer37ca8f52008-08-19 16:34:36 -0400779/*
780 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
781 * nfs_create_server
782 */
783static int
784nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
785 struct nfs_fsinfo *info)
786{
787 int status;
788
789 status = do_proc_fsinfo(server->client, fhandle, info);
790 if (status && server->nfs_client->cl_rpcclient != server->client)
791 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
792 return status;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795static int
796nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
797 struct nfs_pathconf *info)
798{
Chuck Leverdead28d2006-03-20 13:44:23 -0500799 struct rpc_message msg = {
800 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
801 .rpc_argp = fhandle,
802 .rpc_resp = info,
803 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 int status;
805
806 dprintk("NFS call pathconf\n");
Trond Myklebust0e574af2005-10-27 22:12:38 -0400807 nfs_fattr_init(info->fattr);
Chuck Leverdead28d2006-03-20 13:44:23 -0500808 status = rpc_call_sync(server->client, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 dprintk("NFS reply pathconf: %d\n", status);
810 return status;
811}
812
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400813static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400815 struct inode *inode = hdr->inode;
Trond Myklebust8d8928d2018-03-05 12:03:00 -0500816 struct nfs_server *server = NFS_SERVER(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 Myklebustec06c092006-03-20 13:44:27 -0500822 return -EAGAIN;
Trond Myklebust8850df92007-09-28 17:20:07 -0400823
Trond Myklebust8d8928d2018-03-05 12:03:00 -0500824 if (task->tk_status >= 0 && !server->read_hdrsize)
825 cmpxchg(&server->read_hdrsize, 0, hdr->res.replen);
826
Fred Isamancd841602012-04-20 14:47:44 -0400827 nfs_invalidate_atime(inode);
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400828 nfs_refresh_inode(inode, &hdr->fattr);
Trond Myklebustec06c092006-03-20 13:44:27 -0500829 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400832static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
833 struct rpc_message *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400835 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
Trond Myklebust8d8928d2018-03-05 12:03:00 -0500836 hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400839static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
840 struct nfs_pgio_header *hdr)
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400841{
842 rpc_call_start(task);
NeilBrownef1820f2013-09-04 17:04:49 +1000843 return 0;
Bryan Schumakerea7c3302012-03-19 14:54:40 -0400844}
845
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400846static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400848 struct inode *inode = hdr->inode;
Fred Isamancd841602012-04-20 14:47:44 -0400849
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400850 if (hdr->pgio_done_cb != NULL)
851 return hdr->pgio_done_cb(task, hdr);
852
Fred Isamancd841602012-04-20 14:47:44 -0400853 if (nfs3_async_handle_jukebox(task, inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500854 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (task->tk_status >= 0)
Trond Myklebusta08a8cd2015-02-26 17:36:09 -0500856 nfs_writeback_update_inode(hdr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500857 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
Weston Andros Adamsond45f60c2014-06-09 11:48:35 -0400860static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
Anna Schumakerfb91fb02018-05-04 16:22:48 -0400861 struct rpc_message *msg,
862 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400864 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
Fred Isaman0b7c0152012-04-20 14:47:39 -0400867static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
868{
869 rpc_call_start(task);
870}
871
872static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Trond Myklebust16cecdf2014-06-22 12:55:11 -0400874 if (data->commit_done_cb != NULL)
875 return data->commit_done_cb(task, data);
876
Chuck Lever006ea732006-03-20 13:44:14 -0500877 if (nfs3_async_handle_jukebox(task, data->inode))
Trond Myklebust788e7a82006-03-20 13:44:27 -0500878 return -EAGAIN;
Trond Myklebust9e08a3c2007-10-08 14:10:31 -0400879 nfs_refresh_inode(data->inode, data->res.fattr);
Trond Myklebust788e7a82006-03-20 13:44:27 -0500880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
Anna Schumakere9ae1ee22018-05-04 16:22:49 -0400883static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
884 struct rpc_clnt **clnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Trond Myklebustbdc7f022007-07-14 15:40:00 -0400886 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400889static void nfs3_nlm_alloc_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400890{
891 struct nfs_lock_context *l_ctx = data;
892 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
893 get_nfs_open_context(l_ctx->open_context);
894 nfs_get_lock_context(l_ctx->open_context);
895 }
896}
897
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400898static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400899{
900 struct nfs_lock_context *l_ctx = data;
901 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
902 return nfs_async_iocounter_wait(task, l_ctx);
903 return false;
904
905}
906
Trond Myklebustbb3393d2017-04-25 16:25:06 -0400907static void nfs3_nlm_release_call(void *data)
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400908{
909 struct nfs_lock_context *l_ctx = data;
910 struct nfs_open_context *ctx;
911 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
912 ctx = l_ctx->open_context;
913 nfs_put_lock_context(l_ctx);
914 put_nfs_open_context(ctx);
915 }
916}
917
Colin Ian King1b720402018-02-07 11:27:54 +0000918static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400919 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
920 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
921 .nlmclnt_release_call = nfs3_nlm_release_call,
922};
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924static int
925nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
926{
Al Viro496ad9a2013-01-23 17:07:38 -0500927 struct inode *inode = file_inode(filp);
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400928 struct nfs_lock_context *l_ctx = NULL;
929 struct nfs_open_context *ctx = nfs_file_open_context(filp);
930 int status;
Chuck Lever1093a602008-01-11 17:09:59 -0500931
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400932 if (fl->fl_flags & FL_CLOSE) {
933 l_ctx = nfs_get_lock_context(ctx);
934 if (IS_ERR(l_ctx))
935 l_ctx = NULL;
936 else
937 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
938 }
939
940 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
941
942 if (l_ctx)
943 nfs_put_lock_context(l_ctx);
944
945 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946}
947
Bryan Schumaker011e2a72012-06-20 15:53:43 -0400948static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
949{
950 return 0;
951}
952
Bryan Schumakerab962912012-07-16 16:39:11 -0400953static const struct inode_operations nfs3_dir_inode_operations = {
954 .create = nfs_create,
955 .lookup = nfs_lookup,
956 .link = nfs_link,
957 .unlink = nfs_unlink,
958 .symlink = nfs_symlink,
959 .mkdir = nfs_mkdir,
960 .rmdir = nfs_rmdir,
961 .mknod = nfs_mknod,
962 .rename = nfs_rename,
963 .permission = nfs_permission,
964 .getattr = nfs_getattr,
965 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800966#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200967 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800968 .get_acl = nfs3_get_acl,
969 .set_acl = nfs3_set_acl,
970#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400971};
972
973static const struct inode_operations nfs3_file_inode_operations = {
974 .permission = nfs_permission,
975 .getattr = nfs_getattr,
976 .setattr = nfs_setattr,
Christoph Hellwig5f13ee92014-01-30 06:01:52 -0800977#ifdef CONFIG_NFS_V3_ACL
Christoph Hellwig74adf832014-06-18 11:07:03 +0200978 .listxattr = nfs3_listxattr,
Christoph Hellwig013cdf12013-12-20 05:16:53 -0800979 .get_acl = nfs3_get_acl,
980 .set_acl = nfs3_set_acl,
981#endif
Bryan Schumakerab962912012-07-16 16:39:11 -0400982};
983
David Howells509de812006-08-22 20:06:11 -0400984const struct nfs_rpc_ops nfs_v3_clientops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 .version = 3, /* protocol version */
986 .dentry_ops = &nfs_dentry_operations,
Andreas Gruenbacherb7fa0552005-06-22 17:16:27 +0000987 .dir_inode_ops = &nfs3_dir_inode_operations,
988 .file_inode_ops = &nfs3_file_inode_operations,
Jeff Layton1788ea62011-11-04 13:31:21 -0400989 .file_ops = &nfs_file_operations,
Benjamin Coddingtonf30cb752017-04-11 12:50:12 -0400990 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .getroot = nfs3_proc_get_root,
Bryan Schumaker281cad42012-04-27 13:27:45 -0400992 .submount = nfs_submount,
Bryan Schumakerff9099f22012-07-30 16:05:18 -0400993 .try_mount = nfs_try_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 .getattr = nfs3_proc_getattr,
995 .setattr = nfs3_proc_setattr,
996 .lookup = nfs3_proc_lookup,
997 .access = nfs3_proc_access,
998 .readlink = nfs3_proc_readlink,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .create = nfs3_proc_create,
1000 .remove = nfs3_proc_remove,
1001 .unlink_setup = nfs3_proc_unlink_setup,
Bryan Schumaker34e137c2012-03-19 14:54:41 -04001002 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .unlink_done = nfs3_proc_unlink_done,
Jeff Laytond3d41522010-09-17 17:31:57 -04001004 .rename_setup = nfs3_proc_rename_setup,
Bryan Schumakerc6bfa1a2012-03-19 14:54:42 -04001005 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
Jeff Laytond3d41522010-09-17 17:31:57 -04001006 .rename_done = nfs3_proc_rename_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 .link = nfs3_proc_link,
1008 .symlink = nfs3_proc_symlink,
1009 .mkdir = nfs3_proc_mkdir,
1010 .rmdir = nfs3_proc_rmdir,
1011 .readdir = nfs3_proc_readdir,
1012 .mknod = nfs3_proc_mknod,
1013 .statfs = nfs3_proc_statfs,
1014 .fsinfo = nfs3_proc_fsinfo,
1015 .pathconf = nfs3_proc_pathconf,
1016 .decode_dirent = nfs3_decode_dirent,
Anna Schumakera4cdda52014-05-06 09:12:31 -04001017 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .read_setup = nfs3_proc_read_setup,
Trond Myklebustec06c092006-03-20 13:44:27 -05001019 .read_done = nfs3_read_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 .write_setup = nfs3_proc_write_setup,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001021 .write_done = nfs3_write_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .commit_setup = nfs3_proc_commit_setup,
Fred Isaman0b7c0152012-04-20 14:47:39 -04001023 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
Trond Myklebust788e7a82006-03-20 13:44:27 -05001024 .commit_done = nfs3_commit_done,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .lock = nfs3_proc_lock,
Christoph Hellwig013cdf12013-12-20 05:16:53 -08001026 .clear_acl_cache = forget_all_cached_acls,
Trond Myklebust7fe5c392009-03-19 15:35:50 -04001027 .close_context = nfs_close_context,
Bryan Schumaker011e2a72012-06-20 15:53:43 -04001028 .have_delegation = nfs3_have_delegation,
Bryan Schumaker6663ee72012-06-20 15:53:46 -04001029 .alloc_client = nfs_alloc_client,
Andy Adamson45a52a02011-03-01 01:34:08 +00001030 .init_client = nfs_init_client,
Bryan Schumakercdb7eced2012-06-20 15:53:45 -04001031 .free_client = nfs_free_client,
Bryan Schumaker1179acc2012-07-30 16:05:19 -04001032 .create_server = nfs3_create_server,
1033 .clone_server = nfs3_clone_server,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034};