Browse code

Persistent directory for container in execdriver

This is needed for persistent namespaces

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>

Alexandr Morozov authored on 2014/09/10 16:34:38
Showing 4 changed files
... ...
@@ -115,6 +115,10 @@ func (daemon *Daemon) Destroy(container *Container) error {
115 115
 		return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err)
116 116
 	}
117 117
 
118
+	if err := daemon.execDriver.Clean(container.ID); err != nil {
119
+		return fmt.Errorf("Unable to remove execdriver data for %s: %s", container.ID, err)
120
+	}
121
+
118 122
 	selinuxFreeLxcContexts(container.ProcessLabel)
119 123
 
120 124
 	return nil
... ...
@@ -51,6 +51,7 @@ type Driver interface {
51 51
 	Info(id string) Info                          // "temporary" hack (until we move state from core to plugins)
52 52
 	GetPidsForContainer(id string) ([]int, error) // Returns a list of pids for the given container.
53 53
 	Terminate(c *Command) error                   // kill it with fire
54
+	Clean(id string) error                        // clean all traces of container exec
54 55
 }
55 56
 
56 57
 // Network settings of the container
... ...
@@ -457,6 +457,11 @@ func (d *driver) generateEnvConfig(c *execdriver.Command) error {
457 457
 	return ioutil.WriteFile(p, data, 0600)
458 458
 }
459 459
 
460
+// Clean not implemented for lxc
461
+func (d *driver) Clean(id string) error {
462
+	return nil
463
+}
464
+
460 465
 type TtyConsole struct {
461 466
 	MasterPty *os.File
462 467
 	SlavePty  *os.File
... ...
@@ -94,7 +94,7 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
94 94
 	if err := d.createContainerRoot(c.ID); err != nil {
95 95
 		return -1, err
96 96
 	}
97
-	defer d.removeContainerRoot(c.ID)
97
+	defer d.cleanContainer(c.ID)
98 98
 
99 99
 	if err := d.writeContainerFile(container, c.ID); err != nil {
100 100
 		return -1, err
... ...
@@ -186,7 +186,7 @@ func (d *driver) Terminate(p *execdriver.Command) error {
186 186
 		err = syscall.Kill(p.ProcessConfig.Process.Pid, 9)
187 187
 		syscall.Wait4(p.ProcessConfig.Process.Pid, nil, 0, nil)
188 188
 	}
189
-	d.removeContainerRoot(p.ID)
189
+	d.cleanContainer(p.ID)
190 190
 
191 191
 	return err
192 192
 
... ...
@@ -227,15 +227,18 @@ func (d *driver) writeContainerFile(container *libcontainer.Config, id string) e
227 227
 	return ioutil.WriteFile(filepath.Join(d.root, id, "container.json"), data, 0655)
228 228
 }
229 229
 
230
-func (d *driver) createContainerRoot(id string) error {
231
-	return os.MkdirAll(filepath.Join(d.root, id), 0655)
232
-}
233
-
234
-func (d *driver) removeContainerRoot(id string) error {
230
+func (d *driver) cleanContainer(id string) error {
235 231
 	d.Lock()
236 232
 	delete(d.activeContainers, id)
237 233
 	d.Unlock()
234
+	return os.RemoveAll(filepath.Join(d.root, id, "container.json"))
235
+}
236
+
237
+func (d *driver) createContainerRoot(id string) error {
238
+	return os.MkdirAll(filepath.Join(d.root, id), 0655)
239
+}
238 240
 
241
+func (d *driver) Clean(id string) error {
239 242
 	return os.RemoveAll(filepath.Join(d.root, id))
240 243
 }
241 244