Move 'get_partitions' call into Sys::Guestfs::Lib.
authorRichard Jones <rjones@trick.home.annexia.org>
Thu, 9 Jul 2009 13:35:34 +0000 (14:35 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Thu, 9 Jul 2009 14:33:33 +0000 (15:33 +0100)
inspector/virt-inspector.pl
perl/lib/Sys/Guestfs/Lib.pm

index 2922ecc..5b225b2 100755 (executable)
@@ -20,7 +20,7 @@ use warnings;
 use strict;
 
 use Sys::Guestfs;
 use strict;
 
 use Sys::Guestfs;
-use Sys::Guestfs::Lib qw(open_guest);
+use Sys::Guestfs::Lib qw(open_guest get_partitions);
 use Pod::Usage;
 use Getopt::Long;
 use Data::Dumper;
 use Pod::Usage;
 use Getopt::Long;
 use Data::Dumper;
@@ -212,21 +212,6 @@ if ($uri) {
 $g->launch ();
 $g->wait_ready ();
 
 $g->launch ();
 $g->wait_ready ();
 
-# We want to get the list of LVs and partitions (ie. anything that
-# could contain a filesystem).  Discard any partitions which are PVs.
-my @partitions = $g->list_partitions ();
-my @pvs = $g->pvs ();
-sub is_pv {
-    my $t = shift;
-    foreach (@pvs) {
-       return 1 if $_ eq $t;
-    }
-    0;
-}
-@partitions = grep { ! is_pv ($_) } @partitions;
-
-my @lvs = $g->lvs ();
-
 =head1 OUTPUT FORMAT
 
  Operating system(s)
 =head1 OUTPUT FORMAT
 
  Operating system(s)
@@ -270,7 +255,7 @@ right place.  For example:
 =cut
 
 # List of possible filesystems.
 =cut
 
 # List of possible filesystems.
-my @devices = sort (@lvs, @partitions);
+my @devices = get_partitions ($g);
 
 # Now query each one to build up a picture of what's in it.
 my %fses = map { $_ => check_fs ($_) } @devices;
 
 # Now query each one to build up a picture of what's in it.
 my %fses = map { $_ => check_fs ($_) } @devices;
index ae49740..75b2056 100644 (file)
@@ -58,7 +58,7 @@ require Exporter;
 use vars qw(@EXPORT_OK @ISA);
 
 @ISA = qw(Exporter);
 use vars qw(@EXPORT_OK @ISA);
 
 @ISA = qw(Exporter);
-@EXPORT_OK = qw(open_guest);
+@EXPORT_OK = qw(open_guest get_partitions);
 
 =head2 open_guest
 
 
 =head2 open_guest
 
@@ -182,6 +182,43 @@ sub open_guest
     return wantarray ? ($g, $conn, $dom) : $g
 }
 
     return wantarray ? ($g, $conn, $dom) : $g
 }
 
+=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 excluded from the list, and so are any
+devices which are partitioned (eg. C</dev/sda> would not be returned
+if C</dev/sda1> exists).
+
+=cut
+
+sub get_partitions
+{
+    my $g = shift;
+
+    my @partitions = $g->list_partitions ();
+    my @pvs = $g->pvs ();
+    @partitions = grep { ! is_pv ($_, @pvs) } @partitions;
+
+    my @lvs = $g->lvs ();
+
+    return sort (@lvs, @partitions);
+}
+
+sub is_pv {
+    local $_;
+    my $t = shift;
+
+    foreach (@_) {
+       return 1 if $_ eq $t;
+    }
+    0;
+}
+
 1;
 
 =head1 COPYRIGHT
 1;
 
 =head1 COPYRIGHT