From: Frederic Suter Date: Wed, 11 Sep 2019 13:16:53 +0000 (+0200) Subject: enable remote copy and move for disks X-Git-Tag: v3.24~95 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/392ea56b871fa53b1f7f566340d43ddffb80d977?hp=3ad41a910feecc815ecd91d5cfceaa740068d7b4 enable remote copy and move for disks * need to have a local disk on both sides. it amounts to reading on one side, sending the read data and writing it on the other side. * seemless remote accesses for read and write are no longer available. * simplify the s4u-file-remote test (remote operations with storage is still tested in teshsuite by an old MSG test) --- diff --git a/examples/platforms/hosts_with_disks.xml b/examples/platforms/hosts_with_disks.xml index 8a25f01fe2..cdc7148d89 100644 --- a/examples/platforms/hosts_with_disks.xml +++ b/examples/platforms/hosts_with_disks.xml @@ -5,14 +5,18 @@ - + - + + + + + diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp index b4e63504d7..d1dda9329a 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.cpp +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.cpp @@ -17,31 +17,18 @@ static int host(int argc, char* argv[]) const char* filename = file.get_path(); XBT_INFO("Opened file '%s'", filename); file.dump(); - - XBT_INFO("Try to read %llu from '%s'", file.size(), filename); - sg_size_t read = file.read(file.size()); - XBT_INFO("Have read %llu from '%s'. Offset is now at: %llu", read, filename, file.tell()); - XBT_INFO("Seek back to the beginning of the stream..."); - file.seek(0, SEEK_SET); - XBT_INFO("Offset is now at: %llu", file.tell()); - - if (argc > 5) { - simgrid::s4u::File remoteFile(argv[2], nullptr); - filename = remoteFile.get_path(); - XBT_INFO("Opened file '%s'", filename); - XBT_INFO("Try to write %llu MiB to '%s'", remoteFile.size() / 1024, filename); - sg_size_t write = remoteFile.write(remoteFile.size() * 1024); - XBT_INFO("Have written %llu bytes to '%s'.", write, filename); - - if (std::stoi(argv[5]) != 0) { - XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, remoteFile.size(), - simgrid::s4u::Host::current()->get_cname(), argv[3]); - remoteFile.remote_move(simgrid::s4u::Host::by_name(argv[3]), argv[4]); - } else { - XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, remoteFile.size(), - simgrid::s4u::Host::current()->get_cname(), argv[3]); - remoteFile.remote_copy(simgrid::s4u::Host::by_name(argv[3]), argv[4]); - } + XBT_INFO("Try to write %llu MiB to '%s'", file.size() / 1024, filename); + sg_size_t write = file.write(file.size() * 1024); + XBT_INFO("Have written %llu bytes to '%s'.", write, filename); + + if (std::stoi(argv[4]) != 0) { + XBT_INFO("Move '%s' (of size %llu) from '%s' to '%s'", filename, file.size(), + simgrid::s4u::Host::current()->get_cname(), argv[2]); + file.remote_move(simgrid::s4u::Host::by_name(argv[2]), argv[3]); + } else { + XBT_INFO("Copy '%s' (of size %llu) from '%s' to '%s'", filename, file.size(), + simgrid::s4u::Host::current()->get_cname(), argv[2]); + file.remote_copy(simgrid::s4u::Host::by_name(argv[2]), argv[3]); } return 0; @@ -54,18 +41,20 @@ int main(int argc, char** argv) e.load_platform(argv[1]); e.register_function("host", host); e.load_deployment(argv[2]); - std::vector allStorages = e.get_all_storages(); + std::vector all_hosts = e.get_all_hosts(); - for (auto const& s : allStorages) { - XBT_INFO("Init: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s) / INMEGA, - sg_storage_get_size_free(s) / INMEGA, s->get_cname()); + for (auto const& h : all_hosts) { + for (auto const& d : h->get_disks()) + XBT_INFO("Init: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(d) / INMEGA, + sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname()); } e.run(); - for (auto const& s : allStorages) { - XBT_INFO("End: %llu/%llu MiB used/free on '%s'", sg_storage_get_size_used(s) / INMEGA, - sg_storage_get_size_free(s) / INMEGA, s->get_cname()); + for (auto const& h : all_hosts) { + for (auto const& d : h->get_disks()) + XBT_INFO("End: %llu/%llu MiB used/free on '%s@%s'", sg_disk_get_size_used(d) / INMEGA, + sg_disk_get_size_free(d) / INMEGA, d->get_cname(), h->get_cname()); } XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote.tesh b/examples/s4u/io-file-remote/s4u-io-file-remote.tesh index 1f5c26c3c5..e202cc3457 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.tesh +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.tesh @@ -1,64 +1,32 @@ #!/usr/bin/env tesh -$ ${bindir:=.}/s4u-io-file-remote ${platfdir}/storage/remote_io.xml s4u-io-file-remote_d.xml "--log=root.fmt:[%10.6r]%e(%i@%5h)%e%m%n" -> [ 0.000000] (0@ ) Init: 12/476824 MiB used/free on 'Disk1' -> [ 0.000000] (0@ ) Init: 2280/474556 MiB used/free on 'Disk2' -> [ 0.000000] (1@alice) Opened file 'c:\Windows\setupact.log' +$ ${bindir:=.}/s4u-io-file-remote ${platfdir}/hosts_with_disks.xml s4u-io-file-remote_d.xml "--log=root.fmt:[%10.6r]%e(%i@%5h)%e%m%n" +> [ 0.000000] (0@ ) Init: 2280/509719 MiB used/free on 'Disk1@alice' +> [ 0.000000] (0@ ) Init: 35/511964 MiB used/free on 'Disk1@bob' +> [ 0.000000] (0@ ) Init: 0/0 MiB used/free on 'Disk2@bob' +> [ 0.000000] (1@alice) Opened file 'c:\Windows\Professional.xml' > [ 0.000000] (1@alice) File Descriptor information: -> Full path: 'c:\Windows\setupact.log' -> Size: 101663 +> Full path: 'c:\Windows\Professional.xml' +> Size: 31881 > Mount point: 'c:' -> Storage Id: 'Disk2' -> Storage Type: 'SATA-II_HDD' +> Disk Id: 'Disk1' +> Host Id: 'alice' > 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] (1@alice) Try to write 31 MiB to 'c:\Windows\Professional.xml' +> [ 0.000000] (2@ bob) Opened file '/scratch/doc/simgrid/examples/platforms/g5k.xml' > [ 0.000000] (2@ bob) File Descriptor information: -> Full path: '/scratch/lib/libsimgrid.so.3.6.2' -> Size: 12710497 +> Full path: '/scratch/doc/simgrid/examples/platforms/g5k.xml' +> Size: 17028 > Mount point: '/scratch' -> Storage Id: 'Disk1' -> Storage Type: 'SATA-II_HDD' +> Disk Id: 'Disk1' +> Host Id: 'bob' > 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 -> Mount point: '/scratch' -> 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 -> Mount point: 'c:' -> Storage Id: 'Disk2' -> Storage Type: 'SATA-II_HDD' -> File Descriptor Id: 0 -> [ 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 beginning of the stream... -> [ 0.001469] (4@ dave) Offset is now at: 0 -> [ 0.001469] (4@ dave) Opened file 'c:\Windows\Professional.xml' -> [ 0.001469] (4@ dave) Try to write 31 MiB to 'c:\Windows\Professional.xml' -> [ 0.003741] (1@alice) Have read 101663 from 'c:\Windows\setupact.log'. Offset is now at: 101663 -> [ 0.003741] (1@alice) Seek back to the beginning of the stream... -> [ 0.003741] (1@alice) Offset is now at: 0 -> [ 0.276315] (3@ carl) Have read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'. Offset is now at: 12710497 -> [ 0.276315] (3@ carl) Seek back to the beginning of the stream... -> [ 0.276315] (3@ carl) Offset is now at: 0 -> [ 0.387036] (2@ bob) Have read 12710497 from '/scratch/lib/libsimgrid.so.3.6.2'. Offset is now at: 12710497 -> [ 0.387036] (2@ bob) Seek back to the beginning of the stream... -> [ 0.387036] (2@ bob) Offset is now at: 0 -> [ 0.387036] (2@ bob) Opened file '/scratch/doc/simgrid/examples/platforms/g5k.xml' -> [ 0.387036] (2@ bob) Try to write 16 MiB to '/scratch/doc/simgrid/examples/platforms/g5k.xml' -> [ 0.528211] (4@ dave) Have written 32646144 bytes to 'c:\Windows\Professional.xml'. -> [ 0.528211] (4@ dave) Move 'c:\Windows\Professional.xml' (of size 32646144) from 'dave' to 'carl' -> [ 0.819921] (2@ bob) Have written 17436672 bytes to '/scratch/doc/simgrid/examples/platforms/g5k.xml'. -> [ 0.819921] (2@ bob) Copy '/scratch/doc/simgrid/examples/platforms/g5k.xml' (of size 17436672) from 'bob' to 'alice' -> [ 1.843969] (0@ ) End: 60/476776 MiB used/free on 'Disk1' -> [ 1.843969] (0@ ) End: 2297/474539 MiB used/free on 'Disk2' -> [ 1.843969] (0@ ) Simulation time 1.84397 +> [ 0.000000] (2@ bob) Try to write 16 MiB to '/scratch/doc/simgrid/examples/platforms/g5k.xml' +> [ 0.408077] (1@alice) Have written 32646144 bytes to 'c:\Windows\Professional.xml'. +> [ 0.408077] (1@alice) Move 'c:\Windows\Professional.xml' (of size 32646144) from 'alice' to 'bob' +> [ 0.435917] (2@ bob) Have written 17436672 bytes to '/scratch/doc/simgrid/examples/platforms/g5k.xml'. +> [ 0.435917] (2@ bob) Copy '/scratch/doc/simgrid/examples/platforms/g5k.xml' (of size 17436672) from 'bob' to 'alice' +> [ 1.823119] (0@ ) End: 2297/509702 MiB used/free on 'Disk1@alice' +> [ 1.823119] (0@ ) End: 82/511917 MiB used/free on 'Disk1@bob' +> [ 1.823119] (0@ ) End: 0/0 MiB used/free on 'Disk2@bob' +> [ 1.823119] (0@ ) Simulation time 1.82312 diff --git a/examples/s4u/io-file-remote/s4u-io-file-remote_d.xml b/examples/s4u/io-file-remote/s4u-io-file-remote_d.xml index 3b3f1ab705..13caee2765 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote_d.xml +++ b/examples/s4u/io-file-remote/s4u-io-file-remote_d.xml @@ -2,23 +2,15 @@ - + + + + - - - - - - - - - - - diff --git a/examples/s4u/io-file-system/s4u-io-file-system.cpp b/examples/s4u/io-file-system/s4u-io-file-system.cpp index 0542fbfc1f..1650c51a6a 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.cpp +++ b/examples/s4u/io-file-system/s4u-io-file-system.cpp @@ -33,11 +33,11 @@ public: show_info(disks); // Open an non-existing file to create it - std::string filename = "/home/tmp/data.txt"; + std::string filename = "/scratch/tmp/data.txt"; simgrid::s4u::File* file = new simgrid::s4u::File(filename, nullptr); sg_size_t write = file->write(200000); // Write 200,000 bytes - XBT_INFO("Create a %llu bytes file named '%s' on /sd1", write, filename.c_str()); + XBT_INFO("Create a %llu bytes file named '%s' on /scratch", write, filename.c_str()); // check that sizes have changed show_info(disks); @@ -53,7 +53,7 @@ public: XBT_INFO("Write %llu bytes on %s", write, filename.c_str()); // Now rename file from ./tmp/data.txt to ./tmp/simgrid.readme - std::string newpath = "/home/tmp/simgrid.readme"; + std::string newpath = "/scratch/tmp/simgrid.readme"; XBT_INFO("Move '%s' to '%s'", file->get_path(), newpath.c_str()); file->move(newpath); @@ -69,7 +69,7 @@ public: show_info(disks); // Reopen the file and then unlink it - file = new simgrid::s4u::File("/home/tmp/simgrid.readme", nullptr); + file = new simgrid::s4u::File("/scratch/tmp/simgrid.readme", nullptr); XBT_INFO("Unlink file: '%s'", file->get_path()); file->unlink(); delete file; // Unlinking the file on "disk" does not free the object diff --git a/examples/s4u/io-file-system/s4u-io-file-system.tesh b/examples/s4u/io-file-system/s4u-io-file-system.tesh index 8f6229fbe0..1374ff3baa 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.tesh +++ b/examples/s4u/io-file-system/s4u-io-file-system.tesh @@ -2,20 +2,20 @@ $ ${bindir:=.}/s4u-io-file-system ${platfdir}/hosts_with_disks.xml > [bob:host:(1) 0.000000] [s4u_test/INFO] Storage info on bob: -> [bob:host:(1) 0.000000] [s4u_test/INFO] Disk1 (/home) Used: 36933331; Free: 536833978669; Total: 536870912000. +> [bob:host:(1) 0.000000] [s4u_test/INFO] Disk1 (/scratch) Used: 36933331; Free: 536833978669; Total: 536870912000. > [bob:host:(1) 0.000000] [s4u_test/INFO] Disk2 ((null)) Used: 0; Free: 0; Total: 0. -> [bob:host:(1) 0.005000] [s4u_test/INFO] Create a 200000 bytes file named '/home/tmp/data.txt' on /sd1 +> [bob:host:(1) 0.005000] [s4u_test/INFO] Create a 200000 bytes file named '/scratch/tmp/data.txt' on /scratch > [bob:host:(1) 0.005000] [s4u_test/INFO] Storage info on bob: -> [bob:host:(1) 0.005000] [s4u_test/INFO] Disk1 (/home) Used: 37133331; Free: 536833778669; Total: 536870912000. +> [bob:host:(1) 0.005000] [s4u_test/INFO] Disk1 (/scratch) Used: 37133331; Free: 536833778669; Total: 536870912000. > [bob:host:(1) 0.005000] [s4u_test/INFO] Disk2 ((null)) Used: 0; Free: 0; Total: 0. -> [bob:host:(1) 0.007000] [s4u_test/INFO] Read 200000 bytes on /home/tmp/data.txt -> [bob:host:(1) 0.009500] [s4u_test/INFO] Write 100000 bytes on /home/tmp/data.txt -> [bob:host:(1) 0.009500] [s4u_test/INFO] Move '/home/tmp/data.txt' to '/home/tmp/simgrid.readme' +> [bob:host:(1) 0.007000] [s4u_test/INFO] Read 200000 bytes on /scratch/tmp/data.txt +> [bob:host:(1) 0.009500] [s4u_test/INFO] Write 100000 bytes on /scratch/tmp/data.txt +> [bob:host:(1) 0.009500] [s4u_test/INFO] Move '/scratch/tmp/data.txt' to '/scratch/tmp/simgrid.readme' > [bob:host:(1) 0.009500] [s4u_test/INFO] User data attached to the file: 777 > [bob:host:(1) 0.009500] [s4u_test/INFO] Storage info on bob: -> [bob:host:(1) 0.009500] [s4u_test/INFO] Disk1 (/home) Used: 37233331; Free: 536833678669; Total: 536870912000. +> [bob:host:(1) 0.009500] [s4u_test/INFO] Disk1 (/scratch) Used: 37233331; Free: 536833678669; Total: 536870912000. > [bob:host:(1) 0.009500] [s4u_test/INFO] Disk2 ((null)) Used: 0; Free: 0; Total: 0. -> [bob:host:(1) 0.009500] [s4u_test/INFO] Unlink file: '/home/tmp/simgrid.readme' +> [bob:host:(1) 0.009500] [s4u_test/INFO] Unlink file: '/scratch/tmp/simgrid.readme' > [bob:host:(1) 0.009500] [s4u_test/INFO] Storage info on bob: -> [bob:host:(1) 0.009500] [s4u_test/INFO] Disk1 (/home) Used: 36933331; Free: 536833978669; Total: 536870912000. +> [bob:host:(1) 0.009500] [s4u_test/INFO] Disk1 (/scratch) Used: 36933331; Free: 536833978669; Total: 536870912000. > [bob:host:(1) 0.009500] [s4u_test/INFO] Disk2 ((null)) Used: 0; Free: 0; Total: 0. diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 03d82c5a05..771509594c 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -52,6 +52,7 @@ public: const std::unordered_map* get_properties() const; const char* get_property(const std::string& key) const; void set_property(const std::string&, const std::string& value); + Host* get_host(); void set_data(void* data) { userdata_ = data; } void* get_data() { return userdata_; } diff --git a/src/kernel/resource/DiskImpl.hpp b/src/kernel/resource/DiskImpl.hpp index 79abb67563..80ae7a66e0 100644 --- a/src/kernel/resource/DiskImpl.hpp +++ b/src/kernel/resource/DiskImpl.hpp @@ -49,6 +49,7 @@ public: ************/ class DiskImpl : public Resource, public surf::PropertyHolder { bool currently_destroying_ = false; + s4u::Host* host_ = nullptr; public: DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw); @@ -68,6 +69,9 @@ public: void turn_on() override; void turn_off() override; + s4u::Host* get_host() { return host_; } + void set_host(s4u::Host* host) { host_ = host; } + void destroy(); // Must be called instead of the destructor virtual DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) = 0; virtual DiskAction* read(sg_size_t size) = 0; diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 25893f49d8..e9aeb843f4 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -90,8 +90,10 @@ File::File(const std::string& fullpath, sg_host_t host, void* userdata) : fullpa std::map* content; if (local_storage_) content = local_storage_->extension()->get_content(); - else + + if (local_disk_) content = local_disk_->extension()->get_content(); + // if file does not exist create an empty file auto sz = content->find(path_); if (sz != content->end()) { @@ -110,14 +112,25 @@ File::~File() void File::dump() { - XBT_INFO("File Descriptor information:\n" - "\t\tFull path: '%s'\n" - "\t\tSize: %llu\n" - "\t\tMount point: '%s'\n" - "\t\tStorage Id: '%s'\n" - "\t\tStorage Type: '%s'\n" - "\t\tFile Descriptor Id: %d", - get_path(), size_, mount_point_.c_str(), local_storage_->get_cname(), local_storage_->get_type(), desc_id); + if (local_storage_) + XBT_INFO("File Descriptor information:\n" + "\t\tFull path: '%s'\n" + "\t\tSize: %llu\n" + "\t\tMount point: '%s'\n" + "\t\tStorage Id: '%s'\n" + "\t\tStorage Type: '%s'\n" + "\t\tFile Descriptor Id: %d", + get_path(), size_, mount_point_.c_str(), local_storage_->get_cname(), local_storage_->get_type(), desc_id); + if (local_disk_) + XBT_INFO("File Descriptor information:\n" + "\t\tFull path: '%s'\n" + "\t\tSize: %llu\n" + "\t\tMount point: '%s'\n" + "\t\tDisk Id: '%s'\n" + "\t\tHost Id: '%s'\n" + "\t\tFile Descriptor Id: %d", + get_path(), size_, mount_point_.c_str(), local_disk_->get_cname(), local_disk_->get_host()->get_cname(), + desc_id); } sg_size_t File::read(sg_size_t size) @@ -299,8 +312,10 @@ int File::unlink() return -1; } else { XBT_DEBUG("UNLINK %s on disk '%s'", path_.c_str(), name); + if (local_storage_) local_storage_->extension()->decr_used_size(size_); + if (local_disk_) local_disk_->extension()->decr_used_size(size_); @@ -314,45 +329,87 @@ int File::unlink() int File::remote_copy(sg_host_t host, const char* fullpath) { /* Find the host where the file is physically located and read it */ - Storage* storage_src = local_storage_; - Host* src_host = storage_src->get_host(); + Host* src_host; + if (local_storage_) { + src_host = local_storage_->get_host(); + XBT_DEBUG("READ %s on disk '%s'", get_path(), local_storage_->get_cname()); + } + + if (local_disk_) { + src_host = local_disk_->get_host(); + XBT_DEBUG("READ %s on disk '%s'", get_path(), local_disk_->get_cname()); + } + seek(0, SEEK_SET); - XBT_DEBUG("READ %s on disk '%s'", get_path(), local_storage_->get_cname()); // 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 = local_storage_->read(size_); + sg_size_t read_size = 0; + if (local_storage_) + read_size = local_storage_->read(size_); + if (local_disk_) + read_size = local_disk_->read(size_); + current_position_ += read_size; - /* Find the host that owns the storage where the file has to be copied */ - Storage* storage_dest = nullptr; - Host* dst_host; - size_t longest_prefix_length = 0; - - for (auto const& elm : host->get_mounted_storages()) { - std::string mount_point = std::string(fullpath).substr(0, elm.first.size()); - if (mount_point == elm.first && elm.first.length() > longest_prefix_length) { - /* The current mount name is found in the full path and is bigger than the previous*/ - longest_prefix_length = elm.first.length(); - storage_dest = elm.second; + Host* dst_host = host; + if (local_storage_) { + /* Find the host that owns the storage where the file has to be copied */ + Storage* storage_dest = nullptr; + size_t longest_prefix_length = 0; + + for (auto const& elm : host->get_mounted_storages()) { + std::string mount_point = std::string(fullpath).substr(0, elm.first.size()); + if (mount_point == elm.first && elm.first.length() > longest_prefix_length) { + /* The current mount name is found in the full path and is bigger than the previous*/ + longest_prefix_length = elm.first.length(); + storage_dest = elm.second; + } + } + + if (storage_dest != nullptr) { + /* Mount point found, retrieve the host the storage is attached to */ + dst_host = storage_dest->get_host(); + } else { + XBT_WARN("Can't find mount point for '%s' on destination host '%s'", fullpath, host->get_cname()); + return -1; } } - if (storage_dest != nullptr) { - /* Mount point found, retrieve the host the storage is attached to */ - dst_host = storage_dest->get_host(); - } else { - XBT_WARN("Can't find mount point for '%s' on destination host '%s'", fullpath, host->get_cname()); - return -1; + if (local_disk_) { + size_t longest_prefix_length = 0; + Disk* dst_disk = nullptr; + + for (auto const& disk : host->get_disks()) { + const char* current_mount_str = disk->get_property("mount"); + if (current_mount_str) { + std::string current_mount = std::string(current_mount_str); + std::string mount_point = std::string(fullpath).substr(0, current_mount.length()); + if (mount_point == current_mount && current_mount.length() > longest_prefix_length) { + /* The current mount name is found in the full path and is bigger than the previous*/ + longest_prefix_length = current_mount.length(); + dst_disk = disk; + } + } + } + + if (dst_disk == nullptr) { + XBT_WARN("Can't find mount point for '%s' on destination host '%s'", fullpath, host->get_cname()); + return -1; + } } XBT_DEBUG("Initiate data transfer of %llu bytes between %s and %s.", read_size, src_host->get_cname(), - storage_dest->get_host()->get_cname()); + dst_host->get_cname()); src_host->send_to(dst_host, read_size); /* Create file on remote host, write it and close it */ File* fd = new File(fullpath, dst_host, nullptr); - sg_size_t write_size = fd->local_storage_->write(read_size); - fd->local_storage_->extension()->incr_used_size(write_size); - (*(fd->local_storage_->extension()->get_content()))[path_] = size_; + if (local_storage_) { + sg_size_t write_size = fd->local_storage_->write(read_size); + fd->local_storage_->extension()->incr_used_size(write_size); + (*(fd->local_storage_->extension()->get_content()))[path_] = size_; + } + if (local_disk_) + fd->write(read_size); delete fd; return 0; } diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index c9477e434d..562e7423b2 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -20,6 +20,11 @@ xbt::signal Disk::on_creation; xbt::signal Disk::on_destruction; xbt::signal Disk::on_state_change; +Host* Disk::get_host() +{ + return pimpl_->get_host(); +} + const std::unordered_map* Disk::get_properties() const { return pimpl_->get_properties(); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 8a080b8f2e..d1728279df 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -82,6 +82,8 @@ void sg_platf_new_host(simgrid::kernel::routing::HostCreationArgs* args) mount_list.clear(); host->pimpl_->disks_ = std::move(args->disks); + for (auto d : host->pimpl_->disks_) + d->set_host(host); /* Change from the defaults */ if (args->state_trace)