Commit 169b480e authored by Matthew Wilcox's avatar Matthew Wilcox

fs: Convert namespace IDAs to new API

We don't need to keep track of the starting value; the IDA is efficient.
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
parent 5a66847e
...@@ -61,9 +61,6 @@ __setup("mphash_entries=", set_mphash_entries); ...@@ -61,9 +61,6 @@ __setup("mphash_entries=", set_mphash_entries);
static u64 event; static u64 event;
static DEFINE_IDA(mnt_id_ida); static DEFINE_IDA(mnt_id_ida);
static DEFINE_IDA(mnt_group_ida); static DEFINE_IDA(mnt_group_ida);
static DEFINE_SPINLOCK(mnt_id_lock);
static int mnt_id_start = 0;
static int mnt_group_start = 1;
static struct hlist_head *mount_hashtable __read_mostly; static struct hlist_head *mount_hashtable __read_mostly;
static struct hlist_head *mountpoint_hashtable __read_mostly; static struct hlist_head *mountpoint_hashtable __read_mostly;
...@@ -101,50 +98,30 @@ static inline struct hlist_head *mp_hash(struct dentry *dentry) ...@@ -101,50 +98,30 @@ static inline struct hlist_head *mp_hash(struct dentry *dentry)
static int mnt_alloc_id(struct mount *mnt) static int mnt_alloc_id(struct mount *mnt)
{ {
int res; int res = ida_alloc(&mnt_id_ida, GFP_KERNEL);
retry: if (res < 0)
ida_pre_get(&mnt_id_ida, GFP_KERNEL); return res;
spin_lock(&mnt_id_lock); mnt->mnt_id = res;
res = ida_get_new_above(&mnt_id_ida, mnt_id_start, &mnt->mnt_id); return 0;
if (!res)
mnt_id_start = mnt->mnt_id + 1;
spin_unlock(&mnt_id_lock);
if (res == -EAGAIN)
goto retry;
return res;
} }
static void mnt_free_id(struct mount *mnt) static void mnt_free_id(struct mount *mnt)
{ {
int id = mnt->mnt_id; ida_free(&mnt_id_ida, mnt->mnt_id);
spin_lock(&mnt_id_lock);
ida_remove(&mnt_id_ida, id);
if (mnt_id_start > id)
mnt_id_start = id;
spin_unlock(&mnt_id_lock);
} }
/* /*
* Allocate a new peer group ID * Allocate a new peer group ID
*
* mnt_group_ida is protected by namespace_sem
*/ */
static int mnt_alloc_group_id(struct mount *mnt) static int mnt_alloc_group_id(struct mount *mnt)
{ {
int res; int res = ida_alloc_min(&mnt_group_ida, 1, GFP_KERNEL);
if (!ida_pre_get(&mnt_group_ida, GFP_KERNEL)) if (res < 0)
return -ENOMEM; return res;
mnt->mnt_group_id = res;
res = ida_get_new_above(&mnt_group_ida, return 0;
mnt_group_start,
&mnt->mnt_group_id);
if (!res)
mnt_group_start = mnt->mnt_group_id + 1;
return res;
} }
/* /*
...@@ -152,10 +129,7 @@ static int mnt_alloc_group_id(struct mount *mnt) ...@@ -152,10 +129,7 @@ static int mnt_alloc_group_id(struct mount *mnt)
*/ */
void mnt_release_group_id(struct mount *mnt) void mnt_release_group_id(struct mount *mnt)
{ {
int id = mnt->mnt_group_id; ida_free(&mnt_group_ida, mnt->mnt_group_id);
ida_remove(&mnt_group_ida, id);
if (mnt_group_start > id)
mnt_group_start = id;
mnt->mnt_group_id = 0; mnt->mnt_group_id = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment