Skip to contentSkip to conversation

master - lv_update_and_reload: replace code sequence

PATCH Zdenek Kabelac 1 participant 1 message Sep 9, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c710f02e0181cc2db5455f0c98033247a70ecc30
Commit:        c710f02e0181cc2db5455f0c98033247a70ecc30
Parent:        e4e50863a22d4decd1b4c3a89e94b94173d2a704
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Tue Sep 9 14:40:32 2014 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Tue Sep 9 19:20:09 2014 +0200

lv_update_and_reload: replace code sequence

Use lv_update_and_reload() and lv_update_and_reload_origin() to handle write/suspend/commit/resume sequence.

In few places this properly handle vg_revert() after suspend failure, and also ensures there is metadata backup after successful vg_commit().

---
 lib/metadata/cache_manip.c |   27 ++------
 lib/metadata/lv_manip.c    |   35 ++-------
 lib/metadata/raid_manip.c  |  173 ++++----------------------------------------
 tools/lvchange.c           |  120 ++----------------------------
 4 files changed, 34 insertions(+), 321 deletions(-)
lib/metadata/cache_manip.c +6 -21
index 04e165f..73df448 100644
@@ -175,7 +175,6 @@ static int _cleanup_orphan_lv(struct logical_volume *lv)
  */
 int lv_cache_remove(struct logical_volume *cache_lv)
 {
-	struct cmd_context *cmd = cache_lv->vg->cmd;
 	const char *policy_name;
 	uint64_t dirty_blocks;
 	struct lv_segment *cache_seg = first_seg(cache_lv);
@@ -225,14 +224,8 @@ int lv_cache_remove(struct logical_volume *cache_lv)
 		cache_seg->policy_argv = NULL;
 
 		/* update the kernel to put the cleaner policy in place */
-		if (!vg_write(cache_lv->vg))
-			return_0;
-		if (!suspend_lv(cmd, cache_lv))
-			return_0;
-		if (!vg_commit(cache_lv->vg))
-			return_0;
-		if (!resume_lv(cmd, cache_lv))
-			return_0;
+		if (lv_update_and_reload(cache_lv))
+                        return_0;
 	}
 
 	//FIXME: use polling to do this...
@@ -256,7 +249,7 @@ int lv_cache_remove(struct logical_volume *cache_lv)
 	if (!remove_layer_from_lv(cache_lv, corigin_lv))
 			return_0;
 
-	if (!vg_write(cache_lv->vg))
+	if (!lv_update_and_reload(cache_lv))
 		return_0;
 
 	/*
@@ -264,20 +257,12 @@ int lv_cache_remove(struct logical_volume *cache_lv)
 	 * - the top-level cache LV
 	 * - the origin
 	 * - the cache_pool _cdata and _cmeta
-	 */
-	if (!suspend_lv(cmd, cache_lv))
-		return_0;
-
-	if (!vg_commit(cache_lv->vg))
-		return_0;
-
-	/* resume_lv on this (former) cache LV will resume all */
-	/*
+	 *
+	 * resume_lv on this (former) cache LV will resume all
+	 *
 	 * FIXME: currently we can't easily avoid execution of
 	 * blkid on resumed error device
 	 */
-	if (!resume_lv(cmd, cache_lv))
-		return_0;
 
 	/*
 	 * cleanup orphan devices
lib/metadata/lv_manip.c +7 -28
index cec9f84..cc7b6da 100644
@@ -5039,26 +5039,8 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
 	}
 
 	/* store vg on disk(s) */
-	if (!vg_write(vg))
-		goto_out;
-
-	if (!suspend_lv(cmd, lock_lv)) {
-		log_error("Failed to suspend %s", lock_lv->name);
-		vg_revert(vg);
-		goto bad;
-	}
-
-	if (!vg_commit(vg)) {
-		stack;
-		if (!resume_lv(cmd, lock_lv))
-			stack;
-		goto bad;
-	}
-
-	if (!resume_lv(cmd, lock_lv)) {
-		log_error("Problem reactivating %s", lock_lv->name);
-		goto bad;
-	}
+	if (!lv_update_and_reload(lock_lv))
+		goto_bad;
 
 	if (lv_is_cow_covering_origin(lv))
 		if (!monitor_dev_for_events(cmd, lv, 0, 0))
@@ -5069,15 +5051,14 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
 		if (!update_pool_lv(lock_lv, 0))
 			goto_bad;
 
+		backup(vg);
+
 		if (inactive && !deactivate_lv(cmd, lock_lv)) {
 			log_error("Problem deactivating %s.", lock_lv->name);
-			backup(vg);
 			return 0;
 		}
 	}
 
-	backup(vg);
-
 	log_print_unless_silent("Logical volume %s successfully resized", lp->lv_name);
 
 	if (lp->resizefs && (lp->resize == LV_EXTEND) &&
@@ -5085,10 +5066,7 @@ int lv_resize(struct cmd_context *cmd, struct logical_volume *lv,
 		return_0;
 
 	return 1;
-
 bad:
-	backup(vg);
-out:
 	if (inactive && !deactivate_lv(cmd, lock_lv))
 		log_error("Problem deactivating %s.", lock_lv->name);
 
@@ -6951,9 +6929,10 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
 			 *    I say that would be cleaner, but I'm not sure
 			 *    about the effects on thinpool yet...
 			 */
-			if (!vg_write(vg) || !suspend_lv(cmd, lv) ||
-			    !vg_commit(vg) || !resume_lv(cmd, lv))
+			if (!lv_update_and_reload(lv)) {
+				stack;
 				goto deactivate_and_revert_new_lv;
+			}
 
 			if (!(lvl = find_lv_in_vg(vg, lp->origin)))
 				goto deactivate_and_revert_new_lv;
lib/metadata/raid_manip.c +13 -160

231 lines not on this page · raw message

tools/lvchange.c +8 -112

175 lines not on this page · raw message