Merge pull request #1492 from SimonFair/QEMU-Cmdline-and-Clocks

QEMU cmdline
This commit is contained in:
tom mortensen
2023-11-04 18:15:05 -07:00
committed by GitHub
3 changed files with 58 additions and 5 deletions
@@ -987,6 +987,12 @@
}
function appendqemucmdline($xml,$cmdline) {
$newxml = $xml ;
if ($cmdline != null) $newxml = str_replace("</domain>",$cmdline."\n</domain>",$xml) ;
return $newxml ;
}
function domain_new($config) {
// attempt to create all disk images if needed
@@ -1010,6 +1016,8 @@
// generate xml for this domain
$strXML = $this->config_to_xml($config);
$qemucmdline = $config['qemucmdline'];
$strXML = $this->appendqemucmdline($strXML,$qemucmdline) ;
// Start the VM now if requested
@@ -1701,7 +1709,7 @@
if (strpos($xml,'<qemu:commandline>')) {
$tmp = explode("\n", $xml);
for ($i = 0; $i < sizeof($tmp); $i++)
if (strpos('.'.$tmp[$i], "<domain type='kvm'"))
if (strpos('.'.$tmp[$i], "<domain type='kvm'") || strpos('.'.$tmp[$i], '<domain type="kvm"'))
$tmp[$i] = "<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>";
$xml = join("\n", $tmp);
}
@@ -1300,7 +1300,9 @@ private static $encoding = 'UTF-8';
'pci' => $arrOtherDevices,
'nic' => $arrNICs,
'usb' => $arrUSBDevs,
'shares' => $lv->domain_get_mount_filesystems($res)
'shares' => $lv->domain_get_mount_filesystems($res),
'qemucmdline' => getQEMUCmdLine($strDOMXML),
'clocks' => getClocks($strDOMXML)
];
}
@@ -1450,12 +1452,39 @@ private static $encoding = 'UTF-8';
function getClocks($xml) {
$clocks = new SimpleXMLElement($xml);
$clocks = $clocks->clock ;
return json_encode($clocks); ;
$clocks = json_decode(json_encode($clocks->clock),true) ;
$arrClocks = [
"offset" => $clocks['@attributes']['offset'] ,
"hpet" => [
"present" => "no",
"tickpolicy" => "delay"
],
"hypervclock" => [
"present" => "no",
"tickpolicy" => "delay"
],
"pit" => [
"present" => "no",
"tickpolicy" => "delay"
],
"rtc" => [
"present" => "no",
"tickpolicy" => "delay"
]
] ;
foreach ($clocks['timer'] as $timer) {
$name = $timer["@attributes"]["name"] ;
$tickpolicy = $timer["@attributes"]["tickpolicy"] ;
$present = $timer["@attributes"]["present"] ;
if (isset($present)) $arrClocks[$name]['present'] = $present ;
if (isset($tickpolicy)) $arrClocks[$name]['tickpolicy'] = $tickpolicy ;
}
return json_encode($arrClocks) ;
}
function getQEMUCmdLine($xml) {
$x = strpos($xml,"<qemu:commandline>", 0) ;
if ($x === false) return null ;
$y = strpos($xml,"</qemu:commandline>", 0) ;
$z=$y ;
while ($y!=false) {
@@ -229,6 +229,7 @@
array_update_recursive($arrExistingConfig, $arrUpdatedConfig);
$arrConfig = array_replace_recursive($arrExistingConfig, $arrUpdatedConfig);
$xml = custom::createXML('domain',$arrConfig)->saveXML();
$xml = $lv->appendqemucmdline($xml,$_POST["qemucmdline"]) ;
} else {
echo json_encode(['error' => $error]);
exit;
@@ -291,6 +292,7 @@
<input type="hidden" name="domain[arch]" value="<?=htmlspecialchars($arrConfig['domain']['arch'])?>">
<input type="hidden" name="domain[oldname]" id="domain_oldname" value="<?=htmlspecialchars($arrConfig['domain']['name'])?>">
<input type="hidden" name="domain[memoryBacking]" id="domain_memorybacking" value="<?=htmlspecialchars($arrConfig['domain']['memoryBacking'])?>">
<input type="hidden" name="clocks" value="<?=htmlspecialchars($arrConfig['clocks'])?>">
<table>
<tr>
@@ -1416,6 +1418,20 @@
<p>Use boot order to set device as bootable and boot sequence. Only NVMe and Network devices (PCI types 0108 and 02xx) supported for boot order.</p>
</blockquote>
<table>
<tr>
<td>_(QEMU Command Line)_:</td>
<td>
<textarea id="qemucmdline" name="qemucmdline" rows=15 style="width: 850px"><?=htmlspecialchars($arrConfig['qemucmdline'])?></textarea></td></tr>
</td>
</tr>
</table>
<blockquote class="inline_help">
<p>If you need to add QEMU arguments to the XML</p>
Examples can be found on the Libvirt page => <a href="https://libvirt.org/kbase/qemu-passthrough-security.html " target="_blank">https://libvirt.org/kbase/qemu-passthrough-security.html </a>
</p>
</blockquote>
<table>
<tr>
<td></td>
@@ -1950,7 +1966,7 @@ $(function() {
if (audio && !sound.includes(audio)) form.append('<input type="hidden" name="pci[]" value="'+audio+'#remove">');
});
<?endif?>
var postdata = form.find('input,select').serialize().replace(/'/g,"%27");
var postdata = form.find('input,select,textarea[name="qemucmdline"').serialize().replace(/'/g,"%27");
<?if (!$boolNew):?>
// keep checkbox visually unchecked
form.find('input[name="usb[]"],input[name="usbopt[]"],input[name="pci[]"]').each(function(){