Automated cherry pick of #20852: fix(region,host): slvm disk create use guest host lvm disk create from backup (#20855)

* fix(region): slvm disk create use guest host

* fix(host): lvm disk create from backup
This commit is contained in:
wanyaoqi
2024-07-22 15:13:31 +08:00
committed by GitHub
parent be0ebd0aed
commit c045f8878c
3 changed files with 31 additions and 0 deletions
+6
View File
@@ -1472,6 +1472,12 @@ func (disk *SDisk) getCandidateHostIds() ([]string, error) {
}
func (self *SDisk) GetMasterHost(storage *SStorage) (*SHost, error) {
if storage.StorageType == api.STORAGE_SLVM {
if guest := self.GetGuest(); guest != nil {
return guest.GetHost()
}
}
if storage.MasterHost != "" {
return storage.GetMasterHost()
}
+13
View File
@@ -486,6 +486,19 @@ func (s *SLVMStorage) CreateDiskFromExistingPath(context.Context, IDisk, *SDiskC
return errors.Errorf("unsupported operation")
}
func (s *SLVMStorage) CreateDiskFromBackup(ctx context.Context, disk IDisk, input *SDiskCreateByDiskinfo) error {
lvSizeMb := lvmutils.GetQcow2LvSize(int64(input.DiskInfo.DiskSizeMb))
if err := lvmutils.LvCreate(s.GetPath(), disk.GetId(), lvSizeMb*1024*1024); err != nil {
return errors.Wrap(err, "CreateRaw")
}
err := doRestoreDisk(ctx, s, input, disk, disk.GetPath())
if err != nil {
return errors.Wrap(err, "doRestoreDisk")
}
return nil
}
func (s *SLVMStorage) GetFuseTmpPath() string {
localPath := options.HostOptions.ImageCachePath
if len(options.HostOptions.LocalImagePath) > 0 {
+12
View File
@@ -177,3 +177,15 @@ func (s *SSLVMStorage) SetStorageInfo(storageId, storageName string, conf jsonut
}
return nil
}
func (s *SSLVMStorage) CreateDiskFromBackup(ctx context.Context, disk IDisk, input *SDiskCreateByDiskinfo) error {
err := s.SLVMStorage.CreateDiskFromBackup(ctx, disk, input)
if err != nil {
return err
}
err = lvmutils.LVDeactivate(disk.GetPath())
if err != nil {
return errors.Wrap(err, "LVDeactivate")
}
return nil
}