Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2449e3c3b13ec44870eeee6fcfc22ba36f065d58
[simgrid.git] / src / surf / storage.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. The SimGrid Team.
2  * All rights reserved.                                                                 */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package.             */
6
7 #include "xbt/ex.h"
8 #include "xbt/dict.h"
9 #include "xbt/file_stat.h"
10 #include "portable.h"
11 #include "surf_private.h"
12 #include "storage_private.h"
13 #include "surf/surf_resource.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
16                                 "Logging specific to the SURF storage module");
17
18 xbt_lib_t storage_lib;
19 int ROUTING_STORAGE_LEVEL;      //Routing for storagelevel
20 int ROUTING_STORAGE_HOST_LEVEL;
21 int SURF_STORAGE_LEVEL;
22 xbt_lib_t storage_type_lib;
23 int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level
24
25 xbt_dynar_t mount_list = NULL;  /* temporary store of current mount storage */
26
27 surf_model_t surf_storage_model = NULL;
28 lmm_system_t storage_maxmin_system = NULL;
29 static int storage_selective_update = 0;
30 static xbt_swag_t
31     storage_running_action_set_that_does_not_need_being_checked = NULL;
32
33 static xbt_dynar_t storage_list;
34
35 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
36 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
37
38 static xbt_dict_t parse_storage_content(char *filename, unsigned long *used_size);
39 static int storage_action_unref(surf_action_t action);
40 static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state);
41 static surf_action_t storage_action_execute (void *storage, double size, e_surf_action_storage_type_t type);
42
43 static surf_action_t storage_action_ls(void *storage, const char* path)
44 {
45   surf_action_t action = storage_action_execute(storage,0, LS);
46   action->ls_dict = NULL;
47   xbt_dict_t ls_dict = xbt_dict_new();
48
49   char* key;
50   unsigned long size = 0;
51   xbt_dict_cursor_t cursor = NULL;
52
53   xbt_dynar_t dyn = NULL;
54   char* file = NULL;
55
56   // for each file in the storage content
57   xbt_dict_foreach(((storage_t)storage)->content,cursor,key,size){
58     // Search if file start with the prefix 'path'
59     if(xbt_str_start_with(key,path)){
60       file = &key[strlen(path)];
61
62       // Split file with '/'
63       dyn = xbt_str_split(file,"/");
64       file = xbt_dynar_get_as(dyn,0,char*);
65
66       // file
67       if(xbt_dynar_length(dyn) == 1){
68         xbt_dict_set(ls_dict,file,&size,NULL);
69       }
70       // Directory
71       else
72       {
73         // if directory does not exist yet in the dictionary
74         if(!xbt_dict_get_or_null(ls_dict,file))
75           xbt_dict_set(ls_dict,file,NULL,NULL);
76       }
77       xbt_dynar_free(&dyn);
78     }
79   }
80
81   action->ls_dict = ls_dict;
82   return action;
83 }
84
85 static surf_action_t storage_action_unlink(void *storage, surf_file_t stream)
86 {
87   surf_action_t action = storage_action_execute(storage,0, UNLINK);
88
89   // Add memory to storage
90   ((storage_t)storage)->used_size -= stream->size;
91
92   // Remove the file from storage
93   xbt_dict_t content_dict = ((storage_t)storage)->content;
94   xbt_dict_remove(content_dict,stream->name);
95
96   free(stream->name);
97   xbt_free(stream);
98
99   return action;
100 }
101
102 static surf_action_t storage_action_open(void *storage, const char* mount, const char* path, const char* mode)
103 {
104   XBT_DEBUG("\tOpen file '%s'",path);
105   xbt_dict_t content_dict = ((storage_t)storage)->content;
106   unsigned long size = (unsigned long) xbt_dict_get_or_null(content_dict,path);
107   // if file does not exist create an empty file
108   if(!size){
109     xbt_dict_set(content_dict,path,&size,NULL);
110     XBT_DEBUG("File '%s' was not found, file created.",path);
111   }
112   surf_file_t file = xbt_new0(s_surf_file_t,1);
113   file->name = xbt_strdup(path);
114   file->size = size;
115   file->storage = mount;
116
117   surf_action_t action = storage_action_execute(storage,0, OPEN);
118   action->file = (void *)file;
119   return action;
120 }
121
122 static surf_action_t storage_action_close(void *storage, surf_file_t fp)
123 {
124   char *filename = fp->name;
125   XBT_DEBUG("\tClose file '%s' size '%zu'",filename,fp->size);
126   // unref write actions from storage
127   surf_action_storage_t write_action;
128   unsigned int i;
129   xbt_dynar_foreach(((storage_t)storage)->write_actions,i,write_action) {
130     if ((write_action->generic_lmm_action.generic_action.file) == fp) {
131       xbt_dynar_cursor_rm(((storage_t)storage)->write_actions, &i);
132       storage_action_unref((surf_action_t) write_action);
133     }
134   }
135
136   free(fp->name);
137   xbt_free(fp);
138   surf_action_t action = storage_action_execute(storage,0, CLOSE);
139   return action;
140 }
141
142 static surf_action_t storage_action_read(void *storage, void* ptr, double size, size_t nmemb, surf_file_t stream)
143 {
144   if(size > stream->size)
145     size = stream->size;
146   surf_action_t action = storage_action_execute(storage,size,READ);
147   return action;
148 }
149
150 static surf_action_t storage_action_write(void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream)
151 {
152   char *filename = stream->name;
153   XBT_DEBUG("\tWrite file '%s' size '%zu/%zu'",filename,size,stream->size);
154
155   surf_action_t action = storage_action_execute(storage,size,WRITE);
156   action->file = stream;
157
158   // If the storage is full
159   if(((storage_t)storage)->used_size==((storage_t)storage)->size) {
160     storage_action_state_set((surf_action_t) action, SURF_ACTION_FAILED);
161   }
162   return action;
163 }
164
165 static surf_action_t storage_action_execute (void *storage, double size, e_surf_action_storage_type_t type)
166 {
167   surf_action_storage_t action = NULL;
168   storage_t STORAGE = storage;
169
170   XBT_IN("(%s,%f", surf_resource_name(STORAGE), size);
171   action =
172       surf_action_new(sizeof(s_surf_action_storage_t), size, surf_storage_model,
173           STORAGE->state_current != SURF_RESOURCE_ON);
174
175   // Save the storage on action
176   action->storage = storage;
177   GENERIC_LMM_ACTION(action).suspended = 0;     /* Should be useless because of the
178                                                    calloc but it seems to help valgrind... */
179
180   GENERIC_LMM_ACTION(action).variable =
181       lmm_variable_new(storage_maxmin_system, action, 1.0, -1.0 , 3);
182
183   // Must be less than the max bandwidth for all actions
184   lmm_expand(storage_maxmin_system, STORAGE->constraint,
185              GENERIC_LMM_ACTION(action).variable, 1.0);
186
187   switch(type) {
188   case OPEN:
189   case CLOSE:
190   case STAT:
191   case UNLINK:
192   case LS:
193     break;
194   case READ:
195     lmm_expand(storage_maxmin_system, STORAGE->constraint_read,
196                GENERIC_LMM_ACTION(action).variable, 1.0);
197     break;
198   case WRITE:
199     lmm_expand(storage_maxmin_system, STORAGE->constraint_write,
200                GENERIC_LMM_ACTION(action).variable, 1.0);
201     xbt_dynar_push(((storage_t)storage)->write_actions,&action);
202     surf_action_ref((surf_action_t) action);
203     break;
204   }
205   action->type = type;
206   XBT_OUT();
207   return (surf_action_t) action;
208 }
209
210 static void* storage_create_resource(const char* id, const char* model,const char* type_id,const char* content_name)
211 {
212   storage_t storage = NULL;
213
214   xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)),
215               "Storage '%s' declared several times in the platform file",
216               id);
217   storage = (storage_t) surf_resource_new(sizeof(s_storage_t),
218           surf_storage_model, id,NULL);
219
220   storage->state_current = SURF_RESOURCE_ON;
221   storage->used_size = 0;
222   storage->size = 0;
223   storage->write_actions = xbt_dynar_new(sizeof(char *),NULL);
224
225   storage_type_t storage_type = xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL);
226   double Bread  = atof(xbt_dict_get(storage_type->properties,"Bread"));
227   double Bwrite = atof(xbt_dict_get(storage_type->properties,"Bwrite"));
228   double Bconnection   = atof(xbt_dict_get(storage_type->properties,"Bconnection"));
229   XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%ld'",Bconnection,Bread,Bwrite,storage_type->size);
230   storage->constraint       = lmm_constraint_new(storage_maxmin_system, storage, Bconnection);
231   storage->constraint_read  = lmm_constraint_new(storage_maxmin_system, storage, Bread);
232   storage->constraint_write = lmm_constraint_new(storage_maxmin_system, storage, Bwrite);
233   storage->content = parse_storage_content((char*)content_name,&(storage->used_size));
234   storage->size = storage_type->size;
235
236   xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
237
238   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tproperties '%p'\n\t\tBread '%f'\n",
239       id,
240       model,
241       type_id,
242       storage_type->properties,
243       Bread);
244
245   if(!storage_list) storage_list=xbt_dynar_new(sizeof(char *),NULL);
246   xbt_dynar_push(storage_list,&storage);
247
248   return storage;
249 }
250
251 static void storage_finalize(void)
252 {
253   lmm_system_free(storage_maxmin_system);
254   storage_maxmin_system = NULL;
255
256   surf_model_exit(surf_storage_model);
257   surf_storage_model = NULL;
258
259   xbt_dynar_free(&storage_list);
260
261   xbt_swag_free
262       (storage_running_action_set_that_does_not_need_being_checked);
263   storage_running_action_set_that_does_not_need_being_checked = NULL;
264 }
265
266 static void storage_update_actions_state(double now, double delta)
267 {
268   surf_action_storage_t action = NULL;
269   surf_action_storage_t next_action = NULL;
270   xbt_swag_t running_actions = surf_storage_model->states.running_action_set;
271
272   // Update the disk usage
273   // Update the file size
274   // For each action of type write
275   xbt_swag_foreach_safe(action, next_action, running_actions) {
276     if(action->type == WRITE)
277     {
278       double rate = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
279       ((storage_t)(action->storage))->used_size += delta * rate; // disk usage
280       ((surf_action_t)action)->file->size += delta * rate; // file size
281     }
282   }
283
284   xbt_swag_foreach_safe(action, next_action, running_actions) {
285
286     double_update(&(GENERIC_ACTION(action).remains),
287                   lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
288
289     if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
290       double_update(&(GENERIC_ACTION(action).max_duration), delta);
291
292     if(GENERIC_ACTION(action).remains > 0 &&
293         lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0 &&
294         ((storage_t)action->storage)->used_size == ((storage_t)action->storage)->size)
295     {
296       GENERIC_ACTION(action).finish = surf_get_clock();
297       storage_action_state_set((surf_action_t) action, SURF_ACTION_FAILED);
298     } else if ((GENERIC_ACTION(action).remains <= 0) &&
299         (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0))
300     {
301       GENERIC_ACTION(action).finish = surf_get_clock();
302       storage_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
303     } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
304                (GENERIC_ACTION(action).max_duration <= 0))
305     {
306       GENERIC_ACTION(action).finish = surf_get_clock();
307       storage_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
308     }
309   }
310
311   return;
312 }
313
314 static double storage_share_resources(double NOW)
315 {
316   XBT_DEBUG("storage_share_resources %f",NOW);
317   s_surf_action_storage_t action;
318   unsigned int i,j;
319   storage_t storage;
320   surf_action_storage_t write_action;
321
322   double min_completion = generic_maxmin_share_resources(surf_storage_model->states.running_action_set,
323       xbt_swag_offset(action, generic_lmm_action.variable),
324       storage_maxmin_system, lmm_solve);
325
326   double rate;
327   // Foreach disk
328   xbt_dynar_foreach(storage_list,i,storage)
329   {
330     rate = 0;
331     // Foreach write action on disk
332     xbt_dynar_foreach(storage->write_actions,j,write_action)
333     {
334       rate += lmm_variable_getvalue(write_action->generic_lmm_action.variable);
335     }
336     if(rate > 0)
337       min_completion = MIN(min_completion, (storage->size-storage->used_size)/rate);
338   }
339
340   return min_completion;
341 }
342
343 static int storage_resource_used(void *resource_id)
344 {
345   THROW_UNIMPLEMENTED;
346   return 0;
347 }
348
349 static void storage_resources_state(void *id, tmgr_trace_event_t event_type,
350                                  double value, double time)
351 {
352   THROW_UNIMPLEMENTED;
353 }
354
355 static int storage_action_unref(surf_action_t action)
356 {
357   action->refcount--;
358   if (!action->refcount) {
359     xbt_swag_remove(action, action->state_set);
360     if (((surf_action_lmm_t) action)->variable)
361       lmm_variable_free(storage_maxmin_system,
362                         ((surf_action_lmm_t) action)->variable);
363 #ifdef HAVE_TRACING
364     xbt_free(action->category);
365 #endif
366     surf_action_free(&action);
367     return 1;
368   }
369   return 0;
370 }
371
372 static void storage_action_cancel(surf_action_t action)
373 {
374   surf_action_state_set(action, SURF_ACTION_FAILED);
375   return;
376 }
377
378 static void storage_action_state_set(surf_action_t action, e_surf_action_state_t state)
379 {
380   surf_action_state_set(action, state);
381   return;
382 }
383
384 static void storage_action_suspend(surf_action_t action)
385 {
386   XBT_IN("(%p)", action);
387   if (((surf_action_lmm_t) action)->suspended != 2) {
388     lmm_update_variable_weight(storage_maxmin_system,
389                                ((surf_action_lmm_t) action)->variable,
390                                0.0);
391     ((surf_action_lmm_t) action)->suspended = 1;
392   }
393   XBT_OUT();
394 }
395
396 static void storage_action_resume(surf_action_t action)
397 {
398   THROW_UNIMPLEMENTED;
399 }
400
401 static int storage_action_is_suspended(surf_action_t action)
402 {
403   return (((surf_action_lmm_t) action)->suspended == 1);
404 }
405
406 static void storage_action_set_max_duration(surf_action_t action, double duration)
407 {
408   THROW_UNIMPLEMENTED;
409 }
410
411 static void storage_action_set_priority(surf_action_t action, double priority)
412 {
413   THROW_UNIMPLEMENTED;
414 }
415
416 static void parse_storage_init(sg_platf_storage_cbarg_t storage)
417 {
418   void* stype = xbt_lib_get_or_null(storage_type_lib,
419                                     storage->type_id,
420                                     ROUTING_STORAGE_TYPE_LEVEL);
421   if(!stype) xbt_die("No storage type '%s'",storage->type_id);
422
423   // if storage content is not specified use the content of storage_type if exist
424   if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
425     storage->content = ((storage_type_t) stype)->content;
426     XBT_DEBUG("For disk '%s' content is empty, use the content of storage type '%s'",storage->id,((storage_type_t) stype)->type_id);
427   }
428
429   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' \n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tproperties '%p'\n",
430       storage->id,
431       ((storage_type_t) stype)->model,
432       ((storage_type_t) stype)->type_id,
433       storage->content,
434       ((storage_type_t) stype)->properties);
435
436   storage_create_resource(storage->id,
437      ((storage_type_t) stype)->model,
438      ((storage_type_t) stype)->type_id,
439      storage->content);
440 }
441
442 static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage)
443 {
444   XBT_DEBUG("parse_mstorage_init");
445 }
446
447 static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_)
448 {
449   XBT_DEBUG("parse_storage_type_init");
450 }
451
452 static void parse_mount_init(sg_platf_mount_cbarg_t mount)
453 {
454   XBT_DEBUG("parse_mount_init");
455 }
456
457 static void storage_define_callbacks()
458 {
459   sg_platf_storage_add_cb(parse_storage_init);
460   sg_platf_storage_type_add_cb(parse_storage_type_init);
461   sg_platf_mstorage_add_cb(parse_mstorage_init);
462   sg_platf_mount_add_cb(parse_mount_init);
463 }
464
465 static void surf_storage_model_init_internal(void)
466 {
467   s_surf_action_t action;
468
469   XBT_DEBUG("surf_storage_model_init_internal");
470   surf_storage_model = surf_model_init();
471
472   storage_running_action_set_that_does_not_need_being_checked =
473       xbt_swag_new(xbt_swag_offset(action, state_hookup));
474
475   surf_storage_model->name = "Storage";
476   surf_storage_model->action_unref = storage_action_unref;
477   surf_storage_model->action_cancel = storage_action_cancel;
478   surf_storage_model->action_state_set = storage_action_state_set;
479
480   surf_storage_model->model_private->finalize = storage_finalize;
481   surf_storage_model->model_private->update_actions_state = storage_update_actions_state;
482   surf_storage_model->model_private->share_resources = storage_share_resources;
483   surf_storage_model->model_private->resource_used = storage_resource_used;
484   surf_storage_model->model_private->update_resource_state = storage_resources_state;
485
486   surf_storage_model->suspend = storage_action_suspend;
487   surf_storage_model->resume = storage_action_resume;
488   surf_storage_model->is_suspended = storage_action_is_suspended;
489   surf_storage_model->set_max_duration = storage_action_set_max_duration;
490   surf_storage_model->set_priority = storage_action_set_priority;
491
492   surf_storage_model->extension.storage.open = storage_action_open;
493   surf_storage_model->extension.storage.close = storage_action_close;
494   surf_storage_model->extension.storage.read = storage_action_read;
495   surf_storage_model->extension.storage.write = storage_action_write;
496   surf_storage_model->extension.storage.unlink = storage_action_unlink;
497   surf_storage_model->extension.storage.ls = storage_action_ls;
498
499   if (!storage_maxmin_system) {
500     storage_maxmin_system = lmm_system_new(storage_selective_update);
501   }
502
503 }
504
505 void surf_storage_model_init_default(void)
506 {
507   surf_storage_model_init_internal();
508   storage_define_callbacks();
509
510   xbt_dynar_push(model_list, &surf_storage_model);
511 }
512
513 static void storage_parse_storage(sg_platf_storage_cbarg_t storage)
514 {
515   xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
516                "Reading a storage, processing unit \"%s\" already exists", storage->id);
517
518   // Verification of an existing type_id
519 #ifndef NDEBUG
520   void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
521 #endif
522   xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
523
524   XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
525       storage->id,
526       storage->type_id,
527       storage->content);
528
529   xbt_lib_set(storage_lib,
530       storage->id,
531       ROUTING_STORAGE_LEVEL,
532       (void *) xbt_strdup(storage->type_id));
533 }
534
535 static xbt_dict_t parse_storage_content(char *filename, unsigned long *used_size)
536 {
537   *used_size = 0;
538   if ((!filename) || (strcmp(filename, "") == 0))
539     return NULL;
540
541   xbt_dict_t parse_content = xbt_dict_new_homogeneous(NULL);
542   FILE *file = NULL;
543
544   file = surf_fopen(filename, "r");
545   xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
546               xbt_str_join(surf_path, ":"));
547
548   char *line = NULL;
549   size_t len = 0;
550   ssize_t read;
551   char path[1024];
552   unsigned long size;
553
554
555   while ((read = xbt_getline(&line, &len, file)) != -1) {
556     if (read){
557     if(sscanf(line,"%s %ld",path, &size)==2) {
558         *used_size += size;
559         xbt_dict_set(parse_content,path,(void*) size,NULL);
560       } else {
561         xbt_die("Be sure of passing a good format for content file.\n");
562       }
563     }
564   }
565   free(line);
566   fclose(file);
567   return parse_content;
568 }
569
570 static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type)
571 {
572   xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
573                "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
574
575   storage_type_t stype = xbt_new0(s_storage_type_t, 1);
576   stype->model = xbt_strdup(storage_type->model);
577   stype->properties = storage_type->properties;
578   stype->content = xbt_strdup(storage_type->content);
579   stype->type_id = xbt_strdup(storage_type->id);
580   stype->size = storage_type->size * 1000000000; /* storage_type->size is in Gbytes and stype->sizeis in bytes */
581
582   XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s' content '%s'",
583       stype->type_id,
584       stype->model,
585       storage_type->content);
586
587   xbt_lib_set(storage_type_lib,
588       stype->type_id,
589       ROUTING_STORAGE_TYPE_LEVEL,
590       (void *) stype);
591 }
592 static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage)
593 {
594   THROW_UNIMPLEMENTED;
595 //  mount_t mnt = xbt_new0(s_mount_t, 1);
596 //  mnt->id = xbt_strdup(mstorage->type_id);
597 //  mnt->name = xbt_strdup(mstorage->name);
598 //
599 //  if(!mount_list){
600 //    XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
601 //    mount_list = xbt_dynar_new(sizeof(char *), NULL);
602 //  }
603 //  xbt_dynar_push(mount_list,(void *) mnt);
604 //  free(mnt->id);
605 //  free(mnt->name);
606 //  xbt_free(mnt);
607 //  XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
608 }
609
610 static void mount_free(void *p)
611 {
612   mount_t mnt = p;
613   xbt_free(mnt->name);
614 }
615
616 static void storage_parse_mount(sg_platf_mount_cbarg_t mount)
617 {
618   // Verification of an existing storage
619 #ifndef NDEBUG
620   void* storage = xbt_lib_get_or_null(storage_lib, mount->id,ROUTING_STORAGE_LEVEL);
621 #endif
622   xbt_assert(storage,"Disk id \"%s\" does not exists", mount->id);
623
624   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->id, mount->name);
625
626   s_mount_t mnt;
627   mnt.id = surf_storage_resource_priv(surf_storage_resource_by_name(mount->id));
628   mnt.name = xbt_strdup(mount->name);
629
630   if(!mount_list){
631     XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
632     mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
633   }
634   xbt_dynar_push(mount_list,&mnt);
635 }
636
637 static XBT_INLINE void routing_storage_type_free(void *r)
638 {
639   storage_type_t stype = r;
640   free(stype->model);
641   free(stype->type_id);
642   free(stype->content);
643   xbt_dict_free(&(stype->properties));
644   free(stype);
645 }
646
647 static XBT_INLINE void surf_storage_resource_free(void *r)
648 {
649   // specific to storage
650   storage_t storage = r;
651   xbt_dict_free(&storage->content);
652   xbt_dynar_free(&storage->write_actions);
653   // generic resource
654   surf_resource_free(r);
655 }
656
657 static XBT_INLINE void routing_storage_host_free(void *r)
658 {
659   xbt_dynar_t dyn = r;
660   xbt_dynar_free(&dyn);
661 }
662
663 void storage_register_callbacks() {
664
665   ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,xbt_free);
666   ROUTING_STORAGE_HOST_LEVEL = xbt_lib_add_level(storage_lib,routing_storage_host_free);
667   ROUTING_STORAGE_TYPE_LEVEL = xbt_lib_add_level(storage_type_lib,routing_storage_type_free);
668   SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_resource_free);
669
670   sg_platf_storage_add_cb(storage_parse_storage);
671   sg_platf_mstorage_add_cb(storage_parse_mstorage);
672   sg_platf_storage_type_add_cb(storage_parse_storage_type);
673   sg_platf_mount_add_cb(storage_parse_mount);
674 }