diff mbox series

btrfs: tests: add selftests for RAID stripe-tree

Message ID 20240930104054.12290-1-jth@kernel.org (mailing list archive)
State New, archived
Headers show
Series btrfs: tests: add selftests for RAID stripe-tree | expand

Commit Message

Johannes Thumshirn Sept. 30, 2024, 10:40 a.m. UTC
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Add first stash of very basic self tests for the RAID stripe-tree.

More test cases will follow exercising the tree.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/Makefile                       |   3 +-
 fs/btrfs/raid-stripe-tree.c             |   5 +-
 fs/btrfs/raid-stripe-tree.h             |   5 +
 fs/btrfs/tests/btrfs-tests.c            |   3 +
 fs/btrfs/tests/btrfs-tests.h            |   1 +
 fs/btrfs/tests/raid-stripe-tree-tests.c | 274 ++++++++++++++++++++++++
 fs/btrfs/volumes.c                      |   6 +-
 fs/btrfs/volumes.h                      |   5 +
 8 files changed, 296 insertions(+), 6 deletions(-)
 create mode 100644 fs/btrfs/tests/raid-stripe-tree-tests.c

Comments

kernel test robot Sept. 30, 2024, 9:27 p.m. UTC | #1
Hi Johannes,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on linus/master v6.12-rc1 next-20240930]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Johannes-Thumshirn/btrfs-tests-add-selftests-for-RAID-stripe-tree/20240930-184234
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/20240930104054.12290-1-jth%40kernel.org
patch subject: [PATCH] btrfs: tests: add selftests for RAID stripe-tree
config: i386-buildonly-randconfig-004-20241001 (https://download.01.org/0day-ci/archive/20241001/202410010421.NzGgvE6Y-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241001/202410010421.NzGgvE6Y-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410010421.NzGgvE6Y-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from fs/btrfs/ioctl.c:37:
>> fs/btrfs/volumes.h:837:5: warning: "CONFIG_BTRFS_FS_RUN_SANITY_TESTS" is not defined, evaluates to 0 [-Wundef]
     837 | #if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
   In file included from fs/btrfs/relocation.c:16:
>> fs/btrfs/volumes.h:837:5: warning: "CONFIG_BTRFS_FS_RUN_SANITY_TESTS" is not defined, evaluates to 0 [-Wundef]
     837 | #if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from fs/btrfs/relocation.c:39:
>> fs/btrfs/raid-stripe-tree.h:31:5: warning: "CONFIG_BTRFS_FS_RUN_SANITY_TESTS" is not defined, evaluates to 0 [-Wundef]
      31 | #if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
   In file included from fs/btrfs/raid-stripe-tree.c:12:
>> fs/btrfs/raid-stripe-tree.h:31:5: warning: "CONFIG_BTRFS_FS_RUN_SANITY_TESTS" is not defined, evaluates to 0 [-Wundef]
      31 | #if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from fs/btrfs/raid-stripe-tree.c:13:
>> fs/btrfs/volumes.h:837:5: warning: "CONFIG_BTRFS_FS_RUN_SANITY_TESTS" is not defined, evaluates to 0 [-Wundef]
     837 | #if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
         |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/CONFIG_BTRFS_FS_RUN_SANITY_TESTS +837 fs/btrfs/volumes.h

   836	
 > 837	#if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
   838	struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
   839							u64 logical, u16 total_stripes);
   840	#endif
   841
