Skip to content

Commit 7291ac8

Browse files
authored
Fix: overlay umount error by mountpoint (#1698)
Signed-off-by: tgfree <tgfree7@gmail.com> Fix: overlay umount error by mountpoint
1 parent e971bc8 commit 7291ac8

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

pkg/prune/build_pruner.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package prune
1717
import (
1818
"github.com/sealerio/sealer/common"
1919
"github.com/sealerio/sealer/utils/mount"
20-
osi "github.com/sealerio/sealer/utils/os"
2120
)
2221

2322
type buildPrune struct {
@@ -33,10 +32,7 @@ func NewBuildPrune() Pruner {
3332
func (b buildPrune) Select() ([]string, error) {
3433
var pruneList []string
3534
// umount all tmp dir, and delete it
36-
pruneUnits, err := osi.GetDirNameListInDir(b.pruneRootDir, osi.FilterOptions{
37-
All: true,
38-
WithFullPath: true,
39-
})
35+
pruneUnits, err := mount.GetDirNameListInDir(b.pruneRootDir)
4036
if err != nil {
4137
return pruneList, err
4238
}

utils/mount/mount_service.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import (
1919
"net"
2020
"strings"
2121

22+
"github.com/moby/sys/mountinfo"
23+
"github.com/sealerio/sealer/utils/ssh"
2224
"github.com/shirou/gopsutil/disk"
2325
"github.com/sirupsen/logrus"
2426

25-
"github.com/sealerio/sealer/utils/exec"
2627
"github.com/sealerio/sealer/utils/os/fs"
27-
"github.com/sealerio/sealer/utils/ssh"
2828
strUtils "github.com/sealerio/sealer/utils/strings"
2929
)
3030

@@ -120,6 +120,18 @@ func NewMountService(target, upper string, lowLayers []string) (Service, error)
120120
}, nil
121121
}
122122

123+
func GetDirNameListInDir(dir string) ([]string, error) {
124+
var dirs []string
125+
infos, err := mountinfo.GetMounts(mountinfo.PrefixFilter(dir))
126+
if err != nil {
127+
return dirs, err
128+
}
129+
for _, info := range infos {
130+
dirs = append(dirs, info.Mountpoint)
131+
}
132+
return dirs, nil
133+
}
134+
123135
//NewMountServiceByTarget will filter file system by target,if not existed,return false.
124136
func NewMountServiceByTarget(target string) Service {
125137
mounted, info := GetMountDetails(target)
@@ -141,12 +153,11 @@ type Info struct {
141153
}
142154

143155
func GetMountDetails(target string) (bool, *Info) {
144-
cmd := fmt.Sprintf("mount | grep %s", target)
145-
result, err := exec.RunSimpleCmd(cmd)
156+
infos, err := mountinfo.GetMounts(mountinfo.SingleEntryFilter(target))
146157
if err != nil {
147158
return false, nil
148159
}
149-
return mountCmdResultSplit(result, target)
160+
return mountCmdResultSplit(infos[0].VFSOptions, target)
150161
}
151162

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

0 commit comments

Comments
 (0)