blob: 1dface03bd3e5b1ae22d4be3b9ba8bf2e9a6a94c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Server-side XDR 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.
34 *
35 * TODO: Neil Brown made the following observation: We currently
36 * initially reserve NFSD_BUFSIZE space on the transmit queue and
37 * never release any of that until the request is complete.
38 * It would be good to calculate a new maximum response size while
39 * decoding the COMPOUND, and call svc_reserve with this number
40 * at the end of nfs4svc_decode_compoundargs.
41 */
42
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/namei.h>
Boaz Harrosh341eb182009-12-03 20:29:12 +020045#include <linux/statfs.h>
Andy Adamson0733d212009-04-03 08:28:01 +030046#include <linux/utsname.h>
Bryan Schumaker17456802011-07-13 10:50:48 -040047#include <linux/pagemap.h>
J. Bruce Fields4796f452007-07-17 04:04:51 -070048#include <linux/sunrpc/svcauth_gss.h>
Boaz Harrosh9a74af22009-12-03 20:30:56 +020049
J. Bruce Fields2ca72e12011-01-04 17:37:15 -050050#include "idmap.h"
51#include "acl.h"
Boaz Harrosh9a74af22009-12-03 20:30:56 +020052#include "xdr4.h"
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050053#include "vfs.h"
Bryan Schumaker17456802011-07-13 10:50:48 -040054#include "state.h"
J. Bruce Fields10910062011-01-24 12:11:02 -050055#include "cache.h"
Stanislav Kinsbursky3d733712012-11-27 14:11:44 +030056#include "netns.h"
J. Bruce Fields2ca72e12011-01-04 17:37:15 -050057
David Quigley18032ca2013-05-02 13:19:10 -040058#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
59#include <linux/security.h>
60#endif
61
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define NFSDDBG_FACILITY NFSDDBG_XDR
64
J.Bruce Fields42ca0992006-10-04 02:16:20 -070065/*
66 * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
67 * directory in order to indicate to the client that a filesystem boundary is present
68 * We use a fixed fsid for a referral
69 */
70#define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
71#define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
72
Al Virob37ad282006-10-19 23:28:59 -070073static __be32
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -050074check_filename(char *str, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 int i;
77
78 if (len == 0)
79 return nfserr_inval;
80 if (isdotent(str, len))
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -050081 return nfserr_badname;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 for (i = 0; i < len; i++)
83 if (str[i] == '/')
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -050084 return nfserr_badname;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 return 0;
86}
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define DECODE_HEAD \
Al Viro2ebbc012006-10-19 23:28:58 -070089 __be32 *p; \
Al Virob37ad282006-10-19 23:28:59 -070090 __be32 status
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define DECODE_TAIL \
92 status = 0; \
93out: \
94 return status; \
95xdr_error: \
Chuck Lever817cb9d2007-09-11 18:01:20 -040096 dprintk("NFSD: xdr error (%s:%d)\n", \
97 __FILE__, __LINE__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 status = nfserr_bad_xdr; \
99 goto out
100
101#define READ32(x) (x) = ntohl(*p++)
102#define READ64(x) do { \
103 (x) = (u64)ntohl(*p++) << 32; \
104 (x) |= ntohl(*p++); \
105} while (0)
106#define READTIME(x) do { \
107 p++; \
108 (x) = ntohl(*p++); \
109 p++; \
110} while (0)
111#define READMEM(x,nbytes) do { \
112 x = (char *)p; \
113 p += XDR_QUADLEN(nbytes); \
114} while (0)
115#define SAVEMEM(x,nbytes) do { \
116 if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
117 savemem(argp, p, nbytes) : \
118 (char *)p)) { \
Chuck Lever817cb9d2007-09-11 18:01:20 -0400119 dprintk("NFSD: xdr error (%s:%d)\n", \
120 __FILE__, __LINE__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 goto xdr_error; \
122 } \
123 p += XDR_QUADLEN(nbytes); \
124} while (0)
125#define COPYMEM(x,nbytes) do { \
126 memcpy((x), p, nbytes); \
127 p += XDR_QUADLEN(nbytes); \
128} while (0)
129
130/* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
131#define READ_BUF(nbytes) do { \
132 if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
133 p = argp->p; \
134 argp->p += XDR_QUADLEN(nbytes); \
135 } else if (!(p = read_buf(argp, nbytes))) { \
Chuck Lever817cb9d2007-09-11 18:01:20 -0400136 dprintk("NFSD: xdr error (%s:%d)\n", \
137 __FILE__, __LINE__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 goto xdr_error; \
139 } \
140} while (0)
141
J. Bruce Fields590b7432013-06-21 17:06:29 -0400142static void next_decode_page(struct nfsd4_compoundargs *argp)
143{
J. Bruce Fields590b7432013-06-21 17:06:29 -0400144 argp->p = page_address(argp->pagelist[0]);
J. Bruce Fields365da4a2013-11-19 17:32:43 -0500145 argp->pagelist++;
J. Bruce Fields590b7432013-06-21 17:06:29 -0400146 if (argp->pagelen < PAGE_SIZE) {
147 argp->end = argp->p + (argp->pagelen>>2);
148 argp->pagelen = 0;
149 } else {
150 argp->end = argp->p + (PAGE_SIZE>>2);
151 argp->pagelen -= PAGE_SIZE;
152 }
153}
154
J. Bruce Fieldsca2a05a2007-11-11 15:43:12 -0500155static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 /* We want more bytes than seem to be available.
158 * Maybe we need a new page, maybe we have just run out
159 */
J. Bruce Fieldsca2a05a2007-11-11 15:43:12 -0500160 unsigned int avail = (char *)argp->end - (char *)argp->p;
Al Viro2ebbc012006-10-19 23:28:58 -0700161 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 if (avail + argp->pagelen < nbytes)
163 return NULL;
164 if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */
165 return NULL;
166 /* ok, we can do it with the current plus the next page */
167 if (nbytes <= sizeof(argp->tmp))
168 p = argp->tmp;
169 else {
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800170 kfree(argp->tmpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL);
172 if (!p)
173 return NULL;
174
175 }
J. Bruce Fieldsca2a05a2007-11-11 15:43:12 -0500176 /*
177 * The following memcpy is safe because read_buf is always
178 * called with nbytes > avail, and the two cases above both
179 * guarantee p points to at least nbytes bytes.
180 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 memcpy(p, argp->p, avail);
J. Bruce Fields590b7432013-06-21 17:06:29 -0400182 next_decode_page(argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 memcpy(((char*)p)+avail, argp->p, (nbytes - avail));
184 argp->p += XDR_QUADLEN(nbytes - avail);
185 return p;
186}
187
Andy Adamson60adfc52009-04-03 08:28:50 +0300188static int zero_clientid(clientid_t *clid)
189{
190 return (clid->cl_boot == 0) && (clid->cl_id == 0);
191}
192
Christoph Hellwig2d8498d2013-11-20 00:24:11 -0800193/**
194 * defer_free - mark an allocation as deferred freed
195 * @argp: NFSv4 compound argument structure to be freed with
196 * @release: release callback to free @p, typically kfree()
197 * @p: pointer to be freed
198 *
199 * Marks @p to be freed when processing the compound operation
200 * described in @argp finishes.
201 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static int
203defer_free(struct nfsd4_compoundargs *argp,
204 void (*release)(const void *), void *p)
205{
206 struct tmpbuf *tb;
207
208 tb = kmalloc(sizeof(*tb), GFP_KERNEL);
209 if (!tb)
210 return -ENOMEM;
211 tb->buf = p;
212 tb->release = release;
213 tb->next = argp->to_free;
214 argp->to_free = tb;
215 return 0;
216}
217
Christoph Hellwig2d8498d2013-11-20 00:24:11 -0800218/**
219 * savemem - duplicate a chunk of memory for later processing
220 * @argp: NFSv4 compound argument structure to be freed with
221 * @p: pointer to be duplicated
222 * @nbytes: length to be duplicated
223 *
224 * Returns a pointer to a copy of @nbytes bytes of memory at @p
225 * that are preserved until processing of the NFSv4 compound
226 * operation described by @argp finishes.
227 */
Al Viro2ebbc012006-10-19 23:28:58 -0700228static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (p == argp->tmp) {
Thomas Meyer67114fe2011-11-17 23:43:40 +0100231 p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
J. Bruce Fieldsa4db5fe2007-02-16 01:28:30 -0800232 if (!p)
233 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 } else {
Eric Sesterhenn73dff8b2006-10-03 23:37:14 +0200235 BUG_ON(p != argp->tmpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 argp->tmpp = NULL;
237 }
238 if (defer_free(argp, kfree, p)) {
J. Bruce Fieldsa4db5fe2007-02-16 01:28:30 -0800239 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 return NULL;
241 } else
242 return (char *)p;
243}
244
Al Virob37ad282006-10-19 23:28:59 -0700245static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
247{
248 u32 bmlen;
249 DECODE_HEAD;
250
251 bmval[0] = 0;
252 bmval[1] = 0;
Andy Adamson7e705702009-04-03 08:29:11 +0300253 bmval[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 READ_BUF(4);
256 READ32(bmlen);
257 if (bmlen > 1000)
258 goto xdr_error;
259
260 READ_BUF(bmlen << 2);
261 if (bmlen > 0)
262 READ32(bmval[0]);
263 if (bmlen > 1)
264 READ32(bmval[1]);
Andy Adamson7e705702009-04-03 08:29:11 +0300265 if (bmlen > 2)
266 READ32(bmval[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 DECODE_TAIL;
269}
270
Al Virob37ad282006-10-19 23:28:59 -0700271static __be32
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800272nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
David Quigley18032ca2013-05-02 13:19:10 -0400273 struct iattr *iattr, struct nfs4_acl **acl,
274 struct xdr_netobj *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
276 int expected_len, len = 0;
277 u32 dummy32;
278 char *buf;
Al Virob8dd7b92006-10-19 23:29:01 -0700279 int host_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 DECODE_HEAD;
282 iattr->ia_valid = 0;
283 if ((status = nfsd4_decode_bitmap(argp, bmval)))
284 return status;
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 READ_BUF(4);
287 READ32(expected_len);
288
289 if (bmval[0] & FATTR4_WORD0_SIZE) {
290 READ_BUF(8);
291 len += 8;
292 READ64(iattr->ia_size);
293 iattr->ia_valid |= ATTR_SIZE;
294 }
295 if (bmval[0] & FATTR4_WORD0_ACL) {
J. Bruce Fields64a817c2013-03-26 14:11:13 -0400296 u32 nace;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800297 struct nfs4_ace *ace;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 READ_BUF(4); len += 4;
300 READ32(nace);
301
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800302 if (nace > NFS4_ACL_MAX)
303 return nfserr_resource;
304
305 *acl = nfs4_acl_new(nace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (*acl == NULL) {
Al Virob8dd7b92006-10-19 23:29:01 -0700307 host_err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 goto out_nfserr;
309 }
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800310 defer_free(argp, kfree, *acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800312 (*acl)->naces = nace;
313 for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 READ_BUF(16); len += 16;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800315 READ32(ace->type);
316 READ32(ace->flag);
317 READ32(ace->access_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 READ32(dummy32);
319 READ_BUF(dummy32);
320 len += XDR_QUADLEN(dummy32) << 2;
321 READMEM(buf, dummy32);
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800322 ace->whotype = nfs4_acl_get_whotype(buf, dummy32);
J. Bruce Fields3c726022011-01-04 17:53:52 -0500323 status = nfs_ok;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800324 if (ace->whotype != NFS4_ACL_WHO_NAMED)
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -0800325 ;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800326 else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
J. Bruce Fields3c726022011-01-04 17:53:52 -0500327 status = nfsd_map_name_to_gid(argp->rqstp,
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -0800328 buf, dummy32, &ace->who_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 else
J. Bruce Fields3c726022011-01-04 17:53:52 -0500330 status = nfsd_map_name_to_uid(argp->rqstp,
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -0800331 buf, dummy32, &ace->who_uid);
J. Bruce Fields3c726022011-01-04 17:53:52 -0500332 if (status)
333 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 }
335 } else
336 *acl = NULL;
337 if (bmval[1] & FATTR4_WORD1_MODE) {
338 READ_BUF(4);
339 len += 4;
340 READ32(iattr->ia_mode);
341 iattr->ia_mode &= (S_IFMT | S_IALLUGO);
342 iattr->ia_valid |= ATTR_MODE;
343 }
344 if (bmval[1] & FATTR4_WORD1_OWNER) {
345 READ_BUF(4);
346 len += 4;
347 READ32(dummy32);
348 READ_BUF(dummy32);
349 len += (XDR_QUADLEN(dummy32) << 2);
350 READMEM(buf, dummy32);
NeilBrown47c85292011-02-16 13:08:35 +1100351 if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid)))
352 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 iattr->ia_valid |= ATTR_UID;
354 }
355 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
356 READ_BUF(4);
357 len += 4;
358 READ32(dummy32);
359 READ_BUF(dummy32);
360 len += (XDR_QUADLEN(dummy32) << 2);
361 READMEM(buf, dummy32);
NeilBrown47c85292011-02-16 13:08:35 +1100362 if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid)))
363 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 iattr->ia_valid |= ATTR_GID;
365 }
366 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
367 READ_BUF(4);
368 len += 4;
369 READ32(dummy32);
370 switch (dummy32) {
371 case NFS4_SET_TO_CLIENT_TIME:
372 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
373 all 32 bits of 'nseconds'. */
374 READ_BUF(12);
375 len += 12;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -0400376 READ64(iattr->ia_atime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 READ32(iattr->ia_atime.tv_nsec);
378 if (iattr->ia_atime.tv_nsec >= (u32)1000000000)
379 return nfserr_inval;
380 iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
381 break;
382 case NFS4_SET_TO_SERVER_TIME:
383 iattr->ia_valid |= ATTR_ATIME;
384 break;
385 default:
386 goto xdr_error;
387 }
388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
390 READ_BUF(4);
391 len += 4;
392 READ32(dummy32);
393 switch (dummy32) {
394 case NFS4_SET_TO_CLIENT_TIME:
395 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
396 all 32 bits of 'nseconds'. */
397 READ_BUF(12);
398 len += 12;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -0400399 READ64(iattr->ia_mtime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 READ32(iattr->ia_mtime.tv_nsec);
401 if (iattr->ia_mtime.tv_nsec >= (u32)1000000000)
402 return nfserr_inval;
403 iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
404 break;
405 case NFS4_SET_TO_SERVER_TIME:
406 iattr->ia_valid |= ATTR_MTIME;
407 break;
408 default:
409 goto xdr_error;
410 }
411 }
David Quigley18032ca2013-05-02 13:19:10 -0400412
413 label->len = 0;
414#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
415 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
416 READ_BUF(4);
417 len += 4;
418 READ32(dummy32); /* lfs: we don't use it */
419 READ_BUF(4);
420 len += 4;
421 READ32(dummy32); /* pi: we don't use it either */
422 READ_BUF(4);
423 len += 4;
424 READ32(dummy32);
425 READ_BUF(dummy32);
426 if (dummy32 > NFSD4_MAX_SEC_LABEL_LEN)
427 return nfserr_badlabel;
428 len += (XDR_QUADLEN(dummy32) << 2);
429 READMEM(buf, dummy32);
430 label->data = kzalloc(dummy32 + 1, GFP_KERNEL);
431 if (!label->data)
432 return nfserr_jukebox;
J. Bruce Fields3378b7f2013-11-01 10:42:15 -0400433 label->len = dummy32;
David Quigley18032ca2013-05-02 13:19:10 -0400434 defer_free(argp, kfree, label->data);
435 memcpy(label->data, buf, dummy32);
436 }
437#endif
438
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800439 if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
440 || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
441 || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2)
442 READ_BUF(expected_len - len);
443 else if (len != expected_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 goto xdr_error;
445
446 DECODE_TAIL;
447
448out_nfserr:
Al Virob8dd7b92006-10-19 23:29:01 -0700449 status = nfserrno(host_err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 goto out;
451}
452
Al Virob37ad282006-10-19 23:28:59 -0700453static __be32
Benny Halevye31a1b62008-08-12 20:46:18 +0300454nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
455{
456 DECODE_HEAD;
457
458 READ_BUF(sizeof(stateid_t));
459 READ32(sid->si_generation);
460 COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
461
462 DECODE_TAIL;
463}
464
465static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
467{
468 DECODE_HEAD;
469
470 READ_BUF(4);
471 READ32(access->ac_req_access);
472
473 DECODE_TAIL;
474}
475
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400476static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs)
477{
478 DECODE_HEAD;
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500479 u32 dummy, uid, gid;
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400480 char *machine_name;
481 int i;
482 int nr_secflavs;
483
484 /* callback_sec_params4 */
485 READ_BUF(4);
486 READ32(nr_secflavs);
J. Bruce Fields57569a72013-05-17 16:25:32 -0400487 if (nr_secflavs)
488 cbs->flavor = (u32)(-1);
489 else
490 /* Is this legal? Be generous, take it to mean AUTH_NONE: */
491 cbs->flavor = 0;
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400492 for (i = 0; i < nr_secflavs; ++i) {
493 READ_BUF(4);
494 READ32(dummy);
495 switch (dummy) {
496 case RPC_AUTH_NULL:
497 /* Nothing to read */
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500498 if (cbs->flavor == (u32)(-1))
499 cbs->flavor = RPC_AUTH_NULL;
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400500 break;
501 case RPC_AUTH_UNIX:
502 READ_BUF(8);
503 /* stamp */
504 READ32(dummy);
505
506 /* machine name */
507 READ32(dummy);
508 READ_BUF(dummy);
509 SAVEMEM(machine_name, dummy);
510
511 /* uid, gid */
512 READ_BUF(8);
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500513 READ32(uid);
514 READ32(gid);
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400515
516 /* more gids */
517 READ_BUF(4);
518 READ32(dummy);
519 READ_BUF(dummy * 4);
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500520 if (cbs->flavor == (u32)(-1)) {
Eric W. Biederman03bc6d12013-02-02 06:24:49 -0800521 kuid_t kuid = make_kuid(&init_user_ns, uid);
522 kgid_t kgid = make_kgid(&init_user_ns, gid);
523 if (uid_valid(kuid) && gid_valid(kgid)) {
524 cbs->uid = kuid;
525 cbs->gid = kgid;
526 cbs->flavor = RPC_AUTH_UNIX;
527 } else {
528 dprintk("RPC_AUTH_UNIX with invalid"
529 "uid or gid ignoring!\n");
530 }
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500531 }
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400532 break;
533 case RPC_AUTH_GSS:
534 dprintk("RPC_AUTH_GSS callback secflavor "
535 "not supported!\n");
536 READ_BUF(8);
537 /* gcbp_service */
538 READ32(dummy);
539 /* gcbp_handle_from_server */
540 READ32(dummy);
541 READ_BUF(dummy);
542 p += XDR_QUADLEN(dummy);
543 /* gcbp_handle_from_client */
544 READ_BUF(4);
545 READ32(dummy);
546 READ_BUF(dummy);
547 break;
548 default:
549 dprintk("Illegal callback secflavor\n");
550 return nfserr_inval;
551 }
552 }
553 DECODE_TAIL;
554}
555
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -0400556static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc)
557{
558 DECODE_HEAD;
559
560 READ_BUF(4);
561 READ32(bc->bc_cb_program);
562 nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec);
563
564 DECODE_TAIL;
565}
566
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -0400567static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts)
568{
569 DECODE_HEAD;
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -0400570
571 READ_BUF(NFS4_MAX_SESSIONID_LEN + 8);
572 COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
573 READ32(bcts->dir);
Bryan Schumaker6ce23572011-04-27 15:47:16 -0400574 /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker
575 * could help us figure out we should be using it. */
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -0400576 DECODE_TAIL;
577}
578
Al Virob37ad282006-10-19 23:28:59 -0700579static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
581{
582 DECODE_HEAD;
583
Benny Halevye31a1b62008-08-12 20:46:18 +0300584 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 READ32(close->cl_seqid);
Benny Halevye31a1b62008-08-12 20:46:18 +0300586 return nfsd4_decode_stateid(argp, &close->cl_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 DECODE_TAIL;
589}
590
591
Al Virob37ad282006-10-19 23:28:59 -0700592static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit)
594{
595 DECODE_HEAD;
596
597 READ_BUF(12);
598 READ64(commit->co_offset);
599 READ32(commit->co_count);
600
601 DECODE_TAIL;
602}
603
Al Virob37ad282006-10-19 23:28:59 -0700604static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
606{
607 DECODE_HEAD;
608
609 READ_BUF(4);
610 READ32(create->cr_type);
611 switch (create->cr_type) {
612 case NF4LNK:
613 READ_BUF(4);
614 READ32(create->cr_linklen);
615 READ_BUF(create->cr_linklen);
616 SAVEMEM(create->cr_linkname, create->cr_linklen);
617 break;
618 case NF4BLK:
619 case NF4CHR:
620 READ_BUF(8);
621 READ32(create->cr_specdata1);
622 READ32(create->cr_specdata2);
623 break;
624 case NF4SOCK:
625 case NF4FIFO:
626 case NF4DIR:
627 default:
628 break;
629 }
630
631 READ_BUF(4);
632 READ32(create->cr_namelen);
633 READ_BUF(create->cr_namelen);
634 SAVEMEM(create->cr_name, create->cr_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500635 if ((status = check_filename(create->cr_name, create->cr_namelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 return status;
637
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800638 status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
David Quigley18032ca2013-05-02 13:19:10 -0400639 &create->cr_acl, &create->cr_label);
Benny Halevyc0d6fc82009-04-03 08:29:05 +0300640 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 goto out;
642
643 DECODE_TAIL;
644}
645
Al Virob37ad282006-10-19 23:28:59 -0700646static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
648{
Benny Halevye31a1b62008-08-12 20:46:18 +0300649 return nfsd4_decode_stateid(argp, &dr->dr_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
Al Virob37ad282006-10-19 23:28:59 -0700652static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr)
654{
655 return nfsd4_decode_bitmap(argp, getattr->ga_bmval);
656}
657
Al Virob37ad282006-10-19 23:28:59 -0700658static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link)
660{
661 DECODE_HEAD;
662
663 READ_BUF(4);
664 READ32(link->li_namelen);
665 READ_BUF(link->li_namelen);
666 SAVEMEM(link->li_name, link->li_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500667 if ((status = check_filename(link->li_name, link->li_namelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return status;
669
670 DECODE_TAIL;
671}
672
Al Virob37ad282006-10-19 23:28:59 -0700673static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
675{
676 DECODE_HEAD;
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /*
679 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
680 */
681 READ_BUF(28);
682 READ32(lock->lk_type);
683 if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
684 goto xdr_error;
685 READ32(lock->lk_reclaim);
686 READ64(lock->lk_offset);
687 READ64(lock->lk_length);
688 READ32(lock->lk_is_new);
689
690 if (lock->lk_is_new) {
Benny Halevye31a1b62008-08-12 20:46:18 +0300691 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 READ32(lock->lk_new_open_seqid);
Benny Halevye31a1b62008-08-12 20:46:18 +0300693 status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
694 if (status)
695 return status;
696 READ_BUF(8 + sizeof(clientid_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 READ32(lock->lk_new_lock_seqid);
698 COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
699 READ32(lock->lk_new_owner.len);
700 READ_BUF(lock->lk_new_owner.len);
701 READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
702 } else {
Benny Halevye31a1b62008-08-12 20:46:18 +0300703 status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
704 if (status)
705 return status;
706 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 READ32(lock->lk_old_lock_seqid);
708 }
709
710 DECODE_TAIL;
711}
712
Al Virob37ad282006-10-19 23:28:59 -0700713static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt)
715{
716 DECODE_HEAD;
717
718 READ_BUF(32);
719 READ32(lockt->lt_type);
720 if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
721 goto xdr_error;
722 READ64(lockt->lt_offset);
723 READ64(lockt->lt_length);
724 COPYMEM(&lockt->lt_clientid, 8);
725 READ32(lockt->lt_owner.len);
726 READ_BUF(lockt->lt_owner.len);
727 READMEM(lockt->lt_owner.data, lockt->lt_owner.len);
728
729 DECODE_TAIL;
730}
731
Al Virob37ad282006-10-19 23:28:59 -0700732static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
734{
735 DECODE_HEAD;
736
Benny Halevye31a1b62008-08-12 20:46:18 +0300737 READ_BUF(8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 READ32(locku->lu_type);
739 if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
740 goto xdr_error;
741 READ32(locku->lu_seqid);
Benny Halevye31a1b62008-08-12 20:46:18 +0300742 status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
743 if (status)
744 return status;
745 READ_BUF(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 READ64(locku->lu_offset);
747 READ64(locku->lu_length);
748
749 DECODE_TAIL;
750}
751
Al Virob37ad282006-10-19 23:28:59 -0700752static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup)
754{
755 DECODE_HEAD;
756
757 READ_BUF(4);
758 READ32(lookup->lo_len);
759 READ_BUF(lookup->lo_len);
760 SAVEMEM(lookup->lo_name, lookup->lo_len);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500761 if ((status = check_filename(lookup->lo_name, lookup->lo_len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 return status;
763
764 DECODE_TAIL;
765}
766
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200767static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when)
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400768{
769 __be32 *p;
770 u32 w;
771
772 READ_BUF(4);
773 READ32(w);
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200774 *share_access = w & NFS4_SHARE_ACCESS_MASK;
775 *deleg_want = w & NFS4_SHARE_WANT_MASK;
776 if (deleg_when)
777 *deleg_when = w & NFS4_SHARE_WHEN_MASK;
778
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400779 switch (w & NFS4_SHARE_ACCESS_MASK) {
780 case NFS4_SHARE_ACCESS_READ:
781 case NFS4_SHARE_ACCESS_WRITE:
782 case NFS4_SHARE_ACCESS_BOTH:
783 break;
784 default:
785 return nfserr_bad_xdr;
786 }
Benny Halevyfc0d14f2011-10-27 20:43:01 +0200787 w &= ~NFS4_SHARE_ACCESS_MASK;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400788 if (!w)
789 return nfs_ok;
790 if (!argp->minorversion)
791 return nfserr_bad_xdr;
792 switch (w & NFS4_SHARE_WANT_MASK) {
793 case NFS4_SHARE_WANT_NO_PREFERENCE:
794 case NFS4_SHARE_WANT_READ_DELEG:
795 case NFS4_SHARE_WANT_WRITE_DELEG:
796 case NFS4_SHARE_WANT_ANY_DELEG:
797 case NFS4_SHARE_WANT_NO_DELEG:
798 case NFS4_SHARE_WANT_CANCEL:
799 break;
800 default:
801 return nfserr_bad_xdr;
802 }
Benny Halevy92bac8c2011-10-19 19:13:29 -0700803 w &= ~NFS4_SHARE_WANT_MASK;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400804 if (!w)
805 return nfs_ok;
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200806
807 if (!deleg_when) /* open_downgrade */
808 return nfserr_inval;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400809 switch (w) {
810 case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL:
811 case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED:
Benny Halevyc668fc62011-10-19 19:13:13 -0700812 case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL |
813 NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED):
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400814 return nfs_ok;
815 }
816xdr_error:
817 return nfserr_bad_xdr;
818}
819
820static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x)
821{
822 __be32 *p;
823
824 READ_BUF(4);
825 READ32(*x);
826 /* Note: unlinke access bits, deny bits may be zero. */
Dan Carpenter01cd4af2011-10-17 10:41:17 +0300827 if (*x & ~NFS4_SHARE_DENY_BOTH)
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400828 return nfserr_bad_xdr;
829 return nfs_ok;
830xdr_error:
831 return nfserr_bad_xdr;
832}
833
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -0400834static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o)
835{
836 __be32 *p;
837
838 READ_BUF(4);
839 READ32(o->len);
840
841 if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT)
842 return nfserr_bad_xdr;
843
844 READ_BUF(o->len);
845 SAVEMEM(o->data, o->len);
846 return nfs_ok;
847xdr_error:
848 return nfserr_bad_xdr;
849}
850
Al Virob37ad282006-10-19 23:28:59 -0700851static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
853{
854 DECODE_HEAD;
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200855 u32 dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857 memset(open->op_bmval, 0, sizeof(open->op_bmval));
858 open->op_iattr.ia_valid = 0;
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400859 open->op_openowner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800861 open->op_xdr_error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /* seqid, share_access, share_deny, clientid, ownerlen */
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400863 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 READ32(open->op_seqid);
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200865 /* decode, yet ignore deleg_when until supported */
866 status = nfsd4_decode_share_access(argp, &open->op_share_access,
867 &open->op_deleg_want, &dummy);
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400868 if (status)
869 goto xdr_error;
870 status = nfsd4_decode_share_deny(argp, &open->op_share_deny);
871 if (status)
872 goto xdr_error;
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -0400873 READ_BUF(sizeof(clientid_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 COPYMEM(&open->op_clientid, sizeof(clientid_t));
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -0400875 status = nfsd4_decode_opaque(argp, &open->op_owner);
876 if (status)
877 goto xdr_error;
878 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 READ32(open->op_create);
880 switch (open->op_create) {
881 case NFS4_OPEN_NOCREATE:
882 break;
883 case NFS4_OPEN_CREATE:
884 READ_BUF(4);
885 READ32(open->op_createmode);
886 switch (open->op_createmode) {
887 case NFS4_CREATE_UNCHECKED:
888 case NFS4_CREATE_GUARDED:
Benny Halevyc0d6fc82009-04-03 08:29:05 +0300889 status = nfsd4_decode_fattr(argp, open->op_bmval,
David Quigley18032ca2013-05-02 13:19:10 -0400890 &open->op_iattr, &open->op_acl, &open->op_label);
Benny Halevyc0d6fc82009-04-03 08:29:05 +0300891 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 goto out;
893 break;
894 case NFS4_CREATE_EXCLUSIVE:
Chuck Leverab4684d2012-03-02 17:13:50 -0500895 READ_BUF(NFS4_VERIFIER_SIZE);
896 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 break;
Benny Halevy79fb54a2009-04-03 08:29:17 +0300898 case NFS4_CREATE_EXCLUSIVE4_1:
899 if (argp->minorversion < 1)
900 goto xdr_error;
Chuck Leverab4684d2012-03-02 17:13:50 -0500901 READ_BUF(NFS4_VERIFIER_SIZE);
902 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
Benny Halevy79fb54a2009-04-03 08:29:17 +0300903 status = nfsd4_decode_fattr(argp, open->op_bmval,
David Quigley18032ca2013-05-02 13:19:10 -0400904 &open->op_iattr, &open->op_acl, &open->op_label);
Benny Halevy79fb54a2009-04-03 08:29:17 +0300905 if (status)
906 goto out;
907 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 default:
909 goto xdr_error;
910 }
911 break;
912 default:
913 goto xdr_error;
914 }
915
916 /* open_claim */
917 READ_BUF(4);
918 READ32(open->op_claim_type);
919 switch (open->op_claim_type) {
920 case NFS4_OPEN_CLAIM_NULL:
921 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
922 READ_BUF(4);
923 READ32(open->op_fname.len);
924 READ_BUF(open->op_fname.len);
925 SAVEMEM(open->op_fname.data, open->op_fname.len);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500926 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 return status;
928 break;
929 case NFS4_OPEN_CLAIM_PREVIOUS:
930 READ_BUF(4);
931 READ32(open->op_delegate_type);
932 break;
933 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
Benny Halevye31a1b62008-08-12 20:46:18 +0300934 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
935 if (status)
936 return status;
937 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 READ32(open->op_fname.len);
939 READ_BUF(open->op_fname.len);
940 SAVEMEM(open->op_fname.data, open->op_fname.len);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500941 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 return status;
943 break;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400944 case NFS4_OPEN_CLAIM_FH:
945 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
946 if (argp->minorversion < 1)
947 goto xdr_error;
948 /* void */
949 break;
950 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
951 if (argp->minorversion < 1)
952 goto xdr_error;
953 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
954 if (status)
955 return status;
956 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 default:
958 goto xdr_error;
959 }
960
961 DECODE_TAIL;
962}
963
Al Virob37ad282006-10-19 23:28:59 -0700964static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
966{
967 DECODE_HEAD;
Anna Schumakere1a90eb2013-10-30 10:00:20 -0400968
969 if (argp->minorversion >= 1)
970 return nfserr_notsupp;
971
Benny Halevye31a1b62008-08-12 20:46:18 +0300972 status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
973 if (status)
974 return status;
975 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 READ32(open_conf->oc_seqid);
Anna Schumakere1a90eb2013-10-30 10:00:20 -0400977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 DECODE_TAIL;
979}
980
Al Virob37ad282006-10-19 23:28:59 -0700981static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down)
983{
984 DECODE_HEAD;
985
Benny Halevye31a1b62008-08-12 20:46:18 +0300986 status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
987 if (status)
988 return status;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400989 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 READ32(open_down->od_seqid);
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200991 status = nfsd4_decode_share_access(argp, &open_down->od_share_access,
992 &open_down->od_deleg_want, NULL);
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400993 if (status)
994 return status;
995 status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny);
996 if (status)
997 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 DECODE_TAIL;
999}
1000
Al Virob37ad282006-10-19 23:28:59 -07001001static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
1003{
1004 DECODE_HEAD;
1005
1006 READ_BUF(4);
1007 READ32(putfh->pf_fhlen);
1008 if (putfh->pf_fhlen > NFS4_FHSIZE)
1009 goto xdr_error;
1010 READ_BUF(putfh->pf_fhlen);
1011 SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen);
1012
1013 DECODE_TAIL;
1014}
1015
Al Virob37ad282006-10-19 23:28:59 -07001016static __be32
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001017nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p)
1018{
1019 if (argp->minorversion == 0)
1020 return nfs_ok;
1021 return nfserr_notsupp;
1022}
1023
1024static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
1026{
1027 DECODE_HEAD;
1028
Benny Halevye31a1b62008-08-12 20:46:18 +03001029 status = nfsd4_decode_stateid(argp, &read->rd_stateid);
1030 if (status)
1031 return status;
1032 READ_BUF(12);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 READ64(read->rd_offset);
1034 READ32(read->rd_length);
1035
1036 DECODE_TAIL;
1037}
1038
Al Virob37ad282006-10-19 23:28:59 -07001039static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir)
1041{
1042 DECODE_HEAD;
1043
1044 READ_BUF(24);
1045 READ64(readdir->rd_cookie);
1046 COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
1047 READ32(readdir->rd_dircount); /* just in case you needed a useless field... */
1048 READ32(readdir->rd_maxcount);
1049 if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
1050 goto out;
1051
1052 DECODE_TAIL;
1053}
1054
Al Virob37ad282006-10-19 23:28:59 -07001055static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove)
1057{
1058 DECODE_HEAD;
1059
1060 READ_BUF(4);
1061 READ32(remove->rm_namelen);
1062 READ_BUF(remove->rm_namelen);
1063 SAVEMEM(remove->rm_name, remove->rm_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001064 if ((status = check_filename(remove->rm_name, remove->rm_namelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return status;
1066
1067 DECODE_TAIL;
1068}
1069
Al Virob37ad282006-10-19 23:28:59 -07001070static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename)
1072{
1073 DECODE_HEAD;
1074
1075 READ_BUF(4);
1076 READ32(rename->rn_snamelen);
1077 READ_BUF(rename->rn_snamelen + 4);
1078 SAVEMEM(rename->rn_sname, rename->rn_snamelen);
1079 READ32(rename->rn_tnamelen);
1080 READ_BUF(rename->rn_tnamelen);
1081 SAVEMEM(rename->rn_tname, rename->rn_tnamelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001082 if ((status = check_filename(rename->rn_sname, rename->rn_snamelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return status;
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001084 if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return status;
1086
1087 DECODE_TAIL;
1088}
1089
Al Virob37ad282006-10-19 23:28:59 -07001090static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
1092{
1093 DECODE_HEAD;
1094
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001095 if (argp->minorversion >= 1)
1096 return nfserr_notsupp;
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 READ_BUF(sizeof(clientid_t));
1099 COPYMEM(clientid, sizeof(clientid_t));
1100
1101 DECODE_TAIL;
1102}
1103
Al Virob37ad282006-10-19 23:28:59 -07001104static __be32
Andy Adamsondcb488a32007-07-17 04:04:51 -07001105nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
1106 struct nfsd4_secinfo *secinfo)
1107{
1108 DECODE_HEAD;
1109
1110 READ_BUF(4);
1111 READ32(secinfo->si_namelen);
1112 READ_BUF(secinfo->si_namelen);
1113 SAVEMEM(secinfo->si_name, secinfo->si_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001114 status = check_filename(secinfo->si_name, secinfo->si_namelen);
Andy Adamsondcb488a32007-07-17 04:04:51 -07001115 if (status)
1116 return status;
1117 DECODE_TAIL;
1118}
1119
1120static __be32
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001121nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp,
1122 struct nfsd4_secinfo_no_name *sin)
1123{
1124 DECODE_HEAD;
1125
1126 READ_BUF(4);
1127 READ32(sin->sin_style);
1128 DECODE_TAIL;
1129}
1130
1131static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
1133{
Benny Halevye31a1b62008-08-12 20:46:18 +03001134 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Benny Halevye31a1b62008-08-12 20:46:18 +03001136 status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
1137 if (status)
1138 return status;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +08001139 return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr,
David Quigley18032ca2013-05-02 13:19:10 -04001140 &setattr->sa_acl, &setattr->sa_label);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Al Virob37ad282006-10-19 23:28:59 -07001143static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid)
1145{
1146 DECODE_HEAD;
1147
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001148 if (argp->minorversion >= 1)
1149 return nfserr_notsupp;
1150
Chuck Leverab4684d2012-03-02 17:13:50 -05001151 READ_BUF(NFS4_VERIFIER_SIZE);
1152 COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -04001154 status = nfsd4_decode_opaque(argp, &setclientid->se_name);
1155 if (status)
1156 return nfserr_bad_xdr;
1157 READ_BUF(8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 READ32(setclientid->se_callback_prog);
1159 READ32(setclientid->se_callback_netid_len);
1160
1161 READ_BUF(setclientid->se_callback_netid_len + 4);
1162 SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len);
1163 READ32(setclientid->se_callback_addr_len);
1164
1165 READ_BUF(setclientid->se_callback_addr_len + 4);
1166 SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len);
1167 READ32(setclientid->se_callback_ident);
1168
1169 DECODE_TAIL;
1170}
1171
Al Virob37ad282006-10-19 23:28:59 -07001172static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c)
1174{
1175 DECODE_HEAD;
1176
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001177 if (argp->minorversion >= 1)
1178 return nfserr_notsupp;
1179
Chuck Leverab4684d2012-03-02 17:13:50 -05001180 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 COPYMEM(&scd_c->sc_clientid, 8);
Chuck Leverab4684d2012-03-02 17:13:50 -05001182 COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 DECODE_TAIL;
1185}
1186
1187/* Also used for NVERIFY */
Al Virob37ad282006-10-19 23:28:59 -07001188static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify)
1190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 DECODE_HEAD;
1192
1193 if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval)))
1194 goto out;
1195
1196 /* For convenience's sake, we compare raw xdr'd attributes in
J. Bruce Fieldse5f95702012-11-30 17:24:18 -05001197 * nfsd4_proc_verify */
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 READ_BUF(4);
1200 READ32(verify->ve_attrlen);
1201 READ_BUF(verify->ve_attrlen);
1202 SAVEMEM(verify->ve_attrval, verify->ve_attrlen);
1203
1204 DECODE_TAIL;
1205}
1206
Al Virob37ad282006-10-19 23:28:59 -07001207static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
1209{
1210 int avail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 int len;
1212 DECODE_HEAD;
1213
Benny Halevye31a1b62008-08-12 20:46:18 +03001214 status = nfsd4_decode_stateid(argp, &write->wr_stateid);
1215 if (status)
1216 return status;
1217 READ_BUF(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 READ64(write->wr_offset);
1219 READ32(write->wr_stable_how);
1220 if (write->wr_stable_how > 2)
1221 goto xdr_error;
1222 READ32(write->wr_buflen);
1223
1224 /* Sorry .. no magic macros for this.. *
1225 * READ_BUF(write->wr_buflen);
1226 * SAVEMEM(write->wr_buf, write->wr_buflen);
1227 */
1228 avail = (char*)argp->end - (char*)argp->p;
1229 if (avail + argp->pagelen < write->wr_buflen) {
Chuck Lever817cb9d2007-09-11 18:01:20 -04001230 dprintk("NFSD: xdr error (%s:%d)\n",
1231 __FILE__, __LINE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 goto xdr_error;
1233 }
J. Bruce Fields70cc7f72012-11-16 14:16:46 -05001234 write->wr_head.iov_base = p;
1235 write->wr_head.iov_len = avail;
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001236 WARN_ON(avail != (XDR_QUADLEN(avail) << 2));
J. Bruce Fields70cc7f72012-11-16 14:16:46 -05001237 write->wr_pagelist = argp->pagelist;
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001238
1239 len = XDR_QUADLEN(write->wr_buflen) << 2;
1240 if (len >= avail) {
1241 int pages;
1242
1243 len -= avail;
1244
1245 pages = len >> PAGE_SHIFT;
1246 argp->pagelist += pages;
1247 argp->pagelen -= pages * PAGE_SIZE;
1248 len -= pages * PAGE_SIZE;
1249
1250 argp->p = (__be32 *)page_address(argp->pagelist[0]);
J. Bruce Fields365da4a2013-11-19 17:32:43 -05001251 argp->pagelist++;
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001252 argp->end = argp->p + XDR_QUADLEN(PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001254 argp->p += XDR_QUADLEN(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 DECODE_TAIL;
1257}
1258
Al Virob37ad282006-10-19 23:28:59 -07001259static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner)
1261{
1262 DECODE_HEAD;
1263
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001264 if (argp->minorversion >= 1)
1265 return nfserr_notsupp;
1266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 READ_BUF(12);
1268 COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
1269 READ32(rlockowner->rl_owner.len);
1270 READ_BUF(rlockowner->rl_owner.len);
1271 READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len);
1272
Andy Adamson60adfc52009-04-03 08:28:50 +03001273 if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
1274 return nfserr_inval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 DECODE_TAIL;
1276}
1277
Al Virob37ad282006-10-19 23:28:59 -07001278static __be32
Andy Adamson2db134e2009-04-03 08:27:55 +03001279nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
Andy Adamson0733d212009-04-03 08:28:01 +03001280 struct nfsd4_exchange_id *exid)
Andy Adamson2db134e2009-04-03 08:27:55 +03001281{
Mi Jinlong5afa0402010-11-09 09:39:23 +08001282 int dummy, tmp;
Andy Adamson0733d212009-04-03 08:28:01 +03001283 DECODE_HEAD;
1284
1285 READ_BUF(NFS4_VERIFIER_SIZE);
1286 COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE);
1287
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -04001288 status = nfsd4_decode_opaque(argp, &exid->clname);
1289 if (status)
1290 return nfserr_bad_xdr;
Andy Adamson0733d212009-04-03 08:28:01 +03001291
1292 READ_BUF(4);
1293 READ32(exid->flags);
1294
1295 /* Ignore state_protect4_a */
1296 READ_BUF(4);
1297 READ32(exid->spa_how);
1298 switch (exid->spa_how) {
1299 case SP4_NONE:
1300 break;
1301 case SP4_MACH_CRED:
1302 /* spo_must_enforce */
1303 READ_BUF(4);
1304 READ32(dummy);
1305 READ_BUF(dummy * 4);
1306 p += dummy;
1307
1308 /* spo_must_allow */
1309 READ_BUF(4);
1310 READ32(dummy);
1311 READ_BUF(dummy * 4);
1312 p += dummy;
1313 break;
1314 case SP4_SSV:
1315 /* ssp_ops */
1316 READ_BUF(4);
1317 READ32(dummy);
1318 READ_BUF(dummy * 4);
1319 p += dummy;
1320
1321 READ_BUF(4);
1322 READ32(dummy);
1323 READ_BUF(dummy * 4);
1324 p += dummy;
1325
1326 /* ssp_hash_algs<> */
1327 READ_BUF(4);
Mi Jinlong5afa0402010-11-09 09:39:23 +08001328 READ32(tmp);
1329 while (tmp--) {
1330 READ_BUF(4);
1331 READ32(dummy);
1332 READ_BUF(dummy);
1333 p += XDR_QUADLEN(dummy);
1334 }
Andy Adamson0733d212009-04-03 08:28:01 +03001335
1336 /* ssp_encr_algs<> */
1337 READ_BUF(4);
Mi Jinlong5afa0402010-11-09 09:39:23 +08001338 READ32(tmp);
1339 while (tmp--) {
1340 READ_BUF(4);
1341 READ32(dummy);
1342 READ_BUF(dummy);
1343 p += XDR_QUADLEN(dummy);
1344 }
Andy Adamson0733d212009-04-03 08:28:01 +03001345
1346 /* ssp_window and ssp_num_gss_handles */
1347 READ_BUF(8);
1348 READ32(dummy);
1349 READ32(dummy);
1350 break;
1351 default:
1352 goto xdr_error;
1353 }
1354
1355 /* Ignore Implementation ID */
1356 READ_BUF(4); /* nfs_impl_id4 array length */
1357 READ32(dummy);
1358
1359 if (dummy > 1)
1360 goto xdr_error;
1361
1362 if (dummy == 1) {
1363 /* nii_domain */
1364 READ_BUF(4);
1365 READ32(dummy);
1366 READ_BUF(dummy);
1367 p += XDR_QUADLEN(dummy);
1368
1369 /* nii_name */
1370 READ_BUF(4);
1371 READ32(dummy);
1372 READ_BUF(dummy);
1373 p += XDR_QUADLEN(dummy);
1374
1375 /* nii_date */
1376 READ_BUF(12);
1377 p += 3;
1378 }
1379 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001380}
1381
1382static __be32
1383nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
1384 struct nfsd4_create_session *sess)
1385{
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001386 DECODE_HEAD;
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001387 u32 dummy;
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001388
1389 READ_BUF(16);
1390 COPYMEM(&sess->clientid, 8);
1391 READ32(sess->seqid);
1392 READ32(sess->flags);
1393
1394 /* Fore channel attrs */
1395 READ_BUF(28);
1396 READ32(dummy); /* headerpadsz is always 0 */
1397 READ32(sess->fore_channel.maxreq_sz);
1398 READ32(sess->fore_channel.maxresp_sz);
1399 READ32(sess->fore_channel.maxresp_cached);
1400 READ32(sess->fore_channel.maxops);
1401 READ32(sess->fore_channel.maxreqs);
1402 READ32(sess->fore_channel.nr_rdma_attrs);
1403 if (sess->fore_channel.nr_rdma_attrs == 1) {
1404 READ_BUF(4);
1405 READ32(sess->fore_channel.rdma_attrs);
1406 } else if (sess->fore_channel.nr_rdma_attrs > 1) {
1407 dprintk("Too many fore channel attr bitmaps!\n");
1408 goto xdr_error;
1409 }
1410
1411 /* Back channel attrs */
1412 READ_BUF(28);
1413 READ32(dummy); /* headerpadsz is always 0 */
1414 READ32(sess->back_channel.maxreq_sz);
1415 READ32(sess->back_channel.maxresp_sz);
1416 READ32(sess->back_channel.maxresp_cached);
1417 READ32(sess->back_channel.maxops);
1418 READ32(sess->back_channel.maxreqs);
1419 READ32(sess->back_channel.nr_rdma_attrs);
1420 if (sess->back_channel.nr_rdma_attrs == 1) {
1421 READ_BUF(4);
1422 READ32(sess->back_channel.rdma_attrs);
1423 } else if (sess->back_channel.nr_rdma_attrs > 1) {
1424 dprintk("Too many back channel attr bitmaps!\n");
1425 goto xdr_error;
1426 }
1427
J. Bruce Fieldsacb28872012-03-27 14:50:26 -04001428 READ_BUF(4);
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001429 READ32(sess->callback_prog);
J. Bruce Fieldsacb28872012-03-27 14:50:26 -04001430 nfsd4_decode_cb_sec(argp, &sess->cb_sec);
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001431 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001432}
1433
1434static __be32
1435nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
1436 struct nfsd4_destroy_session *destroy_session)
1437{
Benny Halevye10e0cf2009-04-03 08:28:38 +03001438 DECODE_HEAD;
1439 READ_BUF(NFS4_MAX_SESSIONID_LEN);
1440 COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1441
1442 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001443}
1444
1445static __be32
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001446nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp,
1447 struct nfsd4_free_stateid *free_stateid)
1448{
1449 DECODE_HEAD;
1450
1451 READ_BUF(sizeof(stateid_t));
1452 READ32(free_stateid->fr_stateid.si_generation);
1453 COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t));
1454
1455 DECODE_TAIL;
1456}
1457
1458static __be32
Andy Adamson2db134e2009-04-03 08:27:55 +03001459nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
1460 struct nfsd4_sequence *seq)
1461{
Benny Halevyb85d4c02009-04-03 08:28:08 +03001462 DECODE_HEAD;
1463
1464 READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
1465 COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1466 READ32(seq->seqid);
1467 READ32(seq->slotid);
1468 READ32(seq->maxslots);
1469 READ32(seq->cachethis);
1470
1471 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001472}
1473
Bryan Schumaker17456802011-07-13 10:50:48 -04001474static __be32
1475nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid)
1476{
Bryan Schumaker17456802011-07-13 10:50:48 -04001477 int i;
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001478 __be32 *p, status;
1479 struct nfsd4_test_stateid_id *stateid;
Bryan Schumaker17456802011-07-13 10:50:48 -04001480
1481 READ_BUF(4);
1482 test_stateid->ts_num_ids = ntohl(*p++);
1483
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001484 INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
Bryan Schumaker17456802011-07-13 10:50:48 -04001485
1486 for (i = 0; i < test_stateid->ts_num_ids; i++) {
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001487 stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);
1488 if (!stateid) {
Al Viroafcf6792012-04-13 00:15:37 -04001489 status = nfserrno(-ENOMEM);
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001490 goto out;
1491 }
1492
1493 defer_free(argp, kfree, stateid);
1494 INIT_LIST_HEAD(&stateid->ts_id_list);
1495 list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list);
1496
1497 status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid);
Bryan Schumaker17456802011-07-13 10:50:48 -04001498 if (status)
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001499 goto out;
Bryan Schumaker17456802011-07-13 10:50:48 -04001500 }
1501
1502 status = 0;
1503out:
1504 return status;
1505xdr_error:
1506 dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__);
1507 status = nfserr_bad_xdr;
1508 goto out;
1509}
1510
Mi Jinlong345c2842011-10-20 17:51:39 +08001511static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc)
1512{
1513 DECODE_HEAD;
1514
1515 READ_BUF(8);
1516 COPYMEM(&dc->clientid, 8);
1517
1518 DECODE_TAIL;
1519}
1520
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001521static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc)
1522{
1523 DECODE_HEAD;
1524
1525 READ_BUF(4);
1526 READ32(rc->rca_one_fs);
1527
1528 DECODE_TAIL;
1529}
1530
Andy Adamson2db134e2009-04-03 08:27:55 +03001531static __be32
Benny Halevy347e0ad2008-07-02 11:13:41 +03001532nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
1533{
1534 return nfs_ok;
1535}
1536
Benny Halevy3c375c62008-07-02 11:14:01 +03001537static __be32
1538nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
1539{
Benny Halevy1e685ec2009-03-04 23:06:06 +02001540 return nfserr_notsupp;
Benny Halevy3c375c62008-07-02 11:14:01 +03001541}
1542
Benny Halevy347e0ad2008-07-02 11:13:41 +03001543typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
1544
1545static nfsd4_dec nfsd4_dec_ops[] = {
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04001546 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
1547 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
1548 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
1549 [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
1550 [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
1551 [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
1552 [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
1553 [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
1554 [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
1555 [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
1556 [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
1557 [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
1558 [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
1559 [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
1560 [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1561 [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
1562 [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
1563 [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm,
1564 [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
1565 [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001566 [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh,
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04001567 [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
1568 [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
1569 [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
1570 [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
1571 [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
1572 [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
1573 [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew,
1574 [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
1575 [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
1576 [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
1577 [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
1578 [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid,
1579 [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm,
1580 [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1581 [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
1582 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
Andy Adamson2db134e2009-04-03 08:27:55 +03001583
1584 /* new operations for NFSv4.1 */
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -04001585 [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001586 [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001587 [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id,
1588 [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session,
1589 [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001590 [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001591 [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
1592 [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp,
1593 [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
1594 [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp,
1595 [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp,
1596 [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp,
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001597 [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001598 [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence,
1599 [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp,
Bryan Schumaker17456802011-07-13 10:50:48 -04001600 [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001601 [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
Mi Jinlong345c2842011-10-20 17:51:39 +08001602 [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001603 [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete,
Andy Adamson2db134e2009-04-03 08:27:55 +03001604};
1605
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001606static inline bool
1607nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op)
1608{
Anna Schumaker8217d142013-10-30 13:38:13 -04001609 if (op->opnum < FIRST_NFS4_OP)
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001610 return false;
Anna Schumaker8217d142013-10-30 13:38:13 -04001611 else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP)
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001612 return false;
Anna Schumaker8217d142013-10-30 13:38:13 -04001613 else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP)
1614 return false;
1615 else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP)
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001616 return false;
1617 return true;
1618}
Benny Halevyf2feb962008-07-02 11:14:22 +03001619
J. Bruce Fields6ff40de2013-11-05 15:07:16 -05001620/*
1621 * Return a rough estimate of the maximum possible reply size. Note the
1622 * estimate includes rpc headers so is meant to be passed to
1623 * svc_reserve, not svc_reserve_auth.
1624 *
1625 * Also note the current compound encoding permits only one operation to
1626 * use pages beyond the first one, so the maximum possible length is the
1627 * maximum over these values, not the sum.
1628 */
1629static int nfsd4_max_reply(u32 opnum)
1630{
1631 switch (opnum) {
1632 case OP_READLINK:
1633 case OP_READDIR:
1634 /*
1635 * Both of these ops take a single page for data and put
1636 * the head and tail in another page:
1637 */
1638 return 2 * PAGE_SIZE;
1639 case OP_READ:
1640 return INT_MAX;
1641 default:
1642 return PAGE_SIZE;
1643 }
1644}
1645
Benny Halevy347e0ad2008-07-02 11:13:41 +03001646static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
1648{
1649 DECODE_HEAD;
1650 struct nfsd4_op *op;
J. Bruce Fields10910062011-01-24 12:11:02 -05001651 bool cachethis = false;
J. Bruce Fields6ff40de2013-11-05 15:07:16 -05001652 int max_reply = PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 int i;
1654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 READ_BUF(4);
1656 READ32(argp->taglen);
1657 READ_BUF(argp->taglen + 8);
1658 SAVEMEM(argp->tag, argp->taglen);
1659 READ32(argp->minorversion);
1660 READ32(argp->opcnt);
1661
1662 if (argp->taglen > NFSD4_MAX_TAGLEN)
1663 goto xdr_error;
1664 if (argp->opcnt > 100)
1665 goto xdr_error;
1666
Tobias Klausere8c96f82006-03-24 03:15:34 -08001667 if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
1669 if (!argp->ops) {
1670 argp->ops = argp->iops;
Chuck Lever817cb9d2007-09-11 18:01:20 -04001671 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 goto xdr_error;
1673 }
1674 }
1675
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001676 if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION)
Benny Halevy30cff1f2008-07-02 11:13:18 +03001677 argp->opcnt = 0;
1678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 for (i = 0; i < argp->opcnt; i++) {
1680 op = &argp->ops[i];
1681 op->replay = NULL;
1682
J. Bruce Fields8a61b182012-11-16 22:28:38 -05001683 READ_BUF(4);
1684 READ32(op->opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Anna Schumakere1a90eb2013-10-30 10:00:20 -04001686 if (nfsd4_opnum_in_range(argp, op))
1687 op->status = nfsd4_dec_ops[op->opnum](argp, &op->u);
Benny Halevy347e0ad2008-07-02 11:13:41 +03001688 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 op->opnum = OP_ILLEGAL;
1690 op->status = nfserr_op_illegal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692
1693 if (op->status) {
1694 argp->opcnt = i+1;
1695 break;
1696 }
J. Bruce Fields10910062011-01-24 12:11:02 -05001697 /*
1698 * We'll try to cache the result in the DRC if any one
1699 * op in the compound wants to be cached:
1700 */
1701 cachethis |= nfsd4_cache_this_op(op);
J. Bruce Fields6ff40de2013-11-05 15:07:16 -05001702
1703 max_reply = max(max_reply, nfsd4_max_reply(op->opnum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 }
J. Bruce Fields10910062011-01-24 12:11:02 -05001705 /* Sessions make the DRC unnecessary: */
1706 if (argp->minorversion)
1707 cachethis = false;
J. Bruce Fields6ff40de2013-11-05 15:07:16 -05001708 if (max_reply != INT_MAX)
1709 svc_reserve(argp->rqstp, max_reply);
J. Bruce Fields10910062011-01-24 12:11:02 -05001710 argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 DECODE_TAIL;
1713}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715#define WRITE32(n) *p++ = htonl(n)
1716#define WRITE64(n) do { \
1717 *p++ = htonl((u32)((n) >> 32)); \
1718 *p++ = htonl((u32)(n)); \
1719} while (0)
Harvey Harrison5108b272008-07-17 21:33:04 -07001720#define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 *(p + XDR_QUADLEN(nbytes) -1) = 0; \
1722 memcpy(p, ptr, nbytes); \
1723 p += XDR_QUADLEN(nbytes); \
Harvey Harrison5108b272008-07-17 21:33:04 -07001724}} while (0)
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04001725
1726static void write32(__be32 **p, u32 n)
1727{
J. Bruce Fields45eaa1c2012-04-25 18:11:04 -04001728 *(*p)++ = htonl(n);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04001729}
1730
1731static void write64(__be32 **p, u64 n)
1732{
J. Bruce Fields45eaa1c2012-04-25 18:11:04 -04001733 write32(p, (n >> 32));
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04001734 write32(p, (u32)n);
1735}
1736
1737static void write_change(__be32 **p, struct kstat *stat, struct inode *inode)
1738{
1739 if (IS_I_VERSION(inode)) {
1740 write64(p, inode->i_version);
1741 } else {
1742 write32(p, stat->ctime.tv_sec);
1743 write32(p, stat->ctime.tv_nsec);
1744 }
1745}
1746
1747static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)
1748{
1749 write32(p, c->atomic);
1750 if (c->change_supported) {
1751 write64(p, c->before_change);
1752 write64(p, c->after_change);
1753 } else {
1754 write32(p, c->before_ctime_sec);
1755 write32(p, c->before_ctime_nsec);
1756 write32(p, c->after_ctime_sec);
1757 write32(p, c->after_ctime_nsec);
1758 }
1759}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761#define RESERVE_SPACE(nbytes) do { \
1762 p = resp->p; \
1763 BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
1764} while (0)
1765#define ADJUST_ARGS() resp->p = p
1766
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001767/* Encode as an array of strings the string given with components
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001768 * separated @sep, escaped with esc_enter and esc_exit.
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001769 */
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001770static __be32 nfsd4_encode_components_esc(char sep, char *components,
1771 __be32 **pp, int *buflen,
1772 char esc_enter, char esc_exit)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001773{
Al Viro2ebbc012006-10-19 23:28:58 -07001774 __be32 *p = *pp;
1775 __be32 *countp = p;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001776 int strlen, count=0;
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001777 char *str, *end, *next;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001778
1779 dprintk("nfsd4_encode_components(%s)\n", components);
1780 if ((*buflen -= 4) < 0)
1781 return nfserr_resource;
1782 WRITE32(0); /* We will fill this in with @count later */
1783 end = str = components;
1784 while (*end) {
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001785 bool found_esc = false;
1786
1787 /* try to parse as esc_start, ..., esc_end, sep */
1788 if (*str == esc_enter) {
1789 for (; *end && (*end != esc_exit); end++)
1790 /* find esc_exit or end of string */;
1791 next = end + 1;
1792 if (*end && (!*next || *next == sep)) {
1793 str++;
1794 found_esc = true;
1795 }
1796 }
1797
1798 if (!found_esc)
1799 for (; *end && (*end != sep); end++)
1800 /* find sep or end of string */;
1801
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001802 strlen = end - str;
1803 if (strlen) {
1804 if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
1805 return nfserr_resource;
1806 WRITE32(strlen);
1807 WRITEMEM(str, strlen);
1808 count++;
1809 }
1810 else
1811 end++;
1812 str = end;
1813 }
1814 *pp = p;
1815 p = countp;
1816 WRITE32(count);
1817 return 0;
1818}
1819
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001820/* Encode as an array of strings the string given with components
1821 * separated @sep.
1822 */
1823static __be32 nfsd4_encode_components(char sep, char *components,
1824 __be32 **pp, int *buflen)
1825{
1826 return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0);
1827}
1828
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001829/*
1830 * encode a location element of a fs_locations structure
1831 */
Al Virob37ad282006-10-19 23:28:59 -07001832static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
Al Viro2ebbc012006-10-19 23:28:58 -07001833 __be32 **pp, int *buflen)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001834{
Al Virob37ad282006-10-19 23:28:59 -07001835 __be32 status;
Al Viro2ebbc012006-10-19 23:28:58 -07001836 __be32 *p = *pp;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001837
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001838 status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen,
1839 '[', ']');
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001840 if (status)
1841 return status;
1842 status = nfsd4_encode_components('/', location->path, &p, buflen);
1843 if (status)
1844 return status;
1845 *pp = p;
1846 return 0;
1847}
1848
1849/*
Trond Myklebusted748aa2011-09-12 19:37:06 -04001850 * Encode a path in RFC3530 'pathname4' format
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001851 */
Trond Myklebusted748aa2011-09-12 19:37:06 -04001852static __be32 nfsd4_encode_path(const struct path *root,
1853 const struct path *path, __be32 **pp, int *buflen)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001854{
Al Viro301f0262013-09-01 16:06:39 -04001855 struct path cur = *path;
Trond Myklebusted748aa2011-09-12 19:37:06 -04001856 __be32 *p = *pp;
1857 struct dentry **components = NULL;
1858 unsigned int ncomponents = 0;
1859 __be32 err = nfserr_jukebox;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001860
Trond Myklebusted748aa2011-09-12 19:37:06 -04001861 dprintk("nfsd4_encode_components(");
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001862
Trond Myklebusted748aa2011-09-12 19:37:06 -04001863 path_get(&cur);
1864 /* First walk the path up to the nfsd root, and store the
1865 * dentries/path components in an array.
1866 */
1867 for (;;) {
1868 if (cur.dentry == root->dentry && cur.mnt == root->mnt)
1869 break;
1870 if (cur.dentry == cur.mnt->mnt_root) {
1871 if (follow_up(&cur))
1872 continue;
1873 goto out_free;
1874 }
1875 if ((ncomponents & 15) == 0) {
1876 struct dentry **new;
1877 new = krealloc(components,
1878 sizeof(*new) * (ncomponents + 16),
1879 GFP_KERNEL);
1880 if (!new)
1881 goto out_free;
1882 components = new;
1883 }
1884 components[ncomponents++] = cur.dentry;
1885 cur.dentry = dget_parent(cur.dentry);
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001886 }
Trond Myklebusted748aa2011-09-12 19:37:06 -04001887
1888 *buflen -= 4;
1889 if (*buflen < 0)
1890 goto out_free;
1891 WRITE32(ncomponents);
1892
1893 while (ncomponents) {
1894 struct dentry *dentry = components[ncomponents - 1];
Al Viro301f0262013-09-01 16:06:39 -04001895 unsigned int len;
Trond Myklebusted748aa2011-09-12 19:37:06 -04001896
Al Viro301f0262013-09-01 16:06:39 -04001897 spin_lock(&dentry->d_lock);
1898 len = dentry->d_name.len;
Trond Myklebusted748aa2011-09-12 19:37:06 -04001899 *buflen -= 4 + (XDR_QUADLEN(len) << 2);
Al Viro301f0262013-09-01 16:06:39 -04001900 if (*buflen < 0) {
1901 spin_unlock(&dentry->d_lock);
Trond Myklebusted748aa2011-09-12 19:37:06 -04001902 goto out_free;
Al Viro301f0262013-09-01 16:06:39 -04001903 }
Trond Myklebusted748aa2011-09-12 19:37:06 -04001904 WRITE32(len);
1905 WRITEMEM(dentry->d_name.name, len);
1906 dprintk("/%s", dentry->d_name.name);
Al Viro301f0262013-09-01 16:06:39 -04001907 spin_unlock(&dentry->d_lock);
Trond Myklebusted748aa2011-09-12 19:37:06 -04001908 dput(dentry);
1909 ncomponents--;
1910 }
1911
1912 *pp = p;
1913 err = 0;
1914out_free:
1915 dprintk(")\n");
1916 while (ncomponents)
1917 dput(components[--ncomponents]);
1918 kfree(components);
1919 path_put(&cur);
1920 return err;
1921}
1922
1923static __be32 nfsd4_encode_fsloc_fsroot(struct svc_rqst *rqstp,
1924 const struct path *path, __be32 **pp, int *buflen)
1925{
1926 struct svc_export *exp_ps;
1927 __be32 res;
1928
1929 exp_ps = rqst_find_fsidzero_export(rqstp);
1930 if (IS_ERR(exp_ps))
1931 return nfserrno(PTR_ERR(exp_ps));
1932 res = nfsd4_encode_path(&exp_ps->ex_path, path, pp, buflen);
1933 exp_put(exp_ps);
1934 return res;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001935}
1936
1937/*
1938 * encode a fs_locations structure
1939 */
Al Virob37ad282006-10-19 23:28:59 -07001940static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001941 struct svc_export *exp,
Al Viro2ebbc012006-10-19 23:28:58 -07001942 __be32 **pp, int *buflen)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001943{
Al Virob37ad282006-10-19 23:28:59 -07001944 __be32 status;
Al Virocc45f012006-10-19 23:28:44 -07001945 int i;
Al Viro2ebbc012006-10-19 23:28:58 -07001946 __be32 *p = *pp;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001947 struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001948
Trond Myklebusted748aa2011-09-12 19:37:06 -04001949 status = nfsd4_encode_fsloc_fsroot(rqstp, &exp->ex_path, &p, buflen);
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001950 if (status)
1951 return status;
1952 if ((*buflen -= 4) < 0)
1953 return nfserr_resource;
1954 WRITE32(fslocs->locations_count);
1955 for (i=0; i<fslocs->locations_count; i++) {
1956 status = nfsd4_encode_fs_location4(&fslocs->locations[i],
1957 &p, buflen);
1958 if (status)
1959 return status;
1960 }
1961 *pp = p;
1962 return 0;
1963}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
J. Bruce Fields3d2544b2011-08-15 11:49:30 -04001965static u32 nfs4_file_type(umode_t mode)
1966{
1967 switch (mode & S_IFMT) {
1968 case S_IFIFO: return NF4FIFO;
1969 case S_IFCHR: return NF4CHR;
1970 case S_IFDIR: return NF4DIR;
1971 case S_IFBLK: return NF4BLK;
1972 case S_IFLNK: return NF4LNK;
1973 case S_IFREG: return NF4REG;
1974 case S_IFSOCK: return NF4SOCK;
1975 default: return NF4BAD;
1976 };
1977}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Al Virob37ad282006-10-19 23:28:59 -07001979static __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001980nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, kuid_t uid, kgid_t gid,
Al Viro2ebbc012006-10-19 23:28:58 -07001981 __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 int status;
1984
1985 if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4)
1986 return nfserr_resource;
1987 if (whotype != NFS4_ACL_WHO_NAMED)
1988 status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1));
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001989 else if (gid_valid(gid))
1990 status = nfsd_map_gid_to_name(rqstp, gid, (u8 *)(*p + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 else
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001992 status = nfsd_map_uid_to_name(rqstp, uid, (u8 *)(*p + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 if (status < 0)
1994 return nfserrno(status);
1995 *p = xdr_encode_opaque(*p, NULL, status);
1996 *buflen -= (XDR_QUADLEN(status) << 2) + 4;
1997 BUG_ON(*buflen < 0);
1998 return 0;
1999}
2000
Al Virob37ad282006-10-19 23:28:59 -07002001static inline __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002002nfsd4_encode_user(struct svc_rqst *rqstp, kuid_t user, __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003{
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002004 return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, user, INVALID_GID,
2005 p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006}
2007
Al Virob37ad282006-10-19 23:28:59 -07002008static inline __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002009nfsd4_encode_group(struct svc_rqst *rqstp, kgid_t group, __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002011 return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, INVALID_UID, group,
2012 p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013}
2014
Al Virob37ad282006-10-19 23:28:59 -07002015static inline __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002016nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,
Al Viro2ebbc012006-10-19 23:28:58 -07002017 __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018{
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002019 kuid_t uid = INVALID_UID;
2020 kgid_t gid = INVALID_GID;
2021
2022 if (ace->whotype == NFS4_ACL_WHO_NAMED) {
2023 if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
2024 gid = ace->who_gid;
2025 else
2026 uid = ace->who_uid;
2027 }
2028 return nfsd4_encode_name(rqstp, ace->whotype, uid, gid, p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029}
2030
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002031#define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
2032 FATTR4_WORD0_RDATTR_ERROR)
2033#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
2034
David Quigley18032ca2013-05-02 13:19:10 -04002035#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2036static inline __be32
2037nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen)
2038{
2039 __be32 *p = *pp;
2040
2041 if (*buflen < ((XDR_QUADLEN(len) << 2) + 4 + 4 + 4))
2042 return nfserr_resource;
2043
2044 /*
2045 * For now we use a 0 here to indicate the null translation; in
2046 * the future we may place a call to translation code here.
2047 */
2048 if ((*buflen -= 8) < 0)
2049 return nfserr_resource;
2050
2051 WRITE32(0); /* lfs */
2052 WRITE32(0); /* pi */
2053 p = xdr_encode_opaque(p, context, len);
2054 *buflen -= (XDR_QUADLEN(len) << 2) + 4;
2055
2056 *pp = p;
2057 return 0;
2058}
2059#else
2060static inline __be32
J. Bruce Fieldsba4e55b2013-05-15 10:27:52 -04002061nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen)
David Quigley18032ca2013-05-02 13:19:10 -04002062{ return 0; }
2063#endif
2064
Al Virob37ad282006-10-19 23:28:59 -07002065static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002066{
2067 /* As per referral draft: */
2068 if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
2069 *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
2070 if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
2071 *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
2072 *rdattr_err = NFSERR_MOVED;
2073 else
2074 return nfserr_moved;
2075 }
2076 *bmval0 &= WORD0_ABSENT_FS_ATTRS;
2077 *bmval1 &= WORD1_ABSENT_FS_ATTRS;
2078 return 0;
2079}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
J. Bruce Fieldsae7095a2012-10-01 17:50:56 -04002081
2082static int get_parent_attributes(struct svc_export *exp, struct kstat *stat)
2083{
2084 struct path path = exp->ex_path;
2085 int err;
2086
2087 path_get(&path);
2088 while (follow_up(&path)) {
2089 if (path.dentry != path.mnt->mnt_root)
2090 break;
2091 }
Al Viro3dadecc2013-01-24 02:18:08 -05002092 err = vfs_getattr(&path, stat);
J. Bruce Fieldsae7095a2012-10-01 17:50:56 -04002093 path_put(&path);
2094 return err;
2095}
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097/*
2098 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
2099 * ourselves.
2100 *
J. Bruce Fields84822d02012-12-14 17:57:50 -05002101 * countp is the buffer size in _words_
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 */
Al Virob37ad282006-10-19 23:28:59 -07002103__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
J. Bruce Fields84822d02012-12-14 17:57:50 -05002105 struct dentry *dentry, __be32 **buffer, int count, u32 *bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08002106 struct svc_rqst *rqstp, int ignore_crossmnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 u32 bmval0 = bmval[0];
2109 u32 bmval1 = bmval[1];
Andy Adamson7e705702009-04-03 08:29:11 +03002110 u32 bmval2 = bmval[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct kstat stat;
2112 struct svc_fh tempfh;
2113 struct kstatfs statfs;
J. Bruce Fields84822d02012-12-14 17:57:50 -05002114 int buflen = count << 2;
Al Viro2ebbc012006-10-19 23:28:58 -07002115 __be32 *attrlenp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 u32 dummy;
2117 u64 dummy64;
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002118 u32 rdattr_err = 0;
J. Bruce Fields84822d02012-12-14 17:57:50 -05002119 __be32 *p = *buffer;
Al Virob37ad282006-10-19 23:28:59 -07002120 __be32 status;
Al Virob8dd7b92006-10-19 23:29:01 -07002121 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 int aclsupport = 0;
2123 struct nfs4_acl *acl = NULL;
David Quigley18032ca2013-05-02 13:19:10 -04002124 void *context = NULL;
2125 int contextlen;
2126 bool contextsupport = false;
Andy Adamson7e705702009-04-03 08:29:11 +03002127 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2128 u32 minorversion = resp->cstate.minorversion;
Christoph Hellwigebabe9a2010-07-07 18:53:11 +02002129 struct path path = {
2130 .mnt = exp->ex_path.mnt,
2131 .dentry = dentry,
2132 };
Stanislav Kinsbursky3d733712012-11-27 14:11:44 +03002133 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
2135 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
Andy Adamson7e705702009-04-03 08:29:11 +03002136 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
2137 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
2138 BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002140 if (exp->ex_fslocs.migrated) {
Andy Adamson7e705702009-04-03 08:29:11 +03002141 BUG_ON(bmval[2]);
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002142 status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err);
2143 if (status)
2144 goto out;
2145 }
2146
Al Viro3dadecc2013-01-24 02:18:08 -05002147 err = vfs_getattr(&path, &stat);
Al Virob8dd7b92006-10-19 23:29:01 -07002148 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 goto out_nfserr;
J. Bruce Fieldsa16e92e2007-09-28 16:45:51 -04002150 if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
2151 FATTR4_WORD0_MAXNAME)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
2153 FATTR4_WORD1_SPACE_TOTAL))) {
Christoph Hellwigebabe9a2010-07-07 18:53:11 +02002154 err = vfs_statfs(&path, &statfs);
Al Virob8dd7b92006-10-19 23:29:01 -07002155 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 goto out_nfserr;
2157 }
2158 if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
2159 fh_init(&tempfh, NFS4_FHSIZE);
2160 status = fh_compose(&tempfh, exp, dentry, NULL);
2161 if (status)
2162 goto out;
2163 fhp = &tempfh;
2164 }
2165 if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
2166 | FATTR4_WORD0_SUPPORTED_ATTRS)) {
Al Virob8dd7b92006-10-19 23:29:01 -07002167 err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
2168 aclsupport = (err == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 if (bmval0 & FATTR4_WORD0_ACL) {
Al Virob8dd7b92006-10-19 23:29:01 -07002170 if (err == -EOPNOTSUPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 bmval0 &= ~FATTR4_WORD0_ACL;
Al Virob8dd7b92006-10-19 23:29:01 -07002172 else if (err == -EINVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 status = nfserr_attrnotsupp;
2174 goto out;
Al Virob8dd7b92006-10-19 23:29:01 -07002175 } else if (err != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 goto out_nfserr;
2177 }
2178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
David Quigley18032ca2013-05-02 13:19:10 -04002180#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2181 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) ||
2182 bmval[0] & FATTR4_WORD0_SUPPORTED_ATTRS) {
2183 err = security_inode_getsecctx(dentry->d_inode,
2184 &context, &contextlen);
2185 contextsupport = (err == 0);
2186 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
2187 if (err == -EOPNOTSUPP)
2188 bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2189 else if (err)
2190 goto out_nfserr;
2191 }
2192 }
2193#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2194
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002195 if (bmval2) {
2196 if ((buflen -= 16) < 0)
2197 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002198 WRITE32(3);
2199 WRITE32(bmval0);
2200 WRITE32(bmval1);
2201 WRITE32(bmval2);
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002202 } else if (bmval1) {
2203 if ((buflen -= 12) < 0)
2204 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002205 WRITE32(2);
2206 WRITE32(bmval0);
2207 WRITE32(bmval1);
2208 } else {
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002209 if ((buflen -= 8) < 0)
2210 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002211 WRITE32(1);
2212 WRITE32(bmval0);
2213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 attrlenp = p++; /* to be backfilled later */
2215
2216 if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
Andy Adamson7e705702009-04-03 08:29:11 +03002217 u32 word0 = nfsd_suppattrs0(minorversion);
2218 u32 word1 = nfsd_suppattrs1(minorversion);
2219 u32 word2 = nfsd_suppattrs2(minorversion);
2220
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002221 if (!aclsupport)
2222 word0 &= ~FATTR4_WORD0_ACL;
David Quigley18032ca2013-05-02 13:19:10 -04002223 if (!contextsupport)
2224 word2 &= ~FATTR4_WORD2_SECURITY_LABEL;
Andy Adamson7e705702009-04-03 08:29:11 +03002225 if (!word2) {
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002226 if ((buflen -= 12) < 0)
2227 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002228 WRITE32(2);
2229 WRITE32(word0);
2230 WRITE32(word1);
2231 } else {
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002232 if ((buflen -= 16) < 0)
2233 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002234 WRITE32(3);
2235 WRITE32(word0);
2236 WRITE32(word1);
2237 WRITE32(word2);
2238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 }
2240 if (bmval0 & FATTR4_WORD0_TYPE) {
2241 if ((buflen -= 4) < 0)
2242 goto out_resource;
J. Bruce Fields3d2544b2011-08-15 11:49:30 -04002243 dummy = nfs4_file_type(stat.mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 if (dummy == NF4BAD)
2245 goto out_serverfault;
2246 WRITE32(dummy);
2247 }
2248 if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
2249 if ((buflen -= 4) < 0)
2250 goto out_resource;
NeilBrown49640002005-06-23 22:02:58 -07002251 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
NeilBrowne34ac862005-07-07 17:59:30 -07002252 WRITE32(NFS4_FH_PERSISTENT);
NeilBrown49640002005-06-23 22:02:58 -07002253 else
NeilBrowne34ac862005-07-07 17:59:30 -07002254 WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 }
2256 if (bmval0 & FATTR4_WORD0_CHANGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 if ((buflen -= 8) < 0)
2258 goto out_resource;
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002259 write_change(&p, &stat, dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 }
2261 if (bmval0 & FATTR4_WORD0_SIZE) {
2262 if ((buflen -= 8) < 0)
2263 goto out_resource;
2264 WRITE64(stat.size);
2265 }
2266 if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
2267 if ((buflen -= 4) < 0)
2268 goto out_resource;
2269 WRITE32(1);
2270 }
2271 if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
2272 if ((buflen -= 4) < 0)
2273 goto out_resource;
2274 WRITE32(1);
2275 }
2276 if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
2277 if ((buflen -= 4) < 0)
2278 goto out_resource;
2279 WRITE32(0);
2280 }
2281 if (bmval0 & FATTR4_WORD0_FSID) {
2282 if ((buflen -= 16) < 0)
2283 goto out_resource;
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002284 if (exp->ex_fslocs.migrated) {
2285 WRITE64(NFS4_REFERRAL_FSID_MAJOR);
2286 WRITE64(NFS4_REFERRAL_FSID_MINOR);
NeilBrownaf6a4e22007-02-14 00:33:12 -08002287 } else switch(fsid_source(fhp)) {
2288 case FSIDSOURCE_FSID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 WRITE64((u64)exp->ex_fsid);
2290 WRITE64((u64)0);
NeilBrownaf6a4e22007-02-14 00:33:12 -08002291 break;
2292 case FSIDSOURCE_DEV:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 WRITE32(0);
2294 WRITE32(MAJOR(stat.dev));
2295 WRITE32(0);
2296 WRITE32(MINOR(stat.dev));
NeilBrownaf6a4e22007-02-14 00:33:12 -08002297 break;
2298 case FSIDSOURCE_UUID:
2299 WRITEMEM(exp->ex_uuid, 16);
2300 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 }
2302 }
2303 if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
2304 if ((buflen -= 4) < 0)
2305 goto out_resource;
2306 WRITE32(0);
2307 }
2308 if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
2309 if ((buflen -= 4) < 0)
2310 goto out_resource;
Stanislav Kinsbursky3d733712012-11-27 14:11:44 +03002311 WRITE32(nn->nfsd4_lease);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 }
2313 if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
2314 if ((buflen -= 4) < 0)
2315 goto out_resource;
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002316 WRITE32(rdattr_err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318 if (bmval0 & FATTR4_WORD0_ACL) {
2319 struct nfs4_ace *ace;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
2321 if (acl == NULL) {
2322 if ((buflen -= 4) < 0)
2323 goto out_resource;
2324
2325 WRITE32(0);
2326 goto out_acl;
2327 }
2328 if ((buflen -= 4) < 0)
2329 goto out_resource;
2330 WRITE32(acl->naces);
2331
J. Bruce Fields28e05dd2007-02-16 01:28:30 -08002332 for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 if ((buflen -= 4*3) < 0)
2334 goto out_resource;
2335 WRITE32(ace->type);
2336 WRITE32(ace->flag);
2337 WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL);
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002338 status = nfsd4_encode_aclname(rqstp, ace, &p, &buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (status == nfserr_resource)
2340 goto out_resource;
2341 if (status)
2342 goto out;
2343 }
2344 }
2345out_acl:
2346 if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
2347 if ((buflen -= 4) < 0)
2348 goto out_resource;
2349 WRITE32(aclsupport ?
2350 ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
2351 }
2352 if (bmval0 & FATTR4_WORD0_CANSETTIME) {
2353 if ((buflen -= 4) < 0)
2354 goto out_resource;
2355 WRITE32(1);
2356 }
2357 if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
2358 if ((buflen -= 4) < 0)
2359 goto out_resource;
J. Bruce Fields2930d382012-06-05 16:52:06 -04002360 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 }
2362 if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
2363 if ((buflen -= 4) < 0)
2364 goto out_resource;
2365 WRITE32(1);
2366 }
2367 if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
2368 if ((buflen -= 4) < 0)
2369 goto out_resource;
2370 WRITE32(1);
2371 }
2372 if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
2373 buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4;
2374 if (buflen < 0)
2375 goto out_resource;
2376 WRITE32(fhp->fh_handle.fh_size);
2377 WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size);
2378 }
2379 if (bmval0 & FATTR4_WORD0_FILEID) {
2380 if ((buflen -= 8) < 0)
2381 goto out_resource;
Peter Staubach40ee5dc2007-08-16 12:10:07 -04002382 WRITE64(stat.ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 }
2384 if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
2385 if ((buflen -= 8) < 0)
2386 goto out_resource;
2387 WRITE64((u64) statfs.f_ffree);
2388 }
2389 if (bmval0 & FATTR4_WORD0_FILES_FREE) {
2390 if ((buflen -= 8) < 0)
2391 goto out_resource;
2392 WRITE64((u64) statfs.f_ffree);
2393 }
2394 if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
2395 if ((buflen -= 8) < 0)
2396 goto out_resource;
2397 WRITE64((u64) statfs.f_files);
2398 }
J.Bruce Fields81c3f412006-10-04 02:16:19 -07002399 if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
2400 status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen);
2401 if (status == nfserr_resource)
2402 goto out_resource;
2403 if (status)
2404 goto out;
2405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
2407 if ((buflen -= 4) < 0)
2408 goto out_resource;
2409 WRITE32(1);
2410 }
2411 if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
2412 if ((buflen -= 8) < 0)
2413 goto out_resource;
Christoph Hellwigaea240f2013-11-14 05:50:10 -08002414 WRITE64(exp->ex_path.mnt->mnt_sb->s_maxbytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 }
2416 if (bmval0 & FATTR4_WORD0_MAXLINK) {
2417 if ((buflen -= 4) < 0)
2418 goto out_resource;
2419 WRITE32(255);
2420 }
2421 if (bmval0 & FATTR4_WORD0_MAXNAME) {
2422 if ((buflen -= 4) < 0)
2423 goto out_resource;
J. Bruce Fieldsa16e92e2007-09-28 16:45:51 -04002424 WRITE32(statfs.f_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 }
2426 if (bmval0 & FATTR4_WORD0_MAXREAD) {
2427 if ((buflen -= 8) < 0)
2428 goto out_resource;
Greg Banks7adae482006-10-04 02:15:47 -07002429 WRITE64((u64) svc_max_payload(rqstp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 }
2431 if (bmval0 & FATTR4_WORD0_MAXWRITE) {
2432 if ((buflen -= 8) < 0)
2433 goto out_resource;
Greg Banks7adae482006-10-04 02:15:47 -07002434 WRITE64((u64) svc_max_payload(rqstp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 }
2436 if (bmval1 & FATTR4_WORD1_MODE) {
2437 if ((buflen -= 4) < 0)
2438 goto out_resource;
2439 WRITE32(stat.mode & S_IALLUGO);
2440 }
2441 if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
2442 if ((buflen -= 4) < 0)
2443 goto out_resource;
2444 WRITE32(1);
2445 }
2446 if (bmval1 & FATTR4_WORD1_NUMLINKS) {
2447 if ((buflen -= 4) < 0)
2448 goto out_resource;
2449 WRITE32(stat.nlink);
2450 }
2451 if (bmval1 & FATTR4_WORD1_OWNER) {
2452 status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
2453 if (status == nfserr_resource)
2454 goto out_resource;
2455 if (status)
2456 goto out;
2457 }
2458 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
2459 status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
2460 if (status == nfserr_resource)
2461 goto out_resource;
2462 if (status)
2463 goto out;
2464 }
2465 if (bmval1 & FATTR4_WORD1_RAWDEV) {
2466 if ((buflen -= 8) < 0)
2467 goto out_resource;
2468 WRITE32((u32) MAJOR(stat.rdev));
2469 WRITE32((u32) MINOR(stat.rdev));
2470 }
2471 if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
2472 if ((buflen -= 8) < 0)
2473 goto out_resource;
2474 dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
2475 WRITE64(dummy64);
2476 }
2477 if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
2478 if ((buflen -= 8) < 0)
2479 goto out_resource;
2480 dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
2481 WRITE64(dummy64);
2482 }
2483 if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
2484 if ((buflen -= 8) < 0)
2485 goto out_resource;
2486 dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
2487 WRITE64(dummy64);
2488 }
2489 if (bmval1 & FATTR4_WORD1_SPACE_USED) {
2490 if ((buflen -= 8) < 0)
2491 goto out_resource;
2492 dummy64 = (u64)stat.blocks << 9;
2493 WRITE64(dummy64);
2494 }
2495 if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
2496 if ((buflen -= 12) < 0)
2497 goto out_resource;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -04002498 WRITE64((s64)stat.atime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 WRITE32(stat.atime.tv_nsec);
2500 }
2501 if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
2502 if ((buflen -= 12) < 0)
2503 goto out_resource;
2504 WRITE32(0);
2505 WRITE32(1);
2506 WRITE32(0);
2507 }
2508 if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
2509 if ((buflen -= 12) < 0)
2510 goto out_resource;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -04002511 WRITE64((s64)stat.ctime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 WRITE32(stat.ctime.tv_nsec);
2513 }
2514 if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
2515 if ((buflen -= 12) < 0)
2516 goto out_resource;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -04002517 WRITE64((s64)stat.mtime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 WRITE32(stat.mtime.tv_nsec);
2519 }
2520 if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 if ((buflen -= 8) < 0)
2522 goto out_resource;
Frank Filz406a7ea2007-11-27 11:34:05 -08002523 /*
2524 * Get parent's attributes if not ignoring crossmount
2525 * and this is the root of a cross-mounted filesystem.
2526 */
2527 if (ignore_crossmnt == 0 &&
J. Bruce Fieldsae7095a2012-10-01 17:50:56 -04002528 dentry == exp->ex_path.mnt->mnt_root)
2529 get_parent_attributes(exp, &stat);
Peter Staubach40ee5dc2007-08-16 12:10:07 -04002530 WRITE64(stat.ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
David Quigley18032ca2013-05-02 13:19:10 -04002532 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
2533 status = nfsd4_encode_security_label(rqstp, context,
2534 contextlen, &p, &buflen);
2535 if (status)
2536 goto out;
2537 }
Benny Halevy8c18f202009-04-03 08:29:14 +03002538 if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
2539 WRITE32(3);
2540 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
2541 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1);
2542 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2);
2543 }
Andy Adamson7e705702009-04-03 08:29:11 +03002544
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
J. Bruce Fields84822d02012-12-14 17:57:50 -05002546 *buffer = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 status = nfs_ok;
2548
2549out:
J. Bruce Fieldsba4e55b2013-05-15 10:27:52 -04002550#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
David Quigley18032ca2013-05-02 13:19:10 -04002551 if (context)
2552 security_release_secctx(context, contextlen);
J. Bruce Fieldsba4e55b2013-05-15 10:27:52 -04002553#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
J. Bruce Fields28e05dd2007-02-16 01:28:30 -08002554 kfree(acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 if (fhp == &tempfh)
2556 fh_put(&tempfh);
2557 return status;
2558out_nfserr:
Al Virob8dd7b92006-10-19 23:29:01 -07002559 status = nfserrno(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 goto out;
2561out_resource:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 status = nfserr_resource;
2563 goto out;
2564out_serverfault:
2565 status = nfserr_serverfault;
2566 goto out;
2567}
2568
J. Bruce Fieldsc0ce6ec2008-02-11 15:48:47 -05002569static inline int attributes_need_mount(u32 *bmval)
2570{
2571 if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
2572 return 1;
2573 if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
2574 return 1;
2575 return 0;
2576}
2577
Al Virob37ad282006-10-19 23:28:59 -07002578static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
J. Bruce Fields84822d02012-12-14 17:57:50 -05002580 const char *name, int namlen, __be32 **p, int buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581{
2582 struct svc_export *exp = cd->rd_fhp->fh_export;
2583 struct dentry *dentry;
Al Virob37ad282006-10-19 23:28:59 -07002584 __be32 nfserr;
Frank Filz406a7ea2007-11-27 11:34:05 -08002585 int ignore_crossmnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
2588 if (IS_ERR(dentry))
2589 return nfserrno(PTR_ERR(dentry));
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002590 if (!dentry->d_inode) {
2591 /*
2592 * nfsd_buffered_readdir drops the i_mutex between
2593 * readdir and calling this callback, leaving a window
2594 * where this directory entry could have gone away.
2595 */
2596 dput(dentry);
2597 return nfserr_noent;
2598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
2600 exp_get(exp);
Frank Filz406a7ea2007-11-27 11:34:05 -08002601 /*
2602 * In the case of a mountpoint, the client may be asking for
2603 * attributes that are only properties of the underlying filesystem
2604 * as opposed to the cross-mounted file system. In such a case,
2605 * we will not follow the cross mount and will fill the attribtutes
2606 * directly from the mountpoint dentry.
2607 */
J. Bruce Fields3227fa42009-10-25 21:43:01 -04002608 if (nfsd_mountpoint(dentry, exp)) {
J.Bruce Fields021d3a72006-12-13 00:35:24 -08002609 int err;
2610
J. Bruce Fields3227fa42009-10-25 21:43:01 -04002611 if (!(exp->ex_flags & NFSEXP_V4ROOT)
2612 && !attributes_need_mount(cd->rd_bmval)) {
2613 ignore_crossmnt = 1;
2614 goto out_encode;
2615 }
Andy Adamsondcb488a32007-07-17 04:04:51 -07002616 /*
2617 * Why the heck aren't we just using nfsd_lookup??
2618 * Different "."/".." handling? Something else?
2619 * At least, add a comment here to explain....
2620 */
J.Bruce Fields021d3a72006-12-13 00:35:24 -08002621 err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
2622 if (err) {
2623 nfserr = nfserrno(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 goto out_put;
2625 }
Andy Adamsondcb488a32007-07-17 04:04:51 -07002626 nfserr = check_nfsd_access(exp, cd->rd_rqstp);
2627 if (nfserr)
2628 goto out_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
2630 }
J. Bruce Fields3227fa42009-10-25 21:43:01 -04002631out_encode:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08002633 cd->rd_rqstp, ignore_crossmnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634out_put:
2635 dput(dentry);
2636 exp_put(exp);
2637 return nfserr;
2638}
2639
Al Viro2ebbc012006-10-19 23:28:58 -07002640static __be32 *
Al Virob37ad282006-10-19 23:28:59 -07002641nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642{
Al Viro2ebbc012006-10-19 23:28:58 -07002643 __be32 *attrlenp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 if (buflen < 6)
2646 return NULL;
2647 *p++ = htonl(2);
2648 *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
2649 *p++ = htonl(0); /* bmval1 */
2650
2651 attrlenp = p++;
2652 *p++ = nfserr; /* no htonl */
2653 *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
2654 return p;
2655}
2656
2657static int
NeilBrowna0ad13e2007-01-26 00:57:10 -08002658nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
2659 loff_t offset, u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
NeilBrowna0ad13e2007-01-26 00:57:10 -08002661 struct readdir_cd *ccd = ccdv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
2663 int buflen;
Al Viro2ebbc012006-10-19 23:28:58 -07002664 __be32 *p = cd->buffer;
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002665 __be32 *cookiep;
Al Virob37ad282006-10-19 23:28:59 -07002666 __be32 nfserr = nfserr_toosmall;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
2668 /* In nfsv4, "." and ".." never make it onto the wire.. */
2669 if (name && isdotent(name, namlen)) {
2670 cd->common.err = nfs_ok;
2671 return 0;
2672 }
2673
2674 if (cd->offset)
2675 xdr_encode_hyper(cd->offset, (u64) offset);
2676
2677 buflen = cd->buflen - 4 - XDR_QUADLEN(namlen);
2678 if (buflen < 0)
2679 goto fail;
2680
2681 *p++ = xdr_one; /* mark entry present */
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002682 cookiep = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
2684 p = xdr_encode_array(p, name, namlen); /* name length & name */
2685
J. Bruce Fields84822d02012-12-14 17:57:50 -05002686 nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, &p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 switch (nfserr) {
2688 case nfs_ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 break;
2690 case nfserr_resource:
2691 nfserr = nfserr_toosmall;
2692 goto fail;
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002693 case nfserr_noent:
2694 goto skip_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 default:
2696 /*
2697 * If the client requested the RDATTR_ERROR attribute,
2698 * we stuff the error code into this attribute
2699 * and continue. If this attribute was not requested,
2700 * then in accordance with the spec, we fail the
2701 * entire READDIR operation(!)
2702 */
2703 if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
2704 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 p = nfsd4_encode_rdattr_error(p, buflen, nfserr);
Fred Isaman34081ef2006-01-18 17:43:40 -08002706 if (p == NULL) {
2707 nfserr = nfserr_toosmall;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 goto fail;
Fred Isaman34081ef2006-01-18 17:43:40 -08002709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 }
2711 cd->buflen -= (p - cd->buffer);
2712 cd->buffer = p;
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002713 cd->offset = cookiep;
2714skip_entry:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 cd->common.err = nfs_ok;
2716 return 0;
2717fail:
2718 cd->common.err = nfserr;
2719 return -EINVAL;
2720}
2721
Benny Halevye2f282b2008-08-12 20:45:07 +03002722static void
2723nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
2724{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002725 __be32 *p;
Benny Halevye2f282b2008-08-12 20:45:07 +03002726
2727 RESERVE_SPACE(sizeof(stateid_t));
2728 WRITE32(sid->si_generation);
2729 WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
2730 ADJUST_ARGS();
2731}
2732
Benny Halevy695e12f2008-07-04 14:38:33 +03002733static __be32
Al Virob37ad282006-10-19 23:28:59 -07002734nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
2738 if (!nfserr) {
2739 RESERVE_SPACE(8);
2740 WRITE32(access->ac_supported);
2741 WRITE32(access->ac_resp_access);
2742 ADJUST_ARGS();
2743 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002744 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745}
2746
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04002747static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts)
2748{
2749 __be32 *p;
2750
2751 if (!nfserr) {
2752 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 8);
2753 WRITEMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
2754 WRITE32(bcts->dir);
J. Bruce Fields6e67b5d2012-09-13 09:49:43 -04002755 /* Sorry, we do not yet support RDMA over 4.1: */
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04002756 WRITE32(0);
2757 ADJUST_ARGS();
2758 }
2759 return nfserr;
2760}
2761
Benny Halevy695e12f2008-07-04 14:38:33 +03002762static __be32
Al Virob37ad282006-10-19 23:28:59 -07002763nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764{
Benny Halevye2f282b2008-08-12 20:45:07 +03002765 if (!nfserr)
2766 nfsd4_encode_stateid(resp, &close->cl_stateid);
2767
Benny Halevy695e12f2008-07-04 14:38:33 +03002768 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769}
2770
2771
Benny Halevy695e12f2008-07-04 14:38:33 +03002772static __be32
Al Virob37ad282006-10-19 23:28:59 -07002773nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002775 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777 if (!nfserr) {
Chuck Leverab4684d2012-03-02 17:13:50 -05002778 RESERVE_SPACE(NFS4_VERIFIER_SIZE);
2779 WRITEMEM(commit->co_verf.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 ADJUST_ARGS();
2781 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002782 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783}
2784
Benny Halevy695e12f2008-07-04 14:38:33 +03002785static __be32
Al Virob37ad282006-10-19 23:28:59 -07002786nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002788 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
2790 if (!nfserr) {
2791 RESERVE_SPACE(32);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002792 write_cinfo(&p, &create->cr_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 WRITE32(2);
2794 WRITE32(create->cr_bmval[0]);
2795 WRITE32(create->cr_bmval[1]);
2796 ADJUST_ARGS();
2797 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002798 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799}
2800
Al Virob37ad282006-10-19 23:28:59 -07002801static __be32
2802nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803{
2804 struct svc_fh *fhp = getattr->ga_fhp;
2805 int buflen;
2806
2807 if (nfserr)
2808 return nfserr;
2809
2810 buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
2811 nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
J. Bruce Fields84822d02012-12-14 17:57:50 -05002812 &resp->p, buflen, getattr->ga_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08002813 resp->rqstp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 return nfserr;
2815}
2816
Benny Halevy695e12f2008-07-04 14:38:33 +03002817static __be32
2818nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819{
Benny Halevy695e12f2008-07-04 14:38:33 +03002820 struct svc_fh *fhp = *fhpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 unsigned int len;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002822 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
2824 if (!nfserr) {
2825 len = fhp->fh_handle.fh_size;
2826 RESERVE_SPACE(len + 4);
2827 WRITE32(len);
2828 WRITEMEM(&fhp->fh_handle.fh_base, len);
2829 ADJUST_ARGS();
2830 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002831 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832}
2833
2834/*
2835* Including all fields other than the name, a LOCK4denied structure requires
2836* 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
2837*/
2838static void
2839nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld)
2840{
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002841 struct xdr_netobj *conf = &ld->ld_owner;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002842 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002844 RESERVE_SPACE(32 + XDR_LEN(conf->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 WRITE64(ld->ld_start);
2846 WRITE64(ld->ld_length);
2847 WRITE32(ld->ld_type);
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002848 if (conf->len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 WRITEMEM(&ld->ld_clientid, 8);
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002850 WRITE32(conf->len);
2851 WRITEMEM(conf->data, conf->len);
2852 kfree(conf->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
2854 WRITE64((u64)0); /* clientid */
2855 WRITE32(0); /* length of owner name */
2856 }
2857 ADJUST_ARGS();
2858}
2859
Benny Halevy695e12f2008-07-04 14:38:33 +03002860static __be32
Al Virob37ad282006-10-19 23:28:59 -07002861nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862{
Benny Halevye2f282b2008-08-12 20:45:07 +03002863 if (!nfserr)
2864 nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
2865 else if (nfserr == nfserr_denied)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 nfsd4_encode_lock_denied(resp, &lock->lk_denied);
2867
Benny Halevy695e12f2008-07-04 14:38:33 +03002868 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869}
2870
Benny Halevy695e12f2008-07-04 14:38:33 +03002871static __be32
Al Virob37ad282006-10-19 23:28:59 -07002872nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873{
2874 if (nfserr == nfserr_denied)
2875 nfsd4_encode_lock_denied(resp, &lockt->lt_denied);
Benny Halevy695e12f2008-07-04 14:38:33 +03002876 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877}
2878
Benny Halevy695e12f2008-07-04 14:38:33 +03002879static __be32
Al Virob37ad282006-10-19 23:28:59 -07002880nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881{
Benny Halevye2f282b2008-08-12 20:45:07 +03002882 if (!nfserr)
2883 nfsd4_encode_stateid(resp, &locku->lu_stateid);
2884
Benny Halevy695e12f2008-07-04 14:38:33 +03002885 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886}
2887
2888
Benny Halevy695e12f2008-07-04 14:38:33 +03002889static __be32
Al Virob37ad282006-10-19 23:28:59 -07002890nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002892 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893
2894 if (!nfserr) {
2895 RESERVE_SPACE(20);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002896 write_cinfo(&p, &link->li_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 ADJUST_ARGS();
2898 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002899 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900}
2901
2902
Benny Halevy695e12f2008-07-04 14:38:33 +03002903static __be32
Al Virob37ad282006-10-19 23:28:59 -07002904nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
2908 if (nfserr)
2909 goto out;
2910
Benny Halevye2f282b2008-08-12 20:45:07 +03002911 nfsd4_encode_stateid(resp, &open->op_stateid);
2912 RESERVE_SPACE(40);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002913 write_cinfo(&p, &open->op_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 WRITE32(open->op_rflags);
2915 WRITE32(2);
2916 WRITE32(open->op_bmval[0]);
2917 WRITE32(open->op_bmval[1]);
2918 WRITE32(open->op_delegate_type);
2919 ADJUST_ARGS();
2920
2921 switch (open->op_delegate_type) {
2922 case NFS4_OPEN_DELEGATE_NONE:
2923 break;
2924 case NFS4_OPEN_DELEGATE_READ:
Benny Halevye2f282b2008-08-12 20:45:07 +03002925 nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
2926 RESERVE_SPACE(20);
NeilBrown7b190fe2005-06-23 22:03:23 -07002927 WRITE32(open->op_recall);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
2929 /*
2930 * TODO: ACE's in delegations
2931 */
2932 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
2933 WRITE32(0);
2934 WRITE32(0);
2935 WRITE32(0); /* XXX: is NULL principal ok? */
2936 ADJUST_ARGS();
2937 break;
2938 case NFS4_OPEN_DELEGATE_WRITE:
Benny Halevye2f282b2008-08-12 20:45:07 +03002939 nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
2940 RESERVE_SPACE(32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 WRITE32(0);
2942
2943 /*
2944 * TODO: space_limit's in delegations
2945 */
2946 WRITE32(NFS4_LIMIT_SIZE);
2947 WRITE32(~(u32)0);
2948 WRITE32(~(u32)0);
2949
2950 /*
2951 * TODO: ACE's in delegations
2952 */
2953 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
2954 WRITE32(0);
2955 WRITE32(0);
2956 WRITE32(0); /* XXX: is NULL principal ok? */
2957 ADJUST_ARGS();
2958 break;
Benny Halevyd24433c2012-02-16 20:57:17 +02002959 case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */
2960 switch (open->op_why_no_deleg) {
2961 case WND4_CONTENTION:
2962 case WND4_RESOURCE:
2963 RESERVE_SPACE(8);
2964 WRITE32(open->op_why_no_deleg);
2965 WRITE32(0); /* deleg signaling not supported yet */
2966 break;
2967 default:
2968 RESERVE_SPACE(4);
2969 WRITE32(open->op_why_no_deleg);
2970 }
2971 ADJUST_ARGS();
2972 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 default:
2974 BUG();
2975 }
2976 /* XXX save filehandle here */
2977out:
Benny Halevy695e12f2008-07-04 14:38:33 +03002978 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979}
2980
Benny Halevy695e12f2008-07-04 14:38:33 +03002981static __be32
Al Virob37ad282006-10-19 23:28:59 -07002982nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983{
Benny Halevye2f282b2008-08-12 20:45:07 +03002984 if (!nfserr)
2985 nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986
Benny Halevy695e12f2008-07-04 14:38:33 +03002987 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988}
2989
Benny Halevy695e12f2008-07-04 14:38:33 +03002990static __be32
Al Virob37ad282006-10-19 23:28:59 -07002991nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992{
Benny Halevye2f282b2008-08-12 20:45:07 +03002993 if (!nfserr)
2994 nfsd4_encode_stateid(resp, &od->od_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Benny Halevy695e12f2008-07-04 14:38:33 +03002996 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997}
2998
Al Virob37ad282006-10-19 23:28:59 -07002999static __be32
3000nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
NeilBrown44524352006-10-04 02:15:46 -07003001 struct nfsd4_read *read)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002{
3003 u32 eof;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003004 int v;
3005 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 unsigned long maxcount;
3007 long len;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003008 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009
3010 if (nfserr)
3011 return nfserr;
3012 if (resp->xbuf->page_len)
3013 return nfserr_resource;
3014
3015 RESERVE_SPACE(8); /* eof flag and byte count */
3016
Greg Banks7adae482006-10-04 02:15:47 -07003017 maxcount = svc_max_payload(resp->rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 if (maxcount > read->rd_length)
3019 maxcount = read->rd_length;
3020
3021 len = maxcount;
3022 v = 0;
3023 while (len > 0) {
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003024 page = *(resp->rqstp->rq_next_page);
3025 if (!page) { /* ran out of pages */
J. Bruce Fieldsd5f50b02012-12-04 18:25:10 -05003026 maxcount -= len;
3027 break;
3028 }
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003029 resp->rqstp->rq_vec[v].iov_base = page_address(page);
NeilBrown3cc03b12006-10-04 02:15:47 -07003030 resp->rqstp->rq_vec[v].iov_len =
NeilBrown44524352006-10-04 02:15:46 -07003031 len < PAGE_SIZE ? len : PAGE_SIZE;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003032 resp->rqstp->rq_next_page++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 v++;
3034 len -= PAGE_SIZE;
3035 }
3036 read->rd_vlen = v;
3037
J. Bruce Fields039a87c2010-07-30 11:33:32 -04003038 nfserr = nfsd_read_file(read->rd_rqstp, read->rd_fhp, read->rd_filp,
NeilBrown3cc03b12006-10-04 02:15:47 -07003039 read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 &maxcount);
3041
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 if (nfserr)
3043 return nfserr;
NeilBrown44524352006-10-04 02:15:46 -07003044 eof = (read->rd_offset + maxcount >=
3045 read->rd_fhp->fh_dentry->d_inode->i_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
3047 WRITE32(eof);
3048 WRITE32(maxcount);
3049 ADJUST_ARGS();
NeilBrown6ed6dec2006-04-10 22:55:32 -07003050 resp->xbuf->head[0].iov_len = (char*)p
3051 - (char*)resp->xbuf->head[0].iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 resp->xbuf->page_len = maxcount;
3053
NeilBrown6ed6dec2006-04-10 22:55:32 -07003054 /* Use rest of head for padding and remaining ops: */
NeilBrown6ed6dec2006-04-10 22:55:32 -07003055 resp->xbuf->tail[0].iov_base = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 resp->xbuf->tail[0].iov_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 if (maxcount&3) {
NeilBrown6ed6dec2006-04-10 22:55:32 -07003058 RESERVE_SPACE(4);
3059 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 resp->xbuf->tail[0].iov_base += maxcount&3;
3061 resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
NeilBrown6ed6dec2006-04-10 22:55:32 -07003062 ADJUST_ARGS();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 }
3064 return 0;
3065}
3066
Al Virob37ad282006-10-19 23:28:59 -07003067static __be32
3068nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069{
3070 int maxcount;
3071 char *page;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003072 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074 if (nfserr)
3075 return nfserr;
3076 if (resp->xbuf->page_len)
3077 return nfserr_resource;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003078 if (!*resp->rqstp->rq_next_page)
J. Bruce Fieldsd5f50b02012-12-04 18:25:10 -05003079 return nfserr_resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003081 page = page_address(*(resp->rqstp->rq_next_page++));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 maxcount = PAGE_SIZE;
3084 RESERVE_SPACE(4);
3085
3086 /*
3087 * XXX: By default, the ->readlink() VFS op will truncate symlinks
3088 * if they would overflow the buffer. Is this kosher in NFSv4? If
3089 * not, one easy fix is: if ->readlink() precisely fills the buffer,
3090 * assume that truncation occurred, and return NFS4ERR_RESOURCE.
3091 */
3092 nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
3093 if (nfserr == nfserr_isdir)
3094 return nfserr_inval;
3095 if (nfserr)
3096 return nfserr;
3097
3098 WRITE32(maxcount);
3099 ADJUST_ARGS();
NeilBrown6ed6dec2006-04-10 22:55:32 -07003100 resp->xbuf->head[0].iov_len = (char*)p
3101 - (char*)resp->xbuf->head[0].iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 resp->xbuf->page_len = maxcount;
NeilBrown6ed6dec2006-04-10 22:55:32 -07003103
3104 /* Use rest of head for padding and remaining ops: */
NeilBrown6ed6dec2006-04-10 22:55:32 -07003105 resp->xbuf->tail[0].iov_base = p;
3106 resp->xbuf->tail[0].iov_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 if (maxcount&3) {
NeilBrown6ed6dec2006-04-10 22:55:32 -07003108 RESERVE_SPACE(4);
3109 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 resp->xbuf->tail[0].iov_base += maxcount&3;
3111 resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
NeilBrown6ed6dec2006-04-10 22:55:32 -07003112 ADJUST_ARGS();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 }
3114 return 0;
3115}
3116
Al Virob37ad282006-10-19 23:28:59 -07003117static __be32
3118nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119{
3120 int maxcount;
3121 loff_t offset;
Al Viro2ebbc012006-10-19 23:28:58 -07003122 __be32 *page, *savep, *tailbase;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003123 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 if (nfserr)
3126 return nfserr;
3127 if (resp->xbuf->page_len)
3128 return nfserr_resource;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003129 if (!*resp->rqstp->rq_next_page)
J. Bruce Fieldsd5f50b02012-12-04 18:25:10 -05003130 return nfserr_resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
Chuck Leverab4684d2012-03-02 17:13:50 -05003132 RESERVE_SPACE(NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 savep = p;
3134
3135 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
3136 WRITE32(0);
3137 WRITE32(0);
3138 ADJUST_ARGS();
3139 resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base;
NeilBrownbb6e8a92006-04-10 22:55:33 -07003140 tailbase = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
3142 maxcount = PAGE_SIZE;
3143 if (maxcount > readdir->rd_maxcount)
3144 maxcount = readdir->rd_maxcount;
3145
3146 /*
3147 * Convert from bytes to words, account for the two words already
3148 * written, make sure to leave two words at the end for the next
3149 * pointer and eof field.
3150 */
3151 maxcount = (maxcount >> 2) - 4;
3152 if (maxcount < 0) {
3153 nfserr = nfserr_toosmall;
3154 goto err_no_verf;
3155 }
3156
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003157 page = page_address(*(resp->rqstp->rq_next_page++));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 readdir->common.err = 0;
3159 readdir->buflen = maxcount;
3160 readdir->buffer = page;
3161 readdir->offset = NULL;
3162
3163 offset = readdir->rd_cookie;
3164 nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
3165 &offset,
3166 &readdir->common, nfsd4_encode_dirent);
3167 if (nfserr == nfs_ok &&
3168 readdir->common.err == nfserr_toosmall &&
3169 readdir->buffer == page)
3170 nfserr = nfserr_toosmall;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 if (nfserr)
3172 goto err_no_verf;
3173
3174 if (readdir->offset)
3175 xdr_encode_hyper(readdir->offset, offset);
3176
3177 p = readdir->buffer;
3178 *p++ = 0; /* no more entries */
3179 *p++ = htonl(readdir->common.err == nfserr_eof);
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003180 resp->xbuf->page_len = ((char*)p) -
3181 (char*)page_address(*(resp->rqstp->rq_next_page-1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
NeilBrownbb6e8a92006-04-10 22:55:33 -07003183 /* Use rest of head for padding and remaining ops: */
NeilBrownbb6e8a92006-04-10 22:55:33 -07003184 resp->xbuf->tail[0].iov_base = tailbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 resp->xbuf->tail[0].iov_len = 0;
3186 resp->p = resp->xbuf->tail[0].iov_base;
NeilBrownbb6e8a92006-04-10 22:55:33 -07003187 resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 return 0;
3190err_no_verf:
3191 p = savep;
3192 ADJUST_ARGS();
3193 return nfserr;
3194}
3195
Benny Halevy695e12f2008-07-04 14:38:33 +03003196static __be32
Al Virob37ad282006-10-19 23:28:59 -07003197nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
3201 if (!nfserr) {
3202 RESERVE_SPACE(20);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04003203 write_cinfo(&p, &remove->rm_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 ADJUST_ARGS();
3205 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003206 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207}
3208
Benny Halevy695e12f2008-07-04 14:38:33 +03003209static __be32
Al Virob37ad282006-10-19 23:28:59 -07003210nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
3214 if (!nfserr) {
3215 RESERVE_SPACE(40);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04003216 write_cinfo(&p, &rename->rn_sinfo);
3217 write_cinfo(&p, &rename->rn_tinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 ADJUST_ARGS();
3219 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003220 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221}
3222
Benny Halevy695e12f2008-07-04 14:38:33 +03003223static __be32
Mi Jinlong22b6dee2010-12-27 14:29:57 +08003224nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp,
Chuck Levera77c8062013-03-16 15:55:10 -04003225 __be32 nfserr, struct svc_export *exp)
Andy Adamsondcb488a32007-07-17 04:04:51 -07003226{
Chuck Lever676e4eb2013-04-30 18:48:54 -04003227 u32 i, nflavs, supported;
J. Bruce Fields4796f452007-07-17 04:04:51 -07003228 struct exp_flavor_info *flavs;
3229 struct exp_flavor_info def_flavs[2];
Chuck Lever676e4eb2013-04-30 18:48:54 -04003230 __be32 *p, *flavorsp;
3231 static bool report = true;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003232
3233 if (nfserr)
3234 goto out;
J. Bruce Fields4796f452007-07-17 04:04:51 -07003235 if (exp->ex_nflavors) {
3236 flavs = exp->ex_flavors;
3237 nflavs = exp->ex_nflavors;
3238 } else { /* Handling of some defaults in absence of real secinfo: */
3239 flavs = def_flavs;
3240 if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
3241 nflavs = 2;
3242 flavs[0].pseudoflavor = RPC_AUTH_UNIX;
3243 flavs[1].pseudoflavor = RPC_AUTH_NULL;
3244 } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
3245 nflavs = 1;
3246 flavs[0].pseudoflavor
3247 = svcauth_gss_flavor(exp->ex_client);
3248 } else {
3249 nflavs = 1;
3250 flavs[0].pseudoflavor
3251 = exp->ex_client->flavour->flavour;
3252 }
3253 }
3254
Chuck Lever676e4eb2013-04-30 18:48:54 -04003255 supported = 0;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003256 RESERVE_SPACE(4);
Chuck Lever676e4eb2013-04-30 18:48:54 -04003257 flavorsp = p++; /* to be backfilled later */
Andy Adamsondcb488a32007-07-17 04:04:51 -07003258 ADJUST_ARGS();
Chuck Lever676e4eb2013-04-30 18:48:54 -04003259
J. Bruce Fields4796f452007-07-17 04:04:51 -07003260 for (i = 0; i < nflavs; i++) {
Chuck Lever676e4eb2013-04-30 18:48:54 -04003261 rpc_authflavor_t pf = flavs[i].pseudoflavor;
Chuck Levera77c8062013-03-16 15:55:10 -04003262 struct rpcsec_gss_info info;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003263
Chuck Lever676e4eb2013-04-30 18:48:54 -04003264 if (rpcauth_get_gssinfo(pf, &info) == 0) {
3265 supported++;
Chuck Levered9411a2013-04-30 18:48:45 -04003266 RESERVE_SPACE(4 + 4 + info.oid.len + 4 + 4);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003267 WRITE32(RPC_AUTH_GSS);
Chuck Levera77c8062013-03-16 15:55:10 -04003268 WRITE32(info.oid.len);
3269 WRITEMEM(info.oid.data, info.oid.len);
Chuck Levera77c8062013-03-16 15:55:10 -04003270 WRITE32(info.qop);
Chuck Levera77c8062013-03-16 15:55:10 -04003271 WRITE32(info.service);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003272 ADJUST_ARGS();
Chuck Lever676e4eb2013-04-30 18:48:54 -04003273 } else if (pf < RPC_AUTH_MAXFLAVOR) {
3274 supported++;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003275 RESERVE_SPACE(4);
Chuck Lever676e4eb2013-04-30 18:48:54 -04003276 WRITE32(pf);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003277 ADJUST_ARGS();
Chuck Lever676e4eb2013-04-30 18:48:54 -04003278 } else {
3279 if (report)
3280 pr_warn("NFS: SECINFO: security flavor %u "
3281 "is not supported\n", pf);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003282 }
3283 }
Chuck Levera77c8062013-03-16 15:55:10 -04003284
Chuck Lever676e4eb2013-04-30 18:48:54 -04003285 if (nflavs != supported)
3286 report = false;
3287 *flavorsp = htonl(supported);
3288
Andy Adamsondcb488a32007-07-17 04:04:51 -07003289out:
3290 if (exp)
3291 exp_put(exp);
Benny Halevy695e12f2008-07-04 14:38:33 +03003292 return nfserr;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003293}
3294
Mi Jinlong22b6dee2010-12-27 14:29:57 +08003295static __be32
3296nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
3297 struct nfsd4_secinfo *secinfo)
3298{
3299 return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->si_exp);
3300}
3301
3302static __be32
3303nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
3304 struct nfsd4_secinfo_no_name *secinfo)
3305{
3306 return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->sin_exp);
3307}
3308
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309/*
3310 * The SETATTR encode routine is special -- it always encodes a bitmap,
3311 * regardless of the error status.
3312 */
Benny Halevy695e12f2008-07-04 14:38:33 +03003313static __be32
Al Virob37ad282006-10-19 23:28:59 -07003314nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
David Quigley18032ca2013-05-02 13:19:10 -04003318 RESERVE_SPACE(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 if (nfserr) {
David Quigley18032ca2013-05-02 13:19:10 -04003320 WRITE32(3);
3321 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 WRITE32(0);
3323 WRITE32(0);
3324 }
3325 else {
David Quigley18032ca2013-05-02 13:19:10 -04003326 WRITE32(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 WRITE32(setattr->sa_bmval[0]);
3328 WRITE32(setattr->sa_bmval[1]);
David Quigley18032ca2013-05-02 13:19:10 -04003329 WRITE32(setattr->sa_bmval[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 }
3331 ADJUST_ARGS();
Benny Halevy695e12f2008-07-04 14:38:33 +03003332 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333}
3334
Benny Halevy695e12f2008-07-04 14:38:33 +03003335static __be32
Al Virob37ad282006-10-19 23:28:59 -07003336nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 if (!nfserr) {
Chuck Leverab4684d2012-03-02 17:13:50 -05003341 RESERVE_SPACE(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 WRITEMEM(&scd->se_clientid, 8);
Chuck Leverab4684d2012-03-02 17:13:50 -05003343 WRITEMEM(&scd->se_confirm, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 ADJUST_ARGS();
3345 }
3346 else if (nfserr == nfserr_clid_inuse) {
3347 RESERVE_SPACE(8);
3348 WRITE32(0);
3349 WRITE32(0);
3350 ADJUST_ARGS();
3351 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003352 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353}
3354
Benny Halevy695e12f2008-07-04 14:38:33 +03003355static __be32
Al Virob37ad282006-10-19 23:28:59 -07003356nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
3360 if (!nfserr) {
3361 RESERVE_SPACE(16);
3362 WRITE32(write->wr_bytes_written);
3363 WRITE32(write->wr_how_written);
Chuck Leverab4684d2012-03-02 17:13:50 -05003364 WRITEMEM(write->wr_verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 ADJUST_ARGS();
3366 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003367 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368}
3369
J. Bruce Fields57266a62013-04-13 14:27:29 -04003370static const u32 nfs4_minimal_spo_must_enforce[2] = {
3371 [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) |
3372 1 << (OP_EXCHANGE_ID - 32) |
3373 1 << (OP_CREATE_SESSION - 32) |
3374 1 << (OP_DESTROY_SESSION - 32) |
3375 1 << (OP_DESTROY_CLIENTID - 32)
3376};
3377
Benny Halevy695e12f2008-07-04 14:38:33 +03003378static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003379nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003380 struct nfsd4_exchange_id *exid)
3381{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003382 __be32 *p;
Andy Adamson0733d212009-04-03 08:28:01 +03003383 char *major_id;
3384 char *server_scope;
3385 int major_id_sz;
3386 int server_scope_sz;
3387 uint64_t minor_id = 0;
3388
3389 if (nfserr)
3390 return nfserr;
3391
3392 major_id = utsname()->nodename;
3393 major_id_sz = strlen(major_id);
3394 server_scope = utsname()->nodename;
3395 server_scope_sz = strlen(server_scope);
3396
3397 RESERVE_SPACE(
3398 8 /* eir_clientid */ +
3399 4 /* eir_sequenceid */ +
3400 4 /* eir_flags */ +
Kinglong Meea8bb84b2013-12-10 15:24:36 +08003401 4 /* spr_how */);
Andy Adamson0733d212009-04-03 08:28:01 +03003402
3403 WRITEMEM(&exid->clientid, 8);
3404 WRITE32(exid->seqid);
3405 WRITE32(exid->flags);
3406
Andy Adamson0733d212009-04-03 08:28:01 +03003407 WRITE32(exid->spa_how);
Kinglong Meea8bb84b2013-12-10 15:24:36 +08003408 ADJUST_ARGS();
3409
J. Bruce Fields57266a62013-04-13 14:27:29 -04003410 switch (exid->spa_how) {
3411 case SP4_NONE:
3412 break;
3413 case SP4_MACH_CRED:
Kinglong Meea8bb84b2013-12-10 15:24:36 +08003414 /* spo_must_enforce, spo_must_allow */
3415 RESERVE_SPACE(16);
3416
J. Bruce Fields57266a62013-04-13 14:27:29 -04003417 /* spo_must_enforce bitmap: */
3418 WRITE32(2);
3419 WRITE32(nfs4_minimal_spo_must_enforce[0]);
3420 WRITE32(nfs4_minimal_spo_must_enforce[1]);
3421 /* empty spo_must_allow bitmap: */
3422 WRITE32(0);
Kinglong Meea8bb84b2013-12-10 15:24:36 +08003423
3424 ADJUST_ARGS();
J. Bruce Fields57266a62013-04-13 14:27:29 -04003425 break;
3426 default:
3427 WARN_ON_ONCE(1);
3428 }
Andy Adamson0733d212009-04-03 08:28:01 +03003429
Kinglong Meea8bb84b2013-12-10 15:24:36 +08003430 RESERVE_SPACE(
3431 8 /* so_minor_id */ +
3432 4 /* so_major_id.len */ +
3433 (XDR_QUADLEN(major_id_sz) * 4) +
3434 4 /* eir_server_scope.len */ +
3435 (XDR_QUADLEN(server_scope_sz) * 4) +
3436 4 /* eir_server_impl_id.count (0) */);
3437
Andy Adamson0733d212009-04-03 08:28:01 +03003438 /* The server_owner struct */
3439 WRITE64(minor_id); /* Minor id */
3440 /* major id */
3441 WRITE32(major_id_sz);
3442 WRITEMEM(major_id, major_id_sz);
3443
3444 /* Server scope */
3445 WRITE32(server_scope_sz);
3446 WRITEMEM(server_scope, server_scope_sz);
3447
3448 /* Implementation id */
3449 WRITE32(0); /* zero length nfs_impl_id4 array */
3450 ADJUST_ARGS();
3451 return 0;
Andy Adamson2db134e2009-04-03 08:27:55 +03003452}
3453
3454static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003455nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003456 struct nfsd4_create_session *sess)
3457{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003458 __be32 *p;
Andy Adamsonec6b5d72009-04-03 08:28:28 +03003459
3460 if (nfserr)
3461 return nfserr;
3462
3463 RESERVE_SPACE(24);
3464 WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN);
3465 WRITE32(sess->seqid);
3466 WRITE32(sess->flags);
3467 ADJUST_ARGS();
3468
3469 RESERVE_SPACE(28);
3470 WRITE32(0); /* headerpadsz */
3471 WRITE32(sess->fore_channel.maxreq_sz);
3472 WRITE32(sess->fore_channel.maxresp_sz);
3473 WRITE32(sess->fore_channel.maxresp_cached);
3474 WRITE32(sess->fore_channel.maxops);
3475 WRITE32(sess->fore_channel.maxreqs);
3476 WRITE32(sess->fore_channel.nr_rdma_attrs);
3477 ADJUST_ARGS();
3478
3479 if (sess->fore_channel.nr_rdma_attrs) {
3480 RESERVE_SPACE(4);
3481 WRITE32(sess->fore_channel.rdma_attrs);
3482 ADJUST_ARGS();
3483 }
3484
3485 RESERVE_SPACE(28);
3486 WRITE32(0); /* headerpadsz */
3487 WRITE32(sess->back_channel.maxreq_sz);
3488 WRITE32(sess->back_channel.maxresp_sz);
3489 WRITE32(sess->back_channel.maxresp_cached);
3490 WRITE32(sess->back_channel.maxops);
3491 WRITE32(sess->back_channel.maxreqs);
3492 WRITE32(sess->back_channel.nr_rdma_attrs);
3493 ADJUST_ARGS();
3494
3495 if (sess->back_channel.nr_rdma_attrs) {
3496 RESERVE_SPACE(4);
3497 WRITE32(sess->back_channel.rdma_attrs);
3498 ADJUST_ARGS();
3499 }
3500 return 0;
Andy Adamson2db134e2009-04-03 08:27:55 +03003501}
3502
3503static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003504nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003505 struct nfsd4_destroy_session *destroy_session)
3506{
Andy Adamson2db134e2009-04-03 08:27:55 +03003507 return nfserr;
3508}
3509
Daniel Mackc47d8322011-05-16 16:38:14 +02003510static __be32
J. Bruce Fieldsd1829b32012-04-25 18:04:54 -04003511nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003512 struct nfsd4_free_stateid *free_stateid)
3513{
3514 __be32 *p;
3515
3516 if (nfserr)
3517 return nfserr;
3518
3519 RESERVE_SPACE(4);
J. Bruce Fieldsd1829b32012-04-25 18:04:54 -04003520 *p++ = nfserr;
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003521 ADJUST_ARGS();
3522 return nfserr;
3523}
3524
3525static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003526nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003527 struct nfsd4_sequence *seq)
3528{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003529 __be32 *p;
Benny Halevyb85d4c02009-04-03 08:28:08 +03003530
3531 if (nfserr)
3532 return nfserr;
3533
3534 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20);
3535 WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
3536 WRITE32(seq->seqid);
3537 WRITE32(seq->slotid);
J. Bruce Fieldsb7d7ca32011-08-31 15:39:30 -04003538 /* Note slotid's are numbered from zero: */
3539 WRITE32(seq->maxslots - 1); /* sr_highest_slotid */
3540 WRITE32(seq->maxslots - 1); /* sr_target_highest_slotid */
J. Bruce Fields0d7bb712010-11-18 08:30:33 -05003541 WRITE32(seq->status_flags);
Benny Halevyb85d4c02009-04-03 08:28:08 +03003542
3543 ADJUST_ARGS();
Andy Adamson557ce262009-08-28 08:45:04 -04003544 resp->cstate.datap = p; /* DRC cache data pointer */
Benny Halevyb85d4c02009-04-03 08:28:08 +03003545 return 0;
Andy Adamson2db134e2009-04-03 08:27:55 +03003546}
3547
J. Bruce Fields2355c592012-04-25 16:56:22 -04003548static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003549nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
Bryan Schumaker17456802011-07-13 10:50:48 -04003550 struct nfsd4_test_stateid *test_stateid)
3551{
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003552 struct nfsd4_test_stateid_id *stateid, *next;
Bryan Schumaker17456802011-07-13 10:50:48 -04003553 __be32 *p;
Bryan Schumaker17456802011-07-13 10:50:48 -04003554
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003555 RESERVE_SPACE(4 + (4 * test_stateid->ts_num_ids));
Bryan Schumaker17456802011-07-13 10:50:48 -04003556 *p++ = htonl(test_stateid->ts_num_ids);
Bryan Schumaker17456802011-07-13 10:50:48 -04003557
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003558 list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
Al Viro02f5fde2012-04-13 00:10:34 -04003559 *p++ = stateid->ts_id_status;
Bryan Schumaker17456802011-07-13 10:50:48 -04003560 }
Bryan Schumaker17456802011-07-13 10:50:48 -04003561
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003562 ADJUST_ARGS();
Bryan Schumaker17456802011-07-13 10:50:48 -04003563 return nfserr;
3564}
3565
Andy Adamson2db134e2009-04-03 08:27:55 +03003566static __be32
Benny Halevy695e12f2008-07-04 14:38:33 +03003567nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p)
3568{
3569 return nfserr;
3570}
3571
3572typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *);
3573
Andy Adamson2db134e2009-04-03 08:27:55 +03003574/*
3575 * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
3576 * since we don't need to filter out obsolete ops as this is
3577 * done in the decoding phase.
3578 */
Benny Halevy695e12f2008-07-04 14:38:33 +03003579static nfsd4_enc nfsd4_enc_ops[] = {
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04003580 [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access,
3581 [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close,
3582 [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit,
3583 [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create,
3584 [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop,
3585 [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop,
3586 [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr,
3587 [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh,
3588 [OP_LINK] = (nfsd4_enc)nfsd4_encode_link,
3589 [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock,
3590 [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt,
3591 [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku,
3592 [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop,
3593 [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop,
3594 [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop,
3595 [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open,
Benny Halevy84f09f42009-03-04 23:05:35 +02003596 [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop,
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04003597 [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm,
3598 [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade,
3599 [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop,
3600 [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop,
3601 [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop,
3602 [OP_READ] = (nfsd4_enc)nfsd4_encode_read,
3603 [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir,
3604 [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink,
3605 [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove,
3606 [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename,
3607 [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop,
3608 [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop,
3609 [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop,
3610 [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo,
3611 [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr,
3612 [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid,
3613 [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop,
3614 [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop,
3615 [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write,
3616 [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop,
Andy Adamson2db134e2009-04-03 08:27:55 +03003617
3618 /* NFSv4.1 operations */
3619 [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04003620 [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session,
Andy Adamson2db134e2009-04-03 08:27:55 +03003621 [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id,
3622 [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session,
3623 [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003624 [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid,
Andy Adamson2db134e2009-04-03 08:27:55 +03003625 [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
3626 [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop,
3627 [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
3628 [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop,
3629 [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop,
3630 [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop,
Mi Jinlong22b6dee2010-12-27 14:29:57 +08003631 [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name,
Andy Adamson2db134e2009-04-03 08:27:55 +03003632 [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence,
3633 [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop,
Bryan Schumaker17456802011-07-13 10:50:48 -04003634 [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid,
Andy Adamson2db134e2009-04-03 08:27:55 +03003635 [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
3636 [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop,
3637 [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop,
Benny Halevy695e12f2008-07-04 14:38:33 +03003638};
3639
Andy Adamson496c2622009-04-03 08:28:48 +03003640/*
3641 * Calculate the total amount of memory that the compound response has taken
Mi Jinlong58e7b332011-08-28 18:18:56 +08003642 * after encoding the current operation with pad.
Andy Adamson496c2622009-04-03 08:28:48 +03003643 *
Mi Jinlong58e7b332011-08-28 18:18:56 +08003644 * pad: if operation is non-idempotent, pad was calculate by op_rsize_bop()
3645 * which was specified at nfsd4_operation, else pad is zero.
Andy Adamson496c2622009-04-03 08:28:48 +03003646 *
Mi Jinlong58e7b332011-08-28 18:18:56 +08003647 * Compare this length to the session se_fmaxresp_sz and se_fmaxresp_cached.
Andy Adamson496c2622009-04-03 08:28:48 +03003648 *
3649 * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
3650 * will be at least a page and will therefore hold the xdr_buf head.
3651 */
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003652__be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
Andy Adamson496c2622009-04-03 08:28:48 +03003653{
Andy Adamson496c2622009-04-03 08:28:48 +03003654 struct xdr_buf *xb = &resp->rqstp->rq_res;
Andy Adamson496c2622009-04-03 08:28:48 +03003655 struct nfsd4_session *session = NULL;
3656 struct nfsd4_slot *slot = resp->cstate.slot;
Mi Jinlong58e7b332011-08-28 18:18:56 +08003657 u32 length, tlen = 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003658
3659 if (!nfsd4_has_session(&resp->cstate))
Mi Jinlong58e7b332011-08-28 18:18:56 +08003660 return 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003661
3662 session = resp->cstate.session;
Mi Jinlong58e7b332011-08-28 18:18:56 +08003663 if (session == NULL)
3664 return 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003665
3666 if (xb->page_len == 0) {
3667 length = (char *)resp->p - (char *)xb->head[0].iov_base + pad;
3668 } else {
3669 if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
3670 tlen = (char *)resp->p - (char *)xb->tail[0].iov_base;
3671
3672 length = xb->head[0].iov_len + xb->page_len + tlen + pad;
3673 }
3674 dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
3675 length, xb->page_len, tlen, pad);
3676
Mi Jinlong58e7b332011-08-28 18:18:56 +08003677 if (length > session->se_fchannel.maxresp_sz)
3678 return nfserr_rep_too_big;
3679
J. Bruce Fields73e79482012-02-13 16:39:00 -05003680 if ((slot->sl_flags & NFSD4_SLOT_CACHETHIS) &&
Mi Jinlong58e7b332011-08-28 18:18:56 +08003681 length > session->se_fchannel.maxresp_cached)
Andy Adamson496c2622009-04-03 08:28:48 +03003682 return nfserr_rep_too_big_to_cache;
Mi Jinlong58e7b332011-08-28 18:18:56 +08003683
3684 return 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003685}
3686
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687void
3688nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3689{
J. Bruce Fields9411b1d2013-04-01 16:37:12 -04003690 struct nfs4_stateowner *so = resp->cstate.replay_owner;
Al Viro2ebbc012006-10-19 23:28:58 -07003691 __be32 *statp;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003692 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693
3694 RESERVE_SPACE(8);
3695 WRITE32(op->opnum);
3696 statp = p++; /* to be backfilled at the end */
3697 ADJUST_ARGS();
3698
Benny Halevy695e12f2008-07-04 14:38:33 +03003699 if (op->opnum == OP_ILLEGAL)
3700 goto status;
3701 BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
3702 !nfsd4_enc_ops[op->opnum]);
3703 op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u);
Andy Adamson496c2622009-04-03 08:28:48 +03003704 /* nfsd4_check_drc_limit guarantees enough room for error status */
Mi Jinlong58e7b332011-08-28 18:18:56 +08003705 if (!op->status)
3706 op->status = nfsd4_check_resp_size(resp, 0);
J. Bruce Fields9411b1d2013-04-01 16:37:12 -04003707 if (so) {
3708 so->so_replay.rp_status = op->status;
3709 so->so_replay.rp_buflen = (char *)resp->p - (char *)(statp+1);
3710 memcpy(so->so_replay.rp_buf, statp+1, so->so_replay.rp_buflen);
3711 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003712status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 /*
3714 * Note: We write the status directly, instead of using WRITE32(),
3715 * since it is already in network byte order.
3716 */
3717 *statp = op->status;
3718}
3719
3720/*
3721 * Encode the reply stored in the stateowner reply cache
3722 *
3723 * XDR note: do not encode rp->rp_buflen: the buffer contains the
3724 * previously sent already encoded operation.
3725 *
3726 * called with nfs4_lock_state() held
3727 */
3728void
3729nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3730{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003731 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 struct nfs4_replay *rp = op->replay;
3733
3734 BUG_ON(!rp);
3735
3736 RESERVE_SPACE(8);
3737 WRITE32(op->opnum);
3738 *p++ = rp->rp_status; /* already xdr'ed */
3739 ADJUST_ARGS();
3740
3741 RESERVE_SPACE(rp->rp_buflen);
3742 WRITEMEM(rp->rp_buf, rp->rp_buflen);
3743 ADJUST_ARGS();
3744}
3745
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746int
Al Viro2ebbc012006-10-19 23:28:58 -07003747nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748{
3749 return xdr_ressize_check(rqstp, p);
3750}
3751
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003752int nfsd4_release_compoundargs(void *rq, __be32 *p, void *resp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753{
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003754 struct svc_rqst *rqstp = rq;
3755 struct nfsd4_compoundargs *args = rqstp->rq_argp;
3756
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 if (args->ops != args->iops) {
3758 kfree(args->ops);
3759 args->ops = args->iops;
3760 }
Jesper Juhlf99d49a2005-11-07 01:01:34 -08003761 kfree(args->tmpp);
3762 args->tmpp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 while (args->to_free) {
3764 struct tmpbuf *tb = args->to_free;
3765 args->to_free = tb->next;
3766 tb->release(tb->buf);
3767 kfree(tb);
3768 }
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003769 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770}
3771
3772int
Al Viro2ebbc012006-10-19 23:28:58 -07003773nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 args->p = p;
3776 args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len;
3777 args->pagelist = rqstp->rq_arg.pages;
3778 args->pagelen = rqstp->rq_arg.page_len;
3779 args->tmpp = NULL;
3780 args->to_free = NULL;
3781 args->ops = args->iops;
3782 args->rqstp = rqstp;
3783
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003784 return !nfsd4_decode_compound(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785}
3786
3787int
Al Viro2ebbc012006-10-19 23:28:58 -07003788nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundres *resp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789{
3790 /*
3791 * All that remains is to write the tag and operation count...
3792 */
Andy Adamson557ce262009-08-28 08:45:04 -04003793 struct nfsd4_compound_state *cs = &resp->cstate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 struct kvec *iov;
3795 p = resp->tagp;
3796 *p++ = htonl(resp->taglen);
3797 memcpy(p, resp->tag, resp->taglen);
3798 p += XDR_QUADLEN(resp->taglen);
3799 *p++ = htonl(resp->opcnt);
3800
3801 if (rqstp->rq_res.page_len)
3802 iov = &rqstp->rq_res.tail[0];
3803 else
3804 iov = &rqstp->rq_res.head[0];
3805 iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
3806 BUG_ON(iov->iov_len > PAGE_SIZE);
J. Bruce Fields26c0c752010-04-24 15:35:43 -04003807 if (nfsd4_has_session(cs)) {
J. Bruce Fieldsf0f51f52013-06-18 14:26:02 -04003808 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
3809 struct nfs4_client *clp = cs->session->se_client;
J. Bruce Fields26c0c752010-04-24 15:35:43 -04003810 if (cs->status != nfserr_replay_cache) {
3811 nfsd4_store_cache_entry(resp);
J. Bruce Fields73e79482012-02-13 16:39:00 -05003812 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE;
J. Bruce Fields26c0c752010-04-24 15:35:43 -04003813 }
Benny Halevyd7682982010-05-12 00:13:54 +03003814 /* Renew the clientid on success and on replay */
J. Bruce Fieldsf0f51f52013-06-18 14:26:02 -04003815 spin_lock(&nn->client_lock);
J. Bruce Fields221a6872013-04-01 22:23:49 -04003816 nfsd4_put_session(cs->session);
J. Bruce Fieldsf0f51f52013-06-18 14:26:02 -04003817 spin_unlock(&nn->client_lock);
3818 put_client_renew(clp);
Andy Adamsonda3846a2009-04-03 08:28:22 +03003819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 return 1;
3821}
3822
3823/*
3824 * Local variables:
3825 * c-basic-offset: 8
3826 * End:
3827 */