summaryrefslogtreecommitdiff
path: root/fs/nfsd/nfsproc.c
blob: 1f74008bc06ad8c87675841baed4e0b89fbe9183 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
// SPDX-License-Identifier: GPL-2.0
/*
 * Process version 2 NFS requests.
 *
 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
 */

#include <linux/namei.h>
#include <linux/sunrpc/svc.h>

#include "nfs2xdr_gen.h"

#include "auth.h"
#include "nfsd.h"
#include "cache.h"
#include "xdr.h"
#include "vfs.h"
#include "nfserr.h"
#include "trace.h"

#define NFSDDBG_FACILITY		NFSDDBG_PROC

/*
 * Wrapper structures combine xdrgen types with legacy structures.
 * The xdrgen field must be first so the structure can be cast
 * to its XDR type for the RPC dispatch layer.
 */

struct fhandle_wrapper {
	fhandle			xdrgen;
	struct svc_fh		fh;
};

static_assert(offsetof(struct fhandle_wrapper, xdrgen) == 0);

struct attrstat_wrapper {
	struct attrstat		xdrgen;
	struct kstat		stat;
};

static_assert(offsetof(struct attrstat_wrapper, xdrgen) == 0);

struct sattrargs_wrapper {
	struct sattrargs	xdrgen;
	struct svc_fh		fh;
	struct iattr		iattrs;
};

static_assert(offsetof(struct sattrargs_wrapper, xdrgen) == 0);

struct diropargs_wrapper {
	struct diropargs	xdrgen;
	struct svc_fh		fh;
};

static_assert(offsetof(struct diropargs_wrapper, xdrgen) == 0);

struct diropres_wrapper {
	struct diropres		xdrgen;
	struct svc_fh		fh;
	struct kstat		stat;
};

static_assert(offsetof(struct diropres_wrapper, xdrgen) == 0);

struct createargs_wrapper {
	struct createargs	xdrgen;
	struct svc_fh		fh;
	struct iattr		iattrs;
};

static_assert(offsetof(struct createargs_wrapper, xdrgen) == 0);

struct readargs_wrapper {
	struct readargs		xdrgen;
	struct svc_fh		fh;
};

static_assert(offsetof(struct readargs_wrapper, xdrgen) == 0);

struct writeargs_wrapper {
	struct writeargs	xdrgen;
	struct svc_fh		fh;
};

static_assert(offsetof(struct writeargs_wrapper, xdrgen) == 0);

struct renameargs_wrapper {
	struct renameargs	xdrgen;
	struct svc_fh		ffh;
	struct svc_fh		tfh;
};

static_assert(offsetof(struct renameargs_wrapper, xdrgen) == 0);

struct linkargs_wrapper {
	struct linkargs		xdrgen;
	struct svc_fh		ffh;
	struct svc_fh		tfh;
};

static_assert(offsetof(struct linkargs_wrapper, xdrgen) == 0);

struct symlinkargs_wrapper {
	struct symlinkargs	xdrgen;
	struct svc_fh		ffh;
	struct iattr		iattrs;
};

static_assert(offsetof(struct symlinkargs_wrapper, xdrgen) == 0);

struct statfsres_wrapper {
	struct statfsres	xdrgen;
	struct kstatfs		stats;
};

static_assert(offsetof(struct statfsres_wrapper, xdrgen) == 0);

static __be32 nfsd_map_status(__be32 status)
{
	switch (status) {
	case nfs_ok:
		break;
	case nfserr_nofilehandle:
	case nfserr_badhandle:
		status = nfserr_stale;
		break;
	case nfserr_wrongsec:
	case nfserr_xdev:
	case nfserr_file_open:
		status = nfserr_acces;
		break;
	case nfserr_symlink_not_dir:
		status = nfserr_notdir;
		break;
	case nfserr_symlink:
	case nfserr_wrong_type:
		status = nfserr_io;
		break;
	}
	return status;
}

static __always_inline void
nfsd_fhandle_to_svc_fh(struct svc_fh *fhp, const fhandle *fhandle)
{
	fh_init(fhp, NFS_FHSIZE);
	fhp->fh_handle.fh_size = NFS_FHSIZE;
	memcpy(&fhp->fh_handle.fh_raw, fhandle, NFS_FHSIZE);
}

static __always_inline void
nfsd_svc_fh_to_fhandle(fhandle *fhandle, const struct svc_fh *fhp)
{
	memcpy(fhandle, fhp->fh_handle.fh_raw, NFS_FHSIZE);
}

static __always_inline void
nfsd_timespec64_to_timeval(struct timeval *dst,
			   const struct timespec64 *src)
{
	dst->seconds = src->tv_sec;
	dst->useconds = src->tv_nsec / NSEC_PER_USEC;
}

static __always_inline void
nfsd_timeval_to_timespec64(struct timespec64 *dst, const struct timeval *src)
{
	dst->tv_sec = src->seconds;
	dst->tv_nsec = src->useconds * NSEC_PER_USEC;
}

static u32
nfsd_mode_to_ftype(umode_t mode)
{
	switch (mode & S_IFMT) {
	case S_IFREG:  return NFREG;
	case S_IFDIR:  return NFDIR;
	case S_IFBLK:  return NFBLK;
	case S_IFCHR:  return NFCHR;
	case S_IFLNK:  return NFLNK;
	/*
	 * The NFSv2 protocol's ftype enum does not provide specific values
	 * for sockets and FIFOs.
	 */
	case S_IFSOCK: return NFNON;
	case S_IFIFO:  return NFNON;
	}
	return NFNON;
}

static void
nfsd_stat_to_fattr(struct svc_rqst *rqstp, struct fattr *fattr,
		   const struct kstat *stat, const struct svc_fh *fhp)
{
	struct user_namespace *userns = nfsd_user_namespace(rqstp);
	struct timespec64 time;
	u32 fsid;

	fattr->type = nfsd_mode_to_ftype(stat->mode);
	fattr->mode = stat->mode;
	fattr->nlink = stat->nlink;
	fattr->uid = from_kuid_munged(userns, stat->uid);
	fattr->gid = from_kgid_munged(userns, stat->gid);
	if (S_ISLNK(stat->mode) && stat->size > NFS_MAXPATHLEN)
		fattr->size = NFS_MAXPATHLEN;
	else
		fattr->size = stat->size;
	fattr->blocksize = stat->blksize;
	if (S_ISCHR(stat->mode) || S_ISBLK(stat->mode))
		fattr->rdev = new_encode_dev(stat->rdev);
	else
		fattr->rdev = 0xffffffff;
	fattr->blocks = stat->blocks;

	switch (fsid_source(fhp)) {
	case FSIDSOURCE_FSID:
		fsid = (u32)fhp->fh_export->ex_fsid;
		break;
	case FSIDSOURCE_UUID:
		fsid = ((u32 *)fhp->fh_export->ex_uuid)[0];
		fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[1];
		fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[2];
		fsid ^= ((u32 *)fhp->fh_export->ex_uuid)[3];
		break;
	default:
		fsid = new_encode_dev(stat->dev);
	}
	fattr->fsid = fsid;
	fattr->fileid = stat->ino;

	nfsd_timespec64_to_timeval(&fattr->atime, &stat->atime);
	time = stat->mtime;
	lease_get_mtime(d_inode(fhp->fh_dentry), &time);
	nfsd_timespec64_to_timeval(&fattr->mtime, &time);
	nfsd_timespec64_to_timeval(&fattr->ctime, &stat->ctime);
}

/*
 * Because NFSv2 does not have an NFSERR_SYMLINK, Solaris returns
 * NFSERR_ISDIR when the target of a READ or WRITE is any object
 * that is not a regular file.
 */
static __be32 nfsd_map_io_status(__be32 status)
{
	switch (status) {
	case nfserr_symlink:
	case nfserr_wrong_type:
		return nfserr_isdir;
	}
	return nfsd_map_status(status);
}

/*
 * Sun convention: a sattr time-useconds field of one full second (an
 * otherwise out-of-range value) means "set this time to the current
 * server time." It's needed to make permissions checks for the "touch"
 * program across NFSv2 mounts work correctly. See description of
 * sattr in section 6.1 of "NFS Illustrated" by Brent Callaghan,
 * Addison-Wesley, ISBN 0-201-32750-5
 */
#define NFS2_SATTR_SET_TO_SERVER_TIME	(1000000)

static bool
nfsd_sattr_to_iattr(struct svc_rqst *rqstp, struct iattr *iap,
		    const struct sattr *sattr)
{
	static const unsigned int dont_set_it = (unsigned int)-1;

	/* Consumers read ia_size, ia_uid, and ia_gid unguarded by ia_valid */
	memset(iap, 0, sizeof(*iap));

	/*
	 * Some Sun NFS clients put 0xffff in the mode field when they
	 * mean 0xffffffff.
	 */
	if (sattr->mode != dont_set_it && sattr->mode != 0xffff) {
		iap->ia_valid |= ATTR_MODE;
		iap->ia_mode = sattr->mode;
	}
	if (sattr->uid != dont_set_it) {
		iap->ia_uid = make_kuid(nfsd_user_namespace(rqstp), sattr->uid);
		if (uid_valid(iap->ia_uid))
			iap->ia_valid |= ATTR_UID;
	}
	if (sattr->gid != dont_set_it) {
		iap->ia_gid = make_kgid(nfsd_user_namespace(rqstp), sattr->gid);
		if (gid_valid(iap->ia_gid))
			iap->ia_valid |= ATTR_GID;
	}
	if (sattr->size != dont_set_it) {
		iap->ia_valid |= ATTR_SIZE;
		iap->ia_size = sattr->size;
	}
	if (sattr->atime.seconds != dont_set_it &&
	    sattr->atime.useconds != dont_set_it) {
		/*
		 * Reject out-of-range useconds so the conversion to
		 * nanoseconds cannot wrap to a valid but incorrect
		 * value on 32-bit platforms.
		 */
		if (sattr->atime.useconds > NFS2_SATTR_SET_TO_SERVER_TIME)
			return false;
		iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET;
		nfsd_timeval_to_timespec64(&iap->ia_atime, &sattr->atime);

		if (sattr->atime.useconds == NFS2_SATTR_SET_TO_SERVER_TIME)
			iap->ia_valid &= ~ATTR_ATIME_SET;
	}
	if (sattr->mtime.seconds != dont_set_it &&
	    sattr->mtime.useconds != dont_set_it) {
		if (sattr->mtime.useconds > NFS2_SATTR_SET_TO_SERVER_TIME)
			return false;
		iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET;
		nfsd_timeval_to_timespec64(&iap->ia_mtime, &sattr->mtime);

		if (sattr->mtime.useconds == NFS2_SATTR_SET_TO_SERVER_TIME)
			iap->ia_valid &= ~(ATTR_ATIME_SET | ATTR_MTIME_SET);
	}

	return true;
}

/*
 * A full specification of each of the following NFSv2 procedures is
 * available in RFC 1094 Section 2.2.
 */

/**
 * nfsd_proc_null - NULL: Do nothing
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   void NFSPROC_NULL(void) = 0;
 */
static __be32 nfsd_proc_null(struct svc_rqst *rqstp)
{
	return rpc_success;
}

/**
 * nfsd_proc_getattr - GETATTR: Get file attributes
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   attrstat NFSPROC_GETATTR(fhandle) = 1;
 */
static __be32 nfsd_proc_getattr(struct svc_rqst *rqstp)
{
	struct fhandle_wrapper *argp = rqstp->rq_argp;
	struct attrstat_wrapper *resp = rqstp->rq_resp;
	struct kstat *statp = &resp->stat;
	struct svc_fh *fhp = &argp->fh;

	nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen);
	trace_nfsd_vfs_getattr(rqstp, fhp);
	resp->xdrgen.status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP |
					NFSD_MAY_BYPASS_GSS_ON_ROOT);
	if (resp->xdrgen.status != nfs_ok)
		goto out;

	resp->xdrgen.status = fh_getattr(fhp, statp);

out:
	if (resp->xdrgen.status == nfs_ok)
		nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.attributes, statp, fhp);
	else
		resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status);

	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_setattr - SETATTR: Set file attributes
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   attrstat NFSPROC_SETATTR(sattrargs) = 2;
 */
static __be32 nfsd_proc_setattr(struct svc_rqst *rqstp)
{
	struct sattrargs_wrapper *argp = rqstp->rq_argp;
	struct attrstat_wrapper *resp = rqstp->rq_resp;
	struct kstat *statp = &resp->stat;
	struct iattr *iap = &argp->iattrs;
	struct nfsd_attrs nattrs = {
		.na_iattr	= iap,
	};
	struct svc_fh *fhp = &argp->fh;

	nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen.file);
	if (!nfsd_sattr_to_iattr(rqstp, iap, &argp->xdrgen.attributes)) {
		resp->xdrgen.status = nfserr_io;
		goto out;
	}

	/*
	 * NFSv2 does not differentiate between "set-[ac]time-to-now"
	 * which only requires access, and "set-[ac]time-to-X" which
	 * requires ownership.
	 * So if it looks like it might be "set both to the same time which
	 * is close to now", and if setattr_prepare fails, then we
	 * convert to "set to now" instead of "set to explicit time"
	 *
	 * We only call setattr_prepare as the last test as technically
	 * it is not an interface that we should be using.
	 */
#define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
#define	MAX_TOUCH_TIME_ERROR (30*60)
	if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
	    iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
		int hosterr;

		/*
		 * Looks probable.
		 *
		 * Now just make sure time is in the right ballpark.
		 * Solaris, at least, doesn't seem to care what the time
		 * request is.  We require it be within 30 minutes of now.
		 */
		time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds();

		resp->xdrgen.status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
		if (resp->xdrgen.status != nfs_ok)
			goto out;

		hosterr = fh_want_write(fhp);
		if (hosterr) {
			resp->xdrgen.status = nfserrno(hosterr);
			goto out;
		}

		if (delta < 0)
			delta = -delta;
		if (delta < MAX_TOUCH_TIME_ERROR &&
		    setattr_prepare(&nop_mnt_idmap, fhp->fh_dentry, iap) != 0) {
			/*
			 * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
			 * This will cause notify_change to set these times
			 * to "now"
			 */
			iap->ia_valid &= ~BOTH_TIME_SET;
		}
	}

	resp->xdrgen.status = nfsd_setattr(rqstp, fhp, &nattrs, NULL);
	if (resp->xdrgen.status != nfs_ok)
		goto out;

	resp->xdrgen.status = fh_getattr(fhp, statp);

out:
	if (resp->xdrgen.status == nfs_ok)
		nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.attributes, statp, fhp);
	else
		resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status);

	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_root - ROOT: Get filesystem root
 * @rqstp: RPC transaction context
 *
 * Obsolete, replaced by MNTPROC_MNT.
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   void NFSPROC_ROOT(void) = 3;
 */
static __be32 nfsd_proc_root(struct svc_rqst *rqstp)
{
	return rpc_success;
}

/**
 * nfsd_proc_lookup - LOOKUP: Look up file name
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   diropres NFSPROC_LOOKUP(diropargs) = 4;
 */
static __be32 nfsd_proc_lookup(struct svc_rqst *rqstp)
{
	struct diropargs_wrapper *argp = rqstp->rq_argp;
	struct diropres_wrapper *resp = rqstp->rq_resp;
	struct diropargs *what = &argp->xdrgen;
	struct kstat *statp = &resp->stat;
	struct svc_fh *dirfhp = &argp->fh;
	struct svc_fh *fhp = &resp->fh;

	nfsd_fhandle_to_svc_fh(dirfhp, &what->dir);

	fh_init(fhp, NFS_FHSIZE);
	resp->xdrgen.status = nfsd_lookup(rqstp, dirfhp,
					  (char *)what->name.data,
					  what->name.len, fhp);
	if (resp->xdrgen.status != nfs_ok)
		goto out;
	resp->xdrgen.status = fh_getattr(fhp, statp);

out:
	if (resp->xdrgen.status == nfs_ok) {
		nfsd_svc_fh_to_fhandle(&resp->xdrgen.u.diropok.file, fhp);
		nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.diropok.attributes,
				   statp, fhp);
	} else {
		resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status);
	}

	fh_put(fhp);
	fh_put(dirfhp);
	return rpc_success;
}

/**
 * nfsd_proc_readlink - READLINK: Read symbolic link
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   readlinkres NFSPROC_READLINK(fhandle) = 5;
 */
static __be32 nfsd_proc_readlink(struct svc_rqst *rqstp)
{
	struct fhandle_wrapper *argp = rqstp->rq_argp;
	struct readlinkres *resp = rqstp->rq_resp;
	struct svc_fh *fhp = &argp->fh;
	struct page *page;
	u32 len;

	nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen);

	len = NFS_MAXPATHLEN;
	page = *(rqstp->rq_next_page++);
	resp->status = nfsd_readlink(rqstp, fhp, page_address(page), &len);
	if (resp->status == nfs_ok)
		resp->u.data.len = len;
	else
		resp->status = nfsd_map_status(resp->status);

	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_read - READ: Read from file
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   readres NFSPROC_READ(readargs) = 6;
 */
