Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions storage/cmd/containers-storage/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ func createLayer(flags *mflag.FlagSet, action string, m storage.Store, args []st
if err != nil {
return 1, err
}
options := &storage.LayerOptions{IDMappingOptions: *mappings}
options := &storage.LayerOptions{IDMappingOptions: storage.LayerIDMappingOptions{
HostUIDMapping: mappings.HostUIDMapping,
HostGIDMapping: mappings.HostGIDMapping,
UIDMap: mappings.UIDMap,
GIDMap: mappings.GIDMap,
}}
layer, err := m.CreateLayer(paramID, parent, paramNames, paramMountLabel, !paramCreateRO, options)
if err != nil {
return 1, err
Expand Down Expand Up @@ -155,7 +160,12 @@ func importLayer(flags *mflag.FlagSet, action string, m storage.Store, args []st
if err != nil {
return 1, err
}
options := &storage.LayerOptions{IDMappingOptions: *mappings}
options := &storage.LayerOptions{IDMappingOptions: storage.LayerIDMappingOptions{
HostUIDMapping: mappings.HostUIDMapping,
HostGIDMapping: mappings.HostGIDMapping,
UIDMap: mappings.UIDMap,
GIDMap: mappings.GIDMap,
}}
layer, _, err := m.PutLayer(paramID, parent, paramNames, paramMountLabel, !paramCreateRO, options, diffStream)
if err != nil {
return 1, err
Expand Down
3 changes: 0 additions & 3 deletions storage/drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ type MountOpts struct {
// Volatile specifies whether the container storage can be optimized
// at the cost of not syncing all the dirty files in memory.
Volatile bool

// DisableShifting forces the driver to not do any ID shifting at runtime.
DisableShifting bool
}

// ApplyDiffOpts contains optional arguments for ApplyDiff methods.
Expand Down
2 changes: 1 addition & 1 deletion storage/drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO

readWrite := !inAdditionalStore

if !d.SupportsShifting(options.UidMaps, options.GidMaps) || options.DisableShifting {
if !d.SupportsShifting(options.UidMaps, options.GidMaps) {
disableShifting = true
}

Expand Down
16 changes: 10 additions & 6 deletions storage/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,8 +1593,8 @@ func (r *layerStore) create(id string, parentLayer *Layer, names []string, mount
UIDs: templateUIDs,
GIDs: templateGIDs,
Flags: newMapFrom(moreOptions.Flags),
UIDMap: copySlicePreferringNil(moreOptions.UIDMap),
GIDMap: copySlicePreferringNil(moreOptions.GIDMap),
UIDMap: copySlicePreferringNil(moreOptions.IDMappingOptions.UIDMap),
GIDMap: copySlicePreferringNil(moreOptions.IDMappingOptions.GIDMap),
BigDataNames: []string{},
location: r.pickStoreLocation(moreOptions.Volatile, writeable),
}
Expand Down Expand Up @@ -1638,7 +1638,7 @@ func (r *layerStore) create(id string, parentLayer *Layer, names []string, mount
}
}

idMappings := idtools.NewIDMappingsFromMaps(moreOptions.UIDMap, moreOptions.GIDMap)
idMappings := idtools.NewIDMappingsFromMaps(moreOptions.IDMappingOptions.UIDMap, moreOptions.IDMappingOptions.GIDMap)
opts := drivers.CreateOpts{
MountLabel: mountLabel,
StorageOpt: options,
Expand Down Expand Up @@ -1674,9 +1674,13 @@ func (r *layerStore) create(id string, parentLayer *Layer, names []string, mount
}
}

targetMappings := idMappings
if moreOptions.IDMappingOptions.HostUIDMapping && moreOptions.IDMappingOptions.HostGIDMapping {
targetMappings = &idtools.IDMappings{}
}
if oldMappings != nil &&
(!reflect.DeepEqual(oldMappings.UIDs(), idMappings.UIDs()) || !reflect.DeepEqual(oldMappings.GIDs(), idMappings.GIDs())) {
if err = r.driver.UpdateLayerIDMap(id, oldMappings, idMappings, mountLabel); err != nil {
(!reflect.DeepEqual(oldMappings.UIDs(), targetMappings.UIDs()) || !reflect.DeepEqual(oldMappings.GIDs(), targetMappings.GIDs())) {
if err = r.driver.UpdateLayerIDMap(id, oldMappings, targetMappings, mountLabel); err != nil {
cleanupFailureContext = "in UpdateLayerIDMap"
return nil, -1, err
}
Expand Down Expand Up @@ -2595,7 +2599,7 @@ func (r *layerStore) stageWithUnlockedStore(sl *maybeStagedLayerExtraction, pare
result, err := applyDiff(layerOptions, sl.diff, f, func(payload io.Reader) (int64, error) {
cleanup, stagedLayer, size, err := sl.staging.StartStagingDiffToApply(parent, drivers.ApplyDiffOpts{
Diff: payload,
Mappings: idtools.NewIDMappingsFromMaps(layerOptions.UIDMap, layerOptions.GIDMap),
Mappings: idtools.NewIDMappingsFromMaps(layerOptions.IDMappingOptions.UIDMap, layerOptions.IDMappingOptions.GIDMap),
// MountLabel is not supported for the unlocked extraction, see the comment in (*store).PutLayer()
MountLabel: "",
})
Expand Down
71 changes: 36 additions & 35 deletions storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,26 @@ type AutoUserNsOptions = types.AutoUserNsOptions

type IDMappingOptions = types.IDMappingOptions

// LayerIDMappingOptions is different than types.IDMappingOptions as it only covers
// the options needed to create a layer.
type LayerIDMappingOptions struct {
// HostUIDMapping defines whether files are stored with their host UID mapping in the
// store.
HostUIDMapping bool
// HostGIDMapping defines whether files are stored with their host UID mapping in the
// store.
HostGIDMapping bool
UIDMap []idtools.IDMap
GIDMap []idtools.IDMap
}

// LayerOptions is used for passing options to a Store's CreateLayer() and PutLayer() methods.
type LayerOptions struct {
// IDMappingOptions specifies the type of ID mapping which should be
// used for this layer. If nothing is specified, the layer will
// inherit settings from its parent layer or, if it has no parent
// layer, the Store object.
types.IDMappingOptions
IDMappingOptions LayerIDMappingOptions
// TemplateLayer is the ID of a layer whose contents will be used to
// initialize this layer. If set, it should be a child of the layer
// which we want to use as the parent of the new layer.
Expand Down Expand Up @@ -1498,14 +1511,14 @@ func populateLayerOptions(s *store, rlstore rwLayerStore, rlstores []roLayerStor
options.BigData = slices.Clone(lOptions.BigData)
options.Flags = copyMapPreferringNil(lOptions.Flags)
}
if options.HostUIDMapping {
options.UIDMap = nil
if options.IDMappingOptions.HostUIDMapping {
options.IDMappingOptions.UIDMap = nil
}
if options.HostGIDMapping {
options.GIDMap = nil
if options.IDMappingOptions.HostGIDMapping {
options.IDMappingOptions.GIDMap = nil
}
uidMap := options.UIDMap
gidMap := options.GIDMap
uidMap := options.IDMappingOptions.UIDMap
gidMap := options.IDMappingOptions.GIDMap
if parent != "" {
var err error
parentLayer, unlock, err = getParentLayer(rlstore, rlstores, parent)
Expand All @@ -1526,26 +1539,26 @@ func populateLayerOptions(s *store, rlstore rwLayerStore, rlstores []roLayerStor
return nil, nil, unlock, ErrParentIsContainer
}
}
if !options.HostUIDMapping && len(options.UIDMap) == 0 {
if !options.IDMappingOptions.HostUIDMapping && len(options.IDMappingOptions.UIDMap) == 0 {
uidMap = parentLayer.UIDMap
}
if !options.HostGIDMapping && len(options.GIDMap) == 0 {
if !options.IDMappingOptions.HostGIDMapping && len(options.IDMappingOptions.GIDMap) == 0 {
gidMap = parentLayer.GIDMap
}
} else {
if !options.HostUIDMapping && len(options.UIDMap) == 0 {
if !options.IDMappingOptions.HostUIDMapping && len(options.IDMappingOptions.UIDMap) == 0 {
uidMap = s.uidMap
}
if !options.HostGIDMapping && len(options.GIDMap) == 0 {
if !options.IDMappingOptions.HostGIDMapping && len(options.IDMappingOptions.GIDMap) == 0 {
gidMap = s.gidMap
}
}
if s.canUseShifting(uidMap, gidMap) {
options.IDMappingOptions = types.IDMappingOptions{HostUIDMapping: true, HostGIDMapping: true, UIDMap: nil, GIDMap: nil}
options.IDMappingOptions = LayerIDMappingOptions{HostUIDMapping: true, HostGIDMapping: true, UIDMap: nil, GIDMap: nil}
} else {
options.IDMappingOptions = types.IDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
options.IDMappingOptions = LayerIDMappingOptions{
HostUIDMapping: options.IDMappingOptions.HostUIDMapping,
HostGIDMapping: options.IDMappingOptions.HostGIDMapping,
UIDMap: copySlicePreferringNil(uidMap),
GIDMap: copySlicePreferringNil(gidMap),
}
Expand Down Expand Up @@ -1836,14 +1849,14 @@ func (s *store) imageTopLayerForMapping(image *Image, ristore roImageStore, rlst
// mappings, and register it as an alternate top layer in the image.
var layerOptions LayerOptions
if s.canUseShifting(options.UIDMap, options.GIDMap) {
layerOptions.IDMappingOptions = types.IDMappingOptions{
layerOptions.IDMappingOptions = LayerIDMappingOptions{
HostUIDMapping: true,
HostGIDMapping: true,
UIDMap: nil,
GIDMap: nil,
}
} else {
layerOptions.IDMappingOptions = types.IDMappingOptions{
layerOptions.IDMappingOptions = LayerIDMappingOptions{
HostUIDMapping: options.HostUIDMapping,
HostGIDMapping: options.HostGIDMapping,
UIDMap: copySlicePreferringNil(options.UIDMap),
Expand Down Expand Up @@ -1988,20 +2001,12 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
// But in transient store mode, all container layers are volatile.
Volatile: options.Volatile || s.transientStore,
}
if s.canUseShifting(uidMap, gidMap) {
layerOptions.IDMappingOptions = types.IDMappingOptions{
HostUIDMapping: true,
HostGIDMapping: true,
UIDMap: nil,
GIDMap: nil,
}
} else {
layerOptions.IDMappingOptions = types.IDMappingOptions{
HostUIDMapping: idMappingsOptions.HostUIDMapping,
HostGIDMapping: idMappingsOptions.HostGIDMapping,
UIDMap: copySlicePreferringNil(uidMap),
GIDMap: copySlicePreferringNil(gidMap),
}
useHostMapping := idMappingsOptions.HostUIDMapping || s.canUseShifting(uidMap, gidMap)
layerOptions.IDMappingOptions = LayerIDMappingOptions{
HostUIDMapping: useHostMapping,
HostGIDMapping: useHostMapping,
UIDMap: copySlicePreferringNil(uidMap),
GIDMap: copySlicePreferringNil(gidMap),
}
if options.Flags == nil {
options.Flags = make(map[string]any)
Expand Down Expand Up @@ -3054,10 +3059,6 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
if err != nil {
return "", err
}
if options.UidMaps != nil || options.GidMaps != nil {
options.DisableShifting = !s.canUseShifting(options.UidMaps, options.GidMaps)
}

if err := rlstore.startWriting(); err != nil {
return "", err
}
Expand Down
3 changes: 0 additions & 3 deletions storage/tests/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ function setup() {
TESTDIR=${BATS_TMPDIR}/tmp.${suffix}
rm -fr ${TESTDIR}
mkdir -p ${TESTDIR}/{root,runroot}
# disable idmapped mounts in the overlay driver, since that
# is the expectation in the idmaps.bats tests.
export _CONTAINERS_OVERLAY_DISABLE_IDMAP=yes
}

# Delete the unique root directory and a runroot directory.
Expand Down
Loading
Loading