1 #include "storage_interface.hpp"
2 #include "surf_private.h"
4 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
5 "Logging specific to the SURF storage module");
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
14 xbt_dynar_t mount_list = NULL;
15 StorageModelPtr surf_storage_model = NULL;
21 surf_callback(void, StoragePtr) storageCreatedCallbacks;
22 surf_callback(void, StoragePtr) storageDestructedCallbacks;
23 surf_callback(void, StoragePtr) storageStateChangedCallbacks;
24 surf_callback(void, StorageActionPtr) storageActionStateChangedCallbacks;
30 StorageModel::StorageModel() : Model("Storage") {
34 StorageModel::~StorageModel(){
35 lmm_system_free(p_maxminSystem);
37 surf_storage_model = NULL;
39 xbt_dynar_free(&p_storageList);
46 Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
47 const char* type_id, char *content_name, char *content_type, sg_size_t size)
48 : Resource(model, name, props)
49 , p_contentType(content_type)
50 , m_size(size), m_usedSize(0)
51 , p_typeId(xbt_strdup(type_id))
52 , p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL))
54 surf_callback_emit(storageCreatedCallbacks, this);
55 p_content = parseContent(content_name);
56 setState(SURF_RESOURCE_ON);
59 Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
60 lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
61 const char* type_id, char *content_name, char *content_type, sg_size_t size)
62 : Resource(model, name, props, lmm_constraint_new(maxminSystem, this, bconnection))
63 , p_contentType(content_type)
64 , m_size(size), m_usedSize(0)
65 , p_typeId(xbt_strdup(type_id))
66 , p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL)) {
67 surf_callback_emit(storageCreatedCallbacks, this);
68 p_content = parseContent(content_name);
69 setState(SURF_RESOURCE_ON);
70 XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
71 p_constraintRead = lmm_constraint_new(maxminSystem, this, bread);
72 p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
76 surf_callback_emit(storageDestructedCallbacks, this);
77 xbt_dict_free(&p_content);
78 xbt_dynar_free(&p_writeActions);
83 xbt_dict_t Storage::parseContent(char *filename)
86 if ((!filename) || (strcmp(filename, "") == 0))
89 xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
92 file = surf_fopen(filename, "r");
93 xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
94 xbt_str_join(surf_path, ":"));
103 while ((read = xbt_getline(&line, &len, file)) != -1) {
105 if(sscanf(line,"%s %llu", path, &size) == 2) {
107 sg_size_t *psize = xbt_new(sg_size_t, 1);
109 xbt_dict_set(parse_content,path,psize,NULL);
111 xbt_die("Be sure of passing a good format for content file.\n");
117 return parse_content;
120 bool Storage::isUsed()
126 void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/)
131 void Storage::setState(e_surf_resource_state_t state)
133 Resource::setState(state);
134 surf_callback_emit(storageStateChangedCallbacks, this);
137 xbt_dict_t Storage::getContent()
139 /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
140 /*surf_action_t action = storage_action_execute(storage,0, LS);*/
142 xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
143 xbt_dict_cursor_t cursor = NULL;
147 xbt_dict_foreach(p_content, cursor, file, psize){
148 xbt_dict_set(content_dict,file,psize,NULL);
153 sg_size_t Storage::getSize(){
160 StorageAction::StorageAction(ModelPtr model, double cost, bool failed,
161 StoragePtr storage, e_surf_action_storage_type_t type)
162 : Action(model, cost, failed)
163 , m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL)
167 StorageAction::StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
168 StoragePtr storage, e_surf_action_storage_type_t type)
169 : Action(model, cost, failed, var)
170 , m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL) {
173 void StorageAction::setState(e_surf_action_state_t state){
174 Action::setState(state);
175 surf_callback_emit(storageActionStateChangedCallbacks, this);