diff options
author | Simon Rettberg | 2021-09-21 16:52:06 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-03-09 15:06:54 +0100 |
commit | 67e6b6c9981207d7d658f2ad2bf1c39b75c099c7 (patch) | |
tree | d2f54c424dd983a1500acf0d3d0bc3bbfee6e9cd /modules-available/passthrough/inc/passthrough.inc.php | |
parent | [statistics] Support new json-format of hardware info from client (diff) | |
download | slx-admin-67e6b6c9981207d7d658f2ad2bf1c39b75c099c7.tar.gz slx-admin-67e6b6c9981207d7d658f2ad2bf1c39b75c099c7.tar.xz slx-admin-67e6b6c9981207d7d658f2ad2bf1c39b75c099c7.zip |
[passthrough] New module for managing hardware passthrough for QEMU
Diffstat (limited to 'modules-available/passthrough/inc/passthrough.inc.php')
-rw-r--r-- | modules-available/passthrough/inc/passthrough.inc.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/modules-available/passthrough/inc/passthrough.inc.php b/modules-available/passthrough/inc/passthrough.inc.php new file mode 100644 index 00000000..524aea5e --- /dev/null +++ b/modules-available/passthrough/inc/passthrough.inc.php @@ -0,0 +1,53 @@ +<?php + +class Passthrough +{ + + public static function getGroupDropdown(array &$row): array + { + $out = []; + if ($row['class'] === '0300') { + foreach (['GPU', 'GVT'] as $id) { + $out[] = [ + 'ptid' => $id, + 'ptname' => $id, + 'selected' => ($row['@PASSTHROUGH'] === $id ? 'selected' : ''), + ]; + } + return $out; + } + static $list = false; + if ($list === false) { + $list = Database::queryKeyValueList("SELECT groupid, title FROM passthrough_group ORDER BY groupid"); + self::ensurePrepopulated($list); + } + $row['custom_groups'] = true; + foreach ($list as $id => $title) { + if ($id === 'GPU' || $id === 'GVT') + continue; + $item = ['ptid' => $id, 'ptname' => $id . ' (' . $title . ')']; + if ($row['@PASSTHROUGH'] === $id) { + $item['selected'] = 'selected'; + } + $out[] = $item; + } + return $out; + } + + private static function ensurePrepopulated(&$list) + { + $want = [ + 'GPU' => '[Special] GPU passthrough default group', + 'GVT' => '[Special] Intel GVT-g default group', + ]; + foreach ($want as $id => $title) { + if (!isset($list[$id])) { + Database::exec("INSERT INTO passthrough_group (groupid, title) VALUES (:id, :title) + ON DUPLICATE KEY UPDATE title = VALUES(title)", + ['id' => $id, 'title' => $title]); + $list[$id] = $title; + } + } + } + +}
\ No newline at end of file |