Re: [Libguestfs] [PATCH v2v] convert: Allow preferred block driver to be specified on the command line

2023-03-06 Thread Laszlo Ersek
On 3/6/23 17:52, Richard W.M. Jones wrote:

> diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
> index 9d8d271d05..f36b486359 100644
> --- a/convert/convert_windows.ml
> +++ b/convert/convert_windows.ml
> @@ -38,7 +38,7 @@ module G = Guestfs
>   * time the Windows VM is booted on KVM.
>   *)
>  
> -let convert (g : G.guestfs) _ inspect i_firmware _ static_ips =
> +let convert (g : G.guestfs) _ inspect i_firmware block_driver _ static_ips =
>(*--*)
>(* Inspect the Windows guest. *)
>  
> @@ -47,6 +47,16 @@ let convert (g : G.guestfs) _ inspect i_firmware _ 
> static_ips =
> *)
>let virtio_win =
>  Inject_virtio_win.from_environment g inspect.i_root Config.datadir in
> +  (match block_driver with
> +   | Virtio_blk -> () (* the default, no need to do anything *)
> +(*
> +   | Virtio_scsi ->
> +  let drivers = Inject_virtio_win.get_block_driver_priority virtio_win in
> +  let drivers = "vioscsi" :: drivers in
> +  Inject_virtio_win.set_block_driver_priority virtio_win drivers
> +*)
> +   | IDE -> assert false (* not possible - but maybe ...? *)
> +  );
>  
>(* If the Windows guest appears to be using group policy.
> *

So ["virtio_blk"; "vrtioblk"; "viostor"] in
"common/mlcustomize/inject_virtio_win.ml" would be replaced with a
reference cell, and get_block_driver_priority /
set_block_driver_priority would manipulate that.

This looks OK to me.

That said, I'd prefer that this patch be split up a bit (by Andrey).
Patch#1 could introduce the new field and make sure it is passed around
(incl. setting the default virtio-blk value); that's purely boilerplate,
so the patch would be well-focused. Patch #2 could glue the new field to
the new Inject_virtio_win APIs, in "convert_windows.ml". Patch#3 could
implement the command line changes and update the documentation.

Laszlo
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



[Libguestfs] [PATCH v2v] convert: Allow preferred block driver to be specified on the command line

2023-03-06 Thread Richard W.M. Jones
---
 docs/virt-v2v.pod   | 10 ++
 convert/convert.mli |  1 +
 convert/convert_linux.mli   |  3 ++-
 convert/convert_windows.mli |  3 ++-
 convert/convert.ml  |  9 ++---
 convert/convert_linux.ml|  2 +-
 convert/convert_windows.ml  | 12 +++-
 in-place/in_place.ml|  3 ++-
 inspector/inspector.ml  |  3 ++-
 v2v/v2v.ml  | 12 +++-
 10 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/docs/virt-v2v.pod b/docs/virt-v2v.pod
index b458607d14..e096418b2c 100644
--- a/docs/virt-v2v.pod
+++ b/docs/virt-v2v.pod
@@ -207,6 +207,16 @@ The options are silently ignored for other input methods.
 
 See I<--network> below.
 
+=item B<--block-driver virtio-blk>
+
+=item B<--block-driver virtio-scsi>
+
+When choosing a block driver for Windows guests, prefer C or
+C.  The default is C.
+
+Note this has no effect for Linux guests at the moment.  That may be
+added in future.
+
 =item B<--colors>
 
 =item B<--colours>
diff --git a/convert/convert.mli b/convert/convert.mli
index 3bd39e2da8..c63bf6f0da 100644
--- a/convert/convert.mli
+++ b/convert/convert.mli
@@ -17,6 +17,7 @@
  *)
 
 type options = {
+  block_driver : Types.guestcaps_block_type; (** [--block-driver] option *)
   keep_serial_console : bool;
   ks : Tools_utils.key_store;  (** [--key] option *)
   network_map : Networks.t;(** [-b] and [-n] options *)
diff --git a/convert/convert_linux.mli b/convert/convert_linux.mli
index 6eb272e9b4..dc6968fe51 100644
--- a/convert/convert_linux.mli
+++ b/convert/convert_linux.mli
@@ -23,5 +23,6 @@
 Mint and Kali are supported by this module. *)
 
 val convert : Guestfs.guestfs -> Types.source -> Types.inspect ->
-  Firmware.i_firmware -> bool -> Types.static_ip list ->
+  Firmware.i_firmware -> Types.guestcaps_block_type ->
+  bool -> Types.static_ip list ->
   Types.guestcaps
diff --git a/convert/convert_windows.mli b/convert/convert_windows.mli
index 42dac9f50c..33a14f6596 100644
--- a/convert/convert_windows.mli
+++ b/convert/convert_windows.mli
@@ -21,5 +21,6 @@
 This module converts a Windows guest to run on KVM. *)
 
 val convert : Guestfs.guestfs -> Types.source -> Types.inspect ->
