forked from kata-containers/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent: add configurable container pipe size cmdline option
Adds a cmdline option to configure the stdout/stdio pipe sizes. Uses `F_SETPIPE_SZ` to resize the write side of the pipe after creation. Example Cmdline option: `agent.container_pipe_size=2097152` fixes kata-containers#755 Signed-off-by: Alex Price <aprice@atlassian.com>
- Loading branch information
Showing
6 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// createExtendedPipe creates a pipe. | ||
// Optionally extends the pipe if containerPipeSize is positive. | ||
func createExtendedPipe() (*os.File, *os.File, error) { | ||
r, w, err := os.Pipe() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
if containerPipeSize > 0 { | ||
extendPipe(r, w) | ||
} | ||
return r, w, nil | ||
} | ||
|
||
// extendPipe extends the write side of the pipe to value of containerPipeSize | ||
func extendPipe(r, w *os.File) { | ||
syscall.Syscall(syscall.SYS_FCNTL, w.Fd(), syscall.F_SETPIPE_SZ, uintptr(containerPipeSize)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreateExtendedPipe(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
// Test the default | ||
containerPipeSize = 0 | ||
_, w, err := createExtendedPipe() | ||
assert.NoError(err) | ||
size, err := getPipeSize(w) | ||
assert.Equal(syscall.Errno(0), err) | ||
assert.Equal(uint32(65536), size) // Default = 16 pages | ||
|
||
maxSize, err := getPipeMaxSize() | ||
assert.NoError(err) | ||
|
||
// Test setting to the max size | ||
containerPipeSize = maxSize | ||
_, w, err = createExtendedPipe() | ||
assert.NoError(err) | ||
size, err = getPipeSize(w) | ||
assert.Equal(syscall.Errno(0), err) | ||
assert.Equal(containerPipeSize, size) | ||
|
||
// Test setting to a single page | ||
containerPipeSize = 4096 | ||
_, w, err = createExtendedPipe() | ||
assert.NoError(err) | ||
size, err = getPipeSize(w) | ||
assert.Equal(syscall.Errno(0), err) | ||
assert.Equal(containerPipeSize, size) | ||
} | ||
|
||
func getPipeSize(f *os.File) (uint32, error){ | ||
r1, _, err := syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), syscall.F_GETPIPE_SZ, 0) | ||
return uint32(r1), err | ||
} | ||
|
||
func getPipeMaxSize() (uint32, error) { | ||
f, err := os.Open("/proc/sys/fs/pipe-max-size") | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer f.Close() | ||
b, err := ioutil.ReadAll(f) | ||
if err != nil { | ||
return 0, err | ||
} | ||
s := strings.Trim(string(b), "\n") | ||
u, err := strconv.ParseUint(s, 10, 32) | ||
return uint32(u), err | ||
} |