From c687d90470f0587b95d3776e1f8e73d4e0c53bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez?= Date: Thu, 12 Sep 2019 17:55:45 +0200 Subject: [PATCH] B #3687: check snap ID on disk snapshot revert (#3693) (cherry picked from commit 68a76aa9ba2e1c72c42ffc31be9e5669d024fbc8) --- include/VirtualMachineDisk.h | 11 +++++++++++ src/dm/DispatchManagerActions.cc | 6 ++++++ src/vm/VirtualMachineDisk.cc | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/include/VirtualMachineDisk.h b/include/VirtualMachineDisk.h index eb9fb0cccb..3d50c87896 100644 --- a/include/VirtualMachineDisk.h +++ b/include/VirtualMachineDisk.h @@ -245,6 +245,17 @@ public: return (snapshots != 0); } + bool has_snapshot(int snap_id) + { + if (!has_snapshots()) + { + return false; + } + + return snapshots->exists(snap_id); + } + + /** * Renames a snapshot * diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index b6930f256f..84c4bf6ba1 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -2076,6 +2076,12 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, if (vm->set_snapshot_disk(did, snap_id) == -1) { + oss << "Disk id (" << did << ") or snapshot id (" + << snap_id << ") is not invalid."; + + error_str = oss.str(); + + NebulaLog::log("DiM", Log::ERROR, error_str); vm->unlock(); return -1; } diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index 59d44d5bc6..8416811c96 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -1270,6 +1270,11 @@ int VirtualMachineDisks::set_active_snapshot(int id, int snap_id) return -1; } + if (!disk->has_snapshot(snap_id)) + { + return -1; + } + disk->set_active_snapshot(); disk->replace("DISK_SNAPSHOT_ID", snap_id);