-  Firmware.i_firmware -> bool -> Types.static_ip list ->
+  Firmware.i_firmware -> Types.guestcaps_block_type ->
+  bool -> Types.static_ip list ->
   Types.guestcaps
diff --git a/convert/convert.ml b/convert/convert.ml
index 0aa0e5cd3c..fa34d2ed7f 100644
--- a/convert/convert.ml
+++ b/convert/convert.ml
@@ -31,6 +31,7 @@ open Utils
 module G = Guestfs
 
 type options = {
+  block_driver : guestcaps_block_type;
   keep_serial_console : bool;
   ks : key_store;
   network_map : Networks.t;
@@ -88,7 +89,7 @@ let rec convert dir options source =
   (* Conversion. *)
   let guestcaps =
 do_convert g source inspect i_firmware
-  options.keep_serial_console options.static_ips in
+  options.block_driver options.keep_serial_console options.static_ips in
 
   g#umount_all ();
 
@@ -221,7 +222,8 @@ and do_fstrim g inspect =
   ) fses
 
 (* Conversion. *)
-and do_convert g source inspect i_firmware keep_serial_console interfaces =
+and do_convert g source inspect i_firmware
+   block_driver keep_serial_console interfaces =
   (match inspect.i_product_name with
   | "unknown" ->
 message (f_"Converting the guest to run on KVM")
@@ -246,7 +248,8 @@ and do_convert g source inspect i_firmware 
keep_serial_console interfaces =
  inspect.i_type inspect.i_distro in
   debug "picked conversion module %s" conversion_name;
   let guestcaps =
-convert g source inspect i_firmware keep_serial_console interfaces in
+convert g source inspect i_firmware
+block_driver keep_serial_console interfaces in
   debug "%s" (string_of_guestcaps guestcaps);
 
   (* Did we manage to install virtio drivers? *)
diff --git a/convert/convert_linux.ml b/convert/convert_linux.ml
index d5c0f24dbb..0f25af0eab 100644
--- a/convert/convert_linux.ml
+++ b/convert/convert_linux.ml
@@ -34,7 +34,7 @@ open Linux_kernels
 module G = Guestfs
 
 (* The conversion function. *)
-let convert (g : G.guestfs) source inspect i_firmware keep_serial_console _ =
+let convert (g : G.guestfs) source inspect i_firmware _ keep_serial_console _ =
   (*--*)
   (* Inspect the guest first.  We already did some basic inspection in
* the common v2v.ml code, but that has to deal with generic guests
diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml
index 9d8d271d05..f36b486359 100644
--- a/convert/convert_windows.ml
+++ b/convert/convert_windows.ml
@@ -38,7 +38,7 @@ module G = Guestfs
  * time the Windows VM is booted on KVM.
  *)
 
-let convert (g : G.guestfs) _ inspect i_firmware _ static_ips =
+let convert (g : G.guestfs) _ inspect i_firmware block_driver _ 

[Libguestfs] [PATCH v2v] convert: Allow preferred block driver to be specified on the command line

2023-03-06 Thread Richard W.M. Jones
This is just an outline patch, only compile tested.

It doesn't make changes to virt-v2v-in-place, but those would be the
same as made in v2v/v2v.ml.

It reuses the existing Types.guestcaps_block_type which is a bit ugly
but fairly practical.

I've made the change to the documentation, but it needs a test.

Rich.


___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



[Libguestfs] [PATCH common] mlcustomize: Add accessors for block driver priority list

2023-03-06 Thread Richard W.M. Jones
When injecting virtio-win drivers, allow the list of block drivers
that we search to be modified.
---
 mlcustomize/inject_virtio_win.ml  | 12 +---
 mlcustomize/inject_virtio_win.mli | 10 ++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/mlcustomize/inject_virtio_win.ml b/mlcustomize/inject_virtio_win.ml
index 4e977b3..2a7c742 100644
--- a/mlcustomize/inject_virtio_win.ml
+++ b/mlcustomize/inject_virtio_win.ml
@@ -49,6 +49,9 @@ type t = {
   of libosinfo.  Although this behaviour is documented, IMHO it has
   always been a bad idea.  We should change this in future to allow
   the user to select where they want to get drivers from. XXX *)
+
+  mutable block_driver_priority : string list
+  (** List of block drivers *)
 }
 
 type block_type = Virtio_blk | IDE
@@ -107,7 +110,11 @@ and get_inspection g root =
   { g; root;
 i_arch; i_major_version; i_minor_version; i_osinfo;
 i_product_variant; i_windows_current_control_set; i_windows_systemroot;
-virtio_win = ""; was_set = false }
+virtio_win = ""; was_set = false;
+block_driver_priority = ["virtio_blk"; "vrtioblk"; "viostor"] }
+
+let get_block_driver_priority t   = t.block_driver_priority
+let set_block_driver_priority t v = t.block_driver_priority <- v
 
 let scsi_class_guid = "{4D36E97B-E325-11CE-BFC1-08002BE10318}"
 let viostor_legacy_pciid = "VEN_1AF4_1001_00021AF4_00"
