#include "src/plugins/vm/VirtualMachineImpl.hpp"
#include "simgrid/s4u/VirtualMachine.hpp"
+#include "src/simix/ActorImpl.hpp"
+#include "src/simix/smx_host_private.h"
#include <xbt/signal.hpp>
xbt_assert(cpu, "cpu-less host");
double solved_value = ws_vm->pimpl_vm_->action_->getVariable()->value;
- XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->name().c_str(),
- ws_vm->pimpl_vm_->getPm()->name().c_str());
+ XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->cname(), ws_vm->pimpl_vm_->getPm()->cname());
// TODO: check lmm_update_constraint_bound() works fine instead of the below manual substitution.
// cpu_cas01->constraint->bound = solved_value;
/* Initialize the VM parameters */
params_.ramsize = 0;
- XBT_VERB("Create VM(%s)@PM(%s)", piface->name().c_str(), hostPM_->name().c_str());
+ XBT_VERB("Create VM(%s)@PM(%s)", piface->cname(), hostPM_->cname());
}
extern "C" int
vmState_ = SURF_VM_STATE_RUNNING;
}
-void VirtualMachineImpl::save()
+/**
+ * @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.
+ *
+ * @param vm the vm host to save (a sg_host_t)
+ */
+void VirtualMachineImpl::save(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());
+
+ 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;
+
+ 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);
+ }
}
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;
+
+ 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);
+ }
}
/** @brief returns the physical machine on which the VM is running **/
/* Update the physical host of the given VM */
void VirtualMachineImpl::migrate(s4u::Host* host_dest)
{
- const char* vm_name = piface_->name().c_str();
- const char* pm_name_src = hostPM_->name().c_str();
- const char* pm_name_dst = host_dest->name().c_str();
+ const char* vm_name = piface_->cname();
+ const char* pm_name_src = hostPM_->cname();
+ const char* pm_name_dst = host_dest->cname();
/* update net_elm with that of the destination physical host */
piface_->pimpl_netcard = host_dest->pimpl_netcard;