diff options
author | Sam Lang <sam.lang@inktank.com> | 2013-04-09 17:49:11 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:18:49 -0400 |
commit | a84cd29335f4ca38ca8405c1636ee3876bb292b5 (patch) | |
tree | 953fdc6edc1ae9374f59a25c8892d2ce0d662058 /fs/ceph | |
parent | 8b3e1a56982d0eafff0afb0ff9e87c8b944a9bdc (diff) |
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>
Diffstat (limited to 'fs/ceph')
-rw-r--r-- | fs/ceph/mdsmap.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c index 0d3c9240c61b..9278dec9e940 100644 --- a/fs/ceph/mdsmap.c +++ b/fs/ceph/mdsmap.c | |||
@@ -20,7 +20,10 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) | |||
20 | { | 20 | { |
21 | int n = 0; | 21 | int n = 0; |
22 | int i; | 22 | int i; |
23 | char r; | 23 | |
24 | /* special case for one mds */ | ||
25 | if (1 == m->m_max_mds && m->m_info[0].state > 0) | ||
26 | return 0; | ||
24 | 27 | ||
25 | /* count */ | 28 | /* count */ |
26 | for (i = 0; i < m->m_max_mds; i++) | 29 | for (i = 0; i < m->m_max_mds; i++) |
@@ -30,8 +33,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) | |||
30 | return -1; | 33 | return -1; |
31 | 34 | ||
32 | /* pick */ | 35 | /* pick */ |
33 | get_random_bytes(&r, 1); | 36 | n = prandom_u32() % n; |
34 | n = r % n; | ||
35 | i = 0; | 37 | i = 0; |
36 | for (i = 0; n > 0; i++, n--) | 38 | for (i = 0; n > 0; i++, n--) |
37 | while (m->m_info[i].state <= 0) | 39 | while (m->m_info[i].state <= 0) |