public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: snitzer@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2/tools lvconvert.c
Date: Wed, 13 Jan 2010 01:49:00 -0000	[thread overview]
Message-ID: <20100113014953.28111.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	snitzer@sourceware.org	2010-01-13 01:49:52

Modified files:
	tools          : lvconvert.c 

Log message:
	Background poll for lvconvert --merge command.
	The merging snapshot is removed when the merge finishes.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvconvert.c.diff?cvsroot=lvm2&r1=1.111&r2=1.112

--- LVM2/tools/lvconvert.c	2010/01/13 01:47:18	1.111
+++ LVM2/tools/lvconvert.c	2010/01/13 01:49:52	1.112
@@ -44,6 +44,8 @@
 	char **pvs;
 	struct dm_list *pvh;
 	struct dm_list *failed_pvs;
+
+	struct logical_volume *lv_to_poll;
 };
 
 static int _lvconvert_name_params(struct lvconvert_params *lp,
@@ -370,6 +372,54 @@
 	return r;
 }
 
+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 of snapshot into logical volume %s has 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 progress_t _poll_merge_progress(struct cmd_context *cmd,
+				       struct logical_volume *lv,
+				       const char *name __attribute((unused)),
+				       struct daemon_parms *parms)
+{
+	float percent = 0.0;
+	percent_range_t percent_range;
+
+	if (!lv_snapshot_percent(lv, &percent, &percent_range)) {
+		log_error("%s: Failed query for merging percentage", lv->name);
+		return PROGRESS_CHECK_FAILED;
+	} else if (percent_range == PERCENT_INVALID) {
+		log_error("%s: Merging snapshot invalidated. Aborting merge.", lv->name);
+		return PROGRESS_CHECK_FAILED;
+	}
+
+	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 (percent_range == PERCENT_0)
+		return PROGRESS_FINISHED_ALL;
+
+	return PROGRESS_UNFINISHED;
+}
+
 static struct poll_functions _lvconvert_mirror_fns = {
 	.get_copy_vg = _get_lvconvert_vg,
 	.get_copy_lv = _get_lvconvert_lv,
@@ -377,6 +427,13 @@
 	.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)
 {
@@ -393,8 +450,12 @@
 
 	memcpy(uuid, &lv->lvid, sizeof(lv->lvid));
 
-	return poll_daemon(cmd, lv_full_name, uuid, background, 0,
-			   &_lvconvert_mirror_fns, "Converted");
+	if (!lv->merging_snapshot)
+		return poll_daemon(cmd, lv_full_name, uuid, background, 0,
+				   &_lvconvert_mirror_fns, "Converted");
+	else
+		return poll_daemon(cmd, lv_full_name, uuid, background, 0,
+				   &_lvconvert_merge_fns, "Merged");
 }
 
 static int _insert_lvconvert_layer(struct cmd_context *cmd,
@@ -1121,6 +1182,9 @@
 		/* merge is running regardless of this deactivation failure */
 	}
 
+	lp->need_polling = 1;
+	lp->lv_to_poll = origin;
+
 	r = 1;
 	log_print("Merging of volume %s started.", lv->name);
 out:
@@ -1237,17 +1301,18 @@
 	} else
 		lp.pvh = &vg->pvs;
 
+	lp.lv_to_poll = lvl->lv;
 	ret = lvconvert_single(cmd, lvl->lv, &lp);
 
 bad:
 	unlock_vg(cmd, lp.vg_name);
 
 	if (ret == ECMD_PROCESSED && lp.need_polling) {
-		if (!lv_info(cmd, lvl->lv, &info, 1, 0) || !info.exists) {
+		if (!lv_info(cmd, lp.lv_to_poll, &info, 1, 0) || !info.exists) {
 			log_print("Conversion starts after activation");
 			goto out;
 		}
-		ret = lvconvert_poll(cmd, lvl->lv,
+		ret = lvconvert_poll(cmd, lp.lv_to_poll,
 				     lp.wait_completion ? 0 : 1U);
 	}
 out:


             reply	other threads:[~2010-01-13  1:49 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-13  1:49 snitzer [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-04-19 21:50 jbrassow
2012-02-23 22:36 zkabelac
2012-02-22 16:03 jbrassow
2012-02-22 15:20 jbrassow
2012-02-13 18:38 jbrassow
2012-02-13 18:36 jbrassow
2012-01-25 22:38 zkabelac
2011-12-08 18:00 agk
2011-06-29  2:06 jbrassow
2011-06-28 21:28 jbrassow
2011-01-19 19:24 jbrassow
2010-11-28 18:37 snitzer
2010-07-13 22:04 jbrassow
2010-07-13 21:53 jbrassow
2010-07-01 10:10 mornfall
2010-06-23 20:32 jbrassow
2010-04-28 17:41 jbrassow
2010-04-26 18:12 agk
2010-04-20 12:18 agk
2010-03-31 20:39 agk
2010-02-05 22:47 snitzer
2010-01-13  1:47 snitzer
2010-01-11 17:13 jbrassow
2010-01-07 20:42 jbrassow
2009-10-21 22:19 jbrassow
2009-08-02 21:56 mornfall
2009-06-26 11:29 wysochanski
2009-06-10 15:27 mornfall
2009-05-19 10:27 mbroz
2009-05-19 10:12 mbroz
2008-01-16 22:54 agk
2008-01-16 19:40 agk
2008-01-16 19:16 agk
2007-12-21  1:08 agk
2007-08-01 20:54 jbrassow
2006-05-11 18:56 agk
2006-04-07 14:14 agk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100113014953.28111.qmail@sourceware.org \
    --to=snitzer@sourceware.org \
    --cc=lvm-devel@redhat.com \
    --cc=lvm2-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).