 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH 1/3] Fix RHEV cleanup on unclean shutdown
                                
                                
                                
                                    
                                        by Matthew Booth
                                    
                                
                                
                                        Cleanup was not happening properly if a migration to RHEV was killed
prematurely with a Ctrl-C. Firstly, the SIGINT and SIGQUIT handlers were not
being registered early enough in virt-v2v.pl. Secondly, if Ctrl-C killed the
guestfs qemu process first it would deliver a SIGPIPE to v2v, which caused an
unclean shutdown without cleanup.
Fixes RHBZ#596015
---
 v2v/virt-v2v.pl |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index bed69a0..36297ed 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -214,6 +214,14 @@ Display version number and exit.
 
 =cut
 
+$SIG{'INT'} = \&signal_exit;
+$SIG{'QUIT'} = \&signal_exit;
+
+# SIGPIPE will cause an untidy exit of the perl process, without calling
+# destructors. We don't rely on it anywhere, as we check for errors when reading
+# from or writing to a pipe.
+$SIG{'PIPE'} = 'IGNORE';
+
 # Initialise the message output prefix
 Sys::VirtV2V::UserMessage->set_identifier('virt-v2v');
 
@@ -362,9 +370,6 @@ if ($output_method eq 'rhev') {
     $> = "0";
 }
 
-$SIG{'INT'} = \&close_guest_handle;
-$SIG{'QUIT'} = \&close_guest_handle;
-
 # Inspect the guest
 my $os = inspect_guest($g);
 
@@ -425,6 +430,12 @@ sub close_guest_handle
     }
 }
 
+sub signal_exit
+{
+    close_guest_handle();
+    exit(1);
+}
+
 sub get_guestfs_handle
 {
     my ($storage, $transferiso) = @_;
-- 
1.7.0.1
                                
                         
                        
                                
                                15 years, 4 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                                
                                 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH 1/2] Target: Pass os description to create_guest
                                
                                
                                
                                    
                                        by Matthew Booth
                                    
                                
                                
                                        This will allow use of raw data from os description in addition to libvirt XML
when writing guest output.
---
 lib/Sys/VirtV2V/Target/LibVirt.pm |    2 +-
 lib/Sys/VirtV2V/Target/RHEV.pm    |    2 +-
 v2v/virt-v2v.pl                   |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/Sys/VirtV2V/Target/LibVirt.pm b/lib/Sys/VirtV2V/Target/LibVirt.pm
