idr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/bitmap.h>
  3. #include <linux/bug.h>
  4. #include <linux/export.h>
  5. #include <linux/idr.h>
  6. #include <linux/slab.h>
  7. #include <linux/spinlock.h>
  8. #include <linux/xarray.h>
  9. /**
  10. * idr_alloc_u32() - Allocate an ID.
  11. * @idr: IDR handle.
  12. * @ptr: Pointer to be associated with the new ID.
  13. * @nextid: Pointer to an ID.
  14. * @max: The maximum ID to allocate (inclusive).
  15. * @gfp: Memory allocation flags.
  16. *
  17. * Allocates an unused ID in the range specified by @nextid and @max.
  18. * Note that @max is inclusive whereas the @end parameter to idr_alloc()
  19. * is exclusive. The new ID is assigned to @nextid before the pointer
  20. * is inserted into the IDR, so if @nextid points into the object pointed
  21. * to by @ptr, a concurrent lookup will not find an uninitialised ID.
  22. *
  23. * The caller should provide their own locking to ensure that two
  24. * concurrent modifications to the IDR are not possible. Read-only
  25. * accesses to the IDR may be done under the RCU read lock or may
  26. * exclude simultaneous writers.
  27. *
  28. * Return: 0 if an ID was allocated, -ENOMEM if memory allocation failed,
  29. * or -ENOSPC if no free IDs could be found. If an error occurred,
  30. * @nextid is unchanged.
  31. */
  32. int idr_alloc_u32(struct idr *idr, void *ptr, u32 *nextid,
  33. unsigned long max, gfp_t gfp)
  34. {
  35. struct radix_tree_iter iter;
  36. void __rcu **slot;
  37. unsigned int base = idr->idr_base;
  38. unsigned int id = *nextid;
  39. if (WARN_ON_ONCE(!(idr->idr_rt.xa_flags & ROOT_IS_IDR)))
  40. idr->idr_rt.xa_flags |= IDR_RT_MARKER;
  41. id = (id < base) ? 0 : id - base;
  42. radix_tree_iter_init(&iter, id);
  43. slot = idr_get_free(&idr->idr_rt, &iter, gfp, max - base);
  44. if (IS_ERR(slot))
  45. return PTR_ERR(slot);
  46. *nextid = iter.index + base;
  47. /* there is a memory barrier inside radix_tree_iter_replace() */
  48. radix_tree_iter_replace(&idr->idr_rt, &iter, slot, ptr);
  49. radix_tree_iter_tag_clear(&idr->idr_rt, &iter, IDR_FREE);
  50. return 0;
  51. }
  52. EXPORT_SYMBOL_GPL(idr_alloc_u32);
  53. /**
  54. * idr_alloc() - Allocate an ID.
  55. * @idr: IDR handle.
  56. * @ptr: Pointer to be associated with the new ID.
  57. * @start: The minimum ID (inclusive).
  58. * @end: The maximum ID (exclusive).
  59. * @gfp: Memory allocation flags.
  60. *
  61. * Allocates an unused ID in the range specified by @start and @end. If
  62. * @end is <= 0, it is treated as one larger than %INT_MAX. This allows
  63. * callers to use @start + N as @end as long as N is within integer range.
  64. *
  65. * The caller should provide their own locking to ensure that two
  66. * concurrent modifications to the IDR are not possible. Read-only
  67. * accesses to the IDR may be done under the RCU read lock or may
  68. * exclude simultaneous writers.
  69. *
  70. * Return: The newly allocated ID, -ENOMEM if memory allocation failed,
  71. * or -ENOSPC if no free IDs could be found.
  72. */
  73. int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp)
  74. {
  75. u32 id = start;
  76. int ret;
  77. if (WARN_ON_ONCE(start < 0))
  78. return -EINVAL;
  79. ret = idr_alloc_u32(idr, ptr, &id, end > 0 ? end - 1 : INT_MAX, gfp);
  80. if (ret)
  81. return ret;
  82. return id;
  83. }
  84. EXPORT_SYMBOL_GPL(idr_alloc);
  85. /**
  86. * idr_alloc_cyclic() - Allocate an ID cyclically.
  87. * @idr: IDR handle.
  88. * @ptr: Pointer to be associated with the new ID.
  89. * @start: The minimum ID (inclusive).
  90. * @end: The maximum ID (exclusive).
  91. * @gfp: Memory allocation flags.
  92. *
  93. * Allocates an unused ID in the range specified by @nextid and @end. If
  94. * @end is <= 0, it is treated as one larger than %INT_MAX. This allows
  95. * callers to use @start + N as @end as long as N is within integer range.
  96. * The search for an unused ID will start at the last ID allocated and will
  97. * wrap around to @start if no free IDs are found before reaching @end.
  98. *
  99. * The caller should provide their own locking to ensure that two
  100. * concurrent modifications to the IDR are not possible. Read-only
  101. * accesses to the IDR may be done under the RCU read lock or may
  102. * exclude simultaneous writers.
  103. *
  104. * Return: The newly allocated ID, -ENOMEM if memory allocation failed,
  105. * or -ENOSPC if no free IDs could be found.
  106. */
  107. int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, gfp_t gfp)
  108. {
  109. u32 id = idr->idr_next;
  110. int err, max = end > 0 ? end - 1 : INT_MAX;
  111. if ((int)id < start)
  112. id = start;
  113. err = idr_alloc_u32(idr, ptr, &id, max, gfp);
  114. if ((err == -ENOSPC) && (id > start)) {
  115. id = start;
  116. err = idr_alloc_u32(idr, ptr, &id, max, gfp);
  117. }
  118. if (err)
  119. return err;
  120. idr->idr_next = id + 1;
  121. return id;
  122. }
  123. EXPORT_SYMBOL(idr_alloc_cyclic);
  124. /**
  125. * idr_remove() - Remove an ID from the IDR.
  126. * @idr: IDR handle.
  127. * @id: Pointer ID.
  128. *
  129. * Removes this ID from the IDR. If the ID was not previously in the IDR,
  130. * this function returns %NULL.
  131. *
  132. * Since this function modifies the IDR, the caller should provide their
  133. * own locking to ensure that concurrent modification of the same IDR is
  134. * not possible.
  135. *
  136. * Return: The pointer formerly associated with this ID.
  137. */
  138. void *idr_remove(struct idr *idr, unsigned long id)
  139. {
  140. return radix_tree_delete_item(&idr->idr_rt, id - idr->idr_base, NULL);
  141. }
  142. EXPORT_SYMBOL_GPL(idr_remove);
  143. /**
  144. * idr_find() - Return pointer for given ID.
  145. * @idr: IDR handle.
  146. * @id: Pointer ID.
  147. *
  148. * Looks up the pointer associated with this ID. A %NULL pointer may
  149. * indicate that @id is not allocated or that the %NULL pointer was
  150. * associated with this ID.
  151. *
  152. * This function can be called under rcu_read_lock(), given that the leaf
  153. * pointers lifetimes are correctly managed.
  154. *
  155. * Return: The pointer associated with this ID.
  156. */
  157. void *idr_find(const struct idr *idr, unsigned long id)
  158. {
  159. return radix_tree_lookup(&idr->idr_rt, id - idr->idr_base);
  160. }
  161. EXPORT_SYMBOL_GPL(idr_find);
  162. /**
  163. * idr_for_each() - Iterate through all stored pointers.
  164. * @idr: IDR handle.
  165. * @fn: Function to be called for each pointer.
  166. * @data: Data passed to callback function.
  167. *
  168. * The callback function will be called for each entry in @idr, passing
  169. * the ID, the entry and @data.
  170. *
  171. * If @fn returns anything other than %0, the iteration stops and that
  172. * value is returned from this function.
  173. *
  174. * idr_for_each() can be called concurrently with idr_alloc() and
  175. * idr_remove() if protected by RCU. Newly added entries may not be
  176. * seen and deleted entries may be seen, but adding and removing entries
  177. * will not cause other entries to be skipped, nor spurious ones to be seen.
  178. */
  179. int idr_for_each(const struct idr *idr,
  180. int (*fn)(int id, void *p, void *data), void *data)
  181. {
  182. struct radix_tree_iter iter;
  183. void __rcu **slot;
  184. int base = idr->idr_base;
  185. radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0) {
  186. int ret;
  187. unsigned long id = iter.index + base;
  188. if (WARN_ON_ONCE(id > INT_MAX))
  189. break;
  190. ret = fn(id, rcu_dereference_raw(*slot), data);
  191. if (ret)
  192. return ret;
  193. }
  194. return 0;
  195. }
  196. EXPORT_SYMBOL(idr_for_each);
  197. /**
  198. * idr_get_next_ul() - Find next populated entry.
  199. * @idr: IDR handle.
  200. * @nextid: Pointer to an ID.
  201. *
  202. * Returns the next populated entry in the tree with an ID greater than
  203. * or equal to the value pointed to by @nextid. On exit, @nextid is updated
  204. * to the ID of the found value. To use in a loop, the value pointed to by
  205. * nextid must be incremented by the user.
  206. */
  207. void *idr_get_next_ul(struct idr *idr, unsigned long *nextid)
  208. {
  209. struct radix_tree_iter iter;
  210. void __rcu **slot;
  211. void *entry = NULL;
  212. unsigned long base = idr->idr_base;
  213. unsigned long id = *nextid;
  214. id = (id < base) ? 0 : id - base;
  215. radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, id) {
  216. entry = rcu_dereference_raw(*slot);
  217. if (!entry)
  218. continue;
  219. if (!xa_is_internal(entry))
  220. break;
  221. if (slot != &idr->idr_rt.xa_head && !xa_is_retry(entry))
  222. break;
  223. slot = radix_tree_iter_retry(&iter);
  224. }
  225. if (!slot)
  226. return NULL;
  227. *nextid = iter.index + base;
  228. return entry;
  229. }
  230. EXPORT_SYMBOL(idr_get_next_ul);
  231. /**
  232. * idr_get_next() - Find next populated entry.
  233. * @idr: IDR handle.
  234. * @nextid: Pointer to an ID.
  235. *
  236. * Returns the next populated entry in the tree with an ID greater than
  237. * or equal to the value pointed to by @nextid. On exit, @nextid is updated
  238. * to the ID of the found value. To use in a loop, the value pointed to by
  239. * nextid must be incremented by the user.
  240. */
  241. void *idr_get_next(struct idr *idr, int *nextid)
  242. {
  243. unsigned long id = *nextid;
  244. void *entry = idr_get_next_ul(idr, &id);
  245. if (WARN_ON_ONCE(id > INT_MAX))
  246. return NULL;
  247. *nextid = id;
  248. return entry;
  249. }
  250. EXPORT_SYMBOL(idr_get_next);
  251. /**
  252. * idr_replace() - replace pointer for given ID.
  253. * @idr: IDR handle.
  254. * @ptr: New pointer to associate with the ID.
  255. * @id: ID to change.
  256. *
  257. * Replace the pointer registered with an ID and return the old value.
  258. * This function can be called under the RCU read lock concurrently with
  259. * idr_alloc() and idr_remove() (as long as the ID being removed is not
  260. * the one being replaced!).
  261. *
  262. * Returns: the old value on success. %-ENOENT indicates that @id was not
  263. * found. %-EINVAL indicates that @ptr was not valid.
  264. */
  265. void *idr_replace(struct idr *idr, void *ptr, unsigned long id)
  266. {
  267. struct radix_tree_node *node;
  268. void __rcu **slot = NULL;
  269. void *entry;
  270. id -= idr->idr_base;
  271. entry = __radix_tree_lookup(&idr->idr_rt, id, &node, &slot);
  272. if (!slot || radix_tree_tag_get(&idr->idr_rt, id, IDR_FREE))
  273. return ERR_PTR(-ENOENT);
  274. __radix_tree_replace(&idr->idr_rt, node, slot, ptr);
  275. return entry;
  276. }
  277. EXPORT_SYMBOL(idr_replace);
  278. /**
  279. * DOC: IDA description
  280. *
  281. * The IDA is an ID allocator which does not provide the ability to
  282. * associate an ID with a pointer. As such, it only needs to store one
  283. * bit per ID, and so is more space efficient than an IDR. To use an IDA,
  284. * define it using DEFINE_IDA() (or embed a &struct ida in a data structure,
  285. * then initialise it using ida_init()). To allocate a new ID, call
  286. * ida_alloc(), ida_alloc_min(), ida_alloc_max() or ida_alloc_range().
  287. * To free an ID, call ida_free().
  288. *
  289. * ida_destroy() can be used to dispose of an IDA without needing to
  290. * free the individual IDs in it. You can use ida_is_empty() to find
  291. * out whether the IDA has any IDs currently allocated.
  292. *
  293. * The IDA handles its own locking. It is safe to call any of the IDA
  294. * functions without synchronisation in your code.
  295. *
  296. * IDs are currently limited to the range [0-INT_MAX]. If this is an awkward
  297. * limitation, it should be quite straightforward to raise the maximum.
  298. */
  299. /*
  300. * Developer's notes:
  301. *
  302. * The IDA uses the functionality provided by the XArray to store bitmaps in
  303. * each entry. The XA_FREE_MARK is only cleared when all bits in the bitmap
  304. * have been set.
  305. *
  306. * I considered telling the XArray that each slot is an order-10 node
  307. * and indexing by bit number, but the XArray can't allow a single multi-index
  308. * entry in the head, which would significantly increase memory consumption
  309. * for the IDA. So instead we divide the index by the number of bits in the
  310. * leaf bitmap before doing a radix tree lookup.
  311. *
  312. * As an optimisation, if there are only a few low bits set in any given
  313. * leaf, instead of allocating a 128-byte bitmap, we store the bits
  314. * as a value entry. Value entries never have the XA_FREE_MARK cleared
  315. * because we can always convert them into a bitmap entry.
  316. *
  317. * It would be possible to optimise further; once we've run out of a
  318. * single 128-byte bitmap, we currently switch to a 576-byte node, put
  319. * the 128-byte bitmap in the first entry and then start allocating extra
  320. * 128-byte entries. We could instead use the 512 bytes of the node's
  321. * data as a bitmap before moving to that scheme. I do not believe this
  322. * is a worthwhile optimisation; Rasmus Villemoes surveyed the current
  323. * users of the IDA and almost none of them use more than 1024 entries.
  324. * Those that do use more than the 8192 IDs that the 512 bytes would
  325. * provide.
  326. *
  327. * The IDA always uses a lock to alloc/free. If we add a 'test_bit'
  328. * equivalent, it will still need locking. Going to RCU lookup would require
  329. * using RCU to free bitmaps, and that's not trivial without embedding an
  330. * RCU head in the bitmap, which adds a 2-pointer overhead to each 128-byte
  331. * bitmap, which is excessive.
  332. */
  333. /**
  334. * ida_alloc_range() - Allocate an unused ID.
  335. * @ida: IDA handle.
  336. * @min: Lowest ID to allocate.
  337. * @max: Highest ID to allocate.
  338. * @gfp: Memory allocation flags.
  339. *
  340. * Allocate an ID between @min and @max, inclusive. The allocated ID will
  341. * not exceed %INT_MAX, even if @max is larger.
  342. *
  343. * Context: Any context. It is safe to call this function without
  344. * locking in your code.
  345. * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
  346. * or %-ENOSPC if there are no free IDs.
  347. */
  348. int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max,
  349. gfp_t gfp)
  350. {
  351. XA_STATE(xas, &ida->xa, min / IDA_BITMAP_BITS);
  352. unsigned bit = min % IDA_BITMAP_BITS;
  353. unsigned long flags;
  354. struct ida_bitmap *bitmap, *alloc = NULL;
  355. if ((int)min < 0)
  356. return -ENOSPC;
  357. if ((int)max < 0)
  358. max = INT_MAX;
  359. retry:
  360. xas_lock_irqsave(&xas, flags);
  361. next:
  362. bitmap = xas_find_marked(&xas, max / IDA_BITMAP_BITS, XA_FREE_MARK);
  363. if (xas.xa_index > min / IDA_BITMAP_BITS)
  364. bit = 0;
  365. if (xas.xa_index * IDA_BITMAP_BITS + bit > max)
  366. goto nospc;
  367. if (xa_is_value(bitmap)) {
  368. unsigned long tmp = xa_to_value(bitmap);
  369. if (bit < BITS_PER_XA_VALUE) {
  370. bit = find_next_zero_bit(&tmp, BITS_PER_XA_VALUE, bit);
  371. if (xas.xa_index * IDA_BITMAP_BITS + bit > max)
  372. goto nospc;
  373. if (bit < BITS_PER_XA_VALUE) {
  374. tmp |= 1UL << bit;
  375. xas_store(&xas, xa_mk_value(tmp));
  376. goto out;
  377. }
  378. }
  379. bitmap = alloc;
  380. if (!bitmap)
  381. bitmap = kzalloc(sizeof(*bitmap), GFP_NOWAIT);
  382. if (!bitmap)
  383. goto alloc;
  384. bitmap->bitmap[0] = tmp;
  385. xas_store(&xas, bitmap);
  386. if (xas_error(&xas)) {
  387. bitmap->bitmap[0] = 0;
  388. goto out;
  389. }
  390. }
  391. if (bitmap) {
  392. bit = find_next_zero_bit(bitmap->bitmap, IDA_BITMAP_BITS, bit);
  393. if (xas.xa_index * IDA_BITMAP_BITS + bit > max)
  394. goto nospc;
  395. if (bit == IDA_BITMAP_BITS)
  396. goto next;
  397. __set_bit(bit, bitmap->bitmap);
  398. if (bitmap_full(bitmap->bitmap, IDA_BITMAP_BITS))
  399. xas_clear_mark(&xas, XA_FREE_MARK);
  400. } else {
  401. if (bit < BITS_PER_XA_VALUE) {
  402. bitmap = xa_mk_value(1UL << bit);
  403. } else {
  404. bitmap = alloc;
  405. if (!bitmap)
  406. bitmap = kzalloc(sizeof(*bitmap), GFP_NOWAIT);
  407. if (!bitmap)
  408. goto alloc;
  409. __set_bit(bit, bitmap->bitmap);
  410. }
  411. xas_store(&xas, bitmap);
  412. }
  413. out:
  414. xas_unlock_irqrestore(&xas, flags);
  415. if (xas_nomem(&xas, gfp)) {
  416. xas.xa_index = min / IDA_BITMAP_BITS;
  417. bit = min % IDA_BITMAP_BITS;
  418. goto retry;
  419. }
  420. if (bitmap != alloc)
  421. kfree(alloc);
  422. if (xas_error(&xas))
  423. return xas_error(&xas);
  424. return xas.xa_index * IDA_BITMAP_BITS + bit;
  425. alloc:
  426. xas_unlock_irqrestore(&xas, flags);
  427. alloc = kzalloc(sizeof(*bitmap), gfp);
  428. if (!alloc)
  429. return -ENOMEM;
  430. xas_set(&xas, min / IDA_BITMAP_BITS);
  431. bit = min % IDA_BITMAP_BITS;
  432. goto retry;
  433. nospc:
  434. xas_unlock_irqrestore(&xas, flags);
  435. kfree(alloc);
  436. return -ENOSPC;
  437. }
  438. EXPORT_SYMBOL(ida_alloc_range);
  439. /**
  440. * ida_free() - Release an allocated ID.
  441. * @ida: IDA handle.
  442. * @id: Previously allocated ID.
  443. *
  444. * Context: Any context. It is safe to call this function without
  445. * locking in your code.
  446. */
  447. void ida_free(struct ida *ida, unsigned int id)
  448. {
  449. XA_STATE(xas, &ida->xa, id / IDA_BITMAP_BITS);
  450. unsigned bit = id % IDA_BITMAP_BITS;
  451. struct ida_bitmap *bitmap;
  452. unsigned long flags;
  453. BUG_ON((int)id < 0);
  454. xas_lock_irqsave(&xas, flags);
  455. bitmap = xas_load(&xas);
  456. if (xa_is_value(bitmap)) {
  457. unsigned long v = xa_to_value(bitmap);
  458. if (bit >= BITS_PER_XA_VALUE)
  459. goto err;
  460. if (!(v & (1UL << bit)))
  461. goto err;
  462. v &= ~(1UL << bit);
  463. if (!v)
  464. goto delete;
  465. xas_store(&xas, xa_mk_value(v));
  466. } else {
  467. if (!test_bit(bit, bitmap->bitmap))
  468. goto err;
  469. __clear_bit(bit, bitmap->bitmap);
  470. xas_set_mark(&xas, XA_FREE_MARK);
  471. if (bitmap_empty(bitmap->bitmap, IDA_BITMAP_BITS)) {
  472. kfree(bitmap);
  473. delete:
  474. xas_store(&xas, NULL);
  475. }
  476. }
  477. xas_unlock_irqrestore(&xas, flags);
  478. return;
  479. err:
  480. xas_unlock_irqrestore(&xas, flags);
  481. WARN(1, "ida_free called for id=%d which is not allocated.\n", id);
  482. }
  483. EXPORT_SYMBOL(ida_free);
  484. /**
  485. * ida_destroy() - Free all IDs.
  486. * @ida: IDA handle.
  487. *
  488. * Calling this function frees all IDs and releases all resources used
  489. * by an IDA. When this call returns, the IDA is empty and can be reused
  490. * or freed. If the IDA is already empty, there is no need to call this
  491. * function.
  492. *
  493. * Context: Any context. It is safe to call this function without
  494. * locking in your code.
  495. */
  496. void ida_destroy(struct ida *ida)
  497. {
  498. XA_STATE(xas, &ida->xa, 0);
  499. struct ida_bitmap *bitmap;
  500. unsigned long flags;
  501. xas_lock_irqsave(&xas, flags);
  502. xas_for_each(&xas, bitmap, ULONG_MAX) {
  503. if (!xa_is_value(bitmap))
  504. kfree(bitmap);
  505. xas_store(&xas, NULL);
  506. }
  507. xas_unlock_irqrestore(&xas, flags);
  508. }
  509. EXPORT_SYMBOL(ida_destroy);
  510. #ifndef __KERNEL__
  511. extern void xa_dump_index(unsigned long index, unsigned int shift);
  512. #define IDA_CHUNK_SHIFT ilog2(IDA_BITMAP_BITS)
  513. static void ida_dump_entry(void *entry, unsigned long index)
  514. {
  515. unsigned long i;
  516. if (!entry)
  517. return;
  518. if (xa_is_node(entry)) {
  519. struct xa_node *node = xa_to_node(entry);
  520. unsigned int shift = node->shift + IDA_CHUNK_SHIFT +
  521. XA_CHUNK_SHIFT;
  522. xa_dump_index(index * IDA_BITMAP_BITS, shift);
  523. xa_dump_node(node);
  524. for (i = 0; i < XA_CHUNK_SIZE; i++)
  525. ida_dump_entry(node->slots[i],
  526. index | (i << node->shift));
  527. } else if (xa_is_value(entry)) {
  528. xa_dump_index(index * IDA_BITMAP_BITS, ilog2(BITS_PER_LONG));
  529. pr_cont("value: data %lx [%px]\n", xa_to_value(entry), entry);
  530. } else {
  531. struct ida_bitmap *bitmap = entry;
  532. xa_dump_index(index * IDA_BITMAP_BITS, IDA_CHUNK_SHIFT);
  533. pr_cont("bitmap: %p data", bitmap);
  534. for (i = 0; i < IDA_BITMAP_LONGS; i++)
  535. pr_cont(" %lx", bitmap->bitmap[i]);
  536. pr_cont("\n");
  537. }
  538. }
  539. static void ida_dump(struct ida *ida)
  540. {
  541. struct xarray *xa = &ida->xa;
  542. pr_debug("ida: %p node %p free %d\n", ida, xa->xa_head,
  543. xa->xa_flags >> ROOT_TAG_SHIFT);
  544. ida_dump_entry(xa->xa_head, 0);
  545. }
  546. #endif