2 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
4 * This file is released under the GPL.
10 #include <linux/device-mapper.h>
11 #include "dm-exception-store.h"
12 #include "dm-bio-list.h"
13 #include <linux/blkdev.h>
14 #include <linux/workqueue.h>
16 struct exception_table {
19 struct list_head *table;
22 #define DM_TRACKED_CHUNK_HASH_SIZE 16
23 #define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \
24 (DM_TRACKED_CHUNK_HASH_SIZE - 1))
27 struct rw_semaphore lock;
29 struct dm_dev *origin;
31 /* List of snapshots per Origin */
32 struct list_head list;
34 /* You can't use a snapshot if this is 0 (e.g. if full) */
37 /* Origin writes don't trigger exceptions until this is set */
40 /* Used for display of table */
43 mempool_t *pending_pool;
45 atomic_t pending_exceptions_count;
47 struct exception_table pending;
48 struct exception_table complete;
51 * pe_lock protects all pending_exception operations and access
52 * as well as the snapshot_bios list.
56 /* The on disk metadata handler */
57 struct dm_exception_store *store;
59 struct dm_kcopyd_client *kcopyd_client;
61 /* Queue of snapshot writes for ksnapd to flush */
62 struct bio_list queued_bios;
63 struct work_struct queued_bios_work;
65 /* Chunks with outstanding reads */
66 mempool_t *tracked_chunk_pool;
67 spinlock_t tracked_chunk_lock;
68 struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE];
72 * Return the number of sectors in the device.
74 static inline sector_t get_dev_size(struct block_device *bdev)
76 return bdev->bd_inode->i_size >> SECTOR_SHIFT;
79 static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector)
81 return (sector & ~s->store->chunk_mask) >> s->store->chunk_shift;
84 static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk)
86 return chunk << s->store->chunk_shift;
89 static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs)
92 * There is only ever one instance of a particular block
93 * device so we can compare pointers safely.