/** 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. */
/** 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;
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);
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<void(s4u::Storage&)> onCreation;
static simgrid::xbt::signal<void(s4u::Storage&)> onDestruction;
Host* attached_to_ = nullptr;
- surf::StorageImpl* const pimpl_ = nullptr;
private:
+ surf::StorageImpl* const pimpl_ = nullptr;
std::string name_;
void* userdata_ = nullptr;
};
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;
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;
#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()
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;
sg_size_t Storage::getSize()
{
- return pimpl_->size_;
+ return pimpl_->getSize();
}
xbt_dict_t Storage::getProperties()
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);
* 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 {
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<std::string, sg_size_t>* content = location_->content_;
+ location_ = st->getImpl();
+ std::map<std::string, sg_size_t>* content = location_->getContent();
// if file does not exist create an empty file
if (content->find(path) != content->end())
size_ = content->at(path);
/* 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;
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 {
location_->usedSize_ -= size_;
// Remove the file from storage
- location_->content_->erase(path_);
+ location_->getContent()->erase(path_);
return 0;
}
{
/* 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<std::string, sg_size_t>* content = location_->content_;
+ std::map<std::string, sg_size_t>* content = location_->getContent();
if (content->find(path_) != content->end()) { // src file exists
sg_size_t new_size = content->at(path_);
content->erase(path_);
void HostImpl::getAttachedStorageList(std::vector<const char*>* storages)
{
for (auto s : storage_)
- if (s.second->attach_ == piface_->getCname())
+ if (s.second->getHost() == piface_->getCname())
storages->push_back(s.second->piface_.getName());
}
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);
void turnOn() override;
void turnOff() override;
- std::map<std::string, sg_size_t>* 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
*
* @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<std::string, sg_size_t>* parseContent(const char* filename);
static std::unordered_map<std::string, StorageImpl*>* storages;
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<std::string, sg_size_t>* 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_;
};
/**********
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());
}
}
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<StorageAction*>(&*it);
// 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);
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)) ||