blob: d9454fe5653f70af2175432d22e36cebcbaef5be [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{
144 argp->pagelist++;
145 argp->p = page_address(argp->pagelist[0]);
146 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193static int
194defer_free(struct nfsd4_compoundargs *argp,
195 void (*release)(const void *), void *p)
196{
197 struct tmpbuf *tb;
198
199 tb = kmalloc(sizeof(*tb), GFP_KERNEL);
200 if (!tb)
201 return -ENOMEM;
202 tb->buf = p;
203 tb->release = release;
204 tb->next = argp->to_free;
205 argp->to_free = tb;
206 return 0;
207}
208
Al Viro2ebbc012006-10-19 23:28:58 -0700209static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (p == argp->tmp) {
Thomas Meyer67114fe2011-11-17 23:43:40 +0100212 p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
J. Bruce Fieldsa4db5fe2007-02-16 01:28:30 -0800213 if (!p)
214 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 } else {
Eric Sesterhenn73dff8b2006-10-03 23:37:14 +0200216 BUG_ON(p != argp->tmpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 argp->tmpp = NULL;
218 }
219 if (defer_free(argp, kfree, p)) {
J. Bruce Fieldsa4db5fe2007-02-16 01:28:30 -0800220 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 return NULL;
222 } else
223 return (char *)p;
224}
225
Al Virob37ad282006-10-19 23:28:59 -0700226static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
228{
229 u32 bmlen;
230 DECODE_HEAD;
231
232 bmval[0] = 0;
233 bmval[1] = 0;
Andy Adamson7e705702009-04-03 08:29:11 +0300234 bmval[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 READ_BUF(4);
237 READ32(bmlen);
238 if (bmlen > 1000)
239 goto xdr_error;
240
241 READ_BUF(bmlen << 2);
242 if (bmlen > 0)
243 READ32(bmval[0]);
244 if (bmlen > 1)
245 READ32(bmval[1]);
Andy Adamson7e705702009-04-03 08:29:11 +0300246 if (bmlen > 2)
247 READ32(bmval[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 DECODE_TAIL;
250}
251
Al Virob37ad282006-10-19 23:28:59 -0700252static __be32
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800253nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
David Quigley18032ca2013-05-02 13:19:10 -0400254 struct iattr *iattr, struct nfs4_acl **acl,
255 struct xdr_netobj *label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 int expected_len, len = 0;
258 u32 dummy32;
259 char *buf;
Al Virob8dd7b92006-10-19 23:29:01 -0700260 int host_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 DECODE_HEAD;
263 iattr->ia_valid = 0;
264 if ((status = nfsd4_decode_bitmap(argp, bmval)))
265 return status;
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 READ_BUF(4);
268 READ32(expected_len);
269
270 if (bmval[0] & FATTR4_WORD0_SIZE) {
271 READ_BUF(8);
272 len += 8;
273 READ64(iattr->ia_size);
274 iattr->ia_valid |= ATTR_SIZE;
275 }
276 if (bmval[0] & FATTR4_WORD0_ACL) {
J. Bruce Fields64a817c2013-03-26 14:11:13 -0400277 u32 nace;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800278 struct nfs4_ace *ace;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 READ_BUF(4); len += 4;
281 READ32(nace);
282
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800283 if (nace > NFS4_ACL_MAX)
284 return nfserr_resource;
285
286 *acl = nfs4_acl_new(nace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (*acl == NULL) {
Al Virob8dd7b92006-10-19 23:29:01 -0700288 host_err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 goto out_nfserr;
290 }
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800291 defer_free(argp, kfree, *acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800293 (*acl)->naces = nace;
294 for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 READ_BUF(16); len += 16;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800296 READ32(ace->type);
297 READ32(ace->flag);
298 READ32(ace->access_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 READ32(dummy32);
300 READ_BUF(dummy32);
301 len += XDR_QUADLEN(dummy32) << 2;
302 READMEM(buf, dummy32);
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800303 ace->whotype = nfs4_acl_get_whotype(buf, dummy32);
J. Bruce Fields3c726022011-01-04 17:53:52 -0500304 status = nfs_ok;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800305 if (ace->whotype != NFS4_ACL_WHO_NAMED)
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -0800306 ;
J. Bruce Fields28e05dd2007-02-16 01:28:30 -0800307 else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
J. Bruce Fields3c726022011-01-04 17:53:52 -0500308 status = nfsd_map_name_to_gid(argp->rqstp,
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -0800309 buf, dummy32, &ace->who_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 else
J. Bruce Fields3c726022011-01-04 17:53:52 -0500311 status = nfsd_map_name_to_uid(argp->rqstp,
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -0800312 buf, dummy32, &ace->who_uid);
J. Bruce Fields3c726022011-01-04 17:53:52 -0500313 if (status)
314 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316 } else
317 *acl = NULL;
318 if (bmval[1] & FATTR4_WORD1_MODE) {
319 READ_BUF(4);
320 len += 4;
321 READ32(iattr->ia_mode);
322 iattr->ia_mode &= (S_IFMT | S_IALLUGO);
323 iattr->ia_valid |= ATTR_MODE;
324 }
325 if (bmval[1] & FATTR4_WORD1_OWNER) {
326 READ_BUF(4);
327 len += 4;
328 READ32(dummy32);
329 READ_BUF(dummy32);
330 len += (XDR_QUADLEN(dummy32) << 2);
331 READMEM(buf, dummy32);
NeilBrown47c85292011-02-16 13:08:35 +1100332 if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid)))
333 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 iattr->ia_valid |= ATTR_UID;
335 }
336 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
337 READ_BUF(4);
338 len += 4;
339 READ32(dummy32);
340 READ_BUF(dummy32);
341 len += (XDR_QUADLEN(dummy32) << 2);
342 READMEM(buf, dummy32);
NeilBrown47c85292011-02-16 13:08:35 +1100343 if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid)))
344 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 iattr->ia_valid |= ATTR_GID;
346 }
347 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
348 READ_BUF(4);
349 len += 4;
350 READ32(dummy32);
351 switch (dummy32) {
352 case NFS4_SET_TO_CLIENT_TIME:
353 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
354 all 32 bits of 'nseconds'. */
355 READ_BUF(12);
356 len += 12;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -0400357 READ64(iattr->ia_atime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 READ32(iattr->ia_atime.tv_nsec);
359 if (iattr->ia_atime.tv_nsec >= (u32)1000000000)
360 return nfserr_inval;
361 iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
362 break;
363 case NFS4_SET_TO_SERVER_TIME:
364 iattr->ia_valid |= ATTR_ATIME;
365 break;
366 default:
367 goto xdr_error;
368 }
369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
371 READ_BUF(4);
372 len += 4;
373 READ32(dummy32);
374 switch (dummy32) {
375 case NFS4_SET_TO_CLIENT_TIME:
376 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
377 all 32 bits of 'nseconds'. */
378 READ_BUF(12);
379 len += 12;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -0400380 READ64(iattr->ia_mtime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 READ32(iattr->ia_mtime.tv_nsec);
382 if (iattr->ia_mtime.tv_nsec >= (u32)1000000000)
383 return nfserr_inval;
384 iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
385 break;
386 case NFS4_SET_TO_SERVER_TIME:
387 iattr->ia_valid |= ATTR_MTIME;
388 break;
389 default:
390 goto xdr_error;
391 }
392 }
David Quigley18032ca2013-05-02 13:19:10 -0400393
394 label->len = 0;
395#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
396 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
397 READ_BUF(4);
398 len += 4;
399 READ32(dummy32); /* lfs: we don't use it */
400 READ_BUF(4);
401 len += 4;
402 READ32(dummy32); /* pi: we don't use it either */
403 READ_BUF(4);
404 len += 4;
405 READ32(dummy32);
406 READ_BUF(dummy32);
407 if (dummy32 > NFSD4_MAX_SEC_LABEL_LEN)
408 return nfserr_badlabel;
409 len += (XDR_QUADLEN(dummy32) << 2);
410 READMEM(buf, dummy32);
411 label->data = kzalloc(dummy32 + 1, GFP_KERNEL);
412 if (!label->data)
413 return nfserr_jukebox;
414 defer_free(argp, kfree, label->data);
415 memcpy(label->data, buf, dummy32);
416 }
417#endif
418
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800419 if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
420 || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
421 || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2)
422 READ_BUF(expected_len - len);
423 else if (len != expected_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 goto xdr_error;
425
426 DECODE_TAIL;
427
428out_nfserr:
Al Virob8dd7b92006-10-19 23:29:01 -0700429 status = nfserrno(host_err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 goto out;
431}
432
Al Virob37ad282006-10-19 23:28:59 -0700433static __be32
Benny Halevye31a1b62008-08-12 20:46:18 +0300434nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
435{
436 DECODE_HEAD;
437
438 READ_BUF(sizeof(stateid_t));
439 READ32(sid->si_generation);
440 COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
441
442 DECODE_TAIL;
443}
444
445static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
447{
448 DECODE_HEAD;
449
450 READ_BUF(4);
451 READ32(access->ac_req_access);
452
453 DECODE_TAIL;
454}
455
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400456static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs)
457{
458 DECODE_HEAD;
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500459 u32 dummy, uid, gid;
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400460 char *machine_name;
461 int i;
462 int nr_secflavs;
463
464 /* callback_sec_params4 */
465 READ_BUF(4);
466 READ32(nr_secflavs);
J. Bruce Fields57569a72013-05-17 16:25:32 -0400467 if (nr_secflavs)
468 cbs->flavor = (u32)(-1);
469 else
470 /* Is this legal? Be generous, take it to mean AUTH_NONE: */
471 cbs->flavor = 0;
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400472 for (i = 0; i < nr_secflavs; ++i) {
473 READ_BUF(4);
474 READ32(dummy);
475 switch (dummy) {
476 case RPC_AUTH_NULL:
477 /* Nothing to read */
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500478 if (cbs->flavor == (u32)(-1))
479 cbs->flavor = RPC_AUTH_NULL;
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400480 break;
481 case RPC_AUTH_UNIX:
482 READ_BUF(8);
483 /* stamp */
484 READ32(dummy);
485
486 /* machine name */
487 READ32(dummy);
488 READ_BUF(dummy);
489 SAVEMEM(machine_name, dummy);
490
491 /* uid, gid */
492 READ_BUF(8);
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500493 READ32(uid);
494 READ32(gid);
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400495
496 /* more gids */
497 READ_BUF(4);
498 READ32(dummy);
499 READ_BUF(dummy * 4);
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500500 if (cbs->flavor == (u32)(-1)) {
Eric W. Biederman03bc6d12013-02-02 06:24:49 -0800501 kuid_t kuid = make_kuid(&init_user_ns, uid);
502 kgid_t kgid = make_kgid(&init_user_ns, gid);
503 if (uid_valid(kuid) && gid_valid(kgid)) {
504 cbs->uid = kuid;
505 cbs->gid = kgid;
506 cbs->flavor = RPC_AUTH_UNIX;
507 } else {
508 dprintk("RPC_AUTH_UNIX with invalid"
509 "uid or gid ignoring!\n");
510 }
J. Bruce Fields12fc3e92012-11-05 16:01:48 -0500511 }
J. Bruce Fieldsacb28872012-03-27 14:50:26 -0400512 break;
513 case RPC_AUTH_GSS:
514 dprintk("RPC_AUTH_GSS callback secflavor "
515 "not supported!\n");
516 READ_BUF(8);
517 /* gcbp_service */
518 READ32(dummy);
519 /* gcbp_handle_from_server */
520 READ32(dummy);
521 READ_BUF(dummy);
522 p += XDR_QUADLEN(dummy);
523 /* gcbp_handle_from_client */
524 READ_BUF(4);
525 READ32(dummy);
526 READ_BUF(dummy);
527 break;
528 default:
529 dprintk("Illegal callback secflavor\n");
530 return nfserr_inval;
531 }
532 }
533 DECODE_TAIL;
534}
535
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -0400536static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc)
537{
538 DECODE_HEAD;
539
540 READ_BUF(4);
541 READ32(bc->bc_cb_program);
542 nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec);
543
544 DECODE_TAIL;
545}
546
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -0400547static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts)
548{
549 DECODE_HEAD;
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -0400550
551 READ_BUF(NFS4_MAX_SESSIONID_LEN + 8);
552 COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
553 READ32(bcts->dir);
Bryan Schumaker6ce23572011-04-27 15:47:16 -0400554 /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker
555 * could help us figure out we should be using it. */
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -0400556 DECODE_TAIL;
557}
558
Al Virob37ad282006-10-19 23:28:59 -0700559static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
561{
562 DECODE_HEAD;
563
Benny Halevye31a1b62008-08-12 20:46:18 +0300564 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 READ32(close->cl_seqid);
Benny Halevye31a1b62008-08-12 20:46:18 +0300566 return nfsd4_decode_stateid(argp, &close->cl_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 DECODE_TAIL;
569}
570
571
Al Virob37ad282006-10-19 23:28:59 -0700572static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit)
574{
575 DECODE_HEAD;
576
577 READ_BUF(12);
578 READ64(commit->co_offset);
579 READ32(commit->co_count);
580
581 DECODE_TAIL;
582}
583
Al Virob37ad282006-10-19 23:28:59 -0700584static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
586{
587 DECODE_HEAD;
588
589 READ_BUF(4);
590 READ32(create->cr_type);
591 switch (create->cr_type) {
592 case NF4LNK:
593 READ_BUF(4);
594 READ32(create->cr_linklen);
595 READ_BUF(create->cr_linklen);
596 SAVEMEM(create->cr_linkname, create->cr_linklen);
597 break;
598 case NF4BLK:
599 case NF4CHR:
600 READ_BUF(8);
601 READ32(create->cr_specdata1);
602 READ32(create->cr_specdata2);
603 break;
604 case NF4SOCK:
605 case NF4FIFO:
606 case NF4DIR:
607 default:
608 break;
609 }
610
611 READ_BUF(4);
612 READ32(create->cr_namelen);
613 READ_BUF(create->cr_namelen);
614 SAVEMEM(create->cr_name, create->cr_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500615 if ((status = check_filename(create->cr_name, create->cr_namelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 return status;
617
Yu Zhiguo3c8e0312009-05-16 16:22:31 +0800618 status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
David Quigley18032ca2013-05-02 13:19:10 -0400619 &create->cr_acl, &create->cr_label);
Benny Halevyc0d6fc82009-04-03 08:29:05 +0300620 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 goto out;
622
623 DECODE_TAIL;
624}
625
Al Virob37ad282006-10-19 23:28:59 -0700626static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
628{
Benny Halevye31a1b62008-08-12 20:46:18 +0300629 return nfsd4_decode_stateid(argp, &dr->dr_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630}
631
Al Virob37ad282006-10-19 23:28:59 -0700632static inline __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr)
634{
635 return nfsd4_decode_bitmap(argp, getattr->ga_bmval);
636}
637
Al Virob37ad282006-10-19 23:28:59 -0700638static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link)
640{
641 DECODE_HEAD;
642
643 READ_BUF(4);
644 READ32(link->li_namelen);
645 READ_BUF(link->li_namelen);
646 SAVEMEM(link->li_name, link->li_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500647 if ((status = check_filename(link->li_name, link->li_namelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return status;
649
650 DECODE_TAIL;
651}
652
Al Virob37ad282006-10-19 23:28:59 -0700653static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
655{
656 DECODE_HEAD;
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 /*
659 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
660 */
661 READ_BUF(28);
662 READ32(lock->lk_type);
663 if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
664 goto xdr_error;
665 READ32(lock->lk_reclaim);
666 READ64(lock->lk_offset);
667 READ64(lock->lk_length);
668 READ32(lock->lk_is_new);
669
670 if (lock->lk_is_new) {
Benny Halevye31a1b62008-08-12 20:46:18 +0300671 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 READ32(lock->lk_new_open_seqid);
Benny Halevye31a1b62008-08-12 20:46:18 +0300673 status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
674 if (status)
675 return status;
676 READ_BUF(8 + sizeof(clientid_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 READ32(lock->lk_new_lock_seqid);
678 COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
679 READ32(lock->lk_new_owner.len);
680 READ_BUF(lock->lk_new_owner.len);
681 READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
682 } else {
Benny Halevye31a1b62008-08-12 20:46:18 +0300683 status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
684 if (status)
685 return status;
686 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 READ32(lock->lk_old_lock_seqid);
688 }
689
690 DECODE_TAIL;
691}
692
Al Virob37ad282006-10-19 23:28:59 -0700693static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt)
695{
696 DECODE_HEAD;
697
698 READ_BUF(32);
699 READ32(lockt->lt_type);
700 if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
701 goto xdr_error;
702 READ64(lockt->lt_offset);
703 READ64(lockt->lt_length);
704 COPYMEM(&lockt->lt_clientid, 8);
705 READ32(lockt->lt_owner.len);
706 READ_BUF(lockt->lt_owner.len);
707 READMEM(lockt->lt_owner.data, lockt->lt_owner.len);
708
709 DECODE_TAIL;
710}
711
Al Virob37ad282006-10-19 23:28:59 -0700712static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
714{
715 DECODE_HEAD;
716
Benny Halevye31a1b62008-08-12 20:46:18 +0300717 READ_BUF(8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 READ32(locku->lu_type);
719 if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
720 goto xdr_error;
721 READ32(locku->lu_seqid);
Benny Halevye31a1b62008-08-12 20:46:18 +0300722 status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
723 if (status)
724 return status;
725 READ_BUF(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 READ64(locku->lu_offset);
727 READ64(locku->lu_length);
728
729 DECODE_TAIL;
730}
731
Al Virob37ad282006-10-19 23:28:59 -0700732static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup)
734{
735 DECODE_HEAD;
736
737 READ_BUF(4);
738 READ32(lookup->lo_len);
739 READ_BUF(lookup->lo_len);
740 SAVEMEM(lookup->lo_name, lookup->lo_len);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500741 if ((status = check_filename(lookup->lo_name, lookup->lo_len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return status;
743
744 DECODE_TAIL;
745}
746
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200747static __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 -0400748{
749 __be32 *p;
750 u32 w;
751
752 READ_BUF(4);
753 READ32(w);
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200754 *share_access = w & NFS4_SHARE_ACCESS_MASK;
755 *deleg_want = w & NFS4_SHARE_WANT_MASK;
756 if (deleg_when)
757 *deleg_when = w & NFS4_SHARE_WHEN_MASK;
758
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400759 switch (w & NFS4_SHARE_ACCESS_MASK) {
760 case NFS4_SHARE_ACCESS_READ:
761 case NFS4_SHARE_ACCESS_WRITE:
762 case NFS4_SHARE_ACCESS_BOTH:
763 break;
764 default:
765 return nfserr_bad_xdr;
766 }
Benny Halevyfc0d14f2011-10-27 20:43:01 +0200767 w &= ~NFS4_SHARE_ACCESS_MASK;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400768 if (!w)
769 return nfs_ok;
770 if (!argp->minorversion)
771 return nfserr_bad_xdr;
772 switch (w & NFS4_SHARE_WANT_MASK) {
773 case NFS4_SHARE_WANT_NO_PREFERENCE:
774 case NFS4_SHARE_WANT_READ_DELEG:
775 case NFS4_SHARE_WANT_WRITE_DELEG:
776 case NFS4_SHARE_WANT_ANY_DELEG:
777 case NFS4_SHARE_WANT_NO_DELEG:
778 case NFS4_SHARE_WANT_CANCEL:
779 break;
780 default:
781 return nfserr_bad_xdr;
782 }
Benny Halevy92bac8c2011-10-19 19:13:29 -0700783 w &= ~NFS4_SHARE_WANT_MASK;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400784 if (!w)
785 return nfs_ok;
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200786
787 if (!deleg_when) /* open_downgrade */
788 return nfserr_inval;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400789 switch (w) {
790 case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL:
791 case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED:
Benny Halevyc668fc62011-10-19 19:13:13 -0700792 case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL |
793 NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED):
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400794 return nfs_ok;
795 }
796xdr_error:
797 return nfserr_bad_xdr;
798}
799
800static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x)
801{
802 __be32 *p;
803
804 READ_BUF(4);
805 READ32(*x);
806 /* Note: unlinke access bits, deny bits may be zero. */
Dan Carpenter01cd4afa2011-10-17 10:41:17 +0300807 if (*x & ~NFS4_SHARE_DENY_BOTH)
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400808 return nfserr_bad_xdr;
809 return nfs_ok;
810xdr_error:
811 return nfserr_bad_xdr;
812}
813
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -0400814static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o)
815{
816 __be32 *p;
817
818 READ_BUF(4);
819 READ32(o->len);
820
821 if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT)
822 return nfserr_bad_xdr;
823
824 READ_BUF(o->len);
825 SAVEMEM(o->data, o->len);
826 return nfs_ok;
827xdr_error:
828 return nfserr_bad_xdr;
829}
830
Al Virob37ad282006-10-19 23:28:59 -0700831static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
833{
834 DECODE_HEAD;
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200835 u32 dummy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 memset(open->op_bmval, 0, sizeof(open->op_bmval));
838 open->op_iattr.ia_valid = 0;
J. Bruce Fieldsfe0750e2011-07-30 23:33:59 -0400839 open->op_openowner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
J. Bruce Fields9d313b12013-02-28 12:51:49 -0800841 open->op_xdr_error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 /* seqid, share_access, share_deny, clientid, ownerlen */
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400843 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 READ32(open->op_seqid);
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200845 /* decode, yet ignore deleg_when until supported */
846 status = nfsd4_decode_share_access(argp, &open->op_share_access,
847 &open->op_deleg_want, &dummy);
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400848 if (status)
849 goto xdr_error;
850 status = nfsd4_decode_share_deny(argp, &open->op_share_deny);
851 if (status)
852 goto xdr_error;
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -0400853 READ_BUF(sizeof(clientid_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 COPYMEM(&open->op_clientid, sizeof(clientid_t));
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -0400855 status = nfsd4_decode_opaque(argp, &open->op_owner);
856 if (status)
857 goto xdr_error;
858 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 READ32(open->op_create);
860 switch (open->op_create) {
861 case NFS4_OPEN_NOCREATE:
862 break;
863 case NFS4_OPEN_CREATE:
864 READ_BUF(4);
865 READ32(open->op_createmode);
866 switch (open->op_createmode) {
867 case NFS4_CREATE_UNCHECKED:
868 case NFS4_CREATE_GUARDED:
Benny Halevyc0d6fc82009-04-03 08:29:05 +0300869 status = nfsd4_decode_fattr(argp, open->op_bmval,
David Quigley18032ca2013-05-02 13:19:10 -0400870 &open->op_iattr, &open->op_acl, &open->op_label);
Benny Halevyc0d6fc82009-04-03 08:29:05 +0300871 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 goto out;
873 break;
874 case NFS4_CREATE_EXCLUSIVE:
Chuck Leverab4684d2012-03-02 17:13:50 -0500875 READ_BUF(NFS4_VERIFIER_SIZE);
876 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 break;
Benny Halevy79fb54a2009-04-03 08:29:17 +0300878 case NFS4_CREATE_EXCLUSIVE4_1:
879 if (argp->minorversion < 1)
880 goto xdr_error;
Chuck Leverab4684d2012-03-02 17:13:50 -0500881 READ_BUF(NFS4_VERIFIER_SIZE);
882 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
Benny Halevy79fb54a2009-04-03 08:29:17 +0300883 status = nfsd4_decode_fattr(argp, open->op_bmval,
David Quigley18032ca2013-05-02 13:19:10 -0400884 &open->op_iattr, &open->op_acl, &open->op_label);
Benny Halevy79fb54a2009-04-03 08:29:17 +0300885 if (status)
886 goto out;
887 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 default:
889 goto xdr_error;
890 }
891 break;
892 default:
893 goto xdr_error;
894 }
895
896 /* open_claim */
897 READ_BUF(4);
898 READ32(open->op_claim_type);
899 switch (open->op_claim_type) {
900 case NFS4_OPEN_CLAIM_NULL:
901 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
902 READ_BUF(4);
903 READ32(open->op_fname.len);
904 READ_BUF(open->op_fname.len);
905 SAVEMEM(open->op_fname.data, open->op_fname.len);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500906 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 return status;
908 break;
909 case NFS4_OPEN_CLAIM_PREVIOUS:
910 READ_BUF(4);
911 READ32(open->op_delegate_type);
912 break;
913 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
Benny Halevye31a1b62008-08-12 20:46:18 +0300914 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
915 if (status)
916 return status;
917 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 READ32(open->op_fname.len);
919 READ_BUF(open->op_fname.len);
920 SAVEMEM(open->op_fname.data, open->op_fname.len);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -0500921 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 return status;
923 break;
J. Bruce Fields8b289b22011-10-19 11:52:12 -0400924 case NFS4_OPEN_CLAIM_FH:
925 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
926 if (argp->minorversion < 1)
927 goto xdr_error;
928 /* void */
929 break;
930 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
931 if (argp->minorversion < 1)
932 goto xdr_error;
933 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
934 if (status)
935 return status;
936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 default:
938 goto xdr_error;
939 }
940
941 DECODE_TAIL;
942}
943
Al Virob37ad282006-10-19 23:28:59 -0700944static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
946{
947 DECODE_HEAD;
948
Benny Halevye31a1b62008-08-12 20:46:18 +0300949 status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
950 if (status)
951 return status;
952 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 READ32(open_conf->oc_seqid);
954
955 DECODE_TAIL;
956}
957
Al Virob37ad282006-10-19 23:28:59 -0700958static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down)
960{
961 DECODE_HEAD;
962
Benny Halevye31a1b62008-08-12 20:46:18 +0300963 status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
964 if (status)
965 return status;
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400966 READ_BUF(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 READ32(open_down->od_seqid);
Benny Halevy2c8bd7e2012-02-16 20:57:09 +0200968 status = nfsd4_decode_share_access(argp, &open_down->od_share_access,
969 &open_down->od_deleg_want, NULL);
J. Bruce Fields04f9e662011-10-10 14:37:13 -0400970 if (status)
971 return status;
972 status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny);
973 if (status)
974 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 DECODE_TAIL;
976}
977
Al Virob37ad282006-10-19 23:28:59 -0700978static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
980{
981 DECODE_HEAD;
982
983 READ_BUF(4);
984 READ32(putfh->pf_fhlen);
985 if (putfh->pf_fhlen > NFS4_FHSIZE)
986 goto xdr_error;
987 READ_BUF(putfh->pf_fhlen);
988 SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen);
989
990 DECODE_TAIL;
991}
992
Al Virob37ad282006-10-19 23:28:59 -0700993static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
995{
996 DECODE_HEAD;
997
Benny Halevye31a1b62008-08-12 20:46:18 +0300998 status = nfsd4_decode_stateid(argp, &read->rd_stateid);
999 if (status)
1000 return status;
1001 READ_BUF(12);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 READ64(read->rd_offset);
1003 READ32(read->rd_length);
1004
1005 DECODE_TAIL;
1006}
1007
Al Virob37ad282006-10-19 23:28:59 -07001008static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir)
1010{
1011 DECODE_HEAD;
1012
1013 READ_BUF(24);
1014 READ64(readdir->rd_cookie);
1015 COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
1016 READ32(readdir->rd_dircount); /* just in case you needed a useless field... */
1017 READ32(readdir->rd_maxcount);
1018 if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
1019 goto out;
1020
1021 DECODE_TAIL;
1022}
1023
Al Virob37ad282006-10-19 23:28:59 -07001024static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove)
1026{
1027 DECODE_HEAD;
1028
1029 READ_BUF(4);
1030 READ32(remove->rm_namelen);
1031 READ_BUF(remove->rm_namelen);
1032 SAVEMEM(remove->rm_name, remove->rm_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001033 if ((status = check_filename(remove->rm_name, remove->rm_namelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 return status;
1035
1036 DECODE_TAIL;
1037}
1038
Al Virob37ad282006-10-19 23:28:59 -07001039static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename)
1041{
1042 DECODE_HEAD;
1043
1044 READ_BUF(4);
1045 READ32(rename->rn_snamelen);
1046 READ_BUF(rename->rn_snamelen + 4);
1047 SAVEMEM(rename->rn_sname, rename->rn_snamelen);
1048 READ32(rename->rn_tnamelen);
1049 READ_BUF(rename->rn_tnamelen);
1050 SAVEMEM(rename->rn_tname, rename->rn_tnamelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001051 if ((status = check_filename(rename->rn_sname, rename->rn_snamelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 return status;
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001053 if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 return status;
1055
1056 DECODE_TAIL;
1057}
1058
Al Virob37ad282006-10-19 23:28:59 -07001059static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
1061{
1062 DECODE_HEAD;
1063
1064 READ_BUF(sizeof(clientid_t));
1065 COPYMEM(clientid, sizeof(clientid_t));
1066
1067 DECODE_TAIL;
1068}
1069
Al Virob37ad282006-10-19 23:28:59 -07001070static __be32
Andy Adamsondcb488a32007-07-17 04:04:51 -07001071nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
1072 struct nfsd4_secinfo *secinfo)
1073{
1074 DECODE_HEAD;
1075
1076 READ_BUF(4);
1077 READ32(secinfo->si_namelen);
1078 READ_BUF(secinfo->si_namelen);
1079 SAVEMEM(secinfo->si_name, secinfo->si_namelen);
J. Bruce Fieldsa36b1722012-11-25 16:31:00 -05001080 status = check_filename(secinfo->si_name, secinfo->si_namelen);
Andy Adamsondcb488a32007-07-17 04:04:51 -07001081 if (status)
1082 return status;
1083 DECODE_TAIL;
1084}
1085
1086static __be32
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001087nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp,
1088 struct nfsd4_secinfo_no_name *sin)
1089{
1090 DECODE_HEAD;
1091
1092 READ_BUF(4);
1093 READ32(sin->sin_style);
1094 DECODE_TAIL;
1095}
1096
1097static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
1099{
Benny Halevye31a1b62008-08-12 20:46:18 +03001100 __be32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Benny Halevye31a1b62008-08-12 20:46:18 +03001102 status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
1103 if (status)
1104 return status;
Yu Zhiguo3c8e0312009-05-16 16:22:31 +08001105 return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr,
David Quigley18032ca2013-05-02 13:19:10 -04001106 &setattr->sa_acl, &setattr->sa_label);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
Al Virob37ad282006-10-19 23:28:59 -07001109static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid)
1111{
1112 DECODE_HEAD;
1113
Chuck Leverab4684d2012-03-02 17:13:50 -05001114 READ_BUF(NFS4_VERIFIER_SIZE);
1115 COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -04001117 status = nfsd4_decode_opaque(argp, &setclientid->se_name);
1118 if (status)
1119 return nfserr_bad_xdr;
1120 READ_BUF(8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 READ32(setclientid->se_callback_prog);
1122 READ32(setclientid->se_callback_netid_len);
1123
1124 READ_BUF(setclientid->se_callback_netid_len + 4);
1125 SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len);
1126 READ32(setclientid->se_callback_addr_len);
1127
1128 READ_BUF(setclientid->se_callback_addr_len + 4);
1129 SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len);
1130 READ32(setclientid->se_callback_ident);
1131
1132 DECODE_TAIL;
1133}
1134
Al Virob37ad282006-10-19 23:28:59 -07001135static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c)
1137{
1138 DECODE_HEAD;
1139
Chuck Leverab4684d2012-03-02 17:13:50 -05001140 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 COPYMEM(&scd_c->sc_clientid, 8);
Chuck Leverab4684d2012-03-02 17:13:50 -05001142 COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 DECODE_TAIL;
1145}
1146
1147/* Also used for NVERIFY */
Al Virob37ad282006-10-19 23:28:59 -07001148static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify)
1150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 DECODE_HEAD;
1152
1153 if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval)))
1154 goto out;
1155
1156 /* For convenience's sake, we compare raw xdr'd attributes in
J. Bruce Fieldse5f95702012-11-30 17:24:18 -05001157 * nfsd4_proc_verify */
1158
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 READ_BUF(4);
1160 READ32(verify->ve_attrlen);
1161 READ_BUF(verify->ve_attrlen);
1162 SAVEMEM(verify->ve_attrval, verify->ve_attrlen);
1163
1164 DECODE_TAIL;
1165}
1166
Al Virob37ad282006-10-19 23:28:59 -07001167static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
1169{
1170 int avail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 int len;
1172 DECODE_HEAD;
1173
Benny Halevye31a1b62008-08-12 20:46:18 +03001174 status = nfsd4_decode_stateid(argp, &write->wr_stateid);
1175 if (status)
1176 return status;
1177 READ_BUF(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 READ64(write->wr_offset);
1179 READ32(write->wr_stable_how);
1180 if (write->wr_stable_how > 2)
1181 goto xdr_error;
1182 READ32(write->wr_buflen);
1183
1184 /* Sorry .. no magic macros for this.. *
1185 * READ_BUF(write->wr_buflen);
1186 * SAVEMEM(write->wr_buf, write->wr_buflen);
1187 */
1188 avail = (char*)argp->end - (char*)argp->p;
1189 if (avail + argp->pagelen < write->wr_buflen) {
Chuck Lever817cb9d2007-09-11 18:01:20 -04001190 dprintk("NFSD: xdr error (%s:%d)\n",
1191 __FILE__, __LINE__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 goto xdr_error;
1193 }
J. Bruce Fields70cc7f72012-11-16 14:16:46 -05001194 write->wr_head.iov_base = p;
1195 write->wr_head.iov_len = avail;
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001196 WARN_ON(avail != (XDR_QUADLEN(avail) << 2));
J. Bruce Fields70cc7f72012-11-16 14:16:46 -05001197 write->wr_pagelist = argp->pagelist;
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001198
1199 len = XDR_QUADLEN(write->wr_buflen) << 2;
1200 if (len >= avail) {
1201 int pages;
1202
1203 len -= avail;
1204
1205 pages = len >> PAGE_SHIFT;
1206 argp->pagelist += pages;
1207 argp->pagelen -= pages * PAGE_SIZE;
1208 len -= pages * PAGE_SIZE;
1209
1210 argp->p = (__be32 *)page_address(argp->pagelist[0]);
1211 argp->end = argp->p + XDR_QUADLEN(PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
J. Bruce Fields5a80a542012-11-16 10:01:30 -05001213 argp->p += XDR_QUADLEN(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 DECODE_TAIL;
1216}
1217
Al Virob37ad282006-10-19 23:28:59 -07001218static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner)
1220{
1221 DECODE_HEAD;
1222
1223 READ_BUF(12);
1224 COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
1225 READ32(rlockowner->rl_owner.len);
1226 READ_BUF(rlockowner->rl_owner.len);
1227 READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len);
1228
Andy Adamson60adfc52009-04-03 08:28:50 +03001229 if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
1230 return nfserr_inval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 DECODE_TAIL;
1232}
1233
Al Virob37ad282006-10-19 23:28:59 -07001234static __be32
Andy Adamson2db134e2009-04-03 08:27:55 +03001235nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
Andy Adamson0733d212009-04-03 08:28:01 +03001236 struct nfsd4_exchange_id *exid)
Andy Adamson2db134e2009-04-03 08:27:55 +03001237{
Mi Jinlong5afa0402010-11-09 09:39:23 +08001238 int dummy, tmp;
Andy Adamson0733d212009-04-03 08:28:01 +03001239 DECODE_HEAD;
1240
1241 READ_BUF(NFS4_VERIFIER_SIZE);
1242 COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE);
1243
J. Bruce Fieldsa084daf2011-10-10 15:07:40 -04001244 status = nfsd4_decode_opaque(argp, &exid->clname);
1245 if (status)
1246 return nfserr_bad_xdr;
Andy Adamson0733d212009-04-03 08:28:01 +03001247
1248 READ_BUF(4);
1249 READ32(exid->flags);
1250
1251 /* Ignore state_protect4_a */
1252 READ_BUF(4);
1253 READ32(exid->spa_how);
1254 switch (exid->spa_how) {
1255 case SP4_NONE:
1256 break;
1257 case SP4_MACH_CRED:
1258 /* spo_must_enforce */
1259 READ_BUF(4);
1260 READ32(dummy);
1261 READ_BUF(dummy * 4);
1262 p += dummy;
1263
1264 /* spo_must_allow */
1265 READ_BUF(4);
1266 READ32(dummy);
1267 READ_BUF(dummy * 4);
1268 p += dummy;
1269 break;
1270 case SP4_SSV:
1271 /* ssp_ops */
1272 READ_BUF(4);
1273 READ32(dummy);
1274 READ_BUF(dummy * 4);
1275 p += dummy;
1276
1277 READ_BUF(4);
1278 READ32(dummy);
1279 READ_BUF(dummy * 4);
1280 p += dummy;
1281
1282 /* ssp_hash_algs<> */
1283 READ_BUF(4);
Mi Jinlong5afa0402010-11-09 09:39:23 +08001284 READ32(tmp);
1285 while (tmp--) {
1286 READ_BUF(4);
1287 READ32(dummy);
1288 READ_BUF(dummy);
1289 p += XDR_QUADLEN(dummy);
1290 }
Andy Adamson0733d212009-04-03 08:28:01 +03001291
1292 /* ssp_encr_algs<> */
1293 READ_BUF(4);
Mi Jinlong5afa0402010-11-09 09:39:23 +08001294 READ32(tmp);
1295 while (tmp--) {
1296 READ_BUF(4);
1297 READ32(dummy);
1298 READ_BUF(dummy);
1299 p += XDR_QUADLEN(dummy);
1300 }
Andy Adamson0733d212009-04-03 08:28:01 +03001301
1302 /* ssp_window and ssp_num_gss_handles */
1303 READ_BUF(8);
1304 READ32(dummy);
1305 READ32(dummy);
1306 break;
1307 default:
1308 goto xdr_error;
1309 }
1310
1311 /* Ignore Implementation ID */
1312 READ_BUF(4); /* nfs_impl_id4 array length */
1313 READ32(dummy);
1314
1315 if (dummy > 1)
1316 goto xdr_error;
1317
1318 if (dummy == 1) {
1319 /* nii_domain */
1320 READ_BUF(4);
1321 READ32(dummy);
1322 READ_BUF(dummy);
1323 p += XDR_QUADLEN(dummy);
1324
1325 /* nii_name */
1326 READ_BUF(4);
1327 READ32(dummy);
1328 READ_BUF(dummy);
1329 p += XDR_QUADLEN(dummy);
1330
1331 /* nii_date */
1332 READ_BUF(12);
1333 p += 3;
1334 }
1335 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001336}
1337
1338static __be32
1339nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
1340 struct nfsd4_create_session *sess)
1341{
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001342 DECODE_HEAD;
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001343 u32 dummy;
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001344
1345 READ_BUF(16);
1346 COPYMEM(&sess->clientid, 8);
1347 READ32(sess->seqid);
1348 READ32(sess->flags);
1349
1350 /* Fore channel attrs */
1351 READ_BUF(28);
1352 READ32(dummy); /* headerpadsz is always 0 */
1353 READ32(sess->fore_channel.maxreq_sz);
1354 READ32(sess->fore_channel.maxresp_sz);
1355 READ32(sess->fore_channel.maxresp_cached);
1356 READ32(sess->fore_channel.maxops);
1357 READ32(sess->fore_channel.maxreqs);
1358 READ32(sess->fore_channel.nr_rdma_attrs);
1359 if (sess->fore_channel.nr_rdma_attrs == 1) {
1360 READ_BUF(4);
1361 READ32(sess->fore_channel.rdma_attrs);
1362 } else if (sess->fore_channel.nr_rdma_attrs > 1) {
1363 dprintk("Too many fore channel attr bitmaps!\n");
1364 goto xdr_error;
1365 }
1366
1367 /* Back channel attrs */
1368 READ_BUF(28);
1369 READ32(dummy); /* headerpadsz is always 0 */
1370 READ32(sess->back_channel.maxreq_sz);
1371 READ32(sess->back_channel.maxresp_sz);
1372 READ32(sess->back_channel.maxresp_cached);
1373 READ32(sess->back_channel.maxops);
1374 READ32(sess->back_channel.maxreqs);
1375 READ32(sess->back_channel.nr_rdma_attrs);
1376 if (sess->back_channel.nr_rdma_attrs == 1) {
1377 READ_BUF(4);
1378 READ32(sess->back_channel.rdma_attrs);
1379 } else if (sess->back_channel.nr_rdma_attrs > 1) {
1380 dprintk("Too many back channel attr bitmaps!\n");
1381 goto xdr_error;
1382 }
1383
J. Bruce Fieldsacb28872012-03-27 14:50:26 -04001384 READ_BUF(4);
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001385 READ32(sess->callback_prog);
J. Bruce Fieldsacb28872012-03-27 14:50:26 -04001386 nfsd4_decode_cb_sec(argp, &sess->cb_sec);
Andy Adamsonec6b5d72009-04-03 08:28:28 +03001387 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001388}
1389
1390static __be32
1391nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
1392 struct nfsd4_destroy_session *destroy_session)
1393{
Benny Halevye10e0cf2009-04-03 08:28:38 +03001394 DECODE_HEAD;
1395 READ_BUF(NFS4_MAX_SESSIONID_LEN);
1396 COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1397
1398 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001399}
1400
1401static __be32
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001402nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp,
1403 struct nfsd4_free_stateid *free_stateid)
1404{
1405 DECODE_HEAD;
1406
1407 READ_BUF(sizeof(stateid_t));
1408 READ32(free_stateid->fr_stateid.si_generation);
1409 COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t));
1410
1411 DECODE_TAIL;
1412}
1413
1414static __be32
Andy Adamson2db134e2009-04-03 08:27:55 +03001415nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
1416 struct nfsd4_sequence *seq)
1417{
Benny Halevyb85d4c02009-04-03 08:28:08 +03001418 DECODE_HEAD;
1419
1420 READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
1421 COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1422 READ32(seq->seqid);
1423 READ32(seq->slotid);
1424 READ32(seq->maxslots);
1425 READ32(seq->cachethis);
1426
1427 DECODE_TAIL;
Andy Adamson2db134e2009-04-03 08:27:55 +03001428}
1429
Bryan Schumaker17456802011-07-13 10:50:48 -04001430static __be32
1431nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid)
1432{
Bryan Schumaker17456802011-07-13 10:50:48 -04001433 int i;
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001434 __be32 *p, status;
1435 struct nfsd4_test_stateid_id *stateid;
Bryan Schumaker17456802011-07-13 10:50:48 -04001436
1437 READ_BUF(4);
1438 test_stateid->ts_num_ids = ntohl(*p++);
1439
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001440 INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
Bryan Schumaker17456802011-07-13 10:50:48 -04001441
1442 for (i = 0; i < test_stateid->ts_num_ids; i++) {
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001443 stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);
1444 if (!stateid) {
Al Viroafcf6792012-04-13 00:15:37 -04001445 status = nfserrno(-ENOMEM);
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001446 goto out;
1447 }
1448
1449 defer_free(argp, kfree, stateid);
1450 INIT_LIST_HEAD(&stateid->ts_id_list);
1451 list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list);
1452
1453 status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid);
Bryan Schumaker17456802011-07-13 10:50:48 -04001454 if (status)
Bryan Schumaker03cfb422012-01-27 10:22:49 -05001455 goto out;
Bryan Schumaker17456802011-07-13 10:50:48 -04001456 }
1457
1458 status = 0;
1459out:
1460 return status;
1461xdr_error:
1462 dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__);
1463 status = nfserr_bad_xdr;
1464 goto out;
1465}
1466
Mi Jinlong345c2842011-10-20 17:51:39 +08001467static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc)
1468{
1469 DECODE_HEAD;
1470
1471 READ_BUF(8);
1472 COPYMEM(&dc->clientid, 8);
1473
1474 DECODE_TAIL;
1475}
1476
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001477static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc)
1478{
1479 DECODE_HEAD;
1480
1481 READ_BUF(4);
1482 READ32(rc->rca_one_fs);
1483
1484 DECODE_TAIL;
1485}
1486
Andy Adamson2db134e2009-04-03 08:27:55 +03001487static __be32
Benny Halevy347e0ad2008-07-02 11:13:41 +03001488nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
1489{
1490 return nfs_ok;
1491}
1492
Benny Halevy3c375c62008-07-02 11:14:01 +03001493static __be32
1494nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
1495{
Benny Halevy1e685ec2009-03-04 23:06:06 +02001496 return nfserr_notsupp;
Benny Halevy3c375c62008-07-02 11:14:01 +03001497}
1498
Benny Halevy347e0ad2008-07-02 11:13:41 +03001499typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
1500
1501static nfsd4_dec nfsd4_dec_ops[] = {
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04001502 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
1503 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
1504 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
1505 [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
1506 [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
1507 [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
1508 [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
1509 [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
1510 [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
1511 [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
1512 [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
1513 [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
1514 [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
1515 [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
1516 [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1517 [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
1518 [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
1519 [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm,
1520 [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
1521 [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
J. Bruce Fieldsa1c8c4d2009-03-09 12:17:29 -04001522 [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_noop,
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04001523 [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
1524 [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
1525 [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
1526 [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
1527 [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
1528 [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
1529 [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew,
1530 [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
1531 [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
1532 [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
1533 [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
1534 [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid,
1535 [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm,
1536 [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1537 [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
1538 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
Benny Halevy347e0ad2008-07-02 11:13:41 +03001539};
1540
Andy Adamson2db134e2009-04-03 08:27:55 +03001541static nfsd4_dec nfsd41_dec_ops[] = {
Randy Dunlap9064caa2009-04-28 16:48:25 -07001542 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
1543 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
1544 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
1545 [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
1546 [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
1547 [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
1548 [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
1549 [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
1550 [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
1551 [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
1552 [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
1553 [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
1554 [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
1555 [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
1556 [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1557 [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
1558 [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
1559 [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_notsupp,
1560 [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
1561 [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
1562 [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_notsupp,
1563 [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
1564 [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
1565 [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
1566 [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
1567 [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
1568 [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
1569 [OP_RENEW] = (nfsd4_dec)nfsd4_decode_notsupp,
1570 [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
1571 [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
1572 [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
1573 [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
1574 [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_notsupp,
1575 [OP_SETCLIENTID_CONFIRM]= (nfsd4_dec)nfsd4_decode_notsupp,
1576 [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1577 [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
1578 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_notsupp,
Andy Adamson2db134e2009-04-03 08:27:55 +03001579
1580 /* new operations for NFSv4.1 */
J. Bruce Fieldscb73a9f2012-11-01 18:09:48 -04001581 [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04001582 [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001583 [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id,
1584 [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session,
1585 [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04001586 [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001587 [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
1588 [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp,
1589 [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
1590 [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp,
1591 [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp,
1592 [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp,
J. Bruce Fields04f4ad12010-12-16 09:51:13 -05001593 [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001594 [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence,
1595 [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp,
Bryan Schumaker17456802011-07-13 10:50:48 -04001596 [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid,
Randy Dunlap9064caa2009-04-28 16:48:25 -07001597 [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
Mi Jinlong345c2842011-10-20 17:51:39 +08001598 [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid,
J. Bruce Fields4dc6ec02010-04-19 15:11:28 -04001599 [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete,
Andy Adamson2db134e2009-04-03 08:27:55 +03001600};
1601
Benny Halevyf2feb962008-07-02 11:14:22 +03001602struct nfsd4_minorversion_ops {
1603 nfsd4_dec *decoders;
1604 int nops;
1605};
1606
1607static struct nfsd4_minorversion_ops nfsd4_minorversion[] = {
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04001608 [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) },
Andy Adamson2db134e2009-04-03 08:27:55 +03001609 [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
Steve Dickson4bdc33e2013-05-02 13:18:57 -04001610 [2] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
Benny Halevyf2feb962008-07-02 11:14:22 +03001611};
1612
Benny Halevy347e0ad2008-07-02 11:13:41 +03001613static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
1615{
1616 DECODE_HEAD;
1617 struct nfsd4_op *op;
Benny Halevyf2feb962008-07-02 11:14:22 +03001618 struct nfsd4_minorversion_ops *ops;
J. Bruce Fields10910062011-01-24 12:11:02 -05001619 bool cachethis = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 int i;
1621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 READ_BUF(4);
1623 READ32(argp->taglen);
1624 READ_BUF(argp->taglen + 8);
1625 SAVEMEM(argp->tag, argp->taglen);
1626 READ32(argp->minorversion);
1627 READ32(argp->opcnt);
1628
1629 if (argp->taglen > NFSD4_MAX_TAGLEN)
1630 goto xdr_error;
1631 if (argp->opcnt > 100)
1632 goto xdr_error;
1633
Tobias Klausere8c96f82006-03-24 03:15:34 -08001634 if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
1636 if (!argp->ops) {
1637 argp->ops = argp->iops;
Chuck Lever817cb9d2007-09-11 18:01:20 -04001638 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 goto xdr_error;
1640 }
1641 }
1642
Benny Halevyf2feb962008-07-02 11:14:22 +03001643 if (argp->minorversion >= ARRAY_SIZE(nfsd4_minorversion))
Benny Halevy30cff1f2008-07-02 11:13:18 +03001644 argp->opcnt = 0;
1645
Benny Halevyf2feb962008-07-02 11:14:22 +03001646 ops = &nfsd4_minorversion[argp->minorversion];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 for (i = 0; i < argp->opcnt; i++) {
1648 op = &argp->ops[i];
1649 op->replay = NULL;
1650
J. Bruce Fields8a61b182012-11-16 22:28:38 -05001651 READ_BUF(4);
1652 READ32(op->opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Ricardo Labiagade3cab72009-12-11 20:03:27 -08001654 if (op->opnum >= FIRST_NFS4_OP && op->opnum <= LAST_NFS4_OP)
Benny Halevyf2feb962008-07-02 11:14:22 +03001655 op->status = ops->decoders[op->opnum](argp, &op->u);
Benny Halevy347e0ad2008-07-02 11:13:41 +03001656 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 op->opnum = OP_ILLEGAL;
1658 op->status = nfserr_op_illegal;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 }
1660
1661 if (op->status) {
1662 argp->opcnt = i+1;
1663 break;
1664 }
J. Bruce Fields10910062011-01-24 12:11:02 -05001665 /*
1666 * We'll try to cache the result in the DRC if any one
1667 * op in the compound wants to be cached:
1668 */
1669 cachethis |= nfsd4_cache_this_op(op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 }
J. Bruce Fields10910062011-01-24 12:11:02 -05001671 /* Sessions make the DRC unnecessary: */
1672 if (argp->minorversion)
1673 cachethis = false;
1674 argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
1676 DECODE_TAIL;
1677}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679#define WRITE32(n) *p++ = htonl(n)
1680#define WRITE64(n) do { \
1681 *p++ = htonl((u32)((n) >> 32)); \
1682 *p++ = htonl((u32)(n)); \
1683} while (0)
Harvey Harrison5108b272008-07-17 21:33:04 -07001684#define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 *(p + XDR_QUADLEN(nbytes) -1) = 0; \
1686 memcpy(p, ptr, nbytes); \
1687 p += XDR_QUADLEN(nbytes); \
Harvey Harrison5108b272008-07-17 21:33:04 -07001688}} while (0)
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04001689
1690static void write32(__be32 **p, u32 n)
1691{
J. Bruce Fields45eaa1c2012-04-25 18:11:04 -04001692 *(*p)++ = htonl(n);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04001693}
1694
1695static void write64(__be32 **p, u64 n)
1696{
J. Bruce Fields45eaa1c2012-04-25 18:11:04 -04001697 write32(p, (n >> 32));
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04001698 write32(p, (u32)n);
1699}
1700
1701static void write_change(__be32 **p, struct kstat *stat, struct inode *inode)
1702{
1703 if (IS_I_VERSION(inode)) {
1704 write64(p, inode->i_version);
1705 } else {
1706 write32(p, stat->ctime.tv_sec);
1707 write32(p, stat->ctime.tv_nsec);
1708 }
1709}
1710
1711static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)
1712{
1713 write32(p, c->atomic);
1714 if (c->change_supported) {
1715 write64(p, c->before_change);
1716 write64(p, c->after_change);
1717 } else {
1718 write32(p, c->before_ctime_sec);
1719 write32(p, c->before_ctime_nsec);
1720 write32(p, c->after_ctime_sec);
1721 write32(p, c->after_ctime_nsec);
1722 }
1723}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725#define RESERVE_SPACE(nbytes) do { \
1726 p = resp->p; \
1727 BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
1728} while (0)
1729#define ADJUST_ARGS() resp->p = p
1730
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001731/* Encode as an array of strings the string given with components
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001732 * separated @sep, escaped with esc_enter and esc_exit.
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001733 */
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001734static __be32 nfsd4_encode_components_esc(char sep, char *components,
1735 __be32 **pp, int *buflen,
1736 char esc_enter, char esc_exit)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001737{
Al Viro2ebbc012006-10-19 23:28:58 -07001738 __be32 *p = *pp;
1739 __be32 *countp = p;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001740 int strlen, count=0;
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001741 char *str, *end, *next;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001742
1743 dprintk("nfsd4_encode_components(%s)\n", components);
1744 if ((*buflen -= 4) < 0)
1745 return nfserr_resource;
1746 WRITE32(0); /* We will fill this in with @count later */
1747 end = str = components;
1748 while (*end) {
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001749 bool found_esc = false;
1750
1751 /* try to parse as esc_start, ..., esc_end, sep */
1752 if (*str == esc_enter) {
1753 for (; *end && (*end != esc_exit); end++)
1754 /* find esc_exit or end of string */;
1755 next = end + 1;
1756 if (*end && (!*next || *next == sep)) {
1757 str++;
1758 found_esc = true;
1759 }
1760 }
1761
1762 if (!found_esc)
1763 for (; *end && (*end != sep); end++)
1764 /* find sep or end of string */;
1765
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001766 strlen = end - str;
1767 if (strlen) {
1768 if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
1769 return nfserr_resource;
1770 WRITE32(strlen);
1771 WRITEMEM(str, strlen);
1772 count++;
1773 }
1774 else
1775 end++;
1776 str = end;
1777 }
1778 *pp = p;
1779 p = countp;
1780 WRITE32(count);
1781 return 0;
1782}
1783
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001784/* Encode as an array of strings the string given with components
1785 * separated @sep.
1786 */
1787static __be32 nfsd4_encode_components(char sep, char *components,
1788 __be32 **pp, int *buflen)
1789{
1790 return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0);
1791}
1792
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001793/*
1794 * encode a location element of a fs_locations structure
1795 */
Al Virob37ad282006-10-19 23:28:59 -07001796static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
Al Viro2ebbc012006-10-19 23:28:58 -07001797 __be32 **pp, int *buflen)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001798{
Al Virob37ad282006-10-19 23:28:59 -07001799 __be32 status;
Al Viro2ebbc012006-10-19 23:28:58 -07001800 __be32 *p = *pp;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001801
Weston Andros Adamsone7a04442012-04-24 11:07:59 -04001802 status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen,
1803 '[', ']');
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001804 if (status)
1805 return status;
1806 status = nfsd4_encode_components('/', location->path, &p, buflen);
1807 if (status)
1808 return status;
1809 *pp = p;
1810 return 0;
1811}
1812
1813/*
Trond Myklebusted748aa2011-09-12 19:37:06 -04001814 * Encode a path in RFC3530 'pathname4' format
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001815 */
Trond Myklebusted748aa2011-09-12 19:37:06 -04001816static __be32 nfsd4_encode_path(const struct path *root,
1817 const struct path *path, __be32 **pp, int *buflen)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001818{
Al Viro301f0262013-09-01 16:06:39 -04001819 struct path cur = *path;
Trond Myklebusted748aa2011-09-12 19:37:06 -04001820 __be32 *p = *pp;
1821 struct dentry **components = NULL;
1822 unsigned int ncomponents = 0;
1823 __be32 err = nfserr_jukebox;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001824
Trond Myklebusted748aa2011-09-12 19:37:06 -04001825 dprintk("nfsd4_encode_components(");
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001826
Trond Myklebusted748aa2011-09-12 19:37:06 -04001827 path_get(&cur);
1828 /* First walk the path up to the nfsd root, and store the
1829 * dentries/path components in an array.
1830 */
1831 for (;;) {
1832 if (cur.dentry == root->dentry && cur.mnt == root->mnt)
1833 break;
1834 if (cur.dentry == cur.mnt->mnt_root) {
1835 if (follow_up(&cur))
1836 continue;
1837 goto out_free;
1838 }
1839 if ((ncomponents & 15) == 0) {
1840 struct dentry **new;
1841 new = krealloc(components,
1842 sizeof(*new) * (ncomponents + 16),
1843 GFP_KERNEL);
1844 if (!new)
1845 goto out_free;
1846 components = new;
1847 }
1848 components[ncomponents++] = cur.dentry;
1849 cur.dentry = dget_parent(cur.dentry);
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001850 }
Trond Myklebusted748aa2011-09-12 19:37:06 -04001851
1852 *buflen -= 4;
1853 if (*buflen < 0)
1854 goto out_free;
1855 WRITE32(ncomponents);
1856
1857 while (ncomponents) {
1858 struct dentry *dentry = components[ncomponents - 1];
Al Viro301f0262013-09-01 16:06:39 -04001859 unsigned int len;
Trond Myklebusted748aa2011-09-12 19:37:06 -04001860
Al Viro301f0262013-09-01 16:06:39 -04001861 spin_lock(&dentry->d_lock);
1862 len = dentry->d_name.len;
Trond Myklebusted748aa2011-09-12 19:37:06 -04001863 *buflen -= 4 + (XDR_QUADLEN(len) << 2);
Al Viro301f0262013-09-01 16:06:39 -04001864 if (*buflen < 0) {
1865 spin_unlock(&dentry->d_lock);
Trond Myklebusted748aa2011-09-12 19:37:06 -04001866 goto out_free;
Al Viro301f0262013-09-01 16:06:39 -04001867 }
Trond Myklebusted748aa2011-09-12 19:37:06 -04001868 WRITE32(len);
1869 WRITEMEM(dentry->d_name.name, len);
1870 dprintk("/%s", dentry->d_name.name);
Al Viro301f0262013-09-01 16:06:39 -04001871 spin_unlock(&dentry->d_lock);
Trond Myklebusted748aa2011-09-12 19:37:06 -04001872 dput(dentry);
1873 ncomponents--;
1874 }
1875
1876 *pp = p;
1877 err = 0;
1878out_free:
1879 dprintk(")\n");
1880 while (ncomponents)
1881 dput(components[--ncomponents]);
1882 kfree(components);
1883 path_put(&cur);
1884 return err;
1885}
1886
1887static __be32 nfsd4_encode_fsloc_fsroot(struct svc_rqst *rqstp,
1888 const struct path *path, __be32 **pp, int *buflen)
1889{
1890 struct svc_export *exp_ps;
1891 __be32 res;
1892
1893 exp_ps = rqst_find_fsidzero_export(rqstp);
1894 if (IS_ERR(exp_ps))
1895 return nfserrno(PTR_ERR(exp_ps));
1896 res = nfsd4_encode_path(&exp_ps->ex_path, path, pp, buflen);
1897 exp_put(exp_ps);
1898 return res;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001899}
1900
1901/*
1902 * encode a fs_locations structure
1903 */
Al Virob37ad282006-10-19 23:28:59 -07001904static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001905 struct svc_export *exp,
Al Viro2ebbc012006-10-19 23:28:58 -07001906 __be32 **pp, int *buflen)
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001907{
Al Virob37ad282006-10-19 23:28:59 -07001908 __be32 status;
Al Virocc45f012006-10-19 23:28:44 -07001909 int i;
Al Viro2ebbc012006-10-19 23:28:58 -07001910 __be32 *p = *pp;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001911 struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001912
Trond Myklebusted748aa2011-09-12 19:37:06 -04001913 status = nfsd4_encode_fsloc_fsroot(rqstp, &exp->ex_path, &p, buflen);
J.Bruce Fields81c3f412006-10-04 02:16:19 -07001914 if (status)
1915 return status;
1916 if ((*buflen -= 4) < 0)
1917 return nfserr_resource;
1918 WRITE32(fslocs->locations_count);
1919 for (i=0; i<fslocs->locations_count; i++) {
1920 status = nfsd4_encode_fs_location4(&fslocs->locations[i],
1921 &p, buflen);
1922 if (status)
1923 return status;
1924 }
1925 *pp = p;
1926 return 0;
1927}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
J. Bruce Fields3d2544b2011-08-15 11:49:30 -04001929static u32 nfs4_file_type(umode_t mode)
1930{
1931 switch (mode & S_IFMT) {
1932 case S_IFIFO: return NF4FIFO;
1933 case S_IFCHR: return NF4CHR;
1934 case S_IFDIR: return NF4DIR;
1935 case S_IFBLK: return NF4BLK;
1936 case S_IFLNK: return NF4LNK;
1937 case S_IFREG: return NF4REG;
1938 case S_IFSOCK: return NF4SOCK;
1939 default: return NF4BAD;
1940 };
1941}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
Al Virob37ad282006-10-19 23:28:59 -07001943static __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001944nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, kuid_t uid, kgid_t gid,
Al Viro2ebbc012006-10-19 23:28:58 -07001945 __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946{
1947 int status;
1948
1949 if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4)
1950 return nfserr_resource;
1951 if (whotype != NFS4_ACL_WHO_NAMED)
1952 status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1));
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001953 else if (gid_valid(gid))
1954 status = nfsd_map_gid_to_name(rqstp, gid, (u8 *)(*p + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 else
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001956 status = nfsd_map_uid_to_name(rqstp, uid, (u8 *)(*p + 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 if (status < 0)
1958 return nfserrno(status);
1959 *p = xdr_encode_opaque(*p, NULL, status);
1960 *buflen -= (XDR_QUADLEN(status) << 2) + 4;
1961 BUG_ON(*buflen < 0);
1962 return 0;
1963}
1964
Al Virob37ad282006-10-19 23:28:59 -07001965static inline __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001966nfsd4_encode_user(struct svc_rqst *rqstp, kuid_t user, __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967{
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001968 return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, user, INVALID_GID,
1969 p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970}
1971
Al Virob37ad282006-10-19 23:28:59 -07001972static inline __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001973nfsd4_encode_group(struct svc_rqst *rqstp, kgid_t group, __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974{
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001975 return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, INVALID_UID, group,
1976 p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977}
1978
Al Virob37ad282006-10-19 23:28:59 -07001979static inline __be32
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001980nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,
Al Viro2ebbc012006-10-19 23:28:58 -07001981 __be32 **p, int *buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08001983 kuid_t uid = INVALID_UID;
1984 kgid_t gid = INVALID_GID;
1985
1986 if (ace->whotype == NFS4_ACL_WHO_NAMED) {
1987 if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
1988 gid = ace->who_gid;
1989 else
1990 uid = ace->who_uid;
1991 }
1992 return nfsd4_encode_name(rqstp, ace->whotype, uid, gid, p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993}
1994
J.Bruce Fields42ca0992006-10-04 02:16:20 -07001995#define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
1996 FATTR4_WORD0_RDATTR_ERROR)
1997#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
1998
David Quigley18032ca2013-05-02 13:19:10 -04001999#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2000static inline __be32
2001nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen)
2002{
2003 __be32 *p = *pp;
2004
2005 if (*buflen < ((XDR_QUADLEN(len) << 2) + 4 + 4 + 4))
2006 return nfserr_resource;
2007
2008 /*
2009 * For now we use a 0 here to indicate the null translation; in
2010 * the future we may place a call to translation code here.
2011 */
2012 if ((*buflen -= 8) < 0)
2013 return nfserr_resource;
2014
2015 WRITE32(0); /* lfs */
2016 WRITE32(0); /* pi */
2017 p = xdr_encode_opaque(p, context, len);
2018 *buflen -= (XDR_QUADLEN(len) << 2) + 4;
2019
2020 *pp = p;
2021 return 0;
2022}
2023#else
2024static inline __be32
J. Bruce Fieldsba4e55b2013-05-15 10:27:52 -04002025nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen)
David Quigley18032ca2013-05-02 13:19:10 -04002026{ return 0; }
2027#endif
2028
Al Virob37ad282006-10-19 23:28:59 -07002029static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002030{
2031 /* As per referral draft: */
2032 if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
2033 *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
2034 if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
2035 *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
2036 *rdattr_err = NFSERR_MOVED;
2037 else
2038 return nfserr_moved;
2039 }
2040 *bmval0 &= WORD0_ABSENT_FS_ATTRS;
2041 *bmval1 &= WORD1_ABSENT_FS_ATTRS;
2042 return 0;
2043}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
J. Bruce Fieldsae7095a2012-10-01 17:50:56 -04002045
2046static int get_parent_attributes(struct svc_export *exp, struct kstat *stat)
2047{
2048 struct path path = exp->ex_path;
2049 int err;
2050
2051 path_get(&path);
2052 while (follow_up(&path)) {
2053 if (path.dentry != path.mnt->mnt_root)
2054 break;
2055 }
Al Viro3dadecc2013-01-24 02:18:08 -05002056 err = vfs_getattr(&path, stat);
J. Bruce Fieldsae7095a2012-10-01 17:50:56 -04002057 path_put(&path);
2058 return err;
2059}
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061/*
2062 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
2063 * ourselves.
2064 *
J. Bruce Fields84822d02012-12-14 17:57:50 -05002065 * countp is the buffer size in _words_
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 */
Al Virob37ad282006-10-19 23:28:59 -07002067__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
J. Bruce Fields84822d02012-12-14 17:57:50 -05002069 struct dentry *dentry, __be32 **buffer, int count, u32 *bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08002070 struct svc_rqst *rqstp, int ignore_crossmnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071{
2072 u32 bmval0 = bmval[0];
2073 u32 bmval1 = bmval[1];
Andy Adamson7e705702009-04-03 08:29:11 +03002074 u32 bmval2 = bmval[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 struct kstat stat;
2076 struct svc_fh tempfh;
2077 struct kstatfs statfs;
J. Bruce Fields84822d02012-12-14 17:57:50 -05002078 int buflen = count << 2;
Al Viro2ebbc012006-10-19 23:28:58 -07002079 __be32 *attrlenp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 u32 dummy;
2081 u64 dummy64;
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002082 u32 rdattr_err = 0;
J. Bruce Fields84822d02012-12-14 17:57:50 -05002083 __be32 *p = *buffer;
Al Virob37ad282006-10-19 23:28:59 -07002084 __be32 status;
Al Virob8dd7b92006-10-19 23:29:01 -07002085 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 int aclsupport = 0;
2087 struct nfs4_acl *acl = NULL;
David Quigley18032ca2013-05-02 13:19:10 -04002088 void *context = NULL;
2089 int contextlen;
2090 bool contextsupport = false;
Andy Adamson7e705702009-04-03 08:29:11 +03002091 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2092 u32 minorversion = resp->cstate.minorversion;
Christoph Hellwigebabe9a2010-07-07 18:53:11 +02002093 struct path path = {
2094 .mnt = exp->ex_path.mnt,
2095 .dentry = dentry,
2096 };
Stanislav Kinsbursky3d733712012-11-27 14:11:44 +03002097 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
Andy Adamson7e705702009-04-03 08:29:11 +03002100 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
2101 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
2102 BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002104 if (exp->ex_fslocs.migrated) {
Andy Adamson7e705702009-04-03 08:29:11 +03002105 BUG_ON(bmval[2]);
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002106 status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err);
2107 if (status)
2108 goto out;
2109 }
2110
Al Viro3dadecc2013-01-24 02:18:08 -05002111 err = vfs_getattr(&path, &stat);
Al Virob8dd7b92006-10-19 23:29:01 -07002112 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 goto out_nfserr;
J. Bruce Fieldsa16e92e2007-09-28 16:45:51 -04002114 if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
2115 FATTR4_WORD0_MAXNAME)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
2117 FATTR4_WORD1_SPACE_TOTAL))) {
Christoph Hellwigebabe9a2010-07-07 18:53:11 +02002118 err = vfs_statfs(&path, &statfs);
Al Virob8dd7b92006-10-19 23:29:01 -07002119 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 goto out_nfserr;
2121 }
2122 if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
2123 fh_init(&tempfh, NFS4_FHSIZE);
2124 status = fh_compose(&tempfh, exp, dentry, NULL);
2125 if (status)
2126 goto out;
2127 fhp = &tempfh;
2128 }
2129 if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
2130 | FATTR4_WORD0_SUPPORTED_ATTRS)) {
Al Virob8dd7b92006-10-19 23:29:01 -07002131 err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
2132 aclsupport = (err == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 if (bmval0 & FATTR4_WORD0_ACL) {
Al Virob8dd7b92006-10-19 23:29:01 -07002134 if (err == -EOPNOTSUPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 bmval0 &= ~FATTR4_WORD0_ACL;
Al Virob8dd7b92006-10-19 23:29:01 -07002136 else if (err == -EINVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 status = nfserr_attrnotsupp;
2138 goto out;
Al Virob8dd7b92006-10-19 23:29:01 -07002139 } else if (err != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 goto out_nfserr;
2141 }
2142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
David Quigley18032ca2013-05-02 13:19:10 -04002144#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2145 if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) ||
2146 bmval[0] & FATTR4_WORD0_SUPPORTED_ATTRS) {
2147 err = security_inode_getsecctx(dentry->d_inode,
2148 &context, &contextlen);
2149 contextsupport = (err == 0);
2150 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
2151 if (err == -EOPNOTSUPP)
2152 bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2153 else if (err)
2154 goto out_nfserr;
2155 }
2156 }
2157#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2158
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002159 if (bmval2) {
2160 if ((buflen -= 16) < 0)
2161 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002162 WRITE32(3);
2163 WRITE32(bmval0);
2164 WRITE32(bmval1);
2165 WRITE32(bmval2);
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002166 } else if (bmval1) {
2167 if ((buflen -= 12) < 0)
2168 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002169 WRITE32(2);
2170 WRITE32(bmval0);
2171 WRITE32(bmval1);
2172 } else {
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002173 if ((buflen -= 8) < 0)
2174 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002175 WRITE32(1);
2176 WRITE32(bmval0);
2177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 attrlenp = p++; /* to be backfilled later */
2179
2180 if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
Andy Adamson7e705702009-04-03 08:29:11 +03002181 u32 word0 = nfsd_suppattrs0(minorversion);
2182 u32 word1 = nfsd_suppattrs1(minorversion);
2183 u32 word2 = nfsd_suppattrs2(minorversion);
2184
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002185 if (!aclsupport)
2186 word0 &= ~FATTR4_WORD0_ACL;
David Quigley18032ca2013-05-02 13:19:10 -04002187 if (!contextsupport)
2188 word2 &= ~FATTR4_WORD2_SECURITY_LABEL;
Andy Adamson7e705702009-04-03 08:29:11 +03002189 if (!word2) {
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002190 if ((buflen -= 12) < 0)
2191 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002192 WRITE32(2);
2193 WRITE32(word0);
2194 WRITE32(word1);
2195 } else {
Benny Halevy2b44f1b2010-09-30 20:47:46 +02002196 if ((buflen -= 16) < 0)
2197 goto out_resource;
Andy Adamson7e705702009-04-03 08:29:11 +03002198 WRITE32(3);
2199 WRITE32(word0);
2200 WRITE32(word1);
2201 WRITE32(word2);
2202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 }
2204 if (bmval0 & FATTR4_WORD0_TYPE) {
2205 if ((buflen -= 4) < 0)
2206 goto out_resource;
J. Bruce Fields3d2544b2011-08-15 11:49:30 -04002207 dummy = nfs4_file_type(stat.mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 if (dummy == NF4BAD)
2209 goto out_serverfault;
2210 WRITE32(dummy);
2211 }
2212 if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
2213 if ((buflen -= 4) < 0)
2214 goto out_resource;
NeilBrown49640002005-06-23 22:02:58 -07002215 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
NeilBrowne34ac862005-07-07 17:59:30 -07002216 WRITE32(NFS4_FH_PERSISTENT);
NeilBrown49640002005-06-23 22:02:58 -07002217 else
NeilBrowne34ac862005-07-07 17:59:30 -07002218 WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 }
2220 if (bmval0 & FATTR4_WORD0_CHANGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 if ((buflen -= 8) < 0)
2222 goto out_resource;
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002223 write_change(&p, &stat, dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 }
2225 if (bmval0 & FATTR4_WORD0_SIZE) {
2226 if ((buflen -= 8) < 0)
2227 goto out_resource;
2228 WRITE64(stat.size);
2229 }
2230 if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
2231 if ((buflen -= 4) < 0)
2232 goto out_resource;
2233 WRITE32(1);
2234 }
2235 if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
2236 if ((buflen -= 4) < 0)
2237 goto out_resource;
2238 WRITE32(1);
2239 }
2240 if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
2241 if ((buflen -= 4) < 0)
2242 goto out_resource;
2243 WRITE32(0);
2244 }
2245 if (bmval0 & FATTR4_WORD0_FSID) {
2246 if ((buflen -= 16) < 0)
2247 goto out_resource;
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002248 if (exp->ex_fslocs.migrated) {
2249 WRITE64(NFS4_REFERRAL_FSID_MAJOR);
2250 WRITE64(NFS4_REFERRAL_FSID_MINOR);
NeilBrownaf6a4e22007-02-14 00:33:12 -08002251 } else switch(fsid_source(fhp)) {
2252 case FSIDSOURCE_FSID:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 WRITE64((u64)exp->ex_fsid);
2254 WRITE64((u64)0);
NeilBrownaf6a4e22007-02-14 00:33:12 -08002255 break;
2256 case FSIDSOURCE_DEV:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 WRITE32(0);
2258 WRITE32(MAJOR(stat.dev));
2259 WRITE32(0);
2260 WRITE32(MINOR(stat.dev));
NeilBrownaf6a4e22007-02-14 00:33:12 -08002261 break;
2262 case FSIDSOURCE_UUID:
2263 WRITEMEM(exp->ex_uuid, 16);
2264 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 }
2266 }
2267 if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
2268 if ((buflen -= 4) < 0)
2269 goto out_resource;
2270 WRITE32(0);
2271 }
2272 if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
2273 if ((buflen -= 4) < 0)
2274 goto out_resource;
Stanislav Kinsbursky3d733712012-11-27 14:11:44 +03002275 WRITE32(nn->nfsd4_lease);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 }
2277 if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
2278 if ((buflen -= 4) < 0)
2279 goto out_resource;
J.Bruce Fields42ca0992006-10-04 02:16:20 -07002280 WRITE32(rdattr_err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 }
2282 if (bmval0 & FATTR4_WORD0_ACL) {
2283 struct nfs4_ace *ace;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 if (acl == NULL) {
2286 if ((buflen -= 4) < 0)
2287 goto out_resource;
2288
2289 WRITE32(0);
2290 goto out_acl;
2291 }
2292 if ((buflen -= 4) < 0)
2293 goto out_resource;
2294 WRITE32(acl->naces);
2295
J. Bruce Fields28e05dd2007-02-16 01:28:30 -08002296 for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 if ((buflen -= 4*3) < 0)
2298 goto out_resource;
2299 WRITE32(ace->type);
2300 WRITE32(ace->flag);
2301 WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL);
Eric W. Biedermanab8e4ae2013-02-02 05:18:08 -08002302 status = nfsd4_encode_aclname(rqstp, ace, &p, &buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 if (status == nfserr_resource)
2304 goto out_resource;
2305 if (status)
2306 goto out;
2307 }
2308 }
2309out_acl:
2310 if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
2311 if ((buflen -= 4) < 0)
2312 goto out_resource;
2313 WRITE32(aclsupport ?
2314 ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
2315 }
2316 if (bmval0 & FATTR4_WORD0_CANSETTIME) {
2317 if ((buflen -= 4) < 0)
2318 goto out_resource;
2319 WRITE32(1);
2320 }
2321 if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
2322 if ((buflen -= 4) < 0)
2323 goto out_resource;
J. Bruce Fields2930d382012-06-05 16:52:06 -04002324 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 }
2326 if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
2327 if ((buflen -= 4) < 0)
2328 goto out_resource;
2329 WRITE32(1);
2330 }
2331 if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
2332 if ((buflen -= 4) < 0)
2333 goto out_resource;
2334 WRITE32(1);
2335 }
2336 if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
2337 buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4;
2338 if (buflen < 0)
2339 goto out_resource;
2340 WRITE32(fhp->fh_handle.fh_size);
2341 WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size);
2342 }
2343 if (bmval0 & FATTR4_WORD0_FILEID) {
2344 if ((buflen -= 8) < 0)
2345 goto out_resource;
Peter Staubach40ee5dc2007-08-16 12:10:07 -04002346 WRITE64(stat.ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 }
2348 if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
2349 if ((buflen -= 8) < 0)
2350 goto out_resource;
2351 WRITE64((u64) statfs.f_ffree);
2352 }
2353 if (bmval0 & FATTR4_WORD0_FILES_FREE) {
2354 if ((buflen -= 8) < 0)
2355 goto out_resource;
2356 WRITE64((u64) statfs.f_ffree);
2357 }
2358 if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
2359 if ((buflen -= 8) < 0)
2360 goto out_resource;
2361 WRITE64((u64) statfs.f_files);
2362 }
J.Bruce Fields81c3f412006-10-04 02:16:19 -07002363 if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
2364 status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen);
2365 if (status == nfserr_resource)
2366 goto out_resource;
2367 if (status)
2368 goto out;
2369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
2371 if ((buflen -= 4) < 0)
2372 goto out_resource;
2373 WRITE32(1);
2374 }
2375 if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
2376 if ((buflen -= 8) < 0)
2377 goto out_resource;
2378 WRITE64(~(u64)0);
2379 }
2380 if (bmval0 & FATTR4_WORD0_MAXLINK) {
2381 if ((buflen -= 4) < 0)
2382 goto out_resource;
2383 WRITE32(255);
2384 }
2385 if (bmval0 & FATTR4_WORD0_MAXNAME) {
2386 if ((buflen -= 4) < 0)
2387 goto out_resource;
J. Bruce Fieldsa16e92e2007-09-28 16:45:51 -04002388 WRITE32(statfs.f_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 }
2390 if (bmval0 & FATTR4_WORD0_MAXREAD) {
2391 if ((buflen -= 8) < 0)
2392 goto out_resource;
Greg Banks7adae482006-10-04 02:15:47 -07002393 WRITE64((u64) svc_max_payload(rqstp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 }
2395 if (bmval0 & FATTR4_WORD0_MAXWRITE) {
2396 if ((buflen -= 8) < 0)
2397 goto out_resource;
Greg Banks7adae482006-10-04 02:15:47 -07002398 WRITE64((u64) svc_max_payload(rqstp));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 }
2400 if (bmval1 & FATTR4_WORD1_MODE) {
2401 if ((buflen -= 4) < 0)
2402 goto out_resource;
2403 WRITE32(stat.mode & S_IALLUGO);
2404 }
2405 if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
2406 if ((buflen -= 4) < 0)
2407 goto out_resource;
2408 WRITE32(1);
2409 }
2410 if (bmval1 & FATTR4_WORD1_NUMLINKS) {
2411 if ((buflen -= 4) < 0)
2412 goto out_resource;
2413 WRITE32(stat.nlink);
2414 }
2415 if (bmval1 & FATTR4_WORD1_OWNER) {
2416 status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
2417 if (status == nfserr_resource)
2418 goto out_resource;
2419 if (status)
2420 goto out;
2421 }
2422 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
2423 status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
2424 if (status == nfserr_resource)
2425 goto out_resource;
2426 if (status)
2427 goto out;
2428 }
2429 if (bmval1 & FATTR4_WORD1_RAWDEV) {
2430 if ((buflen -= 8) < 0)
2431 goto out_resource;
2432 WRITE32((u32) MAJOR(stat.rdev));
2433 WRITE32((u32) MINOR(stat.rdev));
2434 }
2435 if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
2436 if ((buflen -= 8) < 0)
2437 goto out_resource;
2438 dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
2439 WRITE64(dummy64);
2440 }
2441 if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
2442 if ((buflen -= 8) < 0)
2443 goto out_resource;
2444 dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
2445 WRITE64(dummy64);
2446 }
2447 if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
2448 if ((buflen -= 8) < 0)
2449 goto out_resource;
2450 dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
2451 WRITE64(dummy64);
2452 }
2453 if (bmval1 & FATTR4_WORD1_SPACE_USED) {
2454 if ((buflen -= 8) < 0)
2455 goto out_resource;
2456 dummy64 = (u64)stat.blocks << 9;
2457 WRITE64(dummy64);
2458 }
2459 if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
2460 if ((buflen -= 12) < 0)
2461 goto out_resource;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -04002462 WRITE64((s64)stat.atime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 WRITE32(stat.atime.tv_nsec);
2464 }
2465 if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
2466 if ((buflen -= 12) < 0)
2467 goto out_resource;
2468 WRITE32(0);
2469 WRITE32(1);
2470 WRITE32(0);
2471 }
2472 if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
2473 if ((buflen -= 12) < 0)
2474 goto out_resource;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -04002475 WRITE64((s64)stat.ctime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 WRITE32(stat.ctime.tv_nsec);
2477 }
2478 if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
2479 if ((buflen -= 12) < 0)
2480 goto out_resource;
Bryan Schumakerbf8d9092013-04-19 16:09:38 -04002481 WRITE64((s64)stat.mtime.tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 WRITE32(stat.mtime.tv_nsec);
2483 }
2484 if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 if ((buflen -= 8) < 0)
2486 goto out_resource;
Frank Filz406a7ea2007-11-27 11:34:05 -08002487 /*
2488 * Get parent's attributes if not ignoring crossmount
2489 * and this is the root of a cross-mounted filesystem.
2490 */
2491 if (ignore_crossmnt == 0 &&
J. Bruce Fieldsae7095a2012-10-01 17:50:56 -04002492 dentry == exp->ex_path.mnt->mnt_root)
2493 get_parent_attributes(exp, &stat);
Peter Staubach40ee5dc2007-08-16 12:10:07 -04002494 WRITE64(stat.ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 }
David Quigley18032ca2013-05-02 13:19:10 -04002496 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
2497 status = nfsd4_encode_security_label(rqstp, context,
2498 contextlen, &p, &buflen);
2499 if (status)
2500 goto out;
2501 }
Benny Halevy8c18f202009-04-03 08:29:14 +03002502 if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
2503 WRITE32(3);
2504 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
2505 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1);
2506 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2);
2507 }
Andy Adamson7e705702009-04-03 08:29:11 +03002508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
J. Bruce Fields84822d02012-12-14 17:57:50 -05002510 *buffer = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 status = nfs_ok;
2512
2513out:
J. Bruce Fieldsba4e55b2013-05-15 10:27:52 -04002514#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
David Quigley18032ca2013-05-02 13:19:10 -04002515 if (context)
2516 security_release_secctx(context, contextlen);
J. Bruce Fieldsba4e55b2013-05-15 10:27:52 -04002517#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
J. Bruce Fields28e05dd2007-02-16 01:28:30 -08002518 kfree(acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 if (fhp == &tempfh)
2520 fh_put(&tempfh);
2521 return status;
2522out_nfserr:
Al Virob8dd7b92006-10-19 23:29:01 -07002523 status = nfserrno(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 goto out;
2525out_resource:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 status = nfserr_resource;
2527 goto out;
2528out_serverfault:
2529 status = nfserr_serverfault;
2530 goto out;
2531}
2532
J. Bruce Fieldsc0ce6ec2008-02-11 15:48:47 -05002533static inline int attributes_need_mount(u32 *bmval)
2534{
2535 if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
2536 return 1;
2537 if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
2538 return 1;
2539 return 0;
2540}
2541
Al Virob37ad282006-10-19 23:28:59 -07002542static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
J. Bruce Fields84822d02012-12-14 17:57:50 -05002544 const char *name, int namlen, __be32 **p, int buflen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
2546 struct svc_export *exp = cd->rd_fhp->fh_export;
2547 struct dentry *dentry;
Al Virob37ad282006-10-19 23:28:59 -07002548 __be32 nfserr;
Frank Filz406a7ea2007-11-27 11:34:05 -08002549 int ignore_crossmnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
2551 dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
2552 if (IS_ERR(dentry))
2553 return nfserrno(PTR_ERR(dentry));
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002554 if (!dentry->d_inode) {
2555 /*
2556 * nfsd_buffered_readdir drops the i_mutex between
2557 * readdir and calling this callback, leaving a window
2558 * where this directory entry could have gone away.
2559 */
2560 dput(dentry);
2561 return nfserr_noent;
2562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564 exp_get(exp);
Frank Filz406a7ea2007-11-27 11:34:05 -08002565 /*
2566 * In the case of a mountpoint, the client may be asking for
2567 * attributes that are only properties of the underlying filesystem
2568 * as opposed to the cross-mounted file system. In such a case,
2569 * we will not follow the cross mount and will fill the attribtutes
2570 * directly from the mountpoint dentry.
2571 */
J. Bruce Fields3227fa42009-10-25 21:43:01 -04002572 if (nfsd_mountpoint(dentry, exp)) {
J.Bruce Fields021d3a72006-12-13 00:35:24 -08002573 int err;
2574
J. Bruce Fields3227fa42009-10-25 21:43:01 -04002575 if (!(exp->ex_flags & NFSEXP_V4ROOT)
2576 && !attributes_need_mount(cd->rd_bmval)) {
2577 ignore_crossmnt = 1;
2578 goto out_encode;
2579 }
Andy Adamsondcb488a32007-07-17 04:04:51 -07002580 /*
2581 * Why the heck aren't we just using nfsd_lookup??
2582 * Different "."/".." handling? Something else?
2583 * At least, add a comment here to explain....
2584 */
J.Bruce Fields021d3a72006-12-13 00:35:24 -08002585 err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
2586 if (err) {
2587 nfserr = nfserrno(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 goto out_put;
2589 }
Andy Adamsondcb488a32007-07-17 04:04:51 -07002590 nfserr = check_nfsd_access(exp, cd->rd_rqstp);
2591 if (nfserr)
2592 goto out_put;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
2594 }
J. Bruce Fields3227fa42009-10-25 21:43:01 -04002595out_encode:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08002597 cd->rd_rqstp, ignore_crossmnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598out_put:
2599 dput(dentry);
2600 exp_put(exp);
2601 return nfserr;
2602}
2603
Al Viro2ebbc012006-10-19 23:28:58 -07002604static __be32 *
Al Virob37ad282006-10-19 23:28:59 -07002605nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606{
Al Viro2ebbc012006-10-19 23:28:58 -07002607 __be32 *attrlenp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608
2609 if (buflen < 6)
2610 return NULL;
2611 *p++ = htonl(2);
2612 *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
2613 *p++ = htonl(0); /* bmval1 */
2614
2615 attrlenp = p++;
2616 *p++ = nfserr; /* no htonl */
2617 *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
2618 return p;
2619}
2620
2621static int
NeilBrowna0ad13e2007-01-26 00:57:10 -08002622nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
2623 loff_t offset, u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624{
NeilBrowna0ad13e2007-01-26 00:57:10 -08002625 struct readdir_cd *ccd = ccdv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
2627 int buflen;
Al Viro2ebbc012006-10-19 23:28:58 -07002628 __be32 *p = cd->buffer;
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002629 __be32 *cookiep;
Al Virob37ad282006-10-19 23:28:59 -07002630 __be32 nfserr = nfserr_toosmall;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
2632 /* In nfsv4, "." and ".." never make it onto the wire.. */
2633 if (name && isdotent(name, namlen)) {
2634 cd->common.err = nfs_ok;
2635 return 0;
2636 }
2637
2638 if (cd->offset)
2639 xdr_encode_hyper(cd->offset, (u64) offset);
2640
2641 buflen = cd->buflen - 4 - XDR_QUADLEN(namlen);
2642 if (buflen < 0)
2643 goto fail;
2644
2645 *p++ = xdr_one; /* mark entry present */
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002646 cookiep = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
2648 p = xdr_encode_array(p, name, namlen); /* name length & name */
2649
J. Bruce Fields84822d02012-12-14 17:57:50 -05002650 nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, &p, buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 switch (nfserr) {
2652 case nfs_ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 break;
2654 case nfserr_resource:
2655 nfserr = nfserr_toosmall;
2656 goto fail;
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002657 case nfserr_noent:
2658 goto skip_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 default:
2660 /*
2661 * If the client requested the RDATTR_ERROR attribute,
2662 * we stuff the error code into this attribute
2663 * and continue. If this attribute was not requested,
2664 * then in accordance with the spec, we fail the
2665 * entire READDIR operation(!)
2666 */
2667 if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
2668 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 p = nfsd4_encode_rdattr_error(p, buflen, nfserr);
Fred Isaman34081ef2006-01-18 17:43:40 -08002670 if (p == NULL) {
2671 nfserr = nfserr_toosmall;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 goto fail;
Fred Isaman34081ef2006-01-18 17:43:40 -08002673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 }
2675 cd->buflen -= (p - cd->buffer);
2676 cd->buffer = p;
J. Bruce Fieldsb2c0cea2009-05-05 19:04:29 -04002677 cd->offset = cookiep;
2678skip_entry:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 cd->common.err = nfs_ok;
2680 return 0;
2681fail:
2682 cd->common.err = nfserr;
2683 return -EINVAL;
2684}
2685
Benny Halevye2f282b2008-08-12 20:45:07 +03002686static void
2687nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
2688{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002689 __be32 *p;
Benny Halevye2f282b2008-08-12 20:45:07 +03002690
2691 RESERVE_SPACE(sizeof(stateid_t));
2692 WRITE32(sid->si_generation);
2693 WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
2694 ADJUST_ARGS();
2695}
2696
Benny Halevy695e12f2008-07-04 14:38:33 +03002697static __be32
Al Virob37ad282006-10-19 23:28:59 -07002698nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002700 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
2702 if (!nfserr) {
2703 RESERVE_SPACE(8);
2704 WRITE32(access->ac_supported);
2705 WRITE32(access->ac_resp_access);
2706 ADJUST_ARGS();
2707 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002708 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709}
2710
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04002711static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts)
2712{
2713 __be32 *p;
2714
2715 if (!nfserr) {
2716 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 8);
2717 WRITEMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
2718 WRITE32(bcts->dir);
J. Bruce Fields6e67b5d2012-09-13 09:49:43 -04002719 /* Sorry, we do not yet support RDMA over 4.1: */
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04002720 WRITE32(0);
2721 ADJUST_ARGS();
2722 }
2723 return nfserr;
2724}
2725
Benny Halevy695e12f2008-07-04 14:38:33 +03002726static __be32
Al Virob37ad282006-10-19 23:28:59 -07002727nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Benny Halevye2f282b2008-08-12 20:45:07 +03002729 if (!nfserr)
2730 nfsd4_encode_stateid(resp, &close->cl_stateid);
2731
Benny Halevy695e12f2008-07-04 14:38:33 +03002732 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733}
2734
2735
Benny Halevy695e12f2008-07-04 14:38:33 +03002736static __be32
Al Virob37ad282006-10-19 23:28:59 -07002737nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002739 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740
2741 if (!nfserr) {
Chuck Leverab4684d2012-03-02 17:13:50 -05002742 RESERVE_SPACE(NFS4_VERIFIER_SIZE);
2743 WRITEMEM(commit->co_verf.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 ADJUST_ARGS();
2745 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002746 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747}
2748
Benny Halevy695e12f2008-07-04 14:38:33 +03002749static __be32
Al Virob37ad282006-10-19 23:28:59 -07002750nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754 if (!nfserr) {
2755 RESERVE_SPACE(32);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002756 write_cinfo(&p, &create->cr_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 WRITE32(2);
2758 WRITE32(create->cr_bmval[0]);
2759 WRITE32(create->cr_bmval[1]);
2760 ADJUST_ARGS();
2761 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002762 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763}
2764
Al Virob37ad282006-10-19 23:28:59 -07002765static __be32
2766nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
2768 struct svc_fh *fhp = getattr->ga_fhp;
2769 int buflen;
2770
2771 if (nfserr)
2772 return nfserr;
2773
2774 buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
2775 nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
J. Bruce Fields84822d02012-12-14 17:57:50 -05002776 &resp->p, buflen, getattr->ga_bmval,
Frank Filz406a7ea2007-11-27 11:34:05 -08002777 resp->rqstp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 return nfserr;
2779}
2780
Benny Halevy695e12f2008-07-04 14:38:33 +03002781static __be32
2782nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783{
Benny Halevy695e12f2008-07-04 14:38:33 +03002784 struct svc_fh *fhp = *fhpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 unsigned int len;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
2788 if (!nfserr) {
2789 len = fhp->fh_handle.fh_size;
2790 RESERVE_SPACE(len + 4);
2791 WRITE32(len);
2792 WRITEMEM(&fhp->fh_handle.fh_base, len);
2793 ADJUST_ARGS();
2794 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002795 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796}
2797
2798/*
2799* Including all fields other than the name, a LOCK4denied structure requires
2800* 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
2801*/
2802static void
2803nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld)
2804{
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002805 struct xdr_netobj *conf = &ld->ld_owner;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002806 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002808 RESERVE_SPACE(32 + XDR_LEN(conf->len));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 WRITE64(ld->ld_start);
2810 WRITE64(ld->ld_length);
2811 WRITE32(ld->ld_type);
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002812 if (conf->len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 WRITEMEM(&ld->ld_clientid, 8);
J. Bruce Fields7c13f342011-08-30 22:15:47 -04002814 WRITE32(conf->len);
2815 WRITEMEM(conf->data, conf->len);
2816 kfree(conf->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
2818 WRITE64((u64)0); /* clientid */
2819 WRITE32(0); /* length of owner name */
2820 }
2821 ADJUST_ARGS();
2822}
2823
Benny Halevy695e12f2008-07-04 14:38:33 +03002824static __be32
Al Virob37ad282006-10-19 23:28:59 -07002825nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826{
Benny Halevye2f282b2008-08-12 20:45:07 +03002827 if (!nfserr)
2828 nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
2829 else if (nfserr == nfserr_denied)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 nfsd4_encode_lock_denied(resp, &lock->lk_denied);
2831
Benny Halevy695e12f2008-07-04 14:38:33 +03002832 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833}
2834
Benny Halevy695e12f2008-07-04 14:38:33 +03002835static __be32
Al Virob37ad282006-10-19 23:28:59 -07002836nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837{
2838 if (nfserr == nfserr_denied)
2839 nfsd4_encode_lock_denied(resp, &lockt->lt_denied);
Benny Halevy695e12f2008-07-04 14:38:33 +03002840 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841}
2842
Benny Halevy695e12f2008-07-04 14:38:33 +03002843static __be32
Al Virob37ad282006-10-19 23:28:59 -07002844nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845{
Benny Halevye2f282b2008-08-12 20:45:07 +03002846 if (!nfserr)
2847 nfsd4_encode_stateid(resp, &locku->lu_stateid);
2848
Benny Halevy695e12f2008-07-04 14:38:33 +03002849 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850}
2851
2852
Benny Halevy695e12f2008-07-04 14:38:33 +03002853static __be32
Al Virob37ad282006-10-19 23:28:59 -07002854nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002856 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
2858 if (!nfserr) {
2859 RESERVE_SPACE(20);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002860 write_cinfo(&p, &link->li_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 ADJUST_ARGS();
2862 }
Benny Halevy695e12f2008-07-04 14:38:33 +03002863 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864}
2865
2866
Benny Halevy695e12f2008-07-04 14:38:33 +03002867static __be32
Al Virob37ad282006-10-19 23:28:59 -07002868nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002870 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872 if (nfserr)
2873 goto out;
2874
Benny Halevye2f282b2008-08-12 20:45:07 +03002875 nfsd4_encode_stateid(resp, &open->op_stateid);
2876 RESERVE_SPACE(40);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04002877 write_cinfo(&p, &open->op_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 WRITE32(open->op_rflags);
2879 WRITE32(2);
2880 WRITE32(open->op_bmval[0]);
2881 WRITE32(open->op_bmval[1]);
2882 WRITE32(open->op_delegate_type);
2883 ADJUST_ARGS();
2884
2885 switch (open->op_delegate_type) {
2886 case NFS4_OPEN_DELEGATE_NONE:
2887 break;
2888 case NFS4_OPEN_DELEGATE_READ:
Benny Halevye2f282b2008-08-12 20:45:07 +03002889 nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
2890 RESERVE_SPACE(20);
NeilBrown7b190fe2005-06-23 22:03:23 -07002891 WRITE32(open->op_recall);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
2893 /*
2894 * TODO: ACE's in delegations
2895 */
2896 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
2897 WRITE32(0);
2898 WRITE32(0);
2899 WRITE32(0); /* XXX: is NULL principal ok? */
2900 ADJUST_ARGS();
2901 break;
2902 case NFS4_OPEN_DELEGATE_WRITE:
Benny Halevye2f282b2008-08-12 20:45:07 +03002903 nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
2904 RESERVE_SPACE(32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 WRITE32(0);
2906
2907 /*
2908 * TODO: space_limit's in delegations
2909 */
2910 WRITE32(NFS4_LIMIT_SIZE);
2911 WRITE32(~(u32)0);
2912 WRITE32(~(u32)0);
2913
2914 /*
2915 * TODO: ACE's in delegations
2916 */
2917 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
2918 WRITE32(0);
2919 WRITE32(0);
2920 WRITE32(0); /* XXX: is NULL principal ok? */
2921 ADJUST_ARGS();
2922 break;
Benny Halevyd24433c2012-02-16 20:57:17 +02002923 case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */
2924 switch (open->op_why_no_deleg) {
2925 case WND4_CONTENTION:
2926 case WND4_RESOURCE:
2927 RESERVE_SPACE(8);
2928 WRITE32(open->op_why_no_deleg);
2929 WRITE32(0); /* deleg signaling not supported yet */
2930 break;
2931 default:
2932 RESERVE_SPACE(4);
2933 WRITE32(open->op_why_no_deleg);
2934 }
2935 ADJUST_ARGS();
2936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 default:
2938 BUG();
2939 }
2940 /* XXX save filehandle here */
2941out:
Benny Halevy695e12f2008-07-04 14:38:33 +03002942 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943}
2944
Benny Halevy695e12f2008-07-04 14:38:33 +03002945static __be32
Al Virob37ad282006-10-19 23:28:59 -07002946nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947{
Benny Halevye2f282b2008-08-12 20:45:07 +03002948 if (!nfserr)
2949 nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
Benny Halevy695e12f2008-07-04 14:38:33 +03002951 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952}
2953
Benny Halevy695e12f2008-07-04 14:38:33 +03002954static __be32
Al Virob37ad282006-10-19 23:28:59 -07002955nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956{
Benny Halevye2f282b2008-08-12 20:45:07 +03002957 if (!nfserr)
2958 nfsd4_encode_stateid(resp, &od->od_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
Benny Halevy695e12f2008-07-04 14:38:33 +03002960 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961}
2962
Al Virob37ad282006-10-19 23:28:59 -07002963static __be32
2964nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
NeilBrown44524352006-10-04 02:15:46 -07002965 struct nfsd4_read *read)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966{
2967 u32 eof;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05002968 int v;
2969 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 unsigned long maxcount;
2971 long len;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07002972 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
2974 if (nfserr)
2975 return nfserr;
2976 if (resp->xbuf->page_len)
2977 return nfserr_resource;
2978
2979 RESERVE_SPACE(8); /* eof flag and byte count */
2980
Greg Banks7adae482006-10-04 02:15:47 -07002981 maxcount = svc_max_payload(resp->rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 if (maxcount > read->rd_length)
2983 maxcount = read->rd_length;
2984
2985 len = maxcount;
2986 v = 0;
2987 while (len > 0) {
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05002988 page = *(resp->rqstp->rq_next_page);
2989 if (!page) { /* ran out of pages */
J. Bruce Fieldsd5f50b02012-12-04 18:25:10 -05002990 maxcount -= len;
2991 break;
2992 }
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05002993 resp->rqstp->rq_vec[v].iov_base = page_address(page);
NeilBrown3cc03b12006-10-04 02:15:47 -07002994 resp->rqstp->rq_vec[v].iov_len =
NeilBrown44524352006-10-04 02:15:46 -07002995 len < PAGE_SIZE ? len : PAGE_SIZE;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05002996 resp->rqstp->rq_next_page++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 v++;
2998 len -= PAGE_SIZE;
2999 }
3000 read->rd_vlen = v;
3001
J. Bruce Fields039a87c2010-07-30 11:33:32 -04003002 nfserr = nfsd_read_file(read->rd_rqstp, read->rd_fhp, read->rd_filp,
NeilBrown3cc03b12006-10-04 02:15:47 -07003003 read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 &maxcount);
3005
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 if (nfserr)
3007 return nfserr;
NeilBrown44524352006-10-04 02:15:46 -07003008 eof = (read->rd_offset + maxcount >=
3009 read->rd_fhp->fh_dentry->d_inode->i_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
3011 WRITE32(eof);
3012 WRITE32(maxcount);
3013 ADJUST_ARGS();
NeilBrown6ed6dec2006-04-10 22:55:32 -07003014 resp->xbuf->head[0].iov_len = (char*)p
3015 - (char*)resp->xbuf->head[0].iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 resp->xbuf->page_len = maxcount;
3017
NeilBrown6ed6dec2006-04-10 22:55:32 -07003018 /* Use rest of head for padding and remaining ops: */
NeilBrown6ed6dec2006-04-10 22:55:32 -07003019 resp->xbuf->tail[0].iov_base = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 resp->xbuf->tail[0].iov_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 if (maxcount&3) {
NeilBrown6ed6dec2006-04-10 22:55:32 -07003022 RESERVE_SPACE(4);
3023 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 resp->xbuf->tail[0].iov_base += maxcount&3;
3025 resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
NeilBrown6ed6dec2006-04-10 22:55:32 -07003026 ADJUST_ARGS();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 }
3028 return 0;
3029}
3030
Al Virob37ad282006-10-19 23:28:59 -07003031static __be32
3032nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
3034 int maxcount;
3035 char *page;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037
3038 if (nfserr)
3039 return nfserr;
3040 if (resp->xbuf->page_len)
3041 return nfserr_resource;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003042 if (!*resp->rqstp->rq_next_page)
J. Bruce Fieldsd5f50b02012-12-04 18:25:10 -05003043 return nfserr_resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003045 page = page_address(*(resp->rqstp->rq_next_page++));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
3047 maxcount = PAGE_SIZE;
3048 RESERVE_SPACE(4);
3049
3050 /*
3051 * XXX: By default, the ->readlink() VFS op will truncate symlinks
3052 * if they would overflow the buffer. Is this kosher in NFSv4? If
3053 * not, one easy fix is: if ->readlink() precisely fills the buffer,
3054 * assume that truncation occurred, and return NFS4ERR_RESOURCE.
3055 */
3056 nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
3057 if (nfserr == nfserr_isdir)
3058 return nfserr_inval;
3059 if (nfserr)
3060 return nfserr;
3061
3062 WRITE32(maxcount);
3063 ADJUST_ARGS();
NeilBrown6ed6dec2006-04-10 22:55:32 -07003064 resp->xbuf->head[0].iov_len = (char*)p
3065 - (char*)resp->xbuf->head[0].iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 resp->xbuf->page_len = maxcount;
NeilBrown6ed6dec2006-04-10 22:55:32 -07003067
3068 /* Use rest of head for padding and remaining ops: */
NeilBrown6ed6dec2006-04-10 22:55:32 -07003069 resp->xbuf->tail[0].iov_base = p;
3070 resp->xbuf->tail[0].iov_len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 if (maxcount&3) {
NeilBrown6ed6dec2006-04-10 22:55:32 -07003072 RESERVE_SPACE(4);
3073 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 resp->xbuf->tail[0].iov_base += maxcount&3;
3075 resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
NeilBrown6ed6dec2006-04-10 22:55:32 -07003076 ADJUST_ARGS();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 }
3078 return 0;
3079}
3080
Al Virob37ad282006-10-19 23:28:59 -07003081static __be32
3082nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083{
3084 int maxcount;
3085 loff_t offset;
Al Viro2ebbc012006-10-19 23:28:58 -07003086 __be32 *page, *savep, *tailbase;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
3089 if (nfserr)
3090 return nfserr;
3091 if (resp->xbuf->page_len)
3092 return nfserr_resource;
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003093 if (!*resp->rqstp->rq_next_page)
J. Bruce Fieldsd5f50b02012-12-04 18:25:10 -05003094 return nfserr_resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095
Chuck Leverab4684d2012-03-02 17:13:50 -05003096 RESERVE_SPACE(NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 savep = p;
3098
3099 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
3100 WRITE32(0);
3101 WRITE32(0);
3102 ADJUST_ARGS();
3103 resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base;
NeilBrownbb6e8a92006-04-10 22:55:33 -07003104 tailbase = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105
3106 maxcount = PAGE_SIZE;
3107 if (maxcount > readdir->rd_maxcount)
3108 maxcount = readdir->rd_maxcount;
3109
3110 /*
3111 * Convert from bytes to words, account for the two words already
3112 * written, make sure to leave two words at the end for the next
3113 * pointer and eof field.
3114 */
3115 maxcount = (maxcount >> 2) - 4;
3116 if (maxcount < 0) {
3117 nfserr = nfserr_toosmall;
3118 goto err_no_verf;
3119 }
3120
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003121 page = page_address(*(resp->rqstp->rq_next_page++));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 readdir->common.err = 0;
3123 readdir->buflen = maxcount;
3124 readdir->buffer = page;
3125 readdir->offset = NULL;
3126
3127 offset = readdir->rd_cookie;
3128 nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
3129 &offset,
3130 &readdir->common, nfsd4_encode_dirent);
3131 if (nfserr == nfs_ok &&
3132 readdir->common.err == nfserr_toosmall &&
3133 readdir->buffer == page)
3134 nfserr = nfserr_toosmall;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 if (nfserr)
3136 goto err_no_verf;
3137
3138 if (readdir->offset)
3139 xdr_encode_hyper(readdir->offset, offset);
3140
3141 p = readdir->buffer;
3142 *p++ = 0; /* no more entries */
3143 *p++ = htonl(readdir->common.err == nfserr_eof);
J. Bruce Fieldsafc59402012-12-10 18:01:37 -05003144 resp->xbuf->page_len = ((char*)p) -
3145 (char*)page_address(*(resp->rqstp->rq_next_page-1));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
NeilBrownbb6e8a92006-04-10 22:55:33 -07003147 /* Use rest of head for padding and remaining ops: */
NeilBrownbb6e8a92006-04-10 22:55:33 -07003148 resp->xbuf->tail[0].iov_base = tailbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 resp->xbuf->tail[0].iov_len = 0;
3150 resp->p = resp->xbuf->tail[0].iov_base;
NeilBrownbb6e8a92006-04-10 22:55:33 -07003151 resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
3153 return 0;
3154err_no_verf:
3155 p = savep;
3156 ADJUST_ARGS();
3157 return nfserr;
3158}
3159
Benny Halevy695e12f2008-07-04 14:38:33 +03003160static __be32
Al Virob37ad282006-10-19 23:28:59 -07003161nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003163 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 if (!nfserr) {
3166 RESERVE_SPACE(20);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04003167 write_cinfo(&p, &remove->rm_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 ADJUST_ARGS();
3169 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003170 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171}
3172
Benny Halevy695e12f2008-07-04 14:38:33 +03003173static __be32
Al Virob37ad282006-10-19 23:28:59 -07003174nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
3178 if (!nfserr) {
3179 RESERVE_SPACE(40);
J. Bruce Fieldsc654b8a2009-04-16 17:33:25 -04003180 write_cinfo(&p, &rename->rn_sinfo);
3181 write_cinfo(&p, &rename->rn_tinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 ADJUST_ARGS();
3183 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003184 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185}
3186
Benny Halevy695e12f2008-07-04 14:38:33 +03003187static __be32
Mi Jinlong22b6dee2010-12-27 14:29:57 +08003188nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp,
Chuck Levera77c8062013-03-16 15:55:10 -04003189 __be32 nfserr, struct svc_export *exp)
Andy Adamsondcb488a32007-07-17 04:04:51 -07003190{
Chuck Lever676e4eb2013-04-30 18:48:54 -04003191 u32 i, nflavs, supported;
J. Bruce Fields4796f452007-07-17 04:04:51 -07003192 struct exp_flavor_info *flavs;
3193 struct exp_flavor_info def_flavs[2];
Chuck Lever676e4eb2013-04-30 18:48:54 -04003194 __be32 *p, *flavorsp;
3195 static bool report = true;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003196
3197 if (nfserr)
3198 goto out;
J. Bruce Fields4796f452007-07-17 04:04:51 -07003199 if (exp->ex_nflavors) {
3200 flavs = exp->ex_flavors;
3201 nflavs = exp->ex_nflavors;
3202 } else { /* Handling of some defaults in absence of real secinfo: */
3203 flavs = def_flavs;
3204 if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
3205 nflavs = 2;
3206 flavs[0].pseudoflavor = RPC_AUTH_UNIX;
3207 flavs[1].pseudoflavor = RPC_AUTH_NULL;
3208 } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
3209 nflavs = 1;
3210 flavs[0].pseudoflavor
3211 = svcauth_gss_flavor(exp->ex_client);
3212 } else {
3213 nflavs = 1;
3214 flavs[0].pseudoflavor
3215 = exp->ex_client->flavour->flavour;
3216 }
3217 }
3218
Chuck Lever676e4eb2013-04-30 18:48:54 -04003219 supported = 0;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003220 RESERVE_SPACE(4);
Chuck Lever676e4eb2013-04-30 18:48:54 -04003221 flavorsp = p++; /* to be backfilled later */
Andy Adamsondcb488a32007-07-17 04:04:51 -07003222 ADJUST_ARGS();
Chuck Lever676e4eb2013-04-30 18:48:54 -04003223
J. Bruce Fields4796f452007-07-17 04:04:51 -07003224 for (i = 0; i < nflavs; i++) {
Chuck Lever676e4eb2013-04-30 18:48:54 -04003225 rpc_authflavor_t pf = flavs[i].pseudoflavor;
Chuck Levera77c8062013-03-16 15:55:10 -04003226 struct rpcsec_gss_info info;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003227
Chuck Lever676e4eb2013-04-30 18:48:54 -04003228 if (rpcauth_get_gssinfo(pf, &info) == 0) {
3229 supported++;
Chuck Levered9411a2013-04-30 18:48:45 -04003230 RESERVE_SPACE(4 + 4 + info.oid.len + 4 + 4);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003231 WRITE32(RPC_AUTH_GSS);
Chuck Levera77c8062013-03-16 15:55:10 -04003232 WRITE32(info.oid.len);
3233 WRITEMEM(info.oid.data, info.oid.len);
Chuck Levera77c8062013-03-16 15:55:10 -04003234 WRITE32(info.qop);
Chuck Levera77c8062013-03-16 15:55:10 -04003235 WRITE32(info.service);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003236 ADJUST_ARGS();
Chuck Lever676e4eb2013-04-30 18:48:54 -04003237 } else if (pf < RPC_AUTH_MAXFLAVOR) {
3238 supported++;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003239 RESERVE_SPACE(4);
Chuck Lever676e4eb2013-04-30 18:48:54 -04003240 WRITE32(pf);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003241 ADJUST_ARGS();
Chuck Lever676e4eb2013-04-30 18:48:54 -04003242 } else {
3243 if (report)
3244 pr_warn("NFS: SECINFO: security flavor %u "
3245 "is not supported\n", pf);
Andy Adamsondcb488a32007-07-17 04:04:51 -07003246 }
3247 }
Chuck Levera77c8062013-03-16 15:55:10 -04003248
Chuck Lever676e4eb2013-04-30 18:48:54 -04003249 if (nflavs != supported)
3250 report = false;
3251 *flavorsp = htonl(supported);
3252
Andy Adamsondcb488a32007-07-17 04:04:51 -07003253out:
3254 if (exp)
3255 exp_put(exp);
Benny Halevy695e12f2008-07-04 14:38:33 +03003256 return nfserr;
Andy Adamsondcb488a32007-07-17 04:04:51 -07003257}
3258
Mi Jinlong22b6dee2010-12-27 14:29:57 +08003259static __be32
3260nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
3261 struct nfsd4_secinfo *secinfo)
3262{
3263 return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->si_exp);
3264}
3265
3266static __be32
3267nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
3268 struct nfsd4_secinfo_no_name *secinfo)
3269{
3270 return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->sin_exp);
3271}
3272
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273/*
3274 * The SETATTR encode routine is special -- it always encodes a bitmap,
3275 * regardless of the error status.
3276 */
Benny Halevy695e12f2008-07-04 14:38:33 +03003277static __be32
Al Virob37ad282006-10-19 23:28:59 -07003278nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
David Quigley18032ca2013-05-02 13:19:10 -04003282 RESERVE_SPACE(16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 if (nfserr) {
David Quigley18032ca2013-05-02 13:19:10 -04003284 WRITE32(3);
3285 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 WRITE32(0);
3287 WRITE32(0);
3288 }
3289 else {
David Quigley18032ca2013-05-02 13:19:10 -04003290 WRITE32(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 WRITE32(setattr->sa_bmval[0]);
3292 WRITE32(setattr->sa_bmval[1]);
David Quigley18032ca2013-05-02 13:19:10 -04003293 WRITE32(setattr->sa_bmval[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 }
3295 ADJUST_ARGS();
Benny Halevy695e12f2008-07-04 14:38:33 +03003296 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297}
3298
Benny Halevy695e12f2008-07-04 14:38:33 +03003299static __be32
Al Virob37ad282006-10-19 23:28:59 -07003300nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
3304 if (!nfserr) {
Chuck Leverab4684d2012-03-02 17:13:50 -05003305 RESERVE_SPACE(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 WRITEMEM(&scd->se_clientid, 8);
Chuck Leverab4684d2012-03-02 17:13:50 -05003307 WRITEMEM(&scd->se_confirm, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 ADJUST_ARGS();
3309 }
3310 else if (nfserr == nfserr_clid_inuse) {
3311 RESERVE_SPACE(8);
3312 WRITE32(0);
3313 WRITE32(0);
3314 ADJUST_ARGS();
3315 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003316 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317}
3318
Benny Halevy695e12f2008-07-04 14:38:33 +03003319static __be32
Al Virob37ad282006-10-19 23:28:59 -07003320nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
3324 if (!nfserr) {
3325 RESERVE_SPACE(16);
3326 WRITE32(write->wr_bytes_written);
3327 WRITE32(write->wr_how_written);
Chuck Leverab4684d2012-03-02 17:13:50 -05003328 WRITEMEM(write->wr_verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 ADJUST_ARGS();
3330 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003331 return nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332}
3333
J. Bruce Fields57266a62013-04-13 14:27:29 -04003334static const u32 nfs4_minimal_spo_must_enforce[2] = {
3335 [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) |
3336 1 << (OP_EXCHANGE_ID - 32) |
3337 1 << (OP_CREATE_SESSION - 32) |
3338 1 << (OP_DESTROY_SESSION - 32) |
3339 1 << (OP_DESTROY_CLIENTID - 32)
3340};
3341
Benny Halevy695e12f2008-07-04 14:38:33 +03003342static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003343nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003344 struct nfsd4_exchange_id *exid)
3345{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003346 __be32 *p;
Andy Adamson0733d212009-04-03 08:28:01 +03003347 char *major_id;
3348 char *server_scope;
3349 int major_id_sz;
3350 int server_scope_sz;
3351 uint64_t minor_id = 0;
3352
3353 if (nfserr)
3354 return nfserr;
3355
3356 major_id = utsname()->nodename;
3357 major_id_sz = strlen(major_id);
3358 server_scope = utsname()->nodename;
3359 server_scope_sz = strlen(server_scope);
3360
3361 RESERVE_SPACE(
3362 8 /* eir_clientid */ +
3363 4 /* eir_sequenceid */ +
3364 4 /* eir_flags */ +
Weston Andros Adamson58cd57b2013-08-05 15:47:07 -04003365 4 /* spr_how */ +
3366 8 /* spo_must_enforce, spo_must_allow */ +
Andy Adamson0733d212009-04-03 08:28:01 +03003367 8 /* so_minor_id */ +
3368 4 /* so_major_id.len */ +
3369 (XDR_QUADLEN(major_id_sz) * 4) +
3370 4 /* eir_server_scope.len */ +
3371 (XDR_QUADLEN(server_scope_sz) * 4) +
3372 4 /* eir_server_impl_id.count (0) */);
3373
3374 WRITEMEM(&exid->clientid, 8);
3375 WRITE32(exid->seqid);
3376 WRITE32(exid->flags);
3377
Andy Adamson0733d212009-04-03 08:28:01 +03003378 WRITE32(exid->spa_how);
J. Bruce Fields57266a62013-04-13 14:27:29 -04003379 switch (exid->spa_how) {
3380 case SP4_NONE:
3381 break;
3382 case SP4_MACH_CRED:
3383 /* spo_must_enforce bitmap: */
3384 WRITE32(2);
3385 WRITE32(nfs4_minimal_spo_must_enforce[0]);
3386 WRITE32(nfs4_minimal_spo_must_enforce[1]);
3387 /* empty spo_must_allow bitmap: */
3388 WRITE32(0);
3389 break;
3390 default:
3391 WARN_ON_ONCE(1);
3392 }
Andy Adamson0733d212009-04-03 08:28:01 +03003393
3394 /* The server_owner struct */
3395 WRITE64(minor_id); /* Minor id */
3396 /* major id */
3397 WRITE32(major_id_sz);
3398 WRITEMEM(major_id, major_id_sz);
3399
3400 /* Server scope */
3401 WRITE32(server_scope_sz);
3402 WRITEMEM(server_scope, server_scope_sz);
3403
3404 /* Implementation id */
3405 WRITE32(0); /* zero length nfs_impl_id4 array */
3406 ADJUST_ARGS();
3407 return 0;
Andy Adamson2db134e2009-04-03 08:27:55 +03003408}
3409
3410static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003411nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003412 struct nfsd4_create_session *sess)
3413{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003414 __be32 *p;
Andy Adamsonec6b5d72009-04-03 08:28:28 +03003415
3416 if (nfserr)
3417 return nfserr;
3418
3419 RESERVE_SPACE(24);
3420 WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN);
3421 WRITE32(sess->seqid);
3422 WRITE32(sess->flags);
3423 ADJUST_ARGS();
3424
3425 RESERVE_SPACE(28);
3426 WRITE32(0); /* headerpadsz */
3427 WRITE32(sess->fore_channel.maxreq_sz);
3428 WRITE32(sess->fore_channel.maxresp_sz);
3429 WRITE32(sess->fore_channel.maxresp_cached);
3430 WRITE32(sess->fore_channel.maxops);
3431 WRITE32(sess->fore_channel.maxreqs);
3432 WRITE32(sess->fore_channel.nr_rdma_attrs);
3433 ADJUST_ARGS();
3434
3435 if (sess->fore_channel.nr_rdma_attrs) {
3436 RESERVE_SPACE(4);
3437 WRITE32(sess->fore_channel.rdma_attrs);
3438 ADJUST_ARGS();
3439 }
3440
3441 RESERVE_SPACE(28);
3442 WRITE32(0); /* headerpadsz */
3443 WRITE32(sess->back_channel.maxreq_sz);
3444 WRITE32(sess->back_channel.maxresp_sz);
3445 WRITE32(sess->back_channel.maxresp_cached);
3446 WRITE32(sess->back_channel.maxops);
3447 WRITE32(sess->back_channel.maxreqs);
3448 WRITE32(sess->back_channel.nr_rdma_attrs);
3449 ADJUST_ARGS();
3450
3451 if (sess->back_channel.nr_rdma_attrs) {
3452 RESERVE_SPACE(4);
3453 WRITE32(sess->back_channel.rdma_attrs);
3454 ADJUST_ARGS();
3455 }
3456 return 0;
Andy Adamson2db134e2009-04-03 08:27:55 +03003457}
3458
3459static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003460nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003461 struct nfsd4_destroy_session *destroy_session)
3462{
Andy Adamson2db134e2009-04-03 08:27:55 +03003463 return nfserr;
3464}
3465
Daniel Mackc47d8322011-05-16 16:38:14 +02003466static __be32
J. Bruce Fieldsd1829b32012-04-25 18:04:54 -04003467nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003468 struct nfsd4_free_stateid *free_stateid)
3469{
3470 __be32 *p;
3471
3472 if (nfserr)
3473 return nfserr;
3474
3475 RESERVE_SPACE(4);
J. Bruce Fieldsd1829b32012-04-25 18:04:54 -04003476 *p++ = nfserr;
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003477 ADJUST_ARGS();
3478 return nfserr;
3479}
3480
3481static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003482nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
Andy Adamson2db134e2009-04-03 08:27:55 +03003483 struct nfsd4_sequence *seq)
3484{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003485 __be32 *p;
Benny Halevyb85d4c02009-04-03 08:28:08 +03003486
3487 if (nfserr)
3488 return nfserr;
3489
3490 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20);
3491 WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
3492 WRITE32(seq->seqid);
3493 WRITE32(seq->slotid);
J. Bruce Fieldsb7d7ca32011-08-31 15:39:30 -04003494 /* Note slotid's are numbered from zero: */
3495 WRITE32(seq->maxslots - 1); /* sr_highest_slotid */
3496 WRITE32(seq->maxslots - 1); /* sr_target_highest_slotid */
J. Bruce Fields0d7bb712010-11-18 08:30:33 -05003497 WRITE32(seq->status_flags);
Benny Halevyb85d4c02009-04-03 08:28:08 +03003498
3499 ADJUST_ARGS();
Andy Adamson557ce262009-08-28 08:45:04 -04003500 resp->cstate.datap = p; /* DRC cache data pointer */
Benny Halevyb85d4c02009-04-03 08:28:08 +03003501 return 0;
Andy Adamson2db134e2009-04-03 08:27:55 +03003502}
3503
J. Bruce Fields2355c592012-04-25 16:56:22 -04003504static __be32
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003505nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
Bryan Schumaker17456802011-07-13 10:50:48 -04003506 struct nfsd4_test_stateid *test_stateid)
3507{
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003508 struct nfsd4_test_stateid_id *stateid, *next;
Bryan Schumaker17456802011-07-13 10:50:48 -04003509 __be32 *p;
Bryan Schumaker17456802011-07-13 10:50:48 -04003510
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003511 RESERVE_SPACE(4 + (4 * test_stateid->ts_num_ids));
Bryan Schumaker17456802011-07-13 10:50:48 -04003512 *p++ = htonl(test_stateid->ts_num_ids);
Bryan Schumaker17456802011-07-13 10:50:48 -04003513
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003514 list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
Al Viro02f5fde2012-04-13 00:10:34 -04003515 *p++ = stateid->ts_id_status;
Bryan Schumaker17456802011-07-13 10:50:48 -04003516 }
Bryan Schumaker17456802011-07-13 10:50:48 -04003517
Bryan Schumaker03cfb422012-01-27 10:22:49 -05003518 ADJUST_ARGS();
Bryan Schumaker17456802011-07-13 10:50:48 -04003519 return nfserr;
3520}
3521
Andy Adamson2db134e2009-04-03 08:27:55 +03003522static __be32
Benny Halevy695e12f2008-07-04 14:38:33 +03003523nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p)
3524{
3525 return nfserr;
3526}
3527
3528typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *);
3529
Andy Adamson2db134e2009-04-03 08:27:55 +03003530/*
3531 * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
3532 * since we don't need to filter out obsolete ops as this is
3533 * done in the decoding phase.
3534 */
Benny Halevy695e12f2008-07-04 14:38:33 +03003535static nfsd4_enc nfsd4_enc_ops[] = {
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04003536 [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access,
3537 [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close,
3538 [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit,
3539 [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create,
3540 [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop,
3541 [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop,
3542 [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr,
3543 [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh,
3544 [OP_LINK] = (nfsd4_enc)nfsd4_encode_link,
3545 [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock,
3546 [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt,
3547 [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku,
3548 [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop,
3549 [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop,
3550 [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop,
3551 [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open,
Benny Halevy84f09f42009-03-04 23:05:35 +02003552 [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop,
J. Bruce Fieldsad1060c2008-07-18 15:04:16 -04003553 [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm,
3554 [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade,
3555 [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop,
3556 [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop,
3557 [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop,
3558 [OP_READ] = (nfsd4_enc)nfsd4_encode_read,
3559 [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir,
3560 [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink,
3561 [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove,
3562 [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename,
3563 [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop,
3564 [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop,
3565 [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop,
3566 [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo,
3567 [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr,
3568 [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid,
3569 [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop,
3570 [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop,
3571 [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write,
3572 [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop,
Andy Adamson2db134e2009-04-03 08:27:55 +03003573
3574 /* NFSv4.1 operations */
3575 [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop,
J. Bruce Fields1d1bc8f2010-10-04 23:12:59 -04003576 [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session,
Andy Adamson2db134e2009-04-03 08:27:55 +03003577 [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id,
3578 [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session,
3579 [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session,
Bryan Schumakere1ca12d2011-07-13 11:04:21 -04003580 [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid,
Andy Adamson2db134e2009-04-03 08:27:55 +03003581 [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
3582 [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop,
3583 [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
3584 [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop,
3585 [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop,
3586 [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop,
Mi Jinlong22b6dee2010-12-27 14:29:57 +08003587 [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name,
Andy Adamson2db134e2009-04-03 08:27:55 +03003588 [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence,
3589 [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop,
Bryan Schumaker17456802011-07-13 10:50:48 -04003590 [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid,
Andy Adamson2db134e2009-04-03 08:27:55 +03003591 [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
3592 [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop,
3593 [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop,
Benny Halevy695e12f2008-07-04 14:38:33 +03003594};
3595
Andy Adamson496c2622009-04-03 08:28:48 +03003596/*
3597 * Calculate the total amount of memory that the compound response has taken
Mi Jinlong58e7b332011-08-28 18:18:56 +08003598 * after encoding the current operation with pad.
Andy Adamson496c2622009-04-03 08:28:48 +03003599 *
Mi Jinlong58e7b332011-08-28 18:18:56 +08003600 * pad: if operation is non-idempotent, pad was calculate by op_rsize_bop()
3601 * which was specified at nfsd4_operation, else pad is zero.
Andy Adamson496c2622009-04-03 08:28:48 +03003602 *
Mi Jinlong58e7b332011-08-28 18:18:56 +08003603 * Compare this length to the session se_fmaxresp_sz and se_fmaxresp_cached.
Andy Adamson496c2622009-04-03 08:28:48 +03003604 *
3605 * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
3606 * will be at least a page and will therefore hold the xdr_buf head.
3607 */
J. Bruce Fields57b7b432012-04-25 17:58:50 -04003608__be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
Andy Adamson496c2622009-04-03 08:28:48 +03003609{
Andy Adamson496c2622009-04-03 08:28:48 +03003610 struct xdr_buf *xb = &resp->rqstp->rq_res;
Andy Adamson496c2622009-04-03 08:28:48 +03003611 struct nfsd4_session *session = NULL;
3612 struct nfsd4_slot *slot = resp->cstate.slot;
Mi Jinlong58e7b332011-08-28 18:18:56 +08003613 u32 length, tlen = 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003614
3615 if (!nfsd4_has_session(&resp->cstate))
Mi Jinlong58e7b332011-08-28 18:18:56 +08003616 return 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003617
3618 session = resp->cstate.session;
Mi Jinlong58e7b332011-08-28 18:18:56 +08003619 if (session == NULL)
3620 return 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003621
3622 if (xb->page_len == 0) {
3623 length = (char *)resp->p - (char *)xb->head[0].iov_base + pad;
3624 } else {
3625 if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
3626 tlen = (char *)resp->p - (char *)xb->tail[0].iov_base;
3627
3628 length = xb->head[0].iov_len + xb->page_len + tlen + pad;
3629 }
3630 dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
3631 length, xb->page_len, tlen, pad);
3632
Mi Jinlong58e7b332011-08-28 18:18:56 +08003633 if (length > session->se_fchannel.maxresp_sz)
3634 return nfserr_rep_too_big;
3635
J. Bruce Fields73e79482012-02-13 16:39:00 -05003636 if ((slot->sl_flags & NFSD4_SLOT_CACHETHIS) &&
Mi Jinlong58e7b332011-08-28 18:18:56 +08003637 length > session->se_fchannel.maxresp_cached)
Andy Adamson496c2622009-04-03 08:28:48 +03003638 return nfserr_rep_too_big_to_cache;
Mi Jinlong58e7b332011-08-28 18:18:56 +08003639
3640 return 0;
Andy Adamson496c2622009-04-03 08:28:48 +03003641}
3642
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643void
3644nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3645{
J. Bruce Fields9411b1d2013-04-01 16:37:12 -04003646 struct nfs4_stateowner *so = resp->cstate.replay_owner;
Al Viro2ebbc012006-10-19 23:28:58 -07003647 __be32 *statp;
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003648 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649
3650 RESERVE_SPACE(8);
3651 WRITE32(op->opnum);
3652 statp = p++; /* to be backfilled at the end */
3653 ADJUST_ARGS();
3654
Benny Halevy695e12f2008-07-04 14:38:33 +03003655 if (op->opnum == OP_ILLEGAL)
3656 goto status;
3657 BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
3658 !nfsd4_enc_ops[op->opnum]);
3659 op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u);
Andy Adamson496c2622009-04-03 08:28:48 +03003660 /* nfsd4_check_drc_limit guarantees enough room for error status */
Mi Jinlong58e7b332011-08-28 18:18:56 +08003661 if (!op->status)
3662 op->status = nfsd4_check_resp_size(resp, 0);
J. Bruce Fields9411b1d2013-04-01 16:37:12 -04003663 if (so) {
3664 so->so_replay.rp_status = op->status;
3665 so->so_replay.rp_buflen = (char *)resp->p - (char *)(statp+1);
3666 memcpy(so->so_replay.rp_buf, statp+1, so->so_replay.rp_buflen);
3667 }
Benny Halevy695e12f2008-07-04 14:38:33 +03003668status:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 /*
3670 * Note: We write the status directly, instead of using WRITE32(),
3671 * since it is already in network byte order.
3672 */
3673 *statp = op->status;
3674}
3675
3676/*
3677 * Encode the reply stored in the stateowner reply cache
3678 *
3679 * XDR note: do not encode rp->rp_buflen: the buffer contains the
3680 * previously sent already encoded operation.
3681 *
3682 * called with nfs4_lock_state() held
3683 */
3684void
3685nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3686{
J. Bruce Fieldsbc749ca2009-04-07 16:55:27 -07003687 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 struct nfs4_replay *rp = op->replay;
3689
3690 BUG_ON(!rp);
3691
3692 RESERVE_SPACE(8);
3693 WRITE32(op->opnum);
3694 *p++ = rp->rp_status; /* already xdr'ed */
3695 ADJUST_ARGS();
3696
3697 RESERVE_SPACE(rp->rp_buflen);
3698 WRITEMEM(rp->rp_buf, rp->rp_buflen);
3699 ADJUST_ARGS();
3700}
3701
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702int
Al Viro2ebbc012006-10-19 23:28:58 -07003703nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704{
3705 return xdr_ressize_check(rqstp, p);
3706}
3707
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003708int nfsd4_release_compoundargs(void *rq, __be32 *p, void *resp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709{
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003710 struct svc_rqst *rqstp = rq;
3711 struct nfsd4_compoundargs *args = rqstp->rq_argp;
3712
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 if (args->ops != args->iops) {
3714 kfree(args->ops);
3715 args->ops = args->iops;
3716 }
Jesper Juhlf99d49a2005-11-07 01:01:34 -08003717 kfree(args->tmpp);
3718 args->tmpp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 while (args->to_free) {
3720 struct tmpbuf *tb = args->to_free;
3721 args->to_free = tb->next;
3722 tb->release(tb->buf);
3723 kfree(tb);
3724 }
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003725 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726}
3727
3728int
Al Viro2ebbc012006-10-19 23:28:58 -07003729nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 args->p = p;
3732 args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len;
3733 args->pagelist = rqstp->rq_arg.pages;
3734 args->pagelen = rqstp->rq_arg.page_len;
3735 args->tmpp = NULL;
3736 args->to_free = NULL;
3737 args->ops = args->iops;
3738 args->rqstp = rqstp;
3739
J. Bruce Fields3e98abf2011-07-16 17:15:10 -04003740 return !nfsd4_decode_compound(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741}
3742
3743int
Al Viro2ebbc012006-10-19 23:28:58 -07003744nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundres *resp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745{
3746 /*
3747 * All that remains is to write the tag and operation count...
3748 */
Andy Adamson557ce262009-08-28 08:45:04 -04003749 struct nfsd4_compound_state *cs = &resp->cstate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 struct kvec *iov;
3751 p = resp->tagp;
3752 *p++ = htonl(resp->taglen);
3753 memcpy(p, resp->tag, resp->taglen);
3754 p += XDR_QUADLEN(resp->taglen);
3755 *p++ = htonl(resp->opcnt);
3756
3757 if (rqstp->rq_res.page_len)
3758 iov = &rqstp->rq_res.tail[0];
3759 else
3760 iov = &rqstp->rq_res.head[0];
3761 iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
3762 BUG_ON(iov->iov_len > PAGE_SIZE);
J. Bruce Fields26c0c752010-04-24 15:35:43 -04003763 if (nfsd4_has_session(cs)) {
J. Bruce Fieldsf0f51f52013-06-18 14:26:02 -04003764 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
3765 struct nfs4_client *clp = cs->session->se_client;
J. Bruce Fields26c0c752010-04-24 15:35:43 -04003766 if (cs->status != nfserr_replay_cache) {
3767 nfsd4_store_cache_entry(resp);
J. Bruce Fields73e79482012-02-13 16:39:00 -05003768 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE;
J. Bruce Fields26c0c752010-04-24 15:35:43 -04003769 }
Benny Halevyd7682982010-05-12 00:13:54 +03003770 /* Renew the clientid on success and on replay */
J. Bruce Fieldsf0f51f52013-06-18 14:26:02 -04003771 spin_lock(&nn->client_lock);
J. Bruce Fields221a6872013-04-01 22:23:49 -04003772 nfsd4_put_session(cs->session);
J. Bruce Fieldsf0f51f52013-06-18 14:26:02 -04003773 spin_unlock(&nn->client_lock);
3774 put_client_renew(clp);
Andy Adamsonda3846a2009-04-03 08:28:22 +03003775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 return 1;
3777}
3778
3779/*
3780 * Local variables:
3781 * c-basic-offset: 8
3782 * End:
3783 */