mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user