Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pkg/multicloud/esxi/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ func (host *SHost) addDisks(ctx context.Context, ds *SDatastore, disks []SDiskIn
}
newImagePath := fmt.Sprintf("[%s] %s/%s.vmdk", ds.GetRelName(), uuid, uuid)

err = host.copyVirtualDisk(imagePath, newImagePath, disk.Driver)
err = host.copyVirtualDisk(imagePath, newImagePath, disk.Driver, disk.Preallocation)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -989,7 +989,7 @@ func (host *SHost) addDisks(ctx context.Context, ds *SDatastore, disks []SDiskIn
if err != nil {
return nil, errors.Wrapf(err, "getDatastoreObj")
}
log.Debugf("ds: %s, size: %d, image path: %s, uuid: %s, index: %d, ctrlKey: %d, driver: %s, key: %d.", vds.String(), size, imagePath, uuid, unitNumber, ctrlKey, disk.Driver, 2000+i)
log.Debugf("ds: %s, size: %d, image path: %s, uuid: %s, index: %d, preallocation: %s, ctrlKey: %d, driver: %s, key: %d.", vds.String(), size, imagePath, uuid, unitNumber, disk.Preallocation, ctrlKey, disk.Driver, 2000+i)
diskDev, err := NewDiskDev(ctx, size, SDiskConfig{
SizeMb: size,
Uuid: uuid,
Expand Down Expand Up @@ -1038,10 +1038,10 @@ func (host *SHost) addDisks(ctx context.Context, ds *SDatastore, disks []SDiskIn
return evm, nil
}

func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver, preallocation string) error {
dm := object.NewVirtualDiskManager(host.manager.client.Client)
spec := &types.VirtualDiskSpec{
DiskType: "thin",
DiskType: string(types.VirtualDiskTypeThin),
}
switch diskDriver {
case "", "scsi", "pvscsi":
Expand Down Expand Up @@ -1069,6 +1069,22 @@ func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
if err != nil {
return errors.Wrap(err, "wait CopyVirtualDiskTask")
}
if preallocation == api.DISK_PREALLOCATION_FULL || preallocation == api.DISK_PREALLOCATION_FALLOC {
err = func() error {
task, err = dm.InflateVirtualDisk(host.manager.context, dstPath, host.datacenter.getDcObj())
if err != nil {
return errors.Wrap(err, "unable to InflateVirtualDisk")
}
err = task.Wait(host.manager.context)
if err != nil {
return errors.Wrap(err, "wait InflateVirtualDiskTask")
}
return nil
}()
if err != nil {
log.Errorf("inflate disk %s failed: %s", dstPath, err)
}
}
return nil
}

Expand Down