Browse code

Migrate old mount format to use mount specs

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2016/08/05 04:34:52
Showing 2 changed files
... ...
@@ -182,6 +182,10 @@ func (daemon *Daemon) restore() error {
182 182
 		wg.Add(1)
183 183
 		go func(c *container.Container) {
184 184
 			defer wg.Done()
185
+			if err := backportMountSpec(c); err != nil {
186
+				logrus.Errorf("Failed to migrate old mounts to use new spec format")
187
+			}
188
+
185 189
 			rm := c.RestartManager(false)
186 190
 			if c.IsRunning() || c.IsPaused() {
187 191
 				if err := daemon.containerd.Restore(c.ID, libcontainerd.WithRestartManager(rm)); err != nil {
... ...
@@ -230,3 +230,47 @@ func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPo
230 230
 	}
231 231
 	return nil
232 232
 }
233
+
234
+func backportMountSpec(container *container.Container) error {
235
+	for target, m := range container.MountPoints {
236
+		if m.Spec.Type != "" {
237
+			// if type is set on even one mount, no need to migrate
238
+			return nil
239
+		}
240
+		if m.Name != "" {
241
+			m.Type = mounttypes.TypeVolume
242
+			m.Spec.Type = mounttypes.TypeVolume
243
+
244
+			// make sure this is not an anyonmous volume before setting the spec source
245
+			if _, exists := container.Config.Volumes[target]; !exists {
246
+				m.Spec.Source = m.Name
247
+			}
248
+			if container.HostConfig.VolumeDriver != "" {
249
+				m.Spec.VolumeOptions = &mounttypes.VolumeOptions{
250
+					DriverConfig: &mounttypes.Driver{Name: container.HostConfig.VolumeDriver},
251
+				}
252
+			}
253
+			if strings.Contains(m.Mode, "nocopy") {
254
+				if m.Spec.VolumeOptions == nil {
255
+					m.Spec.VolumeOptions = &mounttypes.VolumeOptions{}
256
+				}
257
+				m.Spec.VolumeOptions.NoCopy = true
258
+			}
259
+		} else {
260
+			m.Type = mounttypes.TypeBind
261
+			m.Spec.Type = mounttypes.TypeBind
262
+			m.Spec.Source = m.Source
263
+			if m.Propagation != "" {
264
+				m.Spec.BindOptions = &mounttypes.BindOptions{
265
+					Propagation: m.Propagation,
266
+				}
267
+			}
268
+		}
269
+
270
+		m.Spec.Target = m.Destination
271
+		if !m.RW {
272
+			m.Spec.ReadOnly = true
273
+		}
274
+	}
275
+	return container.ToDiskLocking()
276
+}