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 StorageModel::StorageModel() : Model("Storage") {
25 StorageModel::~StorageModel(){
26 lmm_system_free(p_maxminSystem);
28 surf_storage_model = NULL;
30 xbt_dynar_free(&p_storageList);
37 Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
38 const char* type_id, char *content_name, char *content_type, sg_size_t size)
39 : Resource(model, name, props)
40 , p_contentType(content_type)
41 , m_size(size), m_usedSize(0)
42 , p_typeId(xbt_strdup(type_id))
43 , p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL))
45 p_content = parseContent(content_name);
46 m_stateCurrent = SURF_RESOURCE_ON;
49 Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
50 lmm_system_t maxminSystem, double bread, double bwrite, double bconnection,
51 const char* type_id, char *content_name, char *content_type, sg_size_t size)
52 : Resource(model, name, props, lmm_constraint_new(maxminSystem, this, bconnection))
53 , p_contentType(content_type)
54 , m_size(size), m_usedSize(0)
55 , p_typeId(xbt_strdup(type_id))
56 , p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL)) {
57 p_content = parseContent(content_name);
58 m_stateCurrent = SURF_RESOURCE_ON;
59 XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
60 p_constraintRead = lmm_constraint_new(maxminSystem, this, bread);
61 p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
65 xbt_dict_free(&p_content);
66 xbt_dynar_free(&p_writeActions);
71 xbt_dict_t Storage::parseContent(char *filename)
74 if ((!filename) || (strcmp(filename, "") == 0))
77 xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free);
80 file = surf_fopen(filename, "r");
81 xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename,
82 xbt_str_join(surf_path, ":"));
91 while ((read = xbt_getline(&line, &len, file)) != -1) {
93 if(sscanf(line,"%s %llu", path, &size) == 2) {
95 sg_size_t *psize = xbt_new(sg_size_t, 1);
97 xbt_dict_set(parse_content,path,psize,NULL);
99 xbt_die("Be sure of passing a good format for content file.\n");
105 return parse_content;
108 bool Storage::isUsed()
114 void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/)
119 xbt_dict_t Storage::getContent()
121 /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
122 /*surf_action_t action = storage_action_execute(storage,0, LS);*/
124 xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL);
125 xbt_dict_cursor_t cursor = NULL;
129 xbt_dict_foreach(p_content, cursor, file, psize){
130 xbt_dict_set(content_dict,file,psize,NULL);
135 sg_size_t Storage::getSize(){
144 StorageAction::StorageAction(ModelPtr model, double cost, bool failed,
145 StoragePtr storage, e_surf_action_storage_type_t type)
146 : Action(model, cost, failed)
147 , m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL)
151 StorageAction::StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
152 StoragePtr storage, e_surf_action_storage_type_t type)
153 : Action(model, cost, failed, var)
154 , m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL) {