summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-10-26 13:01:47 +0100
committerRichard W.M. Jones <rjones@redhat.com>2010-10-27 10:59:45 +0100
commitd600342b7d29c0176ff96a7807ebb38303ecb3a6 (patch)
treea3dc73472290c604c37a1c7a6ea065dab59de0f5 /tools
parent6590e04bdcc3038312cb0a5f5545f1f0924907b2 (diff)
downloadlibguestfs-d600342b7d29c0176ff96a7807ebb38303ecb3a6.tar.gz
libguestfs-d600342b7d29c0176ff96a7807ebb38303ecb3a6.tar.xz
libguestfs-d600342b7d29c0176ff96a7807ebb38303ecb3a6.zip
df: Add --uuid option to print guest UUIDs instead of names (RHBZ#646821).
Diffstat (limited to 'tools')
-rwxr-xr-xtools/virt-df36
1 files changed, 31 insertions, 5 deletions
diff --git a/tools/virt-df b/tools/virt-df
index 61fcfb8e..6ec1c1a7 100755
--- a/tools/virt-df
+++ b/tools/virt-df
@@ -173,6 +173,20 @@ guests.
=back
+=cut
+
+my $uuid;
+
+=item B<--uuid>
+
+Print UUIDs instead of names. This is useful for following
+a guest even when the guest is migrated or renamed, or when
+two guests happen to have the same name.
+
+Note that only domains that we fetch from libvirt come with UUIDs.
+For disk images, we still print the disk image name even when
+this option is specified.
+
=back
=cut
@@ -185,6 +199,7 @@ GetOptions ("help|?" => \$help,
"human-readable|human|h" => \$human,
"inodes|i" => \$inodes,
"one-per-guest" => \$one_per_guest,
+ "uuid" => \$uuid,
) or pod2usage (2);
pod2usage (1) if $help;
if ($version) {
@@ -242,6 +257,7 @@ if (@ARGV == 0) { # No params, use libvirt.
my @disks = get_disks_from_libvirt ($dom);
push @domains, { dom => $dom,
name => $dom->get_name (),
+ uuid => $dom->get_uuid_string (),
disks => \@disks }
}
} elsif (@ARGV == 1) { # One param, could be disk image or domname.
@@ -263,6 +279,7 @@ if (@ARGV == 0) { # No params, use libvirt.
my @disks = get_disks_from_libvirt ($dom);
push @domains, { dom => $dom,
name => $dom->get_name (),
+ uuid => $dom->get_uuid_string (),
disks => \@disks }
}
} else { # >= 2 params, all disk images.
@@ -366,6 +383,7 @@ sub multi_df
my $n = 0;
foreach $d (@_) {
my $name = $d->{name};
+ my $uuid = $d->{uuid};
my $nr_disks = @{$d->{disks}};
# Filter LVM to only the devices applying to the original domain.
@@ -376,14 +394,14 @@ sub multi_df
# contain mountable filesystems. Stat those which are
# mountable, and ignore the others.
foreach (@devs) {
- try_df ($name, $g, $_, canonical_dev ($_, $n));
+ try_df ($name, $uuid, $g, $_, canonical_dev ($_, $n));
}
foreach (filter_partitions (\@devs, @partitions)) {
- try_df ($name, $g, $_, canonical_dev ($_, $n));
+ try_df ($name, $uuid, $g, $_, canonical_dev ($_, $n));
}
if ($has_lvm2) {
foreach ($g->lvs ()) {
- try_df ($name, $g, $_);
+ try_df ($name, $uuid, $g, $_);
}
}
@@ -433,6 +451,7 @@ sub try_df
{
local $_;
my $domname = shift;
+ my $domuuid = shift;
my $g = shift;
my $dev = shift;
my $display = shift || $dev;
@@ -443,7 +462,7 @@ sub try_df
%stat = $g->statvfs ("/");
};
if (!$@) {
- print_stat ($domname, $display, \%stat);
+ print_stat ($domname, $domuuid, $display, \%stat);
}
$g->umount_all ();
}
@@ -451,10 +470,17 @@ sub try_df
sub print_stat
{
my $domname = shift;
+ my $domuuid = shift;
my $dev = shift;
my $stat = shift;
- my @cols = ($domname, $dev);
+ my @cols;
+ if (!$uuid || !defined $domuuid) {
+ push @cols, $domname;
+ } else {
+ push @cols, $domuuid;
+ }
+ push @cols, $dev;
if (!$inodes) {
my $bsize = $stat->{bsize}; # block size