Prevent appending multiple times to the file
This commit is contained in:
parent
ff5d20f4f9
commit
68aec7fdb8
2 changed files with 39 additions and 9 deletions
|
@ -27,8 +27,14 @@ func Set_Dracut() {
|
||||||
// Write the dracut config file
|
// Write the dracut config file
|
||||||
fileio.AppendContent(fmt.Sprintf("add_drivers+=\" %s \"\n", strings.Join(vfio_modules(), " ")), dracutConf)
|
fileio.AppendContent(fmt.Sprintf("add_drivers+=\" %s \"\n", strings.Join(vfio_modules(), " ")), dracutConf)
|
||||||
|
|
||||||
// Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments)
|
// Get the current kernel arguments we have generated
|
||||||
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
|
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
|
||||||
|
|
||||||
|
// If the kernel argument is not already in the file
|
||||||
|
if !strings.Contains(kernel_args, "rd.driver.pre=vfio_pci") {
|
||||||
|
// Add to our kernel arguments file that vfio_pci should load early (dracut does this using kernel arguments)
|
||||||
|
fileio.AppendContent(" rd.driver.pre=vfio_pci", config.Path.CMDLINE)
|
||||||
|
}
|
||||||
|
|
||||||
// Make a backup of dracutConf if there is one there
|
// Make a backup of dracutConf if there is one there
|
||||||
backupFile(strings.Replace(dracutConf, "config", "", 1))
|
backupFile(strings.Replace(dracutConf, "config", "", 1))
|
||||||
|
|
|
@ -2,7 +2,10 @@ package configs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||||
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
)
|
)
|
||||||
|
@ -16,11 +19,32 @@ func DisableVFIOVideo(i int) {
|
||||||
// Write to logger
|
// Write to logger
|
||||||
logger.Printf("Adding vfio_pci.disable_vga=%v to %s", i, config.Path.CMDLINE)
|
logger.Printf("Adding vfio_pci.disable_vga=%v to %s", i, config.Path.CMDLINE)
|
||||||
|
|
||||||
// Add to the kernel arguments that we want to disable VFIO video output on the host
|
// Get the current kernel arguments we have generated
|
||||||
fileio.AppendContent(
|
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
|
||||||
fmt.Sprintf(
|
|
||||||
" vfio_pci.disable_vga=%v", i,
|
// If the kernel argument is already in the file
|
||||||
),
|
if strings.Contains(kernel_args, "vfio_pci.disable_vga") {
|
||||||
config.Path.CMDLINE,
|
// Remove the old file
|
||||||
)
|
err := os.Remove(config.Path.CMDLINE)
|
||||||
|
errorcheck.ErrorCheck(err, fmt.Sprintf("Could not rewrite %s", config.Path.CMDLINE))
|
||||||
|
|
||||||
|
// Enable or disable the VGA based on our given value
|
||||||
|
if i == 0 {
|
||||||
|
kernel_args = strings.Replace(kernel_args, "vfio_pci.disable_vga=1", "vfio_pci.disable_vga=0", 1)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
kernel_args = strings.Replace(kernel_args, "vfio_pci.disable_vga=0", "vfio_pci.disable_vga=1", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rewrite the kernel_args file
|
||||||
|
fileio.AppendContent(kernel_args, config.Path.CMDLINE)
|
||||||
|
} else {
|
||||||
|
// Add to the kernel arguments that we want to disable VFIO video output on the host
|
||||||
|
fileio.AppendContent(
|
||||||
|
fmt.Sprintf(
|
||||||
|
" vfio_pci.disable_vga=%v", i,
|
||||||
|
),
|
||||||
|
config.Path.CMDLINE,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue