From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D8C4C433DB for ; Tue, 9 Feb 2021 23:54:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC81F64E3E for ; Tue, 9 Feb 2021 23:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234658AbhBIXxn (ORCPT ); Tue, 9 Feb 2021 18:53:43 -0500 Received: from mx2.suse.de ([195.135.220.15]:38648 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233594AbhBIUd4 (ORCPT ); Tue, 9 Feb 2021 15:33:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 753BEB14C; Tue, 9 Feb 2021 20:31:23 +0000 (UTC) From: Michal Rostecki To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org (open list:BTRFS FILE SYSTEM), linux-kernel@vger.kernel.org (open list) Cc: Michal Rostecki Subject: [PATCH RFC 3/6] btrfs: Add stripe_physical function Date: Tue, 9 Feb 2021 21:30:37 +0100 Message-Id: <20210209203041.21493-4-mrostecki@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210209203041.21493-1-mrostecki@suse.de> References: <20210209203041.21493-1-mrostecki@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Rostecki Move the calculation of the physical address for a stripe to the new function - stripe_physical(). It can be used by raid1 read policies to calculate the offset and select mirrors based on I/O locality. Signed-off-by: Michal Rostecki --- fs/btrfs/volumes.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 292175206873..1ac364a2f105 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5498,6 +5498,23 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len) return ret; } +/* + * Calculates the physical location for the given stripe and I/O geometry. + * + * @map: mapping containing the logical extent + * @stripe_index: index of the stripe to make a calculation for + * @stripe_offset: offset of the block in its stripe + * @stripe_nr: index of the stripe whete the block falls in + * + * Returns the physical location. + */ +static u64 stripe_physical(struct map_lookup *map, u32 stripe_index, + u64 stripe_offset, u64 stripe_nr) +{ + return map->stripes[stripe_index].physical + stripe_offset + + stripe_nr * map->stripe_len; +} + static int find_live_mirror(struct btrfs_fs_info *fs_info, struct map_lookup *map, int first, int dev_replace_is_ongoing) @@ -6216,8 +6233,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, } for (i = 0; i < num_stripes; i++) { - bbio->stripes[i].physical = map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; + bbio->stripes[i].physical = stripe_physical(map, stripe_index, + stripe_offset, + stripe_nr); bbio->stripes[i].dev = map->stripes[stripe_index].dev; stripe_index++; } -- 2.30.0