From f2ab5ef24de6012a21143374f337309f6ce24a8d Mon Sep 17 00:00:00 2001 From: jiefenghuang Date: Thu, 29 Aug 2024 18:12:48 +0800 Subject: [PATCH] fix/meta: evict symlink cache after unlink Signed-off-by: jiefenghuang --- pkg/meta/base_test.go | 17 +++++++++++++++++ pkg/meta/redis.go | 3 +++ pkg/meta/sql.go | 3 +++ pkg/meta/tkv.go | 3 +++ 4 files changed, 26 insertions(+) diff --git a/pkg/meta/base_test.go b/pkg/meta/base_test.go index 9c58c1d9aa89..876494d58d48 100644 --- a/pkg/meta/base_test.go +++ b/pkg/meta/base_test.go @@ -692,6 +692,23 @@ func testMetaClient(t *testing.T, m Meta) { if st := m.ReadLink(ctx, parent, &target1); st != syscall.EINVAL { t.Fatalf("readlink d: %s", st) } + + // case: symlink cache + if st := m.Unlink(ctx, 1, "s"); st != 0 { + t.Fatalf("unlink s: %s", st) + } + if st := m.ReadLink(ctx, inode, &target1); st == 0 { + t.Fatalf("readlink s should fail") + } + + // restore symlink + if st := m.Symlink(ctx, 1, "s", "/f", &inode, attr); st != 0 { + t.Fatalf("symlink s -> /f: %s", st) + } + if attr.Mode&0777 != 0777 { + t.Fatalf("mode of symlink should be 0777") + } + if st := m.Lookup(ctx, 1, "f", &inode, attr, true); st != 0 { t.Fatalf("lookup f: %s", st) } diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index c875eb97ef69..1dd72e1160df 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -1485,6 +1485,9 @@ func (m *redisMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, s } m.updateStats(newSpace, newInode) } + if err == nil && _type == TypeSymlink { + m.symlinks.Delete(inode) + } return errno(err) } diff --git a/pkg/meta/sql.go b/pkg/meta/sql.go index 9803051fe54d..9e9e3ddf78c3 100644 --- a/pkg/meta/sql.go +++ b/pkg/meta/sql.go @@ -1565,6 +1565,9 @@ func (m *dbMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip if err == nil && attr != nil { m.parseAttr(&n, attr) } + if err == nil && n.Type == TypeSymlink { + m.symlinks.Delete(n.Inode) + } return errno(err) } diff --git a/pkg/meta/tkv.go b/pkg/meta/tkv.go index 357bcfd1e97f..f79ad2ad7fff 100644 --- a/pkg/meta/tkv.go +++ b/pkg/meta/tkv.go @@ -1354,6 +1354,9 @@ func (m *kvMeta) doUnlink(ctx Context, parent Ino, name string, attr *Attr, skip } m.updateStats(newSpace, newInode) } + if err == nil && _type == TypeSymlink { + m.symlinks.Delete(inode) + } return errno(err) }