From: Frederic Suter Date: Mon, 10 Jul 2017 11:18:50 +0000 (+0200) Subject: cleanups X-Git-Tag: v3_17~416^2~3 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7bd4c4c813d5e95bbe17bab38c0c07e53a50218d cleanups --- diff --git a/include/simgrid/s4u/File.hpp b/include/simgrid/s4u/File.hpp index 6736f85da5..9fbc6f2c13 100644 --- a/include/simgrid/s4u/File.hpp +++ b/include/simgrid/s4u/File.hpp @@ -32,11 +32,7 @@ public: /** Retrieves the path to the file */ const char* getPath() { return path_; } - /** Simulates a read action. Returns the size of data actually read - * - * 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 local read action. Returns the size of data actually read */ sg_size_t read(sg_size_t size); /** Simulates a write action. Returns the size of data actually written. */ @@ -66,11 +62,6 @@ public: /** Remove a file from disk */ int unlink(); - /* 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); - */ const char* storage_type; const char* storageId; std::string mount_point; diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 615e3e7588..854e0f9ab9 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -32,10 +32,9 @@ public: const char* getName(); const char* getType(); Host* getHost(); + sg_size_t getSize(); /** Retrieve the total amount of space of this storage element */ sg_size_t getSizeFree(); sg_size_t getSizeUsed(); - /** Retrieve the total amount of space of this storage element */ - sg_size_t getSize(); xbt_dict_t getProperties(); const char* getProperty(const char* key); @@ -45,6 +44,8 @@ public: void setUserdata(void* data) { userdata_ = data; } void* getUserdata() { return userdata_; } + surf::StorageImpl* getImpl() { return pimpl_; } + /* The signals */ /** @brief Callback signal fired when a new Link is created */ static simgrid::xbt::signal onCreation; @@ -53,9 +54,9 @@ public: static simgrid::xbt::signal onDestruction; Host* attached_to_ = nullptr; - surf::StorageImpl* const pimpl_ = nullptr; private: + surf::StorageImpl* const pimpl_ = nullptr; std::string name_; void* userdata_ = nullptr; }; diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index f2447ebb23..0c183afcf1 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -49,7 +49,6 @@ typedef simgrid::surf::CpuModel surf_CpuModel; typedef simgrid::surf::Cpu surf_Cpu; typedef simgrid::surf::HostModel surf_HostModel; typedef simgrid::surf::NetworkModel surf_NetworkModel; -typedef simgrid::surf::StorageImpl surf_Storage; typedef simgrid::surf::StorageModel surf_StorageModel; typedef simgrid::surf::Resource surf_Resource; typedef simgrid::surf::Action surf_Action; @@ -62,7 +61,6 @@ typedef struct surf_CpuModel surf_CpuModel; typedef struct surf_Cpu surf_Cpu; typedef struct surf_HostModel surf_HostModel; typedef struct surf_NetworkModel surf_NetworkModel; -typedef struct surf_StorageImpl surf_Storage; typedef struct surf_StorageModel surf_StorageModel; typedef struct surf_Resource surf_Resource; typedef struct surf_Host surf_Host; diff --git a/src/kernel/activity/SynchroIo.cpp b/src/kernel/activity/SynchroIo.cpp index e954fae5a6..a9543f70b3 100644 --- a/src/kernel/activity/SynchroIo.cpp +++ b/src/kernel/activity/SynchroIo.cpp @@ -5,8 +5,6 @@ #include "src/kernel/activity/SynchroIo.hpp" #include "src/simix/smx_private.h" -#include "src/surf/FileImpl.hpp" -#include "src/surf/StorageImpl.hpp" #include "src/surf/surf_interface.hpp" void simgrid::kernel::activity::IoImpl::suspend() @@ -28,26 +26,21 @@ void simgrid::kernel::activity::IoImpl::post() case SIMCALL_FILE_WRITE: simcall_file_write__set__result(simcall, surf_io->getCost()); break; - case SIMCALL_FILE_READ: simcall_file_read__set__result(simcall, surf_io->getCost()); break; - default: break; } } switch (surf_io->getState()) { - case simgrid::surf::Action::State::failed: state = SIMIX_FAILED; break; - case simgrid::surf::Action::State::done: state = SIMIX_DONE; break; - default: THROW_IMPOSSIBLE; break; diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 694466c9a4..60a91423aa 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -57,7 +57,7 @@ sg_size_t Storage::getSizeUsed() sg_size_t Storage::getSize() { - return pimpl_->size_; + return pimpl_->getSize(); } xbt_dict_t Storage::getProperties() diff --git a/src/simix/smx_io_private.h b/src/simix/smx_io_private.h index e4689f7298..e51804df3c 100644 --- a/src/simix/smx_io_private.h +++ b/src/simix/smx_io_private.h @@ -13,8 +13,6 @@ XBT_PRIVATE smx_activity_t SIMIX_file_read(surf_file_t fd, sg_size_t size, sg_host_t host); XBT_PRIVATE smx_activity_t SIMIX_file_write(surf_file_t fd, sg_size_t size, 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(surf_file_t fd, sg_host_t host); XBT_PRIVATE void SIMIX_io_destroy(smx_activity_t synchro); XBT_PRIVATE void SIMIX_io_finish(smx_activity_t synchro); diff --git a/src/surf/FileImpl.cpp b/src/surf/FileImpl.cpp index fd81b4acb0..53548500a5 100644 --- a/src/surf/FileImpl.cpp +++ b/src/surf/FileImpl.cpp @@ -5,7 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/surf/FileImpl.hpp" -#include "src/surf/HostImpl.hpp" +#include "src/surf/StorageImpl.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_file, surf, "Logging specific to the SURF file module"); namespace simgrid { @@ -14,8 +14,8 @@ namespace surf { FileImpl::FileImpl(sg_storage_t st, std::string path, std::string mount) : path_(path), mount_point_(mount) { XBT_DEBUG("\tOpen file '%s'", path.c_str()); - location_ = st->pimpl_; - std::map* content = location_->content_; + location_ = st->getImpl(); + std::map* content = location_->getContent(); // if file does not exist create an empty file if (content->find(path) != content->end()) size_ = content->at(path); @@ -51,7 +51,7 @@ Action* FileImpl::write(sg_size_t size) /* Substract the part of the file that might disappear from the used sized on the storage element */ location_->usedSize_ -= (size_ - current_position_); // If the storage is full before even starting to write - if (location_->usedSize_ >= location_->size_) { + if (location_->usedSize_ >= location_->getSize()) { action->setState(Action::State::failed); } return action; @@ -77,7 +77,7 @@ int FileImpl::seek(sg_offset_t offset, int origin) int FileImpl::unlink() { /* Check if the file is on this storage */ - if (location_->content_->find(path_) == location_->content_->end()) { + if (location_->getContent()->find(path_) == location_->getContent()->end()) { XBT_WARN("File %s is not on disk %s. Impossible to unlink", cname(), location_->cname()); return -1; } else { @@ -85,7 +85,7 @@ int FileImpl::unlink() location_->usedSize_ -= size_; // Remove the file from storage - location_->content_->erase(path_); + location_->getContent()->erase(path_); return 0; } @@ -95,7 +95,7 @@ void FileImpl::move(const char* fullpath) { /* Check if the new full path is on the same mount point */ if (not strncmp(mount_point_.c_str(), fullpath, mount_point_.size())) { - std::map* content = location_->content_; + std::map* content = location_->getContent(); if (content->find(path_) != content->end()) { // src file exists sg_size_t new_size = content->at(path_); content->erase(path_); diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 76576cdf58..6d88f2734f 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -103,7 +103,7 @@ HostImpl::HostImpl(s4u::Host* host) : piface_(host) void HostImpl::getAttachedStorageList(std::vector* storages) { for (auto s : storage_) - if (s.second->attach_ == piface_->getCname()) + if (s.second->getHost() == piface_->getCname()) storages->push_back(s.second->piface_.getName()); } diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index 8faa657e2b..1fb0fbcc67 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -62,9 +62,8 @@ StorageImpl::StorageImpl(Model* model, const char* name, lmm_system_t maxminSyst const char* type_id, const char* content_name, sg_size_t size, const char* attach) : Resource(model, name, lmm_constraint_new(maxminSystem, this, MAX(bread, bwrite))) , piface_(this) - , size_(size) - , usedSize_(0) , typeId_(type_id) + , size_(size) , attach_(attach) { content_ = parseContent(content_name); diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 3061a60dc5..97a3e7d588 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -102,14 +102,6 @@ public: void turnOn() override; void turnOff() override; - std::map* content_; - sg_size_t size_; - sg_size_t usedSize_; - std::string typeId_; - 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 Read a file * @@ -146,6 +138,8 @@ public: * @return The used size in bytes of the current Storage */ virtual sg_size_t getUsedSize(); + virtual sg_size_t getSize() { return size_; } + virtual std::string getHost() { return attach_; } std::map* parseContent(const char* filename); static std::unordered_map* storages; @@ -153,6 +147,16 @@ public: lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/ lmm_constraint_t constraintRead_; /* Constraint for maximum write bandwidth*/ + + std::string typeId_; + sg_size_t usedSize_ = 0; + +private: + sg_size_t size_; + std::map* content_; + // Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores + // the Host directly. + std::string attach_; }; /********** diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 819b1f59f6..2ab9fced8e 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -18,12 +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_.c_str()); + simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->getHost().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_.c_str()); + s.second->getHost().c_str()); else - s.second->piface_.attached_to_ = sg_host_by_name(s.second->attach_.c_str()); + s.second->piface_.attached_to_ = sg_host_by_name(s.second->getHost().c_str()); } } @@ -74,10 +74,8 @@ double StorageN11Model::nextOccuringEvent(double now) void StorageN11Model::updateActionsState(double /*now*/, double delta) { - ActionList *actionSet = getRunningActionSet(); - for(ActionList::iterator it(actionSet->begin()), itNext=it, itend(actionSet->end()) - ; it != itend ; it=itNext) { + for (ActionList::iterator it(actionSet->begin()), itNext = it, itend(actionSet->end()); it != itend; it = itNext) { ++itNext; StorageAction *action = static_cast(&*it); @@ -104,8 +102,8 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) // which becomes the new file size action->file_->setSize(action->file_->tell()); - action->storage_->content_->erase(action->file_->cname()); - action->storage_->content_->insert({action->file_->cname(), action->file_->size()}); + action->storage_->getContent()->erase(action->file_->cname()); + action->storage_->getContent()->insert({action->file_->cname(), action->file_->size()}); } action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta); @@ -114,7 +112,7 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) action->updateMaxDuration(delta); if (action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 && - action->storage_->usedSize_ == action->storage_->size_) { + action->storage_->usedSize_ == action->storage_->getSize()) { action->finish(); action->setState(Action::State::failed); } else if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) ||