From patchwork Mon Sep 29 12:34:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Grunau X-Patchwork-Id: 4995831 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 D165CBEEA6 for ; Mon, 29 Sep 2014 12:34:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A0E420220 for ; Mon, 29 Sep 2014 12:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25E4F2025B for ; Mon, 29 Sep 2014 12:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753465AbaI2Mem (ORCPT ); Mon, 29 Sep 2014 08:34:42 -0400 Received: from soltyk.jannau.net ([185.27.253.110]:42037 "EHLO soltyk.jannau.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753355AbaI2Mek (ORCPT ); Mon, 29 Sep 2014 08:34:40 -0400 Received: from coburn.home.jannau.net (55d46691.access.ecotel.net [85.212.102.145]) by soltyk.jannau.net (Postfix) with ESMTPSA id E0DE03E1A19 for ; Mon, 29 Sep 2014 14:34:38 +0200 (CEST) From: Janne Grunau To: ceph-devel@vger.kernel.org Subject: [PATCH v3 2/4] erasure code: use a function for the chunk mapping index Date: Mon, 29 Sep 2014 14:34:30 +0200 Message-Id: <1411994072-18850-3-git-send-email-j@jannau.net> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1411994072-18850-1-git-send-email-j@jannau.net> References: <1410796508-28711-1-git-send-email-j@jannau.net> <1411994072-18850-1-git-send-email-j@jannau.net> 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.7 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 --- src/erasure-code/ErasureCode.cc | 14 ++++++++------ src/erasure-code/ErasureCode.h | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/erasure-code/ErasureCode.cc b/src/erasure-code/ErasureCode.cc index 5953f49..8b6c57f 100644 --- a/src/erasure-code/ErasureCode.cc +++ b/src/erasure-code/ErasureCode.cc @@ -22,6 +22,11 @@ #include "common/strtol.h" #include "ErasureCode.h" +int ErasureCode::chunk_index(unsigned int i) const +{ + return chunk_mapping.size() > i ? chunk_mapping[i] : i; +} + int ErasureCode::minimum_to_decode(const set &want_to_read, const set &available_chunks, set *minimum) @@ -85,8 +90,7 @@ int ErasureCode::encode(const set &want_to_encode, return err; unsigned blocksize = get_chunk_size(in.length()); for (unsigned int i = 0; i < k + m; i++) { - int chunk_index = chunk_mapping.size() > 0 ? chunk_mapping[i] : i; - bufferlist &chunk = (*encoded)[chunk_index]; + bufferlist &chunk = (*encoded)[chunk_index(i)]; chunk.substr_of(out, i * blocksize, blocksize); } encode_chunks(want_to_encode, encoded); @@ -223,15 +227,13 @@ int ErasureCode::decode_concat(const map &chunks, set want_to_read; for (unsigned int i = 0; i < get_data_chunk_count(); i++) { - int chunk = chunk_mapping.size() > i ? chunk_mapping[i] : i; - want_to_read.insert(chunk); + want_to_read.insert(chunk_index(i)); } map decoded_map; int r = decode(want_to_read, chunks, &decoded_map); if (r == 0) { for (unsigned int i = 0; i < get_data_chunk_count(); i++) { - int chunk = chunk_mapping.size() > i ? chunk_mapping[i] : i; - decoded->claim_append(decoded_map[chunk]); + decoded->claim_append(decoded_map[chunk_index(i)]); } } return r; diff --git a/src/erasure-code/ErasureCode.h b/src/erasure-code/ErasureCode.h index 7aaea95..ab00120 100644 --- a/src/erasure-code/ErasureCode.h +++ b/src/erasure-code/ErasureCode.h @@ -85,6 +85,9 @@ namespace ceph { virtual int decode_concat(const map &chunks, bufferlist *decoded); + + private: + int chunk_index(unsigned int i) const; }; }