From e8115d1c8d1b7e3620ca8db7454b04ae44503ba4 Mon Sep 17 00:00:00 2001 From: Mikko Ylinen Date: Wed, 9 Jun 2021 10:08:07 +0300 Subject: [PATCH] qat: do not fail if driver/unbind file does not exist /driver symlink does not exist if the device is not bound to any driver. bindDevice() failed when writing to /driver/unbind errored but IsNotExist() error is acceptable in case there's no driver to unbind. Signed-off-by: Mikko Ylinen --- cmd/qat_plugin/dpdkdrv/dpdkdrv.go | 9 ++++----- cmd/qat_plugin/dpdkdrv/dpdkdrv_test.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cmd/qat_plugin/dpdkdrv/dpdkdrv.go b/cmd/qat_plugin/dpdkdrv/dpdkdrv.go index 74460dde..ff3283f6 100644 --- a/cmd/qat_plugin/dpdkdrv/dpdkdrv.go +++ b/cmd/qat_plugin/dpdkdrv/dpdkdrv.go @@ -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) diff --git a/cmd/qat_plugin/dpdkdrv/dpdkdrv_test.go b/cmd/qat_plugin/dpdkdrv/dpdkdrv_test.go index e699a773..6fd9ff38 100644 --- a/cmd/qat_plugin/dpdkdrv/dpdkdrv_test.go +++ b/cmd/qat_plugin/dpdkdrv/dpdkdrv_test.go @@ -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",