diff options
Diffstat (limited to 'fs/nfsd/nfs4xdr.c')
-rw-r--r-- | fs/nfsd/nfs4xdr.c | 633 |
1 files changed, 615 insertions, 18 deletions
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 9250067943d8..b820c311931c 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include <linux/fs.h> | 45 | #include <linux/fs.h> |
46 | #include <linux/namei.h> | 46 | #include <linux/namei.h> |
47 | #include <linux/vfs.h> | 47 | #include <linux/vfs.h> |
48 | #include <linux/utsname.h> | ||
48 | #include <linux/sunrpc/xdr.h> | 49 | #include <linux/sunrpc/xdr.h> |
49 | #include <linux/sunrpc/svc.h> | 50 | #include <linux/sunrpc/svc.h> |
50 | #include <linux/sunrpc/clnt.h> | 51 | #include <linux/sunrpc/clnt.h> |
@@ -188,6 +189,11 @@ static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) | |||
188 | return p; | 189 | return p; |
189 | } | 190 | } |
190 | 191 | ||
192 | static int zero_clientid(clientid_t *clid) | ||
193 | { | ||
194 | return (clid->cl_boot == 0) && (clid->cl_id == 0); | ||
195 | } | ||
196 | |||
191 | static int | 197 | static int |
192 | defer_free(struct nfsd4_compoundargs *argp, | 198 | defer_free(struct nfsd4_compoundargs *argp, |
193 | void (*release)(const void *), void *p) | 199 | void (*release)(const void *), void *p) |
@@ -230,6 +236,7 @@ nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) | |||
230 | 236 | ||
231 | bmval[0] = 0; | 237 | bmval[0] = 0; |
232 | bmval[1] = 0; | 238 | bmval[1] = 0; |
239 | bmval[2] = 0; | ||
233 | 240 | ||
234 | READ_BUF(4); | 241 | READ_BUF(4); |
235 | READ32(bmlen); | 242 | READ32(bmlen); |
@@ -241,13 +248,27 @@ nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) | |||
241 | READ32(bmval[0]); | 248 | READ32(bmval[0]); |
242 | if (bmlen > 1) | 249 | if (bmlen > 1) |
243 | READ32(bmval[1]); | 250 | READ32(bmval[1]); |
251 | if (bmlen > 2) | ||
252 | READ32(bmval[2]); | ||
244 | 253 | ||
245 | DECODE_TAIL; | 254 | DECODE_TAIL; |
246 | } | 255 | } |
247 | 256 | ||
257 | static u32 nfsd_attrmask[] = { | ||
258 | NFSD_WRITEABLE_ATTRS_WORD0, | ||
259 | NFSD_WRITEABLE_ATTRS_WORD1, | ||
260 | NFSD_WRITEABLE_ATTRS_WORD2 | ||
261 | }; | ||
262 | |||
263 | static u32 nfsd41_ex_attrmask[] = { | ||
264 | NFSD_SUPPATTR_EXCLCREAT_WORD0, | ||
265 | NFSD_SUPPATTR_EXCLCREAT_WORD1, | ||
266 | NFSD_SUPPATTR_EXCLCREAT_WORD2 | ||
267 | }; | ||
268 | |||
248 | static __be32 | 269 | static __be32 |
249 | nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, struct iattr *iattr, | 270 | nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, u32 *writable, |
250 | struct nfs4_acl **acl) | 271 | struct iattr *iattr, struct nfs4_acl **acl) |
251 | { | 272 | { |
252 | int expected_len, len = 0; | 273 | int expected_len, len = 0; |
253 | u32 dummy32; | 274 | u32 dummy32; |
@@ -263,9 +284,12 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, struct iattr *ia | |||
263 | * According to spec, unsupported attributes return ERR_ATTRNOTSUPP; | 284 | * According to spec, unsupported attributes return ERR_ATTRNOTSUPP; |
264 | * read-only attributes return ERR_INVAL. | 285 | * read-only attributes return ERR_INVAL. |
265 | */ | 286 | */ |
266 | if ((bmval[0] & ~NFSD_SUPPORTED_ATTRS_WORD0) || (bmval[1] & ~NFSD_SUPPORTED_ATTRS_WORD1)) | 287 | if ((bmval[0] & ~nfsd_suppattrs0(argp->minorversion)) || |
288 | (bmval[1] & ~nfsd_suppattrs1(argp->minorversion)) || | ||
289 | (bmval[2] & ~nfsd_suppattrs2(argp->minorversion))) | ||
267 | return nfserr_attrnotsupp; | 290 | return nfserr_attrnotsupp; |
268 | if ((bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0) || (bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1)) | 291 | if ((bmval[0] & ~writable[0]) || (bmval[1] & ~writable[1]) || |
292 | (bmval[2] & ~writable[2])) | ||
269 | return nfserr_inval; | 293 | return nfserr_inval; |
270 | 294 | ||
271 | READ_BUF(4); | 295 | READ_BUF(4); |
@@ -400,6 +424,7 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, struct iattr *ia | |||
400 | goto xdr_error; | 424 | goto xdr_error; |
401 | } | 425 | } |
402 | } | 426 | } |
427 | BUG_ON(bmval[2]); /* no such writeable attr supported yet */ | ||
403 | if (len != expected_len) | 428 | if (len != expected_len) |
404 | goto xdr_error; | 429 | goto xdr_error; |
405 | 430 | ||
@@ -493,7 +518,9 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create | |||
493 | if ((status = check_filename(create->cr_name, create->cr_namelen, nfserr_inval))) | 518 | if ((status = check_filename(create->cr_name, create->cr_namelen, nfserr_inval))) |
494 | return status; | 519 | return status; |
495 | 520 | ||
496 | if ((status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr, &create->cr_acl))) | 521 | status = nfsd4_decode_fattr(argp, create->cr_bmval, nfsd_attrmask, |
522 | &create->cr_iattr, &create->cr_acl); | ||
523 | if (status) | ||
497 | goto out; | 524 | goto out; |
498 | 525 | ||
499 | DECODE_TAIL; | 526 | DECODE_TAIL; |
@@ -583,6 +610,8 @@ nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) | |||
583 | READ_BUF(lockt->lt_owner.len); | 610 | READ_BUF(lockt->lt_owner.len); |
584 | READMEM(lockt->lt_owner.data, lockt->lt_owner.len); | 611 | READMEM(lockt->lt_owner.data, lockt->lt_owner.len); |
585 | 612 | ||
613 | if (argp->minorversion && !zero_clientid(&lockt->lt_clientid)) | ||
614 | return nfserr_inval; | ||
586 | DECODE_TAIL; | 615 | DECODE_TAIL; |
587 | } | 616 | } |
588 | 617 | ||
@@ -652,13 +681,26 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) | |||
652 | switch (open->op_createmode) { | 681 | switch (open->op_createmode) { |
653 | case NFS4_CREATE_UNCHECKED: | 682 | case NFS4_CREATE_UNCHECKED: |
654 | case NFS4_CREATE_GUARDED: | 683 | case NFS4_CREATE_GUARDED: |
655 | if ((status = nfsd4_decode_fattr(argp, open->op_bmval, &open->op_iattr, &open->op_acl))) | 684 | status = nfsd4_decode_fattr(argp, open->op_bmval, |
685 | nfsd_attrmask, &open->op_iattr, &open->op_acl); | ||
686 | if (status) | ||
656 | goto out; | 687 | goto out; |
657 | break; | 688 | break; |
658 | case NFS4_CREATE_EXCLUSIVE: | 689 | case NFS4_CREATE_EXCLUSIVE: |
659 | READ_BUF(8); | 690 | READ_BUF(8); |
660 | COPYMEM(open->op_verf.data, 8); | 691 | COPYMEM(open->op_verf.data, 8); |
661 | break; | 692 | break; |
693 | case NFS4_CREATE_EXCLUSIVE4_1: | ||
694 | if (argp->minorversion < 1) | ||
695 | goto xdr_error; | ||
696 | READ_BUF(8); | ||
697 | COPYMEM(open->op_verf.data, 8); | ||
698 | status = nfsd4_decode_fattr(argp, open->op_bmval, | ||
699 | nfsd41_ex_attrmask, &open->op_iattr, | ||
700 | &open->op_acl); | ||
701 | if (status) | ||
702 | goto out; | ||
703 | break; | ||
662 | default: | 704 | default: |
663 | goto xdr_error; | 705 | goto xdr_error; |
664 | } | 706 | } |
@@ -851,7 +893,7 @@ nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *seta | |||
851 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); | 893 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
852 | if (status) | 894 | if (status) |
853 | return status; | 895 | return status; |
854 | return nfsd4_decode_fattr(argp, setattr->sa_bmval, | 896 | return nfsd4_decode_fattr(argp, setattr->sa_bmval, nfsd_attrmask, |
855 | &setattr->sa_iattr, &setattr->sa_acl); | 897 | &setattr->sa_iattr, &setattr->sa_acl); |
856 | } | 898 | } |
857 | 899 | ||
@@ -993,6 +1035,241 @@ nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_rel | |||
993 | READ_BUF(rlockowner->rl_owner.len); | 1035 | READ_BUF(rlockowner->rl_owner.len); |
994 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); | 1036 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); |
995 | 1037 | ||
1038 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) | ||
1039 | return nfserr_inval; | ||
1040 | DECODE_TAIL; | ||
1041 | } | ||
1042 | |||
1043 | static __be32 | ||
1044 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, | ||
1045 | struct nfsd4_exchange_id *exid) | ||
1046 | { | ||
1047 | int dummy; | ||
1048 | DECODE_HEAD; | ||
1049 | |||
1050 | READ_BUF(NFS4_VERIFIER_SIZE); | ||
1051 | COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE); | ||
1052 | |||
1053 | READ_BUF(4); | ||
1054 | READ32(exid->clname.len); | ||
1055 | |||
1056 | READ_BUF(exid->clname.len); | ||
1057 | SAVEMEM(exid->clname.data, exid->clname.len); | ||
1058 | |||
1059 | READ_BUF(4); | ||
1060 | READ32(exid->flags); | ||
1061 | |||
1062 | /* Ignore state_protect4_a */ | ||
1063 | READ_BUF(4); | ||
1064 | READ32(exid->spa_how); | ||
1065 | switch (exid->spa_how) { | ||
1066 | case SP4_NONE: | ||
1067 | break; | ||
1068 | case SP4_MACH_CRED: | ||
1069 | /* spo_must_enforce */ | ||
1070 | READ_BUF(4); | ||
1071 | READ32(dummy); | ||
1072 | READ_BUF(dummy * 4); | ||
1073 | p += dummy; | ||
1074 | |||
1075 | /* spo_must_allow */ | ||
1076 | READ_BUF(4); | ||
1077 | READ32(dummy); | ||
1078 | READ_BUF(dummy * 4); | ||
1079 | p += dummy; | ||
1080 | break; | ||
1081 | case SP4_SSV: | ||
1082 | /* ssp_ops */ | ||
1083 | READ_BUF(4); | ||
1084 | READ32(dummy); | ||
1085 | READ_BUF(dummy * 4); | ||
1086 | p += dummy; | ||
1087 | |||
1088 | READ_BUF(4); | ||
1089 | READ32(dummy); | ||
1090 | READ_BUF(dummy * 4); | ||
1091 | p += dummy; | ||
1092 | |||
1093 | /* ssp_hash_algs<> */ | ||
1094 | READ_BUF(4); | ||
1095 | READ32(dummy); | ||
1096 | READ_BUF(dummy); | ||
1097 | p += XDR_QUADLEN(dummy); | ||
1098 | |||
1099 | /* ssp_encr_algs<> */ | ||
1100 | READ_BUF(4); | ||
1101 | READ32(dummy); | ||
1102 | READ_BUF(dummy); | ||
1103 | p += XDR_QUADLEN(dummy); | ||
1104 | |||
1105 | /* ssp_window and ssp_num_gss_handles */ | ||
1106 | READ_BUF(8); | ||
1107 | READ32(dummy); | ||
1108 | READ32(dummy); | ||
1109 | break; | ||
1110 | default: | ||
1111 | goto xdr_error; | ||
1112 | } | ||
1113 | |||
1114 | /* Ignore Implementation ID */ | ||
1115 | READ_BUF(4); /* nfs_impl_id4 array length */ | ||
1116 | READ32(dummy); | ||
1117 | |||
1118 | if (dummy > 1) | ||
1119 | goto xdr_error; | ||
1120 | |||
1121 | if (dummy == 1) { | ||
1122 | /* nii_domain */ | ||
1123 | READ_BUF(4); | ||
1124 | READ32(dummy); | ||
1125 | READ_BUF(dummy); | ||
1126 | p += XDR_QUADLEN(dummy); | ||
1127 | |||
1128 | /* nii_name */ | ||
1129 | READ_BUF(4); | ||
1130 | READ32(dummy); | ||
1131 | READ_BUF(dummy); | ||
1132 | p += XDR_QUADLEN(dummy); | ||
1133 | |||
1134 | /* nii_date */ | ||
1135 | READ_BUF(12); | ||
1136 | p += 3; | ||
1137 | } | ||
1138 | DECODE_TAIL; | ||
1139 | } | ||
1140 | |||
1141 | static __be32 | ||
1142 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, | ||
1143 | struct nfsd4_create_session *sess) | ||
1144 | { | ||
1145 | DECODE_HEAD; | ||
1146 | |||
1147 | u32 dummy; | ||
1148 | char *machine_name; | ||
1149 | int i; | ||
1150 | int nr_secflavs; | ||
1151 | |||
1152 | READ_BUF(16); | ||
1153 | COPYMEM(&sess->clientid, 8); | ||
1154 | READ32(sess->seqid); | ||
1155 | READ32(sess->flags); | ||
1156 | |||
1157 | /* Fore channel attrs */ | ||
1158 | READ_BUF(28); | ||
1159 | READ32(dummy); /* headerpadsz is always 0 */ | ||
1160 | READ32(sess->fore_channel.maxreq_sz); | ||
1161 | READ32(sess->fore_channel.maxresp_sz); | ||
1162 | READ32(sess->fore_channel.maxresp_cached); | ||
1163 | READ32(sess->fore_channel.maxops); | ||
1164 | READ32(sess->fore_channel.maxreqs); | ||
1165 | READ32(sess->fore_channel.nr_rdma_attrs); | ||
1166 | if (sess->fore_channel.nr_rdma_attrs == 1) { | ||
1167 | READ_BUF(4); | ||
1168 | READ32(sess->fore_channel.rdma_attrs); | ||
1169 | } else if (sess->fore_channel.nr_rdma_attrs > 1) { | ||
1170 | dprintk("Too many fore channel attr bitmaps!\n"); | ||
1171 | goto xdr_error; | ||
1172 | } | ||
1173 | |||
1174 | /* Back channel attrs */ | ||
1175 | READ_BUF(28); | ||
1176 | READ32(dummy); /* headerpadsz is always 0 */ | ||
1177 | READ32(sess->back_channel.maxreq_sz); | ||
1178 | READ32(sess->back_channel.maxresp_sz); | ||
1179 | READ32(sess->back_channel.maxresp_cached); | ||
1180 | READ32(sess->back_channel.maxops); | ||
1181 | READ32(sess->back_channel.maxreqs); | ||
1182 | READ32(sess->back_channel.nr_rdma_attrs); | ||
1183 | if (sess->back_channel.nr_rdma_attrs == 1) { | ||
1184 | READ_BUF(4); | ||
1185 | READ32(sess->back_channel.rdma_attrs); | ||
1186 | } else if (sess->back_channel.nr_rdma_attrs > 1) { | ||
1187 | dprintk("Too many back channel attr bitmaps!\n"); | ||
1188 | goto xdr_error; | ||
1189 | } | ||
1190 | |||
1191 | READ_BUF(8); | ||
1192 | READ32(sess->callback_prog); | ||
1193 | |||
1194 | /* callback_sec_params4 */ | ||
1195 | READ32(nr_secflavs); | ||
1196 | for (i = 0; i < nr_secflavs; ++i) { | ||
1197 | READ_BUF(4); | ||
1198 | READ32(dummy); | ||
1199 | switch (dummy) { | ||
1200 | case RPC_AUTH_NULL: | ||
1201 | /* Nothing to read */ | ||
1202 | break; | ||
1203 | case RPC_AUTH_UNIX: | ||
1204 | READ_BUF(8); | ||
1205 | /* stamp */ | ||
1206 | READ32(dummy); | ||
1207 | |||
1208 | /* machine name */ | ||
1209 | READ32(dummy); | ||
1210 | READ_BUF(dummy); | ||
1211 | SAVEMEM(machine_name, dummy); | ||
1212 | |||
1213 | /* uid, gid */ | ||
1214 | READ_BUF(8); | ||
1215 | READ32(sess->uid); | ||
1216 | READ32(sess->gid); | ||
1217 | |||
1218 | /* more gids */ | ||
1219 | READ_BUF(4); | ||
1220 | READ32(dummy); | ||
1221 | READ_BUF(dummy * 4); | ||
1222 | for (i = 0; i < dummy; ++i) | ||
1223 | READ32(dummy); | ||
1224 | break; | ||
1225 | case RPC_AUTH_GSS: | ||
1226 | dprintk("RPC_AUTH_GSS callback secflavor " | ||
1227 | "not supported!\n"); | ||
1228 | READ_BUF(8); | ||
1229 | /* gcbp_service */ | ||
1230 | READ32(dummy); | ||
1231 | /* gcbp_handle_from_server */ | ||
1232 | READ32(dummy); | ||
1233 | READ_BUF(dummy); | ||
1234 | p += XDR_QUADLEN(dummy); | ||
1235 | /* gcbp_handle_from_client */ | ||
1236 | READ_BUF(4); | ||
1237 | READ32(dummy); | ||
1238 | READ_BUF(dummy); | ||
1239 | p += XDR_QUADLEN(dummy); | ||
1240 | break; | ||
1241 | default: | ||
1242 | dprintk("Illegal callback secflavor\n"); | ||
1243 | return nfserr_inval; | ||
1244 | } | ||
1245 | } | ||
1246 | DECODE_TAIL; | ||
1247 | } | ||
1248 | |||
1249 | static __be32 | ||
1250 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, | ||
1251 | struct nfsd4_destroy_session *destroy_session) | ||
1252 | { | ||
1253 | DECODE_HEAD; | ||
1254 | READ_BUF(NFS4_MAX_SESSIONID_LEN); | ||
1255 | COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN); | ||
1256 | |||
1257 | DECODE_TAIL; | ||
1258 | } | ||
1259 | |||
1260 | static __be32 | ||
1261 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, | ||
1262 | struct nfsd4_sequence *seq) | ||
1263 | { | ||
1264 | DECODE_HEAD; | ||
1265 | |||
1266 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); | ||
1267 | COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); | ||
1268 | READ32(seq->seqid); | ||
1269 | READ32(seq->slotid); | ||
1270 | READ32(seq->maxslots); | ||
1271 | READ32(seq->cachethis); | ||
1272 | |||
996 | DECODE_TAIL; | 1273 | DECODE_TAIL; |
997 | } | 1274 | } |
998 | 1275 | ||
@@ -1005,7 +1282,7 @@ nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) | |||
1005 | static __be32 | 1282 | static __be32 |
1006 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) | 1283 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
1007 | { | 1284 | { |
1008 | return nfserr_opnotsupp; | 1285 | return nfserr_notsupp; |
1009 | } | 1286 | } |
1010 | 1287 | ||
1011 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); | 1288 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
@@ -1031,7 +1308,7 @@ static nfsd4_dec nfsd4_dec_ops[] = { | |||
1031 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, | 1308 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
1032 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, | 1309 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
1033 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, | 1310 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
1034 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_notsupp, | 1311 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_noop, |
1035 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, | 1312 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
1036 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, | 1313 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
1037 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, | 1314 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
@@ -1050,6 +1327,67 @@ static nfsd4_dec nfsd4_dec_ops[] = { | |||
1050 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, | 1327 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
1051 | }; | 1328 | }; |
1052 | 1329 | ||
1330 | static nfsd4_dec nfsd41_dec_ops[] = { | ||
1331 | [OP_ACCESS] (nfsd4_dec)nfsd4_decode_access, | ||
1332 | [OP_CLOSE] (nfsd4_dec)nfsd4_decode_close, | ||
1333 | [OP_COMMIT] (nfsd4_dec)nfsd4_decode_commit, | ||
1334 | [OP_CREATE] (nfsd4_dec)nfsd4_decode_create, | ||
1335 | [OP_DELEGPURGE] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1336 | [OP_DELEGRETURN] (nfsd4_dec)nfsd4_decode_delegreturn, | ||
1337 | [OP_GETATTR] (nfsd4_dec)nfsd4_decode_getattr, | ||
1338 | [OP_GETFH] (nfsd4_dec)nfsd4_decode_noop, | ||
1339 | [OP_LINK] (nfsd4_dec)nfsd4_decode_link, | ||
1340 | [OP_LOCK] (nfsd4_dec)nfsd4_decode_lock, | ||
1341 | [OP_LOCKT] (nfsd4_dec)nfsd4_decode_lockt, | ||
1342 | [OP_LOCKU] (nfsd4_dec)nfsd4_decode_locku, | ||
1343 | [OP_LOOKUP] (nfsd4_dec)nfsd4_decode_lookup, | ||
1344 | [OP_LOOKUPP] (nfsd4_dec)nfsd4_decode_noop, | ||
1345 | [OP_NVERIFY] (nfsd4_dec)nfsd4_decode_verify, | ||
1346 | [OP_OPEN] (nfsd4_dec)nfsd4_decode_open, | ||
1347 | [OP_OPENATTR] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1348 | [OP_OPEN_CONFIRM] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1349 | [OP_OPEN_DOWNGRADE] (nfsd4_dec)nfsd4_decode_open_downgrade, | ||
1350 | [OP_PUTFH] (nfsd4_dec)nfsd4_decode_putfh, | ||
1351 | [OP_PUTPUBFH] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1352 | [OP_PUTROOTFH] (nfsd4_dec)nfsd4_decode_noop, | ||
1353 | [OP_READ] (nfsd4_dec)nfsd4_decode_read, | ||
1354 | [OP_READDIR] (nfsd4_dec)nfsd4_decode_readdir, | ||
1355 | [OP_READLINK] (nfsd4_dec)nfsd4_decode_noop, | ||
1356 | [OP_REMOVE] (nfsd4_dec)nfsd4_decode_remove, | ||
1357 | [OP_RENAME] (nfsd4_dec)nfsd4_decode_rename, | ||
1358 | [OP_RENEW] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1359 | [OP_RESTOREFH] (nfsd4_dec)nfsd4_decode_noop, | ||
1360 | [OP_SAVEFH] (nfsd4_dec)nfsd4_decode_noop, | ||
1361 | [OP_SECINFO] (nfsd4_dec)nfsd4_decode_secinfo, | ||
1362 | [OP_SETATTR] (nfsd4_dec)nfsd4_decode_setattr, | ||
1363 | [OP_SETCLIENTID] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1364 | [OP_SETCLIENTID_CONFIRM](nfsd4_dec)nfsd4_decode_notsupp, | ||
1365 | [OP_VERIFY] (nfsd4_dec)nfsd4_decode_verify, | ||
1366 | [OP_WRITE] (nfsd4_dec)nfsd4_decode_write, | ||
1367 | [OP_RELEASE_LOCKOWNER] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1368 | |||
1369 | /* new operations for NFSv4.1 */ | ||
1370 | [OP_BACKCHANNEL_CTL] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1371 | [OP_BIND_CONN_TO_SESSION](nfsd4_dec)nfsd4_decode_notsupp, | ||
1372 | [OP_EXCHANGE_ID] (nfsd4_dec)nfsd4_decode_exchange_id, | ||
1373 | [OP_CREATE_SESSION] (nfsd4_dec)nfsd4_decode_create_session, | ||
1374 | [OP_DESTROY_SESSION] (nfsd4_dec)nfsd4_decode_destroy_session, | ||
1375 | [OP_FREE_STATEID] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1376 | [OP_GET_DIR_DELEGATION] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1377 | [OP_GETDEVICEINFO] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1378 | [OP_GETDEVICELIST] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1379 | [OP_LAYOUTCOMMIT] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1380 | [OP_LAYOUTGET] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1381 | [OP_LAYOUTRETURN] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1382 | [OP_SECINFO_NO_NAME] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1383 | [OP_SEQUENCE] (nfsd4_dec)nfsd4_decode_sequence, | ||
1384 | [OP_SET_SSV] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1385 | [OP_TEST_STATEID] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1386 | [OP_WANT_DELEGATION] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1387 | [OP_DESTROY_CLIENTID] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1388 | [OP_RECLAIM_COMPLETE] (nfsd4_dec)nfsd4_decode_notsupp, | ||
1389 | }; | ||
1390 | |||
1053 | struct nfsd4_minorversion_ops { | 1391 | struct nfsd4_minorversion_ops { |
1054 | nfsd4_dec *decoders; | 1392 | nfsd4_dec *decoders; |
1055 | int nops; | 1393 | int nops; |
@@ -1057,6 +1395,7 @@ struct nfsd4_minorversion_ops { | |||
1057 | 1395 | ||
1058 | static struct nfsd4_minorversion_ops nfsd4_minorversion[] = { | 1396 | static struct nfsd4_minorversion_ops nfsd4_minorversion[] = { |
1059 | [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) }, | 1397 | [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) }, |
1398 | [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) }, | ||
1060 | }; | 1399 | }; |
1061 | 1400 | ||
1062 | static __be32 | 1401 | static __be32 |
@@ -1412,6 +1751,7 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, | |||
1412 | { | 1751 | { |
1413 | u32 bmval0 = bmval[0]; | 1752 | u32 bmval0 = bmval[0]; |
1414 | u32 bmval1 = bmval[1]; | 1753 | u32 bmval1 = bmval[1]; |
1754 | u32 bmval2 = bmval[2]; | ||
1415 | struct kstat stat; | 1755 | struct kstat stat; |
1416 | struct svc_fh tempfh; | 1756 | struct svc_fh tempfh; |
1417 | struct kstatfs statfs; | 1757 | struct kstatfs statfs; |
@@ -1425,12 +1765,16 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, | |||
1425 | int err; | 1765 | int err; |
1426 | int aclsupport = 0; | 1766 | int aclsupport = 0; |
1427 | struct nfs4_acl *acl = NULL; | 1767 | struct nfs4_acl *acl = NULL; |
1768 | struct nfsd4_compoundres *resp = rqstp->rq_resp; | ||
1769 | u32 minorversion = resp->cstate.minorversion; | ||
1428 | 1770 | ||
1429 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); | 1771 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
1430 | BUG_ON(bmval0 & ~NFSD_SUPPORTED_ATTRS_WORD0); | 1772 | BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion)); |
1431 | BUG_ON(bmval1 & ~NFSD_SUPPORTED_ATTRS_WORD1); | 1773 | BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion)); |
1774 | BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion)); | ||
1432 | 1775 | ||
1433 | if (exp->ex_fslocs.migrated) { | 1776 | if (exp->ex_fslocs.migrated) { |
1777 | BUG_ON(bmval[2]); | ||
1434 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err); | 1778 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err); |
1435 | if (status) | 1779 | if (status) |
1436 | goto out; | 1780 | goto out; |
@@ -1476,22 +1820,42 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, | |||
1476 | if ((buflen -= 16) < 0) | 1820 | if ((buflen -= 16) < 0) |
1477 | goto out_resource; | 1821 | goto out_resource; |
1478 | 1822 | ||
1479 | WRITE32(2); | 1823 | if (unlikely(bmval2)) { |
1480 | WRITE32(bmval0); | 1824 | WRITE32(3); |
1481 | WRITE32(bmval1); | 1825 | WRITE32(bmval0); |
1826 | WRITE32(bmval1); | ||
1827 | WRITE32(bmval2); | ||
1828 | } else if (likely(bmval1)) { | ||
1829 | WRITE32(2); | ||
1830 | WRITE32(bmval0); | ||
1831 | WRITE32(bmval1); | ||
1832 | } else { | ||
1833 | WRITE32(1); | ||
1834 | WRITE32(bmval0); | ||
1835 | } | ||
1482 | attrlenp = p++; /* to be backfilled later */ | 1836 | attrlenp = p++; /* to be backfilled later */ |
1483 | 1837 | ||
1484 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { | 1838 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
1485 | u32 word0 = NFSD_SUPPORTED_ATTRS_WORD0; | 1839 | u32 word0 = nfsd_suppattrs0(minorversion); |
1840 | u32 word1 = nfsd_suppattrs1(minorversion); | ||
1841 | u32 word2 = nfsd_suppattrs2(minorversion); | ||
1842 | |||
1486 | if ((buflen -= 12) < 0) | 1843 | if ((buflen -= 12) < 0) |
1487 | goto out_resource; | 1844 | goto out_resource; |
1488 | if (!aclsupport) | 1845 | if (!aclsupport) |
1489 | word0 &= ~FATTR4_WORD0_ACL; | 1846 | word0 &= ~FATTR4_WORD0_ACL; |
1490 | if (!exp->ex_fslocs.locations) | 1847 | if (!exp->ex_fslocs.locations) |
1491 | word0 &= ~FATTR4_WORD0_FS_LOCATIONS; | 1848 | word0 &= ~FATTR4_WORD0_FS_LOCATIONS; |
1492 | WRITE32(2); | 1849 | if (!word2) { |
1493 | WRITE32(word0); | 1850 | WRITE32(2); |
1494 | WRITE32(NFSD_SUPPORTED_ATTRS_WORD1); | 1851 | WRITE32(word0); |
1852 | WRITE32(word1); | ||
1853 | } else { | ||
1854 | WRITE32(3); | ||
1855 | WRITE32(word0); | ||
1856 | WRITE32(word1); | ||
1857 | WRITE32(word2); | ||
1858 | } | ||
1495 | } | 1859 | } |
1496 | if (bmval0 & FATTR4_WORD0_TYPE) { | 1860 | if (bmval0 & FATTR4_WORD0_TYPE) { |
1497 | if ((buflen -= 4) < 0) | 1861 | if ((buflen -= 4) < 0) |
@@ -1801,6 +2165,13 @@ out_acl: | |||
1801 | } | 2165 | } |
1802 | WRITE64(stat.ino); | 2166 | WRITE64(stat.ino); |
1803 | } | 2167 | } |
2168 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { | ||
2169 | WRITE32(3); | ||
2170 | WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0); | ||
2171 | WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1); | ||
2172 | WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2); | ||
2173 | } | ||
2174 | |||
1804 | *attrlenp = htonl((char *)p - (char *)attrlenp - 4); | 2175 | *attrlenp = htonl((char *)p - (char *)attrlenp - 4); |
1805 | *countp = p - buffer; | 2176 | *countp = p - buffer; |
1806 | status = nfs_ok; | 2177 | status = nfs_ok; |
@@ -2572,6 +2943,143 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_w | |||
2572 | } | 2943 | } |
2573 | 2944 | ||
2574 | static __be32 | 2945 | static __be32 |
2946 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr, | ||
2947 | struct nfsd4_exchange_id *exid) | ||
2948 | { | ||
2949 | ENCODE_HEAD; | ||
2950 | char *major_id; | ||
2951 | char *server_scope; | ||
2952 | int major_id_sz; | ||
2953 | int server_scope_sz; | ||
2954 | uint64_t minor_id = 0; | ||
2955 | |||
2956 | if (nfserr) | ||
2957 | return nfserr; | ||
2958 | |||
2959 | major_id = utsname()->nodename; | ||
2960 | major_id_sz = strlen(major_id); | ||
2961 | server_scope = utsname()->nodename; | ||
2962 | server_scope_sz = strlen(server_scope); | ||
2963 | |||
2964 | RESERVE_SPACE( | ||
2965 | 8 /* eir_clientid */ + | ||
2966 | 4 /* eir_sequenceid */ + | ||
2967 | 4 /* eir_flags */ + | ||
2968 | 4 /* spr_how (SP4_NONE) */ + | ||
2969 | 8 /* so_minor_id */ + | ||
2970 | 4 /* so_major_id.len */ + | ||
2971 | (XDR_QUADLEN(major_id_sz) * 4) + | ||
2972 | 4 /* eir_server_scope.len */ + | ||
2973 | (XDR_QUADLEN(server_scope_sz) * 4) + | ||
2974 | 4 /* eir_server_impl_id.count (0) */); | ||
2975 | |||
2976 | WRITEMEM(&exid->clientid, 8); | ||
2977 | WRITE32(exid->seqid); | ||
2978 | WRITE32(exid->flags); | ||
2979 | |||
2980 | /* state_protect4_r. Currently only support SP4_NONE */ | ||
2981 | BUG_ON(exid->spa_how != SP4_NONE); | ||
2982 | WRITE32(exid->spa_how); | ||
2983 | |||
2984 | /* The server_owner struct */ | ||
2985 | WRITE64(minor_id); /* Minor id */ | ||
2986 | /* major id */ | ||
2987 | WRITE32(major_id_sz); | ||
2988 | WRITEMEM(major_id, major_id_sz); | ||
2989 | |||
2990 | /* Server scope */ | ||
2991 | WRITE32(server_scope_sz); | ||
2992 | WRITEMEM(server_scope, server_scope_sz); | ||
2993 | |||
2994 | /* Implementation id */ | ||
2995 | WRITE32(0); /* zero length nfs_impl_id4 array */ | ||
2996 | ADJUST_ARGS(); | ||
2997 | return 0; | ||
2998 | } | ||
2999 | |||
3000 | static __be32 | ||
3001 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr, | ||
3002 | struct nfsd4_create_session *sess) | ||
3003 | { | ||
3004 | ENCODE_HEAD; | ||
3005 | |||
3006 | if (nfserr) | ||
3007 | return nfserr; | ||
3008 | |||
3009 | RESERVE_SPACE(24); | ||
3010 | WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN); | ||
3011 | WRITE32(sess->seqid); | ||
3012 | WRITE32(sess->flags); | ||
3013 | ADJUST_ARGS(); | ||
3014 | |||
3015 | RESERVE_SPACE(28); | ||
3016 | WRITE32(0); /* headerpadsz */ | ||
3017 | WRITE32(sess->fore_channel.maxreq_sz); | ||
3018 | WRITE32(sess->fore_channel.maxresp_sz); | ||
3019 | WRITE32(sess->fore_channel.maxresp_cached); | ||
3020 | WRITE32(sess->fore_channel.maxops); | ||
3021 | WRITE32(sess->fore_channel.maxreqs); | ||
3022 | WRITE32(sess->fore_channel.nr_rdma_attrs); | ||
3023 | ADJUST_ARGS(); | ||
3024 | |||
3025 | if (sess->fore_channel.nr_rdma_attrs) { | ||
3026 | RESERVE_SPACE(4); | ||
3027 | WRITE32(sess->fore_channel.rdma_attrs); | ||
3028 | ADJUST_ARGS(); | ||
3029 | } | ||
3030 | |||
3031 | RESERVE_SPACE(28); | ||
3032 | WRITE32(0); /* headerpadsz */ | ||
3033 | WRITE32(sess->back_channel.maxreq_sz); | ||
3034 | WRITE32(sess->back_channel.maxresp_sz); | ||
3035 | WRITE32(sess->back_channel.maxresp_cached); | ||
3036 | WRITE32(sess->back_channel.maxops); | ||
3037 | WRITE32(sess->back_channel.maxreqs); | ||
3038 | WRITE32(sess->back_channel.nr_rdma_attrs); | ||
3039 | ADJUST_ARGS(); | ||
3040 | |||
3041 | if (sess->back_channel.nr_rdma_attrs) { | ||
3042 | RESERVE_SPACE(4); | ||
3043 | WRITE32(sess->back_channel.rdma_attrs); | ||
3044 | ADJUST_ARGS(); | ||
3045 | } | ||
3046 | return 0; | ||
3047 | } | ||
3048 | |||
3049 | static __be32 | ||
3050 | nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, | ||
3051 | struct nfsd4_destroy_session *destroy_session) | ||
3052 | { | ||
3053 | return nfserr; | ||
3054 | } | ||
3055 | |||
3056 | __be32 | ||
3057 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr, | ||
3058 | struct nfsd4_sequence *seq) | ||
3059 | { | ||
3060 | ENCODE_HEAD; | ||
3061 | |||
3062 | if (nfserr) | ||
3063 | return nfserr; | ||
3064 | |||
3065 | RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20); | ||
3066 | WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); | ||
3067 | WRITE32(seq->seqid); | ||
3068 | WRITE32(seq->slotid); | ||
3069 | WRITE32(seq->maxslots); | ||
3070 | /* | ||
3071 | * FIXME: for now: | ||
3072 | * target_maxslots = maxslots | ||
3073 | * status_flags = 0 | ||
3074 | */ | ||
3075 | WRITE32(seq->maxslots); | ||
3076 | WRITE32(0); | ||
3077 | |||
3078 | ADJUST_ARGS(); | ||
3079 | return 0; | ||
3080 | } | ||
3081 | |||
3082 | static __be32 | ||
2575 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) | 3083 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
2576 | { | 3084 | { |
2577 | return nfserr; | 3085 | return nfserr; |
@@ -2579,6 +3087,11 @@ nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) | |||
2579 | 3087 | ||
2580 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); | 3088 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
2581 | 3089 | ||
3090 | /* | ||
3091 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 | ||
3092 | * since we don't need to filter out obsolete ops as this is | ||
3093 | * done in the decoding phase. | ||
3094 | */ | ||
2582 | static nfsd4_enc nfsd4_enc_ops[] = { | 3095 | static nfsd4_enc nfsd4_enc_ops[] = { |
2583 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, | 3096 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
2584 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, | 3097 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
@@ -2617,8 +3130,77 @@ static nfsd4_enc nfsd4_enc_ops[] = { | |||
2617 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, | 3130 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
2618 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, | 3131 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
2619 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, | 3132 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
3133 | |||
3134 | /* NFSv4.1 operations */ | ||
3135 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, | ||
3136 | [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_noop, | ||
3137 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, | ||
3138 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, | ||
3139 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session, | ||
3140 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, | ||
3141 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, | ||
3142 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, | ||
3143 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, | ||
3144 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, | ||
3145 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, | ||
3146 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, | ||
3147 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_noop, | ||
3148 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, | ||
3149 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, | ||
3150 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_noop, | ||
3151 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, | ||
3152 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, | ||
3153 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, | ||
2620 | }; | 3154 | }; |
2621 | 3155 | ||
3156 | /* | ||
3157 | * Calculate the total amount of memory that the compound response has taken | ||
3158 | * after encoding the current operation. | ||
3159 | * | ||
3160 | * pad: add on 8 bytes for the next operation's op_code and status so that | ||
3161 | * there is room to cache a failure on the next operation. | ||
3162 | * | ||
3163 | * Compare this length to the session se_fmaxresp_cached. | ||
3164 | * | ||
3165 | * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so | ||
3166 | * will be at least a page and will therefore hold the xdr_buf head. | ||
3167 | */ | ||
3168 | static int nfsd4_check_drc_limit(struct nfsd4_compoundres *resp) | ||
3169 | { | ||
3170 | int status = 0; | ||
3171 | struct xdr_buf *xb = &resp->rqstp->rq_res; | ||
3172 | struct nfsd4_compoundargs *args = resp->rqstp->rq_argp; | ||
3173 | struct nfsd4_session *session = NULL; | ||
3174 | struct nfsd4_slot *slot = resp->cstate.slot; | ||
3175 | u32 length, tlen = 0, pad = 8; | ||
3176 | |||
3177 | if (!nfsd4_has_session(&resp->cstate)) | ||
3178 | return status; | ||
3179 | |||
3180 | session = resp->cstate.session; | ||
3181 | if (session == NULL || slot->sl_cache_entry.ce_cachethis == 0) | ||
3182 | return status; | ||
3183 | |||
3184 | if (resp->opcnt >= args->opcnt) | ||
3185 | pad = 0; /* this is the last operation */ | ||
3186 | |||
3187 | if (xb->page_len == 0) { | ||
3188 | length = (char *)resp->p - (char *)xb->head[0].iov_base + pad; | ||
3189 | } else { | ||
3190 | if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0) | ||
3191 | tlen = (char *)resp->p - (char *)xb->tail[0].iov_base; | ||
3192 | |||
3193 | length = xb->head[0].iov_len + xb->page_len + tlen + pad; | ||
3194 | } | ||
3195 | dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__, | ||
3196 | length, xb->page_len, tlen, pad); | ||
3197 | |||
3198 | if (length <= session->se_fmaxresp_cached) | ||
3199 | return status; | ||
3200 | else | ||
3201 | return nfserr_rep_too_big_to_cache; | ||
3202 | } | ||
3203 | |||
2622 | void | 3204 | void |
2623 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) | 3205 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
2624 | { | 3206 | { |
@@ -2635,6 +3217,9 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) | |||
2635 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || | 3217 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
2636 | !nfsd4_enc_ops[op->opnum]); | 3218 | !nfsd4_enc_ops[op->opnum]); |
2637 | op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u); | 3219 | op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u); |
3220 | /* nfsd4_check_drc_limit guarantees enough room for error status */ | ||
3221 | if (!op->status && nfsd4_check_drc_limit(resp)) | ||
3222 | op->status = nfserr_rep_too_big_to_cache; | ||
2638 | status: | 3223 | status: |
2639 | /* | 3224 | /* |
2640 | * Note: We write the status directly, instead of using WRITE32(), | 3225 | * Note: We write the status directly, instead of using WRITE32(), |
@@ -2735,6 +3320,18 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo | |||
2735 | iov = &rqstp->rq_res.head[0]; | 3320 | iov = &rqstp->rq_res.head[0]; |
2736 | iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; | 3321 | iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; |
2737 | BUG_ON(iov->iov_len > PAGE_SIZE); | 3322 | BUG_ON(iov->iov_len > PAGE_SIZE); |
3323 | if (nfsd4_has_session(&resp->cstate)) { | ||
3324 | if (resp->cstate.status == nfserr_replay_cache && | ||
3325 | !nfsd4_not_cached(resp)) { | ||
3326 | iov->iov_len = resp->cstate.iovlen; | ||
3327 | } else { | ||
3328 | nfsd4_store_cache_entry(resp); | ||
3329 | dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__); | ||
3330 | resp->cstate.slot->sl_inuse = 0; | ||
3331 | } | ||
3332 | if (resp->cstate.session) | ||
3333 | nfsd4_put_session(resp->cstate.session); | ||
3334 | } | ||
2738 | return 1; | 3335 | return 1; |
2739 | } | 3336 | } |
2740 | 3337 | ||