X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=perl%2Flib%2FSys%2FGuestfs%2FLib.pm;h=007db64c135aa7002083f0c81650445f7852a702;hp=5df62292571af4bdb6ee41ff66412573e595a53b;hb=b9838001015a06a69a08b69d9f013d82f0ea3139;hpb=40d58fe65e10aa692d056a573e21e5afdc9329c7 diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm index 5df6229..007db64 100644 --- a/perl/lib/Sys/Guestfs/Lib.pm +++ b/perl/lib/Sys/Guestfs/Lib.pm @@ -285,16 +285,9 @@ sub feature_available { =head2 get_partitions - @partitions = get_partitions ($g); - -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 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). +This function is deprecated. It will not be updated in future +versions of libguestfs. New code should not use this function. Use +the core API function L instead. =cut @@ -531,12 +524,12 @@ sub _check_linux_root $r->{package_management} = "yum"; } - elsif (/(Red Hat Enterprise Linux|CentOS|Scientific Linux)/) { + elsif (/(Red Hat|CentOS|Scientific Linux)/) { chomp; $r->{product_name} = $_; my $distro = $1; - if($distro eq "Red Hat Enterprise Linux") { + if($distro eq "Red Hat") { $r->{osdistro} = "rhel"; } @@ -874,7 +867,7 @@ sub _assign_mount_points foreach (@fstab) { my ($spec, $file) = @$_; - my ($dev, $fs) = _find_filesystem ($g, $fses, $spec); + my ($dev, $fs) = _find_filesystem ($g, $fses, $spec, $file); if ($dev) { $r->{mounts}->{$file} = $dev; $r->{filesystems}->{$dev} = $fs; @@ -895,26 +888,33 @@ sub _find_filesystem my $g = shift; my $fses = shift; local $_ = shift; + my $file = shift; if (/^LABEL=(.*)/) { my $label = $1; - foreach (sort keys %$fses) { - if (exists $fses->{$_}->{label} && - $fses->{$_}->{label} eq $label) { - return ($_, $fses->{$_}); - } - } - warn __x("unknown filesystem label {label}\n", label => $label); + my $dev; + eval { + $dev = $g->findfs_label ($label); + }; + warn "unknown filesystem LABEL=$label in /etc/fstab: $@\n" if $@; + return () if !defined $dev; + $dev = _canonical_dev ($dev); + return ($dev, $fses->{$dev}) if exists $fses->{$dev}; + # Otherwise return nothing. It's just a filesystem that we are + # ignoring, eg. swap. return (); } elsif (/^UUID=(.*)/) { my $uuid = $1; - foreach (sort keys %$fses) { - if (exists $fses->{$_}->{uuid} && - $fses->{$_}->{uuid} eq $uuid) { - return ($_, $fses->{$_}); - } - } - warn __x("unknown filesystem UUID {uuid}\n", uuid => $uuid); + my $dev; + eval { + $dev = $g->findfs_uuid ($uuid); + }; + warn "unknown filesystem UUID=$uuid in /etc/fstab: $@\n" if $@; + return () if !defined $dev; + $dev = _canonical_dev ($dev); + return ($dev, $fses->{$dev}) if exists $fses->{$dev}; + # Otherwise return nothing. It's just a filesystem that we are + # ignoring, eg. swap. return (); } else { return ($_, $fses->{$_}) if exists $fses->{$_}; @@ -928,6 +928,9 @@ sub _find_filesystem if (m{^/dev/hd(.*)} && exists $fses->{"/dev/sd$1"}) { return ("/dev/sd$1", $fses->{"/dev/sd$1"}); } + if (m{^/dev/vd(.*)} && exists $fses->{"/dev/sd$1"}) { + return ("/dev/sd$1", $fses->{"/dev/sd$1"}); + } if (m{^/dev/xvd(.*)} && exists $fses->{"/dev/sd$1"}) { return ("/dev/sd$1", $fses->{"/dev/sd$1"}); } @@ -935,7 +938,9 @@ sub _find_filesystem return ("/dev/$1/$2", $fses->{"/dev/$1/$2"}); } + return () if $file =~ (/media\/cdrom/); return () if m{/dev/cdrom}; + return () if m{/dev/fd0}; warn __x("unknown filesystem {fs}\n", fs => $_); return (); @@ -1109,7 +1114,7 @@ sub _find_grub_prefix die(__"Can't find grub on guest") unless($g->exists('/boot/grub/menu.lst')); # Look for the most specific mount point in mounts - foreach my $path qw(/boot/grub /boot /) { + foreach my $path (qw(/boot/grub /boot /)) { if(exists($mounts->{$path})) { return "" if($path eq '/'); return $path; @@ -1340,10 +1345,10 @@ sub _find_modprobe_aliases my %modprobe_aliases; - for my $pattern qw(/files/etc/conf.modules/alias - /files/etc/modules.conf/alias - /files/etc/modprobe.conf/alias - /files/etc/modprobe.d/*/alias) { + for my $pattern (qw(/files/etc/conf.modules/alias + /files/etc/modules.conf/alias + /files/etc/modprobe.conf/alias + /files/etc/modprobe.d/*/alias)) { for my $path ( $g->aug_match($pattern) ) { $path =~ m{^/files(.*)/alias(?:\[\d*\])?$} or die __x("{path} doesn't match augeas pattern",