dm-bio-prison.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2011-2012 Red Hat, Inc.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_BIO_PRISON_H
  7. #define DM_BIO_PRISON_H
  8. #include "persistent-data/dm-block-manager.h" /* FIXME: for dm_block_t */
  9. #include "dm-thin-metadata.h" /* FIXME: for dm_thin_id */
  10. #include <linux/list.h>
  11. #include <linux/bio.h>
  12. /*----------------------------------------------------------------*/
  13. /*
  14. * Sometimes we can't deal with a bio straight away. We put them in prison
  15. * where they can't cause any mischief. Bios are put in a cell identified
  16. * by a key, multiple bios can be in the same cell. When the cell is
  17. * subsequently unlocked the bios become available.
  18. */
  19. struct dm_bio_prison;
  20. struct dm_bio_prison_cell;
  21. /* FIXME: this needs to be more abstract */
  22. struct dm_cell_key {
  23. int virtual;
  24. dm_thin_id dev;
  25. dm_block_t block;
  26. };
  27. struct dm_bio_prison *dm_bio_prison_create(unsigned nr_cells);
  28. void dm_bio_prison_destroy(struct dm_bio_prison *prison);
  29. /*
  30. * This may block if a new cell needs allocating. You must ensure that
  31. * cells will be unlocked even if the calling thread is blocked.
  32. *
  33. * Returns 1 if the cell was already held, 0 if @inmate is the new holder.
  34. */
  35. int dm_bio_detain(struct dm_bio_prison *prison, struct dm_cell_key *key,
  36. struct bio *inmate, struct dm_bio_prison_cell **ref);
  37. void dm_cell_release(struct dm_bio_prison_cell *cell, struct bio_list *bios);
  38. void dm_cell_release_no_holder(struct dm_bio_prison_cell *cell, struct bio_list *inmates);
  39. void dm_cell_error(struct dm_bio_prison_cell *cell);
  40. /*----------------------------------------------------------------*/
  41. /*
  42. * We use the deferred set to keep track of pending reads to shared blocks.
  43. * We do this to ensure the new mapping caused by a write isn't performed
  44. * until these prior reads have completed. Otherwise the insertion of the
  45. * new mapping could free the old block that the read bios are mapped to.
  46. */
  47. struct dm_deferred_set;
  48. struct dm_deferred_entry;
  49. struct dm_deferred_set *dm_deferred_set_create(void);
  50. void dm_deferred_set_destroy(struct dm_deferred_set *ds);
  51. struct dm_deferred_entry *dm_deferred_entry_inc(struct dm_deferred_set *ds);
  52. void dm_deferred_entry_dec(struct dm_deferred_entry *entry, struct list_head *head);
  53. int dm_deferred_set_add_work(struct dm_deferred_set *ds, struct list_head *work);
  54. /*----------------------------------------------------------------*/
  55. #endif