Background poll for lvconvert -M command. The merging snapshot is removed when the merge finishes. Signed-off-by: Mikulas Patocka --- tools/lvconvert.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) Index: LVM2.2.02.39/tools/lvconvert.c =================================================================== --- LVM2.2.02.39.orig/tools/lvconvert.c 2008-08-04 19:40:44.000000000 +0200 +++ LVM2.2.02.39/tools/lvconvert.c 2008-08-04 20:46:33.000000000 +0200 @@ -326,6 +326,49 @@ 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 dm_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) +{ + int r; + float percent; + if (!(r = lv_snapshot_percent(lv, &percent))) { + log_error("Failed to query for merging percentage of lv %s.", lv->name); + return PROGRESS_FINISHED; + } + if (r == TARGET_STATUS_INVALIDATED) { + log_print("%s: Snapshot invalidated, aborting merging", lv->name); + return PROGRESS_FINISHED; + } + if (parms->progress_display) + log_print("%s: %s: %.1f%%", lv->name, parms->progress_title, percent); + else + log_verbose("%s: %s: %.1f%%", lv->name, parms->progress_title, percent); + if (r == TARGET_STATUS_FINISHED) 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 +377,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 +394,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 +812,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;