All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add escape sequence for ':' in command's PV list
@ 2009-05-13 11:09 Peter Rajnoha
  2009-05-13 19:43 ` Dave Wysochanski
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Rajnoha @ 2009-05-13 11:09 UTC (permalink / raw)
  To: lvm-devel

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


diff --git a/tools/toollib.c b/tools/toollib.c
index aa33468..b5a43b5 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -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)))) {



^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [PATCH] Add escape sequence for ':' in command's PV list
@ 2010-09-15 12:30 Peter Rajnoha
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Rajnoha @ 2010-09-15 12:30 UTC (permalink / raw)
  To: lvm-devel

This is reincarnation of simple, old and forgotten (and not so important) patch
I sent a long long time ago but it faded away somehow. But I'd like to have
this cleaned up finally (..to not make a mess on my desk :)).

At that time, I used doubling of characters to escape the ":". But since
we use "\" everywhere else, let's do it this way. (rhbz #491409)

(I remember there was a discussion about adding some form of generic
mechanism for escaping characters by means of adding a new command to
do that. Do we still want that? Is that really necessary?)

Peter
---
 lib/misc/lvm-string.c |   20 ++++++++++++++++++--
 lib/misc/lvm-string.h |    6 ++++++
 tools/toollib.c       |   15 +++++++--------
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c
index 7eed799..6c1c1a5 100644
--- a/lib/misc/lvm-string.c
+++ b/lib/misc/lvm-string.c
@@ -105,14 +105,19 @@ static void _quote_characters(char **out, const char *src,
  * Also unquote quote_char.
  */
 static void _unquote_characters(char *src, const int orig_char,
-				const int quote_char)
+				const int quote_char,
+				char **substr_first_unquoted)
 {
 	char *out = src;
 
+	*substr_first_unquoted = NULL;
+
 	while (*src) {
 		if (*src == quote_char &&
 		    (*(src + 1) == orig_char || *(src + 1) == quote_char))
 			src++;
+		else if (*src == orig_char)
+			*substr_first_unquoted = out;
 
 		*out++ = *src++;
 	}
@@ -209,7 +214,18 @@ char *escape_double_quotes(char *out, const char *src)
  */
 void unescape_double_quotes(char *src)
 {
-	_unquote_characters(src, '\"', '\\');
+	char *s;
+
+	_unquote_characters(src, '\"', '\\', &s);
+}
+
+/*
+ * Unescape colons in situ and save the substring starting
+ * at the position of the first unescaped colon.
+ */
+void unescape_colons(char *src, char **substr_first_unquoted)
+{
+	_unquote_characters(src, ':', '\\', substr_first_unquoted);
 }
 
 /*
diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h
index 35d9245..f649fdc 100644
--- a/lib/misc/lvm-string.h
+++ b/lib/misc/lvm-string.h
@@ -60,4 +60,10 @@ char *escape_double_quotes(char *out, const char *src);
  */
 void unescape_double_quotes(char *src);
 
+/*
+ * Unescape colons in situ and save the substring starting
+ * at the position of the first unescaped colon.
+ */
+void unescape_colons(char *src, char **substr_first_unquoted);
+
 #endif
diff --git a/tools/toollib.c b/tools/toollib.c
index 5da30f4..104f33c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1093,7 +1093,7 @@ 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;
 	int i;
 
@@ -1128,13 +1128,12 @@ struct dm_list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int
 
 		pvname = argv[i];
 
-		if ((colon = strchr(pvname, ':'))) {
-			if (!(pvname = dm_pool_strndup(mem, pvname,
-						    (unsigned) (colon -
-								pvname)))) {
-				log_error("Failed to clone PV name");
-				return NULL;
-			}
+		unescape_colons(pvname, &colon);
+
+		if (colon && !(pvname = dm_pool_strndup(mem, pvname,
+					(unsigned) (colon - pvname)))) {
+			log_error("Failed to clone PV name");
+			return NULL;
 		}
 
 		if (!(pvl = find_pv_in_vg(vg, pvname))) {



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-09-15 12:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-13 11:09 [PATCH] Add escape sequence for ':' in command's PV list Peter Rajnoha
2009-05-13 19:43 ` Dave Wysochanski
2009-05-13 19:55   ` Milan Broz
2009-05-14  9:33   ` Peter Rajnoha
2009-05-14 19:25     ` Dave Wysochanski
2009-05-15 12:07       ` Dave Wysochanski
2009-05-15 12:27         ` Dave Wysochanski
2009-05-15 17:57           ` Peter Rajnoha
2009-05-15 18:13             ` Alasdair G Kergon
  -- strict thread matches above, loose matches on Subject: below --
2010-09-15 12:30 Peter Rajnoha

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.