Pino Toscano
2016-Nov-21 13:39 UTC
[Libguestfs] [PATCH 1/2] kernel: refactor build_kernel & find_kernel
Move the handling of the SUPERMIN_* envvars, and the kernel copy/symlink
out of find_kernel to build_kernel: this way find_kernel does only the
search. Also, the modules path search is done in by find_kernel as
well.
This is mostly code motion, with no behaviour changes.
---
src/kernel.ml | 89 +++++++++++++++++++++++++++++------------------------------
1 file changed, 44 insertions(+), 45 deletions(-)
diff --git a/src/kernel.ml b/src/kernel.ml
index 9b0e8a2..2e061d8 100644
--- a/src/kernel.ml
+++ b/src/kernel.ml
@@ -40,28 +40,7 @@ let patt_of_cpu host_cpu
let rec build_kernel debug host_cpu dtb_wildcard copy_kernel kernel dtb (*
Locate the kernel. *)
- let kernel_name, kernel_version - find_kernel debug host_cpu copy_kernel
kernel in
-
- (* If the user passed --dtb option, locate dtb. *)
- (match dtb_wildcard with
- | None -> ()
- | Some wildcard ->
- find_dtb debug copy_kernel kernel_name wildcard dtb
- );
-
- (* Get the kernel modules. *)
- let modpath = find_modpath debug kernel_version in
-
- if debug >= 1 then (
- printf "supermin: kernel: kernel_version %s\n" kernel_version;
- printf "supermin: kernel: modules %s\n%!" modpath;
- );
-
- (kernel_version, modpath)
-
-and find_kernel debug host_cpu copy_kernel kernel - let kernel_file,
kernel_name, kernel_version + let kernel_file, kernel_name, kernel_version,
modpath try
let kernel_env = getenv "SUPERMIN_KERNEL" in
if debug >= 1 then
@@ -78,38 +57,58 @@ and find_kernel debug host_cpu copy_kernel kernel
printf "supermin: kernel: SUPERMIN_KERNEL version %s\n%!"
kernel_version;
let kernel_name = Filename.basename kernel_env in
- kernel_env, kernel_name, kernel_version
+ let modpath = find_modpath debug kernel_version in
+ kernel_env, kernel_name, kernel_version, modpath
with Not_found ->
- let is_arm - String.length host_cpu >= 3 &&
- host_cpu.[0] = 'a' && host_cpu.[1] = 'r'
&& host_cpu.[2] = 'm' in
+ find_kernel debug host_cpu kernel in
- let all_files = Sys.readdir "/boot" in
- let all_files = Array.to_list all_files in
+ (* If the user passed --dtb option, locate dtb. *)
+ (match dtb_wildcard with
+ | None -> ()
+ | Some wildcard ->
+ find_dtb debug copy_kernel kernel_name wildcard dtb
+ );
- (* In original: ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v
xen *)
- let patterns = patt_of_cpu host_cpu in
- let files = kernel_filter patterns is_arm all_files in
+ if debug >= 1 then (
+ printf "supermin: kernel: kernel_version %s\n" kernel_version;
+ printf "supermin: kernel: modules %s\n%!" modpath;
+ );
- let files - if files <> [] then files
- else
- (* In original: ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen
*)
- kernel_filter ["vmlinu?-*"] is_arm all_files in
+ copy_or_symlink_file copy_kernel kernel_file kernel;
- if files = [] then no_kernels host_cpu;
+ (kernel_version, modpath)
- let files = List.sort (fun a b -> compare_version b a) files in
- let kernel_name = List.hd files in
- let kernel_version = get_kernel_version kernel_name in
+and find_kernel debug host_cpu kernel + let is_arm + String.length host_cpu
>= 3 &&
+ host_cpu.[0] = 'a' && host_cpu.[1] = 'r' &&
host_cpu.[2] = 'm' in
- if debug >= 1 then
- printf "supermin: kernel: picked kernel %s\n%!" kernel_name;
+ let all_files = Sys.readdir "/boot" in
+ let all_files = Array.to_list all_files in
- ("/boot" // kernel_name), kernel_name, kernel_version in
+ (* In original: ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen
*)
+ let patterns = patt_of_cpu host_cpu in
+ let files = kernel_filter patterns is_arm all_files in
- copy_or_symlink_file copy_kernel kernel_file kernel;
- kernel_name, kernel_version
+ let files + if files <> [] then files
+ else
+ (* In original: ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen *)
+ kernel_filter ["vmlinu?-*"] is_arm all_files in
+
+ if files = [] then no_kernels host_cpu;
+
+ let files = List.sort (fun a b -> compare_version b a) files in
+ let kernel_name = List.hd files in
+ let kernel_version = get_kernel_version kernel_name in
+
+ if debug >= 1 then
+ printf "supermin: kernel: picked kernel %s\n%!" kernel_name;
+
+ (* Get the kernel modules. *)
+ let modpath = find_modpath debug kernel_version in
+
+ ("/boot" // kernel_name), kernel_name, kernel_version, modpath
and kernel_filter patterns is_arm all_files let files --
2.7.4
Pino Toscano
2016-Nov-21 13:39 UTC
[Libguestfs] [PATCH 2/2] kernel: find vmlinuz kernels in modules path (RHBZ#1394699)
Newer kernel packages e.g. in Fedora place the kernel image named
"vmlinuz" directly within the modules path of that kernel.
Find these images first, not looking for kernels in /boot if any is
found under modules paths.
---
src/kernel.ml | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/kernel.ml b/src/kernel.ml
index 2e061d8..b4e89da 100644
--- a/src/kernel.ml
+++ b/src/kernel.ml
@@ -22,6 +22,7 @@ open Printf
open Utils
open Ext2fs
open Fnmatch
+open Glob
let patt_of_cpu host_cpu let models @@ -60,7 +61,28 @@ let rec build_kernel
debug host_cpu dtb_wildcard copy_kernel kernel dtb let modpath =
find_modpath debug kernel_version in
kernel_env, kernel_name, kernel_version, modpath
with Not_found ->
- find_kernel debug host_cpu kernel in
+ let kernels + let files = glob "/lib/modules/*/vmlinuz"
[GLOB_NOSORT; GLOB_NOESCAPE] in
+ let files = Array.to_list files in
+ let kernels + List.map (
+ fun f ->
+ let modpath = Filename.dirname f in
+ f, Filename.basename f, Filename.basename modpath, modpath
+ ) files in
+ List.sort (
+ fun (_, _, a, _) (_, _, b, _) -> compare_version b a
+ ) kernels in
+
+ if kernels <> [] then (
+ let kernel = List.hd kernels in
+ if debug >= 1 then (
+ let kernel_file, _, _, _ = kernel in
+ printf "supermin: kernel: picked vmlinuz %s\n%!"
kernel_file;
+ );
+ kernel
+ ) else
+ find_kernel debug host_cpu kernel in
(* If the user passed --dtb option, locate dtb. *)
(match dtb_wildcard with
--
2.7.4
Richard W.M. Jones
2016-Dec-07 11:53 UTC
Re: [Libguestfs] [PATCH 2/2] kernel: find vmlinuz kernels in modules path (RHBZ#1394699)
The changes seem OK, so ACK. This code gives me a headache ... We don't have any module interface kernel.mli defined, and it passes around tuples instead of well-defined structs. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Possibly Parallel Threads
- [supermin] Be smarter about finding suitable kernel images
- Re: libguestfs supermin error
- Re: [supermin] Be smarter about finding suitable kernel images
- [PATCH 2/2] kernel: find vmlinuz kernels in modules path (RHBZ#1394699)
- [PATCH supermin 0/9] kernel: Multiple fixes to handling of kernels (RHBZ#1477758).