kernel test robot Oct. 1, 2024, 1:11 a.m. UTC | #2
Hi Johannes,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on linus/master v6.12-rc1 next-20240930]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Johannes-Thumshirn/btrfs-tests-add-selftests-for-RAID-stripe-tree/20240930-184234
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/20240930104054.12290-1-jth%40kernel.org
patch subject: [PATCH] btrfs: tests: add selftests for RAID stripe-tree
config: x86_64-randconfig-122-20241001 (https://download.01.org/0day-ci/archive/20241001/202410010831.9lOBKwBS-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241001/202410010831.9lOBKwBS-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410010831.9lOBKwBS-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
   fs/btrfs/print-tree.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/print-tree.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/root-tree.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/extent-tree.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/extent-tree.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/extent-tree.c:1829:9: sparse: sparse: context imbalance in 'run_and_cleanup_extent_op' - unexpected unlock
   fs/btrfs/extent-tree.c:1893:28: sparse: sparse: context imbalance in 'cleanup_ref_head' - unexpected unlock
   fs/btrfs/extent-tree.c:1972:36: sparse: sparse: context imbalance in 'btrfs_run_delayed_refs_for_head' - unexpected unlock
   fs/btrfs/extent-tree.c:2041:21: sparse: sparse: context imbalance in '__btrfs_run_delayed_refs' - wrong count at exit
--
   fs/btrfs/ctree.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/ctree.c:260:22: sparse: sparse: incompatible types in comparison expression (different address spaces):
   fs/btrfs/ctree.c:260:22: sparse:    struct extent_buffer [noderef] __rcu *
   fs/btrfs/ctree.c:260:22: sparse:    struct extent_buffer *
   fs/btrfs/ctree.c:620:17: sparse: sparse: incompatible types in comparison expression (different address spaces):
   fs/btrfs/ctree.c:620:17: sparse:    struct extent_buffer [noderef] __rcu *
   fs/btrfs/ctree.c:620:17: sparse:    struct extent_buffer *
   fs/btrfs/ctree.c:981:17: sparse: sparse: incompatible types in comparison expression (different address spaces):
   fs/btrfs/ctree.c:981:17: sparse:    struct extent_buffer [noderef] __rcu *
   fs/btrfs/ctree.c:981:17: sparse:    struct extent_buffer *
   fs/btrfs/ctree.c:2910:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
   fs/btrfs/ctree.c:2910:9: sparse:    struct extent_buffer [noderef] __rcu *
   fs/btrfs/ctree.c:2910:9: sparse:    struct extent_buffer *
--
   fs/btrfs/inode-item.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/super.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/super.c: note: in included file (through include/trace/trace_events.h, include/trace/define_trace.h, include/trace/events/btrfs.h):
   include/trace/events/btrfs.h:2394:1: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned char [usertype] opf @@     got restricted blk_opf_t enum req_op @@
   include/trace/events/btrfs.h:2394:1: sparse:     expected unsigned char [usertype] opf
   include/trace/events/btrfs.h:2394:1: sparse:     got restricted blk_opf_t enum req_op
   fs/btrfs/super.c: note: in included file (through include/trace/perf.h, include/trace/define_trace.h, include/trace/events/btrfs.h):
   include/trace/events/btrfs.h:2394:1: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned char [usertype] opf @@     got restricted blk_opf_t enum req_op @@
   include/trace/events/btrfs.h:2394:1: sparse:     expected unsigned char [usertype] opf
   include/trace/events/btrfs.h:2394:1: sparse:     got restricted blk_opf_t enum req_op
--
   fs/btrfs/transaction.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/transaction.c: note: in included file (through arch/x86/include/generated/asm/unaligned.h, fs/btrfs/accessors.h, fs/btrfs/ctree.h):
   include/asm-generic/unaligned.h:37:16: sparse: sparse: self-comparison always evaluates to true
--
   fs/btrfs/sysfs.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/sysfs.c:662:9: sparse: sparse: context imbalance in 'btrfs_show_u64' - different lock contexts for basic block
--
   fs/btrfs/disk-io.c: note: in included file (through fs/btrfs/raid56.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/inode.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/inode.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/inode.c: note: in included file (through arch/x86/include/asm/processor.h, arch/x86/include/asm/cpufeature.h, arch/x86/include/asm/thread_info.h, ...):
   include/linux/err.h:41:17: sparse: sparse: self-comparison always evaluates to false
--
   fs/btrfs/extent_io.c: note: in included file (through fs/btrfs/zoned.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/extent_io.c:2465:13: sparse: sparse: context imbalance in 'detach_extent_buffer_folio' - different lock contexts for basic block
--
   fs/btrfs/ioctl.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/ioctl.c:434:6: sparse: sparse: context imbalance in 'btrfs_exclop_start_try_lock' - wrong count at exit
   fs/btrfs/ioctl.c:447:6: sparse: sparse: context imbalance in 'btrfs_exclop_start_unlock' - unexpected unlock
--
   fs/btrfs/volumes.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/volumes.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/volumes.c:405:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct rcu_string *str @@     got struct rcu_string [noderef] __rcu *name @@
   fs/btrfs/volumes.c:405:31: sparse:     expected struct rcu_string *str
   fs/btrfs/volumes.c:405:31: sparse:     got struct rcu_string [noderef] __rcu *name
   fs/btrfs/volumes.c:659:43: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected char const *device_path @@     got char [noderef] __rcu * @@
   fs/btrfs/volumes.c:659:43: sparse:     expected char const *device_path
   fs/btrfs/volumes.c:659:43: sparse:     got char [noderef] __rcu *
   fs/btrfs/volumes.c:855:50: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected char const * @@     got char [noderef] __rcu * @@
   fs/btrfs/volumes.c:855:50: sparse:     expected char const *
   fs/btrfs/volumes.c:855:50: sparse:     got char [noderef] __rcu *
   fs/btrfs/volumes.c:928:39: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected struct rcu_string *str @@     got struct rcu_string [noderef] __rcu *name @@
   fs/btrfs/volumes.c:928:39: sparse:     expected struct rcu_string *str
   fs/btrfs/volumes.c:928:39: sparse:     got struct rcu_string [noderef] __rcu *name
   fs/btrfs/volumes.c:978:34: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected char const *dev_path @@     got char [noderef] __rcu * @@
   fs/btrfs/volumes.c:978:34: sparse:     expected char const *dev_path
   fs/btrfs/volumes.c:978:34: sparse:     got char [noderef] __rcu *
   fs/btrfs/volumes.c:1352:42: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected char const * @@     got char [noderef] __rcu * @@
   fs/btrfs/volumes.c:1352:42: sparse:     expected char const *
   fs/btrfs/volumes.c:1352:42: sparse:     got char [noderef] __rcu *
   fs/btrfs/volumes.c:2113:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected char const *device_path @@     got char [noderef] __rcu * @@
   fs/btrfs/volumes.c:2113:31: sparse:     expected char const *device_path
   fs/btrfs/volumes.c:2113:31: sparse:     got char [noderef] __rcu *
   fs/btrfs/volumes.c:1505:29: sparse: sparse: self-comparison always evaluates to false
--
   fs/btrfs/free-space-cache.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/free-space-cache.c:1144:9: sparse: sparse: context imbalance in 'write_cache_extent_entries' - different lock contexts for basic block
   fs/btrfs/free-space-cache.c:2398:28: sparse: sparse: context imbalance in 'insert_into_bitmap' - unexpected unlock
--
   fs/btrfs/delayed-ref.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/tree-log.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/delayed-inode.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/props.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/dev-replace.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/scrub.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/scrub.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/block-rsv.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/tree-checker.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/space-info.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/delalloc-space.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/raid56.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/raid-stripe-tree.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/raid-stripe-tree.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/direct-io.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/relocation.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/relocation.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/bio.c: note: in included file:
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
   fs/btrfs/bio.c: note: in included file:
>> fs/btrfs/raid-stripe-tree.h:31:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'
--
   fs/btrfs/block-group.c: note: in included file (through fs/btrfs/space-info.h):
>> fs/btrfs/volumes.h:837:5: sparse: sparse: undefined preprocessor identifier 'CONFIG_BTRFS_FS_RUN_SANITY_TESTS'

vim +/CONFIG_BTRFS_FS_RUN_SANITY_TESTS +837 fs/btrfs/volumes.h

   836	
 > 837	#if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
   838	struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
   839							u64 logical, u16 total_stripes);
   840	#endif
   841
diff mbox series

Patch

diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile
index 87617f2968bc..3cfc440c636c 100644
--- a/fs/btrfs/Makefile
+++ b/fs/btrfs/Makefile
@@ -43,4 +43,5 @@  btrfs-$(CONFIG_FS_VERITY) += verity.o
 btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
 	tests/extent-buffer-tests.o tests/btrfs-tests.o \
 	tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o \
-	tests/free-space-tree-tests.o tests/extent-map-tests.o
+	tests/free-space-tree-tests.o tests/extent-map-tests.o \
+	tests/raid-stripe-tree-tests.o
diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
index 4c859b550f6c..b7787a8e4af2 100644
--- a/fs/btrfs/raid-stripe-tree.c
+++ b/fs/btrfs/raid-stripe-tree.c
@@ -108,8 +108,9 @@  static int update_raid_extent_item(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
-					struct btrfs_io_context *bioc)
+EXPORT_FOR_TESTS
+int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
+				 struct btrfs_io_context *bioc)
 {
 	struct btrfs_fs_info *fs_info = trans->fs_info;
 	struct btrfs_key stripe_key;
diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h
index 1ac1c21aac2f..4908ddc1a7ea 100644
--- a/fs/btrfs/raid-stripe-tree.h
+++ b/fs/btrfs/raid-stripe-tree.h
@@ -28,6 +28,11 @@  int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
 int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
 			     struct btrfs_ordered_extent *ordered_extent);
 
+#if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
+				 struct btrfs_io_context *bioc);
+#endif
+
 static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
 						 u64 map_type)
 {
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index ce50847e1e01..18e1ab4a0914 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -291,6 +291,9 @@  int btrfs_run_sanity_tests(void)
 			ret = btrfs_test_free_space_tree(sectorsize, nodesize);
 			if (ret)
 				goto out;
+			ret = btrfs_test_raid_stripe_tree(sectorsize, nodesize);
+			if (ret)
+				goto out;
 		}
 	}
 	ret = btrfs_test_extent_map();
