Skip to content

Commit

Permalink
Fix: overlay umount error by mountpoint (#1698)
Browse files Browse the repository at this point in the history
Signed-off-by: tgfree <[email protected]>

Fix: overlay umount error by mountpoint
  • Loading branch information
tgfree7 authored Sep 15, 2022
1 parent e971bc8 commit 7291ac8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 1 addition & 5 deletions pkg/prune/build_pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package prune
import (
"github.com/sealerio/sealer/common"
"github.com/sealerio/sealer/utils/mount"
osi "github.com/sealerio/sealer/utils/os"
)

type buildPrune struct {
Expand All @@ -33,10 +32,7 @@ func NewBuildPrune() Pruner {
func (b buildPrune) Select() ([]string, error) {
var pruneList []string
// umount all tmp dir, and delete it
pruneUnits, err := osi.GetDirNameListInDir(b.pruneRootDir, osi.FilterOptions{
All: true,
WithFullPath: true,
})
pruneUnits, err := mount.GetDirNameListInDir(b.pruneRootDir)
if err != nil {
return pruneList, err
}
Expand Down
21 changes: 16 additions & 5 deletions utils/mount/mount_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"net"
"strings"

"github.com/moby/sys/mountinfo"
"github.com/sealerio/sealer/utils/ssh"
"github.com/shirou/gopsutil/disk"
"github.com/sirupsen/logrus"

"github.com/sealerio/sealer/utils/exec"
"github.com/sealerio/sealer/utils/os/fs"
"github.com/sealerio/sealer/utils/ssh"
strUtils "github.com/sealerio/sealer/utils/strings"
)

Expand Down Expand Up @@ -120,6 +120,18 @@ func NewMountService(target, upper string, lowLayers []string) (Service, error)
}, nil
}

func GetDirNameListInDir(dir string) ([]string, error) {
var dirs []string
infos, err := mountinfo.GetMounts(mountinfo.PrefixFilter(dir))
if err != nil {
return dirs, err
}
for _, info := range infos {
dirs = append(dirs, info.Mountpoint)
}
return dirs, nil
}

//NewMountServiceByTarget will filter file system by target,if not existed,return false.
func NewMountServiceByTarget(target string) Service {
mounted, info := GetMountDetails(target)
Expand All @@ -141,12 +153,11 @@ type Info struct {
}

func GetMountDetails(target string) (bool, *Info) {
cmd := fmt.Sprintf("mount | grep %s", target)
result, err := exec.RunSimpleCmd(cmd)
infos, err := mountinfo.GetMounts(mountinfo.SingleEntryFilter(target))
if err != nil {
return false, nil
}
return mountCmdResultSplit(result, target)
return mountCmdResultSplit(infos[0].VFSOptions, target)
}

func GetRemoteMountDetails(s ssh.Interface, ip net.IP, target string) (bool, *Info) {
Expand Down

0 comments on commit 7291ac8

Please sign in to comment.