Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 15:59:30 +0000 (16:59 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 15:59:30 +0000 (16:59 +0100)
15 files changed:
include/simgrid/s4u/NetZone.hpp
include/simgrid/s4u/host.hpp
include/surf/surf_routing.h
src/bindings/java/jmsg_as.cpp
src/bindings/java/jmsg_host.cpp
src/msg/msg_environment.cpp
src/msg/msg_host.cpp
src/s4u/s4u_host.cpp
src/s4u/s4u_netzone.cpp
src/simgrid/host.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/sg_platf.cpp
src/surf/storage_interface.cpp
src/surf/storage_n11.cpp

index 6b738f1..d04ad90 100644 (file)
@@ -48,7 +48,7 @@ public:
   NetZone* father();
 
   xbt_dict_t children(); // Sub netzones
-  xbt_dynar_t hosts();   // my content as a dynar
+  std::vector<Host*> hosts(); // my content as a vector of hosts
 
   /** Get the properties assigned to a host */
   std::unordered_map<std::string, std::string>* properties();
index 77147d3..7c48221 100644 (file)
@@ -94,7 +94,7 @@ public:
   void setPstate(int pstate_index);
   int pstate();
   xbt_dict_t mountedStoragesAsDict(); // HACK
-  xbt_dynar_t attachedStorages();
+  std::vector<const char*> attachedStorages();
 
   /** Get an associative list [mount point]->[Storage] of all local mount points.
    *
index 20384e3..abe93e0 100644 (file)
@@ -17,7 +17,6 @@ XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level
 
 XBT_PUBLIC_DATA(xbt_lib_t) storage_lib;
 XBT_PUBLIC_DATA(int) ROUTING_STORAGE_LEVEL;        //Routing storage level
-XBT_PUBLIC_DATA(int) ROUTING_STORAGE_HOST_LEVEL;
 XBT_PUBLIC_DATA(int) SURF_STORAGE_LEVEL;  // Surf storage level
 XBT_PUBLIC_DATA(xbt_lib_t) file_lib;
 XBT_PUBLIC_DATA(xbt_lib_t) storage_type_lib;
index cac6920..57bc735 100644 (file)
@@ -129,27 +129,22 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo
   jobjectArray jtable;
   jobject jhost;
   jstring jname;
-  msg_host_t host;
   simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas);
 
-  xbt_dynar_t table = as->hosts();
-  int count = xbt_dynar_length(table);
-
   jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
-
+  std::vector<sg_host_t> table = as->hosts();
   if (!cls)
     return nullptr;
 
-  jtable = env->NewObjectArray(static_cast<jsize>(count), cls, nullptr);
+  jtable = env->NewObjectArray(static_cast<jsize>(table.size()), cls, nullptr);
 
   if (!jtable) {
     jxbt_throw_jni(env, "Hosts table allocation failed");
     return nullptr;
   }
 
-  for (int index = 0; index < count; index++) {
-    host = xbt_dynar_get_as(table,index,msg_host_t);
-
+  int index = 0;
+  for (auto host : table) {
     jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
     if (!jhost) {
       jname = env->NewStringUTF(host->cname());
@@ -160,8 +155,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo
     }
 
     env->SetObjectArrayElement(jtable, index, jhost);
+    index++;
   }
-  xbt_dynar_free(&table);
   return jtable;
 }
 
index f3f0fc5..6a095c5 100644 (file)
@@ -272,15 +272,13 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIE
   }
   jobjectArray jtable;
 
-  xbt_dynar_t dyn = MSG_host_get_attached_storage_list(host);
-  int count = xbt_dynar_length(dyn);
-  jclass cls = jxbt_get_class(env, "java/lang/String");
-  jtable = env->NewObjectArray((jsize) count, cls, nullptr);
-  int index;
-  char *storage_name;
+  xbt_dynar_t dyn = sg_host_get_attached_storage_list(host);
+  jclass cls      = jxbt_get_class(env, "java/lang/String");
+  jtable          = env->NewObjectArray(static_cast<jsize>(xbt_dynar_length(dyn)), cls, nullptr);
+  unsigned int index;
+  const char* storage_name;
   jstring jstorage_name;
-  for (index = 0; index < count; index++) {
-    storage_name = xbt_dynar_get_as(dyn,index,char*);
+  xbt_dynar_foreach (dyn, index, storage_name) {
     jstorage_name = env->NewStringUTF(storage_name);
     env->SetObjectArrayElement(jtable, index, jstorage_name);
   }
index 122783e..733814c 100644 (file)
@@ -80,7 +80,13 @@ void MSG_environment_as_set_property_value(msg_netzone_t netzone, const char* na
 
 xbt_dynar_t MSG_environment_as_get_hosts(msg_netzone_t netzone)
 {
-  return netzone->hosts();
+  xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
+
+  for (auto host : netzone->hosts()) {
+    xbt_dynar_push(res, &host);
+  }
+
+  return res;
 }
 
 SG_END_DECL()
index e8f6518..3d68513 100644 (file)
@@ -5,6 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/s4u/host.hpp"
+#include "simgrid/s4u/storage.hpp"
 #include "src/msg/msg_private.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg);
@@ -255,8 +256,7 @@ xbt_dict_t MSG_host_get_mounted_storage_list(msg_host_t host)
  */
 xbt_dynar_t MSG_host_get_attached_storage_list(msg_host_t host)
 {
-  xbt_assert((host != nullptr), "Invalid parameters");
-  return host->attachedStorages();
+  return sg_host_get_attached_storage_list(host);
 }
 
 /** \ingroup m_host_management
index d821972..dcfa890 100644 (file)
@@ -257,7 +257,7 @@ xbt_dict_t Host::mountedStoragesAsDict()
  * \brief Returns the list of storages attached to an host.
  * \return a dict containing all storages attached to the host
  */
-xbt_dynar_t Host::attachedStorages()
+std::vector<const char*> Host::attachedStorages()
 {
   return simgrid::simix::kernelImmediate([this] {
     return this->pimpl_->getAttachedStorageList();
index e2149e6..5377233 100644 (file)
@@ -72,14 +72,14 @@ NetZone* NetZone::father()
   return father_;
 }
 
-xbt_dynar_t NetZone::hosts()
+std::vector<s4u::Host*> NetZone::hosts()
 {
-  xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
+  std::vector<s4u::Host*> res;
 
   for (auto card : vertices_) {
     s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name());
     if (host != nullptr)
-      xbt_dynar_push(res, &host);
+      res.push_back(host);
   }
   return res;
 }
index 901e0bd..51bc85e 100644 (file)
@@ -121,10 +121,12 @@ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){
 }
 
 xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){
-  return host->pimpl_->getAttachedStorageList();
+  xbt_dynar_t storage_dynar = xbt_dynar_new(sizeof(const char*), nullptr);
+  for (auto name : host->attachedStorages())
+    xbt_dynar_push(storage_dynar, &name);
+  return storage_dynar;
 }
 
