Skip to contentSkip to conversation

Add mirror log to dependency tree using its UUID.

PATCH New Milan Broz 2 participants 3 messages Feb 1, 2010 – Feb 23, 2010

lore
Share & tools
lore

Milan Broz

author
#0 lore raw

PATCH 1/1 Add mirror log to dependency tree using its UUID.

Now depencecy tree calculation tries to add log device using "_mlog" layer. It is wrong because log device do not use layering (it has its own UUID without layer suffix).
It currently works because query is done only by name.

Because I plan to change all kernel dm info queries to use UUID only, it must be rewritten to use proper UUID.

In ideal world we can use log_lv directly. Unfortunately the lvconvert code is currently broken, so code must search for log_lv according to name (it doesn't provide log_lv when it should).

(mornfall: please can we fix lvconvert to use proper LV struct with log lv prepared? See _lv_update_log_type() confusion where new log_lv get lost...)

For now, the patch below works... (with my later changes)

---
 lib/activate/dev_manager.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)
lib/activate/dev_manager.c +29 -2
index 6023574..23cea2e 100644
@@ -823,8 +823,32 @@ static int _add_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, struc
 	if (!_add_dev_to_dtree(dm, dtree, lv, "cow"))
 		return_0;
 
-	if (!_add_dev_to_dtree(dm, dtree, lv, "_mlog"))
-		return_0;
+	return 1;
+}
+
+static int _add_mirrored_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
+				     struct logical_volume *lv)
+{
+	struct lv_segment *seg = first_seg(lv);
+	struct lv_list *lvl;
+	char log_name[NAME_LEN];
+
+	if (seg->log_lv) {
+		if (!_add_dev_to_dtree(dm, dtree, seg->log_lv, NULL))
+			return_0;
+	} else {
+		/*
+		 * FIXME: This should not be needed at all!
+		 * Mirrored LV should have log_lv always updated, unfortunately
+		 * some convert operations use old LV struct here.
+		 * For now, try to find log LV using its reserved name.
+		 */
+		if (dm_snprintf(log_name, NAME_LEN, "%s_mlog", lv->name) < 0)
+			return_0;
+		if ((lvl = find_lv_in_vg(lv->vg, log_name)) &&
+		    !_add_dev_to_dtree(dm, dtree, lvl->lv, NULL))
+			return_0;
+	}
 
 	return 1;
 }
