Commit a84cd29335f4ca38ca8405c1636ee3876bb292b5
Committed by
Sage Weil
1 parent
8b3e1a5698
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
ceph: Use pseudo-random numbers to choose mds
We don't need to use up entropy to choose an mds, so use prandom_u32() to get a pseudo-random number. Also, we don't need to choose a random mds if only one mds is available, so add special casing for the common case. Fixes http://tracker.ceph.com/issues/3579 Signed-off-by: Sam Lang <sam.lang@inktank.com> Reviewed-by: Greg Farnum <greg@inktank.com> Reviewed-by: Alex Elder <elder@inktank.com>
Showing 1 changed file with 5 additions and 3 deletions Side-by-side Diff
fs/ceph/mdsmap.c
... | ... | @@ -20,8 +20,11 @@ |
20 | 20 | { |
21 | 21 | int n = 0; |
22 | 22 | int i; |
23 | - char r; | |
24 | 23 | |
24 | + /* special case for one mds */ | |
25 | + if (1 == m->m_max_mds && m->m_info[0].state > 0) | |
26 | + return 0; | |
27 | + | |
25 | 28 | /* count */ |
26 | 29 | for (i = 0; i < m->m_max_mds; i++) |
27 | 30 | if (m->m_info[i].state > 0) |
... | ... | @@ -30,8 +33,7 @@ |
30 | 33 | return -1; |
31 | 34 | |
32 | 35 | /* pick */ |
33 | - get_random_bytes(&r, 1); | |
34 | - n = r % n; | |
36 | + n = prandom_u32() % n; | |
35 | 37 | i = 0; |
36 | 38 | for (i = 0; n > 0; i++, n--) |
37 | 39 | while (m->m_info[i].state <= 0) |