Skip to content

Commit

Permalink
wip: pass cpu topology on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Jul 14, 2023
1 parent 817a5db commit 74e9584
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
8 changes: 6 additions & 2 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ sub _update_isos {
,file_re => 'alpine-standard-3.16.*-x86_64.iso'
,sha256_url => '$url/alpine-standard-3.16.*.iso.sha256'
,min_disk_size => '2'
,options => { machine => 'pc-q35', bios => 'UEFI' }
,options => { machine => 'pc-q35', bios => 'UEFI'
,hardware => { cpu => { cpu => { topology => { threads => 2, cores => 2}}}}
}
}
,alpine381_32 => {
name => 'Alpine 3.16 32 bits'
Expand Down Expand Up @@ -866,7 +868,9 @@ sub _update_isos {
,min_ram => 4
,arch => 'x86_64'
,extra_iso => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.2\d+-\d+/virtio-win-0.1.2\d+.iso'
,options => { machine => 'pc-q35', bios => 'UEFI' }
,options => { machine => 'pc-q35', bios => 'UEFI'
,hardware => { cpu => { cpu => { topology => { threads => 2, cores => 2}}}}
}
}
,empty_32bits => {
name => 'Empty Machine 32 bits'
Expand Down
4 changes: 2 additions & 2 deletions lib/Ravada/VM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ sub _around_create_domain {
$domain->_data('is_compacted' => 1);
$domain->_data('alias' => $alias) if $alias;
$domain->_data('date_status_change', Ravada::Utils::now());
_change_hardware_install($domain,$hardware) if $hardware;
$self->_change_hardware_install($domain,$hardware) if $hardware;

if ($id_base) {
$domain->run_timeout($base->run_timeout)
Expand Down Expand Up @@ -541,7 +541,7 @@ sub _around_create_domain {
return $domain;
}

sub _change_hardware_install($domain, $hardware) {
sub _change_hardware_install($self, $domain, $hardware) {

for my $item (sort keys %$hardware) {
Ravada::Request->change_hardware(
Expand Down
2 changes: 2 additions & 0 deletions lib/Ravada/VM/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,8 @@ sub _domain_create_from_iso {
if $spice_password;
$domain->xml_description();

$self->_change_hardware_install($domain,$iso->{options}->{hardware});

return $domain;
}

Expand Down
11 changes: 8 additions & 3 deletions public/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,14 @@ ravadaApp.directive("solShowMachine", swMach)
}
}
}
if ($scope.id_iso && $scope.id_iso.options
&& $scope.id_iso.options['bios']) {
$scope.bios = $scope.id_iso.options['bios'];
if ($scope.id_iso && $scope.id_iso.options) {
if( $scope.id_iso.options['bios']) {
$scope.bios = $scope.id_iso.options['bios'];
}
if( $scope.id_iso.options['hardware']) {
$scope.hardware = $scope.id_iso.options['hardware'];
}

}

};
Expand Down
1 change: 1 addition & 0 deletions script/rvd_front
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,7 @@ sub req_new_domain {
my $vm = ( $c->param('backend') or 'KVM');
$swap = int($swap * 1024*1024*1024);
my $bios = $c->param('bios');
my $hardware = $c->param('hardware');
my $machine = ($c->param('machine') or '');
$machine =~ s/^string://;
$machine = '' if $machine eq '?';
Expand Down
9 changes: 5 additions & 4 deletions t/kvm/uefi.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@ sub test_threads($vm) {
my $name = new_domain_name();
my $id_iso = search_id_iso('Alpine');

my $n_threads = 4;
my $req = Ravada::Request->create_domain(
name => $name
,vm => $vm->type
,id_iso => $id_iso
,id_owner => user_admin->id
,memory => 512 * 1024
,disk => 1024 * 1024
,options => { hardware => { cpu => { topology => { threads => 4 } }} }
,options => { hardware => { cpu => { cpu => { topology => { threads => $n_threads }}}} }
);
wait_request( debug => 1);
wait_request( debug => 0);
my $domain = $vm->search_domain($name);
ok($domain);
my $config = $domain->xml_description();

my $doc = XML::LibXML->load_xml(string => $config);
my ($topology) = $doc->findnodes("/domain/vcpu/topology");
my ($topology) = $doc->findnodes("/domain/cpu/topology");
ok($topology) or die $domain->name;
die $topology->toString;
is($topology->getAttribute('threads'), $n_threads);

}

Expand Down

0 comments on commit 74e9584

Please sign in to comment.