From: Alasdair Kergon Date: Thu, 6 Apr 2006 13:39:16 +0000 (+0000) Subject: Introduce origin_from_cow() X-Git-Tag: v2_02_91~4574 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=2cd0aa727a6d9e3c5a30828de093131b7ad3cee9;p=lvm2.git Introduce origin_from_cow() --- diff --git a/WHATS_NEW b/WHATS_NEW index 592262ef6..9a2638a21 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.03 - =================================== + Introduce origin_from_cow(). pvremove without -f now fails if there's no PV label. Support lvconvert -s. Suppress locking library load failure message if --ignorelockingfailure. diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 3e0a73c5b..b80afbbfd 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -538,8 +538,12 @@ int lv_is_cow(const struct logical_volume *lv); int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv); +/* Given a cow LV, return return the snapshot lv_segment that uses it */ struct lv_segment *find_cow(const struct logical_volume *lv); +/* Given a cow LV, return its origin */ +struct logical_volume *origin_from_cow(const struct logical_volume *lv); + int vg_add_snapshot(struct format_instance *fid, const char *name, struct logical_volume *origin, struct logical_volume *cow, union lvid *lvid, uint32_t extent_count, diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c index a2536f50f..792bc741d 100644 --- a/lib/metadata/snapshot_manip.c +++ b/lib/metadata/snapshot_manip.c @@ -34,6 +34,12 @@ struct lv_segment *find_cow(const struct logical_volume *lv) return lv->snapshot; } +/* Given a cow LV, return its origin */ +struct logical_volume *origin_from_cow(const struct logical_volume *lv) +{ + return lv->snapshot->origin; +} + int vg_add_snapshot(struct format_instance *fid, const char *name, struct logical_volume *origin, struct logical_volume *cow, union lvid *lvid, diff --git a/lib/report/report.c b/lib/report/report.c index 855f19700..cf8f71fe6 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -324,7 +324,6 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field, const struct logical_volume *lv = (const struct logical_volume *) data; struct lvinfo info; char *repstr; - struct lv_segment *snap_seg; float snap_percent; if (!(repstr = dm_pool_zalloc(rh->mem, 7))) { @@ -344,7 +343,7 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field, repstr[0] = 'v'; else if (lv_is_origin(lv)) repstr[0] = 'o'; - else if (find_cow(lv)) + else if (lv_is_cow(lv)) repstr[0] = 's'; else repstr[0] = '-'; @@ -377,8 +376,8 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field, repstr[4] = 'd'; /* Inactive without table */ /* Snapshot dropped? */ - if (info.live_table && (snap_seg = find_cow(lv)) && - (!lv_snapshot_percent(snap_seg->cow, &snap_percent) || + if (info.live_table && lv_is_cow(lv) && + (!lv_snapshot_percent(find_cow(lv)->cow, &snap_percent) || snap_percent < 0 || snap_percent >= 100)) { repstr[0] = toupper(repstr[0]); if (info.suspended) @@ -491,10 +490,9 @@ static int _origin_disp(struct report_handle *rh, struct field *field, const void *data) { const struct logical_volume *lv = (const struct logical_volume *) data; - struct lv_segment *snap_seg; - if ((snap_seg = find_cow(lv))) - return _string_disp(rh, field, &snap_seg->origin->name); + if (lv_is_cow(lv)) + return _string_disp(rh, field, &origin_from_cow(lv)->name); field->report_string = ""; field->sort_value = (const void *) field->report_string; @@ -667,11 +665,10 @@ static int _chunksize_disp(struct report_handle *rh, struct field *field, const void *data) { const struct lv_segment *seg = (const struct lv_segment *) data; - struct lv_segment *snap_seg; uint64_t size; - if ((snap_seg = find_cow(seg->lv))) - size = (uint64_t) snap_seg->chunk_size; + if (lv_is_cow(seg->lv)) + size = (uint64_t) find_cow(seg->lv)->chunk_size; else size = 0; diff --git a/tools/lvremove.c b/tools/lvremove.c index e29af6f38..5ecf850e4 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -83,7 +83,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv, } if (lv_is_cow(lv)) { - origin = find_cow(lv)->origin; + origin = origin_from_cow(lv); log_verbose("Removing snapshot %s", lv->name); if (!vg_remove_snapshot(lv)) { stack; diff --git a/tools/lvresize.c b/tools/lvresize.c index ce5f821a9..fc9724695 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -116,7 +116,6 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) { struct volume_group *vg; struct logical_volume *lv; - struct lv_segment *snap_seg; struct lvinfo info; uint32_t stripesize_extents = 0; uint32_t seg_stripes = 0, seg_stripesize = 0, seg_size = 0; @@ -521,8 +520,8 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) backup(vg); /* If snapshot, must suspend all associated devices */ - if ((snap_seg = find_cow(lv))) - lock_lv = snap_seg->origin; + if (lv_is_cow(lv)) + lock_lv = origin_from_cow(lv); else lock_lv = lv; diff --git a/tools/lvscan.c b/tools/lvscan.c index 41a74674e..bad372ef0 100644 --- a/tools/lvscan.c +++ b/tools/lvscan.c @@ -43,9 +43,9 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv, snap_active = 0; } snap_seg = NULL; - } else if ((snap_seg = find_cow(lv))) { + } else if (lv_is_cow(lv)) { if (inkernel && - (snap_active = lv_snapshot_percent(snap_seg->cow, + (snap_active = lv_snapshot_percent(find_cow(lv)->cow, &snap_percent))) if (snap_percent < 0 || snap_percent >= 100) snap_active = 0; diff --git a/tools/vgchange.c b/tools/vgchange.c index 461caa940..6584560e4 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -198,7 +198,7 @@ static int _vgchange_clustered(struct cmd_context *cmd, if (clustered) { list_iterate_items(lvl, &vg->lvs) { - if (lvl->lv->origin_count || lvl->lv->snapshot) { + if (lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) { log_error("Volume group %s contains snapshots " "that are not yet supported.", vg->name);