summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-06-18 19:02:48 -0400
committerMatthew Wilcox <willy@infradead.org>2018-08-21 23:54:21 -0400
commitb03f8e43c9261878bf29d8cc1c3ba458cc98287e (patch)
treeafc7045075d7fdafcac2ea5a3eaa46fe44644e91
parentf272668deb9108b6118a85ffd73886b9a92c1002 (diff)
ida: Remove old API
Delete ida_pre_get(), ida_get_new(), ida_get_new_above() and ida_remove() from the public API. Some of these functions still exist as internal helpers, but they should not be called by consumers. Signed-off-by: Matthew Wilcox <willy@infradead.org>
-rw-r--r--include/linux/idr.h21
-rw-r--r--lib/idr.c48
-rw-r--r--lib/radix-tree.c9
3 files changed, 11 insertions, 67 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h
index cd339da0b1aa..2e1db0e36486 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -225,13 +225,9 @@ struct ida {
225} 225}
226#define DEFINE_IDA(name) struct ida name = IDA_INIT(name) 226#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
227 227
228int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
229int ida_get_new_above(struct ida *ida, int starting_id, int *p_id);
230void ida_remove(struct ida *ida, int id);
231void ida_destroy(struct ida *ida);
232
233int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); 228int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t);
234void ida_free(struct ida *, unsigned int id); 229void ida_free(struct ida *, unsigned int id);
230void ida_destroy(struct ida *ida);
235 231
236/** 232/**
237 * ida_alloc() - Allocate an unused ID. 233 * ida_alloc() - Allocate an unused ID.
@@ -292,20 +288,11 @@ static inline void ida_init(struct ida *ida)
292 ida_alloc_range(ida, start, (end) - 1, gfp) 288 ida_alloc_range(ida, start, (end) - 1, gfp)
293#define ida_simple_remove(ida, id) ida_free(ida, id) 289#define ida_simple_remove(ida, id) ida_free(ida, id)
294 290
295/**
296 * ida_get_new - allocate new ID
297 * @ida: idr handle
298 * @p_id: pointer to the allocated handle
299 *
300 * Simple wrapper around ida_get_new_above() w/ @starting_id of zero.
301 */
302static inline int ida_get_new(struct ida *ida, int *p_id)
303{
304 return ida_get_new_above(ida, 0, p_id);
305}
306
307static inline bool ida_is_empty(const struct ida *ida) 291static inline bool ida_is_empty(const struct ida *ida)
308{ 292{
309 return radix_tree_empty(&ida->ida_rt); 293 return radix_tree_empty(&ida->ida_rt);
310} 294}
295
296/* in lib/radix-tree.c */
297int ida_pre_get(struct ida *ida, gfp_t gfp_mask);
311#endif /* __IDR_H__ */ 298#endif /* __IDR_H__ */
diff --git a/lib/idr.c b/lib/idr.c
index 760fce92f1fb..1dc52191acb6 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -320,16 +320,9 @@ EXPORT_SYMBOL(idr_replace);
320 * ida_alloc(), ida_alloc_min(), ida_alloc_max() or ida_alloc_range(). 320 * ida_alloc(), ida_alloc_min(), ida_alloc_max() or ida_alloc_range().
321 * To free an ID, call ida_free(). 321 * To free an ID, call ida_free().
322 * 322 *
323 * If you have more complex locking requirements, use a loop around 323 * ida_destroy() can be used to dispose of an IDA without needing to
324 * ida_pre_get() and ida_get_new() to allocate a new ID. Then use 324 * free the individual IDs in it. You can use ida_is_empty() to find
325 * ida_remove() to free an ID. You must make sure that ida_get_new() and 325 * out whether the IDA has any IDs currently allocated.
326 * ida_remove() cannot be called at the same time as each other for the
327 * same IDA.
328 *
329 * You can also use ida_get_new_above() if you need an ID to be allocated
330 * above a particular number. ida_destroy() can be used to dispose of an
331 * IDA without needing to free the individual IDs in it. You can use
332 * ida_is_empty() to find out whether the IDA has any IDs currently allocated.
333 * 326 *
334 * IDs are currently limited to the range [0-INT_MAX]. If this is an awkward 327 * IDs are currently limited to the range [0-INT_MAX]. If this is an awkward
335 * limitation, it should be quite straightforward to raise the maximum. 328 * limitation, it should be quite straightforward to raise the maximum.
@@ -370,25 +363,7 @@ EXPORT_SYMBOL(idr_replace);
370 363
371#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) 364#define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1)
372 365
373/** 366static int ida_get_new_above(struct ida *ida, int start, int *id)
374 * ida_get_new_above - allocate new ID above or equal to a start id
375 * @ida: ida handle
376 * @start: id to start search at
377 * @id: pointer to the allocated handle
378 *
379 * Allocate new ID above or equal to @start. It should be called
380 * with any required locks to ensure that concurrent calls to
381 * ida_get_new_above() / ida_get_new() / ida_remove() are not allowed.
382 * Consider using ida_alloc_range() if you do not have complex locking
383 * requirements.
384 *
385 * If memory is required, it will return %-EAGAIN, you should unlock
386 * and go back to the ida_pre_get() call. If the ida is full, it will
387 * return %-ENOSPC. On success, it will return 0.
388 *
389 * @id returns a value in the range @start ... %0x7fffffff.
390 */
391int ida_get_new_above(struct ida *ida, int start, int *id)
392{ 367{
393 struct radix_tree_root *root = &ida->ida_rt; 368 struct radix_tree_root *root = &ida->ida_rt;
394 void __rcu **slot; 369 void __rcu **slot;
@@ -473,16 +448,8 @@ int ida_get_new_above(struct ida *ida, int start, int *id)
473 return 0; 448 return 0;
474 } 449 }
475} 450}
476EXPORT_SYMBOL(ida_get_new_above);
477 451
478/** 452static void ida_remove(struct ida *ida, int id)
479 * ida_remove - Free the given ID
480 * @ida: ida handle
481 * @id: ID to free
482 *
483 * This function should not be called at the same time as ida_get_new_above().
484 */
485void ida_remove(struct ida *ida, int id)
486{ 453{
487 unsigned long index = id / IDA_BITMAP_BITS; 454 unsigned long index = id / IDA_BITMAP_BITS;
488 unsigned offset = id % IDA_BITMAP_BITS; 455 unsigned offset = id % IDA_BITMAP_BITS;
@@ -519,9 +486,8 @@ void ida_remove(struct ida *ida, int id)
519 } 486 }
520 return; 487 return;
521 err: 488 err:
522 WARN(1, "ida_remove called for id=%d which is not allocated.\n", id); 489 WARN(1, "ida_free called for id=%d which is not allocated.\n", id);
523} 490}
524EXPORT_SYMBOL(ida_remove);
525 491
526/** 492/**
527 * ida_destroy() - Free all IDs. 493 * ida_destroy() - Free all IDs.
@@ -568,7 +534,7 @@ EXPORT_SYMBOL(ida_destroy);
568int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, 534int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
569 gfp_t gfp) 535 gfp_t gfp)
570{ 536{
571 int ret, id; 537 int ret, id = 0;
572 unsigned long flags; 538 unsigned long flags;
573 539
574 if ((int)min < 0) 540 if ((int)min < 0)
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index cc6096b97afb..bc03ecc4dfd2 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -2106,14 +2106,6 @@ void idr_preload(gfp_t gfp_mask)
2106} 2106}
2107EXPORT_SYMBOL(idr_preload); 2107EXPORT_SYMBOL(idr_preload);
2108 2108
2109/**
2110 * ida_pre_get - reserve resources for ida allocation
2111 * @ida: ida handle
2112 * @gfp: memory allocation flags
2113 *
2114 * This function should be called before calling ida_get_new_above(). If it
2115 * is unable to allocate memory, it will return %0. On success, it returns %1.
2116 */
2117int ida_pre_get(struct ida *ida, gfp_t gfp) 2109int ida_pre_get(struct ida *ida, gfp_t gfp)
2118{ 2110{
2119 /* 2111 /*
@@ -2134,7 +2126,6 @@ int ida_pre_get(struct ida *ida, gfp_t gfp)
2134 2126
2135 return 1; 2127 return 1;
2136} 2128}
2137EXPORT_SYMBOL(ida_pre_get);
2138 2129
2139void __rcu **idr_get_free(struct radix_tree_root *root, 2130void __rcu **idr_get_free(struct radix_tree_root *root,
2140 struct radix_tree_iter *iter, gfp_t gfp, 2131 struct radix_tree_iter *iter, gfp_t gfp,