Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

NFSv4.2: Clean up: move decode_*xattr() functions

Move them out of the encode_*() section and into the decode_*() section
where it belongs.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Anna Schumaker and committed by
Trond Myklebust
04b4c9fb fd42ba82

+162 -164
+162 -164
fs/nfs/nfs42xdr.c
··· 464 464 xdr_write_pages(xdr, arg->xattr_pages, 0, arg->xattr_len); 465 465 } 466 466 467 - static int decode_setxattr(struct xdr_stream *xdr, 468 - struct nfs4_change_info *cinfo) 469 - { 470 - int status; 471 - 472 - status = decode_op_hdr(xdr, OP_SETXATTR); 473 - if (status) 474 - goto out; 475 - status = decode_change_info(xdr, cinfo); 476 - out: 477 - return status; 478 - } 479 - 480 - 481 467 static void encode_getxattr(struct xdr_stream *xdr, const char *name, 482 468 struct compound_hdr *hdr) 483 469 { ··· 471 485 encode_string(xdr, strlen(name), name); 472 486 } 473 487 474 - static int decode_getxattr(struct xdr_stream *xdr, 475 - struct nfs42_getxattrres *res, 476 - struct rpc_rqst *req) 477 - { 478 - int status; 479 - __be32 *p; 480 - u32 len, rdlen; 481 - 482 - status = decode_op_hdr(xdr, OP_GETXATTR); 483 - if (status) 484 - return status; 485 - 486 - p = xdr_inline_decode(xdr, 4); 487 - if (unlikely(!p)) 488 - return -EIO; 489 - 490 - len = be32_to_cpup(p); 491 - 492 - /* 493 - * Only check against the page length here. The actual 494 - * requested length may be smaller, but that is only 495 - * checked against after possibly caching a valid reply. 496 - */ 497 - if (len > req->rq_rcv_buf.page_len) 498 - return -ERANGE; 499 - 500 - res->xattr_len = len; 501 - 502 - if (len > 0) { 503 - rdlen = xdr_read_pages(xdr, len); 504 - if (rdlen < len) 505 - return -EIO; 506 - } 507 - 508 - return 0; 509 - } 510 - 511 488 static void encode_removexattr(struct xdr_stream *xdr, const char *name, 512 489 struct compound_hdr *hdr) 513 490 { 514 491 encode_op_hdr(xdr, OP_REMOVEXATTR, decode_removexattr_maxsz, hdr); 515 492 encode_string(xdr, strlen(name), name); 516 - } 517 - 518 - 519 - static int decode_removexattr(struct xdr_stream *xdr, 520 - struct nfs4_change_info *cinfo) 521 - { 522 - int status; 523 - 524 - status = decode_op_hdr(xdr, OP_REMOVEXATTR); 525 - if (status) 526 - goto out; 527 - 528 - status = decode_change_info(xdr, cinfo); 529 - out: 530 - return status; 531 493 } 532 494 533 495 static void encode_listxattrs(struct xdr_stream *xdr, ··· 497 563 * plus the EOF marker. So, add the cookie and the names count. 498 564 */ 499 565 *p = cpu_to_be32(arg->count + 8 + 4); 500 - } 501 - 502 - static int decode_listxattrs(struct xdr_stream *xdr, 503 - struct nfs42_listxattrsres *res) 504 - { 505 - int status; 506 - __be32 *p; 507 - u32 count, len, ulen; 508 - size_t left, copied; 509 - char *buf; 510 - 511 - status = decode_op_hdr(xdr, OP_LISTXATTRS); 512 - if (status) { 513 - /* 514 - * Special case: for LISTXATTRS, NFS4ERR_TOOSMALL 515 - * should be translated to ERANGE. 516 - */ 517 - if (status == -ETOOSMALL) 518 - status = -ERANGE; 519 - /* 520 - * Special case: for LISTXATTRS, NFS4ERR_NOXATTR 521 - * should be translated to success with zero-length reply. 522 - */ 523 - if (status == -ENODATA) { 524 - res->eof = true; 525 - status = 0; 526 - } 527 - goto out; 528 - } 529 - 530 - p = xdr_inline_decode(xdr, 8); 531 - if (unlikely(!p)) 532 - return -EIO; 533 - 534 - xdr_decode_hyper(p, &res->cookie); 535 - 536 - p = xdr_inline_decode(xdr, 4); 537 - if (unlikely(!p)) 538 - return -EIO; 539 - 540 - left = res->xattr_len; 541 - buf = res->xattr_buf; 542 - 543 - count = be32_to_cpup(p); 544 - copied = 0; 545 - 546 - /* 547 - * We have asked for enough room to encode the maximum number 548 - * of possible attribute names, so everything should fit. 549 - * 550 - * But, don't rely on that assumption. Just decode entries 551 - * until they don't fit anymore, just in case the server did 552 - * something odd. 553 - */ 554 - while (count--) { 555 - p = xdr_inline_decode(xdr, 4); 556 - if (unlikely(!p)) 557 - return -EIO; 558 - 559 - len = be32_to_cpup(p); 560 - if (len > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) { 561 - status = -ERANGE; 562 - goto out; 563 - } 564 - 565 - p = xdr_inline_decode(xdr, len); 566 - if (unlikely(!p)) 567 - return -EIO; 568 - 569 - ulen = len + XATTR_USER_PREFIX_LEN + 1; 570 - if (buf) { 571 - if (ulen > left) { 572 - status = -ERANGE; 573 - goto out; 574 - } 575 - 576 - memcpy(buf, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 577 - memcpy(buf + XATTR_USER_PREFIX_LEN, p, len); 578 - 579 - buf[ulen - 1] = 0; 580 - buf += ulen; 581 - left -= ulen; 582 - } 583 - copied += ulen; 584 - } 585 - 586 - p = xdr_inline_decode(xdr, 4); 587 - if (unlikely(!p)) 588 - return -EIO; 589 - 590 - res->eof = be32_to_cpup(p); 591 - res->copied = copied; 592 - 593 - out: 594 - if (status == -ERANGE && res->xattr_len == XATTR_LIST_MAX) 595 - status = -E2BIG; 596 - 597 - return status; 598 566 } 599 567 600 568 /* ··· 1026 1190 static int decode_layouterror(struct xdr_stream *xdr) 1027 1191 { 1028 1192 return decode_op_hdr(xdr, OP_LAYOUTERROR); 1193 + } 1194 + 1195 + static int decode_setxattr(struct xdr_stream *xdr, 1196 + struct nfs4_change_info *cinfo) 1197 + { 1198 + int status; 1199 + 1200 + status = decode_op_hdr(xdr, OP_SETXATTR); 1201 + if (status) 1202 + goto out; 1203 + status = decode_change_info(xdr, cinfo); 1204 + out: 1205 + return status; 1206 + } 1207 + 1208 + static int decode_getxattr(struct xdr_stream *xdr, 1209 + struct nfs42_getxattrres *res, 1210 + struct rpc_rqst *req) 1211 + { 1212 + int status; 1213 + __be32 *p; 1214 + u32 len, rdlen; 1215 + 1216 + status = decode_op_hdr(xdr, OP_GETXATTR); 1217 + if (status) 1218 + return status; 1219 + 1220 + p = xdr_inline_decode(xdr, 4); 1221 + if (unlikely(!p)) 1222 + return -EIO; 1223 + 1224 + len = be32_to_cpup(p); 1225 + 1226 + /* 1227 + * Only check against the page length here. The actual 1228 + * requested length may be smaller, but that is only 1229 + * checked against after possibly caching a valid reply. 1230 + */ 1231 + if (len > req->rq_rcv_buf.page_len) 1232 + return -ERANGE; 1233 + 1234 + res->xattr_len = len; 1235 + 1236 + if (len > 0) { 1237 + rdlen = xdr_read_pages(xdr, len); 1238 + if (rdlen < len) 1239 + return -EIO; 1240 + } 1241 + 1242 + return 0; 1243 + } 1244 + 1245 + static int decode_removexattr(struct xdr_stream *xdr, 1246 + struct nfs4_change_info *cinfo) 1247 + { 1248 + int status; 1249 + 1250 + status = decode_op_hdr(xdr, OP_REMOVEXATTR); 1251 + if (status) 1252 + goto out; 1253 + 1254 + status = decode_change_info(xdr, cinfo); 1255 + out: 1256 + return status; 1257 + } 1258 + 1259 + static int decode_listxattrs(struct xdr_stream *xdr, 1260 + struct nfs42_listxattrsres *res) 1261 + { 1262 + int status; 1263 + __be32 *p; 1264 + u32 count, len, ulen; 1265 + size_t left, copied; 1266 + char *buf; 1267 + 1268 + status = decode_op_hdr(xdr, OP_LISTXATTRS); 1269 + if (status) { 1270 + /* 1271 + * Special case: for LISTXATTRS, NFS4ERR_TOOSMALL 1272 + * should be translated to ERANGE. 1273 + */ 1274 + if (status == -ETOOSMALL) 1275 + status = -ERANGE; 1276 + /* 1277 + * Special case: for LISTXATTRS, NFS4ERR_NOXATTR 1278 + * should be translated to success with zero-length reply. 1279 + */ 1280 + if (status == -ENODATA) { 1281 + res->eof = true; 1282 + status = 0; 1283 + } 1284 + goto out; 1285 + } 1286 + 1287 + p = xdr_inline_decode(xdr, 8); 1288 + if (unlikely(!p)) 1289 + return -EIO; 1290 + 1291 + xdr_decode_hyper(p, &res->cookie); 1292 + 1293 + p = xdr_inline_decode(xdr, 4); 1294 + if (unlikely(!p)) 1295 + return -EIO; 1296 + 1297 + left = res->xattr_len; 1298 + buf = res->xattr_buf; 1299 + 1300 + count = be32_to_cpup(p); 1301 + copied = 0; 1302 + 1303 + /* 1304 + * We have asked for enough room to encode the maximum number 1305 + * of possible attribute names, so everything should fit. 1306 + * 1307 + * But, don't rely on that assumption. Just decode entries 1308 + * until they don't fit anymore, just in case the server did 1309 + * something odd. 1310 + */ 1311 + while (count--) { 1312 + p = xdr_inline_decode(xdr, 4); 1313 + if (unlikely(!p)) 1314 + return -EIO; 1315 + 1316 + len = be32_to_cpup(p); 1317 + if (len > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) { 1318 + status = -ERANGE; 1319 + goto out; 1320 + } 1321 + 1322 + p = xdr_inline_decode(xdr, len); 1323 + if (unlikely(!p)) 1324 + return -EIO; 1325 + 1326 + ulen = len + XATTR_USER_PREFIX_LEN + 1; 1327 + if (buf) { 1328 + if (ulen > left) { 1329 + status = -ERANGE; 1330 + goto out; 1331 + } 1332 + 1333 + memcpy(buf, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); 1334 + memcpy(buf + XATTR_USER_PREFIX_LEN, p, len); 1335 + 1336 + buf[ulen - 1] = 0; 1337 + buf += ulen; 1338 + left -= ulen; 1339 + } 1340 + copied += ulen; 1341 + } 1342 + 1343 + p = xdr_inline_decode(xdr, 4); 1344 + if (unlikely(!p)) 1345 + return -EIO; 1346 + 1347 + res->eof = be32_to_cpup(p); 1348 + res->copied = copied; 1349 + 1350 + out: 1351 + if (status == -ERANGE && res->xattr_len == XATTR_LIST_MAX) 1352 + status = -E2BIG; 1353 + 1354 + return status; 1029 1355 } 1030 1356 1031 1357 /*