5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-01-25 06:03:52 +03:00

introduce version_cmp helper for qemu_machine_feature_enabled

will be reused for a "running KVM/QEMU version is at least" helper in
a next patch

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2019-10-23 10:38:12 +02:00
parent d610b14591
commit 19e9b30895

View File

@ -7178,9 +7178,29 @@ sub qemu_machine_feature_enabled {
$current_minor = $2;
}
return 1 if $current_major > $version_major ||
($current_major == $version_major &&
$current_minor >= $version_minor);
return 1 if version_cmp($current_major, $version_major, $current_minor, $version_minor) >= 0;
}
# gets in pairs the versions you want to compares, i.e.:
# ($a-major, $b-major, $a-minor, $b-minor, $a-extra, $b-extra, ...)
# returns 0 if same, -1 if $a is older than $b, +1 if $a is newer than $b
sub version_cmp {
my @versions = @_;
my $size = scalar(@versions);
return 0 if $size == 0;
die "cannot compare odd count of versions" if $size & 1;
for (my $i = 0; $i < $size; $i += 2) {
my ($a, $b) = splice(@versions, 0, 2);
$a //= 0;
$b //= 0;
return 1 if $a > $b;
return -1 if $a < $b;
}
return 0;
}
sub qemu_machine_pxe {