mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: delete disk skip recycle_bin
This commit is contained in:
@@ -297,3 +297,7 @@ type DiskAllocateFromBackupInput struct {
|
||||
BackupStorageId string
|
||||
BackupStorageAccessInfo *jsonutils.JSONDict
|
||||
}
|
||||
|
||||
type DiskDeleteInput struct {
|
||||
SkipRecycle *bool
|
||||
}
|
||||
|
||||
@@ -1028,11 +1028,12 @@ func (s *SKVMGuestInstance) delTmpDisks(ctx context.Context, migrated bool) erro
|
||||
diskPath, _ := disk.GetString("path")
|
||||
d, _ := storageman.GetManager().GetDiskByPath(diskPath)
|
||||
if d != nil && d.GetType() == api.STORAGE_LOCAL && migrated {
|
||||
if err := d.DeleteAllSnapshot(); err != nil {
|
||||
skipRecycle := true
|
||||
if err := d.DeleteAllSnapshot(skipRecycle); err != nil {
|
||||
log.Errorln(err)
|
||||
return err
|
||||
}
|
||||
if _, err := d.Delete(ctx, nil); err != nil {
|
||||
if _, err := d.Delete(ctx, api.DiskDeleteInput{SkipRecycle: &skipRecycle}); err != nil {
|
||||
log.Errorln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ type IDisk interface {
|
||||
OnRebuildRoot(ctx context.Context, params api.DiskAllocateInput) error
|
||||
DoDeleteSnapshot(snapshotId string) error
|
||||
|
||||
DeleteAllSnapshot() error
|
||||
DeleteAllSnapshot(skipRecycle bool) error
|
||||
DiskSnapshot(ctx context.Context, params interface{}) (jsonutils.JSONObject, error)
|
||||
DiskDeleteSnapshot(ctx context.Context, params interface{}) (jsonutils.JSONObject, error)
|
||||
Delete(ctx context.Context, params interface{}) (jsonutils.JSONObject, error)
|
||||
|
||||
@@ -114,9 +114,10 @@ func (d *SLocalDisk) UmountFuseImage() {
|
||||
}
|
||||
|
||||
func (d *SLocalDisk) Delete(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
|
||||
p := params.(api.DiskDeleteInput)
|
||||
dpath := d.GetPath()
|
||||
log.Infof("Delete guest disk %s", dpath)
|
||||
if err := d.Storage.DeleteDiskfile(dpath); err != nil {
|
||||
if err := d.Storage.DeleteDiskfile(dpath, p.SkipRecycle != nil && *p.SkipRecycle); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
d.UmountFuseImage()
|
||||
@@ -136,7 +137,7 @@ func (d *SLocalDisk) Delete(ctx context.Context, params interface{}) (jsonutils.
|
||||
}
|
||||
|
||||
func (d *SLocalDisk) OnRebuildRoot(ctx context.Context, params api.DiskAllocateInput) error {
|
||||
_, err := d.Delete(ctx, params)
|
||||
_, err := d.Delete(ctx, api.DiskDeleteInput{})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -572,13 +573,13 @@ func (d *SLocalDisk) CleanupSnapshots(ctx context.Context, params interface{}) (
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *SLocalDisk) DeleteAllSnapshot() error {
|
||||
func (d *SLocalDisk) DeleteAllSnapshot(skipRecycle bool) error {
|
||||
snapshotDir := d.GetSnapshotDir()
|
||||
if !fileutils2.Exists(snapshotDir) {
|
||||
return nil
|
||||
}
|
||||
if options.HostOptions.RecycleDiskfile {
|
||||
return d.Storage.DeleteDiskfile(snapshotDir)
|
||||
return d.Storage.DeleteDiskfile(snapshotDir, skipRecycle)
|
||||
} else {
|
||||
log.Infof("Delete disk(%s) snapshot dir %s", d.Id, snapshotDir)
|
||||
return procutils.NewCommand("rm", "-rf", snapshotDir).Run()
|
||||
@@ -607,5 +608,5 @@ func (d *SLocalDisk) PrepareMigrate(liveMigrate bool) (string, error) {
|
||||
|
||||
func (d *SLocalDisk) DoDeleteSnapshot(snapshotId string) error {
|
||||
snapshotPath := path.Join(d.GetSnapshotDir(), snapshotId)
|
||||
return d.Storage.DeleteDiskfile(snapshotPath)
|
||||
return d.Storage.DeleteDiskfile(snapshotPath, false)
|
||||
}
|
||||
|
||||
@@ -86,20 +86,21 @@ func (d *SRBDDisk) GetDiskSetupScripts(idx int) string {
|
||||
return fmt.Sprintf("DISK_%d=%s\n", idx, d.GetPath())
|
||||
}
|
||||
|
||||
func (d *SRBDDisk) DeleteAllSnapshot() error {
|
||||
func (d *SRBDDisk) DeleteAllSnapshot(skipRecycle bool) error {
|
||||
return fmt.Errorf("Not Impl")
|
||||
}
|
||||
|
||||
func (d *SRBDDisk) Delete(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
|
||||
p := params.(api.DiskDeleteInput)
|
||||
storage := d.Storage.(*SRbdStorage)
|
||||
storageConf := d.Storage.GetStorageConf()
|
||||
pool, _ := storageConf.GetString("pool")
|
||||
return nil, storage.deleteImage(pool, d.Id)
|
||||
return nil, storage.deleteImage(pool, d.Id, p.SkipRecycle != nil && *p.SkipRecycle)
|
||||
}
|
||||
|
||||
func (d *SRBDDisk) OnRebuildRoot(ctx context.Context, params api.DiskAllocateInput) error {
|
||||
if len(params.BackingDiskId) == 0 {
|
||||
_, err := d.Delete(ctx, params)
|
||||
_, err := d.Delete(ctx, api.DiskDeleteInput{})
|
||||
return err
|
||||
}
|
||||
storage := d.Storage.(*SRbdStorage)
|
||||
@@ -191,7 +192,7 @@ func (d *SRBDDisk) createFromTemplate(ctx context.Context, imageId, format strin
|
||||
|
||||
storage := d.Storage.(*SRbdStorage)
|
||||
destPool, _ := storage.StorageConf.GetString("pool")
|
||||
storage.deleteImage(destPool, d.Id) //重装系统时,需要删除以前的系统盘
|
||||
storage.deleteImage(destPool, d.Id, false) //重装系统时,需要删除以前的系统盘
|
||||
err = storage.cloneImage(ctx, imageCacheManager.GetPath(), imageCache.GetName(), destPool, d.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cloneImage(%s)", imageCache.GetName())
|
||||
|
||||
@@ -274,7 +274,7 @@ func diskCreate(ctx context.Context, storage storageman.IStorage, diskId string,
|
||||
|
||||
func diskDelete(ctx context.Context, storage storageman.IStorage, diskId string, disk storageman.IDisk, body jsonutils.JSONObject) (interface{}, error) {
|
||||
if disk != nil {
|
||||
hostutils.DelayTask(ctx, disk.Delete, nil)
|
||||
hostutils.DelayTask(ctx, disk.Delete, compute.DiskDeleteInput{})
|
||||
} else {
|
||||
hostutils.DelayTask(ctx, nil, nil)
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (r *SRbdImageCache) Release() {
|
||||
func (r *SRbdImageCache) Remove(ctx context.Context) error {
|
||||
imageCacheManger := r.Manager.(*SRbdImageCacheManager)
|
||||
storage := imageCacheManger.storage.(*SRbdStorage)
|
||||
if err := storage.deleteImage(r.Manager.GetPath(), r.GetName()); err != nil {
|
||||
if err := storage.deleteImage(r.Manager.GetPath(), r.GetName(), false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ type IStorage interface {
|
||||
|
||||
CreateSnapshotFormUrl(ctx context.Context, snapshotUrl, diskId, snapshotPath string) error
|
||||
|
||||
DeleteDiskfile(diskPath string) error
|
||||
DeleteDiskfile(diskPath string, skipRecycle bool) error
|
||||
GetFuseTmpPath() string
|
||||
GetFuseMountPath() string
|
||||
GetImgsaveBackupPath() string
|
||||
@@ -313,7 +313,7 @@ func (s *SBaseStorage) RemoveDisk(d IDisk) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SBaseStorage) DeleteDiskfile(diskpath string) error {
|
||||
func (s *SBaseStorage) DeleteDiskfile(diskpath string, skipRecycle bool) error {
|
||||
return fmt.Errorf("Not Implement")
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ func requestDeleteSnapshot(
|
||||
return
|
||||
}
|
||||
if !pendingDelete {
|
||||
if err := storage.DeleteDiskfile(deleteSnapshotPath); err != nil {
|
||||
if err := storage.DeleteDiskfile(deleteSnapshotPath, false); err != nil {
|
||||
log.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -291,9 +291,9 @@ func (s *SLocalStorage) Detach() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SLocalStorage) DeleteDiskfile(diskpath string) error {
|
||||
func (s *SLocalStorage) DeleteDiskfile(diskpath string, skipRecycle bool) error {
|
||||
log.Infof("Start Delete %s", diskpath)
|
||||
if options.HostOptions.RecycleDiskfile {
|
||||
if options.HostOptions.RecycleDiskfile && !skipRecycle {
|
||||
var (
|
||||
destDir = s.getRecyclePath()
|
||||
destFile = fmt.Sprintf("%s.%d", path.Base(diskpath), time.Now().Unix())
|
||||
|
||||
@@ -198,7 +198,7 @@ func (s *SRbdStorage) resizeImage(pool string, name string, sizeMb uint64) error
|
||||
return img.Resize(int64(sizeMb))
|
||||
}
|
||||
|
||||
func (s *SRbdStorage) deleteImage(pool string, name string) error {
|
||||
func (s *SRbdStorage) deleteImage(pool string, name string, skipRecycle bool) error {
|
||||
client, err := s.GetClient()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetClient")
|
||||
|
||||
Reference in New Issue
Block a user