From 5eae491d47092d0c92f45a90a5c2ccb217db72fa Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Mon, 29 Dec 2025 11:01:22 +0800 Subject: [PATCH] fix(glance): image disk_format use String2ImageFormat (#23991) --- pkg/image/models/images.go | 4 ++-- pkg/util/qemuimg/qemuimg.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index 92e7679740..5a380d2428 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -546,7 +546,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 @@ -1458,7 +1458,7 @@ func (self *SImage) DoCheckStatus(ctx context.Context, userCred mcclient.TokenCr } img, err := qemuimg.NewQemuImage(self.GetLocalLocation()) if err == nil { - format := string(img.Format) + format := string(img.String2ImageFormat()) virtualSizeMB := int32(img.SizeBytes / 1024 / 1024) if (len(format) > 0 && self.DiskFormat != format) || (virtualSizeMB > 0 && self.MinDiskMB != virtualSizeMB) { db.Update(self, func() error { diff --git a/pkg/util/qemuimg/qemuimg.go b/pkg/util/qemuimg/qemuimg.go index b2041b340b..dc8d0b974f 100644 --- a/pkg/util/qemuimg/qemuimg.go +++ b/pkg/util/qemuimg/qemuimg.go @@ -910,6 +910,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