From daf48de02c5ddf826a62409660b93eaaeaa7006b Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 2 Jul 2019 15:47:05 +0200 Subject: [PATCH] Define and throw simgrid::VmFailureException. --- include/simgrid/Exception.hpp | 10 ++++++++++ src/plugins/vm/VirtualMachineImpl.cpp | 12 +++++++----- src/plugins/vm/VmLiveMigration.cpp | 17 ++++++++++++----- src/plugins/vm/s4u_VirtualMachine.cpp | 6 ++++-- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 8c1e0f7917..39002a85ff 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -169,6 +169,16 @@ public: } }; +/** Exception raised when a VM fails */ +class VmFailureException : public xbt_ex { +public: + VmFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message) + : xbt_ex(std::move(throwpoint), std::move(message)) + { + category = vm_error; + } +}; + /** Exception raised when something got canceled before completion */ class CancelException : public xbt_ex { public: diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 191d5cfd9a..b7b2002332 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -4,9 +4,9 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/plugins/vm/VirtualMachineImpl.hpp" +#include "simgrid/Exception.hpp" #include "src/include/surf/surf.hpp" #include "src/kernel/activity/ExecImpl.hpp" -#include "xbt/asserts.h" // xbt_log_no_loc XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module"); @@ -173,10 +173,11 @@ VirtualMachineImpl::~VirtualMachineImpl() void VirtualMachineImpl::suspend(smx_actor_t issuer) { if (get_state() != s4u::VirtualMachine::state::RUNNING) - THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->get_cname()); + throw VmFailureException(XBT_THROW_POINT, + xbt::string_printf("Cannot suspend VM %s: it is not running.", piface_->get_cname())); if (issuer->get_host() == piface_) - THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->get_cname(), - piface_->get_cname()); + throw VmFailureException(XBT_THROW_POINT, xbt::string_printf("Actor %s cannot suspend the VM %s in which it runs", + issuer->get_cname(), piface_->get_cname())); XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->get_cname(), process_list_.size()); @@ -195,7 +196,8 @@ void VirtualMachineImpl::suspend(smx_actor_t issuer) void VirtualMachineImpl::resume() { if (get_state() != s4u::VirtualMachine::state::SUSPENDED) - THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->get_cname()); + throw VmFailureException(XBT_THROW_POINT, + xbt::string_printf("Cannot resume VM %s: it was not suspended", piface_->get_cname())); XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->get_cname(), process_list_.size()); diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 460e9f441f..08add03749 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -324,14 +324,21 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) simgrid::s4u::Host* src_pm = vm->get_pm(); if (not src_pm->is_on()) - THROWF(vm_error, 0, "Cannot migrate VM '%s' from host '%s', which is offline.", vm->get_cname(), - src_pm->get_cname()); + throw simgrid::VmFailureException( + XBT_THROW_POINT, simgrid::xbt::string_printf("Cannot migrate VM '%s' from host '%s', which is offline.", + vm->get_cname(), src_pm->get_cname())); if (not dst_pm->is_on()) - THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->get_cname(), dst_pm->get_cname()); + throw simgrid::VmFailureException( + XBT_THROW_POINT, simgrid::xbt::string_printf("Cannot migrate VM '%s' to host '%s', which is offline.", + vm->get_cname(), dst_pm->get_cname())); if (vm->get_state() != simgrid::s4u::VirtualMachine::state::RUNNING) - THROWF(vm_error, 0, "Cannot migrate VM '%s' that is not running yet.", vm->get_cname()); + throw simgrid::VmFailureException( + XBT_THROW_POINT, + simgrid::xbt::string_printf("Cannot migrate VM '%s' that is not running yet.", vm->get_cname())); if (vm->get_impl()->is_migrating_) - THROWF(vm_error, 0, "Cannot migrate VM '%s' that is already migrating.", vm->get_cname()); + throw simgrid::VmFailureException( + XBT_THROW_POINT, + simgrid::xbt::string_printf("Cannot migrate VM '%s' that is already migrating.", vm->get_cname())); vm->get_impl()->is_migrating_ = true; simgrid::s4u::VirtualMachine::on_migration_start(*vm); diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 0a927afca0..7dd96b893a 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -3,6 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/Exception.hpp" #include "simgrid/s4u/Actor.hpp" #include "simgrid/vm.h" #include "src/include/surf/surf.hpp" @@ -84,8 +85,9 @@ void VirtualMachine::start() if (vm_ramsize > pm_ramsize - total_ramsize_of_vms) { XBT_WARN("cannot start %s@%s due to memory shortage: vm_ramsize %ld, free %ld, pm_ramsize %ld (bytes).", this->get_cname(), pm->get_cname(), vm_ramsize, pm_ramsize - total_ramsize_of_vms, pm_ramsize); - THROWF(vm_error, 0, "Memory shortage on host '%s', VM '%s' cannot be started", pm->get_cname(), - this->get_cname()); + throw VmFailureException(XBT_THROW_POINT, + xbt::string_printf("Memory shortage on host '%s', VM '%s' cannot be started", + pm->get_cname(), this->get_cname())); } } -- 2.20.1