From a108fafefaa52133ff6d5dd671ac382ac4089252 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 15 Jun 2018 09:25:17 +0200 Subject: [PATCH] make e_surf_vm_state_t an enum class --- include/simgrid/s4u/VirtualMachine.hpp | 16 ++++++++-------- src/bindings/java/jmsg_vm.cpp | 2 +- src/plugins/vm/VirtualMachineImpl.cpp | 18 +++++++++--------- src/plugins/vm/VirtualMachineImpl.hpp | 6 +++--- src/plugins/vm/VmLiveMigration.cpp | 4 ++-- src/plugins/vm/s4u_VirtualMachine.cpp | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index 33f8183e7b..9205ceecd1 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -8,13 +8,6 @@ #include -enum e_surf_vm_state_t { - SURF_VM_STATE_CREATED, /**< created, but not yet started */ - SURF_VM_STATE_RUNNING, - SURF_VM_STATE_SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */ - SURF_VM_STATE_DESTROYED -}; - namespace simgrid { namespace s4u { @@ -38,6 +31,13 @@ public: VirtualMachine(VirtualMachine const&) = delete; VirtualMachine& operator=(VirtualMachine const&) = delete; + enum class state { + CREATED, /**< created, but not yet started */ + RUNNING, + SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */ + DESTROYED + }; + simgrid::vm::VirtualMachineImpl* get_impl() { return pimpl_vm_; } void start(); void suspend(); @@ -51,7 +51,7 @@ public: void set_ramsize(size_t ramsize); void set_bound(double bound); - e_surf_vm_state_t getState(); + VirtualMachine::state getState(); static simgrid::xbt::signal on_start; static simgrid::xbt::signal on_started; static simgrid::xbt::signal on_shutdown; diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index f85535969a..90e884e7fb 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -90,7 +90,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_VM_all(JNIEnv* env, jclass c msg_host_t h; xbt_dynar_foreach (hosts, it, h) { simgrid::s4u::VirtualMachine* vm = dynamic_cast(h); - if (vm != nullptr && vm->getState() != SURF_VM_STATE_DESTROYED) { + if (vm != nullptr && vm->getState() != simgrid::s4u::VirtualMachine::state::DESTROYED) { jobject jvm = static_cast(vm->extension(JAVA_HOST_LEVEL)); vms.push_back(jvm); } diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index 1ecf9eef92..19a7b8cbe7 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -141,7 +141,7 @@ VirtualMachineImpl::~VirtualMachineImpl() void VirtualMachineImpl::suspend(smx_actor_t issuer) { - if (get_state() != SURF_VM_STATE_RUNNING) + if (get_state() != s4u::VirtualMachine::state::RUNNING) THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->get_cname()); if (issuer->host == piface_) THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->get_cname(), @@ -159,12 +159,12 @@ void VirtualMachineImpl::suspend(smx_actor_t issuer) XBT_DEBUG("suspend all processes on the VM done done"); - vm_state_ = SURF_VM_STATE_SUSPENDED; + vm_state_ = s4u::VirtualMachine::state::SUSPENDED; } void VirtualMachineImpl::resume() { - if (get_state() != SURF_VM_STATE_SUSPENDED) + if (get_state() != s4u::VirtualMachine::state::SUSPENDED) THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->get_cname()); auto& process_list = piface_->extension()->process_list; @@ -177,7 +177,7 @@ void VirtualMachineImpl::resume() smx_process.resume(); } - vm_state_ = SURF_VM_STATE_RUNNING; + vm_state_ = s4u::VirtualMachine::state::RUNNING; } /** @brief Power off a VM. @@ -189,16 +189,16 @@ void VirtualMachineImpl::resume() */ void VirtualMachineImpl::shutdown(smx_actor_t issuer) { - if (get_state() != SURF_VM_STATE_RUNNING) { + if (get_state() != s4u::VirtualMachine::state::RUNNING) { const char* stateName = "(unknown state)"; switch (get_state()) { - case SURF_VM_STATE_CREATED: + case s4u::VirtualMachine::state::CREATED: stateName = "created, but not yet started"; break; - case SURF_VM_STATE_SUSPENDED: + case s4u::VirtualMachine::state::SUSPENDED: stateName = "suspended"; break; - case SURF_VM_STATE_DESTROYED: + case s4u::VirtualMachine::state::DESTROYED: stateName = "destroyed"; break; default: /* SURF_VM_STATE_RUNNING or unexpected values */ @@ -217,7 +217,7 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) SIMIX_process_kill(&smx_process, issuer); } - set_state(SURF_VM_STATE_DESTROYED); + set_state(s4u::VirtualMachine::state::DESTROYED); /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */ } diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 3db713d0a8..903b787584 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -53,8 +53,8 @@ public: sg_size_t get_ramsize() { return ramsize_; } void set_ramsize(sg_size_t ramsize) { ramsize_ = ramsize; } - e_surf_vm_state_t get_state() { return vm_state_; } - void set_state(e_surf_vm_state_t state) { vm_state_ = state; } + s4u::VirtualMachine::state get_state() { return vm_state_; } + void set_state(s4u::VirtualMachine::state state) { vm_state_ = state; } int get_core_amount() { return core_amount_; } @@ -69,7 +69,7 @@ private: s4u::Host* physical_host_; int core_amount_; size_t ramsize_ = 0; - e_surf_vm_state_t vm_state_ = SURF_VM_STATE_CREATED; + s4u::VirtualMachine::state vm_state_ = s4u::VirtualMachine::state::CREATED; }; /********* diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 0d11db6de0..86b1958fa1 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -43,7 +43,7 @@ void MigrationRx::operator()() /* Update the vm location */ /* precopy migration makes the VM temporally paused */ - xbt_assert(vm_->getState() == SURF_VM_STATE_SUSPENDED); + xbt_assert(vm_->getState() == s4u::VirtualMachine::state::SUSPENDED); /* Update the vm location and resume it */ vm_->set_pm(dst_pm_); @@ -338,7 +338,7 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) src_pm->get_cname()); if (dst_pm->is_off()) THROWF(vm_error, 0, "Cannot migrate VM '%s' to host '%s', which is offline.", vm->get_cname(), dst_pm->get_cname()); - if (vm->getState() != SURF_VM_STATE_RUNNING) + if (vm->getState() != simgrid::s4u::VirtualMachine::state::RUNNING) THROWF(vm_error, 0, "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()); diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index a3c9efdf07..a393f46aba 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -95,7 +95,7 @@ void VirtualMachine::start() } } - this->pimpl_vm_->set_state(SURF_VM_STATE_RUNNING); + this->pimpl_vm_->set_state(VirtualMachine::state::RUNNING); }); on_started(*this); @@ -140,7 +140,7 @@ void VirtualMachine::set_pm(simgrid::s4u::Host* pm) simgrid::simix::simcall([this, pm]() { pimpl_vm_->set_physical_host(pm); }); } -e_surf_vm_state_t VirtualMachine::getState() +VirtualMachine::state VirtualMachine::getState() { return simgrid::simix::simcall([this]() { return pimpl_vm_->get_state(); }); } @@ -237,19 +237,19 @@ void sg_vm_set_bound(sg_vm_t vm, double bound) /** @brief Returns whether the given VM has just created, not running. */ int sg_vm_is_created(sg_vm_t vm) { - return vm->getState() == SURF_VM_STATE_CREATED; + return vm->getState() == simgrid::s4u::VirtualMachine::state::CREATED; } /** @brief Returns whether the given VM is currently running */ int sg_vm_is_running(sg_vm_t vm) { - return vm->getState() == SURF_VM_STATE_RUNNING; + return vm->getState() == simgrid::s4u::VirtualMachine::state::RUNNING; } /** @brief Returns whether the given VM is currently suspended, not running. */ int sg_vm_is_suspended(sg_vm_t vm) { - return vm->getState() == SURF_VM_STATE_SUSPENDED; + return vm->getState() == simgrid::s4u::VirtualMachine::state::SUSPENDED; } /** @brief Start a vm (i.e., boot the guest operating system) -- 2.20.1