Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
WIP. crude surf_file_t to FileImpl conversion
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 26 Jun 2017 14:50:01 +0000 (16:50 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 26 Jun 2017 14:50:01 +0000 (16:50 +0200)
include/simgrid/forward.h
src/include/surf/surf.h
src/surf/FileImpl.hpp [new file with mode: 0644]
src/surf/HostImpl.cpp
src/surf/StorageImpl.hpp
src/surf/storage_n11.cpp
src/surf/storage_n11.hpp
tools/cmake/DefinePackages.cmake

index 96e8194..3776800 100644 (file)
@@ -47,6 +47,7 @@ namespace surf {
   class LinkImpl;
   class HostImpl;
   class StorageImpl;
   class LinkImpl;
   class HostImpl;
   class StorageImpl;
+  class FileImpl;
 }
 namespace trace_mgr {
   class trace;
 }
 namespace trace_mgr {
   class trace;
index 22b5e44..191c350 100644 (file)
@@ -54,6 +54,7 @@ typedef simgrid::surf::StorageModel surf_StorageModel;
 typedef simgrid::surf::Resource surf_Resource;
 typedef simgrid::surf::HostImpl surf_Host;
 typedef simgrid::surf::Action surf_Action;
 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
 
 
 #else
 
@@ -67,6 +68,7 @@ typedef struct surf_StorageModel surf_StorageModel;
 typedef struct surf_Resource surf_Resource;
 typedef struct surf_Host surf_Host;
 typedef struct surf_Action surf_Action;
 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
 
 
 #endif
 
@@ -82,6 +84,7 @@ typedef surf_HostModel *surf_host_model_t;
 typedef surf_NetworkModel *surf_network_model_t;
 typedef surf_StorageModel *surf_storage_model_t;
 typedef surf_Storage* surf_storage_t;
 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
 
 /** @ingroup SURF_c_bindings
  *  \brief Action structure
@@ -93,7 +96,6 @@ typedef surf_Storage* surf_storage_t;
  */
 typedef surf_Action *surf_action_t;
 
  */
 typedef surf_Action *surf_action_t;
 
-typedef struct surf_file *surf_file_t;
 
 /** \brief Resource model description
  */
 
 /** \brief Resource model description
  */
diff --git a/src/surf/FileImpl.hpp b/src/surf/FileImpl.hpp
new file mode 100644 (file)
index 0000000..938a1b5
--- /dev/null
@@ -0,0 +1,34 @@
+/* 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_ */
index fa047d2..9a80433 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/plugins/vm/VirtualMachineImpl.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");
 #include <string>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module");
@@ -114,22 +115,22 @@ void HostImpl::getAttachedStorageList(std::vector<const char*>* storages)
 
 Action* HostImpl::close(surf_file_t fd)
 {
 
 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)
 {
   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)
 {
   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 st->write(fd, size);
 }
 
@@ -140,17 +141,17 @@ int HostImpl::unlink(surf_file_t fd)
     return -1;
   } else {
 
     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 */
     /* 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 {
       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
 
       // Remove the file from storage
-      st->content_->erase(fd->name);
+      st->content_->erase(fd->cname());
 
       return 0;
     }
 
       return 0;
     }
@@ -159,25 +160,25 @@ int HostImpl::unlink(surf_file_t fd)
 
 sg_size_t HostImpl::getSize(surf_file_t fd)
 {
 
 sg_size_t HostImpl::getSize(surf_file_t fd)
 {
-  return fd->size;
+  return fd->size();
 }
 
 sg_size_t HostImpl::fileTell(surf_file_t fd)
 {
 }
 
 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:
 }
 
 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:
     return 0;
   case SEEK_CUR:
-    fd->current_position += offset;
+    fd->incrPosition(offset);
     return 0;
   case SEEK_END:
     return 0;
   case SEEK_END:
-    fd->current_position = fd->size + offset;
+    fd->setPosition(fd->size() + offset);
     return 0;
   default:
     return -1;
     return 0;
   default:
     return -1;
@@ -187,21 +188,21 @@ int HostImpl::fileSeek(surf_file_t fd, sg_offset_t offset, int origin)
 int HostImpl::fileMove(surf_file_t fd, const char* fullpath)
 {
   /* Check if the new full path is on the same mount point */
 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});
       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 {
       return 0;
     } else {
-      XBT_WARN("File %s doesn't exist", fd->name);
+      XBT_WARN("File %s doesn't exist", fd->cname());
       return -1;
     }
   } else {
       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;
   }
 }
     return -1;
   }
 }
