Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: use xarray for old mount id

While the ida does use the xarray internally we can use it explicitly
which allows us to increment the unique mount id under the xa lock.
This allows us to remove the atomic as we're now allocating both ids in
one go.

Link: https://lore.kernel.org/r/20241217-erhielten-regung-44bb1604ca8f@brauner
Signed-off-by: Christian Brauner <brauner@kernel.org>

+10 -9
+10 -9
fs/namespace.c
··· 65 65 __setup("mphash_entries=", set_mphash_entries); 66 66 67 67 static u64 event; 68 - static DEFINE_IDA(mnt_id_ida); 68 + static DEFINE_XARRAY_FLAGS(mnt_id_xa, XA_FLAGS_ALLOC); 69 69 static DEFINE_IDA(mnt_group_ida); 70 70 71 71 /* Don't allow confusion with old 32bit mount ID */ 72 72 #define MNT_UNIQUE_ID_OFFSET (1ULL << 31) 73 - static atomic64_t mnt_id_ctr = ATOMIC64_INIT(MNT_UNIQUE_ID_OFFSET); 73 + static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET; 74 74 75 75 static struct hlist_head *mount_hashtable __ro_after_init; 76 76 static struct hlist_head *mountpoint_hashtable __ro_after_init; ··· 267 267 268 268 static int mnt_alloc_id(struct mount *mnt) 269 269 { 270 - int res = ida_alloc(&mnt_id_ida, GFP_KERNEL); 270 + int res; 271 271 272 - if (res < 0) 273 - return res; 274 - mnt->mnt_id = res; 275 - mnt->mnt_id_unique = atomic64_inc_return(&mnt_id_ctr); 276 - return 0; 272 + xa_lock(&mnt_id_xa); 273 + res = __xa_alloc(&mnt_id_xa, &mnt->mnt_id, mnt, XA_LIMIT(1, INT_MAX), GFP_KERNEL); 274 + if (!res) 275 + mnt->mnt_id_unique = ++mnt_id_ctr; 276 + xa_unlock(&mnt_id_xa); 277 + return res; 277 278 } 278 279 279 280 static void mnt_free_id(struct mount *mnt) 280 281 { 281 - ida_free(&mnt_id_ida, mnt->mnt_id); 282 + xa_erase(&mnt_id_xa, mnt->mnt_id); 282 283 } 283 284 284 285 /*