Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
File mgmt looks like a plugin now \o/
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 10 Jul 2017 11:05:14 +0000 (13:05 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 10 Jul 2017 11:05:14 +0000 (13:05 +0200)
include/simgrid/s4u/File.hpp
src/kernel/activity/SynchroIo.hpp
src/msg/msg_io.cpp
src/s4u/s4u_file.cpp
src/simix/smx_io.cpp
src/surf/FileImpl.cpp
src/surf/FileImpl.hpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp

index 11167ff..6736f85 100644 (file)
@@ -65,7 +65,6 @@ public:
 
   /** Remove a file from disk */
   int unlink();
-  int unlink(sg_host_t host);
 
   /* FIXME: add these to the S4U API:
   XBT_PUBLIC(const char *) MSG_file_get_name(msg_file_t file);
index 7a229bf..2b6ab93 100644 (file)
@@ -20,7 +20,6 @@ public:
   void resume() override;
   void post() override;
 
-  sg_host_t host        = nullptr;
   surf_action_t surf_io = nullptr;
   };
 
index b479145..0203ed7 100644 (file)
@@ -200,10 +200,7 @@ int MSG_file_close(msg_file_t fd)
  */
 msg_error_t MSG_file_unlink(msg_file_t fd)
 {
-  /* Find the host where the file is physically located (remote or local)*/
-  msg_storage_t storage_src = simgrid::s4u::Storage::byName(fd->storageId);
-  msg_host_t attached_host  = storage_src->getHost();
-  fd->unlink(attached_host);
+  fd->unlink();
   delete fd;
   return MSG_OK;
 }
index ad9f634..db1c5b2 100644 (file)
@@ -91,18 +91,12 @@ sg_size_t File::tell()
 
 void File::move(const char* fullpath)
 {
-  sg_host_t host = Host::current();
-  simgrid::simix::kernelImmediate([this, host, fullpath] { pimpl_->move(host, fullpath); });
+  simgrid::simix::kernelImmediate([this, fullpath] { pimpl_->move(fullpath); });
 }
 
 int File::unlink()
 {
-  return unlink(Host::current());
-}
-
-int File::unlink(sg_host_t host)
-{
-  return simgrid::simix::kernelImmediate([this, host] { return pimpl_->unlink(host); });
+  return simgrid::simix::kernelImmediate([this] { return pimpl_->unlink(); });
 }
 
 }} // namespace simgrid::s4u
index 1b31af0..9d6ccb2 100644 (file)
@@ -36,8 +36,7 @@ smx_activity_t SIMIX_file_read(surf_file_t file, sg_size_t size, sg_host_t host)
     THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->getCname());
 
   simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
-  synchro->host = host;
-  synchro->surf_io                           = host->pimpl_->read(file, size);
+  synchro->surf_io                           = file->read(size);
 
   synchro->surf_io->setData(synchro);
   XBT_DEBUG("Create io synchro %p", synchro);
@@ -59,8 +58,7 @@ smx_activity_t SIMIX_file_write(surf_file_t file, sg_size_t size, sg_host_t host
     THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->getCname());
 
   simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
-  synchro->host = host;
-  synchro->surf_io                           = host->pimpl_->write(file, size);
+  synchro->surf_io                           = file->write(size);
   synchro->surf_io->setData(synchro);
   XBT_DEBUG("Create io synchro %p", synchro);
 
index 5c7cda0..fd81b4a 100644 (file)
@@ -14,7 +14,8 @@ namespace surf {
 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());
-  std::map<std::string, sg_size_t>* content = st->pimpl_->content_;
+  location_ = st->pimpl_;
+  std::map<std::string, sg_size_t>* content = location_->content_;
   // if file does not exist create an empty file
   if (content->find(path) != content->end())
     size_ = content->at(path);
@@ -25,6 +26,37 @@ FileImpl::FileImpl(sg_storage_t st, std::string path, std::string mount) : path_
   }
 }
 
