Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
drop unimplementd VM methods: save/restore
[simgrid.git] / src / plugins / vm / VirtualMachineImpl.cpp
index 74d2ea7..67cd7bf 100644 (file)
@@ -154,9 +154,28 @@ void VirtualMachineImpl::setState(e_surf_vm_state_t state)
 {
   vmState_ = state;
 }
-void VirtualMachineImpl::suspend()
+void VirtualMachineImpl::suspend(smx_actor_t issuer)
 {
+  if (isMigrating)
+    THROWF(vm_error, 0, "Cannot suspend VM '%s': it is migrating", piface_->cname());
+  if (getState() != SURF_VM_STATE_RUNNING)
+    THROWF(vm_error, 0, "Cannot suspend VM %s: it is not running.", piface_->cname());
+  if (issuer->host == piface_)
+    THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->cname(), piface_->cname());
+
+  xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+  XBT_DEBUG("suspend VM(%s), where %d processes exist", piface_->cname(), xbt_swag_size(process_list));
+
   action_->suspend();
+
+  smx_actor_t smx_process, smx_process_safe;
+  xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
+    XBT_DEBUG("suspend %s", smx_process->name.c_str());
+    SIMIX_process_suspend(smx_process, issuer);
+  }
+
+  XBT_DEBUG("suspend all processes on the VM done done");
+
   vmState_ = SURF_VM_STATE_SUSPENDED;
 }
 
@@ -179,53 +198,30 @@ void VirtualMachineImpl::resume()
   vmState_ = SURF_VM_STATE_RUNNING;
 }
 
-/**
- * @brief Function to save a VM.
- * This function is the same as vm_suspend, but the state of the VM is saved to the disk, and not preserved in memory.
- * We can later restore it again.
+/** @brief Power off a VM.
+ *
+ * All hosted processes will be killed, but the VM state is preserved on memory.
+ * It can later be restarted.
  *
- * @param issuer the process requesting this operation
+ * @param issuer the actor requesting the shutdown
  */
-void VirtualMachineImpl::save(smx_actor_t issuer)
+void VirtualMachineImpl::shutdown(smx_actor_t issuer)
 {
-  if (isMigrating)
-    THROWF(vm_error, 0, "Cannot save VM %s: it is migrating.", piface_->cname());
-
   if (getState() != SURF_VM_STATE_RUNNING)
-    THROWF(vm_error, 0, "Cannot save VM %s: it is not running.", piface_->cname());
+    THROWF(vm_error, 0, "Cannot shutdown VM %s: it is not running", piface_->cname());
 
   xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
-
-  XBT_DEBUG("Save VM %s, where %d processes exist", piface_->cname(), xbt_swag_size(process_list));
-
-  vmState_ = SURF_VM_STATE_SAVING;
-  action_->suspend();
-  vmState_ = SURF_VM_STATE_SAVED;
+  XBT_DEBUG("shutdown VM %s, that contains %d processes", piface_->cname(), xbt_swag_size(process_list));
 
   smx_actor_t smx_process, smx_process_safe;
   xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
-    XBT_DEBUG("suspend %s", smx_process->cname());
-    SIMIX_process_suspend(smx_process, issuer);
+    XBT_DEBUG("kill %s", smx_process->cname());
+    SIMIX_process_kill(smx_process, issuer);
   }
-}
-
-void VirtualMachineImpl::restore()
-{
-  if (getState() != SURF_VM_STATE_SAVED)
-    THROWF(vm_error, 0, "Cannot restore VM %s: it was not saved", piface_->cname());
-
-  xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
-  XBT_DEBUG("Restore VM %s, where %d processes exist", piface_->cname(), xbt_swag_size(process_list));
 
-  vmState_ = SURF_VM_STATE_RESTORING;
-  action_->resume();
-  vmState_ = SURF_VM_STATE_RUNNING;
+  setState(SURF_VM_STATE_CREATED);
 
-  smx_actor_t smx_process, smx_process_safe;
-  xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
-    XBT_DEBUG("resume %s", smx_process->cname());
-    SIMIX_process_resume(smx_process);
-  }
+  /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */
 }
 
 /** @brief returns the physical machine on which the VM is running **/
@@ -234,21 +230,24 @@ s4u::Host* VirtualMachineImpl::getPm()
   return hostPM_;
 }
 
-/* Update the physical host of the given VM */
-void VirtualMachineImpl::migrate(s4u::Host* host_dest)
+/** @brief Change the physical host on which the given VM is running
+ *
+ * This is an instantaneous migration.
+ */
+void VirtualMachineImpl::setPm(s4u::Host* destination)
 {
   const char* vm_name     = piface_->cname();
   const char* pm_name_src = hostPM_->cname();
-  const char* pm_name_dst = host_dest->cname();
+  const char* pm_name_dst = destination->cname();
 
   /* update net_elm with that of the destination physical host */
-  piface_->pimpl_netcard = host_dest->pimpl_netcard;
+  piface_->pimpl_netcard = destination->pimpl_netcard;
 
-  hostPM_ = host_dest;
+  hostPM_ = destination;
 
   /* Update vcpu's action for the new pm */
   /* create a cpu action bound to the pm model at the destination. */
-  surf::CpuAction* new_cpu_action = static_cast<surf::CpuAction*>(host_dest->pimpl_cpu->execution_start(0));
+  surf::CpuAction* new_cpu_action = static_cast<surf::CpuAction*>(destination->pimpl_cpu->execution_start(0));
 
   surf::Action::State state = action_->getState();
   if (state != surf::Action::State::done)