summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-08-31 20:39:40 +0100
committerRichard Jones <rjones@redhat.com>2010-09-01 14:20:22 +0100
commitc9bc865a7acf372a66f7c9a3f34440deb32f1ea9 (patch)
tree555ee3c6079d9938b9777464b4bbbef495cffca2 /tools
parent8ff17e1c9cf348c93ac731281b1e4a0d5fa7caf3 (diff)
downloadlibguestfs-c9bc865a7acf372a66f7c9a3f34440deb32f1ea9.tar.gz
libguestfs-c9bc865a7acf372a66f7c9a3f34440deb32f1ea9.tar.xz
libguestfs-c9bc865a7acf372a66f7c9a3f34440deb32f1ea9.zip
resize: Add progress bar to virt-resize.
With this commit you will see a plain progress bar during the lengthy copy operations, similar to below: Summary of changes: /dev/sda1: partition will be left alone /dev/sda2: partition will be resized from 7.5G to 9.5G /dev/sda2: content will be expanded using the 'pvresize' method Copying /dev/sda1 ... [############################################################################] Copying /dev/sda2 ... [########################################------------------------------------]
Diffstat (limited to 'tools')
-rwxr-xr-xtools/virt-resize29
1 files changed, 23 insertions, 6 deletions
diff --git a/tools/virt-resize b/tools/virt-resize
index a70492e8..28f51af1 100755
--- a/tools/virt-resize
+++ b/tools/virt-resize
@@ -33,6 +33,8 @@ $Data::Dumper::Sortkeys = 1;
die __"virt-resize: sorry this program does not work on a 32 bit host\n"
if ~1 == 4294967294;
+$| = 1;
+
=encoding utf8
=head1 NAME
@@ -583,6 +585,7 @@ sub launch_guestfs
$g->set_trace (1) if $debug;
$g->add_drive_ro ($infile);
$g->add_drive ($outfile);
+ $g->set_progress_callback (\&progress_callback) unless $quiet;
$g->launch ();
}
@@ -1122,16 +1125,11 @@ sub copy_data
}
if (!$quiet && !$debug) {
- local $| = 1;
- print __x("Copying {p} ...", p => $part);
+ print __x("Copying {p} ...\n", p => $part);
}
$g->copy_size ($part, $target,
$newsize < $oldsize ? $newsize : $oldsize);
-
- if (!$quiet && !$debug) {
- print " ", __"done", "\n";
- }
}
}
}
@@ -1330,6 +1328,25 @@ sub canonicalize
$_;
}
+# Not as sophisticated as the guestfish progress bar, because
+# I intend to use an external library for this at some point (XXX).
+sub progress_callback
+{
+ my $proc_nr = shift;
+ my $serial = shift;
+ my $position = shift;
+ my $total = shift;
+
+ my $ratio = $position / $total;
+ if ($ratio < 0) { $ratio = 0 }
+ elsif ($ratio > 1) { $ratio = 1 }
+
+ my $dots = int ($ratio * 76);
+
+ print "[", "#"x$dots, "-"x(76-$dots), "]\r";
+ print "\n" if $ratio == 1;
+}
+
=head1 NOTES
=head2 "Partition 1 does not end on cylinder boundary."