[Libguestfs] [PATCH 11/11] v2v: improve initrd search

Richard W.M. Jones rjones at redhat.com
Thu May 12 14:09:29 UTC 2016


On Thu, May 12, 2016 at 03:29:19PM +0200, Cédric Bosdonnat wrote:
> To make sure we can also find the initrd on openSUSE and SLES, we need two improvements:
>  * the initrd filename may not end with '.img'
>  * don't use the version + release from the RPM data, rather from the
>    /lib/modules/<version>/ path as we need to find it out anyway.
> ---
>  v2v/convert_linux.ml | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
> index e5778ef..4d3e628 100644
> --- a/v2v/convert_linux.ml
> +++ b/v2v/convert_linux.ml
> @@ -125,7 +125,7 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
>    let installed_kernels : kernel_info list =
>      let rex_ko = Str.regexp ".*\\.k?o\\(\\.xz\\)?$" in
>      let rex_ko_extract = Str.regexp ".*/\\([^/]+\\)\\.k?o\\(\\.xz\\)?$" in
> -    let rex_initrd = Str.regexp "^initr\\(d\\|amfs\\)-.*\\.img$" in
> +    let rex_initrd = Str.regexp "^initr\\(d\\|amfs\\)-.*\\(\\.img\\)?$" in
>      filter_map (
>        function
>        | { G.app2_name = name } as app
> @@ -157,8 +157,8 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
>                 try g#statns vmlinuz with G.Error _ -> raise Not_found in
>  
>               (* Get/construct the version.  XXX Read this from kernel file. *)
> -             let version =
> -               sprintf "%s-%s" app.G.app2_version app.G.app2_release in
> +             let prefix_len = String.length "/lib/modules/" in
> +             let version = String.sub modpath prefix_len ((String.length modpath) - prefix_len) in

Too many parentheses here.  Function application always has the
highest precedence in functional languages.

Also you can nest variables to make them private.

Thus this becomes:

  let version =
    let prefix_len = String.length "/lib/modules/" in
    String.sub modpath prefix_len (String.length modpath - prefix_len) in

- - -

The patches that I _didn't_ comment on all look OK to me.

I'd like to see the whole series posted again with everything
fixed though.

Thanks, Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list