From patchwork Thu Mar 27 18:18:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3899401 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 40CC19F2E8 for ; Thu, 27 Mar 2014 18:20:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 630D020253 for ; Thu, 27 Mar 2014 18:20:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D67120225 for ; Thu, 27 Mar 2014 18:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756045AbaC0SUO (ORCPT ); Thu, 27 Mar 2014 14:20:14 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:34386 "EHLO mail-ee0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757163AbaC0ST1 (ORCPT ); Thu, 27 Mar 2014 14:19:27 -0400 Received: by mail-ee0-f45.google.com with SMTP id d17so3193642eek.18 for ; Thu, 27 Mar 2014 11:19:26 -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=x4bmj9kQxiJQsdL74CzNhyKoWrRB+Vs0ZAncuv27WLQ=; b=A6Et2gAY4OMWzNlwP0MbptUpVGDqfVjE/QyQlj+JO73WJOcT8dOCQKeMlTsc4PmPJy hfusBSb11+7E7SIj6VlXE7td93ycuRpdWFc8A5QTxxuMWdXs9rUiNm4O1Ln738muopGc hWTlh7rrnrX/F6NBD0zR4dgFKcxOu9iLO32+2rbniXylPFP6h4K2zEpNifv3smo5Ow64 kQ09Yfb8tVERveeWdCs5tWVAfnFR9YcDDfqbTTyhb0TOk7JY6XXf4iTaLspaMVaCRv23 h12uBnJMj/CUPgzvHT3XpsVe+dI4HCwFatWBADCAikjBvQHVnGjsttb/Fcp9f4U+xvpS 9HLQ== X-Gm-Message-State: ALoCoQlp2TpQM26XfXtSdDnw+4cHtbY5ZcbPHv8bpjKtsGnZXZuefXG8ZSFwwXeQKKlWpDMEeIQt X-Received: by 10.14.37.8 with SMTP id x8mr3147630eea.32.1395944366703; Thu, 27 Mar 2014 11:19:26 -0700 (PDT) Received: from localhost ([109.110.66.7]) by mx.google.com with ESMTPSA id l42sm5974144eew.19.2014.03.27.11.19.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 11:19:26 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 27/33] libceph: introduce apply_temps() helper Date: Thu, 27 Mar 2014 20:18:13 +0200 Message-Id: <1395944299-21970-28-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 apply_temp() helper for applying various temporary mappings (at this point only pg_temp mappings) to the up set, therefore transforming it into an acting set. Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder --- net/ceph/osdmap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index ee095e07cf98..6d418433d80d 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -1590,6 +1590,58 @@ static int raw_to_up_osds(struct ceph_osdmap *osdmap, } /* + * Given up set, apply pg_temp mapping. + * + * Return acting set length. *primary is set to acting primary osd id, + * or -1 if acting set is empty. + */ +static int apply_temps(struct ceph_osdmap *osdmap, + struct ceph_pg_pool_info *pool, struct ceph_pg pgid, + int *osds, int len, int *primary) +{ + struct ceph_pg_mapping *pg; + int temp_len; + int temp_primary; + int i; + + /* raw_pg -> pg */ + pgid.seed = ceph_stable_mod(pgid.seed, pool->pg_num, + pool->pg_num_mask); + + /* pg_temp? */ + pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid); + if (pg) { + temp_len = 0; + temp_primary = -1; + + for (i = 0; i < pg->pg_temp.len; i++) { + if (ceph_osd_is_down(osdmap, pg->pg_temp.osds[i])) { + if (ceph_can_shift_osds(pool)) + continue; + else + osds[temp_len++] = CRUSH_ITEM_NONE; + } else { + osds[temp_len++] = pg->pg_temp.osds[i]; + } + } + + /* apply pg_temp's primary */ + for (i = 0; i < temp_len; i++) { + if (osds[i] != CRUSH_ITEM_NONE) { + temp_primary = osds[i]; + break; + } + } + } else { + temp_len = len; + temp_primary = *primary; + } + + *primary = temp_primary; + return temp_len; +} + +/* * Return acting set for given pgid. */ int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid,