Skip to content

Commit c318613

Browse files
rfjakobhanwen
authored andcommitted
fs: tests: add TestStaleHardlinks (fails at the moment)
This test shows a problem in selecting a random path for a node when there is more than one. The failure looks like this: 18:41:50.796468 rx 136: LOOKUP n1 ["link0"] 6b 18:41:50.796489 tx 136: OK, {n2 g1 tE=0s tA=0s {M0100600 SZ=0 L=1 1026:1026 B0*4096 i0:269663 A 1616348510.793212 M 1616348510.793212 C 1616348510.795212}} 18:41:50.796535 rx 138: OPEN n2 {O_RDONLY,0x8000} 18:41:50.796557 tx 138: 2=no such file or directory, {Fh 0 } The LOOKUP succeeds (because the file "link0" is there). But the OPEN fails because go-fuse chooses another (stale) path. I will try to make the behavoir more robust against changes behind our back, but this patch only adds a test to show the problem. Change-Id: I39b31ba717ddaaad7dda6ecd86707c75cd25102e
1 parent 7b2174e commit c318613

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

fs/simple_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,51 @@ func TestFsstress(t *testing.T) {
630630
}
631631
}
632632

633+
// TestStaleHardlinks creates a lot of hard links and deletes them again
634+
// behind the back of the loopback fs. Then opens the original file.
635+
//
636+
// Fails at the moment. Core of the problem:
637+
//
638+
// 18:41:50.796468 rx 136: LOOKUP n1 ["link0"] 6b
639+
// 18:41:50.796489 tx 136: OK, {n2 g1 tE=0s tA=0s {M0100600 SZ=0 L=1 1026:1026 B0*4096 i0:269663 A 1616348510.793212 M 1616348510.793212 C 1616348510.795212}}
640+
// 18:41:50.796535 rx 138: OPEN n2 {O_RDONLY,0x8000}
641+
// 18:41:50.796557 tx 138: 2=no such file or directory, {Fh 0 }
642+
func TestStaleHardlinks(t *testing.T) {
643+
// Disable all caches we can disable
644+
tc := newTestCase(t, &testOptions{attrCache: false, entryCache: false})
645+
defer tc.Clean()
646+
647+
// "link0" is original file
648+
link0 := tc.mntDir + "/link0"
649+
if fd, err := syscall.Creat(link0, 0600); err != nil {
650+
t.Fatal(err)
651+
} else {
652+
syscall.Close(fd)
653+
}
654+
// Create hardlinks via mntDir
655+
for i := 1; i < 20; i++ {
656+
linki := fmt.Sprintf(tc.mntDir+"/link%d", i)
657+
if err := syscall.Link(link0, linki); err != nil {
658+
t.Fatal(err)
659+
}
660+
}
661+
// Delete hardlinks via origDir (behind loopback fs's back)
662+
for i := 1; i < 20; i++ {
663+
linki := fmt.Sprintf(tc.origDir+"/link%d", i)
664+
if err := syscall.Unlink(linki); err != nil {
665+
t.Fatal(err)
666+
}
667+
}
668+
// Try to open link0 via mntDir
669+
fd, err := syscall.Open(link0, syscall.O_RDONLY, 0)
670+
if err != nil {
671+
t.Error(err)
672+
} else {
673+
syscall.Close(fd)
674+
}
675+
676+
}
677+
633678
func init() {
634679
syscall.Umask(0)
635680
}

0 commit comments

Comments
 (0)