dm-thin-metadata.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2010-2011 Red Hat, Inc.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_THIN_METADATA_H
  7. #define DM_THIN_METADATA_H
  8. #include "persistent-data/dm-block-manager.h"
  9. #define THIN_METADATA_BLOCK_SIZE 4096
  10. /*
  11. * The metadata device is currently limited in size.
  12. *
  13. * We have one block of index, which can hold 255 index entries. Each
  14. * index entry contains allocation info about 16k metadata blocks.
  15. */
  16. #define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT)))
  17. /*
  18. * A metadata device larger than 16GB triggers a warning.
  19. */
  20. #define THIN_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
  21. /*----------------------------------------------------------------*/
  22. struct dm_pool_metadata;
  23. struct dm_thin_device;
  24. /*
  25. * Device identifier
  26. */
  27. typedef uint64_t dm_thin_id;
  28. /*
  29. * Reopens or creates a new, empty metadata volume.
  30. */
  31. struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
  32. sector_t data_block_size);
  33. int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
  34. /*
  35. * Compat feature flags. Any incompat flags beyond the ones
  36. * specified below will prevent use of the thin metadata.
  37. */
  38. #define THIN_FEATURE_COMPAT_SUPP 0UL
  39. #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
  40. #define THIN_FEATURE_INCOMPAT_SUPP 0UL
  41. /*
  42. * Device creation/deletion.
  43. */
  44. int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
  45. /*
  46. * An internal snapshot.
  47. *
  48. * You can only snapshot a quiesced origin i.e. one that is either
  49. * suspended or not instanced at all.
  50. */
  51. int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
  52. dm_thin_id origin);
  53. /*
  54. * Deletes a virtual device from the metadata. It _is_ safe to call this
  55. * when that device is open. Operations on that device will just start
  56. * failing. You still need to call close() on the device.
  57. */
  58. int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
  59. dm_thin_id dev);
  60. /*
  61. * Commits _all_ metadata changes: device creation, deletion, mapping
  62. * updates.
  63. */
  64. int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
  65. /*
  66. * Set/get userspace transaction id.
  67. */
  68. int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
  69. uint64_t current_id,
  70. uint64_t new_id);
  71. int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
  72. uint64_t *result);
  73. /*
  74. * Hold/get root for userspace transaction.
  75. */
  76. int dm_pool_hold_metadata_root(struct dm_pool_metadata *pmd);
  77. int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
  78. dm_block_t *result);
  79. /*
  80. * Actions on a single virtual device.
  81. */
  82. /*
  83. * Opening the same device more than once will fail with -EBUSY.
  84. */
  85. int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
  86. struct dm_thin_device **td);
  87. int dm_pool_close_thin_device(struct dm_thin_device *td);
  88. dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
  89. struct dm_thin_lookup_result {
  90. dm_block_t block;
  91. int shared;
  92. };
  93. /*
  94. * Returns:
  95. * -EWOULDBLOCK iff @can_block is set and would block.
  96. * -ENODATA iff that mapping is not present.
  97. * 0 success
  98. */
  99. int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
  100. int can_block, struct dm_thin_lookup_result *result);
  101. /*
  102. * Obtain an unused block.
  103. */
  104. int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
  105. /*
  106. * Insert or remove block.
  107. */
  108. int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
  109. dm_block_t data_block);
  110. int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
  111. /*
  112. * Queries.
  113. */
  114. int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
  115. dm_block_t *highest_mapped);
  116. int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
  117. int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
  118. dm_block_t *result);
  119. int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
  120. dm_block_t *result);
  121. int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
  122. dm_block_t *result);
  123. int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
  124. int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
  125. /*
  126. * Returns -ENOSPC if the new size is too small and already allocated
  127. * blocks would be lost.
  128. */
  129. int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
  130. /*----------------------------------------------------------------*/
  131. #endif