1 /* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/plugins/vm/VirtualMachineImpl.hpp"
7 #include "src/simix/smx_private.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_host, ker_resource, "Host resources agregate CPU, networking and I/O features");
26 HostImpl::HostImpl(s4u::Host* host) : piface_(host)
28 /* The VM wants to reinstall a new HostImpl, but we don't want to leak the previously existing one */
29 delete piface_->pimpl_;
30 piface_->pimpl_ = this;
35 /* All actors should be gone when the host is turned off (by the end of the simulation). */
36 if (not actor_list_.empty()) {
37 std::string msg = "Shutting down host, but it's not empty:";
38 for (auto const& actor : actor_list_)
39 msg += "\n\t" + std::string(actor.get_name());
41 simix_global->display_all_actor_status();
42 xbt_die("%s", msg.c_str());
44 for (auto const& arg : actors_at_boot_)
46 actors_at_boot_.clear();
48 for (auto const& d : disks_)
52 /** Re-starts all the actors that are marked as restartable.
54 * Weird things will happen if you turn on a host that is already on. S4U is fool-proof, not this.
56 void HostImpl::turn_on() const
58 for (auto const& arg : actors_at_boot_) {
59 XBT_DEBUG("Booting Actor %s(%s) right now", arg->name.c_str(), arg->host->get_cname());
60 simgrid::kernel::actor::ActorImplPtr actor = simgrid::kernel::actor::ActorImpl::create(
61 arg->name, arg->code, nullptr, arg->host, arg->properties.get(), nullptr);
63 *actor->on_exit = *arg->on_exit;
64 if (arg->kill_time >= 0)
65 actor->set_kill_time(arg->kill_time);
66 if (arg->auto_restart)
67 actor->set_auto_restart(arg->auto_restart);
73 /** Kill all actors hosted here */
74 void HostImpl::turn_off(const kernel::actor::ActorImpl* issuer)
76 for (auto& actor : actor_list_) {
77 XBT_DEBUG("Killing Actor %s@%s on behalf of %s which turned off that host.", actor.get_cname(),
78 actor.get_host()->get_cname(), issuer->get_cname());
81 // When a host is turned off, we want to keep only the actors that should restart for when it will boot again.
82 // Then get rid of the others.
83 auto elm = remove_if(begin(actors_at_boot_), end(actors_at_boot_), [](const kernel::actor::ProcessArg* arg) {
84 if (arg->auto_restart)
89 actors_at_boot_.erase(elm, end(actors_at_boot_));
92 std::vector<s4u::ActorPtr> HostImpl::get_all_actors()
94 std::vector<s4u::ActorPtr> res;
95 for (auto& actor : actor_list_)
96 res.emplace_back(actor.get_ciface());
99 size_t HostImpl::get_actor_count() const
101 return actor_list_.size();
104 std::vector<s4u::Disk*> HostImpl::get_disks() const
106 std::vector<s4u::Disk*> disks;
107 for (auto const& d : disks_)
108 disks.push_back(d->get_iface());
112 void HostImpl::set_disks(const std::vector<kernel::resource::DiskImpl*>& disks, s4u::Host* host)
115 for (auto d : disks_)
119 void HostImpl::add_disk(const s4u::Disk* disk)
121 disks_.push_back(disk->get_impl());
124 void HostImpl::remove_disk(const std::string& disk_name)
126 auto position = disks_.begin();
127 for (auto const& d : disks_) {
128 if (d->get_name() == disk_name) {
129 disks_.erase(position);
137 } // namespace simgrid