4 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
6 * This file is released under the GPL.
13 #include "dm-bio-list.h"
14 #include <linux/blkdev.h>
15 #include <linux/workqueue.h>
17 struct exception_table {
19 struct list_head *table;
23 * The snapshot code deals with largish chunks of the disk at a
24 * time. Typically 64k - 256k.
26 /* FIXME: can we get away with limiting these to a uint32_t ? */
27 typedef sector_t chunk_t;
30 * An exception is used where an old chunk of data has been
31 * replaced by a new one.
34 struct list_head hash_list;
41 * Abstraction to handle the meta/layout of exception stores (the
44 struct exception_store {
47 * Destroys this object when you've finished with it.
49 void (*destroy) (struct exception_store *store);
52 * The target shouldn't read the COW device until this is
55 int (*read_metadata) (struct exception_store *store);
58 * Find somewhere to store the next exception.
60 int (*prepare_exception) (struct exception_store *store,
64 * Update the metadata with this exception.
66 void (*commit_exception) (struct exception_store *store,
68 void (*callback) (void *, int success),
69 void *callback_context);
72 * The snapshot is invalid, note this in the metadata.
74 void (*drop_snapshot) (struct exception_store *store);
77 * Return how full the snapshot is.
79 void (*fraction_full) (struct exception_store *store,
81 sector_t *denominator);
83 struct dm_snapshot *snap;
88 struct rw_semaphore lock;
89 struct dm_table *table;
91 struct dm_dev *origin;
94 /* List of snapshots per Origin */
95 struct list_head list;
97 /* Size of data blocks saved - must be a power of 2 */
102 /* You can't use a snapshot if this is 0 (e.g. if full) */
105 /* Origin writes don't trigger exceptions until this is set */
108 /* Used for display of table */
111 /* The last percentage we notified */
114 struct exception_table pending;
115 struct exception_table complete;
118 * pe_lock protects all pending_exception operations and access
119 * as well as the snapshot_bios list.
123 /* The on disk metadata handler */
124 struct exception_store store;
126 struct kcopyd_client *kcopyd_client;
128 /* Queue of snapshot writes for ksnapd to flush */
129 struct bio_list queued_bios;
130 struct work_struct queued_bios_work;
134 * Used by the exception stores to load exceptions hen
137 int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new);
140 * Constructor and destructor for the default persistent
143 int dm_create_persistent(struct exception_store *store);
145 int dm_create_transient(struct exception_store *store);
148 * Return the number of sectors in the device.
150 static inline sector_t get_dev_size(struct block_device *bdev)
152 return bdev->bd_inode->i_size >> SECTOR_SHIFT;
155 static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector)
157 return (sector & ~s->chunk_mask) >> s->chunk_shift;
160 static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk)
162 return chunk << s->chunk_shift;
165 static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs)
168 * There is only ever one instance of a particular block
169 * device so we can compare pointers safely.