Merge pull request #1992 from SimonFair/7.1-NoVM-Pinning

7.1 no vm pinning
This commit is contained in:
tom mortensen
2025-02-06 12:39:09 -08:00
committed by GitHub
8 changed files with 167 additions and 43 deletions
+19 -3
View File
@@ -19,6 +19,12 @@ $_SERVER['REQUEST_URI'] = 'settings';
require_once "$docroot/webGui/include/Translations.php";
$cpus = explode(';',$_POST['cpus']??'');
$corecount = 0;
foreach ($cpus as $pair) {
unset($cpu1,$cpu2);
[$cpu1, $cpu2] = my_preg_split('/[,-]/',$pair);
if (!$cpu2) $corecount++; else $corecount=$corecount+2;
}
function scan($area, $text) {
return isset($area) ? strpos($area,$text)!==false : false;
@@ -30,9 +36,10 @@ function create($id, $name, $vcpu) {
$total = count($cpus);
$loop = floor(($total-1)/32)+1;
$text = [];
$unit = str_replace([' ','(',')','[',']'],'',$name);
$unit = urlencode(str_replace([' ','(',')','[',']'],'',$name));
$name = urlencode($name);
echo "<td><span id='$id-$unit' style='color:#267CA8;display:none'><i class='fa fa-refresh fa-spin'></i> "._('updating')."</span></td>";
if ($id == "vm") $checkclass = "class=\"vcpu-".htmlspecialchars($name)."\""; else $checkclass = "";
for ($c = 0; $c < $loop; $c++) {
$max = ($c == $loop-1 ? ($total%32?:32) : 32);
for ($n = 0; $n < $max; $n++) {
@@ -41,8 +48,8 @@ function create($id, $name, $vcpu) {
$check1 = ($vcpu && in_array($cpu1, $vcpu)) ? 'checked':'';
$check2 = $cpu2 ? ($vcpu && (in_array($cpu2, $vcpu)) ? 'checked':''):'';
if (empty($text[$n])) $text[$n] = '';
$text[$n] .="<label class='checkbox'><input type='checkbox' name='$name:$cpu1' $check1><span class='checkmark'></span></label><br>";
if ($cpu2) $text[$n] .= "<label class='checkbox'><input type='checkbox' name='$name:$cpu2' $check2><span class='checkmark'></span></label><br>";
$text[$n] .="<label class='checkbox'><input type='checkbox' $checkclass name='$name:$cpu1' $check1><span class='checkmark'></span></label><br>";
if ($cpu2) $text[$n] .= "<label class='checkbox'><input type='checkbox' $checkclass name='$name:$cpu2' $check2><span class='checkmark'></span></label><br>";
}
}
echo implode(array_map(function($t){return "<td>$t</td>";},$text));
@@ -66,6 +73,15 @@ case 'vm':
$uuid = $lv->domain_get_uuid($lv->get_domain_by_name($vm));
$cfg = domain_to_config($uuid);
echo "<tr><td>$vm</td>";
if ($cfg['domain']['vcpu'] >0 ) $disabled = "disabled"; else $disabled = "";
$vmenc = urlencode($vm);
$vcpuselect="<select id='vm-$vmenc-vcpu' name='$vmenc' class='narrow vcpus-$vmenc' title='"._("vcpu allocated to vm")."' $disabled>";
for ($i = 1; $i <= ($corecount); $i++) {
$vcpuselect .= mk_option($cfg['domain']['vcpus'], $i, $i);
}
$vcpuselect .= '</select>';
if ($disabled == "disabled") $buttontext = htmlspecialchars("Deselect All"); else $buttontext = htmlspecialchars("Select All");
echo "<td>$vcpuselect<input type=\"button\" value=\""._("$buttontext")."\" id=\"vmbtnvCPUSelect;$vmenc\" name=\"vmbtnvCPUSelect$vmenc\" onclick=\"vcpupins(this)\" /></td>";
create('vm', $vm, $cfg['domain']['vcpu']);
echo "</tr>";
}
+9 -6
View File
@@ -16,7 +16,7 @@ require_once "$docroot/webGui/include/Helpers.php";
$_SERVER['REQUEST_URI'] = 'settings';
require_once "$docroot/webGui/include/Translations.php";
$map = $changes = [];
$vcpus = $map = $changes = [];
$data = json_decode($_POST['data'], true);
@@ -30,6 +30,9 @@ foreach ($data['cpus'] as $key => $val) {
[$name, $cpu] = my_explode(':', $key);
$map[decode($name)] .= "$cpu,";
}
foreach ($data['cores'] as $name => $val) {
$vcpu[decode($name)] .= $val;
}
/* map holds the list of each vm, container or isolcpus and its newly proposed cpu assignments */
$map = array_map(function($d) {
return substr($d, 0, -1);
@@ -40,13 +43,13 @@ switch ($data['id']) {
/* report changed vms in temporary file */
require_once "$docroot/plugins/dynamix.vm.manager/include/libvirt_helpers.php";
foreach ($map as $name => $cpuset) {
if (!strlen($cpuset)) {
$reply = ['error' => _("Not allowed to assign ZERO cores")];
break 2;
}
$uuid = $lv->domain_get_uuid($lv->get_domain_by_name($name));
$cfg = domain_to_config($uuid);
$cpus = implode(',', $cfg['domain']['vcpu']);
if ($cfg['domain']['vcpu']) $cpus = implode(',', $cfg['domain']['vcpu']); else $cpus = "";
if (!strlen($cpuset)) {
$cpuset = -1 * $vcpu[$name];
$cpus = -1 * $cfg['domain']['vcpus'];
}
/* only act on changes */
if ($cpus != $cpuset || strlen($cpus) != strlen($cpuset)) {
$changes[] = $name;
+19 -14
View File
@@ -40,7 +40,8 @@ case 'vm':
/* Read new CPU assignments and delete the temporary file */
$cpuset = explode(',', file_get_contents($file));
unlink($file);
$vcpus = count($cpuset);
$nopin = false;
if ($cpuset[0] >= 0) $vcpus = count($cpuset); else {$vcpus = -1 * $cpuset[0]; $nopin = true; }
/* Initial cores/threads assignment */
$cores = $vcpus;
@@ -68,22 +69,26 @@ case 'vm':
/* Preserve existing emulatorpin attributes */
$pin = [];
foreach ($xml->cputune->emulatorpin->attributes() as $key => $value) {
$pin[$key] = (string) $value;
if (isset($xml->cputune)) {
foreach ($xml->cputune->emulatorpin->attributes() as $key => $value) {
$pin[$key] = (string) $value;
}
}
unset($xml->cputune);
/* Add new cputune configuration */
$xml->addChild('cputune');
for ($i = 0; $i < $vcpus; $i++) {
$vcpu = $xml->cputune->addChild('vcpupin');
$vcpu['vcpu'] = $i;
$vcpu['cpuset'] = _var($cpuset, $i);
}
if ($pin) {
$attr = $xml->cputune->addChild('emulatorpin');
foreach ($pin as $key => $value) {
$attr[$key] = $value;
if (!$nopin) {
$xml->addChild('cputune');
for ($i = 0; $i < $vcpus; $i++) {
$vcpu = $xml->cputune->addChild('vcpupin');
$vcpu['vcpu'] = $i;
$vcpu['cpuset'] = _var($cpuset, $i);
}
if ($pin) {
$attr = $xml->cputune->addChild('emulatorpin');
foreach ($pin as $key => $value) {
$attr[$key] = $value;
}
}
}
@@ -109,7 +114,7 @@ case 'vm':
/* Backup NVRAM, undefine the domain, and restore NVRAM */
$lv->nvram_backup($uuid);
$lv->domain_undefine($dom);
#$lv->domain_undefine($dom);
$lv->nvram_restore($uuid);
/* Define the domain with the updated XML configuration */