[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 7/8] Converter: add default <features> if none are present



Add ACPI if the guest and hypervisor support it.
Add APIC and PAE if the hypervisor supports it.
---
 lib/Sys/VirtV2V/Converter.pm |   66 ++++++++++++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/lib/Sys/VirtV2V/Converter.pm b/lib/Sys/VirtV2V/Converter.pm
index 4115c1e..a53dd92 100644
--- a/lib/Sys/VirtV2V/Converter.pm
+++ b/lib/Sys/VirtV2V/Converter.pm
@@ -314,28 +314,58 @@ sub _configure_capabilities
         }
     }
 
-    # Check that /domain/features are listed in capabilities
-    # Get a list of supported features
-    my %features;
-    foreach my $feature ($guestcap->findnodes('features/*')) {
-        $features{$feature->getNodeName()} = 1;
-    }
+    # Get the domain features node
+    my ($domfeatures) = $dom->findnodes('/domain/features');
+
+    # Check existing features are supported by the hypervisor
+    if (defined($domfeatures)) {
+        # Check that /domain/features are listed in capabilities
+        # Get a list of supported features
+        my %features;
+        foreach my $feature ($guestcap->findnodes('features/*')) {
+            $features{$feature->getNodeName()} = 1;
+        }
 
-    foreach my $feature ($dom->findnodes('/domain/features/*')) {
-        my $name = $feature->getNodeName();
+        foreach my $feature ($domfeatures->findnodes('*')) {
+            my $name = $feature->getNodeName();
 
-        if (!exists($features{$name})) {
-            print STDERR user_message
-                (__x("The connected hypervisor does not support ".
-                     "feature {feature}", feature => $name));
-            $feature->getParentNode()->removeChild($feature);
+            if (!exists($features{$name})) {
+                print STDERR user_message
+                    (__x("The connected hypervisor does not support ".
+                         "feature {feature}", feature => $name));
+                $feature->getParentNode()->removeChild($feature);
+            }
+
+            if ($name eq 'acpi' && !$guestcaps->{acpi}) {
+                print STDERR user_message
+                   (__"The target guest does not support acpi under KVM. ACPI ".
+                      "will be disabled.");
+                $feature->getParentNode()->removeChild($feature);
+            }
         }
+    }
 
-        if ($name eq 'acpi' && !$guestcaps->{acpi}) {
-            print STDERR user_message
-                (__"The target guest does not support acpi under KVM. ACPI ".
-                   "will be disabled.");
-            $feature->getParentNode()->removeChild($feature);
+    # Add a features element if there isn't one already
+    else {
+        $domfeatures = $dom->createElement('features');
+        my ($root) = $dom->findnodes('/domain');
+        $root->appendChild($domfeatures);
+    }
+
+    # Add acpi support if the guest supports it
+    if ($guestcaps->{acpi}) {
+        $domfeatures->appendChild($dom->createElement('acpi'));
+    }
+
+    # Add apic and pae if they're supported by the hypervisor and not already
+    # there
+    foreach my $feature ('apic', 'pae') {
+        my ($d) = $domfeatures->findnodes($feature);
+        next if (defined($d));
+
+        my ($c) = $guestcap->findnodes("features/$feature");
+        if (defined($c)) {
+            $domfeatures->appendChild($dom->createElement($feature));
         }
     }
 }
-- 
1.6.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]