Skip to content

Commit

Permalink
vfs:support O_TMPFILE flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Nov 20, 2024
1 parent 47b02d5 commit 3471997
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ require (

replace github.com/minio/minio v0.0.0-20210206053228-97fe57bba92c => github.com/juicedata/minio v0.0.0-20240912134328-6a47725331ab

replace github.com/hanwen/go-fuse/v2 v2.1.1-0.20210611132105-24a1dfe6b4f8 => github.com/juicedata/go-fuse/v2 v2.1.1-0.20240809072820-d78c97ed7b7a
replace github.com/hanwen/go-fuse/v2 v2.1.1-0.20210611132105-24a1dfe6b4f8 => github.com/juicedata/go-fuse/v2 v2.1.1-0.20241119160225-81ccbb4066e4

replace github.com/dgrijalva/jwt-go v3.2.0+incompatible => github.com/golang-jwt/jwt v3.2.1+incompatible

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juicedata/cli/v2 v2.19.4-0.20230605075551-9c9c5c0dce83 h1:RyHTka3jCnTaUqfRYjlwcQlr53aasmkvHEbYLXthqr8=
github.com/juicedata/cli/v2 v2.19.4-0.20230605075551-9c9c5c0dce83/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI=
github.com/juicedata/go-fuse/v2 v2.1.1-0.20240809072820-d78c97ed7b7a h1:Rzopfv1+KpROzMWd6NVAs1wTjr5bc5ZdzIhIs0u5XBc=
github.com/juicedata/go-fuse/v2 v2.1.1-0.20240809072820-d78c97ed7b7a/go.mod h1:xKwi1cF7nXAOBCXujD5ie0ZKsxc8GGSA1rlMJc+8IJs=
github.com/juicedata/go-fuse/v2 v2.1.1-0.20241119160225-81ccbb4066e4 h1:lMjWJaHLita+9s8z174ZUp8L1MtIMUl0FCau/dfBJsQ=
github.com/juicedata/go-fuse/v2 v2.1.1-0.20241119160225-81ccbb4066e4/go.mod h1:xKwi1cF7nXAOBCXujD5ie0ZKsxc8GGSA1rlMJc+8IJs=
github.com/juicedata/go-nfs-client v0.0.0-20231018052507-dbca444fa7e8 h1:mVVipCbohnzKZPiHGzFncLKEJZpypqjpGr4End2PP48=
github.com/juicedata/go-nfs-client v0.0.0-20231018052507-dbca444fa7e8/go.mod h1:xOMqi3lOrcGe9uZLnSzgaq94Vc3oz6VPCNDLJUnXpKs=
github.com/juicedata/godaemon v0.0.0-20210629045518-3da5144a127d h1:kpQMvNZJKGY3PTt7OSoahYc4nM0HY67SvK0YyS0GLwA=
Expand Down
3 changes: 3 additions & 0 deletions pkg/meta/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,9 @@ func (m *baseMeta) Link(ctx Context, inode, parent Ino, name string, attr *Attr)
if attr.Typ == TypeDirectory {
return syscall.EPERM
}
if attr.Flags*FlagTmpFile != 0 {
return syscall.ENOENT
}
if m.checkDirQuota(ctx, parent, align4K(attr.Length), 1) {
return syscall.EDQUOT
}
Expand Down
1 change: 1 addition & 0 deletions pkg/meta/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const (
const (
FlagImmutable = 1 << iota
FlagAppend
FlagTmpFile
)

const (
Expand Down
18 changes: 18 additions & 0 deletions pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"syscall"
"time"

"github.com/google/uuid"
"github.com/juicedata/juicefs/pkg/acl"
"github.com/juicedata/juicefs/pkg/chunk"
"github.com/juicedata/juicefs/pkg/meta"
Expand Down Expand Up @@ -474,10 +475,17 @@ func (v *VFS) Releasedir(ctx Context, ino Ino, fh uint64) int {
return 0
}

const O_TMPFILE = 020000000

func (v *VFS) Create(ctx Context, parent Ino, name string, mode uint16, cumask uint16, flags uint32) (entry *meta.Entry, fh uint64, err syscall.Errno) {
defer func() {
logit(ctx, "create", err, "(%d,%s,%s:0%04o):%s [fh:%d]", parent, name, smode(mode), mode, (*Entry)(entry), fh)
}()
// O_TMPFILE support
doUnlink := runtime.GOOS == "linux" && flags&O_TMPFILE != 0
if doUnlink {
name = fmt.Sprintf("tmpfile_%s", uuid.New().String())
}
if parent == rootID && IsSpecialName(name) {
err = syscall.EEXIST
return
Expand All @@ -499,6 +507,16 @@ func (v *VFS) Create(ctx Context, parent Ino, name string, mode uint16, cumask u
entry = &meta.Entry{Inode: inode, Attr: attr}
v.invalidateDirHandle(parent, name, inode, attr)
}

if doUnlink {
if flags&syscall.O_EXCL != 0 {
attr.Flags |= meta.FlagTmpFile
if err = v.Meta.SetAttr(ctx, inode, uint16(meta.SetAttrFlag), 0, attr); err != 0 {
return
}
}
err = v.Unlink(ctx, parent, name)
}
return
}

Expand Down

0 comments on commit 3471997

Please sign in to comment.