[pve-devel] [PATCH 2/4] introduce version_to_int

Stefan Priebe s.priebe at profihost.ag
Sun May 26 22:55:04 CEST 2013


Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
---
 PVE/QemuServer.pm |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 47da506..f1c07fc 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -669,6 +669,18 @@ sub kvm_user_version {
 
 }
 
+sub version_to_int {
+    my $ver = shift;
+
+    if ($ver =~ m/^(\d+)\.(\d+)$/) {
+        return $1*1000000+$2*1000;
+    } elsif ($ver =~ m/^(\d+)\.(\d+)\.(\d+)$/) {
+        return $1*1000000+$2*1000+$3;
+    }
+
+    die "Cannot read version $ver\n";
+}
+
 my $kernel_has_vhost_net = -c '/dev/vhost-net';
 
 sub disknames {
@@ -2226,12 +2238,7 @@ sub config_to_command {
     my $pciaddr = '';
     my $bridges = {};
     my $kvmver = kvm_user_version();
-    my $vernum = 0; # unknown
-    if ($kvmver =~ m/^(\d+)\.(\d+)$/) {
-	$vernum = $1*1000000+$2*1000;
-    } elsif ($kvmver =~ m/^(\d+)\.(\d+)\.(\d+)$/) {
-	$vernum = $1*1000000+$2*1000+$3;
-    }
+    my $vernum = version_to_int($kvmver);
 
     die "detected old qemu-kvm binary ($kvmver)\n" if $vernum < 15000;
 
-- 
1.7.10.4




More information about the pve-devel mailing list