Skip to contentSkip to conversation

libdm-deptree-return-failure-activate-and-preload-children

PATCH New Mike Snitzer 2 participants 10 messages Nov 20, 2009 – Nov 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 libdm-deptree-return-failure-activate-and-preload-children

Return error immediately to dm_tree_preload_children() and dm_tree_activate_children() callers.

Otherwise resume_lv and its variants can fail silently.

Catching these failures is especially important now that dm targets like crypt and snapshot-merge can fail in .preresume

---
 libdm/libdm-deptree.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
libdm/libdm-deptree.c +6 -4
index 1465fd3..bb10fe5 100644
@@ -1158,7 +1158,8 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,
 			continue;
 
 		if (dm_tree_node_num_children(child, 0))
-			dm_tree_activate_children(child, uuid_prefix, uuid_prefix_len);
+			if (!dm_tree_activate_children(child, uuid_prefix, uuid_prefix_len))
+				return_0;
 	}
 
 	handle = NULL;
@@ -1204,7 +1205,7 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,
 				log_error("Unable to resume %s (%" PRIu32
 					  ":%" PRIu32 ")", child->name, child->info.major,
 					  child->info.minor);
-				continue;
+				return 0;
 			}
 
 			/* Update cached info */
@@ -1621,7 +1622,8 @@ int dm_tree_preload_children(struct dm_tree_node *dnode,
 			continue;
 
 		if (dm_tree_node_num_children(child, 0))
-			dm_tree_preload_children(child, uuid_prefix, uuid_prefix_len);
+			if (!dm_tree_preload_children(child, uuid_prefix, uuid_prefix_len))
+				return_0;
 
 		/* FIXME Cope if name exists with no uuid? */
 		if (!child->info.exists) {
@@ -1655,7 +1657,7 @@ int dm_tree_preload_children(struct dm_tree_node *dnode,
 			log_error("Unable to resume %s (%" PRIu32
 				  ":%" PRIu32 ")", child->name, child->info.major,
 				  child->info.minor);
-			continue;
+			return 0;
 		}
 
 		/* Update cached info */
Signature · 1 line
1.6.5.2
#1 lore raw

PATCH 2/5 libdm-deptree-return-failure-suspend-children

Return error immediately to dm_tree_suspend_children() callers.

Otherwise suspend_lv and its variants can fail silently.

---
 libdm/libdm-deptree.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +3 -2
index bb10fe5..6f5355d 100644
@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,
 			log_error("Unable to suspend %s (%" PRIu32
 				  ":%" PRIu32 ")", name, info.major,
 				  info.minor);
-			continue;
+			return 0;
 		}
 
 		/* Update cached info */
@@ -1130,7 +1130,8 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,
 			continue;
 
 		if (dm_tree_node_num_children(child, 0))
-			dm_tree_suspend_children(child, uuid_prefix, uuid_prefix_len);
+			if (!dm_tree_suspend_children(child, uuid_prefix, uuid_prefix_len))
+				return_0;
 	}
 
 	return 1;
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH 2/5 libdm-deptree-return-failure-suspend-children

Dne 20.11.2009 22:29, Mike Snitzer napsal(a):

Quoted 14 lines

Return error immediately to dm_tree_suspend_children() callers.

Otherwise suspend_lv and its variants can fail silently.

---
 libdm/libdm-deptree.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +0 -0
index bb10fe5..6f5355d 100644

libdm/libdm-deptree.c int dm_tree_suspend_children(struct dm_tree_node *dnode, · line 1113

Quoted 6 lines
libdm/libdm-deptree.c +1 -1
@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,
 			log_error("Unable to suspend %s (%" PRIu32
 				  ":%" PRIu32 ")", name, info.major,
 				  info.minor);
-			continue;
+			return 0;
 		}

This is a bit hard to tell what's the right way here - either to continue suspending 'the rest of the monster' or to stop with the first failure.

In case of the replicator - when suspend of one head would fail - I would probably prefer to see the code to continue suspending remaing heads.

Zdenek

Quoted 12 lines
libdm/libdm-deptree.c +2 -1
 		/* Update cached info */
@@ -1130,7 +1130,8 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,
 			continue;
 
 		if (dm_tree_node_num_children(child, 0))