@@ -176,14 +183,13 @@ let rec inject_virtio_win_drivers ({ g } as t) reg =
   else (
 (* Can we install the block driver? *)
 let block : block_type =
-  let filenames = ["virtio_blk"; "vrtioblk"; "viostor"] in
   let viostor_driver = try (
 Some (
   List.find (
 fun driver_file ->
   let source = driverdir // driver_file ^ ".sys" in
   g#exists source
-  ) filenames
+  ) t.block_driver_priority
 )
   ) with Not_found -> None in
   match viostor_driver with
diff --git a/mlcustomize/inject_virtio_win.mli 
b/mlcustomize/inject_virtio_win.mli
index 0ced02e..7bd9b9f 100644
--- a/mlcustomize/inject_virtio_win.mli
+++ b/mlcustomize/inject_virtio_win.mli
@@ -64,6 +64,16 @@ val from_environment : Guestfs.guestfs -> string -> string 
-> t
 
 This should only be used by [virt-v2v] and is considered a legacy method. 
*)
 
+val get_block_driver_priority : t -> string list
+val set_block_driver_priority : t -> string list -> unit
+(** Get or set the current block driver priority list.  This is
+a list of virtio-win block driver names (eg. ["viostor"]) that
+we search until we come to the first [name ^ ".sys"] that
+we find, and that is the block driver which gets installed.
+
+This module contains a default priority list which should
+be suitable for most use cases. *)
+
 val inject_virtio_win_drivers : t -> Registry.t -> virtio_win_installed
 (** [inject_virtio_win_drivers t reg]
 installs virtio drivers from the driver directory or driver
-- 
2.39.2

___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs



Re: [Libguestfs] [PATCH] docs: Prefer 'cookie' over 'handle'

2023-03-06 Thread Eric Blake
On Sun, Mar 05, 2023 at 10:53:38AM +0200, Wouter Verhelst wrote:
> On Sat, Mar 04, 2023 at 10:03:46PM +0200, Nir Soffer wrote:
> > On Sat, Mar 4, 2023 at 12:15 AM Eric Blake  wrote:
> > > Makes no difference to implementations (other than older code
> > > still using 'handle' may be slightly harder to tie back to the spec).
> > 
> > To avoid confusion with older code that carefully used "handle" to match
> > the spec, maybe add a note that "cookie" was named "handle" before?
> 
> Yes, this. I'm happy with renaming it cookie (it makes sense), but there
> is a *lot* of stuff out there that calls it "handle" (including a
> wireshark plugin) and it would be confusing if that link isn't available
> anywhere.

Sure.  v2 will include patches to nbd code as well.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs


Re: [Libguestfs] [PATCH v2 1/6] spec: Recommend cap on NBD_REPLY_TYPE_BLOCK_STATUS length

2023-03-06 Thread Nir Soffer
On Sun, Mar 5, 2023 at 10:42 AM Wouter Verhelst  wrote:
>
> On Fri, Mar 03, 2023 at 04:17:40PM -0600, Eric Blake wrote:
> > On Fri, Dec 16, 2022 at 10:32:01PM +0300, Vladimir Sementsov-Ogievskiy 
> > wrote:
> > > s-o-b line missed.
> >
> > I'm not sure if the NBD project has a strict policy on including one,
> > but I don't mind adding it.
>
> I've never required it, mostly because it's something that I myself
> always forget, too, so, *shrug*.
>
> (if there were a way in git to make it add that automatically, that
> would help; I've looked but haven't found it)

What I'm using in all projects that require signed-off-by is:

$ cat .git/hooks/commit-msg
#!/bin/sh

# Add Signed-off-by trailer.
sob=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
git interpret-trailers --in-place --trailer "$sob" "$1"

You can also use a pre-commit hook but the commit-msg hook is more
convenient.

And in github you can add the DCO application to the project:
https://github.com/apps/dco

Once installed it will check that all commits are signed off, and
provide helpful error
messages to contributors.

Nir

___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs


Re: [Libguestfs] [PATCH v2 1/6] spec: Recommend cap on NBD_REPLY_TYPE_BLOCK_STATUS length

2023-03-06 Thread Laszlo Ersek
On 3/5/23 09:41, Wouter Verhelst wrote:
> On Fri, Mar 03, 2023 at 04:17:40PM -0600, Eric Blake wrote:
>> On Fri, Dec 16, 2022 at 10:32:01PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>>> s-o-b line missed.
>>
>> I'm not sure if the NBD project has a strict policy on including one,
>> but I don't mind adding it.
> 
> I've never required it, mostly because it's something that I myself
> always forget, too, so, *shrug*.
> 
> (if there were a way in git to make it add that automatically, that
> would help; I've looked but haven't found it)
> 

You can point the "commit.template" git-config knob to a particular
file, and then include your S-o-b in that file.

There is also the "-s" ("--signoff") option for git-commit, but I don't
see a git-config knob to make that permanent. (You can always introduce
a git.alias for it though.)

Laszlo
___
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs