diff options
author | Sam Lang <sam.lang@inktank.com> | 2013-04-09 16:49:11 -0500 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-01 21:18:49 -0700 |
commit | a84cd29335f4ca38ca8405c1636ee3876bb292b5 (patch) | |
tree | 953fdc6edc1ae9374f59a25c8892d2ce0d662058 /fs/ceph | |
parent | 8b3e1a56982d0eafff0afb0ff9e87c8b944a9bdc (diff) | |
download | op-kernel-dev-a84cd29335f4ca38ca8405c1636ee3876bb292b5.zip op-kernel-dev-a84cd29335f4ca38ca8405c1636ee3876bb292b5.tar.gz |
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 0d3c924..9278dec 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) { int n = 0; int i; - char r; + + /* special case for one mds */ + if (1 == m->m_max_mds && m->m_info[0].state > 0) + return 0; /* count */ for (i = 0; i < m->m_max_mds; i++) @@ -30,8 +33,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) return -1; /* pick */ - get_random_bytes(&r, 1); - n = r % n; + n = prandom_u32() % n; i = 0; for (i = 0; n > 0; i++, n--) while (m->m_info[i].state <= 0) |