Skip to content

Commit 0023abb

Browse files
committed
Remove old/uneeded volume migration from vers 1.7
Signed-off-by: Brian Goff <[email protected]>
1 parent 63826e2 commit 0023abb

5 files changed

Lines changed: 0 additions & 259 deletions

File tree

daemon/daemon.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,6 @@ func (daemon *Daemon) restore() error {
179179
delete(containers, id)
180180
continue
181181
}
182-
// verify that all volumes valid and have been migrated from the pre-1.7 layout
183-
if err := daemon.verifyVolumesInfo(c); err != nil {
184-
// don't skip the container due to error
185-
logrus.Errorf("Failed to verify volumes for container '%s': %v", c.ID, err)
186-
}
187182
if err := daemon.Register(c); err != nil {
188183
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
189184
delete(containers, id)

daemon/daemon_unix_test.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ import (
66
"errors"
77
"io/ioutil"
88
"os"
9-
"path/filepath"
109
"testing"
1110

1211
containertypes "github.com/docker/docker/api/types/container"
1312
"github.com/docker/docker/container"
1413
"github.com/docker/docker/daemon/config"
15-
"github.com/docker/docker/pkg/idtools"
16-
"github.com/docker/docker/volume"
17-
"github.com/docker/docker/volume/drivers"
18-
"github.com/docker/docker/volume/local"
19-
"github.com/docker/docker/volume/store"
20-
"github.com/gotestyourself/gotestyourself/assert"
2114
)
2215

2316
type fakeContainerGetter struct {
@@ -273,85 +266,3 @@ func TestNetworkOptions(t *testing.T) {
273266
t.Fatal("Expected networkOptions error, got nil")
274267
}
275268
}
276-
277-
func TestMigratePre17Volumes(t *testing.T) {
278-
rootDir, err := ioutil.TempDir("", "test-daemon-volumes")
279-
if err != nil {
280-
t.Fatal(err)
281-
}
282-
defer os.RemoveAll(rootDir)
283-
284-
volumeRoot := filepath.Join(rootDir, "volumes")
285-
err = os.MkdirAll(volumeRoot, 0755)
286-
if err != nil {
287-
t.Fatal(err)
288-
}
289-
290-
containerRoot := filepath.Join(rootDir, "containers")
291-
cid := "1234"
292-
err = os.MkdirAll(filepath.Join(containerRoot, cid), 0755)
293-
assert.NilError(t, err)
294-
295-
vid := "5678"
296-
vfsPath := filepath.Join(rootDir, "vfs", "dir", vid)
297-
err = os.MkdirAll(vfsPath, 0755)
298-
assert.NilError(t, err)
299-
300-
config := []byte(`
301-
{
302-
"ID": "` + cid + `",
303-
"Volumes": {
304-
"/foo": "` + vfsPath + `",
305-
"/bar": "/foo",
306-
"/quux": "/quux"
307-
},
308-
"VolumesRW": {
309-
"/foo": true,
310-
"/bar": true,
311-
"/quux": false
312-
}
313-
}
314-
`)
315-
316-
volStore, err := store.New(volumeRoot)
317-
if err != nil {
318-
t.Fatal(err)
319-
}
320-
drv, err := local.New(volumeRoot, idtools.IDPair{UID: 0, GID: 0})
321-
if err != nil {
322-
t.Fatal(err)
323-
}
324-
volumedrivers.Register(drv, volume.DefaultDriverName)
325-
326-
daemon := &Daemon{
327-
root: rootDir,
328-
repository: containerRoot,
329-
volumes: volStore,
330-
}
331-
err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600)
332-
if err != nil {
333-
t.Fatal(err)
334-
}
335-
c, err := daemon.load(cid)
336-
if err != nil {
337-
t.Fatal(err)
338-
}
339-
if err := daemon.verifyVolumesInfo(c); err != nil {
340-
t.Fatal(err)
341-
}
342-
343-
expected := map[string]volume.MountPoint{
344-
"/foo": {Destination: "/foo", RW: true, Name: vid},
345-
"/bar": {Source: "/foo", Destination: "/bar", RW: true},
346-
"/quux": {Source: "/quux", Destination: "/quux", RW: false},
347-
}
348-
for id, mp := range c.MountPoints {
349-
x, exists := expected[id]
350-
if !exists {
351-
t.Fatal("volume not migrated")
352-
}
353-
if mp.Source != x.Source || mp.Destination != x.Destination || mp.RW != x.RW || mp.Name != x.Name {
354-
t.Fatalf("got unexpected mountpoint, expected: %+v, got: %+v", x, mp)
355-
}
356-
}
357-
}

