Merge pull request #164 from jiangcuo/port-pve-manager
add qemu-server compatible
This commit is contained in:
commit
ebfc40fa2c
@ -0,0 +1,22 @@
|
||||
diff --git a/PVE/API2/Qemu/Machine.pm b/PVE/API2/Qemu/Machine.pm
|
||||
index db6c3d80..19896e3c 100644
|
||||
--- a/PVE/API2/Qemu/Machine.pm
|
||||
+++ b/PVE/API2/Qemu/Machine.pm
|
||||
@@ -38,7 +38,7 @@ __PACKAGE__->register_method({
|
||||
},
|
||||
type => {
|
||||
type => 'string',
|
||||
- enum => ['q35', 'virt'],
|
||||
+ enum => ['q35', 'virt', 'i440fx'],
|
||||
description => "The machine type.",
|
||||
},
|
||||
version => {
|
||||
@@ -50,7 +50,7 @@ __PACKAGE__->register_method({
|
||||
},
|
||||
code => sub {
|
||||
my $machines = eval {
|
||||
- my $raw = file_get_contents('/usr/share/kvm/machine-versions-aarch64.json');
|
||||
+ my $raw = file_get_contents('/usr/share/kvm/machine-versions.json');
|
||||
return from_json($raw, { utf8 => 1 });
|
||||
};
|
||||
die "could not load supported machine versions - $@\n" if $@;
|
||||
@ -0,0 +1,78 @@
|
||||
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
|
||||
index 7110378e..30489608 100644
|
||||
--- a/PVE/API2/Qemu.pm
|
||||
+++ b/PVE/API2/Qemu.pm
|
||||
@@ -17,7 +17,7 @@ use PVE::CGroup;
|
||||
use PVE::Cluster qw (cfs_read_file cfs_write_file);;
|
||||
use PVE::RRD;
|
||||
use PVE::SafeSyslog;
|
||||
-use PVE::Tools qw(extract_param);
|
||||
+use PVE::Tools qw(extract_param get_host_arch);
|
||||
use PVE::Exception qw(raise raise_param_exc raise_perm_exc);
|
||||
use PVE::Storage;
|
||||
use PVE::JSONSchema qw(get_standard_option);
|
||||
@@ -675,6 +675,7 @@ my $hwtypeoptions = {
|
||||
|
||||
my $generaloptions = {
|
||||
'agent' => 1,
|
||||
+ 'arch' => 1,
|
||||
'autostart' => 1,
|
||||
'bios' => 1,
|
||||
'description' => 1,
|
||||
@@ -1225,10 +1226,10 @@ __PACKAGE__->register_method({
|
||||
);
|
||||
$conf->{$_} = $created_opts->{$_} for keys $created_opts->%*;
|
||||
|
||||
- # set default bios to ovmf
|
||||
- if (!$conf->{bios}){
|
||||
- $conf->{bios} = 'ovmf';
|
||||
- }
|
||||
+ # set default bios to ovmf
|
||||
+ if (!$conf->{bios}){
|
||||
+ $conf->{bios} = 'ovmf';
|
||||
+ }
|
||||
|
||||
if (!$conf->{boot}) {
|
||||
my $devs = PVE::QemuServer::get_default_bootdevices($conf);
|
||||
@@ -1243,6 +1244,10 @@ __PACKAGE__->register_method({
|
||||
$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
|
||||
}
|
||||
|
||||
+ if (!$conf->{arch}) {
|
||||
+ $conf->{arch} = get_host_arch();
|
||||
+ }
|
||||
+
|
||||
if ((!defined($conf->{vmgenid}) || $conf->{vmgenid} eq '1') && $arch ne 'aarch64') {
|
||||
$conf->{vmgenid} = PVE::QemuServer::generate_uuid();
|
||||
}
|
||||
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
|
||||
index 4214a7ca..18ab3326 100755
|
||||
--- a/PVE/CLI/qm.pm
|
||||
+++ b/PVE/CLI/qm.pm
|
||||
@@ -1124,11 +1124,11 @@ our $cmddef = {
|
||||
my $vmlist = shift;
|
||||
exit 0 if (!scalar(@$vmlist));
|
||||
|
||||
- printf "%10s %-20s %-10s %-10s %12s %-10s\n",
|
||||
- qw(VMID NAME STATUS MEM(MB) BOOTDISK(GB) PID);
|
||||
+ printf "%10s %-20s %-12s %-10s %-10s %12s %-10s\n",
|
||||
+ qw(VMID NAME ARCH STATUS MEM(MB) BOOTDISK(GB) PID);
|
||||
|
||||
foreach my $rec (sort { $a->{vmid} <=> $b->{vmid} } @$vmlist) {
|
||||
- printf "%10s %-20s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name},
|
||||
+ printf "%10s %-20s %-12s %-10s %-10s %12.2f %-10s\n", $rec->{vmid}, $rec->{name}, $rec->{arch},
|
||||
$rec->{qmpstatus} || $rec->{status},
|
||||
($rec->{maxmem} || 0)/(1024*1024),
|
||||
($rec->{maxdisk} || 0)/(1024*1024*1024),
|
||||
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
|
||||
index d351dfbc..302bf73d 100644
|
||||
--- a/PVE/QemuServer.pm
|
||||
+++ b/PVE/QemuServer.pm
|
||||
@@ -3017,6 +3017,7 @@ sub vmstatus {
|
||||
$d->{cpus} = $conf->{vcpus} if $conf->{vcpus};
|
||||
|
||||
$d->{name} = $conf->{name} || "VM $vmid";
|
||||
+ $d->{arch} = $conf->{arch} || get_host_arch();
|
||||
$d->{maxmem} = get_current_memory($conf->{memory})*(1024*1024);
|
||||
|
||||
if ($conf->{balloon}) {
|
||||
@ -0,0 +1,27 @@
|
||||
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
|
||||
index 30489608..03ba56d5 100644
|
||||
--- a/PVE/API2/Qemu.pm
|
||||
+++ b/PVE/API2/Qemu.pm
|
||||
@@ -1254,13 +1254,20 @@ __PACKAGE__->register_method({
|
||||
|
||||
my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
|
||||
my $machine = $machine_conf->{type};
|
||||
- if (!$machine || $machine =~ m/^(?:pc|q35|virt)$/) {
|
||||
+ if (!$machine){
|
||||
+ if ($conf->{arch} eq 'x86_64'){
|
||||
+ $machine = 'pc';
|
||||
+ }else{
|
||||
+ $machine = 'virt';
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
# always pin Windows' machine version on create, they get to easily confused
|
||||
if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
|
||||
$machine_conf->{type} = PVE::QemuServer::windows_get_pinned_machine_version($machine);
|
||||
$conf->{machine} = PVE::QemuServer::Machine::print_machine($machine_conf);
|
||||
}
|
||||
- }
|
||||
+
|
||||
PVE::QemuServer::Machine::assert_valid_machine_property($conf, $machine_conf);
|
||||
|
||||
$conf->{lock} = 'import' if $live_import_mapping;
|
||||
@ -0,0 +1,32 @@
|
||||
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
|
||||
index df8ea459..d8f79e1d 100644
|
||||
--- a/PVE/QemuServer/CPUConfig.pm
|
||||
+++ b/PVE/QemuServer/CPUConfig.pm
|
||||
@@ -18,6 +18,7 @@ get_cpu_options
|
||||
get_cpu_bitness
|
||||
is_native_arch
|
||||
get_amd_sev_object
|
||||
+get_default_cpu_type
|
||||
);
|
||||
|
||||
# under certain race-conditions, this module might be loaded before pve-cluster
|
||||
@@ -773,13 +774,14 @@ sub get_cpu_from_running_vm {
|
||||
sub get_default_cpu_type {
|
||||
my ($arch, $kvm) = @_;
|
||||
|
||||
- my $cputype = $kvm ? 'kvm64' : 'qemu64';
|
||||
+ # if !kvm ,cpu will set to max for all arch
|
||||
+ my $cputype = 'max';
|
||||
+ if ($kvm){
|
||||
+ $cputype = 'host' if $arch eq 'x86_64';
|
||||
$cputype = 'host' if $arch eq 'aarch64';
|
||||
- $cputype = 'host' if $arch eq 'arm';
|
||||
$cputype = 'rv64' if $arch eq 'riscv64';
|
||||
- $cputype = 'max' if $arch eq 'loongarch64';
|
||||
- $cputype = 'host' if $arch eq 'x86_64';
|
||||
-
|
||||
+ $cputype = 'la464' if $arch eq 'loongarch64';
|
||||
+ }
|
||||
return $cputype;
|
||||
}
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
|
||||
index 03ba56d5..2734110a 100644
|
||||
--- a/PVE/API2/Qemu.pm
|
||||
+++ b/PVE/API2/Qemu.pm
|
||||
@@ -28,7 +28,7 @@ use PVE::GuestImport;
|
||||
use PVE::QemuConfig;
|
||||
use PVE::QemuServer;
|
||||
use PVE::QemuServer::Cloudinit;
|
||||
-use PVE::QemuServer::CPUConfig;
|
||||
+use PVE::QemuServer::CPUConfig qw(get_default_cpu_type);
|
||||
use PVE::QemuServer::Drive qw(checked_parse_volname);
|
||||
use PVE::QemuServer::Helpers;
|
||||
use PVE::QemuServer::ImportDisk;
|
||||
@@ -1244,24 +1244,41 @@ __PACKAGE__->register_method({
|
||||
$conf->{smbios1} = PVE::QemuServer::generate_smbios1_uuid();
|
||||
}
|
||||
|
||||
+ # set default arch for vm
|
||||
+ my $hostarch = get_host_arch();
|
||||
if (!$conf->{arch}) {
|
||||
- $conf->{arch} = get_host_arch();
|
||||
+ $conf->{arch} = $hostarch;
|
||||
}
|
||||
|
||||
if ((!defined($conf->{vmgenid}) || $conf->{vmgenid} eq '1') && $arch ne 'aarch64') {
|
||||
$conf->{vmgenid} = PVE::QemuServer::generate_uuid();
|
||||
}
|
||||
|
||||
- my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
|
||||
- my $machine = $machine_conf->{type};
|
||||
- if (!$machine){
|
||||
+ # We detect the value of machine
|
||||
+ # and if not, force it to be specified
|
||||
+ if (!$conf->{machine}){
|
||||
if ($conf->{arch} eq 'x86_64'){
|
||||
- $machine = 'pc';
|
||||
+ $conf->{machine} = 'pc';
|
||||
}else{
|
||||
- $machine = 'virt';
|
||||
+ $conf->{machine} = 'virt';
|
||||
}
|
||||
}
|
||||
|
||||
+ my $machine_conf = PVE::QemuServer::Machine::parse_machine($conf->{machine});
|
||||
+ my $machine = $machine_conf->{type};
|
||||
+
|
||||
+ # We check the status of the kvm
|
||||
+ # if it is a different architecture, the kvm will be disabled in vm config.
|
||||
+ my $kvm = $conf->{kvm} // 1;
|
||||
+ if ($conf->{arch} ne $hostarch) {
|
||||
+ $kvm = 0;
|
||||
+ }
|
||||
+ $conf->{kvm} = $kvm;
|
||||
+
|
||||
+ if (!$conf->{cpu}) {
|
||||
+ $conf->{cpu} = get_default_cpu_type($arch,$kvm);
|
||||
+ }
|
||||
+
|
||||
# always pin Windows' machine version on create, they get to easily confused
|
||||
if (PVE::QemuServer::Helpers::windows_version($conf->{ostype})) {
|
||||
$machine_conf->{type} = PVE::QemuServer::windows_get_pinned_machine_version($machine);
|
||||
@ -8,3 +8,8 @@ patches/007-bump-version-to-8.3.3+port.patch
|
||||
patches/009-add-gicversion-param.patch
|
||||
patches/010-bump-version-to-8.3.3+port2.patch
|
||||
patches/011-Add-x86_64-cpu-for-compatible-with-x86-host.patch
|
||||
patches/012-Add-i440fx-and-use-new-machine-versions.json.patch
|
||||
patches/013-Add-vm-arch-when-create-and-cli-show.patch
|
||||
patches/015-Set-the-default-machine-according-to-the-different-architecture.patch
|
||||
patches/016-Optimizes-the-get_default_cpu_type-function.patch
|
||||
patches/017-kvm-machine-check-when-vm-create.patch
|
||||
|
||||
Loading…
Reference in New Issue
Block a user