From f10e276574a1cbf6df033decb20f43c1ea4e01c0 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 14 Jun 2022 17:20:15 +0200 Subject: [PATCH] drivers: enhance check for mount fs type when checking that a mount has a specific file system type, also validate that it is 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 --- drivers/driver_linux.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/driver_linux.go b/drivers/driver_linux.go index 0fe3eea7ae..505c940a89 100644 --- a/drivers/driver_linux.go +++ b/drivers/driver_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package graphdriver @@ -168,5 +169,16 @@ func Mounted(fsType FsMagic, mountPath string) (bool, error) { 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), &buf); err != nil { + return true, err + } + return FsMagic(buf.Type) != fsType, nil }