From 0af24eadd83ec0406172c767ad0deffa921c0eaf Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 30 Mar 2017 10:53:03 +0200 Subject: [PATCH] complete s4u::Storage interface, what a mess... not all storages are put in the static storages_ map --- include/simgrid/msg.h | 1 - include/simgrid/s4u/storage.hpp | 34 +++++++--------- include/simgrid/simix.h | 2 - src/msg/msg_io.cpp | 4 +- src/s4u/s4u_file.cpp | 2 +- src/s4u/s4u_storage.cpp | 40 +++++++++++++++---- src/simix/smx_io.cpp | 8 ---- src/surf/HostImpl.cpp | 1 - .../storage_client_server.cpp | 29 ++++++-------- .../storage_client_server.tesh | 2 + 10 files changed, 66 insertions(+), 57 deletions(-) diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 9e22c1ae8d..5853a9c516 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -226,7 +226,6 @@ XBT_PUBLIC(msg_error_t) MSG_storage_set_data(msg_storage_t host, void *data); XBT_PUBLIC(void *) MSG_storage_get_data(msg_storage_t storage); XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage); XBT_PUBLIC(sg_size_t) MSG_storage_get_size(msg_storage_t storage); -XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname); XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage); /************************** Host handling ***********************************/ diff --git a/include/simgrid/s4u/storage.hpp b/include/simgrid/s4u/storage.hpp index faba7d8e94..79f6ac522e 100644 --- a/include/simgrid/s4u/storage.hpp +++ b/include/simgrid/s4u/storage.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2015. The SimGrid Team. +/* Copyright (c) 2006-2015, 2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,15 +7,13 @@ #ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_ #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_ +#include +#include +#include #include - -#include - +#include #include -#include -#include - namespace simgrid { namespace s4u { @@ -23,27 +21,24 @@ XBT_PUBLIC_CLASS Storage { friend s4u::Engine; Storage(std::string name, smx_storage_t inferior); - virtual ~Storage(); public: + Storage() = default; + virtual ~Storage(); /** Retrieve a Storage by its name. It must exist in the platform file */ static Storage &byName(const char* name); const char *name(); + const char* host(); sg_size_t sizeFree(); sg_size_t sizeUsed(); /** Retrieve the total amount of space of this storage element */ sg_size_t size(); xbt_dict_t properties(); + const char* property(const char* key); + void setProperty(const char* key, char* value); std::map* content(); + std::unordered_map* allStorages(); - /* TODO: missing API: -XBT_PUBLIC(void) MSG_storage_set_property_value(msg_storage_t storage, const char *name, char *value,void_f_pvoid_t free_ctn); -XBT_PUBLIC(const char *)MSG_storage_get_property_value(msg_storage_t storage, const char *name); -XBT_PUBLIC(xbt_dynar_t) MSG_storages_as_dynar(void); -XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage); -XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname); -XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage); - */ protected: smx_storage_t inferior(); @@ -52,12 +47,13 @@ public: void *userdata() {return userdata_;} private: - static boost::unordered_map *storages_; + static std::unordered_map* storages_; + std::string hostname_; std::string name_; - sg_size_t size_; + sg_size_t size_ = 0; smx_storage_t pimpl_ = nullptr; - void *userdata_ = nullptr; + void* userdata_ = nullptr; }; } /* namespace s4u */ diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index d2d368a17f..506b318b72 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -374,8 +374,6 @@ XBT_PUBLIC(xbt_dict_t) simcall_storage_get_properties(smx_storage_t storage); XBT_PUBLIC(void*) SIMIX_storage_get_data(smx_storage_t storage); XBT_PUBLIC(void) SIMIX_storage_set_data(smx_storage_t storage, void *data); XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_storage_t storage); -XBT_PUBLIC(sg_size_t) SIMIX_storage_get_size(smx_storage_t storage); -XBT_PUBLIC(const char*) SIMIX_storage_get_host(smx_storage_t storage); /************************** MC simcalls **********************************/ XBT_PUBLIC(int) simcall_mc_random(int min, int max); diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index 3341faf194..a013379644 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -447,8 +447,8 @@ msg_storage_t __MSG_storage_create(smx_storage_t storage) msg_storage_priv_t storage_private = xbt_new0(s_msg_storage_priv_t, 1); storage_private->name = SIMIX_storage_get_name(storage); - storage_private->hostname = SIMIX_storage_get_host(storage); - storage_private->size = SIMIX_storage_get_size(storage); + storage_private->hostname = surf_storage_get_host(storage); + storage_private->size = surf_storage_get_size(storage); xbt_lib_set(storage_lib, storage_private->name, MSG_STORAGE_LEVEL, storage_private); return xbt_lib_get_elm_or_null(storage_lib, storage_private->name); diff --git a/src/s4u/s4u_file.cpp b/src/s4u/s4u_file.cpp index e6fe865dc0..bb87435f54 100644 --- a/src/s4u/s4u_file.cpp +++ b/src/s4u/s4u_file.cpp @@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files"); namespace simgrid { namespace s4u { -File::File(const char* fullpath, void* userdata) : path_(fullpath) +File::File(const char* fullpath, void* userdata) : path_(fullpath), userdata_(userdata) { // this cannot fail because we get a xbt_die if the mountpoint does not exist pimpl_ = simcall_file_open(fullpath, Host::current()); diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 48c58d71da..e816d0d286 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2015. The SimGrid Team. +/* Copyright (c) 2006-2015, 2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,28 +7,34 @@ #include "simgrid/s4u/storage.hpp" #include "simgrid/simix.hpp" #include "src/surf/storage_interface.hpp" - #include "xbt/lib.h" +#include + extern xbt_lib_t storage_lib; namespace simgrid { namespace s4u { -boost::unordered_map *Storage::storages_ = new boost::unordered_map (); +std::unordered_map* Storage::storages_ = new std::unordered_map(); + Storage::Storage(std::string name, smx_storage_t inferior) : name_(name), pimpl_(inferior) { - size_ = SIMIX_storage_get_size(pimpl_); + hostname_ = surf_storage_get_host(pimpl_); + size_ = surf_storage_get_size(pimpl_); storages_->insert({name, this}); } Storage::~Storage() = default; -smx_storage_t Storage::inferior() { +smx_storage_t Storage::inferior() +{ return pimpl_; } -Storage &Storage::byName(const char*name) { - s4u::Storage *res = nullptr; + +Storage& Storage::byName(const char* name) +{ + s4u::Storage* res = nullptr; try { res = storages_->at(name); } catch (std::out_of_range& e) { @@ -46,6 +52,11 @@ const char* Storage::name() return name_.c_str(); } +const char* Storage::host() +{ + return hostname_.c_str(); +} + sg_size_t Storage::sizeFree() { return simcall_storage_get_free_size(pimpl_); @@ -65,11 +76,26 @@ xbt_dict_t Storage::properties() return simcall_storage_get_properties(pimpl_); } +const char* Storage::property(const char* key) +{ + return static_cast(xbt_dict_get_or_null(this->properties(), key)); +} + +void Storage::setProperty(const char* key, char* value) +{ + xbt_dict_set(this->properties(), key, value, nullptr); +} + std::map* Storage::content() { return simgrid::simix::kernelImmediate( [this] { return static_cast(surf_storage_resource_priv(this->pimpl_))->getContent(); }); } +std::unordered_map* Storage::allStorages() +{ + return storages_; +} + } /* namespace s4u */ } /* namespace simgrid */ diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index fc2dbd1a02..fda05d8e5f 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -212,10 +212,6 @@ int SIMIX_file_move(smx_actor_t process, smx_file_t file, const char* fullpath) return surf_host_file_move(host, file->surf_file, fullpath); } -sg_size_t SIMIX_storage_get_size(smx_storage_t storage){ - return surf_storage_get_size(storage); -} - sg_size_t simcall_HANDLER_storage_get_free_size(smx_simcall_t simcall, smx_storage_t storage) { return SIMIX_storage_get_free_size(simcall->issuer, storage); @@ -244,10 +240,6 @@ const char* SIMIX_storage_get_name(smx_storage_t storage){ return sg_storage_name(storage); } -const char* SIMIX_storage_get_host(smx_storage_t storage){ - return surf_storage_get_host(storage); -} - void SIMIX_io_destroy(smx_activity_t synchro) { simgrid::kernel::activity::Io *io = static_cast(synchro); diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 9e5602fd0c..85a859b018 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -161,7 +161,6 @@ void HostImpl::getAttachedStorageList(std::vector* storages) Action* HostImpl::open(const char* fullpath) { - simgrid::surf::Storage* st = nullptr; size_t longest_prefix_length = 0; std::string path; diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index 6e7abbae31..73aa75a651 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -92,21 +92,18 @@ static void get_set_storage_data(const char* storage_name) xbt_free(data); } -// static void dump_platform_storages(void){ -// unsigned int cursor; -// xbt_dynar_t storages = MSG_storages_as_dynar(); -// msg_storage_t storage; -// xbt_dynar_foreach(storages, cursor, storage){ -// XBT_INFO("Storage %s is attached to %s", MSG_storage_get_name(storage), MSG_storage_get_host(storage)); -// MSG_storage_set_property_value(storage, "other usage", xbt_strdup("gpfs")); -// } -// xbt_dynar_free(&storages); -// Expected output in tesh file -//> [ 1.207952] (server@alice) Storage Disk1 is attached to bob -//> [ 1.207952] (server@alice) Storage Disk2 is attached to alice -//> [ 1.207952] (server@alice) Storage Disk3 is attached to carl -//> [ 1.207952] (server@alice) Storage Disk4 is attached to denise -//} +static void dump_platform_storages(void) +{ + std::unordered_map* storages = simgrid::s4u::Storage().allStorages(); + + for (auto storage : *storages) { + XBT_INFO("Storage %s is attached to %s", storage.first.c_str(), storage.second->host()); + storage.second->setProperty("other usage", xbt_strdup("gpfs")); + } + // Expected output in tesh file that's missing for now + //> [ 1.207952] (server@alice) Storage Disk3 is attached to carl + //> [ 1.207952] (server@alice) Storage Disk4 is attached to denise +} static void storage_info(simgrid::s4u::Host* host) { @@ -165,7 +162,7 @@ static void server() } storage_info(simgrid::s4u::this_actor::host()); - // dump_platform_storages(); + dump_platform_storages(); } int main(int argc, char* argv[]) diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.tesh b/teshsuite/s4u/storage_client_server/storage_client_server.tesh index 15bd867976..ee942ed592 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.tesh +++ b/teshsuite/s4u/storage_client_server/storage_client_server.tesh @@ -101,4 +101,6 @@ $ ./storage_client_server$EXEEXT ${srcdir:=.}/../../../examples/platforms/storag > [ 1.207952] (server@alice) \Windows\win.ini size: 92 bytes > [ 1.207952] (server@alice) \Windows\winhlp32.exe size: 10752 bytes > [ 1.207952] (server@alice) \Windows\write.exe size: 10752 bytes +> [ 1.207952] (server@alice) Storage Disk1 is attached to bob +> [ 1.207952] (server@alice) Storage Disk2 is attached to alice > [ 1.207952] (maestro@) Simulated time: 1.20795 -- 2.20.1