4 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
6 * This file is released under the GPL.
13 #include <linux/blkdev.h>
15 struct exception_table {
17 struct list_head *table;
21 * The snapshot code deals with largish chunks of the disk at a
22 * time. Typically 64k - 256k.
24 /* FIXME: can we get away with limiting these to a uint32_t ? */
25 typedef sector_t chunk_t;
28 * An exception is used where an old chunk of data has been
29 * replaced by a new one.
32 struct list_head hash_list;
39 * Abstraction to handle the meta/layout of exception stores (the
42 struct exception_store {
45 * Destroys this object when you've finished with it.
47 void (*destroy) (struct exception_store *store);
50 * The target shouldn't read the COW device until this is
53 int (*read_metadata) (struct exception_store *store);
56 * Find somewhere to store the next exception.
58 int (*prepare_exception) (struct exception_store *store,
62 * Update the metadata with this exception.
64 void (*commit_exception) (struct exception_store *store,
66 void (*callback) (void *, int success),
67 void *callback_context);
70 * The snapshot is invalid, note this in the metadata.
72 void (*drop_snapshot) (struct exception_store *store);
75 * Return how full the snapshot is.
77 void (*fraction_full) (struct exception_store *store,
79 sector_t *denominator);
81 struct dm_snapshot *snap;
86 struct rw_semaphore lock;
87 struct dm_table *table;
89 struct dm_dev *origin;
92 /* List of snapshots per Origin */
93 struct list_head list;
95 /* Size of data blocks saved - must be a power of 2 */
100 /* You can't use a snapshot if this is 0 (e.g. if full) */
103 /* Origin writes don't trigger exceptions until this is set */
106 /* Used for display of table */
109 /* The last percentage we notified */
112 struct exception_table pending;
113 struct exception_table complete;
115 /* The on disk metadata handler */
116 struct exception_store store;
118 struct kcopyd_client *kcopyd_client;
122 * Used by the exception stores to load exceptions hen
125 int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new);
128 * Constructor and destructor for the default persistent
131 int dm_create_persistent(struct exception_store *store, uint32_t chunk_size);
133 int dm_create_transient(struct exception_store *store,
134 struct dm_snapshot *s, int blocksize);
137 * Return the number of sectors in the device.
139 static inline sector_t get_dev_size(struct block_device *bdev)
141 return bdev->bd_inode->i_size >> SECTOR_SHIFT;
144 static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector)
146 return (sector & ~s->chunk_mask) >> s->chunk_shift;
149 static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk)
151 return chunk << s->chunk_shift;
154 static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs)
157 * There is only ever one instance of a particular block
158 * device so we can compare pointers safely.