Skip to content

Commit b38c9eb

Browse files
xiubliidryomov
authored andcommitted
ceph: add possible_max_rank and make the code more readable
The m_num_mds here is actually the number for MDSs which are in up:active status, and it will be duplicated to m_num_active_mds, so remove it. Add possible_max_rank to the mdsmap struct and this will be the correctly possible largest rank boundary. Remove the special case for one mds in __mdsmap_get_random_mds(), because the validate mds rank may not always be 0. Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 0eb3085 commit b38c9eb

4 files changed

Lines changed: 31 additions & 40 deletions

File tree

‎fs/ceph/debugfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int mdsmap_show(struct seq_file *s, void *p)
3333
seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
3434
seq_printf(s, "session_timeout %d\n", mdsmap->m_session_timeout);
3535
seq_printf(s, "session_autoclose %d\n", mdsmap->m_session_autoclose);
36-
for (i = 0; i < mdsmap->m_num_mds; i++) {
36+
for (i = 0; i < mdsmap->possible_max_rank; i++) {
3737
struct ceph_entity_addr *addr = &mdsmap->m_info[i].addr;
3838
int state = mdsmap->m_info[i].state;
3939
seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,

‎fs/ceph/mds_client.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,
598598
{
599599
struct ceph_mds_session *s;
600600

601-
if (mds >= mdsc->mdsmap->m_num_mds)
601+
if (mds >= mdsc->mdsmap->possible_max_rank)
602602
return ERR_PTR(-EINVAL);
603603

604604
s = kzalloc(sizeof(*s), GFP_NOFS);
@@ -1231,7 +1231,7 @@ static void __open_export_target_sessions(struct ceph_mds_client *mdsc,
12311231
struct ceph_mds_session *ts;
12321232
int i, mds = session->s_mds;
12331233

1234-
if (mds >= mdsc->mdsmap->m_num_mds)
1234+
if (mds >= mdsc->mdsmap->possible_max_rank)
12351235
return;
12361236

12371237
mi = &mdsc->mdsmap->m_info[mds];
@@ -3785,7 +3785,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
37853785
dout("check_new_map new %u old %u\n",
37863786
newmap->m_epoch, oldmap->m_epoch);
37873787

3788-
for (i = 0; i < oldmap->m_num_mds && i < mdsc->max_sessions; i++) {
3788+
for (i = 0; i < oldmap->possible_max_rank && i < mdsc->max_sessions; i++) {
37893789
if (!mdsc->sessions[i])
37903790
continue;
37913791
s = mdsc->sessions[i];
@@ -3799,7 +3799,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
37993799
ceph_mdsmap_is_laggy(newmap, i) ? " (laggy)" : "",
38003800
ceph_session_state_name(s->s_state));
38013801

3802-
if (i >= newmap->m_num_mds) {
3802+
if (i >= newmap->possible_max_rank) {
38033803
/* force close session for stopped mds */
38043804
get_session(s);
38053805
__unregister_session(mdsc, s);
@@ -3856,7 +3856,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,
38563856
}
38573857
}
38583858

3859-
for (i = 0; i < newmap->m_num_mds && i < mdsc->max_sessions; i++) {
3859+
for (i = 0; i < newmap->possible_max_rank && i < mdsc->max_sessions; i++) {
38603860
s = mdsc->sessions[i];
38613861
if (!s)
38623862
continue;

‎fs/ceph/mdsmap.c‎

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,23 @@
1414
#include "super.h"
1515

1616
#define CEPH_MDS_IS_READY(i, ignore_laggy) \
17-
(m->m_info[i].state > 0 && (ignore_laggy ? true : !m->m_info[i].laggy))
17+
(m->m_info[i].state > 0 && ignore_laggy ? true : !m->m_info[i].laggy)
1818

1919
static int __mdsmap_get_random_mds(struct ceph_mdsmap *m, bool ignore_laggy)
2020
{
2121
int n = 0;
2222
int i, j;
2323

24-
/*
25-
* special case for one mds, no matter it is laggy or
26-
* not we have no choice
27-
*/
28-
if (1 == m->m_num_mds && m->m_info[0].state > 0)
29-
return 0;
30-
3124
/* count */
32-
for (i = 0; i < m->m_num_mds; i++)
25+
for (i = 0; i < m->possible_max_rank; i++)
3326
if (CEPH_MDS_IS_READY(i, ignore_laggy))
3427
n++;
3528
if (n == 0)
3629
return -1;
3730

3831
/* pick */
3932
n = prandom_u32() % n;
40-
for (j = 0, i = 0; i < m->m_num_mds; i++) {
33+
for (j = 0, i = 0; i < m->possible_max_rank; i++) {
4134
if (CEPH_MDS_IS_READY(i, ignore_laggy))
4235
j++;
4336
if (j > n)
@@ -55,10 +48,10 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
5548
int mds;
5649

5750
mds = __mdsmap_get_random_mds(m, false);
58-
if (mds == m->m_num_mds || mds == -1)
51+
if (mds == m->possible_max_rank || mds == -1)
5952
mds = __mdsmap_get_random_mds(m, true);
6053

61-
return mds == m->m_num_mds ? -1 : mds;
54+
return mds == m->possible_max_rank ? -1 : mds;
6255
}
6356

6457
#define __decode_and_drop_type(p, end, type, bad) \
@@ -129,7 +122,6 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
129122
int err;
130123
u8 mdsmap_v, mdsmap_cv;
131124
u16 mdsmap_ev;
132-
u32 possible_max_rank;
133125

134126
m = kzalloc(sizeof(*m), GFP_NOFS);
135127
if (!m)
@@ -157,24 +149,23 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
157149
m->m_max_mds = ceph_decode_32(p);
158150

159151
/*
160-
* pick out the active nodes as the m_num_mds, the m_num_mds
161-
* maybe larger than m_max_mds when decreasing the max_mds in
162-
* cluster side, in other case it should less than or equal
163-
* to m_max_mds.
152+
* pick out the active nodes as the m_num_active_mds, the
153+
* m_num_active_mds maybe larger than m_max_mds when decreasing
154+
* the max_mds in cluster side, in other case it should less
155+
* than or equal to m_max_mds.
164156
*/
165-
m->m_num_mds = n = ceph_decode_32(p);
166-
m->m_num_active_mds = m->m_num_mds;
157+
m->m_num_active_mds = n = ceph_decode_32(p);
167158

168159
/*
169-
* the possible max rank, it maybe larger than the m->m_num_mds,
160+
* the possible max rank, it maybe larger than the m_num_active_mds,
170161
* for example if the mds_max == 2 in the cluster, when the MDS(0)
171162
* was laggy and being replaced by a new MDS, we will temporarily
172163
* receive a new mds map with n_num_mds == 1 and the active MDS(1),
173-
* and the mds rank >= m->m_num_mds.
164+
* and the mds rank >= m_num_active_mds.
174165
*/
175-
possible_max_rank = max((u32)m->m_num_mds, m->m_max_mds);
166+
m->possible_max_rank = max(m->m_num_active_mds, m->m_max_mds);
176167

177-
m->m_info = kcalloc(m->m_num_mds, sizeof(*m->m_info), GFP_NOFS);
168+
m->m_info = kcalloc(m->possible_max_rank, sizeof(*m->m_info), GFP_NOFS);
178169
if (!m->m_info)
179170
goto nomem;
180171

@@ -248,7 +239,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
248239
ceph_mds_state_name(state),
249240
laggy ? "(laggy)" : "");
250241

251-
if (mds < 0 || mds >= possible_max_rank) {
242+
if (mds < 0 || mds >= m->possible_max_rank) {
252243
pr_warn("mdsmap_decode got incorrect mds(%d)\n", mds);
253244
continue;
254245
}
@@ -318,22 +309,22 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
318309

319310
for (i = 0; i < n; i++) {
320311
s32 mds = ceph_decode_32(p);
321-
if (mds >= 0 && mds < m->m_num_mds) {
312+
if (mds >= 0 && mds < m->possible_max_rank) {
322313
if (m->m_info[mds].laggy)
323314
num_laggy++;
324315
}
325316
}
326317
m->m_num_laggy = num_laggy;
327318

328-
if (n > m->m_num_mds) {
319+
if (n > m->possible_max_rank) {
329320
void *new_m_info = krealloc(m->m_info,
330321
n * sizeof(*m->m_info),
331322
GFP_NOFS | __GFP_ZERO);
332323
if (!new_m_info)
333324
goto nomem;
334325
m->m_info = new_m_info;
335326
}
336-
m->m_num_mds = n;
327+
m->possible_max_rank = n;
337328
}
338329

339330
/* inc */
@@ -404,7 +395,7 @@ void ceph_mdsmap_destroy(struct ceph_mdsmap *m)
404395
{
405396
int i;
406397

407-
for (i = 0; i < m->m_num_mds; i++)
398+
for (i = 0; i < m->possible_max_rank; i++)
408399
kfree(m->m_info[i].export_targets);
409400
kfree(m->m_info);
410401
kfree(m->m_data_pg_pools);
@@ -420,7 +411,7 @@ bool ceph_mdsmap_is_cluster_available(struct ceph_mdsmap *m)
420411
return false;
421412
if (m->m_num_laggy == m->m_num_active_mds)
422413
return false;
423-
for (i = 0; i < m->m_num_mds; i++) {
414+
for (i = 0; i < m->possible_max_rank; i++) {
424415
if (m->m_info[i].state == CEPH_MDS_STATE_ACTIVE)
425416
nr_active++;
426417
}

‎include/linux/ceph/mdsmap.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ struct ceph_mdsmap {
2626
u32 m_session_autoclose; /* seconds */
2727
u64 m_max_file_size;
2828
u32 m_max_mds; /* expected up:active mds number */
29-
int m_num_active_mds; /* actual up:active mds number */
30-
int m_num_mds; /* size of m_info array */
29+
u32 m_num_active_mds; /* actual up:active mds number */
30+
u32 possible_max_rank; /* possible max rank index */
3131
struct ceph_mds_info *m_info;
3232

3333
/* which object pools file data can be stored in */
@@ -43,22 +43,22 @@ struct ceph_mdsmap {
4343
static inline struct ceph_entity_addr *
4444
ceph_mdsmap_get_addr(struct ceph_mdsmap *m, int w)
4545
{
46-
if (w >= m->m_num_mds)
46+
if (w >= m->possible_max_rank)
4747
return NULL;
4848
return &m->m_info[w].addr;
4949
}
5050

5151
static inline int ceph_mdsmap_get_state(struct ceph_mdsmap *m, int w)
5252
{
5353
BUG_ON(w < 0);
54-
if (w >= m->m_num_mds)
54+
if (w >= m->possible_max_rank)
5555
return CEPH_MDS_STATE_DNE;
5656
return m->m_info[w].state;
5757
}
5858

5959
static inline bool ceph_mdsmap_is_laggy(struct ceph_mdsmap *m, int w)
6060
{
61-
if (w >= 0 && w < m->m_num_mds)
61+
if (w >= 0 && w < m->possible_max_rank)
6262
return m->m_info[w].laggy;
6363
return false;
6464
}

0 commit comments

Comments
 (0)