Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
leak--
[simgrid.git] / src / surf / storage.cpp
index 72ed082..961409f 100644 (file)
@@ -33,6 +33,7 @@ static XBT_INLINE void routing_storage_type_free(void *r)
   free(stype->model);
   free(stype->type_id);
   free(stype->content);
+  free(stype->content_type);
   xbt_dict_free(&(stype->properties));
   xbt_dict_free(&(stype->properties));
   free(stype);
@@ -89,17 +90,17 @@ static void parse_storage_init(sg_platf_storage_cbarg_t storage)
                                      storage->properties);
 }
 
-static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage)
+static void parse_mstorage_init(sg_platf_mstorage_cbarg_t /*mstorage*/)
 {
   XBT_DEBUG("parse_mstorage_init");
 }
 
-static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_)
+static void parse_storage_type_init(sg_platf_storage_type_cbarg_t /*storagetype_*/)
 {
   XBT_DEBUG("parse_storage_type_init");
 }
 
-static void parse_mount_init(sg_platf_mount_cbarg_t mount)
+static void parse_mount_init(sg_platf_mount_cbarg_t /*mount*/)
 {
   XBT_DEBUG("parse_mount_init");
 }
@@ -126,43 +127,6 @@ static void storage_parse_storage(sg_platf_storage_cbarg_t storage)
       (void *) xbt_strdup(storage->type_id));
 }
 
-static xbt_dict_t parse_storage_content(char *filename, sg_size_t *used_size)
-{
-  *used_size = 0;
-  if ((!filename) || (strcmp(filename, "") == 0))
-    return NULL;
-
-  xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
-  FILE *file = NULL;
-
-  file = surf_fopen(filename, "r");
-  xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
-              xbt_str_join(surf_path, ":"));
-
-  char *line = NULL;
-  size_t len = 0;
-  ssize_t read;
-  char path[1024];
-  sg_size_t size;
-
-
-  while ((read = xbt_getline(&line, &len, file)) != -1) {
-    if (read){
-    if(sscanf(line,"%s %" SCNu64, path, &size) == 2) {
-        *used_size += size;
-        sg_size_t *psize = xbt_new(sg_size_t, 1);
-        *psize = size;
-        xbt_dict_set(parse_content,path,psize,NULL);
-      } else {
-        xbt_die("Be sure of passing a good format for content file.\n");
-      }
-    }
-  }
-  free(line);
-  fclose(file);
-  return parse_content;
-}
-
 static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type)
 {
   xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
@@ -188,7 +152,7 @@ static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_typ
       ROUTING_STORAGE_TYPE_LEVEL,
       (void *) stype);
 }
