Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move some of the file mgmt logic out of the storage model
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 10 Jul 2017 09:43:04 +0000 (11:43 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 10 Jul 2017 09:57:38 +0000 (11:57 +0200)
src/surf/HostImpl.cpp
src/surf/StorageImpl.hpp
src/surf/storage_n11.cpp
src/surf/storage_n11.hpp

index f2012bf..160224e 100644 (file)
@@ -120,14 +120,33 @@ 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());
-  return st->read(fd, size);
+  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'", fd->cname(), st->cname());
-  return st->write(fd, size);
+  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 8091af1..3061a60 100644 (file)
@@ -113,20 +113,18 @@ public:
   /**
    * @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 StorageAction* read(surf_file_t fd, sg_size_t size) = 0;
+  virtual StorageAction* read(sg_size_t size) = 0;
 
   /**
    * @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 StorageAction* write(surf_file_t fd, sg_size_t size) = 0;
+  virtual StorageAction* write(sg_size_t size) = 0;
 
   /**
    * @brief Get the content of the current Storage
index 6b5addb..819b1f5 100644 (file)
@@ -137,36 +137,14 @@ StorageN11::StorageN11(StorageModel* model, const char* name, lmm_system_t maxmi
   simgrid::s4u::Storage::onCreation(this->piface_);
 }
 
-StorageAction *StorageN11::read(surf_file_t fd, sg_size_t size)
+StorageAction* StorageN11::read(sg_size_t size)
 {
-  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);
-
-  StorageAction* action = new StorageN11Action(model(), size, isOff(), this, READ);
-  return action;
+  return new StorageN11Action(model(), size, isOff(), this, READ);
 }
 
-StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size)
+StorageAction* StorageN11::write(sg_size_t 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->tell());
-  // If the storage is full before even starting to write
-  if(usedSize_==size_) {
-    action->setState(Action::State::failed);
-  }
-  return action;
+  return new StorageN11Action(model(), size, isOff(), this, WRITE);
 }
 
 /**********
index bb7e0ee..2da0174 100644 (file)
@@ -46,8 +46,8 @@ public:
   virtual ~StorageN11() = default;
   StorageAction *open(const char* mount, const char* path);
   StorageAction *ls(const char *path);
-  StorageAction* read(surf_file_t fd, sg_size_t size);
-  StorageAction* write(surf_file_t fd, sg_size_t size);
+  StorageAction* read(sg_size_t size);
+  StorageAction* write(sg_size_t size);
   void rename(const char *src, const char *dest);
 };