1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Migrate old mount format to use mount specs

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-08-04 15:34:52 -04:00
parent fc7b904dce
commit 29b1c1da73
2 changed files with 48 additions and 0 deletions

View file

@ -182,6 +182,10 @@ func (daemon *Daemon) restore() error {
wg.Add(1)
go func(c *container.Container) {
defer wg.Done()
if err := backportMountSpec(c); err != nil {
logrus.Errorf("Failed to migrate old mounts to use new spec format")
}
rm := c.RestartManager(false)
if c.IsRunning() || c.IsPaused() {
if err := daemon.containerd.Restore(c.ID, libcontainerd.WithRestartManager(rm)); err != nil {

View file

@ -230,3 +230,47 @@ func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volume.MountPo
}
return nil
}
func backportMountSpec(container *container.Container) error {
for target, m := range container.MountPoints {
if m.Spec.Type != "" {
// if type is set on even one mount, no need to migrate
return nil
}
if m.Name != "" {
m.Type = mounttypes.TypeVolume
m.Spec.Type = mounttypes.TypeVolume
// make sure this is not an anyonmous volume before setting the spec source
if _, exists := container.Config.Volumes[target]; !exists {
m.Spec.Source = m.Name
}
if container.HostConfig.VolumeDriver != "" {
m.Spec.VolumeOptions = &mounttypes.VolumeOptions{
DriverConfig: &mounttypes.Driver{Name: container.HostConfig.VolumeDriver},
}
}
if strings.Contains(m.Mode, "nocopy") {
if m.Spec.VolumeOptions == nil {
m.Spec.VolumeOptions = &mounttypes.VolumeOptions{}
}
m.Spec.VolumeOptions.NoCopy = true
}
} else {
m.Type = mounttypes.TypeBind
m.Spec.Type = mounttypes.TypeBind
m.Spec.Source = m.Source
if m.Propagation != "" {
m.Spec.BindOptions = &mounttypes.BindOptions{
Propagation: m.Propagation,
}
}
}
m.Spec.Target = m.Destination
if !m.RW {
m.Spec.ReadOnly = true
}
}
return container.ToDiskLocking()
}