fix(glance): image disk_format use String2ImageFormat (#23989)

This commit is contained in:
wanyaoqi
2025-12-29 11:00:49 +08:00
committed by GitHub
parent b0985f1ad0
commit 059c98003f
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -561,7 +561,7 @@ func (self *SImage) SaveImageFromStream(reader io.Reader, totalSize int64, calCh
if err != nil {
return errors.Wrapf(err, "NewQemuImage %s", localPath)
}
format = string(img.Format)
format = string(img.String2ImageFormat())
virtualSizeBytes = img.SizeBytes
var fastChksum string
@@ -1475,7 +1475,7 @@ func (image *SImage) DoCheckStatus(ctx context.Context, userCred mcclient.TokenC
}
img, err := qemuimg.NewQemuImage(image.GetLocalLocation())
if err == nil {
format := string(img.Format)
format := string(img.String2ImageFormat())
virtualSizeMB := int32(img.SizeBytes / 1024 / 1024)
if (len(format) > 0 && image.DiskFormat != format) || (virtualSizeMB > 0 && image.MinDiskMB != virtualSizeMB) {
db.Update(image, func() error {
+4
View File
@@ -914,6 +914,10 @@ func (img *SQemuImage) String() string {
return fmt.Sprintf("Qemu %s %d(%d) %s", img.Format, img.GetSizeMB(), img.GetActualSizeMB(), img.Path)
}
func (img *SQemuImage) String2ImageFormat() qemuimgfmt.TImageFormat {
return qemuimgfmt.String2ImageFormat(string(img.Format))
}
func (img *SQemuImage) WholeChainFormatIs(format string) (bool, error) {
if img.Format.String() != format {
return false, nil