From 6a6935148284f51d20bceed365ed0edea8b5a70e Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 19 Jun 2017 10:26:18 +0200 Subject: [PATCH] massive cleanups in the storage world. Next step will be to improve the file management --- examples/msg/io-storage/io-storage.c | 4 +- examples/s4u/io/s4u_io.cpp | 20 ++-- examples/s4u/io/s4u_io.tesh | 4 +- include/simgrid/msg.h | 1 - include/simgrid/s4u/File.hpp | 17 ++-- include/simgrid/s4u/Host.hpp | 9 +- include/simgrid/s4u/Storage.hpp | 13 ++- include/simgrid/simix.h | 3 +- src/include/surf/surf.h | 3 - src/msg/msg_host.cpp | 17 +--- src/msg/msg_io.cpp | 98 +++++++++---------- src/s4u/s4u_file.cpp | 86 +++++++++++----- src/s4u/s4u_host.cpp | 55 ++++------- src/s4u/s4u_storage.cpp | 14 ++- src/simgrid/host.cpp | 11 ++- src/simix/libsmx.cpp | 13 +-- src/simix/popping_accessors.h | 60 +++++------- src/simix/popping_bodies.cpp | 14 +-- src/simix/popping_enum.h | 1 - src/simix/popping_generated.cpp | 12 +-- src/simix/simcalls.in | 3 +- src/simix/smx_io.cpp | 28 ++---- src/simix/smx_io_private.h | 3 +- src/surf/HostImpl.cpp | 71 ++------------ src/surf/HostImpl.hpp | 25 ----- src/surf/StorageImpl.cpp | 19 ++-- src/surf/StorageImpl.hpp | 27 ++--- src/surf/storage_n11.cpp | 24 ++--- src/surf/surf_c_bindings.cpp | 10 +- .../storage_client_server.cpp | 22 ++--- .../storage_client_server.tesh | 2 +- 31 files changed, 285 insertions(+), 404 deletions(-) diff --git a/examples/msg/io-storage/io-storage.c b/examples/msg/io-storage/io-storage.c index a4c8b338ea..e4075c12e4 100644 --- a/examples/msg/io-storage/io-storage.c +++ b/examples/msg/io-storage/io-storage.c @@ -100,11 +100,11 @@ static int host(int argc, char *argv[]){ char* mountname; xbt_dict_t content; char* path; - sg_size_t *size; + sg_size_t size; xbt_dict_foreach(contents, curs, mountname, content){ XBT_INFO("Print the content of mount point: %s",mountname); xbt_dict_foreach(content,curs2,path,size){ - XBT_INFO("%s size: %llu bytes", path,*((sg_size_t*)size)); + XBT_INFO("%s size: %llu bytes", path, (sg_size_t)size); } xbt_dict_free(&content); } diff --git a/examples/s4u/io/s4u_io.cpp b/examples/s4u/io/s4u_io.cpp index 90126b62a4..d9cd197265 100644 --- a/examples/s4u/io/s4u_io.cpp +++ b/examples/s4u/io/s4u_io.cpp @@ -11,27 +11,27 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category"); class MyHost { public: - - void show_info(boost::unordered_map const&mounts) { + void show_info(std::unordered_map const& mounts) + { XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->cname()); for (const auto&kv : mounts) { const char* mountpoint = kv.first.c_str(); - simgrid::s4u::Storage storage = *kv.second; + simgrid::s4u::Storage* storage = kv.second; // Retrieve disk's information - sg_size_t free_size = storage.sizeFree(); - sg_size_t used_size = storage.sizeUsed(); - sg_size_t size = storage.size(); + sg_size_t free_size = storage->sizeFree(); + sg_size_t used_size = storage->sizeUsed(); + sg_size_t size = storage->size(); - XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", - storage.name(), mountpoint, used_size, free_size, size); + XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", storage->name(), mountpoint, used_size, free_size, + size); } } void operator()() { - boost::unordered_map const& mounts = - simgrid::s4u::Host::current()->mountedStorages(); + std::unordered_map const& mounts = + simgrid::s4u::Host::current()->mountedStorages(); show_info(mounts); diff --git a/examples/s4u/io/s4u_io.tesh b/examples/s4u/io/s4u_io.tesh index 0a17043aa8..84a8d27291 100644 --- a/examples/s4u/io/s4u_io.tesh +++ b/examples/s4u/io/s4u_io.tesh @@ -2,12 +2,12 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u_io > [denise:host:(0) 0.000000] [s4u_test/INFO] Storage info on denise: -> [denise:host:(0) 0.000000] [s4u_test/INFO] Disk4 (/home) Used: 13221994; Free: 536857690006; Total: 536870912000. > [denise:host:(0) 0.000000] [s4u_test/INFO] Disk2 (c:) Used: 2391537133; Free: 534479374867; Total: 536870912000. +> [denise:host:(0) 0.000000] [s4u_test/INFO] Disk4 (/home) Used: 13221994; Free: 536857690006; Total: 536870912000. > [denise:host:(0) 0.003333] [s4u_test/INFO] Create a 200000 bytes file named '/home/tmp/data.txt' on /sd1 > [denise:host:(0) 0.003333] [s4u_test/INFO] Storage info on denise: -> [denise:host:(0) 0.003333] [s4u_test/INFO] Disk4 (/home) Used: 13421994; Free: 536857490006; Total: 536870912000. > [denise:host:(0) 0.003333] [s4u_test/INFO] Disk2 (c:) Used: 2391537133; Free: 534479374867; Total: 536870912000. +> [denise:host:(0) 0.003333] [s4u_test/INFO] Disk4 (/home) Used: 13421994; Free: 536857490006; Total: 536870912000. > [denise:host:(0) 0.004333] [s4u_test/INFO] Read 200000 bytes on /home/tmp/data.txt > [denise:host:(0) 0.006000] [s4u_test/INFO] Write 100000 bytes on /home/tmp/data.txt > [denise:host:(0) 0.006000] [s4u_test/INFO] Move '/home/tmp/data.txt' to '/home/tmp/simgrid.readme' diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 427b2327ba..6eb90dde8d 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -209,7 +209,6 @@ XBT_PUBLIC(void) MSG_file_dump(msg_file_t fd); XBT_PUBLIC(msg_error_t) MSG_file_unlink(msg_file_t fd); XBT_PUBLIC(msg_error_t) MSG_file_seek(msg_file_t fd, sg_offset_t offset, int origin); XBT_PUBLIC(sg_size_t) MSG_file_tell (msg_file_t fd); -XBT_PUBLIC(void) __MSG_file_get_info(msg_file_t fd); XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file); XBT_PUBLIC(msg_error_t) MSG_file_move(msg_file_t fd, const char* fullpath); XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath); diff --git a/include/simgrid/s4u/File.hpp b/include/simgrid/s4u/File.hpp index e4556c578f..bcc90277aa 100644 --- a/include/simgrid/s4u/File.hpp +++ b/include/simgrid/s4u/File.hpp @@ -25,6 +25,7 @@ XBT_PUBLIC_CLASS File { public: File(const char* fullpath, void* userdata); + File(const char* fullpath, sg_host_t host, void* userdata); ~File(); /** Retrieves the path to the file */ @@ -36,12 +37,10 @@ public: * Any storage is considered as local, and no network communication ever occur. */ sg_size_t read(sg_size_t size); - /** Simulates a write action. Returns the size of data actually written. - * - * FIXME: reading from a remotely mounted disk is not implemented yet. - * Any storage is considered as local, and no network communication ever occur. - */ + + /** Simulates a write action. Returns the size of data actually written. */ sg_size_t write(sg_size_t size); + sg_size_t write(sg_size_t size, sg_host_t host); /** Allows to store user data on that host */ void setUserdata(void* data) { userdata_ = data; } @@ -63,18 +62,20 @@ public: /** Remove a file from disk */ void unlink(); + void unlink(sg_host_t host); /* FIXME: add these to the S4U API: XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file); XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath); XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath); */ - char* storage_type; - char* storageId; - char* mount_point; + const char* storage_type; + const char* storageId; + std::string mount_point; int desc_id = 0; private: + sg_host_t host_ = nullptr; smx_file_t pimpl_ = nullptr; const char* path_ = nullptr; void* userdata_ = nullptr; diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 6f9d6ce59e..31ecd57f3e 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -7,8 +7,7 @@ #define SIMGRID_S4U_HOST_HPP #include - -#include +#include #include "xbt/Extendable.hpp" #include "xbt/dict.h" @@ -95,21 +94,20 @@ public: int pstatesCount() const; void setPstate(int pstate_index); int pstate(); - xbt_dict_t mountedStoragesAsDict(); // HACK void attachedStorages(std::vector * storages); /** Get an associative list [mount point]->[Storage] of all local mount points. * * This is defined in the platform file, and cannot be modified programatically (yet). */ - boost::unordered_map const& mountedStorages(); + std::unordered_map const& mountedStorages(); void routeTo(Host * dest, std::vector * links, double* latency); void routeTo(Host * dest, std::vector * links, double* latency); private: simgrid::xbt::string name_ = "noname"; - boost::unordered_map* mounts = nullptr; // caching + std::unordered_map* mounts = nullptr; // caching public: // TODO, this could be a unique_ptr @@ -148,6 +146,5 @@ public class Host { */ public native int getLoad(); - } #endif diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 3c11ee8b0e..f366c3a982 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -30,17 +30,18 @@ public: /** 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(); + const char* type(); + Host* 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::map* content(); -public: void setUserdata(void* data) { userdata_ = data; } void* userdata() { return userdata_; } @@ -51,10 +52,12 @@ public: /** @brief Callback signal fired when a Link is destroyed */ static simgrid::xbt::signal onDestruction; + Host* attached_to_ = nullptr; + surf::StorageImpl* const pimpl_ = nullptr; + private: std::string name_; - surf::StorageImpl* const pimpl_ = nullptr; - void* userdata_ = nullptr; + void* userdata_ = nullptr; }; } /* namespace s4u */ diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 2e98432974..6c74149d4a 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -353,11 +353,10 @@ XBT_PUBLIC(void *) simcall_file_get_data(smx_file_t fd); XBT_PUBLIC(void) simcall_file_set_data(smx_file_t fd, void *data); XBT_PUBLIC(sg_size_t) simcall_file_read(smx_file_t fd, sg_size_t size, sg_host_t host); XBT_PUBLIC(sg_size_t) simcall_file_write(smx_file_t fd, sg_size_t size, sg_host_t host); -XBT_PUBLIC(smx_file_t) simcall_file_open(const char* fullpath, sg_host_t host); +XBT_PUBLIC(smx_file_t) simcall_file_open(const char* mount, const char* path, sg_storage_t st); XBT_PUBLIC(int) simcall_file_close(smx_file_t fd, sg_host_t host); XBT_PUBLIC(int) simcall_file_unlink(smx_file_t fd, sg_host_t host); XBT_PUBLIC(sg_size_t) simcall_file_get_size(smx_file_t fd); -XBT_PUBLIC(xbt_dynar_t) simcall_file_get_info(smx_file_t fd); XBT_PUBLIC(sg_size_t) simcall_file_tell(smx_file_t fd); XBT_PUBLIC(int) simcall_file_seek(smx_file_t fd, sg_offset_t offset, int origin); XBT_PUBLIC(int) simcall_file_move(smx_file_t fd, const char* fullpath); diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 0d0ced1f14..22b5e44107 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -138,9 +138,6 @@ XBT_PUBLIC(surf_action_t) surf_model_extract_failed_action_set(surf_model_t mode */ XBT_PUBLIC(int) surf_model_running_action_set_size(surf_model_t model); -/** @brief Create a file opening action on the given host */ -XBT_PUBLIC(surf_action_t) surf_host_open(sg_host_t host, const char* fullpath); - /** @brief Create a file closing action on the given host */ XBT_PUBLIC(surf_action_t) surf_host_close(sg_host_t host, surf_file_t fd); diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index f8e8cd7ecd..6c7c2fe93f 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -240,8 +240,7 @@ int MSG_host_get_nb_pstates(msg_host_t host) { */ xbt_dict_t MSG_host_get_mounted_storage_list(msg_host_t host) { - xbt_assert((host != nullptr), "Invalid parameters"); - return host->mountedStoragesAsDict(); + return sg_host_get_mounted_storage_list(host); } /** \ingroup m_host_management @@ -263,19 +262,9 @@ xbt_dict_t MSG_host_get_storage_content(msg_host_t host) { xbt_assert((host != nullptr), "Invalid parameters"); xbt_dict_t contents = xbt_dict_new_homogeneous(nullptr); - msg_storage_t storage; - char* storage_name; - char* mount_name; - xbt_dict_cursor_t cursor = nullptr; - - xbt_dict_t storage_list = host->mountedStoragesAsDict(); + for (auto elm : host->mountedStorages()) + xbt_dict_set(contents, elm.first.c_str(), MSG_storage_get_content(elm.second), nullptr); - xbt_dict_foreach(storage_list,cursor,mount_name,storage_name){ - storage = simgrid::s4u::Storage::byName(storage_name); - xbt_dict_t content = MSG_storage_get_content(storage); - xbt_dict_set(contents,mount_name, content,nullptr); - } - xbt_dict_free(&storage_list); return contents; } diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index eeb421e424..7aa6b09209 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -3,7 +3,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "../surf/StorageImpl.hpp" #include "simgrid/s4u/File.hpp" #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" @@ -56,7 +55,7 @@ msg_error_t MSG_file_set_data(msg_file_t fd, void *data) * * This functions checks whether \a file is a valid pointer and return the user data associated to \a file if possible. */ -void *MSG_file_get_data(msg_file_t fd) +void* MSG_file_get_data(msg_file_t fd) { return fd->userdata(); } @@ -74,7 +73,7 @@ void MSG_file_dump (msg_file_t fd){ "\t\tStorage Id: '%s'\n" "\t\tStorage Type: '%s'\n" "\t\tFile Descriptor Id: %d", - fd->path(), fd->size(), fd->mount_point, fd->storageId, fd->storage_type, fd->desc_id); + fd->path(), fd->size(), fd->mount_point.c_str(), fd->storageId, fd->storage_type, fd->desc_id); } /** \ingroup msg_file @@ -93,7 +92,7 @@ sg_size_t MSG_file_read(msg_file_t fd, sg_size_t size) /* Find the host where the file is physically located and read it */ msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId); - msg_host_t attached_host = MSG_host_by_name(storage_src->host()); + msg_host_t attached_host = storage_src->host(); read_size = fd->read(size); // TODO re-add attached_host; if (strcmp(attached_host->cname(), MSG_host_self()->cname())) { @@ -134,7 +133,7 @@ sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) /* Find the host where the file is physically located (remote or local)*/ msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId); - msg_host_t attached_host = MSG_host_by_name(storage_src->host()); + msg_host_t attached_host = storage_src->host(); if (strcmp(attached_host->cname(), MSG_host_self()->cname())) { /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ @@ -187,6 +186,7 @@ msg_file_t MSG_file_open(const char* fullpath, void* data) */ int MSG_file_close(msg_file_t fd) { + MSG_host_release_file_descriptor_id(MSG_host_self(), fd->desc_id); delete fd; return MSG_OK; @@ -201,9 +201,9 @@ int MSG_file_close(msg_file_t fd) msg_error_t MSG_file_unlink(msg_file_t fd) { /* Find the host where the file is physically located (remote or local)*/ - // msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId); - // msg_host_t attached_host = MSG_host_by_name(storage_src->host()); - fd->unlink(); // simcall_file_unlink(fd->simdata->smx_file, attached_host); + msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId); + msg_host_t attached_host = storage_src->host(); + fd->unlink(attached_host); return MSG_OK; } @@ -213,7 +213,8 @@ msg_error_t MSG_file_unlink(msg_file_t fd) * \param fd is the file descriptor (#msg_file_t) * \return the size of the file (as a #sg_size_t) */ -sg_size_t MSG_file_get_size(msg_file_t fd){ +sg_size_t MSG_file_get_size(msg_file_t fd) +{ return fd->size(); } @@ -276,65 +277,56 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa { /* Find the host where the file is physically located and read it */ msg_storage_t storage_src = simgrid::s4u::Storage::byName(file->storageId); - msg_host_t attached_host = MSG_host_by_name(storage_src->host()); + msg_host_t src_host = storage_src->host(); MSG_file_seek(file, 0, SEEK_SET); sg_size_t read_size = file->read(file->size()); - /* Find the real host destination where the file will be physically stored */ - xbt_dict_cursor_t cursor = nullptr; + /* Find the host that owns the storage where the file has to be copied */ msg_storage_t storage_dest = nullptr; - msg_host_t host_dest; + msg_host_t dst_host; size_t longest_prefix_length = 0; - xbt_dict_t storage_list = host->mountedStoragesAsDict(); - char *mount_name; - char *storage_name; - xbt_dict_foreach(storage_list,cursor,mount_name,storage_name){ - char* file_mount_name = static_cast(xbt_malloc(strlen(mount_name) + 1)); - strncpy(file_mount_name, fullpath, strlen(mount_name) + 1); - file_mount_name[strlen(mount_name)] = '\0'; - - if (not strcmp(file_mount_name, mount_name) && strlen(mount_name) > longest_prefix_length) { + for (auto elm : host->mountedStorages()) { + std::string mount_point = std::string(fullpath).substr(0, elm.first.size()); + if (mount_point == elm.first && elm.first.length() > longest_prefix_length) { /* The current mount name is found in the full path and is bigger than the previous*/ - longest_prefix_length = strlen(mount_name); - storage_dest = simgrid::s4u::Storage::byName(storage_name); + longest_prefix_length = elm.first.length(); + storage_dest = elm.second; } - xbt_free(file_mount_name); } - xbt_dict_free(&storage_list); - if(longest_prefix_length>0){ + if (longest_prefix_length > 0) { /* Mount point found, retrieve the host the storage is attached to */ - host_dest = MSG_host_by_name(storage_dest->host()); + dst_host = storage_dest->host(); }else{ XBT_WARN("Can't find mount point for '%s' on destination host '%s'", fullpath, host->cname()); return MSG_TASK_CANCELED; } - XBT_DEBUG("Initiate data transfer of %llu bytes between %s and %s.", read_size, attached_host->cname(), - storage_dest->host()); - msg_host_t m_host_list[] = {attached_host, host_dest}; + XBT_DEBUG("Initiate data transfer of %llu bytes between %s and %s.", read_size, src_host->cname(), + storage_dest->host()->cname()); + msg_host_t m_host_list[] = {src_host, dst_host}; double flops_amount[] = {0, 0}; double bytes_amount[] = {0, static_cast(read_size), 0, 0}; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, nullptr); - msg_error_t transfer = MSG_parallel_task_execute(task); + msg_error_t err = MSG_parallel_task_execute(task); MSG_task_destroy(task); - if(transfer != MSG_OK){ - if (transfer == MSG_HOST_FAILURE) - XBT_WARN("Transfer error, %s remote host just turned off!", storage_dest->host()); - if (transfer == MSG_TASK_CANCELED) + if (err != MSG_OK) { + if (err == MSG_HOST_FAILURE) + XBT_WARN("Transfer error, %s remote host just turned off!", storage_dest->host()->cname()); + if (err == MSG_TASK_CANCELED) XBT_WARN("Transfer error, task has been canceled!"); - return transfer; + return err; } /* Create file on remote host, write it and close it */ - smx_file_t smx_file = simcall_file_open(fullpath, host_dest); - simcall_file_write(smx_file, read_size, host_dest); - simcall_file_close(smx_file, host_dest); + msg_file_t fd = new simgrid::s4u::File(fullpath, dst_host, nullptr); + fd->write(read_size, dst_host); + delete fd; return MSG_OK; } @@ -364,7 +356,8 @@ msg_error_t MSG_file_rmove (msg_file_t file, msg_host_t host, const char* fullpa * * This functions checks whether a storage is a valid pointer or not and return its name. */ -const char *MSG_storage_get_name(msg_storage_t storage) { +const char* MSG_storage_get_name(msg_storage_t storage) +{ xbt_assert((storage != nullptr), "Invalid parameters"); return storage->name(); } @@ -374,7 +367,8 @@ const char *MSG_storage_get_name(msg_storage_t storage) { * \param storage a storage * \return the free space size of the storage element (as a #sg_size_t) */ -sg_size_t MSG_storage_get_free_size(msg_storage_t storage){ +sg_size_t MSG_storage_get_free_size(msg_storage_t storage) +{ return storage->sizeFree(); } @@ -383,7 +377,8 @@ sg_size_t MSG_storage_get_free_size(msg_storage_t storage){ * \param storage a storage * \return the used space size of the storage element (as a #sg_size_t) */ -sg_size_t MSG_storage_get_used_size(msg_storage_t storage){ +sg_size_t MSG_storage_get_used_size(msg_storage_t storage) +{ return storage->sizeUsed(); } @@ -435,11 +430,13 @@ msg_storage_t MSG_storage_get_by_name(const char *name) /** \ingroup msg_storage_management * \brief Returns a dynar containing all the storage elements declared at a given point of time */ -xbt_dynar_t MSG_storages_as_dynar() { +xbt_dynar_t MSG_storages_as_dynar() +{ + std::map* storage_map = simgrid::s4u::allStorages(); xbt_dynar_t res = xbt_dynar_new(sizeof(msg_storage_t),nullptr); - for (auto s : *simgrid::s4u::allStorages()) { + for (auto s : *storage_map) xbt_dynar_push(res, &(s.second)); - } + delete storage_map; return res; } @@ -474,11 +471,11 @@ void *MSG_storage_get_data(msg_storage_t storage) */ xbt_dict_t MSG_storage_get_content(msg_storage_t storage) { - std::map* content = storage->content(); + std::map* content = storage->content(); xbt_dict_t content_dict = xbt_dict_new_homogeneous(nullptr); for (auto entry : *content) { - xbt_dict_set(content_dict, entry.first.c_str(), entry.second, nullptr); + xbt_dict_set(content_dict, entry.first.c_str(), (void*)entry.second, nullptr); } return content_dict; } @@ -500,9 +497,10 @@ sg_size_t MSG_storage_get_size(msg_storage_t storage) * * This functions checks whether a storage is a valid pointer or not and return its name. */ -const char *MSG_storage_get_host(msg_storage_t storage) { +const char* MSG_storage_get_host(msg_storage_t storage) +{ xbt_assert((storage != nullptr), "Invalid parameters"); - return storage->host(); + return storage->host()->cname(); } SG_END_DECL() diff --git a/src/s4u/s4u_file.cpp b/src/s4u/s4u_file.cpp index 0f26d5903c..ec8cd7cd48 100644 --- a/src/s4u/s4u_file.cpp +++ b/src/s4u/s4u_file.cpp @@ -3,60 +3,98 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/simix.h" -#include "src/msg/msg_private.h" #include "xbt/log.h" -#include "simgrid/s4u/Actor.hpp" -#include "simgrid/s4u/Comm.hpp" #include "simgrid/s4u/File.hpp" #include "simgrid/s4u/Host.hpp" -#include "simgrid/s4u/Mailbox.hpp" #include "simgrid/s4u/Storage.hpp" +#include "src/surf/HostImpl.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files"); namespace simgrid { namespace s4u { -File::File(const char* fullpath, void* userdata) : path_(fullpath), userdata_(userdata) +File::File(const char* fullpath, void* userdata) : File(fullpath, Host::current(), userdata){}; + +File::File(const char* fullpath, sg_host_t host, 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()); - xbt_dynar_t info = simcall_file_get_info(pimpl_); - storage_type = xbt_dynar_pop_as(info, char*); - storageId = xbt_dynar_pop_as(info, char*); - mount_point = xbt_dynar_pop_as(info, char*); - xbt_dynar_free(&info); + Storage* st = nullptr; + size_t longest_prefix_length = 0; + std::string path; + XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath, host->cname()); + + for (auto mnt : host->mountedStorages()) { + XBT_DEBUG("See '%s'", mnt.first.c_str()); + mount_point = std::string(fullpath).substr(0, mnt.first.size()); + + if (mount_point == mnt.first && mnt.first.length() > longest_prefix_length) { + /* The current mount name is found in the full path and is bigger than the previous*/ + longest_prefix_length = mnt.first.length(); + st = mnt.second; + } + } + if (longest_prefix_length > 0) { /* Mount point found, split fullpath into mount_name and path+filename*/ + mount_point = std::string(fullpath).substr(0, longest_prefix_length); + path = std::string(fullpath).substr(longest_prefix_length, strlen(fullpath)); + } else + xbt_die("Can't find mount point for '%s' on '%s'", fullpath, host->cname()); + + pimpl_ = simcall_file_open(mount_point.c_str(), path.c_str(), st); + host_ = host; + storage_type = st->type(); + storageId = st->name(); } -File::~File() { - // Host::current()->extension()->file_descriptor_table->push_back(desc_id_); - simcall_file_close(pimpl_, Host::current()); +File::~File() +{ + simcall_file_close(pimpl_, host_); } -sg_size_t File::read(sg_size_t size) { +sg_size_t File::read(sg_size_t size) +{ return simcall_file_read(pimpl_, size, Host::current()); } -sg_size_t File::write(sg_size_t size) { + +sg_size_t File::write(sg_size_t size) +{ return simcall_file_write(pimpl_,size, Host::current()); } -sg_size_t File::size() { + +sg_size_t File::write(sg_size_t size, sg_host_t host) +{ + return simcall_file_write(pimpl_, size, host); +} + +sg_size_t File::size() +{ return simcall_file_get_size(pimpl_); } -void File::seek(sg_size_t pos) { +void File::seek(sg_size_t pos) +{ simcall_file_seek(pimpl_,pos,SEEK_SET); } -sg_size_t File::tell() { + +sg_size_t File::tell() +{ return simcall_file_tell(pimpl_); } -void File::move(const char*fullpath) { + +void File::move(const char* fullpath) +{ simcall_file_move(pimpl_,fullpath); } -void File::unlink() { - sg_host_t attached = Host::current(); // FIXME: we should check where this file is attached - simcall_file_unlink(pimpl_,attached); + +void File::unlink() +{ + simcall_file_unlink(pimpl_, Host::current()); +} + +void File::unlink(sg_host_t host) +{ + simcall_file_unlink(pimpl_, host); } }} // namespace simgrid::s4u diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 8ee524a1b7..b131fe6085 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -160,6 +160,7 @@ void Host::routeTo(Host* dest, std::vector* links, double* latency) for (surf::LinkImpl* l : linkImpls) links->push_back(&l->piface_); } + /** @brief Just like Host::routeTo, but filling an array of link implementations */ void Host::routeTo(Host* dest, std::vector* links, double* latency) { @@ -172,24 +173,6 @@ void Host::routeTo(Host* dest, std::vector* links, double* late } } -boost::unordered_map const& Host::mountedStorages() { - if (mounts == nullptr) { - mounts = new boost::unordered_map (); - - xbt_dict_t dict = this->mountedStoragesAsDict(); - - xbt_dict_cursor_t cursor; - char *mountname; - char *storagename; - xbt_dict_foreach(dict, cursor, mountname, storagename) { - mounts->insert({mountname, Storage::byName(storagename)}); - } - xbt_dict_free(&dict); - } - - return *mounts; -} - /** Get the properties assigned to a host */ xbt_dict_t Host::properties() { return simgrid::simix::kernelImmediate([this] { @@ -198,13 +181,14 @@ xbt_dict_t Host::properties() { } /** Retrieve the property value (or nullptr if not set) */ -const char*Host::property(const char*key) { +const char* Host::property(const char* key) +{ return this->pimpl_->getProperty(key); } -void Host::setProperty(const char*key, const char *value){ - simgrid::simix::kernelImmediate([this, key, value] { - this->pimpl_->setProperty(key, value); - }); + +void Host::setProperty(const char* key, const char* value) +{ + simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); } /** Get the processes attached to the host */ @@ -247,22 +231,10 @@ int Host::pstate() return this->pimpl_cpu->getPState(); } -/** - * \ingroup simix_storage_management - * \brief Returns the list of storages mounted on an host. - * \return a dict containing all storages mounted on the host - */ -xbt_dict_t Host::mountedStoragesAsDict() -{ - return simgrid::simix::kernelImmediate([this] { - return this->pimpl_->getMountedStorageList(); - }); -} - /** * \ingroup simix_storage_management * \brief Returns the list of storages attached to an host. - * \return a dict containing all storages attached to the host + * \return a vector containing all storages attached to the host */ void Host::attachedStorages(std::vector* storages) { @@ -271,5 +243,16 @@ void Host::attachedStorages(std::vector* storages) }); } +std::unordered_map const& Host::mountedStorages() +{ + if (mounts == nullptr) { + mounts = new std::unordered_map(); + for (auto m : this->pimpl_->storage_) { + mounts->insert({m.first, &m.second->piface_}); + } + } + return *mounts; +} + } // namespace simgrid } // namespace s4u diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 23c7e603f3..b1112a2c76 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -4,12 +4,15 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "../surf/StorageImpl.hpp" +#include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" #include namespace simgrid { namespace s4u { + +// attached_to_ = Host::by_name_or_null(pimpl->attach_); std::map* allStorages() { std::unordered_map* map = surf::StorageImpl::storagesMap(); @@ -33,9 +36,14 @@ const char* Storage::name() return pimpl_->cname(); } -const char* Storage::host() +const char* Storage::type() +{ + return pimpl_->typeId_; +} + +Host* Storage::host() { - return pimpl_->attach_; + return attached_to_; } sg_size_t Storage::sizeFree() @@ -67,7 +75,7 @@ void Storage::setProperty(const char* key, char* value) xbt_dict_set(this->properties(), key, value, nullptr); } -std::map* Storage::content() +std::map* Storage::content() { return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); }); } diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 52e1ab79a5..dd03b1f62a 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -3,6 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include #include #include "simgrid/host.h" @@ -120,7 +121,15 @@ void sg_host_user_destroy(sg_host_t host) { // ========= storage related functions ============ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){ - return host->pimpl_->getMountedStorageList(); + xbt_assert((host != nullptr), "Invalid parameters"); + xbt_dict_t res = xbt_dict_new_homogeneous(nullptr); + for (auto elm : host->mountedStorages()) { + const char* mount_name = elm.first.c_str(); + sg_storage_t storage = elm.second; + xbt_dict_set(res, mount_name, (void*)storage->name(), nullptr); + } + + return res; } xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){ diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 5c1ee870bf..96cd223368 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -681,9 +681,9 @@ sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size, sg_host_t host) * \ingroup simix_file_management * \brief */ -smx_file_t simcall_file_open(const char* fullpath, sg_host_t host) +smx_file_t simcall_file_open(const char* mount, const char* path, sg_storage_t st) { - return simcall_BODY_file_open(fullpath, host); + return simcall_BODY_file_open(mount, path, st); } /** @@ -720,15 +720,6 @@ sg_size_t simcall_file_tell(smx_file_t fd){ return simcall_BODY_file_tell(fd); } -/** - * \ingroup simix_file_management - * - */ -xbt_dynar_t simcall_file_get_info(smx_file_t fd) -{ - return simcall_BODY_file_get_info(fd); -} - /** * \ingroup simix_file_management * diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 5e15eb5ed3..1b5db257b9 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -1418,25 +1418,41 @@ static inline void simcall_file_write__set__result(smx_simcall_t simcall, sg_siz simgrid::simix::marshal(simcall->result, result); } -static inline const char* simcall_file_open__get__fullpath(smx_simcall_t simcall) { +static inline const char* simcall_file_open__get__mount(smx_simcall_t simcall) +{ return simgrid::simix::unmarshal(simcall->args[0]); } -static inline const char* simcall_file_open__getraw__fullpath(smx_simcall_t simcall) +static inline const char* simcall_file_open__getraw__mount(smx_simcall_t simcall) { return simgrid::simix::unmarshal_raw(simcall->args[0]); } -static inline void simcall_file_open__set__fullpath(smx_simcall_t simcall, const char* arg) { - simgrid::simix::marshal(simcall->args[0], arg); +static inline void simcall_file_open__set__mount(smx_simcall_t simcall, const char* arg) +{ + simgrid::simix::marshal(simcall->args[0], arg); } -static inline sg_host_t simcall_file_open__get__host(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[1]); +static inline const char* simcall_file_open__get__path(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal(simcall->args[1]); } -static inline sg_host_t simcall_file_open__getraw__host(smx_simcall_t simcall) +static inline const char* simcall_file_open__getraw__path(smx_simcall_t simcall) { - return simgrid::simix::unmarshal_raw(simcall->args[1]); + return simgrid::simix::unmarshal_raw(simcall->args[1]); } -static inline void simcall_file_open__set__host(smx_simcall_t simcall, sg_host_t arg) { - simgrid::simix::marshal(simcall->args[1], arg); +static inline void simcall_file_open__set__path(smx_simcall_t simcall, const char* arg) +{ + simgrid::simix::marshal(simcall->args[1], arg); +} +static inline sg_storage_t simcall_file_open__get__st(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal(simcall->args[2]); +} +static inline sg_storage_t simcall_file_open__getraw__st(smx_simcall_t simcall) +{ + return simgrid::simix::unmarshal_raw(simcall->args[2]); +} +static inline void simcall_file_open__set__st(smx_simcall_t simcall, sg_storage_t arg) +{ + simgrid::simix::marshal(simcall->args[2], arg); } static inline smx_file_t simcall_file_open__get__result(smx_simcall_t simcall){ return simgrid::simix::unmarshal(simcall->result); @@ -1594,27 +1610,6 @@ static inline void simcall_file_seek__set__result(smx_simcall_t simcall, int res simgrid::simix::marshal(simcall->result, result); } -static inline smx_file_t simcall_file_get_info__get__fd(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[0]); -} -static inline smx_file_t simcall_file_get_info__getraw__fd(smx_simcall_t simcall) -{ - return simgrid::simix::unmarshal_raw(simcall->args[0]); -} -static inline void simcall_file_get_info__set__fd(smx_simcall_t simcall, smx_file_t arg) { - simgrid::simix::marshal(simcall->args[0], arg); -} -static inline xbt_dynar_t simcall_file_get_info__get__result(smx_simcall_t simcall){ - return simgrid::simix::unmarshal(simcall->result); -} -static inline xbt_dynar_t simcall_file_get_info__getraw__result(smx_simcall_t simcall) -{ - return simgrid::simix::unmarshal_raw(simcall->result); -} -static inline void simcall_file_get_info__set__result(smx_simcall_t simcall, xbt_dynar_t result){ - simgrid::simix::marshal(simcall->result, result); -} - static inline smx_file_t simcall_file_move__get__fd(smx_simcall_t simcall) { return simgrid::simix::unmarshal(simcall->args[0]); } @@ -1775,11 +1770,10 @@ XBT_PRIVATE void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_ XBT_PRIVATE int simcall_HANDLER_sem_get_capacity(smx_simcall_t simcall, smx_sem_t sem); XBT_PRIVATE void simcall_HANDLER_file_read(smx_simcall_t simcall, smx_file_t fd, sg_size_t size, sg_host_t host); XBT_PRIVATE void simcall_HANDLER_file_write(smx_simcall_t simcall, smx_file_t fd, sg_size_t size, sg_host_t host); -XBT_PRIVATE void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* fullpath, sg_host_t host); +XBT_PRIVATE void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* mount, const char* path, sg_storage_t st); XBT_PRIVATE void simcall_HANDLER_file_close(smx_simcall_t simcall, smx_file_t fd, sg_host_t host); XBT_PRIVATE sg_size_t simcall_HANDLER_file_get_size(smx_simcall_t simcall, smx_file_t fd); XBT_PRIVATE sg_size_t simcall_HANDLER_file_tell(smx_simcall_t simcall, smx_file_t fd); XBT_PRIVATE int simcall_HANDLER_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_offset_t offset, int origin); -XBT_PRIVATE xbt_dynar_t simcall_HANDLER_file_get_info(smx_simcall_t simcall, smx_file_t fd); XBT_PRIVATE int simcall_HANDLER_file_move(smx_simcall_t simcall, smx_file_t fd, const char* fullpath); XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max); \ No newline at end of file diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index cafc761568..02f679ab76 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -343,10 +343,12 @@ inline static sg_size_t simcall_BODY_file_write(smx_file_t fd, sg_size_t size, s return simcall(SIMCALL_FILE_WRITE, fd, size, host); } -inline static smx_file_t simcall_BODY_file_open(const char* fullpath, sg_host_t host) { + inline static smx_file_t simcall_BODY_file_open(const char* mount, const char* path, sg_storage_t st) + { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_file_open(&SIMIX_process_self()->simcall, fullpath, host); - return simcall(SIMCALL_FILE_OPEN, fullpath, host); + if (0) + simcall_HANDLER_file_open(&SIMIX_process_self()->simcall, mount, path, st); + return simcall(SIMCALL_FILE_OPEN, mount, path, st); } inline static int simcall_BODY_file_close(smx_file_t fd, sg_host_t host) { @@ -379,12 +381,6 @@ inline static int simcall_BODY_file_seek(smx_file_t fd, sg_offset_t offset, int return simcall(SIMCALL_FILE_SEEK, fd, offset, origin); } -inline static xbt_dynar_t simcall_BODY_file_get_info(smx_file_t fd) { - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_file_get_info(&SIMIX_process_self()->simcall, fd); - return simcall(SIMCALL_FILE_GET_INFO, fd); - } - inline static int simcall_BODY_file_move(smx_file_t fd, const char* fullpath) { /* Go to that function to follow the code flow through the simcall barrier */ if (0) simcall_HANDLER_file_move(&SIMIX_process_self()->simcall, fd, fullpath); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 4e59ccf9af..1a6d2d71ca 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -69,7 +69,6 @@ typedef enum { SIMCALL_FILE_GET_SIZE, SIMCALL_FILE_TELL, SIMCALL_FILE_SEEK, - SIMCALL_FILE_GET_INFO, SIMCALL_FILE_MOVE, SIMCALL_MC_RANDOM, SIMCALL_SET_CATEGORY, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 1a27a3acd1..1fc2e8a1a2 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -75,7 +75,6 @@ const char* simcall_names[] = { "SIMCALL_FILE_GET_SIZE", "SIMCALL_FILE_TELL", "SIMCALL_FILE_SEEK", - "SIMCALL_FILE_GET_INFO", "SIMCALL_FILE_MOVE", "SIMCALL_MC_RANDOM", "SIMCALL_SET_CATEGORY", @@ -348,8 +347,10 @@ case SIMCALL_FILE_WRITE: break; case SIMCALL_FILE_OPEN: - simcall_HANDLER_file_open(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1])); - break; + simcall_HANDLER_file_open(simcall, simgrid::simix::unmarshal(simcall->args[0]), + simgrid::simix::unmarshal(simcall->args[1]), + simgrid::simix::unmarshal(simcall->args[2])); + break; case SIMCALL_FILE_CLOSE: simcall_HANDLER_file_close(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1])); @@ -375,11 +376,6 @@ case SIMCALL_FILE_SEEK: SIMIX_simcall_answer(simcall); break; -case SIMCALL_FILE_GET_INFO: - simgrid::simix::marshal(simcall->result, simcall_HANDLER_file_get_info(simcall, simgrid::simix::unmarshal(simcall->args[0]))); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_FILE_MOVE: simgrid::simix::marshal(simcall->result, simcall_HANDLER_file_move(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1]))); SIMIX_simcall_answer(simcall); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index ad9ed06060..a7879aac34 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -87,13 +87,12 @@ int sem_get_capacity(smx_sem_t sem); sg_size_t file_read(smx_file_t fd, sg_size_t size, sg_host_t host) [[block]]; sg_size_t file_write(smx_file_t fd, sg_size_t size, sg_host_t host) [[block]]; -smx_file_t file_open(const char* fullpath, sg_host_t host) [[block]]; +smx_file_t file_open(const char* mount, const char* path, sg_storage_t st) [[block]]; int file_close(smx_file_t fd, sg_host_t host) [[block]]; int file_unlink(smx_file_t fd, sg_host_t host) [[nohandler]]; sg_size_t file_get_size(smx_file_t fd); sg_size_t file_tell(smx_file_t fd); int file_seek(smx_file_t fd, sg_offset_t offset, int origin); -xbt_dynar_t file_get_info(smx_file_t fd); int file_move(smx_file_t fd, const char* fullpath); int mc_random(int min, int max); diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index a420fe13df..e033cb90b6 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -9,6 +9,8 @@ #include #include "simgrid/s4u/Host.hpp" +#include "simgrid/s4u/Storage.hpp" +#include "src/surf/StorageImpl.hpp" #include @@ -66,21 +68,21 @@ smx_activity_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_host_t host) } //SIMIX FILE OPEN -void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* fullpath, sg_host_t host) +void simcall_HANDLER_file_open(smx_simcall_t simcall, const char* mount, const char* path, sg_storage_t st) { - smx_activity_t synchro = SIMIX_file_open(fullpath, host); + smx_activity_t synchro = SIMIX_file_open(mount, path, st); synchro->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = synchro; } -smx_activity_t SIMIX_file_open(const char* fullpath, sg_host_t host) +smx_activity_t SIMIX_file_open(const char* mount, const char* path, sg_storage_t st) { - if (host->isOff()) - THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->cname()); + if (st->host()->isOff()) + THROWF(host_error, 0, "Host %s failed, you cannot call this function", st->host()->cname()); simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl(); - synchro->host = host; - synchro->surf_io = surf_host_open(host, fullpath); + synchro->host = st->host(); + synchro->surf_io = st->pimpl_->open(mount, path); synchro->surf_io->setData(synchro); XBT_DEBUG("Create io synchro %p", synchro); @@ -142,18 +144,6 @@ sg_size_t SIMIX_file_tell(smx_actor_t process, smx_file_t fd) return surf_host_file_tell(host, fd->surf_file); } - -xbt_dynar_t simcall_HANDLER_file_get_info(smx_simcall_t simcall, smx_file_t fd) -{ - return SIMIX_file_get_info(simcall->issuer, fd); -} - -xbt_dynar_t SIMIX_file_get_info(smx_actor_t process, smx_file_t fd) -{ - sg_host_t host = process->host; - return surf_host_get_info(host, fd->surf_file); -} - int simcall_HANDLER_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_offset_t offset, int origin) { return SIMIX_file_seek(simcall->issuer, fd, offset, origin); diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index 0d48df10c3..70e553d19e 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -13,12 +13,11 @@ XBT_PRIVATE smx_activity_t SIMIX_file_read(smx_file_t fd, sg_size_t size, sg_host_t host); XBT_PRIVATE smx_activity_t SIMIX_file_write(smx_file_t fd, sg_size_t size, sg_host_t host); -XBT_PRIVATE smx_activity_t SIMIX_file_open(const char* fullpath, sg_host_t host); +XBT_PRIVATE smx_activity_t SIMIX_file_open(const char* mount, const char* path, sg_storage_t st); XBT_PRIVATE smx_activity_t SIMIX_file_close(smx_file_t fd, sg_host_t host); XBT_PRIVATE int SIMIX_file_unlink(smx_file_t fd, sg_host_t host); XBT_PRIVATE sg_size_t SIMIX_file_get_size(smx_actor_t process, smx_file_t fd); XBT_PRIVATE sg_size_t SIMIX_file_tell(smx_actor_t process, smx_file_t fd); -XBT_PRIVATE xbt_dynar_t SIMIX_file_get_info(smx_actor_t process, smx_file_t fd); XBT_PRIVATE int SIMIX_file_seek(smx_actor_t process, smx_file_t fd, sg_offset_t offset, int origin); XBT_PRIVATE int SIMIX_file_move(smx_actor_t process, smx_file_t fd, const char* fullpath); diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 1978dbc89b..2cb9e021f2 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -48,6 +48,7 @@ static inline double has_cost(double* array, int pos) else return -1.0; } + Action* HostModel::executeParallelTask(int host_nb, simgrid::s4u::Host** host_list, double* flops_amount, double* bytes_amount, double rate) { @@ -104,54 +105,13 @@ simgrid::surf::StorageImpl* HostImpl::findStorageOnMountList(const char* mount) return storage_.at(mount); } -xbt_dict_t HostImpl::getMountedStorageList() -{ - xbt_dict_t storage_list = xbt_dict_new_homogeneous(nullptr); - char* storage_name = nullptr; - - for (auto mnt : storage_) { - storage_name = (char*)mnt.second->cname(); - xbt_dict_set(storage_list, mnt.first.c_str(), storage_name, nullptr); - } - return storage_list; -} - void HostImpl::getAttachedStorageList(std::vector* storages) { for (auto s : storage_) - if (not strcmp(static_cast(s.second->attach_), piface_->cname())) + if (s.second->attach_ == piface_->cname()) storages->push_back(s.second->piface_.name()); } -Action* HostImpl::open(const char* fullpath) -{ - simgrid::surf::StorageImpl* st = nullptr; - size_t longest_prefix_length = 0; - std::string path; - std::string mount_name; - - XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath, piface_->cname()); - for (auto mnt : storage_) { - XBT_DEBUG("See '%s'", mnt.first.c_str()); - std::string file_mount_name = std::string(fullpath).substr(0, mnt.first.size()); - - if (file_mount_name == mnt.first && mnt.first.length() > longest_prefix_length) { - /* The current mount name is found in the full path and is bigger than the previous*/ - longest_prefix_length = mnt.first.length(); - st = mnt.second; - } - } - if (longest_prefix_length > 0) { /* Mount point found, split fullpath into mount_name and path+filename*/ - mount_name = std::string(fullpath).substr(0, longest_prefix_length); - path = std::string(fullpath).substr(longest_prefix_length, strlen(fullpath)); - } else - xbt_die("Can't find mount point for '%s' on '%s'", fullpath, piface_->cname()); - - XBT_DEBUG("OPEN %s on disk '%s'", path.c_str(), st->cname()); - Action* action = st->open(mount_name.c_str(), path.c_str()); - return action; -} - Action* HostImpl::close(surf_file_t fd) { simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount); @@ -190,8 +150,6 @@ int HostImpl::unlink(surf_file_t fd) st->usedSize_ -= fd->size; // Remove the file from storage - sg_size_t* psize = st->content_->at(fd->name); - delete psize; st->content_->erase(fd->name); xbt_free(fd->name); @@ -207,20 +165,6 @@ sg_size_t HostImpl::getSize(surf_file_t fd) return fd->size; } -xbt_dynar_t HostImpl::getInfo(surf_file_t fd) -{ - simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount); - sg_size_t* psize = xbt_new(sg_size_t, 1); - *psize = fd->size; - xbt_dynar_t info = xbt_dynar_new(sizeof(void*), nullptr); - xbt_dynar_push_as(info, sg_size_t*, psize); - xbt_dynar_push_as(info, void*, fd->mount); - xbt_dynar_push_as(info, void*, (void*)st->cname()); - xbt_dynar_push_as(info, void*, st->typeId_); - - return info; -} - sg_size_t HostImpl::fileTell(surf_file_t fd) { return fd->current_position; @@ -247,16 +191,13 @@ int HostImpl::fileMove(surf_file_t fd, const char* fullpath) { /* Check if the new full path is on the same mount point */ if (not strncmp((const char*)fd->mount, fullpath, strlen(fd->mount))) { - std::map* content = findStorageOnMountList(fd->mount)->content_; + std::map* content = findStorageOnMountList(fd->mount)->content_; if (content->find(fd->name) != content->end()) { // src file exists - sg_size_t* psize = content->at(std::string(fd->name)); - sg_size_t* new_psize = new sg_size_t; - *new_psize = *psize; - delete psize; + sg_size_t new_size = content->at(std::string(fd->name)); content->erase(fd->name); std::string path = std::string(fullpath).substr(strlen(fd->mount), strlen(fullpath)); - content->insert({path.c_str(), new_psize}); - XBT_DEBUG("Move file from %s to %s, size '%llu'", fd->name, fullpath, *psize); + content->insert({path.c_str(), new_size}); + XBT_DEBUG("Move file from %s to %s, size '%llu'", fd->name, fullpath, new_size); return 0; } else { XBT_WARN("File %s doesn't exist", fd->name); diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 06936554df..d22e5d4b53 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -69,20 +69,9 @@ public: /** @brief Return the storage of corresponding mount point */ virtual simgrid::surf::StorageImpl* findStorageOnMountList(const char* storage); - /** @brief Get the xbt_dict_t of mount_point: Storage */ - virtual xbt_dict_t getMountedStorageList(); - /** @brief Get the xbt_dynar_t of storages attached to the Host */ virtual void getAttachedStorageList(std::vector* storages); - /** - * @brief Open a file - * - * @param fullpath The full path to the file - * @return The StorageAction corresponding to the opening - */ - virtual Action* open(const char* fullpath); - /** * @brief Close a file * @@ -126,20 +115,6 @@ public: */ virtual Action* write(surf_file_t fd, sg_size_t size); - /** - * @brief Get the information of a file descriptor - * @details The returned xbt_dynar_t contains: - * - the size of the file, - * - the mount point, - * - the storage name, - * - the storage typeId, - * - the storage content type - * - * @param fd The file descriptor - * @return An xbt_dynar_t with the file information - */ - virtual xbt_dynar_t getInfo(surf_file_t fd); - /** * @brief Get the current position of the file descriptor * diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index aea1e2602a..a6b13179b0 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -68,7 +68,7 @@ StorageImpl::StorageImpl(Model* model, const char* name, lmm_system_t maxminSyst , writeActions_(std::vector()) { content_ = parseContent(content_name); - attach_ = xbt_strdup(attach); + attach_ = attach; turnOn(); XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size); constraintRead_ = lmm_constraint_new(maxminSystem, this, bread); @@ -79,22 +79,19 @@ StorageImpl::StorageImpl(Model* model, const char* name, lmm_system_t maxminSyst StorageImpl::~StorageImpl() { storageDestructedCallbacks(this); - if (content_ != nullptr) { - for (auto entry : *content_) - delete entry.second; + if (content_ != nullptr) delete content_; - } + free(typeId_); - free(attach_); } -std::map* StorageImpl::parseContent(const char* filename) +std::map* StorageImpl::parseContent(const char* filename) { usedSize_ = 0; if ((not filename) || (strcmp(filename, "") == 0)) return nullptr; - std::map* parse_content = new std::map(); + std::map* parse_content = new std::map(); std::ifstream* fs = surf_ifsopen(filename); @@ -109,9 +106,7 @@ std::map* StorageImpl::parseContent(const char* filenam sg_size_t size = std::stoull(tokens.at(1)); usedSize_ += size; - sg_size_t* psize = new sg_size_t; - *psize = size; - parse_content->insert({tokens.front(), psize}); + parse_content->insert({tokens.front(), size}); } } while (not fs->eof()); delete fs; @@ -144,7 +139,7 @@ void StorageImpl::turnOff() } } -std::map* StorageImpl::getContent() +std::map* StorageImpl::getContent() { /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */ return content_; diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 9b1af7f869..ac7a6025fa 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -102,20 +102,21 @@ public: void turnOn() override; void turnOff() override; - std::map* content_; + std::map* content_; sg_size_t size_; sg_size_t usedSize_; char* typeId_; - char* attach_; // FIXME: this is the name of the host. Use the host directly - - /** - * @brief Open a file - * - * @param mount The mount point - * @param path The path to the file - * - * @return The StorageAction corresponding to the opening - */ + std::string attach_; // Name of the host to which this storage is attached. + // Only used until the platform is fully parsed only. + // Then the interface stores the Host directly. + /** + * @brief Open a file + * + * @param mount The mount point + * @param path The path to the file + * + * @return The StorageAction corresponding to the opening + */ virtual StorageAction* open(const char* mount, const char* path) = 0; /** @@ -149,7 +150,7 @@ public: * * @return A xbt_dict_t with path as keys and size in bytes as values */ - virtual std::map* getContent(); + virtual std::map* getContent(); /** * @brief Get the available size in bytes of the current Storage @@ -165,7 +166,7 @@ public: */ virtual sg_size_t getUsedSize(); - std::map* parseContent(const char* filename); + std::map* parseContent(const char* filename); static std::unordered_map* storages; static std::unordered_map* storagesMap() { return StorageImpl::storages; } std::vector writeActions_; diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 2cedbb9eea..3d90a4e809 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -18,9 +18,12 @@ extern std::map storage_types; static void check_disk_attachment() { for (auto s : *simgrid::surf::StorageImpl::storagesMap()) { - simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->attach_); + simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->attach_.c_str()); if (not host_elm) - surf_parse_error("Unable to attach storage %s: host %s does not exist.", s.second->cname(), s.second->attach_); + surf_parse_error("Unable to attach storage %s: host %s does not exist.", s.second->cname(), + s.second->attach_.c_str()); + else + s.second->piface_.attached_to_ = sg_host_by_name(s.second->attach_.c_str()); } } @@ -113,12 +116,8 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) // which becomes the new file size action->file_->size = action->file_->current_position; - sg_size_t* psize = new sg_size_t; - *psize = action->file_->size; - std::map* content_dict = action->storage_->content_; - auto entry = content_dict->find(action->file_->name); - delete entry->second; - entry->second = psize; + action->storage_->content_->erase(action->file_->name); + action->storage_->content_->insert({action->file_->name, action->file_->size}); } action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta); @@ -155,15 +154,12 @@ StorageAction *StorageN11::open(const char* mount, const char* path) XBT_DEBUG("\tOpen file '%s'",path); sg_size_t size; - sg_size_t* psize = nullptr; // if file does not exist create an empty file if (content_->find(path) != content_->end()) - size = *(content_->at(path)); + size = content_->at(path); else { - psize = new sg_size_t; - size = 0; - *psize = size; - content_->insert({path, psize}); + size = 0; + content_->insert({path, size}); XBT_DEBUG("File '%s' was not found, file created.",path); } surf_file_t file = xbt_new0(s_surf_file_t,1); diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 0f0061812d..fb3169c914 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -165,10 +165,6 @@ int surf_model_running_action_set_size(surf_model_t model){ return model->getRunningActionSet()->size(); } -surf_action_t surf_host_open(sg_host_t host, const char* fullpath){ - return host->pimpl_->open(fullpath); -} - surf_action_t surf_host_close(sg_host_t host, surf_file_t fd){ return host->pimpl_->close(fd); } @@ -189,10 +185,6 @@ surf_action_t surf_host_write(sg_host_t host, surf_file_t fd, sg_size_t size){ return host->pimpl_->write(fd, size); } -xbt_dynar_t surf_host_get_info(sg_host_t host, surf_file_t fd){ - return host->pimpl_->getInfo(fd); -} - size_t surf_host_file_tell(sg_host_t host, surf_file_t fd){ return host->pimpl_->fileTell(fd); } @@ -228,7 +220,7 @@ xbt_dict_t surf_storage_get_properties(surf_storage_t resource) const char* surf_storage_get_host(surf_storage_t resource) { - return static_cast(resource)->attach_; + return static_cast(resource)->attach_.c_str(); } const char* surf_storage_get_name(surf_storage_t resource) diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index b2fdc637b2..0dcfafd4cf 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -64,16 +64,16 @@ static void hsm_put(const char* remote_host, const char* src, const char* dest) static void display_storage_content(simgrid::s4u::Storage* storage) { XBT_INFO("Print the content of the storage element: %s", storage->name()); - std::map* content = storage->content(); + std::map* content = storage->content(); if (not content->empty()) { for (auto entry : *content) - XBT_INFO("\t%s size: %llu bytes", entry.first.c_str(), *entry.second); + XBT_INFO("\t%s size: %llu bytes", entry.first.c_str(), entry.second); } else { XBT_INFO("\tNo content."); } } -static void dump_storage_by_name(char* name) +static void dump_storage_by_name(const char* name) { XBT_INFO("*** Dump a storage element ***"); simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(name); @@ -98,7 +98,7 @@ static void dump_platform_storages() std::map* storages = simgrid::s4u::allStorages(); for (auto storage : *storages) { - XBT_INFO("Storage %s is attached to %s", storage.first.c_str(), storage.second->host()); + XBT_INFO("Storage %s is attached to %s", storage.first.c_str(), storage.second->host()->cname()); storage.second->setProperty("other usage", xbt_strdup("gpfs")); } delete storages; @@ -107,14 +107,11 @@ static void dump_platform_storages() static void storage_info(simgrid::s4u::Host* host) { XBT_INFO("*** Storage info on %s ***", host->cname()); - xbt_dict_cursor_t cursor = NULL; - char* mount_name; - char* storage_name; - xbt_dict_t storage_list = host->mountedStoragesAsDict(); - xbt_dict_foreach (storage_list, cursor, mount_name, storage_name) { - XBT_INFO("\tStorage name: %s, mount name: %s", storage_name, mount_name); - simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(storage_name); + for (auto elm : host->mountedStorages()) { + const char* mount_name = elm.first.c_str(); + simgrid::s4u::Storage* storage = elm.second; + XBT_INFO("\tStorage name: %s, mount name: %s", storage->name(), mount_name); sg_size_t free_size = storage->sizeFree(); sg_size_t used_size = storage->sizeUsed(); @@ -123,9 +120,8 @@ static void storage_info(simgrid::s4u::Host* host) XBT_INFO("\t\tUsed size: %llu bytes", used_size); display_storage_properties(storage); - dump_storage_by_name(storage_name); + dump_storage_by_name(storage->name()); } - xbt_dict_free(&storage_list); } static void client() diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.tesh b/teshsuite/s4u/storage_client_server/storage_client_server.tesh index d334f6b9f4..08781a10da 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.tesh +++ b/teshsuite/s4u/storage_client_server/storage_client_server.tesh @@ -53,10 +53,10 @@ $ ./storage_client_server$EXEEXT ${srcdir:=.}/../../../examples/platforms/storag > [ 0.803996] (client@bob) client sends 6217 to alice > [ 0.806104] (server@alice) 6217 bytes on 6217 bytes have been written by server on /sd1 > [ 1.207952] (server@alice) *** Storage info on alice *** +> [ 1.207952] (server@alice) Storage name: Disk2, mount name: c: > [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 *** > [ 1.207952] (client@bob) Get data: '(null)' > [ 1.207952] (client@bob) Set and get data: 'Some data' -> [ 1.207952] (server@alice) Storage name: Disk2, mount name: c: > [ 1.207952] (server@alice) Free size: 534479367024 bytes > [ 1.207952] (server@alice) Used size: 2391544976 bytes > [ 1.207952] (server@alice) No property attached. -- 2.20.1