[PATCH 1/2] Add new augeas directory with grub device.map lens
by Matthew Booth
Add a directory to contain required augeas lenses which aren't yet upstream.
Include a new lens for grub's device.map.
---
augeas/README.txt | 4 ++++
augeas/device_map.aug | 28 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
create mode 100644 augeas/README.txt
create mode 100644 augeas/device_map.aug
diff --git a/augeas/README.txt b/augeas/README.txt
new file mode 100644
index 0000000..709be7c
--- /dev/null
+++ b/augeas/README.txt
@@ -0,0 +1,4 @@
+This directory contains augeas lenses required by virt-v2v.
+
+device_map.aug posted upstream:
+http://www.redhat.com/archives/augeas-devel/2010-June/msg00027.html
diff --git a/augeas/device_map.aug b/augeas/device_map.aug
new file mode 100644
index 0000000..090edd5
--- /dev/null
+++ b/augeas/device_map.aug
@@ -0,0 +1,28 @@
+(* Parsing grub's device.map *)
+
+module Device_map =
+ autoload xfm
+
+ let sep_tab = Sep.tab
+ let eol = Util.eol
+ let fspath = Rx.fspath
+ let del_str = Util.del_str
+
+ let comment = Util.comment
+ let empty = Util.empty
+
+ let dev_name = /(h|f|c)d[0-9]+(,[0-9a-zA-Z]+){0,2}/
+ let dev_hex = /0x[0-9a-fA-F]+/
+ let dev_dec = /[0-9]+/
+
+ let device = del_str "(" . key ( dev_name | dev_hex | dev_dec ) . del_str ")"
+
+ let map = [ device . sep_tab . store fspath . eol ]
+
+ let lns = ( empty | comment | map ) *
+
+ let xfm = transform lns (incl "/boot/grub/device.map")
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
--
1.7.1
14 years, 2 months
Support for Citrix Xen, Oracle Xen, and Novell Xen?
by Martin Jeppesen
Hi there,
Having a mixed environment of technologies, I was wondering if there
are plans for supporting Citrix Xen, Oracle Xen, and Novell Xen in
virt-v2v?
I'd say Citrix Xen and Oracle Xen are really the most important of the three.
Martin
14 years, 2 months
Re: [Libguestfs] libguestfs
by Richard W.M. Jones
On Mon, Jun 28, 2010 at 03:42:03PM +0200, jlvazquez2(a)correo.ei.uvigo.es wrote:
> I am creating a virtualization project where I would be very
> libguestfs library aid. With this library can do almost everything
> I need, less to install packages from the internet in virtualized disks.
> It would be interesting to have internet access at virt-rescue, eg virt-
> rescue --nat or virt-rescue --ip 33.22.34.3 --dns 32.32.3.2.
Does this not work? We have used the network for some things, eg.
running yum and connecting to RHN. There are some limitations in the
stable version, fixed in the development version:
https://bugzilla.redhat.com/show_bug.cgi?id=588763
The idea of adding --ip and other options to virt-rescue is a
reasonable idea, assuming that the network doesn't work already.
> Or a modified version of yum install package that allows virtualized
> disks, eg: yum --disk disco.img gimp.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
14 years, 2 months
Re: [Libguestfs] febootstrap F12 ppc coreutils PREIN
by Richard W.M. Jones
On Fri, Jun 18, 2010 at 11:09:10AM -0700, Dwayne Fontenot <dwayne.fontenot(a)att.net> wrote:
>
> open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
> fstat64(3, {st_mode=S_IFREG|0644, st_size=80626448, ...}) = 0
> mmap2(NULL, 2097152, PROT_READ, MAP_PRIVATE, 3, 0) = 0x30041000
> mmap2(NULL, 245760, PROT_READ, MAP_PRIVATE, 3, 0x2330) = 0x30241000
> --- SIGSEGV (Segmentation fault) @ 0 (0) ---
> +++ killed by SIGSEGV +++
Yes, that's really interesting. I didn't suspect that locale-archive
would be a non-portable binary file. I wonder if there's some
environment variable to make it use a different file?
CC-ing to libguestfs mailing list.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
14 years, 2 months
[PATCH] Look for i686 target for i386 Windows guest
by Matthew Booth
We detect a Windows guest with 32 bit userspace as i386. Ensure we look for a
i686 kvm target in this case.
Fixes RHBZ#605593
---
lib/Sys/VirtV2V/Target/LibVirt.pm | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/lib/Sys/VirtV2V/Target/LibVirt.pm b/lib/Sys/VirtV2V/Target/LibVirt.pm
index cb9961d..199ca9e 100644
--- a/lib/Sys/VirtV2V/Target/LibVirt.pm
+++ b/lib/Sys/VirtV2V/Target/LibVirt.pm
@@ -317,6 +317,9 @@ sub _configure_capabilities
my $arch = $guestcaps->{arch};
+ # i386 userspace means i686 guest
+ $arch = 'i686' if ($arch eq 'i386');
+
(my $guestcap) = $caps->findnodes
("/capabilities/guest[arch[\@name='$arch']/domain/\@type='kvm']");
--
1.7.1
14 years, 2 months
[PATCH] Improve error message when LibvirtXML is given invalid domain XML
by Matthew Booth
If a user accidentally passed a valid XML document to the LibvirtXML which
wasn't actually a libvirt domain XML document, they would end up getting obtuse
errors from a libguestfs library. This change does 2 sanity checks:
1. After parsing a the XML document, check /domain/name exists.
2. Check that the domain defines some storage
The second check is generally useful, as we can't usefully do anything with a
domain which has no storage.
---
lib/Sys/VirtV2V/Connection.pm | 3 +++
lib/Sys/VirtV2V/Connection/LibVirtXML.pm | 5 +++++
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/lib/Sys/VirtV2V/Connection.pm b/lib/Sys/VirtV2V/Connection.pm
index da6a44b..4dc659d 100644
--- a/lib/Sys/VirtV2V/Connection.pm
+++ b/lib/Sys/VirtV2V/Connection.pm
@@ -186,6 +186,9 @@ sub _storage_iterate
$source_e->setAttribute($source->getName(), '');
}
+ die(user_message(__("Guest doesn't define any recognised storage devices")))
+ unless (@paths > 0);
+
$self->{paths} = \@paths;
$self->{devices} = \@devices;
}
diff --git a/lib/Sys/VirtV2V/Connection/LibVirtXML.pm b/lib/Sys/VirtV2V/Connection/LibVirtXML.pm
index 729f1e8..ac3e82b 100644
--- a/lib/Sys/VirtV2V/Connection/LibVirtXML.pm
+++ b/lib/Sys/VirtV2V/Connection/LibVirtXML.pm
@@ -95,6 +95,11 @@ sub _get_dom
# Display any parse errors
die(user_message(__x("Unable to parse domain from file {path}: {error}",
path => $self->{path}, error => $@))) if ($@);
+
+ # Check it looks like domain XML
+ my ($dummy) = $self->{dom}->findnodes('/domain/name');
+ die(user_message(__x("{path} doesn't look like a libvirt domain XML file",
+ path => $self->{path}))) unless (defined($dummy));
}
=back
--
1.7.1
14 years, 2 months
[PATCH] Improve cleanup of libguestfs handle with Sys::VirtV2V::GuestfsHandle
by Matthew Booth
This change replaces all direct usage of a Sys::Guestfs object in virt-v2v with
a Sys::VirtV2V::GuestfsHandle proxy object. The proxy does 3 things:
* Holds handle initialisation code
* Adds the ability to explicitly close the handle
* Adds the ability to register a callback to be executed before close
The cleanup code in Sys::VirtV2V::Config is updated to use the new callback
mechanism.
Additionally, the initialisation code improves handling of failure while
virt-v2v is running with uid:gid == 36:36. If cleanup handlers are called in
this context they can fail due to insufficient permissions. If this code dies,
permissions will be restored before the die is propagated. If this code receives
a user signal it will be postponed until after the code has completed.
---
MANIFEST | 1 +
lib/Sys/VirtV2V/Config.pm | 22 +---
lib/Sys/VirtV2V/GuestfsHandle.pm | 208 ++++++++++++++++++++++++++++++++++++++
v2v/virt-v2v.pl | 72 ++------------
4 files changed, 223 insertions(+), 80 deletions(-)
create mode 100644 lib/Sys/VirtV2V/GuestfsHandle.pm
diff --git a/MANIFEST b/MANIFEST
index 06df2aa..fb6a2fc 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,6 +4,7 @@ COPYING
COPYING.LIB
lib/Sys/VirtV2V.pm
lib/Sys/VirtV2V/ExecHelper.pm
+lib/Sys/VirtV2V/GuestfsHandle.pm
lib/Sys/VirtV2V/GuestOS.pm
lib/Sys/VirtV2V/GuestOS/RedHat.pm
lib/Sys/VirtV2V/Config.pm
diff --git a/lib/Sys/VirtV2V/Config.pm b/lib/Sys/VirtV2V/Config.pm
index 3f689e0..761bee5 100644
--- a/lib/Sys/VirtV2V/Config.pm
+++ b/lib/Sys/VirtV2V/Config.pm
@@ -233,10 +233,13 @@ sub get_transfer_path
my $transfer = $devices[$#devices];
$g->mount_ro($transfer, $self->{transfer_mount});
- $self->{transfer_mounted} = 1;
- # We'll need this to unmount in DESTROY
- $self->{g} = $g;
+ # Umount and remove the transfer mount point before the guestfs
+ # handle is closed
+ $g->add_on_close(sub {
+ $g->umount($self->{transfer_mount});
+ $g->rmdir($self->{transfer_mount});
+ });
}
}
@@ -498,19 +501,6 @@ sub set_default_net_mapping
$self->{default_net_mapping} = [ $name, $type ];
}
-sub DESTROY
-{
- my $self = shift;
-
- my $g = $self->{g};
-
- # Remove the transfer mount point if it was used
- $g->umount($self->{transfer_mount})
- if(defined($self->{transfer_mounted}));
- $g->rmdir($self->{transfer_mount})
- if(defined($self->{transfer_mount}));
-}
-
=back
=head1 COPYRIGHT
diff --git a/lib/Sys/VirtV2V/GuestfsHandle.pm b/lib/Sys/VirtV2V/GuestfsHandle.pm
new file mode 100644
index 0000000..8720744
--- /dev/null
+++ b/lib/Sys/VirtV2V/GuestfsHandle.pm
@@ -0,0 +1,208 @@
+# Sys::VirtV2V::GuestfsHandle
+# Copyright (C) 2010 Red Hat Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+package Sys::VirtV2V::GuestfsHandle;
+
+use strict;
+use warnings;
+
+use Carp;
+
+use Sys::Guestfs::Lib qw(open_guest);
+use Sys::VirtV2V::UserMessage qw(user_message);
+
+use Locale::TextDomain 'virt-v2v';
+
+=pod
+
+=head1 NAME
+
+Sys::VirtV2V::GuestfsHandle - Proxy Sys::Guestfs with custom close behaviour
+
+=head1 SYNOPSIS
+
+ use Sys::VirtV2V::GuestfsHandle;
+
+ my $g = new Sys::VirtV2V::GuestfsHandle($storage, $transferiso);
+
+ # GuestfsHandle proxies all Sys::Guestfs methods
+ print join("\n", $g->list_devices());
+
+ # GuestfsHandle adds 2 new methods
+ $g->add_on_close(sub { print "Bye!\n"; });
+ $g->close();
+
+=head1 DESCRIPTION
+
+Sys::VirtV2V::GuestfsHandle is a proxy to Sys::Guestfs which adds a custom
+close() method, and the ability to register pre-close callbacks.
+
+=head1 METHODS
+
+=over
+
+=item new(storage, transferiso, isrhev)
+
+Create a new object. Open a new Sys::Guestfs handle to proxy, using the disks
+defined in the array I<storage>. Add I<transferiso> as a read-only drive if it
+is given. If I<isrhev> is true, the handle will use user and group 36:36.
+
+=cut
+
+sub new
+{
+ my $class = shift;
+ my ($storage, $transfer, $isrhev) = @_;
+
+ my $self = {};
+
+ my $interface = "ide";
+
+ # Don't respond to signals while we're running setuid. Cleanup operations
+ # can fail if they run as the wrong user.
+ my $sigint = $SIG{'INT'};
+ my $sigquit = $SIG{'QUIT'};
+ my $sig_received;
+
+ $SIG{'INT'} = $SIG{'QUIT'} = sub {
+ $sig_received = shift;
+ };
+
+ if ($isrhev) {
+ $) = "36 36";
+ $> = "36";
+ }
+
+ # Open a guest handle
+ my $g;
+
+ eval {
+ $g = open_guest($storage, rw => 1, interface => $interface);
+
+ # Add the transfer iso if there is one
+ $g->add_drive_ro_with_if($transfer, $interface) if (defined($transfer));
+
+ $g->launch();
+ };
+ my $err = $@;
+
+ if ($isrhev) {
+ $) = "0 0";
+ $> = "0";
+ }
+
+ die($err) if ($err);
+
+ if (defined($sig_received)) {
+ &$sigint($sig_received) if ($sig_received eq 'INT');
+ &$sigquit($sig_received) if ($sig_received eq 'QUIT');
+ }
+ $SIG{'INT'} = $sigint;
+ $SIG{'QUIT'} = $sigquit;
+
+ # Enable autosync to defend against data corruption on unclean shutdown
+ $g->set_autosync(1);
+
+ $self->{g} = $g;
+
+ $self->{onclose} = [];
+
+ bless($self, $class);
+ return $self;
+}
+
+=item add_on_close
+
+Register a callback to be called before closing the underlying Sys::Guestfs
+handle.
+
+=cut
+
+sub add_on_close
+{
+ my $self = shift;
+
+ push(@{$self->{onclose}}, shift);
+}
+
+=item close
+
+Call all registered close callbacks, then close the Sys::Guestfs handle.
+
+=cut
+
+sub close
+{
+ my $self = shift;
+
+ my $g = $self->{g};
+
+ # Nothing to do if handle is already closed
+ return unless (defined($g));
+
+ foreach my $onclose (@{$self->{onclose}}) {
+ &$onclose();
+ }
+
+ my $retval = $?;
+ $? = 0;
+
+ # This will close the underlying libguestfs handle, which may affect $?
+ $self->{g} = undef;
+
+ warn(user_message(__x("libguestfs did not shut down cleanly")))
+ if ($? != 0);
+
+ $? = $retval;
+}
+
+our $AUTOLOAD;
+sub AUTOLOAD
+{
+ (my $methodname) = $AUTOLOAD =~ m/.*::(\w+)$/;
+
+ # We don't want to call DESTROY explicitly
+ return if ($methodname eq "DESTROY");
+
+ my $self = shift;
+ my $g = $self->{g};
+
+ croak("$methodname called on guestfs handle after handle was closed")
+ unless (defined($g));
+
+ return $g->$methodname(@_);
+}
+
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright (C) 2010 Red Hat Inc.
+
+=head1 LICENSE
+
+Please see the file COPYING.LIB for the full license.
+
+=head1 SEE ALSO
+
+L<virt-v2v(1)>,
+L<http://libguestfs.org/>.
+
+=cut
+
+1;
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index 9008ad6..adaa9a9 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -25,7 +25,7 @@ use Getopt::Long;
use Locale::TextDomain 'virt-v2v';
use Sys::Guestfs;
-use Sys::Guestfs::Lib qw(open_guest get_partitions inspect_all_partitions
+use Sys::Guestfs::Lib qw(get_partitions inspect_all_partitions
inspect_operating_systems mount_operating_system
inspect_in_detail);
@@ -37,6 +37,7 @@ use Sys::VirtV2V::Connection::LibVirtXML;
use Sys::VirtV2V::Target::LibVirt;
use Sys::VirtV2V::Target::RHEV;
use Sys::VirtV2V::ExecHelper;
+use Sys::VirtV2V::GuestfsHandle;
use Sys::VirtV2V::GuestOS;
use Sys::VirtV2V::UserMessage qw(user_message);
@@ -357,18 +358,9 @@ my $storage = $conn->get_storage_paths();
my $transferiso;
$transferiso = $config->get_transfer_iso();
-if ($output_method eq 'rhev') {
- $) = "36 36";
- $> = "36";
-}
-
# Open a libguestfs handle on the guest's storage devices
-my $g = get_guestfs_handle($storage, $transferiso);
-
-if ($output_method eq 'rhev') {
- $) = "0";
- $> = "0";
-}
+my $g = new Sys::VirtV2V::GuestfsHandle($storage, $transferiso,
+ $output_method eq 'rhev');
my $os;
my $guestcaps;
@@ -390,11 +382,11 @@ eval {
# can result in failure to umount RHEV export's temporary mount point.
if ($@) {
my $err = $@;
- close_guest_handle();
+ $g->close();
die($err);
}
-close_guest_handle();
+$g->close();
$target->create_guest($os, $dom, $guestcaps);
@@ -418,58 +410,10 @@ END {
###############################################################################
## Helper functions
-sub close_guest_handle
-{
- # Config may cache the guestfs handle, preventing cleanup below
- $config = undef;
-
- if (defined($g)) {
- my $retval = $?;
-
- eval {
- $g->umount_all();
- $g->sync();
- };
- if ($@) {
- warn(user_message(__x("Error cleaning up guest handle: {error}",
- error => $@)));
- $retval ||= 1;
- }
-
- # Note that this undef is what actually causes the underlying handle to
- # be closed. This is required to allow the RHEV target's temporary mount
- # directory to be unmounted and deleted prior to exit.
- $g = undef;
-
- # The above undef causes libguestfs's qemu process to be killed. This
- # may update $?, so we preserve it here.
- $? ||= $retval;
- }
-}
-
sub signal_exit
{
- close_guest_handle();
- exit(1);
-}
-
-sub get_guestfs_handle
-{
- my ($storage, $transferiso) = @_;
- my $interface = "ide";
-
- my $g = open_guest($storage, rw => 1, interface => $interface);
-
- # Add the transfer iso if there is one
- $g->add_drive_ro_with_if($transferiso, $interface)
- if(defined($transferiso));
-
- # Enable autosync to defend against data corruption on unclean shutdown
- $g->set_autosync(1);
-
- $g->launch();
-
- return $g;
+ $g->close() if (defined($g));
+ die(user_message(__x("Received signal {sig}. Exiting.", sig => shift)));
}
# Inspect the guest's storage. Returns an OS hashref as returned by
--
1.7.1
14 years, 2 months
Administrivia: git problem
by Richard W.M. Jones
$ git clone git://git.annexia.org/git/libguestfs.git
Initialized empty Git repository in /tmp/libguestfs/.git/
remote: Counting objects: 13903, done.
remote: Compressing objects: 100% (3093/3093), done.
Receiving objects: 19% (2642/13903), 1.33 MiB | 52 KiB/s
It always stops at the same place.
The particularly strange thing is, it always stops at the same place
_when I run it on the git server itself_.
The problem appears to be something related to the virtual eth0 on
that machine, possibly MTU related, but I'm still looking into it.
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, 2 months
Re: [Libguestfs] febootstrap git empty /lib dir
by Richard W.M. Jones
On Wed, Jun 16, 2010 at 03:38:22PM -0700, Dwayne Fontenot <dwayne.fontenot(a)att.net> wrote:
> Is lib/ supposed to be empty in febootstrap git HEAD?
Yes. Run ./autogen.sh to populate it with gnulib stuff.
Actually, this may not work too well unless you have gnulib checked
out exactly in ../gnulib. I need to ask Jim Meyering nicely if he'll
make gnulib into a submodule of febootstrap.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
14 years, 2 months