Commit 60267ba3 authored by Ilya Dryomov's avatar Ilya Dryomov

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: 4f1ddb1e ("ceph: implement updated ceph_mds_request_head structure")
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
parent 5c8fe583
...@@ -2475,6 +2475,22 @@ static int set_request_path_attr(struct inode *rinode, struct dentry *rdentry, ...@@ -2475,6 +2475,22 @@ static int set_request_path_attr(struct inode *rinode, struct dentry *rdentry,
return r; return r;
} }
static void encode_timestamp_and_gids(void **p,
const struct ceph_mds_request *req)
{
struct ceph_timespec ts;
int i;
ceph_encode_timespec64(&ts, &req->r_stamp);
ceph_encode_copy(p, &ts, sizeof(ts));
/* gid_list */
ceph_encode_32(p, req->r_cred->group_info->ngroups);
for (i = 0; i < req->r_cred->group_info->ngroups; i++)
ceph_encode_64(p, from_kgid(&init_user_ns,
req->r_cred->group_info->gid[i]));
}
/* /*
* called under mdsc->mutex * called under mdsc->mutex
*/ */
...@@ -2491,7 +2507,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, ...@@ -2491,7 +2507,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
u64 ino1 = 0, ino2 = 0; u64 ino1 = 0, ino2 = 0;
int pathlen1 = 0, pathlen2 = 0; int pathlen1 = 0, pathlen2 = 0;
bool freepath1 = false, freepath2 = false; bool freepath1 = false, freepath2 = false;
int len, i; int len;
u16 releases; u16 releases;
void *p, *end; void *p, *end;
int ret; int ret;
...@@ -2517,17 +2533,10 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, ...@@ -2517,17 +2533,10 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
goto out_free1; goto out_free1;
} }
if (legacy) { len = legacy ? sizeof(*head) : sizeof(struct ceph_mds_request_head);
/* Old style */
len = sizeof(*head);
} else {
/* New style: add gid_list and any later fields */
len = sizeof(struct ceph_mds_request_head) + sizeof(u32) +
(sizeof(u64) * req->r_cred->group_info->ngroups);
}
len += pathlen1 + pathlen2 + 2*(1 + sizeof(u32) + sizeof(u64)) + len += pathlen1 + pathlen2 + 2*(1 + sizeof(u32) + sizeof(u64)) +
sizeof(struct ceph_timespec); sizeof(struct ceph_timespec);
len += sizeof(u32) + (sizeof(u64) * req->r_cred->group_info->ngroups);
/* calculate (max) length for cap releases */ /* calculate (max) length for cap releases */
len += sizeof(struct ceph_mds_request_release) * len += sizeof(struct ceph_mds_request_release) *
...@@ -2548,7 +2557,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, ...@@ -2548,7 +2557,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
msg->hdr.tid = cpu_to_le64(req->r_tid); msg->hdr.tid = cpu_to_le64(req->r_tid);
/* /*
* The old ceph_mds_request_header didn't contain a version field, and * The old ceph_mds_request_head didn't contain a version field, and
* one was added when we moved the message version from 3->4. * one was added when we moved the message version from 3->4.
*/ */
if (legacy) { if (legacy) {
...@@ -2609,20 +2618,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session, ...@@ -2609,20 +2618,7 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
head->num_releases = cpu_to_le16(releases); head->num_releases = cpu_to_le16(releases);
/* time stamp */ encode_timestamp_and_gids(&p, req);
{
struct ceph_timespec ts;
ceph_encode_timespec64(&ts, &req->r_stamp);
ceph_encode_copy(&p, &ts, sizeof(ts));
}
/* gid list */
if (!legacy) {
ceph_encode_32(&p, req->r_cred->group_info->ngroups);
for (i = 0; i < req->r_cred->group_info->ngroups; i++)
ceph_encode_64(&p, from_kgid(&init_user_ns,
req->r_cred->group_info->gid[i]));
}
if (WARN_ON_ONCE(p > end)) { if (WARN_ON_ONCE(p > end)) {
ceph_msg_put(msg); ceph_msg_put(msg);
...@@ -2730,13 +2726,8 @@ static int __prepare_send_request(struct ceph_mds_session *session, ...@@ -2730,13 +2726,8 @@ static int __prepare_send_request(struct ceph_mds_session *session,
/* remove cap/dentry releases from message */ /* remove cap/dentry releases from message */
rhead->num_releases = 0; rhead->num_releases = 0;
/* time stamp */
p = msg->front.iov_base + req->r_request_release_offset; p = msg->front.iov_base + req->r_request_release_offset;
{ encode_timestamp_and_gids(&p, req);
struct ceph_timespec ts;
ceph_encode_timespec64(&ts, &req->r_stamp);
ceph_encode_copy(&p, &ts, sizeof(ts));
}
msg->front.iov_len = p - msg->front.iov_base; msg->front.iov_len = p - msg->front.iov_base;
msg->hdr.front_len = cpu_to_le32(msg->front.iov_len); msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment