Deleted Added
full compact
linux_idr.c (277139) linux_idr.c (283675)
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 171 unchanged lines hidden (view full) ---

180 res = il->ary[idx];
181 il->ary[idx] = ptr;
182 }
183out:
184 mtx_unlock(&idr->lock);
185 return (res);
186}
187
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 171 unchanged lines hidden (view full) ---

180 res = il->ary[idx];
181 il->ary[idx] = ptr;
182 }
183out:
184 mtx_unlock(&idr->lock);
185 return (res);
186}
187
188void *
189idr_find(struct idr *idr, int id)
188static inline void *
189idr_find_locked(struct idr *idr, int id)
190{
191 struct idr_layer *il;
192 void *res;
193 int layer;
194
190{
191 struct idr_layer *il;
192 void *res;
193 int layer;
194
195 res = NULL;
195 mtx_assert(&idr->lock, MA_OWNED);
196
196 id &= MAX_ID_MASK;
197 id &= MAX_ID_MASK;
197 mtx_lock(&idr->lock);
198 res = NULL;
198 il = idr->top;
199 layer = idr->layers - 1;
200 if (il == NULL || id > idr_max(idr))
199 il = idr->top;
200 layer = idr->layers - 1;
201 if (il == NULL || id > idr_max(idr))
201 goto out;
202 return (NULL);
202 while (layer && il) {
203 il = il->ary[idr_pos(id, layer)];
204 layer--;
205 }
206 if (il != NULL)
207 res = il->ary[id & IDR_MASK];
203 while (layer && il) {
204 il = il->ary[idr_pos(id, layer)];
205 layer--;
206 }
207 if (il != NULL)
208 res = il->ary[id & IDR_MASK];
208out:
209 return (res);
210}
211
212void *
213idr_find(struct idr *idr, int id)
214{
215 void *res;
216
217 mtx_lock(&idr->lock);
218 res = idr_find_locked(idr, id);
209 mtx_unlock(&idr->lock);
210 return (res);
211}
212
213int
214idr_pre_get(struct idr *idr, gfp_t gfp_mask)
215{
216 struct idr_layer *il, *iln;

--- 109 unchanged lines hidden (view full) ---

326 * Clear bitmaps potentially up to the root.
327 */
328 while (il->bitmap == 0 && ++layer < idr->layers) {
329 il = stack[layer];
330 il->bitmap &= ~(1 << idr_pos(id, layer));
331 }
332 error = 0;
333out:
219 mtx_unlock(&idr->lock);
220 return (res);
221}
222
223int
224idr_pre_get(struct idr *idr, gfp_t gfp_mask)
225{
226 struct idr_layer *il, *iln;

--- 109 unchanged lines hidden (view full) ---

336 * Clear bitmaps potentially up to the root.
337 */
338 while (il->bitmap == 0 && ++layer < idr->layers) {
339 il = stack[layer];
340 il->bitmap &= ~(1 << idr_pos(id, layer));
341 }
342 error = 0;
343out:
334 mtx_unlock(&idr->lock);
335#ifdef INVARIANTS
344#ifdef INVARIANTS
336 if (error == 0 && idr_find(idr, id) != ptr) {
345 if (error == 0 && idr_find_locked(idr, id) != ptr) {
337 panic("idr_get_new: Failed for idr %p, id %d, ptr %p\n",
338 idr, id, ptr);
339 }
340#endif
346 panic("idr_get_new: Failed for idr %p, id %d, ptr %p\n",
347 idr, id, ptr);
348 }
349#endif
350 mtx_unlock(&idr->lock);
341 return (error);
342}
343
344int
345idr_get_new_above(struct idr *idr, void *ptr, int starting_id, int *idp)
346{
347 struct idr_layer *stack[MAX_LEVEL];
348 struct idr_layer *il;

--- 84 unchanged lines hidden (view full) ---

433 * Clear bitmaps potentially up to the root.
434 */
435 while (il->bitmap == 0 && ++layer < idr->layers) {
436 il = stack[layer];
437 il->bitmap &= ~(1 << idr_pos(id, layer));
438 }
439 error = 0;
440out:
351 return (error);
352}
353
354int
355idr_get_new_above(struct idr *idr, void *ptr, int starting_id, int *idp)
356{
357 struct idr_layer *stack[MAX_LEVEL];
358 struct idr_layer *il;

--- 84 unchanged lines hidden (view full) ---

443 * Clear bitmaps potentially up to the root.
444 */
445 while (il->bitmap == 0 && ++layer < idr->layers) {
446 il = stack[layer];
447 il->bitmap &= ~(1 << idr_pos(id, layer));
448 }
449 error = 0;
450out:
441 mtx_unlock(&idr->lock);
442#ifdef INVARIANTS
451#ifdef INVARIANTS
443 if (error == 0 && idr_find(idr, id) != ptr) {
452 if (error == 0 && idr_find_locked(idr, id) != ptr) {
444 panic("idr_get_new_above: Failed for idr %p, id %d, ptr %p\n",
445 idr, id, ptr);
446 }
447#endif
453 panic("idr_get_new_above: Failed for idr %p, id %d, ptr %p\n",
454 idr, id, ptr);
455 }
456#endif
457 mtx_unlock(&idr->lock);
448 return (error);
449}
458 return (error);
459}