dm-region-hash.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2003 Sistina Software Limited.
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * Device-Mapper dirty region hash interface.
  6. *
  7. * This file is released under the GPL.
  8. */
  9. #ifndef DM_REGION_HASH_H
  10. #define DM_REGION_HASH_H
  11. #include <linux/dm-dirty-log.h>
  12. /*-----------------------------------------------------------------
  13. * Region hash
  14. *----------------------------------------------------------------*/
  15. struct dm_region_hash;
  16. struct dm_region;
  17. /*
  18. * States a region can have.
  19. */
  20. enum dm_rh_region_states {
  21. DM_RH_CLEAN = 0x01, /* No writes in flight. */
  22. DM_RH_DIRTY = 0x02, /* Writes in flight. */
  23. DM_RH_NOSYNC = 0x04, /* Out of sync. */
  24. DM_RH_RECOVERING = 0x08, /* Under resynchronization. */
  25. };
  26. /*
  27. * Region hash create/destroy.
  28. */
  29. struct bio_list;
  30. struct dm_region_hash *dm_region_hash_create(
  31. void *context, void (*dispatch_bios)(void *context,
  32. struct bio_list *bios),
  33. void (*wakeup_workers)(void *context),
  34. void (*wakeup_all_recovery_waiters)(void *context),
  35. sector_t target_begin, unsigned max_recovery,
  36. struct dm_dirty_log *log, uint32_t region_size,
  37. region_t nr_regions);
  38. void dm_region_hash_destroy(struct dm_region_hash *rh);
  39. struct dm_dirty_log *dm_rh_dirty_log(struct dm_region_hash *rh);
  40. /*
  41. * Conversion functions.
  42. */
  43. region_t dm_rh_bio_to_region(struct dm_region_hash *rh, struct bio *bio);
  44. sector_t dm_rh_region_to_sector(struct dm_region_hash *rh, region_t region);
  45. void *dm_rh_region_context(struct dm_region *reg);
  46. /*
  47. * Get region size and key (ie. number of the region).
  48. */
  49. sector_t dm_rh_get_region_size(struct dm_region_hash *rh);
  50. region_t dm_rh_get_region_key(struct dm_region *reg);
  51. /*
  52. * Get/set/update region state (and dirty log).
  53. *
  54. */
  55. int dm_rh_get_state(struct dm_region_hash *rh, region_t region, int may_block);
  56. void dm_rh_set_state(struct dm_region_hash *rh, region_t region,
  57. enum dm_rh_region_states state, int may_block);
  58. /* Non-zero errors_handled leaves the state of the region NOSYNC */
  59. void dm_rh_update_states(struct dm_region_hash *rh, int errors_handled);
  60. /* Flush the region hash and dirty log. */
  61. int dm_rh_flush(struct dm_region_hash *rh);
  62. /* Inc/dec pending count on regions. */
  63. void dm_rh_inc_pending(struct dm_region_hash *rh, struct bio_list *bios);
  64. void dm_rh_dec(struct dm_region_hash *rh, region_t region);
  65. /* Delay bios on regions. */
  66. void dm_rh_delay(struct dm_region_hash *rh, struct bio *bio);
  67. void dm_rh_mark_nosync(struct dm_region_hash *rh, struct bio *bio);
  68. /*
  69. * Region recovery control.
  70. */
  71. /* Prepare some regions for recovery by starting to quiesce them. */
  72. void dm_rh_recovery_prepare(struct dm_region_hash *rh);
  73. /* Try fetching a quiesced region for recovery. */
  74. struct dm_region *dm_rh_recovery_start(struct dm_region_hash *rh);
  75. /* Report recovery end on a region. */
  76. void dm_rh_recovery_end(struct dm_region *reg, int error);
  77. /* Returns number of regions with recovery work outstanding. */
  78. int dm_rh_recovery_in_flight(struct dm_region_hash *rh);
  79. /* Start/stop recovery. */
  80. void dm_rh_start_recovery(struct dm_region_hash *rh);
  81. void dm_rh_stop_recovery(struct dm_region_hash *rh);
  82. #endif /* DM_REGION_HASH_H */