-			dm_tree_suspend_children(child, uuid_prefix, uuid_prefix_len);
+			if (!dm_tree_suspend_children(child, uuid_prefix, uuid_prefix_len))
+				return_0;
 	}
 
 	return 1;
#3 lore raw

Re: [PATCH 2/5] libdm-deptree-return-failure-suspend-children

Quoted 26 lines · Zdenek Kabelac

Dne 20.11.2009 22:29, Mike Snitzer napsal(a):

Quoted 14 lines

Return error immediately to dm_tree_suspend_children() callers.

Otherwise suspend_lv and its variants can fail silently.

---
 libdm/libdm-deptree.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +0 -0
index bb10fe5..6f5355d 100644

libdm/libdm-deptree.c int dm_tree_suspend_children(struct dm_tree_node *dnode, · line 1113

Quoted 6 lines
libdm/libdm-deptree.c +1 -1
@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,
 			log_error("Unable to suspend %s (%" PRIu32
 				  ":%" PRIu32 ")", name, info.major,
 				  info.minor);
-			continue;
+			return 0;
 		}

This is a bit hard to tell what's the right way here - either to continue suspending 'the rest of the monster' or to stop with the first failure.

Quoted 2 lines

In case of the replicator - when suspend of one head would fail - I would probably prefer to see the code to continue suspending remaing heads.

OK, the other possibility that Alasdair and I discussed is that we could return failure once all nodes at the same level have been processed.

Would that work for replicator? Are all heads at the same level in the tree?

Mike

#4 lore raw

Re: [PATCH 2/5] libdm-deptree-return-failure-suspend-children

Dne 21.11.2009 03:26, Mike Snitzer napsal(a):

Quoted 29 lines
Quoted 26 lines · Zdenek Kabelac

Dne 20.11.2009 22:29, Mike Snitzer napsal(a):

Quoted 14 lines

Return error immediately to dm_tree_suspend_children() callers.

Otherwise suspend_lv and its variants can fail silently.

---
 libdm/libdm-deptree.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +0 -0
index bb10fe5..6f5355d 100644

libdm/libdm-deptree.c int dm_tree_suspend_children(struct dm_tree_node *dnode, · line 1113

Quoted 6 lines
libdm/libdm-deptree.c +1 -1
@@ -1109,7 +1109,7 @@ int dm_tree_suspend_children(struct dm_tree_node *dnode,
 			log_error("Unable to suspend %s (%" PRIu32
 				  ":%" PRIu32 ")", name, info.major,
 				  info.minor);
-			continue;
+			return 0;
 		}

This is a bit hard to tell what's the right way here - either to continue suspending 'the rest of the monster' or to stop with the first failure.

Quoted 7 lines
Quoted 2 lines

In case of the replicator - when suspend of one head would fail - I would probably prefer to see the code to continue suspending remaing heads.

OK, the other possibility that Alasdair and I discussed is that we could return failure once all nodes at the same level have been processed.

Would that work for replicator? Are all heads at the same level in the tree?

Yes - that would probably work well for replicator (though the error in the suspend as rather hypothetical in this case anyway)

But - still - is it the best thing to stop suspending elements from tree - if one path fails?

Zdenek

#5 lore raw

PATCH 3/5 libdm-deptree-return-failure-deactivate-children

In reply to Mike Snitzer

Return error immediately to dm_tree_deactivate_children() callers.

Otherwise deactivate_lv can fail silently.

---
 libdm/libdm-deptree.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
libdm/libdm-deptree.c +3 -2
index 6f5355d..91f7177 100644
@@ -1043,11 +1043,12 @@ int dm_tree_deactivate_children(struct dm_tree_node *dnode,
 			log_error("Unable to deactivate %s (%" PRIu32
 				  ":%" PRIu32 ")", name, info.major,
 				  info.minor);
-			continue;
+			return 0;
 		}
 
 		if (dm_tree_node_num_children(child, 0))
-			dm_tree_deactivate_children(child, uuid_prefix, uuid_prefix_len);
+			if (!dm_tree_deactivate_children(child, uuid_prefix, uuid_prefix_len))
+				return_0;
 	}
 
 	return 1;
