From 62ea9881079f9fddce6410579288ef85d4acd4eb Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Tue, 16 Apr 2024 00:01:50 +0800 Subject: [PATCH] fix: fail to create encrypted nfs disk --- pkg/hostman/storageman/disk_local.go | 8 +++++++- pkg/hostman/storageman/disk_nas.go | 13 +------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pkg/hostman/storageman/disk_local.go b/pkg/hostman/storageman/disk_local.go index a413ad8567..3b7d379323 100644 --- a/pkg/hostman/storageman/disk_local.go +++ b/pkg/hostman/storageman/disk_local.go @@ -240,7 +240,13 @@ func (d *SLocalDisk) CreateFromImageFuse(ctx context.Context, url string, size i } func (d *SLocalDisk) CreateFromTemplate(ctx context.Context, imageId, format string, size int64, encryptInfo *apis.SEncryptInfo) (jsonutils.JSONObject, error) { - var imageCacheManager = storageManager.LocalStorageImagecacheManager + imageCacheManager := storageManager.LocalStorageImagecacheManager + return d.createFromTemplateAndResize(ctx, imageId, format, imageCacheManager, encryptInfo, size) +} + +func (d *SLocalDisk) createFromTemplateAndResize( + ctx context.Context, imageId, format string, imageCacheManager IImageCacheManger, encryptInfo *apis.SEncryptInfo, size int64, +) (jsonutils.JSONObject, error) { ret, err := d.createFromTemplate(ctx, imageId, format, imageCacheManager, encryptInfo) if err != nil { return nil, err diff --git a/pkg/hostman/storageman/disk_nas.go b/pkg/hostman/storageman/disk_nas.go index 2c13998d61..4c61ec9b3a 100644 --- a/pkg/hostman/storageman/disk_nas.go +++ b/pkg/hostman/storageman/disk_nas.go @@ -43,18 +43,7 @@ func NewNasDisk(storage IStorage, id string) *SNasDisk { func (d *SNasDisk) CreateFromTemplate(ctx context.Context, imageId, format string, size int64, encryptInfo *apis.SEncryptInfo) (jsonutils.JSONObject, error) { imageCacheManager := storageManager.GetStoragecacheById(d.Storage.GetStoragecacheId()) - ret, err := d.SLocalDisk.createFromTemplate(ctx, imageId, format, imageCacheManager, encryptInfo) - if err != nil { - return nil, err - } - retSize, _ := ret.Int("disk_size") - log.Infof("REQSIZE: %d, RETSIZE: %d", size, retSize) - if size > retSize { - params := jsonutils.NewDict() - params.Set("size", jsonutils.NewInt(size)) - return d.Resize(ctx, params) - } - return ret, nil + return d.SLocalDisk.createFromTemplateAndResize(ctx, imageId, format, imageCacheManager, encryptInfo, size) } func (d *SNasDisk) CreateFromImageFuse(ctx context.Context, url string, size int64, encryptInfo *apis.SEncryptInfo) error {