From: Frederic Suter Date: Mon, 10 Jul 2017 09:43:04 +0000 (+0200) Subject: move some of the file mgmt logic out of the storage model X-Git-Tag: v3_17~416^2~5 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0342cac8cbf7d74cf6efa11b33abd8cb6d87cc3c move some of the file mgmt logic out of the storage model --- diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index f2012bf066..160224e35d 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -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; } } diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 8091af1b8d..3061a60dc5 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -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 diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 6b5addb4c3..819b1f59f6 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -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); } /********** diff --git a/src/surf/storage_n11.hpp b/src/surf/storage_n11.hpp index bb7e0eeab4..2da0174a66 100644 --- a/src/surf/storage_n11.hpp +++ b/src/surf/storage_n11.hpp @@ -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); };