dm-snap.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_SNAPSHOT_H
  7. #define DM_SNAPSHOT_H
  8. #include <linux/device-mapper.h>
  9. #include "dm-exception-store.h"
  10. #include "dm-bio-list.h"
  11. #include <linux/blkdev.h>
  12. #include <linux/workqueue.h>
  13. struct exception_table {
  14. uint32_t hash_mask;
  15. unsigned hash_shift;
  16. struct list_head *table;
  17. };
  18. #define DM_TRACKED_CHUNK_HASH_SIZE 16
  19. #define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \
  20. (DM_TRACKED_CHUNK_HASH_SIZE - 1))
  21. struct dm_snapshot {
  22. struct rw_semaphore lock;
  23. struct dm_target *ti;
  24. struct dm_dev *origin;
  25. struct dm_dev *cow;
  26. /* List of snapshots per Origin */
  27. struct list_head list;
  28. /* Size of data blocks saved - must be a power of 2 */
  29. chunk_t chunk_size;
  30. chunk_t chunk_mask;
  31. chunk_t chunk_shift;
  32. /* You can't use a snapshot if this is 0 (e.g. if full) */
  33. int valid;
  34. /* Origin writes don't trigger exceptions until this is set */
  35. int active;
  36. /* Used for display of table */
  37. char type;
  38. mempool_t *pending_pool;
  39. atomic_t pending_exceptions_count;
  40. struct exception_table pending;
  41. struct exception_table complete;
  42. /*
  43. * pe_lock protects all pending_exception operations and access
  44. * as well as the snapshot_bios list.
  45. */
  46. spinlock_t pe_lock;
  47. /* The on disk metadata handler */
  48. struct dm_exception_store store;
  49. struct dm_kcopyd_client *kcopyd_client;
  50. /* Queue of snapshot writes for ksnapd to flush */
  51. struct bio_list queued_bios;
  52. struct work_struct queued_bios_work;
  53. /* Chunks with outstanding reads */
  54. mempool_t *tracked_chunk_pool;
  55. spinlock_t tracked_chunk_lock;
  56. struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE];
  57. };
  58. /*
  59. * Return the number of sectors in the device.
  60. */
  61. static inline sector_t get_dev_size(struct block_device *bdev)
  62. {
  63. return bdev->bd_inode->i_size >> SECTOR_SHIFT;
  64. }
  65. static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector)
  66. {
  67. return (sector & ~s->chunk_mask) >> s->chunk_shift;
  68. }
  69. static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk)
  70. {
  71. return chunk << s->chunk_shift;
  72. }
  73. static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs)
  74. {
  75. /*
  76. * There is only ever one instance of a particular block
  77. * device so we can compare pointers safely.
  78. */
  79. return lhs == rhs;
  80. }
  81. #endif