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