12 #include <linux/module.h>
13 #include <linux/slab.h>
36 static uint32_t calc_nr_buckets(
unsigned nr_cells)
41 nr_cells =
min(nr_cells, 8192
u);
67 prison->
cell_pool = mempool_create_slab_pool(nr_cells, _cell_cache);
75 prison->
cells = (
struct hlist_head *) (prison + 1);
76 for (i = 0; i < nr_buckets; i++)
92 const unsigned long BIG_PRIME = 4294967291
UL;
112 if (keys_equal(&cell->key, key))
129 uint32_t hash = hash_key(prison, key);
132 BUG_ON(hash > prison->nr_buckets);
136 cell = __search_bucket(prison->cells + hash, key);
138 bio_list_add(&cell->
bios, inmate);
145 spin_unlock_irqrestore(&prison->lock, flags);
153 cell = __search_bucket(prison->cells + hash, key);
156 bio_list_add(&cell->
bios, inmate);
168 bio_list_init(&cell->
bios);
169 hlist_add_head(&cell->
list, prison->cells + hash);
174 spin_unlock_irqrestore(&prison->lock, flags);
189 hlist_del(&cell->
list);
192 bio_list_add(inmates, cell->
holder);
193 bio_list_merge(inmates, &cell->
bios);
205 __cell_release(cell, bios);
206 spin_unlock_irqrestore(&prison->
lock, flags);
216 static void __cell_release_singleton(
struct dm_bio_prison_cell *cell,
struct bio *bio)
221 __cell_release(cell,
NULL);
230 __cell_release_singleton(cell, bio);
231 spin_unlock_irqrestore(&prison->
lock, flags);
242 hlist_del(&cell->
list);
243 bio_list_merge(inmates, &cell->
bios);
254 __cell_release_no_holder(cell, inmates);
255 spin_unlock_irqrestore(&prison->
lock, flags);
266 bio_list_init(&bios);
269 __cell_release(cell, &bios);
270 spin_unlock_irqrestore(&prison->
lock, flags);
272 while ((bio = bio_list_pop(&bios)))
279 #define DEFERRED_SET_SIZE 64
309 INIT_LIST_HEAD(&ds->
entries[i].work_items);
330 spin_unlock_irqrestore(&ds->
lock, flags);
336 static unsigned ds_next(
unsigned index)
360 __sweep(entry->
ds, head);
361 spin_unlock_irqrestore(&entry->
ds->lock, flags);
381 if (!ds->
entries[next_entry].count)
384 spin_unlock_irqrestore(&ds->
lock, flags);
392 static int __init dm_bio_prison_init(
void)
401 static void __exit dm_bio_prison_exit(
void)