daemon/daemon_windows.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,13 +632,6 @@ func setupDaemonProcess(config *config.Config) error {
632632
return nil
633633
}
634634

635-
// verifyVolumesInfo is a no-op on windows.
636-
// This is called during daemon initialization to migrate volumes from pre-1.7.
637-
// volumes were not supported on windows pre-1.7
638-
func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error {
639-
return nil
640-
}
641-
642635
func (daemon *Daemon) setupSeccompProfile() error {
643636
return nil
644637
}

daemon/volumes_unix.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
package daemon // import "github.com/docker/docker/daemon"
44

55
import (
6-
"encoding/json"
76
"fmt"
87
"os"
9-
"path/filepath"
108
"sort"
119
"strconv"
1210
"strings"
@@ -15,9 +13,6 @@ import (
1513
"github.com/docker/docker/pkg/fileutils"
1614
"github.com/docker/docker/pkg/mount"
1715
"github.com/docker/docker/volume"
18-
"github.com/docker/docker/volume/drivers"
19-
"github.com/docker/docker/volume/local"
20-
"github.com/pkg/errors"
2116
)
2217

2318
// setupMounts iterates through each of the mount points for a container and
@@ -113,80 +108,6 @@ func setBindModeIfNull(bind *volume.MountPoint) {
113108
}
114109
}
115110