Signature · 1 line
1.6.5.2
#6 lore raw

PATCH 4/5 lvm-stack-on-resume-and-suspend-failures

In reply to Mike Snitzer

Add missing 'stack;' for all suspend_lv and resume_lv callers.

---
 lib/locking/locking.c   |    6 ++++--
 lib/metadata/lv_manip.c |    3 ++-
 lib/metadata/mirror.c   |    5 +++--
 tools/lvchange.c        |    6 ++++--
 tools/lvconvert.c       |    3 ++-
 tools/lvresize.c        |    3 ++-
 tools/pvmove.c          |   21 ++++++++++++++-------
 tools/toollib.c         |   13 ++++++++++++-
 8 files changed, 43 insertions(+), 17 deletions(-)
lib/locking/locking.c +4 -2
index 9d86433..de890b2 100644
@@ -439,7 +439,8 @@ int resume_lvs(struct cmd_context *cmd, struct dm_list *lvs)
 	struct lv_list *lvl;
 
 	dm_list_iterate_items(lvl, lvs)
-		resume_lv(cmd, lvl->lv);
+		if (!resume_lv(cmd, lvl->lv))
+			stack;
 
 	return 1;
 }
@@ -455,7 +456,8 @@ int suspend_lvs(struct cmd_context *cmd, struct dm_list *lvs)
 			log_error("Failed to suspend %s", lvl->lv->name);
 			dm_list_uniterate(lvh, lvs, &lvl->list) {
 				lvl = dm_list_item(lvh, struct lv_list);
-				resume_lv(cmd, lvl->lv);
+				if (!resume_lv(cmd, lvl->lv))
+					stack;
 			}
 
 			return 0;
lib/metadata/lv_manip.c +2 -1
index 5041fd8..260a9ee 100644
@@ -1822,7 +1822,8 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
 	if (!(r = vg_commit(vg)))
 		stack;
 
-	resume_lvs(cmd, &lvs_changed);
+	if (!resume_lvs(cmd, &lvs_changed))
+		stack;
 out:
 	backup(vg);
 	return r;
lib/metadata/mirror.c +3 -2
index 6936e8c..d53a219 100644
@@ -596,8 +596,9 @@ static int _remove_mirror_images(struct logical_volume *lv,
 	}
 
 	if (!vg_commit(mirrored_seg->lv->vg)) {
-		resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv);
-		return 0;
+		if (!resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv))
+			stack;
+		return_0;
 	}
 
 	log_very_verbose("Updating \"%s\" in kernel", mirrored_seg->lv->name);
tools/lvchange.c +4 -2
index ab4dc33..ce94101 100644
@@ -64,7 +64,8 @@ static int lvchange_permission(struct cmd_context *cmd,
 	}
 
 	if (!vg_commit(lv->vg)) {
-		resume_lv(cmd, lv);
+		if (!resume_lv(cmd, lv))
+			stack;
 		goto_out;
 	}
 
@@ -385,7 +386,8 @@ static int lvchange_readahead(struct cmd_context *cmd,
 	}
 
 	if (!vg_commit(lv->vg)) {
-		resume_lv(cmd, lv);
+		if (!resume_lv(cmd, lv))
+			stack;
 		goto_out;
 	}
 
tools/lvconvert.c +2 -1
index 0821c30..d1b86bf 100644
@@ -790,7 +790,8 @@ static int _lvconvert_mirrors(struct cmd_context *cmd, struct logical_volume *lv
 	}
 
 	if (!vg_commit(lv->vg)) {
-		resume_lv(cmd, lv);
+		if (!resume_lv(cmd, lv))
+			stack;
 		goto_out;
 	}
 
tools/lvresize.c +2 -1
index 3b3a2eb..761ed27 100644
@@ -638,7 +638,8 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 
 	if (!vg_commit(vg)) {
 		stack;
-		resume_lv(cmd, lock_lv);
+		if (!resume_lv(cmd, lock_lv))
+			stack;
 		backup(vg);
 		return ECMD_FAILED;
 	}
