@@ -125,10 +125,14 @@ func RunCmdTimeout(timeout time.Duration, cmd string, args ...string) error {
125125
126126// ParseDiskSpec converts a disk specification into a Disk. The format is:
127127// <size>[:<opt1>,<opt2>,...], like ["5G:channel=nvme"]
128- func ParseDiskSpec (spec string ) (int64 , map [string ]string , error ) {
128+ func ParseDiskSpec (spec string , allowNoSize bool ) (int64 , map [string ]string , error ) {
129129 diskmap := map [string ]string {}
130130 split := strings .Split (spec , ":" )
131- if split [0 ] == "" || (! strings .HasSuffix (split [0 ], "G" )) {
131+ if split [0 ] == "" {
132+ if ! allowNoSize {
133+ return 0 , nil , fmt .Errorf ("no size provided in '%s'" , spec )
134+ }
135+ } else if ! strings .HasSuffix (split [0 ], "G" ) {
132136 return 0 , nil , fmt .Errorf ("invalid size opt %s" , spec )
133137 }
134138 var disksize string
@@ -149,10 +153,14 @@ func ParseDiskSpec(spec string) (int64, map[string]string, error) {
149153 } else {
150154 return 0 , nil , fmt .Errorf ("invalid disk spec %s" , spec )
151155 }
152- disksize = strings .TrimSuffix (disksize , "G" )
153- size , err := strconv .ParseInt (disksize , 10 , 32 )
154- if err != nil {
155- return 0 , nil , fmt .Errorf ("failed to convert %q to int64: %w" , disksize , err )
156+ var size int64 = 0
157+ if disksize != "" {
158+ disksize = strings .TrimSuffix (disksize , "G" )
159+ var err error
160+ size , err = strconv .ParseInt (disksize , 10 , 32 )
161+ if err != nil {
162+ return 0 , nil , fmt .Errorf ("failed to convert %q to int64: %w" , disksize , err )
163+ }
156164 }
157165 return size , diskmap , nil
158166}
0 commit comments