From ea9feae9d8793e417c393d6c61b558bb8764698d Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 12 Jun 2018 10:22:02 +0100
Subject: [PATCH] p2v: Allow virt-v2v input and output drivers containing '-'
(RHBZ#1590220).
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The new ‘-o rhv-upload’ output mode contains a '-' character in the
name, but the regular expression which matched the output of the
virt-v2v command did not recognize '-' as a valid character. It ended
up mapping this to just "rhv" meaning two "rhv" entries would appear
in the list of output drivers.
Thanks: Ming Xie.
(cherry picked from commit 3886a113f231f7b38a89333491888c4d9a0c19da)
---
p2v/ssh.c | 7 +++++--
v2v/modules_list.ml | 11 +++++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/p2v/ssh.c b/p2v/ssh.c
index d2699fffd..15f53b692 100644
--- a/p2v/ssh.c
+++ b/p2v/ssh.c
@@ -181,8 +181,11 @@ compile_regexps (void)
0);
COMPILE (feature_libguestfs_rewrite_re, "libguestfs-rewrite", 0);
COMPILE (feature_colours_option_re, "colours-option", 0);
- COMPILE (feature_input_re, "input:((?:\\w)*)", 0);
- COMPILE (feature_output_re, "output:((?:\\w)*)", 0);
+ /* The input and output regexps must match the same pattern in
+ * v2v/modules_list.ml.
+ */
+ COMPILE (feature_input_re, "input:((?:[-\\w])+)", 0);
+ COMPILE (feature_output_re, "output:((?:[-\\w])+)", 0);
COMPILE (portfwd_re, "Allocated port ((?:\\d)+) for remote forward", 0);
}
diff --git a/v2v/modules_list.ml b/v2v/modules_list.ml
index 91b029b07..b7accc4f9 100644
--- a/v2v/modules_list.ml
+++ b/v2v/modules_list.ml
@@ -21,8 +21,15 @@ open Std_utils
let input_modules = ref []
and output_modules = ref []
-let register_input_module name = List.push_front name input_modules
-and register_output_module name = List.push_front name output_modules
+(* Must match the regular expressions in p2v/ssh.c *)
+let module_name_re = PCRE.compile ~anchored:true "[-\\w]+"
+
+let register_input_module name =
+ assert (PCRE.matches module_name_re name);
+ List.push_front name input_modules
+and register_output_module name =
+ assert (PCRE.matches module_name_re name);
+ List.push_front name output_modules
let input_modules () = List.sort compare !input_modules
and output_modules () = List.sort compare !output_modules
--
2.17.1