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.

ceph: reencode gid_list when reconnecting

On reconnect, cap and dentry releases are dropped and the fields
that follow must be reencoded into the freed space. Currently these
are timestamp and gid_list, but gid_list isn't reencoded. This
results in

failed to decode message of type 24 v4: End of buffer

errors on the MDS.

While at it, make a change to encode gid_list unconditionally,
without regard to what head/which version was used as a result
of checking whether CEPH_FEATURE_FS_BTIME is supported or not.

URL: https://tracker.ceph.com/issues/48618
Fixes: 4f1ddb1ea874 ("ceph: implement updated ceph_mds_request_head structure")
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>

+22 -31
+22 -31
fs/ceph/mds_client.c
··· 2475 2475 return r; 2476 2476 } 2477 2477 2478 + static void encode_timestamp_and_gids(void **p, 2479 + const struct ceph_mds_request *req) 2480 + { 2481 + struct ceph_timespec ts; 2482 + int i; 2483 + 2484 + ceph_encode_timespec64(&ts, &req->r_stamp); 2485 + ceph_encode_copy(p, &ts, sizeof(ts)); 2486 + 2487 + /* gid_list */ 2488 + ceph_encode_32(p, req->r_cred->group_info->ngroups); 2489 + for (i = 0; i < req->r_cred->group_info->ngroups; i++) 2490 + ceph_encode_64(p, from_kgid(&init_user_ns, 2491 + req->r_cred->group_info->gid[i])); 2492 + } 2493 + 2478 2494 /* 2479 2495 * called under mdsc->mutex 2480 2496 */ ··· 2507 2491 u64 ino1 = 0, ino2 = 0; 2508 2492 int pathlen1 = 0, pathlen2 = 0; 2509 2493 bool freepath1 = false, freepath2 = false; 2510 - int len, i; 2494 + int len; 2511 2495 u16 releases; 2512 2496 void *p, *end; 2513 2497 int ret; ··· 2533 2517 goto out_free1; 2534 2518 } 2535 2519 2536 - if (legacy) { 2537 - /* Old style */ 2538 - len = sizeof(*head); 2539 - } else { 2540 - /* New style: add gid_list and any later fields */ 2541 - len = sizeof(struct ceph_mds_request_head) + sizeof(u32) + 2542 - (sizeof(u64) * req->r_cred->group_info->ngroups); 2543 - } 2544 - 2520 + len = legacy ? sizeof(*head) : sizeof(struct ceph_mds_request_head); 2545 2521 len += pathlen1 + pathlen2 + 2*(1 + sizeof(u32) + sizeof(u64)) + 2546 2522 sizeof(struct ceph_timespec); 2523 + len += sizeof(u32) + (sizeof(u64) * req->r_cred->group_info->ngroups); 2547 2524 2548 2525 /* calculate (max) length for cap releases */ 2549 2526 len += sizeof(struct ceph_mds_request_release) * ··· 2557 2548 msg->hdr.tid = cpu_to_le64(req->r_tid); 2558 2549 2559 2550 /* 2560 - * The old ceph_mds_request_header didn't contain a version field, and 2551 + * The old ceph_mds_request_head didn't contain a version field, and 2561 2552 * one was added when we moved the message version from 3->4. 2562 2553 */ 2563 2554 if (legacy) { ··· 2618 2609 2619 2610 head->num_releases = cpu_to_le16(releases); 2620 2611 2621 - /* time stamp */ 2622 - { 2623 - struct ceph_timespec ts; 2624 - ceph_encode_timespec64(&ts, &req->r_stamp); 2625 - ceph_encode_copy(&p, &ts, sizeof(ts)); 2626 - } 2627 - 2628 - /* gid list */ 2629 - if (!legacy) { 2630 - ceph_encode_32(&p, req->r_cred->group_info->ngroups); 2631 - for (i = 0; i < req->r_cred->group_info->ngroups; i++) 2632 - ceph_encode_64(&p, from_kgid(&init_user_ns, 2633 - req->r_cred->group_info->gid[i])); 2634 - } 2612 + encode_timestamp_and_gids(&p, req); 2635 2613 2636 2614 if (WARN_ON_ONCE(p > end)) { 2637 2615 ceph_msg_put(msg); ··· 2726 2730 /* remove cap/dentry releases from message */ 2727 2731 rhead->num_releases = 0; 2728 2732 2729 - /* time stamp */ 2730 2733 p = msg->front.iov_base + req->r_request_release_offset; 2731 - { 2732 - struct ceph_timespec ts; 2733 - ceph_encode_timespec64(&ts, &req->r_stamp); 2734 - ceph_encode_copy(&p, &ts, sizeof(ts)); 2735 - } 2734 + encode_timestamp_and_gids(&p, req); 2736 2735 2737 2736 msg->front.iov_len = p - msg->front.iov_base; 2738 2737 msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);