diff --git a/pkg/compute/regiondrivers/kvm.go b/pkg/compute/regiondrivers/kvm.go index 3af4a86080..540bfb710a 100644 --- a/pkg/compute/regiondrivers/kvm.go +++ b/pkg/compute/regiondrivers/kvm.go @@ -1209,6 +1209,9 @@ func (self *SKVMRegionDriver) GetDiskResetParams(snapshot *models.SSnapshot) *js params.Set("snapshot_id", jsonutils.NewString(snapshot.Id)) params.Set("out_of_chain", jsonutils.NewBool(snapshot.OutOfChain)) params.Set("location", jsonutils.NewString(snapshot.Location)) + if len(snapshot.BackingDiskId) > 0 { + params.Set("backing_disk_id", jsonutils.NewString(snapshot.BackingDiskId)) + } return params } diff --git a/pkg/hostman/storageman/disk_rbd.go b/pkg/hostman/storageman/disk_rbd.go index cc08701692..19ee6f1aea 100644 --- a/pkg/hostman/storageman/disk_rbd.go +++ b/pkg/hostman/storageman/disk_rbd.go @@ -280,9 +280,13 @@ func (d *SRBDDisk) ResetFromSnapshot(ctx context.Context, params interface{}) (j if !ok { return nil, hostutils.ParamsError } + diskId := resetParams.BackingDiskId + if len(diskId) == 0 { + diskId = d.GetId() + } storage := d.Storage.(*SRbdStorage) pool, _ := storage.StorageConf.GetString("pool") - return nil, storage.resetDisk(pool, d.GetId(), resetParams.SnapshotId) + return nil, storage.resetDisk(pool, diskId, resetParams.SnapshotId) } func (d *SRBDDisk) CreateFromRbdSnapshot(ctx context.Context, snapshot, srcDiskId, srcPool string) error { diff --git a/pkg/hostman/storageman/diskhandlers/diskhandler.go b/pkg/hostman/storageman/diskhandlers/diskhandler.go index 64fdb4e84f..0a60f42aa6 100644 --- a/pkg/hostman/storageman/diskhandlers/diskhandler.go +++ b/pkg/hostman/storageman/diskhandlers/diskhandler.go @@ -315,9 +315,11 @@ func diskReset(ctx context.Context, storage storageman.IStorage, diskId string, if err != nil { return nil, httperrors.NewMissingParameterError("snapshot_id") } + backingDiskId, _ := body.GetString("backing_disk_id") hostutils.DelayTask(ctx, disk.ResetFromSnapshot, &storageman.SDiskReset{ - SnapshotId: snapshotId, - Input: body, + SnapshotId: snapshotId, + BackingDiskId: backingDiskId, + Input: body, }) return nil, nil } diff --git a/pkg/hostman/storageman/storagehelper.go b/pkg/hostman/storageman/storagehelper.go index 345ccd9e70..c5d51679cd 100644 --- a/pkg/hostman/storageman/storagehelper.go +++ b/pkg/hostman/storageman/storagehelper.go @@ -36,8 +36,9 @@ func (i *SDiskCreateByDiskinfo) String() string { } type SDiskReset struct { - SnapshotId string - Input jsonutils.JSONObject + SnapshotId string + BackingDiskId string + Input jsonutils.JSONObject } type SDiskCleanupSnapshots struct {