snapshot move to recycle bin

This commit is contained in:
wanyaoqi
2019-09-26 22:32:38 +08:00
parent 49a2c10dec
commit 52ef3ec920
4 changed files with 21 additions and 10 deletions
+3 -4
View File
@@ -811,7 +811,7 @@ func (s *SGuestDiskSnapshotTask) onReloadBlkdevSucc(res string) {
func (s *SGuestDiskSnapshotTask) onSnapshotBlkdevFail(string) {
snapshotDir := s.disk.GetSnapshotDir()
snapshotPath := path.Join(snapshotDir, s.snapshotId)
_, err := procutils.NewCommand("rm", "-rf", snapshotPath).Run()
_, err := procutils.NewCommand("mv", "-f", snapshotPath, s.disk.GetPath()).Run()
if err != nil {
log.Errorln(err)
}
@@ -908,7 +908,7 @@ func (s *SGuestSnapshotDeleteTask) onReloadBlkdevSucc(err string) {
func (s *SGuestSnapshotDeleteTask) onSnapshotBlkdevFail(res string) {
snapshotPath := path.Join(s.disk.GetSnapshotDir(), s.convertSnapshot)
if _, err := procutils.NewCommand("rm", "-f", s.tmpPath, snapshotPath).Run(); err != nil {
if _, err := procutils.NewCommand("mv", "-f", s.tmpPath, snapshotPath).Run(); err != nil {
log.Errorln(err)
}
s.taskFailed("Reload blkdev failed")
@@ -923,8 +923,7 @@ func (s *SGuestSnapshotDeleteTask) onResumeSucc(res string) {
}
}
if !s.pendingDelete {
snapshotDir := s.disk.GetSnapshotDir()
procutils.NewCommand("rm", "-f", path.Join(snapshotDir, s.deleteSnapshot))
s.disk.DoDeleteSnapshot(s.deleteSnapshot)
}
body := jsonutils.NewDict()
body.Set("deleted", jsonutils.JSONTrue)
+5
View File
@@ -37,6 +37,7 @@ type IDisk interface {
GetDiskSetupScripts(idx int) string
GetSnapshotLocation() string
OnRebuildRoot(ctx context.Context, params jsonutils.JSONObject) error
DoDeleteSnapshot(snapshotId string) error
DeleteAllSnapshot() error
DiskSnapshot(ctx context.Context, params interface{}) (jsonutils.JSONObject, error)
@@ -173,3 +174,7 @@ func (d *SBaseDisk) DiskDeleteSnapshot(ctx context.Context, params interface{})
func (d *SBaseDisk) CreateFromRbdSnapshot(ctx context.Context, napshotUrl, srcDiskId, srcPool string) error {
return fmt.Errorf("Not implement disk.CreateFromRbdSnapshot")
}
func (d *SBaseDisk) DoDeleteSnapshot(snapshotId string) error {
return fmt.Errorf("Not implement disk.DoDeleteSnapshot")
}
+5
View File
@@ -541,3 +541,8 @@ func (d *SLocalDisk) PrepareMigrate(liveMigrate bool) (string, error) {
}
return "", nil
}
func (d *SLocalDisk) DoDeleteSnapshot(snapshotId string) error {
snapshotPath := path.Join(d.GetSnapshotDir(), snapshotId)
return d.Storage.DeleteDiskfile(snapshotPath)
}
+8 -6
View File
@@ -387,11 +387,11 @@ func checkSnapshots(storage IStorage, snapshotDir string, maxSnapshotCount int)
// if snapshot count greater than maxsnapshot count, do convert
if len(snapshots) >= maxSnapshotCount {
requestConvertSnapshot(snapshotPath, diskId)
requestConvertSnapshot(storage, snapshotPath, diskId)
}
}
func requestConvertSnapshot(snapshotPath, diskId string) {
func requestConvertSnapshot(storage IStorage, snapshotPath, diskId string) {
log.Infof("SNPASHOT path %s", snapshotPath)
res, err := modules.Disks.GetSpecific(
hostutils.GetComputeSession(context.Background()), diskId, "convert-snapshot", nil)
@@ -421,11 +421,13 @@ func requestConvertSnapshot(snapshotPath, diskId string) {
return
}
requestDeleteSnapshot(
diskId, snapshotPath, deleteSnapshot, convertSnapshotPath, outfile, pendingDelete)
storage, diskId, snapshotPath, deleteSnapshot,
convertSnapshotPath, outfile, pendingDelete,
)
}
func requestDeleteSnapshot(
diskId, snapshotPath, deleteSnapshot, convertSnapshotPath,
storage IStorage, diskId, snapshotPath, deleteSnapshot, convertSnapshotPath,
outfile string, pendingDelete bool,
) {
deleteSnapshotPath := path.Join(snapshotPath, deleteSnapshot)
@@ -446,8 +448,8 @@ func requestDeleteSnapshot(
return
}
if !pendingDelete {
if out, err := procutils.NewCommand("rm", "-f", deleteSnapshotPath).Run(); err != nil {
log.Errorf("%s", out)
if err := storage.DeleteDiskfile(deleteSnapshotPath); err != nil {
log.Errorln(err)
return
}
}