Update WIP.

This commit is contained in:
SimonFair
2025-11-09 16:33:03 +00:00
parent 1266a3dfe4
commit 0c496152dd
4 changed files with 88 additions and 37 deletions
+33 -11
View File
@@ -78,7 +78,7 @@ function saveVFsConfig(pciId,vd,interactive=1) {
removeRebootNotice(message);
document.getElementById("warning").innerHTML = "<b>_(No changes)_.</b>";
}
$('#t1').load('/webGui/include/SysDevs.php', { table: 't1' });
if (interactive == 1) $('#t1').load('/webGui/include/SysDevs.php', { table: 't1' });
});
}
@@ -165,38 +165,59 @@ function applyVFSettings(pciId,vd) {
function applyVFsConfig(pciId, vd, vfs) {
saveVFsConfig(pciId,vd,0);
var message = "_(System Devices)_: _(A reboot is required to apply changes)_";
var numvfs = document.getElementById("vf" + pciId).value;
var numvfs = parseInt(document.getElementById("vf" + pciId).value, 10);
vfs = parseInt(vfs, 10);
// Case 1: VFs will be removed
if (vfs != 0 && numvfs == 0) {
if (vfs !== 0 && numvfs === 0) {
swal({
title: "VFs will be removed",
text: "Card will reset.",
type: "warning",
showCancelButton: false,
confirmButtonColor: "#3085d6",
showCancelButton: true,
confirmButtonText: "OK",
closeOnConfirm: true
}, function() {
}, function(isConfirm) {
if (isConfirm) {
// User clicked OK
sleep(2000);
doApply(pciId, vd, numvfs, message);
} else {
// User clicked Cancel — optionally show feedback
swal("Cancelled", "No changes were made.", "info");
}
});
return;
}
// Case 2: Number of VFs changed
if (vfs != numvfs && numvfs != 0) {
if (vfs !== numvfs && vfs !== 0) {
swal({
title: "Number of VFs changed",
text: "Will need to remove and re-add VFs.",
type: "warning",
showCancelButton: false,
confirmButtonColor: "#3085d6",
showCancelButton: true,
confirmButtonText: "OK",
closeOnConfirm: true
}, function() {
}, function(isConfirm) {
if (isConfirm) {
// User clicked OK
sleep(2000);
doApply(pciId, vd, numvfs, message);
} else {
// User clicked Cancel — optionally show feedback
swal("Cancelled", "No changes were made.", "info");
}
return;
});
}
if (vfs !== numvfs && vfs === 0) doApply(pciId, vd, numvfs, message);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function doApply(pciId, vd, numvfs, message) {
@@ -206,7 +227,8 @@ function doApply(pciId, vd, numvfs, message) {
text: "Please wait while configuration is applied.",
type: "info",
showConfirmButton: false,
allowOutsideClick: false
allowOutsideClick: false,
closeOnConfirm: false
});
// Perform the POST
@@ -69,6 +69,13 @@ function getSriovInfoJson(bool $includeVfDetails = true): string {
$vf_entry = ['pci' => $vf_pci];
if ($includeVfDetails) {
// Vendor:Device formatted string
$vendorFile = "/sys/bus/pci/devices/{$vf_pci}/vendor";
$deviceFile = "/sys/bus/pci/devices/{$vf_pci}/device";
$vendor = is_readable($vendorFile) ? trim(file_get_contents($vendorFile)) : null;
$device = is_readable($deviceFile) ? trim(file_get_contents($deviceFile)) : null;
$vf_entry['vd'] = ($vendor && $device) ? sprintf('%s:%s', substr($vendor, 2), substr($device, 2)) : null;
// Network interface info
$net = glob("/sys/bus/pci/devices/{$vf_pci}/net/*");
if ($net && isset($net[0])) {
@@ -18,6 +18,26 @@
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
require_once "$docroot/webGui/include/Secure.php";
require_once "$docroot/webGui/include/Wrappers.php";
require_once "$docroot/webGui/include/SriovHelpers.php";
function action_settings($pciid) {
$sriov = json_decode(getSriovInfoJson(),true);
$sriov_devices_settings=parseVFSettings();
$vfs = $sriov[$pciid]['vfs'];
file_put_contents('/tmp/vfaction',"");
foreach($vfs as $vf) {
if (array_key_exists($vf['pci'],$sriov_devices_settings)) {
$vfpci = $vf['pci'];
$vfio = $sriov_devices_settings[$vfpci]['vfio'];
$mac = $sriov_devices_settings[$vfpci]['mac'];
$action_cmd = "/usr/local/sbin/sriov-vfsettings.sh ".escapeshellarg($vf['pci'])." ".escapeshellarg($vf['vd'])." ".escapeshellarg($vfio)." ".escapeshellarg($mac);
file_put_contents('/tmp/vfaction',$action_cmd,FILE_APPEND);
$action_result = shell_exec($action_cmd);
#if ($action_result == "error") return $action_result;
}
}
}
$sriov = '/boot/config/sriov.cfg';
$sriovvfs = '/boot/config/sriovvfs.cfg';
@@ -47,22 +67,14 @@ if (isset($pciid) && isset($vd)) {
if ($numvfs != $currentvfs) {
file_put_contents($filepath,0);
file_put_contents($filepath,$numvfs);
# Apply VF changes.
# foreach VF.
action_settings($pciid);
echo 1;
return;
}
file_put_contents($filepath,$numvfs);
# Apply VF changes.
# foreach VF.
action_settings($pciid);
echo 1;
return;
#else action numvfs > pf
#Apply VF settings.
break;
case "sriovsettings":
$old = is_file($sriovvfs) ? rtrim(file_get_contents($sriovvfs)) : '';