diff options
Diffstat (limited to 'include/linux/idr.h')
| -rw-r--r-- | include/linux/idr.h | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h index 3e8215b2c371..3ec8628ce17f 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h | |||
| @@ -236,34 +236,74 @@ struct ida { | |||
| 236 | } | 236 | } |
| 237 | #define DEFINE_IDA(name) struct ida name = IDA_INIT(name) | 237 | #define DEFINE_IDA(name) struct ida name = IDA_INIT(name) |
| 238 | 238 | ||
| 239 | int ida_pre_get(struct ida *ida, gfp_t gfp_mask); | 239 | int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); |
| 240 | int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); | 240 | void ida_free(struct ida *, unsigned int id); |
| 241 | void ida_remove(struct ida *ida, int id); | ||
| 242 | void ida_destroy(struct ida *ida); | 241 | void ida_destroy(struct ida *ida); |
| 243 | 242 | ||
| 244 | int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, | 243 | /** |
| 245 | gfp_t gfp_mask); | 244 | * ida_alloc() - Allocate an unused ID. |
| 246 | void ida_simple_remove(struct ida *ida, unsigned int id); | 245 | * @ida: IDA handle. |
| 246 | * @gfp: Memory allocation flags. | ||
| 247 | * | ||
| 248 | * Allocate an ID between 0 and %INT_MAX, inclusive. | ||
| 249 | * | ||
| 250 | * Context: Any context. | ||
| 251 | * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, | ||
| 252 | * or %-ENOSPC if there are no free IDs. | ||
| 253 | */ | ||
| 254 | static inline int ida_alloc(struct ida *ida, gfp_t gfp) | ||
| 255 | { | ||
| 256 | return ida_alloc_range(ida, 0, ~0, gfp); | ||
| 257 | } | ||
| 247 | 258 | ||
| 248 | static inline void ida_init(struct ida *ida) | 259 | /** |
| 260 | * ida_alloc_min() - Allocate an unused ID. | ||
| 261 | * @ida: IDA handle. | ||
| 262 | * @min: Lowest ID to allocate. | ||
| 263 | * @gfp: Memory allocation flags. | ||
| 264 | * | ||
| 265 | * Allocate an ID between @min and %INT_MAX, inclusive. | ||
| 266 | * | ||
| 267 | * Context: Any context. | ||
| 268 | * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, | ||
| 269 | * or %-ENOSPC if there are no free IDs. | ||
| 270 | */ | ||
| 271 | static inline int ida_alloc_min(struct ida *ida, unsigned int min, gfp_t gfp) | ||
| 249 | { | 272 | { |
| 250 | INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT); | 273 | return ida_alloc_range(ida, min, ~0, gfp); |
| 251 | } | 274 | } |
| 252 | 275 | ||
| 253 | /** | 276 | /** |
| 254 | * ida_get_new - allocate new ID | 277 | * ida_alloc_max() - Allocate an unused ID. |
| 255 | * @ida: idr handle | 278 | * @ida: IDA handle. |
| 256 | * @p_id: pointer to the allocated handle | 279 | * @max: Highest ID to allocate. |
| 280 | * @gfp: Memory allocation flags. | ||
| 281 | * | ||
| 282 | * Allocate an ID between 0 and @max, inclusive. | ||
| 257 | * | 283 | * |
| 258 | * Simple wrapper around ida_get_new_above() w/ @starting_id of zero. | 284 | * Context: Any context. |
| 285 | * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, | ||
| 286 | * or %-ENOSPC if there are no free IDs. | ||
| 259 | */ | 287 | */ |
| 260 | static inline int ida_get_new(struct ida *ida, int *p_id) | 288 | static inline int ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp) |
| 261 | { | 289 | { |
| 262 | return ida_get_new_above(ida, 0, p_id); | 290 | return ida_alloc_range(ida, 0, max, gfp); |
| 263 | } | 291 | } |
| 264 | 292 | ||
| 293 | static inline void ida_init(struct ida *ida) | ||
| 294 | { | ||
| 295 | INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT); | ||
| 296 | } | ||
| 297 | |||
| 298 | #define ida_simple_get(ida, start, end, gfp) \ | ||
| 299 | ida_alloc_range(ida, start, (end) - 1, gfp) | ||
| 300 | #define ida_simple_remove(ida, id) ida_free(ida, id) | ||
| 301 | |||
| 265 | static inline bool ida_is_empty(const struct ida *ida) | 302 | static inline bool ida_is_empty(const struct ida *ida) |
| 266 | { | 303 | { |
| 267 | return radix_tree_empty(&ida->ida_rt); | 304 | return radix_tree_empty(&ida->ida_rt); |
| 268 | } | 305 | } |
| 306 | |||
| 307 | /* in lib/radix-tree.c */ | ||
| 308 | int ida_pre_get(struct ida *ida, gfp_t gfp_mask); | ||
| 269 | #endif /* __IDR_H__ */ | 309 | #endif /* __IDR_H__ */ |
