dm-bio-prison.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /* FIXME: this needs to be more abstract */
  21. struct dm_cell_key {
  22. int virtual;
  23. dm_thin_id dev;
  24. dm_block_t block;
  25. };
  26. /*
  27. * Treat this as opaque, only in header so callers can manage allocation
  28. * themselves.
  29. */
  30. struct dm_bio_prison_cell {
  31. struct hlist_node list;
  32. struct dm_cell_key key;
  33. struct bio *holder;
  34. struct bio_list bios;
  35. };
  36. struct dm_bio_prison *dm_bio_prison_create(unsigned nr_cells);
  37. void dm_bio_prison_destroy(struct dm_bio_prison *prison);
  38. /*
  39. * These two functions just wrap a mempool. This is a transitory step:
  40. * Eventually all bio prison clients should manage their own cell memory.
  41. *
  42. * Like mempool_alloc(), dm_bio_prison_alloc_cell() can only fail if called
  43. * in interrupt context or passed GFP_NOWAIT.
  44. */
  45. struct dm_bio_prison_cell *dm_bio_prison_alloc_cell(struct dm_bio_prison *prison,
  46. gfp_t gfp);
  47. void dm_bio_prison_free_cell(struct dm_bio_prison *prison,
  48. struct dm_bio_prison_cell *cell);
  49. /*
  50. * Creates, or retrieves a cell for the given key.
  51. *
  52. * Returns 1 if pre-existing cell returned, zero if new cell created using
  53. * @cell_prealloc.
  54. */
  55. int dm_get_cell(struct dm_bio_prison *prison,
  56. struct dm_cell_key *key,
  57. struct dm_bio_prison_cell *cell_prealloc,
  58. struct dm_bio_prison_cell **cell_result);
  59. /*
  60. * An atomic op that combines retrieving a cell, and adding a bio to it.
  61. *
  62. * Returns 1 if the cell was already held, 0 if @inmate is the new holder.
  63. */
  64. int dm_bio_detain(struct dm_bio_prison *prison,
  65. struct dm_cell_key *key,
  66. struct bio *inmate,
  67. struct dm_bio_prison_cell *cell_prealloc,
  68. struct dm_bio_prison_cell **cell_result);
  69. void dm_cell_release(struct dm_bio_prison *prison,
  70. struct dm_bio_prison_cell *cell,
  71. struct bio_list *bios);
  72. void dm_cell_release_no_holder(struct dm_bio_prison *prison,
  73. struct dm_bio_prison_cell *cell,
  74. struct bio_list *inmates);
  75. void dm_cell_error(struct dm_bio_prison *prison,
  76. struct dm_bio_prison_cell *cell);
  77. /*----------------------------------------------------------------*/
  78. /*
  79. * We use the deferred set to keep track of pending reads to shared blocks.
  80. * We do this to ensure the new mapping caused by a write isn't performed
  81. * until these prior reads have completed. Otherwise the insertion of the
  82. * new mapping could free the old block that the read bios are mapped to.
  83. */
  84. struct dm_deferred_set;
  85. struct dm_deferred_entry;
  86. struct dm_deferred_set *dm_deferred_set_create(void);
  87. void dm_deferred_set_destroy(struct dm_deferred_set *ds);
  88. struct dm_deferred_entry *dm_deferred_entry_inc(struct dm_deferred_set *ds);
  89. void dm_deferred_entry_dec(struct dm_deferred_entry *entry, struct list_head *head);
  90. int dm_deferred_set_add_work(struct dm_deferred_set *ds, struct list_head *work);
  91. /*----------------------------------------------------------------*/
  92. #endif