tools/pvmove.c +14 -7
index ac09d6a..a56e377 100644
@@ -292,7 +292,8 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 	/* Suspend mirrors on subsequent calls */
 	if (!first_time) {
 		if (!suspend_lv(cmd, lv_mirr)) {
-			resume_lvs(cmd, lvs_changed);
+			if (!resume_lvs(cmd, lvs_changed))
+				stack;
 			vg_revert(vg);
 			goto_out;
 		}
@@ -302,8 +303,10 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 	if (!vg_commit(vg)) {
 		log_error("ABORTING: Volume group metadata update failed.");
 		if (!first_time)
-			resume_lv(cmd, lv_mirr);
-		resume_lvs(cmd, lvs_changed);
+			if (!resume_lv(cmd, lv_mirr))
+				stack;
+		if (!resume_lvs(cmd, lvs_changed))
+			stack;
 		goto out;
 	}
 
@@ -327,7 +330,8 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 	} else if (!resume_lv(cmd, lv_mirr)) {
 		log_error("Unable to reactivate logical volume \"%s\"",
 			  lv_mirr->name);
-		resume_lvs(cmd, lvs_changed);
+		if (!resume_lvs(cmd, lvs_changed))
+			stack;
 		goto out;
 	}
 
@@ -501,8 +505,10 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
 		log_error("ABORTING: Failed to write new data locations "
 			  "to disk.");
 		vg_revert(vg);
-		resume_lv(cmd, lv_mirr);
-		resume_lvs(cmd, lvs_changed);
+		if (!resume_lv(cmd, lv_mirr))
+			stack;
+		if (!resume_lvs(cmd, lvs_changed))
+			stack;
 		return 0;
 	}
 
@@ -514,7 +520,8 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
 	}
 
 	/* Unsuspend LVs */
-	resume_lvs(cmd, lvs_changed);
+	if (!resume_lvs(cmd, lvs_changed))
+		stack;
 
 	/* Deactivate mirror LV */
 	if (!deactivate_lv(cmd, lv_mirr)) {
tools/toollib.c +12 -1
index 39a6d69..ada1302 100644
@@ -1252,7 +1252,18 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
 
 int lv_refresh(struct cmd_context *cmd, struct logical_volume *lv)
 {
-	return suspend_lv(cmd, lv) && resume_lv(cmd, lv);
+	int r = 0;
+
+	r = suspend_lv(cmd, lv);
+	if (!r)
+		goto_out;
+
+	r = resume_lv(cmd, lv);
+	if (!r)
+		goto_out;
+
+out:
+	return r;
 }
 
 int vg_refresh_visible(struct cmd_context *cmd, struct volume_group *vg)
Signature · 1 line
1.6.5.2
#7 lore raw

PATCH 4/5 lvm-stack-on-resume-and-suspend-failures

Dne 20.11.2009 22:29, Mike Snitzer napsal(a):

Quoted 2 lines

Add missing 'stack;' for all suspend_lv and resume_lv callers.

How about using some macro like:

#define test_stack(a...) \
	do { \
		if (!a) \
			stack; \
	} while(0);

Well the name is randomly picked - but it could make code more compact and readable ?

Zdenek

Quoted 12 lines
---
 lib/locking/locking.c   |    6 ++++--
 lib/metadata/lv_manip.c |    3 ++-
 lib/metadata/mirror.c   |    5 +++--
 tools/lvchange.c        |    6 ++++--
 tools/lvconvert.c       |    3 ++-
 tools/lvresize.c        |    3 ++-
 tools/pvmove.c          |   21 ++++++++++++++-------
 tools/toollib.c         |   13 ++++++++++++-
 8 files changed, 43 insertions(+), 17 deletions(-)
#8 lore raw

PATCH 5/5 lvm-stack-on-activate-and-deactivate-failures

In reply to Mike Snitzer

Add missing 'stack;' for all activate_lv and deactivate_lv callers.

---
 lib/activate/activate.c |    3 ++-
 lib/locking/locking.c   |    3 ++-
 tools/pvmove.c          |   11 +++++++++--
 tools/vgchange.c        |   20 +++++++++++++++-----
 4 files changed, 28 insertions(+), 9 deletions(-)
lib/activate/activate.c +2 -1
index b3a70db..7256dab 100644
@@ -710,7 +710,8 @@ int lv_is_active(struct logical_volume *lv)
 	 * FIXME: check status to not deactivate already activate device
 	 */
 	if (activate_lv_excl(lv->vg->cmd, lv)) {
-		deactivate_lv(lv->vg->cmd, lv);
+		if (!deactivate_lv(lv->vg->cmd, lv))
+			stack;
 		return 0;
 	}
 
lib/locking/locking.c +2 -1
index de890b2..8b89b23 100644
@@ -483,7 +483,8 @@ int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusiv
 			log_error("Failed to activate %s", lvl->lv->name);
 			dm_list_uniterate(lvh, lvs, &lvl->list) {
 				lvl = dm_list_item(lvh, struct lv_list);
-				activate_lv(cmd, lvl->lv);
+				if (!activate_lv(cmd, lvl->lv))
+					stack;
 			}
 			return 0;
 		}