@@ -849,6 +873,9 @@ static struct dm_tree *_create_partial_dtree(struct dev_manager *dm, struct logi
 		if (!_add_lv_to_dtree(dm, dtree, dm_list_struct_base(snh, struct lv_segment, origin_list)->cow))
 			goto_bad;
 
+	if ((lv->status & MIRRORED) && !_add_mirrored_lv_to_dtree(dm, dtree, lv))
+		goto_bad;
+
 	/* Add any LVs used by segments in this LV */
 	dm_list_iterate_items(seg, &lv->segments)
 		for (s = 0; s < seg->area_count; s++)
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 1/1 Add mirror log to dependency tree using its UUID.

Hi,

Quoted 11 lines · Milan Broz

Now depencecy tree calculation tries to add log device using "_mlog" layer. It is wrong because log device do not use layering (it has its own UUID without layer suffix).
It currently works because query is done only by name.

Because I plan to change all kernel dm info queries to use UUID only, it must be rewritten to use proper UUID.

In ideal world we can use log_lv directly. Unfortunately the lvconvert code is currently broken, so code must search for log_lv according to name (it doesn't provide log_lv when it should).

I have double-checked and this is not true. See below.

Quoted 3 lines

(mornfall: please can we fix lvconvert to use proper LV struct with log lv prepared? See _lv_update_log_type() confusion where new log_lv get lost...)

If I was a little more careful to check the patch, this could have been easy... You have moved the _mlog from _add_lv_to_dtree to _create_partial_dtree -- but this is not correct! The following patch works:

(The problem with the proposed patch is that when a nested mirror is created -- which happens upon lvconvert -m+1, for example, the partial tree will only contain the toplevel (temporary) mirror and the two images -- one regular and one mirrored... the mirrored one will however not get any of its dependencies in the tree, hence *partial*... this breaks lvconvert since the suspend/resume cycle leaves the _mlog device, which is not included in the partial trees, in the wrong state.)

lib/activate/dev_manager.c +2 -1
diff -rN -u -p old-upstream/lib/activate/dev_manager.c new-upstream/lib/activate/dev_manager.c
@@ -823,7 +823,8 @@ static int _add_lv_to_dtree(struct dev_m
 	if (!_add_dev_to_dtree(dm, dtree, lv, "cow"))
 		return_0;
 
-	if (!_add_dev_to_dtree(dm, dtree, lv, "_mlog"))
+	if ((lv->status & MIRRORED) && first_seg(lv)->log_lv &&
+	    !_add_dev_to_dtree(dm, dtree, first_seg(lv)->log_lv, NULL))
 		return_0;
 
 	return 1;

(the original patch):

Quoted 38 lines
lib/activate/dev_manager.c +26 -2
@@ -823,8 +823,32 @@ static int _add_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree, struc
 	if (!_add_dev_to_dtree(dm, dtree, lv, "cow"))
 		return_0;
 
-	if (!_add_dev_to_dtree(dm, dtree, lv, "_mlog"))
-		return_0;
+	return 1;
+}
+
+static int _add_mirrored_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
+				     struct logical_volume *lv)
+{
+	struct lv_segment *seg = first_seg(lv);
+	struct lv_list *lvl;
+	char log_name[NAME_LEN];
+
+	if (seg->log_lv) {
+		if (!_add_dev_to_dtree(dm, dtree, seg->log_lv, NULL))
+			return_0;
+	} else {
+		/*
+		 * FIXME: This should not be needed at all!
+		 * Mirrored LV should have log_lv always updated, unfortunately
+		 * some convert operations use old LV struct here.
+		 * For now, try to find log LV using its reserved name.
+		 */
+		if (dm_snprintf(log_name, NAME_LEN, "%s_mlog", lv->name) < 0)
+			return_0;
+		if ((lvl = find_lv_in_vg(lv->vg, log_name)) &&
+		    !_add_dev_to_dtree(dm, dtree, lvl->lv, NULL))
+			return_0;
+	}
 
 	return 1;
 }

lib/activate/dev_manager.c static struct dm_tree *_create_partial_dtree(struct dev_manager *dm, struct logi · line 881

Quoted 9 lines
lib/activate/dev_manager.c +3 -0
@@ -849,6 +873,9 @@ static struct dm_tree *_create_partial_dtree(struct dev_manager *dm, struct logi
 		if (!_add_lv_to_dtree(dm, dtree, dm_list_struct_base(snh, struct lv_segment, origin_list)->cow))
 			goto_bad;
 
+	if ((lv->status & MIRRORED) && !_add_mirrored_lv_to_dtree(dm, dtree, lv))
+		goto_bad;
+
 	/* Add any LVs used by segments in this LV */
 	dm_list_iterate_items(seg, &lv->segments)
 		for (s = 0; s < seg->area_count; s++)

Yours,
Petr.

PS: Yes, it took me a few hours to track this down : - ( ... Next time I should read more carefully.

author
#2 lore raw

PATCH 1/1 Add mirror log to dependency tree using its UUID.

Quoted 4 lines · Petr Rockai

If I was a little more careful to check the patch, this could have been easy... You have moved the _mlog from _add_lv_to_dtree to _create_partial_dtree -- but this is not correct! The following patch works:

:-)

lib/activate/dev_manager.c static int _add_lv_to_dtree(struct dev_m · line 828

Quoted 8 lines
lib/activate/dev_manager.c +2 -1
@@ -823,7 +823,8 @@ static int _add_lv_to_dtree(struct dev_m
 	if (!_add_dev_to_dtree(dm, dtree, lv, "cow"))
 		return_0;
 
-	if (!_add_dev_to_dtree(dm, dtree, lv, "_mlog"))
+	if ((lv->status & MIRRORED) && first_seg(lv)->log_lv &&
+	    !_add_dev_to_dtree(dm, dtree, first_seg(lv)->log_lv, NULL))
 		return_0;

yes, this seem to be correct, ack

Milan