Skip to content

Commit 7528c27

Browse files
committed
add qemu-server compatible
1 parent e06098c commit 7528c27

6 files changed

Lines changed: 225 additions & 0 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/PVE/API2/Qemu/Machine.pm b/PVE/API2/Qemu/Machine.pm
2+
index db6c3d80..19896e3c 100644
3+
--- a/PVE/API2/Qemu/Machine.pm
4+
+++ b/PVE/API2/Qemu/Machine.pm
5+
@@ -38,7 +38,7 @@ __PACKAGE__->register_method({
6+
},
7+
type => {
8+
type => 'string',
9+
- enum => ['q35', 'virt'],
10+
+ enum => ['q35', 'virt', 'i440fx'],
11+
description => "The machine type.",
12+
},
13+
version => {
14+
@@ -50,7 +50,7 @@ __PACKAGE__->register_method({
15+
},
16+
code => sub {
17+
my $machines = eval {
18+
- my $raw = file_get_contents('/usr/share/kvm/machine-versions-aarch64.json');
19+
+ my $raw = file_get_contents('/usr/share/kvm/machine-versions.json');
20+
return from_json($raw, { utf8 => 1 });
21+
};
22+
die "could not load supported machine versions - $@\n" if $@;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
2+
index 7110378e..30489608 100644
3+
--- a/PVE/API2/Qemu.pm
4+
+++ b/PVE/API2/Qemu.pm
5+
@@ -17,7 +17,7 @@ use PVE::CGroup;
6+
use PVE::Cluster qw (cfs_read_file cfs_write_file);;
7+
use PVE::RRD;
8+
use PVE::SafeSyslog;
9+
-use PVE::Tools qw(extract_param);
10+
+use PVE::Tools qw(extract_param get_host_arch);
11+
use PVE::Exception qw(raise raise_param_exc raise_perm_exc);
12+
use PVE::Storage;
13+
use PVE::JSONSchema qw(get_standard_option);
14+
@@ -675,6 +675,7 @@ my $hwtypeoptions = {
15+
16+
my $generaloptions = {
17+
'agent' => 1,
18+
+ 'arch' => 1,
19+
'autostart' => 1,
20+
'bios' => 1,
21+
'description' => 1,
22+
@@ -1225,10 +1226,10 @@ __PACKAGE__->register_method({
23+
);
24+
$conf->{$_} = $created_opts->{$_} for keys $created_opts->%*;
25+
26+
- # set default bios to ovmf
27+
- if (!$conf->{bios}){
28+
- $conf->{bios} = 'ovmf';
29+
- }
30+
+ # set default bios to ovmf
31+
+ if (!$conf->{bios}){
32+
+ $conf->{bios} = 'ovmf';
33+
+ }
34+
35+
if (!$conf->{boot}) {
36+
my $devs = PVE::QemuServer::get_default_bootdevices($conf);
37+
@@ -1243,6 +1244,10 @@ __PACKAGE__->register_method({
38+
$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
39+
}
40+
41+
+ if (!$conf->{arch}) {
42+
+ $conf->{arch} = get_host_arch();
43+
+ }
44+
+
45+
if ((!defined($conf->{vmgenid}) || $conf->{vmgenid} eq '1') && $arch ne 'aarch64') {
46+
$conf->{vmgenid} = PVE::QemuServer::generate_uuid();
47+
}
48+
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
49+
index 4214a7ca..18ab3326 100755
50+
--- a/PVE/CLI/qm.pm
51+
+++ b/PVE/CLI/qm.pm
52+
@@ -1124,11 +1124,11 @@ our $cmddef = {
53+
my $vmlist = shift;
54+
exit 0 if (!scalar(@$vmlist));
55+
56+
- printf "%10s %-20s %-10s %-10s %12s %-10s\n",
57+
- qw(VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID);
58+
+ printf "%10s %-20s %-12s %-10s %-10s %12s %-10s\n",
59+
+ qw(VMID NAME ARCH STATUS MEM(MB) BOOTDISK(GB) PID);
60+
61+
foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) {
62+
- printf "%10s %-20s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name},
63+
+ printf "%10s %-20s %-12s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name}, $rec->{arch},
64+
$rec->{qmpstatus} || $rec->{status},
65+
($rec->{maxmem} || 0)/(1024*1024),
66+
($rec->{maxdisk} || 0)/(1024*1024*1024),
67+
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
68+
index d351dfbc..302bf73d 100644
69+
--- a/PVE/QemuServer.pm
70+
+++ b/PVE/QemuServer.pm
71+
@@ -3017,6 +3017,7 @@ sub vmstatus {
72+
$d->{cpus} = $conf->{vcpus} if $conf->{vcpus};
73+
74+
$d->{name} = $conf->{name} || "VM $vmid";
75+
+ $d->{arch} = $conf->{arch} || get_host_arch();
76+
$d->{maxmem} = get_current_memory($conf->{memory})*(1024*1024);
77+
78+
if ($conf->{balloon}) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
2+
index 30489608..03ba56d5 100644
3+
--- a/PVE/API2/Qemu.pm
4+
+++ b/PVE/API2/Qemu.pm
5+
@@ -1254,13 +1254,20 @@ __PACKAGE__->register_method({
6+
7+
my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
8+
my $machine = $machine_conf->{type};
9+
- if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) {
10+
+ if (!$machine){
11+
+ if ($conf->{arch} eq 'x86_64'){
12+
+ $machine = 'pc';
13+
+ }else{
14+
+ $machine = 'virt';
15+
+ }
16+
+ }
17+
+
18+
# always pin Windows' machine version on create, they get to easily confused
19+
if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
20+
$machine_conf->{type} = PVE::QemuServer::windows_get_pinned_machine_version($machine);
21+
$conf->{machine} = PVE::QemuServer::Machine::print_machine($machine_conf);
22+
}
23+
- }
24+
+
25+
PVE::QemuServer::Machine::assert_valid_machine_property($conf, $machine_conf);
26+
27+
$conf->{lock} = 'import' if $live_import_mapping;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
2+
index df8ea459..d8f79e1d 100644
3+
--- a/PVE/QemuServer/CPUConfig.pm
4+
+++ b/PVE/QemuServer/CPUConfig.pm
5+
@@ -18,6 +18,7 @@ get_cpu_options
6+
get_cpu_bitness
7+
is_native_arch
8+
get_amd_sev_object
9+
+get_default_cpu_type
10+
);
11+
12+
# under certain race-conditions, this module might be loaded before pve-cluster
13+
@@ -773,13 +774,14 @@ sub get_cpu_from_running_vm {
14+
sub get_default_cpu_type {
15+
my ($arch, $kvm) = @_;
16+
17+
- my $cputype = $kvm ? 'kvm64' : 'qemu64';
18+
+ # if !kvm ,cpu will set to max for all arch
19+
+ my $cputype = 'max';
20+
+ if ($kvm){
21+
+ $cputype = 'host' if $arch eq 'x86_64';
22+
$cputype = 'host' if $arch eq 'aarch64';
23+
- $cputype = 'host' if $arch eq 'arm';
24+
$cputype = 'rv64' if $arch eq 'riscv64';
25+
- $cputype = 'max' if $arch eq 'loongarch64';
26+
- $cputype = 'host' if $arch eq 'x86_64';
27+
-
28+
+ $cputype = 'la464' if $arch eq 'loongarch64';
29+
+ }
30+
return $cputype;
31+
}
32+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
2+
index 03ba56d5..2734110a 100644
3+
--- a/PVE/API2/Qemu.pm
4+
+++ b/PVE/API2/Qemu.pm
5+
@@ -28,7 +28,7 @@ use PVE::GuestImport;
6+
use PVE::QemuConfig;
7+
use PVE::QemuServer;
8+
use PVE::QemuServer::Cloudinit;
9+
-use PVE::QemuServer::CPUConfig;
10+
+use PVE::QemuServer::CPUConfig qw(get_default_cpu_type);
11+
use PVE::QemuServer::Drive qw(checked_parse_volname);
12+
use PVE::QemuServer::Helpers;
13+
use PVE::QemuServer::ImportDisk;
14+
@@ -1244,24 +1244,41 @@ __PACKAGE__->register_method({
15+
$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
16+
}
17+
18+
+ # set default arch for vm
19+
+ my $hostarch = get_host_arch();
20+
if (!$conf->{arch}) {
21+
- $conf->{arch} = get_host_arch();
22+
+ $conf->{arch} = $hostarch;
23+
}
24+
25+
if ((!defined($conf->{vmgenid}) || $conf->{vmgenid} eq '1') && $arch ne 'aarch64') {
26+
$conf->{vmgenid} = PVE::QemuServer::generate_uuid();
27+
}
28+
29+
- my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
30+
- my $machine = $machine_conf->{type};
31+
- if (!$machine){
32+
+ # We detect the value of machine
33+
+ # and if not, force it to be specified
34+
+ if (!$conf->{machine}){
35+
if ($conf->{arch} eq 'x86_64'){
36+
- $machine = 'pc';
37+
+ $conf->{machine} = 'pc';
38+
}else{
39+
- $machine = 'virt';
40+
+ $conf->{machine} = 'virt';
41+
}
42+
}
43+
44+
+ my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
45+
+ my $machine = $machine_conf->{type};
46+
+
47+
+ # We check the status of the kvm
48+
+ # if it is a different architecture, the kvm will be disabled in vm config.
49+
+ my $kvm = $conf->{kvm} // 1;
50+
+ if ($conf->{arch} ne $hostarch) {
51+
+ $kvm = 0;
52+
+ }
53+
+ $conf->{kvm} = $kvm;
54+
+
55+
+ if (!$conf->{cpu}) {
56+
+ $conf->{cpu} = get_default_cpu_type($arch,$kvm);
57+
+ }
58+
+
59+
# always pin Windows' machine version on create, they get to easily confused
60+
if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
61+
$machine_conf->{type} = PVE::QemuServer::windows_get_pinned_machine_version($machine);

‎packages/qemu-server/series‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ patches/007-bump-version-to-8.3.3+port.patch
88
patches/009-add-gicversion-param.patch
99
patches/010-bump-version-to-8.3.3+port2.patch
1010
patches/011-Add-x86_64-cpu-for-compatible-with-x86-host.patch
11+
patches/012-Add-i440fx-and-use-new-machine-versions.json.patch
12+
patches/013-Add-vm-arch-when-create-and-cli-show.patch
13+
patches/015-Set-the-default-machine-according-to-the-different-architecture.patch
14+
patches/016-Optimizes-the-get_default_cpu_type-function.patch
15+
patches/017-kvm-machine-check-when-vm-create.patch

0 commit comments

Comments
 (0)