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 ***********************************/
-/* 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
#ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_
#define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
+#include <map>
+#include <simgrid/s4u/forward.hpp>
+#include <simgrid/simix.h>
#include <string>
-
-#include <boost/unordered_map.hpp>
-
+#include <unordered_map>
#include <xbt/base.h>
-#include <simgrid/simix.h>
-#include <simgrid/s4u/forward.hpp>
-
namespace simgrid {
namespace s4u {
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<std::string, sg_size_t*>* content();
+ std::unordered_map<std::string, Storage*>* 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();
void *userdata() {return userdata_;}
private:
- static boost::unordered_map<std::string, Storage *> *storages_;
+ static std::unordered_map<std::string, Storage*>* 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 */
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);
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);
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());
-/* 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
#include "simgrid/s4u/storage.hpp"
#include "simgrid/simix.hpp"
#include "src/surf/storage_interface.hpp"
-
#include "xbt/lib.h"
+#include <unordered_map>
+
extern xbt_lib_t storage_lib;
namespace simgrid {
namespace s4u {
-boost::unordered_map <std::string, Storage *> *Storage::storages_ = new boost::unordered_map<std::string, Storage*> ();
+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)
{
- 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) {
return name_.c_str();
}
+const char* Storage::host()
+{
+ return hostname_.c_str();
+}
+
sg_size_t Storage::sizeFree()
{
return simcall_storage_get_free_size(pimpl_);
return simcall_storage_get_properties(pimpl_);
}
+const char* Storage::property(const char* key)
+{
+ return static_cast<const char*>(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<std::string, sg_size_t*>* Storage::content()
{
return simgrid::simix::kernelImmediate(
[this] { return static_cast<simgrid::surf::Storage*>(surf_storage_resource_priv(this->pimpl_))->getContent(); });
}
+std::unordered_map<std::string, Storage*>* Storage::allStorages()
+{
+ return storages_;
+}
+
} /* namespace s4u */
} /* namespace simgrid */
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);
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<simgrid::kernel::activity::Io*>(synchro);
Action* HostImpl::open(const char* fullpath)
{
-
simgrid::surf::Storage* st = nullptr;
size_t longest_prefix_length = 0;
std::string path;
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<std::string, simgrid::s4u::Storage*>* 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)
{
}
storage_info(simgrid::s4u::this_actor::host());
- // dump_platform_storages();
+ dump_platform_storages();
}
int main(int argc, char* argv[])
> [ 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