From 4643d07edbaccebbfb599a4d383ddc2c66a7ed0d Mon Sep 17 00:00:00 2001 From: Davies Liu Date: Mon, 9 Oct 2023 13:01:05 +0800 Subject: [PATCH] info: fix info on read-only mountpoint (#4085) --- pkg/meta/base_test.go | 4 ++++ pkg/meta/tkv_lock.go | 35 +++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkg/meta/base_test.go b/pkg/meta/base_test.go index b563d8cbe267..3808f1c6bb53 100644 --- a/pkg/meta/base_test.go +++ b/pkg/meta/base_test.go @@ -1717,6 +1717,10 @@ func testReadOnly(t *testing.T, m Meta) { if st := m.Open(ctx, inode, syscall.O_RDWR, attr); st != syscall.EROFS { t.Fatalf("open f: %s", st) } + + if plocks, flocks, err := m.ListLocks(ctx, 1); err != nil || len(plocks) != 0 || len(flocks) != 0 { + t.Fatalf("list locks: %v %v %v", plocks, flocks, err) + } } func testConcurrentDir(t *testing.T, m Meta) { diff --git a/pkg/meta/tkv_lock.go b/pkg/meta/tkv_lock.go index 7d6cffa2c4b2..8b799fed6f5c 100644 --- a/pkg/meta/tkv_lock.go +++ b/pkg/meta/tkv_lock.go @@ -229,22 +229,25 @@ func (m *kvMeta) ListLocks(ctx context.Context, inode Ino) ([]PLockItem, []FLock var flocks []FLockItem var plocks []PLockItem - err := m.txn(func(tx *kvTxn) error { - fv := tx.get(fKey) - fs := unmarshalFlock(fv) - for k, t := range fs { - flocks = append(flocks, FLockItem{ownerKey{k.sid, k.owner}, string(t)}) - } + fv, err := m.get(fKey) + if err != nil { + return nil, nil, err + } + fs := unmarshalFlock(fv) + for k, t := range fs { + flocks = append(flocks, FLockItem{ownerKey{k.sid, k.owner}, string(t)}) + } - pv := tx.get(pKey) - owners := unmarshalPlock(pv) - for k, records := range owners { - ls := loadLocks(records) - for _, l := range ls { - plocks = append(plocks, PLockItem{ownerKey{k.sid, k.owner}, l}) - } + pv, err := m.get(pKey) + if err != nil { + return nil, nil, err + } + owners := unmarshalPlock(pv) + for k, records := range owners { + ls := loadLocks(records) + for _, l := range ls { + plocks = append(plocks, PLockItem{ownerKey{k.sid, k.owner}, l}) } - return nil - }) - return plocks, flocks, err + } + return plocks, flocks, nil }