Use lv_is_origin() and lv_is_cow() rather than directly accessing lv->origin_count and lv->snapshot - just like the rest of the code. Also, use lv_is_cow() instead of find_cow() in a few places where it would aid clarity. (Requires patch to make lv_snapshot_percent() take a const LV) Finally, note that find_cow(lv)->cow == lv, and so use the LV pointer directly where we can rather than going through the confusing indirection. --- LVM2.2.02.01/tools/lvresize.c.use-snapshot-accessors 2006-04-06 10:21:53.000000000 +0100 +++ LVM2.2.02.01/tools/lvresize.c 2006-04-06 10:22:27.000000000 +0100 @@ -116,7 +116,6 @@ { 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; @@ -517,8 +516,8 @@ 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 = find_cow(lv)->origin; else lock_lv = lv; --- LVM2.2.02.01/tools/vgchange.c.use-snapshot-accessors 2006-04-06 09:13:40.000000000 +0100 +++ LVM2.2.02.01/tools/vgchange.c 2006-04-06 09:14:03.000000000 +0100 @@ -198,7 +198,7 @@ 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); --- LVM2.2.02.01/lib/report/report.c.use-snapshot-accessors 2006-04-06 10:01:57.000000000 +0100 +++ LVM2.2.02.01/lib/report/report.c 2006-04-06 12:39:28.000000000 +0100 @@ -324,7 +324,6 @@ 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 @@ 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 @@ 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(lv, &snap_percent) || snap_percent < 0 || snap_percent >= 100)) { repstr[0] = toupper(repstr[0]); if (info.suspended) @@ -491,10 +490,9 @@ 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, &find_cow(lv)->origin->name); field->report_string = ""; field->sort_value = (const void *) field->report_string; @@ -667,11 +665,10 @@ 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; @@ -840,7 +837,6 @@ const void *data) { const struct logical_volume *lv = (const struct logical_volume *) data; - struct lv_segment *snap_seg; struct lvinfo info; float snap_percent; uint64_t *sortval; @@ -851,15 +847,15 @@ return 0; } - if (!(snap_seg = find_cow(lv)) || - (lv_info(lv->vg->cmd, snap_seg->cow, &info, 0) && !info.exists)) { + if (!lv_is_cow(lv) || + (lv_info(lv->vg->cmd, lv, &info, 0) && !info.exists)) { field->report_string = ""; *sortval = UINT64_C(0); field->sort_value = sortval; return 1; } - if (!lv_snapshot_percent(snap_seg->cow, &snap_percent) + if (!lv_snapshot_percent(lv, &snap_percent) || snap_percent < 0) { field->report_string = "100.00"; *sortval = UINT64_C(100);