Skip to content

Commit

Permalink
store: use the original image if the driver supports shifting
Browse files Browse the repository at this point in the history
do not create a new image with different uid/gid if the driver has
support for shifting.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Jul 17, 2018
1 parent ea979e6 commit 45588a6
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,18 @@ func (s *store) PutLayer(id, parent string, names []string, mountLabel string, w
gidMap = s.gidMap
}
}
layerOptions := &LayerOptions{
IDMappingOptions: IDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
UIDMap: copyIDMap(uidMap),
GIDMap: copyIDMap(gidMap),
},
var layerOptions *LayerOptions
if s.graphDriver.SupportsShifting() {
layerOptions = &LayerOptions{IDMappingOptions: IDMappingOptions{HostUIDMapping: true, HostGIDMapping: true, UIDMap: nil, GIDMap: nil}}
} else {
layerOptions = &LayerOptions{
IDMappingOptions: IDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
UIDMap: copyIDMap(uidMap),
GIDMap: copyIDMap(gidMap),
},
}
}
return rlstore.Put(id, parentLayer, names, mountLabel, nil, layerOptions, writeable, nil, diff)
}
Expand Down Expand Up @@ -1036,13 +1041,19 @@ func (s *store) imageTopLayerForMapping(image *Image, ristore ROImageStore, read
return nil, errors.Wrapf(err, "error reading layer %q to create an ID-mapped version of it", layer.ID)
}
defer rc.Close()
layerOptions := LayerOptions{
IDMappingOptions: IDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
UIDMap: copyIDMap(options.UIDMap),
GIDMap: copyIDMap(options.GIDMap),
},

var layerOptions LayerOptions
if s.graphDriver.SupportsShifting() {
layerOptions = LayerOptions{IDMappingOptions: IDMappingOptions{HostUIDMapping: true, HostGIDMapping: true, UIDMap: nil, GIDMap: nil}}
} else {
layerOptions = LayerOptions{
IDMappingOptions: IDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
UIDMap: copyIDMap(options.UIDMap),
GIDMap: copyIDMap(options.GIDMap),
},
}
}
mappedLayer, _, err := rlstore.Put("", parentLayer, nil, layer.MountLabel, nil, &layerOptions, false, nil, rc)
if err != nil {
Expand Down Expand Up @@ -1086,6 +1097,15 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
imageID := ""
uidMap := options.UIDMap
gidMap := options.GIDMap

var idMappingsOptions IDMappingOptions
if s.graphDriver.SupportsShifting() {
uidMap, gidMap = nil, nil
idMappingsOptions = IDMappingOptions{HostUIDMapping: true, HostGIDMapping: true, UIDMap: nil, GIDMap: nil}
} else {
idMappingsOptions = options.IDMappingOptions
}

if image != "" {
var imageHomeStore ROImageStore
istore, err := s.ImageStore()
Expand Down Expand Up @@ -1118,7 +1138,7 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
if err != nil {
return nil, err
}
ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, imageHomeStore == istore, rlstore, lstores, options.IDMappingOptions)
ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, imageHomeStore == istore, rlstore, lstores, idMappingsOptions)
if err != nil {
return nil, err
}
Expand All @@ -1137,15 +1157,15 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
gidMap = s.gidMap
}
}
layerOptions := &LayerOptions{
layerOptions := LayerOptions{
IDMappingOptions: IDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
HostUIDMapping: idMappingsOptions.HostUIDMapping,
HostGIDMapping: idMappingsOptions.HostGIDMapping,
UIDMap: copyIDMap(uidMap),
GIDMap: copyIDMap(gidMap),
},
}
clayer, err := rlstore.Create(layer, imageTopLayer, nil, "", nil, layerOptions, true)
clayer, err := rlstore.Create(layer, imageTopLayer, nil, "", nil, &layerOptions, true)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 45588a6

Please sign in to comment.