Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Restructure surf++ storage
[simgrid.git] / src / surf / storage_interface.cpp
1 #include "storage_interface.hpp"
2 #include "surf_private.h"
3
4 #define __STDC_FORMAT_MACROS
5
6 extern "C" {
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
8                                 "Logging specific to the SURF storage module");
9 }
10
11 xbt_lib_t storage_lib;
12 int ROUTING_STORAGE_LEVEL;      //Routing for storagelevel
13 int ROUTING_STORAGE_HOST_LEVEL;
14 int SURF_STORAGE_LEVEL;
15 xbt_lib_t storage_type_lib;
16 int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level
17
18 xbt_dynar_t mount_list = NULL;
19 StorageModelPtr surf_storage_model = NULL;
20
21 /*********
22  * Model *
23  *********/
24
25 StorageModel::StorageModel() : Model("Storage") {
26 }
27
28 StorageModel::~StorageModel(){
29   lmm_system_free(p_maxminSystem);
30
31   surf_storage_model = NULL;
32
33   xbt_dynar_free(&p_storageList);
34 }
35
36 /************
37  * Resource *
38  ************/
39
40 Storage::Storage(const char* type_id, char *content_name, char *content_type, sg_size_t size)
41 :  p_content(parseContent(content_name)), p_contentType(content_type),
42    m_size(size), m_usedSize(0), p_typeId(xbt_strdup(type_id)), p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL))
43 {
44   p_stateCurrent = SURF_RESOURCE_ON;
45 }
46
47 Storage::~Storage(){
48   xbt_dict_free(&p_content);
49   xbt_dynar_free(&p_writeActions);
50   free(p_typeId);
51   free(p_contentType);
52 }
53
54 xbt_dict_t Storage::parseContent(char *filename)
55 {
56   m_usedSize = 0;
57   if ((!filename) || (strcmp(filename, "") == 0))
58     return NULL;
59
60   xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
61   FILE *file = NULL;
62
63   file = surf_fopen(filename, "r");
64   xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
65               xbt_str_join(surf_path, ":"));
66
67   char *line = NULL;
68   size_t len = 0;
69   ssize_t read;
70   char path[1024];
71   sg_size_t size;
72
73
74   while ((read = xbt_getline(&line, &len, file)) != -1) {
75     if (read){
76     if(sscanf(line,"%s %llu", path, &size) == 2) {
77         m_usedSize += size;
78         sg_size_t *psize = xbt_new(sg_size_t, 1);
79         *psize = size;
80         xbt_dict_set(parse_content,path,psize,NULL);
81       } else {
82         xbt_die("Be sure of passing a good format for content file.\n");
83       }
84     }
85   }
86   free(line);
87   fclose(file);
88   return parse_content;
89 }
90
91 bool Storage::isUsed()
92 {
93   THROW_UNIMPLEMENTED;
94   return false;
95 }
96
97 void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/)
98 {
99   THROW_UNIMPLEMENTED;
100 }
101
102 xbt_dict_t Storage::getContent()
103 {
104   /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
105   /*surf_action_t action = storage_action_execute(storage,0, LS);*/
106
107   xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
108   xbt_dict_cursor_t cursor = NULL;
109   char *file;
110   sg_size_t *psize;
111
112   xbt_dict_foreach(p_content, cursor, file, psize){
113     xbt_dict_set(content_dict,file,psize,NULL);
114   }
115   return content_dict;
116 }
117
118 sg_size_t Storage::getSize(){
119   return m_size;
120 }
121
122 StorageLmm::StorageLmm(lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
123              const char* type_id, char *content_name, char *content_type, sg_size_t size)
124  :  ResourceLmm(), Storage(type_id, content_name, content_type, size) {
125   XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
126
127   p_constraint = lmm_constraint_new(maxminSystem, this, bconnection);
128   p_constraintRead  = lmm_constraint_new(maxminSystem, this, bread);
129   p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
130 }
131
132 /**********
133  * Action *
134  **********/
135 StorageAction::StorageAction(StoragePtr storage, e_surf_action_storage_type_t type)
136 : m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL)
137 {
138 };
139
140 StorageActionLmm::StorageActionLmm(StorageLmmPtr storage, e_surf_action_storage_type_t type)
141   : StorageAction(storage, type) {
142 }
143