From patchwork Wed Apr 10 15:05:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Lang X-Patchwork-Id: 2422021 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id C3036DF2E5 for ; Wed, 10 Apr 2013 15:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936553Ab3DJPGE (ORCPT ); Wed, 10 Apr 2013 11:06:04 -0400 Received: from mail-ie0-f173.google.com ([209.85.223.173]:46351 "EHLO mail-ie0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935753Ab3DJPGC (ORCPT ); Wed, 10 Apr 2013 11:06:02 -0400 Received: by mail-ie0-f173.google.com with SMTP id 10so559929ied.4 for ; Wed, 10 Apr 2013 08:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=UWpTQEaCu7YTOcm6JR0gfcodnBE38Qo7l1maWj7RA6w=; b=OBEu1bbE/NsBGnuSLZWDYu0ogXFkobV95pU/RA8QDeteqXBrP2n0DDRBPF5yyOtgiZ /WyOWFBQdOeXlmDu3hrTVnzozcfjO+4135Y83mv+dLLkUkAHTaGqhkA+re8eXRivdoFb kfihVA4BD0DOe5nX6k1s3JZdy2dMsGwCAGjvUDSAR7egM0aAL1the+fSiplpTjPxAvHH u9jyv7cxVX2wO1IpX1Rk5+8WZNyUUjHbKr88guw49C+BTvwH7kOYtZEdgYxfQhw4xK9v UAhQCGKctlmqhfJplvhA8Cf629Mku688MP+CynXnKB0cHHZM3wH6FQXeWn0m6rGdBj2C H/iQ== X-Received: by 10.50.73.65 with SMTP id j1mr1777428igv.49.1365606362106; Wed, 10 Apr 2013 08:06:02 -0700 (PDT) Received: from scout (207-229-177-80.c3-0.drb-ubr1.chi-drb.il.cable.rcn.com. [207.229.177.80]) by mx.google.com with ESMTPS id qn10sm27545067igc.6.2013.04.10.08.05.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 10 Apr 2013 08:06:01 -0700 (PDT) Received: by scout (sSMTP sendmail emulation); Wed, 10 Apr 2013 10:05:58 -0500 From: Sam Lang To: ceph-devel@vger.kernel.org Cc: Sam Lang Subject: [PATCH] ceph: Use pseudo-random numbers to choose mds Date: Wed, 10 Apr 2013 10:05:38 -0500 Message-Id: <1365606338-12278-1-git-send-email-sam.lang@inktank.com> X-Mailer: git-send-email 1.7.10.4 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 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 Reviewed-by: Greg Farnum --- fs/ceph/mdsmap.c | 8 +++++--- 1 file 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)