From d378b3806dd55bcd5c99110fd5569eb456f94d7e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 6 Apr 2022 16:54:27 +0200 Subject: [statistics] client details: show which pci devices are passed through --- modules-available/statistics/pages/machine.inc.php | 37 +++++++++++++++++++--- .../statistics/templates/machine-main.html | 2 ++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index 6ea0ce28..4e8f9f34 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -61,8 +61,12 @@ class SubPage Message::addError('unknown-machine', $uuid); return; } - if (Module::isAvailable('locations') && !Location::isLeaf($client['locationid'])) { - $client['hasroomplan'] = false; + $locations = []; + if ($client['locationid'] > 0 && Module::isAvailable('locations')) { + if (!Location::isLeaf($client['locationid'])) { + $client['hasroomplan'] = false; + } + $locations = Location::getLocationRootChain($client['locationid']); } User::assertPermission('machine.view-details', (int)$client['locationid']); // Hack: Get raw collected data @@ -89,18 +93,43 @@ class SubPage } } unset($item); + // PCI + // 1) get passthrough groups + $passthroughTypes = []; + if (!empty($locations)) { + $hw = new HardwareQuery(HardwareInfo::PCI_DEVICE, $uuid, true); + // TODO: Get list of enabled pass through groups for this client's location + $hw->addForeignJoin(true, '@PASSTHROUGH', 'passthrough_group_x_location', 'groupid', + 'locationid', $locations); + $hw->addGlobalColumn('vendor'); + $hw->addGlobalColumn('device'); + $res = $hw->query(); + foreach ($res as $row) { + $devId = $row['vendor'] . ':' . $row['device']; + if (!isset($passthroughTypes[$devId])) { + $passthroughTypes[$devId] = []; + } + $passthroughTypes[$devId][] = $row['@PASSTHROUGH']; + } + } + // 2) Sort and mangle list $client['lspci1'] = $client['lspci2'] = []; foreach ($client['lspci'] as $item) { + $devId = $item['vendor'] . ':' . $item['device']; $item['vendor_s'] = PciId::getPciId(PciId::VENDOR, $item['vendor']); $item['device_s'] = PciId::getPciId(PciId::DEVICE, $item['vendor'] . $item['device']); if ($item['vendor_s'] === false) { $pciLookup[$item['vendor']] = true; } if ($item['device_s'] === false) { - $pciLookup[$item['vendor'] . ':' . $item['device']] = true; + $pciLookup[$devId] = true; + } + // Passthrough enabled? + if (isset($passthroughTypes[$devId])) { + $item['pt'] = implode(', ', $passthroughTypes[$devId]); } $class = $item['class']; - if ($class === '0300' || $class === '0200' || $class === '0403') { + if ($class === '0300' || $class === '0200' || $class === '0403' || !empty($item['pt'])) { $dst =& $client['lspci1']; } else { $dst =& $client['lspci2']; diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html index 9ec19820..aa80d5c3 100644 --- a/modules-available/statistics/templates/machine-main.html +++ b/modules-available/statistics/templates/machine-main.html @@ -396,6 +396,7 @@ {{#entries}}
 └ + {{pt}} {{vendor_s}} {{device_s}} [{{vendor}}:{{device}}] @@ -408,6 +409,7 @@ {{#entries}}
 └ + {{pt}} {{vendor_s}} {{device_s}} [{{vendor}}:{{device}}] -- cgit v1.2.3-55-g7522