+
+static void storage_parse_storage(sg_platf_storage_cbarg_t storage)
+{
+ xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
+ "Reading a storage, processing unit \"%s\" already exists", storage->id);
+
+ // Verification of an existing type_id
+#ifndef NDEBUG
+ void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
+#endif
+ xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
+
+ XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
+ storage->id,
+ storage->type_id,
+ storage->content);
+
+ xbt_lib_set(storage_lib,
+ storage->id,
+ ROUTING_STORAGE_LEVEL,
+ (void *) xbt_strdup(storage->type_id));
+}
+
+static xbt_dict_t parse_storage_content(char *filename, size_t *used_size)
+{
+ *used_size = 0;
+ if ((!filename) || (strcmp(filename, "") == 0))
+ return NULL;
+
+ xbt_dict_t parse_content = xbt_dict_new_homogeneous(NULL);
+ 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];
+ size_t size;
+
+
+ while ((read = xbt_getline(&line, &len, file)) != -1) {
+ if (read){
+ if(sscanf(line,"%s %zu",path, &size)==2) {
+ *used_size += size;
+ xbt_dict_set(parse_content,path,(void*) size,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),
+ "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
+
+ storage_type_t stype = xbt_new0(s_storage_type_t, 1);
+ stype->model = xbt_strdup(storage_type->model);
+ stype->properties = storage_type->properties;
+ stype->content = xbt_strdup(storage_type->content);
+ stype->type_id = xbt_strdup(storage_type->id);
+ stype->size = storage_type->size * 1000000000; /* storage_type->size is in Gbytes and stype->sizeis in bytes */
+
+ XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s' content '%s'",
+ stype->type_id,
+ stype->model,
+ storage_type->content);
+
+ xbt_lib_set(storage_type_lib,
+ stype->type_id,
+ ROUTING_STORAGE_TYPE_LEVEL,
+ (void *) stype);
+}
+static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage)
+{
+ THROW_UNIMPLEMENTED;
+// mount_t mnt = xbt_new0(s_mount_t, 1);
+// mnt->id = xbt_strdup(mstorage->type_id);
+// mnt->name = xbt_strdup(mstorage->name);
+//
+// if(!mount_list){
+// XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
+// mount_list = xbt_dynar_new(sizeof(char *), NULL);
+// }
+// xbt_dynar_push(mount_list,(void *) mnt);
+// free(mnt->id);
+// free(mnt->name);
+// xbt_free(mnt);
+// XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
+}
+
+static void mount_free(void *p)
+{
+ mount_t mnt = p;
+ xbt_free(mnt->name);
+}
+
+static void storage_parse_mount(sg_platf_mount_cbarg_t mount)
+{
+ // Verification of an existing storage
+#ifndef NDEBUG
+ void* storage = xbt_lib_get_or_null(storage_lib, mount->id,ROUTING_STORAGE_LEVEL);
+#endif
+ xbt_assert(storage,"Disk id \"%s\" does not exists", mount->id);
+
+ XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->id, mount->name);
+
+ s_mount_t mnt;
+ mnt.id = surf_storage_resource_priv(surf_storage_resource_by_name(mount->id));
+ 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);
+}
+
+static XBT_INLINE void routing_storage_type_free(void *r)
+{
+ storage_type_t stype = r;
+ free(stype->model);
+ free(stype->type_id);
+ free(stype->content);
+ xbt_dict_free(&(stype->properties));
+ free(stype);
+}
+
+static XBT_INLINE void surf_storage_resource_free(void *r)
+{
+ // specific to storage
+ storage_t storage = r;
+ xbt_dict_free(&storage->content);
+ xbt_dynar_free(&storage->write_actions);
+ // generic resource
+ surf_resource_free(r);
+}
+
+static XBT_INLINE void routing_storage_host_free(void *r)
+{
+ xbt_dynar_t dyn = r;
+ xbt_dynar_free(&dyn);
+}
+
+void storage_register_callbacks() {
+
+ ROUTING_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,xbt_free);
+ 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,surf_storage_resource_free);
+
+ sg_platf_storage_add_cb(storage_parse_storage);
+ sg_platf_mstorage_add_cb(storage_parse_mstorage);
+ sg_platf_storage_type_add_cb(storage_parse_storage_type);
+ sg_platf_mount_add_cb(storage_parse_mount);
+}