summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2013-06-14 00:23:21 -0700
committerKent Overstreet <koverstreet@google.com>2013-06-14 15:55:33 -0700
commit7de40113622910fe0e2f6f5814ba46f0c0e27450 (patch)
tree185c7d51a4013285f5d892f6c4de4cc47ca7a6a5
parentc39e425262418e54739d0a4899d521fcd087210b (diff)
kill some ida hacks
-rw-r--r--fs/namespace.c49
-rw-r--r--fs/super.c37
-rw-r--r--include/linux/idr.h14
-rw-r--r--kernel/cgroup.c7
-rw-r--r--lib/idr.c14
5 files changed, 34 insertions, 87 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index 7b1ca9ba0b0a..001e4762b655 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -32,9 +32,6 @@
static int event;
static DEFINE_IDA(mnt_id_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 list_head *mount_hashtable __read_mostly;
static struct list_head *mountpoint_hashtable __read_mostly;
@@ -71,29 +68,17 @@ static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
*/
static int mnt_alloc_id(struct mount *mnt)
{
- int res;
-
-retry:
- ida_pre_get(&mnt_id_ida, GFP_KERNEL);
- spin_lock(&mnt_id_lock);
- res = ida_get_new_above(&mnt_id_ida, mnt_id_start, &mnt->mnt_id);
- if (!res)
- mnt_id_start = mnt->mnt_id + 1;
- spin_unlock(&mnt_id_lock);
- if (res == -EAGAIN)
- goto retry;
+ int res = ida_get(&mnt_id_ida, GFP_KERNEL);
+ if (res < 0)
+ return res;
- return res;
+ mnt->mnt_id = res;
+ return 0;
}
static void mnt_free_id(struct mount *mnt)
{
- int id = 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);
+ ida_remove(&mnt_id_ida, mnt->mnt_id);
}
/*
@@ -103,18 +88,12 @@ static void mnt_free_id(struct mount *mnt)
*/
static int mnt_alloc_group_id(struct mount *mnt)
{
- int res;
-
- if (!ida_pre_get(&mnt_group_ida, GFP_KERNEL))
- return -ENOMEM;
-
- res = ida_get_new_above(&mnt_group_ida,
- mnt_group_start,
- &mnt->mnt_group_id);
- if (!res)
- mnt_group_start = mnt->mnt_group_id + 1;
+ int res = ida_simple_get(&mnt_id_ida, 1, 0, GFP_KERNEL);
+ if (res < 0)
+ return res;
- return res;
+ mnt->mnt_group_id = res;
+ return 0;
}
/*
@@ -122,11 +101,7 @@ static int mnt_alloc_group_id(struct mount *mnt)
*/
void mnt_release_group_id(struct mount *mnt)
{
- int id = mnt->mnt_group_id;
- ida_remove(&mnt_group_ida, id);
- if (mnt_group_start > id)
- mnt_group_start = id;
- mnt->mnt_group_id = 0;
+ ida_remove(&mnt_group_ida, mnt->mnt_group_id);
}
/*
diff --git a/fs/super.c b/fs/super.c
index 7465d4364208..9c2febd1c56a 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -818,36 +818,18 @@ void emergency_remount(void)
*/
static DEFINE_IDA(unnamed_dev_ida);
-static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */
-static int unnamed_dev_start = 0; /* don't bother trying below it */
int get_anon_bdev(dev_t *p)
{
int dev;
- int error;
- retry:
- if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0)
- return -ENOMEM;
- spin_lock(&unnamed_dev_lock);
- error = ida_get_new_above(&unnamed_dev_ida, unnamed_dev_start, &dev);
- if (!error)
- unnamed_dev_start = dev + 1;
- spin_unlock(&unnamed_dev_lock);
- if (error == -EAGAIN)
- /* We raced and lost with another CPU. */
- goto retry;
- else if (error)
- return -EAGAIN;
-
- if (dev == (1 << MINORBITS)) {
- spin_lock(&unnamed_dev_lock);
- ida_remove(&unnamed_dev_ida, dev);
- if (unnamed_dev_start > dev)
- unnamed_dev_start = dev;
- spin_unlock(&unnamed_dev_lock);
+ dev = ida_simple_get(&unnamed_dev_ida, 0,
+ 1 << MINORBITS, GFP_ATOMIC);
+ if (dev == -ENOSPC)
return -EMFILE;
- }
+ if (dev < 0)
+ return dev;
+
*p = MKDEV(0, dev & MINORMASK);
return 0;
}
@@ -855,12 +837,7 @@ EXPORT_SYMBOL(get_anon_bdev);
void free_anon_bdev(dev_t dev)
{
- int slot = MINOR(dev);
- spin_lock(&unnamed_dev_lock);
- ida_remove(&unnamed_dev_ida, slot);
- if (slot < unnamed_dev_start)
- unnamed_dev_start = slot;
- spin_unlock(&unnamed_dev_lock);
+ ida_remove(&unnamed_dev_ida, MINOR(dev));
}
EXPORT_SYMBOL(free_anon_bdev);
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 15b0d293c6d7..1b305ac344af 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -220,7 +220,7 @@ struct ida {
#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
-int ida_get_new_above(struct ida *ida, int starting_id, int *p_id);
+int ida_get_new(struct ida *ida, int *p_id);
void ida_remove(struct ida *ida, unsigned id);
void ida_destroy(struct ida *ida);
void ida_init(struct ida *ida);
@@ -228,18 +228,6 @@ void ida_init(struct ida *ida);
int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
gfp_t gfp_mask);
-/**
- * ida_get_new - allocate new ID
- * @ida: idr handle
- * @p_id: pointer to the allocated handle
- *
- * Simple wrapper around ida_get_new_above() w/ @starting_id of zero.
- */
-static inline int ida_get_new(struct ida *ida, int *p_id)
-{
- return ida_get_new_above(ida, 0, p_id);
-}
-
static inline int ida_get(struct ida *ida, gfp_t gfp_mask)
{
return ida_simple_get(ida, 0, 0, gfp_mask);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 139bb88efd94..3ed66110e9ee 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -190,7 +190,6 @@ static LIST_HEAD(roots);
static int root_count;
static DEFINE_IDA(hierarchy_ida);
-static int next_hierarchy_id;
/* dummytop is a shorthand for the dummy hierarchy's top cgroup */
#define dummytop (&rootnode.top_cgroup)
@@ -1427,15 +1426,11 @@ static void init_cgroup_root(struct cgroupfs_root *root)
static bool init_root_id(struct cgroupfs_root *root)
{
- int ret = 0;
-
- ret = ida_simple_get(&hierarchy_ida, next_hierarchy_id, 0, GFP_KERNEL);
+ int ret = ida_get(&hierarchy_ida, GFP_KERNEL);
if (ret < 0)
return false;
root->hierarchy_id = ret;
- next_hierarchy_id = root->hierarchy_id + 1;
-
return true;
}
diff --git a/lib/idr.c b/lib/idr.c
index b4e95f793c9f..c61418a83f68 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -1019,7 +1019,19 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
return 0;
}
-EXPORT_SYMBOL(ida_get_new_above);
+
+/**
+ * ida_get_new - allocate new ID
+ * @ida: idr handle
+ * @p_id: pointer to the allocated handle
+ *
+ * Simple wrapper around ida_get_new_above() w/ @starting_id of zero.
+ */
+int ida_get_new(struct ida *ida, int *p_id)
+{
+ return ida_get_new_above(ida, 0, p_id);
+}
+EXPORT_SYMBOL(ida_get_new);
static void __ida_remove(struct ida *ida, int id)
{