Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
complete s4u::Storage interface, what a mess...
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 30 Mar 2017 08:53:03 +0000 (10:53 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 30 Mar 2017 08:55:29 +0000 (10:55 +0200)
not all storages are put in the static storages_ map

include/simgrid/msg.h
include/simgrid/s4u/storage.hpp
include/simgrid/simix.h
src/msg/msg_io.cpp
src/s4u/s4u_file.cpp
src/s4u/s4u_storage.cpp
src/simix/smx_io.cpp
src/surf/HostImpl.cpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp
teshsuite/s4u/storage_client_server/storage_client_server.tesh

index 9e22c1a..5853a9c 100644 (file)
@@ -226,7 +226,6 @@ XBT_PUBLIC(msg_error_t) MSG_storage_set_data(msg_storage_t host, void *data);
 XBT_PUBLIC(void *) MSG_storage_get_data(msg_storage_t storage);
 XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage);
 XBT_PUBLIC(sg_size_t) MSG_storage_get_size(msg_storage_t storage);
-XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
 XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage);
 
 /************************** Host handling ***********************************/
index faba7d8..79f6ac5 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2015. The SimGrid Team.
+/* Copyright (c) 2006-2015, 2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -7,15 +7,13 @@
 #ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_
 #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
 
+#include <map>
+#include <simgrid/s4u/forward.hpp>
+#include <simgrid/simix.h>
 #include <string>
-
-#include <boost/unordered_map.hpp>
-
+#include <unordered_map>
 #include <xbt/base.h>
 
-#include <simgrid/simix.h>
-#include <simgrid/s4u/forward.hpp>
-
 namespace simgrid {
 namespace s4u {
 
@@ -23,27 +21,24 @@ XBT_PUBLIC_CLASS Storage {
   friend s4u::Engine;
 
   Storage(std::string name, smx_storage_t inferior);
-  virtual ~Storage();
 
 public:
+  Storage() = default;
+  virtual ~Storage();
   /** Retrieve a Storage by its name. It must exist in the platform file */
   static Storage &byName(const char* name);
   const char *name();
+  const char* host();
   sg_size_t sizeFree();
   sg_size_t sizeUsed();
   /** Retrieve the total amount of space of this storage element */
   sg_size_t size();
   xbt_dict_t properties();
+  const char* property(const char* key);
+  void setProperty(const char* key, char* value);
   std::map<std::string, sg_size_t*>* content();
+  std::unordered_map<std::string, Storage*>* allStorages();
 
-  /* TODO: missing API:
-XBT_PUBLIC(void) MSG_storage_set_property_value(msg_storage_t storage, const char *name, char *value,void_f_pvoid_t free_ctn);
-XBT_PUBLIC(const char *)MSG_storage_get_property_value(msg_storage_t storage, const char *name);
-XBT_PUBLIC(xbt_dynar_t) MSG_storages_as_dynar(void);
-XBT_PUBLIC(xbt_dict_t) MSG_storage_get_content(msg_storage_t storage);
-XBT_PUBLIC(msg_error_t) MSG_storage_file_move(msg_file_t fd, msg_host_t dest, char* mount, char* fullname);
-XBT_PUBLIC(const char *) MSG_storage_get_host(msg_storage_t storage);
-   */
 protected:
   smx_storage_t inferior();
 
@@ -52,12 +47,13 @@ public:
   void *userdata() {return userdata_;}
   
 private:
-  static boost::unordered_map<std::string, Storage *> *storages_;
+  static std::unordered_map<std::string, Storage*>* storages_;
 
+  std::string hostname_;
   std::string name_;
-  sg_size_t size_;
+  sg_size_t size_      = 0;
   smx_storage_t pimpl_ = nullptr;
-  void *userdata_ = nullptr;
+  void* userdata_      = nullptr;
 };
 
 } /* namespace s4u */
index d2d368a..506b318 100644 (file)
@@ -374,8 +374,6 @@ XBT_PUBLIC(xbt_dict_t) simcall_storage_get_properties(smx_storage_t storage);
 XBT_PUBLIC(void*) SIMIX_storage_get_data(smx_storage_t storage);
 XBT_PUBLIC(void) SIMIX_storage_set_data(smx_storage_t storage, void *data);
 XBT_PUBLIC(const char*) SIMIX_storage_get_name(smx_storage_t storage);
