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);