- [$dbdf, $ven_dev, $vfio_flag, $mac] = explode('|', $entry);
- $sriov_devices_settings[$dbdf] = [
- 'dbdf' => $dbdf,
- 'vendor' => $ven_dev,
- 'vfio' => (int)$vfio_flag,
- 'mac' => strtoupper($mac),
- ];
- }
- }
-
- # $sriov_devices_settings = array_values(array_unique($sriov_devices_settings, SORT_REGULAR));
-}
-
$disks = (array)parse_ini_file('state/disks.ini',true);
$devicelist = array_column($disks, 'device');
$lines = array ();
@@ -430,7 +200,6 @@ if (is_file("/boot/config/sriovvfs.cfg")) {
echo "SRIOV Available VFs:{$sriov[$pciaddress]['total_vfs']}";
$num_vfs= $sriov[$pciaddress]['num_vfs'];
-
if (isset($sriov_devices[$pciaddress]))
$file_numvfs = $sriov_devices[$pciaddress]['vf_count'];
else $file_numvfs = 0;
@@ -452,7 +221,7 @@ if (is_file("/boot/config/sriovvfs.cfg")) {
echo " "._("Current:").$num_vfs;
#sprintf(" "._("Current").":%1s",$num_vfs);
echo ' ';
- echo ' ';
+ echo ' ';
if ($file_numvfs != $num_vfs) echo " ".sprintf(_("Pending action or reboot"));
@@ -479,9 +248,9 @@ if (is_file("/boot/config/sriovvfs.cfg")) {
if (file_exists('/sys/bus/pci/devices/'.$pciaddress.'/reset')) echo "";
echo "| ";
if (!$removed) {
- echo '| or just
- echo (in_array($pciaddress."|".$vd, $vfio_cfg_devices) || in_array($pciaddress, $vfio_cfg_devices)) ? " checked>" : ">";
+ echo (array_key_exists($pciaddress,$sriov_devices_settings) && $sriov_devices_settings[$pciaddress]['vfio'] == 1) ? " checked>" : ">";
}
} else { echo " | "; }
echo ' | MAC Address:';
echo "";
echo ' ';
- echo ' ';
+ echo ' ';
if ($vrf['driver'] == "vfio-pci")
echo _("Current").": ";
echo $vrf['driver'] == "vfio-pci" ? _("Bound to VFIO") : strtoupper($vrf['mac']);
diff --git a/emhttp/plugins/dynamix/include/apply.sriov-cfg.php b/emhttp/plugins/dynamix/include/apply.sriov-cfg.php
new file mode 100644
index 000000000..fb7ead073
--- /dev/null
+++ b/emhttp/plugins/dynamix/include/apply.sriov-cfg.php
@@ -0,0 +1,94 @@
+
+
+
+#VFSETTINGS=0000:04:11.5|8086:1520|0|62:00:04:11:05:01 0000:04:10.5|8086:1520|1|62:00:04:10:05:01
+#VFS=0000:04:00.1|8086:1521|3 0000:04:00.0|8086:1521|2
+
+$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
+require_once "$docroot/webGui/include/Secure.php";
+require_once "$docroot/webGui/include/Wrappers.php";
+
+$sriov = '/boot/config/sriov.cfg';
+$sriovvfs = '/boot/config/sriovvfs.cfg';
+
+$type = _var($_POST,'type');
+$pciid = _var($_POST,'pciid');
+$vd = _var($_POST,'vd');
+
+if (isset($pciid) && isset($vd)) {
+ $newelement_check = $pciid.'|'.$vd.'|';
+
+ switch($type) {
+ case "sriov":
+ $old = is_file($sriov) ? rtrim(file_get_contents($sriov)) : '';
+ $newexplode = explode(" ",str_replace("VFS=","",$old));
+ $new = $old;
+ $numvfs= _var($_POST,'numvfs');
+ $currentvfs = _var($_POST,'currentvfs');
+ $newelement_change = $newelement_check.$numfs;
+ $found = false;
+ $filepath = "/sys/bus/pci/devices/$pciid/sriov_numvfs";
+ if ($numvfs == 0) {
+ file_put_contents($filepath,0);
+ echo 1;
+ return;
+ }
+ if ($numvfs != $currentvfs) {
+ file_put_contents($filepath,0);
+ file_put_contents($filepath,$numvfs);
+ # Apply VF changes.
+ # foreach VF.
+ echo 1;
+ return;
+ }
+ file_put_contents($filepath,$numvfs);
+ # Apply VF changes.
+ # foreach VF.
+ echo 1;
+ return;
+
+ #else action numvfs > pf
+
+ #Apply VF settings.
+
+
+ break;
+ case "sriovsettings":
+ $old = is_file($sriovvfs) ? rtrim(file_get_contents($sriovvfs)) : '';
+ $newexplode = explode(" ",str_replace("VFSETTINGS=","",$old));
+ $mac= _var($_POST,'mac');
+ $vfio= _var($_POST,'vfio');
+ if ($vfio == "true") $vfio = 1; else $vfio = 0;
+ $found = false;
+ foreach($newexplode as $key => $newelement) {
+ if (strpos($newelement,$newelement_check) !== false) {
+ $found = true;
+ if($mac == "" && $vfio == 0) {
+ unset($newexplode[$key]) ;
+ break;
+ } else {
+ $newexplode[$key] = $newelement_check.$vfio."|".$mac;
+ break;
+ }
+ }
+ }
+ if (!$found) $newexplode[] = $newelement_check.$vfio."|".$mac;
+ $new = "VFSETTINGS=".implode(" ",$newexplode);
+ $file = $sriovvfs;
+ break;
+ }
+}
+
+
+?>
diff --git a/emhttp/plugins/dynamix/include/update.sriov-cfg.php b/emhttp/plugins/dynamix/include/update.sriov-cfg.php
index 138505514..c55cff61c 100644
--- a/emhttp/plugins/dynamix/include/update.sriov-cfg.php
+++ b/emhttp/plugins/dynamix/include/update.sriov-cfg.php
@@ -58,6 +58,7 @@ if (isset($pciid) && isset($vd)) {
$newexplode = explode(" ",str_replace("VFSETTINGS=","",$old));
$mac= _var($_POST,'mac');
$vfio= _var($_POST,'vfio');
+ if ($vfio == "true") $vfio = 1; else $vfio = 0;
$found = false;
foreach($newexplode as $key => $newelement) {
if (strpos($newelement,$newelement_check) !== false) {
diff --git a/sbin/sriov b/sbin/sriov
index c806736f6..5c1d5391a 100755
--- a/sbin/sriov
+++ b/sbin/sriov
@@ -67,15 +67,8 @@ VFSETTINGS_LINE=$(grep "^VFSETTINGS=" "$CFG_VFS" | cut -d= -f2- | tr -d '"')
for PARAM_VFS in $VFSETTINGS_LINE; do
IFS='|' read -r arg1 arg2 arg3 arg4 <<< "$PARAM_VFS"
echo "Processing $arg1 $arg2 set Mac to $arg4"
- /usr/local/sbin/sriov-setmac.sh "$arg1" "$arg2" "$arg4"
+ /usr/local/sbin/sriov-vfsettings.sh "$arg1" "$arg2" "$arg3" "$arg4"
echo "---"
-
- if [[ "$arg3" == "1" ]]; then
- /usr/local/sbin/vfio-pci-bind.sh "$arg1" "$arg2" \
- 1>>/var/log/vfio-pci \
- 2>>/var/log/vfio-pci-errors
- fi
-
done
diff --git a/sbin/sriov-setmac.sh b/sbin/sriov-vfsettings.sh
old mode 100755
new mode 100644
similarity index 100%
rename from sbin/sriov-setmac.sh
rename to sbin/sriov-vfsettings.sh
|