network: Move up defer block tp cleanup network

Move the defer for cleaning up network before the call to add network.
This way if any change made by add network is reverted by in case of
failure. This is particulary important for physical network interfaces
as with this step we make sure that driver for the physical interface is
reverted back to the original host driver. Without this the physical
network iterface will remain bound to vfio.

Fixes: #8646

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2023-12-12 21:02:48 -08:00
parent 61ce7455c5
commit b005cda689

View File

@ -70,18 +70,19 @@ func createSandboxFromConfig(ctx context.Context, sandboxConfig SandboxConfig, f
}
}()
// network rollback
defer func() {
if err != nil {
virtLog.Info("Removing network after failure in createSandbox")
s.removeNetwork(ctx)
}
}()
// Create the sandbox network
if err = s.createNetwork(ctx); err != nil {
return nil, err
}
// network rollback
defer func() {
if err != nil {
s.removeNetwork(ctx)
}
}()
// Set the sandbox host cgroups.
if err := s.setupResourceController(); err != nil {
return nil, err