mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(host): check cluster is valid before do qemuimg convert (#24947)
This commit is contained in:
@@ -507,6 +507,13 @@ func convertEncrypt(srcInfo, destInfo SImageInfo, compact bool, workerOpions []s
|
||||
return nil
|
||||
}
|
||||
|
||||
func isValidClusterSize(size int) bool {
|
||||
if size < 512 || size > 2*1024*1024 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageFormat, compact bool, password string, encryptFormat TEncryptFormat, encryptAlg seclib2.TSymEncAlg) error {
|
||||
if !img.IsValid() {
|
||||
return fmt.Errorf("self is not valid")
|
||||
@@ -515,6 +522,9 @@ func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageForm
|
||||
if compact {
|
||||
destClusterSize = DefaultQcow2ClusterSize
|
||||
}
|
||||
if format == qemuimgfmt.QCOW2 && !isValidClusterSize(destClusterSize) {
|
||||
destClusterSize = DefaultQcow2ClusterSize
|
||||
}
|
||||
return Convert(SImageInfo{
|
||||
Path: img.Path,
|
||||
Format: img.Format,
|
||||
|
||||
Reference in New Issue
Block a user