Skip to content

Commit

Permalink
do not limit tmp space that agent remaps
Browse files Browse the repository at this point in the history
https://www.pivotaltracker.com/story/show/117177967
[#117177967]

Signed-off-by: Aditya Mishra <amishra@pivotal.io>
  • Loading branch information
pivotal-saman-alvi authored and adi-mishra committed May 9, 2016
1 parent 49840a2 commit d466f19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 39 deletions.
28 changes: 12 additions & 16 deletions platform/linux_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,38 +699,34 @@ func (p linux) SetupTmpDir() error {
return nil
}

_, systemTmpDirIsMounted, err := p.IsMountPoint(systemTmpDir)
_, _, _, err = p.cmdRunner.RunCommand("mkdir", "-p", boshRootTmpPath)
if err != nil {
return bosherr.WrapErrorf(err, "Checking for mount point %s", systemTmpDir)
return bosherr.WrapError(err, "Creating root tmp dir")
}

if !systemTmpDirIsMounted {
// If it's not mounted on /tmp, blow it away
_, _, _, err = p.cmdRunner.RunCommand("truncate", "-s", "128M", boshRootTmpPath)
if err != nil {
return bosherr.WrapError(err, "Truncating root tmp dir")
}
bindMounter := boshdisk.NewLinuxBindMounter(p.diskManager.GetMounter())
mounted, err := bindMounter.IsMounted(boshRootTmpPath)

if !mounted && err == nil {
// change permissions
_, _, _, err = p.cmdRunner.RunCommand("chmod", "0700", boshRootTmpPath)
if err != nil {
return bosherr.WrapError(err, "Chmoding root tmp dir")
}

_, _, _, err = p.cmdRunner.RunCommand("mke2fs", "-t", "ext4", "-m", "1", "-F", boshRootTmpPath)
if err != nil {
return bosherr.WrapError(err, "Creating root tmp dir filesystem")
}

err = p.diskManager.GetMounter().Mount(boshRootTmpPath, systemTmpDir, "-t", "ext4", "-o", "loop,noexec")
// mount
err = bindMounter.Mount(boshRootTmpPath, systemTmpDir)
if err != nil {
return bosherr.WrapError(err, "Mounting root tmp dir over /tmp")
return bosherr.WrapError(err, "Bind mounting root tmp dir over /tmp")
}

// Change permissions for new mount point
// change permissions for mount point
err = p.changeTmpDirPermissions(systemTmpDir)
if err != nil {
return err
}
} else if err != nil {
return err
}

return nil
Expand Down
38 changes: 15 additions & 23 deletions platform/linux_platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package platform_test

import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"os"
"path"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

fakedpresolv "github.com/cloudfoundry/bosh-agent/infrastructure/devicepathresolver/fakes"
. "github.com/cloudfoundry/bosh-agent/platform"
fakecert "github.com/cloudfoundry/bosh-agent/platform/cert/fakes"
Expand Down Expand Up @@ -1348,45 +1347,38 @@ Number Start End Size File system Name Flags
mounter.IsMountPointResult = false
})

It("creates new tmp filesystem of 128MB placed in data dir", func() {
It("creates a root_tmp folder", func() {
err := act()
Expect(err).NotTo(HaveOccurred())
Expect(cmdRunner.RunCommands[3]).To(Equal([]string{"mkdir", "-p", "/fake-dir/data/root_tmp"}))
})

It("changes permissions on the new bind mount folder", func() {
err := act()
Expect(err).NotTo(HaveOccurred())

Expect(cmdRunner.RunCommands[3]).To(Equal([]string{"truncate", "-s", "128M", "/fake-dir/data/root_tmp"}))
Expect(cmdRunner.RunCommands[4]).To(Equal([]string{"chmod", "0700", "/fake-dir/data/root_tmp"}))
Expect(cmdRunner.RunCommands[5]).To(Equal([]string{"mke2fs", "-t", "ext4", "-m", "1", "-F", "/fake-dir/data/root_tmp"}))
})

It("mounts the new tmp filesystem over /tmp", func() {
It("bind mounts it in /tmp", func() {
err := act()
Expect(err).NotTo(HaveOccurred())

Expect(len(mounter.MountPartitionPaths)).To(Equal(1))
Expect(mounter.MountPartitionPaths[0]).To(Equal("/fake-dir/data/root_tmp"))
Expect(mounter.MountMountPoints[0]).To(Equal("/tmp"))
Expect(mounter.MountMountOptions[0]).To(Equal([]string{"-t", "ext4", "-o", "loop,noexec"}))
})

It("returns error if mounting the new tmp filesystem fails", func() {
mounter.MountErr = errors.New("fake-mount-error")

err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-mount-error"))
})

It("changes permissions on /tmp again because it is a new mount", func() {
It("changes permissions for the system /tmp folder", func() {
err := act()
Expect(err).NotTo(HaveOccurred())

Expect(cmdRunner.RunCommands[6]).To(Equal([]string{"chown", "root:vcap", "/tmp"}))
Expect(cmdRunner.RunCommands[7]).To(Equal([]string{"chmod", "0770", "/tmp"}))
Expect(cmdRunner.RunCommands[5]).To(Equal([]string{"chown", "root:vcap", "/tmp"}))
})
})

Context("when /tmp is a mount point", func() {
BeforeEach(func() {
mounter.IsMountPointResult = true
mounter.IsMountedResult = true
})

It("returns without an error", func() {
Expand All @@ -1399,13 +1391,13 @@ Number Start End Size File system Name Flags

Context("when /tmp cannot be determined if it is a mount point", func() {
BeforeEach(func() {
mounter.IsMountPointErr = errors.New("fake-is-mount-point-error")
mounter.IsMountedErr = errors.New("fake-is-mounted-error")
})

It("returns error", func() {
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-is-mount-point-error"))
Expect(err.Error()).To(ContainSubstring("fake-is-mounted-error"))
})

ItDoesNotTryToUseLoopDevice()
Expand Down

0 comments on commit d466f19

Please sign in to comment.