[Libguestfs] [PATCH] p2v: tests: Don't fail when test machine has only a single hard disk.

Pino Toscano ptoscano at redhat.com
Tue Jul 21 10:03:48 UTC 2015


On Tuesday 21 July 2015 10:55:48 Richard W.M. Jones wrote:
> virt-p2v looks in /sys/block to find disks, and ignores the hard disk
> containing the root device.  This is correct when virt-p2v runs off
> the ISO, but when running the tests on a machine that has a single
> hard disk, all_disks would be NULL, resulting in a test failure.
> 
> Fix this by allowing all_disks to be NULL, but adding an extra check
> later so that we don't perform the conversion with no hard disks (the
> gui.c path already has this check, so it is only needed in the
> kernel.c path).
> ---
>  p2v/kernel.c |  9 +++++++++
>  p2v/main.c   | 14 ++++----------
>  2 files changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/p2v/kernel.c b/p2v/kernel.c
> index dce6fbb..b283417 100644
> --- a/p2v/kernel.c
> +++ b/p2v/kernel.c
> @@ -206,6 +206,15 @@ kernel_configuration (struct config *config, char **cmdline, int cmdline_source)
>      exit (EXIT_SUCCESS);
>    }
>  
> +  /* Some disks must have been specified for conversion. */
> +  if (config->disks == NULL || guestfs_int_count_strings (config->disks) == 0) {
> +    fprintf (stderr, "%s: error: no non-removable disks were discovered on this machine.\n",
> +             guestfs_int_program_name);
> +    fprintf (stderr, "virt-p2v looked in /sys/block and in p2v.disks on the kernel command line.\n");
> +    fprintf (stderr, "This is a fatal error and virt-p2v cannot continue.\n");
> +    exit (EXIT_FAILURE);
> +  }
> +
>    /* Perform the conversion in text mode. */
>    if (start_conversion (config, notify_ui_callback) == -1) {
>      const char *err = get_conversion_error ();
> diff --git a/p2v/main.c b/p2v/main.c
> index be32e4b..12ffd01 100644
> --- a/p2v/main.c
> +++ b/p2v/main.c
> @@ -279,7 +279,8 @@ set_config_defaults (struct config *config)
>      config->flags = 0;
>  
>    find_all_disks ();
> -  config->disks = guestfs_int_copy_string_list (all_disks);
> +  if (all_disks)
> +    config->disks = guestfs_int_copy_string_list (all_disks);
>    if (all_removable)
>      config->removable = guestfs_int_copy_string_list (all_removable);
>    find_all_interfaces ();
> @@ -448,15 +449,8 @@ find_all_disks (void)
>      exit (EXIT_FAILURE);
>    }
>  
> -  if (all_disks == NULL) {
> -    fprintf (stderr, "%s: error: no non-removable disks were discovered on this machine.\n",
> -             guestfs_int_program_name);
> -    fprintf (stderr, "virt-p2v looked in /sys/block.\n");
> -    fprintf (stderr, "This is a fatal error and virt-p2v cannot continue.\n");
> -    exit (EXIT_FAILURE);
> -  }
> -
> -  qsort (all_disks, nr_disks, sizeof (char *), compare);
> +  if (all_disks)
> +    qsort (all_disks, nr_disks, sizeof (char *), compare);
>    if (all_removable)
>      qsort (all_removable, nr_removable, sizeof (char *), compare);
>  }

LGTM, and works in the mentioned case.

Thanks,
-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20150721/b6337396/attachment.sig>


More information about the Libguestfs mailing list