From patchwork Mon Nov 11 11:51:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 11236837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEEE613BD for ; Mon, 11 Nov 2019 11:51:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBC5921655 for ; Mon, 11 Nov 2019 11:51:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Iy2ExHDz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbfKKLvZ (ORCPT ); Mon, 11 Nov 2019 06:51:25 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57613 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726810AbfKKLvZ (ORCPT ); Mon, 11 Nov 2019 06:51:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573473084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GDNFoderkQrnYyZj4E6c9FtkV33mg0Gci6iSHwP+PZY=; b=Iy2ExHDzAUOnUEnXI8HhXP9z1qYbSMlydM471FSK4TjDWoJbR0xDCDaW4/Q0bEYgvSJR2Z letcHlcHkaD883YnaYK+/qADkOZzpgQZYhjdaWOfltM19LbmJJ/hsgq8E2xfT2Qe9XtzA5 gUl/KclS2iX/24WE7oLwoFjNZLR7FTc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-GamrE1PKOYuMs1fFZelrIw-1; Mon, 11 Nov 2019 06:51:21 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BCDEDB21; Mon, 11 Nov 2019 11:51:20 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-180.pek2.redhat.com [10.72.12.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB2EF608EB; Mon, 11 Nov 2019 11:51:14 +0000 (UTC) From: xiubli@redhat.com To: jlayton@kernel.org, sage@redhat.com, idryomov@gmail.com Cc: pdonnell@redhat.com, ceph-devel@vger.kernel.org, Xiubo Li Subject: [PATCH] ceph: fix geting random mds from mdsmap Date: Mon, 11 Nov 2019 06:51:05 -0500 Message-Id: <20191111115105.58758-1-xiubli@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: GamrE1PKOYuMs1fFZelrIw-1 X-Mimecast-Spam-Score: 0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org From: Xiubo Li For example, if we have 5 mds in the mdsmap and the states are: m_info[5] --> [-1, 1, -1, 1, 1] If we get a ramdon number 1, then we should get the mds index 3 as expected, but actually we will get index 2, which the state is -1. Signed-off-by: Xiubo Li --- fs/ceph/mdsmap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c index ce2d00da5096..2011147f76bf 100644 --- a/fs/ceph/mdsmap.c +++ b/fs/ceph/mdsmap.c @@ -20,7 +20,7 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) { int n = 0; - int i; + int i, j; /* special case for one mds */ if (1 == m->m_num_mds && m->m_info[0].state > 0) @@ -35,9 +35,12 @@ int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m) /* pick */ n = prandom_u32() % n; - for (i = 0; n > 0; i++, n--) - while (m->m_info[i].state <= 0) - i++; + for (j = 0, i = 0; i < m->m_num_mds; i++) { + if (m->m_info[0].state > 0) + j++; + if (j > n) + break; + } return i; }