Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 27 Jun 2017 17:45:36 +0000 (19:45 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 27 Jun 2017 17:45:36 +0000 (19:45 +0200)
include/simgrid/forward.h
src/include/surf/surf.h
src/simix/smx_io.cpp
src/surf/FileImpl.hpp [new file with mode: 0644]
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/StorageImpl.hpp
src/surf/storage_n11.cpp
src/surf/storage_n11.hpp
src/surf/surf_c_bindings.cpp
tools/cmake/DefinePackages.cmake

index 96e8194..3776800 100644 (file)
@@ -47,6 +47,7 @@ namespace surf {
   class LinkImpl;
   class HostImpl;
   class StorageImpl;
+  class FileImpl;
 }
 namespace trace_mgr {
   class trace;
index 22b5e44..ef5036b 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::FileImpl surf_File;
 
 #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_File surf_File;
 
 #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_File* surf_file_t;
 
 /** @ingroup SURF_c_bindings
  *  \brief Action structure
@@ -93,7 +96,6 @@ typedef surf_Storage* surf_storage_t;
  */
 typedef surf_Action *surf_action_t;
 
-typedef struct surf_file *surf_file_t;
 
 /** \brief Resource model description
  */
@@ -190,16 +192,6 @@ XBT_PUBLIC(sg_size_t) surf_host_get_used_size(sg_host_t resource, const char* na
  */
 XBT_PUBLIC(int) surf_host_unlink(sg_host_t host, surf_file_t fd);
 
-/**
- * @brief Get the size of a file on a host
- *
- * @param host The surf host
- * @param fd The file descriptor
- *
- * @return The size in bytes of the file
- */
-XBT_PUBLIC(size_t) surf_host_get_size(sg_host_t host, surf_file_t fd);
-
 /**
  * @brief Get the current position of the file descriptor
  *
@@ -236,33 +228,6 @@ XBT_PUBLIC(int) surf_host_file_move(sg_host_t host, surf_file_t fd, const char*
  */
 XBT_PUBLIC(int) surf_host_file_seek(sg_host_t host, surf_file_t fd, sg_offset_t offset, int origin);
 
-/**
- * @brief Get the size in bytes of a storage
- *
- * @param resource The surf storage
- * @return The size in bytes of the storage
- */
-XBT_PUBLIC(sg_size_t) surf_storage_get_size(surf_storage_t resource);
-
-/**
- * @brief Get the available size in bytes of a storage
- *
- * @param resource The surf storage
- * @return The available size in bytes of the storage
- */
-XBT_PUBLIC(sg_size_t) surf_storage_get_free_size(surf_storage_t resource);
-
-/**
- * @brief Get the size in bytes of a storage
- *
- * @param resource The surf storage
- * @return The used size in bytes of the storage
- */
-XBT_PUBLIC(sg_size_t) surf_storage_get_used_size(surf_storage_t resource);
-
-/** @brief return the properties set associated to that storage */
-XBT_PUBLIC(xbt_dict_t) surf_storage_get_properties(surf_storage_t resource);
-
 /**
  * @brief [brief description]
  * @details [long description]
@@ -288,25 +253,6 @@ XBT_PUBLIC(double) surf_network_action_get_latency_limited(surf_action_t action)
  */
 XBT_PUBLIC(surf_file_t) surf_storage_action_get_file(surf_action_t action);
 
-/**
- * @brief Get the result dictionary of an ls action
- *
- * @param action The surf storage action
- * @return The dictionry listing a path
- */
-XBT_PUBLIC(xbt_dict_t) surf_storage_action_get_ls_dict(surf_action_t action);
-
-
-/**
- * @brief Get the host the storage is attached to
- *
- * @param resource The surf storage
- * @return The host name
- * may not exist.
- */
-XBT_PUBLIC(const char*) surf_storage_get_host(surf_storage_t resource);
-XBT_PUBLIC(const char*) surf_storage_get_name(surf_storage_t resource);
-
 /** @} */
 
 /**************************************/
index eb041ec..ee23b9d 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "simgrid/s4u/Host.hpp"
 #include "simgrid/s4u/Storage.hpp"
+#include "src/surf/FileImpl.hpp"
 #include "src/surf/StorageImpl.hpp"
 
 #include <mc/mc.h>
@@ -127,8 +128,7 @@ sg_size_t simcall_HANDLER_file_get_size(smx_simcall_t simcall, smx_file_t fd)
 
 sg_size_t SIMIX_file_get_size(smx_actor_t process, smx_file_t fd)
 {
-  sg_host_t host = process->host;
-  return  surf_host_get_size(host, fd->surf_file);
+  return fd->surf_file->size();
 }
 
 sg_size_t simcall_HANDLER_file_tell(smx_simcall_t simcall, smx_file_t fd)
@@ -138,8 +138,7 @@ sg_size_t simcall_HANDLER_file_tell(smx_simcall_t simcall, smx_file_t fd)
 
 sg_size_t SIMIX_file_tell(smx_actor_t process, smx_file_t fd)
 {
-  sg_host_t host = process->host;
-  return  surf_host_file_tell(host, fd->surf_file);
+  return fd->surf_file->tell();
 }
 
 int simcall_HANDLER_file_seek(smx_simcall_t simcall, smx_file_t fd, sg_offset_t offset, int origin)
diff --git a/src/surf/FileImpl.hpp b/src/surf/FileImpl.hpp
new file mode 100644 (file)
index 0000000..e8ae85b
--- /dev/null
@@ -0,0 +1,37 @@
+/* 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_
+
+#include "surf/surf.h"
+#include <string>
+
+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..b636340 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"
+#include "src/surf/FileImpl.hpp"
 #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)
 {
-  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);
 }
 
@@ -140,44 +141,34 @@ int HostImpl::unlink(surf_file_t fd)
     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;
-}
-
-sg_size_t HostImpl::fileTell(surf_file_t fd)
-{
-  return fd->current_position;
-}
-
 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;
@@ -187,21 +178,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 */
-  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;
   }
 }
index d22e5d4..d57d519 100644 (file)
@@ -89,14 +89,6 @@ public:
    */
   virtual int unlink(surf_file_t fd);
 
-  /**
-   * @brief Get the size in bytes of the file
-   *
-   * @param fd The file descriptor to read
-   * @return The size in bytes of the file
-   */
-  virtual sg_size_t getSize(surf_file_t fd);
-
   /**
    * @brief Read a file
    *
@@ -115,14 +107,6 @@ public:
    */
   virtual Action* write(surf_file_t fd, sg_size_t size);
 
-  /**
-   * @brief Get the current position of the file descriptor
-   *
-   * @param fd The file descriptor
-   * @return The current position of the file descriptor
-   */
-  virtual sg_size_t fileTell(surf_file_t fd);
-
   /**
    * @brief Set the position indicator associated with the file descriptor to a new position
    * @details [long description]
index fbb7449..4cfb23d 100644 (file)
@@ -223,7 +223,7 @@ public:
 
   e_surf_action_storage_type_t type_;
   StorageImpl* storage_;
-  surf_file_t file_;
+  FileImpl* file_;
   double progress_;
 };
 }
@@ -239,11 +239,4 @@ typedef struct s_storage_type {
 } 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_ */
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",
-                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 */
@@ -112,12 +112,12 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta)
       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);
