File reset_virtio_after_config.patch of Package virt-v2v

If an online update of a specific kernel version fails (due to it not existing
in the repo, or some other error), an update from the local virt-v2v repo is
attempted. If that fails, virtio is disabled, and any available kernel is
installed. During this process, it is possible to install a virtio capable
kernel. This patch catches that condition, and resets $virtio to a value which
matches the installed kernel.

This patch also fixes the following two issues:

 - Only list valid kernels under grub2 (no symlinks)
 - Ensure $version is populated before checking for /lib/modules/$version

Index: virt-v2v-0.9.1/lib/Sys/VirtConvert/Converter/Linux.pm
===================================================================
--- virt-v2v-0.9.1.orig/lib/Sys/VirtConvert/Converter/Linux.pm
+++ virt-v2v-0.9.1/lib/Sys/VirtConvert/Converter/Linux.pm
@@ -509,8 +509,11 @@ sub list_kernels
                         $g->glob_expand('/boot/vmlinuz-*'),
                         $g->glob_expand('/vmlinuz-*'))
     {
-        push(@kernels, $kernel)
-           unless $kernel =~ /\.(?:dpkg-.*|rpmsave|rpmnew)$/;
+        # Only add normal files (no symbolic links)
+        if ($g->is_file_opts($kernel, followsymlinks=>0)) {
+            push(@kernels, $kernel)
+               unless $kernel =~ /\.(?:dpkg-.*|rpmsave|rpmnew)$/;
+        }
     }
 
     return @kernels;
@@ -732,6 +735,12 @@ sub convert
     # Get an appropriate kernel, or install one if none is available
     my $kernel = _configure_kernel($virtio, $g, $root, $config, $meta, $grub);
 
+    # If _install_capability failed to install a specific version of kernel,
+    #_configure_kernel can install a virtio kernel. If it does, reset virtio
+    if (!$virtio) {
+        $virtio = _supports_virtio($kernel, $g);
+    }
+
     # Install user custom packages
     if (! _install_capability('user-custom', $g, $root, $config, $meta, $grub)) {
         logmsg WARN, __('Failed to install user-custom packages');
@@ -1298,10 +1307,13 @@ sub _is_hv_kernel
 {
     my ($g, $version) = @_;
 
-    # Xen PV kernels can be distinguished from other kernels by their inclusion
-    # of the xennet driver
-    foreach my $entry ($g->find("/lib/modules/$version/")) {
-        return 1 if $entry =~ /(^|\/)xennet\.k?o$/;
+    # If modules directory was not found earlier, $version can be undefined
+    if (defined($version)) {
+        # Xen PV kernels can be distinguished from other kernels by their
+        # inclusion of the xennet driver
+        foreach my $entry ($g->find("/lib/modules/$version/")) {
+            return 1 if $entry =~ /(^|\/)xennet\.k?o$/;
+        }
     }
 
     return 0;