Logo AND Algorithmique Numérique Distribuée

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