mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/fileutil: use fcntl syscall wrappers from golang.org/x/sys/unix (#12316)
Direct syscalls using syscall.Syscall(SYS_*, ...) should no longer be used on darwin, see [1]. Instead, use the fcntl libSystem wrappers provided by the golang.org/x/sys/unix package which implement the same functionality. [1] https://golang.org/doc/go1.12#darwin
This commit is contained in:
parent
4136df7933
commit
add86bbd1a
@ -369,7 +369,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"project": "golang.org/x/sys/unix",
|
"project": "golang.org/x/sys",
|
||||||
"licenses": [
|
"licenses": [
|
||||||
{
|
{
|
||||||
"type": "BSD 3-clause \"New\" or \"Revised\" License",
|
"type": "BSD 3-clause \"New\" or \"Revised\" License",
|
||||||
|
1
go.mod
1
go.mod
@ -42,6 +42,7 @@ require (
|
|||||||
go.uber.org/zap v1.15.0
|
go.uber.org/zap v1.15.0
|
||||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc
|
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
|
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
|
||||||
|
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff
|
||||||
golang.org/x/text v0.3.3 // indirect
|
golang.org/x/text v0.3.3 // indirect
|
||||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2
|
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2
|
||||||
google.golang.org/grpc v1.26.0
|
google.golang.org/grpc v1.26.0
|
||||||
|
2
go.sum
2
go.sum
@ -185,6 +185,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
|
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
|
||||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8=
|
||||||
|
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0/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.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
@ -19,7 +19,8 @@ package fileutil
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func preallocExtend(f *os.File, sizeInBytes int64) error {
|
func preallocExtend(f *os.File, sizeInBytes int64) error {
|
||||||
@ -32,18 +33,18 @@ func preallocExtend(f *os.File, sizeInBytes int64) error {
|
|||||||
func preallocFixed(f *os.File, sizeInBytes int64) error {
|
func preallocFixed(f *os.File, sizeInBytes int64) error {
|
||||||
// allocate all requested space or no space at all
|
// allocate all requested space or no space at all
|
||||||
// TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag
|
// TODO: allocate contiguous space on disk with F_ALLOCATECONTIG flag
|
||||||
fstore := &syscall.Fstore_t{
|
fstore := &unix.Fstore_t{
|
||||||
Flags: syscall.F_ALLOCATEALL,
|
Flags: unix.F_ALLOCATEALL,
|
||||||
Posmode: syscall.F_PEOFPOSMODE,
|
Posmode: unix.F_PEOFPOSMODE,
|
||||||
Length: sizeInBytes}
|
Length: sizeInBytes,
|
||||||
p := unsafe.Pointer(fstore)
|
}
|
||||||
_, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_PREALLOCATE), uintptr(p))
|
err := unix.FcntlFstore(f.Fd(), unix.F_PREALLOCATE, fstore)
|
||||||
if errno == 0 || errno == syscall.ENOTSUP {
|
if err == nil || err == unix.ENOTSUP {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// wrong argument to fallocate syscall
|
// wrong argument to fallocate syscall
|
||||||
if errno == syscall.EINVAL {
|
if err == unix.EINVAL {
|
||||||
// filesystem "st_blocks" are allocated in the units of
|
// filesystem "st_blocks" are allocated in the units of
|
||||||
// "Allocation Block Size" (run "diskutil info /" command)
|
// "Allocation Block Size" (run "diskutil info /" command)
|
||||||
var stat syscall.Stat_t
|
var stat syscall.Stat_t
|
||||||
@ -61,5 +62,5 @@ func preallocFixed(f *os.File, sizeInBytes int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errno
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ package fileutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Fsync on HFS/OSX flushes the data on to the physical drive but the drive
|
// Fsync on HFS/OSX flushes the data on to the physical drive but the drive
|
||||||
@ -26,11 +27,8 @@ import (
|
|||||||
// written in out-of-order sequence. Using F_FULLFSYNC ensures that the
|
// written in out-of-order sequence. Using F_FULLFSYNC ensures that the
|
||||||
// physical drive's buffer will also get flushed to the media.
|
// physical drive's buffer will also get flushed to the media.
|
||||||
func Fsync(f *os.File) error {
|
func Fsync(f *os.File) error {
|
||||||
_, _, errno := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), uintptr(syscall.F_FULLFSYNC), uintptr(0))
|
_, err := unix.FcntlInt(f.Fd(), unix.F_FULLFSYNC, 0)
|
||||||
if errno == 0 {
|
return err
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errno
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence
|
// Fdatasync on darwin platform invokes fcntl(F_FULLFSYNC) for actual persistence
|
||||||
|
Loading…
x
Reference in New Issue
Block a user