Skip to content

Commit e180bfd

Browse files
authored
Merge pull request #644 from mythi/PR-2021-034
qat: do not fail if driver/unbind file does not exist
2 parents 6aa1a47 + e8115d1 commit e180bfd

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

cmd/qat_plugin/dpdkdrv/dpdkdrv.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Intel Corporation. All Rights Reserved.
1+
// Copyright 2017-2021 Intel Corporation. All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -201,9 +201,8 @@ func (dp *DevicePlugin) getDeviceID(pciAddr string) (string, error) {
201201
func (dp *DevicePlugin) bindDevice(vfBdf string) error {
202202
unbindDevicePath := filepath.Join(dp.pciDeviceDir, vfBdf, driverUnbindSuffix)
203203

204-
// Unbind from the kernel driver
205-
err := os.WriteFile(unbindDevicePath, []byte(vfBdf), 0600)
206-
if err != nil {
204+
// Unbind from the kernel driver. IsNotExist means the device is not bound to any driver.
205+
if err := os.WriteFile(unbindDevicePath, []byte(vfBdf), 0600); !os.IsNotExist(err) {
207206
return errors.Wrapf(err, "Unbinding from kernel driver failed for the device %s", vfBdf)
208207
}
209208
vfdevID, err := dp.getDeviceID(vfBdf)
@@ -319,7 +318,7 @@ func getCurrentDriver(device string) string {
319318
symlink := filepath.Join(device, "driver")
320319
driver, err := filepath.EvalSymlinks(symlink)
321320
if err != nil {
322-
klog.Warningf("unable to evaluate symlink: %s", symlink)
321+
klog.Infof("no driver bound to device %q", filepath.Base(device))
323322
return ""
324323
}
325324
return filepath.Base(driver)

cmd/qat_plugin/dpdkdrv/dpdkdrv_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,28 @@ func TestScanPrivate(t *testing.T) {
295295
maxDevNum: 1,
296296
expectedDevNum: 1,
297297
},
298+
{
299+
name: "vfio-pci DPDKdriver with no kernel bound driver and where vfdevID is equal to qatDevId (37c9)",
300+
dpdkDriver: "vfio-pci",
301+
kernelVfDrivers: []string{"c6xxvf"},
302+
dirs: []string{
303+
"sys/bus/pci/drivers/c6xx",
304+
"sys/bus/pci/drivers/vfio-pci",
305+
"sys/bus/pci/devices/0000:02:00.0",
306+
"sys/bus/pci/devices/0000:02:01.0",
307+
},
308+
files: map[string][]byte{
309+
"sys/bus/pci/devices/0000:02:01.0/device": []byte("0x37c9"),
310+
"sys/bus/pci/drivers/vfio-pci/new_id": []byte("some junk"),
311+
},
312+
symlinks: map[string]string{
313+
"sys/bus/pci/devices/0000:02:01.0/iommu_group": "sys/kernel/iommu_groups/vfiotestfile",
314+
"sys/bus/pci/drivers/c6xx/0000:02:00.0": "sys/bus/pci/devices/0000:02:00.0",
315+
"sys/bus/pci/devices/0000:02:00.0/virtfn0": "sys/bus/pci/devices/0000:02:01.0",
316+
},
317+
maxDevNum: 1,
318+
expectedDevNum: 1,
319+
},
298320
{
299321
name: "vfio-pci DPDKdriver with one kernel bound device (QAT device) where vfdevID is equal to qatDevId not enabbled in kernelVfDrivers",
300322
dpdkDriver: "vfio-pci",

0 commit comments

Comments
 (0)