From c45a8a2c1c7eeb4f5c1e7f50da9d19e7c3e9f76d Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 19 Jan 2005 17:19:39 +0000 Subject: [PATCH] Store snapshot and origin sizes separately. --- WHATS_NEW | 1 + lib/activate/dev_manager.c | 9 +++++---- lib/format1/import-export.c | 2 +- lib/format_text/export.c | 2 +- lib/metadata/metadata.h | 7 ++++--- lib/metadata/snapshot_manip.c | 7 ++++--- lib/snapshot/snapshot.c | 10 ++++++++-- tools/lvcreate.c | 3 ++- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 5e5af75e5..fe1fa5807 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.01.01 - =================================== + Store snapshot and origin sizes separately. Update vgcreate man page. Version 2.01.00 - 17th January 2005 diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 9aa22938d..80b284021 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -878,6 +878,7 @@ static int _populate_snapshot(struct dev_manager *dm, struct snapshot *s; struct dev_layer *dlo, *dlc; char devbufo[10], devbufc[10]; + uint64_t size; if (!(s = find_cow(dl->lv))) { log_error("Couldn't find snapshot for '%s'.", dl->lv->name); @@ -925,10 +926,10 @@ static int _populate_snapshot(struct dev_manager *dm, return 0; } - log_debug("Adding target: 0 %" PRIu64 " snapshot %s", - s->origin->size, params); - if (!dm_task_add_target - (dmt, UINT64_C(0), s->origin->size, "snapshot", params)) { + size = (uint64_t) s->le_count * s->origin->vg->extent_size; + + log_debug("Adding target: 0 %" PRIu64 " snapshot %s", size, params); + if (!dm_task_add_target(dmt, UINT64_C(0), size, "snapshot", params)) { stack; return 0; } diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index 92719c6e4..335b729fe 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -646,7 +646,7 @@ int import_snapshots(struct pool *mem, struct volume_group *vg, continue; /* insert the snapshot */ - if (!vg_add_snapshot(org, cow, 1, NULL, + if (!vg_add_snapshot(org, cow, 1, NULL, org->le_count, lvd->lv_chunk_size)) { log_err("Couldn't add snapshot."); return 0; diff --git a/lib/format_text/export.c b/lib/format_text/export.c index cc1351fd6..223191a16 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -513,7 +513,7 @@ static int _print_snapshot(struct formatter *f, struct snapshot *snap, } seg.le = 0; - seg.len = snap->origin->le_count; + seg.len = snap->le_count; seg.origin = snap->origin; seg.cow = snap->cow; seg.chunk_size = snap->chunk_size; diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index c30952dd4..17c6d3e5b 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -255,6 +255,7 @@ struct snapshot { int persistent; /* boolean */ uint32_t chunk_size; /* in 512 byte sectors */ + uint32_t le_count; struct logical_volume *origin; struct logical_volume *cow; @@ -496,9 +497,9 @@ struct snapshot *find_cow(const struct logical_volume *lv); struct snapshot *find_origin(const struct logical_volume *lv); struct list *find_snapshots(const struct logical_volume *lv); -int vg_add_snapshot(struct logical_volume *origin, - struct logical_volume *cow, - int persistent, struct id *id, uint32_t chunk_size); +int vg_add_snapshot(struct logical_volume *origin, struct logical_volume *cow, + int persistent, struct id *id, uint32_t extent_count, + uint32_t chunk_size); int vg_remove_snapshot(struct volume_group *vg, struct logical_volume *cow); diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c index 1854b5130..664c73b28 100644 --- a/lib/metadata/snapshot_manip.c +++ b/lib/metadata/snapshot_manip.c @@ -104,9 +104,9 @@ struct list *find_snapshots(const struct logical_volume *lv) return snaplist; } -int vg_add_snapshot(struct logical_volume *origin, - struct logical_volume *cow, - int persistent, struct id *id, uint32_t chunk_size) +int vg_add_snapshot(struct logical_volume *origin, struct logical_volume *cow, + int persistent, struct id *id, uint32_t extent_count, + uint32_t chunk_size) { struct snapshot *s; struct snapshot_list *sl; @@ -127,6 +127,7 @@ int vg_add_snapshot(struct logical_volume *origin, s->persistent = persistent; s->chunk_size = chunk_size; + s->le_count = extent_count; s->origin = origin; s->cow = cow; diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c index 82e8a27e2..89ef65f77 100644 --- a/lib/snapshot/snapshot.c +++ b/lib/snapshot/snapshot.c @@ -31,7 +31,7 @@ static const char *_name(const struct lv_segment *seg) static int _text_import(struct lv_segment *seg, const struct config_node *sn, struct hash_table *pv_hash) { - uint32_t chunk_size; + uint32_t chunk_size, extent_count; const char *org_name, *cow_name; struct logical_volume *org, *cow; @@ -70,7 +70,11 @@ static int _text_import(struct lv_segment *seg, const struct config_node *sn, return 0; } - if (!vg_add_snapshot(org, cow, 1, &seg->lv->lvid.id[1], chunk_size)) { + if (!get_config_uint32(sn, "extent_count", &extent_count)) + extent_count = org->le_count; + + if (!vg_add_snapshot(org, cow, 1, &seg->lv->lvid.id[1], extent_count, + chunk_size)) { stack; return 0; } @@ -81,6 +85,8 @@ static int _text_import(struct lv_segment *seg, const struct config_node *sn, static int _text_export(const struct lv_segment *seg, struct formatter *f) { outf(f, "chunk_size = %u", seg->chunk_size); + if (seg->len != seg->origin->le_count) + outf(f, "extent_count = %u", seg->len); outf(f, "origin = \"%s\"", seg->origin->name); outf(f, "cow_store = \"%s\"", seg->cow->name); diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 3ef022049..155fe7195 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -609,7 +609,8 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) return 0; } - if (!vg_add_snapshot(org, lv, 1, NULL, lp->chunk_size)) { + if (!vg_add_snapshot(org, lv, 1, NULL, lv->le_count, + lp->chunk_size)) { log_err("Couldn't create snapshot."); return 0; }