From 1914c616267d5de7e8967c65afb7ba98a8499dd6 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 12 Sep 2019 15:22:54 +0200 Subject: [PATCH] add default values for disk properties in file system plugin If no are given for keys "size" and "mount" the following default values are used: * 500GiB for "size" * "/" for "mount" The third property "content" remains fully optional. If this prop is not set, the disk is considered as empty. --- examples/platforms/hosts_with_disks.xml | 2 - .../io-file-remote/s4u-io-file-remote.tesh | 4 +- .../s4u/io-file-system/s4u-io-file-system.cpp | 6 +- .../io-file-system/s4u-io-file-system.tesh | 8 +-- include/simgrid/plugins/file_system.h | 11 ++-- src/plugins/file_system/s4u_FileSystem.cpp | 63 ++++++++++--------- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/examples/platforms/hosts_with_disks.xml b/examples/platforms/hosts_with_disks.xml index d729d8db9e..f42369da68 100644 --- a/examples/platforms/hosts_with_disks.xml +++ b/examples/platforms/hosts_with_disks.xml @@ -13,8 +13,6 @@ - - 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 0837c04630..6f27f1c436 100644 --- a/examples/s4u/io-file-remote/s4u-io-file-remote.tesh +++ b/examples/s4u/io-file-remote/s4u-io-file-remote.tesh @@ -3,7 +3,7 @@ $ ${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: 12/511987 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] (0@ ) Init: 0/512000 MiB used/free on 'Disk2@bob' > [ 0.000000] (1@alice) Opened file '/lib/libsimgrid.so.3.6.2' > [ 0.000000] (1@alice) File Descriptor information: > Full path: '/lib/libsimgrid.so.3.6.2' @@ -28,5 +28,5 @@ $ ${bindir:=.}/s4u-io-file-remote ${platfdir}/hosts_with_disks.xml s4u-io-file-r > [162.912320] (1@alice) Move '/lib/libsimgrid.so.3.6.2' (of size 13015548928) from 'alice' to 'bob' > [666.092709] (0@ ) End: 17/511982 MiB used/free on 'Disk1@alice' > [666.092709] (0@ ) End: 12452/499547 MiB used/free on 'Disk1@bob' -> [666.092709] (0@ ) End: 0/0 MiB used/free on 'Disk2@bob' +> [666.092709] (0@ ) End: 0/512000 MiB used/free on 'Disk2@bob' > [666.092709] (0@ ) Simulation time 666.093 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 1650c51a6a..4c91e69c3c 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.cpp +++ b/examples/s4u/io-file-system/s4u-io-file-system.cpp @@ -18,11 +18,9 @@ public: XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->get_cname()); for (auto const& d : disks) { - const char* mountpoint = d->get_property("mount"); - // Retrieve disk's information - XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", d->get_cname(), mountpoint, sg_disk_get_size_used(d), - sg_disk_get_size_free(d), sg_disk_get_size(d)); + XBT_INFO(" %s (%s) Used: %llu; Free: %llu; Total: %llu.", d->get_cname(), sg_disk_get_mount_point(d), + sg_disk_get_size_used(d), sg_disk_get_size_free(d), sg_disk_get_size(d)); } } 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 1374ff3baa..b2ad152bd1 100644 --- a/examples/s4u/io-file-system/s4u-io-file-system.tesh +++ b/examples/s4u/io-file-system/s4u-io-file-system.tesh @@ -3,19 +3,19 @@ $ ${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 (/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.000000] [s4u_test/INFO] Disk2 (/) Used: 0; Free: 536870912000; Total: 536870912000. > [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 (/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.005000] [s4u_test/INFO] Disk2 (/) Used: 0; Free: 536870912000; Total: 536870912000. > [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 (/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] Disk2 (/) Used: 0; Free: 536870912000; Total: 536870912000. > [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 (/scratch) Used: 36933331; Free: 536833978669; 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] Disk2 (/) Used: 0; Free: 536870912000; Total: 536870912000. diff --git a/include/simgrid/plugins/file_system.h b/include/simgrid/plugins/file_system.h index c9b6dd345a..086b34f97b 100644 --- a/include/simgrid/plugins/file_system.h +++ b/include/simgrid/plugins/file_system.h @@ -44,6 +44,7 @@ XBT_PUBLIC int sg_file_rmove(sg_file_t file, sg_host_t host, const char* fullpat XBT_PUBLIC sg_size_t sg_disk_get_size_free(sg_disk_t d); XBT_PUBLIC sg_size_t sg_disk_get_size_used(sg_disk_t d); XBT_PUBLIC sg_size_t sg_disk_get_size(sg_disk_t d); +XBT_PUBLIC const char* sg_disk_get_mount_point(sg_disk_t d); XBT_PUBLIC sg_size_t sg_storage_get_size_free(sg_storage_t st); XBT_PUBLIC sg_size_t sg_storage_get_size_used(sg_storage_t st); @@ -149,16 +150,18 @@ public: FileSystemDiskExt(const FileSystemDiskExt&) = delete; FileSystemDiskExt& operator=(const FileSystemDiskExt&) = delete; std::map* parse_content(const std::string& filename); - std::map* get_content() { return content_.get(); } - sg_size_t get_size() { return size_; } - sg_size_t get_used_size() { return used_size_; } + std::map* get_content() const { return content_.get(); } + const char* get_mount_point() { return mount_point_.c_str(); } + sg_size_t get_size() const { return size_; } + sg_size_t get_used_size() const { return used_size_; } void decr_used_size(sg_size_t size) { used_size_ -= size; } void incr_used_size(sg_size_t size) { used_size_ += size; } private: std::unique_ptr> content_; + std::string mount_point_; sg_size_t used_size_ = 0; - sg_size_t size_ = 0; + sg_size_t size_ = static_cast(500 * 1024) * 1024 * 1024; }; class XBT_PUBLIC FileSystemStorageExt { diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 2b88d165c2..5c3eb02209 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -57,25 +57,22 @@ File::File(const std::string& fullpath, sg_host_t host, void* userdata) : fullpa Disk* d = nullptr; size_t longest_prefix_length = 0; 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); - mount_point_ = 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(); - d = disk; - } - if (longest_prefix_length > 0) { /* Mount point found, split fullpath_ into mount_name and path+filename*/ - mount_point_ = fullpath_.substr(0, longest_prefix_length); - if (mount_point_ == std::string("/")) - path_ = fullpath_; - else - path_ = fullpath_.substr(longest_prefix_length, fullpath_.length()); - XBT_DEBUG("%s + %s", mount_point_.c_str(), path_.c_str()); - } else - xbt_die("Can't find mount point for '%s' on '%s'", fullpath_.c_str(), host->get_cname()); + std::string current_mount = disk->extension()->get_mount_point(); + mount_point_ = 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(); + d = disk; } + if (longest_prefix_length > 0) { /* Mount point found, split fullpath_ into mount_name and path+filename*/ + mount_point_ = fullpath_.substr(0, longest_prefix_length); + if (mount_point_ == std::string("/")) + path_ = fullpath_; + else + path_ = fullpath_.substr(longest_prefix_length, fullpath_.length()); + XBT_DEBUG("%s + %s", mount_point_.c_str(), path_.c_str()); + } else + xbt_die("Can't find mount point for '%s' on '%s'", fullpath_.c_str(), host->get_cname()); } local_disk_ = d; } @@ -383,15 +380,12 @@ int File::remote_copy(sg_host_t host, const char* fullpath) 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; - } + std::string current_mount = disk->extension()->get_mount_point(); + 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; } } @@ -428,8 +422,16 @@ int File::remote_move(sg_host_t host, const char* fullpath) FileSystemDiskExt::FileSystemDiskExt(simgrid::s4u::Disk* ptr) { const char* size_str = ptr->get_property("size"); + if (size_str) + size_ = surf_parse_get_size(size_str, "disk size", ptr->get_name()); + + const char* current_mount_str = ptr->get_property("mount"); + if (current_mount_str) + mount_point_ = std::string(current_mount_str); + else + mount_point_ = std::string("/"); + const char* content_str = ptr->get_property("content"); - size_ = size_str ? surf_parse_get_size(size_str, "disk size", ptr->get_name()) : 0; if (content_str) content_.reset(parse_content(content_str)); } @@ -653,6 +655,11 @@ sg_size_t sg_disk_get_size(sg_disk_t d) return d->extension()->get_size(); } +const char* sg_disk_get_mount_point(sg_disk_t d) +{ + return d->extension()->get_mount_point(); +} + sg_size_t sg_storage_get_size_free(sg_storage_t st) { return st->extension()->get_size() - st->extension()->get_used_size(); -- 2.20.1