Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mems, cpus check and move common codes into utils #344

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
generate: add param check for mems and cpus
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
  • Loading branch information
Ma Shimiao committed Aug 17, 2017
commit ef48deee08dc529af6e747bcfb6570b2cc677a16
44 changes: 42 additions & 2 deletions cmd/oci-runtime-tool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
}

if context.IsSet("linux-cpus") {
g.SetLinuxResourcesCPUCpus(context.String("linux-cpus"))
if err := uintListValid(context.String("linux-cpus")); err != nil {
return err
} else {
g.SetLinuxResourcesCPUCpus(context.String("linux-cpus"))
}
}

if context.IsSet("linux-hugepage-limits-add") {
Expand All @@ -517,7 +521,11 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
}

if context.IsSet("linux-mems") {
g.SetLinuxResourcesCPUMems(context.String("linux-mems"))
if err := uintListValid(context.String("linux-mems")); err != nil {
return err
} else {
g.SetLinuxResourcesCPUMems(context.String("linux-mems"))
}
}

if context.IsSet("linux-mem-limit") {
Expand Down Expand Up @@ -662,6 +670,38 @@ func parseConsoleSize(consoleSize string) (uint, uint, error) {
return uint(width), uint(height), nil
}

func uintListValid(val string) error {
if val == "" {
return nil
}

split := strings.Split(val, ",")
errInvalidFormat := fmt.Errorf("invalid format: %s", val)

for _, r := range split {
if !strings.Contains(r, "-") {
_, err := strconv.Atoi(r)
if err != nil {
return errInvalidFormat
}
} else {
split := strings.SplitN(r, "-", 2)
min, err := strconv.Atoi(split[0])
if err != nil {
return errInvalidFormat
}
max, err := strconv.Atoi(split[1])
if err != nil {
return errInvalidFormat
}
if max < min {
return errInvalidFormat
}
}
}
return nil
}

func parseIDMapping(idms string) (uint32, uint32, uint32, error) {
idm := strings.Split(idms, ":")
if len(idm) != 3 {
Expand Down