-
 // =========== user-level functions ===============
 // ================================================
 /** @brief Returns the total speed of a host */
index 407c77f..5366a5d 100644 (file)
@@ -3,7 +3,6 @@
 /* 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/HostImpl.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include <string>
 
@@ -113,11 +112,9 @@ HostImpl::~HostImpl() = default;
 simgrid::surf::Storage* HostImpl::findStorageOnMountList(const char* mount)
 {
   simgrid::surf::Storage* st = nullptr;
-  s_mount_t mnt;
-  unsigned int cursor;
 
   XBT_DEBUG("Search for storage name '%s' on '%s'", mount, piface_->cname());
-  xbt_dynar_foreach (storage_, cursor, mnt) {
+  for (auto mnt : storage_) {
     XBT_DEBUG("See '%s'", mnt.name);
     if (!strcmp(mount, mnt.name)) {
       st = static_cast<simgrid::surf::Storage*>(mnt.storage);
@@ -131,31 +128,29 @@ simgrid::surf::Storage* HostImpl::findStorageOnMountList(const char* mount)
 
 xbt_dict_t HostImpl::getMountedStorageList()
 {
-  s_mount_t mnt;
-  unsigned int i;
   xbt_dict_t storage_list = xbt_dict_new_homogeneous(nullptr);
   char* storage_name      = nullptr;
 
-  xbt_dynar_foreach (storage_, i, mnt) {
+  for (auto mnt : storage_) {
     storage_name = (char*)static_cast<simgrid::surf::Storage*>(mnt.storage)->cname();
     xbt_dict_set(storage_list, mnt.name, storage_name, nullptr);
   }
   return storage_list;
 }
 
-xbt_dynar_t HostImpl::getAttachedStorageList()
+std::vector<const char*> HostImpl::getAttachedStorageList()
 {
   xbt_lib_cursor_t cursor;
   char* key;
   void** data;
-  xbt_dynar_t result = xbt_dynar_new(sizeof(void*), nullptr);
+  std::vector<const char*> result;
   xbt_lib_foreach(storage_lib, cursor, key, data)
   {
     if (xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != nullptr) {
       simgrid::surf::Storage* storage = static_cast<simgrid::surf::Storage*>(
           xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL));
       if (!strcmp(static_cast<const char*>(storage->attach_), piface_->cname())) {
-        xbt_dynar_push_as(result, void*, (void*)storage->cname());
+        result.push_back(storage->cname());
       }
     }
   }
@@ -166,14 +161,12 @@ Action* HostImpl::open(const char* fullpath)
 {
 
   simgrid::surf::Storage* st = nullptr;
-  s_mount_t mnt;
-  unsigned int cursor;
   size_t longest_prefix_length = 0;
   std::string path;
   std::string mount_name;
 
   XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath, piface_->cname());
-  xbt_dynar_foreach (storage_, cursor, mnt) {
+  for (auto mnt : storage_) {
     XBT_DEBUG("See '%s'", mnt.name);
     std::string file_mount_name = std::string(fullpath).substr(0, strlen(mnt.name));
 
index 3cf0989..4c28215 100644 (file)
@@ -73,7 +73,7 @@ public:
   virtual xbt_dict_t getMountedStorageList();
 
   /** @brief Get the xbt_dynar_t of storages attached to the Host */
