qat: do not fail if driver/unbind file does not exist

<device>/driver symlink does not exist if the device is not bound
to any driver. bindDevice() failed when writing to <device>/driver/unbind
errored but IsNotExist() error is acceptable in case there's no driver
to unbind.

Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
This commit is contained in:
Mikko Ylinen 2021-06-09 10:08:07 +03:00
parent 37daf67bfa
commit e8115d1c8d
2 changed files with 26 additions and 5 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2017 Intel Corporation. All Rights Reserved.
// Copyright 2017-2021 Intel Corporation. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -201,9 +201,8 @@ func (dp *DevicePlugin) getDeviceID(pciAddr string) (string, error) {
func (dp *DevicePlugin) bindDevice(vfBdf string) error {
unbindDevicePath := filepath.Join(dp.pciDeviceDir, vfBdf, driverUnbindSuffix)
// Unbind from the kernel driver
err := os.WriteFile(unbindDevicePath, []byte(vfBdf), 0600)
if err != nil {
// Unbind from the kernel driver. IsNotExist means the device is not bound to any driver.
if err := os.WriteFile(unbindDevicePath, []byte(vfBdf), 0600); !os.IsNotExist(err) {
return errors.Wrapf(err, "Unbinding from kernel driver failed for the device %s", vfBdf)
}
vfdevID, err := dp.getDeviceID(vfBdf)
@ -319,7 +318,7 @@ func getCurrentDriver(device string) string {
symlink := filepath.Join(device, "driver")
driver, err := filepath.EvalSymlinks(symlink)
if err != nil {
klog.Warningf("unable to evaluate symlink: %s", symlink)
klog.Infof("no driver bound to device %q", filepath.Base(device))
return ""
}
return filepath.Base(driver)

View File

@ -295,6 +295,28 @@ func TestScanPrivate(t *testing.T) {
maxDevNum: 1,
expectedDevNum: 1,
},
{
name: "vfio-pci DPDKdriver with no kernel bound driver and where vfdevID is equal to qatDevId (37c9)",
dpdkDriver: "vfio-pci",
kernelVfDrivers: []string{"c6xxvf"},
dirs: []string{
"sys/bus/pci/drivers/c6xx",
"sys/bus/pci/drivers/vfio-pci",
"sys/bus/pci/devices/0000:02:00.0",
"sys/bus/pci/devices/0000:02:01.0",
},
files: map[string][]byte{
"sys/bus/pci/devices/0000:02:01.0/device": []byte("0x37c9"),
"sys/bus/pci/drivers/vfio-pci/new_id": []byte("some junk"),
},
symlinks: map[string]string{
"sys/bus/pci/devices/0000:02:01.0/iommu_group": "sys/kernel/iommu_groups/vfiotestfile",
"sys/bus/pci/drivers/c6xx/0000:02:00.0": "sys/bus/pci/devices/0000:02:00.0",
"sys/bus/pci/devices/0000:02:00.0/virtfn0": "sys/bus/pci/devices/0000:02:01.0",
},
maxDevNum: 1,
expectedDevNum: 1,
},
{
name: "vfio-pci DPDKdriver with one kernel bound device (QAT device) where vfdevID is equal to qatDevId not enabbled in kernelVfDrivers",
dpdkDriver: "vfio-pci",