1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-24 14:50:34 +03:00

mirror/raid: Move 'copy_percent' to common code (mirror.c -> lv_manip.c)

The 'copy_percent' function takes the 'extents_copied' field from each
segment in an LV to create the numerator for the ratio that is to
become the copy_percent.  (Otherwise known as the 'sync' percent for
non-pvmove uses, like mirror LVs and RAID LVs.)  This function safely
works on RAID - not just mirrors - so it is better to have it in
lv_manip.c rather than mirror.c.

There's a lot of different functions that do a lot of different things
in lv_manip.c, so I placed the function near a function in lv_manip.c
that it was close to in metadata-exported.h.  Different placement in the
file or a different name for the function may be useful.
This commit is contained in:
Jonathan Brassow 2012-10-23 20:33:54 -05:00
parent 8073ce1690
commit 6db461e3b0
3 changed files with 19 additions and 18 deletions

View File

@ -199,6 +199,24 @@ uint32_t find_free_lvnum(struct logical_volume *lv)
return i;
}
percent_t copy_percent(const struct logical_volume *lv)
{
uint32_t numerator = 0u, denominator = 0u;
struct lv_segment *seg;
dm_list_iterate_items(seg, &lv->segments) {
denominator += seg->area_len;
if ((seg_is_raid(seg) || seg_is_mirrored(seg))
&& (seg->area_count > 1))
numerator += seg->extents_copied;
else
numerator += seg->area_len;
}
return denominator ? make_percent( numerator, denominator ) : 100.0;
}
/*
* All lv_segments get created here.
*/

View File

@ -831,11 +831,11 @@ struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd,
struct logical_volume *find_pvmove_lv_in_lv(struct logical_volume *lv);
const char *get_pvmove_pvname_from_lv(struct logical_volume *lv);
const char *get_pvmove_pvname_from_lv_mirr(struct logical_volume *lv_mirr);
percent_t copy_percent(const struct logical_volume *lv_mirr);
struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
struct logical_volume *lv);
uint32_t find_free_lvnum(struct logical_volume *lv);
percent_t copy_percent(const struct logical_volume *lv_mirr);
char *generate_lv_name(struct volume_group *vg, const char *format,
char *buffer, size_t len);

View File

@ -1623,23 +1623,6 @@ struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
return lvs;
}
percent_t copy_percent(const struct logical_volume *lv_mirr)
{
uint32_t numerator = 0u, denominator = 0u;
struct lv_segment *seg;
dm_list_iterate_items(seg, &lv_mirr->segments) {
denominator += seg->area_len;
if (seg_is_mirrored(seg) && seg->area_count > 1)
numerator += seg->extents_copied;
else
numerator += seg->area_len;
}
return denominator ? make_percent( numerator, denominator ) : 100.0;
}
/*
* Fixup mirror pointers after single-pass segment import
*/