Skip to content

Commit e213bdf

Browse files
authored
fix(host): set qemuimg convert cluster_size 64k on compat image (#22967)
1 parent d0b72da commit e213bdf

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/util/qemuimg/qemuimg.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const (
6767

6868
const DefaultConvertCorutines = 8
6969

70+
const DefaultQcow2ClusterSize = 65536
71+
7072
var preallocation = "metadata"
7173

7274
func 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

Comments
 (0)