dm-snap.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_dev *origin;
  24. /* List of snapshots per Origin */
  25. struct list_head list;
  26. /* You can't use a snapshot if this is 0 (e.g. if full) */
  27. int valid;
  28. /* Origin writes don't trigger exceptions until this is set */
  29. int active;
  30. /* Used for display of table */
  31. char type;
  32. mempool_t *pending_pool;
  33. atomic_t pending_exceptions_count;
  34. struct exception_table pending;
  35. struct exception_table complete;
  36. /*
  37. * pe_lock protects all pending_exception operations and access
  38. * as well as the snapshot_bios list.
  39. */
  40. spinlock_t pe_lock;
  41. /* The on disk metadata handler */
  42. struct dm_exception_store *store;
  43. struct dm_kcopyd_client *kcopyd_client;
  44. /* Queue of snapshot writes for ksnapd to flush */
  45. struct bio_list queued_bios;
  46. struct work_struct queued_bios_work;
  47. /* Chunks with outstanding reads */
  48. mempool_t *tracked_chunk_pool;
  49. spinlock_t tracked_chunk_lock;
  50. struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE];
  51. };
  52. /*
  53. * Return the number of sectors in the device.
  54. */
  55. static inline sector_t get_dev_size(struct block_device *bdev)
  56. {
  57. return bdev->bd_inode->i_size >> SECTOR_SHIFT;
  58. }
  59. static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector)
  60. {
  61. return (sector & ~s->store->chunk_mask) >> s->store->chunk_shift;
  62. }
  63. static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk)
  64. {
  65. return chunk << s->store->chunk_shift;
  66. }
  67. static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs)
  68. {
  69. /*
  70. * There is only ever one instance of a particular block
  71. * device so we can compare pointers safely.
  72. */
  73. return lhs == rhs;
  74. }
  75. #endif