dm-exception-store.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
  3. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * Device-mapper snapshot exception store.
  6. *
  7. * This file is released under the GPL.
  8. */
  9. #ifndef _LINUX_DM_EXCEPTION_STORE
  10. #define _LINUX_DM_EXCEPTION_STORE
  11. #include <linux/blkdev.h>
  12. #include <linux/device-mapper.h>
  13. /*
  14. * The snapshot code deals with largish chunks of the disk at a
  15. * time. Typically 32k - 512k.
  16. */
  17. typedef sector_t chunk_t;
  18. /*
  19. * An exception is used where an old chunk of data has been
  20. * replaced by a new one.
  21. * If chunk_t is 64 bits in size, the top 8 bits of new_chunk hold the number
  22. * of chunks that follow contiguously. Remaining bits hold the number of the
  23. * chunk within the device.
  24. */
  25. struct dm_snap_exception {
  26. struct list_head hash_list;
  27. chunk_t old_chunk;
  28. chunk_t new_chunk;
  29. };
  30. /*
  31. * Abstraction to handle the meta/layout of exception stores (the
  32. * COW device).
  33. */
  34. struct dm_exception_store;
  35. struct dm_exception_store_type {
  36. int (*ctr) (struct dm_exception_store *store,
  37. unsigned argc, char **argv);
  38. /*
  39. * Destroys this object when you've finished with it.
  40. */
  41. void (*dtr) (struct dm_exception_store *store);
  42. /*
  43. * The target shouldn't read the COW device until this is
  44. * called. As exceptions are read from the COW, they are
  45. * reported back via the callback.
  46. */
  47. int (*read_metadata) (struct dm_exception_store *store,
  48. int (*callback)(void *callback_context,
  49. chunk_t old, chunk_t new),
  50. void *callback_context);
  51. /*
  52. * Find somewhere to store the next exception.
  53. */
  54. int (*prepare_exception) (struct dm_exception_store *store,
  55. struct dm_snap_exception *e);
  56. /*
  57. * Update the metadata with this exception.
  58. */
  59. void (*commit_exception) (struct dm_exception_store *store,
  60. struct dm_snap_exception *e,
  61. void (*callback) (void *, int success),
  62. void *callback_context);
  63. /*
  64. * The snapshot is invalid, note this in the metadata.
  65. */
  66. void (*drop_snapshot) (struct dm_exception_store *store);
  67. int (*status) (struct dm_exception_store *store, status_type_t status,
  68. char *result, unsigned int maxlen);
  69. /*
  70. * Return how full the snapshot is.
  71. */
  72. void (*fraction_full) (struct dm_exception_store *store,
  73. sector_t *numerator,
  74. sector_t *denominator);
  75. };
  76. struct dm_exception_store {
  77. struct dm_exception_store_type type;
  78. struct dm_snapshot *snap;
  79. void *context;
  80. };
  81. /*
  82. * Funtions to manipulate consecutive chunks
  83. */
  84. # if defined(CONFIG_LBD) || (BITS_PER_LONG == 64)
  85. # define DM_CHUNK_CONSECUTIVE_BITS 8
  86. # define DM_CHUNK_NUMBER_BITS 56
  87. static inline chunk_t dm_chunk_number(chunk_t chunk)
  88. {
  89. return chunk & (chunk_t)((1ULL << DM_CHUNK_NUMBER_BITS) - 1ULL);
  90. }
  91. static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e)
  92. {
  93. return e->new_chunk >> DM_CHUNK_NUMBER_BITS;
  94. }
  95. static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
  96. {
  97. e->new_chunk += (1ULL << DM_CHUNK_NUMBER_BITS);
  98. BUG_ON(!dm_consecutive_chunk_count(e));
  99. }
  100. # else
  101. # define DM_CHUNK_CONSECUTIVE_BITS 0
  102. static inline chunk_t dm_chunk_number(chunk_t chunk)
  103. {
  104. return chunk;
  105. }
  106. static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e)
  107. {
  108. return 0;
  109. }
  110. static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
  111. {
  112. }
  113. # endif
  114. int dm_exception_store_init(void);
  115. void dm_exception_store_exit(void);
  116. /*
  117. * Two exception store implementations.
  118. */
  119. int dm_persistent_snapshot_init(void);
  120. void dm_persistent_snapshot_exit(void);
  121. int dm_transient_snapshot_init(void);
  122. void dm_transient_snapshot_exit(void);
  123. int dm_create_persistent(struct dm_exception_store *store);
  124. int dm_create_transient(struct dm_exception_store *store);
  125. #endif /* _LINUX_DM_EXCEPTION_STORE */