Skip to contentSkip to conversation

lvconvert: fix wrong name order when merging thin snapshot

PATCH New Eric Ren 2 participants 3 messages Oct 30, 2017

lore
Share & tools
lore

Eric Ren

author
#0 lore raw

PATCH 1/1 lvconvert: fix wrong name order when merging thin snapshot

The wrong message occurs when merging thin snapshot as below:

"""
lvcreate --type thin-pool -l80%FREE -n pool1 vg1
lvcreate -T vg1/pool1 -V 1G -n lv1
mkfs.ext2 /dev/vg1/lv1
mkdir mnt
mount /dev/vg1/lv1 mnt/
touch mnt/foo
lvcreate -s -n lv1.snap1 vg1/lv1
touch mnt/bar
umount mnt
lvconvert --merge vg1/lv1.snap1
Merging of thin snapshot vg1/lv1 will occur on next activation of vg1/lv1.snap1.
"""

Fix the wrong name order by saving the initial names at the beginning, and also remove the unnecessary callings to display_lvname().

---
 tools/lvconvert.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/lvconvert.c +8 -6
index 76be5cb..3b2341c 100644
@@ -2101,10 +2101,12 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
 	int origin_is_active = 0, r = 0;
 	struct lv_segment *snap_seg = first_seg(lv);
 	struct logical_volume *origin = snap_seg->origin;
+	const char *origin_name = display_lvname(origin);
+	const char *snap_name = display_lvname(lv);
 
 	if (!origin) {
 		log_error("%s is not a mergeable logical volume.",
-			  display_lvname(lv));
+			  snap_name);
 		return 0;
 	}
 
@@ -2118,16 +2120,16 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
 	if (lv_is_external_origin(origin)) {
 		if (!(origin = origin_from_cow(lv)))
 			log_error(INTERNAL_ERROR "%s is missing origin.",
-				  display_lvname(lv));
+				  snap_name);
 		else
 			log_error("%s is read-only external origin %s.",
-				  display_lvname(lv), display_lvname(origin));
+				  snap_name, origin_name);
 		return 0;
 	}
 
 	if (lv_is_origin(origin)) {
 		log_error("Merging into the old snapshot origin %s is not supported.",
-			  display_lvname(origin));
+			  origin_name);
 		return 0;
 	}
 
@@ -2155,7 +2157,7 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
 
 		if (origin_is_active && !activate_lv(cmd, lv)) {
 			log_error("Failed to reactivate origin %s.",
-				  display_lvname(lv));
+				  origin_name);
 			goto out;
 		}
 
@@ -2176,7 +2178,7 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
 	if (r)
 		log_print_unless_silent("Merging of thin snapshot %s will occur on "
 					"next activation of %s.",
-					display_lvname(lv), display_lvname(origin));
+					snap_name, origin_name);
 
 	return r;
 }
Signature · 1 line
2.10.2
#1 lore raw

PATCH 1/1 lvconvert: fix wrong name order when merging thin snapshot

Dne 30.10.2017 v 05:48 Eric Ren napsal(a):

Quoted 29 lines

The wrong message occurs when merging thin snapshot as below:

"""
lvcreate --type thin-pool -l80%FREE -n pool1 vg1
lvcreate -T vg1/pool1 -V 1G -n lv1
mkfs.ext2 /dev/vg1/lv1
mkdir mnt
mount /dev/vg1/lv1 mnt/
touch mnt/foo
lvcreate -s -n lv1.snap1 vg1/lv1
touch mnt/bar
umount mnt
lvconvert --merge vg1/lv1.snap1
Merging of thin snapshot vg1/lv1 will occur on next activation of vg1/lv1.snap1.
"""

Fix the wrong name order by saving the initial names at the beginning, and also remove the unnecessary callings to display_lvname().

---
  tools/lvconvert.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
tools/lvconvert.c +0 -0
index 76be5cb..3b2341c 100644

tools/lvconvert.c static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd, · line 2105

Quoted 5 lines
tools/lvconvert.c +2 -0
@@ -2101,10 +2101,12 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
  	int origin_is_active = 0, r = 0;
  	struct lv_segment *snap_seg = first_seg(lv);
  	struct logical_volume *origin = snap_seg->origin;
+	const char *origin_name = display_lvname(origin);
+	const char *snap_name = display_lvname(lv);

Hi

The only trouble here is that 'display_lvname()' is using internal ring buffer inside cmd struct, so the output is meant to be used immediately, otherwise it might get overwritten and you will get on output some garbage. So the proper solution here is to copy the string (dm_strncpy()) in a local buffer[NAME_LEN] buffer.

But I'll handle that one myself.

Thanks for noticing.

Regards

Zdenek

author
#2 lore raw

PATCH 1/1 lvconvert: fix wrong name order when merging thin snapshot

Hi Zdenek,

Quoted 7 lines

The only trouble here is that 'display_lvname()' is using internal ring buffer inside cmd struct, so the output is meant to be used immediately, otherwise
it might get overwritten and you will get on output some garbage. So the proper solution here is to copy the string (dm_strncpy()) in a local buffer[NAME_LEN] buffer.

I considered fixing it in this way, but it seems using display_lvname() here is OK. I tested this patch,
which doesn't output garbage, and I see other places also do like this. So, I intended to save a
string copy.

Quoted 3 lines

But I'll handle that one myself.

Thanks for noticing.

No problem, but I'm thinking I can send patch v2 if it's a real problem...

Thanks,
Eric