static __be32 nfsd_proc_read(struct svc_rqst *rqstp)
{
	struct readargs_wrapper *argp = rqstp->rq_argp;
	struct readres *resp = rqstp->rq_resp;
	unsigned long count = argp->xdrgen.count;
	u32 offset = argp->xdrgen.offset;
	struct svc_fh *fhp = &argp->fh;
	struct kstat stat;
	u32 eof;

	nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen.file);
	count = min_t(u32, count, NFS_MAXDATA);
	count = min_t(u32, count, rqstp->rq_res.buflen);

	/*
	 * 19 is 1 word for status, 17 words for fattr, and 1 word
	 * for the byte count.
	 */
	svc_reserve_auth(rqstp, (19 << 2) + count + 4);
	resp->status = nfsd_read(rqstp, fhp, offset, &count, &eof);

	if (resp->status == nfs_ok) {
		struct readresok *resok = &resp->u.readresok;

		resok->data.len = count;
		resp->status = fh_getattr(fhp, &stat);
		if (resp->status == nfs_ok)
			nfsd_stat_to_fattr(rqstp, &resok->attributes, &stat,
					   fhp);
	}
	if (resp->status == nfserr_jukebox)
		set_bit(RQ_DROPME, &rqstp->rq_flags);
	if (resp->status != nfs_ok)
		resp->status = nfsd_map_io_status(resp->status);

	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_writecache - WRITECACHE: To-client write cache
 * @rqstp: RPC transaction context
 *
 * Reserved.
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   void NFSPROC_WRITECACHE(void) = 7;
 */
static __be32 nfsd_proc_writecache(struct svc_rqst *rqstp)
{
	return rpc_success;
}

/**
 * nfsd_proc_write - WRITE: Write to file
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   attrstat NFSPROC_WRITE(writeargs) = 8;
 */
static __be32 nfsd_proc_write(struct svc_rqst *rqstp)
{
	struct writeargs_wrapper *argp = rqstp->rq_argp;
	struct attrstat_wrapper *resp = rqstp->rq_resp;
	struct kstat *statp = &resp->stat;
	unsigned long count = argp->xdrgen.data.len;
	struct svc_fh *fhp = &argp->fh;

	nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen.file);

	resp->xdrgen.status = nfsd_write(rqstp, fhp, argp->xdrgen.offset,
					 &argp->xdrgen.data, &count,
					 IOCB_DSYNC, NULL);
	if (resp->xdrgen.status == nfs_ok) {
		resp->xdrgen.status = fh_getattr(fhp, statp);
		if (resp->xdrgen.status == nfs_ok)
			nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.attributes,
					   statp, fhp);
	}
	if (resp->xdrgen.status == nfserr_jukebox)
		set_bit(RQ_DROPME, &rqstp->rq_flags);
	if (resp->xdrgen.status != nfs_ok)
		resp->xdrgen.status = nfsd_map_io_status(resp->xdrgen.status);

	fh_put(fhp);
	return rpc_success;
}

/*
 * Implement NFSv2's unchecked CREATE semantics. Based on type bits in the
 * mode field, NFSv2 CREATE can create regular files, devices, and FIFOs.
 *
 * Caller must release @fhp and @resfhp.
 */
static __be32
nfsd_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
		 struct svc_fh *resfhp, struct createargs_wrapper *argp)
{
	struct diropargs *where = &argp->xdrgen.where;
	struct iattr *attr = &argp->iattrs;
	dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
	struct nfsd_attrs attrs = {
		.na_iattr	= attr,
	};
	struct svc_export *exp;
	struct dentry *dchild;
	struct inode *inode;
	int type, mode;
	__be32 status;
	int host_err;

	if (name_is_dot_dotdot(where->name.data, where->name.len))
		return nfserr_exist;

	status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
	if (status != nfs_ok)
		return status;

	host_err = fh_want_write(fhp);
	if (host_err)
		return nfserrno(host_err);

	dchild = start_creating(&nop_mnt_idmap, fhp->fh_dentry,
				&QSTR_LEN(where->name.data, where->name.len));
	if (IS_ERR(dchild)) {
		status = nfserrno(PTR_ERR(dchild));
		goto out_drop_write;
	}
	/*
	 * If name exists we need to check for mountpoints
	 */
	exp = exp_get(fhp->fh_export);
	if (d_is_reg(dchild) &&
	    unlikely(nfsd_mountpoint(dchild, exp))) {
		status = nfsd_cross_mnt(rqstp, &dchild, &exp);
		if (status != nfs_ok) {
			exp_put(exp);
			goto out;
		}
	}

	status = fh_compose(resfhp, exp, dchild, fhp);
	exp_put(exp);
	if (!status && d_really_is_negative(dchild))
		status = nfserr_noent;
	if (status) {
		if (status != nfserr_noent)
			goto out;
		/*
		 * If the new file handle wasn't verified, we can't tell
		 * whether the file exists or not. Time to bail ...
		 */
		status = nfserr_acces;
		if (!resfhp->fh_dentry) {
			printk(KERN_WARNING
				"nfsd_proc_create: file handle not verified\n");
			goto out;
		}
	}

	inode = d_inode(resfhp->fh_dentry);

