* blist_alloc() - reserve space in the block bitmap. Return the base * of a contiguous region or SWAPBLK_NONE if space could * not be allocated. */
| 283 | * not be allocated. |
| 284 | */ |
| 285 | daddr_t |
| 286 | blist_alloc(blist_t bl, int *count, int maxcount) |
| 287 | { |
| 288 | daddr_t blk, cursor; |
| 289 | |
| 290 | KASSERT(*count <= maxcount, |
| 291 | ("invalid parameters %d > %d", *count, maxcount)); |
| 292 | KASSERT(*count <= BLIST_MAX_ALLOC, |
| 293 | ("minimum allocation too large: %d", *count)); |
| 294 | |
| 295 | /* |
| 296 | * This loop iterates at most twice. An allocation failure in the |
| 297 | * first iteration leads to a second iteration only if the cursor was |
| 298 | * non-zero. When the cursor is zero, an allocation failure will |
| 299 | * stop further iterations. |
| 300 | */ |
| 301 | for (cursor = bl->bl_cursor;; cursor = 0) { |
| 302 | blk = blst_meta_alloc(bl->bl_root, cursor, count, maxcount, |
| 303 | bl->bl_radix); |
| 304 | if (blk != SWAPBLK_NONE) { |
| 305 | bl->bl_avail -= *count; |
| 306 | bl->bl_cursor = blk + *count; |
| 307 | if (bl->bl_cursor == bl->bl_blocks) |
| 308 | bl->bl_cursor = 0; |
| 309 | return (blk); |
| 310 | } |
| 311 | if (cursor == 0) |
| 312 | return (SWAPBLK_NONE); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * blist_avail() - return the number of free blocks. |
no test coverage detected