erofs: modernize device IDR to XArray
PATCH 1/1 erofs: modernize device IDR to XArray
Currently, EROFS maintains a list of extra devices using a legacy IDR structure (sbi->devs->tree). Modernize this to use a standard, more efficient XArray instead.
This migration simplifies device management, removes legacy boilerplate, and aligns EROFS device tracking with modern Linux kernel storage subsystem conventions:
1. Convert sbi->devs->tree from a legacy IDR to an XArray initialized with XA_FLAGS_ALLOC flags.
2. Use xa_alloc() to safely register devices under xa_limit_32b limits.
3. Use xa_load() for direct, fast lookups.
4. Replace custom IDR traversal wrappers with modern xa_for_each() iterators.
5. Replace custom IDR releasing callback helpers with a clean xa_for_each() loop and clean up the tree with xa_destroy().
--- fs/erofs/data.c | 6 +++--- fs/erofs/internal.h | 2 +- fs/erofs/super.c | 43 +++++++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 24 deletions(-)
fs/erofs/data.c +3 -3
@@ -211,13 +211,13 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)struct erofs_dev_context *devs =EROFS_SB (sb)->devs;struct erofs_device_info *dif;erofs_off_t startoff; -int id; +unsigned long id;erofs_fill_from_devinfo (map, sb, &EROFS_SB (sb)->dif0); map->m_bdev = sb->s_bdev;/* use s_bdev for the primary device */ if (map->m_deviceid) {down_read (&devs->rwsem); - dif =idr_find (&devs->tree, map->m_deviceid -1 ); + dif =xa_load (&devs->tree, map->m_deviceid -1 );if (!dif) {up_read (&devs->rwsem);return -ENODEV ;
@@ -231,7 +231,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)up_read (&devs->rwsem); }else if (devs->extra_devices && !devs->flatdev) {down_read (&devs->rwsem); -idr_for_each_entry (&devs->tree, dif, id) { +xa_for_each (&devs->tree, id, dif) {if (!dif->uniaddr)continue ;
fs/erofs/internal.h +1 -1
@@ -64,7 +64,7 @@ struct erofs_mount_opts { };struct erofs_dev_context { -struct idr tree; +struct xarray tree;struct rw_semaphore rwsem;unsigned int extra_devices;
fs/erofs/super.c +23 -20
101 lines not on this page · raw message
Signature · 1 line
2.47.3