@@ -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);
   }
-  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;
@@ -176,7 +172,7 @@ StorageAction *StorageN11::open(const char* mount, const char* path)
 
 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;
@@ -187,25 +183,23 @@ StorageAction *StorageN11::close(surf_file_t fd)
       ++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;
@@ -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)
 {
-  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);
index 72703a1..16016d2 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <xbt/base.h>
 
+#include "FileImpl.hpp"
 #include "StorageImpl.hpp"
 
 #ifndef STORAGE_N11_HPP_
index fb3169c..9e2e4c5 100644 (file)
@@ -173,10 +173,6 @@ int surf_host_unlink(sg_host_t host, surf_file_t fd){
   return host->pimpl_->unlink(fd);
 }
 
-size_t surf_host_get_size(sg_host_t host, surf_file_t fd){
-  return host->pimpl_->getSize(fd);
-}
-
 surf_action_t surf_host_read(sg_host_t host, surf_file_t fd, sg_size_t size){
   return host->pimpl_->read(fd, size);
 }
@@ -185,10 +181,6 @@ surf_action_t surf_host_write(sg_host_t host, surf_file_t fd, sg_size_t size){
   return host->pimpl_->write(fd, size);
 }
 
-size_t surf_host_file_tell(sg_host_t host, surf_file_t fd){
-  return host->pimpl_->fileTell(fd);
-}
-
 int surf_host_file_seek(sg_host_t host, surf_file_t fd,
                                sg_offset_t offset, int origin){
   return host->pimpl_->fileSeek(fd, offset, origin);
@@ -198,36 +190,6 @@ int surf_host_file_move(sg_host_t host, surf_file_t fd, const char* fullpath){
   return host->pimpl_->fileMove(fd, fullpath);
 }
 
-sg_size_t surf_storage_get_size(surf_storage_t resource)
-{
-  return static_cast<simgrid::surf::StorageImpl*>(resource)->size_;
-}
-
-sg_size_t surf_storage_get_free_size(surf_storage_t resource)
-{
-  return static_cast<simgrid::surf::StorageImpl*>(resource)->getFreeSize();
-}
-
-sg_size_t surf_storage_get_used_size(surf_storage_t resource)
-{
-  return static_cast<simgrid::surf::StorageImpl*>(resource)->getUsedSize();
-}
-
-xbt_dict_t surf_storage_get_properties(surf_storage_t resource)
-{
-  return static_cast<simgrid::surf::StorageImpl*>(resource)->getProperties();
-}
-
-const char* surf_storage_get_host(surf_storage_t resource)
-{
-  return static_cast<simgrid::surf::StorageImpl*>(resource)->attach_.c_str();
-}
-
-const char* surf_storage_get_name(surf_storage_t resource)
-{
-  return static_cast<simgrid::surf::StorageImpl*>(resource)->cname();
-}
-
 void surf_cpu_action_set_bound(surf_action_t action, double bound) {
   static_cast<simgrid::surf::CpuAction*>(action)->setBound(bound);
 }
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/FileImpl.hpp
   src/surf/StorageImpl.hpp
   src/surf/storage_n11.hpp
   src/surf/surf_interface.hpp