mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #2615 from ioito/hotfix/qx-rbd-rebuild-root
fix: avoid rbd image exist when rebuild-root
This commit is contained in:
@@ -172,6 +172,7 @@ func (d *SRBDDisk) createFromTemplate(ctx context.Context, imageId, format strin
|
||||
defer imageCacheManager.ReleaseImage(imageId)
|
||||
storage := d.Storage.(*SRbdStorage)
|
||||
destPool, _ := storage.StorageConf.GetString("pool")
|
||||
storage.deleteImage(destPool, d.Id) //重装系统时,需要删除以前的系统盘
|
||||
if err := storage.cloneImage(imageCacheManager.GetPath(), imageCache.GetName(), destPool, d.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -268,9 +268,22 @@ func (s *SRbdStorage) copyImage(srcPool string, srcImage string, destPool string
|
||||
// 速度快
|
||||
func (s *SRbdStorage) cloneImage(srcPool string, srcImage string, destPool string, destImage string) error {
|
||||
_, err := s.withImage(srcPool, srcImage, func(src *rbd.Image) (interface{}, error) {
|
||||
snapshot, err := src.CreateSnapshot(destImage)
|
||||
snapInfos, err := src.GetSnapshotNames()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "src.CreateSnapshot")
|
||||
return nil, errors.Wrap(err, "image.GetSnapshotNames()")
|
||||
}
|
||||
var snapshot *rbd.Snapshot = nil
|
||||
for _, snap := range snapInfos {
|
||||
if snap.Name == destImage {
|
||||
snapshot = src.GetSnapshot(destImage)
|
||||
break
|
||||
}
|
||||
}
|
||||
if snapshot == nil {
|
||||
snapshot, err = src.CreateSnapshot(destImage)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "src.CreateSnapshot")
|
||||
}
|
||||
}
|
||||
|
||||
isProtect, err := snapshot.IsProtected()
|
||||
|
||||
Reference in New Issue
Block a user