dm-cache-policy-internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2012 Red Hat. All rights reserved.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_CACHE_POLICY_INTERNAL_H
  7. #define DM_CACHE_POLICY_INTERNAL_H
  8. #include "dm-cache-policy.h"
  9. /*----------------------------------------------------------------*/
  10. /*
  11. * Little inline functions that simplify calling the policy methods.
  12. */
  13. static inline int policy_map(struct dm_cache_policy *p, dm_oblock_t oblock,
  14. bool can_block, bool can_migrate, bool discarded_oblock,
  15. struct bio *bio, struct policy_result *result)
  16. {
  17. return p->map(p, oblock, can_block, can_migrate, discarded_oblock, bio, result);
  18. }
  19. static inline int policy_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock)
  20. {
  21. BUG_ON(!p->lookup);
  22. return p->lookup(p, oblock, cblock);
  23. }
  24. static inline void policy_set_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
  25. {
  26. if (p->set_dirty)
  27. p->set_dirty(p, oblock);
  28. }
  29. static inline void policy_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
  30. {
  31. if (p->clear_dirty)
  32. p->clear_dirty(p, oblock);
  33. }
  34. static inline int policy_load_mapping(struct dm_cache_policy *p,
  35. dm_oblock_t oblock, dm_cblock_t cblock,
  36. uint32_t hint, bool hint_valid)
  37. {
  38. return p->load_mapping(p, oblock, cblock, hint, hint_valid);
  39. }
  40. static inline int policy_walk_mappings(struct dm_cache_policy *p,
  41. policy_walk_fn fn, void *context)
  42. {
  43. return p->walk_mappings ? p->walk_mappings(p, fn, context) : 0;
  44. }
  45. static inline int policy_writeback_work(struct dm_cache_policy *p,
  46. dm_oblock_t *oblock,
  47. dm_cblock_t *cblock)
  48. {
  49. return p->writeback_work ? p->writeback_work(p, oblock, cblock) : -ENOENT;
  50. }
  51. static inline void policy_remove_mapping(struct dm_cache_policy *p, dm_oblock_t oblock)
  52. {
  53. return p->remove_mapping(p, oblock);
  54. }
  55. static inline void policy_force_mapping(struct dm_cache_policy *p,
  56. dm_oblock_t current_oblock, dm_oblock_t new_oblock)
  57. {
  58. return p->force_mapping(p, current_oblock, new_oblock);
  59. }
  60. static inline dm_cblock_t policy_residency(struct dm_cache_policy *p)
  61. {
  62. return p->residency(p);
  63. }
  64. static inline void policy_tick(struct dm_cache_policy *p)
  65. {
  66. if (p->tick)
  67. return p->tick(p);
  68. }
  69. static inline int policy_emit_config_values(struct dm_cache_policy *p, char *result, unsigned maxlen)
  70. {
  71. ssize_t sz = 0;
  72. if (p->emit_config_values)
  73. return p->emit_config_values(p, result, maxlen);
  74. DMEMIT("0");
  75. return 0;
  76. }
  77. static inline int policy_set_config_value(struct dm_cache_policy *p,
  78. const char *key, const char *value)
  79. {
  80. return p->set_config_value ? p->set_config_value(p, key, value) : -EINVAL;
  81. }
  82. /*----------------------------------------------------------------*/
  83. /*
  84. * Creates a new cache policy given a policy name, a cache size, an origin size and the block size.
  85. */
  86. struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size,
  87. sector_t origin_size, sector_t block_size);
  88. /*
  89. * Destroys the policy. This drops references to the policy module as well
  90. * as calling it's destroy method. So always use this rather than calling
  91. * the policy->destroy method directly.
  92. */
  93. void dm_cache_policy_destroy(struct dm_cache_policy *p);
  94. /*
  95. * In case we've forgotten.
  96. */
  97. const char *dm_cache_policy_get_name(struct dm_cache_policy *p);
  98. const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p);
  99. size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p);
  100. /*----------------------------------------------------------------*/
  101. #endif /* DM_CACHE_POLICY_INTERNAL_H */