[Libguestfs] [PATCH 2/7] v2v: extract controller offset discovery as a function
Richard W.M. Jones
rjones at redhat.com
Tue Apr 5 12:16:47 UTC 2016
On Tue, Apr 05, 2016 at 01:47:28PM +0200, Cédric Bosdonnat wrote:
> This function is needed for other drivers, move the code in order to
> help sharing it later.
Simple refactoring, looks fine.
Rich.
> v2v/windows_virtio.ml | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
> index b0d9d08..14ffc51 100644
> --- a/v2v/windows_virtio.ml
> +++ b/v2v/windows_virtio.ml
> @@ -226,18 +226,7 @@ and add_viostor_to_driver_database g root arch current_cs driverdir =
> *)
> let controller_path =
> [ current_cs; "Control"; "Class"; scsi_adapter_guid ] in
> - let controller_offset =
> - match Windows.get_node g root controller_path with
> - | None ->
> - error (f_"cannot find HKLM\\SYSTEM\\%s in the guest registry")
> - (String.concat "\\" controller_path)
> - | Some node ->
> - let rec loop node i =
> - let controller_offset = sprintf "%04d" i in
> - let child = g#hivex_node_get_child node controller_offset in
> - if child = 0_L then controller_offset else loop node (i+1)
> - in
> - loop node 0 in
> + let controller_offset = get_controller_offset g root controller_path in
>
> let regedits = [
> controller_path @ [ controller_offset ],
> @@ -400,6 +389,19 @@ and set_free_oem_inf g root guid driver_inf driverdir =
> g#cp (driverdir // driver_inf) ("/Windows/Inf/" ^ oem_inf);
> oem_inf
>
> +and get_controller_offset g root controller_path =
> + match Windows.get_node g root controller_path with
> + | None ->
> + error (f_"cannot find HKLM\\SYSTEM\\%s in the guest registry")
> + (String.concat "\\" controller_path)
> + | Some node ->
> + let rec loop node i =
> + let controller_offset = sprintf "%04d" i in
> + let child = g#hivex_node_get_child node controller_offset in
> + if child = 0_L then controller_offset else loop node (i+1)
> + in
> + loop node 0
> +
> (* Copy the matching drivers to the driverdir; return true if any have
> * been copied.
> *)
> --
> 2.6.2
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list