dm-cache-metadata.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2012 Red Hat, Inc.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_CACHE_METADATA_H
  7. #define DM_CACHE_METADATA_H
  8. #include "dm-cache-block-types.h"
  9. #include "dm-cache-policy-internal.h"
  10. #include "persistent-data/dm-space-map-metadata.h"
  11. /*----------------------------------------------------------------*/
  12. #define DM_CACHE_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
  13. /* FIXME: remove this restriction */
  14. /*
  15. * The metadata device is currently limited in size.
  16. */
  17. #define DM_CACHE_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
  18. /*
  19. * A metadata device larger than 16GB triggers a warning.
  20. */
  21. #define DM_CACHE_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
  22. /*----------------------------------------------------------------*/
  23. /*
  24. * Ext[234]-style compat feature flags.
  25. *
  26. * A new feature which old metadata will still be compatible with should
  27. * define a DM_CACHE_FEATURE_COMPAT_* flag (rarely useful).
  28. *
  29. * A new feature that is not compatible with old code should define a
  30. * DM_CACHE_FEATURE_INCOMPAT_* flag and guard the relevant code with
  31. * that flag.
  32. *
  33. * A new feature that is not compatible with old code accessing the
  34. * metadata RDWR should define a DM_CACHE_FEATURE_RO_COMPAT_* flag and
  35. * guard the relevant code with that flag.
  36. *
  37. * As these various flags are defined they should be added to the
  38. * following masks.
  39. */
  40. #define DM_CACHE_FEATURE_COMPAT_SUPP 0UL
  41. #define DM_CACHE_FEATURE_COMPAT_RO_SUPP 0UL
  42. #define DM_CACHE_FEATURE_INCOMPAT_SUPP 0UL
  43. struct dm_cache_metadata;
  44. /*
  45. * Reopens or creates a new, empty metadata volume. Returns an ERR_PTR on
  46. * failure. If reopening then features must match.
  47. */
  48. struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
  49. sector_t data_block_size,
  50. bool may_format_device,
  51. size_t policy_hint_size,
  52. unsigned metadata_version);
  53. void dm_cache_metadata_close(struct dm_cache_metadata *cmd);
  54. /*
  55. * The metadata needs to know how many cache blocks there are. We don't
  56. * care about the origin, assuming the core target is giving us valid
  57. * origin blocks to map to.
  58. */
  59. int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size);
  60. int dm_cache_size(struct dm_cache_metadata *cmd, dm_cblock_t *result);
  61. int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
  62. sector_t discard_block_size,
  63. dm_dblock_t new_nr_entries);
  64. typedef int (*load_discard_fn)(void *context, sector_t discard_block_size,
  65. dm_dblock_t dblock, bool discarded);
  66. int dm_cache_load_discards(struct dm_cache_metadata *cmd,
  67. load_discard_fn fn, void *context);
  68. int dm_cache_set_discard(struct dm_cache_metadata *cmd, dm_dblock_t dblock, bool discard);
  69. int dm_cache_remove_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock);
  70. int dm_cache_insert_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock, dm_oblock_t oblock);
  71. int dm_cache_changed_this_transaction(struct dm_cache_metadata *cmd);
  72. typedef int (*load_mapping_fn)(void *context, dm_oblock_t oblock,
  73. dm_cblock_t cblock, bool dirty,
  74. uint32_t hint, bool hint_valid);
  75. int dm_cache_load_mappings(struct dm_cache_metadata *cmd,
  76. struct dm_cache_policy *policy,
  77. load_mapping_fn fn,
  78. void *context);
  79. int dm_cache_set_dirty_bits(struct dm_cache_metadata *cmd,
  80. unsigned nr_bits, unsigned long *bits);
  81. struct dm_cache_statistics {
  82. uint32_t read_hits;
  83. uint32_t read_misses;
  84. uint32_t write_hits;
  85. uint32_t write_misses;
  86. };
  87. void dm_cache_metadata_get_stats(struct dm_cache_metadata *cmd,
  88. struct dm_cache_statistics *stats);
  89. /*
  90. * 'void' because it's no big deal if it fails.
  91. */
  92. void dm_cache_metadata_set_stats(struct dm_cache_metadata *cmd,
  93. struct dm_cache_statistics *stats);
  94. int dm_cache_commit(struct dm_cache_metadata *cmd, bool clean_shutdown);
  95. int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata *cmd,
  96. dm_block_t *result);
  97. int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,
  98. dm_block_t *result);
  99. void dm_cache_dump(struct dm_cache_metadata *cmd);
  100. /*
  101. * The policy is invited to save a 32bit hint value for every cblock (eg,
  102. * for a hit count). These are stored against the policy name. If
  103. * policies are changed, then hints will be lost. If the machine crashes,
  104. * hints will be lost.
  105. *
  106. * The hints are indexed by the cblock, but many policies will not
  107. * neccessarily have a fast way of accessing efficiently via cblock. So
  108. * rather than querying the policy for each cblock, we let it walk its data
  109. * structures and fill in the hints in whatever order it wishes.
  110. */
  111. int dm_cache_write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *p);
  112. /*
  113. * Query method. Are all the blocks in the cache clean?
  114. */
  115. int dm_cache_metadata_all_clean(struct dm_cache_metadata *cmd, bool *result);
  116. int dm_cache_metadata_needs_check(struct dm_cache_metadata *cmd, bool *result);
  117. int dm_cache_metadata_set_needs_check(struct dm_cache_metadata *cmd);
  118. void dm_cache_metadata_set_read_only(struct dm_cache_metadata *cmd);
  119. void dm_cache_metadata_set_read_write(struct dm_cache_metadata *cmd);
  120. int dm_cache_metadata_abort(struct dm_cache_metadata *cmd);
  121. /*----------------------------------------------------------------*/
  122. #endif /* DM_CACHE_METADATA_H */