blob: bdb71a57c94eb6f3de1366cbc7304d5b34375226 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#define NFSDDBG_FACILITY NFSDDBG_PROC
45
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080046static u32 nfsd_attrmask[] = {
47 NFSD_WRITEABLE_ATTRS_WORD0,
48 NFSD_WRITEABLE_ATTRS_WORD1,
49 NFSD_WRITEABLE_ATTRS_WORD2
50};
51
52static u32 nfsd41_ex_attrmask[] = {
53 NFSD_SUPPATTR_EXCLCREAT_WORD0,
54 NFSD_SUPPATTR_EXCLCREAT_WORD1,
55 NFSD_SUPPATTR_EXCLCREAT_WORD2
56};
57
58static __be32
59check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
60 u32 *bmval, u32 *writable)
61{
62 struct dentry *dentry = cstate->current_fh.fh_dentry;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080063
64 /*
65 * Check about attributes are supported by the NFSv4 server or not.
66 * According to spec, unsupported attributes return ERR_ATTRNOTSUPP.
67 */
68 if ((bmval[0] & ~nfsd_suppattrs0(cstate->minorversion)) ||
69 (bmval[1] & ~nfsd_suppattrs1(cstate->minorversion)) ||
70 (bmval[2] & ~nfsd_suppattrs2(cstate->minorversion)))
71 return nfserr_attrnotsupp;
72
73 /*
Trond Myklebusta06b1262009-08-31 15:16:11 -040074 * Check FATTR4_WORD0_ACL can be supported
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080075 * in current environment or not.
76 */
77 if (bmval[0] & FATTR4_WORD0_ACL) {
78 if (!IS_POSIXACL(dentry->d_inode))
79 return nfserr_attrnotsupp;
80 }
Yu Zhiguo3c8e0312009-05-16 16:22:31 +080081
82 /*
83 * According to spec, read-only attributes return ERR_INVAL.
84 */
85 if (writable) {
86 if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) ||
87 (bmval[2] & ~writable[2]))
88 return nfserr_inval;
89 }
90
91 return nfs_ok;
92}
93
94static __be32
95nfsd4_check_open_attributes(struct svc_rqst *rqstp,
96 struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
97{
98 __be32 status = nfs_ok;
99
100 if (open->op_create == NFS4_OPEN_CREATE) {
101 if (open->op_createmode == NFS4_CREATE_UNCHECKED
102 || open->op_createmode == NFS4_CREATE_GUARDED)
103 status = check_attr_support(rqstp, cstate,
104 open->op_bmval, nfsd_attrmask);
105 else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
106 status = check_attr_support(rqstp, cstate,
107 open->op_bmval, nfsd41_ex_attrmask);
108 }
109
110 return status;
111}
112
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800113static int
114is_create_with_attrs(struct nfsd4_open *open)
115{
116 return open->op_create == NFS4_OPEN_CREATE
117 && (open->op_createmode == NFS4_CREATE_UNCHECKED
118 || open->op_createmode == NFS4_CREATE_GUARDED
119 || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
120}
121
122/*
123 * if error occurs when setting the acl, just clear the acl bit
124 * in the returned attr bitmap.
125 */
126static void
127do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
128 struct nfs4_acl *acl, u32 *bmval)
129{
130 __be32 status;
131
132 status = nfsd4_set_nfs4_acl(rqstp, fhp, acl);
133 if (status)
134 /*
135 * We should probably fail the whole open at this point,
136 * but we've already created the file, so it's too late;
137 * So this seems the least of evils:
138 */
139 bmval[0] &= ~FATTR4_WORD0_ACL;
140}
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142static inline void
143fh_dup2(struct svc_fh *dst, struct svc_fh *src)
144{
145 fh_put(dst);
146 dget(src->fh_dentry);
147 if (src->fh_export)
148 cache_get(&src->fh_export->h);
149 *dst = *src;
150}
151
Al Virob37ad282006-10-19 23:28:59 -0700152static __be32
J. Bruce Fieldsdc730e12006-10-17 00:10:13 -0700153do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Al Virob37ad282006-10-19 23:28:59 -0700155 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 if (open->op_truncate &&
158 !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
159 return nfserr_inval;
160
J. Bruce Fieldsa0432262011-08-25 10:48:39 -0400161 accmode |= NFSD_MAY_READ_IF_EXEC;
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200164 accmode |= NFSD_MAY_READ;
J. Bruce Fields9801d8a2006-10-17 00:10:14 -0700165 if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200166 accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
J. Bruce Fields57ecb342009-12-01 19:42:57 -0500167 if (open->op_share_deny & NFS4_SHARE_DENY_READ)
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200168 accmode |= NFSD_MAY_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
171
172 return status;
173}
174
J. Bruce Fieldsaadab6c2011-08-15 16:55:02 -0400175static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
176{
177 umode_t mode = fh->fh_dentry->d_inode->i_mode;
178
179 if (S_ISREG(mode))
180 return nfs_ok;
181 if (S_ISDIR(mode))
182 return nfserr_isdir;
183 /*
184 * Using err_symlink as our catch-all case may look odd; but
185 * there's no other obvious error for this case in 4.0, and we
186 * happen to know that it will cause the linux v4 client to do
187 * the right thing on attempts to open something other than a
188 * regular file.
189 */
190 return nfserr_symlink;
191}
192
Al Virob37ad282006-10-19 23:28:59 -0700193static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
195{
196 struct svc_fh resfh;
Al Virob37ad282006-10-19 23:28:59 -0700197 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 fh_init(&resfh, NFS4_FHSIZE);
200 open->op_truncate = 0;
201
202 if (open->op_create) {
Benny Halevy79fb54a2009-04-03 08:29:17 +0300203 /* FIXME: check session persistence and pnfs flags.
204 * The nfsv4.1 spec requires the following semantics:
205 *
206 * Persistent | pNFS | Server REQUIRED | Client Allowed
207 * Reply Cache | server | |
208 * -------------+--------+-----------------+--------------------
209 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
210 * | | | (SHOULD)
211 * | | and EXCLUSIVE4 | or EXCLUSIVE4
212 * | | | (SHOULD NOT)
213 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
214 * yes | no | GUARDED4 | GUARDED4
215 * yes | yes | GUARDED4 | GUARDED4
216 */
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /*
219 * Note: create modes (UNCHECKED,GUARDED...) are the same
Mi Jinlongac6721a2011-04-20 17:06:25 +0800220 * in NFSv4 as in v3 except EXCLUSIVE4_1.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 */
Mi Jinlongac6721a2011-04-20 17:06:25 +0800222 status = do_nfsd_create(rqstp, current_fh, open->op_fname.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 open->op_fname.len, &open->op_iattr,
224 &resfh, open->op_createmode,
Jeff Layton749997e2007-07-31 00:37:51 -0700225 (u32 *)open->op_verf.data,
J. Bruce Fields856121b2011-10-13 11:37:11 -0400226 &open->op_truncate, &open->op_created);
Jeff Layton749997e2007-07-31 00:37:51 -0700227
J. Bruce Fields99f88722009-02-02 15:12:27 -0500228 /*
229 * Following rfc 3530 14.2.16, use the returned bitmask
230 * to indicate which attributes we used to store the
231 * verifier:
Jeff Layton749997e2007-07-31 00:37:51 -0700232 */
233 if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
J. Bruce Fields99f88722009-02-02 15:12:27 -0500234 open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
Jeff Layton749997e2007-07-31 00:37:51 -0700235 FATTR4_WORD1_TIME_MODIFY);
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800236 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 status = nfsd_lookup(rqstp, current_fh,
238 open->op_fname.data, open->op_fname.len, &resfh);
239 fh_unlock(current_fh);
J. Bruce Fieldsaadab6c2011-08-15 16:55:02 -0400240 if (status)
241 goto out;
242 status = nfsd_check_obj_isreg(&resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800244 if (status)
245 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800247 if (is_create_with_attrs(open) && open->op_acl != NULL)
248 do_set_nfs4_acl(rqstp, &resfh, open->op_acl, open->op_bmval);
249
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800250 /* set reply cache */
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400251 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
J. Bruce Fieldsa4773c082009-02-02 17:23:10 -0500252 &resfh.fh_handle);
J. Bruce Fields856121b2011-10-13 11:37:11 -0400253 if (!open->op_created)
J. Bruce Fields41fd1e42012-01-27 16:26:02 -0500254 status = do_open_permission(rqstp, &resfh, open,
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200255 NFSD_MAY_NOP);
J. Bruce Fields41fd1e42012-01-27 16:26:02 -0500256 set_change_info(&open->op_cinfo, current_fh);
257 fh_dup2(current_fh, &resfh);
J. Bruce Fieldsaf858522006-11-08 17:44:39 -0800258out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 fh_put(&resfh);
260 return status;
261}
262
Al Virob37ad282006-10-19 23:28:59 -0700263static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
265{
Al Virob37ad282006-10-19 23:28:59 -0700266 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* We don't know the target directory, and therefore can not
269 * set the change info
270 */
271
272 memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
273
274 /* set replay cache */
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400275 fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
J. Bruce Fieldsa4773c082009-02-02 17:23:10 -0500276 &current_fh->fh_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278 open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
279 (open->op_iattr.ia_size == 0);
280
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200281 status = do_open_permission(rqstp, current_fh, open,
282 NFSD_MAY_OWNER_OVERRIDE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 return status;
285}
286
Andy Adamson60adfc52009-04-03 08:28:50 +0300287static void
288copy_clientid(clientid_t *clid, struct nfsd4_session *session)
289{
290 struct nfsd4_sessionid *sid =
291 (struct nfsd4_sessionid *)session->se_sessionid.data;
292
293 clid->cl_boot = sid->clientid.cl_boot;
294 clid->cl_id = sid->clientid.cl_id;
295}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
J.Bruce Fields71911552006-12-13 00:35:29 -0800297static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800298nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -0800299 struct nfsd4_open *open)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Al Virob37ad282006-10-19 23:28:59 -0700301 __be32 status;
Andy Adamson66689582009-04-03 08:28:45 +0300302 struct nfsd4_compoundres *resp;
303
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400304 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 (int)open->op_fname.len, open->op_fname.data,
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400306 open->op_openowner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* This check required by spec. */
309 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
310 return nfserr_inval;
311
J. Bruce Fields856121b2011-10-13 11:37:11 -0400312 open->op_created = 0;
Mi Jinlongab1350b2011-07-14 15:06:26 +0800313 /*
314 * RFC5661 18.51.3
315 * Before RECLAIM_COMPLETE done, server should deny new lock
316 */
317 if (nfsd4_has_session(cstate) &&
318 !cstate->session->se_client->cl_firststate &&
319 open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
320 return nfserr_grace;
321
Andy Adamson60adfc52009-04-03 08:28:50 +0300322 if (nfsd4_has_session(cstate))
323 copy_clientid(&open->op_clientid, cstate->session);
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 nfs4_lock_state();
326
327 /* check seqid for replay. set nfs4_owner */
Andy Adamson66689582009-04-03 08:28:45 +0300328 resp = rqstp->rq_resp;
329 status = nfsd4_process_open1(&resp->cstate, open);
Al Viroa90b0612006-10-19 23:29:03 -0700330 if (status == nfserr_replay_me) {
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400331 struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800332 fh_put(&cstate->current_fh);
J. Bruce Fieldsa4773c082009-02-02 17:23:10 -0500333 fh_copy_shallow(&cstate->current_fh.fh_handle,
334 &rp->rp_openfh);
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200335 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (status)
337 dprintk("nfsd4_open: replay failed"
338 " restoring previous filehandle\n");
339 else
Al Viroa90b0612006-10-19 23:29:03 -0700340 status = nfserr_replay_me;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342 if (status)
343 goto out;
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800344
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800345 status = nfsd4_check_open_attributes(rqstp, cstate, open);
346 if (status)
347 goto out;
348
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800349 /* Openowner is now set, so sequence id will get bumped. Now we need
350 * these checks before we do any creates: */
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800351 status = nfserr_grace;
J. Bruce Fieldsaf558e32007-09-06 12:34:25 -0400352 if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800353 goto out;
354 status = nfserr_no_grace;
J. Bruce Fieldsaf558e32007-09-06 12:34:25 -0400355 if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
J. Bruce Fieldscbd0d512006-02-07 12:58:32 -0800356 goto out;
J. Bruce Fieldsfb553c02006-01-18 17:43:36 -0800357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 switch (open->op_claim_type) {
NeilBrown0dd3c192005-06-23 22:02:56 -0700359 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 case NFS4_OPEN_CLAIM_NULL:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800361 status = do_open_lookup(rqstp, &cstate->current_fh,
362 open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (status)
364 goto out;
365 break;
366 case NFS4_OPEN_CLAIM_PREVIOUS:
J. Bruce Fieldsdad1c062011-09-12 12:24:13 -0400367 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
Mi Jinlong0cf99b92011-11-23 10:48:40 +0800368 status = nfs4_check_open_reclaim(&open->op_clientid);
369 if (status)
370 goto out;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400371 case NFS4_OPEN_CLAIM_FH:
372 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800373 status = do_open_fhandle(rqstp, &cstate->current_fh,
374 open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (status)
376 goto out;
377 break;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400378 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
J. Bruce Fieldsdad1c062011-09-12 12:24:13 -0400380 open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
J. Bruce Fields2fdada02007-07-27 16:10:37 -0400381 dprintk("NFSD: unsupported OPEN claim type %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 open->op_claim_type);
383 status = nfserr_notsupp;
384 goto out;
385 default:
J. Bruce Fields2fdada02007-07-27 16:10:37 -0400386 dprintk("NFSD: Invalid OPEN claim type %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 open->op_claim_type);
388 status = nfserr_inval;
389 goto out;
390 }
391 /*
392 * nfsd4_process_open2() does the actual opening of the file. If
393 * successful, it (1) truncates the file if open->op_truncate was
394 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
395 */
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800396 status = nfsd4_process_open2(rqstp, &cstate->current_fh, open);
J. Bruce Fields856121b2011-10-13 11:37:11 -0400397 WARN_ON(status && open->op_created);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398out:
J. Bruce Fieldsd29b20c2011-10-13 15:12:59 -0400399 nfsd4_cleanup_open_state(open, status);
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400400 if (open->op_openowner)
401 cstate->replay_owner = &open->op_openowner->oo_owner;
J. Bruce Fields7c13f342011-08-30 22:15:47 -0400402 else
J. Bruce Fields5ec094c2011-08-30 17:02:48 -0400403 nfs4_unlock_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return status;
405}
406
407/*
408 * filehandle-manipulating ops.
409 */
J.Bruce Fields71911552006-12-13 00:35:29 -0800410static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800411nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
412 struct svc_fh **getfh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800414 if (!cstate->current_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return nfserr_nofilehandle;
416
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800417 *getfh = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return nfs_ok;
419}
420
J.Bruce Fields71911552006-12-13 00:35:29 -0800421static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800422nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
423 struct nfsd4_putfh *putfh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800425 fh_put(&cstate->current_fh);
426 cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
427 memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
428 putfh->pf_fhlen);
J. Bruce Fields68d93182011-04-08 17:00:50 -0400429 return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
J.Bruce Fields71911552006-12-13 00:35:29 -0800432static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800433nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
434 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Al Virob37ad282006-10-19 23:28:59 -0700436 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800438 fh_put(&cstate->current_fh);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700439 status = exp_pseudoroot(rqstp, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return status;
441}
442
J.Bruce Fields71911552006-12-13 00:35:29 -0800443static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800444nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
445 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800447 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return nfserr_restorefh;
449
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800450 fh_dup2(&cstate->current_fh, &cstate->save_fh);
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100451 if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) {
452 memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
453 SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG);
454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return nfs_ok;
456}
457
J.Bruce Fields71911552006-12-13 00:35:29 -0800458static __be32
J.Bruce Fieldsb5914802006-12-13 00:35:38 -0800459nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
460 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800462 if (!cstate->current_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 return nfserr_nofilehandle;
464
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800465 fh_dup2(&cstate->save_fh, &cstate->current_fh);
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +0100466 if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) {
467 memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
468 SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG);
469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return nfs_ok;
471}
472
473/*
474 * misc nfsv4 ops
475 */
J.Bruce Fields71911552006-12-13 00:35:29 -0800476static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800477nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
478 struct nfsd4_access *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 if (access->ac_req_access & ~NFS3_ACCESS_FULL)
481 return nfserr_inval;
482
483 access->ac_resp_access = access->ac_req_access;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800484 return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
485 &access->ac_supported);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486}
487
J.Bruce Fields71911552006-12-13 00:35:29 -0800488static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800489nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
490 struct nfsd4_commit *commit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 u32 *p = (u32 *)commit->co_verf.data;
493 *p++ = nfssvc_boot.tv_sec;
494 *p++ = nfssvc_boot.tv_usec;
495
J. Bruce Fields75c096f2011-08-15 18:39:32 -0400496 return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800497 commit->co_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
Al Virob37ad282006-10-19 23:28:59 -0700500static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800501nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
502 struct nfsd4_create *create)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
504 struct svc_fh resfh;
Al Virob37ad282006-10-19 23:28:59 -0700505 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 dev_t rdev;
507
508 fh_init(&resfh, NFS4_FHSIZE);
509
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200510 status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR,
511 NFSD_MAY_CREATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (status)
513 return status;
514
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800515 status = check_attr_support(rqstp, cstate, create->cr_bmval,
516 nfsd_attrmask);
517 if (status)
518 return status;
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 switch (create->cr_type) {
521 case NF4LNK:
522 /* ugh! we have to null-terminate the linktext, or
523 * vfs_symlink() will choke. it is always safe to
524 * null-terminate by brute force, since at worst we
525 * will overwrite the first byte of the create namelen
526 * in the XDR buffer, which has already been extracted
527 * during XDR decode.
528 */
529 create->cr_linkname[create->cr_linklen] = 0;
530
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800531 status = nfsd_symlink(rqstp, &cstate->current_fh,
532 create->cr_name, create->cr_namelen,
533 create->cr_linkname, create->cr_linklen,
534 &resfh, &create->cr_iattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 break;
536
537 case NF4BLK:
538 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
539 if (MAJOR(rdev) != create->cr_specdata1 ||
540 MINOR(rdev) != create->cr_specdata2)
541 return nfserr_inval;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800542 status = nfsd_create(rqstp, &cstate->current_fh,
543 create->cr_name, create->cr_namelen,
544 &create->cr_iattr, S_IFBLK, rdev, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 break;
546
547 case NF4CHR:
548 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
549 if (MAJOR(rdev) != create->cr_specdata1 ||
550 MINOR(rdev) != create->cr_specdata2)
551 return nfserr_inval;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800552 status = nfsd_create(rqstp, &cstate->current_fh,
553 create->cr_name, create->cr_namelen,
554 &create->cr_iattr,S_IFCHR, rdev, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 break;
556
557 case NF4SOCK:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800558 status = nfsd_create(rqstp, &cstate->current_fh,
559 create->cr_name, create->cr_namelen,
560 &create->cr_iattr, S_IFSOCK, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 break;
562
563 case NF4FIFO:
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800564 status = nfsd_create(rqstp, &cstate->current_fh,
565 create->cr_name, create->cr_namelen,
566 &create->cr_iattr, S_IFIFO, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 break;
568
569 case NF4DIR:
570 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800571 status = nfsd_create(rqstp, &cstate->current_fh,
572 create->cr_name, create->cr_namelen,
573 &create->cr_iattr, S_IFDIR, 0, &resfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 break;
575
576 default:
577 status = nfserr_badtype;
578 }
579
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800580 if (status)
581 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Yu Zhiguo9208faf2009-07-06 17:24:16 +0800583 if (create->cr_acl != NULL)
584 do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
585 create->cr_bmval);
586
587 fh_unlock(&cstate->current_fh);
588 set_change_info(&create->cr_cinfo, &cstate->current_fh);
589 fh_dup2(&cstate->current_fh, &resfh);
590out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 fh_put(&resfh);
592 return status;
593}
594
J.Bruce Fields71911552006-12-13 00:35:29 -0800595static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800596nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
597 struct nfsd4_getattr *getattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Al Virob37ad282006-10-19 23:28:59 -0700599 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200601 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 if (status)
603 return status;
604
605 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
606 return nfserr_inval;
607
Andy Adamson7e705702009-04-03 08:29:11 +0300608 getattr->ga_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
609 getattr->ga_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
610 getattr->ga_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800612 getattr->ga_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return nfs_ok;
614}
615
J.Bruce Fields71911552006-12-13 00:35:29 -0800616static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800617nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
618 struct nfsd4_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
Al Virob37ad282006-10-19 23:28:59 -0700620 __be32 status = nfserr_nofilehandle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800622 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return status;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800624 status = nfsd_link(rqstp, &cstate->current_fh,
625 link->li_name, link->li_namelen, &cstate->save_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (!status)
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800627 set_change_info(&link->li_cinfo, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return status;
629}
630
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500631static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
633 struct svc_fh tmp_fh;
Al Virob37ad282006-10-19 23:28:59 -0700634 __be32 ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 fh_init(&tmp_fh, NFS4_FHSIZE);
J. Bruce Fieldsdf547ef2007-07-17 04:04:43 -0700637 ret = exp_pseudoroot(rqstp, &tmp_fh);
638 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return ret;
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500640 if (tmp_fh.fh_dentry == fh->fh_dentry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 fh_put(&tmp_fh);
642 return nfserr_noent;
643 }
644 fh_put(&tmp_fh);
J. Bruce Fields0ff7ab42010-12-16 10:06:27 -0500645 return nfsd_lookup(rqstp, fh, "..", 2, fh);
646}
647
648static __be32
649nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
650 void *arg)
651{
652 return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
J.Bruce Fields71911552006-12-13 00:35:29 -0800655static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800656nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
657 struct nfsd4_lookup *lookup)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800659 return nfsd_lookup(rqstp, &cstate->current_fh,
660 lookup->lo_name, lookup->lo_len,
661 &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
J.Bruce Fields71911552006-12-13 00:35:29 -0800664static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800665nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
666 struct nfsd4_read *read)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
Al Virob37ad282006-10-19 23:28:59 -0700668 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670 /* no need to check permission - this will be done in nfsd_read() */
671
NeilBrown7e06b7f2005-06-23 22:03:13 -0700672 read->rd_filp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 if (read->rd_offset >= OFFSET_MAX)
674 return nfserr_inval;
675
676 nfs4_lock_state();
677 /* check stateid */
Benny Halevydd453df2009-04-03 08:28:41 +0300678 if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid,
679 RD_STATE, &read->rd_filp))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
681 goto out;
682 }
NeilBrown7e06b7f2005-06-23 22:03:13 -0700683 if (read->rd_filp)
684 get_file(read->rd_filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 status = nfs_ok;
686out:
687 nfs4_unlock_state();
688 read->rd_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800689 read->rd_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 return status;
691}
692
J.Bruce Fields71911552006-12-13 00:35:29 -0800693static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800694nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
695 struct nfsd4_readdir *readdir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 u64 cookie = readdir->rd_cookie;
698 static const nfs4_verifier zeroverf;
699
700 /* no need to check permission - this will be done in nfsd_readdir() */
701
702 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
703 return nfserr_inval;
704
Andy Adamson7e705702009-04-03 08:29:11 +0300705 readdir->rd_bmval[0] &= nfsd_suppattrs0(cstate->minorversion);
706 readdir->rd_bmval[1] &= nfsd_suppattrs1(cstate->minorversion);
707 readdir->rd_bmval[2] &= nfsd_suppattrs2(cstate->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Bernd Schubert832023b2011-08-08 17:38:08 +0200709 if ((cookie == 1) || (cookie == 2) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
711 return nfserr_bad_cookie;
712
713 readdir->rd_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800714 readdir->rd_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return nfs_ok;
716}
717
J.Bruce Fields71911552006-12-13 00:35:29 -0800718static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800719nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
720 struct nfsd4_readlink *readlink)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
722 readlink->rl_rqstp = rqstp;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800723 readlink->rl_fhp = &cstate->current_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 return nfs_ok;
725}
726
J.Bruce Fields71911552006-12-13 00:35:29 -0800727static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800728nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
729 struct nfsd4_remove *remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
Al Virob37ad282006-10-19 23:28:59 -0700731 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
J. Bruce Fieldsaf558e32007-09-06 12:34:25 -0400733 if (locks_in_grace())
NeilBrownc815afc2005-06-23 22:03:00 -0700734 return nfserr_grace;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800735 status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
736 remove->rm_name, remove->rm_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 if (!status) {
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800738 fh_unlock(&cstate->current_fh);
739 set_change_info(&remove->rm_cinfo, &cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741 return status;
742}
743
J.Bruce Fields71911552006-12-13 00:35:29 -0800744static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800745nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
746 struct nfsd4_rename *rename)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Al Virob37ad282006-10-19 23:28:59 -0700748 __be32 status = nfserr_nofilehandle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800750 if (!cstate->save_fh.fh_dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 return status;
J. Bruce Fieldsaf558e32007-09-06 12:34:25 -0400752 if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
NeilBrownc815afc2005-06-23 22:03:00 -0700753 & NFSEXP_NOSUBTREECHECK))
754 return nfserr_grace;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800755 status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
756 rename->rn_snamelen, &cstate->current_fh,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 rename->rn_tname, rename->rn_tnamelen);
758
759 /* the underlying filesystem returns different error's than required
760 * by NFSv4. both save_fh and current_fh have been verified.. */
761 if (status == nfserr_isdir)
762 status = nfserr_exist;
763 else if ((status == nfserr_notdir) &&
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800764 (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) &&
765 S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 status = nfserr_exist;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 if (!status) {
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800769 set_change_info(&rename->rn_sinfo, &cstate->current_fh);
770 set_change_info(&rename->rn_tinfo, &cstate->save_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772 return status;
773}
774
J.Bruce Fields71911552006-12-13 00:35:29 -0800775static __be32
Andy Adamsondcb488a32007-07-17 04:04:51 -0700776nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
777 struct nfsd4_secinfo *secinfo)
778{
779 struct svc_fh resfh;
780 struct svc_export *exp;
781 struct dentry *dentry;
782 __be32 err;
783
784 fh_init(&resfh, NFS4_FHSIZE);
J. Bruce Fields29a78a32011-04-09 11:28:53 -0400785 err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
786 if (err)
787 return err;
Andy Adamsondcb488a32007-07-17 04:04:51 -0700788 err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
789 secinfo->si_name, secinfo->si_namelen,
790 &exp, &dentry);
791 if (err)
792 return err;
793 if (dentry->d_inode == NULL) {
794 exp_put(exp);
795 err = nfserr_noent;
796 } else
797 secinfo->si_exp = exp;
798 dput(dentry);
J. Bruce Fields56560b92010-12-16 09:57:15 -0500799 if (cstate->minorversion)
800 /* See rfc 5661 section 2.6.3.1.1.8 */
801 fh_put(&cstate->current_fh);
Andy Adamsondcb488a32007-07-17 04:04:51 -0700802 return err;
803}
804
805static __be32
J. Bruce Fields04f4ad12010-12-16 09:51:13 -0500806nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
807 struct nfsd4_secinfo_no_name *sin)
808{
809 __be32 err;
810
811 switch (sin->sin_style) {
812 case NFS4_SECINFO_STYLE4_CURRENT_FH:
813 break;
814 case NFS4_SECINFO_STYLE4_PARENT:
815 err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
816 if (err)
817 return err;
818 break;
819 default:
820 return nfserr_inval;
821 }
822 exp_get(cstate->current_fh.fh_export);
823 sin->sin_exp = cstate->current_fh.fh_export;
824 fh_put(&cstate->current_fh);
825 return nfs_ok;
826}
827
828static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800829nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
830 struct nfsd4_setattr *setattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Al Virob37ad282006-10-19 23:28:59 -0700832 __be32 status = nfs_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
835 nfs4_lock_state();
Benny Halevydd453df2009-04-03 08:28:41 +0300836 status = nfs4_preprocess_stateid_op(cstate,
J. Bruce Fields6150ef02009-02-21 13:36:16 -0800837 &setattr->sa_stateid, WR_STATE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 nfs4_unlock_state();
J. Bruce Fields375c5542006-01-18 17:43:33 -0800839 if (status) {
Greg Banks3e3b4802006-10-02 02:17:41 -0700840 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
J. Bruce Fields375c5542006-01-18 17:43:33 -0800841 return status;
842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
Al Virobad0dcf2011-11-23 12:03:18 -0500844 status = fh_want_write(&cstate->current_fh);
Dave Hansen18f335a2008-02-15 14:37:38 -0800845 if (status)
846 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 status = nfs_ok;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800848
849 status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
850 nfsd_attrmask);
851 if (status)
852 goto out;
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (setattr->sa_acl != NULL)
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800855 status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh,
856 setattr->sa_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (status)
Dave Hansen18f335a2008-02-15 14:37:38 -0800858 goto out;
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800859 status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 0, (time_t)0);
Dave Hansen18f335a2008-02-15 14:37:38 -0800861out:
Al Virobad0dcf2011-11-23 12:03:18 -0500862 fh_drop_write(&cstate->current_fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 return status;
864}
865
J.Bruce Fields71911552006-12-13 00:35:29 -0800866static __be32
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800867nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
868 struct nfsd4_write *write)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
870 stateid_t *stateid = &write->wr_stateid;
871 struct file *filp = NULL;
872 u32 *p;
Al Virob37ad282006-10-19 23:28:59 -0700873 __be32 status = nfs_ok;
David Shaw31dec252009-03-05 20:16:14 -0500874 unsigned long cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 /* no need to check permission - this will be done in nfsd_write() */
877
878 if (write->wr_offset >= OFFSET_MAX)
879 return nfserr_inval;
880
881 nfs4_lock_state();
Benny Halevydd453df2009-04-03 08:28:41 +0300882 status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp);
NeilBrown7e06b7f2005-06-23 22:03:13 -0700883 if (filp)
884 get_file(filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 nfs4_unlock_state();
886
J. Bruce Fields375c5542006-01-18 17:43:33 -0800887 if (status) {
888 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
889 return status;
890 }
891
David Shaw31dec252009-03-05 20:16:14 -0500892 cnt = write->wr_buflen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 write->wr_how_written = write->wr_stable_how;
894 p = (u32 *)write->wr_verifier.data;
895 *p++ = nfssvc_boot.tv_sec;
896 *p++ = nfssvc_boot.tv_usec;
897
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800898 status = nfsd_write(rqstp, &cstate->current_fh, filp,
899 write->wr_offset, rqstp->rq_vec, write->wr_vlen,
David Shaw31dec252009-03-05 20:16:14 -0500900 &cnt, &write->wr_how_written);
NeilBrown7e06b7f2005-06-23 22:03:13 -0700901 if (filp)
902 fput(filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
David Shaw31dec252009-03-05 20:16:14 -0500904 write->wr_bytes_written = cnt;
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
909/* This routine never returns NFS_OK! If there are no other errors, it
910 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
911 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
912 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
913 */
Al Virob37ad282006-10-19 23:28:59 -0700914static __be32
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -0800915_nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800916 struct nfsd4_verify *verify)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Al Viro2ebbc012006-10-19 23:28:58 -0700918 __be32 *buf, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 int count;
Al Virob37ad282006-10-19 23:28:59 -0700920 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200922 status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 if (status)
924 return status;
925
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800926 status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
927 if (status)
928 return status;
929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
931 || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
932 return nfserr_inval;
933 if (verify->ve_attrlen & 3)
934 return nfserr_inval;
935
936 /* count in words:
937 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
938 */
939 count = 4 + (verify->ve_attrlen >> 2);
940 buf = kmalloc(count << 2, GFP_KERNEL);
941 if (!buf)
J. Bruce Fields3e772462011-08-10 19:07:33 -0400942 return nfserr_jukebox;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
J.Bruce Fieldsca364312006-12-13 00:35:27 -0800944 status = nfsd4_encode_fattr(&cstate->current_fh,
945 cstate->current_fh.fh_export,
946 cstate->current_fh.fh_dentry, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 &count, verify->ve_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -0800948 rqstp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 /* this means that nfsd4_encode_fattr() ran out of space */
951 if (status == nfserr_resource && count == 0)
952 status = nfserr_not_same;
953 if (status)
954 goto out_kfree;
955
Benny Halevy95ec28c2009-04-03 08:29:08 +0300956 /* skip bitmap */
957 p = buf + 1 + ntohl(buf[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 status = nfserr_not_same;
959 if (ntohl(*p++) != verify->ve_attrlen)
960 goto out_kfree;
961 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
962 status = nfserr_same;
963
964out_kfree:
965 kfree(buf);
966 return status;
967}
968
J.Bruce Fieldsc954e2a2006-12-13 00:35:31 -0800969static __be32
970nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
971 struct nfsd4_verify *verify)
972{
973 __be32 status;
974
975 status = _nfsd4_verify(rqstp, cstate, verify);
976 return status == nfserr_not_same ? nfs_ok : status;
977}
978
979static __be32
980nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
981 struct nfsd4_verify *verify)
982{
983 __be32 status;
984
985 status = _nfsd4_verify(rqstp, cstate, verify);
986 return status == nfserr_same ? nfs_ok : status;
987}
988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989/*
990 * NULL call.
991 */
Al Viro7111c662006-10-19 23:28:45 -0700992static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
994{
995 return nfs_ok;
996}
997
Shankar Anande2b20952006-07-10 04:45:44 -0700998static inline void nfsd4_increment_op_stats(u32 opnum)
999{
1000 if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
1001 nfsdstats.nfs4_opcount[opnum]++;
1002}
1003
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001004typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *,
1005 void *);
Mi Jinlong58e7b332011-08-28 18:18:56 +08001006typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001007typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *);
1008typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *);
Mi Jinlong58e7b332011-08-28 18:18:56 +08001009
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001010enum nfsd4_op_flags {
1011 ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */
Mi Jinlong5ece3ca2011-02-18 09:08:31 +08001012 ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */
1013 ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */
J. Bruce Fields68d93182011-04-08 17:00:50 -04001014 /* For rfc 5661 section 2.6.3.1.1: */
1015 OP_HANDLES_WRONGSEC = 1 << 3,
1016 OP_IS_PUTFH_LIKE = 1 << 4,
J. Bruce Fields10910062011-01-24 12:11:02 -05001017 /*
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001018 * These are the ops whose result size we estimate before
1019 * encoding, to avoid performing an op then not being able to
1020 * respond or cache a response. This includes writes and setattrs
1021 * as well as the operations usually called "nonidempotent":
1022 */
1023 OP_MODIFIES_SOMETHING = 1 << 5,
1024 /*
1025 * Cache compounds containing these ops in the xid-based drc:
J. Bruce Fields10910062011-01-24 12:11:02 -05001026 * We use the DRC for compounds containing non-idempotent
1027 * operations, *except* those that are 4.1-specific (since
1028 * sessions provide their own EOS), and except for stateful
1029 * operations other than setclientid and setclientid_confirm
1030 * (since sequence numbers provide EOS for open, lock, etc in
1031 * the v4.0 case).
1032 */
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001033 OP_CACHEME = 1 << 6,
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001034 /*
1035 * These are ops which clear current state id.
1036 */
1037 OP_CLEAR_STATEID = 1 << 7,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001038};
1039
1040struct nfsd4_operation {
1041 nfsd4op_func op_func;
1042 u32 op_flags;
1043 char *op_name;
Mi Jinlong58e7b332011-08-28 18:18:56 +08001044 /* Try to get response size before operation */
1045 nfsd4op_rsize op_rsize_bop;
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001046 stateid_setter op_get_currentstateid;
1047 stateid_getter op_set_currentstateid;
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001048};
1049
1050static struct nfsd4_operation nfsd4_ops[];
1051
Adrian Bunkf1c7f792008-08-08 19:26:42 +03001052static const char *nfsd4_op_name(unsigned opnum);
Benny Halevyb001a1b2008-07-02 11:15:03 +03001053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054/*
J. Bruce Fields57716352010-04-21 12:27:19 -04001055 * Enforce NFSv4.1 COMPOUND ordering rules:
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001056 *
J. Bruce Fields57716352010-04-21 12:27:19 -04001057 * Also note, enforced elsewhere:
1058 * - SEQUENCE other than as first op results in
1059 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001060 * - BIND_CONN_TO_SESSION must be the only op in its compound.
1061 * (Enforced in nfsd4_bind_conn_to_session().)
J. Bruce Fields57716352010-04-21 12:27:19 -04001062 * - DESTROY_SESSION must be the final operation in a compound, if
1063 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
1064 * (Enforced in nfsd4_destroy_session().)
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001065 */
J. Bruce Fields57716352010-04-21 12:27:19 -04001066static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001067{
J. Bruce Fields57716352010-04-21 12:27:19 -04001068 struct nfsd4_op *op = &args->ops[0];
1069
1070 /* These ordering requirements don't apply to NFSv4.0: */
1071 if (args->minorversion == 0)
1072 return nfs_ok;
1073 /* This is weird, but OK, not our problem: */
1074 if (args->opcnt == 0)
1075 return nfs_ok;
1076 if (op->status == nfserr_op_illegal)
1077 return nfs_ok;
1078 if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
1079 return nfserr_op_not_in_session;
1080 if (op->opnum == OP_SEQUENCE)
1081 return nfs_ok;
1082 if (args->opcnt != 1)
1083 return nfserr_not_only_op;
1084 return nfs_ok;
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001085}
1086
J. Bruce Fields22b03212011-04-09 11:23:24 -04001087static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
1088{
1089 return &nfsd4_ops[op->opnum];
1090}
1091
J. Bruce Fields10910062011-01-24 12:11:02 -05001092bool nfsd4_cache_this_op(struct nfsd4_op *op)
1093{
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001094 return OPDESC(op)->op_flags & OP_CACHEME;
J. Bruce Fields10910062011-01-24 12:11:02 -05001095}
1096
J. Bruce Fields68d93182011-04-08 17:00:50 -04001097static bool need_wrongsec_check(struct svc_rqst *rqstp)
1098{
1099 struct nfsd4_compoundres *resp = rqstp->rq_resp;
1100 struct nfsd4_compoundargs *argp = rqstp->rq_argp;
1101 struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
1102 struct nfsd4_op *next = &argp->ops[resp->opcnt];
1103 struct nfsd4_operation *thisd;
1104 struct nfsd4_operation *nextd;
1105
1106 thisd = OPDESC(this);
1107 /*
1108 * Most ops check wronsec on our own; only the putfh-like ops
1109 * have special rules.
1110 */
1111 if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
1112 return false;
1113 /*
1114 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
1115 * put-filehandle operation if we're not going to use the
1116 * result:
1117 */
1118 if (argp->opcnt == resp->opcnt)
1119 return false;
1120
1121 nextd = OPDESC(next);
1122 /*
1123 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
1124 * errors themselves as necessary; others should check for them
1125 * now:
1126 */
1127 return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
1128}
1129
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001130/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 * COMPOUND call.
1132 */
Al Viro7111c662006-10-19 23:28:45 -07001133static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134nfsd4_proc_compound(struct svc_rqst *rqstp,
1135 struct nfsd4_compoundargs *args,
1136 struct nfsd4_compoundres *resp)
1137{
1138 struct nfsd4_op *op;
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001139 struct nfsd4_operation *opdesc;
Andy Adamsone354d572009-03-28 11:30:52 +03001140 struct nfsd4_compound_state *cstate = &resp->cstate;
J.Bruce Fieldse5710192006-12-13 00:35:20 -08001141 int slack_bytes;
Mi Jinlong58e7b332011-08-28 18:18:56 +08001142 u32 plen = 0;
Al Virob37ad282006-10-19 23:28:59 -07001143 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 resp->xbuf = &rqstp->rq_res;
Andy Adamsone354d572009-03-28 11:30:52 +03001146 resp->p = rqstp->rq_res.head[0].iov_base +
1147 rqstp->rq_res.head[0].iov_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 resp->tagp = resp->p;
1149 /* reserve space for: taglen, tag, and opcnt */
1150 resp->p += 2 + XDR_QUADLEN(args->taglen);
1151 resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
1152 resp->taglen = args->taglen;
1153 resp->tag = args->tag;
1154 resp->opcnt = 0;
1155 resp->rqstp = rqstp;
Andy Adamsond87a8ad2009-04-03 08:28:53 +03001156 resp->cstate.minorversion = args->minorversion;
Andy Adamsone354d572009-03-28 11:30:52 +03001157 resp->cstate.replay_owner = NULL;
J. Bruce Fields26c0c752010-04-24 15:35:43 -04001158 resp->cstate.session = NULL;
Andy Adamsone354d572009-03-28 11:30:52 +03001159 fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
1160 fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
NeilBrown8ff30fa2010-08-12 17:04:07 +10001161 /*
1162 * Don't use the deferral mechanism for NFSv4; compounds make it
1163 * too hard to avoid non-idempotency problems.
1164 */
1165 rqstp->rq_usedeferral = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 /*
1168 * According to RFC3010, this takes precedence over all other errors.
1169 */
1170 status = nfserr_minor_vers_mismatch;
Benny Halevy8daf2202009-04-03 08:28:59 +03001171 if (args->minorversion > nfsd_supported_minorversion)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 goto out;
1173
J. Bruce Fields57716352010-04-21 12:27:19 -04001174 status = nfs41_check_op_ordering(args);
1175 if (status) {
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001176 op = &args->ops[0];
J. Bruce Fields57716352010-04-21 12:27:19 -04001177 op->status = status;
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001178 goto encode_op;
1179 }
1180
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 while (!status && resp->opcnt < args->opcnt) {
1182 op = &args->ops[resp->opcnt++];
1183
Benny Halevyb001a1b2008-07-02 11:15:03 +03001184 dprintk("nfsv4 compound op #%d/%d: %d (%s)\n",
1185 resp->opcnt, args->opcnt, op->opnum,
1186 nfsd4_op_name(op->opnum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 /*
1188 * The XDR decode routines may have pre-set op->status;
1189 * for example, if there is a miscellaneous XDR error
1190 * it will be set to nfserr_bad_xdr.
1191 */
1192 if (op->status)
1193 goto encode_op;
1194
1195 /* We must be able to encode a successful response to
1196 * this operation, with enough room left over to encode a
1197 * failed response to the next operation. If we don't
1198 * have enough room, fail with ERR_RESOURCE.
1199 */
J.Bruce Fieldse5710192006-12-13 00:35:20 -08001200 slack_bytes = (char *)resp->end - (char *)resp->p;
1201 if (slack_bytes < COMPOUND_SLACK_SPACE
1202 + COMPOUND_ERR_SLACK_SPACE) {
1203 BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 op->status = nfserr_resource;
1205 goto encode_op;
1206 }
1207
J. Bruce Fields22b03212011-04-09 11:23:24 -04001208 opdesc = OPDESC(op);
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001209
J.Bruce Fieldsca364312006-12-13 00:35:27 -08001210 if (!cstate->current_fh.fh_dentry) {
J.Bruce Fields27d630e2006-12-13 00:35:43 -08001211 if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
J.Bruce Fields42ca0992006-10-04 02:16:20 -07001212 op->status = nfserr_nofilehandle;
1213 goto encode_op;
1214 }
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001215 } else if (cstate->current_fh.fh_export->ex_fslocs.migrated &&
1216 !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
J.Bruce Fields42ca0992006-10-04 02:16:20 -07001217 op->status = nfserr_moved;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 goto encode_op;
1219 }
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001220
Mi Jinlong58e7b332011-08-28 18:18:56 +08001221 /* If op is non-idempotent */
1222 if (opdesc->op_flags & OP_MODIFIES_SOMETHING) {
1223 plen = opdesc->op_rsize_bop(rqstp, op);
1224 op->status = nfsd4_check_resp_size(resp, plen);
1225 }
1226
1227 if (op->status)
1228 goto encode_op;
1229
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001230 if (opdesc->op_func) {
1231 if (opdesc->op_get_currentstateid)
1232 opdesc->op_get_currentstateid(cstate, &op->u);
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001233 op->status = opdesc->op_func(rqstp, cstate, &op->u);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001234 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 BUG_ON(op->status == nfs_ok);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001237 if (!op->status) {
1238 if (opdesc->op_set_currentstateid)
1239 opdesc->op_set_currentstateid(cstate, &op->u);
1240
1241 if (opdesc->op_flags & OP_CLEAR_STATEID)
Tigran Mkrtchyan37c593c2012-02-13 22:55:32 +01001242 clear_current_stateid(cstate);
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001243
1244 if (need_wrongsec_check(rqstp))
1245 op->status = check_nfsd_access(cstate->current_fh.fh_export, rqstp);
1246 }
J. Bruce Fields68d93182011-04-08 17:00:50 -04001247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248encode_op:
Andy Adamson49557cc2009-07-23 19:02:16 -04001249 /* Only from SEQUENCE */
Andy Adamsonda3846a2009-04-03 08:28:22 +03001250 if (resp->cstate.status == nfserr_replay_cache) {
1251 dprintk("%s NFS4.1 replay from cache\n", __func__);
Andy Adamsonabfabf82009-07-23 19:02:18 -04001252 status = op->status;
Andy Adamsonda3846a2009-04-03 08:28:22 +03001253 goto out;
1254 }
Al Viroa90b0612006-10-19 23:29:03 -07001255 if (op->status == nfserr_replay_me) {
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08001256 op->replay = &cstate->replay_owner->so_replay;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 nfsd4_encode_replay(resp, op);
1258 status = op->status = op->replay->rp_status;
1259 } else {
1260 nfsd4_encode_operation(resp, op);
1261 status = op->status;
1262 }
Benny Halevy04077172008-12-15 19:40:49 +02001263
1264 dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n",
1265 args->ops, args->opcnt, resp->opcnt, op->opnum,
1266 be32_to_cpu(status));
1267
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08001268 if (cstate->replay_owner) {
J. Bruce Fields5ec094c2011-08-30 17:02:48 -04001269 nfs4_unlock_state();
J.Bruce Fieldsa4f1706a92006-12-13 00:35:28 -08001270 cstate->replay_owner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 }
NeilBrown7e06b7f2005-06-23 22:03:13 -07001272 /* XXX Ugh, we need to get rid of this kind of special case: */
1273 if (op->opnum == OP_READ && op->u.read.rd_filp)
1274 fput(op->u.read.rd_filp);
Shankar Anande2b20952006-07-10 04:45:44 -07001275
1276 nfsd4_increment_op_stats(op->opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
1278
Andy Adamsonda3846a2009-04-03 08:28:22 +03001279 resp->cstate.status = status;
Andy Adamsone354d572009-03-28 11:30:52 +03001280 fh_put(&resp->cstate.current_fh);
1281 fh_put(&resp->cstate.save_fh);
1282 BUG_ON(resp->cstate.replay_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283out:
Andy Adamson2f425872009-04-03 08:27:32 +03001284 /* Reset deferral mechanism for RPC deferrals */
1285 rqstp->rq_usedeferral = 1;
J. Bruce Fields3b12cd92008-05-05 17:17:44 -04001286 dprintk("nfsv4 compound returned %d\n", ntohl(status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 return status;
1288}
1289
Mi Jinlong58e7b332011-08-28 18:18:56 +08001290#define op_encode_hdr_size (2)
1291#define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
1292#define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
1293#define op_encode_change_info_maxsz (5)
1294#define nfs4_fattr_bitmap_maxsz (4)
1295
1296#define op_encode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1297#define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
1298
1299#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
1300
1301#define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
1302#define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
1303 op_encode_ace_maxsz)
1304
1305#define op_encode_channel_attrs_maxsz (6 + 1 + 1)
1306
1307static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1308{
1309 return (op_encode_hdr_size) * sizeof(__be32);
1310}
1311
1312static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1313{
1314 return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
1315}
1316
1317static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1318{
1319 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
1320}
1321
1322static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1323{
1324 return (op_encode_hdr_size + op_encode_change_info_maxsz
1325 + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
1326}
1327
1328static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1329{
1330 return (op_encode_hdr_size + op_encode_change_info_maxsz)
1331 * sizeof(__be32);
1332}
1333
1334static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1335{
1336 return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
1337 * sizeof(__be32);
1338}
1339
1340static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1341{
1342 return (op_encode_hdr_size + op_encode_stateid_maxsz
1343 + op_encode_change_info_maxsz + 1
1344 + nfs4_fattr_bitmap_maxsz
1345 + op_encode_delegation_maxsz) * sizeof(__be32);
1346}
1347
1348static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1349{
1350 u32 maxcount = 0, rlen = 0;
1351
1352 maxcount = svc_max_payload(rqstp);
1353 rlen = op->u.read.rd_length;
1354
1355 if (rlen > maxcount)
1356 rlen = maxcount;
1357
1358 return (op_encode_hdr_size + 2) * sizeof(__be32) + rlen;
1359}
1360
1361static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1362{
1363 u32 rlen = op->u.readdir.rd_maxcount;
1364
1365 if (rlen > PAGE_SIZE)
1366 rlen = PAGE_SIZE;
1367
1368 return (op_encode_hdr_size + op_encode_verifier_maxsz)
1369 * sizeof(__be32) + rlen;
1370}
1371
1372static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1373{
1374 return (op_encode_hdr_size + op_encode_change_info_maxsz)
1375 * sizeof(__be32);
1376}
1377
1378static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1379{
1380 return (op_encode_hdr_size + op_encode_change_info_maxsz
1381 + op_encode_change_info_maxsz) * sizeof(__be32);
1382}
1383
1384static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1385{
1386 return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
1387}
1388
1389static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1390{
1391 return (op_encode_hdr_size + 2 + 1024) * sizeof(__be32);
1392}
1393
1394static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1395{
1396 return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
1397}
1398
1399static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1400{
1401 return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
1402 1 + 1 + 0 + /* eir_flags, spr_how, SP4_NONE (for now) */\
1403 2 + /*eir_server_owner.so_minor_id */\
1404 /* eir_server_owner.so_major_id<> */\
1405 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
1406 /* eir_server_scope<> */\
1407 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
1408 1 + /* eir_server_impl_id array length */\
1409 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
1410}
1411
1412static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1413{
1414 return (op_encode_hdr_size + \
1415 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
1416 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
1417}
1418
1419static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
1420{
1421 return (op_encode_hdr_size + \
1422 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
1423 2 + /* csr_sequence, csr_flags */\
1424 op_encode_channel_attrs_maxsz + \
1425 op_encode_channel_attrs_maxsz) * sizeof(__be32);
1426}
1427
Benny Halevy20766012009-03-28 11:32:05 +03001428static struct nfsd4_operation nfsd4_ops[] = {
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001429 [OP_ACCESS] = {
1430 .op_func = (nfsd4op_func)nfsd4_access,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001431 .op_name = "OP_ACCESS",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001432 },
1433 [OP_CLOSE] = {
1434 .op_func = (nfsd4op_func)nfsd4_close,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001435 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001436 .op_name = "OP_CLOSE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001437 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001438 .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid,
1439 .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001440 },
1441 [OP_COMMIT] = {
1442 .op_func = (nfsd4op_func)nfsd4_commit,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001443 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001444 .op_name = "OP_COMMIT",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001445 .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001446 },
1447 [OP_CREATE] = {
1448 .op_func = (nfsd4op_func)nfsd4_create,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01001449 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001450 .op_name = "OP_CREATE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001451 .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001452 },
1453 [OP_DELEGRETURN] = {
1454 .op_func = (nfsd4op_func)nfsd4_delegreturn,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001455 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001456 .op_name = "OP_DELEGRETURN",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001457 .op_rsize_bop = nfsd4_only_status_rsize,
Tigran Mkrtchyan9428fe12012-02-13 22:55:31 +01001458 .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001459 },
1460 [OP_GETATTR] = {
1461 .op_func = (nfsd4op_func)nfsd4_getattr,
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001462 .op_flags = ALLOWED_ON_ABSENT_FS,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001463 .op_name = "OP_GETATTR",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001464 },
1465 [OP_GETFH] = {
1466 .op_func = (nfsd4op_func)nfsd4_getfh,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001467 .op_name = "OP_GETFH",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001468 },
1469 [OP_LINK] = {
1470 .op_func = (nfsd4op_func)nfsd4_link,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001471 .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
1472 | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001473 .op_name = "OP_LINK",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001474 .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001475 },
1476 [OP_LOCK] = {
1477 .op_func = (nfsd4op_func)nfsd4_lock,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001478 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001479 .op_name = "OP_LOCK",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001480 .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize,
Tigran Mkrtchyan62cd4a52012-02-13 22:55:25 +01001481 .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001482 },
1483 [OP_LOCKT] = {
1484 .op_func = (nfsd4op_func)nfsd4_lockt,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001485 .op_name = "OP_LOCKT",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001486 },
1487 [OP_LOCKU] = {
1488 .op_func = (nfsd4op_func)nfsd4_locku,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001489 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001490 .op_name = "OP_LOCKU",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001491 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
Tigran Mkrtchyan62cd4a52012-02-13 22:55:25 +01001492 .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001493 },
1494 [OP_LOOKUP] = {
1495 .op_func = (nfsd4op_func)nfsd4_lookup,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01001496 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001497 .op_name = "OP_LOOKUP",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001498 },
1499 [OP_LOOKUPP] = {
1500 .op_func = (nfsd4op_func)nfsd4_lookupp,
Tigran Mkrtchyand1471052012-02-13 22:55:29 +01001501 .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001502 .op_name = "OP_LOOKUPP",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001503 },
1504 [OP_NVERIFY] = {
1505 .op_func = (nfsd4op_func)nfsd4_nverify,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001506 .op_name = "OP_NVERIFY",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001507 },
1508 [OP_OPEN] = {
1509 .op_func = (nfsd4op_func)nfsd4_open,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001510 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001511 .op_name = "OP_OPEN",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001512 .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize,
Tigran Mkrtchyan8b704842012-02-13 22:55:24 +01001513 .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001514 },
1515 [OP_OPEN_CONFIRM] = {
1516 .op_func = (nfsd4op_func)nfsd4_open_confirm,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001517 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001518 .op_name = "OP_OPEN_CONFIRM",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001519 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001520 },
1521 [OP_OPEN_DOWNGRADE] = {
1522 .op_func = (nfsd4op_func)nfsd4_open_downgrade,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001523 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001524 .op_name = "OP_OPEN_DOWNGRADE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001525 .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize,
Tigran Mkrtchyan9428fe12012-02-13 22:55:31 +01001526 .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid,
1527 .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001528 },
1529 [OP_PUTFH] = {
1530 .op_func = (nfsd4op_func)nfsd4_putfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001531 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Tigran Mkrtchyan80e01cc2012-02-13 22:55:27 +01001532 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING
1533 | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001534 .op_name = "OP_PUTFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001535 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001536 },
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001537 [OP_PUTPUBFH] = {
J. Bruce Fieldsa1c8c4d2009-03-09 12:17:29 -04001538 .op_func = (nfsd4op_func)nfsd4_putrootfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001539 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Tigran Mkrtchyan80e01cc2012-02-13 22:55:27 +01001540 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING
1541 | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001542 .op_name = "OP_PUTPUBFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001543 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldseeac2942006-12-13 00:35:39 -08001544 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001545 [OP_PUTROOTFH] = {
1546 .op_func = (nfsd4op_func)nfsd4_putrootfh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001547 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Tigran Mkrtchyan80e01cc2012-02-13 22:55:27 +01001548 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING
1549 | OP_CLEAR_STATEID,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001550 .op_name = "OP_PUTROOTFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001551 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001552 },
1553 [OP_READ] = {
1554 .op_func = (nfsd4op_func)nfsd4_read,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001555 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001556 .op_name = "OP_READ",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001557 .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize,
Tigran Mkrtchyan30813e22012-02-13 22:55:26 +01001558 .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001559 },
1560 [OP_READDIR] = {
1561 .op_func = (nfsd4op_func)nfsd4_readdir,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001562 .op_flags = OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001563 .op_name = "OP_READDIR",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001564 .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001565 },
1566 [OP_READLINK] = {
1567 .op_func = (nfsd4op_func)nfsd4_readlink,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001568 .op_name = "OP_READLINK",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001569 },
1570 [OP_REMOVE] = {
1571 .op_func = (nfsd4op_func)nfsd4_remove,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001572 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001573 .op_name = "OP_REMOVE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001574 .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001575 },
1576 [OP_RENAME] = {
1577 .op_func = (nfsd4op_func)nfsd4_rename,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001578 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001579 .op_name = "OP_RENAME",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001580 .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001581 },
1582 [OP_RENEW] = {
1583 .op_func = (nfsd4op_func)nfsd4_renew,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001584 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
1585 | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001586 .op_name = "OP_RENEW",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001587 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
1588
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001589 },
1590 [OP_RESTOREFH] = {
1591 .op_func = (nfsd4op_func)nfsd4_restorefh,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001592 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
Mi Jinlong58e7b332011-08-28 18:18:56 +08001593 | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001594 .op_name = "OP_RESTOREFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001595 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001596 },
1597 [OP_SAVEFH] = {
1598 .op_func = (nfsd4op_func)nfsd4_savefh,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001599 .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001600 .op_name = "OP_SAVEFH",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001601 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001602 },
Andy Adamsondcb488a32007-07-17 04:04:51 -07001603 [OP_SECINFO] = {
1604 .op_func = (nfsd4op_func)nfsd4_secinfo,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001605 .op_flags = OP_HANDLES_WRONGSEC,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001606 .op_name = "OP_SECINFO",
Andy Adamsondcb488a32007-07-17 04:04:51 -07001607 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001608 [OP_SETATTR] = {
1609 .op_func = (nfsd4op_func)nfsd4_setattr,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001610 .op_name = "OP_SETATTR",
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001611 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001612 .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize,
Tigran Mkrtchyan1e97b512012-02-13 22:55:30 +01001613 .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001614 },
1615 [OP_SETCLIENTID] = {
1616 .op_func = (nfsd4op_func)nfsd4_setclientid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001617 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001618 | OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001619 .op_name = "OP_SETCLIENTID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001620 .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001621 },
1622 [OP_SETCLIENTID_CONFIRM] = {
1623 .op_func = (nfsd4op_func)nfsd4_setclientid_confirm,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001624 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001625 | OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001626 .op_name = "OP_SETCLIENTID_CONFIRM",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001627 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001628 },
1629 [OP_VERIFY] = {
1630 .op_func = (nfsd4op_func)nfsd4_verify,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001631 .op_name = "OP_VERIFY",
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001632 },
1633 [OP_WRITE] = {
1634 .op_func = (nfsd4op_func)nfsd4_write,
J. Bruce Fieldsc8566942011-09-20 08:49:51 -04001635 .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001636 .op_name = "OP_WRITE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001637 .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
Tigran Mkrtchyan30813e22012-02-13 22:55:26 +01001638 .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001639 },
1640 [OP_RELEASE_LOCKOWNER] = {
1641 .op_func = (nfsd4op_func)nfsd4_release_lockowner,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001642 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
1643 | OP_MODIFIES_SOMETHING,
Benny Halevyb001a1b2008-07-02 11:15:03 +03001644 .op_name = "OP_RELEASE_LOCKOWNER",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001645 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001646 },
Andy Adamson069b6ad2009-04-03 08:27:58 +03001647
1648 /* NFSv4.1 operations */
1649 [OP_EXCHANGE_ID] = {
1650 .op_func = (nfsd4op_func)nfsd4_exchange_id,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001651 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1652 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001653 .op_name = "OP_EXCHANGE_ID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001654 .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001655 },
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001656 [OP_BIND_CONN_TO_SESSION] = {
1657 .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001658 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1659 | OP_MODIFIES_SOMETHING,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001660 .op_name = "OP_BIND_CONN_TO_SESSION",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001661 .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001662 },
Andy Adamson069b6ad2009-04-03 08:27:58 +03001663 [OP_CREATE_SESSION] = {
1664 .op_func = (nfsd4op_func)nfsd4_create_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001665 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1666 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001667 .op_name = "OP_CREATE_SESSION",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001668 .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001669 },
1670 [OP_DESTROY_SESSION] = {
1671 .op_func = (nfsd4op_func)nfsd4_destroy_session,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001672 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1673 | OP_MODIFIES_SOMETHING,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001674 .op_name = "OP_DESTROY_SESSION",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001675 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001676 },
1677 [OP_SEQUENCE] = {
1678 .op_func = (nfsd4op_func)nfsd4_sequence,
Andy Adamsonf9bb94c2009-04-03 08:28:12 +03001679 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
Andy Adamson069b6ad2009-04-03 08:27:58 +03001680 .op_name = "OP_SEQUENCE",
1681 },
Benny Halevy094b5d72011-06-16 11:39:10 -04001682 [OP_DESTROY_CLIENTID] = {
Mi Jinlong345c2842011-10-20 17:51:39 +08001683 .op_func = (nfsd4op_func)nfsd4_destroy_clientid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001684 .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
1685 | OP_MODIFIES_SOMETHING,
Benny Halevy094b5d72011-06-16 11:39:10 -04001686 .op_name = "OP_DESTROY_CLIENTID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001687 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
Benny Halevy094b5d72011-06-16 11:39:10 -04001688 },
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001689 [OP_RECLAIM_COMPLETE] = {
1690 .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001691 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001692 .op_name = "OP_RECLAIM_COMPLETE",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001693 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001694 },
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001695 [OP_SECINFO_NO_NAME] = {
1696 .op_func = (nfsd4op_func)nfsd4_secinfo_no_name,
J. Bruce Fields68d93182011-04-08 17:00:50 -04001697 .op_flags = OP_HANDLES_WRONGSEC,
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001698 .op_name = "OP_SECINFO_NO_NAME",
1699 },
Bryan Schumaker17456802011-07-13 10:50:48 -04001700 [OP_TEST_STATEID] = {
1701 .op_func = (nfsd4op_func)nfsd4_test_stateid,
1702 .op_flags = ALLOWED_WITHOUT_FH,
1703 .op_name = "OP_TEST_STATEID",
1704 },
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001705 [OP_FREE_STATEID] = {
1706 .op_func = (nfsd4op_func)nfsd4_free_stateid,
Mi Jinlong58e7b332011-08-28 18:18:56 +08001707 .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001708 .op_name = "OP_FREE_STATEID",
Mi Jinlong58e7b332011-08-28 18:18:56 +08001709 .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001710 },
J.Bruce Fieldsb5914802006-12-13 00:35:38 -08001711};
1712
Adrian Bunkf1c7f792008-08-08 19:26:42 +03001713static const char *nfsd4_op_name(unsigned opnum)
Benny Halevyb001a1b2008-07-02 11:15:03 +03001714{
1715 if (opnum < ARRAY_SIZE(nfsd4_ops))
1716 return nfsd4_ops[opnum].op_name;
1717 return "unknown_operation";
1718}
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720#define nfsd4_voidres nfsd4_voidargs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721struct nfsd4_voidargs { int dummy; };
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723static struct svc_procedure nfsd_procedures4[2] = {
Yu Zhiguo0a93a472009-05-19 14:09:54 +08001724 [NFSPROC4_NULL] = {
1725 .pc_func = (svc_procfunc) nfsd4_proc_null,
1726 .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres,
1727 .pc_argsize = sizeof(struct nfsd4_voidargs),
1728 .pc_ressize = sizeof(struct nfsd4_voidres),
1729 .pc_cachetype = RC_NOCACHE,
1730 .pc_xdrressize = 1,
1731 },
1732 [NFSPROC4_COMPOUND] = {
1733 .pc_func = (svc_procfunc) nfsd4_proc_compound,
1734 .pc_decode = (kxdrproc_t) nfs4svc_decode_compoundargs,
1735 .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres,
1736 .pc_argsize = sizeof(struct nfsd4_compoundargs),
1737 .pc_ressize = sizeof(struct nfsd4_compoundres),
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04001738 .pc_release = nfsd4_release_compoundargs,
Yu Zhiguo0a93a472009-05-19 14:09:54 +08001739 .pc_cachetype = RC_NOCACHE,
1740 .pc_xdrressize = NFSD_BUFSIZE/4,
1741 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742};
1743
1744struct svc_version nfsd_version4 = {
1745 .vs_vers = 4,
1746 .vs_nproc = 2,
1747 .vs_proc = nfsd_procedures4,
1748 .vs_dispatch = nfsd_dispatch,
1749 .vs_xdrsize = NFS4_SVC_XDRSIZE,
1750};
1751
1752/*
1753 * Local variables:
1754 * c-basic-offset: 8
1755 * End:
1756 */