fix(host): set qemuimg convert cluster_size 64k on compat image (#22965)

This commit is contained in:
wanyaoqi
2025-07-29 00:01:10 +08:00
committed by GitHub
parent 4080c2ddfb
commit 5a3bc2acb6
+10 -4
View File
@@ -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)
}