-static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage)
+static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t /*mstorage*/)
 {
   THROW_UNIMPLEMENTED;
 //  mount_t mnt = xbt_new0(s_mount_t, 1);
@@ -227,7 +191,7 @@ static void storage_parse_mount(sg_platf_mount_cbarg_t mount)
   mnt.name = xbt_strdup(mount->name);
 
   if(!mount_list){
-    //FIXME:XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
+    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);
@@ -329,6 +293,7 @@ double StorageModel::shareResources(double now)
   XBT_DEBUG("storage_share_resources %f", now);
   unsigned int i, j;
   StoragePtr storage;
+  void *_write_action;
   StorageActionLmmPtr write_action;
 
   double min_completion = shareResourcesMaxMin(p_runningActionSet,
@@ -340,8 +305,9 @@ double StorageModel::shareResources(double now)
   {
     rate = 0;
     // Foreach write action on disk
-    xbt_dynar_foreach(storage->p_writeActions, j, write_action)
+    xbt_dynar_foreach(storage->p_writeActions, j, _write_action)
     {
+      write_action = dynamic_cast<StorageActionLmmPtr>(static_cast<ActionPtr>(_write_action));
       rate += lmm_variable_getvalue(write_action->p_variable);
     }
     if(rate > 0)
@@ -351,7 +317,7 @@ double StorageModel::shareResources(double now)
   return min_completion;
 }
 
-void StorageModel::updateActionsState(double now, double delta)
+void StorageModel::updateActionsState(double /*now*/, double delta)
 {
   void *_action, *_next_action;
   StorageActionLmmPtr action = NULL;
@@ -427,7 +393,7 @@ xbt_dict_t Storage::parseContent(char *filename)
 
   while ((read = xbt_getline(&line, &len, file)) != -1) {
     if (read){
-    if(sscanf(line,"%s %" SCNu64, path, &size) == 2) {
+    if(sscanf(line,"%s %llu", path, &size) == 2) {
         m_usedSize += size;
         sg_size_t *psize = xbt_new(sg_size_t, 1);
         *psize = size;
@@ -449,14 +415,14 @@ xbt_dict_t Storage::parseContent(char *filename)
 Storage::Storage(StorageModelPtr model, const char* name, xbt_dict_t properties)
 :  Resource(model, name, properties)
 {
-  p_writeActions = xbt_dynar_new(sizeof(char *),NULL);
+  p_writeActions = xbt_dynar_new(sizeof(ActionPtr),NULL);
 }
 
 StorageLmm::StorageLmm(StorageModelPtr model, const char* name, xbt_dict_t properties,
             lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
-            const char* type_id, char *content_name, char *content_type, size_t size)
+            const char* type_id, char *content_name, char *content_type, sg_size_t size)
  :  Resource(model, name, properties), ResourceLmm(), Storage(model, name, properties) {
-  XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'", bconnection, bread, bwrite, ((unsigned long)size));
+  XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
 
   p_stateCurrent = SURF_RESOURCE_ON;
   m_usedSize = 0;
@@ -477,7 +443,7 @@ bool Storage::isUsed()
   return false;
 }
 
-void Storage::updateState(tmgr_trace_event_t event_type, double value, double date)
+void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/)
 {
   THROW_UNIMPLEMENTED;
 }
@@ -555,11 +521,13 @@ StorageActionPtr StorageLmm::open(const char* mount, const char* path)
 StorageActionPtr StorageLmm::close(surf_file_t fd)
 {
   char *filename = fd->name;
-  XBT_DEBUG("\tClose file '%s' size '%" PRIu64 "'", filename, fd->size);
+  XBT_DEBUG("\tClose file '%s' size '%llu'", filename, fd->size);
   // unref write actions from storage
+  void *_write_action;
   StorageActionLmmPtr write_action;
   unsigned int i;
-  xbt_dynar_foreach(p_writeActions, i, write_action) {
+  xbt_dynar_foreach(p_writeActions, i, _write_action) {
+       write_action = dynamic_cast<StorageActionLmmPtr>(static_cast<ActionPtr>(_write_action));
     if ((write_action->p_file) == fd) {
       xbt_dynar_cursor_rm(p_writeActions, &i);
       write_action->unref();
@@ -583,7 +551,7 @@ StorageActionPtr StorageLmm::read(surf_file_t fd, sg_size_t size)
 StorageActionPtr StorageLmm::write(surf_file_t fd, sg_size_t size)
 {
   char *filename = fd->name;
-  XBT_DEBUG("\tWrite file '%s' size '%" PRIu64 "/%" PRIu64 "'",filename,size,fd->size);
+  XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size);
 
   StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
   action->p_file = fd;
@@ -604,7 +572,7 @@ void StorageLmm::rename(const char *src, const char *dest)
   if (psize){// src file exists
     xbt_dict_remove(p_content, src);
     xbt_dict_set(p_content, dest, new_psize,NULL);
-    XBT_DEBUG("Change file name from %s to %s, size '%" PRIu64 "'",src, dest, *psize);
+    XBT_DEBUG("Change file name from %s to %s, size '%llu'",src, dest, *psize);
   }
   else
     XBT_DEBUG("File %s doesn't exist",src);
@@ -635,8 +603,10 @@ sg_size_t StorageLmm::getSize(){
  **********/
 
 StorageActionLmm::StorageActionLmm(ModelPtr model, double cost, bool failed, StorageLmmPtr storage, e_surf_action_storage_type_t type)
-  : Action(model, cost, failed), ActionLmm(model, cost, failed), StorageAction(model, cost, failed, storage, type) {
-  XBT_IN("(%s,%" PRIu64, storage->m_name, cost);
+  : Action(model, cost, failed),
+    ActionLmm(model, cost, failed),
+    StorageAction(model, cost, failed, storage, type) {
+  XBT_IN("(%s,%g", storage->m_name, cost);
   p_variable = lmm_variable_new(p_model->p_maxminSystem, this, 1.0, -1.0 , 3);
 
   // Must be less than the max bandwidth for all actions
@@ -654,7 +624,9 @@ StorageActionLmm::StorageActionLmm(ModelPtr model, double cost, bool failed, Sto
   case WRITE:
     lmm_expand(p_model->p_maxminSystem, storage->p_constraintWrite,
                p_variable, 1.0);
-    xbt_dynar_push(storage->p_writeActions, static_cast<ActionPtr>(this));
+    ActionPtr action = this;
+    xbt_dynar_push(storage->p_writeActions, &action);
+    ref();
     break;
   }
   XBT_OUT();
@@ -704,12 +676,12 @@ bool StorageActionLmm::isSuspended()
   return m_suspended == 1;
 }
 
-void StorageActionLmm::setMaxDuration(double duration)
+void StorageActionLmm::setMaxDuration(double /*duration*/)
 {
   THROW_UNIMPLEMENTED;
 }
 
-void StorageActionLmm::setPriority(double priority)
+void StorageActionLmm::setPriority(double /*priority*/)
 {
   THROW_UNIMPLEMENTED;
 }