Skip to content

Commit

Permalink
Release VF when CMD ADD failed
Browse files Browse the repository at this point in the history
After moving VF to container check if error occurs then move the VF back
to original namespace

Fixes k8snetworkplumbingwg#38
  • Loading branch information
Mmduh-483 authored and ahalimx86 committed Feb 1, 2019
1 parent 45a5db0 commit 8ede7c3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sriov/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/version"
"github.com/intel/sriov-cni/pkg/config"
"github.com/vishvananda/netlink"
)

func init() {
Expand Down Expand Up @@ -56,7 +57,21 @@ func cmdAdd(args *skel.CmdArgs) error {
}

if n.DeviceInfo != nil && n.DeviceInfo.PCIaddr != "" && n.DeviceInfo.Vfid >= 0 && n.DeviceInfo.Pfname != "" {
if err = setupVF(n, args.IfName, args.ContainerID, netns); err != nil {
err = setupVF(n, args.IfName, args.ContainerID, netns)
defer func() {
if err != nil {
if !n.DPDKMode {
err = netns.Do(func(_ ns.NetNS) error {
_, err := netlink.LinkByName(args.IfName)
return err
})
}
if n.DPDKMode || err == nil {
releaseVF(n, args.IfName, args.ContainerID, netns)
}
}
}()
if err != nil {
return fmt.Errorf("failed to set up pod interface %q from the device %q: %v", args.IfName, n.Master, err)
}
} else {
Expand Down

0 comments on commit 8ede7c3

Please sign in to comment.