index fbb7449..4cfb23d 100644 (file)
@@ -223,7 +223,7 @@ public:
 
   e_surf_action_storage_type_t type_;
   StorageImpl* storage_;
 
   e_surf_action_storage_type_t type_;
   StorageImpl* storage_;
-  surf_file_t file_;
+  FileImpl* file_;
   double progress_;
 };
 }
   double progress_;
 };
 }
@@ -239,11 +239,4 @@ typedef struct s_storage_type {
 } s_storage_type_t;
 typedef s_storage_type_t* storage_type_t;
 
 } 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_ */
 #endif /* STORAGE_INTERFACE_HPP_ */
index 3d90a4e..579ea96 100644 (file)
@@ -102,7 +102,7 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
       long int incr = current_progress;
 
       XBT_DEBUG("%s:\n\t progress =  %.2f, current_progress = %.2f, incr = %ld, lrint(1) = %ld, lrint(2) = %ld",
       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 */
                 lrint(action->progress_ + current_progress), lrint(action->progress_) + incr);
 
       /* take care of rounding error accumulation */
@@ -112,12 +112,12 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
       action->progress_ += current_progress;
 
       action->storage_->usedSize_ += incr;     // disk usage
       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
       //  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);
     }
 
     action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta);
@@ -162,11 +162,7 @@ StorageAction *StorageN11::open(const char* mount, const char* path)
     content_->insert({path, size});
     XBT_DEBUG("File '%s' was not found, file created.",path);
   }
     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* action = new StorageN11Action(model(), 0, isOff(), this, OPEN);
   action->file_         = file;
@@ -176,7 +172,7 @@ StorageAction *StorageN11::open(const char* mount, const char* path)
 
 StorageAction *StorageN11::close(surf_file_t fd)
 {
 
 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;
   // unref write actions from storage
   for (std::vector<StorageAction*>::iterator it = writeActions_.begin(); it != writeActions_.end();) {
     StorageAction *write_action = *it;
@@ -187,25 +183,23 @@ StorageAction *StorageN11::close(surf_file_t fd)
       ++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)
 {
   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 = 0;
     } else {
-      size = fd->size - fd->current_position;
+      size = fd->size() - fd->tell();
     }
     }
-    fd->current_position = fd->size;
+    fd->setPosition(fd->size());
   }
   else
   }
   else
-    fd->current_position += size;
+    fd->incrPosition(size);
 
   StorageAction* action = new StorageN11Action(model(), size, isOff(), this, READ);
   return action;
 
   StorageAction* action = new StorageN11Action(model(), size, isOff(), this, READ);
   return action;
@@ -213,13 +207,12 @@ StorageAction *StorageN11::read(surf_file_t fd, sg_size_t size)
 
 StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size)
 {
 
 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 */
 
   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);
   // If the storage is full before even starting to write
   if(usedSize_==size_) {
     action->setState(Action::State::failed);
index 72703a1..16016d2 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <xbt/base.h>
 
 
 #include <xbt/base.h>
 
+#include "FileImpl.hpp"
 #include "StorageImpl.hpp"
 
 #ifndef STORAGE_N11_HPP_
 #include "StorageImpl.hpp"
 
 #ifndef STORAGE_N11_HPP_
index 54e6223..4c2e631 100644 (file)
@@ -53,6 +53,7 @@ set(EXTRA_DIST
   src/surf/xml/simgrid_dtd.c
   src/surf/xml/surfxml_sax_cb.cpp
 
   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
   src/surf/StorageImpl.hpp
   src/surf/storage_n11.hpp
   src/surf/surf_interface.hpp