Logo AND Algorithmique Numérique Distribuée

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