From patchwork Thu Mar 27 18:18:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3899411 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AC079BF540 for ; Thu, 27 Mar 2014 18:20:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFCD720253 for ; Thu, 27 Mar 2014 18:20:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E456120225 for ; Thu, 27 Mar 2014 18:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757164AbaC0ST1 (ORCPT ); Thu, 27 Mar 2014 14:19:27 -0400 Received: from mail-ee0-f42.google.com ([74.125.83.42]:53957 "EHLO mail-ee0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757156AbaC0STZ (ORCPT ); Thu, 27 Mar 2014 14:19:25 -0400 Received: by mail-ee0-f42.google.com with SMTP id d17so3238219eek.1 for ; Thu, 27 Mar 2014 11:19:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=HEMCtKvHdOllISAsQP2mQyHLncgpc2CEf8RWWsfKgt0=; b=Idr1cAuEYgE1beKhwtnDRV0aiR76TqB4TP1rfjGcSXeE+eSyYXFe1r0N02avBfcu2V 2WC+zxhUTc+g01gVc5DDrfwKPyaD2p3KtmFH4PBhxazHEQPAywMLmTvxPgkspZzUy1hG K4aQsNsMQK8VRaFACJalpD900hyJi7k5/s9R43w3EgVlF1nw3km7g06Aua2O7aZYMyWF fFawVV9oM+X3vFCpFPaGZze8AAvwYPLGg9rcxcpd2wssEYiITOF5HfaUQir2m1Tt1uEw P1TzyyikIkUTdOjWKknrCRX8f3gtyy7cttP4gsuCYUUQ2c9+2/4i0rb4kMQOdES5jge0 ZZpg== X-Gm-Message-State: ALoCoQkGkVOpAiyPA+5l8/wpMvqXfbFBtxXi+rnazKSm8Y10r1Wbo0T9hDjECynLZBmhoQ3umSo9 X-Received: by 10.14.180.2 with SMTP id i2mr2626420eem.53.1395944364370; Thu, 27 Mar 2014 11:19:24 -0700 (PDT) Received: from localhost ([109.110.66.7]) by mx.google.com with ESMTPSA id w12sm5942975eez.36.2014.03.27.11.19.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 11:19:23 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 26/33] libceph: introduce pg_to_raw_osds() and raw_to_up_osds() helpers Date: Thu, 27 Mar 2014 20:18:12 +0200 Message-Id: <1395944299-21970-27-git-send-email-ilya.dryomov@inktank.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> References: <1395944299-21970-1-git-send-email-ilya.dryomov@inktank.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pg_to_raw_osds() helper for computing a raw (crush) set, which can contain non-existant and down osds. raw_to_up_osds() helper for pruning non-existant and down osds from the raw set, therefore transforming it into an up set, and determining up primary. Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder --- net/ceph/osdmap.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 3ac2098972ea..ee095e07cf98 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -1514,6 +1514,82 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid, } /* + * Calculate raw (crush) set for given pgid. + * + * Return raw set length, or error. + */ +static int pg_to_raw_osds(struct ceph_osdmap *osdmap, + struct ceph_pg_pool_info *pool, + struct ceph_pg pgid, u32 pps, int *osds) +{ + int ruleno; + int len; + + /* crush */ + ruleno = crush_find_rule(osdmap->crush, pool->crush_ruleset, + pool->type, pool->size); + if (ruleno < 0) { + pr_err("no crush rule: pool %lld ruleset %d type %d size %d\n", + pgid.pool, pool->crush_ruleset, pool->type, + pool->size); + return -ENOENT; + } + + len = do_crush(osdmap, ruleno, pps, osds, + min_t(int, pool->size, CEPH_PG_MAX_SIZE), + osdmap->osd_weight, osdmap->max_osd); + if (len < 0) { + pr_err("error %d from crush rule %d: pool %lld ruleset %d type %d size %d\n", + len, ruleno, pgid.pool, pool->crush_ruleset, + pool->type, pool->size); + return len; + } + + return len; +} + +/* + * Given raw set, calculate up set and up primary. + * + * Return up set length. *primary is set to up primary osd id, or -1 + * if up set is empty. + */ +static int raw_to_up_osds(struct ceph_osdmap *osdmap, + struct ceph_pg_pool_info *pool, + int *osds, int len, int *primary) +{ + int up_primary = -1; + int i; + + if (ceph_can_shift_osds(pool)) { + int removed = 0; + + for (i = 0; i < len; i++) { + if (ceph_osd_is_down(osdmap, osds[i])) { + removed++; + continue; + } + if (removed) + osds[i - removed] = osds[i]; + } + + len -= removed; + if (len > 0) + up_primary = osds[0]; + } else { + for (i = len - 1; i >= 0; i--) { + if (ceph_osd_is_down(osdmap, osds[i])) + osds[i] = CRUSH_ITEM_NONE; + else + up_primary = osds[i]; + } + } + + *primary = up_primary; + return len; +} + +/* * Return acting set for given pgid. */ int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid,