[PATCH] v2v: Fix error on exit unmounting transfer ISO
by Matthew Booth
If the transfer iso was mounted during conversion, virt-v2v would always give
the following error on shutdown:
(in cleanup) umount: /tmp/transferb7icam: umount:
/sysroot/tmp/transferb7icam: not found at
/home/mbooth/src/virt-v2v/blib/lib/Sys/VirtV2V/GuestOS/RedHat.pm line 1171.
This was because the GuestOS::RedHat cleanup was being called implicitly on
exit, which is after umount_all has been called explicitly on the libguestfs
handle. This change garbage collects the guestos explicitly before the
libguestfs handle.
---
v2v/virt-v2v.pl | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index 08f1c8d..c7ebad3 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -366,6 +366,9 @@ END {
sub close_guest_handle
{
+ # Perform GuestOS cleanup before closing the handle
+ $guestos = undef;
+
if (defined($g)) {
$g->umount_all();
$g->sync();
--
1.6.6.1
14 years, 7 months
[PATCH] Target::LibVirt: Don't truncate a volume when opening it
by Matthew Booth
perl's '>' open mode truncates by default, and will create a new file if
necessary. We don't want to truncate an existing volume when writing to it, and
it's an error if the volume doesn't already exist. Use sysopen to be explicit
about this.
---
lib/Sys/VirtV2V/Target/LibVirt.pm | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/Sys/VirtV2V/Target/LibVirt.pm b/lib/Sys/VirtV2V/Target/LibVirt.pm
index c8802ac..99a1ad2 100644
--- a/lib/Sys/VirtV2V/Target/LibVirt.pm
+++ b/lib/Sys/VirtV2V/Target/LibVirt.pm
@@ -20,6 +20,8 @@ use warnings;
package Sys::VirtV2V::Target::LibVirt::Vol;
+use POSIX;
+
use Sys::VirtV2V::UserMessage qw(user_message);
sub _new
@@ -106,7 +108,9 @@ sub open
my $self = shift;
my $path = $self->get_path();
- open(my $fd, '>', $path)
+
+ # We want to open the existing volume without truncating it
+ sysopen(my $fd, $path, O_WRONLY)
or die(user_message(__x("Error opening storage volume {path} ".
"for writing: {error}", error => $!)));
--
1.6.6.1
14 years, 7 months
[PATCH] Connection: Handle case of cdrom with no <source> element
by Matthew Booth
CD-ROM devices don't necessarily have a <source> element in their libvirt domain
XML, which caused an error.
This fixes RHBZ#579676
---
lib/Sys/VirtV2V/Connection.pm | 103 ++++++++++++++++++++++-------------------
1 files changed, 56 insertions(+), 47 deletions(-)
diff --git a/lib/Sys/VirtV2V/Connection.pm b/lib/Sys/VirtV2V/Connection.pm
index a211662..c901b90 100644
--- a/lib/Sys/VirtV2V/Connection.pm
+++ b/lib/Sys/VirtV2V/Connection.pm
@@ -116,7 +116,8 @@ sub _storage_iterate
my @paths;
# A list of libvirt target device names
my @devices;
- foreach my $disk ($dom->findnodes('/domain/devices/disk')) {
+
+ foreach my $disk ($dom->findnodes("/domain/devices/disk[\@device='disk']")) {
my ($source_e) = $disk->findnodes('source');
my ($source) = $source_e->findnodes('@file | @dev');
@@ -125,55 +126,63 @@ sub _storage_iterate
my ($dev) = $disk->findnodes('target/@dev');
defined($dev) or die("disk does not have a target device: \n".
- $dom->toString());
+ $dom->toString());
- # If the disk is a floppy or a cdrom, blank its source
- my $device = $disk->getAttribute('device');
- if ($device eq 'floppy' || $device eq 'cdrom') {
- $source_e->setAttribute($source->getName(), '');
- }
+ my $path = $source->getValue();
+
+ # Die if transfer required and no output target
+ die (user_message(__"No output target was specified"))
+ unless (defined($target));
+
+ # Fetch the remote storage
+ my $vol = $transfer->transfer($self, $path, $target);
- else {
- my $path = $source->getValue();
-
- # Die if transfer required and no output target
- die (user_message(__"No output target was specified"))
- unless (defined($target));
-
- # Fetch the remote storage
- my $vol = $transfer->transfer($self, $path, $target);
-
- # Export the new path
- $path = $vol->get_path();
-
- # Find any existing driver element.
- my ($driver) = $disk->findnodes('driver');
-
- # Create a new driver element if none exists
- unless (defined($driver)) {
- $driver =
- $disk->getOwnerDocument()->createElement("driver");
- $disk->appendChild($driver);
- }
- $driver->setAttribute('name', 'qemu');
- $driver->setAttribute('type', $vol->get_format());
-
- # Remove the @file or @dev attribute before adding a new one
- $source_e->removeAttributeNode($source);
-
- # Set @file or @dev as appropriate
- if ($vol->is_block())
- {
- $disk->setAttribute('type', 'block');
- $source_e->setAttribute('dev', $path);
- } else {
- $disk->setAttribute('type', 'file');
- $source_e->setAttribute('file', $path);
- }
-
- push(@paths, $path);
- push(@devices, $dev->getNodeValue());
+ # Export the new path
+ $path = $vol->get_path();
+
+ # Find any existing driver element.
+ my ($driver) = $disk->findnodes('driver');
+
+ # Create a new driver element if none exists
+ unless (defined($driver)) {
+ $driver =
+ $disk->getOwnerDocument()->createElement("driver");
+ $disk->appendChild($driver);
}
+ $driver->setAttribute('name', 'qemu');
+ $driver->setAttribute('type', $vol->get_format());
+
+ # Remove the @file or @dev attribute before adding a new one
+ $source_e->removeAttributeNode($source);
+
+ # Set @file or @dev as appropriate
+ if ($vol->is_block()) {
+ $disk->setAttribute('type', 'block');
+ $source_e->setAttribute('dev', $path);
+ } else {
+ $disk->setAttribute('type', 'file');
+ $source_e->setAttribute('file', $path);
+ }
+
+ push(@paths, $path);
+ push(@devices, $dev->getNodeValue());
+ }
+
+ # Blank the source of floppies or cdroms
+ foreach my $disk ($dom->findnodes('/domain/devices/disk'.
+ "[\@device='floppy' or \@device='cdrom']"))
+ {
+ my ($source_e) = $disk->findnodes('source');
+
+ # Nothing to do if there's no source element
+ next unless (defined($source_e));
+
+ # Blank file or dev as appropriate
+ my ($source) = $source_e->findnodes('@file | @dev');
+ defined($source) or die("source element has neither dev nor file: \n".
+ $dom->toString());
+
+ $source_e->setAttribute($source->getName(), '');
}
$self->{paths} = \@paths;
--
1.6.6.1
14 years, 7 months
'make uninstall' does not clean up ocaml binding files
by Jinxin Zheng
Hi all,
I have successfully compiled the libguestfs-1.0.89 source and 'make install'ed on my Fedora 12 box. Everything went fine. I have ocaml installed so the default configuration enabled ocaml binding.
then I found some minimal configure mistake with my compilation and wanted to compile and install again.
1.first I made uninstall and cleaned up everthing:
$ make uninstall
$ make clean
$ make distclean
2.I reconfigured the source and compiled again:
$ ./configure ...
$ make
3.compiling seems fine, install then:
$ make install
This is where I failed. The make command fails complaining that the /usr/lib64/ocaml/guestfs directory isn't clean, as attached full output log of this step.
I thinks the problem is at the cleaning step. I'm not actually confident that it's the correct way I cleaned up the installation.
Would like to seek for suggestion. Thanks.
Jinxin Zheng
14 years, 7 months
[PATCH] RHEV: Use dd and direct io to write to NFS
by Matthew Booth
I've been experiencing severe stability issues writing large amounts of data to
an NFS export (I have never successfully written 8GB of data without having to
reboot my machine). This patch alleviates the problem. I have successfully
exported an 8GB disk with this patch in place.
---
lib/Sys/VirtV2V/Target/RHEV.pm | 29 ++++++-----------------------
1 files changed, 6 insertions(+), 23 deletions(-)
diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm
index 4b663ef..9b4b73a 100644
--- a/lib/Sys/VirtV2V/Target/RHEV.pm
+++ b/lib/Sys/VirtV2V/Target/RHEV.pm
@@ -285,29 +285,12 @@ sub open
path => "$path.meta",
error => $!)));
- # Open the data file for writing
- my $data;
- open($data, '>', $path)
- or die(__x("Unable to open {path} for writing: {error}",
- path => "$path",
- error => $!));
-
- # Write all data received to the data file
- my $buffer;
-
- for(;;) {
- my $ret = sysread(STDIN, $buffer, 64*1024);
- die("Error in NFSHelper reading from stdin: $!")
- unless (defined($ret));
- last if ($ret == 0);
-
- print $data $buffer;
- }
-
- close($data)
- or die(user_message(__x("Error closing {path}: {error}",
- path => "$path",
- error => $!)));
+ # Write the remainder of the data using dd in 2MB chunks
+ # XXX - mbooth(a)redhat.com 06/04/2010 (Fedora 12 writing to RHEL 5 NFS)
+ # Use direct IO as writing a large amount of data to NFS regularly
+ # crashes my machine. Using direct io crashes less.
+ exec('dd', 'obs='.1024*1024*2, 'oflag=direct', 'of='.$path)
+ or die("Unable to execute dd: $!");
});
}
--
1.6.6.1
14 years, 7 months
[PATCH] Fix tar-in command hangs when running out of disk space (RHBZ#580246).
by Richard W.M. Jones
This patch also contains some code cleanup, error message fixes, and a
regression test. However the pertinent change appears to be this one
(which I don't fully understand):
- return fwrite (buf, len, 1, fp) == 1 ? 0 : -1;
+ return fwrite (buf, 1, len, fp) < len ? 0 : -1;
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
14 years, 7 months
[PATCH] LocalCopy: Use blockdev to get the size of block devices
by Matthew Booth
LocalCopy was previously only using stat to determine the size of a source disk.
If that source disk was a block device it would return 4k. Amongst other
problems, this resulted in disks which would not import into RHEV.
---
lib/Sys/VirtV2V/Transfer/LocalCopy.pm | 32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/lib/Sys/VirtV2V/Transfer/LocalCopy.pm b/lib/Sys/VirtV2V/Transfer/LocalCopy.pm
index 814bf4a..093e78f 100644
--- a/lib/Sys/VirtV2V/Transfer/LocalCopy.pm
+++ b/lib/Sys/VirtV2V/Transfer/LocalCopy.pm
@@ -17,6 +17,7 @@
package Sys::VirtV2V::Transfer::LocalCopy;
+use POSIX;
use File::Spec;
use File::stat;
@@ -79,7 +80,36 @@ sub transfer
path => $path,
error => $!)));
- my $vol = $target->create_volume($name, $st->size);
+ my $size;
+
+ # If it's a block device, use the output of blockdev command
+ if (S_ISBLK($st->mode)) {
+ my $blockdev;
+ open($blockdev, '-|', 'blockdev', '--getsize64', $path)
+ or die("Unable to execute blockdev: $!");
+
+ while (<$blockdev>) {
+ if (defined($size)) {
+ my $error = "blockdev returned multiple output lines:\n$size\n";
+ $error .= $_;
+ while(<$blockdev>) {
+ $error .= $_;
+ }
+ die($error);
+ }
+ chomp;
+ $size = $_;
+ }
+
+ close($blockdev) or die("blockdev returned an error: $size");
+ }
+
+ # Otherwise use the size of the file directly
+ else {
+ $size = $st->size;
+ }
+
+ my $vol = $target->create_volume($name, $size);
$vol->open();
for (;;) {
--
1.6.6.1
14 years, 7 months