Skip to content

Commit

Permalink
drivers: enhance check for mount fs type
Browse files Browse the repository at this point in the history
when checking that a mount has a specific file system type, also
validate that it is on a different than its parent directory.

This helps when using virtiofs as the underlying file system since the
check used for fuse-overlayfs would fail since they both use FUSE.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Jun 15, 2022
1 parent 388efef commit 4cbf3d4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion drivers/driver_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package graphdriver
Expand Down Expand Up @@ -165,8 +166,22 @@ func (c *defaultChecker) IsMounted(path string) bool {
// Mounted checks if the given path is mounted as the fs type
func Mounted(fsType FsMagic, mountPath string) (bool, error) {
var buf unix.Statfs_t
var bufParent unix.Statfs_t

if err := unix.Statfs(mountPath, &buf); err != nil {
return false, err
}
return FsMagic(buf.Type) == fsType, nil
if FsMagic(buf.Type) != fsType {
return false, nil
}
// it is already the root
if mountPath == "/" {
return true, nil
}
if err := unix.Statfs(filepath.Dir(mountPath), &bufParent); err != nil {
return true, err
}
// check that the parent directory is on a different mount
// than mountPath
return bufParent.Fsid != buf.Fsid, nil
}

0 comments on commit 4cbf3d4

Please sign in to comment.