dm-space-map.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2011 Red Hat, Inc.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef _LINUX_DM_SPACE_MAP_H
  7. #define _LINUX_DM_SPACE_MAP_H
  8. #include "dm-block-manager.h"
  9. /*
  10. * struct dm_space_map keeps a record of how many times each block in a device
  11. * is referenced. It needs to be fixed on disk as part of the transaction.
  12. */
  13. struct dm_space_map {
  14. void (*destroy)(struct dm_space_map *sm);
  15. /*
  16. * You must commit before allocating the newly added space.
  17. */
  18. int (*extend)(struct dm_space_map *sm, dm_block_t extra_blocks);
  19. /*
  20. * Extensions do not appear in this count until after commit has
  21. * been called.
  22. */
  23. int (*get_nr_blocks)(struct dm_space_map *sm, dm_block_t *count);
  24. /*
  25. * Space maps must never allocate a block from the previous
  26. * transaction, in case we need to rollback. This complicates the
  27. * semantics of get_nr_free(), it should return the number of blocks
  28. * that are available for allocation _now_. For instance you may
  29. * have blocks with a zero reference count that will not be
  30. * available for allocation until after the next commit.
  31. */
  32. int (*get_nr_free)(struct dm_space_map *sm, dm_block_t *count);
  33. int (*get_count)(struct dm_space_map *sm, dm_block_t b, uint32_t *result);
  34. int (*count_is_more_than_one)(struct dm_space_map *sm, dm_block_t b,
  35. int *result);
  36. int (*set_count)(struct dm_space_map *sm, dm_block_t b, uint32_t count);
  37. int (*commit)(struct dm_space_map *sm);
  38. int (*inc_block)(struct dm_space_map *sm, dm_block_t b);
  39. int (*dec_block)(struct dm_space_map *sm, dm_block_t b);
  40. /*
  41. * new_block will increment the returned block.
  42. */
  43. int (*new_block)(struct dm_space_map *sm, dm_block_t *b);
  44. /*
  45. * The root contains all the information needed to fix the space map.
  46. * Generally this info is small, so squirrel it away in a disk block
  47. * along with other info.
  48. */
  49. int (*root_size)(struct dm_space_map *sm, size_t *result);
  50. int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
  51. };
  52. /*----------------------------------------------------------------*/
  53. static inline void dm_sm_destroy(struct dm_space_map *sm)
  54. {
  55. sm->destroy(sm);
  56. }
  57. static inline int dm_sm_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
  58. {
  59. return sm->extend(sm, extra_blocks);
  60. }
  61. static inline int dm_sm_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
  62. {
  63. return sm->get_nr_blocks(sm, count);
  64. }
  65. static inline int dm_sm_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
  66. {
  67. return sm->get_nr_free(sm, count);
  68. }
  69. static inline int dm_sm_get_count(struct dm_space_map *sm, dm_block_t b,
  70. uint32_t *result)
  71. {
  72. return sm->get_count(sm, b, result);
  73. }
  74. static inline int dm_sm_count_is_more_than_one(struct dm_space_map *sm,
  75. dm_block_t b, int *result)
  76. {
  77. return sm->count_is_more_than_one(sm, b, result);
  78. }
  79. static inline int dm_sm_set_count(struct dm_space_map *sm, dm_block_t b,
  80. uint32_t count)
  81. {
  82. return sm->set_count(sm, b, count);
  83. }
  84. static inline int dm_sm_commit(struct dm_space_map *sm)
  85. {
  86. return sm->commit(sm);
  87. }
  88. static inline int dm_sm_inc_block(struct dm_space_map *sm, dm_block_t b)
  89. {
  90. return sm->inc_block(sm, b);
  91. }
  92. static inline int dm_sm_dec_block(struct dm_space_map *sm, dm_block_t b)
  93. {
  94. return sm->dec_block(sm, b);
  95. }
  96. static inline int dm_sm_new_block(struct dm_space_map *sm, dm_block_t *b)
  97. {
  98. return sm->new_block(sm, b);
  99. }
  100. static inline int dm_sm_root_size(struct dm_space_map *sm, size_t *result)
  101. {
  102. return sm->root_size(sm, result);
  103. }
  104. static inline int dm_sm_copy_root(struct dm_space_map *sm, void *copy_to_here_le, size_t len)
  105. {
  106. return sm->copy_root(sm, copy_to_here_le, len);
  107. }
  108. #endif /* _LINUX_DM_SPACE_MAP_H */