From patchwork Tue Nov 10 11:26:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11894035 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 209C4697 for ; Tue, 10 Nov 2020 11:28:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECCAA20795 for ; Tue, 10 Nov 2020 11:28:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="CRESpMiZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731738AbgKJL2y (ORCPT ); Tue, 10 Nov 2020 06:28:54 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:11994 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731283AbgKJL2p (ORCPT ); Tue, 10 Nov 2020 06:28:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1605007724; x=1636543724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=phzcPvuHmsPkQJ+yUffj3Bei/hxUy575+3UAfNI92uo=; b=CRESpMiZl/HW+4mVAzsQKyuFNfcbWvaaEH19XMHkkBYG3A+q+ekEuD0n YxrnPhpPlxm6AdZaGuWX3F7OracCTS8mmo2HTX3Q87pZKz2PPDDGnrcnB rgF+c6z5vpLZvNgQuXgjMovX640ZKr6L7qkISNLiqZEh208+LHX+d8jm+ DxvQjn6f8arxs851HdfzCfryd7sh9OA+qPajhorHYbEZxM/Z/FJ9BsliQ 0JIg6yuf/b0p614l0aHnNkOZCS8O/9fD8FcKy5JQQqJBMWFvLeCgigCQF yIiH+h/PPtoEEa+fDi58FjWI1cfXJM6X+A7jzT9xNI09v6lzQELXDUzBA A==; IronPort-SDR: 6DD7g/XoorMleccjUPkPUWngVja6g68PlWfQvI1+eh2kAWHijwwx2oKRfRWRjqfVPvQSWI4cyH WR11Ydlr3h44oduvgggpVPs7BGXdgHBkUR9OP5l+MeCkXROmOJMC0sj34HcnfOOlXxgPOeFX+9 cmMTb01syp5vZywvzKNX/sOIbKzNHD9oNbRAHcVBdc544qWko91ppJ6+Smfi6VBtiJCJyL4yue /KUi1FSIDLo1xwUQvQuy+pF76Rf0tV0pb+t7YRHdJEPpnCGWAibvDZb61l6FstLA8X+ZTX2SoA vYQ= X-IronPort-AV: E=Sophos;i="5.77,466,1596470400"; d="scan'208";a="152376580" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Nov 2020 19:28:44 +0800 IronPort-SDR: UviRmUMZjM+PaDXCuLfagybCyHaKXWZkydYzKYkuPcN6rlA4vrc88qep8IShCYJOZpxOUw65DC H3EgH+jz7/wlOyQpK7s8E0Apfh5WOl3QO0bYbAFR6wcEJRJJZM8JCB9xQzfI6zWTyYom2lk0+2 X9ZLi0bB9pKFJHwwkDuxx790mFc76CGCIOsgVxeV78hAF1aWEitM4Ss/46/TzDMc5FSiZxDw79 eSuHm0sR4G66C5yImA5vdDD7Z+AJGtSpQGgLJghbgQ8JWKHJN1OPrsXbr4MfxGpt4DfGxcT5GK Z1Q32wT+blq0lqJYmj/BtMpG Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2020 03:14:45 -0800 IronPort-SDR: Yr55ZuEVX28RKeIJjbXvdfmwR0XijpHt1uoVUSsiheJ3zhe9q+UrPDs0mzqlm9kcFMsn/Z3ZBC wIbGz8s9Kcvxx/4PJ+kfSmCbaHxkpm1l1u+kXx3kFnNo6MXLiLpbItgmtZa0Eutb5oI4L4oy7e l72/rNjd38eEy8akY3lTYBzPXqHoAYBYeQrfc7YlrRDsXtgOXNExX1iSpp5NB52Jlr1LE7WWOu u3G+5cnWhbidenPjvLUuRVFaURyxToueIUVkII+7WmO+fKKKJ/TNbLMvqBHBsPcNTTsYm5iTh7 3tM= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip01.wdc.com with ESMTP; 10 Nov 2020 03:28:43 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, dsterba@suse.com Cc: hare@suse.com, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , "Darrick J. Wong" , Naohiro Aota Subject: [PATCH v10 24/41] btrfs: extend btrfs_rmap_block for specifying a device Date: Tue, 10 Nov 2020 20:26:27 +0900 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org btrfs_rmap_block currently reverse-maps the physical addresses on all devices to the corresponding logical addresses. This commit extends the function to match to a specified device. The old functionality of querying all devices is left intact by specifying NULL as target device. We pass block_device instead of btrfs_device to __btrfs_rmap_block. This function is intended to reverse-map the result of bio, which only have block_device. This commit also exports the function for later use. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 20 ++++++++++++++------ fs/btrfs/block-group.h | 8 +++----- fs/btrfs/tests/extent-map-tests.c | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 31511e59ca74..04bb0602f1cc 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1646,8 +1646,11 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) } /** - * btrfs_rmap_block - Map a physical disk address to a list of logical addresses + * btrfs_rmap_block - Map a physical disk address to a list of logical + * addresses * @chunk_start: logical address of block group + * @bdev: physical device to resolve. Can be NULL to indicate any + * device. * @physical: physical address to map to logical addresses * @logical: return array of logical addresses which map to @physical * @naddrs: length of @logical @@ -1657,9 +1660,9 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) * Used primarily to exclude those portions of a block group that contain super * block copies. */ -EXPORT_FOR_TESTS int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, - u64 physical, u64 **logical, int *naddrs, int *stripe_len) + struct block_device *bdev, u64 physical, u64 **logical, + int *naddrs, int *stripe_len) { struct extent_map *em; struct map_lookup *map; @@ -1677,6 +1680,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, map = em->map_lookup; data_stripe_length = em->orig_block_len; io_stripe_size = map->stripe_len; + chunk_start = em->start; /* For RAID5/6 adjust to a full IO stripe length */ if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) @@ -1691,14 +1695,18 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, for (i = 0; i < map->num_stripes; i++) { bool already_inserted = false; u64 stripe_nr; + u64 offset; int j; if (!in_range(physical, map->stripes[i].physical, data_stripe_length)) continue; + if (bdev && map->stripes[i].dev->bdev != bdev) + continue; + stripe_nr = physical - map->stripes[i].physical; - stripe_nr = div64_u64(stripe_nr, map->stripe_len); + stripe_nr = div64_u64_rem(stripe_nr, map->stripe_len, &offset); if (map->type & BTRFS_BLOCK_GROUP_RAID10) { stripe_nr = stripe_nr * map->num_stripes + i; @@ -1712,7 +1720,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, * instead of map->stripe_len */ - bytenr = chunk_start + stripe_nr * io_stripe_size; + bytenr = chunk_start + stripe_nr * io_stripe_size + offset; /* Ensure we don't add duplicate addresses */ for (j = 0; j < nr; j++) { @@ -1754,7 +1762,7 @@ static int exclude_super_stripes(struct btrfs_block_group *cache) for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { bytenr = btrfs_sb_offset(i); - ret = btrfs_rmap_block(fs_info, cache->start, + ret = btrfs_rmap_block(fs_info, cache->start, NULL, bytenr, &logical, &nr, &stripe_len); if (ret) return ret; diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 5be47f4bfea7..9a4009eaaecb 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -275,6 +275,9 @@ void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type); u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags); void btrfs_put_block_group_cache(struct btrfs_fs_info *info); int btrfs_free_block_groups(struct btrfs_fs_info *info); +int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, + struct block_device *bdev, u64 physical, u64 **logical, + int *naddrs, int *stripe_len); static inline u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info) { @@ -301,9 +304,4 @@ static inline int btrfs_block_group_done(struct btrfs_block_group *cache) void btrfs_freeze_block_group(struct btrfs_block_group *cache); void btrfs_unfreeze_block_group(struct btrfs_block_group *cache); -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS -int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, - u64 physical, u64 **logical, int *naddrs, int *stripe_len); -#endif - #endif /* BTRFS_BLOCK_GROUP_H */ diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c index 57379e96ccc9..c0aefe6dee0b 100644 --- a/fs/btrfs/tests/extent-map-tests.c +++ b/fs/btrfs/tests/extent-map-tests.c @@ -507,7 +507,7 @@ static int test_rmap_block(struct btrfs_fs_info *fs_info, goto out_free; } - ret = btrfs_rmap_block(fs_info, em->start, btrfs_sb_offset(1), + ret = btrfs_rmap_block(fs_info, em->start, NULL, btrfs_sb_offset(1), &logical, &out_ndaddrs, &out_stripe_len); if (ret || (out_ndaddrs == 0 && test->expected_mapped_addr)) { test_err("didn't rmap anything but expected %d",