	/* Unfudge the mode bits */
	if (attr->ia_valid & ATTR_MODE) {
		type = attr->ia_mode & S_IFMT;
		mode = attr->ia_mode & ~S_IFMT;
		if (!type) {
			/* no type, so if target exists, assume same as that,
			 * else assume a file */
			if (inode) {
				type = inode->i_mode & S_IFMT;
				switch (type) {
				case S_IFCHR:
				case S_IFBLK:
					/* reserve rdev for later checking */
					rdev = inode->i_rdev;
					attr->ia_valid |= ATTR_SIZE;
					fallthrough;
				case S_IFIFO:
					/* this is probably a permission check..
					 * at least IRIX implements perm checking on
					 *   echo thing > device-special-file-or-pipe
					 * by doing a CREATE with type==0
					 */
					status = nfsd_permission(
						&rqstp->rq_cred,
						resfhp->fh_export,
						resfhp->fh_dentry,
						NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
					if (status && status != nfserr_rofs)
						goto out;
				}
			} else
				type = S_IFREG;
		}
	} else if (inode) {
		type = inode->i_mode & S_IFMT;
		mode = inode->i_mode & ~S_IFMT;
	} else {
		type = S_IFREG;
		mode = 0;	/* ??? */
	}

	attr->ia_valid |= ATTR_MODE;
	attr->ia_mode = mode;

	/* Special treatment for non-regular files according to the
	 * gospel of sun micro
	 */
	if (type != S_IFREG) {
		if (type != S_IFBLK && type != S_IFCHR) {
			rdev = 0;
		} else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
			/* If you think you've seen the worst, grok this. */
			type = S_IFIFO;
		} else {
			/* Okay, char or block special */
			if (!rdev)
				rdev = wanted;
		}

		/* we've used the SIZE information, so discard it */
		attr->ia_valid &= ~ATTR_SIZE;

		/* Make sure the type and device matches */
		status = nfserr_exist;
		if (inode && inode_wrong_type(inode, type))
			goto out;
	}

	status = nfs_ok;
	if (!inode) {
		/* File doesn't exist. Create it and set attrs */
		status = nfsd_create_locked(rqstp, fhp, &attrs, type,
					    rdev, resfhp);
		/* nfsd_create_locked() unlocked the parent */
		dput(dchild);
		goto out_drop_write;
	} else if (type == S_IFREG) {
		dprintk("nfsd:   existing %s, valid=%x, size=%ld\n",
			where->name.data, attr->ia_valid, (long)attr->ia_size);
		/* File already exists. We ignore all attributes except
		 * size, so that creat() behaves exactly like
		 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
		 */
		attr->ia_valid &= ATTR_SIZE;
		if (attr->ia_valid)
			status = nfsd_setattr(rqstp, resfhp, &attrs, NULL);
	}

out:
	end_creating(dchild);
out_drop_write:
	fh_drop_write(fhp);
	return status;
}

/**
 * nfsd_proc_create - CREATE: Create a file
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   diropres NFSPROC_CREATE(createargs) = 9;
 */
static __be32 nfsd_proc_create(struct svc_rqst *rqstp)
{
	struct createargs_wrapper *argp = rqstp->rq_argp;
	struct diropres_wrapper *resp = rqstp->rq_resp;
	struct kstat *statp = &resp->stat;
	struct svc_fh *dirfhp = &argp->fh;
	struct svc_fh *fhp = &resp->fh;

	nfsd_fhandle_to_svc_fh(dirfhp, &argp->xdrgen.where.dir);
	fh_init(fhp, NFS_FHSIZE);
	if (!nfsd_sattr_to_iattr(rqstp, &argp->iattrs, &argp->xdrgen.attributes)) {
		resp->xdrgen.status = nfserr_io;
		goto out;
	}

	resp->xdrgen.status = nfsd_create_file(rqstp, dirfhp, fhp, argp);
	if (resp->xdrgen.status != nfs_ok)
		goto out;
	resp->xdrgen.status = fh_getattr(fhp, statp);

out:
	if (resp->xdrgen.status == nfs_ok) {
		nfsd_svc_fh_to_fhandle(&resp->xdrgen.u.diropok.file, fhp);
		nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.diropok.attributes,
				   statp, fhp);
	} else {
		resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status);
	}

	fh_put(fhp);
	fh_put(dirfhp);
	return rpc_success;
}

/**
 * nfsd_proc_remove - REMOVE: Remove a file
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   nfsstat NFSPROC_REMOVE(diropargs) = 10;
 */
