Background poll for lvconvert -M command. The merging snapshot is removed when the merge finishes. Signed-off-by: Mikulas Patocka --- tools/lvconvert.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) Index: LVM2.2.02.39/tools/lvconvert.c =================================================================== --- LVM2.2.02.39.orig/tools/lvconvert.c 2008-07-06 21:56:21.000000000 +0200 +++ LVM2.2.02.39/tools/lvconvert.c 2008-07-06 21:56:24.000000000 +0200 @@ -326,6 +326,42 @@ static int _finish_lvconvert_mirror(stru return 1; } +static int _finish_lvconvert_merge(struct cmd_context *cmd, + struct volume_group *vg, + struct logical_volume *lv, + struct list *lvs_changed __attribute((unused))) +{ + struct lv_segment *snap_seg = lv->merging_snapshot; + if (!snap_seg) { + log_error("Logical volume %s has no merging snapshot.", lv->name); + return 0; + } + + log_print("Merge into logical volume %s finished.", lv->name); + if (!lv_remove_single(cmd, snap_seg->cow, DONT_PROMPT)) { + log_error("Could not remove snapshot %s merged into %s.", snap_seg->cow->name, lv->name); + return 0; + } + + return 1; +} + +static int _poll_merge_progress(struct cmd_context *cmd, + struct volume_group *vg, + struct logical_volume *lv, + struct daemon_parms *parms) +{ + float percent; + if (!lv_snapshot_percent(lv, &percent)) { + log_error("Failed to query for merging percentage of lv %s.", lv->name); + return PROGRESS_FINISHED; + } + printf("progress... %f\n", percent); +/* !!! FIXME: don't use floating point math ; audit the whole lvm for it */ + if (!percent) return PROGRESS_FINISHED; + return PROGRESS_TRY_AGAIN; +} + static struct poll_functions _lvconvert_mirror_fns = { .get_copy_vg = _get_lvconvert_vg, .get_copy_lv = _get_lvconvert_lv, @@ -334,6 +370,13 @@ static struct poll_functions _lvconvert_ .finish_copy = _finish_lvconvert_mirror, }; +static struct poll_functions _lvconvert_merge_fns = { + .get_copy_vg = _get_lvconvert_vg, + .get_copy_lv = _get_lvconvert_lv, + .poll_progress = _poll_merge_progress, + .finish_copy = _finish_lvconvert_merge, +}; + int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv, unsigned background) { @@ -344,8 +387,12 @@ int lvconvert_poll(struct cmd_context *c if (!dm_snprintf(lv_full_name, len, "%s/%s", lv->vg->name, lv->name)) return_0; - return poll_daemon(cmd, lv_full_name, background, 0, - &_lvconvert_mirror_fns, "Converted"); + if (!lv->merging_snapshot) + return poll_daemon(cmd, lv_full_name, background, 0, + &_lvconvert_mirror_fns, "Converted"); + else + return poll_daemon(cmd, lv_full_name, background, 0, + &_lvconvert_merge_fns, "Merged"); } static int _insert_lvconvert_layer(struct cmd_context *cmd, @@ -758,6 +805,9 @@ static int lvconvert_merge(struct cmd_co return 0; } + lp->need_polling = 1; + lp->lv_to_poll = origin; + log_print("Merging of volume %s started.", lv->name); return 1;