Logo AND Algorithmique Numérique Distribuée

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