Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add default values for disk properties in file system plugin
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 12 Sep 2019 13:22:54 +0000 (15:22 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 12 Sep 2019 13:22:54 +0000 (15:22 +0200)
If no <prop> 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
examples/s4u/io-file-remote/s4u-io-file-remote.tesh
examples/s4u/io-file-system/s4u-io-file-system.cpp
examples/s4u/io-file-system/s4u-io-file-system.tesh
include/simgrid/plugins/file_system.h
src/plugins/file_system/s4u_FileSystem.cpp

index d729d8d..f42369d 100644 (file)
@@ -13,8 +13,6 @@
 
     <host id="alice" speed="1Gf">
       <disk id="Disk1" read_bw="200MBps" write_bw="80MBps">
-        <prop id="size" value="500GiB"/>
-        <prop id="mount" value="/"/>
         <prop id="content" value="storage/content/small_content.txt"/>
       </disk>
     </host>
index 0837c04..6f27f1c 100644 (file)
@@ -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
index 1650c51..4c91e69 100644 (file)
@@ -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));
     }
   }
 
index 1374ff3..b2ad152 100644 (file)
@@ -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.
index c9b6dd3..086b34f 100644 (file)
@@ -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<std::string, sg_size_t>* parse_content(const std::string& filename);
-  std::map<std::string, sg_size_t>* get_content() { return content_.get(); }
-  sg_size_t get_size() { return size_; }
-  sg_size_t get_used_size() { return used_size_; }
+  std::map<std::string, sg_size_t>* 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<std::map<std::string, sg_size_t>> content_;
+  std::string mount_point_;
   sg_size_t used_size_ = 0;
-  sg_size_t size_      = 0;
+  sg_size_t size_      = static_cast<sg_size_t>(500 * 1024) * 1024 * 1024;
 };
 
 class XBT_PUBLIC FileSystemStorageExt {
index 2b88d16..5c3eb02 100644 (file)
@@ -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<FileSystemDiskExt>()->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<FileSystemDiskExt>()->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<FileSystemDiskExt>()->get_size();
 }
 
+const char* sg_disk_get_mount_point(sg_disk_t d)
+{
+  return d->extension<FileSystemDiskExt>()->get_mount_point();
+}
+
 sg_size_t sg_storage_get_size_free(sg_storage_t st)
 {
   return st->extension<FileSystemStorageExt>()->get_size() - st->extension<FileSystemStorageExt>()->get_used_size();