Handle image metadata when drivers are switched
This commit is contained in:
parent
24586d7af5
commit
1b28cdc7f9
10
graph.go
10
graph.go
|
@ -52,8 +52,10 @@ func (graph *Graph) restore() error {
|
||||||
}
|
}
|
||||||
for _, v := range dir {
|
for _, v := range dir {
|
||||||
id := v.Name()
|
id := v.Name()
|
||||||
|
if graph.driver.Exists(id) {
|
||||||
graph.idIndex.Add(id)
|
graph.idIndex.Add(id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +139,14 @@ func (graph *Graph) Register(jsonData []byte, layerData archive.Archive, img *Im
|
||||||
if graph.Exists(img.ID) {
|
if graph.Exists(img.ID) {
|
||||||
return fmt.Errorf("Image %s already exists", img.ID)
|
return fmt.Errorf("Image %s already exists", img.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that the image root does not exist on the filesystem
|
||||||
|
// when it is not registered in the graph.
|
||||||
|
// This is common when you switch from one graph driver to another
|
||||||
|
if err := os.RemoveAll(graph.imageRoot(img.ID)); err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
tmp, err := graph.Mktemp("")
|
tmp, err := graph.Mktemp("")
|
||||||
defer os.RemoveAll(tmp)
|
defer os.RemoveAll(tmp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -38,6 +38,9 @@ func pathExists(pth string) bool {
|
||||||
// symlink.
|
// symlink.
|
||||||
func (a *Driver) Migrate(pth string, setupInit func(p string) error) error {
|
func (a *Driver) Migrate(pth string, setupInit func(p string) error) error {
|
||||||
if pathExists(path.Join(pth, "graph")) {
|
if pathExists(path.Join(pth, "graph")) {
|
||||||
|
if err := a.migrateRepositories(pth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := a.migrateImages(path.Join(pth, "graph")); err != nil {
|
if err := a.migrateImages(path.Join(pth, "graph")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -46,6 +49,14 @@ func (a *Driver) Migrate(pth string, setupInit func(p string) error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Driver) migrateRepositories(pth string) error {
|
||||||
|
name := path.Join(pth, "repositories")
|
||||||
|
if err := os.Rename(name, name+"-aufs"); err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Driver) migrateContainers(pth string, setupInit func(p string) error) error {
|
func (a *Driver) migrateContainers(pth string, setupInit func(p string) error) error {
|
||||||
fis, err := ioutil.ReadDir(pth)
|
fis, err := ioutil.ReadDir(pth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -121,3 +121,7 @@ func (d *Driver) unmount(id, mountPoint string) error {
|
||||||
// Unmount the device
|
// Unmount the device
|
||||||
return d.DeviceSet.UnmountDevice(id, mountPoint, true)
|
return d.DeviceSet.UnmountDevice(id, mountPoint, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Exists(id string) bool {
|
||||||
|
return d.Devices[id] != nil
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ type Driver interface {
|
||||||
Remove(id string) error
|
Remove(id string) error
|
||||||
|
|
||||||
Get(id string) (dir string, err error)
|
Get(id string) (dir string, err error)
|
||||||
|
Exists(id string) bool
|
||||||
|
|
||||||
Status() [][2]string
|
Status() [][2]string
|
||||||
|
|
||||||
|
|
|
@ -84,3 +84,8 @@ func (d *Driver) Get(id string) (string, error) {
|
||||||
}
|
}
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Exists(id string) bool {
|
||||||
|
_, err := os.Stat(d.dir(id))
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
|
@ -671,7 +671,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
repositories, err := NewTagStore(path.Join(config.Root, "repositories"), g)
|
repositories, err := NewTagStore(path.Join(config.Root, "repositories-"+driver.String()), g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue