pkg/spec.InitFSMounts: fix mount opts in place

... rather than create a new slice and then make the caller
replace the original with the new one.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2020-03-31 10:20:05 -07:00
parent c11c5e180a
commit f2c42a3958
3 changed files with 11 additions and 19 deletions

View File

@ -371,11 +371,9 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
// BIND MOUNTS // BIND MOUNTS
configSpec.Mounts = SupercedeUserMounts(userMounts, configSpec.Mounts) configSpec.Mounts = SupercedeUserMounts(userMounts, configSpec.Mounts)
// Process mounts to ensure correct options // Process mounts to ensure correct options
finalMounts, err := InitFSMounts(configSpec.Mounts) if err := InitFSMounts(configSpec.Mounts); err != nil {
if err != nil {
return nil, err return nil, err
} }
configSpec.Mounts = finalMounts
// BLOCK IO // BLOCK IO
blkio, err := config.CreateBlockIO() blkio, err := config.CreateBlockIO()

View File

@ -855,21 +855,19 @@ func SupercedeUserMounts(mounts []spec.Mount, configMount []spec.Mount) []spec.M
} }
// Ensure mount options on all mounts are correct // Ensure mount options on all mounts are correct
func InitFSMounts(inputMounts []spec.Mount) ([]spec.Mount, error) { func InitFSMounts(mounts []spec.Mount) error {
// We need to look up mounts so we can figure out the proper mount flags // We need to look up mounts so we can figure out the proper mount flags
// to apply. // to apply.
systemMounts, err := pmount.GetMounts() systemMounts, err := pmount.GetMounts()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error retrieving system mounts to look up mount options") return errors.Wrapf(err, "error retrieving system mounts to look up mount options")
} }
// TODO: We probably don't need to re-build the mounts array for i, m := range mounts {
var mounts []spec.Mount
for _, m := range inputMounts {
if m.Type == TypeBind { if m.Type == TypeBind {
baseMnt, err := findMount(m.Source, systemMounts) baseMnt, err := findMount(m.Source, systemMounts)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error looking up mountpoint for mount %s", m.Source) return errors.Wrapf(err, "error looking up mountpoint for mount %s", m.Source)
} }
var noexec, nosuid, nodev bool var noexec, nosuid, nodev bool
for _, baseOpt := range strings.Split(baseMnt.Opts, ",") { for _, baseOpt := range strings.Split(baseMnt.Opts, ",") {
@ -890,21 +888,19 @@ func InitFSMounts(inputMounts []spec.Mount) ([]spec.Mount, error) {
opts, err := util.ProcessOptions(m.Options, false, defaultMountOpts) opts, err := util.ProcessOptions(m.Options, false, defaultMountOpts)
if err != nil { if err != nil {
return nil, err return err
} }
m.Options = opts mounts[i].Options = opts
} }
if m.Type == TypeTmpfs && filepath.Clean(m.Destination) != "/dev" { if m.Type == TypeTmpfs && filepath.Clean(m.Destination) != "/dev" {
opts, err := util.ProcessOptions(m.Options, true, nil) opts, err := util.ProcessOptions(m.Options, true, nil)
if err != nil { if err != nil {
return nil, err return err
} }
m.Options = opts mounts[i].Options = opts
} }
mounts = append(mounts, m)
} }
return mounts, nil return nil
} }
// TODO: We could make this a bit faster by building a tree of the mountpoints // TODO: We could make this a bit faster by building a tree of the mountpoints

View File

@ -215,11 +215,9 @@ func (s *SpecGenerator) toOCISpec(rt *libpod.Runtime, newImage *image.Image) (*s
// BIND MOUNTS // BIND MOUNTS
configSpec.Mounts = createconfig.SupercedeUserMounts(s.Mounts, configSpec.Mounts) configSpec.Mounts = createconfig.SupercedeUserMounts(s.Mounts, configSpec.Mounts)
// Process mounts to ensure correct options // Process mounts to ensure correct options
finalMounts, err := createconfig.InitFSMounts(configSpec.Mounts) if err := createconfig.InitFSMounts(configSpec.Mounts); err != nil {
if err != nil {
return nil, err return nil, err
} }
configSpec.Mounts = finalMounts
// Add annotations // Add annotations
if configSpec.Annotations == nil { if configSpec.Annotations == nil {