Skip to contentSkip to conversation

Add escape sequence for ':' in command's PV list

PATCH New Peter Rajnoha 4 participants 9 messages May 13, 2009 – May 15, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Hi,

this little patch provides an escape sequence in command's PV list where ':' is also used as a delimiter for extent ranges. To escape this char, we just double it, so '::' is translated to ':' and ':' is extent range delimiter.
(BZ #491409)

Peter

tools/toollib.c +16 -3
index aa33468..b5a43b5 100644
@@ -1095,8 +1095,9 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
 	struct dm_list *r;
 	struct pv_list *pvl;
 	struct dm_list tags, arg_pvnames;
-	const char *pvname = NULL;
+	char *pvname = NULL;
 	char *colon, *tagname;
+	char *ptr, *ptr_end;
 	int i;
 
 	/* Build up list of PVs */
@@ -1128,9 +1129,21 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
 			continue;
 		}
 
-		pvname = argv[i];
+		ptr = pvname = argv[i];
+		ptr_end = strchr(ptr, '\0');
+		colon = NULL;
 
-		if ((colon = strchr(pvname, ':'))) {
+		while ((ptr = strchr(ptr, ':'))) {
+			if (ptr[1] == ':') {
+				memmove(ptr, ptr + 1, ptr_end - ptr);
+				ptr_end--;
+			}
+			else if (!colon)
+				colon = ptr;
+			ptr++;
+		}
+
+		if (colon) {
 			if (!(pvname = dm_pool_strndup(mem, pvname,
 						    (unsigned) (colon -
 								pvname)))) {
#1 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 40 lines · Peter Rajnoha

Hi,

this little patch provides an escape sequence in command's PV list where ':' is also used as a delimiter for extent ranges. To escape this char, we just double it, so '::' is translated to ':' and ':' is extent range delimiter.
(BZ #491409)

Peter

tools/toollib.c +9 -3
index aa33468..b5a43b5 100644
@@ -1095,8 +1095,9 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
 	struct dm_list *r;
 	struct pv_list *pvl;
 	struct dm_list tags, arg_pvnames;
-	const char *pvname = NULL;
+	char *pvname = NULL;
 	char *colon, *tagname;
+	char *ptr, *ptr_end;
 	int i;
 
 	/* Build up list of PVs */
@@ -1128,9 +1129,21 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
 			continue;
 		}
 
-		pvname = argv[i];
+		ptr = pvname = argv[i];
+		ptr_end = strchr(ptr, '\0');
+		colon = NULL;
 
-		if ((colon = strchr(pvname, ':'))) {
+		while ((ptr = strchr(ptr, ':'))) {
+			if (ptr[1] == ':') {
+				memmove(ptr, ptr + 1, ptr_end - ptr);
+				ptr_end--;

tools/toollib.c struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int · line 1149

Quoted 10 lines
tools/toollib.c +7 -0
+			}
+			else if (!colon)
+				colon = ptr;
+			ptr++;
+		}
+
+		if (colon) {
 			if (!(pvname = dm_pool_strndup(mem, pvname,
 						    (unsigned) (colon -
 								pvname)))) {

Reviewed and the code works as advertised, however...

This code should probably go inside lvm-string.c with the other code that handles special characters.
Also, think about consistency among pvcreate, vgcreate, and lvcreate.

Attached is a patch for a small test I put together that I think should work once this bug is fixed. It does not work currently because arguments to pvcreate and vgcreate are handled differently than lvcreate (it will pass if you change these args to just $dev1 instead of $dev1_escaped). I know, it does not make sense to specify a pe range for pvcreate or vgcreate. But shouldn't we be consistent, or at least very much clarify the arguments are different? I can just imagine someone scripting something and then being surprised when they needed to quote only for lvcreate, pvmove, etc.

To see where it fails look at the verbose output of pvcreate or you can just read the pvcreate code.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-pvcreate-test-for-escaped.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20090513/efcbda86/attachment.bin>

#2 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 1 line

+dev1_escaped=echo $dev1 | awk '{ print substr($1,1,index($1,":")-1)"::"substr($1,index($1,":")+1) }'

please can we somehow standardize which tools are required for testsuite?

or at least first test that the tools are available - like awk, mdadm, mke2fsck...

Milan

#3 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

In reply to Dave Wysochanski
Quoted 5 lines · Dave Wysochanski

I know, it does not make sense to specify a pe range
for pvcreate or vgcreate. But shouldn't we be consistent, or at least very much clarify the arguments are different? I can just imagine someone scripting something and then being surprised when they needed to quote only for lvcreate, pvmove, etc.

Hmm, then the question is, what should we do with single unescaped ':' if it appears in pvcreate, vgcreate, e.g. "pvcreate /dev/a::b:c" -- the first double one is OK, but what about the second single one? Should it be considered as an input error then? (...probably giving the user a message like "PE range definition not allowed here.")

Peter

#4 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 7 lines · Peter Rajnoha
Quoted 5 lines · Dave Wysochanski

I know, it does not make sense to specify a pe range
for pvcreate or vgcreate. But shouldn't we be consistent, or at least very much clarify the arguments are different? I can just imagine someone scripting something and then being surprised when they needed to quote only for lvcreate, pvmove, etc.

Quoted 6 lines

Hmm, then the question is, what should we do with single unescaped ':' if it appears in pvcreate, vgcreate, e.g. "pvcreate /dev/a::b:c" -- the first double one is OK, but what about the second single one? Should it be considered as an input error then? (...probably giving the user a message like "PE range definition not allowed here.")

At this point I'd lean towards just clarifing the difference in the arguments for the commands (e.g. in man pages, etc). See attached patch for a stab at updating the man pages. If we go this route, then your patch is fine as is IMO.

Also, on IRC yesterday, Alasdair suggested a new built-in command to
escape names such as this
17:01:40 < deepthot> agk_: on the escaping, you mean someone would do something like: lvcreate -L 16M -n lvname vgname lvmescape /dev/pname?
17:05:07 < agk_> almost: lvmescape /dev/path then they can append :4-10 on it

IMO, this is a good idea. However, in the spirit of not getting too sidetracked, I think if we add proper explanation, we can probably defer adding the built-in command, which probably requires some design thought (for example, how to specify whether it is a pvname, vgname, etc - they may have different characters to escape, etc). If you want to tackle that too though, go for it.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Update-man-pages-to-clarify-usage-of-PE-ranges-and.patch
Type: text/x-patch
Size: 5291 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20090514/bb0b9abe/attachment.bin>

#5 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 25 lines · Dave Wysochanski
Quoted 7 lines · Peter Rajnoha
Quoted 5 lines · Dave Wysochanski

I know, it does not make sense to specify a pe range
for pvcreate or vgcreate. But shouldn't we be consistent, or at least very much clarify the arguments are different? I can just imagine someone scripting something and then being surprised when they needed to quote only for lvcreate, pvmove, etc.

Quoted 6 lines

Hmm, then the question is, what should we do with single unescaped ':' if it appears in pvcreate, vgcreate, e.g. "pvcreate /dev/a::b:c" -- the first double one is OK, but what about the second single one? Should it be considered as an input error then? (...probably giving the user a message like "PE range definition not allowed here.")

At this point I'd lean towards just clarifing the difference in the arguments for the commands (e.g. in man pages, etc). See attached patch for a stab at updating the man pages. If we go this route, then your patch is fine as is IMO.

Also, on IRC yesterday, Alasdair suggested a new built-in command to
escape names such as this
17:01:40 < deepthot> agk_: on the escaping, you mean someone would do something like: lvcreate -L 16M -n lvname vgname lvmescape /dev/pname?
17:05:07 < agk_> almost: lvmescape /dev/path then they can append :4-10 on it

Quoted 7 lines

IMO, this is a good idea. However, in the spirit of not getting too sidetracked, I think if we add proper explanation, we can probably defer adding the built-in command, which probably requires some design thought (for example, how to specify whether it is a pvname, vgname, etc - they may have different characters to escape, etc). If you want to tackle that too though, go for it.

Upon further thought, I agree with you Peter - let's reject the ":" in pvcreate/vgcreate commands and print a message about pe range not allowed in these commands. This way the commands are all consistent - require a "::" if any pvname contains a ":" in any of the commands.

#6 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 34 lines · Dave Wysochanski
Quoted 25 lines · Dave Wysochanski
Quoted 7 lines · Peter Rajnoha
Quoted 5 lines · Dave Wysochanski

I know, it does not make sense to specify a pe range
for pvcreate or vgcreate. But shouldn't we be consistent, or at least very much clarify the arguments are different? I can just imagine someone scripting something and then being surprised when they needed to quote only for lvcreate, pvmove, etc.

Quoted 6 lines

Hmm, then the question is, what should we do with single unescaped ':' if it appears in pvcreate, vgcreate, e.g. "pvcreate /dev/a::b:c" -- the first double one is OK, but what about the second single one? Should it be considered as an input error then? (...probably giving the user a message like "PE range definition not allowed here.")

At this point I'd lean towards just clarifing the difference in the arguments for the commands (e.g. in man pages, etc). See attached patch for a stab at updating the man pages. If we go this route, then your patch is fine as is IMO.

Also, on IRC yesterday, Alasdair suggested a new built-in command to
escape names such as this
17:01:40 < deepthot> agk_: on the escaping, you mean someone would do something like: lvcreate -L 16M -n lvname vgname lvmescape /dev/pname?
17:05:07 < agk_> almost: lvmescape /dev/path then they can append :4-10 on it

Quoted 7 lines

IMO, this is a good idea. However, in the spirit of not getting too sidetracked, I think if we add proper explanation, we can probably defer adding the built-in command, which probably requires some design thought (for example, how to specify whether it is a pvname, vgname, etc - they may have different characters to escape, etc). If you want to tackle that too though, go for it.

Quoted 5 lines

Upon further thought, I agree with you Peter - let's reject the ":" in pvcreate/vgcreate commands and print a message about pe range not allowed in these commands. This way the commands are all consistent - require a "::" if any pvname contains a ":" in any of the commands.

Updated man page patch is attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Update-man-pages-to-clarify-usage-of-PE-ranges-and.patch
Type: text/x-patch
Size: 5575 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20090515/284e1366/attachment.bin>

#7 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 8 lines · Dave Wysochanski
Quoted 5 lines

Upon further thought, I agree with you Peter - let's reject the ":" in pvcreate/vgcreate commands and print a message about pe range not allowed in these commands. This way the commands are all consistent - require a "::" if any pvname contains a ":" in any of the commands.

Updated man page patch is attached.

OK, thanks. I'll move the code to a separate function then and I'll add checks for pvcreate/vgcreate, too.

Peter

#8 lore raw

PATCH 1/1 Add escape sequence for ':' in command's PV list

Quoted 2 lines · Peter Rajnoha

OK, thanks. I'll move the code to a separate function then and I'll add checks for pvcreate/vgcreate, too.

Main thing I'm bothered about here is applying a simple policy across the board. Having different policies in different places is a recipe for confusion.

[Note that doubling the hyphens in device names does not set a precedent as that is meant to be an internal tool matter, not exposed to the user who uses /dev/vgname/lvname.]

How many more things need escaping?

Is the policy "any character that needs escaping will be doubled"?

Or do we go for "any character that needs escaping will be preceded by a backslash"?
(See config strings - does this work with config settings on cmdline too?)

Alasdair