Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 1.1.3 #4958

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6245089
Hadoop: make libjfs singleton to avoid possible jnr weakhashmap infin…
tangyoupeng Feb 18, 2024
468ccae
Hadoop: use auto increment fs handle to avoid possible conflict (#4411)
tangyoupeng Feb 21, 2024
9fda3ae
vfs: fix file length after fallocate & copyfilerange (#4427)
SandyXSD Feb 28, 2024
b9cb903
flush the source file of copy_file_range (#4436)
davies Feb 29, 2024
ffa686e
vfs: invalidate entry cache in readdir (#4453)
SandyXSD Mar 6, 2024
d7bc327
gateway: add open flag when downloading an object (#4507)
SandyXSD Mar 14, 2024
9c48fea
fix guid lookupGroup (#4532)
tangyoupeng Mar 18, 2024
0228f13
Hadoop: rmr check perm only when is not empty (#4539)
tangyoupeng Mar 20, 2024
e61402c
meta: fix negative values in quota before used in statfs (#4591)
SandyXSD Mar 27, 2024
7dfbd36
meta/sql: fix nanosecond part in Write (#4618)
SandyXSD Apr 1, 2024
44b1e55
Fix panic when reading and writing s.writer concurrently (#4710)
polyrabbit Apr 17, 2024
10250b2
postgres: fix postgres address parse (#4731)
zhijian-pro Apr 18, 2024
0783284
cmd/clone: set the attr should be done after checking permissions (#4…
zhijian-pro Apr 22, 2024
4f002f9
meta/redis: fix some transactions that are not wrapped by multi/exec …
SandyXSD May 1, 2024
dcd6efe
cmd/clone: fix src mode check (#4856)
zhijian-pro May 15, 2024
6da52bd
vfs: fix the race of getting file length (#4876)
SandyXSD May 21, 2024
7ae55d0
fix: JfsObjects.CompleteMultipartUpload (#4893)
prOOrc May 28, 2024
6355277
meta: fix protection check for compaction (#4901)
SandyXSD May 30, 2024
ed49485
vfs: fix the issue that plock may be unlocked by mistake (#4910)
SandyXSD May 30, 2024
8c1188e
upgrade golang.org/x/net to 0.23 (#4911)
davies May 30, 2024
b70501a
Manager's IP address is never set in sync cluster mode (#4939)
polyrabbit Jun 13, 2024
20276e1
CI: upgrade golangci-lint to v1.54
SandyXSD Jun 20, 2024
56cba4f
skip redis test in ci
zhoucheng361 Jun 20, 2024
c13ce55
CI: remove keyctl05 from ltpsyscall test
zhoucheng361 Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/bash/rm_syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ getxattr05 getxattr05
finit_module02 finit_module02
msgstress03 msgstress03
kill11 kill11
keyctl05 keyctl05
2 changes: 1 addition & 1 deletion .github/workflows/redis_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
tar -xvf redis.tar.gz -C redis --strip-components 1
cd redis
make
make test
# make test
stat /tmp/jfs
df -lh

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.0
version: v1.54

- name: Setup upterm session
if: ${{ failure() && github.event_name == 'workflow_dispatch' && github.event.inputs.debug == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion cmd/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (f *jFile) Close() error {
}

func (j *juiceFS) Get(key string, off, limit int64) (io.ReadCloser, error) {
f, err := j.jfs.Open(ctx, j.path(key), 0)
f, err := j.jfs.Open(ctx, j.path(key), vfs.MODE_MASK_R)
if err != 0 {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ require (
go.etcd.io/etcd/client/v3 v3.5.9
go.uber.org/automaxprocs v1.5.2
go.uber.org/zap v1.20.0
golang.org/x/crypto v0.17.0
golang.org/x/net v0.17.0
golang.org/x/crypto v0.21.0
golang.org/x/net v0.23.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sync v0.2.0
golang.org/x/sys v0.15.0
golang.org/x/term v0.15.0
golang.org/x/sys v0.18.0
golang.org/x/term v0.18.0
golang.org/x/text v0.14.0
google.golang.org/api v0.94.0
google.golang.org/protobuf v1.30.0
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,8 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1225,8 +1225,8 @@ golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1369,15 +1369,15 @@ golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 1 addition & 1 deletion pkg/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func (fs *FileSystem) CopyFileRange(ctx meta.Context, src string, soff uint64, d
if err != 0 {
return
}
err = fs.m.CopyFileRange(ctx, sfi.inode, soff, dfi.inode, doff, size, 0, &written)
err = fs.m.CopyFileRange(ctx, sfi.inode, soff, dfi.inode, doff, size, 0, &written, nil)
return
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/fuse/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,12 @@ func (fs *fileSystem) ReadDir(cancel <-chan struct{}, in *fuse.ReadIn, out *fuse
defer releaseContext(ctx)
entries, _, err := fs.v.Readdir(ctx, Ino(in.NodeId), in.Size, int(in.Offset), in.Fh, false)
var de fuse.DirEntry
for _, e := range entries {
for i, e := range entries {
de.Ino = uint64(e.Inode)
de.Name = string(e.Name)
de.Mode = e.Attr.SMode()
if !out.AddDirEntry(de) {
fs.v.UpdateReaddirOffset(ctx, Ino(in.NodeId), in.Fh, int(in.Offset)+i)
break
}
}
Expand All @@ -371,12 +372,13 @@ func (fs *fileSystem) ReadDirPlus(cancel <-chan struct{}, in *fuse.ReadIn, out *
entries, readAt, err := fs.v.Readdir(ctx, Ino(in.NodeId), in.Size, int(in.Offset), in.Fh, true)
ctx.start = readAt
var de fuse.DirEntry
for _, e := range entries {
for i, e := range entries {
de.Ino = uint64(e.Inode)
de.Name = string(e.Name)
de.Mode = e.Attr.SMode()
eo := out.AddDirLookupEntry(de)
if eo == nil {
fs.v.UpdateReaddirOffset(ctx, Ino(in.NodeId), in.Fh, int(in.Offset)+i)
break
}
if e.Attr.Full {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (n *jfsObjects) GetObjectNInfo(ctx context.Context, bucket, object string,
if err != nil {
return
}
f, eno := n.fs.Open(mctx, n.path(bucket, object), 0)
f, eno := n.fs.Open(mctx, n.path(bucket, object), vfs.MODE_MASK_R)
if eno != 0 {
return nil, jfsToObjectErr(ctx, eno, bucket, object)
}
Expand Down Expand Up @@ -925,7 +925,7 @@ func (n *jfsObjects) CompleteMultipartUpload(ctx context.Context, bucket, object
var total uint64
for _, part := range parts {
p := n.ppath(bucket, uploadID, strconv.Itoa(part.PartNumber))
copied, eno := n.fs.CopyFileRange(mctx, p, 0, tmp, total, 1<<30)
copied, eno := n.fs.CopyFileRange(mctx, p, 0, tmp, total, 5<<30)
if eno != 0 {
err = jfsToObjectErr(ctx, eno, bucket, object, uploadID)
logger.Errorf("merge parts: %s", err)
Expand Down
19 changes: 7 additions & 12 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,25 +986,20 @@ func (m *baseMeta) StatFS(ctx Context, ino Ino, totalspace, availspace, iused, i
if q == nil {
continue
}
q.sanitize()
if usage == nil {
usage = q
}
if q.MaxSpace > 0 {
ls := q.MaxSpace - q.UsedSpace
if ls < 0 {
ls = 0
}
if uint64(ls) < *availspace {
*availspace = uint64(ls)
ls := uint64(q.MaxSpace - q.UsedSpace)
if ls < *availspace {
*availspace = ls
}
}
if q.MaxInodes > 0 {
li := q.MaxInodes - q.UsedInodes
if li < 0 {
li = 0
}
if uint64(li) < *iavail {
*iavail = uint64(li)
li := uint64(q.MaxInodes - q.UsedInodes)
if li < *iavail {
*iavail = li
}
}
}
Expand Down
73 changes: 57 additions & 16 deletions pkg/meta/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,25 +476,25 @@ func testMetaClient(t *testing.T, m Meta) {
if len(slices) != 2 || slices[0].Id != 0 || slices[0].Size != 100 || slices[1].Id != sliceId || slices[1].Size != 100 {
t.Fatalf("slices: %v", slices)
}
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocKeepSize, 100, 50); st != 0 {
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocKeepSize, 100, 50, nil); st != 0 {
t.Fatalf("fallocate: %s", st)
}
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocCollapesRange, 100, 50); st != syscall.EINVAL {
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocCollapesRange, 100, 50, nil); st != syscall.EINVAL {
t.Fatalf("fallocate: %s", st)
}
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocInsertRange, 100, 50); st != syscall.EINVAL {
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocInsertRange, 100, 50, nil); st != syscall.EINVAL {
t.Fatalf("fallocate: %s", st)
}
if st := m.Fallocate(ctx, inode, fallocCollapesRange, 100, 50); st != syscall.ENOTSUP {
if st := m.Fallocate(ctx, inode, fallocCollapesRange, 100, 50, nil); st != syscall.ENOTSUP {
t.Fatalf("fallocate: %s", st)
}
if st := m.Fallocate(ctx, inode, fallocPunchHole, 100, 50); st != syscall.EINVAL {
if st := m.Fallocate(ctx, inode, fallocPunchHole, 100, 50, nil); st != syscall.EINVAL {
t.Fatalf("fallocate: %s", st)
}
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocKeepSize, 0, 0); st != syscall.EINVAL {
if st := m.Fallocate(ctx, inode, fallocPunchHole|fallocKeepSize, 0, 0, nil); st != syscall.EINVAL {
t.Fatalf("fallocate: %s", st)
}
if st := m.Fallocate(ctx, parent, fallocPunchHole|fallocKeepSize, 100, 50); st != syscall.EPERM {
if st := m.Fallocate(ctx, parent, fallocPunchHole|fallocKeepSize, 100, 50, nil); st != syscall.EPERM {
t.Fatalf("fallocate dir: %s", st)
}
if st := m.Read(ctx, inode, 0, &slices); st != 0 {
Expand Down Expand Up @@ -659,6 +659,27 @@ func testMetaClient(t *testing.T, m Meta) {
t.Fatalf("total space %d, iavail %d", totalspace, iavail)
}

base.loadQuotas()
base.quotaMu.RLock()
q := base.dirQuotas[subIno]
base.quotaMu.RUnlock()
q.update(4<<10, 15) // used > max
base.doFlushQuotas()
if st := m.StatFS(ctx, subIno, &totalspace, &availspace, &iused, &iavail); st != 0 {
t.Fatalf("statfs: %s", st)
}
if totalspace != 4<<10 || availspace != 0 || iused != 15 || iavail != 0 {
t.Fatalf("total space %d, availspace %d, iused %d, iavail %d", totalspace, availspace, iused, iavail)
}
q.update(-8<<10, -20) // used < 0
base.doFlushQuotas()
if st := m.StatFS(ctx, subIno, &totalspace, &availspace, &iused, &iavail); st != 0 {
t.Fatalf("statfs: %s", st)
}
if totalspace != 1<<10 || availspace != 1<<10 || iused != 0 || iavail != 10 {
t.Fatalf("total space %d, availspace %d, iused %d, iavail %d", totalspace, availspace, iused, iavail)
}

if st := m.Rmdir(ctx, 1, "subdir"); st != 0 {
t.Fatalf("rmdir subdir: %s", st)
}
Expand Down Expand Up @@ -1283,6 +1304,26 @@ func testCompaction(t *testing.T, m Meta, trash bool) {
if len(slices) != 1 || slices[0].Len != 3<<20 {
t.Fatalf("inode %d should be compacted, but have %d slices, size %d", inode, len(slices), slices[0].Len)
}

m.NewSlice(ctx, &sliceId)
_ = m.Write(ctx, inode, 2, 0, Slice{Id: sliceId, Size: 2338508, Len: 2338508}, time.Now())
m.NewSlice(ctx, &sliceId)
_ = m.Write(ctx, inode, 2, 8829056, Slice{Id: sliceId, Size: 1074933, Len: 1074933}, time.Now())
m.NewSlice(ctx, &sliceId)
_ = m.Write(ctx, inode, 2, 7663608, Slice{Id: sliceId, Size: 41480, Len: 4148}, time.Now())
_ = m.Fallocate(ctx, inode, fallocZeroRange, 2*ChunkSize+4515328, 3152428, nil)
_ = m.Fallocate(ctx, inode, fallocZeroRange, 2*ChunkSize+4515328, 2607724, nil)
if c, ok := m.(compactor); ok {
c.compactChunk(inode, 2, true)
}
if st := m.Read(ctx, inode, 2, &slices); st != 0 {
t.Fatalf("read 1: %s", st)
}
// compact twice: 4515328+2607724-2338508 = 4784544; 8829056+1074933-2338508-4784544=2780937
if len(slices) != 3 || slices[0].Len != 2338508 || slices[1].Len != 4784544 || slices[2].Len != 2780937 {
t.Fatalf("inode %d should be compacted, but have %d slices, size %d,%d,%d",
inode, len(slices), slices[0].Len, slices[1].Len, slices[2].Len)
}
}

func testConcurrentWrite(t *testing.T, m Meta) {
Expand Down Expand Up @@ -1413,7 +1454,7 @@ func testCopyFileRange(t *testing.T, m Meta) {
m.Write(ctx, iin, 3, 0, Slice{12, 63 << 20, 10 << 20, 30 << 20}, time.Now())
m.Write(ctx, iout, 2, 10<<20, Slice{13, 50 << 20, 10 << 20, 30 << 20}, time.Now())
var copied uint64
if st := m.CopyFileRange(ctx, iin, 150, iout, 30<<20, 200<<20, 0, &copied); st != 0 {
if st := m.CopyFileRange(ctx, iin, 150, iout, 30<<20, 200<<20, 0, &copied, nil); st != 0 {
t.Fatalf("copy file range: %s", st)
}
var expected uint64 = 200 << 20
Expand Down Expand Up @@ -1964,17 +2005,17 @@ func testAttrFlags(t *testing.T, m Meta) {
if st := m.SetAttr(ctx, fallocFile, SetAttrFlag, 0, attr); st != 0 {
t.Fatalf("setattr f: %s", st)
}
if st := m.Fallocate(ctx, fallocFile, fallocKeepSize, 0, 1024); st != 0 {
if st := m.Fallocate(ctx, fallocFile, fallocKeepSize, 0, 1024, nil); st != 0 {
t.Fatalf("fallocate f: %s", st)
}
if st := m.Fallocate(ctx, fallocFile, fallocKeepSize|fallocZeroRange, 0, 1024); st != syscall.EPERM {
if st := m.Fallocate(ctx, fallocFile, fallocKeepSize|fallocZeroRange, 0, 1024, nil); st != syscall.EPERM {
t.Fatalf("fallocate f: %s", st)
}
attr.Flags = FlagImmutable
if st := m.SetAttr(ctx, fallocFile, SetAttrFlag, 0, attr); st != 0 {
t.Fatalf("setattr f: %s", st)
}
if st := m.Fallocate(ctx, fallocFile, fallocKeepSize, 0, 1024); st != syscall.EPERM {
if st := m.Fallocate(ctx, fallocFile, fallocKeepSize, 0, 1024, nil); st != syscall.EPERM {
t.Fatalf("fallocate f: %s", st)
}

Expand All @@ -1985,21 +2026,21 @@ func testAttrFlags(t *testing.T, m Meta) {
if st := m.Create(ctx, 1, "copydstfile", 0644, 022, 0, &copydstFile, nil); st != 0 {
t.Fatalf("create f: %s", st)
}
if st := m.Fallocate(ctx, copysrcFile, 0, 0, 1024); st != 0 {
if st := m.Fallocate(ctx, copysrcFile, 0, 0, 1024, nil); st != 0 {
t.Fatalf("fallocate f: %s", st)
}
attr.Flags = FlagAppend
if st := m.SetAttr(ctx, copydstFile, SetAttrFlag, 0, attr); st != 0 {
t.Fatalf("setattr f: %s", st)
}
if st := m.CopyFileRange(ctx, copysrcFile, 0, copydstFile, 0, 1024, 0, nil); st != syscall.EPERM {
if st := m.CopyFileRange(ctx, copysrcFile, 0, copydstFile, 0, 1024, 0, nil, nil); st != syscall.EPERM {
t.Fatalf("copy_file_range f: %s", st)
}
attr.Flags = FlagImmutable
if st := m.SetAttr(ctx, copydstFile, SetAttrFlag, 0, attr); st != 0 {
t.Fatalf("setattr f: %s", st)
}
if st := m.CopyFileRange(ctx, copysrcFile, 0, copydstFile, 0, 1024, 0, nil); st != syscall.EPERM {
if st := m.CopyFileRange(ctx, copysrcFile, 0, copydstFile, 0, 1024, 0, nil, nil); st != syscall.EPERM {
t.Fatalf("copy_file_range f: %s", st)
}
}
Expand Down Expand Up @@ -2182,7 +2223,7 @@ func testDirStat(t *testing.T, m Meta) {
checkResult(0, align4K(0), 1)

// test dir with file and fallocate
if st := m.Fallocate(Background, fileInode, 0, 0, 4097); st != 0 {
if st := m.Fallocate(Background, fileInode, 0, 0, 4097, nil); st != 0 {
t.Fatalf("fallocate: %s", st)
}
time.Sleep(500 * time.Millisecond)
Expand Down Expand Up @@ -2313,7 +2354,7 @@ func testClone(t *testing.T, m Meta) {
if eno := m.Mknod(Background, dir3, "file3", TypeFile, 0777, 022, 0, "", &file3, nil); eno != 0 {
t.Fatalf("mknod: %s", eno)
}
if eno := m.Fallocate(Background, file3, 0, 0, 67108864); eno != 0 {
if eno := m.Fallocate(Background, file3, 0, 0, 67108864, nil); eno != 0 {
t.Fatalf("fallocate: %s", eno)
}

Expand Down
20 changes: 18 additions & 2 deletions pkg/meta/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ func (q *Quota) update(space, inodes int64) {
atomic.AddInt64(&q.newInodes, inodes)
}

// not thread safe
func (q *Quota) sanitize() {
if q.UsedSpace < 0 {
q.UsedSpace = 0
}
if q.MaxSpace > 0 && q.MaxSpace < q.UsedSpace {
q.MaxSpace = q.UsedSpace
}
if q.UsedInodes < 0 {
q.UsedInodes = 0
}
if q.MaxInodes > 0 && q.MaxInodes < q.UsedInodes {
q.MaxInodes = q.UsedInodes
}
}

// Meta is a interface for a meta service for file system.
type Meta interface {
// Name of database
Expand Down Expand Up @@ -354,7 +370,7 @@ type Meta interface {
// Truncate changes the length for given file.
Truncate(ctx Context, inode Ino, flags uint8, attrlength uint64, attr *Attr, skipPermCheck bool) syscall.Errno
// Fallocate preallocate given space for given file.
Fallocate(ctx Context, inode Ino, mode uint8, off uint64, size uint64) syscall.Errno
Fallocate(ctx Context, inode Ino, mode uint8, off uint64, size uint64, length *uint64) syscall.Errno
// ReadLink returns the target of a symlink.
ReadLink(ctx Context, inode Ino, path *[]byte) syscall.Errno
// Symlink creates a symlink in a directory with given name.
Expand Down Expand Up @@ -391,7 +407,7 @@ type Meta interface {
// InvalidateChunkCache invalidate chunk cache
InvalidateChunkCache(ctx Context, inode Ino, indx uint32) syscall.Errno
// CopyFileRange copies part of a file to another one.
CopyFileRange(ctx Context, fin Ino, offIn uint64, fout Ino, offOut uint64, size uint64, flags uint32, copied *uint64) syscall.Errno
CopyFileRange(ctx Context, fin Ino, offIn uint64, fout Ino, offOut uint64, size uint64, flags uint32, copied, outLength *uint64) syscall.Errno
// GetParents returns a map of node parents (> 1 parents if hardlinked)
GetParents(ctx Context, inode Ino) map[Ino]int
// GetDirStat returns the space and inodes usage of a directory.
Expand Down
Loading
Loading