class LinkImpl;
class HostImpl;
class StorageImpl;
+ class FileImpl;
}
namespace trace_mgr {
class trace;
typedef simgrid::surf::Resource surf_Resource;
typedef simgrid::surf::HostImpl surf_Host;
typedef simgrid::surf::Action surf_Action;
+typedef simgrid::surf::FileImpl surf_File;
#else
typedef struct surf_Resource surf_Resource;
typedef struct surf_Host surf_Host;
typedef struct surf_Action surf_Action;
+typedef struct surf_File surf_File;
#endif
typedef surf_NetworkModel *surf_network_model_t;
typedef surf_StorageModel *surf_storage_model_t;
typedef surf_Storage* surf_storage_t;
+typedef surf_File* surf_file_t;
/** @ingroup SURF_c_bindings
* \brief Action structure
*/
typedef surf_Action *surf_action_t;
-typedef struct surf_file *surf_file_t;
/** \brief Resource model description
*/
--- /dev/null
+/* Copyright (c) 2017. The SimGrid Team.
+ * All rights reserved. */
+
+/* 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. */
+
+#ifndef SRC_SURF_FILEIMPL_HPP_
+#define SRC_SURF_FILEIMPL_HPP_
+
+namespace simgrid {
+namespace surf {
+
+class FileImpl {
+public:
+ FileImpl(const char* path, const char* mount, sg_size_t size) : path_(path), mount_point_(mount), size_(size) {}
+ ~FileImpl() = default;
+
+ std::string name() { return path_; }
+ const char* cname() { return path_.c_str(); }
+ const char* mount() { return mount_point_.c_str(); }
+ sg_size_t size() { return size_; }
+ void setSize(sg_size_t size) { size_ = size; }
+ void setPosition(sg_size_t size) { current_position_ = size; }
+ void incrPosition(sg_size_t incr) { current_position_ += incr; }
+ sg_size_t tell() { return current_position_; }
+private:
+ std::string path_;
+ std::string mount_point_;
+ sg_size_t size_;
+ sg_size_t current_position_ = 0;
+};
+}
+}
+#endif /* SRC_SURF_FILEIMPL_HPP_ */
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "src/plugins/vm/VirtualMachineImpl.hpp"
+#include "src/surf/FileImpl.hpp"
#include <string>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module");
Action* HostImpl::close(surf_file_t fd)
{
- simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount);
- XBT_DEBUG("CLOSE %s on disk '%s'", fd->name, st->cname());
+ simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount());
+ XBT_DEBUG("CLOSE %s on disk '%s'", fd->cname(), st->cname());
return st->close(fd);
}
Action* HostImpl::read(surf_file_t fd, sg_size_t size)
{
- simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount);
- XBT_DEBUG("READ %s on disk '%s'", fd->name, st->cname());
+ simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount());
+ XBT_DEBUG("READ %s on disk '%s'", fd->cname(), st->cname());
return st->read(fd, size);
}
Action* HostImpl::write(surf_file_t fd, sg_size_t size)
{
- simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount);
- XBT_DEBUG("WRITE %s on disk '%s'", fd->name, st->cname());
+ simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount());
+ XBT_DEBUG("WRITE %s on disk '%s'", fd->cname(), st->cname());
return st->write(fd, size);
}
return -1;
} else {
- simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount);
+ simgrid::surf::StorageImpl* st = findStorageOnMountList(fd->mount());
/* Check if the file is on this storage */
- if (st->content_->find(fd->name) == st->content_->end()) {
- XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name, st->cname());
+ if (st->content_->find(fd->cname()) == st->content_->end()) {
+ XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->cname(), st->cname());
return -1;
} else {
- XBT_DEBUG("UNLINK %s on disk '%s'", fd->name, st->cname());
- st->usedSize_ -= fd->size;
+ XBT_DEBUG("UNLINK %s on disk '%s'", fd->cname(), st->cname());
+ st->usedSize_ -= fd->size();
// Remove the file from storage
- st->content_->erase(fd->name);
+ st->content_->erase(fd->cname());
return 0;
}
sg_size_t HostImpl::getSize(surf_file_t fd)
{
- return fd->size;
+ return fd->size();
}
sg_size_t HostImpl::fileTell(surf_file_t fd)
{
- return fd->current_position;
+ return fd->tell();
}
int HostImpl::fileSeek(surf_file_t fd, sg_offset_t offset, int origin)
{
switch (origin) {
case SEEK_SET:
- fd->current_position = offset;
+ fd->setPosition(offset);
return 0;
case SEEK_CUR:
- fd->current_position += offset;
+ fd->incrPosition(offset);
return 0;
case SEEK_END:
- fd->current_position = fd->size + offset;
+ fd->setPosition(fd->size() + offset);
return 0;
default:
return -1;
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<std::string, sg_size_t>* content = findStorageOnMountList(fd->mount)->content_;
- if (content->find(fd->name) != content->end()) { // src file exists
- 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));
+ if (not strncmp(fd->mount(), fullpath, strlen(fd->mount()))) {
+ std::map<std::string, sg_size_t>* content = findStorageOnMountList(fd->mount())->content_;
+ if (content->find(fd->name()) != content->end()) { // src file exists
+ sg_size_t new_size = content->at(fd->name());
+ content->erase(fd->name());
+ std::string path = std::string(fullpath).substr(strlen(fd->mount()), strlen(fullpath));
content->insert({path.c_str(), new_size});
- XBT_DEBUG("Move file from %s to %s, size '%llu'", fd->name, fullpath, new_size);
+ XBT_DEBUG("Move file from %s to %s, size '%llu'", fd->cname(), fullpath, new_size);
return 0;
} else {
- XBT_WARN("File %s doesn't exist", fd->name);
+ XBT_WARN("File %s doesn't exist", fd->cname());
return -1;
}
} else {
- XBT_WARN("New full path %s is not on the same mount point: %s. Action has been canceled.", fullpath, fd->mount);
+ XBT_WARN("New full path %s is not on the same mount point: %s. Action has been canceled.", fullpath, fd->mount());
return -1;
}
}
e_surf_action_storage_type_t type_;
StorageImpl* storage_;
- surf_file_t file_;
+ FileImpl* file_;
double progress_;
};
}
} s_storage_type_t;
typedef s_storage_type_t* storage_type_t;
-typedef struct surf_file {
- char* name;
- char* mount;
- sg_size_t size;
- sg_size_t current_position;
-} s_surf_file_t;
-
#endif /* STORAGE_INTERFACE_HPP_ */
long int incr = current_progress;
XBT_DEBUG("%s:\n\t progress = %.2f, current_progress = %.2f, incr = %ld, lrint(1) = %ld, lrint(2) = %ld",
- action->file_->name, action->progress_, current_progress, incr,
+ action->file_->cname(), action->progress_, current_progress, incr,
lrint(action->progress_ + current_progress), lrint(action->progress_) + incr);
/* take care of rounding error accumulation */
action->progress_ += current_progress;
action->storage_->usedSize_ += incr; // disk usage
- action->file_->current_position += incr; // current_position
+ action->file_->incrPosition(incr); // current_position
// which becomes the new file size
- action->file_->size = action->file_->current_position;
+ action->file_->setSize(action->file_->tell());
- action->storage_->content_->erase(action->file_->name);
- action->storage_->content_->insert({action->file_->name, action->file_->size});
+ action->storage_->content_->erase(action->file_->cname());
+ action->storage_->content_->insert({action->file_->cname(), action->file_->size()});
}
action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
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);
- file->name = xbt_strdup(path);
- file->size = size;
- file->mount = xbt_strdup(mount);
- file->current_position = 0;
+ FileImpl* file = new FileImpl(path, mount, size);
StorageAction* action = new StorageN11Action(model(), 0, isOff(), this, OPEN);
action->file_ = file;
StorageAction *StorageN11::close(surf_file_t fd)
{
- XBT_DEBUG("\tClose file '%s' size '%llu'", fd->name, fd->size);
+ XBT_DEBUG("\tClose file '%s' size '%llu'", fd->cname(), fd->size());
// unref write actions from storage
for (std::vector<StorageAction*>::iterator it = writeActions_.begin(); it != writeActions_.end();) {
StorageAction *write_action = *it;
++it;
}
}
- free(fd->name);
- free(fd->mount);
- xbt_free(fd);
+ delete fd;
StorageAction* action = new StorageN11Action(model(), 0, isOff(), this, CLOSE);
return action;
}
StorageAction *StorageN11::read(surf_file_t fd, sg_size_t size)
{
- if(fd->current_position + size > fd->size){
- if (fd->current_position > fd->size){
+ if (fd->tell() + size > fd->size()) {
+ if (fd->tell() > fd->size()) {
size = 0;
} else {
- size = fd->size - fd->current_position;
+ size = fd->size() - fd->tell();
}
- fd->current_position = fd->size;
+ fd->setPosition(fd->size());
}
else
- fd->current_position += size;
+ fd->incrPosition(size);
StorageAction* action = new StorageN11Action(model(), size, isOff(), this, READ);
return action;
StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size)
{
- char *filename = fd->name;
- XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size);
+ XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'", fd->cname(), size, fd->size());
StorageAction* action = new StorageN11Action(model(), size, isOff(), this, WRITE);
action->file_ = fd;
/* Substract the part of the file that might disappear from the used sized on the storage element */
- usedSize_ -= (fd->size - fd->current_position);
+ usedSize_ -= (fd->size() - fd->tell());
// If the storage is full before even starting to write
if(usedSize_==size_) {
action->setState(Action::State::failed);
#include <xbt/base.h>
+#include "FileImpl.hpp"
#include "StorageImpl.hpp"
#ifndef STORAGE_N11_HPP_
src/surf/xml/simgrid_dtd.c
src/surf/xml/surfxml_sax_cb.cpp
+ src/surf/FileImpl.hpp
src/surf/StorageImpl.hpp
src/surf/storage_n11.hpp
src/surf/surf_interface.hpp