Richard W.M. Jones
2014-Dec-04 22:07 UTC
[Libguestfs] [PATCH v3 0/2] v2v: When picking a default kernel, favour non-debug
Since v2: - Use string_suffix kernel_name "-debug" || string_suffix kernel_name "-dbg" - This requires addition of the string_suffix function and some tests
Richard W.M. Jones
2014-Dec-04 22:07 UTC
[Libguestfs] [PATCH v3 1/2] mllib: Add Common_utils.string_suffix function and extend test coverage.
--- mllib/common_utils.ml | 5 +++++ mllib/common_utils.mli | 1 + mllib/common_utils_tests.ml | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 89d8412..b143710 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -98,6 +98,11 @@ let string_prefix str prefix let n = String.length prefix in String.length str >= n && String.sub str 0 n = prefix +let string_suffix str suffix + let sufflen = String.length suffix + and len = String.length str in + len >= sufflen && String.sub str (len - sufflen) sufflen = suffix + let rec string_find s sub let len = String.length s in let sublen = String.length sub in diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index bcdeecf..2103ff1 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -39,6 +39,7 @@ val output_spaces : out_channel -> int -> unit (** Write [n] spaces to [out_channel]. *) val string_prefix : string -> string -> bool +val string_suffix : string -> string -> bool val string_find : string -> string -> int val replace_str : string -> string -> string -> string val string_nsplit : string -> string -> string list diff --git a/mllib/common_utils_tests.ml b/mllib/common_utils_tests.ml index e06b3a4..e12297a 100644 --- a/mllib/common_utils_tests.ml +++ b/mllib/common_utils_tests.ml @@ -78,3 +78,24 @@ let () assert (human_size (-1363149_L) = "-1.3M"); assert (human_size 3650722201_L = "3.4G"); assert (human_size (-3650722201_L) = "-3.4G") + +(* Test Common_utils.string_prefix, string_suffix, string_find. *) +let () + assert (string_prefix "" ""); + assert (string_prefix "foo" ""); + assert (string_prefix "foo" "foo"); + assert (string_prefix "foo123" "foo"); + assert (not (string_prefix "" "foo")); + + assert (string_suffix "" ""); + assert (string_suffix "foo" ""); + assert (string_suffix "foo" "foo"); + assert (string_suffix "123foo" "foo"); + assert (not (string_suffix "" "foo")); + + assert (string_find "" "" = 0); + assert (string_find "foo" "" = 0); + assert (string_find "foo" "o" = 1); + assert (string_find "foobar" "bar" = 3); + assert (string_find "" "baz" = -1); + assert (string_find "foobar" "baz" = -1) -- 2.1.0
Richard W.M. Jones
2014-Dec-04 22:07 UTC
[Libguestfs] [PATCH v3 2/2] v2v: When picking a default kernel, favour non-debug kernels over debug kernels (RHBZ#1170073).
--- v2v/convert_linux.ml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml index f670812..c1e5be7 100644 --- a/v2v/convert_linux.ml +++ b/v2v/convert_linux.ml @@ -49,13 +49,14 @@ type kernel_info = { ki_modules : string list; (* The list of module names. *) ki_supports_virtio : bool; (* Kernel has virtio drivers? *) ki_is_xen_kernel : bool; (* Is a Xen paravirt kernel? *) + ki_is_debug : bool; (* Is debug kernel? *) } let string_of_kernel_info ki - sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b)" + sprintf "(%s, %s, %s, %s, %s, virtio=%b, xen=%b, debug=%b)" ki.ki_name ki.ki_version ki.ki_arch ki.ki_vmlinuz (match ki.ki_initrd with None -> "None" | Some f -> f) - ki.ki_supports_virtio ki.ki_is_xen_kernel + ki.ki_supports_virtio ki.ki_is_xen_kernel ki.ki_is_debug (* The conversion function. *) let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source @@ -241,6 +242,13 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source let supports_virtio = List.mem "virtio_net" modules in let is_xen_kernel = List.mem "xennet" modules in + (* If the package name is like "kernel-debug", then it's + * a debug kernel. + *) + let is_debug + string_suffix app.G.app2_name "-debug" || + string_suffix app.G.app2_name "-dbg" in + Some { ki_app = app; ki_name = name; @@ -253,6 +261,7 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source ki_modules = modules; ki_supports_virtio = supports_virtio; ki_is_xen_kernel = is_xen_kernel; + ki_is_debug = is_debug; } ) @@ -745,7 +754,12 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source let compare_best_kernels k1 k2 let i = compare k1.ki_supports_virtio k2.ki_supports_virtio in if i <> 0 then i - else compare_app2_versions k1.ki_app k2.ki_app + else ( + let i = compare_app2_versions k1.ki_app k2.ki_app in + if i <> 0 then i + (* Favour non-debug kernels over debug kernels (RHBZ#1170073). *) + else compare k2.ki_is_debug k1.ki_is_debug + ) in let kernels = grub_kernels in let kernels = List.filter (fun { ki_is_xen_kernel = is_xen_kernel } -> not is_xen_kernel) kernels in -- 2.1.0
Reasonably Related Threads
- [PATCH v2] v2v: When picking a default kernel, favour non-debug kernels over debug kernels (RHBZ#1170073).
- [PATCH] v2v: linux: Move kernel detection to a separate module.
- [PATCH v2 0/8] v2v: Add drivers for virtio-rng, balloon, pvpanic.
- [PATCH 0/6] v2v: Add drivers for virtio-rng, balloon, pvpanic.
- [PATCH] v2v: When picking a default kernel, favour non-debug kernels over debug kernels (RHBZ#1170073).