aboutsummaryrefslogtreecommitdiffstats
path: root/lib/idr.c
diff options
context:
space:
mode:
authorNadia Derbey <Nadia.Derbey@bull.net>2008-07-25 04:48:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:42 -0400
commit3219b3b7456d5cf15ba7b1fe7b1bcf15ce8840e2 (patch)
treea7743ab2924063ff1b5dca4d835e760c8d4c7edf /lib/idr.c
parent944ca05c7b4972f2ebf37262e0f4933d178ad6db (diff)
idr: make idr_get_new* rcu-safe
Make the idr_get_new* routines rcu-safe. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> Reviewed-by: "Paul E. McKenney" <paulmck@us.ibm.com> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: Jim Houston <jim.houston@comcast.net> Cc: Pierre Peiffer <peifferp@gmail.com> Acked-by: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/idr.c')
-rw-r--r--lib/idr.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 80ba06f29d36..44ab3b2a4eba 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -6,6 +6,8 @@
6 * Modified by George Anzinger to reuse immediately and to use 6 * Modified by George Anzinger to reuse immediately and to use
7 * find bit instructions. Also removed _irq on spinlocks. 7 * find bit instructions. Also removed _irq on spinlocks.
8 * 8 *
9 * Modified by Nadia Derbey to make it RCU safe.
10 *
9 * Small id to pointer translation service. 11 * Small id to pointer translation service.
10 * 12 *
11 * It uses a radix tree like structure as a sparse array indexed 13 * It uses a radix tree like structure as a sparse array indexed
@@ -96,7 +98,7 @@ static void idr_mark_full(struct idr_layer **pa, int id)
96 * @gfp_mask: memory allocation flags 98 * @gfp_mask: memory allocation flags
97 * 99 *
98 * This function should be called prior to locking and calling the 100 * This function should be called prior to locking and calling the
99 * following function. It preallocates enough memory to satisfy 101 * idr_get_new* functions. It preallocates enough memory to satisfy
100 * the worst possible allocation. 102 * the worst possible allocation.
101 * 103 *
102 * If the system is REALLY out of memory this function returns 0, 104 * If the system is REALLY out of memory this function returns 0,
@@ -170,7 +172,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
170 new = get_from_free_list(idp); 172 new = get_from_free_list(idp);
171 if (!new) 173 if (!new)
172 return -1; 174 return -1;
173 p->ary[m] = new; 175 rcu_assign_pointer(p->ary[m], new);
174 p->count++; 176 p->count++;
175 } 177 }
176 pa[l--] = p; 178 pa[l--] = p;
@@ -226,7 +228,7 @@ build_up:
226 __set_bit(0, &new->bitmap); 228 __set_bit(0, &new->bitmap);
227 p = new; 229 p = new;
228 } 230 }
229 idp->top = p; 231 rcu_assign_pointer(idp->top, p);
230 idp->layers = layers; 232 idp->layers = layers;
231 v = sub_alloc(idp, &id, pa); 233 v = sub_alloc(idp, &id, pa);
232 if (v == IDR_NEED_TO_GROW) 234 if (v == IDR_NEED_TO_GROW)
@@ -245,7 +247,8 @@ static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
245 * Successfully found an empty slot. Install the user 247 * Successfully found an empty slot. Install the user
246 * pointer and mark the slot full. 248 * pointer and mark the slot full.
247 */ 249 */
248 pa[0]->ary[id & IDR_MASK] = (struct idr_layer *)ptr; 250 rcu_assign_pointer(pa[0]->ary[id & IDR_MASK],
251 (struct idr_layer *)ptr);
249 pa[0]->count++; 252 pa[0]->count++;
250 idr_mark_full(pa, id); 253 idr_mark_full(pa, id);
251 } 254 }
@@ -710,7 +713,8 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
710 return -EAGAIN; 713 return -EAGAIN;
711 714
712 memset(bitmap, 0, sizeof(struct ida_bitmap)); 715 memset(bitmap, 0, sizeof(struct ida_bitmap));
713 pa[0]->ary[idr_id & IDR_MASK] = (void *)bitmap; 716 rcu_assign_pointer(pa[0]->ary[idr_id & IDR_MASK],
717 (void *)bitmap);
714 pa[0]->count++; 718 pa[0]->count++;
715 } 719 }
716 720