H A D | dm-bio-prison.c | 8 #include "dm-bio-prison.h" 35 struct dm_bio_prison *prison = kmalloc(sizeof(*prison), GFP_KERNEL); dm_bio_prison_create() local 37 if (!prison) dm_bio_prison_create() 40 spin_lock_init(&prison->lock); dm_bio_prison_create() 42 prison->cell_pool = mempool_create_slab_pool(MIN_CELLS, _cell_cache); dm_bio_prison_create() 43 if (!prison->cell_pool) { dm_bio_prison_create() 44 kfree(prison); dm_bio_prison_create() 48 prison->cells = RB_ROOT; dm_bio_prison_create() 50 return prison; dm_bio_prison_create() 54 void dm_bio_prison_destroy(struct dm_bio_prison *prison) dm_bio_prison_destroy() argument 56 mempool_destroy(prison->cell_pool); dm_bio_prison_destroy() 57 kfree(prison); dm_bio_prison_destroy() 61 struct dm_bio_prison_cell *dm_bio_prison_alloc_cell(struct dm_bio_prison *prison, gfp_t gfp) dm_bio_prison_alloc_cell() argument 63 return mempool_alloc(prison->cell_pool, gfp); dm_bio_prison_alloc_cell() 67 void dm_bio_prison_free_cell(struct dm_bio_prison *prison, dm_bio_prison_free_cell() argument 70 mempool_free(cell, prison->cell_pool); dm_bio_prison_free_cell() 107 static int __bio_detain(struct dm_bio_prison *prison, __bio_detain() argument 114 struct rb_node **new = &prison->cells.rb_node, *parent = NULL; __bio_detain() 139 rb_insert_color(&cell_prealloc->node, &prison->cells); __bio_detain() 144 static int bio_detain(struct dm_bio_prison *prison, bio_detain() argument 153 spin_lock_irqsave(&prison->lock, flags); bio_detain() 154 r = __bio_detain(prison, key, inmate, cell_prealloc, cell_result); bio_detain() 155 spin_unlock_irqrestore(&prison->lock, flags); bio_detain() 160 int dm_bio_detain(struct dm_bio_prison *prison, dm_bio_detain() argument 166 return bio_detain(prison, key, inmate, cell_prealloc, cell_result); dm_bio_detain() 170 int dm_get_cell(struct dm_bio_prison *prison, dm_get_cell() argument 175 return bio_detain(prison, key, NULL, cell_prealloc, cell_result); dm_get_cell() 182 static void __cell_release(struct dm_bio_prison *prison, __cell_release() argument 186 rb_erase(&cell->node, &prison->cells); __cell_release() 195 void dm_cell_release(struct dm_bio_prison *prison, dm_cell_release() argument 201 spin_lock_irqsave(&prison->lock, flags); dm_cell_release() 202 __cell_release(prison, cell, bios); dm_cell_release() 203 spin_unlock_irqrestore(&prison->lock, flags); dm_cell_release() 210 static void __cell_release_no_holder(struct dm_bio_prison *prison, __cell_release_no_holder() argument 214 rb_erase(&cell->node, &prison->cells); __cell_release_no_holder() 218 void dm_cell_release_no_holder(struct dm_bio_prison *prison, dm_cell_release_no_holder() argument 224 spin_lock_irqsave(&prison->lock, flags); dm_cell_release_no_holder() 225 __cell_release_no_holder(prison, cell, inmates); dm_cell_release_no_holder() 226 spin_unlock_irqrestore(&prison->lock, flags); dm_cell_release_no_holder() 230 void dm_cell_error(struct dm_bio_prison *prison, dm_cell_error() argument 237 dm_cell_release(prison, cell, &bios); dm_cell_error() 246 void dm_cell_visit_release(struct dm_bio_prison *prison, dm_cell_visit_release() argument 253 spin_lock_irqsave(&prison->lock, flags); dm_cell_visit_release() 255 rb_erase(&cell->node, &prison->cells); dm_cell_visit_release() 256 spin_unlock_irqrestore(&prison->lock, flags); dm_cell_visit_release() 260 static int __promote_or_release(struct dm_bio_prison *prison, __promote_or_release() argument 264 rb_erase(&cell->node, &prison->cells); __promote_or_release() 272 int dm_cell_promote_or_release(struct dm_bio_prison *prison, dm_cell_promote_or_release() argument 278 spin_lock_irqsave(&prison->lock, flags); dm_cell_promote_or_release() 279 r = __promote_or_release(prison, cell); dm_cell_promote_or_release() 280 spin_unlock_irqrestore(&prison->lock, flags); dm_cell_promote_or_release() 422 MODULE_DESCRIPTION(DM_NAME " bio prison");
|