blob: 1a1ff247bc59774682c7008aa85c33e165e9957d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Server-side procedures for NFSv4.
3 *
4 * Copyright (c) 2002 The Regents of the University of Michigan.
5 * All rights reserved.
6 *
7 * Kendrick Smith <kmsmith@umich.edu>
8 * Andy Adamson <andros@umich.edu>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
NeilBrown7e06b7f2005-06-23 22:03:13 -070035#include <linux/file.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Mi Jinlong58e7b332011-08-28 18:18:56 +080038#include "idmap.h"
Boaz Harrosh9a74af22009-12-03 20:30:56 +020039#include "cache.h"
40#include "xdr4.h"
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050041#include "vfs.h"
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +010042#include "current_stateid.h"
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +030043#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
David Quigley18032ca2013-05-02 13:19:10 -040045#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
46#include <linux/security.h>
47
48static inline void
49nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
50{
51 struct inode *inode = resfh->fh_dentry->d_inode;
52 int status;
53
54 mutex_lock(&inode->i_mutex);
55 status = security_inode_setsecctx(resfh->fh_dentry,
56 label->data, label->len);
57 mutex_unlock(&inode->i_mutex);
58
59 if (status)
60 /*
61 * XXX: We should really fail the whole open, but we may
62 * already have created a new file, so it may be too
63 * late. For now this seems the least of evils:
64 */
65 bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
66
67 return;
68}
69#else
70static inline void
71nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
72{ }
73#endif
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define NFSDDBG_FACILITY NFSDDBG_PROC
76
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080077static u32 nfsd_attrmask[] = {
78 NFSD_WRITEABLE_ATTRS_WORD0,
79 NFSD_WRITEABLE_ATTRS_WORD1,
80 NFSD_WRITEABLE_ATTRS_WORD2
81};
82
83static u32 nfsd41_ex_attrmask[] = {
84 NFSD_SUPPATTR_EXCLCREAT_WORD0,
85 NFSD_SUPPATTR_EXCLCREAT_WORD1,
86 NFSD_SUPPATTR_EXCLCREAT_WORD2
87};
88
89static __be32
90check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
91 u32 *bmval, u32 *writable)
92{
93 struct dentry *dentry = cstate->current_fh.fh_dentry;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080094
95 /*
96 * Check about attributes are supported by the NFSv4 server or not.
97 * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
98 */
99 if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
100 (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
101 (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
102 return nfserr_attrnotsupp;
103
104 /*
Trond Myklebusta06b1262009-08-31 15:16:11 -0400105 * Check FATTR4_WORD0_ACL can be supported
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800106 * in current environment or not.
107 */
108 if (bmval[0] & FATTR4_WORD0_ACL) {
109 if (!IS_POSIXACL(dentry->d_inode))
110 return nfserr_attrnotsupp;
111 }
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800112
113 /*
114 * According to spec, read-only attributes return ERR_INVAL.
115 */
116 if (writable) {
117 if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
118 (bmval[2] & ~writable[2]))
119 return nfserr_inval;
120 }
121
122 return nfs_ok;
123}
124
125static __be32
126nfsd4_check_open_attributes(struct svc_rqst *rqstp,
127 struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
128{
129 __be32 status = nfs_ok;
130
131 if (open->op_create == NFS4_OPEN_CREATE) {
132 if (open->op_createmode == NFS4_CREATE_UNCHECKED
133 || open->op_createmode == NFS4_CREATE_GUARDED)
134 status = check_attr_support(rqstp, cstate,
135 open->op_bmval, nfsd_attrmask);
136 else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
137 status = check_attr_support(rqstp, cstate,
138 open->op_bmval, nfsd41_ex_attrmask);
139 }
140
141 return status;
142}
143
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800144static int
145is_create_with_attrs(struct nfsd4_open *open)
146{
147 return open->op_create == NFS4_OPEN_CREATE
148 && (open->op_createmode == NFS4_CREATE_UNCHECKED
149 || open->op_createmode == NFS4_CREATE_GUARDED
150 || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
151}
152
153/*
154 * if error occurs when setting the acl, just clear the acl bit
155 * in the returned attr bitmap.
156 */
157static void
158do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
159 struct nfs4_acl *acl, u32 *bmval)
160{
161 __be32 status;
162
163 status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
164 if (status)
165 /*
166 * We should probably fail the whole open at this point,
167 * but we've already created the file, so it's too late;
168 * So this seems the least of evils:
169 */
170 bmval[0] &= ~FATTR4_WORD0_ACL;
171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static inline void
174fh_dup2(struct svc_fh *dst, struct svc_fh *src)
175{
176 fh_put(dst);
177 dget(src->fh_dentry);
178 if (src->fh_export)
179 cache_get(&src->fh_export->h);
180 *dst = *src;
181}
182
Al Virob37ad282006-10-19 23:28:59 -0700183static __be32
J. Bruce Fieldsdc730e12006-10-17 00:10:13 -0700184do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Al Virob37ad282006-10-19 23:28:59 -0700186 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 if (open->op_truncate &&
189 !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
190 return nfserr_inval;
191
J. Bruce Fieldsa0432262011-08-25 10:48:39 -0400192 accmode |= NFSD_MAY_READ_IF_EXEC;
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200195 accmode |= NFSD_MAY_READ;
J. Bruce Fields9801d8a2006-10-17 00:10:14 -0700196 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200197 accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
J. Bruce Fields57ecb342009-12-01 19:42:57 -0500198 if (open->op_share_deny & NFS4_SHARE_DENY_READ)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200199 accmode |= NFSD_MAY_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
202
203 return status;
204}
205
J. Bruce Fieldsaadab6c2011-08-15 16:55:02 -0400206static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
207{
208 umode_t mode = fh->fh_dentry->d_inode->i_mode;
209
210 if (S_ISREG(mode))
211 return nfs_ok;
212 if (S_ISDIR(mode))
213 return nfserr_isdir;
214 /*
215 * Using err_symlink as our catch-all case may look odd; but
216 * there's no other obvious error for this case in 4.0, and we
217 * happen to know that it will cause the linux v4 client to do
218 * the right thing on attempts to open something other than a
219 * regular file.
220 */
221 return nfserr_symlink;
222}
223
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400224static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400226 if (nfsd4_has_session(cstate))
227 return;
228 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
229 &resfh->fh_handle);
230}
231
232static __be32
233do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
234{
235 struct svc_fh *current_fh = &cstate->current_fh;
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500236 struct svc_fh *resfh;
Neil Brown7007c902012-12-07 15:40:55 -0500237 int accmode;
Al Virob37ad282006-10-19 23:28:59 -0700238 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500240 resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
241 if (!resfh)
242 return nfserr_jukebox;
243 fh_init(resfh, NFS4_FHSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 open->op_truncate = 0;
245
246 if (open->op_create) {
Benny Halevy79fb54a2009-04-03 08:29:17 +0300247 /* FIXME: check session persistence and pnfs flags.
248 * The nfsv4.1 spec requires the following semantics:
249 *
250 * Persistent | pNFS | Server REQUIRED | Client Allowed
251 * Reply Cache | server | |
252 * -------------+--------+-----------------+--------------------
253 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
254 * | | | (SHOULD)
255 * | | and EXCLUSIVE4 | or EXCLUSIVE4
256 * | | | (SHOULD NOT)
257 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
258 * yes | no | GUARDED4 | GUARDED4
259 * yes | yes | GUARDED4 | GUARDED4
260 */
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 /*
263 * Note: create modes (UNCHECKED,GUARDED...) are the same
Mi Jinlongac6721a2011-04-20 17:06:25 +0800264 * in NFSv4 as in v3 except EXCLUSIVE4_1.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 */
Mi Jinlongac6721a2011-04-20 17:06:25 +0800266 status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 open->op_fname.len, &open->op_iattr,
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500268 resfh, open->op_createmode,
Jeff Layton749997e2007-07-31 00:37:51 -0700269 (u32 *)open->op_verf.data,
J. Bruce Fields856121b2011-10-13 11:37:11 -0400270 &open->op_truncate, &open->op_created);
Jeff Layton749997e2007-07-31 00:37:51 -0700271
David Quigley18032ca2013-05-02 13:19:10 -0400272 if (!status && open->op_label.len)
273 nfsd4_security_inode_setsecctx(resfh, &open->op_label, open->op_bmval);
274
J. Bruce Fields99f88722009-02-02 15:12:27 -0500275 /*
276 * Following rfc 3530 14.2.16, use the returned bitmask
277 * to indicate which attributes we used to store the
278 * verifier:
Jeff Layton749997e2007-07-31 00:37:51 -0700279 */
280 if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
J. Bruce Fields99f88722009-02-02 15:12:27 -0500281 open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
J. Bruce Fields9dc4e6c2012-04-09 18:06:49 -0400282 FATTR4_WORD1_TIME_MODIFY);
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800283 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 status = nfsd_lookup(rqstp, current_fh,
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500285 open->op_fname.data, open->op_fname.len, resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 fh_unlock(current_fh);
287 }
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800288 if (status)
289 goto out;
J. Bruce Fields9dc4e6c2012-04-09 18:06:49 -0400290 status = nfsd_check_obj_isreg(resfh);
291 if (status)
292 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800294 if (is_create_with_attrs(open) && open->op_acl != NULL)
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500295 do_set_nfs4_acl(rqstp, resfh, open->op_acl, open->op_bmval);
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800296
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400297 nfsd4_set_open_owner_reply_cache(cstate, open, resfh);
Neil Brown7007c902012-12-07 15:40:55 -0500298 accmode = NFSD_MAY_NOP;
299 if (open->op_created)
300 accmode |= NFSD_MAY_OWNER_OVERRIDE;
301 status = do_open_permission(rqstp, resfh, open, accmode);
J. Bruce Fields41fd1e42012-01-27 16:26:02 -0500302 set_change_info(&open->op_cinfo, current_fh);
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500303 fh_dup2(current_fh, resfh);
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800304out:
J. Bruce Fields59deeb92012-01-27 16:49:55 -0500305 fh_put(resfh);
306 kfree(resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return status;
308}
309
Al Virob37ad282006-10-19 23:28:59 -0700310static __be32
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400311do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400313 struct svc_fh *current_fh = &cstate->current_fh;
Al Virob37ad282006-10-19 23:28:59 -0700314 __be32 status;
J. Bruce Fields9f415eb2013-05-03 16:09:09 -0400315 int accmode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 /* We don't know the target directory, and therefore can not
318 * set the change info
319 */
320
321 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
322
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400323 nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
326 (open->op_iattr.ia_size == 0);
J. Bruce Fields9f415eb2013-05-03 16:09:09 -0400327 /*
328 * In the delegation case, the client is telling us about an
329 * open that it *already* performed locally, some time ago. We
330 * should let it succeed now if possible.
331 *
332 * In the case of a CLAIM_FH open, on the other hand, the client
333 * may be counting on us to enforce permissions (the Linux 4.1
334 * client uses this for normal opens, for example).
335 */
336 if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
337 accmode = NFSD_MAY_OWNER_OVERRIDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
J. Bruce Fields9f415eb2013-05-03 16:09:09 -0400339 status = do_open_permission(rqstp, current_fh, open, accmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 return status;
342}
343
Andy Adamson60adfc52009-04-03 08:28:50 +0300344static void
345copy_clientid(clientid_t *clid, struct nfsd4_session *session)
346{
347 struct nfsd4_sessionid *sid =
348 (struct nfsd4_sessionid *)session->se_sessionid.data;
349
350 clid->cl_boot = sid->clientid.cl_boot;
351 clid->cl_id = sid->clientid.cl_id;
352}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
J.Bruce Fields71911552006-12-13 00:35:29 -0800354static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800355nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -0800356 struct nfsd4_open *open)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Al Virob37ad282006-10-19 23:28:59 -0700358 __be32 status;
Andy Adamson66689582009-04-03 08:28:45 +0300359 struct nfsd4_compoundres *resp;
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +0300360 struct net *net = SVC_NET(rqstp);
361 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
Andy Adamson66689582009-04-03 08:28:45 +0300362
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400363 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 (int)open->op_fname.len, open->op_fname.data,
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400365 open->op_openowner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* This check required by spec. */
368 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
369 return nfserr_inval;
370
J. Bruce Fields856121b2011-10-13 11:37:11 -0400371 open->op_created = 0;
Mi Jinlongab1350b2011-07-14 15:06:26 +0800372 /*
373 * RFC5661 18.51.3
374 * Before RECLAIM_COMPLETE done, server should deny new lock
375 */
376 if (nfsd4_has_session(cstate) &&
Jeff Laytona52d7262012-03-21 09:52:02 -0400377 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE,
378 &cstate->session->se_client->cl_flags) &&
Mi Jinlongab1350b2011-07-14 15:06:26 +0800379 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
380 return nfserr_grace;
381
Andy Adamson60adfc52009-04-03 08:28:50 +0300382 if (nfsd4_has_session(cstate))
383 copy_clientid(&open->op_clientid, cstate->session);
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 nfs4_lock_state();
386
387 /* check seqid for replay. set nfs4_owner */
Andy Adamson66689582009-04-03 08:28:45 +0300388 resp = rqstp->rq_resp;
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +0300389 status = nfsd4_process_open1(&resp->cstate, open, nn);
Al Viroa90b0612006-10-19 23:29:03 -0700390 if (status == nfserr_replay_me) {
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400391 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800392 fh_put(&cstate->current_fh);
J. Bruce Fieldsa4773c082009-02-02 17:23:10 -0500393 fh_copy_shallow(&cstate->current_fh.fh_handle,
394 &rp->rp_openfh);
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200395 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (status)
397 dprintk("nfsd4_open: replay failed"
398 " restoring previous filehandle\n");
399 else
Al Viroa90b0612006-10-19 23:29:03 -0700400 status = nfserr_replay_me;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402 if (status)
403 goto out;
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800404 if (open->op_xdr_error) {
405 status = open->op_xdr_error;
406 goto out;
407 }
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800408
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800409 status = nfsd4_check_open_attributes(rqstp, cstate, open);
410 if (status)
411 goto out;
412
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800413 /* Openowner is now set, so sequence id will get bumped. Now we need
414 * these checks before we do any creates: */
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800415 status = nfserr_grace;
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +0300416 if (locks_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800417 goto out;
418 status = nfserr_no_grace;
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +0300419 if (!locks_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800420 goto out;
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 switch (open->op_claim_type) {
NeilBrown0dd3c192005-06-23 22:02:56 -0700423 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 case NFS4_OPEN_CLAIM_NULL:
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400425 status = do_open_lookup(rqstp, cstate, open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (status)
427 goto out;
428 break;
429 case NFS4_OPEN_CLAIM_PREVIOUS:
J. Bruce Fieldsdad1c062011-09-12 12:24:13 -0400430 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
Stanislav Kinsbursky3320fef192012-11-14 18:22:07 +0300431 status = nfs4_check_open_reclaim(&open->op_clientid,
432 cstate->minorversion,
433 nn);
Mi Jinlong0cf99b92011-11-23 10:48:40 +0800434 if (status)
435 goto out;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400436 case NFS4_OPEN_CLAIM_FH:
437 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
J. Bruce Fieldsbbc9c362013-03-22 18:03:49 -0400438 status = do_open_fhandle(rqstp, cstate, open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (status)
440 goto out;
441 break;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400442 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
J. Bruce Fieldsdad1c062011-09-12 12:24:13 -0400444 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
J. Bruce Fields2fdada02007-07-27 16:10:37 -0400445 dprintk("NFSD: unsupported OPEN claim type %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 open->op_claim_type);
447 status = nfserr_notsupp;
448 goto out;
449 default:
J. Bruce Fields2fdada02007-07-27 16:10:37 -0400450 dprintk("NFSD: Invalid OPEN claim type %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 open->op_claim_type);
452 status = nfserr_inval;
453 goto out;
454 }
455 /*
456 * nfsd4_process_open2() does the actual opening of the file. If
457 * successful, it (1) truncates the file if open->op_truncate was
458 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
459 */
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800460 status = nfsd4_process_open2(rqstp, &cstate->current_fh, open);
J. Bruce Fields856121b2011-10-13 11:37:11 -0400461 WARN_ON(status && open->op_created);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462out:
J. Bruce Fieldsd29b20c2011-10-13 15:12:59 -0400463 nfsd4_cleanup_open_state(open, status);
J. Bruce Fields3d74e6a2013-03-22 17:44:19 -0400464 if (open->op_openowner && !nfsd4_has_session(cstate))
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400465 cstate->replay_owner = &open->op_openowner->oo_owner;
J. Bruce Fields9411b1d2013-04-01 16:37:12 -0400466 nfsd4_bump_seqid(cstate, status);
467 if (!cstate->replay_owner)
J. Bruce Fields5ec094c2011-08-30 17:02:48 -0400468 nfs4_unlock_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return status;
470}
471
472/*
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800473 * OPEN is the only seqid-mutating operation whose decoding can fail
474 * with a seqid-mutating error (specifically, decoding of user names in
475 * the attributes). Therefore we have to do some processing to look up
476 * the stateowner so that we can bump the seqid.
477 */
478static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
479{
480 struct nfsd4_open *open = (struct nfsd4_open *)&op->u;
481
482 if (!seqid_mutating_err(ntohl(op->status)))
483 return op->status;
484 if (nfsd4_has_session(cstate))
485 return op->status;
486 open->op_xdr_error = op->status;
487 return nfsd4_open(rqstp, cstate, open);
488}
489
490/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 * filehandle-manipulating ops.
492 */
J.Bruce Fields71911552006-12-13 00:35:29 -0800493static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800494nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
495 struct svc_fh **getfh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800497 if (!cstate->current_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 return nfserr_nofilehandle;
499
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800500 *getfh = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return nfs_ok;
502}
503
J.Bruce Fields71911552006-12-13 00:35:29 -0800504static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800505nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
506 struct nfsd4_putfh *putfh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800508 fh_put(&cstate->current_fh);
509 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
510 memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
511 putfh->pf_fhlen);
J. Bruce Fields68d93182011-04-08 17:00:50 -0400512 return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
J.Bruce Fields71911552006-12-13 00:35:29 -0800515static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800516nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
517 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Al Virob37ad282006-10-19 23:28:59 -0700519 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800521 fh_put(&cstate->current_fh);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700522 status = exp_pseudoroot(rqstp, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return status;
524}
525
J.Bruce Fields71911552006-12-13 00:35:29 -0800526static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800527nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
528 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800530 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 return nfserr_restorefh;
532
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800533 fh_dup2(&cstate->current_fh, &cstate->save_fh);
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100534 if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
535 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
536 SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return nfs_ok;
539}
540
J.Bruce Fields71911552006-12-13 00:35:29 -0800541static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800542nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
543 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800545 if (!cstate->current_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return nfserr_nofilehandle;
547
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800548 fh_dup2(&cstate->save_fh, &cstate->current_fh);
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100549 if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
550 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
551 SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
552 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return nfs_ok;
554}
555
556/*
557 * misc nfsv4 ops
558 */
J.Bruce Fields71911552006-12-13 00:35:29 -0800559static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800560nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
561 struct nfsd4_access *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
563 if (access->ac_req_access & ~NFS3_ACCESS_FULL)
564 return nfserr_inval;
565
566 access->ac_resp_access = access->ac_req_access;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800567 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
568 &access->ac_supported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +0300571static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)
Chuck Leverab4684d2012-03-02 17:13:50 -0500572{
573 __be32 verf[2];
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +0300574 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
Chuck Leverab4684d2012-03-02 17:13:50 -0500575
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +0300576 verf[0] = (__be32)nn->nfssvc_boot.tv_sec;
577 verf[1] = (__be32)nn->nfssvc_boot.tv_usec;
Chuck Leverab4684d2012-03-02 17:13:50 -0500578 memcpy(verifier->data, verf, sizeof(verifier->data));
579}
580
J.Bruce Fields71911552006-12-13 00:35:29 -0800581static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800582nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
583 struct nfsd4_commit *commit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +0300585 gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp));
J. Bruce Fields75c096f2011-08-15 18:39:32 -0400586 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800587 commit->co_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
Al Virob37ad282006-10-19 23:28:59 -0700590static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800591nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
592 struct nfsd4_create *create)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
594 struct svc_fh resfh;
Al Virob37ad282006-10-19 23:28:59 -0700595 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 dev_t rdev;
597
598 fh_init(&resfh, NFS4_FHSIZE);
599
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200600 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
601 NFSD_MAY_CREATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if (status)
603 return status;
604
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800605 status = check_attr_support(rqstp, cstate, create->cr_bmval,
606 nfsd_attrmask);
607 if (status)
608 return status;
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 switch (create->cr_type) {
611 case NF4LNK:
612 /* ugh! we have to null-terminate the linktext, or
613 * vfs_symlink() will choke. it is always safe to
614 * null-terminate by brute force, since at worst we
615 * will overwrite the first byte of the create namelen
616 * in the XDR buffer, which has already been extracted
617 * during XDR decode.
618 */
619 create->cr_linkname[create->cr_linklen] = 0;
620
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800621 status = nfsd_symlink(rqstp, &cstate->current_fh,
622 create->cr_name, create->cr_namelen,
623 create->cr_linkname, create->cr_linklen,
624 &resfh, &create->cr_iattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 break;
626
627 case NF4BLK:
628 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
629 if (MAJOR(rdev) != create->cr_specdata1 ||
630 MINOR(rdev) != create->cr_specdata2)
631 return nfserr_inval;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800632 status = nfsd_create(rqstp, &cstate->current_fh,
633 create->cr_name, create->cr_namelen,
634 &create->cr_iattr, S_IFBLK, rdev, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 break;
636
637 case NF4CHR:
638 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
639 if (MAJOR(rdev) != create->cr_specdata1 ||
640 MINOR(rdev) != create->cr_specdata2)
641 return nfserr_inval;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800642 status = nfsd_create(rqstp, &cstate->current_fh,
643 create->cr_name, create->cr_namelen,
644 &create->cr_iattr,S_IFCHR, rdev, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 break;
646
647 case NF4SOCK:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800648 status = nfsd_create(rqstp, &cstate->current_fh,
649 create->cr_name, create->cr_namelen,
650 &create->cr_iattr, S_IFSOCK, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
652
653 case NF4FIFO:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800654 status = nfsd_create(rqstp, &cstate->current_fh,
655 create->cr_name, create->cr_namelen,
656 &create->cr_iattr, S_IFIFO, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 break;
658
659 case NF4DIR:
660 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800661 status = nfsd_create(rqstp, &cstate->current_fh,
662 create->cr_name, create->cr_namelen,
663 &create->cr_iattr, S_IFDIR, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 break;
665
666 default:
667 status = nfserr_badtype;
668 }
669
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800670 if (status)
671 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
David Quigley18032ca2013-05-02 13:19:10 -0400673 if (create->cr_label.len)
674 nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
675
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800676 if (create->cr_acl != NULL)
677 do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
678 create->cr_bmval);
679
680 fh_unlock(&cstate->current_fh);
681 set_change_info(&create->cr_cinfo, &cstate->current_fh);
682 fh_dup2(&cstate->current_fh, &resfh);
683out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 fh_put(&resfh);
685 return status;
686}
687
J.Bruce Fields71911552006-12-13 00:35:29 -0800688static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800689nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
690 struct nfsd4_getattr *getattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Al Virob37ad282006-10-19 23:28:59 -0700692 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200694 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (status)
696 return status;
697
698 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
699 return nfserr_inval;
700
Andy Adamson7e705702009-04-03 08:29:11 +0300701 getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
702 getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
703 getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800705 getattr->ga_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return nfs_ok;
707}
708
J.Bruce Fields71911552006-12-13 00:35:29 -0800709static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800710nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
711 struct nfsd4_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Al Virob37ad282006-10-19 23:28:59 -0700713 __be32 status = nfserr_nofilehandle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800715 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 return status;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800717 status = nfsd_link(rqstp, &cstate->current_fh,
718 link->li_name, link->li_namelen, &cstate->save_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (!status)
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800720 set_change_info(&link->li_cinfo, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return status;
722}
723
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500724static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
726 struct svc_fh tmp_fh;
Al Virob37ad282006-10-19 23:28:59 -0700727 __be32 ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 fh_init(&tmp_fh, NFS4_FHSIZE);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700730 ret = exp_pseudoroot(rqstp, &tmp_fh);
731 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return ret;
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500733 if (tmp_fh.fh_dentry == fh->fh_dentry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 fh_put(&tmp_fh);
735 return nfserr_noent;
736 }
737 fh_put(&tmp_fh);
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500738 return nfsd_lookup(rqstp, fh, "..", 2, fh);
739}
740
741static __be32
742nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
743 void *arg)
744{
745 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
J.Bruce Fields71911552006-12-13 00:35:29 -0800748static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800749nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
750 struct nfsd4_lookup *lookup)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800752 return nfsd_lookup(rqstp, &cstate->current_fh,
753 lookup->lo_name, lookup->lo_len,
754 &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
J.Bruce Fields71911552006-12-13 00:35:29 -0800757static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800758nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
759 struct nfsd4_read *read)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760{
Al Virob37ad282006-10-19 23:28:59 -0700761 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /* no need to check permission - this will be done in nfsd_read() */
764
NeilBrown7e06b7f2005-06-23 22:03:13 -0700765 read->rd_filp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 if (read->rd_offset >= OFFSET_MAX)
767 return nfserr_inval;
768
J. Bruce Fields9b3234b2012-12-04 18:03:46 -0500769 /*
770 * If we do a zero copy read, then a client will see read data
771 * that reflects the state of the file *after* performing the
772 * following compound.
773 *
774 * To ensure proper ordering, we therefore turn off zero copy if
775 * the client wants us to do more in this compound:
776 */
777 if (!nfsd4_last_compound_op(rqstp))
778 rqstp->rq_splice_ok = false;
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 nfs4_lock_state();
781 /* check stateid */
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400782 if ((status = nfs4_preprocess_stateid_op(SVC_NET(rqstp),
783 cstate, &read->rd_stateid,
Benny Halevydd453df2009-04-03 08:28:41 +0300784 RD_STATE, &read->rd_filp))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
786 goto out;
787 }
NeilBrown7e06b7f2005-06-23 22:03:13 -0700788 if (read->rd_filp)
789 get_file(read->rd_filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 status = nfs_ok;
791out:
792 nfs4_unlock_state();
793 read->rd_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800794 read->rd_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return status;
796}
797
J.Bruce Fields71911552006-12-13 00:35:29 -0800798static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800799nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
800 struct nfsd4_readdir *readdir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
802 u64 cookie = readdir->rd_cookie;
803 static const nfs4_verifier zeroverf;
804
805 /* no need to check permission - this will be done in nfsd_readdir() */
806
807 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
808 return nfserr_inval;
809
Andy Adamson7e705702009-04-03 08:29:11 +0300810 readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
811 readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
812 readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Bernd Schubert832023b2011-08-08 17:38:08 +0200814 if ((cookie == 1) || (cookie == 2) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
816 return nfserr_bad_cookie;
817
818 readdir->rd_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800819 readdir->rd_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return nfs_ok;
821}
822
J.Bruce Fields71911552006-12-13 00:35:29 -0800823static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800824nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
825 struct nfsd4_readlink *readlink)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827 readlink->rl_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800828 readlink->rl_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 return nfs_ok;
830}
831
J.Bruce Fields71911552006-12-13 00:35:29 -0800832static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800833nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
834 struct nfsd4_remove *remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Al Virob37ad282006-10-19 23:28:59 -0700836 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400838 if (locks_in_grace(SVC_NET(rqstp)))
NeilBrownc815afc2005-06-23 22:03:00 -0700839 return nfserr_grace;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800840 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
841 remove->rm_name, remove->rm_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 if (!status) {
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800843 fh_unlock(&cstate->current_fh);
844 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 }
846 return status;
847}
848
J.Bruce Fields71911552006-12-13 00:35:29 -0800849static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800850nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
851 struct nfsd4_rename *rename)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Al Virob37ad282006-10-19 23:28:59 -0700853 __be32 status = nfserr_nofilehandle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800855 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 return status;
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400857 if (locks_in_grace(SVC_NET(rqstp)) &&
858 !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK))
NeilBrownc815afc2005-06-23 22:03:00 -0700859 return nfserr_grace;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800860 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
861 rename->rn_snamelen, &cstate->current_fh,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 rename->rn_tname, rename->rn_tnamelen);
J. Bruce Fields2a6cf942013-04-30 15:28:51 -0400863 if (status)
864 return status;
865 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
866 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
867 return nfs_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
J.Bruce Fields71911552006-12-13 00:35:29 -0800870static __be32
Andy Adamsondcb488a32007-07-17 04:04:51 -0700871nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
872 struct nfsd4_secinfo *secinfo)
873{
874 struct svc_fh resfh;
875 struct svc_export *exp;
876 struct dentry *dentry;
877 __be32 err;
878
879 fh_init(&resfh, NFS4_FHSIZE);
J. Bruce Fields29a78a32011-04-09 11:28:53 -0400880 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
881 if (err)
882 return err;
Andy Adamsondcb488a32007-07-17 04:04:51 -0700883 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
884 secinfo->si_name, secinfo->si_namelen,
885 &exp, &dentry);
886 if (err)
887 return err;
888 if (dentry->d_inode == NULL) {
889 exp_put(exp);
890 err = nfserr_noent;
891 } else
892 secinfo->si_exp = exp;
893 dput(dentry);
J. Bruce Fields56560b92010-12-16 09:57:15 -0500894 if (cstate->minorversion)
895 /* See rfc 5661 section 2.6.3.1.1.8 */
896 fh_put(&cstate->current_fh);
Andy Adamsondcb488a32007-07-17 04:04:51 -0700897 return err;
898}
899
900static __be32
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500901nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
902 struct nfsd4_secinfo_no_name *sin)
903{
904 __be32 err;
905
906 switch (sin->sin_style) {
907 case NFS4_SECINFO_STYLE4_CURRENT_FH:
908 break;
909 case NFS4_SECINFO_STYLE4_PARENT:
910 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
911 if (err)
912 return err;
913 break;
914 default:
915 return nfserr_inval;
916 }
917 exp_get(cstate->current_fh.fh_export);
918 sin->sin_exp = cstate->current_fh.fh_export;
919 fh_put(&cstate->current_fh);
920 return nfs_ok;
921}
922
923static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800924nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
925 struct nfsd4_setattr *setattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Al Virob37ad282006-10-19 23:28:59 -0700927 __be32 status = nfs_ok;
Al Viro96f6f982012-04-12 23:47:00 -0400928 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
931 nfs4_lock_state();
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +0400932 status = nfs4_preprocess_stateid_op(SVC_NET(rqstp), cstate,
J. Bruce Fields6150ef02009-02-21 13:36:16 -0800933 &setattr->sa_stateid, WR_STATE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 nfs4_unlock_state();
J. Bruce Fields375c5542006-01-18 17:43:33 -0800935 if (status) {
Greg Banks3e3b4802006-10-02 02:17:41 -0700936 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
J. Bruce Fields375c5542006-01-18 17:43:33 -0800937 return status;
938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 }
Al Viro96f6f982012-04-12 23:47:00 -0400940 err = fh_want_write(&cstate->current_fh);
941 if (err)
942 return nfserrno(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 status = nfs_ok;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800944
945 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
946 nfsd_attrmask);
947 if (status)
948 goto out;
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 if (setattr->sa_acl != NULL)
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800951 status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
952 setattr->sa_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (status)
Dave Hansen18f335a2008-02-15 14:37:38 -0800954 goto out;
David Quigley18032ca2013-05-02 13:19:10 -0400955 if (setattr->sa_label.len)
956 status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
957 &setattr->sa_label);
958 if (status)
959 goto out;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800960 status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 0, (time_t)0);
Dave Hansen18f335a2008-02-15 14:37:38 -0800962out:
Al Virobad0dcf2011-11-23 12:03:18 -0500963 fh_drop_write(&cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 return status;
965}
966
J. Bruce Fieldsffe11372012-11-15 14:52:19 -0500967static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write)
968{
969 int i = 1;
970 int buflen = write->wr_buflen;
971
972 vec[0].iov_base = write->wr_head.iov_base;
973 vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len);
974 buflen -= vec[0].iov_len;
975
976 while (buflen) {
977 vec[i].iov_base = page_address(write->wr_pagelist[i - 1]);
978 vec[i].iov_len = min_t(int, PAGE_SIZE, buflen);
979 buflen -= vec[i].iov_len;
980 i++;
981 }
982 return i;
983}
984
J.Bruce Fields71911552006-12-13 00:35:29 -0800985static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800986nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
987 struct nfsd4_write *write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
989 stateid_t *stateid = &write->wr_stateid;
990 struct file *filp = NULL;
Al Virob37ad282006-10-19 23:28:59 -0700991 __be32 status = nfs_ok;
David Shaw31dec252009-03-05 20:16:14 -0500992 unsigned long cnt;
J. Bruce Fieldsffe11372012-11-15 14:52:19 -0500993 int nvecs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 /* no need to check permission - this will be done in nfsd_write() */
996
997 if (write->wr_offset >= OFFSET_MAX)
998 return nfserr_inval;
999
1000 nfs4_lock_state();
Stanislav Kinsbursky5ccb0062012-07-25 16:57:22 +04001001 status = nfs4_preprocess_stateid_op(SVC_NET(rqstp),
1002 cstate, stateid, WR_STATE, &filp);
J. Bruce Fields375c5542006-01-18 17:43:33 -08001003 if (status) {
fanchaotingb0220322013-04-01 21:07:22 +08001004 nfs4_unlock_state();
J. Bruce Fields375c5542006-01-18 17:43:33 -08001005 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
1006 return status;
1007 }
fanchaotingb0220322013-04-01 21:07:22 +08001008 if (filp)
1009 get_file(filp);
1010 nfs4_unlock_state();
J. Bruce Fields375c5542006-01-18 17:43:33 -08001011
David Shaw31dec252009-03-05 20:16:14 -05001012 cnt = write->wr_buflen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 write->wr_how_written = write->wr_stable_how;
Stanislav Kinsburskyb9c0ef82012-12-06 14:23:19 +03001014 gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
J. Bruce Fieldsffe11372012-11-15 14:52:19 -05001016 nvecs = fill_in_write_vector(rqstp->rq_vec, write);
1017 WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
1018
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001019 status = nfsd_write(rqstp, &cstate->current_fh, filp,
J. Bruce Fieldsffe11372012-11-15 14:52:19 -05001020 write->wr_offset, rqstp->rq_vec, nvecs,
David Shaw31dec252009-03-05 20:16:14 -05001021 &cnt, &write->wr_how_written);
NeilBrown7e06b7f2005-06-23 22:03:13 -07001022 if (filp)
1023 fput(filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
David Shaw31dec252009-03-05 20:16:14 -05001025 write->wr_bytes_written = cnt;
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028}
1029
1030/* This routine never returns NFS_OK! If there are no other errors, it
1031 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
1032 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
1033 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
1034 */
Al Virob37ad282006-10-19 23:28:59 -07001035static __be32
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001036_nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001037 struct nfsd4_verify *verify)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038{
Al Viro2ebbc012006-10-19 23:28:58 -07001039 __be32 *buf, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 int count;
Al Virob37ad282006-10-19 23:28:59 -07001041 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
Miklos Szeredi8837abc2008-06-16 13:20:29 +02001043 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (status)
1045 return status;
1046
Yu Zhiguo3c8e0312009-05-16 16:22:31 +08001047 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
1048 if (status)
1049 return status;
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
1052 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
1053 return nfserr_inval;
1054 if (verify->ve_attrlen & 3)
1055 return nfserr_inval;
1056
1057 /* count in words:
1058 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
1059 */
1060 count = 4 + (verify->ve_attrlen >> 2);
1061 buf = kmalloc(count << 2, GFP_KERNEL);
1062 if (!buf)
J. Bruce Fields3e772462011-08-10 19:07:33 -04001063 return nfserr_jukebox;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
J. Bruce Fields84822d02012-12-14 17:57:50 -05001065 p = buf;
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001066 status = nfsd4_encode_fattr(&cstate->current_fh,
1067 cstate->current_fh.fh_export,
J. Bruce Fields84822d02012-12-14 17:57:50 -05001068 cstate->current_fh.fh_dentry, &p,
1069 count, verify->ve_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08001070 rqstp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 /* this means that nfsd4_encode_fattr() ran out of space */
J. Bruce Fields84822d02012-12-14 17:57:50 -05001073 if (status == nfserr_resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 status = nfserr_not_same;
1075 if (status)
1076 goto out_kfree;
1077
Benny Halevy95ec28c2009-04-03 08:29:08 +03001078 /* skip bitmap */
1079 p = buf + 1 + ntohl(buf[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 status = nfserr_not_same;
1081 if (ntohl(*p++) != verify->ve_attrlen)
1082 goto out_kfree;
1083 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
1084 status = nfserr_same;
1085
1086out_kfree:
1087 kfree(buf);
1088 return status;
1089}
1090
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -08001091static __be32
1092nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1093 struct nfsd4_verify *verify)
1094{
1095 __be32 status;
1096
1097 status = _nfsd4_verify(rqstp, cstate, verify);
1098 return status == nfserr_not_same ? nfs_ok : status;
1099}
1100
1101static __be32
1102nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1103 struct nfsd4_verify *verify)
1104{
1105 __be32 status;
1106
1107 status = _nfsd4_verify(rqstp, cstate, verify);
1108 return status == nfserr_same ? nfs_ok : status;
1109}
1110
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111/*
1112 * NULL call.
1113 */
Al Viro7111c662006-10-19 23:28:45 -07001114static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
1116{
1117 return nfs_ok;
1118}
1119
Shankar Anande2b20952006-07-10 04:45:44 -07001120static inline void nfsd4_increment_op_stats(u32 opnum)
1121{
1122 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
1123 nfsdstats.nfs4_opcount[opnum]++;
1124}
1125
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001126typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
1127 void *);
Mi Jinlong58e7b332011-08-28 18:18:56 +08001128typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001129typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *);
1130typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *);
Mi Jinlong58e7b332011-08-28 18:18:56 +08001131
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001132enum nfsd4_op_flags {
1133 ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
Mi Jinlong5ece3ca2011-02-18 09:08:31 +08001134 ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
1135 ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
J. Bruce Fields68d93182011-04-08 17:00:50 -04001136 /* For rfc 5661 section 2.6.3.1.1: */
1137 OP_HANDLES_WRONGSEC = 1 << 3,
1138 OP_IS_PUTFH_LIKE = 1 << 4,
J. Bruce Fields10910062011-01-24 12:11:02 -05001139 /*
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001140 * These are the ops whose result size we estimate before
1141 * encoding, to avoid performing an op then not being able to
1142 * respond or cache a response. This includes writes and setattrs
1143 * as well as the operations usually called "nonidempotent":
1144 */
1145 OP_MODIFIES_SOMETHING = 1 << 5,
1146 /*
1147 * Cache compounds containing these ops in the xid-based drc:
J. Bruce Fields10910062011-01-24 12:11:02 -05001148 * We use the DRC for compounds containing non-idempotent
1149 * operations, *except* those that are 4.1-specific (since
1150 * sessions provide their own EOS), and except for stateful
1151 * operations other than setclientid and setclientid_confirm
1152 * (since sequence numbers provide EOS for open, lock, etc in
1153 * the v4.0 case).
1154 */
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001155 OP_CACHEME = 1 << 6,
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001156 /*
1157 * These are ops which clear current state id.
1158 */
1159 OP_CLEAR_STATEID = 1 << 7,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001160};
1161
1162struct nfsd4_operation {
1163 nfsd4op_func op_func;
1164 u32 op_flags;
1165 char *op_name;
Mi Jinlong58e7b332011-08-28 18:18:56 +08001166 /* Try to get response size before operation */
1167 nfsd4op_rsize op_rsize_bop;
Bryan Schumaker24ff99c2012-08-14 15:55:08 -04001168 stateid_getter op_get_currentstateid;
1169 stateid_setter op_set_currentstateid;
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001170};
1171
1172static struct nfsd4_operation nfsd4_ops[];
1173
Trond Myklebust8f199b82012-03-20 15:11:17 -04001174#ifdef NFSD_DEBUG
Adrian Bunkf1c7f792008-08-08 19:26:42 +03001175static const char *nfsd4_op_name(unsigned opnum);
Trond Myklebust8f199b82012-03-20 15:11:17 -04001176#endif
Benny Halevyb001a1b2008-07-02 11:15:03 +03001177
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178/*
J. Bruce Fields57716352010-04-21 12:27:19 -04001179 * Enforce NFSv4.1 COMPOUND ordering rules:
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001180 *
J. Bruce Fields57716352010-04-21 12:27:19 -04001181 * Also note, enforced elsewhere:
1182 * - SEQUENCE other than as first op results in
1183 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001184 * - BIND_CONN_TO_SESSION must be the only op in its compound.
1185 * (Enforced in nfsd4_bind_conn_to_session().)
J. Bruce Fields57716352010-04-21 12:27:19 -04001186 * - DESTROY_SESSION must be the final operation in a compound, if
1187 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
1188 * (Enforced in nfsd4_destroy_session().)
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001189 */
J. Bruce Fields57716352010-04-21 12:27:19 -04001190static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001191{
J. Bruce Fields57716352010-04-21 12:27:19 -04001192 struct nfsd4_op *op = &args->ops[0];
1193
1194 /* These ordering requirements don't apply to NFSv4.0: */
1195 if (args->minorversion == 0)
1196 return nfs_ok;
1197 /* This is weird, but OK, not our problem: */
1198 if (args->opcnt == 0)
1199 return nfs_ok;
1200 if (op->status == nfserr_op_illegal)
1201 return nfs_ok;
1202 if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
1203 return nfserr_op_not_in_session;
1204 if (op->opnum == OP_SEQUENCE)
1205 return nfs_ok;
1206 if (args->opcnt != 1)
1207 return nfserr_not_only_op;
1208 return nfs_ok;
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001209}
1210
J. Bruce Fields22b03212011-04-09 11:23:24 -04001211static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
1212{
1213 return &nfsd4_ops[op->opnum];
1214}
1215
J. Bruce Fields10910062011-01-24 12:11:02 -05001216bool nfsd4_cache_this_op(struct nfsd4_op *op)
1217{
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001218 return OPDESC(op)->op_flags & OP_CACHEME;
J. Bruce Fields10910062011-01-24 12:11:02 -05001219}
1220
J. Bruce Fields68d93182011-04-08 17:00:50 -04001221static bool need_wrongsec_check(struct svc_rqst *rqstp)
1222{
1223 struct nfsd4_compoundres *resp = rqstp->rq_resp;
1224 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
1225 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
1226 struct nfsd4_op *next = &argp->ops[resp->opcnt];
1227 struct nfsd4_operation *thisd;
1228 struct nfsd4_operation *nextd;
1229
1230 thisd = OPDESC(this);
1231 /*
1232 * Most ops check wronsec on our own; only the putfh-like ops
1233 * have special rules.
1234 */
1235 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
1236 return false;
1237 /*
1238 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
1239 * put-filehandle operation if we're not going to use the
1240 * result:
1241 */
1242 if (argp->opcnt == resp->opcnt)
1243 return false;
1244
1245 nextd = OPDESC(next);
1246 /*
1247 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
1248 * errors themselves as necessary; others should check for them
1249 * now:
1250 */
1251 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
1252}
1253
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001254/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 * COMPOUND call.
1256 */
Al Viro7111c662006-10-19 23:28:45 -07001257static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258nfsd4_proc_compound(struct svc_rqst *rqstp,
1259 struct nfsd4_compoundargs *args,
1260 struct nfsd4_compoundres *resp)
1261{
1262 struct nfsd4_op *op;
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001263 struct nfsd4_operation *opdesc;
Andy Adamsone354d572009-03-28 11:30:52 +03001264 struct nfsd4_compound_state *cstate = &resp->cstate;
J.Bruce Fieldse5710192006-12-13 00:35:20 -08001265 int slack_bytes;
Mi Jinlong58e7b332011-08-28 18:18:56 +08001266 u32 plen = 0;
Al Virob37ad282006-10-19 23:28:59 -07001267 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 resp->xbuf = &rqstp->rq_res;
Andy Adamsone354d572009-03-28 11:30:52 +03001270 resp->p = rqstp->rq_res.head[0].iov_base +
1271 rqstp->rq_res.head[0].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 resp->tagp = resp->p;
1273 /* reserve space for: taglen, tag, and opcnt */
1274 resp->p += 2 + XDR_QUADLEN(args->taglen);
1275 resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
1276 resp->taglen = args->taglen;
1277 resp->tag = args->tag;
1278 resp->opcnt = 0;
1279 resp->rqstp = rqstp;
Andy Adamsond87a8ad2009-04-03 08:28:53 +03001280 resp->cstate.minorversion = args->minorversion;
Andy Adamsone354d572009-03-28 11:30:52 +03001281 resp->cstate.replay_owner = NULL;
J. Bruce Fields26c0c752010-04-24 15:35:43 -04001282 resp->cstate.session = NULL;
Andy Adamsone354d572009-03-28 11:30:52 +03001283 fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
1284 fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
NeilBrown8ff30fa2010-08-12 17:04:07 +10001285 /*
1286 * Don't use the deferral mechanism for NFSv4; compounds make it
1287 * too hard to avoid non-idempotency problems.
1288 */
1289 rqstp->rq_usedeferral = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 /*
1292 * According to RFC3010, this takes precedence over all other errors.
1293 */
1294 status = nfserr_minor_vers_mismatch;
Benny Halevy8daf2202009-04-03 08:28:59 +03001295 if (args->minorversion > nfsd_supported_minorversion)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 goto out;
1297
J. Bruce Fields57716352010-04-21 12:27:19 -04001298 status = nfs41_check_op_ordering(args);
1299 if (status) {
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001300 op = &args->ops[0];
J. Bruce Fields57716352010-04-21 12:27:19 -04001301 op->status = status;
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001302 goto encode_op;
1303 }
1304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 while (!status && resp->opcnt < args->opcnt) {
1306 op = &args->ops[resp->opcnt++];
1307
Benny Halevyb001a1b2008-07-02 11:15:03 +03001308 dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
1309 resp->opcnt, args->opcnt, op->opnum,
1310 nfsd4_op_name(op->opnum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 /*
1312 * The XDR decode routines may have pre-set op->status;
1313 * for example, if there is a miscellaneous XDR error
1314 * it will be set to nfserr_bad_xdr.
1315 */
J. Bruce Fields9d313b12013-02-28 12:51:49 -08001316 if (op->status) {
1317 if (op->opnum == OP_OPEN)
1318 op->status = nfsd4_open_omfg(rqstp, cstate, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 goto encode_op;
J. Bruce Fields9d313b12013-02-28 12:51:49 -08001320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 /* We must be able to encode a successful response to
1323 * this operation, with enough room left over to encode a
1324 * failed response to the next operation. If we don't
1325 * have enough room, fail with ERR_RESOURCE.
1326 */
J.Bruce Fieldse5710192006-12-13 00:35:20 -08001327 slack_bytes = (char *)resp->end - (char *)resp->p;
1328 if (slack_bytes < COMPOUND_SLACK_SPACE
1329 + COMPOUND_ERR_SLACK_SPACE) {
1330 BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 op->status = nfserr_resource;
1332 goto encode_op;
1333 }
1334
J. Bruce Fields22b03212011-04-09 11:23:24 -04001335 opdesc = OPDESC(op);
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001336
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001337 if (!cstate->current_fh.fh_dentry) {
J.Bruce Fields27d630e2006-12-13 00:35:43 -08001338 if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
J.Bruce Fields42ca0992006-10-04 02:16:20 -07001339 op->status = nfserr_nofilehandle;
1340 goto encode_op;
1341 }
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001342 } else if (cstate->current_fh.fh_export->ex_fslocs.migrated &&
1343 !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
J.Bruce Fields42ca0992006-10-04 02:16:20 -07001344 op->status = nfserr_moved;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 goto encode_op;
1346 }
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001347
Mi Jinlong58e7b332011-08-28 18:18:56 +08001348 /* If op is non-idempotent */
1349 if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
1350 plen = opdesc->op_rsize_bop(rqstp, op);
1351 op->status = nfsd4_check_resp_size(resp, plen);
1352 }
1353
1354 if (op->status)
1355 goto encode_op;
1356
J. Bruce Fieldsb600de72013-02-28 11:55:46 -08001357 if (opdesc->op_get_currentstateid)
1358 opdesc->op_get_currentstateid(cstate, &op->u);
1359 op->status = opdesc->op_func(rqstp, cstate, &op->u);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001361 if (!op->status) {
1362 if (opdesc->op_set_currentstateid)
1363 opdesc->op_set_currentstateid(cstate, &op->u);
1364
1365 if (opdesc->op_flags & OP_CLEAR_STATEID)
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +01001366 clear_current_stateid(cstate);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001367
1368 if (need_wrongsec_check(rqstp))
1369 op->status = check_nfsd_access(cstate->current_fh.fh_export, rqstp);
1370 }
J. Bruce Fields68d93182011-04-08 17:00:50 -04001371
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372encode_op:
Andy Adamson49557cc2009-07-23 19:02:16 -04001373 /* Only from SEQUENCE */
Andy Adamsonda3846a2009-04-03 08:28:22 +03001374 if (resp->cstate.status == nfserr_replay_cache) {
1375 dprintk("%s NFS4.1 replay from cache\n", __func__);
Andy Adamsonabfabf82009-07-23 19:02:18 -04001376 status = op->status;
Andy Adamsonda3846a2009-04-03 08:28:22 +03001377 goto out;
1378 }
Al Viroa90b0612006-10-19 23:29:03 -07001379 if (op->status == nfserr_replay_me) {
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08001380 op->replay = &cstate->replay_owner->so_replay;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 nfsd4_encode_replay(resp, op);
1382 status = op->status = op->replay->rp_status;
1383 } else {
1384 nfsd4_encode_operation(resp, op);
1385 status = op->status;
1386 }
Benny Halevy04077172008-12-15 19:40:49 +02001387
1388 dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
1389 args->ops, args->opcnt, resp->opcnt, op->opnum,
1390 be32_to_cpu(status));
1391
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08001392 if (cstate->replay_owner) {
J. Bruce Fields5ec094c2011-08-30 17:02:48 -04001393 nfs4_unlock_state();
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08001394 cstate->replay_owner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
NeilBrown7e06b7f2005-06-23 22:03:13 -07001396 /* XXX Ugh, we need to get rid of this kind of special case: */
1397 if (op->opnum == OP_READ && op->u.read.rd_filp)
1398 fput(op->u.read.rd_filp);
Shankar Anande2b20952006-07-10 04:45:44 -07001399
1400 nfsd4_increment_op_stats(op->opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 }
1402
Andy Adamsonda3846a2009-04-03 08:28:22 +03001403 resp->cstate.status = status;
Andy Adamsone354d572009-03-28 11:30:52 +03001404 fh_put(&resp->cstate.current_fh);
1405 fh_put(&resp->cstate.save_fh);
1406 BUG_ON(resp->cstate.replay_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407out:
Andy Adamson2f425872009-04-03 08:27:32 +03001408 /* Reset deferral mechanism for RPC deferrals */
1409 rqstp->rq_usedeferral = 1;
J. Bruce Fields3b12cd92008-05-05 17:17:44 -04001410 dprintk("nfsv4 compound returned %d\n", ntohl(status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return status;
1412}
1413
Mi Jinlong58e7b332011-08-28 18:18:56 +08001414#define op_encode_hdr_size (2)
1415#define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
1416#define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
1417#define op_encode_change_info_maxsz (5)
1418#define nfs4_fattr_bitmap_maxsz (4)
1419
1420#define op_encode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1421#define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
1422
1423#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1424
1425#define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
1426#define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
1427 op_encode_ace_maxsz)
1428
1429#define op_encode_channel_attrs_maxsz (6 + 1 + 1)
1430
1431static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1432{
1433 return (op_encode_hdr_size) * sizeof(__be32);
1434}
1435
1436static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1437{
1438 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
1439}
1440
1441static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1442{
1443 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
1444}
1445
1446static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1447{
1448 return (op_encode_hdr_size + op_encode_change_info_maxsz
1449 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
1450}
1451
1452static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1453{
1454 return (op_encode_hdr_size + op_encode_change_info_maxsz)
1455 * sizeof(__be32);
1456}
1457
1458static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1459{
1460 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
1461 * sizeof(__be32);
1462}
1463
1464static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1465{
1466 return (op_encode_hdr_size + op_encode_stateid_maxsz
1467 + op_encode_change_info_maxsz + 1
1468 + nfs4_fattr_bitmap_maxsz
1469 + op_encode_delegation_maxsz) * sizeof(__be32);
1470}
1471
1472static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1473{
1474 u32 maxcount = 0, rlen = 0;
1475
1476 maxcount = svc_max_payload(rqstp);
1477 rlen = op->u.read.rd_length;
1478
1479 if (rlen > maxcount)
1480 rlen = maxcount;
1481
1482 return (op_encode_hdr_size + 2) * sizeof(__be32) + rlen;
1483}
1484
1485static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1486{
1487 u32 rlen = op->u.readdir.rd_maxcount;
1488
1489 if (rlen > PAGE_SIZE)
1490 rlen = PAGE_SIZE;
1491
1492 return (op_encode_hdr_size + op_encode_verifier_maxsz)
1493 * sizeof(__be32) + rlen;
1494}
1495
1496static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1497{
1498 return (op_encode_hdr_size + op_encode_change_info_maxsz)
1499 * sizeof(__be32);
1500}
1501
1502static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1503{
1504 return (op_encode_hdr_size + op_encode_change_info_maxsz
1505 + op_encode_change_info_maxsz) * sizeof(__be32);
1506}
1507
1508static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1509{
1510 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
1511}
1512
1513static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1514{
1515 return (op_encode_hdr_size + 2 + 1024) * sizeof(__be32);
1516}
1517
1518static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1519{
1520 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
1521}
1522
1523static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1524{
1525 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
1526 1 + 1 + 0 + /* eir_flags, spr_how, SP4_NONE (for now) */\
1527 2 + /*eir_server_owner.so_minor_id */\
1528 /* eir_server_owner.so_major_id<> */\
1529 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
1530 /* eir_server_scope<> */\
1531 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
1532 1 + /* eir_server_impl_id array length */\
1533 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
1534}
1535
1536static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1537{
1538 return (op_encode_hdr_size + \
1539 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
1540 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
1541}
1542
1543static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1544{
1545 return (op_encode_hdr_size + \
1546 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
1547 2 + /* csr_sequence, csr_flags */\
1548 op_encode_channel_attrs_maxsz + \
1549 op_encode_channel_attrs_maxsz) * sizeof(__be32);
1550}
1551
Benny Halevy20766012009-03-28 11:32:05 +03001552static struct nfsd4_operation nfsd4_ops[] = {
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001553 [OP_ACCESS] = {
1554 .op_func = (nfsd4op_func)nfsd4_access,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001555 .op_name = "OP_ACCESS",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001556 },
1557 [OP_CLOSE] = {
1558 .op_func = (nfsd4op_func)nfsd4_close,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001559 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001560 .op_name = "OP_CLOSE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001561 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001562 .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid,
1563 .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001564 },
1565 [OP_COMMIT] = {
1566 .op_func = (nfsd4op_func)nfsd4_commit,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001567 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001568 .op_name = "OP_COMMIT",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001569 .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001570 },
1571 [OP_CREATE] = {
1572 .op_func = (nfsd4op_func)nfsd4_create,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01001573 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001574 .op_name = "OP_CREATE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001575 .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001576 },
1577 [OP_DELEGRETURN] = {
1578 .op_func = (nfsd4op_func)nfsd4_delegreturn,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001579 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001580 .op_name = "OP_DELEGRETURN",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001581 .op_rsize_bop = nfsd4_only_status_rsize,
Tigran Mkrtchyan9428fe12012-02-13 22:55:31 +01001582 .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001583 },
1584 [OP_GETATTR] = {
1585 .op_func = (nfsd4op_func)nfsd4_getattr,
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001586 .op_flags = ALLOWED_ON_ABSENT_FS,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001587 .op_name = "OP_GETATTR",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001588 },
1589 [OP_GETFH] = {
1590 .op_func = (nfsd4op_func)nfsd4_getfh,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001591 .op_name = "OP_GETFH",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001592 },
1593 [OP_LINK] = {
1594 .op_func = (nfsd4op_func)nfsd4_link,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001595 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
1596 | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001597 .op_name = "OP_LINK",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001598 .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001599 },
1600 [OP_LOCK] = {
1601 .op_func = (nfsd4op_func)nfsd4_lock,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001602 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001603 .op_name = "OP_LOCK",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001604 .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
Tigran Mkrtchyan62cd4a52012-02-13 22:55:25 +01001605 .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001606 },
1607 [OP_LOCKT] = {
1608 .op_func = (nfsd4op_func)nfsd4_lockt,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001609 .op_name = "OP_LOCKT",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001610 },
1611 [OP_LOCKU] = {
1612 .op_func = (nfsd4op_func)nfsd4_locku,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001613 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001614 .op_name = "OP_LOCKU",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001615 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
Tigran Mkrtchyan62cd4a52012-02-13 22:55:25 +01001616 .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001617 },
1618 [OP_LOOKUP] = {
1619 .op_func = (nfsd4op_func)nfsd4_lookup,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01001620 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001621 .op_name = "OP_LOOKUP",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001622 },
1623 [OP_LOOKUPP] = {
1624 .op_func = (nfsd4op_func)nfsd4_lookupp,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01001625 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001626 .op_name = "OP_LOOKUPP",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001627 },
1628 [OP_NVERIFY] = {
1629 .op_func = (nfsd4op_func)nfsd4_nverify,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001630 .op_name = "OP_NVERIFY",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001631 },
1632 [OP_OPEN] = {
1633 .op_func = (nfsd4op_func)nfsd4_open,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001634 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001635 .op_name = "OP_OPEN",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001636 .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001637 .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001638 },
1639 [OP_OPEN_CONFIRM] = {
1640 .op_func = (nfsd4op_func)nfsd4_open_confirm,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001641 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001642 .op_name = "OP_OPEN_CONFIRM",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001643 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001644 },
1645 [OP_OPEN_DOWNGRADE] = {
1646 .op_func = (nfsd4op_func)nfsd4_open_downgrade,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001647 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001648 .op_name = "OP_OPEN_DOWNGRADE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001649 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
Tigran Mkrtchyan9428fe12012-02-13 22:55:31 +01001650 .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid,
1651 .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001652 },
1653 [OP_PUTFH] = {
1654 .op_func = (nfsd4op_func)nfsd4_putfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001655 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Tigran Mkrtchyan80e01cc2012-02-13 22:55:27 +01001656 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING
1657 | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001658 .op_name = "OP_PUTFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001659 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001660 },
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001661 [OP_PUTPUBFH] = {
J. Bruce Fieldsa1c8c4d2009-03-09 12:17:29 -04001662 .op_func = (nfsd4op_func)nfsd4_putrootfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001663 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Tigran Mkrtchyan80e01cc2012-02-13 22:55:27 +01001664 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING
1665 | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001666 .op_name = "OP_PUTPUBFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001667 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001668 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001669 [OP_PUTROOTFH] = {
1670 .op_func = (nfsd4op_func)nfsd4_putrootfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001671 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Tigran Mkrtchyan80e01cc2012-02-13 22:55:27 +01001672 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING
1673 | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001674 .op_name = "OP_PUTROOTFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001675 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001676 },
1677 [OP_READ] = {
1678 .op_func = (nfsd4op_func)nfsd4_read,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001679 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001680 .op_name = "OP_READ",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001681 .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
Tigran Mkrtchyan30813e22012-02-13 22:55:26 +01001682 .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001683 },
1684 [OP_READDIR] = {
1685 .op_func = (nfsd4op_func)nfsd4_readdir,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001686 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001687 .op_name = "OP_READDIR",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001688 .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001689 },
1690 [OP_READLINK] = {
1691 .op_func = (nfsd4op_func)nfsd4_readlink,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001692 .op_name = "OP_READLINK",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001693 },
1694 [OP_REMOVE] = {
1695 .op_func = (nfsd4op_func)nfsd4_remove,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001696 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001697 .op_name = "OP_REMOVE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001698 .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001699 },
1700 [OP_RENAME] = {
1701 .op_func = (nfsd4op_func)nfsd4_rename,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001702 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001703 .op_name = "OP_RENAME",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001704 .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001705 },
1706 [OP_RENEW] = {
1707 .op_func = (nfsd4op_func)nfsd4_renew,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001708 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
1709 | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001710 .op_name = "OP_RENEW",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001711 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
1712
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001713 },
1714 [OP_RESTOREFH] = {
1715 .op_func = (nfsd4op_func)nfsd4_restorefh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001716 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Mi Jinlong58e7b332011-08-28 18:18:56 +08001717 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001718 .op_name = "OP_RESTOREFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001719 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001720 },
1721 [OP_SAVEFH] = {
1722 .op_func = (nfsd4op_func)nfsd4_savefh,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001723 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001724 .op_name = "OP_SAVEFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001725 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001726 },
Andy Adamsondcb488a32007-07-17 04:04:51 -07001727 [OP_SECINFO] = {
1728 .op_func = (nfsd4op_func)nfsd4_secinfo,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001729 .op_flags = OP_HANDLES_WRONGSEC,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001730 .op_name = "OP_SECINFO",
Andy Adamsondcb488a32007-07-17 04:04:51 -07001731 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001732 [OP_SETATTR] = {
1733 .op_func = (nfsd4op_func)nfsd4_setattr,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001734 .op_name = "OP_SETATTR",
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001735 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001736 .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
Tigran Mkrtchyan1e97b512012-02-13 22:55:30 +01001737 .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001738 },
1739 [OP_SETCLIENTID] = {
1740 .op_func = (nfsd4op_func)nfsd4_setclientid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001741 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001742 | OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001743 .op_name = "OP_SETCLIENTID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001744 .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001745 },
1746 [OP_SETCLIENTID_CONFIRM] = {
1747 .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001748 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001749 | OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001750 .op_name = "OP_SETCLIENTID_CONFIRM",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001751 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001752 },
1753 [OP_VERIFY] = {
1754 .op_func = (nfsd4op_func)nfsd4_verify,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001755 .op_name = "OP_VERIFY",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001756 },
1757 [OP_WRITE] = {
1758 .op_func = (nfsd4op_func)nfsd4_write,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001759 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001760 .op_name = "OP_WRITE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001761 .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
Tigran Mkrtchyan30813e22012-02-13 22:55:26 +01001762 .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001763 },
1764 [OP_RELEASE_LOCKOWNER] = {
1765 .op_func = (nfsd4op_func)nfsd4_release_lockowner,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001766 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
1767 | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001768 .op_name = "OP_RELEASE_LOCKOWNER",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001769 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001770 },
Andy Adamson069b6ad2009-04-03 08:27:58 +03001771
1772 /* NFSv4.1 operations */
1773 [OP_EXCHANGE_ID] = {
1774 .op_func = (nfsd4op_func)nfsd4_exchange_id,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001775 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1776 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001777 .op_name = "OP_EXCHANGE_ID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001778 .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001779 },
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -04001780 [OP_BACKCHANNEL_CTL] = {
1781 .op_func = (nfsd4op_func)nfsd4_backchannel_ctl,
1782 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
1783 .op_name = "OP_BACKCHANNEL_CTL",
1784 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
1785 },
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001786 [OP_BIND_CONN_TO_SESSION] = {
1787 .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001788 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1789 | OP_MODIFIES_SOMETHING,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001790 .op_name = "OP_BIND_CONN_TO_SESSION",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001791 .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001792 },
Andy Adamson069b6ad2009-04-03 08:27:58 +03001793 [OP_CREATE_SESSION] = {
1794 .op_func = (nfsd4op_func)nfsd4_create_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001795 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1796 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001797 .op_name = "OP_CREATE_SESSION",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001798 .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001799 },
1800 [OP_DESTROY_SESSION] = {
1801 .op_func = (nfsd4op_func)nfsd4_destroy_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001802 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1803 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001804 .op_name = "OP_DESTROY_SESSION",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001805 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001806 },
1807 [OP_SEQUENCE] = {
1808 .op_func = (nfsd4op_func)nfsd4_sequence,
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001809 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001810 .op_name = "OP_SEQUENCE",
1811 },
Benny Halevy094b5d72011-06-16 11:39:10 -04001812 [OP_DESTROY_CLIENTID] = {
Mi Jinlong345c2842011-10-20 17:51:39 +08001813 .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001814 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1815 | OP_MODIFIES_SOMETHING,
Benny Halevy094b5d72011-06-16 11:39:10 -04001816 .op_name = "OP_DESTROY_CLIENTID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001817 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
Benny Halevy094b5d72011-06-16 11:39:10 -04001818 },
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001819 [OP_RECLAIM_COMPLETE] = {
1820 .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001821 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001822 .op_name = "OP_RECLAIM_COMPLETE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001823 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001824 },
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001825 [OP_SECINFO_NO_NAME] = {
1826 .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001827 .op_flags = OP_HANDLES_WRONGSEC,
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001828 .op_name = "OP_SECINFO_NO_NAME",
1829 },
Bryan Schumaker17456802011-07-13 10:50:48 -04001830 [OP_TEST_STATEID] = {
1831 .op_func = (nfsd4op_func)nfsd4_test_stateid,
1832 .op_flags = ALLOWED_WITHOUT_FH,
1833 .op_name = "OP_TEST_STATEID",
1834 },
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001835 [OP_FREE_STATEID] = {
1836 .op_func = (nfsd4op_func)nfsd4_free_stateid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001837 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001838 .op_name = "OP_FREE_STATEID",
J. Bruce Fieldsa1dc6952012-12-17 18:17:13 -05001839 .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001840 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001841 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001842};
1843
Trond Myklebust8f199b82012-03-20 15:11:17 -04001844#ifdef NFSD_DEBUG
Adrian Bunkf1c7f792008-08-08 19:26:42 +03001845static const char *nfsd4_op_name(unsigned opnum)
Benny Halevyb001a1b2008-07-02 11:15:03 +03001846{
1847 if (opnum < ARRAY_SIZE(nfsd4_ops))
1848 return nfsd4_ops[opnum].op_name;
1849 return "unknown_operation";
1850}
Trond Myklebust8f199b82012-03-20 15:11:17 -04001851#endif
Benny Halevyb001a1b2008-07-02 11:15:03 +03001852
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853#define nfsd4_voidres nfsd4_voidargs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854struct nfsd4_voidargs { int dummy; };
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856static struct svc_procedure nfsd_procedures4[2] = {
Yu Zhiguo0a93a472009-05-19 14:09:54 +08001857 [NFSPROC4_NULL] = {
1858 .pc_func = (svc_procfunc) nfsd4_proc_null,
1859 .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
1860 .pc_argsize = sizeof(struct nfsd4_voidargs),
1861 .pc_ressize = sizeof(struct nfsd4_voidres),
1862 .pc_cachetype = RC_NOCACHE,
1863 .pc_xdrressize = 1,
1864 },
1865 [NFSPROC4_COMPOUND] = {
1866 .pc_func = (svc_procfunc) nfsd4_proc_compound,
1867 .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
1868 .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
1869 .pc_argsize = sizeof(struct nfsd4_compoundargs),
1870 .pc_ressize = sizeof(struct nfsd4_compoundres),
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04001871 .pc_release = nfsd4_release_compoundargs,
Yu Zhiguo0a93a472009-05-19 14:09:54 +08001872 .pc_cachetype = RC_NOCACHE,
1873 .pc_xdrressize = NFSD_BUFSIZE/4,
1874 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875};
1876
1877struct svc_version nfsd_version4 = {
1878 .vs_vers = 4,
1879 .vs_nproc = 2,
1880 .vs_proc = nfsd_procedures4,
1881 .vs_dispatch = nfsd_dispatch,
1882 .vs_xdrsize = NFS4_SVC_XDRSIZE,
1883};
1884
1885/*
1886 * Local variables:
1887 * c-basic-offset: 8
1888 * End:
1889 */