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();
write = file->write(100000); // Write 100,000 bytes
XBT_INFO("Write %llu bytes on %s", write, filename);
- simgrid::s4u::Storage &storage = simgrid::s4u::Storage::byName("Disk4");
+ simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk4");
// Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme
const char *newpath = "/home/tmp/simgrid.readme";
delete file;
// Now attach some user data to disk1
- XBT_INFO("Get/set data for storage element: %s",storage.name());
- XBT_INFO(" Uninitialized storage data: '%s'", (char*)storage.userdata());
+ XBT_INFO("Get/set data for storage element: %s", storage->name());
+ XBT_INFO(" Uninitialized storage data: '%s'", (char*)storage->userdata());
- storage.setUserdata(xbt_strdup("Some user data"));
- XBT_INFO(" Set and get data: '%s'", (char*)storage.userdata());
+ storage->setUserdata(xbt_strdup("Some user data"));
+ XBT_INFO(" Set and get data: '%s'", (char*)storage->userdata());
- xbt_free(storage.userdata());
+ xbt_free(storage->userdata());
}
};
namespace simgrid {
namespace s4u {
+std::unordered_map<std::string, Storage*>* allStorages();
+
XBT_PUBLIC_CLASS Storage
{
friend s4u::Engine;
-
- Storage(std::string name, smx_storage_t inferior);
+ friend simgrid::surf::StorageImpl;
public:
- Storage() = default;
- virtual ~Storage();
+ explicit Storage(surf::StorageImpl * pimpl) : pimpl_(pimpl) {}
+ virtual ~Storage() = default;
/** Retrieve a Storage by its name. It must exist in the platform file */
- static Storage& byName(const char* name);
+ static Storage* byName(const char* name);
const char* name();
const char* host();
sg_size_t sizeFree();
const char* property(const char* key);
void setProperty(const char* key, char* value);
std::map<std::string, sg_size_t*>* content();
- std::unordered_map<std::string, Storage*>* allStorages();
-
-protected:
- smx_storage_t inferior();
public:
void setUserdata(void* data) { userdata_ = data; }
void* userdata() { return userdata_; }
-private:
- static std::unordered_map<std::string, Storage*>* storages_;
+ /* The signals */
+ /** @brief Callback signal fired when a new Link is created */
+ static simgrid::xbt::signal<void(s4u::Storage&)> onCreation;
+
+ /** @brief Callback signal fired when a Link is destroyed */
+ static simgrid::xbt::signal<void(s4u::Storage&)> onDestruction;
- std::string hostname_;
+private:
std::string name_;
- sg_size_t size_ = 0;
- smx_storage_t pimpl_ = nullptr;
+ surf::StorageImpl* const pimpl_ = nullptr;
void* userdata_ = nullptr;
};
void Engine::shutdown() {
delete s4u::Engine::instance_;
s4u::Engine::instance_ = nullptr;
- delete s4u::Storage::storages_;
}
double Engine::getClock()
char *mountname;
char *storagename;
xbt_dict_foreach(dict, cursor, mountname, storagename) {
- mounts->insert({mountname, &Storage::byName(storagename)});
+ mounts->insert({mountname, Storage::byName(storagename)});
}
xbt_dict_free(&dict);
}
#include "xbt/lib.h"
#include <unordered_map>
-extern xbt_lib_t storage_lib;
-
namespace simgrid {
namespace s4u {
-
-std::unordered_map<std::string, Storage*>* Storage::storages_ = new std::unordered_map<std::string, Storage*>();
-
-Storage::Storage(std::string name, smx_storage_t inferior) :
- name_(name), pimpl_(inferior)
+std::unordered_map<std::string, Storage*>* allStorages()
{
- hostname_ = surf_storage_get_host(pimpl_);
- size_ = surf_storage_get_size(pimpl_);
- storages_->insert({name, this});
-}
+ std::unordered_map<std::string, surf::StorageImpl*>* map = surf::StorageImpl::storagesMap();
+ std::unordered_map<std::string, Storage*>* res = new std::unordered_map<std::string, Storage*>;
+ for (auto s : *map)
+ res->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface
-Storage::~Storage() = default;
-
-smx_storage_t Storage::inferior()
-{
- return pimpl_;
+ return res;
}
-Storage& Storage::byName(const char* name)
+Storage* Storage::byName(const char* name)
{
- s4u::Storage* res = nullptr;
- try {
- res = storages_->at(name);
- } catch (std::out_of_range& e) {
- smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
- if (inferior == nullptr)
- xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
-
- res = new Storage(name,inferior);
- }
- return *res;
+ surf::StorageImpl* res = surf::StorageImpl::byName(name);
+ if (res == nullptr)
+ return nullptr;
+ return &res->piface_;
}
const char* Storage::name()
{
- return name_.c_str();
+ return pimpl_->cname();
}
const char* Storage::host()
{
- return hostname_.c_str();
+ return pimpl_->attach_;
}
sg_size_t Storage::sizeFree()
{
- return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); });
+ return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); });
}
sg_size_t Storage::sizeUsed()
{
- return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); });
+ return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
}
sg_size_t Storage::size() {
- return size_;
+ return pimpl_->size_;
}
xbt_dict_t Storage::properties()
{
- return simcall_storage_get_properties(pimpl_);
+ return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
}
const char* Storage::property(const char* key)
std::map<std::string, sg_size_t*>* Storage::content()
{
- return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); });
+ return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); });
}
-std::unordered_map<std::string, Storage*>* Storage::allStorages()
-{
- return storages_;
-}
+/*************
+ * Callbacks *
+ *************/
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
+simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
} /* namespace s4u */
} /* namespace simgrid */
simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
simgrid::xbt::signal<void(StorageAction*, Action::State, Action::State)> storageActionStateChangedCallbacks;
+/* List of storages */
+std::unordered_map<std::string, StorageImpl*>* StorageImpl::storages =
+ new std::unordered_map<std::string, StorageImpl*>();
+
+StorageImpl* StorageImpl::byName(const char* name)
+{
+ if (storages->find(name) == storages->end())
+ return nullptr;
+ return storages->at(name);
+}
+
/*********
* Model *
*********/
StorageImpl::StorageImpl(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite,
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_(xbt_strdup(type_id))
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
constraintRead_ = lmm_constraint_new(maxminSystem, this, bread);
constraintWrite_ = lmm_constraint_new(maxminSystem, this, bwrite);
+ storages->insert({name, this});
}
StorageImpl::~StorageImpl()
#include <xbt/base.h>
#include <xbt/signal.hpp>
+#include "simgrid/s4u/Storage.hpp"
#include "src/surf/PropertyHolder.hpp"
#include "surf_interface.hpp"
#include <map>
StorageImpl(Model* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite,
const char* type_id, const char* content_name, sg_size_t size, const char* attach);
- ~StorageImpl();
+ ~StorageImpl() override;
+
+public:
+ /** @brief Public interface */
+ s4u::Storage piface_;
+ static StorageImpl* byName(const char* name);
/** @brief Check if the Storage is used (if an action currently uses its resources) */
bool isUsed() override;
virtual sg_size_t getUsedSize();
std::map<std::string, sg_size_t*>* parseContent(const char* filename);
-
+ static std::unordered_map<std::string, StorageImpl*>* storages;
+ static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
std::vector<StorageAction*> writeActions_;
lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/
: StorageImpl(model, name, maxminSystem, bread, bwrite, type_id, content_name, size, attach)
{
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
+ simgrid::s4u::Storage::onCreation(this->piface_);
}
StorageAction *StorageN11::open(const char* mount, const char* path)
public:
StorageN11(StorageModel* model, const char* name, lmm_system_t maxminSystem, double bread, double bwrite,
const char* type_id, char* content_name, sg_size_t size, char* attach);
+ virtual ~StorageN11() = default;
StorageAction *open(const char* mount, const char* path);
StorageAction *close(surf_file_t fd);
StorageAction *ls(const char *path);
static void dump_storage_by_name(char* name)
{
XBT_INFO("*** Dump a storage element ***");
- simgrid::s4u::Storage& storage = simgrid::s4u::Storage::byName(name);
- display_storage_content(&storage);
+ simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(name);
+ display_storage_content(storage);
}
static void get_set_storage_data(const char* storage_name)
{
XBT_INFO("*** GET/SET DATA for storage element: %s ***", storage_name);
- simgrid::s4u::Storage& storage = simgrid::s4u::Storage::byName(storage_name);
+ simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(storage_name);
- char* data = static_cast<char*>(storage.userdata());
+ char* data = static_cast<char*>(storage->userdata());
XBT_INFO("Get data: '%s'", data);
- storage.setUserdata(xbt_strdup("Some data"));
- data = static_cast<char*>(storage.userdata());
+ storage->setUserdata(xbt_strdup("Some data"));
+ data = static_cast<char*>(storage->userdata());
XBT_INFO("\tSet and get data: '%s'", data);
xbt_free(data);
}
static void dump_platform_storages()
{
- std::unordered_map<std::string, simgrid::s4u::Storage*>* storages = simgrid::s4u::Storage().allStorages();
+ std::unordered_map<std::string, simgrid::s4u::Storage*>* storages = simgrid::s4u::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
+ delete storages;
}
static void storage_info(simgrid::s4u::Host* host)
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);
+ simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName(storage_name);
- sg_size_t free_size = storage.sizeFree();
- sg_size_t used_size = storage.sizeUsed();
+ sg_size_t free_size = storage->sizeFree();
+ sg_size_t used_size = storage->sizeUsed();
XBT_INFO("\t\tFree size: %llu bytes", free_size);
XBT_INFO("\t\tUsed size: %llu bytes", used_size);
- display_storage_properties(&storage);
+ display_storage_properties(storage);
dump_storage_by_name(storage_name);
}
xbt_dict_free(&storage_list);
> [ 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 Disk3 is attached to carl
> [ 1.207952] (server@alice) Storage Disk2 is attached to alice
+> [ 1.207952] (server@alice) Storage Disk4 is attached to denise
> [ 1.207952] (maestro@) Simulated time: 1.20795