Skip to content

Commit 9ba1e22

Browse files
lxbszidryomov
authored andcommitted
ceph: allocate the correct amount of extra bytes for the session features
The total bytes may potentially be larger than 8. Signed-off-by: Xiubo Li <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 5b3248c commit 9ba1e22

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

fs/ceph/mds_client.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/debugfs.h>
1010
#include <linux/seq_file.h>
1111
#include <linux/ratelimit.h>
12+
#include <linux/bits.h>
1213

1314
#include "super.h"
1415
#include "mds_client.h"
@@ -1057,20 +1058,21 @@ static struct ceph_msg *create_session_msg(u32 op, u64 seq)
10571058
return msg;
10581059
}
10591060

1061+
static const unsigned char feature_bits[] = CEPHFS_FEATURES_CLIENT_SUPPORTED;
1062+
#define FEATURE_BYTES(c) (DIV_ROUND_UP((size_t)feature_bits[c - 1] + 1, 64) * 8)
10601063
static void encode_supported_features(void **p, void *end)
10611064
{
1062-
static const unsigned char bits[] = CEPHFS_FEATURES_CLIENT_SUPPORTED;
1063-
static const size_t count = ARRAY_SIZE(bits);
1065+
static const size_t count = ARRAY_SIZE(feature_bits);
10641066

10651067
if (count > 0) {
10661068
size_t i;
1067-
size_t size = ((size_t)bits[count - 1] + 64) / 64 * 8;
1069+
size_t size = FEATURE_BYTES(count);
10681070

10691071
BUG_ON(*p + 4 + size > end);
10701072
ceph_encode_32(p, size);
10711073
memset(*p, 0, size);
10721074
for (i = 0; i < count; i++)
1073-
((unsigned char*)(*p))[i / 8] |= 1 << (bits[i] % 8);
1075+
((unsigned char*)(*p))[i / 8] |= BIT(feature_bits[i] % 8);
10741076
*p += size;
10751077
} else {
10761078
BUG_ON(*p + 4 > end);
@@ -1091,6 +1093,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
10911093
int metadata_key_count = 0;
10921094
struct ceph_options *opt = mdsc->fsc->client->options;
10931095
struct ceph_mount_options *fsopt = mdsc->fsc->mount_options;
1096+
size_t size, count;
10941097
void *p, *end;
10951098

10961099
const char* metadata[][2] = {
@@ -1108,8 +1111,13 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
11081111
strlen(metadata[i][1]);
11091112
metadata_key_count++;
11101113
}
1114+
11111115
/* supported feature */
1112-
extra_bytes += 4 + 8;
1116+
size = 0;
1117+
count = ARRAY_SIZE(feature_bits);
1118+
if (count > 0)
1119+
size = FEATURE_BYTES(count);
1120+
extra_bytes += 4 + size;
11131121

11141122
/* Allocate the message */
11151123
msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + extra_bytes,
@@ -1129,7 +1137,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
11291137
* Serialize client metadata into waiting buffer space, using
11301138
* the format that userspace expects for map<string, string>
11311139
*
1132-
* ClientSession messages with metadata are v2
1140+
* ClientSession messages with metadata are v3
11331141
*/
11341142
msg->hdr.version = cpu_to_le16(3);
11351143
msg->hdr.compat_version = cpu_to_le16(1);

fs/ceph/mds_client.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
#include <linux/ceph/auth.h>
1818

1919
/* The first 8 bits are reserved for old ceph releases */
20-
#define CEPHFS_FEATURE_MIMIC 8
21-
#define CEPHFS_FEATURE_REPLY_ENCODING 9
22-
#define CEPHFS_FEATURE_RECLAIM_CLIENT 10
23-
#define CEPHFS_FEATURE_LAZY_CAP_WANTED 11
24-
#define CEPHFS_FEATURE_MULTI_RECONNECT 12
20+
enum ceph_feature_type {
21+
CEPHFS_FEATURE_MIMIC = 8,
22+
CEPHFS_FEATURE_REPLY_ENCODING,
23+
CEPHFS_FEATURE_RECLAIM_CLIENT,
24+
CEPHFS_FEATURE_LAZY_CAP_WANTED,
25+
CEPHFS_FEATURE_MULTI_RECONNECT,
26+
27+
CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_MULTI_RECONNECT,
28+
};
2529

26-
#define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
30+
/*
31+
* This will always have the highest feature bit value
32+
* as the last element of the array.
33+
*/
34+
#define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
2735
0, 1, 2, 3, 4, 5, 6, 7, \
2836
CEPHFS_FEATURE_MIMIC, \
2937
CEPHFS_FEATURE_REPLY_ENCODING, \
3038
CEPHFS_FEATURE_LAZY_CAP_WANTED, \
3139
CEPHFS_FEATURE_MULTI_RECONNECT, \
40+
\
41+
CEPHFS_FEATURE_MAX, \
3242
}
3343
#define CEPHFS_FEATURES_CLIENT_REQUIRED {}
3444

35-
3645
/*
3746
* Some lock dependencies:
3847
*

0 commit comments

Comments
 (0)