提交 a84cd293 编写于 作者: S Sam Lang 提交者: Sage Weil

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/3579Signed-off-by: NSam Lang <sam.lang@inktank.com>
Reviewed-by: NGreg Farnum <greg@inktank.com>
Reviewed-by: NAlex Elder <elder@inktank.com>
上级 8b3e1a56
...@@ -20,7 +20,10 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) ...@@ -20,7 +20,10 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
{ {
int n = 0; int n = 0;
int i; int i;
char r;
/* special case for one mds */
if (1 == m->m_max_mds && m->m_info[0].state > 0)
return 0;
/* count */ /* count */
for (i = 0; i < m->m_max_mds; i++) for (i = 0; i < m->m_max_mds; i++)
...@@ -30,8 +33,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) ...@@ -30,8 +33,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
return -1; return -1;
/* pick */ /* pick */
get_random_bytes(&r, 1); n = prandom_u32() % n;
n = r % n;
i = 0; i = 0;
for (i = 0; n > 0; i++, n--) for (i = 0; n > 0; i++, n--)
while (m->m_info[i].state <= 0) while (m->m_info[i].state <= 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册