[Libguestfs] [PATCH v2v 2/3] output: Use Utils.with_nbd_connect_unix when getting size of disks

Laszlo Ersek lersek at redhat.com
Wed Jan 12 11:55:30 UTC 2022


On 01/11/22 13:49, Richard W.M. Jones wrote:
> Instead of calling NBD.connect directly, use our helper function
> Utils.with_nbd_connect_unix.  This changes the semantics slightly
> since errors in shutdown/close will no longer be ignored, but I would
> argue that we want to see those errors since they would indicate
> something going wrong in the NBD server that we'd probably want to
> know about.
> ---
>  output/output.ml | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/output/output.ml b/output/output.ml
> index 2e51743ba2..943c9e8b32 100644
> --- a/output/output.ml
> +++ b/output/output.ml
> @@ -58,13 +58,7 @@ let get_disks dir =
>    let rec loop acc i =
>      let socket = sprintf "%s/in%d" dir i in
>      if Sys.file_exists socket then (
> -      let nbd = NBD.create () in
> -      NBD.connect_unix nbd socket;
> -      let size = NBD.get_size nbd in
> -      (try
> -         NBD.shutdown nbd;
> -         NBD.close nbd
> -       with NBD.Error _ -> ());
> +      let size : int64 = Utils.with_nbd_connect_unix ~socket NBD.get_size in
>        loop ((i, size) :: acc) (i+1)
>      )
>      else
> 

Haha, IIRC I was ever so slightly tempted to do this myself when
introducing "with_nbd_connect_unix" -- but every piece of code I
refactor could turn into a regression I'm responsible for... ;)
Especially noting the change in exception visibility!

Reviewed-by: Laszlo Ersek <lersek at redhat.com>




More information about the Libguestfs mailing list