Skip to content

Commit

Permalink
Address review comments
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 df2e26c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 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
10 changes: 8 additions & 2 deletions microceph/cmd/microceph/disk_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ type cmdDiskAdd struct {

func (c *cmdDiskAdd) Command() *cobra.Command {
cmd := &cobra.Command{
Use: "add <PATH>",
Use: "add <SPEC>",
Short: "Add a new Ceph disk (OSD)",
RunE: c.Run,
Long: `Add a new Ceph disk (OSD) for <SPEC>.
SPEC is either a path to a block device such as /dev/sdb or a specification for a loop file.
The specification for a loop file is of the form "loop,<size>,<nr>"
The size is a number with M, G, or T suffixes for megabytes, gigabytes, or terabytes.
The nr is the number of loop OSDs to create.
A spec of "loop,8G,3" will create 3 loop OSDs of 8GB each.`,
RunE: c.Run,
}

cmd.PersistentFlags().BoolVar(&c.flagWipe, "wipe", false, "Wipe the disk prior to use")
Expand Down

0 comments on commit df2e26c

Please sign in to comment.