@@ -67,6 +67,8 @@ const (
6767
6868const DefaultConvertCorutines = 8
6969
70+ const DefaultQcow2ClusterSize = 65536
71+
7072var preallocation = "metadata"
7173
7274func SetPreallocation (prealloc string ) error {
@@ -385,6 +387,9 @@ func convertOther(srcInfo, destInfo SImageInfo, compact bool, workerOpions []str
385387
386388 if compact {
387389 cmdline = append (cmdline , "-c" )
390+ if destInfo .ClusterSize <= 0 {
391+ destInfo .ClusterSize = DefaultQcow2ClusterSize
392+ }
388393 }
389394 cmdline = append (cmdline , "-f" , srcInfo .Format .String (), "-O" , destInfo .Format .String ())
390395
@@ -396,9 +401,6 @@ func convertOther(srcInfo, destInfo SImageInfo, compact bool, workerOpions []str
396401 options = append (options , fmt .Sprintf ("cluster_size=%d" , destInfo .ClusterSize ))
397402 } else if srcInfo .ClusterSize > 0 {
398403 options = append (options , fmt .Sprintf ("cluster_size=%d" , srcInfo .ClusterSize ))
399- }
400- if srcInfo .ClusterSize > 0 || destInfo .ClusterSize > 0 {
401-
402404 }
403405 if len (options ) > 0 {
404406 cmdline = append (cmdline , "-o" )
@@ -507,6 +509,10 @@ func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageForm
507509 if ! img .IsValid () {
508510 return fmt .Errorf ("self is not valid" )
509511 }
512+ destClusterSize := img .ClusterSize
513+ if compact {
514+ destClusterSize = DefaultQcow2ClusterSize
515+ }
510516 return Convert (SImageInfo {
511517 Path : img .Path ,
512518 Format : img .Format ,
@@ -523,7 +529,7 @@ func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageForm
523529
524530 EncryptFormat : encryptFormat ,
525531 EncryptAlg : encryptAlg ,
526- ClusterSize : img . ClusterSize ,
532+ ClusterSize : destClusterSize ,
527533 }, compact , nil )
528534}
529535
0 commit comments