dm exception store: move cow pointer

Move COW device from snapshot to exception store.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
This commit is contained in:
Jonathan Brassow 2009-04-02 19:55:33 +01:00 committed by Alasdair G Kergon
parent d021684951
commit 49beb2b87a
6 changed files with 30 additions and 23 deletions

View file

@ -139,7 +139,7 @@ EXPORT_SYMBOL(dm_exception_store_type_unregister);
int dm_exception_store_create(const char *type_name, struct dm_target *ti, int dm_exception_store_create(const char *type_name, struct dm_target *ti,
chunk_t chunk_size, chunk_t chunk_mask, chunk_t chunk_size, chunk_t chunk_mask,
chunk_t chunk_shift, chunk_t chunk_shift, struct dm_dev *cow,
struct dm_exception_store **store) struct dm_exception_store **store)
{ {
int r = 0; int r = 0;
@ -163,6 +163,8 @@ int dm_exception_store_create(const char *type_name, struct dm_target *ti,
tmp_store->chunk_mask = chunk_mask; tmp_store->chunk_mask = chunk_mask;
tmp_store->chunk_shift = chunk_shift; tmp_store->chunk_shift = chunk_shift;
tmp_store->cow = cow;
r = type->ctr(tmp_store, 0, NULL); r = type->ctr(tmp_store, 0, NULL);
if (r) { if (r) {
put_type(type); put_type(type);

View file

@ -99,6 +99,8 @@ struct dm_exception_store {
struct dm_snapshot *snap; struct dm_snapshot *snap;
struct dm_dev *cow;
/* Size of data blocks saved - must be a power of 2 */ /* Size of data blocks saved - must be a power of 2 */
chunk_t chunk_size; chunk_t chunk_size;
chunk_t chunk_mask; chunk_t chunk_mask;
@ -155,7 +157,7 @@ int dm_exception_store_type_unregister(struct dm_exception_store_type *type);
int dm_exception_store_create(const char *type_name, struct dm_target *ti, int dm_exception_store_create(const char *type_name, struct dm_target *ti,
chunk_t chunk_size, chunk_t chunk_mask, chunk_t chunk_size, chunk_t chunk_mask,
chunk_t chunk_shift, chunk_t chunk_shift, struct dm_dev *cow,
struct dm_exception_store **store); struct dm_exception_store **store);
void dm_exception_store_destroy(struct dm_exception_store *store); void dm_exception_store_destroy(struct dm_exception_store *store);

View file

@ -189,7 +189,7 @@ static void do_metadata(struct work_struct *work)
static int chunk_io(struct pstore *ps, chunk_t chunk, int rw, int metadata) static int chunk_io(struct pstore *ps, chunk_t chunk, int rw, int metadata)
{ {
struct dm_io_region where = { struct dm_io_region where = {
.bdev = ps->snap->cow->bdev, .bdev = ps->snap->store->cow->bdev,
.sector = ps->snap->store->chunk_size * chunk, .sector = ps->snap->store->chunk_size * chunk,
.count = ps->snap->store->chunk_size, .count = ps->snap->store->chunk_size,
}; };
@ -253,7 +253,7 @@ static void zero_memory_area(struct pstore *ps)
static int zero_disk_area(struct pstore *ps, chunk_t area) static int zero_disk_area(struct pstore *ps, chunk_t area)
{ {
struct dm_io_region where = { struct dm_io_region where = {
.bdev = ps->snap->cow->bdev, .bdev = ps->snap->store->cow->bdev,
.sector = ps->snap->store->chunk_size * area_location(ps, area), .sector = ps->snap->store->chunk_size * area_location(ps, area),
.count = ps->snap->store->chunk_size, .count = ps->snap->store->chunk_size,
}; };
@ -280,7 +280,7 @@ static int read_header(struct pstore *ps, int *new_snapshot)
*/ */
if (!ps->snap->store->chunk_size) { if (!ps->snap->store->chunk_size) {
ps->snap->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, ps->snap->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS,
bdev_hardsect_size(ps->snap->cow->bdev) >> 9); bdev_hardsect_size(ps->snap->store->cow->bdev) >> 9);
ps->snap->store->chunk_mask = ps->snap->store->chunk_size - 1; ps->snap->store->chunk_mask = ps->snap->store->chunk_size - 1;
ps->snap->store->chunk_shift = ffs(ps->snap->store->chunk_size) ps->snap->store->chunk_shift = ffs(ps->snap->store->chunk_size)
- 1; - 1;
@ -476,7 +476,7 @@ static void persistent_fraction_full(struct dm_exception_store *store,
sector_t *numerator, sector_t *denominator) sector_t *numerator, sector_t *denominator)
{ {
*numerator = get_info(store)->next_free * store->chunk_size; *numerator = get_info(store)->next_free * store->chunk_size;
*denominator = get_dev_size(store->snap->cow->bdev); *denominator = get_dev_size(store->cow->bdev);
} }
static void persistent_dtr(struct dm_exception_store *store) static void persistent_dtr(struct dm_exception_store *store)
@ -565,7 +565,7 @@ static int persistent_prepare_exception(struct dm_exception_store *store,
struct pstore *ps = get_info(store); struct pstore *ps = get_info(store);
uint32_t stride; uint32_t stride;
chunk_t next_free; chunk_t next_free;
sector_t size = get_dev_size(store->snap->cow->bdev); sector_t size = get_dev_size(store->cow->bdev);
/* Is there enough room ? */ /* Is there enough room ? */
if (size < ((ps->next_free + 1) * store->chunk_size)) if (size < ((ps->next_free + 1) * store->chunk_size))

View file

@ -40,7 +40,7 @@ static int transient_prepare_exception(struct dm_exception_store *store,
struct dm_snap_exception *e) struct dm_snap_exception *e)
{ {
struct transient_c *tc = store->context; struct transient_c *tc = store->context;
sector_t size = get_dev_size(store->snap->cow->bdev); sector_t size = get_dev_size(store->cow->bdev);
if (size < (tc->next_free + store->chunk_size)) if (size < (tc->next_free + store->chunk_size))
return -1; return -1;
@ -64,7 +64,7 @@ static void transient_fraction_full(struct dm_exception_store *store,
sector_t *numerator, sector_t *denominator) sector_t *numerator, sector_t *denominator)
{ {
*numerator = ((struct transient_c *) store->context)->next_free; *numerator = ((struct transient_c *) store->context)->next_free;
*denominator = get_dev_size(store->snap->cow->bdev); *denominator = get_dev_size(store->cow->bdev);
} }
static int transient_ctr(struct dm_exception_store *store, static int transient_ctr(struct dm_exception_store *store,

View file

@ -468,7 +468,8 @@ static int calc_max_buckets(void)
/* /*
* Allocate room for a suitable hash table. * Allocate room for a suitable hash table.
*/ */
static int init_hash_tables(struct dm_snapshot *s, chunk_t chunk_shift) static int init_hash_tables(struct dm_snapshot *s, chunk_t chunk_shift,
struct dm_dev *cow)
{ {
sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets; sector_t hash_size, cow_dev_size, origin_dev_size, max_buckets;
@ -476,7 +477,7 @@ static int init_hash_tables(struct dm_snapshot *s, chunk_t chunk_shift)
* Calculate based on the size of the original volume or * Calculate based on the size of the original volume or
* the COW volume... * the COW volume...
*/ */
cow_dev_size = get_dev_size(s->cow->bdev); cow_dev_size = get_dev_size(cow->bdev);
origin_dev_size = get_dev_size(s->origin->bdev); origin_dev_size = get_dev_size(s->origin->bdev);
max_buckets = calc_max_buckets(); max_buckets = calc_max_buckets();
@ -516,7 +517,8 @@ static ulong round_up(ulong n, ulong size)
static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg, static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg,
chunk_t *chunk_size, chunk_t *chunk_mask, chunk_t *chunk_size, chunk_t *chunk_mask,
chunk_t *chunk_shift, char **error) chunk_t *chunk_shift, struct dm_dev *cow,
char **error)
{ {
unsigned long chunk_size_ulong; unsigned long chunk_size_ulong;
char *value; char *value;
@ -545,7 +547,7 @@ static int set_chunk_size(struct dm_snapshot *s, const char *chunk_size_arg,
} }
/* Validate the chunk size against the device block size */ /* Validate the chunk size against the device block size */
if (chunk_size_ulong % (bdev_hardsect_size(s->cow->bdev) >> 9)) { if (chunk_size_ulong % (bdev_hardsect_size(cow->bdev) >> 9)) {
*error = "Chunk size is not a multiple of device blocksize"; *error = "Chunk size is not a multiple of device blocksize";
return -EINVAL; return -EINVAL;
} }
@ -569,6 +571,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
char *origin_path; char *origin_path;
char *cow_path; char *cow_path;
chunk_t chunk_size, chunk_mask, chunk_shift; chunk_t chunk_size, chunk_mask, chunk_shift;
struct dm_dev *cow;
if (argc != 4) { if (argc != 4) {
ti->error = "requires exactly 4 arguments"; ti->error = "requires exactly 4 arguments";
@ -601,7 +604,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
} }
r = dm_get_device(ti, cow_path, 0, 0, r = dm_get_device(ti, cow_path, 0, 0,
FMODE_READ | FMODE_WRITE, &s->cow); FMODE_READ | FMODE_WRITE, &cow);
if (r) { if (r) {
dm_put_device(ti, s->origin); dm_put_device(ti, s->origin);
ti->error = "Cannot get COW device"; ti->error = "Cannot get COW device";
@ -609,7 +612,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
} }
r = set_chunk_size(s, argv[3], &chunk_size, &chunk_mask, &chunk_shift, r = set_chunk_size(s, argv[3], &chunk_size, &chunk_mask, &chunk_shift,
&ti->error); cow, &ti->error);
if (r) if (r)
goto bad3; goto bad3;
@ -620,14 +623,14 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
spin_lock_init(&s->pe_lock); spin_lock_init(&s->pe_lock);
/* Allocate hash table for COW data */ /* Allocate hash table for COW data */
if (init_hash_tables(s, chunk_shift)) { if (init_hash_tables(s, chunk_shift, cow)) {
ti->error = "Unable to allocate hash table space"; ti->error = "Unable to allocate hash table space";
r = -ENOMEM; r = -ENOMEM;
goto bad3; goto bad3;
} }
r = dm_exception_store_create(argv[2], ti, chunk_size, chunk_mask, r = dm_exception_store_create(argv[2], ti, chunk_size, chunk_mask,
chunk_shift, &s->store); chunk_shift, cow, &s->store);
if (r) { if (r) {
ti->error = "Couldn't create exception store"; ti->error = "Couldn't create exception store";
r = -EINVAL; r = -EINVAL;
@ -705,7 +708,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
exit_exception_table(&s->complete, exception_cache); exit_exception_table(&s->complete, exception_cache);
bad3: bad3:
dm_put_device(ti, s->cow); dm_put_device(ti, cow);
dm_put_device(ti, s->origin); dm_put_device(ti, s->origin);
bad2: bad2:
@ -732,6 +735,7 @@ static void snapshot_dtr(struct dm_target *ti)
int i; int i;
#endif #endif
struct dm_snapshot *s = ti->private; struct dm_snapshot *s = ti->private;
struct dm_dev *cow = s->store->cow;
flush_workqueue(ksnapd); flush_workqueue(ksnapd);
@ -759,7 +763,7 @@ static void snapshot_dtr(struct dm_target *ti)
mempool_destroy(s->pending_pool); mempool_destroy(s->pending_pool);
dm_put_device(ti, s->origin); dm_put_device(ti, s->origin);
dm_put_device(ti, s->cow); dm_put_device(ti, cow);
kfree(s); kfree(s);
} }
@ -961,7 +965,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
src.sector = chunk_to_sector(s, pe->e.old_chunk); src.sector = chunk_to_sector(s, pe->e.old_chunk);
src.count = min(s->store->chunk_size, dev_size - src.sector); src.count = min(s->store->chunk_size, dev_size - src.sector);
dest.bdev = s->cow->bdev; dest.bdev = s->store->cow->bdev;
dest.sector = chunk_to_sector(s, pe->e.new_chunk); dest.sector = chunk_to_sector(s, pe->e.new_chunk);
dest.count = src.count; dest.count = src.count;
@ -1022,7 +1026,7 @@ __find_pending_exception(struct dm_snapshot *s,
static void remap_exception(struct dm_snapshot *s, struct dm_snap_exception *e, static void remap_exception(struct dm_snapshot *s, struct dm_snap_exception *e,
struct bio *bio, chunk_t chunk) struct bio *bio, chunk_t chunk)
{ {
bio->bi_bdev = s->cow->bdev; bio->bi_bdev = s->store->cow->bdev;
bio->bi_sector = chunk_to_sector(s, dm_chunk_number(e->new_chunk) + bio->bi_sector = chunk_to_sector(s, dm_chunk_number(e->new_chunk) +
(chunk - e->old_chunk)) + (chunk - e->old_chunk)) +
(bio->bi_sector & s->store->chunk_mask); (bio->bi_sector & s->store->chunk_mask);
@ -1168,7 +1172,7 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
* make sense. * make sense.
*/ */
snprintf(result, maxlen, "%s %s %s %llu", snprintf(result, maxlen, "%s %s %s %llu",
snap->origin->name, snap->cow->name, snap->origin->name, snap->store->cow->name,
snap->store->type->name, snap->store->type->name,
(unsigned long long)snap->store->chunk_size); (unsigned long long)snap->store->chunk_size);
break; break;

View file

@ -27,7 +27,6 @@ struct dm_snapshot {
struct rw_semaphore lock; struct rw_semaphore lock;
struct dm_dev *origin; struct dm_dev *origin;
struct dm_dev *cow;
/* List of snapshots per Origin */ /* List of snapshots per Origin */
struct list_head list; struct list_head list;