ACPI: thinkpad-acpi: keep track of module state
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / md / dm-snap.h
blob650e0f1f51d8a6c312a001c8443cf3bc8064d481
1 /*
2 * dm-snapshot.c
4 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
6 * This file is released under the GPL.
7 */
9 #ifndef DM_SNAPSHOT_H
10 #define DM_SNAPSHOT_H
12 #include "dm.h"
13 #include "dm-bio-list.h"
14 #include <linux/blkdev.h>
15 #include <linux/workqueue.h>
17 struct exception_table {
18 uint32_t hash_mask;
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.
33 struct dm_snap_exception {
34 struct list_head hash_list;
36 chunk_t old_chunk;
37 chunk_t new_chunk;
41 * Abstraction to handle the meta/layout of exception stores (the
42 * COW device).
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
53 * called.
55 int (*read_metadata) (struct exception_store *store);
58 * Find somewhere to store the next exception.
60 int (*prepare_exception) (struct exception_store *store,
61 struct dm_snap_exception *e);
64 * Update the metadata with this exception.
66 void (*commit_exception) (struct exception_store *store,
67 struct dm_snap_exception *e,
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,
80 sector_t *numerator,
81 sector_t *denominator);
83 struct dm_snapshot *snap;
84 void *context;
87 struct dm_snapshot {
88 struct rw_semaphore lock;
89 struct dm_table *table;
91 struct dm_dev *origin;
92 struct dm_dev *cow;
94 /* List of snapshots per Origin */
95 struct list_head list;
97 /* Size of data blocks saved - must be a power of 2 */
98 chunk_t chunk_size;
99 chunk_t chunk_mask;
100 chunk_t chunk_shift;
102 /* You can't use a snapshot if this is 0 (e.g. if full) */
103 int valid;
105 /* Origin writes don't trigger exceptions until this is set */
106 int active;
108 /* Used for display of table */
109 char type;
111 /* The last percentage we notified */
112 int last_percent;
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.
121 spinlock_t pe_lock;
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
135 * initialising.
137 int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new);
140 * Constructor and destructor for the default persistent
141 * store.
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.
171 return lhs == rhs;
174 #endif