From c8e225b8e0cc29aca69a58128ea1faf33600c411 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 12 May 2010 18:11:37 +0100 Subject: [PATCH] Improved error if virt-inspector cannot find OSes in image (RHBZ#591142). (cherry picked from commit 94e310dcfbcd368cbe02dbc1643ed2ff9821cd48 and modified to apply to the stable branch) --- perl/lib/Sys/Guestfs/Lib.pm | 8 +++++++- tools/virt-cat | 1 - tools/virt-edit | 1 - tools/virt-ls | 1 - tools/virt-tar | 1 - tools/virt-win-reg | 1 - 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm index 8ec487d..4305b19 100644 --- a/perl/lib/Sys/Guestfs/Lib.pm +++ b/perl/lib/Sys/Guestfs/Lib.pm @@ -1101,7 +1101,8 @@ like: '/dev/VG/Root' => \%os, } -(There can be multiple roots for a multi-boot VM). +There can be multiple roots for a multi-boot VM, but this function +will throw an error if no roots (ie. OSes) could be found. The C<\%os> hash contains the following keys (any can be omitted): @@ -1184,6 +1185,11 @@ sub inspect_operating_systems } } + # If we didn't find any operating systems then it's an error (RHBZ#591142). + if (0 == keys %oses) { + die __"No operating system could be detected inside this disk image.\n\nThis may be because the file is not a disk image, or is not a virtual machine\nimage, or because the OS type is not understood by virt-inspector.\n\nIf you feel this is an error, please file a bug report including as much\ninformation about the disk image as possible.\n"; + } + return \%oses; } diff --git a/tools/virt-cat b/tools/virt-cat index c8cdd19..e000e25 100755 --- a/tools/virt-cat +++ b/tools/virt-cat @@ -150,7 +150,6 @@ my %fses = my $oses = inspect_operating_systems ($g, \%fses); my @roots = keys %$oses; -die __"no root device found in this operating system image" if @roots == 0; die __"multiboot operating systems are not supported by virt-cat" if @roots > 1; my $root_dev = $roots[0]; diff --git a/tools/virt-edit b/tools/virt-edit index c133e6a..e00e4cf 100755 --- a/tools/virt-edit +++ b/tools/virt-edit @@ -133,7 +133,6 @@ my %fses = my $oses = inspect_operating_systems ($g, \%fses); my @roots = keys %$oses; -die __"no root device found in this operating system image" if @roots == 0; die __"multiboot operating systems are not supported by virt-edit" if @roots > 1; my $root_dev = $roots[0]; diff --git a/tools/virt-ls b/tools/virt-ls index 8add52e..8813d2f 100755 --- a/tools/virt-ls +++ b/tools/virt-ls @@ -183,7 +183,6 @@ my %fses = my $oses = inspect_operating_systems ($g, \%fses); my @roots = keys %$oses; -die __"no root device found in this operating system image\n" if @roots == 0; die __"multiboot operating systems are not supported by virt-ls\n" if @roots > 1; my $root_dev = $roots[0]; diff --git a/tools/virt-tar b/tools/virt-tar index 612b500..1470ee0 100755 --- a/tools/virt-tar +++ b/tools/virt-tar @@ -225,7 +225,6 @@ my %fses = my $oses = inspect_operating_systems ($g, \%fses); my @roots = keys %$oses; -die __"no root device found in this operating system image\n" if @roots == 0; die __"multiboot operating systems are not supported by virt-tar\n" if @roots > 1; my $root_dev = $roots[0]; diff --git a/tools/virt-win-reg b/tools/virt-win-reg index 91a1673..c777a0a 100755 --- a/tools/virt-win-reg +++ b/tools/virt-win-reg @@ -280,7 +280,6 @@ my %fses = my $oses = inspect_operating_systems ($g, \%fses); my @roots = keys %$oses; -die __"no root device found in this operating system image" if @roots == 0; die __"multiboot operating systems are not supported by virt-win-reg" if @roots > 1; my $root_dev = $roots[0]; -- 1.8.3.1