mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-22 07:00:44 +01:00
zfs: pipe size: default to value of /proc/sys/fs/pipe-max-siz
Addition by @problame: move getPipeCapacityHint() into platform-specific code. This has the added benefit of not recognizing the envvar as an envconst on platform that do not support resizing pipes. => won't show up in (zrepl status --raw).Global.Envconst fixes #424 cloes #449
This commit is contained in:
parent
1e85b1cb5f
commit
ee2336a24b
13
zfs/zfs.go
13
zfs/zfs.go
@ -26,11 +26,6 @@ import (
|
||||
"github.com/zrepl/zrepl/zfs/zfscmd"
|
||||
)
|
||||
|
||||
var (
|
||||
ZFSSendPipeCapacityHint = int(envconst.Int64("ZFS_SEND_PIPE_CAPACITY_HINT", 1<<25))
|
||||
ZFSRecvPipeCapacityHint = int(envconst.Int64("ZFS_RECV_PIPE_CAPACITY_HINT", 1<<25))
|
||||
)
|
||||
|
||||
type DatasetPath struct {
|
||||
comps []string
|
||||
}
|
||||
@ -328,8 +323,8 @@ func absVersion(fs string, v *ZFSSendArgVersion) (full string, err error) {
|
||||
}
|
||||
|
||||
func pipeWithCapacityHint(capacity int) (r, w *os.File, err error) {
|
||||
if capacity <= 0 {
|
||||
panic(fmt.Sprintf("capacity must be positive %v", capacity))
|
||||
if capacity < 0 {
|
||||
panic(fmt.Sprintf("capacity must be non-negative, got %v", capacity))
|
||||
}
|
||||
stdoutReader, stdoutWriter, err := os.Pipe()
|
||||
if err != nil {
|
||||
@ -858,7 +853,7 @@ func ZFSSend(ctx context.Context, sendArgs ZFSSendArgsValidated) (*SendStream, e
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
// setup stdout with an os.Pipe to control pipe buffer size
|
||||
stdoutReader, stdoutWriter, err := pipeWithCapacityHint(ZFSSendPipeCapacityHint)
|
||||
stdoutReader, stdoutWriter, err := pipeWithCapacityHint(getPipeCapacityHint("ZFS_SEND_PIPE_CAPACITY_HINT"))
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, err
|
||||
@ -1160,7 +1155,7 @@ func ZFSRecv(ctx context.Context, fs string, v *ZFSSendArgVersion, stream io.Rea
|
||||
|
||||
stderr := bytes.NewBuffer(make([]byte, 0, RecvStderrBufSiz))
|
||||
|
||||
stdin, stdinWriter, err := pipeWithCapacityHint(ZFSRecvPipeCapacityHint)
|
||||
stdin, stdinWriter, err := pipeWithCapacityHint(getPipeCapacityHint("ZFS_RECV_PIPE_CAPACITY_HINT"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,10 +7,14 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
func getPipeCapacityHint(envvar string) int {
|
||||
return 0 // not supported
|
||||
}
|
||||
|
||||
var zfsPipeCapacityNotSupported sync.Once
|
||||
|
||||
func trySetPipeCapacity(p *os.File, capacity int) {
|
||||
if debugEnabled {
|
||||
if debugEnabled && capacity != 0 {
|
||||
zfsPipeCapacityNotSupported.Do(func() {
|
||||
debug("trySetPipeCapacity error: OS does not support setting pipe capacity")
|
||||
})
|
||||
|
@ -3,11 +3,33 @@ package zfs
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/zrepl/zrepl/util/envconst"
|
||||
)
|
||||
|
||||
func getPipeCapacityHint(envvar string) int {
|
||||
var capacity int64 = 1 << 25
|
||||
|
||||
// Work around a race condition in Linux >= 5.8 related to pipe resizing.
|
||||
// https://github.com/zrepl/zrepl/issues/424#issuecomment-800370928
|
||||
// https://bugzilla.kernel.org/show_bug.cgi?id=212295
|
||||
if _, err := os.Stat("/proc/sys/fs/pipe-max-size"); err == nil {
|
||||
if dat, err := ioutil.ReadFile("/proc/sys/fs/pipe-max-size"); err == nil {
|
||||
if capacity, err = strconv.ParseInt(strings.TrimSpace(string(dat)), 10, 64); err != nil {
|
||||
capacity = 1 << 25
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return int(envconst.Int64(envvar, capacity))
|
||||
}
|
||||
|
||||
func trySetPipeCapacity(p *os.File, capacity int) {
|
||||
res, err := unix.FcntlInt(p.Fd(), unix.F_SETPIPE_SZ, capacity)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user