dm-thin-metadata.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. bool format_device);
  34. int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
  35. /*
  36. * Compat feature flags. Any incompat flags beyond the ones
  37. * specified below will prevent use of the thin metadata.
  38. */
  39. #define THIN_FEATURE_COMPAT_SUPP 0UL
  40. #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
  41. #define THIN_FEATURE_INCOMPAT_SUPP 0UL
  42. /*
  43. * Device creation/deletion.
  44. */
  45. int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
  46. /*
  47. * An internal snapshot.
  48. *
  49. * You can only snapshot a quiesced origin i.e. one that is either
  50. * suspended or not instanced at all.
  51. */
  52. int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
  53. dm_thin_id origin);
  54. /*
  55. * Deletes a virtual device from the metadata. It _is_ safe to call this
  56. * when that device is open. Operations on that device will just start
  57. * failing. You still need to call close() on the device.
  58. */
  59. int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
  60. dm_thin_id dev);
  61. /*
  62. * Commits _all_ metadata changes: device creation, deletion, mapping
  63. * updates.
  64. */
  65. int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
  66. /*
  67. * Set/get userspace transaction id.
  68. */
  69. int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
  70. uint64_t current_id,
  71. uint64_t new_id);
  72. int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
  73. uint64_t *result);
  74. /*
  75. * Hold/get root for userspace transaction.
  76. *
  77. * The metadata snapshot is a copy of the current superblock (minus the
  78. * space maps). Userland can access the data structures for READ
  79. * operations only. A small performance hit is incurred by providing this
  80. * copy of the metadata to userland due to extra copy-on-write operations
  81. * on the metadata nodes. Release this as soon as you finish with it.
  82. */
  83. int dm_pool_reserve_metadata_snap(struct dm_pool_metadata *pmd);
  84. int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd);
  85. int dm_pool_get_metadata_snap(struct dm_pool_metadata *pmd,
  86. dm_block_t *result);
  87. /*
  88. * Actions on a single virtual device.
  89. */
  90. /*
  91. * Opening the same device more than once will fail with -EBUSY.
  92. */
  93. int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
  94. struct dm_thin_device **td);
  95. int dm_pool_close_thin_device(struct dm_thin_device *td);
  96. dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
  97. struct dm_thin_lookup_result {
  98. dm_block_t block;
  99. unsigned shared:1;
  100. };
  101. /*
  102. * Returns:
  103. * -EWOULDBLOCK iff @can_block is set and would block.
  104. * -ENODATA iff that mapping is not present.
  105. * 0 success
  106. */
  107. int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
  108. int can_block, struct dm_thin_lookup_result *result);
  109. /*
  110. * Obtain an unused block.
  111. */
  112. int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
  113. /*
  114. * Insert or remove block.
  115. */
  116. int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
  117. dm_block_t data_block);
  118. int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
  119. /*
  120. * Queries.
  121. */
  122. int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
  123. dm_block_t *highest_mapped);
  124. int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
  125. int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
  126. dm_block_t *result);
  127. int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
  128. dm_block_t *result);
  129. int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
  130. dm_block_t *result);
  131. int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
  132. int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
  133. /*
  134. * Returns -ENOSPC if the new size is too small and already allocated
  135. * blocks would be lost.
  136. */
  137. int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
  138. /*----------------------------------------------------------------*/
  139. #endif