]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * 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. | |
1da177e4 | 34 | */ |
7e06b7f9 | 35 | #include <linux/file.h> |
b0cb9085 | 36 | #include <linux/falloc.h> |
5a0e3ad6 | 37 | #include <linux/slab.h> |
1da177e4 | 38 | |
58e7b33a | 39 | #include "idmap.h" |
9a74af21 BH |
40 | #include "cache.h" |
41 | #include "xdr4.h" | |
0a3adade | 42 | #include "vfs.h" |
8b70484c | 43 | #include "current_stateid.h" |
3320fef1 | 44 | #include "netns.h" |
4ac7249e | 45 | #include "acl.h" |
9cf514cc | 46 | #include "pnfs.h" |
31ef83dc | 47 | #include "trace.h" |
1da177e4 | 48 | |
18032ca0 DQ |
49 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
50 | #include <linux/security.h> | |
51 | ||
52 | static inline void | |
53 | nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) | |
54 | { | |
2b0143b5 | 55 | struct inode *inode = d_inode(resfh->fh_dentry); |
18032ca0 DQ |
56 | int status; |
57 | ||
5955102c | 58 | inode_lock(inode); |
18032ca0 DQ |
59 | status = security_inode_setsecctx(resfh->fh_dentry, |
60 | label->data, label->len); | |
5955102c | 61 | inode_unlock(inode); |
18032ca0 DQ |
62 | |
63 | if (status) | |
64 | /* | |
65 | * XXX: We should really fail the whole open, but we may | |
66 | * already have created a new file, so it may be too | |
67 | * late. For now this seems the least of evils: | |
68 | */ | |
69 | bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; | |
70 | ||
71 | return; | |
72 | } | |
73 | #else | |
74 | static inline void | |
75 | nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval) | |
76 | { } | |
77 | #endif | |
78 | ||
1da177e4 LT |
79 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
80 | ||
3c8e0316 YZ |
81 | static u32 nfsd_attrmask[] = { |
82 | NFSD_WRITEABLE_ATTRS_WORD0, | |
83 | NFSD_WRITEABLE_ATTRS_WORD1, | |
84 | NFSD_WRITEABLE_ATTRS_WORD2 | |
85 | }; | |
86 | ||
87 | static u32 nfsd41_ex_attrmask[] = { | |
88 | NFSD_SUPPATTR_EXCLCREAT_WORD0, | |
89 | NFSD_SUPPATTR_EXCLCREAT_WORD1, | |
90 | NFSD_SUPPATTR_EXCLCREAT_WORD2 | |
91 | }; | |
92 | ||
93 | static __be32 | |
94 | check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
95 | u32 *bmval, u32 *writable) | |
96 | { | |
97 | struct dentry *dentry = cstate->current_fh.fh_dentry; | |
32ddd944 | 98 | struct svc_export *exp = cstate->current_fh.fh_export; |
3c8e0316 | 99 | |
916d2d84 | 100 | if (!nfsd_attrs_supported(cstate->minorversion, bmval)) |
3c8e0316 | 101 | return nfserr_attrnotsupp; |
916d2d84 BF |
102 | if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry))) |
103 | return nfserr_attrnotsupp; | |
32ddd944 BF |
104 | if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) && |
105 | !(exp->ex_flags & NFSEXP_SECURITY_LABEL)) | |
106 | return nfserr_attrnotsupp; | |
916d2d84 BF |
107 | if (writable && !bmval_is_subset(bmval, writable)) |
108 | return nfserr_inval; | |
47057abd AG |
109 | if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) && |
110 | (bmval[1] & FATTR4_WORD1_MODE)) | |
111 | return nfserr_inval; | |
3c8e0316 YZ |
112 | return nfs_ok; |
113 | } | |
114 | ||
115 | static __be32 | |
116 | nfsd4_check_open_attributes(struct svc_rqst *rqstp, | |
117 | struct nfsd4_compound_state *cstate, struct nfsd4_open *open) | |
118 | { | |
119 | __be32 status = nfs_ok; | |
120 | ||
121 | if (open->op_create == NFS4_OPEN_CREATE) { | |
122 | if (open->op_createmode == NFS4_CREATE_UNCHECKED | |
123 | || open->op_createmode == NFS4_CREATE_GUARDED) | |
124 | status = check_attr_support(rqstp, cstate, | |
125 | open->op_bmval, nfsd_attrmask); | |
126 | else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1) | |
127 | status = check_attr_support(rqstp, cstate, | |
128 | open->op_bmval, nfsd41_ex_attrmask); | |
129 | } | |
130 | ||
131 | return status; | |
132 | } | |
133 | ||
9208faf2 YZ |
134 | static int |
135 | is_create_with_attrs(struct nfsd4_open *open) | |
136 | { | |
137 | return open->op_create == NFS4_OPEN_CREATE | |
138 | && (open->op_createmode == NFS4_CREATE_UNCHECKED | |
139 | || open->op_createmode == NFS4_CREATE_GUARDED | |
140 | || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1); | |
141 | } | |
142 | ||
143 | /* | |
144 | * if error occurs when setting the acl, just clear the acl bit | |
145 | * in the returned attr bitmap. | |
146 | */ | |
147 | static void | |
148 | do_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp, | |
149 | struct nfs4_acl *acl, u32 *bmval) | |
150 | { | |
151 | __be32 status; | |
152 | ||
153 | status = nfsd4_set_nfs4_acl(rqstp, fhp, acl); | |
154 | if (status) | |
155 | /* | |
156 | * We should probably fail the whole open at this point, | |
157 | * but we've already created the file, so it's too late; | |
158 | * So this seems the least of evils: | |
159 | */ | |
160 | bmval[0] &= ~FATTR4_WORD0_ACL; | |
161 | } | |
162 | ||
1da177e4 LT |
163 | static inline void |
164 | fh_dup2(struct svc_fh *dst, struct svc_fh *src) | |
165 | { | |
166 | fh_put(dst); | |
167 | dget(src->fh_dentry); | |
168 | if (src->fh_export) | |
bf18f163 | 169 | exp_get(src->fh_export); |
1da177e4 LT |
170 | *dst = *src; |
171 | } | |
172 | ||
b37ad28b | 173 | static __be32 |
dc730e17 | 174 | do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) |
1da177e4 | 175 | { |
b37ad28b | 176 | __be32 status; |
1da177e4 LT |
177 | |
178 | if (open->op_truncate && | |
179 | !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) | |
180 | return nfserr_inval; | |
181 | ||
a043226b BF |
182 | accmode |= NFSD_MAY_READ_IF_EXEC; |
183 | ||
1da177e4 | 184 | if (open->op_share_access & NFS4_SHARE_ACCESS_READ) |
8837abca | 185 | accmode |= NFSD_MAY_READ; |
9801d8a3 | 186 | if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) |
8837abca | 187 | accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); |
57ecb34f | 188 | if (open->op_share_deny & NFS4_SHARE_DENY_READ) |
8837abca | 189 | accmode |= NFSD_MAY_WRITE; |
1da177e4 LT |
190 | |
191 | status = fh_verify(rqstp, current_fh, S_IFREG, accmode); | |
192 | ||
193 | return status; | |
194 | } | |
195 | ||
aadab6c6 BF |
196 | static __be32 nfsd_check_obj_isreg(struct svc_fh *fh) |
197 | { | |
2b0143b5 | 198 | umode_t mode = d_inode(fh->fh_dentry)->i_mode; |
aadab6c6 BF |
199 | |
200 | if (S_ISREG(mode)) | |
201 | return nfs_ok; | |
202 | if (S_ISDIR(mode)) | |
203 | return nfserr_isdir; | |
204 | /* | |
205 | * Using err_symlink as our catch-all case may look odd; but | |
206 | * there's no other obvious error for this case in 4.0, and we | |
207 | * happen to know that it will cause the linux v4 client to do | |
208 | * the right thing on attempts to open something other than a | |
209 | * regular file. | |
210 | */ | |
211 | return nfserr_symlink; | |
212 | } | |
213 | ||
bbc9c36c BF |
214 | static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh) |
215 | { | |
216 | if (nfsd4_has_session(cstate)) | |
217 | return; | |
218 | fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh, | |
219 | &resfh->fh_handle); | |
220 | } | |
221 | ||
b37ad28b | 222 | static __be32 |
c0e6bee4 | 223 | do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh) |
1da177e4 | 224 | { |
bbc9c36c | 225 | struct svc_fh *current_fh = &cstate->current_fh; |
7007c90f | 226 | int accmode; |
b37ad28b | 227 | __be32 status; |
1da177e4 | 228 | |
c0e6bee4 BF |
229 | *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
230 | if (!*resfh) | |
59deeb9e | 231 | return nfserr_jukebox; |
c0e6bee4 | 232 | fh_init(*resfh, NFS4_FHSIZE); |
1da177e4 LT |
233 | open->op_truncate = 0; |
234 | ||
235 | if (open->op_create) { | |
79fb54ab BH |
236 | /* FIXME: check session persistence and pnfs flags. |
237 | * The nfsv4.1 spec requires the following semantics: | |
238 | * | |
239 | * Persistent | pNFS | Server REQUIRED | Client Allowed | |
240 | * Reply Cache | server | | | |
241 | * -------------+--------+-----------------+-------------------- | |
242 | * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1 | |
243 | * | | | (SHOULD) | |
244 | * | | and EXCLUSIVE4 | or EXCLUSIVE4 | |
245 | * | | | (SHOULD NOT) | |
246 | * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1 | |
247 | * yes | no | GUARDED4 | GUARDED4 | |
248 | * yes | yes | GUARDED4 | GUARDED4 | |
249 | */ | |
250 | ||
1da177e4 LT |
251 | /* |
252 | * Note: create modes (UNCHECKED,GUARDED...) are the same | |
ac6721a1 | 253 | * in NFSv4 as in v3 except EXCLUSIVE4_1. |
1da177e4 | 254 | */ |
ac6721a1 | 255 | status = do_nfsd_create(rqstp, current_fh, open->op_fname.data, |
1da177e4 | 256 | open->op_fname.len, &open->op_iattr, |
c0e6bee4 | 257 | *resfh, open->op_createmode, |
749997e5 | 258 | (u32 *)open->op_verf.data, |
856121b2 | 259 | &open->op_truncate, &open->op_created); |
749997e5 | 260 | |
18032ca0 | 261 | if (!status && open->op_label.len) |
c0e6bee4 | 262 | nfsd4_security_inode_setsecctx(*resfh, &open->op_label, open->op_bmval); |
18032ca0 | 263 | |
99f88726 | 264 | /* |
ead8fb8c KM |
265 | * Following rfc 3530 14.2.16, and rfc 5661 18.16.4 |
266 | * use the returned bitmask to indicate which attributes | |
267 | * we used to store the verifier: | |
749997e5 | 268 | */ |
ead8fb8c KM |
269 | if (nfsd_create_is_exclusive(open->op_createmode) && status == 0) |
270 | open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | | |
271 | FATTR4_WORD1_TIME_MODIFY); | |
4335723e BF |
272 | } else |
273 | /* | |
274 | * Note this may exit with the parent still locked. | |
275 | * We will hold the lock until nfsd4_open's final | |
276 | * lookup, to prevent renames or unlinks until we've had | |
277 | * a chance to an acquire a delegation if appropriate. | |
278 | */ | |
1da177e4 | 279 | status = nfsd_lookup(rqstp, current_fh, |
c0e6bee4 | 280 | open->op_fname.data, open->op_fname.len, *resfh); |
9dc4e6c4 BF |
281 | if (status) |
282 | goto out; | |
c0e6bee4 | 283 | status = nfsd_check_obj_isreg(*resfh); |
af85852d BF |
284 | if (status) |
285 | goto out; | |
1da177e4 | 286 | |
9208faf2 | 287 | if (is_create_with_attrs(open) && open->op_acl != NULL) |
c0e6bee4 | 288 | do_set_nfs4_acl(rqstp, *resfh, open->op_acl, open->op_bmval); |
9208faf2 | 289 | |
c0e6bee4 | 290 | nfsd4_set_open_owner_reply_cache(cstate, open, *resfh); |
7007c90f | 291 | accmode = NFSD_MAY_NOP; |
89f6c336 BF |
292 | if (open->op_created || |
293 | open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR) | |
7007c90f | 294 | accmode |= NFSD_MAY_OWNER_OVERRIDE; |
c0e6bee4 | 295 | status = do_open_permission(rqstp, *resfh, open, accmode); |
41fd1e42 | 296 | set_change_info(&open->op_cinfo, current_fh); |
af85852d | 297 | out: |
1da177e4 LT |
298 | return status; |
299 | } | |
300 | ||
b37ad28b | 301 | static __be32 |
bbc9c36c | 302 | do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open) |
1da177e4 | 303 | { |
bbc9c36c | 304 | struct svc_fh *current_fh = &cstate->current_fh; |
b37ad28b | 305 | __be32 status; |
9f415eb2 | 306 | int accmode = 0; |
1da177e4 | 307 | |
1da177e4 LT |
308 | /* We don't know the target directory, and therefore can not |
309 | * set the change info | |
310 | */ | |
311 | ||
312 | memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); | |
313 | ||
bbc9c36c | 314 | nfsd4_set_open_owner_reply_cache(cstate, open, current_fh); |
1da177e4 LT |
315 | |
316 | open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && | |
317 | (open->op_iattr.ia_size == 0); | |
9f415eb2 BF |
318 | /* |
319 | * In the delegation case, the client is telling us about an | |
320 | * open that it *already* performed locally, some time ago. We | |
321 | * should let it succeed now if possible. | |
322 | * | |
323 | * In the case of a CLAIM_FH open, on the other hand, the client | |
324 | * may be counting on us to enforce permissions (the Linux 4.1 | |
325 | * client uses this for normal opens, for example). | |
326 | */ | |
327 | if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH) | |
328 | accmode = NFSD_MAY_OWNER_OVERRIDE; | |
1da177e4 | 329 | |
9f415eb2 | 330 | status = do_open_permission(rqstp, current_fh, open, accmode); |
1da177e4 LT |
331 | |
332 | return status; | |
333 | } | |
334 | ||
60adfc50 AA |
335 | static void |
336 | copy_clientid(clientid_t *clid, struct nfsd4_session *session) | |
337 | { | |
338 | struct nfsd4_sessionid *sid = | |
339 | (struct nfsd4_sessionid *)session->se_sessionid.data; | |
340 | ||
341 | clid->cl_boot = sid->clientid.cl_boot; | |
342 | clid->cl_id = sid->clientid.cl_id; | |
343 | } | |
1da177e4 | 344 | |
7191155b | 345 | static __be32 |
ca364317 | 346 | nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
a4f1706a | 347 | struct nfsd4_open *open) |
1da177e4 | 348 | { |
b37ad28b | 349 | __be32 status; |
c0e6bee4 | 350 | struct svc_fh *resfh = NULL; |
3320fef1 SK |
351 | struct net *net = SVC_NET(rqstp); |
352 | struct nfsd_net *nn = net_generic(net, nfsd_net_id); | |
6668958f | 353 | |
fe0750e5 | 354 | dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n", |
1da177e4 | 355 | (int)open->op_fname.len, open->op_fname.data, |
fe0750e5 | 356 | open->op_openowner); |
1da177e4 | 357 | |
1da177e4 LT |
358 | /* This check required by spec. */ |
359 | if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) | |
360 | return nfserr_inval; | |
361 | ||
856121b2 | 362 | open->op_created = 0; |
ab1350b2 MJ |
363 | /* |
364 | * RFC5661 18.51.3 | |
365 | * Before RECLAIM_COMPLETE done, server should deny new lock | |
366 | */ | |
367 | if (nfsd4_has_session(cstate) && | |
a52d726b JL |
368 | !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, |
369 | &cstate->session->se_client->cl_flags) && | |
ab1350b2 MJ |
370 | open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) |
371 | return nfserr_grace; | |
372 | ||
60adfc50 AA |
373 | if (nfsd4_has_session(cstate)) |
374 | copy_clientid(&open->op_clientid, cstate->session); | |
375 | ||
1da177e4 | 376 | /* check seqid for replay. set nfs4_owner */ |
6cd22668 | 377 | status = nfsd4_process_open1(cstate, open, nn); |
a90b061c | 378 | if (status == nfserr_replay_me) { |
fe0750e5 | 379 | struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay; |
ca364317 | 380 | fh_put(&cstate->current_fh); |
a4773c08 BF |
381 | fh_copy_shallow(&cstate->current_fh.fh_handle, |
382 | &rp->rp_openfh); | |
8837abca | 383 | status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); |
1da177e4 LT |
384 | if (status) |
385 | dprintk("nfsd4_open: replay failed" | |
386 | " restoring previous filehandle\n"); | |
387 | else | |
a90b061c | 388 | status = nfserr_replay_me; |
1da177e4 LT |
389 | } |
390 | if (status) | |
391 | goto out; | |
9d313b17 BF |
392 | if (open->op_xdr_error) { |
393 | status = open->op_xdr_error; | |
394 | goto out; | |
395 | } | |
fb553c0f | 396 | |
3c8e0316 YZ |
397 | status = nfsd4_check_open_attributes(rqstp, cstate, open); |
398 | if (status) | |
399 | goto out; | |
400 | ||
fb553c0f BF |
401 | /* Openowner is now set, so sequence id will get bumped. Now we need |
402 | * these checks before we do any creates: */ | |
cbd0d51a | 403 | status = nfserr_grace; |
c87fb4a3 | 404 | if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) |
cbd0d51a BF |
405 | goto out; |
406 | status = nfserr_no_grace; | |
c87fb4a3 | 407 | if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) |
cbd0d51a | 408 | goto out; |
fb553c0f | 409 | |
1da177e4 | 410 | switch (open->op_claim_type) { |
0dd3c192 | 411 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
1da177e4 | 412 | case NFS4_OPEN_CLAIM_NULL: |
c0e6bee4 | 413 | status = do_open_lookup(rqstp, cstate, open, &resfh); |
1da177e4 LT |
414 | if (status) |
415 | goto out; | |
416 | break; | |
417 | case NFS4_OPEN_CLAIM_PREVIOUS: | |
3320fef1 | 418 | status = nfs4_check_open_reclaim(&open->op_clientid, |
0fe492db | 419 | cstate, nn); |
0cf99b91 MJ |
420 | if (status) |
421 | goto out; | |
ba5378b6 | 422 | open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED; |
8b289b2c BF |
423 | case NFS4_OPEN_CLAIM_FH: |
424 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: | |
bbc9c36c | 425 | status = do_open_fhandle(rqstp, cstate, open); |
1da177e4 LT |
426 | if (status) |
427 | goto out; | |
c0e6bee4 | 428 | resfh = &cstate->current_fh; |
1da177e4 | 429 | break; |
8b289b2c | 430 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
1da177e4 | 431 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
2fdada03 | 432 | dprintk("NFSD: unsupported OPEN claim type %d\n", |
1da177e4 LT |
433 | open->op_claim_type); |
434 | status = nfserr_notsupp; | |
435 | goto out; | |
436 | default: | |
2fdada03 | 437 | dprintk("NFSD: Invalid OPEN claim type %d\n", |
1da177e4 LT |
438 | open->op_claim_type); |
439 | status = nfserr_inval; | |
440 | goto out; | |
441 | } | |
442 | /* | |
443 | * nfsd4_process_open2() does the actual opening of the file. If | |
444 | * successful, it (1) truncates the file if open->op_truncate was | |
445 | * set, (2) sets open->op_stateid, (3) sets open->op_delegation. | |
446 | */ | |
c0e6bee4 | 447 | status = nfsd4_process_open2(rqstp, resfh, open); |
b3fbfe0e JL |
448 | WARN(status && open->op_created, |
449 | "nfsd4_process_open2 failed to open newly-created file! status=%u\n", | |
450 | be32_to_cpu(status)); | |
1da177e4 | 451 | out: |
c0e6bee4 BF |
452 | if (resfh && resfh != &cstate->current_fh) { |
453 | fh_dup2(&cstate->current_fh, resfh); | |
454 | fh_put(resfh); | |
455 | kfree(resfh); | |
456 | } | |
42297899 | 457 | nfsd4_cleanup_open_state(cstate, open); |
9411b1d4 | 458 | nfsd4_bump_seqid(cstate, status); |
1da177e4 LT |
459 | return status; |
460 | } | |
461 | ||
9d313b17 BF |
462 | /* |
463 | * OPEN is the only seqid-mutating operation whose decoding can fail | |
464 | * with a seqid-mutating error (specifically, decoding of user names in | |
465 | * the attributes). Therefore we have to do some processing to look up | |
466 | * the stateowner so that we can bump the seqid. | |
467 | */ | |
468 | static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op) | |
469 | { | |
470 | struct nfsd4_open *open = (struct nfsd4_open *)&op->u; | |
471 | ||
472 | if (!seqid_mutating_err(ntohl(op->status))) | |
473 | return op->status; | |
474 | if (nfsd4_has_session(cstate)) | |
475 | return op->status; | |
476 | open->op_xdr_error = op->status; | |
477 | return nfsd4_open(rqstp, cstate, open); | |
478 | } | |
479 | ||
1da177e4 LT |
480 | /* |
481 | * filehandle-manipulating ops. | |
482 | */ | |
7191155b | 483 | static __be32 |
b591480b BF |
484 | nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
485 | struct svc_fh **getfh) | |
1da177e4 | 486 | { |
ca364317 | 487 | if (!cstate->current_fh.fh_dentry) |
1da177e4 LT |
488 | return nfserr_nofilehandle; |
489 | ||
ca364317 | 490 | *getfh = &cstate->current_fh; |
1da177e4 LT |
491 | return nfs_ok; |
492 | } | |
493 | ||
7191155b | 494 | static __be32 |
ca364317 BF |
495 | nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
496 | struct nfsd4_putfh *putfh) | |
1da177e4 | 497 | { |
ca364317 BF |
498 | fh_put(&cstate->current_fh); |
499 | cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; | |
500 | memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, | |
501 | putfh->pf_fhlen); | |
68d93184 | 502 | return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS); |
1da177e4 LT |
503 | } |
504 | ||
7191155b | 505 | static __be32 |
b591480b BF |
506 | nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
507 | void *arg) | |
1da177e4 | 508 | { |
b37ad28b | 509 | __be32 status; |
1da177e4 | 510 | |
ca364317 | 511 | fh_put(&cstate->current_fh); |
df547efb | 512 | status = exp_pseudoroot(rqstp, &cstate->current_fh); |
1da177e4 LT |
513 | return status; |
514 | } | |
515 | ||
7191155b | 516 | static __be32 |
b591480b BF |
517 | nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
518 | void *arg) | |
1da177e4 | 519 | { |
ca364317 | 520 | if (!cstate->save_fh.fh_dentry) |
1da177e4 LT |
521 | return nfserr_restorefh; |
522 | ||
ca364317 | 523 | fh_dup2(&cstate->current_fh, &cstate->save_fh); |
37c593c5 TM |
524 | if (HAS_STATE_ID(cstate, SAVED_STATE_ID_FLAG)) { |
525 | memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t)); | |
526 | SET_STATE_ID(cstate, CURRENT_STATE_ID_FLAG); | |
527 | } | |
1da177e4 LT |
528 | return nfs_ok; |
529 | } | |
530 | ||
7191155b | 531 | static __be32 |
b591480b BF |
532 | nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
533 | void *arg) | |
1da177e4 | 534 | { |
ca364317 | 535 | if (!cstate->current_fh.fh_dentry) |
1da177e4 LT |
536 | return nfserr_nofilehandle; |
537 | ||
ca364317 | 538 | fh_dup2(&cstate->save_fh, &cstate->current_fh); |
37c593c5 TM |
539 | if (HAS_STATE_ID(cstate, CURRENT_STATE_ID_FLAG)) { |
540 | memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t)); | |
541 | SET_STATE_ID(cstate, SAVED_STATE_ID_FLAG); | |
542 | } | |
1da177e4 LT |
543 | return nfs_ok; |
544 | } | |
545 | ||
546 | /* | |
547 | * misc nfsv4 ops | |
548 | */ | |
7191155b | 549 | static __be32 |
ca364317 BF |
550 | nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
551 | struct nfsd4_access *access) | |
1da177e4 LT |
552 | { |
553 | if (access->ac_req_access & ~NFS3_ACCESS_FULL) | |
554 | return nfserr_inval; | |
555 | ||
556 | access->ac_resp_access = access->ac_req_access; | |
ca364317 BF |
557 | return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, |
558 | &access->ac_supported); | |
1da177e4 LT |
559 | } |
560 | ||
b9c0ef85 | 561 | static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net) |
ab4684d1 CL |
562 | { |
563 | __be32 verf[2]; | |
b9c0ef85 | 564 | struct nfsd_net *nn = net_generic(net, nfsd_net_id); |
ab4684d1 | 565 | |
f419992c JL |
566 | /* |
567 | * This is opaque to client, so no need to byte-swap. Use | |
568 | * __force to keep sparse happy | |
569 | */ | |
570 | verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; | |
571 | verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec; | |
ab4684d1 CL |
572 | memcpy(verifier->data, verf, sizeof(verifier->data)); |
573 | } | |
574 | ||
7191155b | 575 | static __be32 |
ca364317 BF |
576 | nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
577 | struct nfsd4_commit *commit) | |
1da177e4 | 578 | { |
b9c0ef85 | 579 | gen_boot_verifier(&commit->co_verf, SVC_NET(rqstp)); |
75c096f7 | 580 | return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, |
ca364317 | 581 | commit->co_count); |
1da177e4 LT |
582 | } |
583 | ||
b37ad28b | 584 | static __be32 |
ca364317 BF |
585 | nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
586 | struct nfsd4_create *create) | |
1da177e4 LT |
587 | { |
588 | struct svc_fh resfh; | |
b37ad28b | 589 | __be32 status; |
1da177e4 LT |
590 | dev_t rdev; |
591 | ||
592 | fh_init(&resfh, NFS4_FHSIZE); | |
593 | ||
fa08139d | 594 | status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP); |
1da177e4 LT |
595 | if (status) |
596 | return status; | |
597 | ||
3c8e0316 YZ |
598 | status = check_attr_support(rqstp, cstate, create->cr_bmval, |
599 | nfsd_attrmask); | |
600 | if (status) | |
601 | return status; | |
602 | ||
1da177e4 LT |
603 | switch (create->cr_type) { |
604 | case NF4LNK: | |
ca364317 BF |
605 | status = nfsd_symlink(rqstp, &cstate->current_fh, |
606 | create->cr_name, create->cr_namelen, | |
1e444f5b | 607 | create->cr_data, &resfh); |
1da177e4 LT |
608 | break; |
609 | ||
610 | case NF4BLK: | |
611 | rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); | |
612 | if (MAJOR(rdev) != create->cr_specdata1 || | |
613 | MINOR(rdev) != create->cr_specdata2) | |
614 | return nfserr_inval; | |
ca364317 BF |
615 | status = nfsd_create(rqstp, &cstate->current_fh, |
616 | create->cr_name, create->cr_namelen, | |
617 | &create->cr_iattr, S_IFBLK, rdev, &resfh); | |
1da177e4 LT |
618 | break; |
619 | ||
620 | case NF4CHR: | |
621 | rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); | |
622 | if (MAJOR(rdev) != create->cr_specdata1 || | |
623 | MINOR(rdev) != create->cr_specdata2) | |
624 | return nfserr_inval; | |
ca364317 BF |
625 | status = nfsd_create(rqstp, &cstate->current_fh, |
626 | create->cr_name, create->cr_namelen, | |
627 | &create->cr_iattr,S_IFCHR, rdev, &resfh); | |
1da177e4 LT |
628 | break; |
629 | ||
630 | case NF4SOCK: | |
ca364317 BF |
631 | status = nfsd_create(rqstp, &cstate->current_fh, |
632 | create->cr_name, create->cr_namelen, | |
633 | &create->cr_iattr, S_IFSOCK, 0, &resfh); | |
1da177e4 LT |
634 | break; |
635 | ||
636 | case NF4FIFO: | |
ca364317 BF |
637 | status = nfsd_create(rqstp, &cstate->current_fh, |
638 | create->cr_name, create->cr_namelen, | |
639 | &create->cr_iattr, S_IFIFO, 0, &resfh); | |
1da177e4 LT |
640 | break; |
641 | ||
642 | case NF4DIR: | |
643 | create->cr_iattr.ia_valid &= ~ATTR_SIZE; | |
ca364317 BF |
644 | status = nfsd_create(rqstp, &cstate->current_fh, |
645 | create->cr_name, create->cr_namelen, | |
646 | &create->cr_iattr, S_IFDIR, 0, &resfh); | |
1da177e4 LT |
647 | break; |
648 | ||
649 | default: | |
650 | status = nfserr_badtype; | |
651 | } | |
652 | ||
9208faf2 YZ |
653 | if (status) |
654 | goto out; | |
1da177e4 | 655 | |
18032ca0 DQ |
656 | if (create->cr_label.len) |
657 | nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval); | |
658 | ||
9208faf2 YZ |
659 | if (create->cr_acl != NULL) |
660 | do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, | |
661 | create->cr_bmval); | |
662 | ||
663 | fh_unlock(&cstate->current_fh); | |
664 | set_change_info(&create->cr_cinfo, &cstate->current_fh); | |
665 | fh_dup2(&cstate->current_fh, &resfh); | |
666 | out: | |
1da177e4 LT |
667 | fh_put(&resfh); |
668 | return status; | |
669 | } | |
670 | ||
7191155b | 671 | static __be32 |
ca364317 BF |
672 | nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
673 | struct nfsd4_getattr *getattr) | |
1da177e4 | 674 | { |
b37ad28b | 675 | __be32 status; |
1da177e4 | 676 | |
8837abca | 677 | status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); |
1da177e4 LT |
678 | if (status) |
679 | return status; | |
680 | ||
681 | if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) | |
682 | return nfserr_inval; | |
683 | ||
916d2d84 BF |
684 | getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; |
685 | getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; | |
686 | getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; | |
1da177e4 | 687 | |
ca364317 | 688 | getattr->ga_fhp = &cstate->current_fh; |
1da177e4 LT |
689 | return nfs_ok; |
690 | } | |
691 | ||
7191155b | 692 | static __be32 |
ca364317 BF |
693 | nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
694 | struct nfsd4_link *link) | |
1da177e4 | 695 | { |
b37ad28b | 696 | __be32 status = nfserr_nofilehandle; |
1da177e4 | 697 | |
ca364317 | 698 | if (!cstate->save_fh.fh_dentry) |
1da177e4 | 699 | return status; |
ca364317 BF |
700 | status = nfsd_link(rqstp, &cstate->current_fh, |
701 | link->li_name, link->li_namelen, &cstate->save_fh); | |
1da177e4 | 702 | if (!status) |
ca364317 | 703 | set_change_info(&link->li_cinfo, &cstate->current_fh); |
1da177e4 LT |
704 | return status; |
705 | } | |
706 | ||
0ff7ab46 | 707 | static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh) |
1da177e4 LT |
708 | { |
709 | struct svc_fh tmp_fh; | |
b37ad28b | 710 | __be32 ret; |
1da177e4 LT |
711 | |
712 | fh_init(&tmp_fh, NFS4_FHSIZE); | |
df547efb BF |
713 | ret = exp_pseudoroot(rqstp, &tmp_fh); |
714 | if (ret) | |
1da177e4 | 715 | return ret; |
0ff7ab46 | 716 | if (tmp_fh.fh_dentry == fh->fh_dentry) { |
1da177e4 LT |
717 | fh_put(&tmp_fh); |
718 | return nfserr_noent; | |
719 | } | |
720 | fh_put(&tmp_fh); | |
0ff7ab46 BF |
721 | return nfsd_lookup(rqstp, fh, "..", 2, fh); |
722 | } | |
723 | ||
724 | static __be32 | |
725 | nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
726 | void *arg) | |
727 | { | |
728 | return nfsd4_do_lookupp(rqstp, &cstate->current_fh); | |
1da177e4 LT |
729 | } |
730 | ||
7191155b | 731 | static __be32 |
ca364317 BF |
732 | nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
733 | struct nfsd4_lookup *lookup) | |
1da177e4 | 734 | { |
ca364317 BF |
735 | return nfsd_lookup(rqstp, &cstate->current_fh, |
736 | lookup->lo_name, lookup->lo_len, | |
737 | &cstate->current_fh); | |
1da177e4 LT |
738 | } |
739 | ||
7191155b | 740 | static __be32 |
ca364317 BF |
741 | nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
742 | struct nfsd4_read *read) | |
1da177e4 | 743 | { |
b37ad28b | 744 | __be32 status; |
1da177e4 | 745 | |
7e06b7f9 | 746 | read->rd_filp = NULL; |
1da177e4 LT |
747 | if (read->rd_offset >= OFFSET_MAX) |
748 | return nfserr_inval; | |
749 | ||
9b3234b9 BF |
750 | /* |
751 | * If we do a zero copy read, then a client will see read data | |
752 | * that reflects the state of the file *after* performing the | |
753 | * following compound. | |
754 | * | |
755 | * To ensure proper ordering, we therefore turn off zero copy if | |
756 | * the client wants us to do more in this compound: | |
757 | */ | |
758 | if (!nfsd4_last_compound_op(rqstp)) | |
779fb0f3 | 759 | clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags); |
9b3234b9 | 760 | |
1da177e4 | 761 | /* check stateid */ |
aa0d6aed AS |
762 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
763 | &read->rd_stateid, RD_STATE, | |
764 | &read->rd_filp, &read->rd_tmp_file); | |
af90f707 | 765 | if (status) { |
1da177e4 LT |
766 | dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); |
767 | goto out; | |
768 | } | |
769 | status = nfs_ok; | |
770 | out: | |
1da177e4 | 771 | read->rd_rqstp = rqstp; |
ca364317 | 772 | read->rd_fhp = &cstate->current_fh; |
1da177e4 LT |
773 | return status; |
774 | } | |
775 | ||
7191155b | 776 | static __be32 |
ca364317 BF |
777 | nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
778 | struct nfsd4_readdir *readdir) | |
1da177e4 LT |
779 | { |
780 | u64 cookie = readdir->rd_cookie; | |
781 | static const nfs4_verifier zeroverf; | |
782 | ||
783 | /* no need to check permission - this will be done in nfsd_readdir() */ | |
784 | ||
785 | if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) | |
786 | return nfserr_inval; | |
787 | ||
916d2d84 BF |
788 | readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0]; |
789 | readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1]; | |
790 | readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2]; | |
1da177e4 | 791 | |
832023bf | 792 | if ((cookie == 1) || (cookie == 2) || |
1da177e4 LT |
793 | (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) |
794 | return nfserr_bad_cookie; | |
795 | ||
796 | readdir->rd_rqstp = rqstp; | |
ca364317 | 797 | readdir->rd_fhp = &cstate->current_fh; |
1da177e4 LT |
798 | return nfs_ok; |
799 | } | |
800 | ||
7191155b | 801 | static __be32 |
ca364317 BF |
802 | nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
803 | struct nfsd4_readlink *readlink) | |
1da177e4 LT |
804 | { |
805 | readlink->rl_rqstp = rqstp; | |
ca364317 | 806 | readlink->rl_fhp = &cstate->current_fh; |
1da177e4 LT |
807 | return nfs_ok; |
808 | } | |
809 | ||
7191155b | 810 | static __be32 |
ca364317 BF |
811 | nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
812 | struct nfsd4_remove *remove) | |
1da177e4 | 813 | { |
b37ad28b | 814 | __be32 status; |
1da177e4 | 815 | |
c87fb4a3 | 816 | if (opens_in_grace(SVC_NET(rqstp))) |
c815afc7 | 817 | return nfserr_grace; |
ca364317 BF |
818 | status = nfsd_unlink(rqstp, &cstate->current_fh, 0, |
819 | remove->rm_name, remove->rm_namelen); | |
1da177e4 | 820 | if (!status) { |
ca364317 BF |
821 | fh_unlock(&cstate->current_fh); |
822 | set_change_info(&remove->rm_cinfo, &cstate->current_fh); | |
1da177e4 LT |
823 | } |
824 | return status; | |
825 | } | |
826 | ||
7191155b | 827 | static __be32 |
ca364317 BF |
828 | nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
829 | struct nfsd4_rename *rename) | |
1da177e4 | 830 | { |
b37ad28b | 831 | __be32 status = nfserr_nofilehandle; |
1da177e4 | 832 | |
ca364317 | 833 | if (!cstate->save_fh.fh_dentry) |
1da177e4 | 834 | return status; |
c87fb4a3 | 835 | if (opens_in_grace(SVC_NET(rqstp)) && |
5ccb0066 | 836 | !(cstate->save_fh.fh_export->ex_flags & NFSEXP_NOSUBTREECHECK)) |
c815afc7 | 837 | return nfserr_grace; |
ca364317 BF |
838 | status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, |
839 | rename->rn_snamelen, &cstate->current_fh, | |
1da177e4 | 840 | rename->rn_tname, rename->rn_tnamelen); |
2a6cf944 BF |
841 | if (status) |
842 | return status; | |
843 | set_change_info(&rename->rn_sinfo, &cstate->current_fh); | |
844 | set_change_info(&rename->rn_tinfo, &cstate->save_fh); | |
845 | return nfs_ok; | |
1da177e4 LT |
846 | } |
847 | ||
dcb488a3 AA |
848 | static __be32 |
849 | nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
850 | struct nfsd4_secinfo *secinfo) | |
851 | { | |
dcb488a3 AA |
852 | struct svc_export *exp; |
853 | struct dentry *dentry; | |
854 | __be32 err; | |
855 | ||
29a78a3e BF |
856 | err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC); |
857 | if (err) | |
858 | return err; | |
dcb488a3 AA |
859 | err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, |
860 | secinfo->si_name, secinfo->si_namelen, | |
861 | &exp, &dentry); | |
862 | if (err) | |
863 | return err; | |
2f6fc056 | 864 | fh_unlock(&cstate->current_fh); |
2b0143b5 | 865 | if (d_really_is_negative(dentry)) { |
dcb488a3 AA |
866 | exp_put(exp); |
867 | err = nfserr_noent; | |
868 | } else | |
869 | secinfo->si_exp = exp; | |
870 | dput(dentry); | |
56560b9a BF |
871 | if (cstate->minorversion) |
872 | /* See rfc 5661 section 2.6.3.1.1.8 */ | |
873 | fh_put(&cstate->current_fh); | |
dcb488a3 AA |
874 | return err; |
875 | } | |
876 | ||
04f4ad16 BF |
877 | static __be32 |
878 | nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
879 | struct nfsd4_secinfo_no_name *sin) | |
880 | { | |
881 | __be32 err; | |
882 | ||
883 | switch (sin->sin_style) { | |
884 | case NFS4_SECINFO_STYLE4_CURRENT_FH: | |
885 | break; | |
886 | case NFS4_SECINFO_STYLE4_PARENT: | |
887 | err = nfsd4_do_lookupp(rqstp, &cstate->current_fh); | |
888 | if (err) | |
889 | return err; | |
890 | break; | |
891 | default: | |
892 | return nfserr_inval; | |
893 | } | |
bf18f163 KM |
894 | |
895 | sin->sin_exp = exp_get(cstate->current_fh.fh_export); | |
04f4ad16 BF |
896 | fh_put(&cstate->current_fh); |
897 | return nfs_ok; | |
898 | } | |
899 | ||
7191155b | 900 | static __be32 |
ca364317 BF |
901 | nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
902 | struct nfsd4_setattr *setattr) | |
1da177e4 | 903 | { |
b37ad28b | 904 | __be32 status = nfs_ok; |
96f6f985 | 905 | int err; |
1da177e4 | 906 | |
1da177e4 | 907 | if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { |
af90f707 | 908 | status = nfs4_preprocess_stateid_op(rqstp, cstate, |
aa0d6aed AS |
909 | &cstate->current_fh, &setattr->sa_stateid, |
910 | WR_STATE, NULL, NULL); | |
375c5547 | 911 | if (status) { |
3e3b4800 | 912 | dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); |
375c5547 BF |
913 | return status; |
914 | } | |
1da177e4 | 915 | } |
96f6f985 AV |
916 | err = fh_want_write(&cstate->current_fh); |
917 | if (err) | |
918 | return nfserrno(err); | |
1da177e4 | 919 | status = nfs_ok; |
3c8e0316 YZ |
920 | |
921 | status = check_attr_support(rqstp, cstate, setattr->sa_bmval, | |
922 | nfsd_attrmask); | |
923 | if (status) | |
924 | goto out; | |
925 | ||
1da177e4 | 926 | if (setattr->sa_acl != NULL) |
ca364317 BF |
927 | status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, |
928 | setattr->sa_acl); | |
1da177e4 | 929 | if (status) |
18f335af | 930 | goto out; |
18032ca0 DQ |
931 | if (setattr->sa_label.len) |
932 | status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh, | |
933 | &setattr->sa_label); | |
934 | if (status) | |
935 | goto out; | |
ca364317 | 936 | status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, |
1da177e4 | 937 | 0, (time_t)0); |
18f335af | 938 | out: |
bad0dcff | 939 | fh_drop_write(&cstate->current_fh); |
1da177e4 LT |
940 | return status; |
941 | } | |
942 | ||
ffe1137b BF |
943 | static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write) |
944 | { | |
945 | int i = 1; | |
946 | int buflen = write->wr_buflen; | |
947 | ||
948 | vec[0].iov_base = write->wr_head.iov_base; | |
949 | vec[0].iov_len = min_t(int, buflen, write->wr_head.iov_len); | |
950 | buflen -= vec[0].iov_len; | |
951 | ||
952 | while (buflen) { | |
953 | vec[i].iov_base = page_address(write->wr_pagelist[i - 1]); | |
954 | vec[i].iov_len = min_t(int, PAGE_SIZE, buflen); | |
955 | buflen -= vec[i].iov_len; | |
956 | i++; | |
957 | } | |
958 | return i; | |
959 | } | |
960 | ||
7191155b | 961 | static __be32 |
ca364317 BF |
962 | nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
963 | struct nfsd4_write *write) | |
1da177e4 LT |
964 | { |
965 | stateid_t *stateid = &write->wr_stateid; | |
966 | struct file *filp = NULL; | |
b37ad28b | 967 | __be32 status = nfs_ok; |
31dec253 | 968 | unsigned long cnt; |
ffe1137b | 969 | int nvecs; |
1da177e4 | 970 | |
1da177e4 LT |
971 | if (write->wr_offset >= OFFSET_MAX) |
972 | return nfserr_inval; | |
973 | ||
aa0d6aed AS |
974 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
975 | stateid, WR_STATE, &filp, NULL); | |
375c5547 BF |
976 | if (status) { |
977 | dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); | |
978 | return status; | |
979 | } | |
980 | ||
31dec253 | 981 | cnt = write->wr_buflen; |
1da177e4 | 982 | write->wr_how_written = write->wr_stable_how; |
b9c0ef85 | 983 | gen_boot_verifier(&write->wr_verifier, SVC_NET(rqstp)); |
1da177e4 | 984 | |
ffe1137b BF |
985 | nvecs = fill_in_write_vector(rqstp->rq_vec, write); |
986 | WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec)); | |
987 | ||
af90f707 CH |
988 | status = nfsd_vfs_write(rqstp, &cstate->current_fh, filp, |
989 | write->wr_offset, rqstp->rq_vec, nvecs, &cnt, | |
54bbb7d2 | 990 | write->wr_how_written); |
af90f707 | 991 | fput(filp); |
1da177e4 | 992 | |
31dec253 DS |
993 | write->wr_bytes_written = cnt; |
994 | ||
1da177e4 | 995 | return status; |
1da177e4 LT |
996 | } |
997 | ||
ffa0160a | 998 | static __be32 |
29ae7f9d AS |
999 | nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
1000 | stateid_t *src_stateid, struct file **src, | |
1001 | stateid_t *dst_stateid, struct file **dst) | |
ffa0160a | 1002 | { |
ffa0160a CH |
1003 | __be32 status; |
1004 | ||
1005 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh, | |
29ae7f9d | 1006 | src_stateid, RD_STATE, src, NULL); |
ffa0160a CH |
1007 | if (status) { |
1008 | dprintk("NFSD: %s: couldn't process src stateid!\n", __func__); | |
1009 | goto out; | |
1010 | } | |
1011 | ||
1012 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, | |
29ae7f9d | 1013 | dst_stateid, WR_STATE, dst, NULL); |
ffa0160a CH |
1014 | if (status) { |
1015 | dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__); | |
1016 | goto out_put_src; | |
1017 | } | |
1018 | ||
1019 | /* fix up for NFS-specific error code */ | |
29ae7f9d AS |
1020 | if (!S_ISREG(file_inode(*src)->i_mode) || |
1021 | !S_ISREG(file_inode(*dst)->i_mode)) { | |
ffa0160a CH |
1022 | status = nfserr_wrong_type; |
1023 | goto out_put_dst; | |
1024 | } | |
1025 | ||
29ae7f9d AS |
1026 | out: |
1027 | return status; | |
1028 | out_put_dst: | |
1029 | fput(*dst); | |
1030 | out_put_src: | |
1031 | fput(*src); | |
1032 | goto out; | |
1033 | } | |
1034 | ||
1035 | static __be32 | |
1036 | nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1037 | struct nfsd4_clone *clone) | |
1038 | { | |
1039 | struct file *src, *dst; | |
1040 | __be32 status; | |
1041 | ||
1042 | status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src, | |
1043 | &clone->cl_dst_stateid, &dst); | |
1044 | if (status) | |
1045 | goto out; | |
1046 | ||
ffa0160a CH |
1047 | status = nfsd4_clone_file_range(src, clone->cl_src_pos, |
1048 | dst, clone->cl_dst_pos, clone->cl_count); | |
1049 | ||
ffa0160a | 1050 | fput(dst); |
ffa0160a CH |
1051 | fput(src); |
1052 | out: | |
1053 | return status; | |
1054 | } | |
1055 | ||
29ae7f9d AS |
1056 | static __be32 |
1057 | nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1058 | struct nfsd4_copy *copy) | |
1059 | { | |
1060 | struct file *src, *dst; | |
1061 | __be32 status; | |
1062 | ssize_t bytes; | |
1063 | ||
1064 | status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid, &src, | |
1065 | ©->cp_dst_stateid, &dst); | |
1066 | if (status) | |
1067 | goto out; | |
1068 | ||
1069 | bytes = nfsd_copy_file_range(src, copy->cp_src_pos, | |
1070 | dst, copy->cp_dst_pos, copy->cp_count); | |
1071 | ||
1072 | if (bytes < 0) | |
1073 | status = nfserrno(bytes); | |
1074 | else { | |
1075 | copy->cp_res.wr_bytes_written = bytes; | |
1076 | copy->cp_res.wr_stable_how = NFS_UNSTABLE; | |
1077 | copy->cp_consecutive = 1; | |
1078 | copy->cp_synchronous = 1; | |
1079 | gen_boot_verifier(©->cp_res.wr_verifier, SVC_NET(rqstp)); | |
1080 | status = nfs_ok; | |
1081 | } | |
1082 | ||
1083 | fput(src); | |
1084 | fput(dst); | |
1085 | out: | |
1086 | return status; | |
1087 | } | |
1088 | ||
95d871f0 AS |
1089 | static __be32 |
1090 | nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1091 | struct nfsd4_fallocate *fallocate, int flags) | |
1092 | { | |
1093 | __be32 status = nfserr_notsupp; | |
1094 | struct file *file; | |
1095 | ||
aa0d6aed | 1096 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
95d871f0 | 1097 | &fallocate->falloc_stateid, |
af90f707 | 1098 | WR_STATE, &file, NULL); |
95d871f0 AS |
1099 | if (status != nfs_ok) { |
1100 | dprintk("NFSD: nfsd4_fallocate: couldn't process stateid!\n"); | |
1101 | return status; | |
1102 | } | |
1103 | ||
1104 | status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, file, | |
1105 | fallocate->falloc_offset, | |
1106 | fallocate->falloc_length, | |
1107 | flags); | |
1108 | fput(file); | |
1109 | return status; | |
1110 | } | |
1111 | ||
1112 | static __be32 | |
1113 | nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1114 | struct nfsd4_fallocate *fallocate) | |
1115 | { | |
1116 | return nfsd4_fallocate(rqstp, cstate, fallocate, 0); | |
1117 | } | |
1118 | ||
b0cb9085 AS |
1119 | static __be32 |
1120 | nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1121 | struct nfsd4_fallocate *fallocate) | |
1122 | { | |
1123 | return nfsd4_fallocate(rqstp, cstate, fallocate, | |
1124 | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); | |
1125 | } | |
1126 | ||
24bab491 AS |
1127 | static __be32 |
1128 | nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1129 | struct nfsd4_seek *seek) | |
1130 | { | |
1131 | int whence; | |
1132 | __be32 status; | |
1133 | struct file *file; | |
1134 | ||
aa0d6aed | 1135 | status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh, |
24bab491 | 1136 | &seek->seek_stateid, |
af90f707 | 1137 | RD_STATE, &file, NULL); |
24bab491 AS |
1138 | if (status) { |
1139 | dprintk("NFSD: nfsd4_seek: couldn't process stateid!\n"); | |
1140 | return status; | |
1141 | } | |
1142 | ||
1143 | switch (seek->seek_whence) { | |
1144 | case NFS4_CONTENT_DATA: | |
1145 | whence = SEEK_DATA; | |
1146 | break; | |
1147 | case NFS4_CONTENT_HOLE: | |
1148 | whence = SEEK_HOLE; | |
1149 | break; | |
1150 | default: | |
1151 | status = nfserr_union_notsupp; | |
1152 | goto out; | |
1153 | } | |
1154 | ||
1155 | /* | |
1156 | * Note: This call does change file->f_pos, but nothing in NFSD | |
1157 | * should ever file->f_pos. | |
1158 | */ | |
1159 | seek->seek_pos = vfs_llseek(file, seek->seek_offset, whence); | |
1160 | if (seek->seek_pos < 0) | |
1161 | status = nfserrno(seek->seek_pos); | |
1162 | else if (seek->seek_pos >= i_size_read(file_inode(file))) | |
1163 | seek->seek_eof = true; | |
1164 | ||
1165 | out: | |
1166 | fput(file); | |
1167 | return status; | |
1168 | } | |
1169 | ||
1da177e4 LT |
1170 | /* This routine never returns NFS_OK! If there are no other errors, it |
1171 | * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the | |
1172 | * attributes matched. VERIFY is implemented by mapping NFSERR_SAME | |
1173 | * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. | |
1174 | */ | |
b37ad28b | 1175 | static __be32 |
c954e2a5 | 1176 | _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
ca364317 | 1177 | struct nfsd4_verify *verify) |
1da177e4 | 1178 | { |
2ebbc012 | 1179 | __be32 *buf, *p; |
1da177e4 | 1180 | int count; |
b37ad28b | 1181 | __be32 status; |
1da177e4 | 1182 | |
8837abca | 1183 | status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); |
1da177e4 LT |
1184 | if (status) |
1185 | return status; | |
1186 | ||
3c8e0316 YZ |
1187 | status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL); |
1188 | if (status) | |
1189 | return status; | |
1190 | ||
1da177e4 LT |
1191 | if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) |
1192 | || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) | |
1193 | return nfserr_inval; | |
1194 | if (verify->ve_attrlen & 3) | |
1195 | return nfserr_inval; | |
1196 | ||
1197 | /* count in words: | |
1198 | * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 | |
1199 | */ | |
1200 | count = 4 + (verify->ve_attrlen >> 2); | |
1201 | buf = kmalloc(count << 2, GFP_KERNEL); | |
1202 | if (!buf) | |
3e772463 | 1203 | return nfserr_jukebox; |
1da177e4 | 1204 | |
84822d0b | 1205 | p = buf; |
d5184658 | 1206 | status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh, |
ca364317 | 1207 | cstate->current_fh.fh_export, |
d5184658 BF |
1208 | cstate->current_fh.fh_dentry, |
1209 | verify->ve_bmval, | |
406a7ea9 | 1210 | rqstp, 0); |
41ae6e71 BF |
1211 | /* |
1212 | * If nfsd4_encode_fattr() ran out of space, assume that's because | |
1213 | * the attributes are longer (hence different) than those given: | |
1214 | */ | |
84822d0b | 1215 | if (status == nfserr_resource) |
1da177e4 LT |
1216 | status = nfserr_not_same; |
1217 | if (status) | |
1218 | goto out_kfree; | |
1219 | ||
95ec28cd BH |
1220 | /* skip bitmap */ |
1221 | p = buf + 1 + ntohl(buf[0]); | |
1da177e4 LT |
1222 | status = nfserr_not_same; |
1223 | if (ntohl(*p++) != verify->ve_attrlen) | |
1224 | goto out_kfree; | |
1225 | if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) | |
1226 | status = nfserr_same; | |
1227 | ||
1228 | out_kfree: | |
1229 | kfree(buf); | |
1230 | return status; | |
1231 | } | |
1232 | ||
c954e2a5 BF |
1233 | static __be32 |
1234 | nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1235 | struct nfsd4_verify *verify) | |
1236 | { | |
1237 | __be32 status; | |
1238 | ||
1239 | status = _nfsd4_verify(rqstp, cstate, verify); | |
1240 | return status == nfserr_not_same ? nfs_ok : status; | |
1241 | } | |
1242 | ||
1243 | static __be32 | |
1244 | nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |
1245 | struct nfsd4_verify *verify) | |
1246 | { | |
1247 | __be32 status; | |
1248 | ||
1249 | status = _nfsd4_verify(rqstp, cstate, verify); | |
1250 | return status == nfserr_same ? nfs_ok : status; | |
1251 | } | |
1252 | ||
9cf514cc CH |
1253 | #ifdef CONFIG_NFSD_PNFS |
1254 | static const struct nfsd4_layout_ops * | |
1255 | nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type) | |
1256 | { | |
8a4c3926 | 1257 | if (!exp->ex_layout_types) { |
9cf514cc CH |
1258 | dprintk("%s: export does not support pNFS\n", __func__); |
1259 | return NULL; | |
1260 | } | |
1261 | ||
b550a32e AK |
1262 | if (layout_type >= LAYOUT_TYPE_MAX || |
1263 | !(exp->ex_layout_types & (1 << layout_type))) { | |
9cf514cc CH |
1264 | dprintk("%s: layout type %d not supported\n", |
1265 | __func__, layout_type); | |
1266 | return NULL; | |
1267 | } | |
1268 | ||
1269 | return nfsd4_layout_ops[layout_type]; | |
1270 | } | |
1271 | ||
1272 | static __be32 | |
1273 | nfsd4_getdeviceinfo(struct svc_rqst *rqstp, | |
1274 | struct nfsd4_compound_state *cstate, | |
1275 | struct nfsd4_getdeviceinfo *gdp) | |
1276 | { | |
1277 | const struct nfsd4_layout_ops *ops; | |
1278 | struct nfsd4_deviceid_map *map; | |
1279 | struct svc_export *exp; | |
1280 | __be32 nfserr; | |
1281 | ||
1282 | dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n", | |
1283 | __func__, | |
1284 | gdp->gd_layout_type, | |
1285 | gdp->gd_devid.fsid_idx, gdp->gd_devid.generation, | |
1286 | gdp->gd_maxcount); | |
1287 | ||
1288 | map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx); | |
1289 | if (!map) { | |
1290 | dprintk("%s: couldn't find device ID to export mapping!\n", | |
1291 | __func__); | |
1292 | return nfserr_noent; | |
1293 | } | |
1294 | ||
1295 | exp = rqst_exp_find(rqstp, map->fsid_type, map->fsid); | |
1296 | if (IS_ERR(exp)) { | |
1297 | dprintk("%s: could not find device id\n", __func__); | |
1298 | return nfserr_noent; | |
1299 | } | |
1300 | ||
1301 | nfserr = nfserr_layoutunavailable; | |
1302 | ops = nfsd4_layout_verify(exp, gdp->gd_layout_type); | |
1303 | if (!ops) | |
1304 | goto out; | |
1305 | ||
1306 | nfserr = nfs_ok; | |
f99d4fbd CH |
1307 | if (gdp->gd_maxcount != 0) { |
1308 | nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb, | |
d7c920d1 | 1309 | rqstp, cstate->session->se_client, gdp); |
f99d4fbd | 1310 | } |
9cf514cc CH |
1311 | |
1312 | gdp->gd_notify_types &= ops->notify_types; | |
9cf514cc | 1313 | out: |
a1420384 | 1314 | exp_put(exp); |
9cf514cc CH |
1315 | return nfserr; |
1316 | } | |
1317 | ||
1318 | static __be32 | |
1319 | nfsd4_layoutget(struct svc_rqst *rqstp, | |
1320 | struct nfsd4_compound_state *cstate, | |
1321 | struct nfsd4_layoutget *lgp) | |
1322 | { | |
1323 | struct svc_fh *current_fh = &cstate->current_fh; | |
1324 | const struct nfsd4_layout_ops *ops; | |
1325 | struct nfs4_layout_stateid *ls; | |
1326 | __be32 nfserr; | |
1327 | int accmode; | |
1328 | ||
1329 | switch (lgp->lg_seg.iomode) { | |
1330 | case IOMODE_READ: | |
1331 | accmode = NFSD_MAY_READ; | |
1332 | break; | |
1333 | case IOMODE_RW: | |
1334 | accmode = NFSD_MAY_READ | NFSD_MAY_WRITE; | |
1335 | break; | |
1336 | default: | |
1337 | dprintk("%s: invalid iomode %d\n", | |
1338 | __func__, lgp->lg_seg.iomode); | |
1339 | nfserr = nfserr_badiomode; | |
1340 | goto out; | |
1341 | } | |
1342 | ||
1343 | nfserr = fh_verify(rqstp, current_fh, 0, accmode); | |
1344 | if (nfserr) | |
1345 | goto out; | |
1346 | ||
1347 | nfserr = nfserr_layoutunavailable; | |
1348 | ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type); | |
1349 | if (!ops) | |
1350 | goto out; | |
1351 | ||
1352 | /* | |
1353 | * Verify minlength and range as per RFC5661: | |
1354 | * o If loga_length is less than loga_minlength, | |
1355 | * the metadata server MUST return NFS4ERR_INVAL. | |
1356 | * o If the sum of loga_offset and loga_minlength exceeds | |
1357 | * NFS4_UINT64_MAX, and loga_minlength is not | |
1358 | * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result. | |
1359 | * o If the sum of loga_offset and loga_length exceeds | |
1360 | * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX, | |
1361 | * the error NFS4ERR_INVAL MUST result. | |
1362 | */ | |
1363 | nfserr = nfserr_inval; | |
1364 | if (lgp->lg_seg.length < lgp->lg_minlength || | |
1365 | (lgp->lg_minlength != NFS4_MAX_UINT64 && | |
1366 | lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) || | |
1367 | (lgp->lg_seg.length != NFS4_MAX_UINT64 && | |
1368 | lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset)) | |
1369 | goto out; | |
1370 | if (lgp->lg_seg.length == 0) | |
1371 | goto out; | |
1372 | ||
1373 | nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid, | |
1374 | true, lgp->lg_layout_type, &ls); | |
31ef83dc CH |
1375 | if (nfserr) { |
1376 | trace_layout_get_lookup_fail(&lgp->lg_sid); | |
9cf514cc | 1377 | goto out; |
31ef83dc | 1378 | } |
9cf514cc | 1379 | |
c5c707f9 CH |
1380 | nfserr = nfserr_recallconflict; |
1381 | if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls)) | |
1382 | goto out_put_stid; | |
1383 | ||
2b0143b5 | 1384 | nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry), |
9cf514cc CH |
1385 | current_fh, lgp); |
1386 | if (nfserr) | |
1387 | goto out_put_stid; | |
1388 | ||
1389 | nfserr = nfsd4_insert_layout(lgp, ls); | |
1390 | ||
1391 | out_put_stid: | |
cc8a5532 | 1392 | mutex_unlock(&ls->ls_mutex); |
9cf514cc CH |
1393 | nfs4_put_stid(&ls->ls_stid); |
1394 | out: | |
1395 | return nfserr; | |
1396 | } | |
1397 | ||
1398 | static __be32 | |
1399 | nfsd4_layoutcommit(struct svc_rqst *rqstp, | |
1400 | struct nfsd4_compound_state *cstate, | |
1401 | struct nfsd4_layoutcommit *lcp) | |
1402 | { | |
1403 | const struct nfsd4_layout_seg *seg = &lcp->lc_seg; | |
1404 | struct svc_fh *current_fh = &cstate->current_fh; | |
1405 | const struct nfsd4_layout_ops *ops; | |
1406 | loff_t new_size = lcp->lc_last_wr + 1; | |
1407 | struct inode *inode; | |
1408 | struct nfs4_layout_stateid *ls; | |
1409 | __be32 nfserr; | |
1410 | ||
1411 | nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE); | |
1412 | if (nfserr) | |
1413 | goto out; | |
1414 | ||
1415 | nfserr = nfserr_layoutunavailable; | |
1416 | ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type); | |
1417 | if (!ops) | |
1418 | goto out; | |
2b0143b5 | 1419 | inode = d_inode(current_fh->fh_dentry); |
9cf514cc CH |
1420 | |
1421 | nfserr = nfserr_inval; | |
1422 | if (new_size <= seg->offset) { | |
1423 | dprintk("pnfsd: last write before layout segment\n"); | |
1424 | goto out; | |
1425 | } | |
1426 | if (new_size > seg->offset + seg->length) { | |
1427 | dprintk("pnfsd: last write beyond layout segment\n"); | |
1428 | goto out; | |
1429 | } | |
1430 | if (!lcp->lc_newoffset && new_size > i_size_read(inode)) { | |
1431 | dprintk("pnfsd: layoutcommit beyond EOF\n"); | |
1432 | goto out; | |
1433 | } | |
1434 | ||
1435 | nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid, | |
1436 | false, lcp->lc_layout_type, | |
1437 | &ls); | |
1438 | if (nfserr) { | |
31ef83dc | 1439 | trace_layout_commit_lookup_fail(&lcp->lc_sid); |
9cf514cc CH |
1440 | /* fixup error code as per RFC5661 */ |
1441 | if (nfserr == nfserr_bad_stateid) | |
1442 | nfserr = nfserr_badlayout; | |
1443 | goto out; | |
1444 | } | |
1445 | ||
cc8a5532 JL |
1446 | /* LAYOUTCOMMIT does not require any serialization */ |
1447 | mutex_unlock(&ls->ls_mutex); | |
1448 | ||
9cf514cc CH |
1449 | if (new_size > i_size_read(inode)) { |
1450 | lcp->lc_size_chg = 1; | |
1451 | lcp->lc_newsize = new_size; | |
1452 | } else { | |
1453 | lcp->lc_size_chg = 0; | |
1454 | } | |
1455 | ||
d8398fc1 | 1456 | nfserr = ops->proc_layoutcommit(inode, lcp); |
9cf514cc CH |
1457 | nfs4_put_stid(&ls->ls_stid); |
1458 | out: | |
1459 | return nfserr; | |
1460 | } | |
1461 | ||
1462 | static __be32 | |
1463 | nfsd4_layoutreturn(struct svc_rqst *rqstp, | |
1464 | struct nfsd4_compound_state *cstate, | |
1465 | struct nfsd4_layoutreturn *lrp) | |
1466 | { | |
1467 | struct svc_fh *current_fh = &cstate->current_fh; | |
1468 | __be32 nfserr; | |
1469 | ||
1470 | nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP); | |
1471 | if (nfserr) | |
1472 | goto out; | |
1473 | ||
1474 | nfserr = nfserr_layoutunavailable; | |
1475 | if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type)) | |
1476 | goto out; | |
1477 | ||
1478 | switch (lrp->lr_seg.iomode) { | |
1479 | case IOMODE_READ: | |
1480 | case IOMODE_RW: | |
1481 | case IOMODE_ANY: | |
1482 | break; | |
1483 | default: | |
1484 | dprintk("%s: invalid iomode %d\n", __func__, | |
1485 | lrp->lr_seg.iomode); | |
1486 | nfserr = nfserr_inval; | |
1487 | goto out; | |
1488 | } | |
1489 | ||
1490 | switch (lrp->lr_return_type) { | |
1491 | case RETURN_FILE: | |
1492 | nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp); | |
1493 | break; | |
1494 | case RETURN_FSID: | |
1495 | case RETURN_ALL: | |
1496 | nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp); | |
1497 | break; | |
1498 | default: | |
1499 | dprintk("%s: invalid return_type %d\n", __func__, | |
1500 | lrp->lr_return_type); | |
1501 | nfserr = nfserr_inval; | |
1502 | break; | |
1503 | } | |
1504 | out: | |
1505 | return nfserr; | |
1506 | } | |
1507 | #endif /* CONFIG_NFSD_PNFS */ | |
1508 | ||
1da177e4 LT |
1509 | /* |
1510 | * NULL call. | |
1511 | */ | |
7111c66e | 1512 | static __be32 |
a6beb732 | 1513 | nfsd4_proc_null(struct svc_rqst *rqstp) |
1da177e4 LT |
1514 | { |
1515 | return nfs_ok; | |
1516 | } | |
1517 | ||
e2b20950 SA |
1518 | static inline void nfsd4_increment_op_stats(u32 opnum) |
1519 | { | |
1520 | if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) | |
1521 | nfsdstats.nfs4_opcount[opnum]++; | |
1522 | } | |
1523 | ||
b591480b BF |
1524 | typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, |
1525 | void *); | |
58e7b33a | 1526 | typedef u32(*nfsd4op_rsize)(struct svc_rqst *, struct nfsd4_op *op); |
a6beb732 | 1527 | |
8b70484c TM |
1528 | typedef void(*stateid_setter)(struct nfsd4_compound_state *, void *); |
1529 | typedef void(*stateid_getter)(struct nfsd4_compound_state *, void *); | |
58e7b33a | 1530 | |
f9bb94c4 AA |
1531 | enum nfsd4_op_flags { |
1532 | ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ | |
5ece3caf MJ |
1533 | ALLOWED_ON_ABSENT_FS = 1 << 1, /* ops processed on absent fs */ |
1534 | ALLOWED_AS_FIRST_OP = 1 << 2, /* ops reqired first in compound */ | |
68d93184 BF |
1535 | /* For rfc 5661 section 2.6.3.1.1: */ |
1536 | OP_HANDLES_WRONGSEC = 1 << 3, | |
1537 | OP_IS_PUTFH_LIKE = 1 << 4, | |
1091006c | 1538 | /* |
c856694e BF |
1539 | * These are the ops whose result size we estimate before |
1540 | * encoding, to avoid performing an op then not being able to | |
1541 | * respond or cache a response. This includes writes and setattrs | |
1542 | * as well as the operations usually called "nonidempotent": | |
1543 | */ | |
1544 | OP_MODIFIES_SOMETHING = 1 << 5, | |
1545 | /* | |
1546 | * Cache compounds containing these ops in the xid-based drc: | |
1091006c BF |
1547 | * We use the DRC for compounds containing non-idempotent |
1548 | * operations, *except* those that are 4.1-specific (since | |
1549 | * sessions provide their own EOS), and except for stateful | |
1550 | * operations other than setclientid and setclientid_confirm | |
1551 | * (since sequence numbers provide EOS for open, lock, etc in | |
1552 | * the v4.0 case). | |
1553 | */ | |
c856694e | 1554 | OP_CACHEME = 1 << 6, |
8b70484c TM |
1555 | /* |
1556 | * These are ops which clear current state id. | |
1557 | */ | |
1558 | OP_CLEAR_STATEID = 1 << 7, | |
c856694e BF |
1559 | }; |
1560 | ||
1561 | struct nfsd4_operation { | |
1562 | nfsd4op_func op_func; | |
1563 | u32 op_flags; | |
1564 | char *op_name; | |
58e7b33a MJ |
1565 | /* Try to get response size before operation */ |
1566 | nfsd4op_rsize op_rsize_bop; | |
24ff99c6 BS |
1567 | stateid_getter op_get_currentstateid; |
1568 | stateid_setter op_set_currentstateid; | |
b591480b BF |
1569 | }; |
1570 | ||
1571 | static struct nfsd4_operation nfsd4_ops[]; | |
1572 | ||
f1c7f79b | 1573 | static const char *nfsd4_op_name(unsigned opnum); |
b001a1b6 | 1574 | |
f9bb94c4 | 1575 | /* |
57716355 | 1576 | * Enforce NFSv4.1 COMPOUND ordering rules: |
f9bb94c4 | 1577 | * |
57716355 BF |
1578 | * Also note, enforced elsewhere: |
1579 | * - SEQUENCE other than as first op results in | |
1580 | * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().) | |
1d1bc8f2 BF |
1581 | * - BIND_CONN_TO_SESSION must be the only op in its compound. |
1582 | * (Enforced in nfsd4_bind_conn_to_session().) | |
57716355 BF |
1583 | * - DESTROY_SESSION must be the final operation in a compound, if |
1584 | * sessionid's in SEQUENCE and DESTROY_SESSION are the same. | |
1585 | * (Enforced in nfsd4_destroy_session().) | |
f9bb94c4 | 1586 | */ |
57716355 | 1587 | static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args) |
f9bb94c4 | 1588 | { |
57716355 BF |
1589 | struct nfsd4_op *op = &args->ops[0]; |
1590 | ||
1591 | /* These ordering requirements don't apply to NFSv4.0: */ | |
1592 | if (args->minorversion == 0) | |
1593 | return nfs_ok; | |
1594 | /* This is weird, but OK, not our problem: */ | |
1595 | if (args->opcnt == 0) | |
1596 | return nfs_ok; | |
1597 | if (op->status == nfserr_op_illegal) | |
1598 | return nfs_ok; | |
1599 | if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP)) | |
1600 | return nfserr_op_not_in_session; | |
1601 | if (op->opnum == OP_SEQUENCE) | |
1602 | return nfs_ok; | |
1603 | if (args->opcnt != 1) | |
1604 | return nfserr_not_only_op; | |
1605 | return nfs_ok; | |
f9bb94c4 AA |
1606 | } |
1607 | ||
22b03214 BF |
1608 | static inline struct nfsd4_operation *OPDESC(struct nfsd4_op *op) |
1609 | { | |
1610 | return &nfsd4_ops[op->opnum]; | |
1611 | } | |
1612 | ||
1091006c BF |
1613 | bool nfsd4_cache_this_op(struct nfsd4_op *op) |
1614 | { | |
e372ba60 BF |
1615 | if (op->opnum == OP_ILLEGAL) |
1616 | return false; | |
c856694e | 1617 | return OPDESC(op)->op_flags & OP_CACHEME; |
1091006c BF |
1618 | } |
1619 | ||
68d93184 BF |
1620 | static bool need_wrongsec_check(struct svc_rqst *rqstp) |
1621 | { | |
1622 | struct nfsd4_compoundres *resp = rqstp->rq_resp; | |
1623 | struct nfsd4_compoundargs *argp = rqstp->rq_argp; | |
1624 | struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; | |
1625 | struct nfsd4_op *next = &argp->ops[resp->opcnt]; | |
1626 | struct nfsd4_operation *thisd; | |
1627 | struct nfsd4_operation *nextd; | |
1628 | ||
1629 | thisd = OPDESC(this); | |
1630 | /* | |
1631 | * Most ops check wronsec on our own; only the putfh-like ops | |
1632 | * have special rules. | |
1633 | */ | |
1634 | if (!(thisd->op_flags & OP_IS_PUTFH_LIKE)) | |
1635 | return false; | |
1636 | /* | |
1637 | * rfc 5661 2.6.3.1.1.6: don't bother erroring out a | |
1638 | * put-filehandle operation if we're not going to use the | |
1639 | * result: | |
1640 | */ | |
1641 | if (argp->opcnt == resp->opcnt) | |
1642 | return false; | |
51904b08 BF |
1643 | if (next->opnum == OP_ILLEGAL) |
1644 | return false; | |
68d93184 BF |
1645 | nextd = OPDESC(next); |
1646 | /* | |
1647 | * Rest of 2.6.3.1.1: certain operations will return WRONGSEC | |
1648 | * errors themselves as necessary; others should check for them | |
1649 | * now: | |
1650 | */ | |
1651 | return !(nextd->op_flags & OP_HANDLES_WRONGSEC); | |
1652 | } | |
1653 | ||
2d124dfa BF |
1654 | static void svcxdr_init_encode(struct svc_rqst *rqstp, |
1655 | struct nfsd4_compoundres *resp) | |
1656 | { | |
1657 | struct xdr_stream *xdr = &resp->xdr; | |
1658 | struct xdr_buf *buf = &rqstp->rq_res; | |
1659 | struct kvec *head = buf->head; | |
1660 | ||
1661 | xdr->buf = buf; | |
ddd1ea56 | 1662 | xdr->iov = head; |
2d124dfa | 1663 | xdr->p = head->iov_base + head->iov_len; |
a5cddc88 | 1664 | xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; |
6ac90391 BF |
1665 | /* Tail and page_len should be zero at this point: */ |
1666 | buf->len = buf->head[0].iov_len; | |
2825a7f9 | 1667 | xdr->scratch.iov_len = 0; |
05638dc7 | 1668 | xdr->page_ptr = buf->pages - 1; |
2825a7f9 | 1669 | buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages) |
a5cddc88 | 1670 | - rqstp->rq_auth_slack; |
2d124dfa BF |
1671 | } |
1672 | ||
1da177e4 LT |
1673 | /* |
1674 | * COMPOUND call. | |
1675 | */ | |
7111c66e | 1676 | static __be32 |
a6beb732 | 1677 | nfsd4_proc_compound(struct svc_rqst *rqstp) |
1da177e4 | 1678 | { |
a6beb732 CH |
1679 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
1680 | struct nfsd4_compoundres *resp = rqstp->rq_resp; | |
1da177e4 | 1681 | struct nfsd4_op *op; |
b591480b | 1682 | struct nfsd4_operation *opdesc; |
e354d571 | 1683 | struct nfsd4_compound_state *cstate = &resp->cstate; |
4daeed25 KM |
1684 | struct svc_fh *current_fh = &cstate->current_fh; |
1685 | struct svc_fh *save_fh = &cstate->save_fh; | |
b37ad28b | 1686 | __be32 status; |
1da177e4 | 1687 | |
2d124dfa | 1688 | svcxdr_init_encode(rqstp, resp); |
4aea24b2 | 1689 | resp->tagp = resp->xdr.p; |
1da177e4 | 1690 | /* reserve space for: taglen, tag, and opcnt */ |
d3f627c8 | 1691 | xdr_reserve_space(&resp->xdr, 8 + args->taglen); |
1da177e4 LT |
1692 | resp->taglen = args->taglen; |
1693 | resp->tag = args->tag; | |
1da177e4 | 1694 | resp->rqstp = rqstp; |
4daeed25 | 1695 | cstate->minorversion = args->minorversion; |
4daeed25 KM |
1696 | fh_init(current_fh, NFS4_FHSIZE); |
1697 | fh_init(save_fh, NFS4_FHSIZE); | |
8ff30fa4 N |
1698 | /* |
1699 | * Don't use the deferral mechanism for NFSv4; compounds make it | |
1700 | * too hard to avoid non-idempotency problems. | |
1701 | */ | |
30660e04 | 1702 | clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); |
1da177e4 LT |
1703 | |
1704 | /* | |
1705 | * According to RFC3010, this takes precedence over all other errors. | |
1706 | */ | |
1707 | status = nfserr_minor_vers_mismatch; | |
35f7a14f | 1708 | if (nfsd_minorversion(args->minorversion, NFSD_TEST) <= 0) |
1da177e4 LT |
1709 | goto out; |
1710 | ||
57716355 BF |
1711 | status = nfs41_check_op_ordering(args); |
1712 | if (status) { | |
f9bb94c4 | 1713 | op = &args->ops[0]; |
57716355 | 1714 | op->status = status; |
f9bb94c4 AA |
1715 | goto encode_op; |
1716 | } | |
1717 | ||
1da177e4 LT |
1718 | while (!status && resp->opcnt < args->opcnt) { |
1719 | op = &args->ops[resp->opcnt++]; | |
1720 | ||
b001a1b6 BH |
1721 | dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", |
1722 | resp->opcnt, args->opcnt, op->opnum, | |
1723 | nfsd4_op_name(op->opnum)); | |
1da177e4 LT |
1724 | /* |
1725 | * The XDR decode routines may have pre-set op->status; | |
1726 | * for example, if there is a miscellaneous XDR error | |
1727 | * it will be set to nfserr_bad_xdr. | |
1728 | */ | |
9d313b17 BF |
1729 | if (op->status) { |
1730 | if (op->opnum == OP_OPEN) | |
1731 | op->status = nfsd4_open_omfg(rqstp, cstate, op); | |
1da177e4 | 1732 | goto encode_op; |
9d313b17 | 1733 | } |
1da177e4 | 1734 | |
22b03214 | 1735 | opdesc = OPDESC(op); |
b591480b | 1736 | |
4daeed25 | 1737 | if (!current_fh->fh_dentry) { |
27d630ec | 1738 | if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { |
42ca0993 BF |
1739 | op->status = nfserr_nofilehandle; |
1740 | goto encode_op; | |
1741 | } | |
4daeed25 | 1742 | } else if (current_fh->fh_export->ex_fslocs.migrated && |
eeac294e | 1743 | !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { |
42ca0993 | 1744 | op->status = nfserr_moved; |
1da177e4 LT |
1745 | goto encode_op; |
1746 | } | |
b591480b | 1747 | |
2336745e KM |
1748 | fh_clear_wcc(current_fh); |
1749 | ||
58e7b33a MJ |
1750 | /* If op is non-idempotent */ |
1751 | if (opdesc->op_flags & OP_MODIFIES_SOMETHING) { | |
4c69d585 | 1752 | /* |
a8095f7e BF |
1753 | * Don't execute this op if we couldn't encode a |
1754 | * succesful reply: | |
1755 | */ | |
1756 | u32 plen = opdesc->op_rsize_bop(rqstp, op); | |
1757 | /* | |
1758 | * Plus if there's another operation, make sure | |
4c69d585 BF |
1759 | * we'll have space to at least encode an error: |
1760 | */ | |
1761 | if (resp->opcnt < args->opcnt) | |
1762 | plen += COMPOUND_ERR_SLACK_SPACE; | |
58e7b33a MJ |
1763 | op->status = nfsd4_check_resp_size(resp, plen); |
1764 | } | |
1765 | ||
1766 | if (op->status) | |
1767 | goto encode_op; | |
1768 | ||
b600de7a BF |
1769 | if (opdesc->op_get_currentstateid) |
1770 | opdesc->op_get_currentstateid(cstate, &op->u); | |
1771 | op->status = opdesc->op_func(rqstp, cstate, &op->u); | |
1da177e4 | 1772 | |
8b70484c TM |
1773 | if (!op->status) { |
1774 | if (opdesc->op_set_currentstateid) | |
1775 | opdesc->op_set_currentstateid(cstate, &op->u); | |
1776 | ||
1777 | if (opdesc->op_flags & OP_CLEAR_STATEID) | |
37c593c5 | 1778 | clear_current_stateid(cstate); |
8b70484c TM |
1779 | |
1780 | if (need_wrongsec_check(rqstp)) | |
4daeed25 | 1781 | op->status = check_nfsd_access(current_fh->fh_export, rqstp); |
8b70484c | 1782 | } |
68d93184 | 1783 | |
1da177e4 | 1784 | encode_op: |
49557cc7 | 1785 | /* Only from SEQUENCE */ |
4daeed25 | 1786 | if (cstate->status == nfserr_replay_cache) { |
da3846a2 | 1787 | dprintk("%s NFS4.1 replay from cache\n", __func__); |
abfabf8c | 1788 | status = op->status; |
da3846a2 AA |
1789 | goto out; |
1790 | } | |
a90b061c | 1791 | if (op->status == nfserr_replay_me) { |
a4f1706a | 1792 | op->replay = &cstate->replay_owner->so_replay; |
d0a381dd | 1793 | nfsd4_encode_replay(&resp->xdr, op); |
1da177e4 LT |
1794 | status = op->status = op->replay->rp_status; |
1795 | } else { | |
1796 | nfsd4_encode_operation(resp, op); | |
1797 | status = op->status; | |
1798 | } | |
0407717d BH |
1799 | |
1800 | dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", | |
1801 | args->ops, args->opcnt, resp->opcnt, op->opnum, | |
1802 | be32_to_cpu(status)); | |
1803 | ||
58fb12e6 | 1804 | nfsd4_cstate_clear_replay(cstate); |
e2b20950 | 1805 | nfsd4_increment_op_stats(op->opnum); |
1da177e4 LT |
1806 | } |
1807 | ||
4daeed25 KM |
1808 | cstate->status = status; |
1809 | fh_put(current_fh); | |
1810 | fh_put(save_fh); | |
1811 | BUG_ON(cstate->replay_owner); | |
1da177e4 | 1812 | out: |
2f425878 | 1813 | /* Reset deferral mechanism for RPC deferrals */ |
30660e04 | 1814 | set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags); |
3b12cd98 | 1815 | dprintk("nfsv4 compound returned %d\n", ntohl(status)); |
1da177e4 LT |
1816 | return status; |
1817 | } | |
1818 | ||
58e7b33a MJ |
1819 | #define op_encode_hdr_size (2) |
1820 | #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE)) | |
1821 | #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE)) | |
1822 | #define op_encode_change_info_maxsz (5) | |
1823 | #define nfs4_fattr_bitmap_maxsz (4) | |
1824 | ||
8c7424cf BF |
1825 | /* We'll fall back on returning no lockowner if run out of space: */ |
1826 | #define op_encode_lockowner_maxsz (0) | |
58e7b33a MJ |
1827 | #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz) |
1828 | ||
1829 | #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) | |
1830 | ||
1831 | #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz) | |
1832 | #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \ | |
1833 | op_encode_ace_maxsz) | |
1834 | ||
1835 | #define op_encode_channel_attrs_maxsz (6 + 1 + 1) | |
1836 | ||
1837 | static inline u32 nfsd4_only_status_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1838 | { | |
1839 | return (op_encode_hdr_size) * sizeof(__be32); | |
1840 | } | |
1841 | ||
1842 | static inline u32 nfsd4_status_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1843 | { | |
1844 | return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32); | |
1845 | } | |
1846 | ||
2282cd2c KM |
1847 | static inline u32 nfsd4_access_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1848 | { | |
1849 | /* ac_supported, ac_resp_access */ | |
1850 | return (op_encode_hdr_size + 2)* sizeof(__be32); | |
1851 | } | |
1852 | ||
58e7b33a MJ |
1853 | static inline u32 nfsd4_commit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1854 | { | |
1855 | return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32); | |
1856 | } | |
1857 | ||
1858 | static inline u32 nfsd4_create_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1859 | { | |
1860 | return (op_encode_hdr_size + op_encode_change_info_maxsz | |
1861 | + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); | |
1862 | } | |
1863 | ||
b86cef60 BF |
1864 | /* |
1865 | * Note since this is an idempotent operation we won't insist on failing | |
1866 | * the op prematurely if the estimate is too large. We may turn off splice | |
1867 | * reads unnecessarily. | |
1868 | */ | |
1869 | static inline u32 nfsd4_getattr_rsize(struct svc_rqst *rqstp, | |
1870 | struct nfsd4_op *op) | |
1871 | { | |
1872 | u32 *bmap = op->u.getattr.ga_bmval; | |
1873 | u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2]; | |
1874 | u32 ret = 0; | |
1875 | ||
1876 | if (bmap0 & FATTR4_WORD0_ACL) | |
1877 | return svc_max_payload(rqstp); | |
1878 | if (bmap0 & FATTR4_WORD0_FS_LOCATIONS) | |
1879 | return svc_max_payload(rqstp); | |
1880 | ||
1881 | if (bmap1 & FATTR4_WORD1_OWNER) { | |
1882 | ret += IDMAP_NAMESZ + 4; | |
1883 | bmap1 &= ~FATTR4_WORD1_OWNER; | |
1884 | } | |
1885 | if (bmap1 & FATTR4_WORD1_OWNER_GROUP) { | |
1886 | ret += IDMAP_NAMESZ + 4; | |
1887 | bmap1 &= ~FATTR4_WORD1_OWNER_GROUP; | |
1888 | } | |
1889 | if (bmap0 & FATTR4_WORD0_FILEHANDLE) { | |
1890 | ret += NFS4_FHSIZE + 4; | |
1891 | bmap0 &= ~FATTR4_WORD0_FILEHANDLE; | |
1892 | } | |
1893 | if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) { | |
1ec8c0c4 | 1894 | ret += NFS4_MAXLABELLEN + 12; |
b86cef60 BF |
1895 | bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
1896 | } | |
1897 | /* | |
1898 | * Largest of remaining attributes are 16 bytes (e.g., | |
1899 | * supported_attributes) | |
1900 | */ | |
1901 | ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2)); | |
1902 | /* bitmask, length */ | |
1903 | ret += 20; | |
1904 | return ret; | |
1905 | } | |
1906 | ||
2282cd2c KM |
1907 | static inline u32 nfsd4_getfh_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1908 | { | |
1909 | return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE; | |
1910 | } | |
1911 | ||
58e7b33a MJ |
1912 | static inline u32 nfsd4_link_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1913 | { | |
1914 | return (op_encode_hdr_size + op_encode_change_info_maxsz) | |
1915 | * sizeof(__be32); | |
1916 | } | |
1917 | ||
1918 | static inline u32 nfsd4_lock_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1919 | { | |
1920 | return (op_encode_hdr_size + op_encode_lock_denied_maxsz) | |
1921 | * sizeof(__be32); | |
1922 | } | |
1923 | ||
1924 | static inline u32 nfsd4_open_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1925 | { | |
1926 | return (op_encode_hdr_size + op_encode_stateid_maxsz | |
1927 | + op_encode_change_info_maxsz + 1 | |
1928 | + nfs4_fattr_bitmap_maxsz | |
1929 | + op_encode_delegation_maxsz) * sizeof(__be32); | |
1930 | } | |
1931 | ||
1932 | static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1933 | { | |
1934 | u32 maxcount = 0, rlen = 0; | |
1935 | ||
1936 | maxcount = svc_max_payload(rqstp); | |
3c7aa15d | 1937 | rlen = min(op->u.read.rd_length, maxcount); |
58e7b33a | 1938 | |
622f560e | 1939 | return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32); |
58e7b33a MJ |
1940 | } |
1941 | ||
1942 | static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1943 | { | |
3c7aa15d | 1944 | u32 maxcount = 0, rlen = 0; |
58e7b33a | 1945 | |
3c7aa15d KM |
1946 | maxcount = svc_max_payload(rqstp); |
1947 | rlen = min(op->u.readdir.rd_maxcount, maxcount); | |
58e7b33a | 1948 | |
561f0ed4 BF |
1949 | return (op_encode_hdr_size + op_encode_verifier_maxsz + |
1950 | XDR_QUADLEN(rlen)) * sizeof(__be32); | |
58e7b33a MJ |
1951 | } |
1952 | ||
2282cd2c KM |
1953 | static inline u32 nfsd4_readlink_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1954 | { | |
1955 | return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE; | |
1956 | } | |
1957 | ||
58e7b33a MJ |
1958 | static inline u32 nfsd4_remove_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1959 | { | |
1960 | return (op_encode_hdr_size + op_encode_change_info_maxsz) | |
1961 | * sizeof(__be32); | |
1962 | } | |
1963 | ||
1964 | static inline u32 nfsd4_rename_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
1965 | { | |
1966 | return (op_encode_hdr_size + op_encode_change_info_maxsz | |
1967 | + op_encode_change_info_maxsz) * sizeof(__be32); | |
1968 | } | |
1969 | ||
ccae70a9 BF |
1970 | static inline u32 nfsd4_sequence_rsize(struct svc_rqst *rqstp, |
1971 | struct nfsd4_op *op) | |
1972 | { | |
d1d84c96 BF |
1973 | return (op_encode_hdr_size |
1974 | + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32); | |
ccae70a9 BF |
1975 | } |
1976 | ||
2282cd2c KM |
1977 | static inline u32 nfsd4_test_stateid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1978 | { | |
1979 | return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids) | |
1980 | * sizeof(__be32); | |
1981 | } | |
1982 | ||
58e7b33a MJ |
1983 | static inline u32 nfsd4_setattr_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1984 | { | |
1985 | return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32); | |
1986 | } | |
1987 | ||
2282cd2c KM |
1988 | static inline u32 nfsd4_secinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1989 | { | |
1990 | return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR * | |
1991 | (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32); | |
1992 | } | |
1993 | ||
58e7b33a MJ |
1994 | static inline u32 nfsd4_setclientid_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
1995 | { | |
480efaee BF |
1996 | return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) * |
1997 | sizeof(__be32); | |
58e7b33a MJ |
1998 | } |
1999 | ||
2000 | static inline u32 nfsd4_write_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2001 | { | |
f34e432b | 2002 | return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32); |
58e7b33a MJ |
2003 | } |
2004 | ||
2005 | static inline u32 nfsd4_exchange_id_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2006 | { | |
2007 | return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\ | |
a8bb84bc KM |
2008 | 1 + 1 + /* eir_flags, spr_how */\ |
2009 | 4 + /* spo_must_enforce & _allow with bitmap */\ | |
58e7b33a MJ |
2010 | 2 + /*eir_server_owner.so_minor_id */\ |
2011 | /* eir_server_owner.so_major_id<> */\ | |
2012 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ | |
2013 | /* eir_server_scope<> */\ | |
2014 | XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\ | |
2015 | 1 + /* eir_server_impl_id array length */\ | |
2016 | 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32); | |
2017 | } | |
2018 | ||
2019 | static inline u32 nfsd4_bind_conn_to_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2020 | { | |
2021 | return (op_encode_hdr_size + \ | |
2022 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\ | |
2023 | 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32); | |
2024 | } | |
2025 | ||
2026 | static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2027 | { | |
2028 | return (op_encode_hdr_size + \ | |
2029 | XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\ | |
2030 | 2 + /* csr_sequence, csr_flags */\ | |
2031 | op_encode_channel_attrs_maxsz + \ | |
2032 | op_encode_channel_attrs_maxsz) * sizeof(__be32); | |
2033 | } | |
2034 | ||
29ae7f9d AS |
2035 | static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
2036 | { | |
2037 | return (op_encode_hdr_size + | |
2038 | 1 /* wr_callback */ + | |
2039 | op_encode_stateid_maxsz /* wr_callback */ + | |
2040 | 2 /* wr_count */ + | |
2041 | 1 /* wr_committed */ + | |
2042 | op_encode_verifier_maxsz + | |
2043 | 1 /* cr_consecutive */ + | |
2044 | 1 /* cr_synchronous */) * sizeof(__be32); | |
2045 | } | |
2046 | ||
9cf514cc | 2047 | #ifdef CONFIG_NFSD_PNFS |
2282cd2c KM |
2048 | static inline u32 nfsd4_getdeviceinfo_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) |
2049 | { | |
2050 | u32 maxcount = 0, rlen = 0; | |
2051 | ||
2052 | maxcount = svc_max_payload(rqstp); | |
2053 | rlen = min(op->u.getdeviceinfo.gd_maxcount, maxcount); | |
2054 | ||
2055 | return (op_encode_hdr_size + | |
2056 | 1 /* gd_layout_type*/ + | |
2057 | XDR_QUADLEN(rlen) + | |
2058 | 2 /* gd_notify_types */) * sizeof(__be32); | |
2059 | } | |
2060 | ||
9cf514cc CH |
2061 | /* |
2062 | * At this stage we don't really know what layout driver will handle the request, | |
2063 | * so we need to define an arbitrary upper bound here. | |
2064 | */ | |
2065 | #define MAX_LAYOUT_SIZE 128 | |
2066 | static inline u32 nfsd4_layoutget_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2067 | { | |
2068 | return (op_encode_hdr_size + | |
2069 | 1 /* logr_return_on_close */ + | |
2070 | op_encode_stateid_maxsz + | |
2071 | 1 /* nr of layouts */ + | |
2072 | MAX_LAYOUT_SIZE) * sizeof(__be32); | |
2073 | } | |
2074 | ||
2075 | static inline u32 nfsd4_layoutcommit_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2076 | { | |
2077 | return (op_encode_hdr_size + | |
2078 | 1 /* locr_newsize */ + | |
2079 | 2 /* ns_size */) * sizeof(__be32); | |
2080 | } | |
2081 | ||
2082 | static inline u32 nfsd4_layoutreturn_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2083 | { | |
2084 | return (op_encode_hdr_size + | |
2085 | 1 /* lrs_stateid */ + | |
2086 | op_encode_stateid_maxsz) * sizeof(__be32); | |
2087 | } | |
2088 | #endif /* CONFIG_NFSD_PNFS */ | |
2089 | ||
2282cd2c KM |
2090 | |
2091 | static inline u32 nfsd4_seek_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op) | |
2092 | { | |
2093 | return (op_encode_hdr_size + 3) * sizeof(__be32); | |
2094 | } | |
2095 | ||
20766016 | 2096 | static struct nfsd4_operation nfsd4_ops[] = { |
b591480b BF |
2097 | [OP_ACCESS] = { |
2098 | .op_func = (nfsd4op_func)nfsd4_access, | |
b001a1b6 | 2099 | .op_name = "OP_ACCESS", |
2282cd2c | 2100 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_access_rsize, |
b591480b BF |
2101 | }, |
2102 | [OP_CLOSE] = { | |
2103 | .op_func = (nfsd4op_func)nfsd4_close, | |
58e7b33a | 2104 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2105 | .op_name = "OP_CLOSE", |
58e7b33a | 2106 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, |
8b70484c TM |
2107 | .op_get_currentstateid = (stateid_getter)nfsd4_get_closestateid, |
2108 | .op_set_currentstateid = (stateid_setter)nfsd4_set_closestateid, | |
b591480b BF |
2109 | }, |
2110 | [OP_COMMIT] = { | |
2111 | .op_func = (nfsd4op_func)nfsd4_commit, | |
58e7b33a | 2112 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2113 | .op_name = "OP_COMMIT", |
58e7b33a | 2114 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_commit_rsize, |
b591480b BF |
2115 | }, |
2116 | [OP_CREATE] = { | |
2117 | .op_func = (nfsd4op_func)nfsd4_create, | |
d1471053 | 2118 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID, |
b001a1b6 | 2119 | .op_name = "OP_CREATE", |
58e7b33a | 2120 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_rsize, |
b591480b BF |
2121 | }, |
2122 | [OP_DELEGRETURN] = { | |
2123 | .op_func = (nfsd4op_func)nfsd4_delegreturn, | |
58e7b33a | 2124 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2125 | .op_name = "OP_DELEGRETURN", |
58e7b33a | 2126 | .op_rsize_bop = nfsd4_only_status_rsize, |
9428fe1a | 2127 | .op_get_currentstateid = (stateid_getter)nfsd4_get_delegreturnstateid, |
b591480b BF |
2128 | }, |
2129 | [OP_GETATTR] = { | |
2130 | .op_func = (nfsd4op_func)nfsd4_getattr, | |
eeac294e | 2131 | .op_flags = ALLOWED_ON_ABSENT_FS, |
b86cef60 | 2132 | .op_rsize_bop = nfsd4_getattr_rsize, |
b001a1b6 | 2133 | .op_name = "OP_GETATTR", |
b591480b BF |
2134 | }, |
2135 | [OP_GETFH] = { | |
2136 | .op_func = (nfsd4op_func)nfsd4_getfh, | |
b001a1b6 | 2137 | .op_name = "OP_GETFH", |
2282cd2c | 2138 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_getfh_rsize, |
b591480b BF |
2139 | }, |
2140 | [OP_LINK] = { | |
2141 | .op_func = (nfsd4op_func)nfsd4_link, | |
c856694e BF |
2142 | .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING |
2143 | | OP_CACHEME, | |
b001a1b6 | 2144 | .op_name = "OP_LINK", |
58e7b33a | 2145 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_link_rsize, |
b591480b BF |
2146 | }, |
2147 | [OP_LOCK] = { | |
2148 | .op_func = (nfsd4op_func)nfsd4_lock, | |
58e7b33a | 2149 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2150 | .op_name = "OP_LOCK", |
58e7b33a | 2151 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, |
62cd4a59 | 2152 | .op_set_currentstateid = (stateid_setter)nfsd4_set_lockstateid, |
b591480b BF |
2153 | }, |
2154 | [OP_LOCKT] = { | |
2155 | .op_func = (nfsd4op_func)nfsd4_lockt, | |
b001a1b6 | 2156 | .op_name = "OP_LOCKT", |
2282cd2c | 2157 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_lock_rsize, |
b591480b BF |
2158 | }, |
2159 | [OP_LOCKU] = { | |
2160 | .op_func = (nfsd4op_func)nfsd4_locku, | |
58e7b33a | 2161 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2162 | .op_name = "OP_LOCKU", |
58e7b33a | 2163 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, |
62cd4a59 | 2164 | .op_get_currentstateid = (stateid_getter)nfsd4_get_lockustateid, |
b591480b BF |
2165 | }, |
2166 | [OP_LOOKUP] = { | |
2167 | .op_func = (nfsd4op_func)nfsd4_lookup, | |
d1471053 | 2168 | .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, |
b001a1b6 | 2169 | .op_name = "OP_LOOKUP", |
2282cd2c | 2170 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2171 | }, |
2172 | [OP_LOOKUPP] = { | |
2173 | .op_func = (nfsd4op_func)nfsd4_lookupp, | |
d1471053 | 2174 | .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID, |
b001a1b6 | 2175 | .op_name = "OP_LOOKUPP", |
2282cd2c | 2176 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2177 | }, |
2178 | [OP_NVERIFY] = { | |
2179 | .op_func = (nfsd4op_func)nfsd4_nverify, | |
b001a1b6 | 2180 | .op_name = "OP_NVERIFY", |
2282cd2c | 2181 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2182 | }, |
2183 | [OP_OPEN] = { | |
2184 | .op_func = (nfsd4op_func)nfsd4_open, | |
58e7b33a | 2185 | .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, |
b001a1b6 | 2186 | .op_name = "OP_OPEN", |
58e7b33a | 2187 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_open_rsize, |
8b70484c | 2188 | .op_set_currentstateid = (stateid_setter)nfsd4_set_openstateid, |
b591480b BF |
2189 | }, |
2190 | [OP_OPEN_CONFIRM] = { | |
2191 | .op_func = (nfsd4op_func)nfsd4_open_confirm, | |
58e7b33a | 2192 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2193 | .op_name = "OP_OPEN_CONFIRM", |
58e7b33a | 2194 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, |
b591480b BF |
2195 | }, |
2196 | [OP_OPEN_DOWNGRADE] = { | |
2197 | .op_func = (nfsd4op_func)nfsd4_open_downgrade, | |
58e7b33a | 2198 | .op_flags = OP_MODIFIES_SOMETHING, |
b001a1b6 | 2199 | .op_name = "OP_OPEN_DOWNGRADE", |
58e7b33a | 2200 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_status_stateid_rsize, |
9428fe1a TM |
2201 | .op_get_currentstateid = (stateid_getter)nfsd4_get_opendowngradestateid, |
2202 | .op_set_currentstateid = (stateid_setter)nfsd4_set_opendowngradestateid, | |
b591480b BF |
2203 | }, |
2204 | [OP_PUTFH] = { | |
2205 | .op_func = (nfsd4op_func)nfsd4_putfh, | |
68d93184 | 2206 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
5b648699 | 2207 | | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, |
b001a1b6 | 2208 | .op_name = "OP_PUTFH", |
58e7b33a | 2209 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b | 2210 | }, |
eeac294e | 2211 | [OP_PUTPUBFH] = { |
a1c8c4d1 | 2212 | .op_func = (nfsd4op_func)nfsd4_putrootfh, |
68d93184 | 2213 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
5b648699 | 2214 | | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, |
b001a1b6 | 2215 | .op_name = "OP_PUTPUBFH", |
58e7b33a | 2216 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
eeac294e | 2217 | }, |
b591480b BF |
2218 | [OP_PUTROOTFH] = { |
2219 | .op_func = (nfsd4op_func)nfsd4_putrootfh, | |
68d93184 | 2220 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
5b648699 | 2221 | | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID, |
b001a1b6 | 2222 | .op_name = "OP_PUTROOTFH", |
58e7b33a | 2223 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2224 | }, |
2225 | [OP_READ] = { | |
2226 | .op_func = (nfsd4op_func)nfsd4_read, | |
b001a1b6 | 2227 | .op_name = "OP_READ", |
58e7b33a | 2228 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_read_rsize, |
30813e27 | 2229 | .op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid, |
b591480b BF |
2230 | }, |
2231 | [OP_READDIR] = { | |
2232 | .op_func = (nfsd4op_func)nfsd4_readdir, | |
b001a1b6 | 2233 | .op_name = "OP_READDIR", |
58e7b33a | 2234 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_readdir_rsize, |
b591480b BF |
2235 | }, |
2236 | [OP_READLINK] = { | |
2237 | .op_func = (nfsd4op_func)nfsd4_readlink, | |
b001a1b6 | 2238 | .op_name = "OP_READLINK", |
2282cd2c | 2239 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_readlink_rsize, |
b591480b BF |
2240 | }, |
2241 | [OP_REMOVE] = { | |
2242 | .op_func = (nfsd4op_func)nfsd4_remove, | |
c856694e | 2243 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
b001a1b6 | 2244 | .op_name = "OP_REMOVE", |
58e7b33a | 2245 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_remove_rsize, |
b591480b BF |
2246 | }, |
2247 | [OP_RENAME] = { | |
2248 | .op_func = (nfsd4op_func)nfsd4_rename, | |
c856694e | 2249 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
58e7b33a | 2250 | .op_name = "OP_RENAME", |
58e7b33a | 2251 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_rename_rsize, |
b591480b BF |
2252 | }, |
2253 | [OP_RENEW] = { | |
2254 | .op_func = (nfsd4op_func)nfsd4_renew, | |
58e7b33a MJ |
2255 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
2256 | | OP_MODIFIES_SOMETHING, | |
b001a1b6 | 2257 | .op_name = "OP_RENEW", |
58e7b33a MJ |
2258 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
2259 | ||
b591480b BF |
2260 | }, |
2261 | [OP_RESTOREFH] = { | |
2262 | .op_func = (nfsd4op_func)nfsd4_restorefh, | |
68d93184 | 2263 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
58e7b33a | 2264 | | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING, |
b001a1b6 | 2265 | .op_name = "OP_RESTOREFH", |
58e7b33a | 2266 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2267 | }, |
2268 | [OP_SAVEFH] = { | |
2269 | .op_func = (nfsd4op_func)nfsd4_savefh, | |
58e7b33a | 2270 | .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING, |
b001a1b6 | 2271 | .op_name = "OP_SAVEFH", |
58e7b33a | 2272 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b | 2273 | }, |
dcb488a3 AA |
2274 | [OP_SECINFO] = { |
2275 | .op_func = (nfsd4op_func)nfsd4_secinfo, | |
68d93184 | 2276 | .op_flags = OP_HANDLES_WRONGSEC, |
b001a1b6 | 2277 | .op_name = "OP_SECINFO", |
2282cd2c | 2278 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_secinfo_rsize, |
dcb488a3 | 2279 | }, |
b591480b BF |
2280 | [OP_SETATTR] = { |
2281 | .op_func = (nfsd4op_func)nfsd4_setattr, | |
b001a1b6 | 2282 | .op_name = "OP_SETATTR", |
c856694e | 2283 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
58e7b33a | 2284 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_setattr_rsize, |
1e97b519 | 2285 | .op_get_currentstateid = (stateid_getter)nfsd4_get_setattrstateid, |
b591480b BF |
2286 | }, |
2287 | [OP_SETCLIENTID] = { | |
2288 | .op_func = (nfsd4op_func)nfsd4_setclientid, | |
58e7b33a | 2289 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
c856694e | 2290 | | OP_MODIFIES_SOMETHING | OP_CACHEME, |
b001a1b6 | 2291 | .op_name = "OP_SETCLIENTID", |
58e7b33a | 2292 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_setclientid_rsize, |
b591480b BF |
2293 | }, |
2294 | [OP_SETCLIENTID_CONFIRM] = { | |
2295 | .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, | |
58e7b33a | 2296 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
c856694e | 2297 | | OP_MODIFIES_SOMETHING | OP_CACHEME, |
b001a1b6 | 2298 | .op_name = "OP_SETCLIENTID_CONFIRM", |
58e7b33a | 2299 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2300 | }, |
2301 | [OP_VERIFY] = { | |
2302 | .op_func = (nfsd4op_func)nfsd4_verify, | |
b001a1b6 | 2303 | .op_name = "OP_VERIFY", |
2282cd2c | 2304 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b BF |
2305 | }, |
2306 | [OP_WRITE] = { | |
2307 | .op_func = (nfsd4op_func)nfsd4_write, | |
c856694e | 2308 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, |
b001a1b6 | 2309 | .op_name = "OP_WRITE", |
58e7b33a | 2310 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize, |
30813e27 | 2311 | .op_get_currentstateid = (stateid_getter)nfsd4_get_writestateid, |
b591480b BF |
2312 | }, |
2313 | [OP_RELEASE_LOCKOWNER] = { | |
2314 | .op_func = (nfsd4op_func)nfsd4_release_lockowner, | |
58e7b33a MJ |
2315 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS |
2316 | | OP_MODIFIES_SOMETHING, | |
b001a1b6 | 2317 | .op_name = "OP_RELEASE_LOCKOWNER", |
58e7b33a | 2318 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b591480b | 2319 | }, |
069b6ad4 AA |
2320 | |
2321 | /* NFSv4.1 operations */ | |
2322 | [OP_EXCHANGE_ID] = { | |
2323 | .op_func = (nfsd4op_func)nfsd4_exchange_id, | |
58e7b33a MJ |
2324 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
2325 | | OP_MODIFIES_SOMETHING, | |
069b6ad4 | 2326 | .op_name = "OP_EXCHANGE_ID", |
58e7b33a | 2327 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_exchange_id_rsize, |
069b6ad4 | 2328 | }, |
cb73a9f4 BF |
2329 | [OP_BACKCHANNEL_CTL] = { |
2330 | .op_func = (nfsd4op_func)nfsd4_backchannel_ctl, | |
2331 | .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, | |
2332 | .op_name = "OP_BACKCHANNEL_CTL", | |
2333 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, | |
2334 | }, | |
1d1bc8f2 BF |
2335 | [OP_BIND_CONN_TO_SESSION] = { |
2336 | .op_func = (nfsd4op_func)nfsd4_bind_conn_to_session, | |
58e7b33a MJ |
2337 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
2338 | | OP_MODIFIES_SOMETHING, | |
1d1bc8f2 | 2339 | .op_name = "OP_BIND_CONN_TO_SESSION", |
58e7b33a | 2340 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_bind_conn_to_session_rsize, |
1d1bc8f2 | 2341 | }, |
069b6ad4 AA |
2342 | [OP_CREATE_SESSION] = { |
2343 | .op_func = (nfsd4op_func)nfsd4_create_session, | |
58e7b33a MJ |
2344 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
2345 | | OP_MODIFIES_SOMETHING, | |
069b6ad4 | 2346 | .op_name = "OP_CREATE_SESSION", |
58e7b33a | 2347 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_create_session_rsize, |
069b6ad4 AA |
2348 | }, |
2349 | [OP_DESTROY_SESSION] = { | |
2350 | .op_func = (nfsd4op_func)nfsd4_destroy_session, | |
58e7b33a MJ |
2351 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
2352 | | OP_MODIFIES_SOMETHING, | |
069b6ad4 | 2353 | .op_name = "OP_DESTROY_SESSION", |
58e7b33a | 2354 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
069b6ad4 AA |
2355 | }, |
2356 | [OP_SEQUENCE] = { | |
2357 | .op_func = (nfsd4op_func)nfsd4_sequence, | |
f9bb94c4 | 2358 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, |
069b6ad4 | 2359 | .op_name = "OP_SEQUENCE", |
d1d84c96 | 2360 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_sequence_rsize, |
069b6ad4 | 2361 | }, |
094b5d74 | 2362 | [OP_DESTROY_CLIENTID] = { |
345c2842 | 2363 | .op_func = (nfsd4op_func)nfsd4_destroy_clientid, |
58e7b33a MJ |
2364 | .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP |
2365 | | OP_MODIFIES_SOMETHING, | |
094b5d74 | 2366 | .op_name = "OP_DESTROY_CLIENTID", |
58e7b33a | 2367 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
094b5d74 | 2368 | }, |
4dc6ec00 BF |
2369 | [OP_RECLAIM_COMPLETE] = { |
2370 | .op_func = (nfsd4op_func)nfsd4_reclaim_complete, | |
58e7b33a | 2371 | .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, |
4dc6ec00 | 2372 | .op_name = "OP_RECLAIM_COMPLETE", |
58e7b33a | 2373 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
4dc6ec00 | 2374 | }, |
04f4ad16 BF |
2375 | [OP_SECINFO_NO_NAME] = { |
2376 | .op_func = (nfsd4op_func)nfsd4_secinfo_no_name, | |
68d93184 | 2377 | .op_flags = OP_HANDLES_WRONGSEC, |
04f4ad16 | 2378 | .op_name = "OP_SECINFO_NO_NAME", |
2282cd2c | 2379 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_secinfo_rsize, |
04f4ad16 | 2380 | }, |
17456804 BS |
2381 | [OP_TEST_STATEID] = { |
2382 | .op_func = (nfsd4op_func)nfsd4_test_stateid, | |
2383 | .op_flags = ALLOWED_WITHOUT_FH, | |
2384 | .op_name = "OP_TEST_STATEID", | |
2282cd2c | 2385 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_test_stateid_rsize, |
17456804 | 2386 | }, |
e1ca12df BS |
2387 | [OP_FREE_STATEID] = { |
2388 | .op_func = (nfsd4op_func)nfsd4_free_stateid, | |
58e7b33a | 2389 | .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING, |
e1ca12df | 2390 | .op_name = "OP_FREE_STATEID", |
a1dc6955 | 2391 | .op_get_currentstateid = (stateid_getter)nfsd4_get_freestateid, |
58e7b33a | 2392 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
e1ca12df | 2393 | }, |
9cf514cc CH |
2394 | #ifdef CONFIG_NFSD_PNFS |
2395 | [OP_GETDEVICEINFO] = { | |
2396 | .op_func = (nfsd4op_func)nfsd4_getdeviceinfo, | |
2397 | .op_flags = ALLOWED_WITHOUT_FH, | |
2398 | .op_name = "OP_GETDEVICEINFO", | |
2282cd2c | 2399 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_getdeviceinfo_rsize, |
9cf514cc CH |
2400 | }, |
2401 | [OP_LAYOUTGET] = { | |
2402 | .op_func = (nfsd4op_func)nfsd4_layoutget, | |
2403 | .op_flags = OP_MODIFIES_SOMETHING, | |
2404 | .op_name = "OP_LAYOUTGET", | |
2405 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutget_rsize, | |
2406 | }, | |
2407 | [OP_LAYOUTCOMMIT] = { | |
2408 | .op_func = (nfsd4op_func)nfsd4_layoutcommit, | |
2409 | .op_flags = OP_MODIFIES_SOMETHING, | |
2410 | .op_name = "OP_LAYOUTCOMMIT", | |
2411 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutcommit_rsize, | |
2412 | }, | |
2413 | [OP_LAYOUTRETURN] = { | |
2414 | .op_func = (nfsd4op_func)nfsd4_layoutreturn, | |
2415 | .op_flags = OP_MODIFIES_SOMETHING, | |
2416 | .op_name = "OP_LAYOUTRETURN", | |
2417 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_layoutreturn_rsize, | |
2418 | }, | |
2419 | #endif /* CONFIG_NFSD_PNFS */ | |
24bab491 AS |
2420 | |
2421 | /* NFSv4.2 operations */ | |
95d871f0 AS |
2422 | [OP_ALLOCATE] = { |
2423 | .op_func = (nfsd4op_func)nfsd4_allocate, | |
2424 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, | |
2425 | .op_name = "OP_ALLOCATE", | |
beaca234 | 2426 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
95d871f0 | 2427 | }, |
b0cb9085 AS |
2428 | [OP_DEALLOCATE] = { |
2429 | .op_func = (nfsd4op_func)nfsd4_deallocate, | |
2430 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, | |
2431 | .op_name = "OP_DEALLOCATE", | |
beaca234 | 2432 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, |
b0cb9085 | 2433 | }, |
ffa0160a CH |
2434 | [OP_CLONE] = { |
2435 | .op_func = (nfsd4op_func)nfsd4_clone, | |
2436 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, | |
2437 | .op_name = "OP_CLONE", | |
2438 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize, | |
2439 | }, | |
29ae7f9d AS |
2440 | [OP_COPY] = { |
2441 | .op_func = (nfsd4op_func)nfsd4_copy, | |
2442 | .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME, | |
2443 | .op_name = "OP_COPY", | |
2444 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_copy_rsize, | |
2445 | }, | |
24bab491 AS |
2446 | [OP_SEEK] = { |
2447 | .op_func = (nfsd4op_func)nfsd4_seek, | |
2448 | .op_name = "OP_SEEK", | |
2282cd2c | 2449 | .op_rsize_bop = (nfsd4op_rsize)nfsd4_seek_rsize, |
24bab491 | 2450 | }, |
b591480b BF |
2451 | }; |
2452 | ||
ed941643 AE |
2453 | /** |
2454 | * nfsd4_spo_must_allow - Determine if the compound op contains an | |
2455 | * operation that is allowed to be sent with machine credentials | |
2456 | * | |
2457 | * @rqstp: a pointer to the struct svc_rqst | |
2458 | * | |
2459 | * Checks to see if the compound contains a spo_must_allow op | |
2460 | * and confirms that it was sent with the proper machine creds. | |
2461 | */ | |
2462 | ||
2463 | bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) | |
2464 | { | |
2465 | struct nfsd4_compoundres *resp = rqstp->rq_resp; | |
2466 | struct nfsd4_compoundargs *argp = rqstp->rq_argp; | |
2467 | struct nfsd4_op *this = &argp->ops[resp->opcnt - 1]; | |
2468 | struct nfsd4_compound_state *cstate = &resp->cstate; | |
2469 | struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow; | |
2470 | u32 opiter; | |
2471 | ||
2472 | if (!cstate->minorversion) | |
2473 | return false; | |
2474 | ||
2475 | if (cstate->spo_must_allowed == true) | |
2476 | return true; | |
2477 | ||
2478 | opiter = resp->opcnt; | |
2479 | while (opiter < argp->opcnt) { | |
2480 | this = &argp->ops[opiter++]; | |
2481 | if (test_bit(this->opnum, allow->u.longs) && | |
2482 | cstate->clp->cl_mach_cred && | |
2483 | nfsd4_mach_creds_match(cstate->clp, rqstp)) { | |
2484 | cstate->spo_must_allowed = true; | |
2485 | return true; | |
2486 | } | |
2487 | } | |
2488 | cstate->spo_must_allowed = false; | |
2489 | return false; | |
2490 | } | |
2491 | ||
4f0cefbf BF |
2492 | int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op) |
2493 | { | |
05b7278d | 2494 | if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp) |
4f0cefbf | 2495 | return op_encode_hdr_size * sizeof(__be32); |
2282cd2c KM |
2496 | |
2497 | BUG_ON(OPDESC(op)->op_rsize_bop == NULL); | |
2498 | return OPDESC(op)->op_rsize_bop(rqstp, op); | |
4f0cefbf BF |
2499 | } |
2500 | ||
07d1f802 BF |
2501 | void warn_on_nonidempotent_op(struct nfsd4_op *op) |
2502 | { | |
2503 | if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) { | |
2504 | pr_err("unable to encode reply to nonidempotent op %d (%s)\n", | |
2505 | op->opnum, nfsd4_op_name(op->opnum)); | |
2506 | WARN_ON_ONCE(1); | |
2507 | } | |
2508 | } | |
2509 | ||
f1c7f79b | 2510 | static const char *nfsd4_op_name(unsigned opnum) |
b001a1b6 BH |
2511 | { |
2512 | if (opnum < ARRAY_SIZE(nfsd4_ops)) | |
2513 | return nfsd4_ops[opnum].op_name; | |
2514 | return "unknown_operation"; | |
2515 | } | |
2516 | ||
1da177e4 | 2517 | #define nfsd4_voidres nfsd4_voidargs |
1da177e4 LT |
2518 | struct nfsd4_voidargs { int dummy; }; |
2519 | ||
1da177e4 | 2520 | static struct svc_procedure nfsd_procedures4[2] = { |
0a93a47f | 2521 | [NFSPROC4_NULL] = { |
f7235b6b | 2522 | .pc_func = nfsd4_proc_null, |
0a93a47f YZ |
2523 | .pc_encode = (kxdrproc_t) nfs4svc_encode_voidres, |
2524 | .pc_argsize = sizeof(struct nfsd4_voidargs), | |
2525 | .pc_ressize = sizeof(struct nfsd4_voidres), | |
2526 | .pc_cachetype = RC_NOCACHE, | |
2527 | .pc_xdrressize = 1, | |
2528 | }, | |
2529 | [NFSPROC4_COMPOUND] = { | |
f7235b6b | 2530 | .pc_func = nfsd4_proc_compound, |
026fec7e | 2531 | .pc_decode = nfs4svc_decode_compoundargs, |
0a93a47f YZ |
2532 | .pc_encode = (kxdrproc_t) nfs4svc_encode_compoundres, |
2533 | .pc_argsize = sizeof(struct nfsd4_compoundargs), | |
2534 | .pc_ressize = sizeof(struct nfsd4_compoundres), | |
3e98abff | 2535 | .pc_release = nfsd4_release_compoundargs, |
0a93a47f YZ |
2536 | .pc_cachetype = RC_NOCACHE, |
2537 | .pc_xdrressize = NFSD_BUFSIZE/4, | |
2538 | }, | |
1da177e4 LT |
2539 | }; |
2540 | ||
2541 | struct svc_version nfsd_version4 = { | |
5283b03e JL |
2542 | .vs_vers = 4, |
2543 | .vs_nproc = 2, | |
2544 | .vs_proc = nfsd_procedures4, | |
2545 | .vs_dispatch = nfsd_dispatch, | |
2546 | .vs_xdrsize = NFS4_SVC_XDRSIZE, | |
2547 | .vs_rpcb_optnl = true, | |
2548 | .vs_need_cong_ctrl = true, | |
1da177e4 LT |
2549 | }; |
2550 | ||
2551 | /* | |
2552 | * Local variables: | |
2553 | * c-basic-offset: 8 | |
2554 | * End: | |
2555 | */ |