+Action* FileImpl::read(sg_size_t size)
+{
+  XBT_DEBUG("READ %s on disk '%s'", cname(), location_->cname());
+  if (current_position_ + size > size_) {
+    if (current_position_ > size_) {
+      size = 0;
+    } else {
+      size = size_ - current_position_;
+    }
+    current_position_ = size_;
+  } else
+    current_position_ += size;
+
+  return location_->read(size);
+}
+
+Action* FileImpl::write(sg_size_t size)
+{
+  XBT_DEBUG("WRITE %s on disk '%s'. size '%llu/%llu'", cname(), location_->cname(), size, size_);
+
+  StorageAction* action = location_->write(size);
+  action->file_         = this;
+  /* 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_) {
+    action->setState(Action::State::failed);
+  }
+  return action;
+}
+
 int FileImpl::seek(sg_offset_t offset, int origin)
 {
   switch (origin) {
@@ -42,29 +74,28 @@ int FileImpl::seek(sg_offset_t offset, int origin)
   }
 }
 
-int FileImpl::unlink(sg_host_t host)
+int FileImpl::unlink()
 {
-  simgrid::surf::StorageImpl* st = host->pimpl_->findStorageOnMountList(mount_point_.c_str());
   /* Check if the file is on this storage */
-  if (st->content_->find(path_) == st->content_->end()) {
-    XBT_WARN("File %s is not on disk %s. Impossible to unlink", cname(), st->cname());
+  if (location_->content_->find(path_) == location_->content_->end()) {
+    XBT_WARN("File %s is not on disk %s. Impossible to unlink", cname(), location_->cname());
     return -1;
   } else {
-    XBT_DEBUG("UNLINK %s on disk '%s'", cname(), st->cname());
-    st->usedSize_ -= size_;
+    XBT_DEBUG("UNLINK %s on disk '%s'", cname(), location_->cname());
+    location_->usedSize_ -= size_;
 
     // Remove the file from storage
-    st->content_->erase(path_);
+    location_->content_->erase(path_);
 
     return 0;
   }
 }
 
-void FileImpl::move(sg_host_t host, const char* fullpath)
+void FileImpl::move(const char* fullpath)
 {
   /* 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 = host->pimpl_->findStorageOnMountList(mount_point_.c_str())->content_;
+    std::map<std::string, sg_size_t>* content = location_->content_;
     if (content->find(path_) != content->end()) { // src file exists
       sg_size_t new_size = content->at(path_);
       content->erase(path_);
index b23a10f..0478ea1 100644 (file)
@@ -27,10 +27,13 @@ public:
   void incrPosition(sg_size_t incr) { current_position_ += incr; }
   sg_size_t tell() { return current_position_; }
   int seek(sg_offset_t offset, int origin);
-  int unlink(sg_host_t host);
-  void move(sg_host_t host, const char* fullpath);
+  int unlink();
+  void move(const char* fullpath);
+  Action* read(sg_size_t size);
+  Action* write(sg_size_t size);
 
 private:
+  StorageImpl* location_;
   std::string path_;
   std::string mount_point_;
   sg_size_t size_;
index 160224e..76576cd 100644 (file)
@@ -100,15 +100,6 @@ HostImpl::HostImpl(s4u::Host* host) : piface_(host)
   piface_->pimpl_ = this;
 }
 
-simgrid::surf::StorageImpl* HostImpl::findStorageOnMountList(const char* mount)
-{
-  XBT_DEBUG("Search for storage name '%s' on '%s'", mount, piface_->getCname());
-  if (storage_.find(mount) == storage_.end())
-    xbt_die("Can't find mount '%s' for '%s'", mount, piface_->getCname());
-
-  return storage_.at(mount);
-}
-
 void HostImpl::getAttachedStorageList(std::vector<const char*>* storages)
 {
   for (auto s : storage_)
@@ -116,38 +107,5 @@ void HostImpl::getAttachedStorageList(std::vector<const char*>* storages)
       storages->push_back(s.second->piface_.getName());
 }
 
-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->cname(), st->cname());
-  if (fd->tell() + size > fd->size()) {
-    if (fd->tell() > fd->size()) {
-      size = 0;
-    } else {
-      size = fd->size() - fd->tell();
-    }
-    fd->setPosition(fd->size());
-  } else
-    fd->incrPosition(size);
-
-  return st->read(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'. size '%llu/%llu'", fd->cname(), st->cname(), size, fd->size());
-
-  StorageAction* action = st->write(size);
-  action->file_         = fd;
-  /* Substract the part of the file that might disappear from the used sized on the storage element */
-  st->usedSize_ -= (fd->size() - fd->tell());
-  // If the storage is full before even starting to write
-  if (st->usedSize_ >= st->size_) {
-    action->setState(Action::State::failed);
-  }
-  return action;
-}
-
 }
 }
index 73d033c..7d53cd0 100644 (file)
@@ -66,30 +66,9 @@ public:
   explicit HostImpl(s4u::Host* host);
   virtual ~HostImpl() = default;
 
-  /** @brief Return the storage of corresponding mount point */
-  virtual simgrid::surf::StorageImpl* findStorageOnMountList(const char* storage);
-
-  /** @brief Get the xbt_dynar_t of storages attached to the Host */
+  /** @brief Get the vector of storages (by names) attached to the Host */
   virtual void getAttachedStorageList(std::vector<const char*>* storages);
 
-  /**
-   * @brief Read a file
-   *
-   * @param fd The file descriptor to read
-   * @param size The size in bytes to read
-   * @return The StorageAction corresponding to the reading
-   */
-  virtual Action* read(surf_file_t fd, sg_size_t size);
-
-  /**
-   * @brief Write a file
-   *
-   * @param fd The file descriptor to write
-   * @param size The size in bytes to write
-   * @return The StorageAction corresponding to the writing
-   */
-  virtual Action* write(surf_file_t fd, sg_size_t size);
-
   std::map<std::string, simgrid::surf::StorageImpl*> storage_;
   simgrid::s4u::Host* piface_ = nullptr;