Merge pull request #1684 from SimonFair/VM-Avoid-spinup-of-ISOS-location-volume

Add spin up check to CD info function.
This commit is contained in:
tom mortensen
2024-04-03 15:51:58 -07:00
committed by GitHub
3 changed files with 33 additions and 11 deletions

View File

@@ -53,7 +53,7 @@ foreach ($vms as $vm) {
$image = substr($icon,-4)=='.png' ? "<img src='$icon' class='img'>" : (substr($icon,0,5)=='icon-' ? "<i class='$icon img'></i>" : "<i class='fa fa-$icon img'></i>");
$arrConfig = domain_to_config($uuid);
$snapshots = getvmsnapshots($vm) ;
$cdroms = $lv->get_cdrom_stats($res) ;
$cdroms = $lv->get_cdrom_stats($res,true,true) ;
if ($state == 'running') {
$mem = $dom['memory']/1024;
} else {
@@ -215,7 +215,7 @@ foreach ($vms as $vm) {
$boot= $arrDisk["boot order"];
$serial = $arrDisk["serial"];
if ($boot < 1) $boot = _('Not set');
$reallocation = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($disk)." 2>/dev/null"));
$reallocation = trim(get_realvolume($disk));
if (!empty($reallocation)) $reallocationstr = "($reallocation)"; else $reallocationstr = "";
echo "<tr><td>$disk $reallocationstr</td><td>$serial</td><td>$bus</td>";
if ($state == 'shutoff') {
@@ -237,8 +237,10 @@ foreach ($vms as $vm) {
/* Display VM cdroms */
foreach ($cdroms as $arrCD) {
$tooltip = "";
$capacity = $lv->format_size($arrCD['capacity'], 0);
$allocation = $lv->format_size($arrCD['allocation'], 0);
if ($arrCD['spundown']) {$capacity = $allocation = "*"; $tooltip = "Drive spun down ISO volume is ".$arrCD['reallocation'];} else $tooltip = "ISO volume is ".$arrCD['reallocation'];
$disk = $arrCD['file'] ?? $arrCD['partition'] ?? "" ;
$dev = $arrCD['device'];
$bus = $arrValidDiskBuses[$arrCD['bus']] ?? 'VirtIO';
@@ -247,7 +249,7 @@ foreach ($vms as $vm) {
if ($disk != "" ) {
$title = _('Eject CD Drive');
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\", \"--eject\")";
echo "<tr><td>$disk <a title='$title' href='#' onclick='$changemedia'> <i class='fa fa-eject'></i></a></td><td></td><td>$bus</td><td>$capacity</td><td>$allocation</td><td>$boot</td></tr>";
echo "<tr><td>$disk <a title='$title' href='#' onclick='$changemedia'> <i class='fa fa-eject'></i></a></td><td></td><td>$bus</td><td><span title='$tooltip' data-toggle='tooltip'>$capacity</span></td><td>$allocation</td><td>$boot</td></tr>";
} else {
$title = _('Insert CD');
$changemedia = "changemedia(\"{$uuid}\",\"{$dev}\",\"{$bus}\",\"--select\")";

View File

@@ -1250,33 +1250,44 @@
return $tmp;
}
function get_cdrom_stats($domain, $sort=true) {
function get_cdrom_stats($domain, $sort=true,$spincheck = false) {
$unraiddisks = array_merge_recursive(@parse_ini_file('state/disks.ini',true)?:[], @parse_ini_file('state/devs.ini',true)?:[]);
$dom = $this->get_domain_object($domain);
$tmp = false;
$buses = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@bus', false);
$disks = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@dev', false);
$cds = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/target/@dev', false);
$files = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/source/@file', false);
$boot = $this->get_xpath($dom, '//domain/devices/disk[@device="cdrom"]/boot/@*', false);
$ret = [];
for ($i = 0; $i < $disks['num']; $i++) {
$tmp = libvirt_domain_get_block_info($dom, $disks[$i]);
for ($i = 0; $i < $cds['num']; $i++) {
$spundown = 0;
$reallocation = null;
if (isset($files[$i])) $reallocation = trim(get_realvolume($files[$i]));
if ($spincheck) {
if (isset($unraiddisks[$reallocation]['spundown']) && $unraiddisks[$reallocation]['spundown'] == 1) $spundown = 1; else $tmp = libvirt_domain_get_block_info($dom, $cds[$i]);
} else $tmp = libvirt_domain_get_block_info($dom, $cds[$i]);
if ($tmp) {
$tmp['bus'] = $buses[$i];
$tmp["boot order"] = $boot[$i] ?? "";
$tmp['reallocation'] = $reallocation;
$tmp['spundown'] = $spundown;
$ret[] = $tmp;
}
else {
$this->_set_last_error();
$ret[] = [
'device' => $disks[$i],
'device' => $cds[$i],
'file' => $files[$i],
'type' => '-',
'capacity' => '-',
'allocation' => '-',
'physical' => '-',
'bus' => $buses[$i]
'bus' => $buses[$i],
'reallocation' => $reallocation,
'spundown' => $spundown
];
}
}
@@ -1294,7 +1305,7 @@
}
unset($buses);
unset($disks);
unset($cds);
unset($files);
return $ret;

View File

@@ -291,4 +291,13 @@ function my_mkdir($dirname,$permissions = 0777,$recursive = false) {
break;
}
}
function get_realvolume($path) {
if (strpos($path,"/mnt/user/",0) === 0)
$reallocation = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($path)." 2>/dev/null"));
else {
$realexplode = explode("/",str_replace("/mnt/","",$path));
$reallocation = $realexplode[0];
}
return $reallocation;
}
?>