From: Martin Quinson Date: Sat, 30 Sep 2017 21:22:08 +0000 (+0200) Subject: shutdown all hosted VMs when an host is turned off X-Git-Tag: v3_17~54 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e268f7fa25eff43cfdc9b920754ac7cd1f5a8e08 shutdown all hosted VMs when an host is turned off --- diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index ea9a040ef7..b60dfc3e1d 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -44,6 +44,23 @@ std::deque VirtualMachineImpl::allVms_; // const double virt_overhead = 0.95; const double virt_overhead = 1; +static void hostStateChange(s4u::Host& host) +{ + if (host.isOff()) { // just turned off. + std::vector trash; + /* Find all VMs living on that host */ + for (s4u::VirtualMachine* const& vm : VirtualMachineImpl::allVms_) + if (vm->getPm() == &host) + trash.push_back(vm); + for (s4u::VirtualMachine* vm : trash) + vm->pimpl_vm_->shutdown(SIMIX_process_self()); + } +} +VMModel::VMModel() +{ + s4u::Host::onStateChange.connect(hostStateChange); +} + double VMModel::nextOccuringEvent(double now) { /* TODO: update action's cost with the total cost of processes on the VM. */ @@ -224,7 +241,7 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) THROW_IMPOSSIBLE; break; } - XBT_VERB("Shuting down the VM %s even if it's not running but %s", piface_->getCname(), stateName); + XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->getCname(), stateName); } xbt_swag_t process_list = piface_->extension()->process_list; @@ -233,7 +250,8 @@ void VirtualMachineImpl::shutdown(smx_actor_t issuer) smx_actor_t smx_process; smx_actor_t smx_process_safe; xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) { - XBT_DEBUG("kill %s", smx_process->cname()); + XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process->cname(), smx_process->host->getCname(), + issuer->cname()); SIMIX_process_kill(smx_process, issuer); } diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 1063bf1ff8..79c3affb1d 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -121,6 +121,7 @@ protected: */ class VMModel : public surf::HostModel { public: + VMModel(); void ignoreEmptyVmInPmLMM() override{}; double nextOccuringEvent(double now) override; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 017c339041..86985418e0 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -28,7 +28,7 @@ namespace simgrid { Host::~Host() { - /* Clean Simulator data */ + /* All processes should be gone when the host is turned off (by the end of the simulation). */ if (xbt_swag_size(process_list) != 0) { std::string msg = std::string("Shutting down host, but it's not empty:"); smx_actor_t process = nullptr; @@ -81,7 +81,8 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer) smx_actor_t process = nullptr; xbt_swag_foreach(process, host->process_list) { SIMIX_process_kill(process, issuer); - XBT_DEBUG("Killing %s@%s on behalf of %s", process->cname(), process->host->getCname(), issuer->cname()); + XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process->cname(), + process->host->getCname(), issuer->cname()); } } } else { diff --git a/teshsuite/msg/host_on_off_processes/host_on_off_processes.c b/teshsuite/msg/host_on_off_processes/host_on_off_processes.c index 12d7f31c66..680b014b1b 100644 --- a/teshsuite/msg/host_on_off_processes/host_on_off_processes.c +++ b/teshsuite/msg/host_on_off_processes/host_on_off_processes.c @@ -12,7 +12,8 @@ int tasks_done = 0; static void task_cleanup_handler(void *task) { - MSG_task_destroy(task); + if (task) + MSG_task_destroy(task); } static int process_daemon(int argc, char *argv[]) @@ -171,7 +172,7 @@ static int test_launcher(int argc, char *argv[]) MSG_process_sleep(10); XBT_INFO(" Turn Jupiter off"); MSG_host_off(jupiter); - XBT_INFO("Test 5 seems ok, cool !(number of Process : %d, it should be 2", MSG_process_get_number()); + XBT_INFO("Test 5 seems ok (number of Process: %d, it should be 2)", MSG_process_get_number()); } test =6; diff --git a/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh b/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh index 13b028d28b..5d5d220c5a 100644 --- a/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh +++ b/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh @@ -61,7 +61,7 @@ $ ./host_on_off_processes ${srcdir:=.}/../../../examples/platforms/small_platfor > [Tremblay:commTX:(3) 10.000000] [msg_test/INFO] Start TX > [Tremblay:test_launcher:(1) 10.000000] [msg_test/INFO] number of processes: 3 > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Turn Jupiter off -> [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test 5 seems ok, cool !(number of Process : 2, it should be 2 +> [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test 5 seems ok (number of Process: 2, it should be 2) > [Tremblay:test_launcher:(1) 20.000000] [msg_test/INFO] Test done. See you! > [Tremblay:commTX:(3) 40.000000] [msg_test/INFO] TX done > [40.000000] [msg_test/INFO] Simulation time 40