Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make e_surf_vm_state_t an enum class
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 15 Jun 2018 07:25:17 +0000 (09:25 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 15 Jun 2018 07:25:17 +0000 (09:25 +0200)
include/simgrid/s4u/VirtualMachine.hpp
src/bindings/java/jmsg_vm.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VirtualMachineImpl.hpp
src/plugins/vm/VmLiveMigration.cpp
src/plugins/vm/s4u_VirtualMachine.cpp

index 33f8183..9205cee 100644 (file)
@@ -8,13 +8,6 @@
 
 #include <simgrid/s4u/Host.hpp>
 
 
 #include <simgrid/s4u/Host.hpp>
 
-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 {
 
 namespace simgrid {
 namespace s4u {
 
@@ -38,6 +31,13 @@ public:
   VirtualMachine(VirtualMachine const&) = delete;
   VirtualMachine& operator=(VirtualMachine const&) = delete;
 
   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();
   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);
 
   void set_ramsize(size_t ramsize);
   void set_bound(double bound);
 
-  e_surf_vm_state_t getState();
+  VirtualMachine::state getState();
   static simgrid::xbt::signal<void(VirtualMachine&)> on_start;
   static simgrid::xbt::signal<void(VirtualMachine&)> on_started;
   static simgrid::xbt::signal<void(VirtualMachine&)> on_shutdown;
   static simgrid::xbt::signal<void(VirtualMachine&)> on_start;
   static simgrid::xbt::signal<void(VirtualMachine&)> on_started;
   static simgrid::xbt::signal<void(VirtualMachine&)> on_shutdown;
index f855359..90e884e 100644 (file)
@@ -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<simgrid::s4u::VirtualMachine*>(h);
   msg_host_t h;
   xbt_dynar_foreach (hosts, it, h) {
     simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(h);
-    if (vm != nullptr && vm->getState() != SURF_VM_STATE_DESTROYED) {
+    if (vm != nullptr && vm->getState() != simgrid::s4u::VirtualMachine::state::DESTROYED) {
       jobject jvm = static_cast<jobject>(vm->extension(JAVA_HOST_LEVEL));
       vms.push_back(jvm);
     }
       jobject jvm = static_cast<jobject>(vm->extension(JAVA_HOST_LEVEL));
       vms.push_back(jvm);
     }
index 1ecf9ee..19a7b8c 100644 (file)
@@ -141,7 +141,7 @@ VirtualMachineImpl::~VirtualMachineImpl()
 
 void VirtualMachineImpl::suspend(smx_actor_t issuer)
 {
 
 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(),
     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");
 
 
   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()
 {
 }
 
 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<simgrid::simix::Host>()->process_list;
     THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->get_cname());
 
   auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
@@ -177,7 +177,7 @@ void VirtualMachineImpl::resume()
     smx_process.resume();
   }
 
     smx_process.resume();
   }
 
-  vm_state_ = SURF_VM_STATE_RUNNING;
+  vm_state_ = s4u::VirtualMachine::state::RUNNING;
 }
 
 /** @brief Power off a VM.
 }
 
 /** @brief Power off a VM.
@@ -189,16 +189,16 @@ void VirtualMachineImpl::resume()
  */
 void VirtualMachineImpl::shutdown(smx_actor_t issuer)
 {
  */
 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()) {
     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;
         stateName = "created, but not yet started";
         break;
-      case SURF_VM_STATE_SUSPENDED:
+      case s4u::VirtualMachine::state::SUSPENDED:
         stateName = "suspended";
         break;
         stateName = "suspended";
         break;
-      case SURF_VM_STATE_DESTROYED:
+      case s4u::VirtualMachine::state::DESTROYED:
         stateName = "destroyed";
         break;
       default: /* SURF_VM_STATE_RUNNING or unexpected values */
         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);
   }
 
     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 */
 }
 
   /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */
 }
index 3db713d..903b787 100644 (file)
@@ -53,8 +53,8 @@ public:
   sg_size_t get_ramsize() { return ramsize_; }
   void set_ramsize(sg_size_t ramsize) { ramsize_ = ramsize; }
 
   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_; }
 
 
   int get_core_amount() { return core_amount_; }
 
@@ -69,7 +69,7 @@ private:
   s4u::Host* physical_host_;
   int core_amount_;
   size_t ramsize_            = 0;
   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;
 };
 
 /*********
 };
 
 /*********
index 0d11db6..86b1958 100644 (file)
@@ -43,7 +43,7 @@ void MigrationRx::operator()()
 
   /* Update the vm location */
   /* precopy migration makes the VM temporally paused */
 
   /* 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_);
 
   /* 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());
            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());
     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());
index a3c9efd..a393f46 100644 (file)
@@ -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);
   });
 
   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); });
 }
 
   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(); });
 }
 {
   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)
 {
 /** @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)
 {
 }
 
 /** @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)
 {
 }
 
 /** @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)
 }
 
 /** @brief Start a vm (i.e., boot the guest operating system)