diff --git a/libcontainer/configs/mount.go b/libcontainer/configs/mount.go index 784c61820..b4c616d55 100644 --- a/libcontainer/configs/mount.go +++ b/libcontainer/configs/mount.go @@ -35,12 +35,6 @@ type Mount struct { // Extensions are additional flags that are specific to runc. Extensions int `json:"extensions"` - - // Optional Command to be run before Source is mounted. - PremountCmds []Command `json:"premount_cmds"` - - // Optional Command to be run after Source is mounted. - PostmountCmds []Command `json:"postmount_cmds"` } func (m *Mount) IsBind() bool { diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index ada4f854b..d91201e53 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -840,55 +840,6 @@ func TestPassExtraFiles(t *testing.T) { } } -func TestMountCmds(t *testing.T) { - if testing.Short() { - return - } - - tmpDir := t.TempDir() - config := newTemplateConfig(t, nil) - rootfs := config.Rootfs - config.Mounts = append(config.Mounts, &configs.Mount{ - Source: tmpDir, - Destination: "/tmp", - Device: "bind", - Flags: unix.MS_BIND | unix.MS_REC, - PremountCmds: []configs.Command{ - {Path: "touch", Args: []string{filepath.Join(tmpDir, "hello")}}, - {Path: "touch", Args: []string{filepath.Join(tmpDir, "world")}}, - }, - PostmountCmds: []configs.Command{ - {Path: "cp", Args: []string{filepath.Join(rootfs, "tmp", "hello"), filepath.Join(rootfs, "tmp", "hello-backup")}}, - {Path: "cp", Args: []string{filepath.Join(rootfs, "tmp", "world"), filepath.Join(rootfs, "tmp", "world-backup")}}, - }, - }) - - container, err := newContainer(t, config) - ok(t, err) - defer destroyContainer(container) - - pconfig := libcontainer.Process{ - Cwd: "/", - Args: []string{"sh", "-c", "env"}, - Env: standardEnvironment, - Init: true, - } - err = container.Run(&pconfig) - ok(t, err) - - // Wait for process - waitProcess(&pconfig, t) - - entries, err := os.ReadDir(tmpDir) - ok(t, err) - expected := []string{"hello", "hello-backup", "world", "world-backup"} - for i, e := range entries { - if e.Name() != expected[i] { - t.Errorf("Got(%s), expect %s", e.Name(), expected[i]) - } - } -} - func TestSysctl(t *testing.T) { if testing.Short() { return diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index 51660f5ef..5290a45ec 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "os/exec" "path" "path/filepath" "strconv" @@ -70,12 +69,6 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig, mountFds []int) (err } setupDev := needsSetupDev(config) for i, m := range config.Mounts { - for _, precmd := range m.PremountCmds { - if err := mountCmd(precmd); err != nil { - return fmt.Errorf("error running premount command: %w", err) - } - } - // Just before the loop we checked that if not empty, len(mountFds) == len(config.Mounts). // Therefore, we can access mountFds[i] without any concerns. if mountFds != nil && mountFds[i] != -1 { @@ -85,12 +78,6 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig, mountFds []int) (err if err := mountToRootfs(m, mountConfig); err != nil { return fmt.Errorf("error mounting %q to rootfs at %q: %w", m.Source, m.Destination, err) } - - for _, postcmd := range m.PostmountCmds { - if err := mountCmd(postcmd); err != nil { - return fmt.Errorf("error running postmount command: %w", err) - } - } } if setupDev { @@ -212,16 +199,6 @@ func cleanupTmp(tmpdir string) { _ = os.RemoveAll(tmpdir) } -func mountCmd(cmd configs.Command) error { - command := exec.Command(cmd.Path, cmd.Args[:]...) - command.Env = cmd.Env - command.Dir = cmd.Dir - if out, err := command.CombinedOutput(); err != nil { - return fmt.Errorf("%#v failed: %s: %w", cmd, string(out), err) - } - return nil -} - func prepareBindMount(m *configs.Mount, rootfs string, mountFd *int) error { source := m.Source if mountFd != nil {