Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/machine/wsl/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (w WSLStubber) MountVolumesToVM(_ *vmconfigs.MachineConfig, _ bool) error {
return nil
}

// ===================== CHANGED FUNCTION START =====================

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed.

func (w WSLStubber) Remove(mc *vmconfigs.MachineConfig) ([]string, func() error, error) {
// Note: we could consider swapping the two conditionals
// below if we wanted to hard error on the wsl unregister
Expand All @@ -114,12 +115,26 @@ func (w WSLStubber) Remove(mc *vmconfigs.MachineConfig) ([]string, func() error,
if err := runCmdPassThrough(cmd); err != nil {
return err
}

// The podman-net-usermode WSL distribution is shared across all
// machines using --user-mode-networking, so it isn't removed
// automatically above. Clean it up here if this machine used it
// and no other configured machine still needs it.
// (see https://github.com/containers/podman/issues/29480)
if mc.WSLHypervisor != nil && mc.WSLHypervisor.UserModeNetworking {
if err := removeUserModeDistIfUnused(mc.Name); err != nil {
logrus.Warnf("could not clean up shared user-mode networking distribution: %v", err)
}
}

return nil
}

return []string{}, wslRemoveFunc, nil
}

// ====================== CHANGED FUNCTION END ======================

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


func (w WSLStubber) RemoveAndCleanMachines(_ *define.MachineDirs) error {
return nil
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/machine/wsl/usermodenet.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,32 @@ func appendDisableAutoResolve(dist string) error {

return nil
}

func removeUserModeDistIfUnused(removedName string) error {
exists, err := isWSLExist(userModeDist)
if err != nil || !exists {
return err
}

dirs, err := env.GetMachineDirs(vmtype)
if err != nil {
return err
}

machines, err := vmconfigs.LoadMachinesInDir(dirs)
if err != nil {
return err
}

for name, mc := range machines {
if name == removedName {
continue
}
if mc.WSLHypervisor != nil && mc.WSLHypervisor.UserModeNetworking {
return nil
}
}

_ = terminateDist(userModeDist)
return unregisterDist(userModeDist)
}