Skip to contentSkip to conversation

ceph: Use pseudo-random numbers to choose mds

PATCH In review Sam Lang 2 participants 2 messages Apr 10, 2013 – Apr 11, 2013 Ceph client

lore
Share & tools
lore

Sam Lang

author
#0 lore raw

PATCH 1/1 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

---
 fs/ceph/mdsmap.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/mdsmap.c +5 -3
index 0d3c924..9278dec 100644
@@ -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)
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw

Yup, that is a change to not use entropy and to short-circuit if we only have one choice. And this function has no side effects so it just needs to return an int.

Software Engineer #42 @ http://inktank.com | http://ceph.com

Quoted 47 lines · Sam Lang

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

---
 fs/ceph/mdsmap.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/mdsmap.c +5 -4
index 0d3c924..9278dec 100644
@@ -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)
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html