From 0f80bc05f4bc19070dc6fbd5f627306fdc564953 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sat, 21 May 2022 17:50:33 +0800 Subject: [PATCH] fix: fail to recogonize vmdk image --- pkg/image/models/images.go | 6 ++++-- pkg/util/qemuimg/qemuimg.go | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index 61c7fb1d11..5d109821f8 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -1030,7 +1030,8 @@ func (self *SImage) newSubformat(ctx context.Context, format qemuimg.TImageForma subformat.Size = self.Size subformat.Checksum = self.Checksum subformat.FastHash = self.FastHash - subformat.Status = self.Status + // saved successfully + subformat.Status = api.IMAGE_STATUS_ACTIVE subformat.Location = self.Location } else { subformat.Status = api.IMAGE_STATUS_QUEUED @@ -1880,6 +1881,7 @@ func (img *SImage) doConvert(ctx context.Context, userCred mcclient.TokenCredent if err != nil { return false, errors.Wrap(err, "cleanup sub image") } + continue } subimgs[i].checkStatus(true, false) if subimgs[i].Status != api.IMAGE_STATUS_ACTIVE { @@ -1888,7 +1890,7 @@ func (img *SImage) doConvert(ctx context.Context, userCred mcclient.TokenCredent } } log.Debugf("doConvert imageStatus %s %v", img.Status, needConvert) - if (img.Status == api.IMAGE_STATUS_SAVED || img.Status == api.IMAGE_STATUS_ACTIVE) && needConvert { + if (img.Status == api.IMAGE_STATUS_SAVED || img.Status == api.IMAGE_STATUS_ACTIVE || img.Status == api.IMAGE_STATUS_PROBING) && needConvert { err := img.migrateSubImage(ctx) if err != nil { return false, errors.Wrap(err, "migrateSubImage") diff --git a/pkg/util/qemuimg/qemuimg.go b/pkg/util/qemuimg/qemuimg.go index 92e71ebd43..cdf509211a 100644 --- a/pkg/util/qemuimg/qemuimg.go +++ b/pkg/util/qemuimg/qemuimg.go @@ -117,6 +117,33 @@ func (img *SQemuImage) parse() error { if err != nil { return err } + /* + { + "virtual-size": 107374182400, + "filename": "/opt/cloud/workspace/data/glance/images/3ccecd2b-0ab4-4525-8e64-6f1d3c3a2457", + "cluster-size": 65536, + "format": "vmdk", + "actual-size": 2173186048, + "format-specific": { + "type": "vmdk", + "data": { + "cid": 3046516340, + "parent-cid": 4294967295, + "create-type": "streamOptimized", + "extents": [ + { + "compressed": true, + "virtual-size": 107374182400, + "filename": "/opt/cloud/workspace/data/glance/images/3ccecd2b-0ab4-4525-8e64-6f1d3c3a2457", + "cluster-size": 65536, + "format": "" + } + ] + } + }, + "dirty-flag": false + } + */ info := struct { VirtualSizeBytes int64 `json:"virtual-size"` @@ -131,6 +158,16 @@ func (img *SQemuImage) parse() error { FormatSpecific struct { Type string `json:"type"` Data struct { + Cid uint64 `json:"cid"` + ParentCid uint64 `json:"parent-cid"` + CreateType string `json:"create-type"` + Extents []struct { + Compressed bool `json:"compressed"` + VirtualSize uint64 `json:"virtual-size"` + Filename string `json:"filename"` + ClusterSize uint64 `json:"cluster-size"` + Format string `json:"format"` + } `json:"extents"` Compat string `json:"compat"` LazyRefcounts int `json:"lazy-refcounts"` RefcountBits int `json:"refcount-bits"` @@ -163,6 +200,9 @@ func (img *SQemuImage) parse() error { return errors.Wrap(err, "ParseQemuFilepath") } img.Subformat = info.CreateType + if img.Subformat == "" { + img.Subformat = info.FormatSpecific.Data.CreateType + } if img.Encrypted { img.EncryptFormat = TEncryptFormat(info.FormatSpecific.Data.Encrypt.Format)