-  virtual xbt_dynar_t getAttachedStorageList();
+  virtual std::vector<const char*> getAttachedStorageList();
 
   /**
    * @brief Open a file
@@ -173,7 +173,7 @@ public:
    */
   virtual int fileMove(surf_file_t fd, const char* fullpath);
 
-  xbt_dynar_t storage_        = nullptr;
+  std::vector<s_mount_t> storage_;
   simgrid::s4u::Host* piface_ = nullptr;
 
   simgrid::s4u::Host* getHost() { return piface_; }
index 4a237e7..139683d 100644 (file)
@@ -27,7 +27,7 @@
 #include <string>
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 
-XBT_PRIVATE xbt_dynar_t mount_list = nullptr;
+XBT_PRIVATE std::vector<s_mount_t> mount_list;
 
 namespace simgrid {
 namespace surf {
@@ -77,8 +77,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args)
       routing_get_current()->createHost(args->id, &args->speed_per_pstate, args->core_amount, &props);
 
   host->pimpl_->storage_ = mount_list;
-  xbt_lib_set(storage_lib, args->id, ROUTING_STORAGE_HOST_LEVEL, static_cast<void*>(mount_list));
-  mount_list = nullptr;
+  mount_list.clear();
 
   /* Change from the defaults */
   if (args->state_trace)
@@ -442,11 +441,9 @@ void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){
   mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
   mnt.name = xbt_strdup(mount->name);
 
-  if(!mount_list){
-    XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
-    mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
-  }
-  xbt_dynar_push(mount_list, &mnt);
+  if (mount_list.empty())
+    XBT_DEBUG("Create a Mount list for %s", A_surfxml_host_id);
+  mount_list.push_back(mnt);
 }
 
 void sg_platf_new_route(sg_platf_route_cbarg_t route)
index dbbb601..89a0d0c 100644 (file)
@@ -17,7 +17,6 @@ xbt_lib_t storage_lib;
 int SIMIX_STORAGE_LEVEL        = -1; // Simix storage level
 int MSG_STORAGE_LEVEL          = -1; // Msg storage level
 int ROUTING_STORAGE_LEVEL      = -1; // Routing for storage level
-int ROUTING_STORAGE_HOST_LEVEL = -1;
 int SURF_STORAGE_LEVEL = -1;
 xbt_lib_t storage_type_lib;
 int ROUTING_STORAGE_TYPE_LEVEL = -1; //Routing for storage_type level
index eb203e5..b89e195 100644 (file)
@@ -28,12 +28,6 @@ static inline void routing_storage_type_free(void *r)
   free(stype);
 }
 
-static inline void routing_storage_host_free(void *r)
-{
-  xbt_dynar_t dyn = (xbt_dynar_t) r;
-  xbt_dynar_free(&dyn);
-}
-
 static void check_disk_attachment()
 {
   xbt_lib_cursor_t cursor;
@@ -56,7 +50,6 @@ void storage_register_callbacks()
   instr_routing_define_callbacks();
 
   ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, xbt_free_f);
-  ROUTING_STORAGE_HOST_LEVEL = xbt_lib_add_level(storage_lib, routing_storage_host_free);
   ROUTING_STORAGE_TYPE_LEVEL = xbt_lib_add_level(storage_type_lib, routing_storage_type_free);
   SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, [](void *self) {
     delete static_cast<simgrid::surf::Storage*>(self);