116-
// migrateVolume links the contents of a volume created pre Docker 1.7
117-
// into the location expected by the local driver.
118-
// It creates a symlink from DOCKER_ROOT/vfs/dir/VOLUME_ID to DOCKER_ROOT/volumes/VOLUME_ID/_container_data.
119-
// It preserves the volume json configuration generated pre Docker 1.7 to be able to
120-
// downgrade from Docker 1.7 to Docker 1.6 without losing volume compatibility.
121-
func migrateVolume(id, vfs string) error {
122-
l, err := volumedrivers.GetDriver(volume.DefaultDriverName)
123-
if err != nil {
124-
return err
125-
}
126-
127-
newDataPath := l.(*local.Root).DataPath(id)
128-
fi, err := os.Stat(newDataPath)
129-
if err != nil && !os.IsNotExist(err) {
130-
return err
131-
}
132-
133-
if fi != nil && fi.IsDir() {
134-
return nil
135-
}
136-
137-
return os.Symlink(vfs, newDataPath)
138-
}
139-
140-
// verifyVolumesInfo ports volumes configured for the containers pre docker 1.7.
141-
// It reads the container configuration and creates valid mount points for the old volumes.
142-
func (daemon *Daemon) verifyVolumesInfo(container *container.Container) error {
143-
container.Lock()
144-
defer container.Unlock()
145-
146-
// Inspect old structures only when we're upgrading from old versions
147-
// to versions >= 1.7 and the MountPoints has not been populated with volumes data.
148-
type volumes struct {
149-
Volumes map[string]string
150-
VolumesRW map[string]bool
151-
}
152-
cfgPath, err := container.ConfigPath()
153-
if err != nil {
154-
return err
155-
}
156-
f, err := os.Open(cfgPath)
157-
if err != nil {
158-
return errors.Wrap(err, "could not open container config")
159-
}
160-
defer f.Close()
161-
var cv volumes
162-
if err := json.NewDecoder(f).Decode(&cv); err != nil {
163-
return errors.Wrap(err, "could not decode container config")
164-
}
165-
166-
if len(container.MountPoints) == 0 && len(cv.Volumes) > 0 {
167-
for destination, hostPath := range cv.Volumes {
168-
vfsPath := filepath.Join(daemon.root, "vfs", "dir")
169-
rw := cv.VolumesRW != nil && cv.VolumesRW[destination]
170-
171-
if strings.HasPrefix(hostPath, vfsPath) {
172-
id := filepath.Base(hostPath)
173-
v, err := daemon.volumes.CreateWithRef(id, volume.DefaultDriverName, container.ID, nil, nil)
174-
if err != nil {
175-
return err
176-
}
177-
if err := migrateVolume(id, hostPath); err != nil {
178-
return err
179-
}
180-
container.AddMountPointWithVolume(destination, v, true)
181-
} else { // Bind mount
182-
m := volume.MountPoint{Source: hostPath, Destination: destination, RW: rw}
183-
container.MountPoints[destination] = &m
184-
}
185-
}
186-
}
187-
return nil
188-
}
189-
190111
func (daemon *Daemon) mountVolumes(container *container.Container) error {
191112
mounts, err := daemon.setupMounts(container)
192113
if err != nil {

integration-cli/docker_cli_daemon_test.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
testdaemon "github.com/docker/docker/internal/test/daemon"
3636
"github.com/docker/docker/opts"
3737
"github.com/docker/docker/pkg/mount"
38-
"github.com/docker/docker/pkg/stringid"
3938
units "github.com/docker/go-units"
4039
"github.com/docker/libnetwork/iptables"
4140
"github.com/docker/libtrust"
@@ -2672,84 +2671,6 @@ func (s *DockerDaemonSuite) TestDaemonRestartSaveContainerExitCode(c *check.C) {
26722671
c.Assert(out, checker.Equals, errMsg1)
26732672
}
26742673

2675-
func (s *DockerDaemonSuite) TestDaemonBackcompatPre17Volumes(c *check.C) {
2676-
testRequires(c, SameHostDaemon)
2677-
d := s.d
2678-
d.StartWithBusybox(c)
2679-
2680-
// hack to be able to side-load a container config
2681-
out, err := d.Cmd("create", "busybox:latest")
2682-
c.Assert(err, checker.IsNil, check.Commentf(out))
2683-
id := strings.TrimSpace(out)
2684-
2685-
out, err = d.Cmd("inspect", "--type=image", "--format={{.ID}}", "busybox:latest")
2686-
c.Assert(err, checker.IsNil, check.Commentf(out))
2687-
d.Stop(c)
2688-
<-d.Wait
2689-
2690-
imageID := strings.TrimSpace(out)
2691-
volumeID := stringid.GenerateNonCryptoID()
2692-
vfsPath := filepath.Join(d.Root, "vfs", "dir", volumeID)
2693-
c.Assert(os.MkdirAll(vfsPath, 0755), checker.IsNil)
2694-
2695-
config := []byte(`
2696-
{
2697-
"ID": "` + id + `",
2698-
"Name": "hello",
2699-
"Driver": "` + d.StorageDriver() + `",
2700-
"Image": "` + imageID + `",
2701-
"Config": {"Image": "busybox:latest"},
2702-
"NetworkSettings": {},
2703-
"Volumes": {
2704-
"/bar":"/foo",
2705-
"/foo": "` + vfsPath + `",
2706-
"/quux":"/quux"
2707-
},
2708-
"VolumesRW": {
2709-
"/bar": true,
2710-
"/foo": true,
2711-
"/quux": false
2712-
}
2713-
}
2714-
`)
2715-
2716-
configPath := filepath.Join(d.Root, "containers", id, "config.v2.json")
2717-
c.Assert(ioutil.WriteFile(configPath, config, 600), checker.IsNil)
2718-
d.Start(c)
2719-
2720-
out, err = d.Cmd("inspect", "--type=container", "--format={{ json .Mounts }}", id)
2721-
c.Assert(err, checker.IsNil, check.Commentf(out))
2722-
type mount struct {
2723-
Name string
2724-
Source string
2725-
Destination string
2726-
Driver string
2727-
RW bool
2728-
}
2729-
2730-
ls := []mount{}
2731-
err = json.NewDecoder(strings.NewReader(out)).Decode(&ls)
2732-
c.Assert(err, checker.IsNil)
2733-
2734-
expected := []mount{
2735-
{Source: "/foo", Destination: "/bar", RW: true},
2736-
{Name: volumeID, Destination: "/foo", RW: true},
2737-
{Source: "/quux", Destination: "/quux", RW: false},
2738-
}
2739-
c.Assert(ls, checker.HasLen, len(expected))
2740-
2741-
for _, m := range ls {
2742-
var matched bool
2743-
for _, x := range expected {
2744-
if m.Source == x.Source && m.Destination == x.Destination && m.RW == x.RW || m.Name != x.Name {
2745-
matched = true
2746-
break
2747-
}
2748-
}
2749-
c.Assert(matched, checker.True, check.Commentf("did find match for %+v", m))
2750-
}
2751-
}
2752-
27532674
func (s *DockerDaemonSuite) TestDaemonWithUserlandProxyPath(c *check.C) {
27542675
testRequires(c, SameHostDaemon, DaemonIsLinux)
27552676

0 commit comments

Comments
 (0)