Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a vector of keyval structs is a map
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 22 May 2017 19:38:18 +0000 (21:38 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 22 May 2017 19:38:18 +0000 (21:38 +0200)
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/sg_platf.cpp
src/surf/storage_interface.hpp

index 85a859b..785942d 100644 (file)
@@ -106,28 +106,13 @@ HostImpl::HostImpl(s4u::Host* host) : piface_(host)
   piface_->pimpl_ = this;
 }
 
-/** @brief use destroy() instead of this destructor */
-HostImpl::~HostImpl()
-{
-  for (auto mnt : storage_)
-    xbt_free(mnt.name);
-}
-
 simgrid::surf::Storage* HostImpl::findStorageOnMountList(const char* mount)
 {
-  simgrid::surf::Storage* st = nullptr;
-
   XBT_DEBUG("Search for storage name '%s' on '%s'", mount, piface_->cname());
-  for (auto mnt : storage_) {
-    XBT_DEBUG("See '%s'", mnt.name);
-    if (!strcmp(mount, mnt.name)) {
-      st = static_cast<simgrid::surf::Storage*>(mnt.storage);
-      break;
-    }
-  }
-  if (!st)
+  if (storage_.find(mount) == storage_.end())
     xbt_die("Can't find mount '%s' for '%s'", mount, piface_->cname());
-  return st;
+
+  return storage_.at(mount);
 }
 
 xbt_dict_t HostImpl::getMountedStorageList()
@@ -136,8 +121,8 @@ xbt_dict_t HostImpl::getMountedStorageList()
   char* storage_name      = nullptr;
 
   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);
+    storage_name = (char*)mnt.second->cname();
+    xbt_dict_set(storage_list, mnt.first.c_str(), storage_name, nullptr);
   }
   return storage_list;
 }
@@ -168,14 +153,13 @@ Action* HostImpl::open(const char* fullpath)
 
   XBT_DEBUG("Search for storage name for '%s' on '%s'", fullpath, piface_->cname());
   for (auto mnt : storage_) {
-    XBT_DEBUG("See '%s'", mnt.name);
-    std::string file_mount_name = std::string(fullpath).substr(0, strlen(mnt.name));
-
-    if (!strcmp(file_mount_name.c_str(), mnt.name) &&
-        strlen(mnt.name) > longest_prefix_length) { /* The current mount name is found in the full path and is
-                                                           bigger than the previous*/
-      longest_prefix_length = strlen(mnt.name);
-      st                    = static_cast<simgrid::surf::Storage*>(mnt.storage);
+    XBT_DEBUG("See '%s'", mnt.first.c_str());
+    std::string file_mount_name = std::string(fullpath).substr(0, mnt.first.size());
+
+    if (file_mount_name == mnt.first && mnt.first.length() > longest_prefix_length) {
+      /* The current mount name is found in the full path and is bigger than the previous*/
+      longest_prefix_length = mnt.first.length();
+      st                    = mnt.second;
     }
   }
   if (longest_prefix_length > 0) { /* Mount point found, split fullpath into mount_name and path+filename*/
index 6180248..12287e3 100644 (file)
@@ -64,7 +64,7 @@ class HostImpl : public simgrid::surf::PropertyHolder {
 
 public:
   explicit HostImpl(s4u::Host* host);
-  virtual ~HostImpl();
+  virtual ~HostImpl() = default;
 
   /** @brief Return the storage of corresponding mount point */
   virtual simgrid::surf::Storage* findStorageOnMountList(const char* storage);
@@ -173,7 +173,7 @@ public:
    */
   virtual int fileMove(surf_file_t fd, const char* fullpath);
 
-  std::vector<s_mount_t> storage_;
+  std::map<std::string, simgrid::surf::Storage*> storage_;
   simgrid::s4u::Host* piface_ = nullptr;
 
   simgrid::s4u::Host* getHost() { return piface_; }
index 6c0cbf4..b40d4ab 100644 (file)
@@ -28,7 +28,7 @@
 #include <string>
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
 
-XBT_PRIVATE std::vector<s_mount_t> mount_list;
+XBT_PRIVATE std::map<std::string, simgrid::surf::Storage*> mount_list;
 
 namespace simgrid {
 namespace surf {
@@ -427,13 +427,10 @@ void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){
 
   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
 
-  s_mount_t mnt;
-  mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
-  mnt.name = xbt_strdup(mount->name);
-
   if (mount_list.empty())
     XBT_DEBUG("Create a Mount list for %s", A_surfxml_host_id);
-  mount_list.push_back(mnt);
+  mount_list.insert(
+      {std::string(mount->name), surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId))});
 }
 
 void sg_platf_new_route(sg_platf_route_cbarg_t route)
index 31c6dc8..32fa00f 100644 (file)
@@ -233,12 +233,6 @@ typedef struct s_storage_type {
 } s_storage_type_t;
 typedef s_storage_type_t* storage_type_t;
 
-typedef struct s_mount {
-  void *storage;
-  char *name;
-} s_mount_t;
-typedef s_mount_t* mount_t;
-
 typedef struct surf_file {
   char *name;
   char *mount;