Skip to content

Commit

Permalink
incusd/instance/lxc: Simplify findIdmap
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Dec 4, 2024
1 parent dd38870 commit c91ab37
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func lxcCreate(s *state.State, args db.InstanceArgs, p api.Project, op *operatio
idmapSet, base, err = findIdmap(
s,
args.Name,
d.expandedConfig["security.idmap.isolated"],
util.IsTrue(d.expandedConfig["security.idmap.isolated"]),
d.expandedConfig["security.idmap.base"],
d.expandedConfig["security.idmap.size"],
d.expandedConfig["raw.idmap"],
Expand Down Expand Up @@ -471,12 +471,7 @@ func idmapSize(state *state.State, isolated bool, size string) (int64, error) {

var idmapLock sync.Mutex

func findIdmap(s *state.State, cName string, isolatedStr string, configBase string, configSize string, rawIdmap string) (*idmap.Set, int64, error) {
isolated := false
if util.IsTrue(isolatedStr) {
isolated = true
}

func findIdmap(s *state.State, cName string, isolated bool, configBase string, configSize string, rawIdmap string) (*idmap.Set, int64, error) {
rawMaps, err := idmap.NewSetFromIncusIDMap(rawIdmap)
if err != nil {
return nil, 0, err
Expand Down Expand Up @@ -1929,7 +1924,7 @@ func (d *lxc) startCommon() (string, []func() error, error) {
idmapSet, base, err := findIdmap(
d.state,
d.Name(),
d.expandedConfig["security.idmap.isolated"],
util.IsTrue(d.expandedConfig["security.idmap.isolated"]),
d.expandedConfig["security.idmap.base"],
d.expandedConfig["security.idmap.size"],
d.expandedConfig["raw.idmap"],
Expand Down Expand Up @@ -4510,7 +4505,7 @@ func (d *lxc) Update(args db.InstanceArgs, userRequested bool) error {
idmapSet, base, err = findIdmap(
d.state,
d.Name(),
d.expandedConfig["security.idmap.isolated"],
util.IsTrue(d.expandedConfig["security.idmap.isolated"]),
d.expandedConfig["security.idmap.base"],
d.expandedConfig["security.idmap.size"],
d.expandedConfig["raw.idmap"],
Expand Down

0 comments on commit c91ab37

Please sign in to comment.