index e21a21f..cb9961d 100644
--- a/lib/Sys/VirtV2V/Target/LibVirt.pm
+++ b/lib/Sys/VirtV2V/Target/LibVirt.pm
@@ -298,7 +298,7 @@ Create the guest in the target
 sub create_guest
 {
     my $self = shift;
-    my ($dom, $guestcaps) = @_;
+    my ($desc, $dom, $guestcaps) = @_;
 
     my $vmm = $self->{vmm};
 
diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm
index 65800cd..7c96f0e 100644
--- a/lib/Sys/VirtV2V/Target/RHEV.pm
+++ b/lib/Sys/VirtV2V/Target/RHEV.pm
@@ -564,7 +564,7 @@ Create the guest in the target
 sub create_guest
 {
     my $self = shift;
-    my ($dom, $guestcaps) = @_;
+    my ($desc, $dom, $guestcaps) = @_;
 
     # Get the name of the guest
     my ($name) = $dom->findnodes('/domain/name/text()');
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index bed69a0..96e89d1 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -378,7 +378,7 @@ my $guestcaps = Sys::VirtV2V::Converter->convert($g, $guestos,
 
 close_guest_handle();
 
-$target->create_guest($dom, $guestcaps);
+$target->create_guest($os, $dom, $guestcaps);
 
 my ($name) = $dom->findnodes('/domain/name/text()');
 $name = $name->getNodeValue();
-- 
1.7.0.1
                                
                         
                        
                                
                                15 years, 4 months
                        
                        
                 
         
 
        
            
        
        
        
            
        
        
        
                
                        
                                
                                 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH] ESX: Fix storage URL if storage has a snapshot
                                
                                
                                
                                    
                                        by Matthew Booth
                                    
                                
                                
                                        If an ESX guest has a snapshot, the path the libvirt driver gives us will look
like:
  [yellow:storage1] RHEL4-X/RHEL4-X-000003.vmdk
instead of:
  [yellow:storage1] RHEL4-X/RHEL4-X.vmdk
The current path mangling code does take this into account.
This change makes it use the current mechanism first, but try again after
removing a '-\d+' suffix if it gets a 404. Trying twice should make it continue
to work in the event that a local naming scheme matches the suffix used for
snapshots. Ideally we would be able to get this information from the libvirt
driver, but it's not implemented yet.
---
 lib/Sys/VirtV2V/Transfer/ESX.pm |   52 +++++++++++++++++++++++++++++++-------
 1 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/lib/Sys/VirtV2V/Transfer/ESX.pm b/lib/Sys/VirtV2V/Transfer/ESX.pm
index 5d6b586..faf872d 100644
--- a/lib/Sys/VirtV2V/Transfer/ESX.pm
+++ b/lib/Sys/VirtV2V/Transfer/ESX.pm
@@ -102,9 +102,7 @@ sub get_volume
     my $datastore = $1;
     my $vmdk = $2;
 
-    my $url = URI->new("https://".$self->{_v2v_server});
-    $url->path("/folder/$vmdk-flat.vmdk");
-    $url->query_form(dcPath => "ha-datacenter", dsName => $datastore);
+    my $url = _get_vol_url($self->{_v2v_server}, $vmdk, $datastore);
 
     # Replace / with _ so the vmdk name can be used as a volume name
     my $volname = $vmdk;
@@ -125,16 +123,39 @@ sub get_volume
     # We could do this with a single GET request. The problem with this is that
     # you have to create the volume before writing to it. If the volume creation
     # takes a very long time, the transfer may fail in the mean time.
-    my $r = $self->head($url);
-    if ($r->is_success) {
-        $self->verify_certificate($r) unless ($self->{_v2v_noverify});
-        $self->create_volume($r);
-    } else {
-        $self->report_error($r);
+    my $retried = 0;
+    SIZE: for(;;) {
+        my $r = $self->head($url);
+        if ($r->is_success) {
+            $self->verify_certificate($r) unless ($self->{_v2v_noverify});
+            $self->create_volume($r);
+            last SIZE;
+        }
+
+        # If a disk is actually a snapshot image it will have '-00000n'
+        # appended to its name, e.g.:
+        #  [yellow:storage1] RHEL4-X/RHEL4-X-000003.vmdk
+        # The flat storage is still called RHEL4-X-flat, however.
+        # If we got a 404 and the vmdk name looks like it might be a snapshot,
+        # try again without the snapshot suffix.
+        # XXX: We're in flaky heuristic territory here. When the libvirt ESX
+        # driver implements the volume apis we should look for this information
+        # there instead.
+        elsif ($r->code == 404 && $retried == 0) {
+            $retried = 1;
+            if ($vmdk =~ /^(.*)-\d+$/) {
+                $vmdk = $1;
+                $url = _get_vol_url($self->{_v2v_server}, $vmdk, $datastore);
+            }
+        }
+
+        else {
+            $self->report_error($r);
+        }
     }
 
     $self->{_v2v_received} = 0;
-    $r = $self->get($url,
+    my $r = $self->get($url,
                     ':content_cb' => sub { $self->handle_data(@_); },
                     ':read_size_hint' => 64 * 1024);
 
@@ -160,6 +181,17 @@ sub get_volume
     $self->report_error($r);
 }
 
+sub _get_vol_url
+{
+    my ($server, $vmdk, $datastore) = @_;
+
+    my $url = URI->new("https://".$server);
+    $url->path("/folder/$vmdk-flat.vmdk");
+    $url->query_form(dcPath => "ha-datacenter", dsName => $datastore);
+
+    return $url;
+}
+
 sub report_error
 {
     my $self = shift;
-- 
1.7.0.1
                                
                         
                        
                                
                                15 years, 4 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                        
                                
                                
                                        
                                                
                                        
                                        
                                        [PATCH] ESX: Always validate SSL certificate
                                
                                
                                
                                    
                                        by Matthew Booth
                                    
                                
                                
                                        Since fetching storage from ESX was split into separate HEAD and GET requests,
the SSL certificate has only been validated on the HEAD request. It should be
validated on both.
---
 lib/Sys/VirtV2V/Transfer/ESX.pm |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/Sys/VirtV2V/Transfer/ESX.pm b/lib/Sys/VirtV2V/Transfer/ESX.pm
index f638149..5d6b586 100644
--- a/lib/Sys/VirtV2V/Transfer/ESX.pm
+++ b/lib/Sys/VirtV2V/Transfer/ESX.pm
@@ -143,6 +143,8 @@ sub get_volume
         my $died = $r->header('X-Died');
         die($died) if (defined($died));
 
+        $self->verify_certificate($r) unless ($self->{_v2v_noverify});
+
         # It reports success even if we didn't receive the whole file
         die(user_message(__x("Didn't receive full volume. Received {received} ".
                              "of {total} bytes.",
-- 
1.7.0.1
                                
                         
                        
                                
                                15 years, 4 months
                        
                        
                 
         
 
        
            
        
        
        
                
                        
                                
                                 
                                        
                                
                         
                        
                                
                                
                                        
                                                
                                        
                                        
                                        windows v2v related patches
                                
                                
                                
                                    
                                        by Amos Benari
                                    
                                
                                
                                        1.       The first (0003) is a patch I already sent it disables all vmware
tools on the windows guest.
2.       The next one (0005) is a refactoring of the code to prevent
downloading the registry hive multiple times.
3.       (0006) removes vmware run entries in the software hive.
4.       (0007) disable the parallel port driver.
5.       (0008) is reverting some of the changes in patch (0003), I'll
explain that one a bit:
I tested the v2v conversion and found that in the first run windows plug
and play doesn't find the old keyboard
and as a result it turns off the i8042prt service that is responsible for
the keyboard. This means no keyboard for 
VNC users (rdesktop users have a different keyboard mechanism that does
continue to work). As a result of this 
test, I thought that because the only service that really must be disabled
is the tool service (the one that fails  to
start and create the ugly message) We better be as little intrusive as
possible and disable the minimal set.
 
Amos.
 
                                
                         
                        
                                
                                15 years, 4 months