Pass report files by file descriptor.

geesefs-0-30-9
Aaron Jacobs 2015-03-24 09:46:05 +11:00
parent a438466587
commit b62be9632c
3 changed files with 30 additions and 22 deletions

View File

@ -66,12 +66,6 @@ func (t *flushFSTest) setUp(
// Set up test config. // Set up test config.
t.MountType = "flushfs" t.MountType = "flushfs"
t.MountFlags = []string{ t.MountFlags = []string{
"--flushfs.flushes_file",
t.flushes.Name(),
"--flushfs.fsyncs_file",
t.fsyncs.Name(),
"--flushfs.flush_error", "--flushfs.flush_error",
fmt.Sprintf("%d", int(flushErr)), fmt.Sprintf("%d", int(flushErr)),
@ -79,6 +73,11 @@ func (t *flushFSTest) setUp(
fmt.Sprintf("%d", int(fsyncErr)), fmt.Sprintf("%d", int(fsyncErr)),
} }
t.MountFiles = map[string]*os.File{
"flushfs.flushes_file": t.flushes,
"flushfs.fsyncs_file": t.fsyncs,
}
t.SubprocessTest.SetUp(ti) t.SubprocessTest.SetUp(ti)
} }

View File

@ -31,30 +31,21 @@ import (
var fType = flag.String("type", "", "The name of the samples/ sub-dir.") var fType = flag.String("type", "", "The name of the samples/ sub-dir.")
var fMountPoint = flag.String("mount_point", "", "Path to mount point.") var fMountPoint = flag.String("mount_point", "", "Path to mount point.")
var fFlushesFile = flag.String("flushfs.flushes_file", "", "") var fFlushesFile = flag.Uint64("flushfs.flushes_file", 0, "")
var fFsyncsFile = flag.String("flushfs.fsyncs_file", "", "") var fFsyncsFile = flag.Uint64("flushfs.fsyncs_file", 0, "")
var fFlushError = flag.Int("flushfs.flush_error", 0, "") var fFlushError = flag.Int("flushfs.flush_error", 0, "")
var fFsyncError = flag.Int("flushfs.fsync_error", 0, "") var fFsyncError = flag.Int("flushfs.fsync_error", 0, "")
func makeFlushFS() (fs fuse.FileSystem, err error) { func makeFlushFS() (fs fuse.FileSystem, err error) {
// Check the flags. // Check the flags.
if *fFlushesFile == "" || *fFsyncsFile == "" { if *fFlushesFile == 0 || *fFsyncsFile == 0 {
err = fmt.Errorf("You must set the flushfs flags.") err = fmt.Errorf("You must set the flushfs flags.")
return return
} }
// Open the files. // Set up the files.
flushes, err := os.OpenFile(*fFlushesFile, os.O_RDWR, 0) flushes := os.NewFile(uintptr(*fFlushesFile), "(flushes file)")
if err != nil { fsyncs := os.NewFile(uintptr(*fFsyncsFile), "(fsyncs file)")
err = fmt.Errorf("Opening %s: %v", *fFlushesFile, err)
return
}
fsyncs, err := os.OpenFile(*fFsyncsFile, os.O_RDWR, 0)
if err != nil {
err = fmt.Errorf("Opening %s: %v", *fFsyncsFile, err)
return
}
// Set up errors. // Set up errors.
var flushErr error var flushErr error

View File

@ -20,6 +20,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"os/exec" "os/exec"
"path" "path"
"sync" "sync"
@ -40,6 +41,10 @@ type SubprocessTest struct {
// Additional flags to be passed to the mount_sample tool. // Additional flags to be passed to the mount_sample tool.
MountFlags []string MountFlags []string
// A list of files to pass to mount_sample. The given string flag will be
// used to pass the file descriptor number.
MountFiles map[string]*os.File
// A context object that can be used for long-running operations. // A context object that can be used for long-running operations.
Ctx context.Context Ctx context.Context
@ -132,7 +137,7 @@ func (t *SubprocessTest) initialize() (err error) {
return return
} }
// Set up a command. // Set up basic args for the subprocess.
args := []string{ args := []string{
"--type", "--type",
t.MountType, t.MountType,
@ -142,9 +147,22 @@ func (t *SubprocessTest) initialize() (err error) {
args = append(args, t.MountFlags...) args = append(args, t.MountFlags...)
// Set up inherited files and appropriate flags.
var extraFiles []*os.File
for flag, file := range t.MountFiles {
// Cf. os/exec.Cmd.ExtraFiles
fd := 3 + len(extraFiles)
extraFiles = append(extraFiles, file)
args = append(args, "--"+flag)
args = append(args, fmt.Sprintf("%d", fd))
}
// Set up a command.
t.mountCmd = exec.Command(toolPath, args...) t.mountCmd = exec.Command(toolPath, args...)
t.mountCmd.Stdout = &t.mountStdout t.mountCmd.Stdout = &t.mountStdout
t.mountCmd.Stderr = &t.mountStderr t.mountCmd.Stderr = &t.mountStderr
t.mountCmd.ExtraFiles = extraFiles
// Start it. // Start it.
if err = t.mountCmd.Start(); err != nil { if err = t.mountCmd.Start(); err != nil {