Skip to content

Commit

Permalink
meta: update atime on Open
Browse files Browse the repository at this point in the history
Signed-off-by: Eryu Guan <[email protected]>
  • Loading branch information
eryugey committed May 7, 2023
1 parent 6eab80c commit d1e0016
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -1495,10 +1495,19 @@ func (m *baseMeta) Rename(ctx Context, parentSrc Ino, nameSrc string, parentDst
return st
}

func (m *baseMeta) Open(ctx Context, inode Ino, flags uint32, attr *Attr) syscall.Errno {
func (m *baseMeta) Open(ctx Context, inode Ino, flags uint32, attr *Attr) (rerr syscall.Errno) {
if m.conf.ReadOnly && flags&(syscall.O_WRONLY|syscall.O_RDWR|syscall.O_TRUNC|syscall.O_APPEND) != 0 {
return syscall.EROFS
}

defer func() {
if rerr == 0 {
if err := m.en.touchAtime(ctx, inode, attr); err != 0 {
logger.Warnf("open %v update atime: %s", inode, err)
}
}
}()

if m.conf.OpenCache > 0 && m.of.OpenCheck(inode, attr) {
return 0
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/vfs/vfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ func TestAtime(t *testing.T) {
if fe, e := v.GetAttr(ctx, de.Inode, 0); e != 0 || fe.Attr.Atime != 1234 || fe.Attr.Atimensec != 5678 {
t.Fatalf("getattr after readdir d1: %s atime: %v, atimensec %v", e, fe.Attr.Atime, fe.Attr.Atimensec)
}
if fe, _, e := v.Open(ctx, fe.Inode, syscall.O_RDWR); e != 0 || fe.Attr.Atime != 1234 || fe.Attr.Atimensec != 5678 {
t.Fatalf("open f1: %s atime: %v, atimensec %v", e, fe.Attr.Atime, fe.Attr.Atimensec)
}

// set relatime
v.Conf.Meta.AtimeMode = meta.RelAtime
Expand Down Expand Up @@ -994,4 +997,10 @@ func TestAtime(t *testing.T) {
if fe, e := v.GetAttr(ctx, de.Inode, 0); e != 0 || fe.Attr.Atime < now.Unix() {
t.Fatalf("getattr after readdir d2: %s atime: %v, now %v", e, fe.Attr.Atime, now.Unix())
}
now = time.Now()
time.Sleep(time.Second)
// update atime on open
if fe, _, e := v.Open(ctx, fe.Inode, syscall.O_RDWR); e != 0 || fe.Attr.Atime < now.Unix() {
t.Fatalf("open f1: %s atime: %v, atimensec %v", e, fe.Attr.Atime, fe.Attr.Atimensec)
}
}

0 comments on commit d1e0016

Please sign in to comment.