Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Sabaini <[email protected]>
  • Loading branch information
sabaini committed Nov 22, 2023
1 parent d1fb111 commit 3373ec6
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions microceph/ceph/osd.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,33 +302,32 @@ func parseBackingSpec(spec string) (uint64, int, error) {
r := regexp.MustCompile("loop,([1-9][0-9]*[MGT]),([1-9][0-9]*)")

match := r.FindStringSubmatch(spec)
if match != nil {
// Parse the size and unit from the first matched group.
sizeStr := match[1][:len(match[1])-1]
unit := match[1][len(match[1])-1:]

size, err := strconv.ParseUint(sizeStr, 10, 64)
if err != nil {
return 0, 0, fmt.Errorf("failed to parse size from spec %s: %w", spec, err)
}
if match == nil {
return 0, 0, fmt.Errorf("illegal spec: %s", spec)
}
// Parse the size and unit from the first matched group.
sizeStr := match[1][:len(match[1])-1]
unit := match[1][len(match[1])-1:]

// Convert the size to MB.
switch strings.ToUpper(unit) {
case "G":
size *= 1024
case "T":
size *= 1024 * 1024
}
size, err := strconv.ParseUint(sizeStr, 10, 64)
if err != nil {
return 0, 0, fmt.Errorf("failed to parse size from spec %s: %w", spec, err)
}

num, err := strconv.Atoi(match[2])
if err != nil {
return 0, 0, fmt.Errorf("failed to parse number disks from spec %s: %w", spec, err)
}
// Convert the size to MB.
switch strings.ToUpper(unit) {
case "G":
size *= 1024
case "T":
size *= 1024 * 1024
}

return size, num, nil
num, err := strconv.Atoi(match[2])
if err != nil {
return 0, 0, fmt.Errorf("failed to parse number disks from spec %s: %w", spec, err)
}

return 0, 0, fmt.Errorf("illegal spec: %s", spec)
return size, num, nil
}

// getFreeSpace returns the number of free megabytes of disk capacity
Expand Down

0 comments on commit 3373ec6

Please sign in to comment.