dm-thin-metadata.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. struct dm_pool_metadata;
  12. struct dm_thin_device;
  13. /*
  14. * Device identifier
  15. */
  16. typedef uint64_t dm_thin_id;
  17. /*
  18. * Reopens or creates a new, empty metadata volume.
  19. */
  20. struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
  21. sector_t data_block_size);
  22. int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
  23. /*
  24. * Compat feature flags. Any incompat flags beyond the ones
  25. * specified below will prevent use of the thin metadata.
  26. */
  27. #define THIN_FEATURE_COMPAT_SUPP 0UL
  28. #define THIN_FEATURE_COMPAT_RO_SUPP 0UL
  29. #define THIN_FEATURE_INCOMPAT_SUPP 0UL
  30. /*
  31. * Device creation/deletion.
  32. */
  33. int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
  34. /*
  35. * An internal snapshot.
  36. *
  37. * You can only snapshot a quiesced origin i.e. one that is either
  38. * suspended or not instanced at all.
  39. */
  40. int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
  41. dm_thin_id origin);
  42. /*
  43. * Deletes a virtual device from the metadata. It _is_ safe to call this
  44. * when that device is open. Operations on that device will just start
  45. * failing. You still need to call close() on the device.
  46. */
  47. int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
  48. dm_thin_id dev);
  49. /*
  50. * Commits _all_ metadata changes: device creation, deletion, mapping
  51. * updates.
  52. */
  53. int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
  54. /*
  55. * Set/get userspace transaction id.
  56. */
  57. int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
  58. uint64_t current_id,
  59. uint64_t new_id);
  60. int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
  61. uint64_t *result);
  62. /*
  63. * Hold/get root for userspace transaction.
  64. */
  65. int dm_pool_hold_metadata_root(struct dm_pool_metadata *pmd);
  66. int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
  67. dm_block_t *result);
  68. /*
  69. * Actions on a single virtual device.
  70. */
  71. /*
  72. * Opening the same device more than once will fail with -EBUSY.
  73. */
  74. int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
  75. struct dm_thin_device **td);
  76. int dm_pool_close_thin_device(struct dm_thin_device *td);
  77. dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
  78. struct dm_thin_lookup_result {
  79. dm_block_t block;
  80. int shared;
  81. };
  82. /*
  83. * Returns:
  84. * -EWOULDBLOCK iff @can_block is set and would block.
  85. * -ENODATA iff that mapping is not present.
  86. * 0 success
  87. */
  88. int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
  89. int can_block, struct dm_thin_lookup_result *result);
  90. /*
  91. * Obtain an unused block.
  92. */
  93. int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
  94. /*
  95. * Insert or remove block.
  96. */
  97. int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
  98. dm_block_t data_block);
  99. int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
  100. /*
  101. * Queries.
  102. */
  103. int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
  104. dm_block_t *highest_mapped);
  105. int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
  106. int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
  107. dm_block_t *result);
  108. int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
  109. dm_block_t *result);
  110. int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
  111. dm_block_t *result);
  112. int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
  113. int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
  114. /*
  115. * Returns -ENOSPC if the new size is too small and already allocated
  116. * blocks would be lost.
  117. */
  118. int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
  119. /*----------------------------------------------------------------*/
  120. #endif