Browse code

TestDaemonNoSpaceLeftOnDeviceError: simplify

There is no need to perform a separate losetup step; mount (even
the one in busybox!) is smart enough to set up a loopback device
all by itself (even without -o loop present!). More to say, while
doing this, it sets LO_FLAGS_AUTOCLEAR flag for the kernel to
delete the loopback device as soon as its fs is unmounted (this
is supposed to work since kernel 2.6.25).

Also, remove mount options (-t ext4, -o loop,rw) as they are
either defaults (rw) or mount is smart enough to figure out.
Leave -n so it won't do unnecessary write to container's /etc/mtab.

While at it, touch up some comments.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/03/30 10:31:14
Showing 1 changed files
... ...
@@ -1816,23 +1816,18 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) {
1816 1816
 	c.Assert(mount.MakeRShared(testDir), checker.IsNil)
1817 1817
 	defer mount.Unmount(testDir)
1818 1818
 
1819
-	// create a 2MiB image and mount it as graph root
1819
+	// create a 3MiB image (with a 2MiB ext4 fs) and mount it as graph root
1820 1820
 	// Why in a container? Because `mount` sometimes behaves weirdly and often fails outright on this test in debian:jessie (which is what the test suite runs under if run from the Makefile)
1821 1821
 	dockerCmd(c, "run", "--rm", "-v", testDir+":/test", "busybox", "sh", "-c", "dd of=/test/testfs.img bs=1M seek=3 count=0")
1822 1822
 	icmd.RunCommand("mkfs.ext4", "-F", filepath.Join(testDir, "testfs.img")).Assert(c, icmd.Success)
1823 1823
 
1824
-	result := icmd.RunCommand("losetup", "-f", "--show", filepath.Join(testDir, "testfs.img"))
1825
-	result.Assert(c, icmd.Success)
1826
-	loopname := strings.TrimSpace(string(result.Combined()))
1827
-	defer exec.Command("losetup", "-d", loopname).Run()
1828
-
1829
-	dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", fmt.Sprintf("mkdir -p /test/test-mount && mount -t ext4 -no loop,rw %v /test/test-mount", loopname))
1824
+	dockerCmd(c, "run", "--privileged", "--rm", "-v", testDir+":/test:shared", "busybox", "sh", "-c", "mkdir -p /test/test-mount && mount -n /test/testfs.img /test/test-mount")
1830 1825
 	defer mount.Unmount(filepath.Join(testDir, "test-mount"))
1831 1826
 
1832 1827
 	s.d.Start(c, "--data-root", filepath.Join(testDir, "test-mount"))
1833 1828
 	defer s.d.Stop(c)
1834 1829
 
1835
-	// pull a repository large enough to fill the mount point
1830
+	// pull a repository large enough to overfill the mounted filesystem
1836 1831
 	pullOut, err := s.d.Cmd("pull", "debian:stretch")
1837 1832
 	c.Assert(err, checker.NotNil, check.Commentf(pullOut))
1838 1833
 	c.Assert(pullOut, checker.Contains, "no space left on device")