static __be32 nfsd_proc_remove(struct svc_rqst *rqstp)
{
	struct diropargs_wrapper *argp = rqstp->rq_argp;
	struct diropargs *object = &argp->xdrgen;
	nfsstat *resp = rqstp->rq_resp;
	struct svc_fh *fhp = &argp->fh;

	nfsd_fhandle_to_svc_fh(fhp, &object->dir);

	/* Unlink. -S_IFDIR means file must not be a directory */
	*resp = nfsd_unlink(rqstp, fhp, -S_IFDIR,
			    (char *)object->name.data, object->name.len);
	*resp = nfsd_map_status(*resp);

	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_rename - RENAME: Rename a file or directory
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   nfsstat NFSPROC_RENAME(renameargs) = 11;
 */
static __be32 nfsd_proc_rename(struct svc_rqst *rqstp)
{
	struct renameargs_wrapper *argp = rqstp->rq_argp;
	struct diropargs *from = &argp->xdrgen.from;
	struct diropargs *to = &argp->xdrgen.to;
	nfsstat *resp = rqstp->rq_resp;
	struct svc_fh *ffhp = &argp->ffh;
	struct svc_fh *tfhp = &argp->tfh;

	nfsd_fhandle_to_svc_fh(ffhp, &from->dir);
	nfsd_fhandle_to_svc_fh(tfhp, &to->dir);

	*resp = nfsd_rename(rqstp, ffhp, (char *)from->name.data,
			    from->name.len, tfhp, (char *)to->name.data,
			    to->name.len);
	*resp = nfsd_map_status(*resp);

	fh_put(ffhp);
	fh_put(tfhp);
	return rpc_success;
}

/**
 * nfsd_proc_link - LINK: Create Link to an object
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   nfsstat NFSPROC_LINK(linkargs) = 12;
 */
static __be32 nfsd_proc_link(struct svc_rqst *rqstp)
{
	struct linkargs_wrapper *argp = rqstp->rq_argp;
	struct diropargs *to = &argp->xdrgen.to;
	nfsstat *resp = rqstp->rq_resp;
	struct svc_fh *ffhp = &argp->ffh;
	struct svc_fh *tfhp = &argp->tfh;

	nfsd_fhandle_to_svc_fh(ffhp, &argp->xdrgen.from);
	nfsd_fhandle_to_svc_fh(tfhp, &to->dir);

	*resp = nfsd_link(rqstp, tfhp, (char *)to->name.data, to->name.len,
			  ffhp);
	*resp = nfsd_map_status(*resp);

	fh_put(ffhp);
	fh_put(tfhp);
	return rpc_success;
}

static char *nfsd_symlink_target(const struct xdr_buf *to)
{
	char *result;

	result = kmalloc(to->len + 1, GFP_KERNEL);
	if (!result)
		return ERR_PTR(-ESERVERFAULT);
	/* The target can span the receive buffer's head, pages, and tail */
	if (read_bytes_from_xdr_buf(to, 0, result, to->len)) {
		kfree(result);
		return ERR_PTR(-ESERVERFAULT);
	}
	result[to->len] = '\0';

	/* The VFS rejects a pathname that contains a NUL byte */
	if (strlen(result) != to->len) {
		kfree(result);
		return ERR_PTR(-EINVAL);
	}
	return result;
}

/**
 * nfsd_proc_symlink - SYMLINK: Create a symbolic link
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   nfsstat NFSPROC_SYMLINK(symlinkargs) = 13;
 */
static __be32 nfsd_proc_symlink(struct svc_rqst *rqstp)
{
	struct symlinkargs_wrapper *argp = rqstp->rq_argp;
	struct diropargs *from = &argp->xdrgen.from;
	struct xdr_buf *to = &argp->xdrgen.to;
	nfsstat *resp = rqstp->rq_resp;
	struct svc_fh *fhp = &argp->ffh;
	struct nfsd_attrs nattrs = {
		.na_iattr	= &argp->iattrs,
	};
	struct svc_fh newfh;
	char *tname;

	nfsd_fhandle_to_svc_fh(fhp, &from->dir);
	if (!nfsd_sattr_to_iattr(rqstp, &argp->iattrs, &argp->xdrgen.attributes)) {
		*resp = nfserr_io;
		goto out;
	}

	tname = nfsd_symlink_target(to);
	if (IS_ERR(tname)) {
		*resp = nfserrno(PTR_ERR(tname));
		goto out;
	}

	fh_init(&newfh, NFS_FHSIZE);
	*resp = nfsd_symlink(rqstp, fhp, (char *)from->name.data, from->name.len,
			     tname, &nattrs, &newfh);
	kfree(tname);
	*resp = nfsd_map_status(*resp);

	fh_put(&newfh);
out:
	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_mkdir - MKDIR: Create a directory
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   diropres NFSPROC_MKDIR(createargs) = 14;
 */
static __be32 nfsd_proc_mkdir(struct svc_rqst *rqstp)
{
	struct createargs_wrapper *argp = rqstp->rq_argp;
	struct diropargs *where = &argp->xdrgen.where;
	struct diropres_wrapper *resp = rqstp->rq_resp;
	struct kstat *statp = &resp->stat;
	struct svc_fh *dirfhp = &argp->fh;
	struct svc_fh *fhp = &resp->fh;
	struct nfsd_attrs nattrs = {
		.na_iattr	= &argp->iattrs,
	};

	nfsd_fhandle_to_svc_fh(dirfhp, &where->dir);
	fh_init(fhp, NFS_FHSIZE);
	if (!nfsd_sattr_to_iattr(rqstp, &argp->iattrs, &argp->xdrgen.attributes)) {
		resp->xdrgen.status = nfserr_io;
		goto out;
	}

	argp->iattrs.ia_valid &= ~ATTR_SIZE;
	resp->xdrgen.status = nfsd_create(rqstp, dirfhp,
					  (char *)where->name.data,
					  where->name.len, &nattrs,
					  S_IFDIR, 0, fhp);
	if (resp->xdrgen.status != nfs_ok)
		goto out;
	resp->xdrgen.status = fh_getattr(fhp, statp);

out:
	if (resp->xdrgen.status == nfs_ok) {
		nfsd_svc_fh_to_fhandle(&resp->xdrgen.u.diropok.file, fhp);
		nfsd_stat_to_fattr(rqstp, &resp->xdrgen.u.diropok.attributes,
				   statp, fhp);
	} else {
		resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status);
	}

	fh_put(fhp);
	fh_put(dirfhp);
	return rpc_success;
}

/**
 * nfsd_proc_rmdir - RMDIR: Remove a directory
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   nfsstat NFSPROC_RMDIR(diropargs) = 15;
 */
static __be32 nfsd_proc_rmdir(struct svc_rqst *rqstp)
{
	struct diropargs_wrapper *argp = rqstp->rq_argp;
	struct diropargs *object = &argp->xdrgen;
	nfsstat *resp = rqstp->rq_resp;
	struct svc_fh *fhp = &argp->fh;

	nfsd_fhandle_to_svc_fh(fhp, &object->dir);

	/* Unlink. S_IFDIR means file must be a directory */
	*resp = nfsd_unlink(rqstp, fhp, S_IFDIR,
			    (char *)object->name.data, object->name.len);
	*resp = nfsd_map_status(*resp);

	fh_put(fhp);
	return rpc_success;
}

/**
 * nfsd_proc_readdir - READDIR: Read from directory
 * @rqstp: RPC transaction context
 *
 * The directory is opened here so the reply status reflects any open
 * error before the generated encoder writes the status word.  The
 * entry list is streamed from the reply wrapper's directory reader
 * during encode; nfssvc_release_readdirres() closes the reader and
 * releases the file handle.
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   readdirres NFSPROC_READDIR(readdirargs) = 16;
 */
static __be32 nfsd_proc_readdir(struct svc_rqst *rqstp)
{
	struct readdirargs *argp = rqstp->rq_argp;
	struct readdirres_wrapper *resp = rqstp->rq_resp;
	loff_t offset = be32_to_cpup((__be32 *)argp->cookie);
	struct svc_fh *fhp = &resp->fh;
	__be32 status;

	nfsd_fhandle_to_svc_fh(fhp, &argp->dir);
	trace_nfsd_vfs_readdir(rqstp, fhp, argp->count, offset);

	resp->count = argp->count;
	status = nfsd_readdir_open(rqstp, fhp, &offset, &resp->iter);

	resp->xdrgen.status = nfsd_map_status(status);
	return rpc_success;
}

/**
 * nfsd_proc_statfs - STATFS: Get filesystem attributes
 * @rqstp: RPC transaction context
 *
 * Return:
 *   %rpc_success:		RPC executed successfully
 *
 * RPC synopsis:
 *   statfsres NFSPROC_STATFS(fhandle) = 17;
 */
static __be32 nfsd_proc_statfs(struct svc_rqst *rqstp)
{
	struct fhandle_wrapper *argp = rqstp->rq_argp;
	struct statfsres_wrapper *resp = rqstp->rq_resp;
	struct kstatfs *stat = &resp->stats;
	struct svc_fh *fhp = &argp->fh;

	nfsd_fhandle_to_svc_fh(fhp, &argp->xdrgen);

	resp->xdrgen.status = nfsd_statfs(rqstp, fhp, stat,
					  NFSD_MAY_BYPASS_GSS_ON_ROOT);
	if (resp->xdrgen.status == nfs_ok) {
		struct info *resinfo = &resp->xdrgen.u.info;

		resinfo->tsize = NFS_MAXDATA;
		resinfo->bsize = stat->f_bsize;
		resinfo->blocks = stat->f_blocks;
		resinfo->bfree = stat->f_bfree;
		resinfo->bavail = stat->f_bavail;
	} else {
		resp->xdrgen.status = nfsd_map_status(resp->xdrgen.status);
	}

	fh_put(fhp);
	return rpc_success;
}

/*
 * NFSv2 Server procedures.
 * Only the results of non-idempotent operations are cached.
 */

#define ST 1		/* status */
#define FH 8		/* filehandle */
#define	AT 18		/* attributes */

static const struct svc_procedure nfsd_procedures2[18] = {
	[NFSPROC_NULL] = {
		.pc_func	= nfsd_proc_null,
		.pc_decode	= xdrgen_svc_decode_void,
		.pc_encode	= xdrgen_svc_encode_void,
		.pc_argsize	= XDR_void,
		.pc_argzero	= 0,
		.pc_ressize	= 0,
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= XDR_void,
		.pc_name	= "NULL",
	},
	[NFSPROC_GETATTR] = {
		.pc_func	= nfsd_proc_getattr,
		.pc_decode	= nfs_svc_decode_fhandle,
		.pc_encode	= nfs_svc_encode_attrstat,
		.pc_argsize	= sizeof(struct fhandle_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct attrstat_wrapper),
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= NFS2_attrstat_sz,
		.pc_name	= "GETATTR",
	},
	[NFSPROC_SETATTR] = {
		.pc_func	= nfsd_proc_setattr,
		.pc_decode	= nfs_svc_decode_sattrargs,
		.pc_encode	= nfs_svc_encode_attrstat,
		.pc_argsize	= sizeof(struct sattrargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct attrstat_wrapper),
		.pc_cachetype	= RC_REPLBUFF,
		.pc_xdrressize	= NFS2_attrstat_sz,
		.pc_name	= "SETATTR",
	},
	[NFSPROC_ROOT] = {
		.pc_func	= nfsd_proc_root,
		.pc_decode	= xdrgen_svc_decode_void,
		.pc_encode	= xdrgen_svc_encode_void,
		.pc_argsize	= XDR_void,
		.pc_argzero	= 0,
		.pc_ressize	= 0,
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= XDR_void,
		.pc_name	= "ROOT",
	},
	[NFSPROC_LOOKUP] = {
		.pc_func	= nfsd_proc_lookup,
		.pc_decode	= nfs_svc_decode_diropargs,
		.pc_encode	= nfs_svc_encode_diropres,
		.pc_argsize	= sizeof(struct diropargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct diropres_wrapper),
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= NFS2_diropres_sz,
		.pc_name	= "LOOKUP",
	},
	[NFSPROC_READLINK] = {
		.pc_func	= nfsd_proc_readlink,
		.pc_decode	= nfs_svc_decode_fhandle,
		.pc_encode	= nfs_svc_encode_readlinkres,
		.pc_argsize	= sizeof(struct fhandle_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct readlinkres),
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= NFS2_readlinkres_sz,
		.pc_name	= "READLINK",
	},
	[NFSPROC_READ] = {
		.pc_func	= nfsd_proc_read,
		.pc_decode	= nfs_svc_decode_readargs,
		.pc_encode	= nfs_svc_encode_readres,
		.pc_argsize	= sizeof(struct readargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct readres),
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= NFS2_readres_sz,
		.pc_name	= "READ",
	},
	[NFSPROC_WRITECACHE] = {
		.pc_func	= nfsd_proc_writecache,
		.pc_decode	= xdrgen_svc_decode_void,
		.pc_encode	= xdrgen_svc_encode_void,
		.pc_argsize	= XDR_void,
		.pc_argzero	= 0,
		.pc_ressize	= 0,
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= XDR_void,
		.pc_name	= "WRITECACHE",
	},
	[NFSPROC_WRITE] = {
		.pc_func	= nfsd_proc_write,
		.pc_decode	= nfs_svc_decode_writeargs,
		.pc_encode	= nfs_svc_encode_attrstat,
		.pc_argsize	= sizeof(struct writeargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct attrstat_wrapper),
		.pc_cachetype	= RC_REPLBUFF,
		.pc_xdrressize	= NFS2_attrstat_sz,
		.pc_name	= "WRITE",
	},
	[NFSPROC_CREATE] = {
		.pc_func	= nfsd_proc_create,
		.pc_decode	= nfs_svc_decode_createargs,
		.pc_encode	= nfs_svc_encode_diropres,
		.pc_argsize	= sizeof(struct createargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct diropres_wrapper),
		.pc_cachetype	= RC_REPLBUFF,
		.pc_xdrressize	= NFS2_diropres_sz,
		.pc_name	= "CREATE",
	},
	[NFSPROC_REMOVE] = {
		.pc_func	= nfsd_proc_remove,
		.pc_decode	= nfs_svc_decode_diropargs,
		.pc_encode	= nfs_svc_encode_nfsstat,
		.pc_argsize	= sizeof(struct diropargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(nfsstat),
		.pc_cachetype	= RC_REPLSTAT,
		.pc_xdrressize	= NFS2_nfsstat_sz,
		.pc_name	= "REMOVE",
	},
	[NFSPROC_RENAME] = {
		.pc_func	= nfsd_proc_rename,
		.pc_decode	= nfs_svc_decode_renameargs,
		.pc_encode	= nfs_svc_encode_nfsstat,
		.pc_argsize	= sizeof(struct renameargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(nfsstat),
		.pc_cachetype	= RC_REPLSTAT,
		.pc_xdrressize	= NFS2_nfsstat_sz,
		.pc_name	= "RENAME",
	},
	[NFSPROC_LINK] = {
		.pc_func	= nfsd_proc_link,
		.pc_decode	= nfs_svc_decode_linkargs,
		.pc_encode	= nfs_svc_encode_nfsstat,
		.pc_argsize	= sizeof(struct linkargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(nfsstat),
		.pc_cachetype	= RC_REPLSTAT,
		.pc_xdrressize	= NFS2_nfsstat_sz,
		.pc_name	= "LINK",
	},
	[NFSPROC_SYMLINK] = {
		.pc_func	= nfsd_proc_symlink,
		.pc_decode	= nfs_svc_decode_symlinkargs,
		.pc_encode	= nfs_svc_encode_nfsstat,
		.pc_argsize	= sizeof(struct symlinkargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(nfsstat),
		.pc_cachetype	= RC_REPLSTAT,
		.pc_xdrressize	= NFS2_nfsstat_sz,
		.pc_name	= "SYMLINK",
	},
	[NFSPROC_MKDIR] = {
		.pc_func	= nfsd_proc_mkdir,
		.pc_decode	= nfs_svc_decode_createargs,
		.pc_encode	= nfs_svc_encode_diropres,
		.pc_argsize	= sizeof(struct createargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct diropres_wrapper),
		.pc_cachetype	= RC_REPLBUFF,
		.pc_xdrressize	= NFS2_diropres_sz,
		.pc_name	= "MKDIR",
	},
	[NFSPROC_RMDIR] = {
		.pc_func	= nfsd_proc_rmdir,
		.pc_decode	= nfs_svc_decode_diropargs,
		.pc_encode	= nfs_svc_encode_nfsstat,
		.pc_argsize	= sizeof(struct diropargs_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(nfsstat),
		.pc_cachetype	= RC_REPLSTAT,
		.pc_xdrressize	= NFS2_nfsstat_sz,
		.pc_name	= "RMDIR",
	},
	[NFSPROC_READDIR] = {
		.pc_func	= nfsd_proc_readdir,
		.pc_decode	= nfs_svc_decode_readdirargs,
		.pc_encode	= nfs_svc_encode_readdirres,
		.pc_release	= nfssvc_release_readdirres,
		.pc_argsize	= sizeof(struct readdirargs),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct readdirres_wrapper),
		.pc_cachetype	= RC_NOCACHE,
		.pc_name	= "READDIR",
	},
	[NFSPROC_STATFS] = {
		.pc_func	= nfsd_proc_statfs,
		.pc_decode	= nfs_svc_decode_fhandle,
		.pc_encode	= nfs_svc_encode_statfsres,
		.pc_argsize	= sizeof(struct fhandle_wrapper),
		.pc_argzero	= 0,
		.pc_ressize	= sizeof(struct statfsres_wrapper),
		.pc_cachetype	= RC_NOCACHE,
		.pc_xdrressize	= NFS2_statfsres_sz,
		.pc_name	= "STATFS",
	},
};

/*
 * Storage requirements for XDR arguments and results.
 */
union nfsd_xdrstore {
	struct fhandle_wrapper		fhandle;
	struct sattrargs_wrapper	sattrargs;
	struct diropargs_wrapper	diropargs;
	struct readargs_wrapper		readargs;
	struct writeargs_wrapper	writeargs;
	struct createargs_wrapper	createargs;
	struct renameargs_wrapper	renameargs;
	struct linkargs_wrapper		linkargs;
	struct symlinkargs_wrapper	symlinkargs;
	struct readdirargs	readdirargs;
	struct attrstat_wrapper		attrstat;
	struct diropres_wrapper		diropres;
	struct readlinkres	readlinkres;
	struct readres		readres;
	struct readdirres_wrapper	readdirres;
	struct statfsres_wrapper	statfsres;
};

const struct svc_version nfsd_version2 = {
	.vs_vers	= 2,
	.vs_nproc	= ARRAY_SIZE(nfsd_procedures2),
	.vs_proc	= nfsd_procedures2,
	.vs_dispatch	= nfsd_dispatch,
	.vs_xdrsize	= sizeof(union nfsd_xdrstore),
};