From 883e4b2387e9699a70c1d6087330c12ebb5a3845 Mon Sep 17 00:00:00 2001 From: Fabien Chaix Date: Sun, 26 Jun 2022 01:08:45 +0300 Subject: [PATCH] Make vm_by_name() public and modify c-cloud-migration to use new functions --- examples/c/cloud-migration/cloud-migration.c | 3 ++- include/simgrid/host.h | 1 + include/simgrid/s4u/Host.hpp | 2 ++ src/s4u/s4u_Host.cpp | 10 ++++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/c/cloud-migration/cloud-migration.c b/examples/c/cloud-migration/cloud-migration.c index 3ffb5040f5..5319ebb4e2 100644 --- a/examples/c/cloud-migration/cloud-migration.c +++ b/examples/c/cloud-migration/cloud-migration.c @@ -33,7 +33,8 @@ static void migration_worker_main(int argc, char* argv[]) const char* vm_name = argv[1]; const char* dst_pm_name = argv[2]; - sg_vm_t vm = (sg_vm_t)sg_host_by_name(vm_name); + sg_host_t src_pm = sg_host_self(); + sg_vm_t vm = (sg_vm_t)sg_vm_by_name(src_pm,vm_name); sg_host_t dst_pm = sg_host_by_name(dst_pm_name); vm_migrate(vm, dst_pm); diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 8d709566b0..37efe414fc 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -27,6 +27,7 @@ XBT_PUBLIC void* sg_host_extension_get(const_sg_host_t host, size_t rank); /** Finds a host from its name */ XBT_PUBLIC sg_host_t sg_host_by_name(const char* name); +XBT_PUBLIC sg_vm_t sg_vm_by_name(sg_host_t host, const char* name); /** @brief Return the name of the sg_host_t. */ XBT_PUBLIC const char* sg_host_get_name(const_sg_host_t host); diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 6208ff0c08..8fbe49484b 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -227,6 +227,8 @@ public: VirtualMachine* create_vm(const std::string& name, int core_amount); VirtualMachine* create_vm(const std::string& name, int core_amount, size_t ramsize); + /** Retrieve a VM running on this host from its name, or return nullptr */ + VirtualMachine* vm_by_name_or_null(const std::string& name); void route_to(const Host* dest, std::vector& links, double* latency) const; void route_to(const Host* dest, std::vector& links, double* latency) const; diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 742cd13476..420fb5da89 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -373,6 +373,11 @@ VirtualMachine* Host::create_vm(const std::string& name, int core_amount, size_t [this, &name, core_amount, ramsize] { return this->pimpl_->create_vm(name, core_amount, ramsize); }); } +VirtualMachine* Host::vm_by_name_or_null(const std::string& name) { + simgrid::kernel::resource::VirtualMachineImpl* vm=this->pimpl_->get_vm_by_name_or_null(name); + return vm ? vm->get_iface() : nullptr; +} + ExecPtr Host::exec_init(double flops) const { return this_actor::exec_init(flops); @@ -442,6 +447,11 @@ sg_host_t sg_host_by_name(const char* name) return simgrid::s4u::Host::by_name_or_null(name); } +sg_vm_t sg_vm_by_name(sg_host_t host, const char* name) +{ + return host->vm_by_name_or_null(name); +} + // ========= Layering madness ==============* // ========== User data Layer ========== -- 2.20.1