Skip to content

Commit 2a24ba2

Browse files
authored
Merge pull request #1703 from ioito/automated-cherry-pick-of-#1701-upstream-release-3.11
Automated cherry pick of #1701: fix(esxi): support preallocate system disk
2 parents 2125a6c + 1b881cf commit 2a24ba2

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

pkg/multicloud/esxi/host.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ func (host *SHost) addDisks(ctx context.Context, ds *SDatastore, disks []SDiskIn
944944
}
945945
newImagePath := fmt.Sprintf("[%s] %s/%s.vmdk", ds.GetRelName(), uuid, uuid)
946946

947-
err = host.copyVirtualDisk(imagePath, newImagePath, disk.Driver)
947+
err = host.copyVirtualDisk(imagePath, newImagePath, disk.Driver, disk.Preallocation)
948948
if err != nil {
949949
return nil, err
950950
}
@@ -989,7 +989,7 @@ func (host *SHost) addDisks(ctx context.Context, ds *SDatastore, disks []SDiskIn
989989
if err != nil {
990990
return nil, errors.Wrapf(err, "getDatastoreObj")
991991
}
992-
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)
992+
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)
993993
diskDev, err := NewDiskDev(ctx, size, SDiskConfig{
994994
SizeMb: size,
995995
Uuid: uuid,
@@ -1038,10 +1038,10 @@ func (host *SHost) addDisks(ctx context.Context, ds *SDatastore, disks []SDiskIn
10381038
return evm, nil
10391039
}
10401040

1041-
func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
1041+
func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver, preallocation string) error {
10421042
dm := object.NewVirtualDiskManager(host.manager.client.Client)
10431043
spec := &types.VirtualDiskSpec{
1044-
DiskType: "thin",
1044+
DiskType: string(types.VirtualDiskTypeThin),
10451045
}
10461046
switch diskDriver {
10471047
case "", "scsi", "pvscsi":
@@ -1069,6 +1069,22 @@ func (host *SHost) copyVirtualDisk(srcPath, dstPath, diskDriver string) error {
10691069
if err != nil {
10701070
return errors.Wrap(err, "wait CopyVirtualDiskTask")
10711071
}
1072+
if preallocation == api.DISK_PREALLOCATION_FULL || preallocation == api.DISK_PREALLOCATION_FALLOC {
1073+
err = func() error {
1074+
task, err = dm.InflateVirtualDisk(host.manager.context, dstPath, host.datacenter.getDcObj())
1075+
if err != nil {
1076+
return errors.Wrap(err, "unable to InflateVirtualDisk")
1077+
}
1078+
err = task.Wait(host.manager.context)
1079+
if err != nil {
1080+
return errors.Wrap(err, "wait InflateVirtualDiskTask")
1081+
}
1082+
return nil
1083+
}()
1084+
if err != nil {
1085+
log.Errorf("inflate disk %s failed: %s", dstPath, err)
1086+
}
1087+
}
10721088
return nil
10731089
}
10741090

0 commit comments

Comments
 (0)