Commit 701e7fc8 authored by Kohei Tokunaga's avatar Kohei Tokunaga Committed by Han-Wen Nienhuys

Fix IOCTL to return the error allowed by overlayfs

Since kernel 5.15, IOCTL returning ENOSYS is not allowed in overlayfs lowerdirs.
https://github.com/torvalds/linux/commit/72db82115d2bdfbfba8b15a92d91872cfe1b40c6

This commit fixes this issue by returning ENOTTY which is allowed since
https://github.com/torvalds/linux/commit/5b0a414d06c3ed2097e32ef7944a4abb644b89bd

This fixes the issue in 5.16 and later but not in 5.15.
To fully fix this, maybe we'll need to implement IOCTL.
Signed-off-by: default avatarKohei Tokunaga <ktokunaga.mail@gmail.com>
Change-Id: Ib4a86a62e31980cd57d7153b78be82fa30190798
parent 934a183e
......@@ -10,6 +10,7 @@ import (
"log"
"reflect"
"runtime"
"syscall"
"time"
"unsafe"
)
......@@ -442,7 +443,7 @@ func doStatFs(server *Server, req *request) {
}
func doIoctl(server *Server, req *request) {
req.status = ENOSYS
req.status = Status(syscall.ENOTTY)
}
func doDestroy(server *Server, req *request) {
......
......@@ -5,8 +5,11 @@
package test
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
"time"
......@@ -14,8 +17,18 @@ import (
"golang.org/x/sys/unix"
"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/internal/testutil"
)
var enableOverlayfsTest bool
var enableOverlayfsTestFlag string = "test.overlayfs"
func init() {
// flag to enable test with overayfs. This would not work on kernel 5.15
// so don't enable on that kernel.
flag.BoolVar(&enableOverlayfsTest, enableOverlayfsTestFlag, false, "enable tests with overlayfs (would fail on kernel 5.15)")
}
func TestTouch(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
......@@ -118,6 +131,40 @@ func clearStatfs(s *syscall.Statfs_t) {
s.Flags = 0
}
// Check that fuse mount can serve as a overlayfs lowerdir.
func TestOverlayfs(t *testing.T) {
if !enableOverlayfsTest {
t.Skipf("this test must be enabled through the flag %q", enableOverlayfsTestFlag)
}
if os.Getuid() != 0 {
t.Skip("this test requires root")
}
tc := NewTestCase(t)
defer tc.Cleanup()
testfile := "test"
content := randomData(125)
tc.Mkdir(tc.origSubdir, 0777)
tc.WriteFile(filepath.Join(tc.origSubdir, testfile), content, 0700)
tmpMergedDir := testutil.TempDir()
defer os.RemoveAll(tmpMergedDir)
tmpWorkDir := testutil.TempDir()
defer os.RemoveAll(tmpWorkDir)
tmpUpperDir := testutil.TempDir()
defer os.RemoveAll(tmpUpperDir)
if err := unix.Mount("overlay", tmpMergedDir, "overlay", 0,
fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", tc.mnt, tmpUpperDir, tmpWorkDir)); err != nil {
t.Fatalf("failed to mount overlay: %v", err)
}
defer unix.Unmount(tmpMergedDir, 0)
err := os.Chtimes(filepath.Join(tmpMergedDir, "subdir", testfile), time.Unix(42, 0), time.Unix(43, 0))
if err != nil {
t.Fatalf("Chtimes failed: %v", err)
}
}
func TestFallocate(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment