From 968499473499987433444f45637b875cbba8e67c Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 22 Nov 2017 11:28:23 +0100 Subject: [PATCH] remove FileImpl \o/ --- examples/msg/io-file/io-file.tesh | 6 +- examples/msg/io-remote/io-remote.tesh | 12 ++-- include/simgrid/forward.h | 1 - include/simgrid/s4u/File.hpp | 14 ++-- src/msg/msg_io.cpp | 2 +- src/s4u/s4u_file.cpp | 100 ++++++++++++++++++-------- src/simix/smx_io.cpp | 1 - src/surf/FileImpl.cpp | 84 ---------------------- src/surf/FileImpl.hpp | 42 ----------- src/surf/HostImpl.cpp | 1 - src/surf/storage_n11.hpp | 1 - src/xbt/log.c | 1 - tools/cmake/DefinePackages.cmake | 2 - 13 files changed, 89 insertions(+), 178 deletions(-) delete mode 100644 src/surf/FileImpl.cpp delete mode 100644 src/surf/FileImpl.hpp diff --git a/examples/msg/io-file/io-file.tesh b/examples/msg/io-file/io-file.tesh index e0483eb297..d3700afca5 100644 --- a/examples/msg/io-file/io-file.tesh +++ b/examples/msg/io-file/io-file.tesh @@ -5,9 +5,6 @@ $ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r] > [ 0.000000] (1:host@alice) Open file 'c:\Windows\setupact.log' > [ 0.000000] (2:host@bob) Open file '/home/doc/simgrid/examples/platforms/nancy.xml' > [ 0.000000] (3:host@carl) Open file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' -> [ 0.000000] (1:host@alice) Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000 -> [ 0.000000] (2:host@bob) Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36933331 / 536870912000 -> [ 0.000000] (3:host@carl) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36933331 / 536870912000 > [ 0.000000] (4:host@denise) File Descriptor information: > Full path: '/home/doc/simgrid/examples/platforms/g5k.xml' > Size: 17028 @@ -16,6 +13,9 @@ $ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r] > Storage Type: 'single_SSD' > File Descriptor Id: 0 > [ 0.000000] (4:host@denise) Open file '/home/doc/simgrid/examples/platforms/g5k.xml' +> [ 0.000000] (1:host@alice) Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000 +> [ 0.000000] (2:host@bob) Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36933331 / 536870912000 +> [ 0.000000] (3:host@carl) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36933331 / 536870912000 > [ 0.000000] (4:host@denise) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13221994 / 536870912000 > [ 0.000040] (2:host@bob) Have read 4028 from '/home/doc/simgrid/examples/platforms/nancy.xml' > [ 0.000085] (4:host@denise) Have read 17028 from '/home/doc/simgrid/examples/platforms/g5k.xml' diff --git a/examples/msg/io-remote/io-remote.tesh b/examples/msg/io-remote/io-remote.tesh index 46b251e2e5..390369c62f 100644 --- a/examples/msg/io-remote/io-remote.tesh +++ b/examples/msg/io-remote/io-remote.tesh @@ -4,9 +4,6 @@ $ ${bindir:=.}/io-remote$EXEEXT ${srcdir:=.}/storage/remote_io.xml ${srcdir:=.}/ > [ 0.000000] (0@ ) Init: 12 MiB used on 'Disk1' > [ 0.000000] (0@ ) Init: 2280 MiB used on 'Disk2' > [ 0.000000] (1@alice) Opened file 'c:\Windows\setupact.log' -> [ 0.000000] (2@ bob) Opened file '/scratch/lib/libsimgrid.so.3.6.2' -> [ 0.000000] (3@ carl) Opened file '/scratch/lib/libsimgrid.so.3.6.2' -> [ 0.000000] (4@ dave) Opened file 'c:\Windows\bootstat.dat' > [ 0.000000] (1@alice) File Descriptor information: > Full path: 'c:\Windows\setupact.log' > Size: 101663 @@ -14,6 +11,8 @@ $ ${bindir:=.}/io-remote$EXEEXT ${srcdir:=.}/storage/remote_io.xml ${srcdir:=.}/ > Storage Id: 'Disk2' > Storage Type: 'SATA-II_HDD' > File Descriptor Id: 0 +> [ 0.000000] (1@alice) Try to read 101663 from 'c:\Windows\setupact.log' +> [ 0.000000] (2@ bob) Opened file '/scratch/lib/libsimgrid.so.3.6.2' > [ 0.000000] (2@ bob) File Descriptor information: > Full path: '/scratch/lib/libsimgrid.so.3.6.2' > Size: 12710497 @@ -21,6 +20,8 @@ $ ${bindir:=.}/io-remote$EXEEXT ${srcdir:=.}/storage/remote_io.xml ${srcdir:=.}/ > Storage Id: 'Disk1' > Storage Type: 'SATA-II_HDD' > File Descriptor Id: 0 +> [ 0.000000] (2@ bob) Try to read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2' +> [ 0.000000] (3@ carl) Opened file '/scratch/lib/libsimgrid.so.3.6.2' > [ 0.000000] (3@ carl) File Descriptor information: > Full path: '/scratch/lib/libsimgrid.so.3.6.2' > Size: 12710497 @@ -28,6 +29,8 @@ $ ${bindir:=.}/io-remote$EXEEXT ${srcdir:=.}/storage/remote_io.xml ${srcdir:=.}/ > Storage Id: 'Disk1' > Storage Type: 'SATA-II_HDD' > File Descriptor Id: 0 +> [ 0.000000] (3@ carl) Try to read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2' +> [ 0.000000] (4@ dave) Opened file 'c:\Windows\bootstat.dat' > [ 0.000000] (4@ dave) File Descriptor information: > Full path: 'c:\Windows\bootstat.dat' > Size: 67584 @@ -35,9 +38,6 @@ $ ${bindir:=.}/io-remote$EXEEXT ${srcdir:=.}/storage/remote_io.xml ${srcdir:=.}/ > Storage Id: 'Disk2' > Storage Type: 'SATA-II_HDD' > File Descriptor Id: 0 -> [ 0.000000] (1@alice) Try to read 101663 from 'c:\Windows\setupact.log' -> [ 0.000000] (2@ bob) Try to read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2' -> [ 0.000000] (3@ carl) Try to read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2' > [ 0.000000] (4@ dave) Try to read 67584 from 'c:\Windows\bootstat.dat' > [ 0.001469] (4@ dave) Have read 67584 from 'c:\Windows\bootstat.dat'. Offset is now at: 67584 > [ 0.001469] (4@ dave) Seek back to the begining of the stream... diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index c59cd236a5..9a996b94cc 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -56,7 +56,6 @@ namespace surf { class HostImpl; class StorageImpl; class StorageType; - class FileImpl; } namespace trace_mgr { class trace; diff --git a/include/simgrid/s4u/File.hpp b/include/simgrid/s4u/File.hpp index dca7d832e9..70249e3c55 100644 --- a/include/simgrid/s4u/File.hpp +++ b/include/simgrid/s4u/File.hpp @@ -27,10 +27,10 @@ XBT_PUBLIC_CLASS File public: File(std::string fullpath, void* userdata); File(std::string fullpath, sg_host_t host, void* userdata); - ~File(); + ~File() = default; /** Retrieves the path to the file */ - const char* getPath() { return path_.c_str(); } + const char* getPath() { return fullpath_.c_str(); } /** Simulates a local read action. Returns the size of data actually read */ sg_size_t read(sg_size_t size); @@ -59,14 +59,16 @@ public: /** Remove a file from disk */ int unlink(); - std::string mount_point; - Storage* localStorage; int desc_id = 0; + Storage* localStorage; + std::string mount_point_; private: - simgrid::surf::FileImpl* pimpl_ = nullptr; + sg_size_t size_; std::string path_; - void* userdata_ = nullptr; + std::string fullpath_; + sg_size_t current_position_ = SEEK_SET; + void* userdata_ = nullptr; }; } } // namespace simgrid::s4u diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index 18390a6401..10241250d2 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -73,7 +73,7 @@ void MSG_file_dump (msg_file_t fd){ "\t\tStorage Id: '%s'\n" "\t\tStorage Type: '%s'\n" "\t\tFile Descriptor Id: %d", - fd->getPath(), fd->size(), fd->mount_point.c_str(), fd->localStorage->getCname(), + fd->getPath(), fd->size(), fd->mount_point_.c_str(), fd->localStorage->getCname(), fd->localStorage->getType(), fd->desc_id); } diff --git a/src/s4u/s4u_file.cpp b/src/s4u/s4u_file.cpp index af4a32d907..5615bac50e 100644 --- a/src/s4u/s4u_file.cpp +++ b/src/s4u/s4u_file.cpp @@ -9,7 +9,6 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" -#include "src/surf/FileImpl.hpp" #include "src/surf/HostImpl.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files"); @@ -19,96 +18,139 @@ namespace s4u { File::File(std::string fullpath, void* userdata) : File(fullpath, Host::current(), userdata){}; -File::File(std::string fullpath, sg_host_t host, void* userdata) : path_(fullpath), userdata_(userdata) +File::File(std::string fullpath, sg_host_t host, void* userdata) : fullpath_(fullpath), userdata_(userdata) { // this cannot fail because we get a xbt_die if the mountpoint does not exist Storage* st = nullptr; size_t longest_prefix_length = 0; - std::string path; XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath.c_str(), host->getCname()); for (auto const& mnt : host->getMountedStorages()) { XBT_DEBUG("See '%s'", mnt.first.c_str()); - mount_point = fullpath.substr(0, mnt.first.length()); + mount_point_ = fullpath.substr(0, mnt.first.length()); - if (mount_point == mnt.first && mnt.first.length() > longest_prefix_length) { + if (mount_point_ == mnt.first && mnt.first.length() > longest_prefix_length) { /* The current mount name is found in the full path and is bigger than the previous*/ longest_prefix_length = mnt.first.length(); st = mnt.second; } } if (longest_prefix_length > 0) { /* Mount point found, split fullpath into mount_name and path+filename*/ - mount_point = fullpath.substr(0, longest_prefix_length); - path = fullpath.substr(longest_prefix_length, fullpath.length()); + mount_point_ = fullpath.substr(0, longest_prefix_length); + path_ = fullpath.substr(longest_prefix_length, fullpath.length()); } else xbt_die("Can't find mount point for '%s' on '%s'", fullpath.c_str(), host->getCname()); - pimpl_ = - simgrid::simix::kernelImmediate([this, st, path] { return new simgrid::surf::FileImpl(st, path, mount_point); }); localStorage = st; -} -File::~File() -{ - simgrid::simix::kernelImmediate([this] { delete pimpl_; }); + XBT_DEBUG("\tOpen file '%s'", path_.c_str()); + std::map* content = localStorage->getContent(); + // if file does not exist create an empty file + auto sz = content->find(path_); + if (sz != content->end()) { + size_ = sz->second; + } else { + size_ = 0; + content->insert({path_, size_}); + XBT_DEBUG("File '%s' was not found, file created.", path_.c_str()); + } } sg_size_t File::read(sg_size_t size) { XBT_DEBUG("READ %s on disk '%s'", getPath(), localStorage->getCname()); // if the current position is close to the end of the file, we may not be able to read the requested size - sg_size_t read_size = localStorage->read(std::min(size, this->size() - this->tell())); - pimpl_->incrPosition(read_size); + sg_size_t read_size = localStorage->read(std::min(size, size_ - current_position_)); + current_position_ += read_size; return read_size; } sg_size_t File::write(sg_size_t size) { - XBT_DEBUG("WRITE %s on disk '%s'. size '%llu/%llu'", getPath(), localStorage->getCname(), size, this->size()); + XBT_DEBUG("WRITE %s on disk '%s'. size '%llu/%llu'", getPath(), localStorage->getCname(), size, size_); // If the storage is full before even starting to write if (localStorage->getSizeUsed() >= localStorage->getSize()) return 0; /* Substract the part of the file that might disappear from the used sized on the storage element */ - localStorage->decrUsedSize(this->size() - this->tell()); + localStorage->decrUsedSize(size_ - current_position_); sg_size_t write_size = localStorage->write(size); - pimpl_->incrPosition(write_size); - pimpl_->setSize(this->tell()); + current_position_ += write_size; + size_ = current_position_; - localStorage->getContent()->erase(pimpl_->getName()); - localStorage->getContent()->insert({pimpl_->getName(), this->size()}); + localStorage->getContent()->erase(path_); + localStorage->getContent()->insert({path_, size_}); return write_size; } sg_size_t File::size() { - return simgrid::simix::kernelImmediate([this] { return pimpl_->size(); }); + return size_; } -void File::seek(sg_offset_t pos) +void File::seek(sg_offset_t offset) { - simgrid::simix::kernelImmediate([this, pos] { pimpl_->seek(pos, SEEK_SET); }); + current_position_ = offset; } -void File::seek(sg_offset_t pos, int origin) +void File::seek(sg_offset_t offset, int origin) { - simgrid::simix::kernelImmediate([this, pos, origin] { pimpl_->seek(pos, origin); }); + switch (origin) { + case SEEK_SET: + current_position_ = offset; + break; + case SEEK_CUR: + current_position_ += offset; + break; + case SEEK_END: + current_position_ = size_ + offset; + break; + default: + break; + } } sg_size_t File::tell() { - return simgrid::simix::kernelImmediate([this] { return pimpl_->tell(); }); + return current_position_; } void File::move(std::string fullpath) { - simgrid::simix::kernelImmediate([this, fullpath] { pimpl_->move(fullpath); }); + /* Check if the new full path is on the same mount point */ + if (not strncmp(mount_point_.c_str(), fullpath.c_str(), mount_point_.length())) { + std::map* content = localStorage->getContent(); + auto sz = content->find(path_); + if (sz != content->end()) { // src file exists + sg_size_t new_size = sz->second; + content->erase(path_); + std::string path = fullpath.substr(mount_point_.length(), fullpath.length()); + content->insert({path.c_str(), new_size}); + XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath.c_str(), new_size); + } else { + XBT_WARN("File %s doesn't exist", path_.c_str()); + } + } else { + XBT_WARN("New full path %s is not on the same mount point: %s.", fullpath.c_str(), mount_point_.c_str()); + } } int File::unlink() { - return simgrid::simix::kernelImmediate([this] { return pimpl_->unlink(); }); + /* Check if the file is on local storage */ + if (localStorage->getContent()->find(path_) == localStorage->getContent()->end()) { + XBT_WARN("File %s is not on disk %s. Impossible to unlink", path_.c_str(), localStorage->getCname()); + return -1; + } else { + XBT_DEBUG("UNLINK %s on disk '%s'", path_.c_str(), localStorage->getCname()); + localStorage->decrUsedSize(size_); + + // Remove the file from storage + localStorage->getContent()->erase(fullpath_); + + return 0; + } } }} // namespace simgrid::s4u diff --git a/src/simix/smx_io.cpp b/src/simix/smx_io.cpp index 1f35bf2e57..39c13a1913 100644 --- a/src/simix/smx_io.cpp +++ b/src/simix/smx_io.cpp @@ -9,7 +9,6 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" -#include "src/surf/FileImpl.hpp" #include "src/surf/HostImpl.hpp" #include "src/surf/StorageImpl.hpp" #include "surf/surf.hpp" diff --git a/src/surf/FileImpl.cpp b/src/surf/FileImpl.cpp deleted file mode 100644 index 4a85e3de8e..0000000000 --- a/src/surf/FileImpl.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* 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. */ - -#include "src/surf/FileImpl.hpp" -#include "src/surf/StorageImpl.hpp" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_file, surf, "Logging specific to the SURF file module"); -namespace simgrid { -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()); - location_ = st->getImpl(); - std::map* content = location_->getContent(); - // if file does not exist create an empty file - auto sz = content->find(path); - if (sz != content->end()) { - size_ = sz->second; - } else { - size_ = 0; - content->insert({path, size_}); - XBT_DEBUG("File '%s' was not found, file created.", path.c_str()); - } -} - -int FileImpl::seek(sg_offset_t offset, int origin) -{ - switch (origin) { - case SEEK_SET: - current_position_ = offset; - return 0; - case SEEK_CUR: - current_position_ += offset; - return 0; - case SEEK_END: - current_position_ = size_ + offset; - return 0; - default: - return -1; - } -} - -int FileImpl::unlink() -{ - /* Check if the file is on this storage */ - if (location_->getContent()->find(path_) == location_->getContent()->end()) { - XBT_WARN("File %s is not on disk %s. Impossible to unlink", getCname(), location_->getCname()); - return -1; - } else { - XBT_DEBUG("UNLINK %s on disk '%s'", getCname(), location_->getCname()); - location_->usedSize_ -= size_; - - // Remove the file from storage - location_->getContent()->erase(path_); - - return 0; - } -} - -void FileImpl::move(std::string fullpath) -{ - /* Check if the new full path is on the same mount point */ - if (not strncmp(mount_point_.c_str(), fullpath.c_str(), mount_point_.size())) { - std::map* content = location_->getContent(); - auto sz = content->find(path_); - if (sz != content->end()) { // src file exists - sg_size_t new_size = sz->second; - content->erase(path_); - std::string path = fullpath.substr(mount_point_.length(), fullpath.length()); - content->insert({path.c_str(), new_size}); - XBT_DEBUG("Move file from %s to %s, size '%llu'", path_.c_str(), fullpath.c_str(), new_size); - } else { - XBT_WARN("File %s doesn't exist", path_.c_str()); - } - } else { - XBT_WARN("New full path %s is not on the same mount point: %s.", fullpath.c_str(), mount_point_.c_str()); - } -} -} -} diff --git a/src/surf/FileImpl.hpp b/src/surf/FileImpl.hpp deleted file mode 100644 index b7acf366a4..0000000000 --- a/src/surf/FileImpl.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* 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.hpp" -#include - -namespace simgrid { -namespace surf { - -class FileImpl { -public: - FileImpl(sg_storage_t st, std::string path, std::string mount); - ~FileImpl() = default; - - const std::string& getName() const { return path_; } - const char* getCname() const { 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_; } - int seek(sg_offset_t offset, int origin); - int unlink(); - void move(std::string fullpath); - -private: - StorageImpl* location_; - std::string path_; - std::string mount_point_; - sg_size_t size_; - sg_size_t current_position_ = SEEK_SET; -}; -} -} -#endif /* SRC_SURF_FILEIMPL_HPP_ */ diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 18bf4bcc7e..97bd9437b4 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -4,7 +4,6 @@ * 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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module"); diff --git a/src/surf/storage_n11.hpp b/src/surf/storage_n11.hpp index 5e3ff38b4e..b6d8c4f7ea 100644 --- a/src/surf/storage_n11.hpp +++ b/src/surf/storage_n11.hpp @@ -6,7 +6,6 @@ #include -#include "FileImpl.hpp" #include "StorageImpl.hpp" #ifndef STORAGE_N11_HPP_ diff --git a/src/xbt/log.c b/src/xbt/log.c index 6969b593fd..767f8835ea 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -238,7 +238,6 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(surf_cpu_cas); XBT_LOG_CONNECT(surf_cpu_ti); XBT_LOG_CONNECT(surf_energy); - XBT_LOG_CONNECT(surf_file); XBT_LOG_CONNECT(surf_kernel); XBT_LOG_CONNECT(surf_lagrange); XBT_LOG_CONNECT(surf_lagrange_dichotomy); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index cff4bca7cc..510bb81c52 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -53,7 +53,6 @@ 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 @@ -335,7 +334,6 @@ set(SURF_SRC src/surf/cpu_interface.cpp src/surf/cpu_ti.cpp src/surf/fair_bottleneck.cpp - src/surf/FileImpl.cpp src/surf/instr_routing.cpp src/surf/instr_surf.cpp src/surf/lagrange.cpp -- 2.20.1