tools/pvmove.c +9 -2
index a56e377..0819746 100644
@@ -261,10 +261,17 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
 static int _activate_lv(struct cmd_context *cmd, struct logical_volume *lv_mirr,
 			unsigned exclusive)
 {
+	int r = 0;
+
 	if (exclusive)
-		return activate_lv_excl(cmd, lv_mirr);
+		r = activate_lv_excl(cmd, lv_mirr);
+	else
+		r = activate_lv(cmd, lv_mirr);
 
-	return activate_lv(cmd, lv_mirr);
+	if (!r)
+		stack;
+
+	return r;
 }
 
 static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
tools/vgchange.c +15 -5
index 80ac6e7..c1aa5cf 100644
@@ -79,19 +79,29 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd,
 			continue;
 
 		if (activate == CHANGE_AN) {
-			if (!deactivate_lv(cmd, lv))
+			if (!deactivate_lv(cmd, lv)) {
+				stack;
 				continue;
+			}
 		} else if (activate == CHANGE_ALN) {
-			if (!deactivate_lv_local(cmd, lv))
+			if (!deactivate_lv_local(cmd, lv)) {
+				stack;
 				continue;
+			}
 		} else if (lv_is_origin(lv) || (activate == CHANGE_AE)) {
-			if (!activate_lv_excl(cmd, lv))
+			if (!activate_lv_excl(cmd, lv)) {
+				stack;
 				continue;
+			}
 		} else if (activate == CHANGE_ALY) {
-			if (!activate_lv_local(cmd, lv))
+			if (!activate_lv_local(cmd, lv)) {
+				stack;
 				continue;
-		} else if (!activate_lv(cmd, lv))
+			}
+		} else if (!activate_lv(cmd, lv)) {
+			stack;
 			continue;
+		}
 
 		if (activate != CHANGE_AN && activate != CHANGE_ALN &&
 		    (lv->status & (PVMOVE|CONVERTING)))
Signature · 1 line
1.6.5.2
#9 lore raw

PATCH 1/5 libdm-deptree-return-failure-activate-and-preload-children

In reply to Mike Snitzer

Dne 20.11.2009 22:29, Mike Snitzer napsal(a):

Quoted 8 lines

Return error immediately to dm_tree_preload_children() and dm_tree_activate_children() callers.

Otherwise resume_lv and its variants can fail silently.

Catching these failures is especially important now that dm targets like crypt and snapshot-merge can fail in .preresume

Similar case applies for replicator - and I'm using similar code in my own patch set.

So it's definitely needed.

Ack

Quoted 22 lines
---
 libdm/libdm-deptree.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
libdm/libdm-deptree.c +2 -1
index 1465fd3..bb10fe5 100644
@@ -1158,7 +1158,8 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,
 			continue;
 
 		if (dm_tree_node_num_children(child, 0))
-			dm_tree_activate_children(child, uuid_prefix, uuid_prefix_len);
+			if (!dm_tree_activate_children(child, uuid_prefix, uuid_prefix_len))
+				return_0;
 	}
 
 	handle = NULL;
@@ -1204,7 +1205,7 @@ int dm_tree_activate_children(struct dm_tree_node *dnode,
 				log_error("Unable to resume %s (%" PRIu32
 					  ":%" PRIu32 ")", child->name, child->info.major,