diff --git a/fs/btrfs/tests/btrfs-tests.h b/fs/btrfs/tests/btrfs-tests.h
index dc2f2ab15fa5..61bcadaf2036 100644
--- a/fs/btrfs/tests/btrfs-tests.h
+++ b/fs/btrfs/tests/btrfs-tests.h
@@ -37,6 +37,7 @@  int btrfs_test_extent_io(u32 sectorsize, u32 nodesize);
 int btrfs_test_inodes(u32 sectorsize, u32 nodesize);
 int btrfs_test_qgroups(u32 sectorsize, u32 nodesize);
 int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
+int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize);
 int btrfs_test_extent_map(void);
 struct inode *btrfs_new_test_inode(void);
 struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize);
diff --git a/fs/btrfs/tests/raid-stripe-tree-tests.c b/fs/btrfs/tests/raid-stripe-tree-tests.c
new file mode 100644
index 000000000000..3c1517ae3acf
--- /dev/null
+++ b/fs/btrfs/tests/raid-stripe-tree-tests.c
@@ -0,0 +1,274 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 Western Digital Corporation or its affiliates.
+ */
+
+#include "../fs.h"
+#include "../disk-io.h"
+#include "../transaction.h"
+#include "../volumes.h"
+#include "../raid-stripe-tree.h"
+#include "btrfs-tests.h"
+
+#define RST_TEST_NUM_DEVICES	2
+#define RST_TEST_RAID1_TYPE	(BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_RAID1)
+
+typedef int (*test_func_t)(struct btrfs_trans_handle *trans);
+
+static struct btrfs_device *btrfs_device_by_devid(struct btrfs_fs_devices *fs_devices,
+						  u64 devid)
+{
+	struct btrfs_device *dev;
+
+	list_for_each_entry(dev, &fs_devices->devices, dev_list) {
+		if (dev->devid == devid)
+			return dev;
+	}
+
+	return NULL;
+}
+
+static int test_create_update_delete(struct btrfs_trans_handle *trans)
+{
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct btrfs_io_context *bioc;
+	struct btrfs_io_stripe io_stripe = { };
+	u64 map_type = RST_TEST_RAID1_TYPE;
+	u64 logical = SZ_1M;
+	u64 len = SZ_64K;
+	int ret;
+
+	bioc = alloc_btrfs_io_context(fs_info, logical, RST_TEST_NUM_DEVICES);
+	if (!bioc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0);
+
+	for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) {
+		struct btrfs_io_stripe *stripe = &bioc->stripes[i];
+		struct btrfs_device *dev;
+
+		dev = btrfs_device_by_devid(fs_info->fs_devices, i);
+		if (!dev) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		stripe->dev = dev;
+		stripe->physical = logical + i * SZ_1G;
+	}
+
+	ret = btrfs_insert_one_raid_extent(trans, bioc);
+	if (ret)
+		goto out;
+
+	io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0);
+	if (!io_stripe.dev) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0,
+					   &io_stripe);
+	if (ret)
+		goto out;
+
+	if (io_stripe.physical != logical) {
+		test_err("invalid physical address, expected %llu, got %llu",
+			 logical, io_stripe.physical);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	if (len != SZ_64K) {
+		test_err("invalid stripe length, expected %llu, got %llu",
+			 (u64)SZ_64K, len);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) {
+		struct btrfs_io_stripe *stripe = &bioc->stripes[i];
+		struct btrfs_device *dev;
+
+		dev = btrfs_device_by_devid(fs_info->fs_devices, i);
+		if (!dev) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		stripe->dev = dev;
+		stripe->physical = SZ_1G + logical + i * SZ_1G;
+	}
+
+	ret = btrfs_insert_one_raid_extent(trans, bioc);
+	if (ret)
+		goto out;
+	if (io_stripe.physical != logical + SZ_1G) {
+		test_err("invalid physical address, expected %llu, got %llu",
+			 logical + SZ_1G, io_stripe.physical);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	if (len != SZ_64K) {
+		test_err("invalid stripe length, expected %llu, got %llu",
+			 (u64)SZ_64K, len);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = btrfs_delete_raid_extent(trans, logical, len);
+
+out:
+	btrfs_put_bioc(bioc);
+	return ret;
+}
+
+static int test_simple_create_delete(struct btrfs_trans_handle *trans)
+{
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct btrfs_io_context *bioc;
+	struct btrfs_io_stripe io_stripe = { };
+	u64 map_type = RST_TEST_RAID1_TYPE;
+	u64 logical = SZ_1M;
+	u64 len = SZ_64K;
+	int ret;
+
+	bioc = alloc_btrfs_io_context(fs_info, logical, RST_TEST_NUM_DEVICES);
+	if (!bioc) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	bioc->map_type = map_type;
+	bioc->size = SZ_64K;
+
+	for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) {
+		struct btrfs_io_stripe *stripe = &bioc->stripes[i];
+		struct btrfs_device *dev;
+
+		dev = btrfs_device_by_devid(fs_info->fs_devices, i);
+		if (!dev) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		stripe->dev = dev;
+		stripe->physical = logical + i * SZ_1G;
+	}
+
+	ret = btrfs_insert_one_raid_extent(trans, bioc);
+	if (ret)
+		goto out;
+
+	io_stripe.dev = btrfs_device_by_devid(fs_info->fs_devices, 0);
+	if (!io_stripe.dev) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = btrfs_get_raid_extent_offset(fs_info, logical, &len, map_type, 0,
+					   &io_stripe);
+	if (ret)
+		goto out;
+
+	if (io_stripe.physical != logical) {
+		test_err("invalid physical address, expected %llu, got %llu",
+			 logical, io_stripe.physical);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	if (len != SZ_64K) {
+		test_err("invalid stripe length, expected %llu, got %llu",
+			 (u64)SZ_64K, len);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = btrfs_delete_raid_extent(trans, logical, len);
+
+out:
+	btrfs_put_bioc(bioc);
+	return ret;
+}
+
+test_func_t tests[] = {
+	test_simple_create_delete,
+	test_create_update_delete,
+};
+
+static int run_test(test_func_t test, u32 sectorsize, u32 nodesize)
+{
+	struct btrfs_trans_handle trans;
+	struct btrfs_fs_info *fs_info;
+	struct btrfs_root *root = NULL;
+	int ret;
+
+	fs_info = btrfs_alloc_dummy_fs_info(sectorsize, nodesize);
+	if (!fs_info) {
+		test_std_err(TEST_ALLOC_FS_INFO);
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	root = btrfs_alloc_dummy_root(fs_info);
+	if (IS_ERR(root)) {
+		test_std_err(TEST_ALLOC_ROOT);
+		ret = PTR_ERR(root);
+		goto out;
+	}
+	btrfs_set_super_compat_ro_flags(root->fs_info->super_copy,
+		BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE);
+	root->root_key.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID;
+	root->root_key.type = BTRFS_ROOT_ITEM_KEY;
+	root->root_key.offset = 0;
+	fs_info->stripe_root = root;
+	root->fs_info->tree_root = root;
+
+	root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
+	if (IS_ERR(root->node)) {
+		test_std_err(TEST_ALLOC_EXTENT_BUFFER);
+		ret = PTR_ERR(root->node);
+		goto out;
+	}
+	btrfs_set_header_level(root->node, 0);
+	btrfs_set_header_nritems(root->node, 0);
+	root->alloc_bytenr += 2 * nodesize;
+
+	for (int i = 0; i < RST_TEST_NUM_DEVICES; i++) {
+		struct btrfs_device *dev;
+
+		dev = btrfs_alloc_dummy_device(fs_info);
+		dev->devid = i;
+	}
+
+	btrfs_init_dummy_trans(&trans, root->fs_info);
+	ret = test(&trans);
+	if (ret)
+		goto out;
+
+out:
+	btrfs_free_dummy_root(root);
+	btrfs_free_dummy_fs_info(fs_info);
+
+	return ret;
+}
+
+int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize)
+{
+	int ret = 0;
+
+	test_msg("running RAID stripe-tree tests");
+	for (int i = 0; i < ARRAY_SIZE(tests); i++) {
+		ret = run_test(tests[i], sectorsize, nodesize);
+		if (ret)
+			goto out;
+	}
+
+out:
+	return ret;
+}
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 668138451f7c..6ff64a30349f 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6022,9 +6022,9 @@  static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	return preferred_mirror;
 }
 
-static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
-						       u64 logical,
-						       u16 total_stripes)
+EXPORT_FOR_TESTS
+struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
+						u64 logical, u16 total_stripes)
 {
 	struct btrfs_io_context *bioc;
 
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 26e35fc1c8fd..318fedf7f9fd 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -840,4 +840,9 @@  bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
 bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
 const u8 *btrfs_sb_fsid_ptr(const struct btrfs_super_block *sb);
 
+#if CONFIG_BTRFS_FS_RUN_SANITY_TESTS
+struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info,
+						u64 logical, u16 total_stripes);
+#endif
+
 #endif