X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/eee21ec5f99218189fc98898a09150294cd0fbf4..2f2ce19fcb66a634c19de8dda2dc4b4896203537:/src/surf/storage.cpp diff --git a/src/surf/storage.cpp b/src/surf/storage.cpp index 12444185a9..aa5fe7a24a 100644 --- a/src/surf/storage.cpp +++ b/src/surf/storage.cpp @@ -2,7 +2,6 @@ #include "surf_private.h" #define __STDC_FORMAT_MACROS -#include extern "C" { XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, @@ -90,17 +89,17 @@ static void parse_storage_init(sg_platf_storage_cbarg_t storage) storage->properties); } -static void parse_mstorage_init(sg_platf_mstorage_cbarg_t mstorage) +static void parse_mstorage_init(sg_platf_mstorage_cbarg_t /*mstorage*/) { XBT_DEBUG("parse_mstorage_init"); } -static void parse_storage_type_init(sg_platf_storage_type_cbarg_t storagetype_) +static void parse_storage_type_init(sg_platf_storage_type_cbarg_t /*storagetype_*/) { XBT_DEBUG("parse_storage_type_init"); } -static void parse_mount_init(sg_platf_mount_cbarg_t mount) +static void parse_mount_init(sg_platf_mount_cbarg_t /*mount*/) { XBT_DEBUG("parse_mount_init"); } @@ -127,43 +126,6 @@ static void storage_parse_storage(sg_platf_storage_cbarg_t storage) (void *) xbt_strdup(storage->type_id)); } -static xbt_dict_t parse_storage_content(char *filename, sg_storage_size_t *used_size) -{ - *used_size = 0; - if ((!filename) || (strcmp(filename, "") == 0)) - return NULL; - - xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free); - FILE *file = NULL; - - file = surf_fopen(filename, "r"); - xbt_assert(file != NULL, "Cannot open file '%s' (path=%s)", filename, - xbt_str_join(surf_path, ":")); - - char *line = NULL; - size_t len = 0; - ssize_t read; - char path[1024]; - sg_storage_size_t size; - - - while ((read = xbt_getline(&line, &len, file)) != -1) { - if (read){ - if(sscanf(line,"%s %" SCNu64, path, &size) == 2) { - *used_size += size; - sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1); - *psize = size; - xbt_dict_set(parse_content,path,psize,NULL); - } else { - xbt_die("Be sure of passing a good format for content file.\n"); - } - } - } - free(line); - fclose(file); - return parse_content; -} - static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_type) { xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL), @@ -189,7 +151,7 @@ static void storage_parse_storage_type(sg_platf_storage_type_cbarg_t storage_typ ROUTING_STORAGE_TYPE_LEVEL, (void *) stype); } -static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t mstorage) +static void storage_parse_mstorage(sg_platf_mstorage_cbarg_t /*mstorage*/) { THROW_UNIMPLEMENTED; // mount_t mnt = xbt_new0(s_mount_t, 1); @@ -228,7 +190,7 @@ static void storage_parse_mount(sg_platf_mount_cbarg_t mount) mnt.name = xbt_strdup(mount->name); if(!mount_list){ - //FIXME:XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id); + XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id); mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free); } xbt_dynar_push(mount_list,&mnt); @@ -330,6 +292,7 @@ double StorageModel::shareResources(double now) XBT_DEBUG("storage_share_resources %f", now); unsigned int i, j; StoragePtr storage; + void *_write_action; StorageActionLmmPtr write_action; double min_completion = shareResourcesMaxMin(p_runningActionSet, @@ -341,8 +304,9 @@ double StorageModel::shareResources(double now) { rate = 0; // Foreach write action on disk - xbt_dynar_foreach(storage->p_writeActions, j, write_action) + xbt_dynar_foreach(storage->p_writeActions, j, _write_action) { + write_action = dynamic_cast(static_cast(_write_action)); rate += lmm_variable_getvalue(write_action->p_variable); } if(rate > 0) @@ -352,7 +316,7 @@ double StorageModel::shareResources(double now) return min_completion; } -void StorageModel::updateActionsState(double now, double delta) +void StorageModel::updateActionsState(double /*now*/, double delta) { void *_action, *_next_action; StorageActionLmmPtr action = NULL; @@ -366,12 +330,12 @@ void StorageModel::updateActionsState(double now, double delta) // For each action of type write double rate = lmm_variable_getvalue(action->p_variable); /* Hack to avoid rounding differences between x86 and x86_64 - * (note that the next sizes are of type sg_storage_size_t). */ + * (note that the next sizes are of type sg_size_t). */ long incr = delta * rate + MAXMIN_PRECISION; action->p_storage->m_usedSize += incr; // disk usage action->p_file->size += incr; // file size - sg_storage_size_t *psize = xbt_new(sg_storage_size_t,1); + sg_size_t *psize = xbt_new(sg_size_t,1); *psize = action->p_file->size; xbt_dict_t content_dict = action->p_storage->p_content; @@ -423,14 +387,14 @@ xbt_dict_t Storage::parseContent(char *filename) size_t len = 0; ssize_t read; char path[1024]; - sg_storage_size_t size; + sg_size_t size; while ((read = xbt_getline(&line, &len, file)) != -1) { if (read){ - if(sscanf(line,"%s %" SCNu64, path, &size) == 2) { + if(sscanf(line,"%s %llu", path, &size) == 2) { m_usedSize += size; - sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1); + sg_size_t *psize = xbt_new(sg_size_t, 1); *psize = size; xbt_dict_set(parse_content,path,psize,NULL); } else { @@ -450,14 +414,14 @@ xbt_dict_t Storage::parseContent(char *filename) Storage::Storage(StorageModelPtr model, const char* name, xbt_dict_t properties) : Resource(model, name, properties) { - p_writeActions = xbt_dynar_new(sizeof(char *),NULL); + p_writeActions = xbt_dynar_new(sizeof(ActionPtr),NULL); } StorageLmm::StorageLmm(StorageModelPtr model, const char* name, xbt_dict_t properties, lmm_system_t maxminSystem, double bread, double bwrite, double bconnection, - const char* type_id, char *content_name, char *content_type, size_t size) + const char* type_id, char *content_name, char *content_type, sg_size_t size) : Resource(model, name, properties), ResourceLmm(), Storage(model, name, properties) { - XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%lu'", bconnection, bread, bwrite, ((unsigned long)size)); + XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size); p_stateCurrent = SURF_RESOURCE_ON; m_usedSize = 0; @@ -478,7 +442,7 @@ bool Storage::isUsed() return false; } -void Storage::updateState(tmgr_trace_event_t event_type, double value, double date) +void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) { THROW_UNIMPLEMENTED; } @@ -491,7 +455,7 @@ StorageActionPtr StorageLmm::ls(const char* path) xbt_dict_t ls_dict = xbt_dict_new_homogeneous(xbt_free); char* key; - sg_storage_size_t size = 0; + sg_size_t size = 0; xbt_dict_cursor_t cursor = NULL; xbt_dynar_t dyn = NULL; @@ -509,7 +473,7 @@ StorageActionPtr StorageLmm::ls(const char* path) // file if(xbt_dynar_length(dyn) == 1){ - sg_storage_size_t *psize = xbt_new(sg_storage_size_t, 1); + sg_size_t *psize = xbt_new(sg_size_t, 1); *psize=size; xbt_dict_set(ls_dict, file, psize, NULL); } @@ -531,13 +495,13 @@ StorageActionPtr StorageLmm::ls(const char* path) StorageActionPtr StorageLmm::open(const char* mount, const char* path) { XBT_DEBUG("\tOpen file '%s'",path); - sg_storage_size_t size, *psize; - psize = (sg_storage_size_t*) xbt_dict_get_or_null(p_content, path); + sg_size_t size, *psize; + psize = (sg_size_t*) xbt_dict_get_or_null(p_content, path); // if file does not exist create an empty file if(psize) size = *psize; else { - psize = xbt_new(sg_storage_size_t,1); + psize = xbt_new(sg_size_t,1); size = 0; *psize = size; xbt_dict_set(p_content, path, psize, NULL); @@ -556,11 +520,13 @@ StorageActionPtr StorageLmm::open(const char* mount, const char* path) StorageActionPtr StorageLmm::close(surf_file_t fd) { char *filename = fd->name; - XBT_DEBUG("\tClose file '%s' size '%" PRIu64 "'", filename, fd->size); + XBT_DEBUG("\tClose file '%s' size '%llu'", filename, fd->size); // unref write actions from storage + void *_write_action; StorageActionLmmPtr write_action; unsigned int i; - xbt_dynar_foreach(p_writeActions, i, write_action) { + xbt_dynar_foreach(p_writeActions, i, _write_action) { + write_action = dynamic_cast(static_cast(_write_action)); if ((write_action->p_file) == fd) { xbt_dynar_cursor_rm(p_writeActions, &i); write_action->unref(); @@ -573,7 +539,7 @@ StorageActionPtr StorageLmm::close(surf_file_t fd) return action; } -StorageActionPtr StorageLmm::read(surf_file_t fd, sg_storage_size_t size) +StorageActionPtr StorageLmm::read(surf_file_t fd, sg_size_t size) { if(size > fd->size) size = fd->size; @@ -581,10 +547,10 @@ StorageActionPtr StorageLmm::read(surf_file_t fd, sg_storage_size_t size) return action; } -StorageActionPtr StorageLmm::write(surf_file_t fd, sg_storage_size_t size) +StorageActionPtr StorageLmm::write(surf_file_t fd, sg_size_t size) { char *filename = fd->name; - XBT_DEBUG("\tWrite file '%s' size '%" PRIu64 "/%" PRIu64 "'",filename,size,fd->size); + XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size); StorageActionLmmPtr action = new StorageActionLmm(p_model, size, p_stateCurrent != SURF_RESOURCE_ON, this, WRITE); action->p_file = fd; @@ -596,6 +562,21 @@ StorageActionPtr StorageLmm::write(surf_file_t fd, sg_storage_size_t size) return action; } +void StorageLmm::rename(const char *src, const char *dest) +{ + sg_size_t *psize, *new_psize; + psize = (sg_size_t*) xbt_dict_get_or_null(p_content,src); + new_psize = xbt_new(sg_size_t, 1); + *new_psize = *psize; + if (psize){// src file exists + xbt_dict_remove(p_content, src); + xbt_dict_set(p_content, dest, new_psize,NULL); + XBT_DEBUG("Change file name from %s to %s, size '%llu'",src, dest, *psize); + } + else + XBT_DEBUG("File %s doesn't exist",src); +} + xbt_dict_t StorageLmm::getContent() { /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */ @@ -604,7 +585,7 @@ xbt_dict_t StorageLmm::getContent() xbt_dict_t content_dict = xbt_dict_new_homogeneous(NULL); xbt_dict_cursor_t cursor = NULL; char *file; - sg_storage_size_t *psize; + sg_size_t *psize; xbt_dict_foreach(p_content, cursor, file, psize){ xbt_dict_set(content_dict,file,psize,NULL); @@ -612,7 +593,7 @@ xbt_dict_t StorageLmm::getContent() return content_dict; } -sg_storage_size_t StorageLmm::getSize(){ +sg_size_t StorageLmm::getSize(){ return m_size; } @@ -621,8 +602,10 @@ sg_storage_size_t StorageLmm::getSize(){ **********/ StorageActionLmm::StorageActionLmm(ModelPtr model, double cost, bool failed, StorageLmmPtr storage, e_surf_action_storage_type_t type) - : Action(model, cost, failed), ActionLmm(model, cost, failed), StorageAction(model, cost, failed, storage, type) { - XBT_IN("(%s,%" PRIu64, storage->m_name, cost); + : Action(model, cost, failed), + ActionLmm(model, cost, failed), + StorageAction(model, cost, failed, storage, type) { + XBT_IN("(%s,%g", storage->m_name, cost); p_variable = lmm_variable_new(p_model->p_maxminSystem, this, 1.0, -1.0 , 3); // Must be less than the max bandwidth for all actions @@ -640,7 +623,9 @@ StorageActionLmm::StorageActionLmm(ModelPtr model, double cost, bool failed, Sto case WRITE: lmm_expand(p_model->p_maxminSystem, storage->p_constraintWrite, p_variable, 1.0); - xbt_dynar_push(storage->p_writeActions, static_cast(this)); + ActionPtr action = this; + xbt_dynar_push(storage->p_writeActions, &action); + ref(); break; } XBT_OUT(); @@ -690,12 +675,12 @@ bool StorageActionLmm::isSuspended() return m_suspended == 1; } -void StorageActionLmm::setMaxDuration(double duration) +void StorageActionLmm::setMaxDuration(double /*duration*/) { THROW_UNIMPLEMENTED; } -void StorageActionLmm::setPriority(double priority) +void StorageActionLmm::setPriority(double /*priority*/) { THROW_UNIMPLEMENTED; }