From 5a3bc2acb60c2e553c48f128b8985cd14b594a9c Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Tue, 29 Jul 2025 00:01:10 +0800 Subject: [PATCH] fix(host): set qemuimg convert cluster_size 64k on compat image (#22965) --- pkg/util/qemuimg/qemuimg.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/util/qemuimg/qemuimg.go b/pkg/util/qemuimg/qemuimg.go index adde2638d2..892147345b 100644 --- a/pkg/util/qemuimg/qemuimg.go +++ b/pkg/util/qemuimg/qemuimg.go @@ -67,6 +67,8 @@ const ( const DefaultConvertCorutines = 8 +const DefaultQcow2ClusterSize = 65536 + var preallocation = "metadata" func SetPreallocation(prealloc string) error { @@ -385,6 +387,9 @@ func convertOther(srcInfo, destInfo SImageInfo, compact bool, workerOpions []str if compact { cmdline = append(cmdline, "-c") + if destInfo.ClusterSize <= 0 { + destInfo.ClusterSize = DefaultQcow2ClusterSize + } } cmdline = append(cmdline, "-f", srcInfo.Format.String(), "-O", destInfo.Format.String()) @@ -396,9 +401,6 @@ func convertOther(srcInfo, destInfo SImageInfo, compact bool, workerOpions []str options = append(options, fmt.Sprintf("cluster_size=%d", destInfo.ClusterSize)) } else if srcInfo.ClusterSize > 0 { options = append(options, fmt.Sprintf("cluster_size=%d", srcInfo.ClusterSize)) - } - if srcInfo.ClusterSize > 0 || destInfo.ClusterSize > 0 { - } if len(options) > 0 { cmdline = append(cmdline, "-o") @@ -507,6 +509,10 @@ func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageForm if !img.IsValid() { return fmt.Errorf("self is not valid") } + destClusterSize := img.ClusterSize + if compact { + destClusterSize = DefaultQcow2ClusterSize + } return Convert(SImageInfo{ Path: img.Path, Format: img.Format, @@ -523,7 +529,7 @@ func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageForm EncryptFormat: encryptFormat, EncryptAlg: encryptAlg, - ClusterSize: img.ClusterSize, + ClusterSize: destClusterSize, }, compact, nil) }