2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001-2002 Sistina Software (UK) Limited.
|
|
|
|
*
|
|
|
|
* This file is released under the GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DM_SNAPSHOT_H
|
|
|
|
#define DM_SNAPSHOT_H
|
|
|
|
|
2008-10-21 18:44:59 +02:00
|
|
|
#include <linux/device-mapper.h>
|
2009-01-06 04:05:15 +01:00
|
|
|
#include "dm-exception-store.h"
|
2006-10-03 10:15:30 +02:00
|
|
|
#include "dm-bio-list.h"
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/blkdev.h>
|
2006-10-03 10:15:30 +02:00
|
|
|
#include <linux/workqueue.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
struct exception_table {
|
|
|
|
uint32_t hash_mask;
|
2008-02-08 03:11:27 +01:00
|
|
|
unsigned hash_shift;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct list_head *table;
|
|
|
|
};
|
|
|
|
|
2008-07-21 13:00:32 +02:00
|
|
|
#define DM_TRACKED_CHUNK_HASH_SIZE 16
|
|
|
|
#define DM_TRACKED_CHUNK_HASH(x) ((unsigned long)(x) & \
|
|
|
|
(DM_TRACKED_CHUNK_HASH_SIZE - 1))
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
struct dm_snapshot {
|
|
|
|
struct rw_semaphore lock;
|
2008-04-24 22:43:11 +02:00
|
|
|
struct dm_target *ti;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
struct dm_dev *origin;
|
|
|
|
struct dm_dev *cow;
|
|
|
|
|
|
|
|
/* List of snapshots per Origin */
|
|
|
|
struct list_head list;
|
|
|
|
|
|
|
|
/* Size of data blocks saved - must be a power of 2 */
|
|
|
|
chunk_t chunk_size;
|
|
|
|
chunk_t chunk_mask;
|
|
|
|
chunk_t chunk_shift;
|
|
|
|
|
|
|
|
/* You can't use a snapshot if this is 0 (e.g. if full) */
|
|
|
|
int valid;
|
2006-02-01 12:04:50 +01:00
|
|
|
|
|
|
|
/* Origin writes don't trigger exceptions until this is set */
|
|
|
|
int active;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Used for display of table */
|
|
|
|
char type;
|
|
|
|
|
2008-07-21 13:00:35 +02:00
|
|
|
mempool_t *pending_pool;
|
|
|
|
|
2008-10-30 14:33:16 +01:00
|
|
|
atomic_t pending_exceptions_count;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
struct exception_table pending;
|
|
|
|
struct exception_table complete;
|
|
|
|
|
2006-10-03 10:15:30 +02:00
|
|
|
/*
|
|
|
|
* pe_lock protects all pending_exception operations and access
|
|
|
|
* as well as the snapshot_bios list.
|
|
|
|
*/
|
|
|
|
spinlock_t pe_lock;
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* The on disk metadata handler */
|
2009-01-06 04:05:16 +01:00
|
|
|
struct dm_exception_store store;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-04-24 22:43:19 +02:00
|
|
|
struct dm_kcopyd_client *kcopyd_client;
|
2006-10-03 10:15:30 +02:00
|
|
|
|
|
|
|
/* Queue of snapshot writes for ksnapd to flush */
|
|
|
|
struct bio_list queued_bios;
|
|
|
|
struct work_struct queued_bios_work;
|
2008-07-21 13:00:32 +02:00
|
|
|
|
|
|
|
/* Chunks with outstanding reads */
|
|
|
|
mempool_t *tracked_chunk_pool;
|
|
|
|
spinlock_t tracked_chunk_lock;
|
|
|
|
struct hlist_head tracked_chunk_hash[DM_TRACKED_CHUNK_HASH_SIZE];
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the number of sectors in the device.
|
|
|
|
*/
|
|
|
|
static inline sector_t get_dev_size(struct block_device *bdev)
|
|
|
|
{
|
|
|
|
return bdev->bd_inode->i_size >> SECTOR_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline chunk_t sector_to_chunk(struct dm_snapshot *s, sector_t sector)
|
|
|
|
{
|
|
|
|
return (sector & ~s->chunk_mask) >> s->chunk_shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline sector_t chunk_to_sector(struct dm_snapshot *s, chunk_t chunk)
|
|
|
|
{
|
|
|
|
return chunk << s->chunk_shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int bdev_equal(struct block_device *lhs, struct block_device *rhs)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* There is only ever one instance of a particular block
|
|
|
|
* device so we can compare pointers safely.
|
|
|
|
*/
|
|
|
|
return lhs == rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|