Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert vm_suspend from SMX to S4U
[simgrid.git] / src / simix / smx_vm.cpp
1 /* Copyright (c) 2007-2015. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "mc/mc.h"
7 #include "simgrid/s4u/VirtualMachine.hpp"
8 #include "smx_private.h"
9 #include "src/plugins/vm/VirtualMachineImpl.hpp"
10 #include "src/plugins/vm/VmHostExt.hpp"
11 #include "src/surf/HostImpl.hpp"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX Virtual Machines");
14
15 /**
16  * @brief Function to shutdown a SIMIX VM host. This function powers off the
17  * VM. All the processes on this VM will be killed. But, the state of the VM is
18  * preserved on memory. We can later start it again.
19  *
20  * @param vm the VM to shutdown (a sg_host_t)
21  */
22 void SIMIX_vm_shutdown(sg_host_t vm, smx_actor_t issuer)
23 {
24   if (static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->getState() != SURF_VM_STATE_RUNNING)
25     THROWF(vm_error, 0, "VM(%s) is not running", vm->cname());
26
27   XBT_DEBUG("shutdown VM %s, that contains %d processes", vm->cname(), xbt_swag_size(sg_host_simix(vm)->process_list));
28
29   smx_actor_t smx_process, smx_process_safe;
30   xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(vm)->process_list) {
31     XBT_DEBUG("kill %s", smx_process->name.c_str());
32     SIMIX_process_kill(smx_process, issuer);
33   }
34
35   /* FIXME: we may have to do something at the surf layer, e.g., vcpu action */
36   static_cast<simgrid::s4u::VirtualMachine*>(vm)->pimpl_vm_->setState(SURF_VM_STATE_CREATED);
37 }
38
39 void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t vm)
40 {
41   SIMIX_vm_shutdown(vm, simcall->issuer);
42 }