equal
deleted
inserted
replaced
119 */ |
119 */ |
120 int idr_pre_get(struct idr *idp, gfp_t gfp_mask) |
120 int idr_pre_get(struct idr *idp, gfp_t gfp_mask) |
121 { |
121 { |
122 while (idp->id_free_cnt < IDR_FREE_MAX) { |
122 while (idp->id_free_cnt < IDR_FREE_MAX) { |
123 struct idr_layer *new; |
123 struct idr_layer *new; |
124 new = kmem_cache_alloc(idr_layer_cache, gfp_mask); |
124 new = kmem_cache_zalloc(idr_layer_cache, gfp_mask); |
125 if (new == NULL) |
125 if (new == NULL) |
126 return (0); |
126 return (0); |
127 move_to_free_list(idp, new); |
127 move_to_free_list(idp, new); |
128 } |
128 } |
129 return 1; |
129 return 1; |
290 * |
290 * |
291 * If memory is required, it will return -EAGAIN, you should unlock |
291 * If memory is required, it will return -EAGAIN, you should unlock |
292 * and go back to the idr_pre_get() call. If the idr is full, it will |
292 * and go back to the idr_pre_get() call. If the idr is full, it will |
293 * return -ENOSPC. |
293 * return -ENOSPC. |
294 * |
294 * |
295 * @id returns a value in the range 0 ... 0x7fffffff |
295 * @id returns a value in the range @starting_id ... 0x7fffffff |
296 */ |
296 */ |
297 int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id) |
297 int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id) |
298 { |
298 { |
299 int rv; |
299 int rv; |
300 |
300 |
447 struct idr_layer *pa[MAX_LEVEL]; |
447 struct idr_layer *pa[MAX_LEVEL]; |
448 struct idr_layer **paa = &pa[0]; |
448 struct idr_layer **paa = &pa[0]; |
449 |
449 |
450 n = idp->layers * IDR_BITS; |
450 n = idp->layers * IDR_BITS; |
451 p = idp->top; |
451 p = idp->top; |
|
452 rcu_assign_pointer(idp->top, NULL); |
452 max = 1 << n; |
453 max = 1 << n; |
453 |
454 |
454 id = 0; |
455 id = 0; |
455 while (id < max) { |
456 while (id < max) { |
456 while (n > IDR_BITS && p) { |
457 while (n > IDR_BITS && p) { |
465 free_layer(p); |
466 free_layer(p); |
466 n += IDR_BITS; |
467 n += IDR_BITS; |
467 p = *--paa; |
468 p = *--paa; |
468 } |
469 } |
469 } |
470 } |
470 rcu_assign_pointer(idp->top, NULL); |
|
471 idp->layers = 0; |
471 idp->layers = 0; |
472 } |
472 } |
473 EXPORT_SYMBOL(idr_remove_all); |
473 EXPORT_SYMBOL(idr_remove_all); |
474 |
474 |
475 /** |
475 /** |
621 |
621 |
622 return old_p; |
622 return old_p; |
623 } |
623 } |
624 EXPORT_SYMBOL(idr_replace); |
624 EXPORT_SYMBOL(idr_replace); |
625 |
625 |
626 static void idr_cache_ctor(void *idr_layer) |
|
627 { |
|
628 memset(idr_layer, 0, sizeof(struct idr_layer)); |
|
629 } |
|
630 |
|
631 void __init idr_init_cache(void) |
626 void __init idr_init_cache(void) |
632 { |
627 { |
633 idr_layer_cache = kmem_cache_create("idr_layer_cache", |
628 idr_layer_cache = kmem_cache_create("idr_layer_cache", |
634 sizeof(struct idr_layer), 0, SLAB_PANIC, |
629 sizeof(struct idr_layer), 0, SLAB_PANIC, NULL); |
635 idr_cache_ctor); |
|
636 } |
630 } |
637 |
631 |
638 /** |
632 /** |
639 * idr_init - initialize idr handle |
633 * idr_init - initialize idr handle |
640 * @idp: idr handle |
634 * @idp: idr handle |
721 * |
715 * |
722 * If memory is required, it will return -EAGAIN, you should unlock |
716 * If memory is required, it will return -EAGAIN, you should unlock |
723 * and go back to the ida_pre_get() call. If the ida is full, it will |
717 * and go back to the ida_pre_get() call. If the ida is full, it will |
724 * return -ENOSPC. |
718 * return -ENOSPC. |
725 * |
719 * |
726 * @p_id returns a value in the range 0 ... 0x7fffffff. |
720 * @p_id returns a value in the range @starting_id ... 0x7fffffff. |
727 */ |
721 */ |
728 int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) |
722 int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) |
729 { |
723 { |
730 struct idr_layer *pa[MAX_LEVEL]; |
724 struct idr_layer *pa[MAX_LEVEL]; |
731 struct ida_bitmap *bitmap; |
725 struct ida_bitmap *bitmap; |