dm-exception-store.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /*
  13. * The snapshot code deals with largish chunks of the disk at a
  14. * time. Typically 32k - 512k.
  15. */
  16. typedef sector_t chunk_t;
  17. /*
  18. * An exception is used where an old chunk of data has been
  19. * replaced by a new one.
  20. * If chunk_t is 64 bits in size, the top 8 bits of new_chunk hold the number
  21. * of chunks that follow contiguously. Remaining bits hold the number of the
  22. * chunk within the device.
  23. */
  24. struct dm_snap_exception {
  25. struct list_head hash_list;
  26. chunk_t old_chunk;
  27. chunk_t new_chunk;
  28. };
  29. /*
  30. * Abstraction to handle the meta/layout of exception stores (the
  31. * COW device).
  32. */
  33. struct exception_store {
  34. /*
  35. * Destroys this object when you've finished with it.
  36. */
  37. void (*destroy) (struct exception_store *store);
  38. /*
  39. * The target shouldn't read the COW device until this is
  40. * called.
  41. */
  42. int (*read_metadata) (struct exception_store *store);
  43. /*
  44. * Find somewhere to store the next exception.
  45. */
  46. int (*prepare_exception) (struct exception_store *store,
  47. struct dm_snap_exception *e);
  48. /*
  49. * Update the metadata with this exception.
  50. */
  51. void (*commit_exception) (struct exception_store *store,
  52. struct dm_snap_exception *e,
  53. void (*callback) (void *, int success),
  54. void *callback_context);
  55. /*
  56. * The snapshot is invalid, note this in the metadata.
  57. */
  58. void (*drop_snapshot) (struct exception_store *store);
  59. /*
  60. * Return how full the snapshot is.
  61. */
  62. void (*fraction_full) (struct exception_store *store,
  63. sector_t *numerator,
  64. sector_t *denominator);
  65. struct dm_snapshot *snap;
  66. void *context;
  67. };
  68. /*
  69. * Funtions to manipulate consecutive chunks
  70. */
  71. # if defined(CONFIG_LBD) || (BITS_PER_LONG == 64)
  72. # define DM_CHUNK_CONSECUTIVE_BITS 8
  73. # define DM_CHUNK_NUMBER_BITS 56
  74. static inline chunk_t dm_chunk_number(chunk_t chunk)
  75. {
  76. return chunk & (chunk_t)((1ULL << DM_CHUNK_NUMBER_BITS) - 1ULL);
  77. }
  78. static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e)
  79. {
  80. return e->new_chunk >> DM_CHUNK_NUMBER_BITS;
  81. }
  82. static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
  83. {
  84. e->new_chunk += (1ULL << DM_CHUNK_NUMBER_BITS);
  85. BUG_ON(!dm_consecutive_chunk_count(e));
  86. }
  87. # else
  88. # define DM_CHUNK_CONSECUTIVE_BITS 0
  89. static inline chunk_t dm_chunk_number(chunk_t chunk)
  90. {
  91. return chunk;
  92. }
  93. static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e)
  94. {
  95. return 0;
  96. }
  97. static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
  98. {
  99. }
  100. # endif
  101. /*
  102. * Two exception store implementations.
  103. */
  104. int dm_create_persistent(struct exception_store *store);
  105. int dm_create_transient(struct exception_store *store);
  106. #endif /* _LINUX_DM_EXCEPTION_STORE */