X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=perl%2Flib%2FSys%2FGuestfs%2FLib.pm;h=2c5c837030d408463bdc7bb3cf49cb468f2650eb;hp=8ec487dcd30499e9d9c795b06264c20caff2810f;hb=94e310dcfbcd368cbe02dbc1643ed2ff9821cd48;hpb=4839d5142ca50818965866287932f9ded14729e6 diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm index 8ec487d..2c5c837 100644 --- a/perl/lib/Sys/Guestfs/Lib.pm +++ b/perl/lib/Sys/Guestfs/Lib.pm @@ -1,5 +1,5 @@ # Sys::Guestfs::Lib -# Copyright (C) 2009 Red Hat Inc. +# Copyright (C) 2009-2010 Red Hat Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,6 +20,13 @@ package Sys::Guestfs::Lib; use strict; use warnings; +# The minor part of this version number is incremented when some +# change is made to this module. The major part is incremented if we +# make a change which is not backwards compatible. It is not related +# to the libguestfs version number. +use vars qw($VERSION); +$VERSION = '0.2'; + use Carp qw(croak); use Sys::Guestfs; @@ -260,16 +267,27 @@ This function takes an open libguestfs handle C<$g> and returns all partitions and logical volumes found on it. What is returned is everything that could contain a filesystem (or -swap). Physical volumes are excluded from the list, and so are any -devices which are partitioned (eg. C would not be returned -if C exists). +swap). Physical volumes are not normally included from the list +except if they contain a filesystem directly. Nor are devices which +are partitioned (eg. C would not be returned if C +exists). =cut sub get_partitions { + local $_; my $g = shift; + # Look to see if any devices directly contain filesystems (RHBZ#590167). + my @devices = $g->list_devices (); + my @fses_on_device = (); + foreach (@devices) { + eval { $g->mount_ro ($_, "/"); }; + push @fses_on_device, $_ unless $@; + $g->umount_all (); + } + my @partitions = $g->list_partitions (); my @pvs = $g->pvs (); @partitions = grep { ! _is_pv ($_, @pvs) } @partitions; @@ -277,7 +295,7 @@ sub get_partitions my @lvs; @lvs = $g->lvs () if feature_available ($g, "lvm2"); - return sort (@lvs, @partitions); + return sort (@fses_on_device, @lvs, @partitions); } sub _is_pv { @@ -1101,7 +1119,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 +1203,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; }