Skip to content

Commit

Permalink
info: fix info on read-only mountpoint (#4085)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored Oct 9, 2023
1 parent d5d1e29 commit 4643d07
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
4 changes: 4 additions & 0 deletions pkg/meta/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 19 additions & 16 deletions pkg/meta/tkv_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4643d07

Please sign in to comment.