diff --git a/microceph/ceph/osd.go b/microceph/ceph/osd.go index ec3ce5e2..fe818294 100644 --- a/microceph/ceph/osd.go +++ b/microceph/ceph/osd.go @@ -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 diff --git a/microceph/cmd/microceph/disk_add.go b/microceph/cmd/microceph/disk_add.go index 02b335e6..3fbd8014 100644 --- a/microceph/cmd/microceph/disk_add.go +++ b/microceph/cmd/microceph/disk_add.go @@ -26,9 +26,15 @@ type cmdDiskAdd struct { func (c *cmdDiskAdd) Command() *cobra.Command { cmd := &cobra.Command{ - Use: "add ", + Use: "add ", Short: "Add a new Ceph disk (OSD)", - RunE: c.Run, + Long: `Add a new Ceph disk (OSD) for . + 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,," + 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")