-XBT_PUBLIC(sg_size_t) SIMIX_storage_get_size(smx_storage_t storage);
-XBT_PUBLIC(const char*) SIMIX_storage_get_host(smx_storage_t storage);
 
 /************************** MC simcalls   **********************************/
 XBT_PUBLIC(int) simcall_mc_random(int min, int max);
index 3341faf..a013379 100644 (file)
@@ -447,8 +447,8 @@ msg_storage_t __MSG_storage_create(smx_storage_t storage)
   msg_storage_priv_t storage_private = xbt_new0(s_msg_storage_priv_t, 1);
 
   storage_private->name     = SIMIX_storage_get_name(storage);
-  storage_private->hostname = SIMIX_storage_get_host(storage);
-  storage_private->size     = SIMIX_storage_get_size(storage);
+  storage_private->hostname = surf_storage_get_host(storage);
+  storage_private->size     = surf_storage_get_size(storage);
 
   xbt_lib_set(storage_lib, storage_private->name, MSG_STORAGE_LEVEL, storage_private);
   return xbt_lib_get_elm_or_null(storage_lib, storage_private->name);
index e6fe865..bb87435 100644 (file)
@@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files");
 namespace simgrid {
 namespace s4u {
 
-File::File(const char* fullpath, void* userdata) : path_(fullpath)
+File::File(const char* fullpath, void* userdata) : path_(fullpath), userdata_(userdata)
 {
   // this cannot fail because we get a xbt_die if the mountpoint does not exist
   pimpl_ = simcall_file_open(fullpath, Host::current());
index 48c58d7..e816d0d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2015. The SimGrid Team.
+/* Copyright (c) 2006-2015, 2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -7,28 +7,34 @@
 #include "simgrid/s4u/storage.hpp"
 #include "simgrid/simix.hpp"
 #include "src/surf/storage_interface.hpp"
-
 #include "xbt/lib.h"
+#include <unordered_map>
+
 extern xbt_lib_t storage_lib;
 
 namespace simgrid {
 namespace s4u {
 
-boost::unordered_map <std::string, Storage *> *Storage::storages_ = new boost::unordered_map<std::string, Storage*> ();
+std::unordered_map<std::string, Storage*>* Storage::storages_ = new std::unordered_map<std::string, Storage*>();
+
 Storage::Storage(std::string name, smx_storage_t inferior) :
     name_(name), pimpl_(inferior)
 {
-  size_ = SIMIX_storage_get_size(pimpl_);
+  hostname_ = surf_storage_get_host(pimpl_);
+  size_     = surf_storage_get_size(pimpl_);
   storages_->insert({name, this});
 }
 
 Storage::~Storage() = default;
 
-smx_storage_t Storage::inferior() {
+smx_storage_t Storage::inferior()
+{
   return pimpl_;
 }
-Storage &Storage::byName(const char*name) {
-  s4u::Storage *res = nullptr;
+
+Storage& Storage::byName(const char* name)
+{
+  s4u::Storage* res = nullptr;
   try {
     res = storages_->at(name);
   } catch (std::out_of_range& e) {
@@ -46,6 +52,11 @@ const char* Storage::name()
   return name_.c_str();
 }
 
+const char* Storage::host()
+{
+  return hostname_.c_str();
+}
+
 sg_size_t Storage::sizeFree()
 {
   return simcall_storage_get_free_size(pimpl_);
@@ -65,11 +76,26 @@ xbt_dict_t Storage::properties()
   return simcall_storage_get_properties(pimpl_);
 }
 
+const char* Storage::property(const char* key)
+{
+  return static_cast<const char*>(xbt_dict_get_or_null(this->properties(), key));
+}
+
+void Storage::setProperty(const char* key, char* value)
+{
+  xbt_dict_set(this->properties(), key, value, nullptr);
+}
+
 std::map<std::string, sg_size_t*>* Storage::content()
 {
   return simgrid::simix::kernelImmediate(
       [this] { return static_cast<simgrid::surf::Storage*>(surf_storage_resource_priv(this->pimpl_))->getContent(); });
 }
 
+std::unordered_map<std::string, Storage*>* Storage::allStorages()
+{
+  return storages_;
+}
+
 } /* namespace s4u */
 } /* namespace simgrid */
index fc2dbd1..fda05d8 100644 (file)
@@ -212,10 +212,6 @@ int SIMIX_file_move(smx_actor_t process, smx_file_t file, const char* fullpath)
   return  surf_host_file_move(host, file->surf_file, fullpath);
 }
 
-sg_size_t SIMIX_storage_get_size(smx_storage_t storage){
-  return surf_storage_get_size(storage);
-}
-
 sg_size_t simcall_HANDLER_storage_get_free_size(smx_simcall_t simcall, smx_storage_t storage)
 {
   return SIMIX_storage_get_free_size(simcall->issuer, storage);
@@ -244,10 +240,6 @@ const char* SIMIX_storage_get_name(smx_storage_t storage){
   return sg_storage_name(storage);
 }
 
-const char* SIMIX_storage_get_host(smx_storage_t storage){
-  return surf_storage_get_host(storage);
-}
-
 void SIMIX_io_destroy(smx_activity_t synchro)
 {
   simgrid::kernel::activity::Io *io = static_cast<simgrid::kernel::activity::Io*>(synchro);
index 9e5602f..85a859b 100644 (file)
@@ -161,7 +161,6 @@ void HostImpl::getAttachedStorageList(std::vector<const char*>* storages)
 
 Action* HostImpl::open(const char* fullpath)
 {
-
   simgrid::surf::Storage* st = nullptr;
   size_t longest_prefix_length = 0;
   std::string path;
index 6e7abba..73aa75a 100644 (file)
@@ -92,21 +92,18 @@ static void get_set_storage_data(const char* storage_name)
   xbt_free(data);
 }
 
-// static void dump_platform_storages(void){
-//  unsigned int cursor;
-//  xbt_dynar_t storages = MSG_storages_as_dynar();
-//  msg_storage_t storage;
-//  xbt_dynar_foreach(storages, cursor, storage){
-//    XBT_INFO("Storage %s is attached to %s", MSG_storage_get_name(storage), MSG_storage_get_host(storage));
-//    MSG_storage_set_property_value(storage, "other usage", xbt_strdup("gpfs"));
-//  }
-//  xbt_dynar_free(&storages);
-// Expected output in tesh file
-//> [  1.207952] (server@alice) Storage Disk1 is attached to bob
-//> [  1.207952] (server@alice) Storage Disk2 is attached to alice
-//> [  1.207952] (server@alice) Storage Disk3 is attached to carl
-//> [  1.207952] (server@alice) Storage Disk4 is attached to denise
-//}
+static void dump_platform_storages(void)
+{
+  std::unordered_map<std::string, simgrid::s4u::Storage*>* storages = simgrid::s4u::Storage().allStorages();
+
+  for (auto storage : *storages) {
+    XBT_INFO("Storage %s is attached to %s", storage.first.c_str(), storage.second->host());
+    storage.second->setProperty("other usage", xbt_strdup("gpfs"));
+  }
+  // Expected output in tesh file that's missing for now
+  //> [  1.207952] (server@alice) Storage Disk3 is attached to carl
+  //> [  1.207952] (server@alice) Storage Disk4 is attached to denise
+}
 
 static void storage_info(simgrid::s4u::Host* host)
 {
@@ -165,7 +162,7 @@ static void server()
   }
 
   storage_info(simgrid::s4u::this_actor::host());
-  //  dump_platform_storages();
+  dump_platform_storages();
 }
 
 int main(int argc, char* argv[])
index 15bd867..ee942ed 100644 (file)
@@ -101,4 +101,6 @@ $ ./storage_client_server$EXEEXT ${srcdir:=.}/../../../examples/platforms/storag
 > [  1.207952] (server@alice)  \Windows\win.ini size: 92 bytes
 > [  1.207952] (server@alice)  \Windows\winhlp32.exe size: 10752 bytes
 > [  1.207952] (server@alice)  \Windows\write.exe size: 10752 bytes
+> [  1.207952] (server@alice) Storage Disk1 is attached to bob
+> [  1.207952] (server@alice) Storage Disk2 is attached to alice
 > [  1.207952] (maestro@) Simulated time: 1.20795