diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index f804284..4885357 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -66,12 +66,6 @@ func (t *flushFSTest) setUp( // Set up test config. t.MountType = "flushfs" t.MountFlags = []string{ - "--flushfs.flushes_file", - t.flushes.Name(), - - "--flushfs.fsyncs_file", - t.fsyncs.Name(), - "--flushfs.flush_error", fmt.Sprintf("%d", int(flushErr)), @@ -79,6 +73,11 @@ func (t *flushFSTest) setUp( 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) } diff --git a/samples/mount_sample/mount.go b/samples/mount_sample/mount.go index 963186c..48f860d 100644 --- a/samples/mount_sample/mount.go +++ b/samples/mount_sample/mount.go @@ -31,30 +31,21 @@ import ( var fType = flag.String("type", "", "The name of the samples/ sub-dir.") var fMountPoint = flag.String("mount_point", "", "Path to mount point.") -var fFlushesFile = flag.String("flushfs.flushes_file", "", "") -var fFsyncsFile = flag.String("flushfs.fsyncs_file", "", "") +var fFlushesFile = flag.Uint64("flushfs.flushes_file", 0, "") +var fFsyncsFile = flag.Uint64("flushfs.fsyncs_file", 0, "") var fFlushError = flag.Int("flushfs.flush_error", 0, "") var fFsyncError = flag.Int("flushfs.fsync_error", 0, "") func makeFlushFS() (fs fuse.FileSystem, err error) { // Check the flags. - if *fFlushesFile == "" || *fFsyncsFile == "" { + if *fFlushesFile == 0 || *fFsyncsFile == 0 { err = fmt.Errorf("You must set the flushfs flags.") return } - // Open the files. - flushes, err := os.OpenFile(*fFlushesFile, os.O_RDWR, 0) - if err != nil { - 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 the files. + flushes := os.NewFile(uintptr(*fFlushesFile), "(flushes file)") + fsyncs := os.NewFile(uintptr(*fFsyncsFile), "(fsyncs file)") // Set up errors. var flushErr error diff --git a/samples/subprocess.go b/samples/subprocess.go index 6161ed6..5db0ca6 100644 --- a/samples/subprocess.go +++ b/samples/subprocess.go @@ -20,6 +20,7 @@ import ( "io" "io/ioutil" "log" + "os" "os/exec" "path" "sync" @@ -40,6 +41,10 @@ type SubprocessTest struct { // Additional flags to be passed to the mount_sample tool. 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. Ctx context.Context @@ -132,7 +137,7 @@ func (t *SubprocessTest) initialize() (err error) { return } - // Set up a command. + // Set up basic args for the subprocess. args := []string{ "--type", t.MountType, @@ -142,9 +147,22 @@ func (t *SubprocessTest) initialize() (err error) { 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.Stdout = &t.mountStdout t.mountCmd.Stderr = &t.mountStderr + t.mountCmd.ExtraFiles = extraFiles // Start it. if err = t.mountCmd.Start(); err != nil {