Browse code

Use absolute path for rootfs in OCI config.json

This avoid an extra bind mount within /var/run/docker/libcontainerd

This should resolve situations where a container having the host
/var/run bound prevents other containers from being cleanly removed
(e.g. #21969).

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

Kenfe-Mickael Laventure authored on 2016/04/23 01:23:56
Showing 2 changed files
... ...
@@ -163,15 +163,9 @@ func (clnt *client) Create(containerID string, spec Spec, options ...CreateOptio
163 163
 		}
164 164
 	}()
165 165
 
166
-	// uid/gid
167
-	rootfsDir := filepath.Join(container.dir, "rootfs")
168
-	if err := idtools.MkdirAllAs(rootfsDir, 0700, uid, gid); err != nil && !os.IsExist(err) {
166
+	if err := idtools.MkdirAllAs(container.dir, 0700, uid, gid); err != nil && !os.IsExist(err) {
169 167
 		return err
170 168
 	}
171
-	if err := syscall.Mount(spec.Root.Path, rootfsDir, "bind", syscall.MS_REC|syscall.MS_BIND, ""); err != nil {
172
-		return err
173
-	}
174
-	spec.Root.Path = "rootfs"
175 169
 
176 170
 	f, err := os.Create(filepath.Join(container.dir, configFilename))
177 171
 	if err != nil {
... ...
@@ -258,6 +252,22 @@ func (clnt *client) Stats(containerID string) (*Stats, error) {
258 258
 	return (*Stats)(resp), nil
259 259
 }
260 260
 
261
+// Take care of the old 1.11.0 behavior in case the version upgrade
262
+// happenned without a clean daemon shutdown
263
+func (clnt *client) cleanupOldRootfs(containerID string) {
264
+	// Unmount and delete the bundle folder
265
+	if mts, err := mount.GetMounts(); err == nil {
266
+		for _, mts := range mts {
267
+			if strings.HasSuffix(mts.Mountpoint, containerID+"/rootfs") {
268
+				if err := syscall.Unmount(mts.Mountpoint, syscall.MNT_DETACH); err == nil {
269
+					os.RemoveAll(strings.TrimSuffix(mts.Mountpoint, "/rootfs"))
270
+				}
271
+				break
272
+			}
273
+		}
274
+	}
275
+}
276
+
261 277
 func (clnt *client) setExited(containerID string) error {
262 278
 	clnt.lock(containerID)
263 279
 	defer clnt.unlock(containerID)
... ...
@@ -274,17 +284,7 @@ func (clnt *client) setExited(containerID string) error {
274 274
 			ExitCode: exitCode,
275 275
 		}})
276 276
 
277
-	// Unmount and delete the bundle folder
278
-	if mts, err := mount.GetMounts(); err == nil {
279
-		for _, mts := range mts {
280
-			if strings.HasSuffix(mts.Mountpoint, containerID+"/rootfs") {
281
-				if err := syscall.Unmount(mts.Mountpoint, syscall.MNT_DETACH); err == nil {
282
-					os.RemoveAll(strings.TrimSuffix(mts.Mountpoint, "/rootfs"))
283
-				}
284
-				break
285
-			}
286
-		}
287
-	}
277
+	clnt.cleanupOldRootfs(containerID)
288 278
 
289 279
 	return err
290 280
 }
... ...
@@ -30,7 +30,6 @@ func (ctr *container) clean() error {
30 30
 		return err
31 31
 	}
32 32
 
33
-	syscall.Unmount(filepath.Join(ctr.dir, "rootfs"), syscall.MNT_DETACH) // ignore error
34 33
 	if err := os.RemoveAll(ctr.dir); err != nil {
35 34
 		return err
36 35
 	}