From 0cca27503f7ff7b9d95f8371b6d4c17bc2c4fa7a Mon Sep 17 00:00:00 2001 From: Marcelo Guerrero Date: Wed, 26 Jul 2023 12:23:04 +0200 Subject: [PATCH] Move allocated pci deletion in defer of del cmd The allocated pci is supposed to be deleted when the del command is completed. However, placing this logic at the end of the function does not always guaranteed its execution. For instance, if ResetVfConfig or ReleaseVF fail, the err variable is overwritten which causes the cache to be deleted in the defer function and the next del retry to exit without deleting the allocated pci. By placing this logic along the deletion of the cache will ensure that all operations in the del command are done. --- cmd/sriov/main.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/sriov/main.go b/cmd/sriov/main.go index e785a5e00..afca6293a 100644 --- a/cmd/sriov/main.go +++ b/cmd/sriov/main.go @@ -208,6 +208,9 @@ func cmdDel(args *skel.CmdArgs) error { defer func() { if err == nil && cRefPath != "" { _ = utils.CleanCachedNetConf(cRefPath) + + allocator := utils.NewPCIAllocator(config.DefaultCNIDir) + _ = allocator.DeleteAllocatedPCI(netConf.DeviceID) } }() @@ -260,12 +263,6 @@ func cmdDel(args *skel.CmdArgs) error { } } - // Mark the pci address as released - allocator := utils.NewPCIAllocator(config.DefaultCNIDir) - if err = allocator.DeleteAllocatedPCI(netConf.DeviceID); err != nil { - return fmt.Errorf("error cleaning the pci allocation for vf pci address %s: %v", netConf.DeviceID, err) - } - return nil }