From patchwork Tue Dec 3 14:29:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 11271403 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 3403C138D for ; Tue, 3 Dec 2019 14:30:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 11E36206EC for ; Tue, 3 Dec 2019 14:30:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eu/uJQNn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726086AbfLCOaG (ORCPT ); Tue, 3 Dec 2019 09:30:06 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25205 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725848AbfLCOaG (ORCPT ); Tue, 3 Dec 2019 09:30:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575383405; 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=8Oqw5MPrcX2s7z8kAtDRSSdOIYVP/3Z6GDVI1Fg3Zv8=; b=eu/uJQNnzgkWPqtcLEo6KxBKiGWSxoIETKpSNXdbZILatuFPvYgb3vQDZBKWJNWSLcIvHf PA7FiuBfGzJONSIqLhD5tcnQ3rcKZtHGI/bpObLHOGp7HKAA6qNknYTLogT1c7iehCOuMz sAGBOdwDftGlrM0+OsgUTCpDtaxjH0g= 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-216-n7G63CXfPRiRDWbqcj11Nw-1; Tue, 03 Dec 2019 09:30:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC9DA107B7D8; Tue, 3 Dec 2019 14:29:59 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-69.pek2.redhat.com [10.72.12.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69EDF5D6AE; Tue, 3 Dec 2019 14:29:54 +0000 (UTC) From: xiubli@redhat.com To: jlayton@kernel.org Cc: sage@redhat.com, idryomov@gmail.com, zyan@redhat.com, pdonnell@redhat.com, ceph-devel@vger.kernel.org, Xiubo Li Subject: [PATCH] ceph: fix mdsmap_decode got incorrect mds(X) Date: Tue, 3 Dec 2019 09:29:49 -0500 Message-Id: <20191203142949.34910-1-xiubli@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: n7G63CXfPRiRDWbqcj11Nw-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 The possible max rank, it maybe larger than the m->m_num_mds, for example if the mds_max == 2 in the cluster, when the MDS(0) was laggy and being replaced by a new MDS, we will temporarily receive a new mds map with n_num_mds == 1 and the active MDS(1), and the mds rank >= m->m_num_mds. Signed-off-by: Xiubo Li --- fs/ceph/mdsmap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c index 284d68646c40..a77e0ecb9a6b 100644 --- a/fs/ceph/mdsmap.c +++ b/fs/ceph/mdsmap.c @@ -129,6 +129,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) int err; u8 mdsmap_v, mdsmap_cv; u16 mdsmap_ev; + u32 possible_max_rank; m = kzalloc(sizeof(*m), GFP_NOFS); if (!m) @@ -164,6 +165,15 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) m->m_num_mds = n = ceph_decode_32(p); m->m_num_active_mds = m->m_num_mds; + /* + * the possible max rank, it maybe larger than the m->m_num_mds, + * for example if the mds_max == 2 in the cluster, when the MDS(0) + * was laggy and being replaced by a new MDS, we will temporarily + * receive a new mds map with n_num_mds == 1 and the active MDS(1), + * and the mds rank >= m->m_num_mds. + */ + possible_max_rank = max((u32)m->m_num_mds, m->m_max_mds); + m->m_info = kcalloc(m->m_num_mds, sizeof(*m->m_info), GFP_NOFS); if (!m->m_info) goto nomem; @@ -238,7 +248,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end) ceph_mds_state_name(state), laggy ? "(laggy)" : ""); - if (mds < 0 || mds >= m->m_num_mds) { + if (mds < 0 || mds >= possible_max_rank) { pr_warn("mdsmap_decode got incorrect mds(%d)\n", mds); continue; }